1 /* |
|
2 * Copyright 1997-2005 Sun Microsystems, Inc. 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. 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 |
|
26 package sun.awt.motif; |
|
27 |
|
28 import java.awt.Component; |
|
29 import java.awt.Cursor; |
|
30 import java.awt.Image; |
|
31 import java.awt.Point; |
|
32 |
|
33 import java.awt.datatransfer.Transferable; |
|
34 |
|
35 import java.awt.dnd.DragSourceContext; |
|
36 import java.awt.dnd.DragGestureEvent; |
|
37 import java.awt.dnd.InvalidDnDOperationException; |
|
38 |
|
39 import java.awt.event.InputEvent; |
|
40 |
|
41 import java.awt.peer.ComponentPeer; |
|
42 import java.awt.peer.LightweightPeer; |
|
43 |
|
44 import java.util.Map; |
|
45 import sun.awt.SunToolkit; |
|
46 import sun.awt.dnd.SunDragSourceContextPeer; |
|
47 |
|
48 /** |
|
49 * <p> |
|
50 * TBC |
|
51 * </p> |
|
52 * |
|
53 * @since JDK1.2 |
|
54 * |
|
55 */ |
|
56 |
|
57 final class MDragSourceContextPeer extends SunDragSourceContextPeer { |
|
58 |
|
59 private static final MDragSourceContextPeer theInstance = |
|
60 new MDragSourceContextPeer(null); |
|
61 |
|
62 /** |
|
63 * construct a new MDragSourceContextPeer |
|
64 */ |
|
65 |
|
66 private MDragSourceContextPeer(DragGestureEvent dge) { |
|
67 super(dge); |
|
68 } |
|
69 |
|
70 static MDragSourceContextPeer createDragSourceContextPeer(DragGestureEvent dge) throws InvalidDnDOperationException { |
|
71 theInstance.setTrigger(dge); |
|
72 return theInstance; |
|
73 } |
|
74 |
|
75 protected void startDrag(Transferable transferable, |
|
76 long[] formats, Map formatMap) { |
|
77 try { |
|
78 long nativeCtxtLocal = startDrag(getTrigger().getComponent(), |
|
79 transferable, |
|
80 getTrigger().getTriggerEvent(), |
|
81 getCursor(), |
|
82 getCursor() == null ? 0 : getCursor().getType(), |
|
83 getDragSourceContext().getSourceActions(), |
|
84 formats, |
|
85 formatMap); |
|
86 setNativeContext(nativeCtxtLocal); |
|
87 } catch (Exception e) { |
|
88 throw new InvalidDnDOperationException("failed to create native peer: " + e); |
|
89 } |
|
90 |
|
91 if (getNativeContext() == 0) { |
|
92 throw new InvalidDnDOperationException("failed to create native peer"); |
|
93 } |
|
94 |
|
95 MDropTargetContextPeer.setCurrentJVMLocalSourceTransferable(transferable); |
|
96 } |
|
97 |
|
98 /** |
|
99 * downcall into native code |
|
100 */ |
|
101 |
|
102 private native long startDrag(Component component, |
|
103 Transferable transferable, |
|
104 InputEvent nativeTrigger, |
|
105 Cursor c, int ctype, int actions, |
|
106 long[] formats, Map formatMap); |
|
107 |
|
108 /** |
|
109 * set cursor |
|
110 */ |
|
111 |
|
112 public void setCursor(Cursor c) throws InvalidDnDOperationException { |
|
113 SunToolkit.awtLock(); |
|
114 super.setCursor(c); |
|
115 SunToolkit.awtUnlock(); |
|
116 } |
|
117 |
|
118 protected native void setNativeCursor(long nativeCtxt, Cursor c, int cType); |
|
119 |
|
120 } |
|