author | martin |
Thu, 30 Oct 2014 07:31:41 -0700 | |
changeset 28059 | e576535359cc |
parent 25859 | 3317bb8137f4 |
child 28236 | 610561ed1847 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
23647 | 2 |
* Copyright (c) 2003, 2014, Oracle and/or its affiliates. All rights reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
5506 | 7 |
* published by the Free Software Foundation. Oracle designates this |
2 | 8 |
* particular file as subject to the "Classpath" exception as provided |
5506 | 9 |
* by Oracle in the LICENSE file that accompanied this code. |
2 | 10 |
* |
11 |
* This code is distributed in the hope that it will be useful, but WITHOUT |
|
12 |
* ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or |
|
13 |
* FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License |
|
14 |
* version 2 for more details (a copy is included in the LICENSE file that |
|
15 |
* accompanied this code). |
|
16 |
* |
|
17 |
* You should have received a copy of the GNU General Public License version |
|
18 |
* 2 along with this work; if not, write to the Free Software Foundation, |
|
19 |
* Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA. |
|
20 |
* |
|
5506 | 21 |
* Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA |
22 |
* or visit www.oracle.com if you need additional information or have any |
|
23 |
* questions. |
|
2 | 24 |
*/ |
25 |
||
26 |
package sun.awt.X11; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.peer.*; |
|
30 |
import java.awt.event.*; |
|
31 |
import java.awt.event.ActionEvent; |
|
32 |
import java.awt.event.ActionListener; |
|
33 |
import java.awt.event.TextEvent; |
|
34 |
import javax.swing.text.*; |
|
35 |
import javax.swing.event.DocumentListener; |
|
36 |
import javax.swing.event.DocumentEvent; |
|
37 |
import javax.swing.plaf.ComponentUI; |
|
38 |
import javax.swing.InputMap; |
|
39 |
import javax.swing.JPasswordField; |
|
40 |
import javax.swing.SwingUtilities; |
|
41 |
import javax.swing.TransferHandler; |
|
42 |
||
43 |
import java.awt.event.MouseEvent; |
|
44 |
import java.awt.event.FocusEvent; |
|
45 |
import java.awt.event.KeyEvent; |
|
46 |
||
47 |
import javax.swing.plaf.UIResource; |
|
48 |
import javax.swing.UIDefaults; |
|
49 |
import javax.swing.JTextField; |
|
50 |
import javax.swing.JComponent; |
|
51 |
import javax.swing.border.Border; |
|
52 |
import com.sun.java.swing.plaf.motif.*; |
|
53 |
import java.awt.im.InputMethodRequests; |
|
54 |
||
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
55 |
import sun.util.logging.PlatformLogger; |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
56 |
|
2 | 57 |
import sun.awt.CausedFocusEvent; |
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
58 |
import sun.awt.AWTAccessor; |
2 | 59 |
|
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
60 |
final class XTextFieldPeer extends XComponentPeer implements TextFieldPeer { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2
diff
changeset
|
61 |
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XTextField"); |
2 | 62 |
|
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
63 |
private String text; |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
64 |
private final XAWTTextField xtext; |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
65 |
private final boolean firstChangeSkipped; |
2 | 66 |
|
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
67 |
XTextFieldPeer(TextField target) { |
2 | 68 |
super(target); |
69 |
text = target.getText(); |
|
70 |
xtext = new XAWTTextField(text,this, target.getParent()); |
|
71 |
xtext.getDocument().addDocumentListener(xtext); |
|
72 |
xtext.setCursor(target.getCursor()); |
|
73 |
XToolkit.specialPeerMap.put(xtext,this); |
|
74 |
||
75 |
initTextField(); |
|
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
76 |
setText(target.getText()); |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
77 |
if (target.echoCharIsSet()) { |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
78 |
setEchoChar(target.getEchoChar()); |
2 | 79 |
} |
80 |
else setEchoChar((char)0); |
|
81 |
||
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
82 |
int start = target.getSelectionStart(); |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
83 |
int end = target.getSelectionEnd(); |
2 | 84 |
// Fix for 5100200 |
85 |
// Restoring Motif behaviour |
|
86 |
// Since the end position of the selected text can be greater then the length of the text, |
|
87 |
// so we should set caret to max position of the text |
|
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
88 |
setCaretPosition(Math.min(end, text.length())); |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
89 |
if (end > start) { |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
90 |
// Should be called after setText() and setCaretPosition() |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
91 |
select(start, end); |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
92 |
} |
2 | 93 |
|
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
94 |
setEditable(target.isEditable()); |
2 | 95 |
|
96 |
// After this line we should not change the component's text |
|
97 |
firstChangeSkipped = true; |
|
98 |
} |
|
99 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
100 |
@Override |
2 | 101 |
public void dispose() { |
102 |
XToolkit.specialPeerMap.remove(xtext); |
|
12285
37f0c586ba99
7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
11979
diff
changeset
|
103 |
// visible caret has a timer thread which must be stopped |
37f0c586ba99
7155298: Editable TextArea/TextField are blocking GUI applications from exit
zhouyx
parents:
11979
diff
changeset
|
104 |
xtext.getCaret().setVisible(false); |
2 | 105 |
xtext.removeNotify(); |
106 |
super.dispose(); |
|
107 |
} |
|
108 |
||
109 |
void initTextField() { |
|
110 |
setVisible(target.isVisible()); |
|
111 |
||
112 |
setBounds(x, y, width, height, SET_BOUNDS); |
|
113 |
||
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
114 |
AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
115 |
foreground = compAccessor.getForeground(target); |
2 | 116 |
if (foreground == null) |
117 |
foreground = SystemColor.textText; |
|
118 |
||
119 |
setForeground(foreground); |
|
120 |
||
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
121 |
background = compAccessor.getBackground(target); |
2 | 122 |
if (background == null) { |
123 |
if (((TextField)target).isEditable()) background = SystemColor.text; |
|
124 |
else background = SystemColor.control; |
|
125 |
} |
|
126 |
setBackground(background); |
|
127 |
||
128 |
if (!target.isBackgroundSet()) { |
|
129 |
// This is a way to set the background color of the TextArea |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
130 |
// without calling setBackground - go through accessor |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
131 |
compAccessor.setBackground(target, background); |
2 | 132 |
} |
133 |
if (!target.isForegroundSet()) { |
|
134 |
target.setForeground(SystemColor.textText); |
|
135 |
} |
|
136 |
||
137 |
setFont(font); |
|
138 |
} |
|
139 |
||
140 |
/** |
|
141 |
* @see java.awt.peer.TextComponentPeer |
|
142 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
143 |
@Override |
2 | 144 |
public void setEditable(boolean editable) { |
145 |
if (xtext != null) { |
|
146 |
xtext.setEditable(editable); |
|
147 |
xtext.repaint(); |
|
148 |
} |
|
149 |
} |
|
150 |
||
151 |
/** |
|
152 |
* @see java.awt.peer.ComponentPeer |
|
153 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
154 |
@Override |
2 | 155 |
public void setEnabled(boolean enabled) { |
156 |
super.setEnabled(enabled); |
|
157 |
if (xtext != null) { |
|
158 |
xtext.setEnabled(enabled); |
|
159 |
xtext.repaint(); |
|
160 |
} |
|
161 |
} |
|
162 |
||
163 |
/** |
|
164 |
* @see java.awt.peer.TextComponentPeer |
|
165 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
166 |
@Override |
2 | 167 |
public InputMethodRequests getInputMethodRequests() { |
168 |
if (xtext != null) return xtext.getInputMethodRequests(); |
|
169 |
else return null; |
|
170 |
||
171 |
} |
|
172 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
173 |
@Override |
2 | 174 |
void handleJavaInputMethodEvent(InputMethodEvent e) { |
175 |
if (xtext != null) |
|
176 |
xtext.processInputMethodEventImpl(e); |
|
177 |
} |
|
178 |
||
179 |
/** |
|
180 |
* @see java.awt.peer.TextFieldPeer |
|
181 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
182 |
@Override |
2 | 183 |
public void setEchoChar(char c) { |
184 |
if (xtext != null) { |
|
185 |
xtext.setEchoChar(c); |
|
186 |
xtext.putClientProperty("JPasswordField.cutCopyAllowed", |
|
187 |
xtext.echoCharIsSet() ? Boolean.FALSE : Boolean.TRUE); |
|
188 |
} |
|
189 |
} |
|
190 |
||
191 |
/** |
|
192 |
* @see java.awt.peer.TextComponentPeer |
|
193 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
194 |
@Override |
2 | 195 |
public int getSelectionStart() { |
196 |
return xtext.getSelectionStart(); |
|
197 |
} |
|
198 |
||
199 |
/** |
|
200 |
* @see java.awt.peer.TextComponentPeer |
|
201 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
202 |
@Override |
2 | 203 |
public int getSelectionEnd() { |
204 |
return xtext.getSelectionEnd(); |
|
205 |
} |
|
206 |
||
207 |
/** |
|
208 |
* @see java.awt.peer.TextComponentPeer |
|
209 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
210 |
@Override |
2 | 211 |
public String getText() { |
212 |
return xtext.getText(); |
|
213 |
} |
|
214 |
||
215 |
/** |
|
216 |
* @see java.awt.peer.TextComponentPeer |
|
217 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
218 |
@Override |
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
219 |
public void setText(String text) { |
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
220 |
setXAWTTextField(text); |
2 | 221 |
repaint(); |
222 |
} |
|
223 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
224 |
private void setXAWTTextField(String txt) { |
2 | 225 |
text = txt; |
226 |
if (xtext != null) { |
|
227 |
// JTextField.setText() posts two different events (remove & insert). |
|
228 |
// Since we make no differences between text events, |
|
229 |
// the document listener has to be disabled while |
|
230 |
// JTextField.setText() is called. |
|
231 |
xtext.getDocument().removeDocumentListener(xtext); |
|
232 |
xtext.setText(txt); |
|
233 |
if (firstChangeSkipped) { |
|
234 |
postEvent(new TextEvent(target, TextEvent.TEXT_VALUE_CHANGED)); |
|
235 |
} |
|
236 |
xtext.getDocument().addDocumentListener(xtext); |
|
237 |
xtext.setCaretPosition(0); |
|
238 |
} |
|
239 |
} |
|
240 |
||
241 |
/** |
|
242 |
* to be implemented. |
|
243 |
* @see java.awt.peer.TextComponentPeer |
|
244 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
245 |
@Override |
2 | 246 |
public void setCaretPosition(int position) { |
247 |
if (xtext != null) xtext.setCaretPosition(position); |
|
248 |
} |
|
249 |
||
250 |
void repaintText() { |
|
251 |
xtext.repaintNow(); |
|
252 |
} |
|
253 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
254 |
@Override |
2 | 255 |
public void setBackground(Color c) { |
18178
ee71c923891d
8016747: Replace deprecated PlatformLogger isLoggable(int) with isLoggable(Level)
chegar
parents:
16839
diff
changeset
|
256 |
if (log.isLoggable(PlatformLogger.Level.FINE)) { |
16839
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
13604
diff
changeset
|
257 |
log.fine("target="+ target + ", old=" + background + ", new=" + c); |
d0f2e97b7359
8010297: Missing isLoggable() checks in logging code
anthony
parents:
13604
diff
changeset
|
258 |
} |
2 | 259 |
background = c; |
260 |
if (xtext != null) { |
|
261 |
xtext.setBackground(c); |
|
262 |
xtext.setSelectedTextColor(c); |
|
263 |
} |
|
264 |
repaintText(); |
|
265 |
} |
|
266 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
267 |
@Override |
2 | 268 |
public void setForeground(Color c) { |
269 |
foreground = c; |
|
270 |
if (xtext != null) { |
|
271 |
xtext.setForeground(foreground); |
|
272 |
xtext.setSelectionColor(foreground); |
|
273 |
xtext.setCaretColor(foreground); |
|
274 |
} |
|
275 |
repaintText(); |
|
276 |
} |
|
277 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
278 |
@Override |
2 | 279 |
public void setFont(Font f) { |
280 |
synchronized (getStateLock()) { |
|
281 |
font = f; |
|
282 |
if (xtext != null) { |
|
283 |
xtext.setFont(font); |
|
284 |
} |
|
285 |
} |
|
286 |
xtext.validate(); |
|
287 |
} |
|
288 |
||
289 |
/** |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
25859
diff
changeset
|
290 |
* Deselects the highlighted text. |
2 | 291 |
*/ |
292 |
public void deselect() { |
|
293 |
int selStart=xtext.getSelectionStart(); |
|
294 |
int selEnd=xtext.getSelectionEnd(); |
|
295 |
if (selStart != selEnd) { |
|
296 |
xtext.select(selStart,selStart); |
|
297 |
} |
|
298 |
} |
|
299 |
||
300 |
/** |
|
301 |
* to be implemented. |
|
302 |
* @see java.awt.peer.TextComponentPeer |
|
303 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
304 |
@Override |
2 | 305 |
public int getCaretPosition() { |
306 |
return xtext.getCaretPosition(); |
|
307 |
} |
|
308 |
||
309 |
/** |
|
310 |
* @see java.awt.peer.TextComponentPeer |
|
311 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
312 |
@Override |
2 | 313 |
public void select(int s, int e) { |
314 |
xtext.select(s,e); |
|
315 |
// Fixed 5100806 |
|
316 |
// We must take care that Swing components repainted correctly |
|
317 |
xtext.repaint(); |
|
318 |
} |
|
319 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
320 |
@Override |
2 | 321 |
public Dimension getMinimumSize() { |
322 |
return xtext.getMinimumSize(); |
|
323 |
} |
|
324 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
325 |
@Override |
2 | 326 |
public Dimension getPreferredSize() { |
327 |
return xtext.getPreferredSize(); |
|
328 |
} |
|
329 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
330 |
@Override |
2 | 331 |
public Dimension getPreferredSize(int cols) { |
332 |
return getMinimumSize(cols); |
|
333 |
} |
|
334 |
||
335 |
private static final int PADDING = 16; |
|
336 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
337 |
@Override |
2 | 338 |
public Dimension getMinimumSize(int cols) { |
339 |
Font f = xtext.getFont(); |
|
340 |
FontMetrics fm = xtext.getFontMetrics(f); |
|
341 |
return new Dimension(fm.charWidth('0') * cols + 10, |
|
342 |
fm.getMaxDescent() + fm.getMaxAscent() + PADDING); |
|
343 |
} |
|
344 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
345 |
@Override |
2 | 346 |
public boolean isFocusable() { |
347 |
return true; |
|
348 |
} |
|
349 |
||
350 |
// NOTE: This method is called by privileged threads. |
|
351 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
352 |
public void action(final long when, final int modifiers) { |
|
353 |
postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED, |
|
354 |
text, when, |
|
355 |
modifiers)); |
|
356 |
} |
|
357 |
||
358 |
protected void disposeImpl() { |
|
359 |
} |
|
360 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
361 |
@Override |
2 | 362 |
public void repaint() { |
363 |
if (xtext != null) xtext.repaint(); |
|
364 |
} |
|
10096
f9ac9a52952d
6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents:
5506
diff
changeset
|
365 |
@Override |
f9ac9a52952d
6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents:
5506
diff
changeset
|
366 |
void paintPeer(final Graphics g) { |
2 | 367 |
if (xtext != null) xtext.paint(g); |
368 |
} |
|
369 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
370 |
@Override |
2 | 371 |
public void print(Graphics g) { |
372 |
if (xtext != null) { |
|
373 |
xtext.print(g); |
|
374 |
} |
|
375 |
} |
|
376 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
377 |
@Override |
2 | 378 |
public void focusLost(FocusEvent e) { |
379 |
super.focusLost(e); |
|
380 |
xtext.forwardFocusLost(e); |
|
381 |
} |
|
382 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
383 |
@Override |
2 | 384 |
public void focusGained(FocusEvent e) { |
385 |
super.focusGained(e); |
|
386 |
xtext.forwardFocusGained(e); |
|
387 |
} |
|
388 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
389 |
@Override |
2 | 390 |
void handleJavaKeyEvent(KeyEvent e) { |
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
391 |
AWTAccessor.getComponentAccessor().processEvent(xtext,e); |
2 | 392 |
} |
393 |
||
394 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
395 |
@Override |
2 | 396 |
public void handleJavaMouseEvent( MouseEvent mouseEvent ) { |
397 |
super.handleJavaMouseEvent(mouseEvent); |
|
398 |
if (xtext != null) { |
|
399 |
mouseEvent.setSource(xtext); |
|
400 |
int id = mouseEvent.getID(); |
|
401 |
if (id == MouseEvent.MOUSE_DRAGGED || id == MouseEvent.MOUSE_MOVED) |
|
402 |
xtext.processMouseMotionEventImpl(mouseEvent); |
|
403 |
else |
|
404 |
xtext.processMouseEventImpl(mouseEvent); |
|
405 |
} |
|
406 |
} |
|
407 |
||
408 |
/** |
|
409 |
* DEPRECATED |
|
410 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
411 |
@Override |
2 | 412 |
public Dimension minimumSize() { |
413 |
return getMinimumSize(); |
|
414 |
} |
|
415 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
416 |
@Override |
2 | 417 |
public void setVisible(boolean b) { |
418 |
super.setVisible(b); |
|
419 |
if (xtext != null) xtext.setVisible(b); |
|
420 |
} |
|
421 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
422 |
@Override |
2 | 423 |
public void setBounds(int x, int y, int width, int height, int op) { |
424 |
super.setBounds(x, y, width, height, op); |
|
425 |
if (xtext != null) { |
|
426 |
/* |
|
427 |
* Fixed 6277332, 6198290: |
|
428 |
* the coordinates is coming (to peer): relatively to closest HW parent |
|
429 |
* the coordinates is setting (to textField): relatively to closest ANY parent |
|
430 |
* the parent of peer is target.getParent() |
|
431 |
* the parent of textField is the same |
|
432 |
* see 6277332, 6198290 for more information |
|
433 |
*/ |
|
434 |
int childX = x; |
|
435 |
int childY = y; |
|
436 |
Component parent = target.getParent(); |
|
437 |
// we up to heavyweight parent in order to be sure |
|
438 |
// that the coordinates of the text pane is relatively to closest parent |
|
439 |
while (parent.isLightweight()){ |
|
440 |
childX -= parent.getX(); |
|
441 |
childY -= parent.getY(); |
|
442 |
parent = parent.getParent(); |
|
443 |
} |
|
444 |
xtext.setBounds(childX,childY,width,height); |
|
445 |
xtext.validate(); |
|
446 |
} |
|
447 |
} |
|
448 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
449 |
final class AWTTextFieldUI extends MotifPasswordFieldUI { |
2 | 450 |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
451 |
private JTextField jtf; |
2 | 452 |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
453 |
@Override |
2 | 454 |
protected String getPropertyPrefix() { |
455 |
JTextComponent comp = getComponent(); |
|
456 |
if (comp instanceof JPasswordField && ((JPasswordField)comp).echoCharIsSet()) { |
|
457 |
return "PasswordField"; |
|
458 |
} else { |
|
459 |
return "TextField"; |
|
460 |
} |
|
461 |
} |
|
462 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
463 |
@Override |
2 | 464 |
public void installUI(JComponent c) { |
465 |
super.installUI(c); |
|
466 |
||
467 |
jtf = (JTextField) c; |
|
468 |
||
469 |
JTextField editor = jtf; |
|
470 |
||
471 |
UIDefaults uidefaults = XToolkit.getUIDefaults(); |
|
472 |
||
473 |
String prefix = getPropertyPrefix(); |
|
474 |
Font f = editor.getFont(); |
|
475 |
if ((f == null) || (f instanceof UIResource)) { |
|
476 |
editor.setFont(uidefaults.getFont(prefix + ".font")); |
|
477 |
} |
|
478 |
||
479 |
Color bg = editor.getBackground(); |
|
480 |
if ((bg == null) || (bg instanceof UIResource)) { |
|
481 |
editor.setBackground(uidefaults.getColor(prefix + ".background")); |
|
482 |
} |
|
483 |
||
484 |
Color fg = editor.getForeground(); |
|
485 |
if ((fg == null) || (fg instanceof UIResource)) { |
|
486 |
editor.setForeground(uidefaults.getColor(prefix + ".foreground")); |
|
487 |
} |
|
488 |
||
489 |
Color color = editor.getCaretColor(); |
|
490 |
if ((color == null) || (color instanceof UIResource)) { |
|
491 |
editor.setCaretColor(uidefaults.getColor(prefix + ".caretForeground")); |
|
492 |
} |
|
493 |
||
494 |
Color s = editor.getSelectionColor(); |
|
495 |
if ((s == null) || (s instanceof UIResource)) { |
|
496 |
editor.setSelectionColor(uidefaults.getColor(prefix + ".selectionBackground")); |
|
497 |
} |
|
498 |
||
499 |
Color sfg = editor.getSelectedTextColor(); |
|
500 |
if ((sfg == null) || (sfg instanceof UIResource)) { |
|
501 |
editor.setSelectedTextColor(uidefaults.getColor(prefix + ".selectionForeground")); |
|
502 |
} |
|
503 |
||
504 |
Color dfg = editor.getDisabledTextColor(); |
|
505 |
if ((dfg == null) || (dfg instanceof UIResource)) { |
|
506 |
editor.setDisabledTextColor(uidefaults.getColor(prefix + ".inactiveForeground")); |
|
507 |
} |
|
508 |
||
509 |
Border b = editor.getBorder(); |
|
510 |
if ((b == null) || (b instanceof UIResource)) { |
|
511 |
editor.setBorder(uidefaults.getBorder(prefix + ".border")); |
|
512 |
} |
|
513 |
||
514 |
Insets margin = editor.getMargin(); |
|
515 |
if (margin == null || margin instanceof UIResource) { |
|
516 |
editor.setMargin(uidefaults.getInsets(prefix + ".margin")); |
|
517 |
} |
|
518 |
} |
|
519 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
520 |
@Override |
2 | 521 |
protected void installKeyboardActions() { |
522 |
super.installKeyboardActions(); |
|
523 |
||
524 |
JTextComponent comp = getComponent(); |
|
525 |
||
526 |
UIDefaults uidefaults = XToolkit.getUIDefaults(); |
|
527 |
||
528 |
String prefix = getPropertyPrefix(); |
|
529 |
||
530 |
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap"); |
|
531 |
||
532 |
if (map != null) { |
|
533 |
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED, |
|
534 |
map); |
|
535 |
} |
|
536 |
} |
|
537 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
538 |
@Override |
2 | 539 |
protected Caret createCaret() { |
12523
a3c0565476da
7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
12285
diff
changeset
|
540 |
return new XTextAreaPeer.XAWTCaret(); |
2 | 541 |
} |
542 |
} |
|
543 |
||
23647 | 544 |
@SuppressWarnings("serial") // JDK-implementation class |
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
545 |
final class XAWTTextField extends JPasswordField |
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
546 |
implements ActionListener, DocumentListener { |
2 | 547 |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
548 |
private boolean isFocused = false; |
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
549 |
private final XComponentPeer peer; |
2 | 550 |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
551 |
XAWTTextField(String text, XComponentPeer peer, Container parent) { |
2 | 552 |
super(text); |
553 |
this.peer = peer; |
|
554 |
setDoubleBuffered(true); |
|
555 |
setFocusable(false); |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
556 |
AWTAccessor.getComponentAccessor().setParent(this,parent); |
2 | 557 |
setBackground(peer.getPeerBackground()); |
558 |
setForeground(peer.getPeerForeground()); |
|
559 |
setFont(peer.getPeerFont()); |
|
560 |
setCaretPosition(0); |
|
561 |
addActionListener(this); |
|
562 |
addNotify(); |
|
563 |
||
564 |
} |
|
565 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
566 |
@Override |
2 | 567 |
public void actionPerformed( ActionEvent actionEvent ) { |
568 |
peer.postEvent(new ActionEvent(peer.target, |
|
569 |
ActionEvent.ACTION_PERFORMED, |
|
570 |
getText(), |
|
571 |
actionEvent.getWhen(), |
|
572 |
actionEvent.getModifiers())); |
|
573 |
||
574 |
} |
|
575 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
576 |
@Override |
2 | 577 |
public void insertUpdate(DocumentEvent e) { |
578 |
if (peer != null) { |
|
579 |
peer.postEvent(new TextEvent(peer.target, |
|
580 |
TextEvent.TEXT_VALUE_CHANGED)); |
|
581 |
} |
|
582 |
} |
|
583 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
584 |
@Override |
2 | 585 |
public void removeUpdate(DocumentEvent e) { |
586 |
if (peer != null) { |
|
587 |
peer.postEvent(new TextEvent(peer.target, |
|
588 |
TextEvent.TEXT_VALUE_CHANGED)); |
|
589 |
} |
|
590 |
} |
|
591 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
592 |
@Override |
2 | 593 |
public void changedUpdate(DocumentEvent e) { |
594 |
if (peer != null) { |
|
595 |
peer.postEvent(new TextEvent(peer.target, |
|
596 |
TextEvent.TEXT_VALUE_CHANGED)); |
|
597 |
} |
|
598 |
} |
|
599 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
600 |
@Override |
2 | 601 |
public ComponentPeer getPeer() { |
602 |
return (ComponentPeer) peer; |
|
603 |
} |
|
604 |
||
605 |
public void repaintNow() { |
|
606 |
paintImmediately(getBounds()); |
|
607 |
} |
|
608 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
609 |
@Override |
2 | 610 |
public Graphics getGraphics() { |
611 |
return peer.getGraphics(); |
|
612 |
} |
|
613 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
614 |
@Override |
2 | 615 |
public void updateUI() { |
616 |
ComponentUI ui = new AWTTextFieldUI(); |
|
617 |
setUI(ui); |
|
618 |
} |
|
619 |
||
620 |
void forwardFocusGained( FocusEvent e) { |
|
621 |
isFocused = true; |
|
622 |
FocusEvent fe = CausedFocusEvent.retarget(e, this); |
|
623 |
super.processFocusEvent(fe); |
|
624 |
} |
|
625 |
||
626 |
void forwardFocusLost( FocusEvent e) { |
|
627 |
isFocused = false; |
|
628 |
FocusEvent fe = CausedFocusEvent.retarget(e, this); |
|
629 |
super.processFocusEvent(fe); |
|
630 |
||
631 |
} |
|
632 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
633 |
@Override |
2 | 634 |
public boolean hasFocus() { |
635 |
return isFocused; |
|
636 |
} |
|
637 |
||
638 |
public void processInputMethodEventImpl(InputMethodEvent e) { |
|
639 |
processInputMethodEvent(e); |
|
640 |
} |
|
641 |
||
642 |
public void processMouseEventImpl(MouseEvent e) { |
|
643 |
processMouseEvent(e); |
|
644 |
} |
|
645 |
||
646 |
public void processMouseMotionEventImpl(MouseEvent e) { |
|
647 |
processMouseMotionEvent(e); |
|
648 |
} |
|
649 |
||
650 |
// Fix for 4915454 - override the default implementation to avoid |
|
651 |
// loading SystemFlavorMap and associated classes. |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
652 |
@Override |
2 | 653 |
public void setTransferHandler(TransferHandler newHandler) { |
654 |
TransferHandler oldHandler = (TransferHandler) |
|
13604 | 655 |
getClientProperty(AWTAccessor.getClientPropertyKeyAccessor() |
656 |
.getJComponent_TRANSFER_HANDLER()); |
|
657 |
putClientProperty(AWTAccessor.getClientPropertyKeyAccessor() |
|
658 |
.getJComponent_TRANSFER_HANDLER(), |
|
2 | 659 |
newHandler); |
660 |
||
661 |
firePropertyChange("transferHandler", oldHandler, newHandler); |
|
662 |
} |
|
663 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
664 |
@Override |
2 | 665 |
public void setEchoChar(char c) { |
666 |
super.setEchoChar(c); |
|
667 |
((AWTTextFieldUI)ui).installKeyboardActions(); |
|
668 |
} |
|
669 |
} |
|
670 |
} |