1 19 20 21 package org.netbeans.modules.form.fakepeer; 22 23 import java.awt.*; 24 25 29 class FakeLabelPeer extends FakeComponentPeer 30 { 31 FakeLabelPeer(Label target) { 32 super(target); 33 } 34 35 Component createDelegate() { 36 return new Delegate(); 37 } 38 39 public void setText(String label) { 40 } 41 42 public void setAlignment(int alignment) { 43 } 44 45 49 private class Delegate extends Component 50 { 51 Delegate() { 52 this.setForeground(SystemColor.controlText); 54 } 55 56 public void paint(Graphics g) { 57 Label target = (Label) _target; 58 59 Dimension sz = target.getSize(); 60 g.setColor(target.getBackground()); 61 g.fillRect(0, 0, sz.width, sz.height); 62 63 String label = target.getText(); 64 if (label == null) 65 return; 66 67 g.setFont(target.getFont()); 68 69 FontMetrics fm = g.getFontMetrics(); 70 int w = fm.stringWidth(label), 71 h = fm.getHeight() - fm.getDescent(), 72 x = 0, 73 y = (sz.height - h) / 2 + h - 2, 74 alignment = target.getAlignment(); 75 76 if (alignment == Label.RIGHT) 77 x = sz.width - w; 78 else if (alignment == Label.CENTER) 79 x =(sz.width - w) / 2; 80 81 if (target.isEnabled()) { 82 g.setColor(target.getForeground()); 83 } 84 else { 85 g.setColor(SystemColor.controlLtHighlight); 86 g.drawString(label, x+1, y+1); 87 g.setColor(SystemColor.controlShadow); 88 } 89 90 g.drawString(label, x, y); 91 } 92 93 public Dimension getMinimumSize() { 94 String label = ((Label)_target).getText(); 95 96 FontMetrics fm = this.getFontMetrics(this.getFont()); 97 int w = fm.stringWidth(label); 98 int h = fm.getHeight(); 99 100 return new Dimension(w + 4, h + 4); 101 } 102 } 103 } 104 | Popular Tags |