Whole document tree
2.2 Drag Gesture RecognitionThe gesture(s) that can initiate a Drag and Drop operation vary, not only per platform, but also per Component, and per device. Therefore a mechanism is required in order to encapsulate these dependencies, thus making the task of the author of a Component that wishes to initiate a Drag and Drop operation much simpler. 2.2.1 DragGestureRecognizerThe DragGestureRecognizer is an abstract base class for all device/platform/Component specific Drag and Drop gesture recognizers, and is defined as: public abstract DragGestureRecognizer { protected DragGestureRecognizer( DragSource ds, Component c, int srcActions, DragGestureListener dgl ); public Component getComponent(); public void setComponent(Component c); public int getSourceActions(); public void setSourceActions(int actions); public java.awt.InputEvent getTriggerEvent(); public void resetRecognizer(); public void addDragGestureListener( DragGestureListener dgl ) throws TooManyListenerExceptions; public void removeDragGestureListener( DragGestureListener dgl ); protected abstract void registerListeners(); protected abstract void unregisterListeners(); protected void fireDragGestureRecognized( int dragAction ); protected void appendEvent(InputEvent awtie); } An appropriate concrete subclasses of DragGestureRecognizer for a particular may be obtained in a variety of ways; from a DragSource instance, from the Toolkit, or by other means. Concrete implementation subclasses are obtained through standard APIs' by specifying a Class reference to an abstract DragGestureRecognizer superclass, an instance of a concrete subclass of this actual parameter is instantiated and returned to the requestor. public abstract MouseDragGestureRecognizer extends DragGestureRecognizer implements MouseListener, MouseMotionListener { public MouseDragGestureRecognizer( DragSource ds, Component c, int sa, DragGestureListener dsl ); // ... } The DragGestureListener is defined as: public interface DragGestureListener extends EventListener { void dragGestureRecognized(DragGestureEvent dge); } Usually the dragGestureRecognized() method will simply, via the DragGestureEvent's convenience API startDrag(), start a Drag and Drop operation on the associated DragSource. publc class DragGestureEvent extends EventObject { public DragGestureEvent(DragGestureRecognizer dgr, int dragAction, java.util.List events ); public DragGestureRecognizer getSourceAsDragGestureRecognizer(); public Component getComponent(); public DragSource getDragSource(); public java.util.Iterator iterator(); public Object[] toArray(); public Object[] toArray(Object[] array); public int getDragAction(); public startDrag(Cursor dragCursor, Transferable t, DragSourceListener dsl ); public startDrag(Cursor dragCursor, Image dragImage, Point imageOffset, Transferable t, DragSourceListener dsl ); } The DragGestureEvent encapsulates all the information regarding the nature of the gesture that has just been recognized, including: CONTENTS | PREV | NEXT Copyright © 1997, 1998 Sun Microsystems, Inc. All Rights Reserved. |