KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > form > fakepeer > FakeTextComponentPeer


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.form.fakepeer;
22
23 import java.awt.*;
24
25 /**
26  *
27  * @author Tran Duc Trung
28  */

29 class FakeTextComponentPeer extends FakeComponentPeer
30 {
31     private String JavaDoc _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 JavaDoc getText() {
58         return _text;
59     }
60
61     public void setText(String JavaDoc 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     // JDK 1.3
89
public int getIndexAtPoint(int x, int y) {
90         return 0;
91     }
92
93     // JDK 1.3
94
public Rectangle getCharacterBounds(int i) {
95         return null;
96     }
97
98     // JDK 1.3
99
public long filterEvents(long mask) {
100         return 0;
101     }
102
103     // JDK 1.5
104
public java.awt.im.InputMethodRequests JavaDoc getInputMethodRequests() {
105         return null;
106     }
107
108     //
109
//
110
//
111

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 // g.setClip(1,1,w-3,h-3);
134

135             if (_target.isEnabled()) {
136                 g.setColor(_target.getForeground());
137             }
138             else {
139                 g.setColor(SystemColor.controlShadow);
140             }
141         }
142     }
143 }
144
Popular Tags