1 19 20 21 package org.netbeans.modules.form.fakepeer; 22 23 import java.awt.*; 24 25 29 class FakeCheckboxPeer extends FakeComponentPeer 30 { 31 FakeCheckboxPeer(Checkbox target) { 32 super(target); 33 } 34 35 Component createDelegate() { 36 return new Delegate(); 37 } 38 39 public void setState(boolean state) { 40 } 41 42 public void setCheckboxGroup(CheckboxGroup g) { 43 } 44 45 public void setLabel(String label) { 46 } 47 48 52 private class Delegate extends Component 53 { 54 Delegate() { 55 this.setForeground(SystemColor.controlText); 57 } 58 59 public void paint(Graphics g) { 60 Checkbox target = (Checkbox) _target; 61 Dimension sz = target.getSize(); 62 int bx = 0; 63 int by = (sz.height - BOX_H) / 2; 64 65 g.setColor(target.getBackground()); 66 g.fillRect(0, 0, sz.width, sz.height); 67 68 String label = target.getLabel(); 69 70 if (label != null) { 71 g.setFont(target.getFont()); 72 73 FontMetrics fm = g.getFontMetrics(); 74 int h = fm.getHeight() - fm.getDescent(), 75 x = 18, 76 y = (sz.height - h) / 2 + h - 2; 77 78 if (target.isEnabled()) { 79 g.setColor(target.getForeground()); 80 } 81 else { 82 g.setColor(SystemColor.controlLtHighlight); 83 g.drawString(label, x+1, y+1); 84 g.setColor(SystemColor.controlShadow); 85 } 86 87 g.drawString(label, x, y); 88 by = y - h + 2; 89 } 90 91 93 if (target.getCheckboxGroup() == null) { 94 g.setColor(SystemColor.window); 95 FakePeerUtils.drawLoweredBox(g,bx,by,BOX_W,BOX_H); 96 97 if (target.getState()) { g.setColor(SystemColor.controlText); 99 for (int i=1; i < drCheckPosX_W.length; i++) 100 g.drawLine(drCheckPosX_W[i-1]+bx,drCheckPosY_W[i-1]+by, 101 drCheckPosX_W[i]+bx,drCheckPosY_W[i]+by); 102 } 103 } 104 else { if (radButtIcon1 == null || radButtIcon2 == null) 106 initRBImages(); 107 g.drawImage(target.getState() ? radButtIcon2:radButtIcon1, bx+1, by+1, this); 108 } 109 } 110 111 public Dimension getMinimumSize() { 112 String label = ((Checkbox)_target).getLabel(); 113 114 FontMetrics fm = this.getFontMetrics(this.getFont()); 115 int w = fm.stringWidth(label); 116 int h = fm.getHeight(); 117 118 return new Dimension(w + 6+BOX_W+4, h + 4); 119 } 120 121 void initRBImages() { 122 Toolkit toolkit = Toolkit.getDefaultToolkit(); 123 java.net.URL source = this.getClass().getResource("radbutt1.gif"); 124 radButtIcon1 = toolkit.getImage(source); 125 source = this.getClass().getResource("radbutt2.gif"); 126 radButtIcon2 = toolkit.getImage(source); 127 128 MediaTracker mt = new MediaTracker(this); 129 mt.addImage(radButtIcon1,0); 130 mt.addImage(radButtIcon2,1); 131 try { 132 mt.waitForAll(); 133 } catch (java.lang.InterruptedException e) { 134 } 135 } 136 } 137 138 private static final int BOX_W = 16, BOX_H = 16; 139 private static final int[] drCheckPosX_W = { 4,6,10,10,6,4,4,6,10 }; 140 private static final int[] drCheckPosY_W = { 6,8,4,5,9,7,8,10,6 }; 141 142 private static Image radButtIcon1 = null; 143 private static Image radButtIcon2 = null; 144 } 145 | Popular Tags |