author | asaha |
Wed, 21 Oct 2009 11:28:46 -0700 | |
changeset 4214 | 0fa32d38146b |
parent 4191 | ca8d3ef845c8 |
parent 3938 | ef327bd847c0 |
child 4371 | dc9dcb8b0ae7 |
permissions | -rw-r--r-- |
2 | 1 |
/* |
116
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
2 |
* Copyright 2002-2008 Sun Microsystems, Inc. All Rights Reserved. |
2 | 3 |
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER. |
4 |
* |
|
5 |
* This code is free software; you can redistribute it and/or modify it |
|
6 |
* under the terms of the GNU General Public License version 2 only, as |
|
7 |
* published by the Free Software Foundation. Sun designates this |
|
8 |
* particular file as subject to the "Classpath" exception as provided |
|
9 |
* by Sun 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 Sun Microsystems, Inc., 4150 Network Circle, Santa Clara, |
|
22 |
* CA 95054 USA or visit www.sun.com if you need additional information or |
|
23 |
* have any questions. |
|
24 |
*/ |
|
25 |
package sun.awt.X11; |
|
26 |
||
27 |
import java.awt.AWTEvent; |
|
28 |
import java.awt.AWTException; |
|
29 |
import java.awt.BufferCapabilities; |
|
30 |
import java.awt.Color; |
|
31 |
import java.awt.Component; |
|
32 |
import java.awt.Container; |
|
33 |
import java.awt.Cursor; |
|
34 |
import java.awt.Dimension; |
|
35 |
import java.awt.Font; |
|
36 |
import java.awt.FontMetrics; |
|
37 |
import java.awt.Graphics; |
|
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2458
diff
changeset
|
38 |
import java.awt.GraphicsConfiguration; |
2 | 39 |
import java.awt.Image; |
40 |
import java.awt.Insets; |
|
41 |
import java.awt.KeyboardFocusManager; |
|
42 |
import java.awt.Rectangle; |
|
43 |
import java.awt.SystemColor; |
|
44 |
import java.awt.Toolkit; |
|
45 |
import java.awt.Window; |
|
46 |
import java.awt.dnd.DropTarget; |
|
47 |
import java.awt.dnd.peer.DropTargetPeer; |
|
48 |
import java.awt.event.FocusEvent; |
|
49 |
import java.awt.event.InputEvent; |
|
50 |
import java.awt.event.InputMethodEvent; |
|
51 |
import java.awt.event.KeyEvent; |
|
52 |
import java.awt.event.MouseEvent; |
|
53 |
import java.awt.event.MouseWheelEvent; |
|
54 |
import java.awt.event.PaintEvent; |
|
55 |
import java.awt.event.WindowEvent; |
|
56 |
import java.awt.event.InvocationEvent; |
|
57 |
import java.awt.image.ImageObserver; |
|
58 |
import java.awt.image.ImageProducer; |
|
59 |
import java.awt.image.VolatileImage; |
|
60 |
import java.awt.peer.ComponentPeer; |
|
61 |
import java.awt.peer.ContainerPeer; |
|
62 |
import java.awt.peer.LightweightPeer; |
|
63 |
import java.lang.reflect.*; |
|
64 |
import java.security.*; |
|
65 |
import java.util.Collection; |
|
66 |
import java.util.HashSet; |
|
67 |
import java.util.Set; |
|
68 |
import java.util.Vector; |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
69 |
import sun.util.logging.PlatformLogger; |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
70 |
|
2 | 71 |
import sun.awt.*; |
72 |
import sun.awt.event.IgnorePaintEvent; |
|
73 |
import sun.awt.image.SunVolatileImage; |
|
74 |
import sun.awt.image.ToolkitImage; |
|
887 | 75 |
import sun.java2d.BackBufferCapsProvider; |
2 | 76 |
import sun.java2d.pipe.Region; |
77 |
||
887 | 78 |
public class XComponentPeer extends XWindow implements ComponentPeer, DropTargetPeer, |
79 |
BackBufferCapsProvider |
|
80 |
{ |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
81 |
private static final PlatformLogger log = PlatformLogger.getLogger("sun.awt.X11.XComponentPeer"); |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
82 |
private static final PlatformLogger buffersLog = PlatformLogger.getLogger("sun.awt.X11.XComponentPeer.multibuffer"); |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
83 |
private static final PlatformLogger focusLog = PlatformLogger.getLogger("sun.awt.X11.focus.XComponentPeer"); |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
84 |
private static final PlatformLogger fontLog = PlatformLogger.getLogger("sun.awt.X11.font.XComponentPeer"); |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
85 |
private static final PlatformLogger enableLog = PlatformLogger.getLogger("sun.awt.X11.enable.XComponentPeer"); |
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
86 |
private static final PlatformLogger shapeLog = PlatformLogger.getLogger("sun.awt.X11.shape.XComponentPeer"); |
2 | 87 |
|
88 |
boolean paintPending = false; |
|
89 |
boolean isLayouting = false; |
|
90 |
boolean enabled; |
|
91 |
||
92 |
// Actually used only by XDecoratedPeer |
|
93 |
protected int boundsOperation; |
|
94 |
||
95 |
Color foreground; |
|
96 |
Color background; |
|
97 |
||
98 |
// Colors calculated as on Motif using MotifColorUtilties. |
|
99 |
// If you use these, call updateMotifColors() in the peer's Constructor and |
|
100 |
// setBackground(). Examples are XCheckboxPeer and XButtonPeer. |
|
101 |
Color darkShadow; |
|
102 |
Color lightShadow; |
|
103 |
Color selectColor; |
|
104 |
||
105 |
Font font; |
|
106 |
private long backBuffer = 0; |
|
107 |
private VolatileImage xBackBuffer = null; |
|
108 |
||
109 |
static Color[] systemColors; |
|
110 |
||
111 |
XComponentPeer() { |
|
112 |
} |
|
113 |
||
114 |
XComponentPeer (XCreateWindowParams params) { |
|
115 |
super(params); |
|
116 |
} |
|
117 |
||
118 |
XComponentPeer(Component target, long parentWindow, Rectangle bounds) { |
|
119 |
super(target, parentWindow, bounds); |
|
120 |
} |
|
121 |
||
122 |
/** |
|
123 |
* Standard peer constructor, with corresponding Component |
|
124 |
*/ |
|
125 |
XComponentPeer(Component target) { |
|
126 |
super(target); |
|
127 |
} |
|
128 |
||
129 |
||
130 |
void preInit(XCreateWindowParams params) { |
|
131 |
super.preInit(params); |
|
132 |
boundsOperation = DEFAULT_OPERATION; |
|
133 |
} |
|
134 |
void postInit(XCreateWindowParams params) { |
|
135 |
super.postInit(params); |
|
136 |
Color c; |
|
137 |
Font f; |
|
138 |
Cursor cursor; |
|
139 |
||
140 |
pSetCursor(target.getCursor()); |
|
141 |
||
142 |
foreground = target.getForeground(); |
|
143 |
background = target.getBackground(); |
|
144 |
font = target.getFont(); |
|
145 |
||
146 |
if (isInitialReshape()) { |
|
147 |
Rectangle r = target.getBounds(); |
|
148 |
reshape(r.x, r.y, r.width, r.height); |
|
149 |
} |
|
150 |
||
151 |
enabled = target.isEnabled(); |
|
152 |
||
153 |
// If any of our heavyweight ancestors are disable, we should be too |
|
154 |
// See 6176875 for more information |
|
155 |
Component comp = target; |
|
156 |
while( !(comp == null || comp instanceof Window) ) { |
|
157 |
comp = comp.getParent(); |
|
158 |
if( comp != null && !comp.isEnabled() && !comp.isLightweight() ){ |
|
159 |
setEnabled(false); |
|
160 |
break; |
|
161 |
} |
|
162 |
} |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
163 |
enableLog.fine("Initial enable state: {0}", Boolean.valueOf(enabled)); |
2 | 164 |
|
165 |
if (target.isVisible()) { |
|
2458
f4bee3ba17ee
6806224: PIT : Getting java.lang.NullPointerException while opening Filedialog
dcherepanov
parents:
1978
diff
changeset
|
166 |
setVisible(true); |
2 | 167 |
} |
168 |
} |
|
169 |
||
170 |
protected boolean isInitialReshape() { |
|
171 |
return true; |
|
172 |
} |
|
173 |
||
174 |
public void reparent(ContainerPeer newNativeParent) { |
|
175 |
XComponentPeer newPeer = (XComponentPeer)newNativeParent; |
|
176 |
XToolkit.awtLock(); |
|
177 |
try { |
|
178 |
XlibWrapper.XReparentWindow(XToolkit.getDisplay(), getWindow(), newPeer.getContentWindow(), x, y); |
|
179 |
parentWindow = newPeer; |
|
180 |
} finally { |
|
181 |
XToolkit.awtUnlock(); |
|
182 |
} |
|
183 |
} |
|
184 |
public boolean isReparentSupported() { |
|
185 |
return System.getProperty("sun.awt.X11.XComponentPeer.reparentNotSupported", "false").equals("false"); |
|
186 |
} |
|
187 |
||
188 |
public boolean isObscured() { |
|
189 |
Container container = (target instanceof Container) ? |
|
190 |
(Container)target : target.getParent(); |
|
191 |
||
192 |
if (container == null) { |
|
193 |
return true; |
|
194 |
} |
|
195 |
||
196 |
Container parent; |
|
197 |
while ((parent = container.getParent()) != null) { |
|
198 |
container = parent; |
|
199 |
} |
|
200 |
||
201 |
if (container instanceof Window) { |
|
202 |
XWindowPeer wpeer = (XWindowPeer)(container.getPeer()); |
|
203 |
if (wpeer != null) { |
|
204 |
return (wpeer.winAttr.visibilityState != |
|
205 |
wpeer.winAttr.AWT_UNOBSCURED); |
|
206 |
} |
|
207 |
} |
|
208 |
return true; |
|
209 |
} |
|
210 |
||
211 |
public boolean canDetermineObscurity() { |
|
212 |
return true; |
|
213 |
} |
|
214 |
||
215 |
static XComponentPeer getNativeContainer(Component comp) { |
|
216 |
if (comp == null) { |
|
217 |
return null; |
|
218 |
} |
|
219 |
||
220 |
synchronized(comp.getTreeLock()) { |
|
221 |
while (comp != null && (ComponentAccessor.getPeer(comp) instanceof LightweightPeer)) { |
|
222 |
comp = ComponentAccessor.getParent_NoClientCode(comp); |
|
223 |
} |
|
224 |
||
225 |
if (comp != null) { |
|
226 |
ComponentPeer peer = ComponentAccessor.getPeer(comp); |
|
227 |
if (peer != null && peer instanceof XComponentPeer) { |
|
228 |
return (XComponentPeer)peer; |
|
229 |
} |
|
230 |
} |
|
231 |
} |
|
232 |
||
233 |
return null; |
|
234 |
} |
|
235 |
||
236 |
/************************************************* |
|
237 |
* FOCUS STUFF |
|
238 |
*************************************************/ |
|
239 |
||
240 |
/** |
|
241 |
* Keeps the track of focused state of the _NATIVE_ window |
|
242 |
*/ |
|
243 |
boolean bHasFocus = false; |
|
244 |
||
245 |
/** |
|
246 |
* Descendants should use this method to determine whether or not native window |
|
247 |
* has focus. |
|
248 |
*/ |
|
249 |
final public boolean hasFocus() { |
|
250 |
return bHasFocus; |
|
251 |
} |
|
252 |
||
253 |
/** |
|
254 |
* Called when component receives focus |
|
255 |
*/ |
|
256 |
public void focusGained(FocusEvent e) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
257 |
focusLog.fine("{0}", e); |
2 | 258 |
bHasFocus = true; |
259 |
} |
|
260 |
||
261 |
/** |
|
262 |
* Called when component loses focus |
|
263 |
*/ |
|
264 |
public void focusLost(FocusEvent e) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
265 |
focusLog.fine("{0}", e); |
2 | 266 |
bHasFocus = false; |
267 |
} |
|
268 |
||
269 |
public boolean isFocusable() { |
|
270 |
/* should be implemented by other sub-classes */ |
|
271 |
return false; |
|
272 |
} |
|
273 |
||
274 |
private static Class seClass; |
|
275 |
private static Constructor seCtor; |
|
276 |
||
277 |
final static AWTEvent wrapInSequenced(AWTEvent event) { |
|
278 |
try { |
|
279 |
if (seClass == null) { |
|
280 |
seClass = Class.forName("java.awt.SequencedEvent"); |
|
281 |
} |
|
282 |
||
283 |
if (seCtor == null) { |
|
284 |
seCtor = (Constructor) AccessController.doPrivileged(new PrivilegedExceptionAction() { |
|
285 |
public Object run() throws Exception { |
|
286 |
Constructor ctor = seClass.getConstructor(new Class[] { AWTEvent.class }); |
|
287 |
ctor.setAccessible(true); |
|
288 |
return ctor; |
|
289 |
} |
|
290 |
}); |
|
291 |
} |
|
292 |
||
293 |
return (AWTEvent) seCtor.newInstance(new Object[] { event }); |
|
294 |
} |
|
295 |
catch (ClassNotFoundException e) { |
|
296 |
throw new NoClassDefFoundError("java.awt.SequencedEvent."); |
|
297 |
} |
|
298 |
catch (PrivilegedActionException ex) { |
|
299 |
throw new NoClassDefFoundError("java.awt.SequencedEvent."); |
|
300 |
} |
|
301 |
catch (InstantiationException e) { |
|
302 |
assert false; |
|
303 |
} |
|
304 |
catch (IllegalAccessException e) { |
|
305 |
assert false; |
|
306 |
} |
|
307 |
catch (InvocationTargetException e) { |
|
308 |
assert false; |
|
309 |
} |
|
310 |
||
311 |
return null; |
|
312 |
} |
|
313 |
||
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
314 |
// TODO: consider moving it to KeyboardFocusManagerPeerImpl |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
315 |
final public boolean requestFocus(Component lightweightChild, boolean temporary, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
316 |
boolean focusedWindowChangeAllowed, long time, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
317 |
CausedFocusEvent.Cause cause) |
2 | 318 |
{ |
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
319 |
if (XKeyboardFocusManagerPeer. |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
320 |
processSynchronousLightweightTransfer(target, lightweightChild, temporary, |
2 | 321 |
focusedWindowChangeAllowed, time)) |
322 |
{ |
|
323 |
return true; |
|
324 |
} |
|
325 |
||
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
326 |
int result = XKeyboardFocusManagerPeer. |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
327 |
shouldNativelyFocusHeavyweight(target, lightweightChild, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
328 |
temporary, focusedWindowChangeAllowed, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
329 |
time, cause); |
2 | 330 |
|
331 |
switch (result) { |
|
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
332 |
case XKeyboardFocusManagerPeer.SNFH_FAILURE: |
2 | 333 |
return false; |
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
334 |
case XKeyboardFocusManagerPeer.SNFH_SUCCESS_PROCEED: |
2 | 335 |
// Currently we just generate focus events like we deal with lightweight instead of calling |
336 |
// XSetInputFocus on native window |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
337 |
if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Proceeding with request to " + |
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
338 |
lightweightChild + " in " + target); |
2 | 339 |
/** |
340 |
* The problems with requests in non-focused window arise because shouldNativelyFocusHeavyweight |
|
341 |
* checks that native window is focused while appropriate WINDOW_GAINED_FOCUS has not yet |
|
342 |
* been processed - it is in EventQueue. Thus, SNFH allows native request and stores request record |
|
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
343 |
* in requests list - and it breaks our requests sequence as first record on WGF should be the last |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
344 |
* focus owner which had focus before WLF. So, we should not add request record for such requests |
2 | 345 |
* but store this component in mostRecent - and return true as before for compatibility. |
346 |
*/ |
|
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
347 |
Window parentWindow = SunToolkit.getContainingWindow(target); |
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
348 |
if (parentWindow == null) { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
349 |
return rejectFocusRequestHelper("WARNING: Parent window is null"); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
350 |
} |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
351 |
XWindowPeer wpeer = (XWindowPeer)parentWindow.getPeer(); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
352 |
if (wpeer == null) { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
353 |
return rejectFocusRequestHelper("WARNING: Parent window's peer is null"); |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
354 |
} |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
355 |
/* |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
356 |
* Passing null 'actualFocusedWindow' as we don't want to restore focus on it |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
357 |
* when a component inside a Frame is requesting focus. |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
358 |
* See 6314575 for details. |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
359 |
*/ |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
360 |
boolean res = wpeer.requestWindowFocus(null); |
2 | 361 |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
362 |
if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer("Requested window focus: " + res); |
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
363 |
// If parent window can be made focused and has been made focused(synchronously) |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
364 |
// then we can proceed with children, otherwise we retreat. |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
365 |
if (!(res && parentWindow.isFocused())) { |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
366 |
return rejectFocusRequestHelper("Waiting for asynchronous processing of the request"); |
2 | 367 |
} |
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
368 |
return XKeyboardFocusManagerPeer.deliverFocus(lightweightChild, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
369 |
(Component)target, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
370 |
temporary, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
371 |
focusedWindowChangeAllowed, |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
372 |
time, cause); |
2 | 373 |
// Motif compatibility code |
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
374 |
case XKeyboardFocusManagerPeer.SNFH_SUCCESS_HANDLED: |
2 | 375 |
// Either lightweight or excessive request - all events are generated. |
376 |
return true; |
|
377 |
} |
|
378 |
return false; |
|
379 |
} |
|
380 |
||
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
381 |
private boolean rejectFocusRequestHelper(String logMsg) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
382 |
if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer(logMsg); |
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
383 |
XKeyboardFocusManagerPeer.removeLastFocusRequest(target); |
442
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
384 |
return false; |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
385 |
} |
687798d7d7b6
6522725: Component in a minimized Frame has focus and receives key events
ant
parents:
439
diff
changeset
|
386 |
|
2 | 387 |
void handleJavaFocusEvent(AWTEvent e) { |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
388 |
if (focusLog.isLoggable(PlatformLogger.FINER)) focusLog.finer(e.toString()); |
2 | 389 |
if (e.getID() == FocusEvent.FOCUS_GAINED) { |
390 |
focusGained((FocusEvent)e); |
|
391 |
} else { |
|
392 |
focusLost((FocusEvent)e); |
|
393 |
} |
|
394 |
} |
|
395 |
||
396 |
void handleJavaWindowFocusEvent(AWTEvent e) { |
|
397 |
} |
|
398 |
||
399 |
/************************************************* |
|
400 |
* END OF FOCUS STUFF |
|
401 |
*************************************************/ |
|
402 |
||
403 |
||
404 |
||
405 |
public void setVisible(boolean b) { |
|
406 |
xSetVisible(b); |
|
407 |
} |
|
408 |
||
409 |
public void hide() { |
|
410 |
setVisible(false); |
|
411 |
} |
|
412 |
||
413 |
||
414 |
/** |
|
415 |
* @see java.awt.peer.ComponentPeer |
|
416 |
*/ |
|
417 |
public void setEnabled(boolean value) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
418 |
enableLog.fine("{0}ing {1}", (value?"Enabl":"Disabl"), this); |
2 | 419 |
boolean repaintNeeded = (enabled != value); |
420 |
enabled = value; |
|
421 |
if (target instanceof Container) { |
|
422 |
Component list[] = ((Container)target).getComponents(); |
|
423 |
for (int i = 0; i < list.length; ++i) { |
|
424 |
boolean childEnabled = list[i].isEnabled(); |
|
425 |
ComponentPeer p = list[i].getPeer(); |
|
426 |
if ( p != null ) { |
|
427 |
p.setEnabled(value && childEnabled); |
|
428 |
} |
|
429 |
} |
|
430 |
} |
|
431 |
if (repaintNeeded) { |
|
432 |
repaint(); |
|
433 |
} |
|
434 |
} |
|
435 |
||
436 |
// |
|
437 |
// public so aw/Window can call it |
|
438 |
// |
|
439 |
public boolean isEnabled() { |
|
440 |
return enabled; |
|
441 |
} |
|
442 |
||
443 |
||
444 |
||
445 |
public void enable() { |
|
446 |
setEnabled(true); |
|
447 |
} |
|
448 |
||
449 |
public void disable() { |
|
450 |
setEnabled(false); |
|
451 |
} |
|
452 |
||
453 |
public void paint(Graphics g) { |
|
454 |
} |
|
455 |
public void repaint(long tm, int x, int y, int width, int height) { |
|
456 |
repaint(); |
|
457 |
} |
|
458 |
||
459 |
||
460 |
public Graphics getGraphics() { |
|
461 |
return getGraphics(surfaceData, getPeerForeground(), getPeerBackground(), getPeerFont()); |
|
462 |
} |
|
463 |
||
464 |
||
465 |
||
466 |
public void print(Graphics g) { |
|
467 |
// clear rect here to emulate X clears rect before Expose |
|
468 |
g.setColor(target.getBackground()); |
|
469 |
g.fillRect(0, 0, target.getWidth(), target.getHeight()); |
|
470 |
g.setColor(target.getForeground()); |
|
471 |
// paint peer |
|
472 |
paint(g); |
|
473 |
// allow target to change the picture |
|
474 |
target.print(g); |
|
475 |
} |
|
476 |
||
477 |
public void setBounds(int x, int y, int width, int height, int op) { |
|
478 |
this.x = x; |
|
479 |
this.y = y; |
|
480 |
this.width = width; |
|
481 |
this.height = height; |
|
482 |
xSetBounds(x,y,width,height); |
|
483 |
validateSurface(); |
|
484 |
layout(); |
|
485 |
} |
|
486 |
||
487 |
public void reshape(int x, int y, int width, int height) { |
|
488 |
setBounds(x, y, width, height, SET_BOUNDS); |
|
489 |
} |
|
490 |
||
491 |
public void coalescePaintEvent(PaintEvent e) { |
|
492 |
Rectangle r = e.getUpdateRect(); |
|
493 |
if (!(e instanceof IgnorePaintEvent)) { |
|
494 |
paintArea.add(r, e.getID()); |
|
495 |
} |
|
496 |
if (true) { |
|
497 |
switch(e.getID()) { |
|
498 |
case PaintEvent.UPDATE: |
|
499 |
log.finer("XCP coalescePaintEvent : UPDATE : add : x = " + |
|
500 |
r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height); |
|
501 |
return; |
|
502 |
case PaintEvent.PAINT: |
|
503 |
log.finer("XCP coalescePaintEvent : PAINT : add : x = " + |
|
504 |
r.x + ", y = " + r.y + ", width = " + r.width + ",height = " + r.height); |
|
505 |
return; |
|
506 |
} |
|
507 |
} |
|
508 |
} |
|
509 |
||
510 |
XWindowPeer getParentTopLevel() { |
|
511 |
Container parent = (target instanceof Container) ? ((Container)target) : (ComponentAccessor.getParent_NoClientCode(target)); |
|
512 |
// Search for parent window |
|
513 |
while (parent != null && !(parent instanceof Window)) { |
|
514 |
parent = ComponentAccessor.getParent_NoClientCode(parent); |
|
515 |
} |
|
516 |
if (parent != null) { |
|
517 |
return (XWindowPeer)ComponentAccessor.getPeer(parent); |
|
518 |
} else { |
|
519 |
return null; |
|
520 |
} |
|
521 |
} |
|
522 |
||
523 |
/* This method is intended to be over-ridden by peers to perform user interaction */ |
|
524 |
void handleJavaMouseEvent(MouseEvent e) { |
|
525 |
switch (e.getID()) { |
|
526 |
case MouseEvent.MOUSE_PRESSED: |
|
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
527 |
if (target == e.getSource() && |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
528 |
!target.isFocusOwner() && |
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
529 |
XKeyboardFocusManagerPeer.shouldFocusOnClick(target)) |
2 | 530 |
{ |
531 |
XWindowPeer parentXWindow = getParentTopLevel(); |
|
532 |
Window parentWindow = ((Window)parentXWindow.getTarget()); |
|
533 |
// Simple windows are non-focusable in X terms but focusable in Java terms. |
|
534 |
// As X-non-focusable they don't receive any focus events - we should generate them |
|
535 |
// by ourselfves. |
|
536 |
// if (parentXWindow.isFocusableWindow() /*&& parentXWindow.isSimpleWindow()*/ && |
|
537 |
// !(getCurrentNativeFocusedWindow() == parentWindow)) |
|
538 |
// { |
|
539 |
// setCurrentNativeFocusedWindow(parentWindow); |
|
540 |
// WindowEvent wfg = new WindowEvent(parentWindow, WindowEvent.WINDOW_GAINED_FOCUS); |
|
541 |
// parentWindow.dispatchEvent(wfg); |
|
542 |
// } |
|
2464
3c6755bdc55f
6806217: implement synthetic focus model for MS Windows
ant
parents:
2462
diff
changeset
|
543 |
XKeyboardFocusManagerPeer.requestFocusFor(target, CausedFocusEvent.Cause.MOUSE_EVENT); |
2 | 544 |
} |
545 |
break; |
|
546 |
} |
|
547 |
} |
|
548 |
||
549 |
/* This method is intended to be over-ridden by peers to perform user interaction */ |
|
550 |
void handleJavaKeyEvent(KeyEvent e) { |
|
551 |
} |
|
552 |
||
553 |
/* This method is intended to be over-ridden by peers to perform user interaction */ |
|
554 |
void handleJavaMouseWheelEvent(MouseWheelEvent e) { |
|
555 |
} |
|
556 |
||
557 |
||
558 |
/* This method is intended to be over-ridden by peers to perform user interaction */ |
|
559 |
void handleJavaInputMethodEvent(InputMethodEvent e) { |
|
560 |
} |
|
561 |
||
562 |
void handleF10JavaKeyEvent(KeyEvent e) { |
|
563 |
if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_F10) { |
|
564 |
XWindowPeer winPeer = this.getToplevelXWindow(); |
|
565 |
if (winPeer instanceof XFramePeer) { |
|
566 |
XMenuBarPeer mPeer = ((XFramePeer)winPeer).getMenubarPeer(); |
|
567 |
if (mPeer != null) { |
|
568 |
mPeer.handleF10KeyPress(e); |
|
569 |
} |
|
570 |
} |
|
571 |
} |
|
572 |
} |
|
573 |
||
574 |
public void handleEvent(java.awt.AWTEvent e) { |
|
575 |
if ((e instanceof InputEvent) && !((InputEvent)e).isConsumed() && target.isEnabled()) { |
|
576 |
if (e instanceof MouseEvent) { |
|
577 |
if (e instanceof MouseWheelEvent) { |
|
578 |
handleJavaMouseWheelEvent((MouseWheelEvent) e); |
|
579 |
} |
|
580 |
else |
|
581 |
handleJavaMouseEvent((MouseEvent) e); |
|
582 |
} |
|
583 |
else if (e instanceof KeyEvent) { |
|
584 |
handleF10JavaKeyEvent((KeyEvent)e); |
|
585 |
handleJavaKeyEvent((KeyEvent)e); |
|
586 |
} |
|
587 |
} |
|
588 |
else if (e instanceof KeyEvent && !((InputEvent)e).isConsumed()) { |
|
589 |
// even if target is disabled. |
|
590 |
handleF10JavaKeyEvent((KeyEvent)e); |
|
591 |
} |
|
592 |
else if (e instanceof InputMethodEvent) { |
|
593 |
handleJavaInputMethodEvent((InputMethodEvent) e); |
|
594 |
} |
|
595 |
||
596 |
int id = e.getID(); |
|
597 |
||
598 |
switch(id) { |
|
599 |
case PaintEvent.PAINT: |
|
600 |
// Got native painting |
|
601 |
paintPending = false; |
|
602 |
// Fallthrough to next statement |
|
603 |
case PaintEvent.UPDATE: |
|
604 |
// Skip all painting while layouting and all UPDATEs |
|
605 |
// while waiting for native paint |
|
606 |
if (!isLayouting && !paintPending) { |
|
607 |
paintArea.paint(target,false); |
|
608 |
} |
|
609 |
return; |
|
610 |
case FocusEvent.FOCUS_LOST: |
|
611 |
case FocusEvent.FOCUS_GAINED: |
|
612 |
handleJavaFocusEvent(e); |
|
613 |
break; |
|
614 |
case WindowEvent.WINDOW_LOST_FOCUS: |
|
615 |
case WindowEvent.WINDOW_GAINED_FOCUS: |
|
616 |
handleJavaWindowFocusEvent(e); |
|
617 |
break; |
|
618 |
default: |
|
619 |
break; |
|
620 |
} |
|
621 |
||
622 |
} |
|
623 |
||
624 |
public void handleButtonPressRelease(XEvent xev) { |
|
625 |
/* |
|
626 |
* Fix for 6385277. |
|
627 |
* We request focus on simple Window by click in order |
|
628 |
* to make it behave like Frame/Dialog in this case and also to unify |
|
629 |
* the behaviour with what we have on MS Windows. |
|
630 |
* handleJavaMouseEvent() would be more suitable place to do this |
|
631 |
* but we want Swing to have this functionality also. |
|
632 |
*/ |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
633 |
if (xev.get_type() == XConstants.ButtonPress) { |
2 | 634 |
final XWindowPeer parentXWindow = getParentTopLevel(); |
635 |
Window parentWindow = (Window)parentXWindow.getTarget(); |
|
636 |
if (parentXWindow.isFocusableWindow() && parentXWindow.isSimpleWindow() && |
|
637 |
XKeyboardFocusManagerPeer.getCurrentNativeFocusedWindow() != parentWindow) |
|
638 |
{ |
|
639 |
postEvent(new InvocationEvent(parentWindow, new Runnable() { |
|
640 |
public void run() { |
|
641 |
// Request focus on the EDT of 'parentWindow' because |
|
642 |
// XDecoratedPeer.requestWindowFocus() calls client code. |
|
643 |
parentXWindow.requestXFocus(); |
|
644 |
} |
|
645 |
})); |
|
646 |
} |
|
647 |
} |
|
648 |
super.handleButtonPressRelease(xev); |
|
649 |
} |
|
650 |
||
651 |
public Dimension getMinimumSize() { |
|
652 |
return target.getSize(); |
|
653 |
} |
|
654 |
||
655 |
public Dimension getPreferredSize() { |
|
656 |
return getMinimumSize(); |
|
657 |
} |
|
658 |
||
659 |
public void layout() {} |
|
660 |
||
661 |
public java.awt.Toolkit getToolkit() { |
|
662 |
return Toolkit.getDefaultToolkit(); |
|
663 |
} |
|
664 |
||
665 |
void updateMotifColors(Color bg) { |
|
666 |
int red = bg.getRed(); |
|
667 |
int green = bg.getGreen(); |
|
668 |
int blue = bg.getBlue(); |
|
669 |
||
670 |
darkShadow = new Color(MotifColorUtilities.calculateBottomShadowFromBackground(red,green,blue)); |
|
671 |
lightShadow = new Color(MotifColorUtilities.calculateTopShadowFromBackground(red,green,blue)); |
|
672 |
selectColor= new Color(MotifColorUtilities.calculateSelectFromBackground(red,green,blue)); |
|
673 |
} |
|
674 |
||
675 |
/* |
|
676 |
* Draw a 3D rectangle using the Motif colors. |
|
677 |
* "Normal" rectangles have shadows on the bottom. |
|
678 |
* "Depressed" rectangles (such as pressed buttons) have shadows on the top, |
|
679 |
* in which case true should be passed for topShadow. |
|
680 |
*/ |
|
681 |
public void drawMotif3DRect(Graphics g, |
|
682 |
int x, int y, int width, int height, |
|
683 |
boolean topShadow) { |
|
684 |
g.setColor(topShadow ? darkShadow : lightShadow); |
|
685 |
g.drawLine(x, y, x+width, y); // top |
|
686 |
g.drawLine(x, y+height, x, y); // left |
|
687 |
||
688 |
g.setColor(topShadow ? lightShadow : darkShadow ); |
|
689 |
g.drawLine(x+1, y+height, x+width, y+height); // bottom |
|
690 |
g.drawLine(x+width, y+height, x+width, y+1); // right |
|
691 |
} |
|
692 |
||
693 |
public void setBackground(Color c) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
694 |
if (log.isLoggable(PlatformLogger.FINE)) log.fine("Set background to " + c); |
2 | 695 |
synchronized (getStateLock()) { |
696 |
background = c; |
|
697 |
} |
|
698 |
super.setBackground(c); |
|
699 |
repaint(); |
|
700 |
} |
|
701 |
||
702 |
public void setForeground(Color c) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
703 |
if (log.isLoggable(PlatformLogger.FINE)) log.fine("Set foreground to " + c); |
2 | 704 |
synchronized (getStateLock()) { |
705 |
foreground = c; |
|
706 |
} |
|
707 |
repaint(); |
|
708 |
} |
|
709 |
||
710 |
/** |
|
711 |
* Gets the font metrics for the specified font. |
|
712 |
* @param font the font for which font metrics is to be |
|
713 |
* obtained |
|
714 |
* @return the font metrics for <code>font</code> |
|
715 |
* @see #getFont |
|
716 |
* @see #getPeer |
|
717 |
* @see java.awt.peer.ComponentPeer#getFontMetrics(Font) |
|
718 |
* @see Toolkit#getFontMetrics(Font) |
|
719 |
* @since JDK1.0 |
|
720 |
*/ |
|
721 |
public FontMetrics getFontMetrics(Font font) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
722 |
if (fontLog.isLoggable(PlatformLogger.FINE)) fontLog.fine("Getting font metrics for " + font); |
2 | 723 |
return sun.font.FontDesignMetrics.getMetrics(font); |
724 |
} |
|
725 |
||
726 |
public void setFont(Font f) { |
|
727 |
synchronized (getStateLock()) { |
|
728 |
if (f == null) { |
|
116
9c43d9eb1029
6645856: static field XWindowPeer.defaultFont hides XWindow.defaultFont
son
parents:
2
diff
changeset
|
729 |
f = XWindow.getDefaultFont(); |
2 | 730 |
} |
731 |
font = f; |
|
732 |
} |
|
733 |
// as it stands currently we dont need to do layout or repaint since |
|
734 |
// layout is done in the Component upon setFont. |
|
735 |
//layout(); |
|
736 |
// target.repaint(); |
|
737 |
//repaint()? |
|
738 |
} |
|
739 |
||
740 |
public Font getFont() { |
|
741 |
return font; |
|
742 |
} |
|
743 |
||
744 |
public void updateCursorImmediately() { |
|
745 |
XGlobalCursorManager.getCursorManager().updateCursorImmediately(); |
|
746 |
} |
|
747 |
||
748 |
public void pSetCursor(Cursor cursor) { |
|
749 |
XToolkit.awtLock(); |
|
750 |
try { |
|
751 |
long xcursor = XGlobalCursorManager.getCursor(cursor); |
|
752 |
||
753 |
XSetWindowAttributes xwa = new XSetWindowAttributes(); |
|
754 |
xwa.set_cursor(xcursor); |
|
755 |
||
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
756 |
long valuemask = XConstants.CWCursor; |
2 | 757 |
|
758 |
XlibWrapper.XChangeWindowAttributes(XToolkit.getDisplay(),getWindow(),valuemask,xwa.pData); |
|
759 |
XlibWrapper.XFlush(XToolkit.getDisplay()); |
|
760 |
xwa.dispose(); |
|
761 |
} finally { |
|
762 |
XToolkit.awtUnlock(); |
|
763 |
} |
|
764 |
} |
|
765 |
||
766 |
public Image createImage(ImageProducer producer) { |
|
767 |
return new ToolkitImage(producer); |
|
768 |
} |
|
769 |
||
770 |
public Image createImage(int width, int height) { |
|
771 |
return graphicsConfig.createAcceleratedImage(target, width, height); |
|
772 |
} |
|
773 |
||
774 |
public VolatileImage createVolatileImage(int width, int height) { |
|
775 |
return new SunVolatileImage(target, width, height); |
|
776 |
} |
|
777 |
||
778 |
public boolean prepareImage(Image img, int w, int h, ImageObserver o) { |
|
779 |
return getToolkit().prepareImage(img, w, h, o); |
|
780 |
} |
|
781 |
||
782 |
public int checkImage(Image img, int w, int h, ImageObserver o) { |
|
783 |
return getToolkit().checkImage(img, w, h, o); |
|
784 |
} |
|
785 |
||
786 |
public Dimension preferredSize() { |
|
787 |
return getPreferredSize(); |
|
788 |
} |
|
789 |
||
790 |
public Dimension minimumSize() { |
|
791 |
return getMinimumSize(); |
|
792 |
} |
|
793 |
||
794 |
public Insets getInsets() { |
|
795 |
return new Insets(0, 0, 0, 0); |
|
796 |
} |
|
797 |
||
798 |
public void beginValidate() { |
|
799 |
} |
|
800 |
||
801 |
public void endValidate() { |
|
802 |
} |
|
803 |
||
804 |
||
805 |
/** |
|
806 |
* DEPRECATED: Replaced by getInsets(). |
|
807 |
*/ |
|
808 |
||
809 |
public Insets insets() { |
|
810 |
return getInsets(); |
|
811 |
} |
|
812 |
||
813 |
// Returns true if we are inside begin/endLayout and |
|
814 |
// are waiting for native painting |
|
815 |
public boolean isPaintPending() { |
|
816 |
return paintPending && isLayouting; |
|
817 |
} |
|
818 |
||
819 |
public boolean handlesWheelScrolling() { |
|
820 |
return false; |
|
821 |
} |
|
822 |
||
823 |
public void beginLayout() { |
|
824 |
// Skip all painting till endLayout |
|
825 |
isLayouting = true; |
|
826 |
||
827 |
} |
|
828 |
||
829 |
public void endLayout() { |
|
830 |
if (!paintPending && !paintArea.isEmpty() |
|
831 |
&& !ComponentAccessor.getIgnoreRepaint(target)) |
|
832 |
{ |
|
833 |
// if not waiting for native painting repaint damaged area |
|
834 |
postEvent(new PaintEvent(target, PaintEvent.PAINT, |
|
835 |
new Rectangle())); |
|
836 |
} |
|
837 |
isLayouting = false; |
|
838 |
} |
|
839 |
||
840 |
public Color getWinBackground() { |
|
841 |
return getPeerBackground(); |
|
842 |
} |
|
843 |
||
844 |
static int[] getRGBvals(Color c) { |
|
845 |
||
846 |
int rgbvals[] = new int[3]; |
|
847 |
||
848 |
rgbvals[0] = c.getRed(); |
|
849 |
rgbvals[1] = c.getGreen(); |
|
850 |
rgbvals[2] = c.getBlue(); |
|
851 |
||
852 |
return rgbvals; |
|
853 |
} |
|
854 |
||
855 |
static final int BACKGROUND_COLOR = 0; |
|
856 |
static final int HIGHLIGHT_COLOR = 1; |
|
857 |
static final int SHADOW_COLOR = 2; |
|
858 |
static final int FOREGROUND_COLOR = 3; |
|
859 |
||
860 |
public Color[] getGUIcolors() { |
|
861 |
Color c[] = new Color[4]; |
|
862 |
float backb, highb, shadowb, hue, saturation; |
|
863 |
c[BACKGROUND_COLOR] = getWinBackground(); |
|
864 |
if (c[BACKGROUND_COLOR] == null) { |
|
865 |
c[BACKGROUND_COLOR] = super.getWinBackground(); |
|
866 |
} |
|
867 |
if (c[BACKGROUND_COLOR] == null) { |
|
868 |
c[BACKGROUND_COLOR] = Color.lightGray; |
|
869 |
} |
|
870 |
||
871 |
int[] rgb = getRGBvals(c[BACKGROUND_COLOR]); |
|
872 |
||
873 |
float[] hsb = Color.RGBtoHSB(rgb[0],rgb[1],rgb[2],null); |
|
874 |
||
875 |
hue = hsb[0]; |
|
876 |
saturation = hsb[1]; |
|
877 |
backb = hsb[2]; |
|
878 |
||
879 |
||
880 |
/* Calculate Highlight Brightness */ |
|
881 |
||
882 |
highb = backb + 0.2f; |
|
883 |
shadowb = backb - 0.4f; |
|
884 |
if ((highb > 1.0) ) { |
|
885 |
if ((1.0 - backb) < 0.05) { |
|
886 |
highb = shadowb + 0.25f; |
|
887 |
} else { |
|
888 |
highb = 1.0f; |
|
889 |
} |
|
890 |
} else { |
|
891 |
if (shadowb < 0.0) { |
|
892 |
if ((backb - 0.0) < 0.25) { |
|
893 |
highb = backb + 0.75f; |
|
894 |
shadowb = highb - 0.2f; |
|
895 |
} else { |
|
896 |
shadowb = 0.0f; |
|
897 |
} |
|
898 |
} |
|
899 |
} |
|
900 |
c[HIGHLIGHT_COLOR] = Color.getHSBColor(hue,saturation,highb); |
|
901 |
c[SHADOW_COLOR] = Color.getHSBColor(hue,saturation,shadowb); |
|
902 |
||
903 |
||
904 |
/* |
|
905 |
c[SHADOW_COLOR] = c[BACKGROUND_COLOR].darker(); |
|
906 |
int r2 = c[SHADOW_COLOR].getRed(); |
|
907 |
int g2 = c[SHADOW_COLOR].getGreen(); |
|
908 |
int b2 = c[SHADOW_COLOR].getBlue(); |
|
909 |
*/ |
|
910 |
||
911 |
c[FOREGROUND_COLOR] = getPeerForeground(); |
|
912 |
if (c[FOREGROUND_COLOR] == null) { |
|
913 |
c[FOREGROUND_COLOR] = Color.black; |
|
914 |
} |
|
915 |
/* |
|
916 |
if ((c[BACKGROUND_COLOR].equals(c[HIGHLIGHT_COLOR])) |
|
917 |
&& (c[BACKGROUND_COLOR].equals(c[SHADOW_COLOR]))) { |
|
918 |
c[SHADOW_COLOR] = new Color(c[BACKGROUND_COLOR].getRed() + 75, |
|
919 |
c[BACKGROUND_COLOR].getGreen() + 75, |
|
920 |
c[BACKGROUND_COLOR].getBlue() + 75); |
|
921 |
c[HIGHLIGHT_COLOR] = c[SHADOW_COLOR].brighter(); |
|
922 |
} else if (c[BACKGROUND_COLOR].equals(c[HIGHLIGHT_COLOR])) { |
|
923 |
c[HIGHLIGHT_COLOR] = c[SHADOW_COLOR]; |
|
924 |
c[SHADOW_COLOR] = c[SHADOW_COLOR].darker(); |
|
925 |
} |
|
926 |
*/ |
|
927 |
if (! isEnabled()) { |
|
928 |
c[BACKGROUND_COLOR] = c[BACKGROUND_COLOR].darker(); |
|
929 |
// Reduce the contrast |
|
930 |
// Calculate the NTSC gray (NB: REC709 L* might be better!) |
|
931 |
// for foreground and background; then multiply the foreground |
|
932 |
// by the average lightness |
|
933 |
||
934 |
||
935 |
Color tc = c[BACKGROUND_COLOR]; |
|
936 |
int bg = tc.getRed() * 30 + tc.getGreen() * 59 + tc.getBlue() * 11; |
|
937 |
||
938 |
tc = c[FOREGROUND_COLOR]; |
|
939 |
int fg = tc.getRed() * 30 + tc.getGreen() * 59 + tc.getBlue() * 11; |
|
940 |
||
941 |
float ave = (float) ((fg + bg) / 51000.0); |
|
942 |
// 255 * 100 * 2 |
|
943 |
||
944 |
Color newForeground = new Color((int) (tc.getRed() * ave), |
|
945 |
(int) (tc.getGreen() * ave), |
|
946 |
(int) (tc.getBlue() * ave)); |
|
947 |
||
948 |
if (newForeground.equals(c[FOREGROUND_COLOR])) { |
|
949 |
// This probably means the foreground color is black or white |
|
950 |
newForeground = new Color(ave, ave, ave); |
|
951 |
} |
|
952 |
c[FOREGROUND_COLOR] = newForeground; |
|
953 |
||
954 |
} |
|
955 |
||
956 |
||
957 |
return c; |
|
958 |
} |
|
959 |
||
960 |
/** |
|
961 |
* Returns an array of Colors similar to getGUIcolors(), but using the |
|
962 |
* System colors. This is useful if pieces of a Component (such as |
|
963 |
* the integrated scrollbars of a List) should retain the System color |
|
964 |
* instead of the background color set by Component.setBackground(). |
|
965 |
*/ |
|
966 |
static Color[] getSystemColors() { |
|
967 |
if (systemColors == null) { |
|
968 |
systemColors = new Color[4]; |
|
969 |
systemColors[BACKGROUND_COLOR] = SystemColor.window; |
|
970 |
systemColors[HIGHLIGHT_COLOR] = SystemColor.controlLtHighlight; |
|
971 |
systemColors[SHADOW_COLOR] = SystemColor.controlShadow; |
|
972 |
systemColors[FOREGROUND_COLOR] = SystemColor.windowText; |
|
973 |
} |
|
974 |
return systemColors; |
|
975 |
} |
|
976 |
||
977 |
/** |
|
978 |
* Draw a 3D oval. |
|
979 |
*/ |
|
980 |
public void draw3DOval(Graphics g, Color colors[], |
|
981 |
int x, int y, int w, int h, boolean raised) |
|
982 |
{ |
|
983 |
Color c = g.getColor(); |
|
984 |
g.setColor(raised ? colors[HIGHLIGHT_COLOR] : colors[SHADOW_COLOR]); |
|
985 |
g.drawArc(x, y, w, h, 45, 180); |
|
986 |
g.setColor(raised ? colors[SHADOW_COLOR] : colors[HIGHLIGHT_COLOR]); |
|
987 |
g.drawArc(x, y, w, h, 225, 180); |
|
988 |
g.setColor(c); |
|
989 |
} |
|
990 |
||
991 |
public void draw3DRect(Graphics g, Color colors[], |
|
992 |
int x, int y, int width, int height, boolean raised) |
|
993 |
{ |
|
994 |
Color c = g.getColor(); |
|
995 |
g.setColor(raised ? colors[HIGHLIGHT_COLOR] : colors[SHADOW_COLOR]); |
|
996 |
g.drawLine(x, y, x, y + height); |
|
997 |
g.drawLine(x + 1, y, x + width - 1, y); |
|
998 |
g.setColor(raised ? colors[SHADOW_COLOR] : colors[HIGHLIGHT_COLOR]); |
|
999 |
g.drawLine(x + 1, y + height, x + width, y + height); |
|
1000 |
g.drawLine(x + width, y, x + width, y + height - 1); |
|
1001 |
g.setColor(c); |
|
1002 |
} |
|
1003 |
||
1004 |
/* |
|
1005 |
* drawXXX() methods are used to print the native components by |
|
1006 |
* rendering the Motif look ourselves. |
|
1007 |
* ToDo(aim): needs to query native motif for more accurate color |
|
1008 |
* information. |
|
1009 |
*/ |
|
1010 |
void draw3DOval(Graphics g, Color bg, |
|
1011 |
int x, int y, int w, int h, boolean raised) |
|
1012 |
{ |
|
1013 |
Color c = g.getColor(); |
|
1014 |
Color shadow = bg.darker(); |
|
1015 |
Color highlight = bg.brighter(); |
|
1016 |
||
1017 |
g.setColor(raised ? highlight : shadow); |
|
1018 |
g.drawArc(x, y, w, h, 45, 180); |
|
1019 |
g.setColor(raised ? shadow : highlight); |
|
1020 |
g.drawArc(x, y, w, h, 225, 180); |
|
1021 |
g.setColor(c); |
|
1022 |
} |
|
1023 |
||
1024 |
void draw3DRect(Graphics g, Color bg, |
|
1025 |
int x, int y, int width, int height, |
|
1026 |
boolean raised) { |
|
1027 |
Color c = g.getColor(); |
|
1028 |
Color shadow = bg.darker(); |
|
1029 |
Color highlight = bg.brighter(); |
|
1030 |
||
1031 |
g.setColor(raised ? highlight : shadow); |
|
1032 |
g.drawLine(x, y, x, y + height); |
|
1033 |
g.drawLine(x + 1, y, x + width - 1, y); |
|
1034 |
g.setColor(raised ? shadow : highlight); |
|
1035 |
g.drawLine(x + 1, y + height, x + width, y + height); |
|
1036 |
g.drawLine(x + width, y, x + width, y + height - 1); |
|
1037 |
g.setColor(c); |
|
1038 |
} |
|
1039 |
||
1040 |
void drawScrollbar(Graphics g, Color bg, int thickness, int length, |
|
1041 |
int min, int max, int val, int vis, boolean horizontal) { |
|
1042 |
Color c = g.getColor(); |
|
1043 |
double f = (double)(length - 2*(thickness-1)) / Math.max(1, ((max - min) + vis)); |
|
1044 |
int v1 = thickness + (int)(f * (val - min)); |
|
1045 |
int v2 = (int)(f * vis); |
|
1046 |
int w2 = thickness-4; |
|
1047 |
int tpts_x[] = new int[3]; |
|
1048 |
int tpts_y[] = new int[3]; |
|
1049 |
||
1050 |
if (length < 3*w2 ) { |
|
1051 |
v1 = v2 = 0; |
|
1052 |
if (length < 2*w2 + 2) { |
|
1053 |
w2 = (length-2)/2; |
|
1054 |
} |
|
1055 |
} else if (v2 < 7) { |
|
1056 |
// enforce a minimum handle size |
|
1057 |
v1 = Math.max(0, v1 - ((7 - v2)>>1)); |
|
1058 |
v2 = 7; |
|
1059 |
} |
|
1060 |
||
1061 |
int ctr = thickness/2; |
|
1062 |
int sbmin = ctr - w2/2; |
|
1063 |
int sbmax = ctr + w2/2; |
|
1064 |
||
1065 |
// paint the background slightly darker |
|
1066 |
{ |
|
1067 |
Color d = new Color((int) (bg.getRed() * 0.85), |
|
1068 |
(int) (bg.getGreen() * 0.85), |
|
1069 |
(int) (bg.getBlue() * 0.85)); |
|
1070 |
||
1071 |
g.setColor(d); |
|
1072 |
if (horizontal) { |
|
1073 |
g.fillRect(0, 0, length, thickness); |
|
1074 |
} else { |
|
1075 |
g.fillRect(0, 0, thickness, length); |
|
1076 |
} |
|
1077 |
} |
|
1078 |
||
1079 |
// paint the thumb and arrows in the normal background color |
|
1080 |
g.setColor(bg); |
|
1081 |
if (v1 > 0) { |
|
1082 |
if (horizontal) { |
|
1083 |
g.fillRect(v1, 3, v2, thickness-3); |
|
1084 |
} else { |
|
1085 |
g.fillRect(3, v1, thickness-3, v2); |
|
1086 |
} |
|
1087 |
} |
|
1088 |
||
1089 |
tpts_x[0] = ctr; tpts_y[0] = 2; |
|
1090 |
tpts_x[1] = sbmin; tpts_y[1] = w2; |
|
1091 |
tpts_x[2] = sbmax; tpts_y[2] = w2; |
|
1092 |
if (horizontal) { |
|
1093 |
g.fillPolygon(tpts_y, tpts_x, 3); |
|
1094 |
} else { |
|
1095 |
g.fillPolygon(tpts_x, tpts_y, 3); |
|
1096 |
} |
|
1097 |
||
1098 |
tpts_y[0] = length-2; |
|
1099 |
tpts_y[1] = length-w2; |
|
1100 |
tpts_y[2] = length-w2; |
|
1101 |
if (horizontal) { |
|
1102 |
g.fillPolygon(tpts_y, tpts_x, 3); |
|
1103 |
} else { |
|
1104 |
g.fillPolygon(tpts_x, tpts_y, 3); |
|
1105 |
} |
|
1106 |
||
1107 |
Color highlight = bg.brighter(); |
|
1108 |
||
1109 |
// // // // draw the "highlighted" edges |
|
1110 |
g.setColor(highlight); |
|
1111 |
||
1112 |
// outline & arrows |
|
1113 |
if (horizontal) { |
|
1114 |
g.drawLine(1, thickness, length - 1, thickness); |
|
1115 |
g.drawLine(length - 1, 1, length - 1, thickness); |
|
1116 |
||
1117 |
// arrows |
|
1118 |
g.drawLine(1, ctr, w2, sbmin); |
|
1119 |
g.drawLine(length - w2, sbmin, length - w2, sbmax); |
|
1120 |
g.drawLine(length - w2, sbmin, length - 2, ctr); |
|
1121 |
||
1122 |
} else { |
|
1123 |
g.drawLine(thickness, 1, thickness, length - 1); |
|
1124 |
g.drawLine(1, length - 1, thickness, length - 1); |
|
1125 |
||
1126 |
// arrows |
|
1127 |
g.drawLine(ctr, 1, sbmin, w2); |
|
1128 |
g.drawLine(sbmin, length - w2, sbmax, length - w2); |
|
1129 |
g.drawLine(sbmin, length - w2, ctr, length - 2); |
|
1130 |
} |
|
1131 |
||
1132 |
// thumb |
|
1133 |
if (v1 > 0) { |
|
1134 |
if (horizontal) { |
|
1135 |
g.drawLine(v1, 2, v1 + v2, 2); |
|
1136 |
g.drawLine(v1, 2, v1, thickness-3); |
|
1137 |
} else { |
|
1138 |
g.drawLine(2, v1, 2, v1 + v2); |
|
1139 |
g.drawLine(2, v1, thickness-3, v1); |
|
1140 |
} |
|
1141 |
} |
|
1142 |
||
1143 |
Color shadow = bg.darker(); |
|
1144 |
||
1145 |
// // // // draw the "shadowed" edges |
|
1146 |
g.setColor(shadow); |
|
1147 |
||
1148 |
// outline && arrows |
|
1149 |
if (horizontal) { |
|
1150 |
g.drawLine(0, 0, 0, thickness); |
|
1151 |
g.drawLine(0, 0, length - 1, 0); |
|
1152 |
||
1153 |
// arrows |
|
1154 |
g.drawLine(w2, sbmin, w2, sbmax); |
|
1155 |
g.drawLine(w2, sbmax, 1, ctr); |
|
1156 |
g.drawLine(length-2, ctr, length-w2, sbmax); |
|
1157 |
||
1158 |
} else { |
|
1159 |
g.drawLine(0, 0, thickness, 0); |
|
1160 |
g.drawLine(0, 0, 0, length - 1); |
|
1161 |
||
1162 |
// arrows |
|
1163 |
g.drawLine(sbmin, w2, sbmax, w2); |
|
1164 |
g.drawLine(sbmax, w2, ctr, 1); |
|
1165 |
g.drawLine(ctr, length-2, sbmax, length-w2); |
|
1166 |
} |
|
1167 |
||
1168 |
// thumb |
|
1169 |
if (v1 > 0) { |
|
1170 |
if (horizontal) { |
|
1171 |
g.drawLine(v1 + v2, 2, v1 + v2, thickness-2); |
|
1172 |
g.drawLine(v1, thickness-2, v1 + v2, thickness-2); |
|
1173 |
} else { |
|
1174 |
g.drawLine(2, v1 + v2, thickness-2, v1 + v2); |
|
1175 |
g.drawLine(thickness-2, v1, thickness-2, v1 + v2); |
|
1176 |
} |
|
1177 |
} |
|
1178 |
g.setColor(c); |
|
1179 |
} |
|
1180 |
||
1181 |
/** |
|
1182 |
* The following multibuffering-related methods delegate to our |
|
1183 |
* associated GraphicsConfig (X11 or GLX) to handle the appropriate |
|
1184 |
* native windowing system specific actions. |
|
1185 |
*/ |
|
1186 |
||
887 | 1187 |
private BufferCapabilities backBufferCaps; |
1188 |
||
2 | 1189 |
public void createBuffers(int numBuffers, BufferCapabilities caps) |
1190 |
throws AWTException |
|
1191 |
{ |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1192 |
if (buffersLog.isLoggable(PlatformLogger.FINE)) { |
2 | 1193 |
buffersLog.fine("createBuffers(" + numBuffers + ", " + caps + ")"); |
1194 |
} |
|
887 | 1195 |
// set the caps first, they're used when creating the bb |
1196 |
backBufferCaps = caps; |
|
2 | 1197 |
backBuffer = graphicsConfig.createBackBuffer(this, numBuffers, caps); |
1198 |
xBackBuffer = graphicsConfig.createBackBufferImage(target, |
|
1199 |
backBuffer); |
|
1200 |
} |
|
1201 |
||
887 | 1202 |
@Override |
1203 |
public BufferCapabilities getBackBufferCaps() { |
|
1204 |
return backBufferCaps; |
|
1205 |
} |
|
1206 |
||
1207 |
public void flip(int x1, int y1, int x2, int y2, |
|
1208 |
BufferCapabilities.FlipContents flipAction) |
|
1209 |
{ |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1210 |
if (buffersLog.isLoggable(PlatformLogger.FINE)) { |
2 | 1211 |
buffersLog.fine("flip(" + flipAction + ")"); |
1212 |
} |
|
1213 |
if (backBuffer == 0) { |
|
1214 |
throw new IllegalStateException("Buffers have not been created"); |
|
1215 |
} |
|
887 | 1216 |
graphicsConfig.flip(this, target, xBackBuffer, |
1217 |
x1, y1, x2, y2, flipAction); |
|
2 | 1218 |
} |
1219 |
||
1220 |
public Image getBackBuffer() { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1221 |
if (buffersLog.isLoggable(PlatformLogger.FINE)) { |
2 | 1222 |
buffersLog.fine("getBackBuffer()"); |
1223 |
} |
|
1224 |
if (backBuffer == 0) { |
|
1225 |
throw new IllegalStateException("Buffers have not been created"); |
|
1226 |
} |
|
1227 |
return xBackBuffer; |
|
1228 |
} |
|
1229 |
||
1230 |
public void destroyBuffers() { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1231 |
if (buffersLog.isLoggable(PlatformLogger.FINE)) { |
2 | 1232 |
buffersLog.fine("destroyBuffers()"); |
1233 |
} |
|
1234 |
graphicsConfig.destroyBackBuffer(backBuffer); |
|
1235 |
backBuffer = 0; |
|
1236 |
xBackBuffer = null; |
|
1237 |
} |
|
1238 |
||
1239 |
// End of multi-buffering |
|
1240 |
||
1241 |
public void notifyTextComponentChange(boolean add){ |
|
1242 |
Container parent = ComponentAccessor.getParent_NoClientCode(target); |
|
1243 |
while(!(parent == null || |
|
1244 |
parent instanceof java.awt.Frame || |
|
1245 |
parent instanceof java.awt.Dialog)) { |
|
1246 |
parent = ComponentAccessor.getParent_NoClientCode(parent); |
|
1247 |
} |
|
1248 |
||
1249 |
/* FIX ME - FIX ME need to implement InputMethods |
|
1250 |
if (parent instanceof java.awt.Frame || |
|
1251 |
parent instanceof java.awt.Dialog) { |
|
1252 |
if (add) |
|
1253 |
((MInputMethodControl)parent.getPeer()).addTextComponent((MComponentPeer)this); |
|
1254 |
else |
|
1255 |
((MInputMethodControl)parent.getPeer()).removeTextComponent((MComponentPeer)this); |
|
1256 |
} |
|
1257 |
*/ |
|
1258 |
} |
|
1259 |
||
1260 |
/** |
|
1261 |
* Returns true if this event is disabled and shouldn't be processed by window |
|
1262 |
* Currently if target component is disabled the following event will be disabled on window: |
|
1263 |
* ButtonPress, ButtonRelease, KeyPress, KeyRelease, EnterNotify, LeaveNotify, MotionNotify |
|
1264 |
*/ |
|
1265 |
protected boolean isEventDisabled(XEvent e) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1266 |
enableLog.finest("Component is {1}, checking for disabled event {0}", e, (isEnabled()?"enabled":"disable")); |
2 | 1267 |
if (!isEnabled()) { |
1268 |
switch (e.get_type()) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1269 |
case XConstants.ButtonPress: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1270 |
case XConstants.ButtonRelease: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1271 |
case XConstants.KeyPress: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1272 |
case XConstants.KeyRelease: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1273 |
case XConstants.EnterNotify: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1274 |
case XConstants.LeaveNotify: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1275 |
case XConstants.MotionNotify: |
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1276 |
enableLog.finer("Event {0} is disable", e); |
2 | 1277 |
return true; |
1278 |
} |
|
1279 |
} |
|
1280 |
switch(e.get_type()) { |
|
439
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1281 |
case XConstants.MapNotify: |
3488710b02f8
6623459: Get rid of XConstant, XProtocolConstants and XUtilConstants antipattern
dav
parents:
116
diff
changeset
|
1282 |
case XConstants.UnmapNotify: |
2 | 1283 |
return true; |
1284 |
} |
|
1285 |
return super.isEventDisabled(e); |
|
1286 |
} |
|
1287 |
||
1288 |
Color getPeerBackground() { |
|
1289 |
return background; |
|
1290 |
} |
|
1291 |
||
1292 |
Color getPeerForeground() { |
|
1293 |
return foreground; |
|
1294 |
} |
|
1295 |
||
1296 |
Font getPeerFont() { |
|
1297 |
return font; |
|
1298 |
} |
|
1299 |
||
1300 |
Dimension getPeerSize() { |
|
1301 |
return new Dimension(width,height); |
|
1302 |
} |
|
1303 |
||
1304 |
public void setBoundsOperation(int operation) { |
|
1305 |
synchronized(getStateLock()) { |
|
1306 |
if (boundsOperation == DEFAULT_OPERATION) { |
|
1307 |
boundsOperation = operation; |
|
1308 |
} else if (operation == RESET_OPERATION) { |
|
1309 |
boundsOperation = DEFAULT_OPERATION; |
|
1310 |
} |
|
1311 |
} |
|
1312 |
} |
|
1313 |
||
1314 |
static String operationToString(int operation) { |
|
1315 |
switch (operation) { |
|
1316 |
case SET_LOCATION: |
|
1317 |
return "SET_LOCATION"; |
|
1318 |
case SET_SIZE: |
|
1319 |
return "SET_SIZE"; |
|
1320 |
case SET_CLIENT_SIZE: |
|
1321 |
return "SET_CLIENT_SIZE"; |
|
1322 |
default: |
|
1323 |
case SET_BOUNDS: |
|
1324 |
return "SET_BOUNDS"; |
|
1325 |
} |
|
1326 |
} |
|
1327 |
||
2462
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1328 |
/** |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1329 |
* Lowers this component at the bottom of the above HW peer. If the above parameter |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1330 |
* is null then the method places this component at the top of the Z-order. |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1331 |
*/ |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1332 |
public void setZOrder(ComponentPeer above) { |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1333 |
long aboveWindow = (above != null) ? ((XComponentPeer)above).getWindow() : 0; |
2 | 1334 |
|
2462
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1335 |
XToolkit.awtLock(); |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1336 |
try{ |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1337 |
XlibWrapper.SetZOrder(XToolkit.getDisplay(), getWindow(), aboveWindow); |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1338 |
}finally{ |
192552ca8292
6809227: poor performance on Panel.Add() method in jdk6
dcherepanov
parents:
2459
diff
changeset
|
1339 |
XToolkit.awtUnlock(); |
2 | 1340 |
} |
1341 |
} |
|
1342 |
||
1343 |
private void addTree(Collection order, Set set, Container cont) { |
|
1344 |
for (int i = 0; i < cont.getComponentCount(); i++) { |
|
1345 |
Component comp = cont.getComponent(i); |
|
1346 |
ComponentPeer peer = comp.getPeer(); |
|
1347 |
if (peer instanceof XComponentPeer) { |
|
1348 |
Long window = Long.valueOf(((XComponentPeer)peer).getWindow()); |
|
1349 |
if (!set.contains(window)) { |
|
1350 |
set.add(window); |
|
1351 |
order.add(window); |
|
1352 |
} |
|
1353 |
} else if (comp instanceof Container) { |
|
1354 |
// It is lightweight container, it might contain heavyweight components attached to this |
|
1355 |
// peer |
|
1356 |
addTree(order, set, (Container)comp); |
|
1357 |
} |
|
1358 |
} |
|
1359 |
} |
|
1360 |
||
1361 |
/****** DropTargetPeer implementation ********************/ |
|
1362 |
||
1363 |
public void addDropTarget(DropTarget dt) { |
|
1364 |
Component comp = target; |
|
1365 |
while(!(comp == null || comp instanceof Window)) { |
|
1366 |
comp = comp.getParent(); |
|
1367 |
} |
|
1368 |
||
1369 |
if (comp instanceof Window) { |
|
1370 |
XWindowPeer wpeer = (XWindowPeer)(comp.getPeer()); |
|
1371 |
if (wpeer != null) { |
|
1372 |
wpeer.addDropTarget(); |
|
1373 |
} |
|
1374 |
} |
|
1375 |
} |
|
1376 |
||
1377 |
public void removeDropTarget(DropTarget dt) { |
|
1378 |
Component comp = target; |
|
1379 |
while(!(comp == null || comp instanceof Window)) { |
|
1380 |
comp = comp.getParent(); |
|
1381 |
} |
|
1382 |
||
1383 |
if (comp instanceof Window) { |
|
1384 |
XWindowPeer wpeer = (XWindowPeer)(comp.getPeer()); |
|
1385 |
if (wpeer != null) { |
|
1386 |
wpeer.removeDropTarget(); |
|
1387 |
} |
|
1388 |
} |
|
1389 |
} |
|
1390 |
||
1391 |
/** |
|
1392 |
* Applies the shape to the X-window. |
|
1393 |
* @since 1.7 |
|
1394 |
*/ |
|
1395 |
public void applyShape(Region shape) { |
|
1396 |
if (XlibUtil.isShapingSupported()) { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1397 |
if (shapeLog.isLoggable(PlatformLogger.FINER)) { |
2 | 1398 |
shapeLog.finer( |
1399 |
"*** INFO: Setting shape: PEER: " + this |
|
1400 |
+ "; WINDOW: " + getWindow() |
|
1401 |
+ "; TARGET: " + target |
|
1402 |
+ "; SHAPE: " + shape); |
|
1403 |
} |
|
1404 |
XToolkit.awtLock(); |
|
1405 |
try { |
|
1978
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1406 |
if (shape != null) { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1407 |
XlibWrapper.SetRectangularShape( |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1408 |
XToolkit.getDisplay(), |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1409 |
getWindow(), |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1410 |
shape.getLoX(), shape.getLoY(), |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1411 |
shape.getHiX(), shape.getHiY(), |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1412 |
(shape.isRectangular() ? null : shape) |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1413 |
); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1414 |
} else { |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1415 |
XlibWrapper.SetRectangularShape( |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1416 |
XToolkit.getDisplay(), |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1417 |
getWindow(), |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1418 |
0, 0, |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1419 |
0, 0, |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1420 |
null |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1421 |
); |
8b981ce05cd0
6797195: Forward-port enhancements for hw/lw mixing from 6u12 to 7
anthony
parents:
887
diff
changeset
|
1422 |
} |
2 | 1423 |
} finally { |
1424 |
XToolkit.awtUnlock(); |
|
1425 |
} |
|
1426 |
} else { |
|
3938
ef327bd847c0
6879044: Eliminate the dependency on logging from the AWT/2D/Swing classes
mchung
parents:
2805
diff
changeset
|
1427 |
if (shapeLog.isLoggable(PlatformLogger.FINER)) { |
2 | 1428 |
shapeLog.finer("*** WARNING: Shaping is NOT supported!"); |
1429 |
} |
|
1430 |
} |
|
1431 |
} |
|
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2458
diff
changeset
|
1432 |
|
2805
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1433 |
public boolean updateGraphicsData(GraphicsConfiguration gc) { |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1434 |
int oldVisual = -1, newVisual = -1; |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1435 |
|
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1436 |
if (graphicsConfig != null) { |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1437 |
oldVisual = graphicsConfig.getVisual(); |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1438 |
} |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1439 |
if (gc != null && gc instanceof X11GraphicsConfig) { |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1440 |
newVisual = ((X11GraphicsConfig)gc).getVisual(); |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1441 |
} |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1442 |
|
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1443 |
// If the new visual differs from the old one, the peer must be |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1444 |
// recreated because X11 does not allow changing the visual on the fly. |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1445 |
// So we even skip the initGraphicsConfiguration() call. |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1446 |
// The initial assignment should happen though, hence the != -1 thing. |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1447 |
if (oldVisual != -1 && oldVisual != newVisual) { |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1448 |
return true; |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1449 |
} |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1450 |
|
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2458
diff
changeset
|
1451 |
initGraphicsConfiguration(); |
2805
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1452 |
doValidateSurface(); |
9f18d7e66042
6812298: Dynamic GraphicsConfig changes don't work on X11 platforms
anthony
parents:
2464
diff
changeset
|
1453 |
return false; |
2459
08f3416ff334
6804747: Ensure consistent graphicsConfig member across components hierarchy
anthony
parents:
2458
diff
changeset
|
1454 |
} |
2 | 1455 |
} |