001: /*
002: * Copyright 2003-2005 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.Component;
029: import java.awt.Cursor;
030: import java.awt.Window;
031:
032: import java.awt.datatransfer.Transferable;
033:
034: import java.awt.dnd.DragSourceContext;
035: import java.awt.dnd.DragSourceDragEvent;
036: import java.awt.dnd.DragSourceDropEvent;
037: import java.awt.dnd.DragSourceEvent;
038: import java.awt.dnd.DragGestureEvent;
039: import java.awt.dnd.InvalidDnDOperationException;
040:
041: import java.awt.event.InputEvent;
042:
043: import java.util.Map;
044:
045: import sun.awt.SunToolkit;
046:
047: import sun.awt.dnd.SunDragSourceContextPeer;
048: import sun.awt.dnd.SunDropTargetContextPeer;
049:
050: /**
051: * The X11DragSourceContextPeer class is the class responsible for handling
052: * the interaction between the XDnD/Motif DnD subsystem and Java drag sources.
053: *
054: * @since 1.5
055: */
056: final class X11DragSourceContextPeer extends SunDragSourceContextPeer {
057:
058: private static final X11DragSourceContextPeer theInstance = new X11DragSourceContextPeer(
059: null);
060:
061: /**
062: * construct a new X11DragSourceContextPeer
063: */
064:
065: private X11DragSourceContextPeer(DragGestureEvent dge) {
066: super (dge);
067: }
068:
069: static X11DragSourceContextPeer createDragSourceContextPeer(
070: DragGestureEvent dge) throws InvalidDnDOperationException {
071: theInstance.setTrigger(dge);
072: return theInstance;
073: }
074:
075: protected void startDrag(Transferable transferable, long[] formats,
076: Map formatMap) {
077: Component component = getTrigger().getComponent();
078: Component c = null;
079: MWindowPeer wpeer = null;
080:
081: for (c = component; c != null
082: && !(c instanceof java.awt.Window); c = MComponentPeer
083: .getParent_NoClientCode(c))
084: ;
085:
086: if (c instanceof Window) {
087: wpeer = (MWindowPeer) c.getPeer();
088: }
089:
090: if (wpeer == null) {
091: throw new InvalidDnDOperationException(
092: "Cannot find top-level for the drag source component");
093: }
094:
095: startDrag(component, wpeer, transferable, getTrigger()
096: .getTriggerEvent(), getCursor(),
097: getCursor() == null ? 0 : getCursor().getType(),
098: getDragSourceContext().getSourceActions(), formats,
099: formatMap);
100:
101: /* This implementation doesn't use native context */
102: setNativeContext(0);
103:
104: SunDropTargetContextPeer
105: .setCurrentJVMLocalSourceTransferable(transferable);
106: }
107:
108: /**
109: * downcall into native code
110: */
111:
112: private native long startDrag(Component component,
113: MWindowPeer wpeer, Transferable transferable,
114: InputEvent nativeTrigger, Cursor c, int ctype, int actions,
115: long[] formats, Map formatMap);
116:
117: /**
118: * set cursor
119: */
120:
121: public void setCursor(Cursor c) throws InvalidDnDOperationException {
122: SunToolkit.awtLock();
123: super .setCursor(c);
124: SunToolkit.awtUnlock();
125: }
126:
127: protected native void setNativeCursor(long nativeCtxt, Cursor c,
128: int cType);
129:
130: }
|