1 package org.antlr.gunit.swingui; 2 3 import java.io.IOException; 4 import java.io.InputStream; 5 import java.net.URL; 6 import java.util.logging.Level; 7 import java.util.logging.Logger; 8 import javax.swing.ImageIcon; 9 10 public class ImageFactory { 11 12 private static ImageFactory singleton ; 13 getSingleton()14 public static ImageFactory getSingleton() { 15 if(singleton == null) singleton = new ImageFactory(); 16 return singleton; 17 } 18 ImageFactory()19 private ImageFactory() { 20 ACCEPT = getImage("accept.png"); 21 ADD = getImage("add.png"); 22 DELETE = getImage("delete24.png"); 23 TEXTFILE = getImage("textfile24.png"); 24 TEXTFILE16 = getImage("textfile16.png"); 25 ADDFILE = getImage("addfile24.png"); 26 WINDOW16 = getImage("windowb16.png"); 27 FAV16 = getImage("favb16.png"); 28 SAVE = getImage("floppy24.png"); 29 OPEN = getImage("folder24.png"); 30 EDIT16 = getImage("edit16.png"); 31 FILE16 = getImage("file16.png"); 32 RUN_PASS = getImage("runpass.png"); 33 RUN_FAIL = getImage("runfail.png"); 34 TESTSUITE = getImage("testsuite.png"); 35 TESTGROUP = getImage("testgroup.png"); 36 TESTGROUPX = getImage("testgroupx.png"); 37 NEXT = getImage("next24.png"); 38 } 39 getImage(String name)40 private ImageIcon getImage(String name) { 41 name = IMG_DIR + name; 42 try { 43 final ClassLoader loader = ImageFactory.class.getClassLoader(); 44 final InputStream in = loader.getResourceAsStream(name); 45 final byte[] data = new byte[in.available()]; 46 in.read(data); 47 in.close(); 48 return new ImageIcon(data); 49 } catch (IOException ex) { 50 System.err.println("Can't load image file: " + name); 51 System.exit(1); 52 } catch(RuntimeException e) { 53 System.err.println("Can't load image file: " + name); 54 System.exit(1); 55 } 56 return null; 57 } 58 59 private static final String IMG_DIR = "org/antlr/gunit/swingui/images/"; 60 61 public ImageIcon ACCEPT; 62 public ImageIcon ADD; 63 public ImageIcon DELETE; 64 public ImageIcon TEXTFILE ; 65 public ImageIcon ADDFILE; 66 67 public ImageIcon TEXTFILE16 ; 68 public ImageIcon WINDOW16; 69 public ImageIcon FAV16; 70 public ImageIcon SAVE ; 71 72 public ImageIcon OPEN ; 73 public ImageIcon EDIT16; 74 public ImageIcon FILE16; 75 public ImageIcon NEXT; 76 77 public ImageIcon RUN_PASS; 78 public ImageIcon RUN_FAIL; 79 public ImageIcon TESTSUITE; 80 public ImageIcon TESTGROUP ; 81 public ImageIcon TESTGROUPX; 82 83 } 84