001 /* DragGestureEvent.java -- 002 Copyright (C) 2002 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 039 package java.awt.dnd; 040 041 import java.awt.Component; 042 import java.awt.Cursor; 043 import java.awt.Image; 044 import java.awt.Point; 045 import java.awt.datatransfer.Transferable; 046 import java.awt.event.InputEvent; 047 import java.util.EventObject; 048 import java.util.Iterator; 049 import java.util.List; 050 051 public 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