1 7 8 package javax.swing.plaf.metal; 9 10 import javax.swing.*; 11 12 import java.awt.*; 13 import java.awt.event.*; 14 import java.io.*; 15 import javax.swing.plaf.*; 16 17 32 public class MetalCheckBoxIcon implements Icon, UIResource, Serializable { 33 34 protected int getControlSize() { return 13; } 35 36 public void paintIcon(Component c, Graphics g, int x, int y) { 37 38 JCheckBox cb = (JCheckBox)c; 39 ButtonModel model = cb.getModel(); 40 int controlSize = getControlSize(); 41 42 boolean drawCheck = model.isSelected(); 43 44 if (model.isEnabled()) { 45 if(cb.isBorderPaintedFlat()) { 46 g.setColor(MetalLookAndFeel.getControlDarkShadow()); 47 g.drawRect(x+1, y, controlSize-1, controlSize-1); 48 } 49 if (model.isPressed() && model.isArmed()) { 50 if(cb.isBorderPaintedFlat()) { 51 g.setColor(MetalLookAndFeel.getControlShadow()); 52 g.fillRect(x+2, y+1, controlSize-2, controlSize-2); 53 } else { 54 g.setColor(MetalLookAndFeel.getControlShadow()); 55 g.fillRect(x, y, controlSize-1, controlSize-1); 56 MetalUtils.drawPressed3DBorder(g, x, y, controlSize, controlSize); 57 } 58 } else if(!cb.isBorderPaintedFlat()) { 59 MetalUtils.drawFlush3DBorder(g, x, y, controlSize, controlSize); 60 } 61 g.setColor( MetalLookAndFeel.getControlInfo() ); 62 } else { 63 g.setColor( MetalLookAndFeel.getControlShadow() ); 64 g.drawRect( x, y, controlSize-1, controlSize-1); 65 } 66 67 68 if(drawCheck) { 69 if (cb.isBorderPaintedFlat()) { 70 x++; 71 } 72 drawCheck(c,g,x,y); 73 } 74 } 75 76 protected void drawCheck(Component c, Graphics g, int x, int y) { 77 int controlSize = getControlSize(); 78 g.fillRect( x+3, y+5, 2, controlSize-8 ); 79 g.drawLine( x+(controlSize-4), y+3, x+5, y+(controlSize-6) ); 80 g.drawLine( x+(controlSize-4), y+4, x+5, y+(controlSize-5) ); 81 } 82 83 public int getIconWidth() { 84 return getControlSize(); 85 } 86 87 public int getIconHeight() { 88 return getControlSize(); 89 } 90 } 91 | Popular Tags |