001/* DragGestureEvent.java -- 002 Copyright (C) 2002 Free Software Foundation, Inc. 003 004This file is part of GNU Classpath. 005 006GNU Classpath is free software; you can redistribute it and/or modify 007it under the terms of the GNU General Public License as published by 008the Free Software Foundation; either version 2, or (at your option) 009any later version. 010 011GNU Classpath is distributed in the hope that it will be useful, but 012WITHOUT ANY WARRANTY; without even the implied warranty of 013MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014General Public License for more details. 015 016You should have received a copy of the GNU General Public License 017along with GNU Classpath; see the file COPYING. If not, write to the 018Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 01902110-1301 USA. 020 021Linking this library statically or dynamically with other modules is 022making a combined work based on this library. Thus, the terms and 023conditions of the GNU General Public License cover the whole 024combination. 025 026As a special exception, the copyright holders of this library give you 027permission to link this library with independent modules to produce an 028executable, regardless of the license terms of these independent 029modules, and to copy and distribute the resulting executable under 030terms of your choice, provided that you also meet, for each linked 031independent module, the terms and conditions of the license of that 032module. An independent module is a module which is not derived from 033or based on this library. If you modify this library, you may extend 034this exception to your version of the library, but you are not 035obligated to do so. If you do not wish to do so, delete this 036exception statement from your version. */ 037 038 039package java.awt.dnd; 040 041import java.awt.Component; 042import java.awt.Cursor; 043import java.awt.Image; 044import java.awt.Point; 045import java.awt.datatransfer.Transferable; 046import java.awt.event.InputEvent; 047import java.util.EventObject; 048import java.util.Iterator; 049import java.util.List; 050 051public class DragGestureEvent extends EventObject 052{ 053 /** 054 * Compatible with JDK 1.2+. 055 */ 056 private static final long serialVersionUID = 9080172649166731306L; 057 058 private DragSource dragSource; 059 private Component component; 060 private final Point origin; 061 private final int action; 062 private List<InputEvent> events; 063 private DragGestureRecognizer dgr; 064 065 /** 066 * Constructs a new DragGestureEvent. 067 * @param dgr - DragGestureRecognizer firing this event 068 * @param action - user's preferred action 069 * @param origin - origin of the drag 070 * @param events - List of events that make up the gesture 071 * @throws IllegalArgumentException - if input parameters are null 072 */ 073 public DragGestureEvent(DragGestureRecognizer dgr, int action, Point origin, 074 List<? extends InputEvent> events) 075 { 076 super(dgr); 077 if (origin == null || events == null || dgr == null) 078 throw new IllegalArgumentException(); 079 080 this.origin = origin; 081 this.action = action; 082 this.events = (List<InputEvent>) events; 083 this.dgr = dgr; 084 this.component = dgr.getComponent(); 085 this.dragSource = dgr.getDragSource(); 086 } 087 088 /** 089 * Returns the source casted as a DragGestureRecognizer. 090 * 091 * @return the source casted as a DragGestureRecognizer. 092 */ 093 public DragGestureRecognizer getSourceAsDragGestureRecognizer() 094 { 095 return (DragGestureRecognizer) getSource(); 096 } 097 098 /** 099 * 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