author | alexsch |
Mon, 07 Oct 2013 16:42:29 +0400 | |
changeset 20457 | ecb935d774a3 |
parent 20153 | d5bf90bfcb6d |
child 22060 | cd4f9d7dbeda |
child 23261 | 49117dc9e97c |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
15323
9087838098e6
8006417: JComboBox.showPopup(), hidePopup() fails in JRE 1.7 on OS X
alitvinov
parents:
14753
diff
changeset
|
2 |
* Copyright (c) 2011, 2013, Oracle and/or its affiliates. All rights reserved. |
12047 | 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 |
|
7 |
* published by the Free Software Foundation. Oracle designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Oracle in the LICENSE file that accompanied this code. |
|
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 |
* |
|
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. |
|
24 |
*/ |
|
25 |
||
26 |
package sun.lwawt; |
|
27 |
||
28 |
import java.awt.*; |
|
29 |
import java.awt.List; |
|
30 |
import java.awt.datatransfer.*; |
|
31 |
import java.awt.dnd.*; |
|
32 |
import java.awt.dnd.peer.*; |
|
33 |
import java.awt.image.*; |
|
34 |
import java.awt.peer.*; |
|
35 |
import java.security.*; |
|
36 |
import java.util.*; |
|
37 |
||
38 |
import sun.awt.*; |
|
39 |
import sun.lwawt.macosx.*; |
|
40 |
import sun.print.*; |
|
19807
9f7860fad128
8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents:
18251
diff
changeset
|
41 |
import sun.security.util.SecurityConstants; |
12047 | 42 |
|
43 |
public abstract class LWToolkit extends SunToolkit implements Runnable { |
|
44 |
||
45 |
private final static int STATE_NONE = 0; |
|
46 |
private final static int STATE_INIT = 1; |
|
47 |
private final static int STATE_MESSAGELOOP = 2; |
|
48 |
private final static int STATE_SHUTDOWN = 3; |
|
49 |
private final static int STATE_CLEANUP = 4; |
|
50 |
private final static int STATE_DONE = 5; |
|
51 |
||
52 |
private int runState = STATE_NONE; |
|
53 |
||
54 |
private Clipboard clipboard; |
|
55 |
private MouseInfoPeer mouseInfoPeer; |
|
56 |
||
17410
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
57 |
/** |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
58 |
* Dynamic Layout Resize client code setting. |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
59 |
*/ |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
60 |
private volatile boolean dynamicLayoutSetting = true; |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
61 |
|
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
62 |
protected LWToolkit() { |
12047 | 63 |
} |
64 |
||
65 |
/* |
|
66 |
* This method is called by subclasses to start this toolkit |
|
67 |
* by launching the message loop. |
|
68 |
* |
|
69 |
* This method waits for the toolkit to be completely initialized |
|
70 |
* and returns before the message pump is started. |
|
71 |
*/ |
|
72 |
protected final void init() { |
|
73 |
AWTAutoShutdown.notifyToolkitThreadBusy(); |
|
74 |
||
75 |
ThreadGroup mainTG = AccessController.doPrivileged( |
|
76 |
new PrivilegedAction<ThreadGroup>() { |
|
77 |
public ThreadGroup run() { |
|
78 |
ThreadGroup currentTG = Thread.currentThread().getThreadGroup(); |
|
79 |
ThreadGroup parentTG = currentTG.getParent(); |
|
80 |
while (parentTG != null) { |
|
81 |
currentTG = parentTG; |
|
82 |
parentTG = currentTG.getParent(); |
|
83 |
} |
|
84 |
return currentTG; |
|
85 |
} |
|
86 |
} |
|
87 |
); |
|
88 |
||
89 |
Runtime.getRuntime().addShutdownHook( |
|
90 |
new Thread(mainTG, new Runnable() { |
|
91 |
public void run() { |
|
92 |
shutdown(); |
|
93 |
waitForRunState(STATE_CLEANUP); |
|
94 |
} |
|
95 |
}) |
|
96 |
); |
|
97 |
||
98 |
Thread toolkitThread = new Thread(mainTG, this, "AWT-LW"); |
|
99 |
toolkitThread.setDaemon(true); |
|
100 |
toolkitThread.setPriority(Thread.NORM_PRIORITY + 1); |
|
101 |
toolkitThread.start(); |
|
102 |
||
103 |
waitForRunState(STATE_MESSAGELOOP); |
|
104 |
} |
|
105 |
||
106 |
/* |
|
107 |
* Implemented in subclasses to initialize platform-dependent |
|
108 |
* part of the toolkit (open X display connection, create |
|
109 |
* toolkit HWND, etc.) |
|
110 |
* |
|
111 |
* This method is called on the toolkit thread. |
|
112 |
*/ |
|
113 |
protected abstract void platformInit(); |
|
114 |
||
115 |
/* |
|
116 |
* Sends a request to stop the message pump. |
|
117 |
*/ |
|
118 |
public void shutdown() { |
|
119 |
setRunState(STATE_SHUTDOWN); |
|
120 |
platformShutdown(); |
|
121 |
} |
|
122 |
||
123 |
/* |
|
124 |
* Implemented in subclasses to release all the platform- |
|
125 |
* dependent resources. Called after the message loop is |
|
126 |
* terminated. |
|
127 |
* |
|
128 |
* Could be called (always called?) on a non-toolkit thread. |
|
129 |
*/ |
|
130 |
protected abstract void platformShutdown(); |
|
131 |
||
132 |
/* |
|
133 |
* Implemented in subclasses to release all the platform |
|
134 |
* resources before the application is terminated. |
|
135 |
* |
|
136 |
* This method is called on the toolkit thread. |
|
137 |
*/ |
|
138 |
protected abstract void platformCleanup(); |
|
139 |
||
140 |
private synchronized int getRunState() { |
|
141 |
return runState; |
|
142 |
} |
|
143 |
||
144 |
private synchronized void setRunState(int state) { |
|
145 |
runState = state; |
|
146 |
notifyAll(); |
|
147 |
} |
|
148 |
||
149 |
public boolean isTerminating() { |
|
150 |
return getRunState() >= STATE_SHUTDOWN; |
|
151 |
} |
|
152 |
||
153 |
private void waitForRunState(int state) { |
|
154 |
while (getRunState() < state) { |
|
155 |
try { |
|
156 |
synchronized (this) { |
|
157 |
wait(); |
|
158 |
} |
|
159 |
} catch (InterruptedException z) { |
|
160 |
// TODO: log |
|
161 |
break; |
|
162 |
} |
|
163 |
} |
|
164 |
} |
|
165 |
||
166 |
public void run() { |
|
167 |
setRunState(STATE_INIT); |
|
168 |
platformInit(); |
|
169 |
AWTAutoShutdown.notifyToolkitThreadFree(); |
|
170 |
setRunState(STATE_MESSAGELOOP); |
|
171 |
while (getRunState() < STATE_SHUTDOWN) { |
|
172 |
try { |
|
173 |
platformRunMessage(); |
|
174 |
if (Thread.currentThread().isInterrupted()) { |
|
175 |
if (AppContext.getAppContext().isDisposed()) { |
|
176 |
break; |
|
177 |
} |
|
178 |
} |
|
179 |
} catch (ThreadDeath td) { |
|
180 |
//XXX: if there isn't native code on the stack, the VM just |
|
181 |
//kills the thread right away. Do we expect to catch it |
|
182 |
//nevertheless? |
|
183 |
break; |
|
184 |
} catch (Throwable t) { |
|
185 |
// TODO: log |
|
186 |
System.err.println("Exception on the toolkit thread"); |
|
187 |
t.printStackTrace(System.err); |
|
188 |
} |
|
189 |
} |
|
190 |
//XXX: if that's a secondary loop, jump back to the STATE_MESSAGELOOP |
|
191 |
setRunState(STATE_CLEANUP); |
|
192 |
AWTAutoShutdown.notifyToolkitThreadFree(); |
|
193 |
platformCleanup(); |
|
194 |
setRunState(STATE_DONE); |
|
195 |
} |
|
196 |
||
197 |
/* |
|
198 |
* Process the next message(s) from the native event queue. |
|
199 |
* |
|
200 |
* Initially, all the LWToolkit implementations were supposed |
|
201 |
* to have the similar message loop sequence: check if any events |
|
202 |
* available, peek events, wait. However, the later analysis shown |
|
203 |
* that X11 and Windows implementations are really different, so |
|
204 |
* let the subclasses do whatever they require. |
|
205 |
*/ |
|
206 |
protected abstract void platformRunMessage(); |
|
207 |
||
208 |
public static LWToolkit getLWToolkit() { |
|
209 |
return (LWToolkit)Toolkit.getDefaultToolkit(); |
|
210 |
} |
|
211 |
||
212 |
// ---- TOPLEVEL PEERS ---- // |
|
213 |
||
214 |
/* |
|
215 |
* Note that LWWindowPeer implements WindowPeer, FramePeer |
|
216 |
* and DialogPeer interfaces. |
|
217 |
*/ |
|
218 |
private LWWindowPeer createDelegatedPeer(Window target, PlatformComponent platformComponent, |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
219 |
PlatformWindow platformWindow, LWWindowPeer.PeerType peerType) |
12047 | 220 |
{ |
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
221 |
LWWindowPeer peer = new LWWindowPeer(target, platformComponent, platformWindow, peerType); |
12047 | 222 |
targetCreatedPeer(target, peer); |
223 |
peer.initialize(); |
|
224 |
return peer; |
|
225 |
} |
|
226 |
||
15983
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
227 |
private LWLightweightFramePeer createDelegatedLwPeer(LightweightFrame target, |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
228 |
PlatformComponent platformComponent, |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
229 |
PlatformWindow platformWindow) |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
230 |
{ |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
231 |
LWLightweightFramePeer peer = new LWLightweightFramePeer(target, platformComponent, platformWindow); |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
232 |
targetCreatedPeer(target, peer); |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
233 |
peer.initialize(); |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
234 |
return peer; |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
235 |
} |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
236 |
|
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
237 |
@Override |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
238 |
public FramePeer createLightweightFrame(LightweightFrame target) { |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
239 |
PlatformComponent platformComponent = createLwPlatformComponent(); |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
240 |
PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.LW_FRAME); |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
241 |
return createDelegatedLwPeer(target, platformComponent, platformWindow); |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
242 |
} |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
243 |
|
12047 | 244 |
@Override |
245 |
public WindowPeer createWindow(Window target) { |
|
246 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
247 |
PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.SIMPLEWINDOW); |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
248 |
return createDelegatedPeer(target, platformComponent, platformWindow, LWWindowPeer.PeerType.SIMPLEWINDOW); |
12047 | 249 |
} |
250 |
||
251 |
@Override |
|
252 |
public FramePeer createFrame(Frame target) { |
|
253 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
254 |
PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.FRAME); |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
255 |
return createDelegatedPeer(target, platformComponent, platformWindow, LWWindowPeer.PeerType.FRAME); |
12047 | 256 |
} |
257 |
||
258 |
public LWWindowPeer createEmbeddedFrame(CEmbeddedFrame target) { |
|
259 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
260 |
PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.EMBEDDED_FRAME); |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
261 |
return createDelegatedPeer(target, platformComponent, platformWindow, LWWindowPeer.PeerType.EMBEDDED_FRAME); |
12047 | 262 |
} |
263 |
||
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
264 |
public LWWindowPeer createEmbeddedFrame(CViewEmbeddedFrame target) { |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
265 |
PlatformComponent platformComponent = createPlatformComponent(); |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
266 |
PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.VIEW_EMBEDDED_FRAME); |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
267 |
return createDelegatedPeer(target, platformComponent, platformWindow, LWWindowPeer.PeerType.VIEW_EMBEDDED_FRAME); |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
268 |
} |
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
269 |
|
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
270 |
|
12047 | 271 |
CPrinterDialogPeer createCPrinterDialog(CPrinterDialog target) { |
272 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
273 |
PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.DIALOG); |
|
274 |
CPrinterDialogPeer peer = new CPrinterDialogPeer(target, platformComponent, platformWindow); |
|
275 |
targetCreatedPeer(target, peer); |
|
276 |
return peer; |
|
277 |
} |
|
278 |
||
279 |
@Override |
|
280 |
public DialogPeer createDialog(Dialog target) { |
|
281 |
if (target instanceof CPrinterDialog) { |
|
282 |
return createCPrinterDialog((CPrinterDialog)target); |
|
283 |
} |
|
284 |
||
285 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
286 |
PlatformWindow platformWindow = createPlatformWindow(LWWindowPeer.PeerType.DIALOG); |
|
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
287 |
return createDelegatedPeer(target, platformComponent, platformWindow, LWWindowPeer.PeerType.DIALOG); |
12047 | 288 |
} |
289 |
||
290 |
@Override |
|
291 |
public FileDialogPeer createFileDialog(FileDialog target) { |
|
292 |
FileDialogPeer peer = createFileDialogPeer(target); |
|
293 |
targetCreatedPeer(target, peer); |
|
294 |
return peer; |
|
295 |
} |
|
296 |
||
297 |
// ---- LIGHTWEIGHT COMPONENT PEERS ---- // |
|
298 |
||
299 |
@Override |
|
300 |
public ButtonPeer createButton(Button target) { |
|
301 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
302 |
LWButtonPeer peer = new LWButtonPeer(target, platformComponent); |
|
303 |
targetCreatedPeer(target, peer); |
|
304 |
peer.initialize(); |
|
305 |
return peer; |
|
306 |
} |
|
307 |
||
308 |
@Override |
|
309 |
public CheckboxPeer createCheckbox(Checkbox target) { |
|
310 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
311 |
LWCheckboxPeer peer = new LWCheckboxPeer(target, platformComponent); |
|
312 |
targetCreatedPeer(target, peer); |
|
313 |
peer.initialize(); |
|
314 |
return peer; |
|
315 |
} |
|
316 |
||
317 |
@Override |
|
318 |
public CheckboxMenuItemPeer createCheckboxMenuItem(CheckboxMenuItem target) { |
|
319 |
throw new RuntimeException("not implemented"); |
|
320 |
} |
|
321 |
||
322 |
@Override |
|
323 |
public ChoicePeer createChoice(Choice target) { |
|
324 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
325 |
LWChoicePeer peer = new LWChoicePeer(target, platformComponent); |
|
326 |
targetCreatedPeer(target, peer); |
|
327 |
peer.initialize(); |
|
328 |
return peer; |
|
329 |
} |
|
330 |
||
331 |
@Override |
|
332 |
public LabelPeer createLabel(Label target) { |
|
333 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
334 |
LWLabelPeer peer = new LWLabelPeer(target, platformComponent); |
|
335 |
targetCreatedPeer(target, peer); |
|
336 |
peer.initialize(); |
|
337 |
return peer; |
|
338 |
} |
|
339 |
||
340 |
@Override |
|
341 |
public CanvasPeer createCanvas(Canvas target) { |
|
342 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
13993 | 343 |
LWCanvasPeer<?, ?> peer = new LWCanvasPeer<>(target, platformComponent); |
12047 | 344 |
targetCreatedPeer(target, peer); |
345 |
peer.initialize(); |
|
346 |
return peer; |
|
347 |
} |
|
348 |
||
349 |
@Override |
|
350 |
public ListPeer createList(List target) { |
|
351 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
352 |
LWListPeer peer = new LWListPeer(target, platformComponent); |
|
353 |
targetCreatedPeer(target, peer); |
|
354 |
peer.initialize(); |
|
355 |
return peer; |
|
356 |
} |
|
357 |
||
358 |
@Override |
|
359 |
public MenuPeer createMenu(Menu target) { |
|
360 |
throw new RuntimeException("not implemented"); |
|
361 |
} |
|
362 |
||
363 |
@Override |
|
364 |
public MenuBarPeer createMenuBar(MenuBar target) { |
|
365 |
throw new RuntimeException("not implemented"); |
|
366 |
} |
|
367 |
||
368 |
@Override |
|
369 |
public MenuItemPeer createMenuItem(MenuItem target) { |
|
370 |
throw new RuntimeException("not implemented"); |
|
371 |
} |
|
372 |
||
373 |
@Override |
|
374 |
public PanelPeer createPanel(Panel target) { |
|
375 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
376 |
LWPanelPeer peer = new LWPanelPeer(target, platformComponent); |
|
377 |
targetCreatedPeer(target, peer); |
|
378 |
peer.initialize(); |
|
379 |
return peer; |
|
380 |
} |
|
381 |
||
382 |
@Override |
|
383 |
public PopupMenuPeer createPopupMenu(PopupMenu target) { |
|
384 |
throw new RuntimeException("not implemented"); |
|
385 |
} |
|
386 |
||
387 |
@Override |
|
388 |
public ScrollPanePeer createScrollPane(ScrollPane target) { |
|
389 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
390 |
LWScrollPanePeer peer = new LWScrollPanePeer(target, platformComponent); |
|
391 |
targetCreatedPeer(target, peer); |
|
392 |
peer.initialize(); |
|
393 |
return peer; |
|
394 |
} |
|
395 |
||
396 |
@Override |
|
397 |
public ScrollbarPeer createScrollbar(Scrollbar target) { |
|
398 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
399 |
LWScrollBarPeer peer = new LWScrollBarPeer(target, platformComponent); |
|
400 |
targetCreatedPeer(target, peer); |
|
401 |
peer.initialize(); |
|
402 |
return peer; |
|
403 |
} |
|
404 |
||
405 |
@Override |
|
406 |
public TextAreaPeer createTextArea(TextArea target) { |
|
407 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
408 |
LWTextAreaPeer peer = new LWTextAreaPeer(target, platformComponent); |
|
409 |
targetCreatedPeer(target, peer); |
|
410 |
peer.initialize(); |
|
411 |
return peer; |
|
412 |
} |
|
413 |
||
414 |
@Override |
|
415 |
public TextFieldPeer createTextField(TextField target) { |
|
416 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
417 |
LWTextFieldPeer peer = new LWTextFieldPeer(target, platformComponent); |
|
418 |
targetCreatedPeer(target, peer); |
|
419 |
peer.initialize(); |
|
420 |
return peer; |
|
421 |
} |
|
422 |
||
423 |
// ---- NON-COMPONENT PEERS ---- // |
|
424 |
||
425 |
@Override |
|
426 |
public ColorModel getColorModel() throws HeadlessException { |
|
427 |
return GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice().getDefaultConfiguration().getColorModel(); |
|
428 |
} |
|
429 |
||
430 |
@Override |
|
431 |
public boolean isDesktopSupported() { |
|
432 |
return true; |
|
433 |
} |
|
434 |
||
435 |
@Override |
|
436 |
protected DesktopPeer createDesktopPeer(Desktop target) { |
|
437 |
return new CDesktopPeer(); |
|
438 |
} |
|
439 |
||
440 |
@Override |
|
441 |
public DragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) { |
|
442 |
DragSourceContextPeer dscp = CDragSourceContextPeer.createDragSourceContextPeer(dge); |
|
443 |
||
444 |
return dscp; |
|
445 |
} |
|
446 |
||
447 |
@Override |
|
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13233
diff
changeset
|
448 |
public KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() { |
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13233
diff
changeset
|
449 |
return LWKeyboardFocusManagerPeer.getInstance(); |
12047 | 450 |
} |
451 |
||
452 |
@Override |
|
453 |
public synchronized MouseInfoPeer getMouseInfoPeer() { |
|
454 |
if (mouseInfoPeer == null) { |
|
455 |
mouseInfoPeer = createMouseInfoPeerImpl(); |
|
456 |
} |
|
457 |
return mouseInfoPeer; |
|
458 |
} |
|
459 |
||
460 |
protected MouseInfoPeer createMouseInfoPeerImpl() { |
|
461 |
return new LWMouseInfoPeer(); |
|
462 |
} |
|
463 |
||
464 |
public PrintJob getPrintJob(Frame frame, String doctitle, Properties props) { |
|
465 |
return getPrintJob(frame, doctitle, null, null); |
|
466 |
} |
|
467 |
||
468 |
public PrintJob getPrintJob(Frame frame, String doctitle, JobAttributes jobAttributes, PageAttributes pageAttributes) { |
|
469 |
if (GraphicsEnvironment.isHeadless()) { |
|
470 |
throw new IllegalArgumentException(); |
|
471 |
} |
|
472 |
||
473 |
PrintJob2D printJob = new PrintJob2D(frame, doctitle, jobAttributes, pageAttributes); |
|
474 |
||
475 |
if (printJob.printDialog() == false) { |
|
476 |
printJob = null; |
|
477 |
} |
|
478 |
||
479 |
return printJob; |
|
480 |
} |
|
481 |
||
482 |
@Override |
|
483 |
public RobotPeer createRobot(Robot target, GraphicsDevice screen) { |
|
484 |
throw new RuntimeException("not implemented"); |
|
485 |
} |
|
486 |
||
487 |
@Override |
|
488 |
public boolean isTraySupported() { |
|
489 |
throw new RuntimeException("not implemented"); |
|
490 |
} |
|
491 |
||
492 |
@Override |
|
493 |
public SystemTrayPeer createSystemTray(SystemTray target) { |
|
494 |
throw new RuntimeException("not implemented"); |
|
495 |
} |
|
496 |
||
497 |
@Override |
|
498 |
public TrayIconPeer createTrayIcon(TrayIcon target) { |
|
499 |
throw new RuntimeException("not implemented"); |
|
500 |
} |
|
501 |
||
502 |
@Override |
|
503 |
public Clipboard getSystemClipboard() { |
|
504 |
SecurityManager security = System.getSecurityManager(); |
|
505 |
if (security != null) { |
|
19807
9f7860fad128
8008981: Deprecate SecurityManager checkTopLevelWindow, checkSystemClipboardAccess, checkAwtEventQueueAccess
alanb
parents:
18251
diff
changeset
|
506 |
security.checkPermission(SecurityConstants.AWT.ACCESS_CLIPBOARD_PERMISSION); |
12047 | 507 |
} |
508 |
||
509 |
synchronized (this) { |
|
510 |
if (clipboard == null) { |
|
511 |
clipboard = createPlatformClipboard(); |
|
512 |
} |
|
513 |
} |
|
514 |
return clipboard; |
|
515 |
} |
|
516 |
||
18241 | 517 |
protected abstract SecurityWarningWindow createSecurityWarning(Window ownerWindow, LWWindowPeer ownerPeer); |
518 |
||
12047 | 519 |
// ---- DELEGATES ---- // |
520 |
||
521 |
public abstract Clipboard createPlatformClipboard(); |
|
522 |
||
523 |
/* |
|
524 |
* Creates a delegate for the given peer type (window, frame, dialog, etc.) |
|
525 |
*/ |
|
526 |
protected abstract PlatformWindow createPlatformWindow(LWWindowPeer.PeerType peerType); |
|
527 |
||
528 |
protected abstract PlatformComponent createPlatformComponent(); |
|
529 |
||
15983
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
530 |
protected abstract PlatformComponent createLwPlatformComponent(); |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
531 |
|
12047 | 532 |
protected abstract FileDialogPeer createFileDialogPeer(FileDialog target); |
533 |
||
534 |
// ---- UTILITY METHODS ---- // |
|
535 |
||
536 |
/* |
|
537 |
* Expose non-public targetToPeer() method. |
|
538 |
*/ |
|
539 |
public final static Object targetToPeer(Object target) { |
|
540 |
return SunToolkit.targetToPeer(target); |
|
541 |
} |
|
542 |
||
543 |
/* |
|
544 |
* Expose non-public targetDisposedPeer() method. |
|
545 |
*/ |
|
546 |
public final static void targetDisposedPeer(Object target, Object peer) { |
|
547 |
SunToolkit.targetDisposedPeer(target, peer); |
|
548 |
} |
|
549 |
||
550 |
/* |
|
551 |
* Returns the current cursor manager. |
|
552 |
*/ |
|
553 |
public abstract LWCursorManager getCursorManager(); |
|
554 |
||
555 |
public static void postEvent(AWTEvent event) { |
|
556 |
postEvent(targetToAppContext(event.getSource()), event); |
|
557 |
} |
|
558 |
||
559 |
@Override |
|
20153 | 560 |
public void grab(final Window w) { |
561 |
final Object peer = AWTAccessor.getComponentAccessor().getPeer(w); |
|
562 |
if (peer != null) { |
|
563 |
((LWWindowPeer) peer).grab(); |
|
12047 | 564 |
} |
565 |
} |
|
566 |
||
567 |
@Override |
|
20153 | 568 |
public void ungrab(final Window w) { |
569 |
final Object peer = AWTAccessor.getComponentAccessor().getPeer(w); |
|
570 |
if (peer != null) { |
|
571 |
((LWWindowPeer) peer).ungrab(false); |
|
12047 | 572 |
} |
573 |
} |
|
17410
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
574 |
|
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
575 |
@Override |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
576 |
protected final Object lazilyLoadDesktopProperty(final String name) { |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
577 |
if (name.equals("awt.dynamicLayoutSupported")) { |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
578 |
return isDynamicLayoutSupported(); |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
579 |
} |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
580 |
return super.lazilyLoadDesktopProperty(name); |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
581 |
} |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
582 |
|
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
583 |
@Override |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
584 |
public final void setDynamicLayout(final boolean dynamic) { |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
585 |
dynamicLayoutSetting = dynamic; |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
586 |
} |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
587 |
|
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
588 |
@Override |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
589 |
protected final boolean isDynamicLayoutSet() { |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
590 |
return dynamicLayoutSetting; |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
591 |
} |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
592 |
|
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
593 |
@Override |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
594 |
public final boolean isDynamicLayoutActive() { |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
595 |
// "Live resizing" is active by default and user's data is ignored. |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
596 |
return isDynamicLayoutSupported(); |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
597 |
} |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
598 |
|
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
599 |
/** |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
600 |
* Returns true if dynamic layout of Containers on resize is supported by |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
601 |
* the underlying operating system and/or window manager. |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
602 |
*/ |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
603 |
protected final boolean isDynamicLayoutSupported() { |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
604 |
// "Live resizing" is supported by default. |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
605 |
return true; |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
606 |
} |
12047 | 607 |
} |