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