author | mcherkas |
Mon, 28 Jul 2014 16:09:26 +0400 | |
changeset 26008 | ccab11700f07 |
parent 24551 | cccf7dd14729 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
2 |
* Copyright (c) 2011, 2014, 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.*; |
|
24551
cccf7dd14729
8042219: [macosx] LWComponentPeer should not reference classes from sun.lwawt.macosx
pchelko
parents:
24520
diff
changeset
|
31 |
import java.awt.dnd.DropTarget; |
12047 | 32 |
import java.awt.image.*; |
33 |
import java.awt.peer.*; |
|
34 |
import java.security.*; |
|
35 |
import java.util.*; |
|
36 |
||
37 |
import sun.awt.*; |
|
38 |
import sun.print.*; |
|
24520
e8afd90fcb69
8035169: Move ThreadGroupUtils from the sun.misc package
pchelko
parents:
23900
diff
changeset
|
39 |
import sun.awt.util.ThreadGroupUtils; |
12047 | 40 |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
41 |
import static sun.lwawt.LWWindowPeer.PeerType; |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
42 |
|
12047 | 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 |
||
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23276
diff
changeset
|
75 |
ThreadGroup rootTG = AccessController.doPrivileged( |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23276
diff
changeset
|
76 |
(PrivilegedAction<ThreadGroup>) ThreadGroupUtils::getRootThreadGroup); |
12047 | 77 |
|
78 |
Runtime.getRuntime().addShutdownHook( |
|
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23276
diff
changeset
|
79 |
new Thread(rootTG, () -> { |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23276
diff
changeset
|
80 |
shutdown(); |
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23276
diff
changeset
|
81 |
waitForRunState(STATE_CLEANUP); |
12047 | 82 |
}) |
83 |
); |
|
84 |
||
23900
fd98305f0d19
8031477: [macosx] Loading AWT native library fails
pchelko
parents:
23276
diff
changeset
|
85 |
Thread toolkitThread = new Thread(rootTG, this, "AWT-LW"); |
12047 | 86 |
toolkitThread.setDaemon(true); |
87 |
toolkitThread.setPriority(Thread.NORM_PRIORITY + 1); |
|
88 |
toolkitThread.start(); |
|
89 |
||
90 |
waitForRunState(STATE_MESSAGELOOP); |
|
91 |
} |
|
92 |
||
93 |
/* |
|
94 |
* Implemented in subclasses to initialize platform-dependent |
|
95 |
* part of the toolkit (open X display connection, create |
|
96 |
* toolkit HWND, etc.) |
|
97 |
* |
|
98 |
* This method is called on the toolkit thread. |
|
99 |
*/ |
|
100 |
protected abstract void platformInit(); |
|
101 |
||
102 |
/* |
|
103 |
* Sends a request to stop the message pump. |
|
104 |
*/ |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
105 |
public final void shutdown() { |
12047 | 106 |
setRunState(STATE_SHUTDOWN); |
107 |
platformShutdown(); |
|
108 |
} |
|
109 |
||
110 |
/* |
|
111 |
* Implemented in subclasses to release all the platform- |
|
112 |
* dependent resources. Called after the message loop is |
|
113 |
* terminated. |
|
114 |
* |
|
115 |
* Could be called (always called?) on a non-toolkit thread. |
|
116 |
*/ |
|
117 |
protected abstract void platformShutdown(); |
|
118 |
||
119 |
/* |
|
120 |
* Implemented in subclasses to release all the platform |
|
121 |
* resources before the application is terminated. |
|
122 |
* |
|
123 |
* This method is called on the toolkit thread. |
|
124 |
*/ |
|
125 |
protected abstract void platformCleanup(); |
|
126 |
||
127 |
private synchronized int getRunState() { |
|
128 |
return runState; |
|
129 |
} |
|
130 |
||
131 |
private synchronized void setRunState(int state) { |
|
132 |
runState = state; |
|
133 |
notifyAll(); |
|
134 |
} |
|
135 |
||
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
136 |
public final boolean isTerminating() { |
12047 | 137 |
return getRunState() >= STATE_SHUTDOWN; |
138 |
} |
|
139 |
||
140 |
private void waitForRunState(int state) { |
|
141 |
while (getRunState() < state) { |
|
142 |
try { |
|
143 |
synchronized (this) { |
|
144 |
wait(); |
|
145 |
} |
|
146 |
} catch (InterruptedException z) { |
|
147 |
// TODO: log |
|
148 |
break; |
|
149 |
} |
|
150 |
} |
|
151 |
} |
|
152 |
||
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
153 |
@Override |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
154 |
public final void run() { |
12047 | 155 |
setRunState(STATE_INIT); |
156 |
platformInit(); |
|
157 |
AWTAutoShutdown.notifyToolkitThreadFree(); |
|
158 |
setRunState(STATE_MESSAGELOOP); |
|
159 |
while (getRunState() < STATE_SHUTDOWN) { |
|
160 |
try { |
|
161 |
platformRunMessage(); |
|
162 |
if (Thread.currentThread().isInterrupted()) { |
|
163 |
if (AppContext.getAppContext().isDisposed()) { |
|
164 |
break; |
|
165 |
} |
|
166 |
} |
|
167 |
} catch (ThreadDeath td) { |
|
168 |
//XXX: if there isn't native code on the stack, the VM just |
|
169 |
//kills the thread right away. Do we expect to catch it |
|
170 |
//nevertheless? |
|
171 |
break; |
|
172 |
} catch (Throwable t) { |
|
173 |
// TODO: log |
|
174 |
System.err.println("Exception on the toolkit thread"); |
|
175 |
t.printStackTrace(System.err); |
|
176 |
} |
|
177 |
} |
|
178 |
//XXX: if that's a secondary loop, jump back to the STATE_MESSAGELOOP |
|
179 |
setRunState(STATE_CLEANUP); |
|
180 |
AWTAutoShutdown.notifyToolkitThreadFree(); |
|
181 |
platformCleanup(); |
|
182 |
setRunState(STATE_DONE); |
|
183 |
} |
|
184 |
||
185 |
/* |
|
186 |
* Process the next message(s) from the native event queue. |
|
187 |
* |
|
188 |
* Initially, all the LWToolkit implementations were supposed |
|
189 |
* to have the similar message loop sequence: check if any events |
|
190 |
* available, peek events, wait. However, the later analysis shown |
|
191 |
* that X11 and Windows implementations are really different, so |
|
192 |
* let the subclasses do whatever they require. |
|
193 |
*/ |
|
194 |
protected abstract void platformRunMessage(); |
|
195 |
||
196 |
public static LWToolkit getLWToolkit() { |
|
197 |
return (LWToolkit)Toolkit.getDefaultToolkit(); |
|
198 |
} |
|
199 |
||
200 |
// ---- TOPLEVEL PEERS ---- // |
|
201 |
||
202 |
/* |
|
203 |
* Note that LWWindowPeer implements WindowPeer, FramePeer |
|
204 |
* and DialogPeer interfaces. |
|
205 |
*/ |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
206 |
protected LWWindowPeer createDelegatedPeer(Window target, |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
207 |
PlatformComponent platformComponent, |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
208 |
PlatformWindow platformWindow, |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
209 |
PeerType peerType) { |
14753
a56a685d137f
7154778: [macosx] NSView-based implementation of sun.awt.EmbeddedFrame
serb
parents:
13993
diff
changeset
|
210 |
LWWindowPeer peer = new LWWindowPeer(target, platformComponent, platformWindow, peerType); |
12047 | 211 |
targetCreatedPeer(target, peer); |
212 |
peer.initialize(); |
|
213 |
return peer; |
|
214 |
} |
|
215 |
||
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
216 |
@Override |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
217 |
public final FramePeer createLightweightFrame(LightweightFrame target) { |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
218 |
PlatformComponent platformComponent = createLwPlatformComponent(); |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
219 |
PlatformWindow platformWindow = createPlatformWindow(PeerType.LW_FRAME); |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
220 |
LWLightweightFramePeer peer = new LWLightweightFramePeer(target, |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
221 |
platformComponent, |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
222 |
platformWindow); |
15983
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
223 |
targetCreatedPeer(target, peer); |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
224 |
peer.initialize(); |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
225 |
return peer; |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
226 |
} |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
227 |
|
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
228 |
@Override |
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
229 |
public final WindowPeer createWindow(Window target) { |
12047 | 230 |
PlatformComponent platformComponent = createPlatformComponent(); |
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
231 |
PlatformWindow platformWindow = createPlatformWindow(PeerType.SIMPLEWINDOW); |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
232 |
return createDelegatedPeer(target, platformComponent, platformWindow, PeerType.SIMPLEWINDOW); |
12047 | 233 |
} |
234 |
||
235 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
236 |
public final FramePeer createFrame(Frame target) { |
12047 | 237 |
PlatformComponent platformComponent = createPlatformComponent(); |
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
238 |
PlatformWindow platformWindow = createPlatformWindow(PeerType.FRAME); |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
239 |
return createDelegatedPeer(target, platformComponent, platformWindow, PeerType.FRAME); |
12047 | 240 |
} |
241 |
||
242 |
@Override |
|
243 |
public DialogPeer createDialog(Dialog target) { |
|
244 |
PlatformComponent platformComponent = createPlatformComponent(); |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
245 |
PlatformWindow platformWindow = createPlatformWindow(PeerType.DIALOG); |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
246 |
return createDelegatedPeer(target, platformComponent, platformWindow, PeerType.DIALOG); |
12047 | 247 |
} |
248 |
||
249 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
250 |
public final FileDialogPeer createFileDialog(FileDialog target) { |
12047 | 251 |
FileDialogPeer peer = createFileDialogPeer(target); |
252 |
targetCreatedPeer(target, peer); |
|
253 |
return peer; |
|
254 |
} |
|
255 |
||
256 |
// ---- LIGHTWEIGHT COMPONENT PEERS ---- // |
|
257 |
||
258 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
259 |
public final ButtonPeer createButton(Button target) { |
12047 | 260 |
PlatformComponent platformComponent = createPlatformComponent(); |
261 |
LWButtonPeer peer = new LWButtonPeer(target, platformComponent); |
|
262 |
targetCreatedPeer(target, peer); |
|
263 |
peer.initialize(); |
|
264 |
return peer; |
|
265 |
} |
|
266 |
||
267 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
268 |
public final CheckboxPeer createCheckbox(Checkbox target) { |
12047 | 269 |
PlatformComponent platformComponent = createPlatformComponent(); |
270 |
LWCheckboxPeer peer = new LWCheckboxPeer(target, platformComponent); |
|
271 |
targetCreatedPeer(target, peer); |
|
272 |
peer.initialize(); |
|
273 |
return peer; |
|
274 |
} |
|
275 |
||
276 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
277 |
public final ChoicePeer createChoice(Choice target) { |
12047 | 278 |
PlatformComponent platformComponent = createPlatformComponent(); |
279 |
LWChoicePeer peer = new LWChoicePeer(target, platformComponent); |
|
280 |
targetCreatedPeer(target, peer); |
|
281 |
peer.initialize(); |
|
282 |
return peer; |
|
283 |
} |
|
284 |
||
285 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
286 |
public final LabelPeer createLabel(Label target) { |
12047 | 287 |
PlatformComponent platformComponent = createPlatformComponent(); |
288 |
LWLabelPeer peer = new LWLabelPeer(target, platformComponent); |
|
289 |
targetCreatedPeer(target, peer); |
|
290 |
peer.initialize(); |
|
291 |
return peer; |
|
292 |
} |
|
293 |
||
294 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
295 |
public final CanvasPeer createCanvas(Canvas target) { |
12047 | 296 |
PlatformComponent platformComponent = createPlatformComponent(); |
13993 | 297 |
LWCanvasPeer<?, ?> peer = new LWCanvasPeer<>(target, platformComponent); |
12047 | 298 |
targetCreatedPeer(target, peer); |
299 |
peer.initialize(); |
|
300 |
return peer; |
|
301 |
} |
|
302 |
||
303 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
304 |
public final ListPeer createList(List target) { |
12047 | 305 |
PlatformComponent platformComponent = createPlatformComponent(); |
306 |
LWListPeer peer = new LWListPeer(target, platformComponent); |
|
307 |
targetCreatedPeer(target, peer); |
|
308 |
peer.initialize(); |
|
309 |
return peer; |
|
310 |
} |
|
311 |
||
312 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
313 |
public final PanelPeer createPanel(Panel target) { |
12047 | 314 |
PlatformComponent platformComponent = createPlatformComponent(); |
315 |
LWPanelPeer peer = new LWPanelPeer(target, platformComponent); |
|
316 |
targetCreatedPeer(target, peer); |
|
317 |
peer.initialize(); |
|
318 |
return peer; |
|
319 |
} |
|
320 |
||
321 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
322 |
public final ScrollPanePeer createScrollPane(ScrollPane target) { |
12047 | 323 |
PlatformComponent platformComponent = createPlatformComponent(); |
324 |
LWScrollPanePeer peer = new LWScrollPanePeer(target, platformComponent); |
|
325 |
targetCreatedPeer(target, peer); |
|
326 |
peer.initialize(); |
|
327 |
return peer; |
|
328 |
} |
|
329 |
||
330 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
331 |
public final ScrollbarPeer createScrollbar(Scrollbar target) { |
12047 | 332 |
PlatformComponent platformComponent = createPlatformComponent(); |
333 |
LWScrollBarPeer peer = new LWScrollBarPeer(target, platformComponent); |
|
334 |
targetCreatedPeer(target, peer); |
|
335 |
peer.initialize(); |
|
336 |
return peer; |
|
337 |
} |
|
338 |
||
339 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
340 |
public final TextAreaPeer createTextArea(TextArea target) { |
12047 | 341 |
PlatformComponent platformComponent = createPlatformComponent(); |
342 |
LWTextAreaPeer peer = new LWTextAreaPeer(target, platformComponent); |
|
343 |
targetCreatedPeer(target, peer); |
|
344 |
peer.initialize(); |
|
345 |
return peer; |
|
346 |
} |
|
347 |
||
348 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
349 |
public final TextFieldPeer createTextField(TextField target) { |
12047 | 350 |
PlatformComponent platformComponent = createPlatformComponent(); |
351 |
LWTextFieldPeer peer = new LWTextFieldPeer(target, platformComponent); |
|
352 |
targetCreatedPeer(target, peer); |
|
353 |
peer.initialize(); |
|
354 |
return peer; |
|
355 |
} |
|
356 |
||
357 |
// ---- NON-COMPONENT PEERS ---- // |
|
358 |
||
359 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
360 |
public final ColorModel getColorModel() throws HeadlessException { |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
361 |
return GraphicsEnvironment.getLocalGraphicsEnvironment() |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
362 |
.getDefaultScreenDevice() |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
363 |
.getDefaultConfiguration().getColorModel(); |
12047 | 364 |
} |
365 |
||
366 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
367 |
public final boolean isDesktopSupported() { |
12047 | 368 |
return true; |
369 |
} |
|
370 |
||
371 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
372 |
public final KeyboardFocusManagerPeer getKeyboardFocusManagerPeer() { |
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13233
diff
changeset
|
373 |
return LWKeyboardFocusManagerPeer.getInstance(); |
12047 | 374 |
} |
375 |
||
376 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
377 |
public final synchronized MouseInfoPeer getMouseInfoPeer() { |
12047 | 378 |
if (mouseInfoPeer == null) { |
379 |
mouseInfoPeer = createMouseInfoPeerImpl(); |
|
380 |
} |
|
381 |
return mouseInfoPeer; |
|
382 |
} |
|
383 |
||
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
384 |
protected final MouseInfoPeer createMouseInfoPeerImpl() { |
12047 | 385 |
return new LWMouseInfoPeer(); |
386 |
} |
|
387 |
||
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
388 |
@Override |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
389 |
public final PrintJob getPrintJob(Frame frame, String doctitle, |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
390 |
Properties props) { |
12047 | 391 |
return getPrintJob(frame, doctitle, null, null); |
392 |
} |
|
393 |
||
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
394 |
@Override |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
395 |
public final PrintJob getPrintJob(Frame frame, String doctitle, |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
396 |
JobAttributes jobAttributes, |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
397 |
PageAttributes pageAttributes) { |
12047 | 398 |
if (GraphicsEnvironment.isHeadless()) { |
399 |
throw new IllegalArgumentException(); |
|
400 |
} |
|
401 |
||
402 |
PrintJob2D printJob = new PrintJob2D(frame, doctitle, jobAttributes, pageAttributes); |
|
403 |
||
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
404 |
if (!printJob.printDialog()) { |
12047 | 405 |
printJob = null; |
406 |
} |
|
407 |
||
408 |
return printJob; |
|
409 |
} |
|
410 |
||
411 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
412 |
public final Clipboard getSystemClipboard() { |
12047 | 413 |
SecurityManager security = System.getSecurityManager(); |
414 |
if (security != null) { |
|
22060
cd4f9d7dbeda
8029886: Change SecurityManager check{TopLevelWindow, SystemClipboardAccessAwtEventQueueAccess} to check AllPermission
alanb
parents:
20153
diff
changeset
|
415 |
security.checkPermission(AWTPermissions.ACCESS_CLIPBOARD_PERMISSION); |
12047 | 416 |
} |
417 |
||
418 |
synchronized (this) { |
|
419 |
if (clipboard == null) { |
|
420 |
clipboard = createPlatformClipboard(); |
|
421 |
} |
|
422 |
} |
|
423 |
return clipboard; |
|
424 |
} |
|
425 |
||
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
426 |
protected abstract SecurityWarningWindow createSecurityWarning( |
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
427 |
Window ownerWindow, LWWindowPeer ownerPeer); |
18241 | 428 |
|
12047 | 429 |
// ---- DELEGATES ---- // |
430 |
||
431 |
public abstract Clipboard createPlatformClipboard(); |
|
432 |
||
433 |
/* |
|
434 |
* Creates a delegate for the given peer type (window, frame, dialog, etc.) |
|
435 |
*/ |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
436 |
protected abstract PlatformWindow createPlatformWindow(PeerType peerType); |
12047 | 437 |
|
438 |
protected abstract PlatformComponent createPlatformComponent(); |
|
439 |
||
15983
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
440 |
protected abstract PlatformComponent createLwPlatformComponent(); |
26a673dec5b2
8006406: lightweight embedding in other Java UI toolkits
ant
parents:
15323
diff
changeset
|
441 |
|
12047 | 442 |
protected abstract FileDialogPeer createFileDialogPeer(FileDialog target); |
443 |
||
24551
cccf7dd14729
8042219: [macosx] LWComponentPeer should not reference classes from sun.lwawt.macosx
pchelko
parents:
24520
diff
changeset
|
444 |
protected abstract PlatformDropTarget createDropTarget(DropTarget dropTarget, |
cccf7dd14729
8042219: [macosx] LWComponentPeer should not reference classes from sun.lwawt.macosx
pchelko
parents:
24520
diff
changeset
|
445 |
Component component, |
cccf7dd14729
8042219: [macosx] LWComponentPeer should not reference classes from sun.lwawt.macosx
pchelko
parents:
24520
diff
changeset
|
446 |
LWComponentPeer<?, ?> peer); |
cccf7dd14729
8042219: [macosx] LWComponentPeer should not reference classes from sun.lwawt.macosx
pchelko
parents:
24520
diff
changeset
|
447 |
|
12047 | 448 |
// ---- UTILITY METHODS ---- // |
449 |
||
450 |
/* |
|
451 |
* Expose non-public targetToPeer() method. |
|
452 |
*/ |
|
453 |
public final static Object targetToPeer(Object target) { |
|
454 |
return SunToolkit.targetToPeer(target); |
|
455 |
} |
|
456 |
||
457 |
/* |
|
458 |
* Expose non-public targetDisposedPeer() method. |
|
459 |
*/ |
|
460 |
public final static void targetDisposedPeer(Object target, Object peer) { |
|
461 |
SunToolkit.targetDisposedPeer(target, peer); |
|
462 |
} |
|
463 |
||
464 |
/* |
|
465 |
* Returns the current cursor manager. |
|
466 |
*/ |
|
467 |
public abstract LWCursorManager getCursorManager(); |
|
468 |
||
469 |
public static void postEvent(AWTEvent event) { |
|
470 |
postEvent(targetToAppContext(event.getSource()), event); |
|
471 |
} |
|
472 |
||
473 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
474 |
public final void grab(final Window w) { |
20153 | 475 |
final Object peer = AWTAccessor.getComponentAccessor().getPeer(w); |
476 |
if (peer != null) { |
|
477 |
((LWWindowPeer) peer).grab(); |
|
12047 | 478 |
} |
479 |
} |
|
480 |
||
481 |
@Override |
|
23261
49117dc9e97c
8031090: [macosx] LWToolkit should not depends from the macosx.
serb
parents:
20153
diff
changeset
|
482 |
public final void ungrab(final Window w) { |
20153 | 483 |
final Object peer = AWTAccessor.getComponentAccessor().getPeer(w); |
484 |
if (peer != null) { |
|
485 |
((LWWindowPeer) peer).ungrab(false); |
|
12047 | 486 |
} |
487 |
} |
|
17410
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
488 |
|
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
489 |
@Override |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
490 |
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
|
491 |
if (name.equals("awt.dynamicLayoutSupported")) { |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
492 |
return isDynamicLayoutSupported(); |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
493 |
} |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
494 |
return super.lazilyLoadDesktopProperty(name); |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
495 |
} |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
496 |
|
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
497 |
@Override |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
498 |
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
|
499 |
dynamicLayoutSetting = dynamic; |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
500 |
} |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
501 |
|
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
502 |
@Override |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
503 |
protected final boolean isDynamicLayoutSet() { |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
504 |
return dynamicLayoutSetting; |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
505 |
} |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
506 |
|
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
507 |
@Override |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
508 |
public final boolean isDynamicLayoutActive() { |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
509 |
// "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
|
510 |
return isDynamicLayoutSupported(); |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
511 |
} |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
512 |
|
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
513 |
/** |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
514 |
* 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
|
515 |
* 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
|
516 |
*/ |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
517 |
protected final boolean isDynamicLayoutSupported() { |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
518 |
// "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
|
519 |
return true; |
c9c726c5ce7e
7161575: [macosx] On MacOSX port java.awt.Toolkit.is/setDynamicLayout() are not consistent
serb
parents:
15983
diff
changeset
|
520 |
} |
12047 | 521 |
} |