1 30 31 package com.jgoodies.looks.windows; 32 33 import java.awt.Component ; 34 import java.awt.Graphics ; 35 import java.io.Serializable ; 36 37 import javax.swing.AbstractButton ; 38 import javax.swing.ButtonModel ; 39 import javax.swing.Icon ; 40 import javax.swing.JCheckBox ; 41 import javax.swing.UIManager ; 42 import javax.swing.plaf.UIResource ; 43 44 50 final class WindowsIconFactory { 51 52 53 55 private static Icon checkBoxIcon; 56 private static Icon radioButtonIcon; 57 58 59 62 static Icon getCheckBoxIcon() { 63 if (checkBoxIcon == null) { 64 checkBoxIcon = new CheckBoxIcon(); 65 } 66 return checkBoxIcon; 67 } 68 69 70 73 static Icon getRadioButtonIcon() { 74 if (radioButtonIcon == null) { 75 radioButtonIcon = new RadioButtonIcon(); 76 } 77 return radioButtonIcon; 78 } 79 80 81 83 private static class CheckBoxIcon implements Icon , Serializable { 85 86 private static final int SIZE = 13; 87 88 public void paintIcon(Component c, Graphics g, int x, int y) { 89 JCheckBox cb = (JCheckBox ) c; 90 ButtonModel model = cb.getModel(); 91 92 if(!cb.isBorderPaintedFlat()) { 94 g.setColor(UIManager.getColor("CheckBox.shadow")); 96 g.drawLine(x, y, x+11, y); 97 g.drawLine(x, y+1, x, y+11); 98 99 g.setColor(UIManager.getColor("CheckBox.highlight")); 101 g.drawLine(x+12, y, x+12, y+12); 102 g.drawLine(x, y+12, x+11, y+12); 103 104 g.setColor(UIManager.getColor("CheckBox.darkShadow")); 106 g.drawLine(x+1, y+1, x+10, y+1); 107 g.drawLine(x+1, y+2, x+1, y+10); 108 109 g.setColor(UIManager.getColor("CheckBox.light")); 111 g.drawLine(x+1, y+11, x+11, y+11); 112 g.drawLine(x+11, y+1, x+11, y+10); 113 114 } else { 115 g.setColor(UIManager.getColor("CheckBox.shadow")); 116 g.drawRect(x+1, y+1, SIZE-3, SIZE-3); 117 } 118 g.setColor(UIManager.getColor( 120 (model.isPressed() && model.isArmed()) || !model.isEnabled() 121 ? "CheckBox.background" 122 : "CheckBox.interiorBackground")); 123 g.fillRect(x+2, y+2, SIZE-4, SIZE-4); 124 125 g.setColor(UIManager.getColor(model.isEnabled() 126 ? "CheckBox.checkColor" : "CheckBox.shadow")); 128 129 if (model.isSelected()) { 131 g.drawLine(x+9, y+3, x+9, y+3); 132 g.drawLine(x+8, y+4, x+9, y+4); 133 g.drawLine(x+7, y+5, x+9, y+5); 134 g.drawLine(x+6, y+6, x+8, y+6); 135 g.drawLine(x+3, y+7, x+7, y+7); 136 g.drawLine(x+4, y+8, x+6, y+8); 137 g.drawLine(x+5, y+9, x+5, y+9); 138 g.drawLine(x+3, y+5, x+3, y+5); 139 g.drawLine(x+3, y+6, x+4, y+6); 140 } 141 } 142 143 public int getIconWidth() { return SIZE; } 144 public int getIconHeight() { return SIZE; } 145 } 146 147 148 private static class RadioButtonIcon implements Icon , UIResource , Serializable { 150 151 private static final int SIZE = 13; 152 153 public void paintIcon(Component c, Graphics g, int x, int y) { 154 AbstractButton b = (AbstractButton ) c; 155 ButtonModel model = b.getModel(); 156 157 g.setColor(UIManager.getColor( 159 (model.isPressed() && model.isArmed()) || !model.isEnabled() 160 ? "RadioButton.background" 161 : "RadioButton.interiorBackground")); 162 g.fillRect(x+2, y+2, 8, 8); 163 164 165 g.setColor(UIManager.getColor("RadioButton.shadow")); 167 g.drawLine(x+4, y+0, x+7, y+0); 168 g.drawLine(x+2, y+1, x+3, y+1); 169 g.drawLine(x+8, y+1, x+9, y+1); 170 g.drawLine(x+1, y+2, x+1, y+3); 171 g.drawLine(x+0, y+4, x+0, y+7); 172 g.drawLine(x+1, y+8, x+1, y+9); 173 174 g.setColor(UIManager.getColor("RadioButton.highlight")); 176 g.drawLine(x+2, y+10, x+3, y+10); 177 g.drawLine(x+4, y+11, x+7, y+11); 178 g.drawLine(x+8, y+10, x+9, y+10); 179 g.drawLine(x+10, y+9, x+10, y+8); 180 g.drawLine(x+11, y+7, x+11, y+4); 181 g.drawLine(x+10, y+3, x+10, y+2); 182 183 184 g.setColor(UIManager.getColor("RadioButton.darkShadow")); 186 g.drawLine(x+4, y+1, x+7, y+1); 187 g.drawLine(x+2, y+2, x+3, y+2); 188 g.drawLine(x+8, y+2, x+9, y+2); 189 g.drawLine(x+2, y+3, x+2, y+3); 190 g.drawLine(x+1, y+4, x+1, y+7); 191 g.drawLine(x+2, y+8, x+2, y+8); 192 193 194 g.setColor(UIManager.getColor("RadioButton.light")); 196 g.drawLine(x+2, y+9, x+3, y+9); 197 g.drawLine(x+4, y+10, x+7, y+10); 198 g.drawLine(x+8, y+9, x+9, y+9); 199 g.drawLine(x+9, y+8, x+9, y+8); 200 g.drawLine(x+10, y+7, x+10, y+4); 201 g.drawLine(x+9, y+3, x+9, y+3); 202 203 204 if(model.isSelected()) { 206 g.setColor(UIManager.getColor("RadioButton.checkColor")); g.fillRect(x+4, y+5, 4, 2); 208 g.fillRect(x+5, y+4, 2, 4); 209 } 210 } 211 212 public int getIconWidth() { return SIZE; } 213 public int getIconHeight() { return SIZE; } 214 215 } 216 217 } | Popular Tags |