001: /*
002: * Copyright 1997-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.datatransfer.DataFlavor;
029: import java.awt.datatransfer.UnsupportedFlavorException;
030:
031: import java.awt.dnd.DnDConstants;
032: import java.awt.dnd.InvalidDnDOperationException;
033:
034: import java.io.InputStream;
035:
036: import java.util.Map;
037:
038: import java.io.IOException;
039: import sun.awt.dnd.SunDropTargetContextPeer;
040: import sun.awt.SunToolkit;
041:
042: /**
043: * <p>
044: * The MDropTargetContextPeer class is the class responsible for handling
045: * the interaction between the Motif DnD system and Java.
046: * </p>
047: *
048: * @version 1.51
049: * @since JDK1.2
050: *
051: */
052:
053: final class MDropTargetContextPeer extends SunDropTargetContextPeer {
054:
055: private long nativeDropTransfer;
056:
057: long nativeDataAvailable = 0;
058: Object nativeData = null;
059:
060: /**
061: * create the peer
062: */
063:
064: static MDropTargetContextPeer createMDropTargetContextPeer() {
065: return new MDropTargetContextPeer();
066: }
067:
068: /**
069: * create the peer
070: */
071:
072: private MDropTargetContextPeer() {
073: super ();
074: }
075:
076: protected Object getNativeData(long format) {
077: SunToolkit.awtLock();
078: if (nativeDropTransfer == 0) {
079: nativeDropTransfer = startTransfer(getNativeDragContext(),
080: format);
081: } else {
082: addTransfer(nativeDropTransfer, format);
083: }
084:
085: for (nativeDataAvailable = 0; format != nativeDataAvailable;) {
086: try {
087: SunToolkit.awtLockWait();
088: } catch (Throwable e) {
089: e.printStackTrace();
090: }
091: }
092: SunToolkit.awtUnlock();
093:
094: return nativeData;
095: }
096:
097: /**
098: * signal drop complete
099: */
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,
134: long format);
135:
136: /**
137: * schedule a native DnD data transfer
138: */
139:
140: private native void addTransfer(long nativeDropTransfer, long format);
141:
142: /**
143: * signal that drop is completed
144: */
145:
146: private native void dropDone(long nativeDragContext,
147: long nativeDropTransfer, boolean localTx, boolean success,
148: int dropAction);
149: }
|