author | itakiguchi |
Sun, 06 Jan 2019 19:28:21 -0800 | |
changeset 53188 | 6c8ce24d0fbf |
parent 49998 | 9070717a16a1 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
49998
9070717a16a1
8187392: Deprecated methods in the peers can be removed
serb
parents:
47216
diff
changeset
|
2 |
* Copyright (c) 2003, 2018, 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 |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
57 |
import sun.awt.AWTAccessor; |
2 | 58 |
|
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
59 |
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
|
60 |
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XTextField"); |
2 | 61 |
|
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
62 |
private String text; |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
63 |
private final XAWTTextField xtext; |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
64 |
private final boolean firstChangeSkipped; |
2 | 65 |
|
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
66 |
XTextFieldPeer(TextField target) { |
2 | 67 |
super(target); |
68 |
text = target.getText(); |
|
69 |
xtext = new XAWTTextField(text,this, target.getParent()); |
|
70 |
xtext.getDocument().addDocumentListener(xtext); |
|
71 |
xtext.setCursor(target.getCursor()); |
|
72 |
XToolkit.specialPeerMap.put(xtext,this); |
|
73 |
||
74 |
initTextField(); |
|
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
75 |
setText(target.getText()); |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
76 |
if (target.echoCharIsSet()) { |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
77 |
setEchoChar(target.getEchoChar()); |
2 | 78 |
} |
79 |
else setEchoChar((char)0); |
|
80 |
||
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
81 |
int start = target.getSelectionStart(); |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
82 |
int end = target.getSelectionEnd(); |
2 | 83 |
// Fix for 5100200 |
84 |
// Restoring Motif behaviour |
|
35667 | 85 |
// Since the end position of the selected text can be greater than the length of the text, |
2 | 86 |
// 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
|
87 |
setCaretPosition(Math.min(end, text.length())); |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
88 |
if (end > start) { |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
89 |
// Should be called after setText() and setCaretPosition() |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
90 |
select(start, end); |
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
91 |
} |
2 | 92 |
|
20435
543c1c7dd21a
7150100: [macosx] "0123456789" is selected in the TextField
serb
parents:
18178
diff
changeset
|
93 |
setEditable(target.isEditable()); |
2 | 94 |
|
95 |
// After this line we should not change the component's text |
|
96 |
firstChangeSkipped = true; |
|
31656
786638581dba
8085895: The Textfield can't be shown after clicking "Show Textfield" button.
ssadetsky
parents:
30469
diff
changeset
|
97 |
AWTAccessor.getComponentAccessor().setPeer(xtext, this); |
2 | 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 |
super.dispose(); |
106 |
} |
|
107 |
||
108 |
void initTextField() { |
|
109 |
setVisible(target.isVisible()); |
|
110 |
||
111 |
setBounds(x, y, width, height, SET_BOUNDS); |
|
112 |
||
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
113 |
AWTAccessor.ComponentAccessor compAccessor = AWTAccessor.getComponentAccessor(); |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
114 |
foreground = compAccessor.getForeground(target); |
2 | 115 |
if (foreground == null) |
116 |
foreground = SystemColor.textText; |
|
117 |
||
118 |
setForeground(foreground); |
|
119 |
||
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
120 |
background = compAccessor.getBackground(target); |
2 | 121 |
if (background == null) { |
122 |
if (((TextField)target).isEditable()) background = SystemColor.text; |
|
123 |
else background = SystemColor.control; |
|
124 |
} |
|
125 |
setBackground(background); |
|
126 |
||
127 |
if (!target.isBackgroundSet()) { |
|
128 |
// 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
|
129 |
// without calling setBackground - go through accessor |
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
130 |
compAccessor.setBackground(target, background); |
2 | 131 |
} |
132 |
if (!target.isForegroundSet()) { |
|
133 |
target.setForeground(SystemColor.textText); |
|
134 |
} |
|
135 |
||
136 |
setFont(font); |
|
137 |
} |
|
138 |
||
139 |
/** |
|
140 |
* @see java.awt.peer.TextComponentPeer |
|
141 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
142 |
@Override |
2 | 143 |
public void setEditable(boolean editable) { |
144 |
if (xtext != null) { |
|
145 |
xtext.setEditable(editable); |
|
146 |
xtext.repaint(); |
|
147 |
} |
|
148 |
} |
|
149 |
||
150 |
/** |
|
151 |
* @see java.awt.peer.ComponentPeer |
|
152 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
153 |
@Override |
2 | 154 |
public void setEnabled(boolean enabled) { |
155 |
super.setEnabled(enabled); |
|
156 |
if (xtext != null) { |
|
157 |
xtext.setEnabled(enabled); |
|
158 |
xtext.repaint(); |
|
159 |
} |
|
160 |
} |
|
161 |
||
162 |
/** |
|
163 |
* @see java.awt.peer.TextComponentPeer |
|
164 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
165 |
@Override |
2 | 166 |
public InputMethodRequests getInputMethodRequests() { |
167 |
if (xtext != null) return xtext.getInputMethodRequests(); |
|
168 |
else return null; |
|
169 |
||
170 |
} |
|
171 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
172 |
@Override |
2 | 173 |
void handleJavaInputMethodEvent(InputMethodEvent e) { |
174 |
if (xtext != null) |
|
175 |
xtext.processInputMethodEventImpl(e); |
|
176 |
} |
|
177 |
||
178 |
/** |
|
179 |
* @see java.awt.peer.TextFieldPeer |
|
180 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
181 |
@Override |
2 | 182 |
public void setEchoChar(char c) { |
183 |
if (xtext != null) { |
|
184 |
xtext.setEchoChar(c); |
|
185 |
xtext.putClientProperty("JPasswordField.cutCopyAllowed", |
|
186 |
xtext.echoCharIsSet() ? Boolean.FALSE : Boolean.TRUE); |
|
187 |
} |
|
188 |
} |
|
189 |
||
190 |
/** |
|
191 |
* @see java.awt.peer.TextComponentPeer |
|
192 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
193 |
@Override |
2 | 194 |
public int getSelectionStart() { |
195 |
return xtext.getSelectionStart(); |
|
196 |
} |
|
197 |
||
198 |
/** |
|
199 |
* @see java.awt.peer.TextComponentPeer |
|
200 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
201 |
@Override |
2 | 202 |
public int getSelectionEnd() { |
203 |
return xtext.getSelectionEnd(); |
|
204 |
} |
|
205 |
||
206 |
/** |
|
207 |
* @see java.awt.peer.TextComponentPeer |
|
208 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
209 |
@Override |
28231
b608ffcaed74
8066621: Suppress deprecation warnings in java.desktop module
darcy
parents:
25859
diff
changeset
|
210 |
@SuppressWarnings("deprecation") |
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) { |
|
31656
786638581dba
8085895: The Textfield can't be shown after clicking "Show Textfield" button.
ssadetsky
parents:
30469
diff
changeset
|
261 |
if (xtext.getBackground() != c) { |
786638581dba
8085895: The Textfield can't be shown after clicking "Show Textfield" button.
ssadetsky
parents:
30469
diff
changeset
|
262 |
xtext.setBackground(c); |
786638581dba
8085895: The Textfield can't be shown after clicking "Show Textfield" button.
ssadetsky
parents:
30469
diff
changeset
|
263 |
} |
2 | 264 |
xtext.setSelectedTextColor(c); |
265 |
} |
|
266 |
repaintText(); |
|
267 |
} |
|
268 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
269 |
@Override |
2 | 270 |
public void setForeground(Color c) { |
271 |
foreground = c; |
|
272 |
if (xtext != null) { |
|
31656
786638581dba
8085895: The Textfield can't be shown after clicking "Show Textfield" button.
ssadetsky
parents:
30469
diff
changeset
|
273 |
if (xtext.getForeground() != c) { |
786638581dba
8085895: The Textfield can't be shown after clicking "Show Textfield" button.
ssadetsky
parents:
30469
diff
changeset
|
274 |
xtext.setForeground(foreground); |
786638581dba
8085895: The Textfield can't be shown after clicking "Show Textfield" button.
ssadetsky
parents:
30469
diff
changeset
|
275 |
} |
2 | 276 |
xtext.setSelectionColor(foreground); |
277 |
xtext.setCaretColor(foreground); |
|
278 |
} |
|
279 |
repaintText(); |
|
280 |
} |
|
281 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
282 |
@Override |
2 | 283 |
public void setFont(Font f) { |
53188
6c8ce24d0fbf
8211267: StackOverflowError happened by TextField.setFont(...)
itakiguchi
parents:
49998
diff
changeset
|
284 |
boolean isChanged = false; |
2 | 285 |
synchronized (getStateLock()) { |
286 |
font = f; |
|
31656
786638581dba
8085895: The Textfield can't be shown after clicking "Show Textfield" button.
ssadetsky
parents:
30469
diff
changeset
|
287 |
if (xtext != null && xtext.getFont() != f) { |
2 | 288 |
xtext.setFont(font); |
53188
6c8ce24d0fbf
8211267: StackOverflowError happened by TextField.setFont(...)
itakiguchi
parents:
49998
diff
changeset
|
289 |
isChanged = true; |
2 | 290 |
} |
291 |
} |
|
53188
6c8ce24d0fbf
8211267: StackOverflowError happened by TextField.setFont(...)
itakiguchi
parents:
49998
diff
changeset
|
292 |
if (isChanged) |
6c8ce24d0fbf
8211267: StackOverflowError happened by TextField.setFont(...)
itakiguchi
parents:
49998
diff
changeset
|
293 |
xtext.validate(); |
2 | 294 |
} |
295 |
||
296 |
/** |
|
28059
e576535359cc
8067377: My hobby: caning, then then canning, the the can-can
martin
parents:
25859
diff
changeset
|
297 |
* Deselects the highlighted text. |
2 | 298 |
*/ |
299 |
public void deselect() { |
|
300 |
int selStart=xtext.getSelectionStart(); |
|
301 |
int selEnd=xtext.getSelectionEnd(); |
|
302 |
if (selStart != selEnd) { |
|
303 |
xtext.select(selStart,selStart); |
|
304 |
} |
|
305 |
} |
|
306 |
||
307 |
/** |
|
308 |
* to be implemented. |
|
309 |
* @see java.awt.peer.TextComponentPeer |
|
310 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
311 |
@Override |
2 | 312 |
public int getCaretPosition() { |
313 |
return xtext.getCaretPosition(); |
|
314 |
} |
|
315 |
||
316 |
/** |
|
317 |
* @see java.awt.peer.TextComponentPeer |
|
318 |
*/ |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
319 |
@Override |
2 | 320 |
public void select(int s, int e) { |
321 |
xtext.select(s,e); |
|
322 |
// Fixed 5100806 |
|
323 |
// We must take care that Swing components repainted correctly |
|
324 |
xtext.repaint(); |
|
325 |
} |
|
326 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
327 |
@Override |
2 | 328 |
public Dimension getMinimumSize() { |
329 |
return xtext.getMinimumSize(); |
|
330 |
} |
|
331 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
332 |
@Override |
2 | 333 |
public Dimension getPreferredSize() { |
334 |
return xtext.getPreferredSize(); |
|
335 |
} |
|
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 getPreferredSize(int cols) { |
339 |
return getMinimumSize(cols); |
|
340 |
} |
|
341 |
||
342 |
private static final int PADDING = 16; |
|
343 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
344 |
@Override |
2 | 345 |
public Dimension getMinimumSize(int cols) { |
346 |
Font f = xtext.getFont(); |
|
347 |
FontMetrics fm = xtext.getFontMetrics(f); |
|
348 |
return new Dimension(fm.charWidth('0') * cols + 10, |
|
349 |
fm.getMaxDescent() + fm.getMaxAscent() + PADDING); |
|
350 |
} |
|
351 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
352 |
@Override |
2 | 353 |
public boolean isFocusable() { |
354 |
return true; |
|
355 |
} |
|
356 |
||
357 |
// NOTE: This method is called by privileged threads. |
|
358 |
// DO NOT INVOKE CLIENT CODE ON THIS THREAD! |
|
359 |
public void action(final long when, final int modifiers) { |
|
360 |
postEvent(new ActionEvent(target, ActionEvent.ACTION_PERFORMED, |
|
361 |
text, when, |
|
362 |
modifiers)); |
|
363 |
} |
|
364 |
||
365 |
protected void disposeImpl() { |
|
366 |
} |
|
367 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
368 |
@Override |
2 | 369 |
public void repaint() { |
370 |
if (xtext != null) xtext.repaint(); |
|
371 |
} |
|
10096
f9ac9a52952d
6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents:
5506
diff
changeset
|
372 |
@Override |
f9ac9a52952d
6596915: JCK-runtime-6a/tests/api/java_awt/Component/index.html tesPaintAll fails
serb
parents:
5506
diff
changeset
|
373 |
void paintPeer(final Graphics g) { |
2 | 374 |
if (xtext != null) xtext.paint(g); |
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 print(Graphics g) { |
379 |
if (xtext != null) { |
|
380 |
xtext.print(g); |
|
381 |
} |
|
382 |
} |
|
383 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
384 |
@Override |
2 | 385 |
public void focusLost(FocusEvent e) { |
386 |
super.focusLost(e); |
|
387 |
xtext.forwardFocusLost(e); |
|
388 |
} |
|
389 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
390 |
@Override |
2 | 391 |
public void focusGained(FocusEvent e) { |
392 |
super.focusGained(e); |
|
393 |
xtext.forwardFocusGained(e); |
|
394 |
} |
|
395 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
396 |
@Override |
2 | 397 |
void handleJavaKeyEvent(KeyEvent e) { |
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
398 |
AWTAccessor.getComponentAccessor().processEvent(xtext,e); |
2 | 399 |
} |
400 |
||
401 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
402 |
@Override |
2 | 403 |
public void handleJavaMouseEvent( MouseEvent mouseEvent ) { |
404 |
super.handleJavaMouseEvent(mouseEvent); |
|
405 |
if (xtext != null) { |
|
406 |
mouseEvent.setSource(xtext); |
|
407 |
int id = mouseEvent.getID(); |
|
408 |
if (id == MouseEvent.MOUSE_DRAGGED || id == MouseEvent.MOUSE_MOVED) |
|
409 |
xtext.processMouseMotionEventImpl(mouseEvent); |
|
410 |
else |
|
411 |
xtext.processMouseEventImpl(mouseEvent); |
|
412 |
} |
|
413 |
} |
|
414 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
415 |
@Override |
2 | 416 |
public void setVisible(boolean b) { |
417 |
super.setVisible(b); |
|
418 |
if (xtext != null) xtext.setVisible(b); |
|
419 |
} |
|
420 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
421 |
@Override |
2 | 422 |
public void setBounds(int x, int y, int width, int height, int op) { |
423 |
super.setBounds(x, y, width, height, op); |
|
424 |
if (xtext != null) { |
|
425 |
/* |
|
426 |
* Fixed 6277332, 6198290: |
|
427 |
* the coordinates is coming (to peer): relatively to closest HW parent |
|
428 |
* the coordinates is setting (to textField): relatively to closest ANY parent |
|
429 |
* the parent of peer is target.getParent() |
|
430 |
* the parent of textField is the same |
|
431 |
* see 6277332, 6198290 for more information |
|
432 |
*/ |
|
433 |
int childX = x; |
|
434 |
int childY = y; |
|
435 |
Component parent = target.getParent(); |
|
436 |
// we up to heavyweight parent in order to be sure |
|
437 |
// that the coordinates of the text pane is relatively to closest parent |
|
438 |
while (parent.isLightweight()){ |
|
439 |
childX -= parent.getX(); |
|
440 |
childY -= parent.getY(); |
|
441 |
parent = parent.getParent(); |
|
442 |
} |
|
443 |
xtext.setBounds(childX,childY,width,height); |
|
444 |
xtext.validate(); |
|
445 |
} |
|
446 |
} |
|
447 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
448 |
final class AWTTextFieldUI extends MotifPasswordFieldUI { |
2 | 449 |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
450 |
private JTextField jtf; |
2 | 451 |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
452 |
@Override |
2 | 453 |
protected String getPropertyPrefix() { |
454 |
JTextComponent comp = getComponent(); |
|
455 |
if (comp instanceof JPasswordField && ((JPasswordField)comp).echoCharIsSet()) { |
|
456 |
return "PasswordField"; |
|
457 |
} else { |
|
458 |
return "TextField"; |
|
459 |
} |
|
460 |
} |
|
461 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
462 |
@Override |
2 | 463 |
public void installUI(JComponent c) { |
464 |
super.installUI(c); |
|
465 |
||
466 |
jtf = (JTextField) c; |
|
467 |
||
468 |
JTextField editor = jtf; |
|
469 |
||
470 |
UIDefaults uidefaults = XToolkit.getUIDefaults(); |
|
471 |
||
472 |
String prefix = getPropertyPrefix(); |
|
473 |
Font f = editor.getFont(); |
|
474 |
if ((f == null) || (f instanceof UIResource)) { |
|
475 |
editor.setFont(uidefaults.getFont(prefix + ".font")); |
|
476 |
} |
|
477 |
||
478 |
Color bg = editor.getBackground(); |
|
479 |
if ((bg == null) || (bg instanceof UIResource)) { |
|
480 |
editor.setBackground(uidefaults.getColor(prefix + ".background")); |
|
481 |
} |
|
482 |
||
483 |
Color fg = editor.getForeground(); |
|
484 |
if ((fg == null) || (fg instanceof UIResource)) { |
|
485 |
editor.setForeground(uidefaults.getColor(prefix + ".foreground")); |
|
486 |
} |
|
487 |
||
488 |
Color color = editor.getCaretColor(); |
|
489 |
if ((color == null) || (color instanceof UIResource)) { |
|
490 |
editor.setCaretColor(uidefaults.getColor(prefix + ".caretForeground")); |
|
491 |
} |
|
492 |
||
493 |
Color s = editor.getSelectionColor(); |
|
494 |
if ((s == null) || (s instanceof UIResource)) { |
|
495 |
editor.setSelectionColor(uidefaults.getColor(prefix + ".selectionBackground")); |
|
496 |
} |
|
497 |
||
498 |
Color sfg = editor.getSelectedTextColor(); |
|
499 |
if ((sfg == null) || (sfg instanceof UIResource)) { |
|
500 |
editor.setSelectedTextColor(uidefaults.getColor(prefix + ".selectionForeground")); |
|
501 |
} |
|
502 |
||
503 |
Color dfg = editor.getDisabledTextColor(); |
|
504 |
if ((dfg == null) || (dfg instanceof UIResource)) { |
|
505 |
editor.setDisabledTextColor(uidefaults.getColor(prefix + ".inactiveForeground")); |
|
506 |
} |
|
507 |
||
508 |
Border b = editor.getBorder(); |
|
509 |
if ((b == null) || (b instanceof UIResource)) { |
|
510 |
editor.setBorder(uidefaults.getBorder(prefix + ".border")); |
|
511 |
} |
|
512 |
||
513 |
Insets margin = editor.getMargin(); |
|
514 |
if (margin == null || margin instanceof UIResource) { |
|
515 |
editor.setMargin(uidefaults.getInsets(prefix + ".margin")); |
|
516 |
} |
|
517 |
} |
|
518 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
519 |
@Override |
2 | 520 |
protected void installKeyboardActions() { |
521 |
super.installKeyboardActions(); |
|
522 |
||
523 |
JTextComponent comp = getComponent(); |
|
524 |
||
525 |
UIDefaults uidefaults = XToolkit.getUIDefaults(); |
|
526 |
||
527 |
String prefix = getPropertyPrefix(); |
|
528 |
||
529 |
InputMap map = (InputMap)uidefaults.get(prefix + ".focusInputMap"); |
|
530 |
||
531 |
if (map != null) { |
|
532 |
SwingUtilities.replaceUIInputMap(comp, JComponent.WHEN_FOCUSED, |
|
533 |
map); |
|
534 |
} |
|
535 |
} |
|
536 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
537 |
@Override |
2 | 538 |
protected Caret createCaret() { |
12523
a3c0565476da
7129742: Unable to view focus in Non-Editable TextArea
zhouyx
parents:
12285
diff
changeset
|
539 |
return new XTextAreaPeer.XAWTCaret(); |
2 | 540 |
} |
541 |
} |
|
542 |
||
23647 | 543 |
@SuppressWarnings("serial") // JDK-implementation class |
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
544 |
final class XAWTTextField extends JPasswordField |
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
545 |
implements ActionListener, DocumentListener { |
2 | 546 |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
547 |
private boolean isFocused = false; |
30469 | 548 |
private final XComponentPeer xwin; |
2 | 549 |
|
30469 | 550 |
XAWTTextField(String text, XComponentPeer xwin, Container parent) { |
2 | 551 |
super(text); |
30469 | 552 |
this.xwin = xwin; |
2 | 553 |
setDoubleBuffered(true); |
554 |
setFocusable(false); |
|
4371
dc9dcb8b0ae7
6823138: Need to replace ComponentAccessor with AWTAccessor
dcherepanov
parents:
3938
diff
changeset
|
555 |
AWTAccessor.getComponentAccessor().setParent(this,parent); |
30469 | 556 |
setBackground(xwin.getPeerBackground()); |
557 |
setForeground(xwin.getPeerForeground()); |
|
558 |
setFont(xwin.getPeerFont()); |
|
2 | 559 |
setCaretPosition(0); |
560 |
addActionListener(this); |
|
561 |
addNotify(); |
|
562 |
} |
|
563 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
564 |
@Override |
28231
b608ffcaed74
8066621: Suppress deprecation warnings in java.desktop module
darcy
parents:
25859
diff
changeset
|
565 |
@SuppressWarnings("deprecation") |
2 | 566 |
public void actionPerformed( ActionEvent actionEvent ) { |
30469 | 567 |
xwin.postEvent( |
568 |
new ActionEvent(xwin.target, ActionEvent.ACTION_PERFORMED, |
|
569 |
getText(), actionEvent.getWhen(), |
|
570 |
actionEvent.getModifiers())); |
|
2 | 571 |
|
572 |
} |
|
573 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
574 |
@Override |
2 | 575 |
public void insertUpdate(DocumentEvent e) { |
30469 | 576 |
if (xwin != null) { |
577 |
xwin.postEvent(new TextEvent(xwin.target, |
|
2 | 578 |
TextEvent.TEXT_VALUE_CHANGED)); |
579 |
} |
|
580 |
} |
|
581 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
582 |
@Override |
2 | 583 |
public void removeUpdate(DocumentEvent e) { |
30469 | 584 |
if (xwin != null) { |
585 |
xwin.postEvent(new TextEvent(xwin.target, |
|
2 | 586 |
TextEvent.TEXT_VALUE_CHANGED)); |
587 |
} |
|
588 |
} |
|
589 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
590 |
@Override |
2 | 591 |
public void changedUpdate(DocumentEvent e) { |
30469 | 592 |
if (xwin != null) { |
593 |
xwin.postEvent(new TextEvent(xwin.target, |
|
2 | 594 |
TextEvent.TEXT_VALUE_CHANGED)); |
595 |
} |
|
596 |
} |
|
597 |
||
598 |
public void repaintNow() { |
|
599 |
paintImmediately(getBounds()); |
|
600 |
} |
|
601 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
602 |
@Override |
2 | 603 |
public Graphics getGraphics() { |
30469 | 604 |
return xwin.getGraphics(); |
2 | 605 |
} |
606 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
607 |
@Override |
2 | 608 |
public void updateUI() { |
609 |
ComponentUI ui = new AWTTextFieldUI(); |
|
610 |
setUI(ui); |
|
611 |
} |
|
612 |
||
613 |
void forwardFocusGained( FocusEvent e) { |
|
614 |
isFocused = true; |
|
37694
c064aefc5a2f
8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents:
35667
diff
changeset
|
615 |
FocusEvent fe = new FocusEvent(this, e.getID(), e.isTemporary(), |
c064aefc5a2f
8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents:
35667
diff
changeset
|
616 |
e.getOppositeComponent(), e.getCause()); |
2 | 617 |
super.processFocusEvent(fe); |
618 |
} |
|
619 |
||
620 |
void forwardFocusLost( FocusEvent e) { |
|
621 |
isFocused = false; |
|
37694
c064aefc5a2f
8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents:
35667
diff
changeset
|
622 |
FocusEvent fe = new FocusEvent(this, e.getID(), e.isTemporary(), |
c064aefc5a2f
8080395: consider making sun.awt.CausedFocusEvent functionality public
ssadetsky
parents:
35667
diff
changeset
|
623 |
e.getOppositeComponent(), e.getCause()); |
2 | 624 |
super.processFocusEvent(fe); |
625 |
||
626 |
} |
|
627 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
628 |
@Override |
2 | 629 |
public boolean hasFocus() { |
630 |
return isFocused; |
|
631 |
} |
|
632 |
||
633 |
public void processInputMethodEventImpl(InputMethodEvent e) { |
|
634 |
processInputMethodEvent(e); |
|
635 |
} |
|
636 |
||
637 |
public void processMouseEventImpl(MouseEvent e) { |
|
638 |
processMouseEvent(e); |
|
639 |
} |
|
640 |
||
641 |
public void processMouseMotionEventImpl(MouseEvent e) { |
|
642 |
processMouseMotionEvent(e); |
|
643 |
} |
|
644 |
||
645 |
// Fix for 4915454 - override the default implementation to avoid |
|
646 |
// loading SystemFlavorMap and associated classes. |
|
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
647 |
@Override |
2 | 648 |
public void setTransferHandler(TransferHandler newHandler) { |
649 |
TransferHandler oldHandler = (TransferHandler) |
|
13604 | 650 |
getClientProperty(AWTAccessor.getClientPropertyKeyAccessor() |
651 |
.getJComponent_TRANSFER_HANDLER()); |
|
652 |
putClientProperty(AWTAccessor.getClientPropertyKeyAccessor() |
|
653 |
.getJComponent_TRANSFER_HANDLER(), |
|
2 | 654 |
newHandler); |
655 |
||
656 |
firePropertyChange("transferHandler", oldHandler, newHandler); |
|
657 |
} |
|
658 |
||
20469
47a792bd7dbf
8025603: Unused methods in the awt text peers should be removed
serb
parents:
20435
diff
changeset
|
659 |
@Override |
2 | 660 |
public void setEchoChar(char c) { |
661 |
super.setEchoChar(c); |
|
662 |
((AWTTextFieldUI)ui).installKeyboardActions(); |
|
663 |
} |
|
664 |
} |
|
665 |
} |