1 7 8 9 package java.awt.dnd; 10 11 import java.awt.Component ; 12 import java.awt.Cursor ; 13 14 import java.awt.Image ; 15 import java.awt.Point ; 16 17 import java.awt.event.InputEvent ; 18 19 import java.awt.datatransfer.Transferable ; 20 21 import java.util.EventObject ; 22 23 import java.util.Collections ; 24 import java.util.List ; 25 import java.util.Iterator ; 26 27 import java.io.IOException ; 28 import java.io.ObjectInputStream ; 29 import java.io.ObjectOutputStream ; 30 import java.io.Serializable ; 31 32 33 46 47 public class DragGestureEvent extends EventObject { 48 49 private static final long serialVersionUID = 9080172649166731306L; 50 51 67 68 public DragGestureEvent(DragGestureRecognizer dgr, int act, Point ori, 69 List <? extends InputEvent > evs) 70 { 71 super(dgr); 72 73 if ((component = dgr.getComponent()) == null) 74 throw new IllegalArgumentException ("null component"); 75 if ((dragSource = dgr.getDragSource()) == null) 76 throw new IllegalArgumentException ("null DragSource"); 77 78 if (evs == null || evs.isEmpty()) 79 throw new IllegalArgumentException ("null or empty list of events"); 80 81 if (act != DnDConstants.ACTION_COPY && 82 act != DnDConstants.ACTION_MOVE && 83 act != DnDConstants.ACTION_LINK) 84 throw new IllegalArgumentException ("bad action"); 85 86 if (ori == null) throw new IllegalArgumentException ("null origin"); 87 88 events = evs; 89 action = act; 90 origin = ori; 91 } 92 93 98 99 public DragGestureRecognizer getSourceAsDragGestureRecognizer() { 100 return (DragGestureRecognizer )getSource(); 101 } 102 103 109 110 public Component getComponent() { return component; } 111 112 117 118 public DragSource getDragSource() { return dragSource; } 119 120 126 127 public Point getDragOrigin() { 128 return origin; 129 } 130 131 137 138 public Iterator <InputEvent > iterator() { return events.iterator(); } 139 140 146 147 public Object [] toArray() { return events.toArray(); } 148 149 156 157 public Object [] toArray(Object [] array) { return events.toArray(array); } 158 159 165 166 public int getDragAction() { return action; } 167 168 173 174 public InputEvent getTriggerEvent() { 175 return getSourceAsDragGestureRecognizer().getTriggerEvent(); 176 } 177 178 201 public void startDrag(Cursor dragCursor, Transferable transferable) 202 throws InvalidDnDOperationException { 203 dragSource.startDrag(this, dragCursor, transferable, null); 204 } 205 206 221 222 public void startDrag(Cursor dragCursor, Transferable transferable, DragSourceListener dsl) throws InvalidDnDOperationException { 223 dragSource.startDrag(this, dragCursor, transferable, dsl); 224 } 225 226 245 246 public void startDrag(Cursor dragCursor, Image dragImage, Point imageOffset, Transferable transferable, DragSourceListener dsl) throws InvalidDnDOperationException { 247 dragSource.startDrag(this, dragCursor, dragImage, imageOffset, transferable, dsl); 248 } 249 250 263 private void writeObject(ObjectOutputStream s) throws IOException { 264 s.defaultWriteObject(); 265 266 s.writeObject(SerializationTester.test(events) ? events : null); 267 } 268 269 283 private void readObject(ObjectInputStream s) 284 throws ClassNotFoundException , IOException 285 { 286 ObjectInputStream.GetField f = s.readFields(); 287 288 dragSource = (DragSource )f.get("dragSource", null); 289 component = (Component )f.get("component", null); 290 origin = (Point )f.get("origin", null); 291 action = f.get("action", 0); 292 293 try { 295 events = (List )f.get("events", null); 296 } catch (IllegalArgumentException e) { 297 events = (List )s.readObject(); 299 } 300 301 if (events == null) { 303 events = Collections.EMPTY_LIST; 304 } 305 } 306 307 310 311 private transient List events; 312 313 318 private DragSource dragSource; 319 320 325 private Component component; 326 327 332 private Point origin; 333 334 339 private int action; 340 } 341 | Popular Tags |