1 package net.suberic.pooka.gui; 2 import net.suberic.pooka.Pooka; 3 import net.suberic.util.gui.IconManager; 4 import javax.swing.*; 5 import java.util.HashMap ; 6 import java.util.MissingResourceException ; 7 import java.awt.Component ; 8 9 public class BooleanIcon implements TableCellIcon { 10 public boolean bool; 11 public String iconProperty; 12 public static HashMap labelTable = new HashMap (); 13 protected static Component blankImage = new JLabel(); 14 String mIconId = ""; 15 16 public BooleanIcon(boolean boolValue, String newIconFile, String pId) { 17 bool=boolValue; 18 iconProperty = newIconFile; 19 ((JLabel)blankImage).setOpaque(true); 20 mIconId = pId; 21 } 22 23 28 public Component getIcon() { 29 if (bool) { 30 return getIcon(iconProperty); 31 } else 32 return blankImage; 33 } 34 35 public Component getIcon(String imageKey) { 36 37 if (labelTable.containsKey(imageKey)) 38 return (Component )labelTable.get(imageKey); 39 else 40 return loadImage(imageKey); 41 } 42 43 46 public Component loadImage(String imageKey) { 47 Component returnValue = null; 48 IconManager iconManager = Pooka.getUIFactory().getIconManager(); 49 ImageIcon icon = iconManager.getIcon(imageKey); 50 if (icon != null) { 51 returnValue = new JLabel(icon); 52 ((JLabel)returnValue).setOpaque(true); 53 labelTable.put(imageKey, returnValue); 54 } else { 55 returnValue = null; 56 } 57 58 return returnValue; 59 } 60 61 public int compareTo(Object o) { 62 if (o instanceof BooleanIcon) { 63 boolean oValue = ((BooleanIcon)o).bool; 64 if (bool == oValue) 65 return 0; 66 else if (bool == true) 67 return 1; 68 else 69 return -1; 70 } 71 throw new ClassCastException ("object is not a BooleanIcon."); 72 } 73 74 public String toString() { 75 return ""; 76 } 77 78 81 public String getIconId() { 82 return mIconId; 83 } 84 85 88 public boolean iconValue() { 89 return bool; 90 } 91 92 } 93 | Popular Tags |