1 /*
2 * Copyright (c) 2011, 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 package sun.lwawt;
27
28 import java.awt.Component;
29 import java.awt.Container;
30 import java.awt.Cursor;
31 import java.awt.Point;
32
33 import java.util.concurrent.atomic.AtomicBoolean;
34
35 import sun.awt.SunToolkit;
36
37 public abstract class LWCursorManager {
38
39 /**
40 * A flag to indicate if the update is scheduled, so we don't process it
41 * twice.
42 */
43 private final AtomicBoolean updatePending = new AtomicBoolean(false);
44
45 protected LWCursorManager() {
46 }
47
48 /**
49 * Sets the cursor to correspond the component currently under mouse.
50 *
51 * This method should not be executed on the toolkit thread as it
52 * calls to user code (e.g. Container.findComponentAt).
53 */
54 public final void updateCursor() {
92 }
93
94 /**
95 * Returns the first visible, enabled and showing component under cursor.
96 * Returns null for modal blocked windows.
97 *
98 * @param cursorPos Current cursor position.
99 * @return Component or null.
100 */
101 private static final Component findComponent(final Point cursorPos) {
102 final LWComponentPeer<?, ?> peer = LWWindowPeer.getPeerUnderCursor();
103 Component c = null;
104 if (peer != null && peer.getWindowPeerOrSelf().getBlocker() == null) {
105 c = peer.getTarget();
106 if (c instanceof Container) {
107 final Point p = peer.getLocationOnScreen();
108 c = ((Container) c).findComponentAt(cursorPos.x - p.x,
109 cursorPos.y - p.y);
110 }
111 while (c != null) {
112 if (c.isVisible() && c.isEnabled() && (c.getPeer() != null)) {
113 break;
114 }
115 c = c.getParent();
116 }
117 }
118 return c;
119 }
120
121 /**
122 * Returns the current cursor position.
123 */
124 // TODO: make it public to reuse for MouseInfo
125 protected abstract Point getCursorPosition();
126
127 /**
128 * Sets a cursor. The cursor can be null if the mouse is not over a Java
129 * window.
130 * @param cursor the new {@code Cursor}.
131 */
132 protected abstract void setCursor(Cursor cursor);
|
1 /*
2 * Copyright (c) 2011, 2013, 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 package sun.lwawt;
27
28 import java.awt.Component;
29 import java.awt.Container;
30 import java.awt.Cursor;
31 import java.awt.Point;
32
33 import java.util.concurrent.atomic.AtomicBoolean;
34
35 import sun.awt.AWTAccessor;
36 import sun.awt.SunToolkit;
37
38 public abstract class LWCursorManager {
39
40 /**
41 * A flag to indicate if the update is scheduled, so we don't process it
42 * twice.
43 */
44 private final AtomicBoolean updatePending = new AtomicBoolean(false);
45
46 protected LWCursorManager() {
47 }
48
49 /**
50 * Sets the cursor to correspond the component currently under mouse.
51 *
52 * This method should not be executed on the toolkit thread as it
53 * calls to user code (e.g. Container.findComponentAt).
54 */
55 public final void updateCursor() {
93 }
94
95 /**
96 * Returns the first visible, enabled and showing component under cursor.
97 * Returns null for modal blocked windows.
98 *
99 * @param cursorPos Current cursor position.
100 * @return Component or null.
101 */
102 private static final Component findComponent(final Point cursorPos) {
103 final LWComponentPeer<?, ?> peer = LWWindowPeer.getPeerUnderCursor();
104 Component c = null;
105 if (peer != null && peer.getWindowPeerOrSelf().getBlocker() == null) {
106 c = peer.getTarget();
107 if (c instanceof Container) {
108 final Point p = peer.getLocationOnScreen();
109 c = ((Container) c).findComponentAt(cursorPos.x - p.x,
110 cursorPos.y - p.y);
111 }
112 while (c != null) {
113 final Object p = AWTAccessor.getComponentAccessor().getPeer(c);
114 if (c.isVisible() && c.isEnabled() && p != null) {
115 break;
116 }
117 c = c.getParent();
118 }
119 }
120 return c;
121 }
122
123 /**
124 * Returns the current cursor position.
125 */
126 // TODO: make it public to reuse for MouseInfo
127 protected abstract Point getCursorPosition();
128
129 /**
130 * Sets a cursor. The cursor can be null if the mouse is not over a Java
131 * window.
132 * @param cursor the new {@code Cursor}.
133 */
134 protected abstract void setCursor(Cursor cursor);
|