00001 package dionarap; 00002 00003 import java.io.File; 00004 import java.util.Vector; 00005 00006 import javax.swing.ImageIcon; 00007 00017 public class Artwork { 00019 static public final String DEFAULT_THEME = "Dracula"; 00020 00022 static private final String[] extensions = new String[] { ".gif", ".jpg", ".png" }; 00023 00025 static private Artwork artwork; 00026 00028 private String root; 00029 00031 private String themename; 00032 00034 private Vector<String> themenames; 00035 00037 private ImageIcon opponent, vortex, obstacle, gameover, gamewon, destruction, ammo; 00038 00040 private ImageIcon[] player; 00041 00042 00048 private Artwork() { 00049 this.root = System.getProperty("user.dir") + File.separator + "themes" + File.separator; 00050 this.themenames = new Vector<String>(); 00051 try { 00052 File f = new File(this.root); 00053 File[] files = f.listFiles(); 00054 for (int i = 0; i < files.length; i++) { 00055 if (!files[i].isDirectory()) continue; 00056 00057 this.themenames.add(files[i].getName()); 00058 } 00059 } catch (Exception e) { 00061 } 00062 00063 this.player = new ImageIcon[9]; 00064 00068 this.setTheme(Artwork.DEFAULT_THEME); 00069 } 00070 00071 00076 public void setTheme(String name) { 00077 this.themename = name; 00078 this.loadIcons(); 00079 } 00080 00085 static public Artwork getTheme() { 00086 if (Artwork.artwork == null) 00087 Artwork.artwork = new Artwork(); 00088 00089 return Artwork.artwork; 00090 } 00091 00095 private void loadIcons() { 00096 this.opponent = this.getIcon("opponent"); 00097 this.obstacle = this.getIcon("obstacle"); 00098 this.vortex = this.getIcon("vortex"); 00099 this.gameover = this.getIcon("loss"); 00100 this.gamewon = this.getIcon("gamewon"); 00101 this.destruction = this.getIcon("destruction"); 00102 this.ammo = this.getIcon("ammo"); 00103 00104 for (int i = 0; i < 9; i++) { 00105 this.player[i] = this.getIcon("player" + (i+1)); 00106 } 00107 } 00108 00109 00117 private ImageIcon getIcon(String file) { 00118 String basefilename = this.root + this.themename + File.separator + file; 00119 for (int i = 0; i < Artwork.extensions.length; i++) { 00120 File test = new File(basefilename + Artwork.extensions[i]); 00121 if (test.exists()) return new ImageIcon(test.getAbsolutePath()); 00122 } 00123 System.out.println("Keine passende Datei fuer " + file + " gefunden"); 00124 return null; 00125 } 00126 00127 00132 public String[] getThemes() { 00133 int size = this.themenames.size(); 00134 String[] r = new String[size]; 00135 for (int i = 0; i < size; i++) { 00136 r[i] = this.themenames.get(i); 00137 } 00138 return r; 00139 } 00140 00141 00146 public String getCurrentTheme() { 00147 return this.themename; 00148 } 00149 00150 00155 public ImageIcon getOpponentIcon() { 00156 return this.opponent; 00157 } 00158 00159 00164 public ImageIcon getVortexIcon() { 00165 return this.vortex; 00166 } 00167 00168 00174 public ImageIcon getPlayerIcon(int direction) { 00175 return this.player[direction-1]; 00176 } 00177 00178 00183 public ImageIcon getObstacleIcon() { 00184 return this.obstacle; 00185 } 00186 00187 00192 public ImageIcon getGameOverIcon() { 00193 return this.gameover; 00194 } 00195 00196 00201 public ImageIcon getGameWonIcon() { 00202 return this.gamewon; 00203 } 00204 00205 00210 public ImageIcon getDestructionIcon() { 00211 return this.destruction; 00212 } 00213 00214 00219 public ImageIcon getAmmoIcon() { 00220 return this.ammo; 00221 } 00222 00223 00224 }