1 7 8 package javax.swing.plaf.basic; 9 10 import javax.swing.*; 11 import javax.swing.plaf.UIResource ; 12 13 import java.awt.Graphics ; 14 import java.awt.Color ; 15 import java.awt.Component ; 16 import java.awt.Polygon ; 17 import java.io.Serializable ; 18 19 35 public class BasicIconFactory implements Serializable 36 { 37 private static Icon frame_icon; 38 private static Icon checkBoxIcon; 39 private static Icon radioButtonIcon; 40 private static Icon checkBoxMenuItemIcon; 41 private static Icon radioButtonMenuItemIcon; 42 private static Icon menuItemCheckIcon; 43 private static Icon menuItemArrowIcon; 44 private static Icon menuArrowIcon; 45 46 public static Icon getMenuItemCheckIcon() { 47 if (menuItemCheckIcon == null) { 48 menuItemCheckIcon = new MenuItemCheckIcon(); 49 } 50 return menuItemCheckIcon; 51 } 52 53 public static Icon getMenuItemArrowIcon() { 54 if (menuItemArrowIcon == null) { 55 menuItemArrowIcon = new MenuItemArrowIcon(); 56 } 57 return menuItemArrowIcon; 58 } 59 60 public static Icon getMenuArrowIcon() { 61 if (menuArrowIcon == null) { 62 menuArrowIcon = new MenuArrowIcon(); 63 } 64 return menuArrowIcon; 65 } 66 67 public static Icon getCheckBoxIcon() { 68 if (checkBoxIcon == null) { 69 checkBoxIcon = new CheckBoxIcon(); 70 } 71 return checkBoxIcon; 72 } 73 74 public static Icon getRadioButtonIcon() { 75 if (radioButtonIcon == null) { 76 radioButtonIcon = new RadioButtonIcon(); 77 } 78 return radioButtonIcon; 79 } 80 81 public static Icon getCheckBoxMenuItemIcon() { 82 if (checkBoxMenuItemIcon == null) { 83 checkBoxMenuItemIcon = new CheckBoxMenuItemIcon(); 84 } 85 return checkBoxMenuItemIcon; 86 } 87 88 public static Icon getRadioButtonMenuItemIcon() { 89 if (radioButtonMenuItemIcon == null) { 90 radioButtonMenuItemIcon = new RadioButtonMenuItemIcon(); 91 } 92 return radioButtonMenuItemIcon; 93 } 94 95 public static Icon createEmptyFrameIcon() { 96 if(frame_icon == null) 97 frame_icon = new EmptyFrameIcon(); 98 return frame_icon; 99 } 100 101 private static class EmptyFrameIcon implements Icon, Serializable { 102 int height = 16; 103 int width = 14; 104 public void paintIcon(Component c, Graphics g, int x, int y) { 105 } 106 public int getIconWidth() { return width; } 107 public int getIconHeight() { return height; } 108 }; 109 110 private static class CheckBoxIcon implements Icon, Serializable 111 { 112 final static int csize = 13; 113 public void paintIcon(Component c, Graphics g, int x, int y) { 114 } 115 116 public int getIconWidth() { 117 return csize; 118 } 119 120 public int getIconHeight() { 121 return csize; 122 } 123 } 124 125 private static class RadioButtonIcon implements Icon, UIResource , Serializable 126 { 127 public void paintIcon(Component c, Graphics g, int x, int y) { 128 } 129 130 public int getIconWidth() { 131 return 13; 132 } 133 134 public int getIconHeight() { 135 return 13; 136 } 137 } 139 140 private static class CheckBoxMenuItemIcon implements Icon, UIResource , Serializable 141 { 142 public void paintIcon(Component c, Graphics g, int x, int y) { 143 AbstractButton b = (AbstractButton) c; 144 ButtonModel model = b.getModel(); 145 boolean isSelected = model.isSelected(); 146 if (isSelected) { 147 g.drawLine(x+7, y+1, x+7, y+3); 148 g.drawLine(x+6, y+2, x+6, y+4); 149 g.drawLine(x+5, y+3, x+5, y+5); 150 g.drawLine(x+4, y+4, x+4, y+6); 151 g.drawLine(x+3, y+5, x+3, y+7); 152 g.drawLine(x+2, y+4, x+2, y+6); 153 g.drawLine(x+1, y+3, x+1, y+5); 154 } 155 } 156 public int getIconWidth() { return 9; } 157 public int getIconHeight() { return 9; } 158 159 } 161 162 private static class RadioButtonMenuItemIcon implements Icon, UIResource , Serializable 163 { 164 public void paintIcon(Component c, Graphics g, int x, int y) { 165 AbstractButton b = (AbstractButton) c; 166 ButtonModel model = b.getModel(); 167 if (b.isSelected() == true) { 168 g.fillOval(x+1, y+1, getIconWidth(), getIconHeight()); 169 } 170 } 171 public int getIconWidth() { return 6; } 172 public int getIconHeight() { return 6; } 173 174 } 176 177 private static class MenuItemCheckIcon implements Icon, UIResource , Serializable { 178 public void paintIcon(Component c, Graphics g, int x, int y) { 179 } 180 public int getIconWidth() { return 9; } 181 public int getIconHeight() { return 9; } 182 183 } 185 private static class MenuItemArrowIcon implements Icon, UIResource , Serializable { 186 public void paintIcon(Component c, Graphics g, int x, int y) { 187 } 188 public int getIconWidth() { return 4; } 189 public int getIconHeight() { return 8; } 190 191 } 193 private static class MenuArrowIcon implements Icon, UIResource , Serializable { 194 public void paintIcon(Component c, Graphics g, int x, int y) { 195 Polygon p = new Polygon (); 196 p.addPoint(x, y); 197 p.addPoint(x+getIconWidth(), y+getIconHeight()/2); 198 p.addPoint(x, y+getIconHeight()); 199 g.fillPolygon(p); 200 201 } 202 public int getIconWidth() { return 4; } 203 public int getIconHeight() { return 8; } 204 } } 206 207 | Popular Tags |