1:
37:
38: package ;
39:
40: import ;
41: import ;
42: import ;
43: import ;
44: import ;
45: import ;
46: import ;
47: import ;
48: import ;
49:
50:
55: public class DropTargetContext implements Serializable
56: {
57: static final long serialVersionUID = -634158968993743371L;
58:
59: protected class TransferableProxy implements Transferable
60: {
61: protected boolean isLocal;
62: protected Transferable transferable;
63:
64: TransferableProxy(Transferable t, boolean local)
65: {
66: this.transferable = t;
67: this.isLocal = local;
68: }
69:
70: public DataFlavor[] getTransferDataFlavors()
71: {
72: return transferable.getTransferDataFlavors();
73: }
74:
75: public boolean isDataFlavorSupported(DataFlavor flavor)
76: {
77: return transferable.isDataFlavorSupported(flavor);
78: }
79:
80: public Object getTransferData(DataFlavor flavor)
81: throws UnsupportedFlavorException, IOException
82: {
83: return transferable.getTransferData (flavor);
84: }
85: }
86:
87: private DropTarget dropTarget;
88: private int targetActions;
89: private DropTargetContextPeer dtcp;
90:
91:
92: DropTargetContext(DropTarget dropTarget)
93: {
94: this.dropTarget = dropTarget;
95: }
96:
97: public DropTarget getDropTarget()
98: {
99: return dropTarget;
100: }
101:
102: public Component getComponent()
103: {
104: return dropTarget.getComponent();
105: }
106:
107: public void addNotify(DropTargetContextPeer dtcp)
108: {
109: this.dtcp = dtcp;
110: }
111:
112: public void removeNotify()
113: {
114: this.dtcp = null;
115: }
116:
117: protected void setTargetActions(int actions)
118: {
119: targetActions = actions;
120: }
121:
122: protected int getTargetActions()
123: {
124: return targetActions;
125: }
126:
127:
132: public void dropComplete (boolean success)
133: {
134: if (dtcp != null)
135: dtcp.dropComplete(success);
136: }
137:
138: protected void acceptDrag (int dragOperation)
139: {
140: if (dtcp != null)
141: dtcp.acceptDrag(dragOperation);
142: }
143:
144: protected void rejectDrag ()
145: {
146: if (dtcp != null)
147: dtcp.rejectDrag();
148: }
149:
150: protected void acceptDrop (int dropOperation)
151: {
152: if (dtcp != null)
153: dtcp.acceptDrop(dropOperation);
154: }
155:
156: protected void rejectDrop ()
157: {
158: if (dtcp != null)
159: dtcp.rejectDrop();
160: }
161:
162: protected DataFlavor[] getCurrentDataFlavors ()
163: {
164: if (dtcp != null)
165: dtcp.getTransferDataFlavors();
166: return null;
167: }
168:
169: protected List<DataFlavor> getCurrentDataFlavorsAsList ()
170: {
171: return Arrays.asList(getCurrentDataFlavors ());
172: }
173:
174: protected boolean isDataFlavorSupported (DataFlavor flavor)
175: {
176: return getCurrentDataFlavorsAsList().contains (flavor);
177: }
178:
179:
184: protected Transferable getTransferable()
185: throws InvalidDnDOperationException
186: {
187:
188: if (dtcp != null)
189: return dtcp.getTransferable();
190: return null;
191: }
192:
193: protected Transferable createTransferableProxy(Transferable t, boolean local)
194: {
195: return new TransferableProxy(t, local);
196: }
197: }