001: /*
002: * Copyright 1999-2004 Sun Microsystems, Inc. All Rights Reserved.
003: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
004: *
005: * This code is free software; you can redistribute it and/or modify it
006: * under the terms of the GNU General Public License version 2 only, as
007: * published by the Free Software Foundation. Sun designates this
008: * particular file as subject to the "Classpath" exception as provided
009: * by Sun in the LICENSE file that accompanied this code.
010: *
011: * This code is distributed in the hope that it will be useful, but WITHOUT
012: * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
013: * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
014: * version 2 for more details (a copy is included in the LICENSE file that
015: * accompanied this code).
016: *
017: * You should have received a copy of the GNU General Public License version
018: * 2 along with this work; if not, write to the Free Software Foundation,
019: * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
020: *
021: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
022: * CA 95054 USA or visit www.sun.com if you need additional information or
023: * have any questions.
024: */
025:
026: package sun.awt.motif;
027:
028: import java.awt.*;
029: import sun.awt.GlobalCursorManager;
030: import sun.awt.GlobalCursorManager.*;
031:
032: public final class MGlobalCursorManager extends GlobalCursorManager {
033:
034: static {
035: cacheInit();
036: }
037:
038: private native static void cacheInit();
039:
040: // cached nativeContainer
041: private Component nativeContainer;
042:
043: /**
044: * The MGlobalCursorManager is a singleton.
045: */
046: private static MGlobalCursorManager manager;
047:
048: static GlobalCursorManager getCursorManager() {
049: if (manager == null) {
050: manager = new MGlobalCursorManager();
051: }
052: return manager;
053: }
054:
055: /**
056: * Should be called in response to a native mouse enter or native mouse
057: * button released message. Should not be called during a mouse drag.
058: */
059: static void nativeUpdateCursor(Component heavy) {
060: MGlobalCursorManager.getCursorManager()
061: .updateCursorLater(heavy);
062: }
063:
064: protected void setCursor(Component comp, Cursor cursor,
065: boolean useCache) {
066: if (comp == null) {
067: return;
068: }
069:
070: Cursor cur = useCache ? cursor : getCapableCursor(comp);
071:
072: Component nc = useCache ? nativeContainer
073: : getNativeContainer(comp);
074:
075: // System.out.println(" set cursor="+cursor+" on "+comp+" new curs="+cur);
076: if (nc != null && nc.isDisplayable()) {
077: nativeContainer = nc;
078: ((MComponentPeer) nc.getPeer()).pSetCursor(cur);
079: }
080: }
081:
082: private Component getNativeContainer(Component comp) {
083: while (comp != null && comp.isLightweight()) {
084: comp = comp.getParent();
085: }
086: return comp;
087: }
088:
089: protected native void getCursorPos(Point p);
090:
091: protected native Component findHeavyweightUnderCursor();
092:
093: /*
094: * two native methods to call corresponding methods in Container and
095: * Component
096: */
097: protected native Component findComponentAt(Container con, int x,
098: int y);
099:
100: protected native Point getLocationOnScreen(Component com);
101:
102: protected Component findHeavyweightUnderCursor(boolean useCache) {
103: return findHeavyweightUnderCursor();
104: }
105:
106: private Cursor getCapableCursor(Component comp) {
107: Component c = comp;
108: while ((c != null) && !(c instanceof Window) && c.isEnabled()
109: && c.isVisible() && c.isDisplayable()) {
110: c = c.getParent();
111: }
112: if (c instanceof Window) {
113: return (c.isEnabled() && c.isVisible() && c.isDisplayable() && comp
114: .isEnabled()) ? comp.getCursor() : Cursor
115: .getPredefinedCursor(Cursor.DEFAULT_CURSOR);
116: } else if (c == null) {
117: return null;
118: }
119: return getCapableCursor(c.getParent());
120: }
121: }
|