KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > swt > dnd > DND


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.swt.dnd;
12
13  
14 import org.eclipse.swt.*;
15
16 /**
17  *
18  * Class DND contains all the constants used in defining a
19  * DragSource or a DropTarget.
20  *
21  */

22 public class DND {
23     
24     /**
25      * The transfer mechanism for data that is being cut
26      * and then pasted or copied and then pasted (value is 1).
27      *
28      * @see Clipboard
29      *
30      * @since 3.1
31      */

32     public final static int CLIPBOARD = 1 << 0;
33     
34     /**
35      * The transfer mechanism for clients that use the selection
36      * mechanism (value is 2).
37      *
38      * @see Clipboard
39      *
40      * @since 3.1
41      */

42     public final static int SELECTION_CLIPBOARD = 1 << 1;
43
44     /**
45      * Drag and Drop Operation: no drag/drop operation performed
46      * (value is 0).
47      */

48     public final static int DROP_NONE = 0;
49     
50     /**
51      * Drag and Drop Operation: a copy of the data in the drag source is
52      * added to the drop target (value is 1 &lt;&lt; 0).
53      */

54     public final static int DROP_COPY = 1 << 0;
55     
56     /**
57      * Drag and Drop Operation: a copy of the data is added to the drop target and
58      * the original data is removed from the drag source (value is 1 &lt;&lt; 1).
59      */

60     public final static int DROP_MOVE = 1 << 1;
61     
62     /**
63      * Drag and Drop Operation: the drop target makes a link to the data in
64      * the drag source (value is 1 &lt;&lt; 2).
65      */

66     public final static int DROP_LINK = 1 << 2;
67     
68     /**
69      * Drag and Drop Operation: the drop target moves the data and the drag source removes
70      * any references to the data and updates its display. This is not available on all platforms
71      * and is only used when a non-SWT application is the drop target. In this case, the SWT
72      * drag source is informed in the dragFinished event that the drop target has moved the data.
73      * (value is 1 &lt;&lt; 3).
74      *
75      * @see DragSourceListener#dragFinished
76      */

77     public final static int DROP_TARGET_MOVE = 1 << 3;
78     
79     /**
80      * Drag and Drop Operation: During a dragEnter event or a dragOperationChanged, if no modifier keys
81      * are pressed, the operation is set to DROP_DEFAULT. The application can choose what the default
82      * operation should be by setting a new value in the operation field. If no value is choosen, the
83      * default operation for the platform will be selected (value is 1 &lt;&lt; 4).
84      *
85      * @see DropTargetListener#dragEnter
86      * @see DropTargetListener#dragOperationChanged
87      * @since 2.0
88      */

89     public final static int DROP_DEFAULT = 1 << 4;
90     
91     /**
92      * DragSource Event: the drop has successfully completed or has been terminated (such as hitting
93      * the ESC key); perform cleanup such as removing data on a move operation (value is 2000).
94      */

95     public static final int DragEnd = 2000;
96     
97     /**
98      * DragSource Event: the data to be dropped is required from the drag source (value is 2001).
99      */

100     public static final int DragSetData = 2001;
101     
102     /**
103      * DropTarget Event: the cursor has entered the drop target boundaries (value is 2002).
104      */

105     public static final int DragEnter = 2002;
106     
107     /**
108      * DropTarget Event: the cursor has left the drop target boundaries OR the drop
109      * operation has been cancelled (such as by hitting ECS) OR the drop is about to
110      * happen (user has released the mous ebutotn over this target) (value is 2003).
111      */

112     public static final int DragLeave = 2003;
113     
114     /**
115      * DropTarget Event: the cursor is over the drop target (value is 2004).
116      */

117     public static final int DragOver = 2004;
118     
119     /**
120      * DropTarget Event: the operation being performed has changed usually due to the user
121      * changing the selected modifier keys while dragging (value is 2005).
122      */

123     public static final int DragOperationChanged = 2005;
124     
125     /**
126      * DropTarget Event: the data has been dropped (value is 2006).
127      */

128     public static final int Drop = 2006;
129     
130     /**
131      * DropTarget Event: the drop target is given a last chance to modify the drop (value is 2007).
132      */

133     public static final int DropAccept = 2007;
134     
135     /**
136      * DragSource Event: a drag is about to begin (value is 2008).
137      */

138     public static final int DragStart = 2008;
139
140     /**
141      * DropTarget drag under effect: No effect is shown (value is 0).
142      */

143     public static final int FEEDBACK_NONE = 0;
144     
145     /**
146      * DropTarget drag under effect: The item under the cursor is selected; applies to tables
147      * and trees (value is 1).
148      */

149     public static final int FEEDBACK_SELECT = 1;
150     
151     /**
152      * DropTarget drag under effect: An insertion mark is shown before the item under the cursor; applies to
153      * trees (value is 2).
154      */

155     public static final int FEEDBACK_INSERT_BEFORE = 2;
156     
157     /**
158      * DropTarget drag under effect:An insertion mark is shown after the item under the cursor; applies to
159      * trees (value is 4).
160      */

161     public static final int FEEDBACK_INSERT_AFTER = 4;
162     
163     /**
164      * DropTarget drag under effect: The widget is scrolled up or down to allow the user to drop on items that
165      * are not currently visible; applies to tables and trees (value is 8).
166      */

167     public static final int FEEDBACK_SCROLL = 8;
168     
169     /**
170      * DropTarget drag under effect: The item currently under the cursor is expanded to allow the user to
171      * select a drop target from a sub item; applies to trees (value is 16).
172      */

173     public static final int FEEDBACK_EXPAND = 16;
174
175     /**
176      * Error code: drag source can not be initialized (value is 2000).
177      */

178     public static final int ERROR_CANNOT_INIT_DRAG = 2000;
179     
180     /**
181      * Error code: drop target cannot be initialized (value is 2001).
182      */

183     public static final int ERROR_CANNOT_INIT_DROP = 2001;
184     
185     /**
186      * Error code: Data can not be set on system clipboard (value is 2002).
187      */

188     public static final int ERROR_CANNOT_SET_CLIPBOARD = 2002;
189     
190     /**
191      * Error code: Data does not have correct format for type (value is 2003).
192      * @since 3.1
193      */

194     public static final int ERROR_INVALID_DATA = 2003;
195     
196
197     static final String JavaDoc INIT_DRAG_MESSAGE = "Cannot initialize Drag"; //$NON-NLS-1$
198
static final String JavaDoc INIT_DROP_MESSAGE = "Cannot initialize Drop"; //$NON-NLS-1$
199
static final String JavaDoc CANNOT_SET_CLIPBOARD_MESSAGE = "Cannot set data in clipboard"; //$NON-NLS-1$
200
static final String JavaDoc INVALID_DATA_MESSAGE = "Data does not have correct format for type"; //$NON-NLS-1$
201

202 /**
203  * Throws an appropriate exception based on the passed in error code.
204  *
205  * @param code the DND error code
206  */

207 public static void error (int code) {
208     error (code, 0);
209 }
210
211 /**
212  * Throws an appropriate exception based on the passed in error code.
213  * The <code>hresult</code> argument should be either 0, or the
214  * platform specific error code.
215  * <p>
216  * In DND, errors are reported by throwing one of three exceptions:
217  * <dl>
218  * <dd>java.lang.IllegalArgumentException</dd>
219  * <dt>thrown whenever one of the API methods is invoked with an illegal argument</dt>
220  * <dd>org.eclipse.swt.SWTException (extends java.lang.RuntimeException)</dd>
221  * <dt>thrown whenever a recoverable error happens internally in SWT</dt>
222  * <dd>org.eclipse.swt.SWTError (extends java.lang.Error)</dd>
223  * <dt>thrown whenever a <b>non-recoverable</b> error happens internally in SWT</dt>
224  * </dl>
225  * This method provides the logic which maps between error codes
226  * and one of the above exceptions.
227  * </p>
228  *
229  * @param code the DND error code.
230  * @param hresult the platform specific error code.
231  *
232  * @see SWTError
233  * @see SWTException
234  * @see IllegalArgumentException
235  */

236 public static void error (int code, int hresult) {
237     switch (code) {
238         /* OS Failure/Limit (fatal, may occur only on some platforms) */
239         case DND.ERROR_CANNOT_INIT_DRAG:{
240             String JavaDoc msg = DND.INIT_DRAG_MESSAGE;
241             if (hresult != 0) msg += " result = "+hresult; //$NON-NLS-1$
242
throw new SWTError (code, msg);
243         }
244         case DND.ERROR_CANNOT_INIT_DROP:{
245             String JavaDoc msg = DND.INIT_DROP_MESSAGE;
246             if (hresult != 0) msg += " result = "+hresult; //$NON-NLS-1$
247
throw new SWTError (code, msg);
248         }
249         case DND.ERROR_CANNOT_SET_CLIPBOARD:{
250             String JavaDoc msg = DND.CANNOT_SET_CLIPBOARD_MESSAGE;
251             if (hresult != 0) msg += " result = "+hresult; //$NON-NLS-1$
252
throw new SWTError (code, msg);
253         }
254         case DND.ERROR_INVALID_DATA:{
255             String JavaDoc msg = DND.INVALID_DATA_MESSAGE;
256             if (hresult != 0) msg += " result = "+hresult; //$NON-NLS-1$
257
throw new SWTException (code, msg);
258         }
259     }
260             
261     /* Unknown/Undefined Error */
262     SWT.error(code);
263 }
264
265 }
266
Popular Tags