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.datatransfer.DataFlavor; |
|
29 import java.awt.datatransfer.UnsupportedFlavorException; |
|
30 |
|
31 import java.awt.dnd.DnDConstants; |
|
32 import java.awt.dnd.InvalidDnDOperationException; |
|
33 |
|
34 import java.io.InputStream; |
|
35 |
|
36 import java.util.Map; |
|
37 |
|
38 import java.io.IOException; |
|
39 import sun.awt.dnd.SunDropTargetContextPeer; |
|
40 import sun.awt.SunToolkit; |
|
41 |
|
42 /** |
|
43 * <p> |
|
44 * The MDropTargetContextPeer class is the class responsible for handling |
|
45 * the interaction between the Motif DnD system and Java. |
|
46 * </p> |
|
47 * |
|
48 * @since JDK1.2 |
|
49 * |
|
50 */ |
|
51 |
|
52 final class MDropTargetContextPeer extends SunDropTargetContextPeer { |
|
53 |
|
54 private long nativeDropTransfer; |
|
55 |
|
56 long nativeDataAvailable = 0; |
|
57 Object nativeData = null; |
|
58 |
|
59 /** |
|
60 * create the peer |
|
61 */ |
|
62 |
|
63 static MDropTargetContextPeer createMDropTargetContextPeer() { |
|
64 return new MDropTargetContextPeer(); |
|
65 } |
|
66 |
|
67 /** |
|
68 * create the peer |
|
69 */ |
|
70 |
|
71 private MDropTargetContextPeer() { |
|
72 super(); |
|
73 } |
|
74 |
|
75 protected Object getNativeData(long format) { |
|
76 SunToolkit.awtLock(); |
|
77 if (nativeDropTransfer == 0) { |
|
78 nativeDropTransfer = startTransfer(getNativeDragContext(), |
|
79 format); |
|
80 } else { |
|
81 addTransfer (nativeDropTransfer, format); |
|
82 } |
|
83 |
|
84 for (nativeDataAvailable = 0; |
|
85 format != nativeDataAvailable;) { |
|
86 try { |
|
87 SunToolkit.awtLockWait(); |
|
88 } catch (Throwable e) { |
|
89 e.printStackTrace(); |
|
90 } |
|
91 } |
|
92 SunToolkit.awtUnlock(); |
|
93 |
|
94 return nativeData; |
|
95 } |
|
96 |
|
97 /** |
|
98 * signal drop complete |
|
99 */ |
|
100 |
|
101 protected void doDropDone(boolean success, int dropAction, |
|
102 boolean isLocal) { |
|
103 dropDone(getNativeDragContext(), nativeDropTransfer, isLocal, |
|
104 success, dropAction); |
|
105 } |
|
106 |
|
107 /** |
|
108 * notify transfer complete |
|
109 */ |
|
110 |
|
111 private void newData(long format, String type, byte[] data) { |
|
112 nativeDataAvailable = format; |
|
113 nativeData = data; |
|
114 |
|
115 SunToolkit.awtLockNotifyAll(); |
|
116 } |
|
117 |
|
118 /** |
|
119 * notify transfer failed |
|
120 */ |
|
121 |
|
122 private void transferFailed(long format) { |
|
123 nativeDataAvailable = format; |
|
124 nativeData = null; |
|
125 |
|
126 SunToolkit.awtLockNotifyAll(); |
|
127 } |
|
128 |
|
129 /** |
|
130 * schedule a native DnD transfer |
|
131 */ |
|
132 |
|
133 private native long startTransfer(long nativeDragContext, long format); |
|
134 |
|
135 /** |
|
136 * schedule a native DnD data transfer |
|
137 */ |
|
138 |
|
139 private native void addTransfer(long nativeDropTransfer, long format); |
|
140 |
|
141 /** |
|
142 * signal that drop is completed |
|
143 */ |
|
144 |
|
145 private native void dropDone(long nativeDragContext, long nativeDropTransfer, |
|
146 boolean localTx, boolean success, int dropAction); |
|
147 } |
|