Frames | No Frames |
1: /* DragGestureEvent.java -- 2: Copyright (C) 2002 Free Software Foundation, Inc. 3: 4: This file is part of GNU Classpath. 5: 6: GNU Classpath is free software; you can redistribute it and/or modify 7: it under the terms of the GNU General Public License as published by 8: the Free Software Foundation; either version 2, or (at your option) 9: any later version. 10: 11: GNU Classpath is distributed in the hope that it will be useful, but 12: WITHOUT ANY WARRANTY; without even the implied warranty of 13: MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 14: General Public License for more details. 15: 16: You should have received a copy of the GNU General Public License 17: along with GNU Classpath; see the file COPYING. If not, write to the 18: Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 19: 02110-1301 USA. 20: 21: Linking this library statically or dynamically with other modules is 22: making a combined work based on this library. Thus, the terms and 23: conditions of the GNU General Public License cover the whole 24: combination. 25: 26: As a special exception, the copyright holders of this library give you 27: permission to link this library with independent modules to produce an 28: executable, regardless of the license terms of these independent 29: modules, and to copy and distribute the resulting executable under 30: terms of your choice, provided that you also meet, for each linked 31: independent module, the terms and conditions of the license of that 32: module. An independent module is a module which is not derived from 33: or based on this library. If you modify this library, you may extend 34: this exception to your version of the library, but you are not 35: obligated to do so. If you do not wish to do so, delete this 36: exception statement from your version. */ 37: 38: 39: package java.awt.dnd; 40: 41: import java.awt.Component; 42: import java.awt.Cursor; 43: import java.awt.Image; 44: import java.awt.Point; 45: import java.awt.datatransfer.Transferable; 46: import java.awt.event.InputEvent; 47: import java.util.EventObject; 48: import java.util.Iterator; 49: import java.util.List; 50: 51: public class DragGestureEvent extends EventObject 52: { 53: /** 54: * Compatible with JDK 1.2+. 55: */ 56: private static final long serialVersionUID = 9080172649166731306L; 57: 58: private DragSource dragSource; 59: private Component component; 60: private final Point origin; 61: private final int action; 62: private List<InputEvent> events; 63: private DragGestureRecognizer dgr; 64: 65: /** 66: * Constructs a new DragGestureEvent. 67: * @param dgr - DragGestureRecognizer firing this event 68: * @param action - user's preferred action 69: * @param origin - origin of the drag 70: * @param events - List of events that make up the gesture 71: * @throws IllegalArgumentException - if input parameters are null 72: */ 73: public DragGestureEvent(DragGestureRecognizer dgr, int action, Point origin, 74: List<? extends InputEvent> events) 75: { 76: super(dgr); 77: if (origin == null || events == null || dgr == null) 78: throw new IllegalArgumentException(); 79: 80: this.origin = origin; 81: this.action = action; 82: this.events = (List<InputEvent>) events; 83: this.dgr = dgr; 84: this.component = dgr.getComponent(); 85: this.dragSource = dgr.getDragSource(); 86: } 87: 88: /** 89: * Returns the source casted as a DragGestureRecognizer. 90: * 91: * @return the source casted as a DragGestureRecognizer. 92: */ 93: public DragGestureRecognizer getSourceAsDragGestureRecognizer() 94: { 95: return (DragGestureRecognizer) getSource(); 96: } 97: 98: /** 99: * Returns the Component corresponding to this. 100: * 101: * @return the Component corresponding to this. 102: */ 103: public Component getComponent() 104: { 105: return component; 106: } 107: 108: /** 109: * Gets the DragSource corresponding to this. 110: * 111: * @return the DragSource corresponding to this. 112: */ 113: public DragSource getDragSource() 114: { 115: return dragSource; 116: } 117: 118: /** 119: * Returns the origin of the drag. 120: * 121: * @return the origin of the drag. 122: */ 123: public Point getDragOrigin() 124: { 125: return origin; 126: } 127: 128: /** 129: * Gets an iterator representation of the List of events. 130: * 131: * @return an iterator representation of the List of events. 132: */ 133: public Iterator<InputEvent> iterator() 134: { 135: return events.iterator(); 136: } 137: 138: /** 139: * Gets an array representation of the List of events. 140: * 141: * @return an array representation of the List of events. 142: */ 143: public Object[] toArray() 144: { 145: return events.toArray(); 146: } 147: 148: /** 149: * Gets an array representation of the List of events. 150: * 151: * @param array - the array to store the events in. 152: * @return an array representation of the List of events. 153: */ 154: public Object[] toArray(Object[] array) 155: { 156: return events.toArray(array); 157: } 158: 159: /** 160: * Gets the user's preferred action. 161: * 162: * @return the user's preferred action. 163: */ 164: public int getDragAction() 165: { 166: return action; 167: } 168: 169: /** 170: * Get the event that triggered this gesture. 171: * 172: * @return the event that triggered this gesture. 173: */ 174: public InputEvent getTriggerEvent() 175: { 176: return dgr.getTriggerEvent(); 177: } 178: 179: /** 180: * Starts the drag given the initial Cursor to display, the Transferable 181: * object, and the DragSourceListener to use. 182: * 183: * @exception InvalidDnDOperationException If the Drag and Drop system is 184: * unable to initiate a drag operation, or if the user attempts to start 185: * a drag while an existing drag operation is still executing. 186: */ 187: public void startDrag(Cursor dragCursor, Transferable trans) 188: { 189: startDrag(dragCursor, null, null, trans, null); 190: } 191: 192: /** 193: * Starts the drag given the initial Cursor to display, the Transferable 194: * object, and the DragSourceListener to use. 195: * 196: * @exception InvalidDnDOperationException If the Drag and Drop system is 197: * unable to initiate a drag operation, or if the user attempts to start 198: * a drag while an existing drag operation is still executing. 199: */ 200: public void startDrag(Cursor dragCursor, Transferable trans, 201: DragSourceListener l) 202: { 203: startDrag(dragCursor, null, null, trans, l); 204: } 205: 206: /** 207: * Starts the drag given the initial Cursor to display, the Transferable 208: * object, and the DragSourceListener to use. 209: * 210: * @exception InvalidDnDOperationException If the Drag and Drop system is 211: * unable to initiate a drag operation, or if the user attempts to start 212: * a drag while an existing drag operation is still executing. 213: */ 214: public void startDrag(Cursor dragCursor, Image dragImage, Point imageOffset, 215: Transferable trans, DragSourceListener l) 216: { 217: dragSource.startDrag(this, dragCursor, dragImage, imageOffset, trans, l); 218: } 219: } // class DragGestureEvent