API Overview API Index Package Overview Direct link to this page
JDK 1.6
  java.awt.dnd. DragGestureRecognizer View Javadoc
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446

/*
 * @(#)DragGestureRecognizer.java	1.21 05/11/17
 *
 * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
 * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
 */

package java.awt.dnd;

import java.awt.event.InputEvent;
import java.awt.Component;
import java.awt.Point;

import java.util.TooManyListenersException;
import java.util.ArrayList;

import java.io.IOException;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * The <code>DragGestureRecognizer</code> is an 
 * abstract base class for the specification
 * of a platform-dependent listener that can be associated with a particular
 * <code>Component</code> in order to 
 * identify platform-dependent drag initiating gestures.
 * <p>
 * The appropriate <code>DragGestureRecognizer</code>
 * subclass is obtained from the
 * <code>DragSource</code> asssociated with 
 * a particular <code>Component</code>, or from the <code>Toolkit</code>
 * object via its createDragGestureRecognizer() method.
 * <p>
 * Once the <code>DragGestureRecognizer</code> 
 * is associated with a particular <code>Component</code>
 * it will register the appropriate listener interfaces on that 
 * <code>Component</code>
 * in order to track the input events delivered to the <code>Component</code>.
 * <p>
 * Once the <code>DragGestureRecognizer</code> identifies a sequence of events
 * on the <code>Component</code> as a drag initiating gesture, it will notify
 * its unicast <code>DragGestureListener</code> by 
 * invoking its gestureRecognized() method.
 * <P>
 * When a concrete <code>DragGestureRecognizer</code> 
 * instance detects a drag initiating
 * gesture on the <code>Component</code> it is associated with,
 * it will fire a <code>DragGestureEvent</code> to 
 * the <code>DragGestureListener</code> registered on
 * its unicast event source for <code>DragGestureListener</code>
 * events. This <code>DragGestureListener</code> is responsible 
 * for causing the associated
 * <code>DragSource</code> to start the Drag and Drop operation (if
 * appropriate). 
 * <P>
 * @author Laurence P. G. Cable
 * @version 1.21
 * @see java.awt.dnd.DragGestureListener
 * @see java.awt.dnd.DragGestureEvent
 * @see java.awt.dnd.DragSource
 */

public abstract class DragGestureRecognizer implements Serializable {

    private static final long serialVersionUID = 8996673345831063337L;

    /**
     * Construct a new <code>DragGestureRecognizer</code> 
     * given the <code>DragSource</code> to be used 
     * in this Drag and Drop operation, the <code>Component</code> 
     * this <code>DragGestureRecognizer</code> should "observe" 
     * for drag initiating gestures, the action(s) supported 
     * for this Drag and Drop operation, and the 
     * <code>DragGestureListener</code> to notify
     * once a drag initiating gesture has been detected.
     * <P>
     * @param ds  the <code>DragSource</code> this 
     * <code>DragGestureRecognizer</code> 
     * will use to process the Drag and Drop operation
     *
     * @param c the <code>Component</code> 
     * this <code>DragGestureRecognizer</code> 
     * should "observe" the event stream to, 
     * in order to detect a drag initiating gesture.
     * If this value is <code>null</code>, the 
     * <code>DragGestureRecognizer</code>
     * is not associated with any <code>Component</code>.
     *
     * @param sa  the set (logical OR) of the 
     * <code>DnDConstants</code> 
     * that this Drag and Drop operation will support
     *
     * @param dgl the <code>DragGestureRecognizer</code> 
     * to notify when a drag gesture is detected
     * <P>
     * @throws <code>IllegalArgumentException</code> 
     * if ds is <code>null</code>.
     */

    protected DragGestureRecognizer(DragSource ds, Component c, int sa, DragGestureListener dgl) {
	super();

	if (ds == null) throw new IllegalArgumentException("null DragSource");

	dragSource    = ds;
	component     = c;
	sourceActions = sa & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);

	try {
	    if (dgl != null) addDragGestureListener(dgl);
	} catch (TooManyListenersException tmle) {
	    // cant happen ...
	}
    }

    /**
     * Construct a new <code>DragGestureRecognizer</code> 
     * given the <code>DragSource</code> to be used in this 
     * Drag and Drop
     * operation, the <code>Component</code> this 
     * <code>DragGestureRecognizer</code> should "observe" 
     * for drag initiating gestures, and the action(s) 
     * supported for this Drag and Drop operation.
     * <P>
     * @param ds  the <code>DragSource</code> this 
     * <code>DragGestureRecognizer</code> will use to 
     * process the Drag and Drop operation
     *
     * @param c   the <code>Component</code> this 
     * <code>DragGestureRecognizer</code> should "observe" the event 
     * stream to, in order to detect a drag initiating gesture.
     * If this value is <code>null</code>, the 
     * <code>DragGestureRecognizer</code>
     * is not associated with any <code>Component</code>.
     *
     * @param sa the set (logical OR) of the <code>DnDConstants</code> 
     * that this Drag and Drop operation will support
     * <P>
     * @throws <code>IllegalArgumentException</code> 
     * if ds is <code>null</code>.
     */

    protected DragGestureRecognizer(DragSource ds, Component c, int sa) {
	this(ds, c, sa, null);
    }

    /**
     * Construct a new <code>DragGestureRecognizer</code> 
     * given the <code>DragSource</code> to be used 
     * in this Drag and Drop operation, and 
     * the <code>Component</code> this 
     * <code>DragGestureRecognizer</code> 
     * should "observe" for drag initiating gestures.
     * <P>
     * @param ds the <code>DragSource</code> this 
     * <code>DragGestureRecognizer</code> 
     * will use to process the Drag and Drop operation
     *
     * @param c the <code>Component</code> 
     * this <code>DragGestureRecognizer</code> 
     * should "observe" the event stream to, 
     * in order to detect a drag initiating gesture.
     * If this value is <code>null</code>, 
     * the <code>DragGestureRecognizer</code>
     * is not associated with any <code>Component</code>.
     * <P>
     * @throws <code>IllegalArgumentException</code> 
     * if ds is <code>null</code>.
     */

    protected DragGestureRecognizer(DragSource ds, Component c) {
	this(ds, c, DnDConstants.ACTION_NONE);
    }

    /**
     * Construct a new <code>DragGestureRecognizer</code> 
     * given the <code>DragSource</code> to be used in this 
     * Drag and Drop operation.
     * <P>
     * @param ds the <code>DragSource</code> this 
     * <code>DragGestureRecognizer</code> will 
     * use to process the Drag and Drop operation
     * <P>
     * @throws <code>IllegalArgumentException</code> 
     * if ds is <code>null</code>.
     */

    protected DragGestureRecognizer(DragSource ds) {
	this(ds, null);
    }

    /**
     * register this DragGestureRecognizer's Listeners with the Component
     *
     * subclasses must override this method
     */

    protected abstract void registerListeners();

    /**
     * unregister this DragGestureRecognizer's Listeners with the Component
     *
     * subclasses must override this method
     */

    protected abstract void unregisterListeners();

    /**
     * This method returns the <code>DragSource</code> 
     * this <code>DragGestureRecognizer</code> 
     * will use in order to process the Drag and Drop 
     * operation.
     * <P>
     * @return the DragSource
     */

    public DragSource getDragSource() { return dragSource; }

    /**
     * This method returns the <code>Component</code> 
     * that is to be "observed" by the 
     * <code>DragGestureRecognizer</code> 
     * for drag initiating gestures.
     * <P>
     * @return The Component this DragGestureRecognizer 
     * is associated with
     */

    public synchronized Component getComponent() { return component; }

    /**
     * set the Component that the DragGestureRecognizer is associated with
     *
     * registerListeners() and unregisterListeners() are called as a side
     * effect as appropriate.
     * <P>
     * @param c The <code>Component</code> or <code>null</code>
     */

    public synchronized void setComponent(Component c) {
	if (component != null && dragGestureListener != null)
	    unregisterListeners();

	component = c;

	if (component != null && dragGestureListener != null)
	    registerListeners();
    }

    /**
     * This method returns an int representing the 
     * type of action(s) this Drag and Drop 
     * operation will support.
     * <P>
     * @return the currently permitted source action(s)
     */

    public synchronized int getSourceActions() { return sourceActions; }

    /**
     * This method sets the permitted source drag action(s) 
     * for this Drag and Drop operation.
     * <P>
     * @param actions the permitted source drag action(s)
     */

    public synchronized void setSourceActions(int actions) {
	sourceActions = actions & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
    }

    /**
     * This method returns the first event in the 
     * series of events that initiated 
     * the Drag and Drop operation.
     * <P>
     * @return the initial event that triggered the drag gesture
     */

    public InputEvent getTriggerEvent() { return events.isEmpty() ? null : (InputEvent)events.get(0); }

    /**
     * Reset the Recognizer, if its currently recognizing a gesture, ignore
     * it.
     */

    public void resetRecognizer() { events.clear(); }

    /**
     * Register a new <code>DragGestureListener</code>.
     * <P>
     * @param dgl the <code>DragGestureListener</code> to register 
     * with this <code>DragGestureRecognizer</code>.
     * <P>
     * @throws java.util.TooManyListenersException if a 
     * <code>DragGestureListener</code> has already been added.
     */

    public synchronized void addDragGestureListener(DragGestureListener dgl) throws TooManyListenersException {
	if (dragGestureListener != null)
	    throw new TooManyListenersException();
	else {
	    dragGestureListener = dgl;

	    if (component != null) registerListeners();
	}
    }

    /**
     * unregister the current DragGestureListener
     * <P>
     * @param dgl the <code>DragGestureListener</code> to unregister 
     * from this <code>DragGestureRecognizer</code>
     * <P>
     * @throws <code>IllegalArgumentException</code> if 
     * dgl is not (equal to) the currently registered <code>DragGestureListener</code>.
     */

    public synchronized void removeDragGestureListener(DragGestureListener dgl) {
	if (dragGestureListener == null || !dragGestureListener.equals(dgl))
	    throw new IllegalArgumentException();
	else {
	    dragGestureListener = null;

	    if (component != null) unregisterListeners();
	}
    }

    /**
     * Notify the DragGestureListener that a Drag and Drop initiating
     * gesture has occurred. Then reset the state of the Recognizer.
     * <P>
     * @param dragAction The action initially selected by the users gesture
     * @param p          The point (in Component coords) where the gesture originated
     */
    protected synchronized void fireDragGestureRecognized(int dragAction, Point p) {
        try {
            if (dragGestureListener != null) {
                dragGestureListener.dragGestureRecognized(new DragGestureEvent(this, dragAction, p, events));
            }
        } finally {
            events.clear();
        }
    }

    /**
     * Listeners registered on the Component by this Recognizer shall record
     * all Events that are recognized as part of the series of Events that go
     * to comprise a Drag and Drop initiating gesture via this API.
     *<P>
     * This method is used by a <code>DragGestureRecognizer</code> 
     * implementation to add an <code>InputEvent</code> 
     * subclass (that it believes is one in a series
     * of events that comprise a Drag and Drop operation) 
     * to the array of events that this 
     * <code>DragGestureRecognizer</code> maintains internally.
     * <P>
     * @param awtie the <code>InputEvent</code> 
     * to add to this <code>DragGestureRecognizer</code>'s 
     * internal array of events. Note that <code>null</code>
     * is not a valid value, and will be ignored.
     */

    protected synchronized void appendEvent(InputEvent awtie) {
	events.add(awtie);
    }

    /**
     * Serializes this <code>DragGestureRecognizer</code>. This method first
     * performs default serialization. Then, this object's
     * <code>DragGestureListener</code> is written out if and only if it can be
     * serialized. If not, <code>null</code> is written instead.
     *
     * @serialData The default serializable fields, in alphabetical order,
     *             followed by either a <code>DragGestureListener</code>, or
     *             <code>null</code>.
     * @since 1.4
     */
    private void writeObject(ObjectOutputStream s) throws IOException {
        s.defaultWriteObject();

        s.writeObject(SerializationTester.test(dragGestureListener)
                      ? dragGestureListener : null);
    }

    /**
     * Deserializes this <code>DragGestureRecognizer</code>. This method first
     * performs default deserialization for all non-<code>transient</code>
     * fields. This object's <code>DragGestureListener</code> is then
     * deserialized as well by using the next object in the stream.
     *
     * @since 1.4
     */
    private void readObject(ObjectInputStream s)
        throws ClassNotFoundException, IOException
    {
        s.defaultReadObject();

        dragGestureListener = (DragGestureListener)s.readObject();
    }

    /*
     * fields
     */

    /**
     * The <code>DragSource</code> 
     * associated with this 
     * <code>DragGestureRecognizer</code>.
     *
     * @serial
     */
    protected DragSource          dragSource;
 
    /**
     * The <code>Component</code> 
     * associated with this <code>DragGestureRecognizer</code>.
     *
     * @serial
     */
    protected Component           component;

    /**
     * The <code>DragGestureListener</code> 
     * associated with this <code>DragGestureRecognizer</code>.
     */
    protected transient DragGestureListener dragGestureListener;

  /**
   * An <code>int</code> representing 
   * the type(s) of action(s) used 
   * in this Drag and Drop operation.  
   *
   * @serial
   */
  protected int	 sourceActions;

   /**
    * The list of events (in order) that 
    * the <code>DragGestureRecognizer</code> 
    * "recognized" as a "gesture" that triggers a drag.
    *
    * @serial
    */
   protected ArrayList<InputEvent> events = new ArrayList<InputEvent>(1);
}

Generated By: JavaOnTracks Doclet 0.1.4     ©Thibaut Colar