1 19 20 21 package org.netbeans.modules.form.fakepeer; 22 23 import java.awt.*; 24 25 29 class FakeTextFieldPeer extends FakeTextComponentPeer 30 { 31 FakeTextFieldPeer(TextField target) { 32 super(target); 33 } 34 35 Component createDelegate() { 36 return new Delegate(); 37 } 38 39 public void setEchoChar(char echoChar) { 40 } 41 42 public Dimension getPreferredSize(int columns) { 43 return _delegate.getMinimumSize(); } 45 46 public Dimension getMinimumSize(int columns) { 47 return _delegate.getMinimumSize(); } 49 50 public void setEchoCharacter(char c) { 51 setEchoChar(c); 52 } 53 54 public Dimension preferredSize(int cols) { 55 return getPreferredSize(cols); 56 } 57 58 public Dimension minimumSize(int cols) { 59 return getMinimumSize(cols); 60 } 61 62 66 private class Delegate extends FakeTextComponentPeer.Delegate 67 { 68 public void paint(Graphics g) { 69 super.paint(g); 70 71 TextField target =(TextField) _target; 72 String text = target.getText(); 73 74 if (text != null) { String textOut = text.substring(target.getCaretPosition()); 76 g.setFont(target.getFont()); 78 79 FontMetrics fm = g.getFontMetrics(); 80 int h = fm.getHeight() - fm.getDescent(); 81 g.drawString(textOut, 4, 1 + h); } 83 } 84 85 public Dimension getMinimumSize() { 86 String text = ((TextField)_target).getText(); 87 88 FontMetrics fm = this.getFontMetrics(this.getFont()); 89 int w = fm.stringWidth(text); 90 int h = fm.getHeight(); 91 92 return new Dimension(w > 92 ? 100 : w+8, h + 4); 93 } 94 } 95 } 96 | Popular Tags |