1 /*
   2  * Copyright (c) 1998, 2003, Oracle and/or its affiliates. All rights reserved.
   3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
   4  *
   5  * This code is free software; you can redistribute it and/or modify it
   6  * under the terms of the GNU General Public License version 2 only, as
   7  * published by the Free Software Foundation.  Oracle designates this
   8  * particular file as subject to the "Classpath" exception as provided
   9  * by Oracle in the LICENSE file that accompanied this code.
  10  *
  11  * This code is distributed in the hope that it will be useful, but WITHOUT
  12  * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
  13  * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
  14  * version 2 for more details (a copy is included in the LICENSE file that
  15  * accompanied this code).
  16  *
  17  * You should have received a copy of the GNU General Public License version
  18  * 2 along with this work; if not, write to the Free Software Foundation,
  19  * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
  20  *
  21  * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
  22  * or visit www.oracle.com if you need additional information or have any
  23  * questions.
  24  */
  25 
  26 package java.awt.dnd;
  27 
  28 import java.awt.Component;
  29 
  30 import java.awt.event.MouseEvent;
  31 import java.awt.event.MouseListener;
  32 import java.awt.event.MouseMotionListener;
  33 
  34 /**
  35  * This abstract subclass of {@code DragGestureRecognizer}
  36  * defines a {@code DragGestureRecognizer}
  37  * for mouse-based gestures.
  38  *
  39  * Each platform implements its own concrete subclass of this class,
  40  * available via the Toolkit.createDragGestureRecognizer() method,
  41  * to encapsulate
  42  * the recognition of the platform dependent mouse gesture(s) that initiate
  43  * a Drag and Drop operation.
  44  * <p>
  45  * Mouse drag gesture recognizers should honor the
  46  * drag gesture motion threshold, available through
  47  * {@link DragSource#getDragThreshold}.
  48  * A drag gesture should be recognized only when the distance
  49  * in either the horizontal or vertical direction between
  50  * the location of the latest mouse dragged event and the
  51  * location of the corresponding mouse button pressed event
  52  * is greater than the drag gesture motion threshold.
  53  * <p>
  54  * Drag gesture recognizers created with
  55  * {@link DragSource#createDefaultDragGestureRecognizer}
  56  * follow this convention.
  57  *
  58  * @author Laurence P. G. Cable
  59  *
  60  * @see java.awt.dnd.DragGestureListener
  61  * @see java.awt.dnd.DragGestureEvent
  62  * @see java.awt.dnd.DragSource
  63  */
  64 
  65 public abstract class MouseDragGestureRecognizer extends DragGestureRecognizer implements MouseListener, MouseMotionListener {
  66 
  67     private static final long serialVersionUID = 6220099344182281120L;
  68 
  69     /**
  70      * Construct a new {@code MouseDragGestureRecognizer}
  71      * given the {@code DragSource} for the
  72      * {@code Component} c, the {@code Component}
  73      * to observe, the action(s)
  74      * permitted for this drag operation, and
  75      * the {@code DragGestureListener} to
  76      * notify when a drag gesture is detected.
  77      *
  78      * @param ds  The DragSource for the Component c
  79      * @param c   The Component to observe
  80      * @param act The actions permitted for this Drag
  81      * @param dgl The DragGestureListener to notify when a gesture is detected
  82      *
  83      */
  84 
  85     protected MouseDragGestureRecognizer(DragSource ds, Component c, int act, DragGestureListener dgl) {
  86         super(ds, c, act, dgl);
  87     }
  88 
  89     /**
  90      * Construct a new {@code MouseDragGestureRecognizer}
  91      * given the {@code DragSource} for
  92      * the {@code Component} c,
  93      * the {@code Component} to observe, and the action(s)
  94      * permitted for this drag operation.
  95      *
  96      * @param ds  The DragSource for the Component c
  97      * @param c   The Component to observe
  98      * @param act The actions permitted for this drag
  99      */
 100 
 101     protected MouseDragGestureRecognizer(DragSource ds, Component c, int act) {
 102         this(ds, c, act, null);
 103     }
 104 
 105     /**
 106      * Construct a new {@code MouseDragGestureRecognizer}
 107      * given the {@code DragSource} for the
 108      * {@code Component} c, and the
 109      * {@code Component} to observe.
 110      *
 111      * @param ds  The DragSource for the Component c
 112      * @param c   The Component to observe
 113      */
 114 
 115     protected MouseDragGestureRecognizer(DragSource ds, Component c) {
 116         this(ds, c, DnDConstants.ACTION_NONE);
 117     }
 118 
 119     /**
 120      * Construct a new {@code MouseDragGestureRecognizer}
 121      * given the {@code DragSource} for the {@code Component}.
 122      *
 123      * @param ds  The DragSource for the Component
 124      */
 125 
 126     protected MouseDragGestureRecognizer(DragSource ds) {
 127         this(ds, null);
 128     }
 129 
 130     /**
 131      * register this DragGestureRecognizer's Listeners with the Component
 132      */
 133 
 134     protected void registerListeners() {
 135         component.addMouseListener(this);
 136         component.addMouseMotionListener(this);
 137     }
 138 
 139     /**
 140      * unregister this DragGestureRecognizer's Listeners with the Component
 141      *
 142      * subclasses must override this method
 143      */
 144 
 145 
 146     protected void unregisterListeners() {
 147         component.removeMouseListener(this);
 148         component.removeMouseMotionListener(this);
 149     }
 150 
 151     /**
 152      * Invoked when the mouse has been clicked on a component.
 153      *
 154      * @param e the {@code MouseEvent}
 155      */
 156 
 157     public void mouseClicked(MouseEvent e) { }
 158 
 159     /**
 160      * Invoked when a mouse button has been
 161      * pressed on a {@code Component}.
 162      *
 163      * @param e the {@code MouseEvent}
 164      */
 165 
 166     public void mousePressed(MouseEvent e) { }
 167 
 168     /**
 169      * Invoked when a mouse button has been released on a component.
 170      *
 171      * @param e the {@code MouseEvent}
 172      */
 173 
 174     public void mouseReleased(MouseEvent e) { }
 175 
 176     /**
 177      * Invoked when the mouse enters a component.
 178      *
 179      * @param e the {@code MouseEvent}
 180      */
 181 
 182     public void mouseEntered(MouseEvent e) { }
 183 
 184     /**
 185      * Invoked when the mouse exits a component.
 186      *
 187      * @param e the {@code MouseEvent}
 188      */
 189 
 190     public void mouseExited(MouseEvent e) { }
 191 
 192     /**
 193      * Invoked when a mouse button is pressed on a component.
 194      *
 195      * @param e the {@code MouseEvent}
 196      */
 197 
 198     public void mouseDragged(MouseEvent e) { }
 199 
 200     /**
 201      * Invoked when the mouse button has been moved on a component
 202      * (with no buttons no down).
 203      *
 204      * @param e the {@code MouseEvent}
 205      */
 206 
 207     public void mouseMoved(MouseEvent e) { }
 208 }
--- EOF ---