author | serb |
Mon, 24 Sep 2012 21:33:41 +0400 | |
changeset 13993 | 8b3fe3d8badb |
parent 13652 | 42544e68dc39 |
child 14647 | bacc2d4f4b27 |
permissions | -rw-r--r-- |
12047 | 1 |
/* |
2 |
* Copyright (c) 2011, 2012, Oracle and/or its affiliates. All rights reserved. |
|
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 |
||
27 |
package sun.lwawt; |
|
28 |
||
29 |
import java.awt.*; |
|
30 |
||
31 |
import java.awt.dnd.DropTarget; |
|
32 |
import java.awt.dnd.peer.DropTargetPeer; |
|
33 |
import java.awt.event.*; |
|
34 |
||
35 |
import java.awt.image.ColorModel; |
|
36 |
import java.awt.image.ImageObserver; |
|
37 |
import java.awt.image.ImageProducer; |
|
38 |
import java.awt.image.VolatileImage; |
|
39 |
||
40 |
import java.awt.peer.ComponentPeer; |
|
41 |
import java.awt.peer.ContainerPeer; |
|
42 |
||
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13544
diff
changeset
|
43 |
import java.awt.peer.KeyboardFocusManagerPeer; |
12047 | 44 |
import java.util.concurrent.atomic.AtomicBoolean; |
45 |
import java.lang.reflect.Field; |
|
46 |
import java.security.AccessController; |
|
47 |
import java.security.PrivilegedAction; |
|
48 |
||
49 |
import sun.awt.*; |
|
50 |
||
51 |
import sun.awt.event.IgnorePaintEvent; |
|
52 |
||
53 |
import sun.awt.image.SunVolatileImage; |
|
54 |
import sun.awt.image.ToolkitImage; |
|
55 |
||
56 |
import sun.java2d.SunGraphics2D; |
|
57 |
import sun.java2d.opengl.OGLRenderQueue; |
|
58 |
import sun.java2d.pipe.Region; |
|
59 |
||
12662
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
60 |
import sun.util.logging.PlatformLogger; |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
61 |
|
12047 | 62 |
import javax.swing.JComponent; |
63 |
import javax.swing.SwingUtilities; |
|
64 |
import javax.swing.RepaintManager; |
|
65 |
||
66 |
import sun.lwawt.macosx.CDropTarget; |
|
67 |
||
68 |
import com.sun.java.swing.SwingUtilities3; |
|
69 |
||
70 |
public abstract class LWComponentPeer<T extends Component, D extends JComponent> |
|
12662
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
71 |
implements ComponentPeer, DropTargetPeer |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
72 |
{ |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
73 |
private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.lwawt.focus.LWComponentPeer"); |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
74 |
|
12047 | 75 |
// State lock is to be used for modifications to this |
76 |
// peer's fields (e.g. bounds, background, font, etc.) |
|
77 |
// It should be the last lock in the lock chain |
|
78 |
private final Object stateLock = |
|
79 |
new StringBuilder("LWComponentPeer.stateLock"); |
|
80 |
||
81 |
// The lock to operate with the peers hierarchy. AWT tree |
|
82 |
// lock is not used as there are many peers related ops |
|
83 |
// to be done on the toolkit thread, and we don't want to |
|
84 |
// depend on a public lock on this thread |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
85 |
private static final Object peerTreeLock = |
12047 | 86 |
new StringBuilder("LWComponentPeer.peerTreeLock"); |
87 |
||
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
88 |
private final T target; |
12047 | 89 |
|
90 |
// Container peer. It may not be the peer of the target's direct |
|
91 |
// parent, for example, in the case of hw/lw mixing. However, |
|
92 |
// let's skip this scenario for the time being. We also assume |
|
93 |
// the container peer is not null, which might also be false if |
|
94 |
// addNotify() is called for a component outside of the hierarchy. |
|
95 |
// The exception is LWWindowPeers: their parents are always null |
|
96 |
private LWContainerPeer containerPeer; |
|
97 |
||
98 |
// Handy reference to the top-level window peer. Window peer is |
|
99 |
// borrowed from the containerPeer in constructor, and should also |
|
100 |
// be updated when the component is reparented to another container |
|
101 |
private LWWindowPeer windowPeer; |
|
102 |
||
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
103 |
private final AtomicBoolean disposed = new AtomicBoolean(false); |
12047 | 104 |
|
105 |
// Bounds are relative to parent peer |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
106 |
private final Rectangle bounds = new Rectangle(); |
12047 | 107 |
private Region region; |
108 |
||
109 |
// Component state. Should be accessed under the state lock |
|
110 |
private boolean visible = false; |
|
111 |
private boolean enabled = true; |
|
112 |
||
113 |
private Color background; |
|
114 |
private Color foreground; |
|
115 |
private Font font; |
|
116 |
||
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
117 |
/** |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
118 |
* Paint area to coalesce all the paint events and store the target dirty |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
119 |
* area. |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
120 |
*/ |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
121 |
private final RepaintArea targetPaintArea; |
12047 | 122 |
|
123 |
// private volatile boolean paintPending; |
|
124 |
private volatile boolean isLayouting; |
|
125 |
||
13993 | 126 |
private final D delegate; |
12047 | 127 |
private Container delegateContainer; |
128 |
private Component delegateDropTarget; |
|
129 |
private final Object dropTargetLock = new Object(); |
|
130 |
||
131 |
private int fNumDropTargets = 0; |
|
132 |
private CDropTarget fDropTarget = null; |
|
133 |
||
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
134 |
private final PlatformComponent platformComponent; |
12047 | 135 |
|
13993 | 136 |
/** |
137 |
* Character with reasonable value between the minimum width and maximum. |
|
138 |
*/ |
|
139 |
static final char WIDE_CHAR = '0'; |
|
140 |
||
12047 | 141 |
private final class DelegateContainer extends Container { |
142 |
{ |
|
143 |
enableEvents(0xFFFFFFFF); |
|
144 |
} |
|
145 |
||
146 |
DelegateContainer() { |
|
147 |
super(); |
|
148 |
} |
|
149 |
||
150 |
@Override |
|
151 |
public boolean isLightweight() { |
|
152 |
return false; |
|
153 |
} |
|
154 |
||
155 |
@Override |
|
156 |
public Point getLocation() { |
|
157 |
return getLocationOnScreen(); |
|
158 |
} |
|
159 |
||
160 |
@Override |
|
161 |
public Point getLocationOnScreen() { |
|
162 |
return LWComponentPeer.this.getLocationOnScreen(); |
|
163 |
} |
|
164 |
||
165 |
@Override |
|
166 |
public int getX() { |
|
167 |
return getLocation().x; |
|
168 |
} |
|
169 |
||
170 |
@Override |
|
171 |
public int getY() { |
|
172 |
return getLocation().y; |
|
173 |
} |
|
174 |
} |
|
175 |
||
176 |
public LWComponentPeer(T target, PlatformComponent platformComponent) { |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
177 |
targetPaintArea = new LWRepaintArea(); |
12047 | 178 |
this.target = target; |
179 |
this.platformComponent = platformComponent; |
|
180 |
||
181 |
initializeContainerPeer(); |
|
182 |
// Container peer is always null for LWWindowPeers, so |
|
183 |
// windowPeer is always null for them as well. On the other |
|
184 |
// hand, LWWindowPeer shouldn't use windowPeer at all |
|
185 |
if (containerPeer != null) { |
|
186 |
windowPeer = containerPeer.getWindowPeerOrSelf(); |
|
187 |
} |
|
188 |
// don't bother about z-order here as updateZOrder() |
|
189 |
// will be called from addNotify() later anyway |
|
190 |
if (containerPeer != null) { |
|
191 |
containerPeer.addChildPeer(this); |
|
192 |
} |
|
193 |
||
194 |
// the delegate must be created after the target is set |
|
195 |
AWTEventListener toolkitListener = null; |
|
196 |
synchronized (Toolkit.getDefaultToolkit()) { |
|
197 |
try { |
|
198 |
toolkitListener = getToolkitAWTEventListener(); |
|
199 |
setToolkitAWTEventListener(null); |
|
200 |
||
201 |
synchronized (getDelegateLock()) { |
|
202 |
delegate = createDelegate(); |
|
203 |
if (delegate != null) { |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
204 |
delegate.setVisible(false); |
12047 | 205 |
delegateContainer = new DelegateContainer(); |
206 |
delegateContainer.add(delegate); |
|
207 |
delegateContainer.addNotify(); |
|
208 |
delegate.addNotify(); |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
209 |
resetColorsAndFont(delegate); |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
210 |
delegate.setOpaque(true); |
12047 | 211 |
} else { |
212 |
return; |
|
213 |
} |
|
214 |
} |
|
215 |
||
216 |
} finally { |
|
217 |
setToolkitAWTEventListener(toolkitListener); |
|
218 |
} |
|
219 |
||
220 |
// todo swing: later on we will probably have one global RM |
|
221 |
SwingUtilities3.setDelegateRepaintManager(delegate, new RepaintManager() { |
|
222 |
@Override |
|
223 |
public void addDirtyRegion(final JComponent c, final int x, final int y, final int w, final int h) { |
|
12398 | 224 |
repaintPeer(SwingUtilities.convertRectangle( |
225 |
c, new Rectangle(x, y, w, h), getDelegate())); |
|
12047 | 226 |
} |
227 |
}); |
|
228 |
} |
|
229 |
} |
|
230 |
||
231 |
/** |
|
232 |
* This method must be called under Toolkit.getDefaultToolkit() lock |
|
233 |
* and followed by setToolkitAWTEventListener() |
|
234 |
*/ |
|
235 |
protected final AWTEventListener getToolkitAWTEventListener() { |
|
236 |
return AccessController.doPrivileged(new PrivilegedAction<AWTEventListener>() { |
|
237 |
public AWTEventListener run() { |
|
238 |
Toolkit toolkit = Toolkit.getDefaultToolkit(); |
|
239 |
try { |
|
240 |
Field field = Toolkit.class.getDeclaredField("eventListener"); |
|
241 |
field.setAccessible(true); |
|
242 |
return (AWTEventListener) field.get(toolkit); |
|
243 |
} catch (Exception e) { |
|
244 |
throw new InternalError(e.toString()); |
|
245 |
} |
|
246 |
} |
|
247 |
}); |
|
248 |
} |
|
249 |
||
250 |
protected final void setToolkitAWTEventListener(final AWTEventListener listener) { |
|
251 |
AccessController.doPrivileged(new PrivilegedAction<Void>() { |
|
252 |
public Void run() { |
|
253 |
Toolkit toolkit = Toolkit.getDefaultToolkit(); |
|
254 |
try { |
|
255 |
Field field = Toolkit.class.getDeclaredField("eventListener"); |
|
256 |
field.setAccessible(true); |
|
257 |
field.set(toolkit, listener); |
|
258 |
} catch (Exception e) { |
|
259 |
throw new InternalError(e.toString()); |
|
260 |
} |
|
261 |
return null; |
|
262 |
} |
|
263 |
}); |
|
264 |
} |
|
265 |
||
266 |
/** |
|
267 |
* This method is called under getDelegateLock(). |
|
268 |
* Overridden in subclasses. |
|
269 |
*/ |
|
270 |
protected D createDelegate() { |
|
271 |
return null; |
|
272 |
} |
|
273 |
||
274 |
protected final D getDelegate() { |
|
13993 | 275 |
return delegate; |
12047 | 276 |
} |
277 |
||
278 |
protected Component getDelegateFocusOwner() { |
|
279 |
return getDelegate(); |
|
280 |
} |
|
281 |
||
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
282 |
/** |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
283 |
* Initializes this peer. The call to initialize() is not placed to |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
284 |
* LWComponentPeer ctor to let the subclass ctor to finish completely first. |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
285 |
* Instead, it's the LWToolkit object who is responsible for initialization. |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
286 |
* Note that we call setVisible() at the end of initialization. |
12047 | 287 |
*/ |
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
288 |
public final void initialize() { |
13544
bd136eb2a932
7172187: [macosx] JAWT native CALayer not positioned over Canvas
serb
parents:
13233
diff
changeset
|
289 |
platformComponent.initialize(getPlatformWindow()); |
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
290 |
initializeImpl(); |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
291 |
setVisible(target.isVisible()); |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
292 |
} |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
293 |
|
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
294 |
/** |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
295 |
* Fetching general properties from the target. Should be overridden in |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
296 |
* subclasses to initialize specific peers properties. |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
297 |
*/ |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
298 |
void initializeImpl() { |
12047 | 299 |
setBackground(target.getBackground()); |
300 |
setForeground(target.getForeground()); |
|
301 |
setFont(target.getFont()); |
|
302 |
setBounds(target.getBounds()); |
|
303 |
setEnabled(target.isEnabled()); |
|
304 |
} |
|
305 |
||
306 |
private static void resetColorsAndFont(final Container c) { |
|
307 |
c.setBackground(null); |
|
308 |
c.setForeground(null); |
|
309 |
c.setFont(null); |
|
310 |
for (int i = 0; i < c.getComponentCount(); i++) { |
|
311 |
resetColorsAndFont((Container) c.getComponent(i)); |
|
312 |
} |
|
313 |
} |
|
314 |
||
315 |
final Object getStateLock() { |
|
316 |
return stateLock; |
|
317 |
} |
|
318 |
||
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
319 |
/** |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
320 |
* Synchronize all operations with the Swing delegates under AWT tree lock, |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
321 |
* using a new separate lock to synchronize access to delegates may lead |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
322 |
* deadlocks. Think of it as a 'virtual EDT'. |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
323 |
* |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
324 |
* @return DelegateLock |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
325 |
*/ |
12047 | 326 |
final Object getDelegateLock() { |
327 |
return getTarget().getTreeLock(); |
|
328 |
} |
|
329 |
||
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
330 |
protected static final Object getPeerTreeLock() { |
12047 | 331 |
return peerTreeLock; |
332 |
} |
|
333 |
||
334 |
final T getTarget() { |
|
335 |
return target; |
|
336 |
} |
|
337 |
||
338 |
// Just a helper method |
|
339 |
// Returns the window peer or null if this is a window peer |
|
340 |
protected final LWWindowPeer getWindowPeer() { |
|
341 |
return windowPeer; |
|
342 |
} |
|
343 |
||
344 |
// Returns the window peer or 'this' if this is a window peer |
|
345 |
protected LWWindowPeer getWindowPeerOrSelf() { |
|
346 |
return getWindowPeer(); |
|
347 |
} |
|
348 |
||
349 |
// Just a helper method |
|
350 |
protected final LWContainerPeer getContainerPeer() { |
|
351 |
return containerPeer; |
|
352 |
} |
|
353 |
||
354 |
// Just a helper method |
|
355 |
// Overridden in LWWindowPeer to skip containerPeer initialization |
|
356 |
protected void initializeContainerPeer() { |
|
357 |
Container parent = LWToolkit.getNativeContainer(target); |
|
358 |
if (parent != null) { |
|
359 |
containerPeer = (LWContainerPeer) LWToolkit.targetToPeer(parent); |
|
360 |
} |
|
361 |
} |
|
362 |
||
363 |
public PlatformWindow getPlatformWindow() { |
|
364 |
LWWindowPeer windowPeer = getWindowPeer(); |
|
365 |
return windowPeer.getPlatformWindow(); |
|
366 |
} |
|
367 |
||
368 |
protected AppContext getAppContext() { |
|
369 |
return SunToolkit.targetToAppContext(getTarget()); |
|
370 |
} |
|
371 |
||
372 |
// ---- PEER METHODS ---- // |
|
373 |
||
374 |
@Override |
|
375 |
public Toolkit getToolkit() { |
|
376 |
return LWToolkit.getLWToolkit(); |
|
377 |
} |
|
378 |
||
379 |
// Just a helper method |
|
380 |
public LWToolkit getLWToolkit() { |
|
381 |
return LWToolkit.getLWToolkit(); |
|
382 |
} |
|
383 |
||
384 |
@Override |
|
12639
c1634bcec0a8
7160623: [macosx] Editable TextArea/TextField are blocking GUI applications from exit
serb
parents:
12416
diff
changeset
|
385 |
public final void dispose() { |
12047 | 386 |
if (disposed.compareAndSet(false, true)) { |
387 |
disposeImpl(); |
|
388 |
} |
|
389 |
} |
|
390 |
||
391 |
protected void disposeImpl() { |
|
392 |
LWContainerPeer cp = getContainerPeer(); |
|
393 |
if (cp != null) { |
|
394 |
cp.removeChildPeer(this); |
|
395 |
} |
|
396 |
platformComponent.dispose(); |
|
397 |
LWToolkit.targetDisposedPeer(getTarget(), this); |
|
398 |
} |
|
399 |
||
400 |
public final boolean isDisposed() { |
|
401 |
return disposed.get(); |
|
402 |
} |
|
403 |
||
404 |
/* |
|
405 |
* GraphicsConfiguration is borrowed from the parent peer. The |
|
406 |
* return value must not be null. |
|
407 |
* |
|
408 |
* Overridden in LWWindowPeer. |
|
409 |
*/ |
|
410 |
@Override |
|
411 |
public GraphicsConfiguration getGraphicsConfiguration() { |
|
412 |
// Don't check windowPeer for null as it can only happen |
|
413 |
// for windows, but this method is overridden in |
|
414 |
// LWWindowPeer and doesn't call super() |
|
415 |
return getWindowPeer().getGraphicsConfiguration(); |
|
416 |
} |
|
417 |
||
418 |
/* |
|
419 |
* Overridden in LWWindowPeer to replace its surface |
|
420 |
* data and back buffer. |
|
421 |
*/ |
|
422 |
@Override |
|
423 |
public boolean updateGraphicsData(GraphicsConfiguration gc) { |
|
424 |
// TODO: not implemented |
|
425 |
// throw new RuntimeException("Has not been implemented yet."); |
|
426 |
return false; |
|
427 |
} |
|
428 |
||
429 |
@Override |
|
430 |
public final Graphics getGraphics() { |
|
13233 | 431 |
final Graphics g = getOnscreenGraphics(); |
12047 | 432 |
if (g != null) { |
433 |
synchronized (getPeerTreeLock()){ |
|
434 |
applyConstrain(g); |
|
435 |
} |
|
436 |
} |
|
437 |
return g; |
|
438 |
} |
|
439 |
||
440 |
/* |
|
441 |
* Peer Graphics is borrowed from the parent peer, while |
|
442 |
* foreground and background colors and font are specific to |
|
443 |
* this peer. |
|
444 |
*/ |
|
445 |
public final Graphics getOnscreenGraphics() { |
|
446 |
final LWWindowPeer wp = getWindowPeerOrSelf(); |
|
447 |
return wp.getOnscreenGraphics(getForeground(), getBackground(), |
|
448 |
getFont()); |
|
449 |
||
450 |
} |
|
451 |
||
452 |
private void applyConstrain(final Graphics g) { |
|
453 |
final SunGraphics2D sg2d = (SunGraphics2D) g; |
|
454 |
final Rectangle constr = localToWindow(getSize()); |
|
455 |
// translate and set rectangle constrain. |
|
456 |
sg2d.constrain(constr.x, constr.y, constr.width, constr.height); |
|
457 |
// set region constrain. |
|
458 |
//sg2d.constrain(getVisibleRegion()); |
|
459 |
SG2DConstraint(sg2d, getVisibleRegion()); |
|
460 |
} |
|
461 |
||
462 |
//TODO Move this method to SG2D? |
|
13233 | 463 |
void SG2DConstraint(final SunGraphics2D sg2d, Region r) { |
12047 | 464 |
sg2d.constrainX = sg2d.transX; |
465 |
sg2d.constrainY = sg2d.transY; |
|
466 |
||
467 |
Region c = sg2d.constrainClip; |
|
468 |
if ((sg2d.constrainX | sg2d.constrainY) != 0) { |
|
469 |
r = r.getTranslatedRegion(sg2d.constrainX, sg2d.constrainY); |
|
470 |
} |
|
471 |
if (c == null) { |
|
472 |
c = r; |
|
473 |
} else { |
|
474 |
c = c.getIntersection(r); |
|
475 |
if (c == sg2d.constrainClip) { |
|
476 |
// Common case to ignore |
|
477 |
return; |
|
478 |
} |
|
479 |
} |
|
480 |
sg2d.constrainClip = c; |
|
481 |
//validateCompClip() forced call. |
|
482 |
sg2d.setDevClip(r.getLoX(), r.getLoY(), r.getWidth(), r.getHeight()); |
|
483 |
} |
|
484 |
||
485 |
public Region getVisibleRegion() { |
|
486 |
return computeVisibleRect(this, getRegion()); |
|
487 |
} |
|
488 |
||
489 |
static final Region computeVisibleRect(LWComponentPeer c, Region region) { |
|
490 |
final LWContainerPeer p = c.getContainerPeer(); |
|
491 |
if (p != null) { |
|
492 |
final Rectangle r = c.getBounds(); |
|
493 |
region = region.getTranslatedRegion(r.x, r.y); |
|
494 |
region = region.getIntersection(p.getRegion()); |
|
495 |
region = region.getIntersection(p.getContentSize()); |
|
496 |
region = p.cutChildren(region, c); |
|
497 |
region = computeVisibleRect(p, region); |
|
498 |
region = region.getTranslatedRegion(-r.x, -r.y); |
|
499 |
} |
|
500 |
return region; |
|
501 |
} |
|
502 |
||
503 |
@Override |
|
504 |
public ColorModel getColorModel() { |
|
505 |
// Is it a correct implementation? |
|
506 |
return getGraphicsConfiguration().getColorModel(); |
|
507 |
} |
|
508 |
||
509 |
@Override |
|
510 |
public void createBuffers(int numBuffers, BufferCapabilities caps) |
|
511 |
throws AWTException { |
|
512 |
throw new AWTException("Back buffers are only supported for " + |
|
513 |
"Window or Canvas components."); |
|
514 |
} |
|
515 |
||
516 |
/* |
|
517 |
* To be overridden in LWWindowPeer and LWCanvasPeer. |
|
518 |
*/ |
|
519 |
@Override |
|
520 |
public Image getBackBuffer() { |
|
521 |
// Return null or throw AWTException? |
|
522 |
return null; |
|
523 |
} |
|
524 |
||
525 |
@Override |
|
526 |
public void flip(int x1, int y1, int x2, int y2, |
|
527 |
BufferCapabilities.FlipContents flipAction) { |
|
528 |
// Skip silently or throw AWTException? |
|
529 |
} |
|
530 |
||
531 |
@Override |
|
532 |
public void destroyBuffers() { |
|
533 |
// Do nothing |
|
534 |
} |
|
535 |
||
536 |
// Helper method |
|
537 |
public void setBounds(Rectangle r) { |
|
538 |
setBounds(r.x, r.y, r.width, r.height, SET_BOUNDS); |
|
539 |
} |
|
540 |
||
541 |
/** |
|
542 |
* This method could be called on the toolkit thread. |
|
543 |
*/ |
|
544 |
@Override |
|
545 |
public void setBounds(int x, int y, int w, int h, int op) { |
|
546 |
setBounds(x, y, w, h, op, true, false); |
|
547 |
} |
|
548 |
||
549 |
protected void setBounds(int x, int y, int w, int h, int op, boolean notify, |
|
550 |
final boolean updateTarget) { |
|
551 |
Rectangle oldBounds; |
|
552 |
synchronized (getStateLock()) { |
|
553 |
oldBounds = new Rectangle(bounds); |
|
554 |
if ((op & (SET_LOCATION | SET_BOUNDS)) != 0) { |
|
555 |
bounds.x = x; |
|
556 |
bounds.y = y; |
|
557 |
} |
|
558 |
if ((op & (SET_SIZE | SET_BOUNDS)) != 0) { |
|
559 |
bounds.width = w; |
|
560 |
bounds.height = h; |
|
561 |
} |
|
562 |
} |
|
563 |
boolean moved = (oldBounds.x != x) || (oldBounds.y != y); |
|
564 |
boolean resized = (oldBounds.width != w) || (oldBounds.height != h); |
|
565 |
if (!moved && !resized) { |
|
566 |
return; |
|
567 |
} |
|
568 |
final D delegate = getDelegate(); |
|
569 |
if (delegate != null) { |
|
570 |
synchronized (getDelegateLock()) { |
|
571 |
delegateContainer.setBounds(0, 0, w, h); |
|
572 |
delegate.setBounds(delegateContainer.getBounds()); |
|
573 |
// TODO: the following means that the delegateContainer NEVER gets validated. That's WRONG! |
|
574 |
delegate.validate(); |
|
575 |
} |
|
576 |
} |
|
577 |
||
578 |
final Point locationInWindow = localToWindow(0, 0); |
|
579 |
platformComponent.setBounds(locationInWindow.x, locationInWindow.y, w, |
|
580 |
h); |
|
581 |
if (notify) { |
|
582 |
repaintOldNewBounds(oldBounds); |
|
583 |
if (resized) { |
|
584 |
handleResize(w, h, updateTarget); |
|
585 |
} |
|
586 |
if (moved) { |
|
587 |
handleMove(x, y, updateTarget); |
|
588 |
} |
|
589 |
} |
|
590 |
} |
|
591 |
||
592 |
public final Rectangle getBounds() { |
|
593 |
synchronized (getStateLock()) { |
|
594 |
// Return a copy to prevent subsequent modifications |
|
595 |
return bounds.getBounds(); |
|
596 |
} |
|
597 |
} |
|
598 |
||
599 |
public final Rectangle getSize() { |
|
600 |
synchronized (getStateLock()) { |
|
601 |
// Return a copy to prevent subsequent modifications |
|
602 |
return new Rectangle(bounds.width, bounds.height); |
|
603 |
} |
|
604 |
} |
|
605 |
||
606 |
@Override |
|
607 |
public Point getLocationOnScreen() { |
|
608 |
Point windowLocation = getWindowPeer().getLocationOnScreen(); |
|
609 |
Point locationInWindow = localToWindow(0, 0); |
|
610 |
return new Point(windowLocation.x + locationInWindow.x, |
|
611 |
windowLocation.y + locationInWindow.y); |
|
612 |
} |
|
613 |
||
12396
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12047
diff
changeset
|
614 |
/** |
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12047
diff
changeset
|
615 |
* Returns the cursor of the peer, which is cursor of the target by default, |
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12047
diff
changeset
|
616 |
* but peer can override this behavior. |
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12047
diff
changeset
|
617 |
* |
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12047
diff
changeset
|
618 |
* @param p Point relative to the peer. |
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12047
diff
changeset
|
619 |
* @return Cursor of the peer or null if default cursor should be used. |
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12047
diff
changeset
|
620 |
*/ |
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12047
diff
changeset
|
621 |
protected Cursor getCursor(final Point p) { |
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12047
diff
changeset
|
622 |
return getTarget().getCursor(); |
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12047
diff
changeset
|
623 |
} |
79c64c6eb61e
7150105: [macosx] four scroll-buttons don't display. scroll-sliders cursors are TextCursor.
serb
parents:
12047
diff
changeset
|
624 |
|
12047 | 625 |
@Override |
626 |
public void setBackground(final Color c) { |
|
627 |
final Color oldBg = getBackground(); |
|
628 |
if (oldBg == c || (oldBg != null && oldBg.equals(c))) { |
|
629 |
return; |
|
630 |
} |
|
631 |
synchronized (getStateLock()) { |
|
632 |
background = c; |
|
633 |
} |
|
634 |
final D delegate = getDelegate(); |
|
635 |
if (delegate != null) { |
|
636 |
synchronized (getDelegateLock()) { |
|
637 |
// delegate will repaint the target |
|
638 |
delegate.setBackground(c); |
|
639 |
} |
|
640 |
} else { |
|
641 |
repaintPeer(); |
|
642 |
} |
|
643 |
} |
|
644 |
||
645 |
protected final Color getBackground() { |
|
646 |
synchronized (getStateLock()) { |
|
647 |
return background; |
|
648 |
} |
|
649 |
} |
|
650 |
||
651 |
@Override |
|
652 |
public void setForeground(final Color c) { |
|
653 |
final Color oldFg = getForeground(); |
|
654 |
if (oldFg == c || (oldFg != null && oldFg.equals(c))) { |
|
655 |
return; |
|
656 |
} |
|
657 |
synchronized (getStateLock()) { |
|
658 |
foreground = c; |
|
659 |
} |
|
660 |
final D delegate = getDelegate(); |
|
661 |
if (delegate != null) { |
|
662 |
synchronized (getDelegateLock()) { |
|
663 |
// delegate will repaint the target |
|
664 |
delegate.setForeground(c); |
|
665 |
} |
|
666 |
} else { |
|
667 |
repaintPeer(); |
|
668 |
} |
|
669 |
} |
|
670 |
||
671 |
protected final Color getForeground() { |
|
672 |
synchronized (getStateLock()) { |
|
673 |
return foreground; |
|
674 |
} |
|
675 |
} |
|
676 |
||
677 |
@Override |
|
678 |
public void setFont(final Font f) { |
|
679 |
final Font oldF = getFont(); |
|
680 |
if (oldF == f || (oldF != null && oldF.equals(f))) { |
|
681 |
return; |
|
682 |
} |
|
683 |
synchronized (getStateLock()) { |
|
684 |
font = f; |
|
685 |
} |
|
686 |
final D delegate = getDelegate(); |
|
687 |
if (delegate != null) { |
|
688 |
synchronized (getDelegateLock()) { |
|
689 |
// delegate will repaint the target |
|
690 |
delegate.setFont(f); |
|
691 |
} |
|
692 |
} else { |
|
693 |
repaintPeer(); |
|
694 |
} |
|
695 |
} |
|
696 |
||
697 |
protected final Font getFont() { |
|
698 |
synchronized (getStateLock()) { |
|
699 |
return font; |
|
700 |
} |
|
701 |
} |
|
702 |
||
703 |
@Override |
|
13993 | 704 |
public FontMetrics getFontMetrics(final Font f) { |
12047 | 705 |
// Borrow the metrics from the top-level window |
706 |
// return getWindowPeer().getFontMetrics(f); |
|
707 |
// Obtain the metrics from the offscreen window where this peer is |
|
708 |
// mostly drawn to. |
|
709 |
// TODO: check for "use platform metrics" settings |
|
13993 | 710 |
final Graphics g = getOnscreenGraphics(); |
711 |
if (g != null) { |
|
712 |
try { |
|
12047 | 713 |
return g.getFontMetrics(f); |
13993 | 714 |
} finally { |
12047 | 715 |
g.dispose(); |
716 |
} |
|
717 |
} |
|
13993 | 718 |
synchronized (getDelegateLock()) { |
719 |
return delegateContainer.getFontMetrics(f); |
|
720 |
} |
|
12047 | 721 |
} |
722 |
||
723 |
@Override |
|
724 |
public void setEnabled(final boolean e) { |
|
725 |
boolean status = e; |
|
726 |
final LWComponentPeer cp = getContainerPeer(); |
|
727 |
if (cp != null) { |
|
728 |
status &= cp.isEnabled(); |
|
729 |
} |
|
730 |
synchronized (getStateLock()) { |
|
731 |
if (enabled == status) { |
|
732 |
return; |
|
733 |
} |
|
734 |
enabled = status; |
|
735 |
} |
|
736 |
||
737 |
final D delegate = getDelegate(); |
|
738 |
||
739 |
if (delegate != null) { |
|
740 |
synchronized (getDelegateLock()) { |
|
741 |
delegate.setEnabled(status); |
|
742 |
} |
|
743 |
} else { |
|
744 |
repaintPeer(); |
|
745 |
} |
|
746 |
} |
|
747 |
||
748 |
// Helper method |
|
749 |
public final boolean isEnabled() { |
|
750 |
synchronized (getStateLock()) { |
|
751 |
return enabled; |
|
752 |
} |
|
753 |
} |
|
754 |
||
755 |
@Override |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
756 |
public void setVisible(final boolean v) { |
12047 | 757 |
synchronized (getStateLock()) { |
758 |
if (visible == v) { |
|
759 |
return; |
|
760 |
} |
|
761 |
visible = v; |
|
762 |
} |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
763 |
setVisibleImpl(v); |
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
764 |
} |
12047 | 765 |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
766 |
protected void setVisibleImpl(final boolean v) { |
12047 | 767 |
final D delegate = getDelegate(); |
768 |
||
769 |
if (delegate != null) { |
|
770 |
synchronized (getDelegateLock()) { |
|
771 |
delegate.setVisible(v); |
|
772 |
} |
|
773 |
} |
|
774 |
if (visible) { |
|
775 |
repaintPeer(); |
|
776 |
} else { |
|
777 |
repaintParent(getBounds()); |
|
778 |
} |
|
779 |
} |
|
780 |
||
781 |
// Helper method |
|
782 |
public final boolean isVisible() { |
|
783 |
synchronized (getStateLock()) { |
|
784 |
return visible; |
|
785 |
} |
|
786 |
} |
|
787 |
||
788 |
@Override |
|
789 |
public void paint(final Graphics g) { |
|
790 |
getTarget().paint(g); |
|
791 |
} |
|
792 |
||
793 |
@Override |
|
794 |
public void print(final Graphics g) { |
|
795 |
getTarget().print(g); |
|
796 |
} |
|
797 |
||
798 |
@Override |
|
799 |
public void reparent(ContainerPeer newContainer) { |
|
800 |
// TODO: not implemented |
|
801 |
throw new UnsupportedOperationException("ComponentPeer.reparent()"); |
|
802 |
} |
|
803 |
||
804 |
@Override |
|
805 |
public boolean isReparentSupported() { |
|
806 |
// TODO: not implemented |
|
807 |
return false; |
|
808 |
} |
|
809 |
||
810 |
@Override |
|
811 |
public void setZOrder(ComponentPeer above) { |
|
812 |
LWContainerPeer cp = getContainerPeer(); |
|
813 |
// Don't check containerPeer for null as it can only happen |
|
814 |
// for windows, but this method is overridden in |
|
815 |
// LWWindowPeer and doesn't call super() |
|
816 |
cp.setChildPeerZOrder(this, (LWComponentPeer) above); |
|
817 |
} |
|
818 |
||
819 |
@Override |
|
820 |
public void coalescePaintEvent(PaintEvent e) { |
|
821 |
if (!(e instanceof IgnorePaintEvent)) { |
|
822 |
Rectangle r = e.getUpdateRect(); |
|
823 |
if ((r != null) && !r.isEmpty()) { |
|
824 |
targetPaintArea.add(r, e.getID()); |
|
825 |
} |
|
826 |
} |
|
827 |
} |
|
828 |
||
829 |
/* |
|
830 |
* Should be overridden in subclasses which use complex Swing components. |
|
831 |
*/ |
|
832 |
@Override |
|
833 |
public void layout() { |
|
834 |
// TODO: not implemented |
|
835 |
} |
|
836 |
||
837 |
@Override |
|
838 |
public boolean isObscured() { |
|
839 |
// TODO: not implemented |
|
840 |
return false; |
|
841 |
} |
|
842 |
||
843 |
@Override |
|
844 |
public boolean canDetermineObscurity() { |
|
845 |
// TODO: not implemented |
|
846 |
return false; |
|
847 |
} |
|
848 |
||
849 |
/** |
|
13993 | 850 |
* Determines the preferred size of the component. By default forwards the |
851 |
* request to the Swing helper component. Should be overridden in subclasses |
|
852 |
* if required. |
|
12047 | 853 |
*/ |
854 |
@Override |
|
855 |
public Dimension getPreferredSize() { |
|
13993 | 856 |
final Dimension size; |
857 |
synchronized (getDelegateLock()) { |
|
858 |
size = getDelegate().getPreferredSize(); |
|
859 |
} |
|
860 |
return validateSize(size); |
|
12047 | 861 |
} |
862 |
||
13993 | 863 |
/** |
864 |
* Determines the minimum size of the component. By default forwards the |
|
865 |
* request to the Swing helper component. Should be overridden in subclasses |
|
866 |
* if required. |
|
12047 | 867 |
*/ |
868 |
@Override |
|
869 |
public Dimension getMinimumSize() { |
|
13993 | 870 |
final Dimension size; |
871 |
synchronized (getDelegateLock()) { |
|
872 |
size = getDelegate().getMinimumSize(); |
|
873 |
} |
|
874 |
return validateSize(size); |
|
875 |
} |
|
12047 | 876 |
|
13993 | 877 |
/** |
878 |
* In some situations delegates can return empty minimum/preferred size. |
|
879 |
* (For example: empty JLabel, etc), but awt components never should be |
|
880 |
* empty. In the XPeers or WPeers we use some magic constants, but here we |
|
881 |
* try to use something more useful, |
|
882 |
*/ |
|
883 |
private Dimension validateSize(final Dimension size) { |
|
884 |
if (size.width == 0 || size.height == 0) { |
|
885 |
final FontMetrics fm = getFontMetrics(getFont()); |
|
886 |
size.width = fm.charWidth(WIDE_CHAR); |
|
887 |
size.height = fm.getHeight(); |
|
12047 | 888 |
} |
13993 | 889 |
return size; |
12047 | 890 |
} |
891 |
||
892 |
@Override |
|
893 |
public void updateCursorImmediately() { |
|
894 |
getLWToolkit().getCursorManager().updateCursor(); |
|
895 |
} |
|
896 |
||
897 |
@Override |
|
898 |
public boolean isFocusable() { |
|
899 |
// Overridden in focusable subclasses like buttons |
|
900 |
return false; |
|
901 |
} |
|
902 |
||
903 |
@Override |
|
904 |
public boolean requestFocus(Component lightweightChild, boolean temporary, |
|
905 |
boolean focusedWindowChangeAllowed, long time, |
|
12662
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
906 |
CausedFocusEvent.Cause cause) |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
907 |
{ |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
908 |
if (focusLog.isLoggable(PlatformLogger.FINEST)) { |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
909 |
focusLog.finest("lightweightChild=" + lightweightChild + ", temporary=" + temporary + |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
910 |
", focusedWindowChangeAllowed=" + focusedWindowChangeAllowed + |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
911 |
", time= " + time + ", cause=" + cause); |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
912 |
} |
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13544
diff
changeset
|
913 |
if (LWKeyboardFocusManagerPeer.processSynchronousLightweightTransfer( |
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13544
diff
changeset
|
914 |
getTarget(), lightweightChild, temporary, |
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13544
diff
changeset
|
915 |
focusedWindowChangeAllowed, time)) { |
12047 | 916 |
return true; |
917 |
} |
|
918 |
||
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13544
diff
changeset
|
919 |
int result = LWKeyboardFocusManagerPeer.shouldNativelyFocusHeavyweight( |
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13544
diff
changeset
|
920 |
getTarget(), lightweightChild, temporary, |
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13544
diff
changeset
|
921 |
focusedWindowChangeAllowed, time, cause); |
12047 | 922 |
switch (result) { |
923 |
case LWKeyboardFocusManagerPeer.SNFH_FAILURE: |
|
924 |
return false; |
|
925 |
case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED: |
|
926 |
Window parentWindow = SunToolkit.getContainingWindow(getTarget()); |
|
927 |
if (parentWindow == null) { |
|
12662
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
928 |
focusLog.fine("request rejected, parentWindow is null"); |
12047 | 929 |
LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget()); |
930 |
return false; |
|
931 |
} |
|
932 |
LWWindowPeer parentPeer = (LWWindowPeer) parentWindow.getPeer(); |
|
933 |
if (parentPeer == null) { |
|
12662
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
934 |
focusLog.fine("request rejected, parentPeer is null"); |
12047 | 935 |
LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget()); |
936 |
return false; |
|
937 |
} |
|
938 |
||
12662
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
939 |
// A fix for 7145768. Ensure the parent window is currently natively focused. |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
940 |
// The more evident place to perform this check is in KFM.shouldNativelyFocusHeavyweight, |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
941 |
// however that is the shared code and this particular problem's reproducibility has |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
942 |
// platform specifics. So, it was decided to narrow down the fix to lwawt (OSX) in |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
943 |
// current release. TODO: consider fixing it in the shared code. |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
944 |
if (!focusedWindowChangeAllowed) { |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
945 |
LWWindowPeer decoratedPeer = parentPeer.isSimpleWindow() ? |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
946 |
LWWindowPeer.getOwnerFrameDialog(parentPeer) : parentPeer; |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
947 |
|
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
948 |
if (decoratedPeer == null || !decoratedPeer.getPlatformWindow().isActive()) { |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
949 |
if (focusLog.isLoggable(PlatformLogger.FINE)) { |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
950 |
focusLog.fine("request rejected, focusedWindowChangeAllowed==false, " + |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
951 |
"decoratedPeer is inactive: " + decoratedPeer); |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
952 |
} |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
953 |
LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget()); |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
954 |
return false; |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
955 |
} |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
956 |
} |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
957 |
|
12047 | 958 |
boolean res = parentPeer.requestWindowFocus(cause); |
959 |
// If parent window can be made focused and has been made focused (synchronously) |
|
960 |
// then we can proceed with children, otherwise we retreat |
|
961 |
if (!res || !parentWindow.isFocused()) { |
|
12662
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
962 |
if (focusLog.isLoggable(PlatformLogger.FINE)) { |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
963 |
focusLog.fine("request rejected, res= " + res + ", parentWindow.isFocused()=" + |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
964 |
parentWindow.isFocused()); |
184d8d3b7fff
7145768: [macosx] Regression: failure in b11 of ModalDialogInFocusEventTest
ant
parents:
12639
diff
changeset
|
965 |
} |
12047 | 966 |
LWKeyboardFocusManagerPeer.removeLastFocusRequest(getTarget()); |
967 |
return false; |
|
968 |
} |
|
969 |
||
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13544
diff
changeset
|
970 |
KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance(); |
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13544
diff
changeset
|
971 |
Component focusOwner = kfmPeer.getCurrentFocusOwner(); |
12047 | 972 |
return LWKeyboardFocusManagerPeer.deliverFocus(lightweightChild, |
973 |
getTarget(), temporary, |
|
974 |
focusedWindowChangeAllowed, |
|
975 |
time, cause, focusOwner); |
|
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13544
diff
changeset
|
976 |
|
12047 | 977 |
case LWKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED: |
978 |
return true; |
|
979 |
} |
|
980 |
||
981 |
return false; |
|
982 |
} |
|
983 |
||
984 |
@Override |
|
985 |
public Image createImage(ImageProducer producer) { |
|
986 |
return new ToolkitImage(producer); |
|
987 |
} |
|
988 |
||
989 |
@Override |
|
990 |
public Image createImage(int w, int h) { |
|
12637
983d636eed7c
7154088: [macosx] Regression: Component.createImage do not inherits component attributes
bae
parents:
12416
diff
changeset
|
991 |
CGraphicsConfig gc = (CGraphicsConfig)getGraphicsConfiguration(); |
983d636eed7c
7154088: [macosx] Regression: Component.createImage do not inherits component attributes
bae
parents:
12416
diff
changeset
|
992 |
return gc.createAcceleratedImage(getTarget(), w, h); |
12047 | 993 |
} |
994 |
||
995 |
@Override |
|
996 |
public VolatileImage createVolatileImage(int w, int h) { |
|
997 |
// TODO: is it a right/complete implementation? |
|
998 |
return new SunVolatileImage(getTarget(), w, h); |
|
999 |
} |
|
1000 |
||
1001 |
@Override |
|
1002 |
public boolean prepareImage(Image img, int w, int h, ImageObserver o) { |
|
1003 |
// TODO: is it a right/complete implementation? |
|
1004 |
return getToolkit().prepareImage(img, w, h, o); |
|
1005 |
} |
|
1006 |
||
1007 |
@Override |
|
1008 |
public int checkImage(Image img, int w, int h, ImageObserver o) { |
|
1009 |
// TODO: is it a right/complete implementation? |
|
1010 |
return getToolkit().checkImage(img, w, h, o); |
|
1011 |
} |
|
1012 |
||
1013 |
@Override |
|
1014 |
public boolean handlesWheelScrolling() { |
|
1015 |
// TODO: not implemented |
|
1016 |
return false; |
|
1017 |
} |
|
1018 |
||
1019 |
@Override |
|
1020 |
public final void applyShape(final Region shape) { |
|
1021 |
synchronized (getStateLock()) { |
|
13233 | 1022 |
if (region == shape || (region != null && region.equals(shape))) { |
1023 |
return; |
|
1024 |
} |
|
1025 |
} |
|
1026 |
applyShapeImpl(shape); |
|
1027 |
} |
|
1028 |
||
1029 |
void applyShapeImpl(final Region shape) { |
|
1030 |
synchronized (getStateLock()) { |
|
1031 |
if (shape != null) { |
|
1032 |
region = Region.WHOLE_REGION.getIntersection(shape); |
|
1033 |
} else { |
|
1034 |
region = null; |
|
1035 |
} |
|
12047 | 1036 |
} |
1037 |
repaintParent(getBounds()); |
|
1038 |
} |
|
1039 |
||
1040 |
protected final Region getRegion() { |
|
1041 |
synchronized (getStateLock()) { |
|
13233 | 1042 |
return isShaped() ? region : Region.getInstance(getSize()); |
1043 |
} |
|
1044 |
} |
|
1045 |
||
1046 |
public boolean isShaped() { |
|
1047 |
synchronized (getStateLock()) { |
|
1048 |
return region != null; |
|
12047 | 1049 |
} |
1050 |
} |
|
1051 |
||
1052 |
// DropTargetPeer Method |
|
1053 |
@Override |
|
1054 |
public void addDropTarget(DropTarget dt) { |
|
12416
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1055 |
LWWindowPeer winPeer = getWindowPeerOrSelf(); |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1056 |
if (winPeer != null && winPeer != this) { |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1057 |
// We need to register the DropTarget in the |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1058 |
// peer of the window ancestor of the component |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1059 |
winPeer.addDropTarget(dt); |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1060 |
} else { |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1061 |
synchronized (dropTargetLock) { |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1062 |
// 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1063 |
// if it's the first (or last) one for the component. Otherwise this call is a no-op. |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1064 |
if (++fNumDropTargets == 1) { |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1065 |
// Having a non-null drop target would be an error but let's check just in case: |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1066 |
if (fDropTarget != null) |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1067 |
System.err.println("CComponent.addDropTarget(): current drop target is non-null."); |
12047 | 1068 |
|
12416
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1069 |
// Create a new drop target: |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1070 |
fDropTarget = CDropTarget.createDropTarget(dt, target, this); |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1071 |
} |
12047 | 1072 |
} |
1073 |
} |
|
1074 |
} |
|
1075 |
||
1076 |
// DropTargetPeer Method |
|
1077 |
@Override |
|
1078 |
public void removeDropTarget(DropTarget dt) { |
|
12416
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1079 |
LWWindowPeer winPeer = getWindowPeerOrSelf(); |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1080 |
if (winPeer != null && winPeer != this) { |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1081 |
// We need to unregister the DropTarget in the |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1082 |
// peer of the window ancestor of the component |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1083 |
winPeer.removeDropTarget(dt); |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1084 |
} else { |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1085 |
synchronized (dropTargetLock){ |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1086 |
// 10-14-02 VL: Windows WComponentPeer would add (or remove) the drop target only |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1087 |
// if it's the first (or last) one for the component. Otherwise this call is a no-op. |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1088 |
if (--fNumDropTargets == 0) { |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1089 |
// Having a null drop target would be an error but let's check just in case: |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1090 |
if (fDropTarget != null) { |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1091 |
// Dispose of the drop target: |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1092 |
fDropTarget.dispose(); |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1093 |
fDropTarget = null; |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1094 |
} else |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1095 |
System.err.println("CComponent.removeDropTarget(): current drop target is null."); |
7f39181f3c6e
7161109: [macosx] JCK AWT interactive test DnDTextDropTest fails on MacOS
kizune
parents:
12398
diff
changeset
|
1096 |
} |
12047 | 1097 |
} |
1098 |
} |
|
1099 |
} |
|
1100 |
||
1101 |
// ---- PEER NOTIFICATIONS ---- // |
|
1102 |
||
1103 |
/** |
|
1104 |
* Called when this peer's location has been changed either as a result |
|
1105 |
* of target.setLocation() or as a result of user actions (window is |
|
1106 |
* dragged with mouse). |
|
1107 |
* |
|
1108 |
* To be overridden in LWWindowPeer to update its GraphicsConfig. |
|
1109 |
* |
|
1110 |
* This method could be called on the toolkit thread. |
|
1111 |
*/ |
|
1112 |
protected final void handleMove(final int x, final int y, |
|
1113 |
final boolean updateTarget) { |
|
1114 |
if (updateTarget) { |
|
1115 |
AWTAccessor.getComponentAccessor().setLocation(getTarget(), x, y); |
|
1116 |
} |
|
1117 |
postEvent(new ComponentEvent(getTarget(), |
|
1118 |
ComponentEvent.COMPONENT_MOVED)); |
|
1119 |
} |
|
1120 |
||
1121 |
/** |
|
1122 |
* Called when this peer's size has been changed either as a result of |
|
1123 |
* target.setSize() or as a result of user actions (window is resized). |
|
1124 |
* |
|
1125 |
* To be overridden in LWWindowPeer to update its SurfaceData and |
|
1126 |
* GraphicsConfig. |
|
1127 |
* |
|
1128 |
* This method could be called on the toolkit thread. |
|
1129 |
*/ |
|
1130 |
protected final void handleResize(final int w, final int h, |
|
1131 |
final boolean updateTarget) { |
|
1132 |
if (updateTarget) { |
|
1133 |
AWTAccessor.getComponentAccessor().setSize(getTarget(), w, h); |
|
1134 |
} |
|
1135 |
postEvent(new ComponentEvent(getTarget(), |
|
1136 |
ComponentEvent.COMPONENT_RESIZED)); |
|
1137 |
} |
|
1138 |
||
1139 |
protected final void repaintOldNewBounds(final Rectangle oldB) { |
|
1140 |
repaintParent(oldB); |
|
1141 |
repaintPeer(getSize()); |
|
1142 |
} |
|
1143 |
||
1144 |
protected final void repaintParent(final Rectangle oldB) { |
|
1145 |
final LWContainerPeer cp = getContainerPeer(); |
|
1146 |
if (cp != null) { |
|
1147 |
// Repaint unobscured part of the parent |
|
1148 |
cp.repaintPeer(cp.getContentSize().intersection(oldB)); |
|
1149 |
} |
|
1150 |
} |
|
1151 |
||
1152 |
// ---- EVENTS ---- // |
|
1153 |
||
1154 |
/** |
|
1155 |
* Post an event to the proper Java EDT. |
|
1156 |
*/ |
|
1157 |
public void postEvent(AWTEvent event) { |
|
1158 |
SunToolkit.postEvent(getAppContext(), event); |
|
1159 |
} |
|
1160 |
||
1161 |
protected void postPaintEvent(int x, int y, int w, int h) { |
|
1162 |
// TODO: call getIgnoreRepaint() directly with the right ACC |
|
1163 |
if (AWTAccessor.getComponentAccessor().getIgnoreRepaint(target)) { |
|
1164 |
return; |
|
1165 |
} |
|
1166 |
PaintEvent event = PaintEventDispatcher.getPaintEventDispatcher(). |
|
1167 |
createPaintEvent(getTarget(), x, y, w, h); |
|
1168 |
if (event != null) { |
|
1169 |
postEvent(event); |
|
1170 |
} |
|
1171 |
} |
|
1172 |
||
1173 |
/* |
|
1174 |
* Gives a chance for the peer to handle the event after it's been |
|
1175 |
* processed by the target. |
|
1176 |
*/ |
|
1177 |
@Override |
|
1178 |
public void handleEvent(AWTEvent e) { |
|
1179 |
if ((e instanceof InputEvent) && ((InputEvent) e).isConsumed()) { |
|
1180 |
return; |
|
1181 |
} |
|
1182 |
switch (e.getID()) { |
|
1183 |
case FocusEvent.FOCUS_GAINED: |
|
1184 |
case FocusEvent.FOCUS_LOST: |
|
1185 |
handleJavaFocusEvent((FocusEvent) e); |
|
1186 |
break; |
|
1187 |
case PaintEvent.PAINT: |
|
1188 |
// Got a native paint event |
|
1189 |
// paintPending = false; |
|
1190 |
// fall through to the next statement |
|
1191 |
case PaintEvent.UPDATE: |
|
1192 |
handleJavaPaintEvent(); |
|
1193 |
break; |
|
1194 |
case MouseEvent.MOUSE_PRESSED: |
|
1195 |
handleJavaMouseEvent((MouseEvent)e); |
|
1196 |
} |
|
1197 |
||
1198 |
sendEventToDelegate(e); |
|
1199 |
} |
|
1200 |
||
1201 |
private void sendEventToDelegate(final AWTEvent e) { |
|
1202 |
synchronized (getDelegateLock()) { |
|
1203 |
if (getDelegate() == null || !isShowing() || !isEnabled()) { |
|
1204 |
return; |
|
1205 |
} |
|
1206 |
AWTEvent delegateEvent = createDelegateEvent(e); |
|
1207 |
if (delegateEvent != null) { |
|
1208 |
AWTAccessor.getComponentAccessor() |
|
1209 |
.processEvent((Component) delegateEvent.getSource(), |
|
1210 |
delegateEvent); |
|
1211 |
if (delegateEvent instanceof KeyEvent) { |
|
1212 |
KeyEvent ke = (KeyEvent) delegateEvent; |
|
1213 |
SwingUtilities.processKeyBindings(ke); |
|
1214 |
} |
|
1215 |
} |
|
1216 |
} |
|
1217 |
} |
|
1218 |
||
1219 |
protected AWTEvent createDelegateEvent(AWTEvent e) { |
|
1220 |
AWTEvent delegateEvent = null; |
|
1221 |
if (e instanceof MouseWheelEvent) { |
|
1222 |
MouseWheelEvent me = (MouseWheelEvent) e; |
|
1223 |
delegateEvent = new MouseWheelEvent( |
|
1224 |
delegate, me.getID(), me.getWhen(), |
|
1225 |
me.getModifiers(), |
|
1226 |
me.getX(), me.getY(), |
|
1227 |
me.getClickCount(), |
|
1228 |
me.isPopupTrigger(), |
|
1229 |
me.getScrollType(), |
|
1230 |
me.getScrollAmount(), |
|
1231 |
me.getWheelRotation()); |
|
1232 |
} else if (e instanceof MouseEvent) { |
|
1233 |
MouseEvent me = (MouseEvent) e; |
|
1234 |
||
1235 |
Component eventTarget = SwingUtilities.getDeepestComponentAt(delegate, me.getX(), me.getY()); |
|
1236 |
||
1237 |
if (me.getID() == MouseEvent.MOUSE_DRAGGED) { |
|
1238 |
if (delegateDropTarget == null) { |
|
1239 |
delegateDropTarget = eventTarget; |
|
1240 |
} else { |
|
1241 |
eventTarget = delegateDropTarget; |
|
1242 |
} |
|
1243 |
} |
|
1244 |
if (me.getID() == MouseEvent.MOUSE_RELEASED && delegateDropTarget != null) { |
|
1245 |
eventTarget = delegateDropTarget; |
|
1246 |
delegateDropTarget = null; |
|
1247 |
} |
|
1248 |
if (eventTarget == null) { |
|
1249 |
eventTarget = delegate; |
|
1250 |
} |
|
1251 |
delegateEvent = SwingUtilities.convertMouseEvent(getTarget(), me, eventTarget); |
|
1252 |
} else if (e instanceof KeyEvent) { |
|
1253 |
KeyEvent ke = (KeyEvent) e; |
|
1254 |
delegateEvent = new KeyEvent(getDelegateFocusOwner(), ke.getID(), ke.getWhen(), |
|
1255 |
ke.getModifiers(), ke.getKeyCode(), ke.getKeyChar(), ke.getKeyLocation()); |
|
1256 |
} else if (e instanceof FocusEvent) { |
|
1257 |
FocusEvent fe = (FocusEvent) e; |
|
1258 |
delegateEvent = new FocusEvent(getDelegateFocusOwner(), fe.getID(), fe.isTemporary()); |
|
1259 |
} |
|
1260 |
return delegateEvent; |
|
1261 |
} |
|
1262 |
||
1263 |
protected void handleJavaMouseEvent(MouseEvent e) { |
|
1264 |
Component target = getTarget(); |
|
1265 |
assert (e.getSource() == target); |
|
1266 |
||
1267 |
if (!target.isFocusOwner() && LWKeyboardFocusManagerPeer.shouldFocusOnClick(target)) { |
|
1268 |
LWKeyboardFocusManagerPeer.requestFocusFor(target, CausedFocusEvent.Cause.MOUSE_EVENT); |
|
1269 |
} |
|
1270 |
} |
|
1271 |
||
1272 |
/** |
|
1273 |
* Handler for FocusEvents. |
|
1274 |
*/ |
|
1275 |
protected void handleJavaFocusEvent(FocusEvent e) { |
|
1276 |
// Note that the peer receives all the FocusEvents from |
|
1277 |
// its lightweight children as well |
|
13648
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13544
diff
changeset
|
1278 |
KeyboardFocusManagerPeer kfmPeer = LWKeyboardFocusManagerPeer.getInstance(); |
90effcfc064f
7124375: [macosx] Focus isn't transfered as expected between components
leonidr
parents:
13544
diff
changeset
|
1279 |
kfmPeer.setCurrentFocusOwner(e.getID() == FocusEvent.FOCUS_GAINED ? getTarget() : null); |
12047 | 1280 |
} |
1281 |
||
1282 |
/** |
|
1283 |
* All peers should clear background before paint. |
|
1284 |
* |
|
1285 |
* @return false on components that DO NOT require a clearRect() before |
|
1286 |
* painting. |
|
1287 |
*/ |
|
1288 |
protected final boolean shouldClearRectBeforePaint() { |
|
1289 |
// TODO: sun.awt.noerasebackground |
|
1290 |
return true; |
|
1291 |
} |
|
1292 |
||
1293 |
/** |
|
1294 |
* Handler for PAINT and UPDATE PaintEvents. |
|
1295 |
*/ |
|
1296 |
private void handleJavaPaintEvent() { |
|
1297 |
// Skip all painting while layouting and all UPDATEs |
|
1298 |
// while waiting for native paint |
|
1299 |
// if (!isLayouting && !paintPending) { |
|
1300 |
if (!isLayouting()) { |
|
1301 |
targetPaintArea.paint(getTarget(), shouldClearRectBeforePaint()); |
|
1302 |
} |
|
1303 |
} |
|
1304 |
||
1305 |
// ---- UTILITY METHODS ---- // |
|
1306 |
||
1307 |
/** |
|
1308 |
* Finds a top-most visible component for the given point. The location is |
|
1309 |
* specified relative to the peer's parent. |
|
1310 |
*/ |
|
1311 |
public LWComponentPeer findPeerAt(final int x, final int y) { |
|
1312 |
final Rectangle r = getBounds(); |
|
1313 |
final Region sh = getRegion(); |
|
1314 |
final boolean found = isVisible() && sh.contains(x - r.x, y - r.y); |
|
1315 |
return found ? this : null; |
|
1316 |
} |
|
1317 |
||
1318 |
/* |
|
1319 |
* Translated the given point in Window coordinates to the point in |
|
1320 |
* coordinates local to this component. The given window peer must be |
|
1321 |
* the window where this component is in. |
|
1322 |
*/ |
|
1323 |
public Point windowToLocal(int x, int y, LWWindowPeer wp) { |
|
1324 |
return windowToLocal(new Point(x, y), wp); |
|
1325 |
} |
|
1326 |
||
1327 |
public Point windowToLocal(Point p, LWWindowPeer wp) { |
|
1328 |
LWComponentPeer cp = this; |
|
1329 |
while (cp != wp) { |
|
1330 |
Rectangle cpb = cp.getBounds(); |
|
1331 |
p.x -= cpb.x; |
|
1332 |
p.y -= cpb.y; |
|
1333 |
cp = cp.getContainerPeer(); |
|
1334 |
} |
|
1335 |
// Return a copy to prevent subsequent modifications |
|
1336 |
return new Point(p); |
|
1337 |
} |
|
1338 |
||
1339 |
public Rectangle windowToLocal(Rectangle r, LWWindowPeer wp) { |
|
1340 |
Point p = windowToLocal(r.getLocation(), wp); |
|
1341 |
return new Rectangle(p, r.getSize()); |
|
1342 |
} |
|
1343 |
||
1344 |
public Point localToWindow(int x, int y) { |
|
1345 |
return localToWindow(new Point(x, y)); |
|
1346 |
} |
|
1347 |
||
1348 |
public Point localToWindow(Point p) { |
|
1349 |
LWComponentPeer cp = getContainerPeer(); |
|
1350 |
Rectangle r = getBounds(); |
|
1351 |
while (cp != null) { |
|
1352 |
p.x += r.x; |
|
1353 |
p.y += r.y; |
|
1354 |
r = cp.getBounds(); |
|
1355 |
cp = cp.getContainerPeer(); |
|
1356 |
} |
|
1357 |
// Return a copy to prevent subsequent modifications |
|
1358 |
return new Point(p); |
|
1359 |
} |
|
1360 |
||
1361 |
public Rectangle localToWindow(Rectangle r) { |
|
1362 |
Point p = localToWindow(r.getLocation()); |
|
1363 |
return new Rectangle(p, r.getSize()); |
|
1364 |
} |
|
1365 |
||
1366 |
public final void repaintPeer() { |
|
1367 |
repaintPeer(getSize()); |
|
1368 |
} |
|
1369 |
||
1370 |
public void repaintPeer(final Rectangle r) { |
|
1371 |
final Rectangle toPaint = getSize().intersection(r); |
|
1372 |
if (!isShowing() || toPaint.isEmpty()) { |
|
1373 |
return; |
|
1374 |
} |
|
1375 |
||
1376 |
postPaintEvent(toPaint.x, toPaint.y, toPaint.width, toPaint.height); |
|
1377 |
} |
|
1378 |
||
1379 |
/** |
|
1380 |
* Determines whether this peer is showing on screen. This means that the |
|
1381 |
* peer must be visible, and it must be in a container that is visible and |
|
1382 |
* showing. |
|
1383 |
* |
|
1384 |
* @see #isVisible() |
|
1385 |
*/ |
|
13143
31c70a66a053
7142091: [macosx] RFE: Refactoring of peer initialization/disposing
serb
parents:
12667
diff
changeset
|
1386 |
protected final boolean isShowing() { |
12047 | 1387 |
synchronized (getPeerTreeLock()) { |
1388 |
if (isVisible()) { |
|
1389 |
final LWContainerPeer container = getContainerPeer(); |
|
1390 |
return (container == null) || container.isShowing(); |
|
1391 |
} |
|
1392 |
} |
|
1393 |
return false; |
|
1394 |
} |
|
1395 |
||
1396 |
/** |
|
1397 |
* Paints the peer. Overridden in subclasses to delegate the actual painting |
|
1398 |
* to Swing components. |
|
1399 |
*/ |
|
1400 |
protected final void paintPeer(final Graphics g) { |
|
1401 |
final D delegate = getDelegate(); |
|
1402 |
if (delegate != null) { |
|
1403 |
if (!SwingUtilities.isEventDispatchThread()) { |
|
1404 |
throw new InternalError("Painting must be done on EDT"); |
|
1405 |
} |
|
1406 |
synchronized (getDelegateLock()) { |
|
1407 |
// JComponent.print() is guaranteed to not affect the double buffer |
|
1408 |
getDelegate().print(g); |
|
1409 |
} |
|
1410 |
} |
|
1411 |
} |
|
1412 |
||
1413 |
protected static final void flushOnscreenGraphics(){ |
|
1414 |
final OGLRenderQueue rq = OGLRenderQueue.getInstance(); |
|
1415 |
rq.lock(); |
|
1416 |
try { |
|
1417 |
rq.flushNow(); |
|
1418 |
} finally { |
|
1419 |
rq.unlock(); |
|
1420 |
} |
|
1421 |
} |
|
1422 |
||
1423 |
/** |
|
1424 |
* Used by ContainerPeer to skip all the paint events during layout. |
|
1425 |
* |
|
1426 |
* @param isLayouting layouting state. |
|
1427 |
*/ |
|
1428 |
protected final void setLayouting(final boolean isLayouting) { |
|
1429 |
this.isLayouting = isLayouting; |
|
1430 |
} |
|
1431 |
||
1432 |
/** |
|
1433 |
* Returns layouting state. Used by ComponentPeer to skip all the paint |
|
1434 |
* events during layout. |
|
1435 |
* |
|
1436 |
* @return true during layout, false otherwise. |
|
1437 |
*/ |
|
1438 |
private final boolean isLayouting() { |
|
1439 |
return isLayouting; |
|
1440 |
} |
|
1441 |
} |