1 19 20 21 package org.netbeans.modules.form.fakepeer; 22 23 import java.awt.*; 24 25 29 class FakeTextComponentPeer extends FakeComponentPeer 30 { 31 private String _text; 32 private int _caretPosition = 0; 33 private int selStart = -1; 34 private int selEnd = -1; 35 36 FakeTextComponentPeer(TextComponent target) { 37 super(target); 38 } 39 40 Component createDelegate() { 41 return new Delegate(); 42 } 43 44 void initDelegate() { 45 _text = ((TextComponent)_target).getText(); 46 super.initDelegate(); 47 } 48 49 public boolean isFocusTraversable() { 50 return true; 51 } 52 53 public void setEditable(boolean editable) { 54 repaint(); 55 } 56 57 public String getText() { 58 return _text; 59 } 60 61 public void setText(String text) { 62 _text = text; 63 repaint(); 64 } 65 66 public int getSelectionStart() { 67 return selStart; 68 } 69 70 public int getSelectionEnd() { 71 return selEnd; 72 } 73 74 public void select(int selStart, int selEnd) { 75 this.selStart = selStart; 76 this.selEnd = selEnd; 77 } 78 79 public void setCaretPosition(int pos) { 80 if (pos == 0 || (_text != null && _text.length() > pos)) 81 _caretPosition = pos; 82 } 83 84 public int getCaretPosition() { 85 return _caretPosition; 86 } 87 88 public int getIndexAtPoint(int x, int y) { 90 return 0; 91 } 92 93 public Rectangle getCharacterBounds(int i) { 95 return null; 96 } 97 98 public long filterEvents(long mask) { 100 return 0; 101 } 102 103 public java.awt.im.InputMethodRequests getInputMethodRequests() { 105 return null; 106 } 107 108 112 protected class Delegate extends Component 113 { 114 Delegate() { 115 this.setBackground(SystemColor.window); 116 this.setForeground(SystemColor.windowText); 117 } 118 119 public void paint(Graphics g) { 120 Dimension sz = _target.getSize(); 121 int w = sz.width; 122 int h = sz.height; 123 124 g.setColor(_target.getBackground()); 125 FakePeerUtils.drawLoweredBox(g,0,0,w,h); 126 127 Rectangle r = g.getClipBounds(); 128 if (r.x < 1) r.x = 1; 129 if (r.y < 1) r.y = 1; 130 if (r.width > w-3) r.width = w - 3; 131 if (r.height > h-3) r.height = h - 3; 132 g.setClip(r); 133 135 if (_target.isEnabled()) { 136 g.setColor(_target.getForeground()); 137 } 138 else { 139 g.setColor(SystemColor.controlShadow); 140 } 141 } 142 } 143 } 144 | Popular Tags |