1 19 20 21 package org.netbeans.modules.form.fakepeer; 22 23 import java.awt.*; 24 25 29 class FakeChoicePeer extends FakeComponentPeer 30 { 31 FakeChoicePeer(Choice target) { 32 super(target); 33 } 34 35 Component createDelegate() { 36 return new Delegate(); 37 } 38 39 public void add(String item, int index) { 40 } 41 42 public void remove(int index) { 43 } 44 45 public void removeAll() { 47 } 48 49 public void select(int index) { 50 } 51 52 public void addItem(String item, int index) { 53 add(item, index); 54 } 55 56 60 private class Delegate extends Component 61 { 62 Delegate() { 63 this.setBackground(SystemColor.window); 64 this.setForeground(SystemColor.controlText); 65 } 66 67 public void paint(Graphics g) { 68 Choice target =(Choice) _target; 69 Dimension sz = target.getSize(); 70 71 FontMetrics fm = g.getFontMetrics(); 72 int w = sz.width, 73 h = sz.height, 74 fh = fm.getHeight(), comph = h > fh+4 ? fh+4 : h, y = (h-comph)/2; 78 g.setColor(target.getBackground()); 79 FakePeerUtils.drawLoweredBox(g, 0,y,w,comph); 80 81 String item = target.getSelectedItem(); 82 if (item != null) { 83 if (target.isEnabled()) { 84 g.setColor(target.getForeground()); 85 } 86 else { 87 g.setColor(SystemColor.controlShadow); 88 } 89 g.setFont(target.getFont()); 90 91 g.setClip(2,y+2,w-4,comph-4); 92 int ih = fh - fm.getDescent(), iy = y + 1 + ih; 94 95 g.drawString(item, 4, iy); 96 } 97 98 FakePeerUtils.drawArrowButton( 100 g, w-BUT_W-2, y+2, BUT_W, comph-4, 4, target.isEnabled()); 101 } 102 103 public Dimension getMinimumSize() { 104 String label = ((Choice)_target).getSelectedItem(); 105 106 FontMetrics fm = this.getFontMetrics(this.getFont()); 107 int w = label != null ? fm.stringWidth(label)+5 : 8, 108 h = fm.getHeight(); 109 110 return new Dimension(w + 4 + BUT_W, h + 4); 111 } 112 } 113 114 private static final int BUT_W = 16, BUT_H = 16; 115 } 116 | Popular Tags |