001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.modules.form.fakepeer;
043:
044: import java.awt.*;
045:
046: /**
047: *
048: * @author Tran Duc Trung
049: */
050: class FakeTextComponentPeer extends FakeComponentPeer {
051: private String _text;
052: private int _caretPosition = 0;
053: private int selStart = -1;
054: private int selEnd = -1;
055:
056: FakeTextComponentPeer(TextComponent target) {
057: super (target);
058: }
059:
060: Component createDelegate() {
061: return new Delegate();
062: }
063:
064: @Override
065: void initDelegate() {
066: _text = ((TextComponent) _target).getText();
067: super .initDelegate();
068: }
069:
070: @Override
071: public boolean isFocusTraversable() {
072: return true;
073: }
074:
075: public void setEditable(boolean editable) {
076: repaint();
077: }
078:
079: public String getText() {
080: return _text;
081: }
082:
083: public void setText(String text) {
084: _text = text;
085: repaint();
086: }
087:
088: public int getSelectionStart() {
089: return selStart;
090: }
091:
092: public int getSelectionEnd() {
093: return selEnd;
094: }
095:
096: public void select(int selStart, int selEnd) {
097: this .selStart = selStart;
098: this .selEnd = selEnd;
099: }
100:
101: public void setCaretPosition(int pos) {
102: if (pos == 0 || (_text != null && _text.length() > pos))
103: _caretPosition = pos;
104: }
105:
106: public int getCaretPosition() {
107: return _caretPosition;
108: }
109:
110: // JDK 1.3
111: public int getIndexAtPoint(int x, int y) {
112: return 0;
113: }
114:
115: // JDK 1.3
116: public Rectangle getCharacterBounds(int i) {
117: return null;
118: }
119:
120: // JDK 1.3
121: public long filterEvents(long mask) {
122: return 0;
123: }
124:
125: // JDK 1.5
126: public java.awt.im.InputMethodRequests getInputMethodRequests() {
127: return null;
128: }
129:
130: //
131: //
132: //
133:
134: protected class Delegate extends Component {
135: Delegate() {
136: this .setBackground(SystemColor.window);
137: this .setForeground(SystemColor.windowText);
138: }
139:
140: @Override
141: public void paint(Graphics g) {
142: Dimension sz = _target.getSize();
143: int w = sz.width;
144: int h = sz.height;
145:
146: g.setColor(_target.getBackground());
147: FakePeerUtils.drawLoweredBox(g, 0, 0, w, h);
148:
149: Rectangle r = g.getClipBounds();
150: if (r.x < 1)
151: r.x = 1;
152: if (r.y < 1)
153: r.y = 1;
154: if (r.width > w - 3)
155: r.width = w - 3;
156: if (r.height > h - 3)
157: r.height = h - 3;
158: g.setClip(r);
159: // g.setClip(1,1,w-3,h-3);
160:
161: if (_target.isEnabled()) {
162: g.setColor(_target.getForeground());
163: } else {
164: g.setColor(SystemColor.controlShadow);
165: }
166: }
167: }
168: }
|