1 package org.apache.ojb.tools.mapping.reversedb2.dnd2; 2 3 17 18 37 public class DragHelper 38 { 39 private java.awt.dnd.DragGestureListener dgListener = new DGListener(); 40 private java.awt.dnd.DragSourceListener dsListener = new DSListener(); 41 private java.awt.dnd.DragSource dragSource; 42 private java.util.Map hmDragGestureRecognizers = new java.util.HashMap (); 43 private Class recognizerAbstractClass = null; 44 private DragCopyCutWorkerInterface dragWorker; 45 46 64 public DragHelper(java.awt.dnd.DragGestureListener pDgListener, 65 java.awt.dnd.DragSourceListener pDsListener, 66 java.awt.dnd.DragSource pDragSource, 67 Class pRecognizerAbstractClass, 68 DragCopyCutWorkerInterface pDragWorker) 69 { 70 this(pDragSource, pRecognizerAbstractClass, pDragWorker); 71 this.dgListener = pDgListener; 72 this.dsListener = pDsListener; 73 } 74 75 83 public DragHelper(java.awt.dnd.DragSource pDragSource, 84 Class pRecognizerAbstractClass, 85 DragCopyCutWorkerInterface pDragWorker) 86 { 87 this.dragSource = pDragSource; 88 this.recognizerAbstractClass = pRecognizerAbstractClass; 89 this.dragWorker = pDragWorker; 90 } 91 92 93 98 public DragHelper(DragCopyCutWorkerInterface pDragWorker) 99 { 100 this(java.awt.dnd.DragSource.getDefaultDragSource(), 101 null, pDragWorker); 102 } 103 104 108 public void registerComponent(java.awt.Component c) 109 { 110 unregisterComponent(c); 111 if (recognizerAbstractClass == null) 112 { 113 hmDragGestureRecognizers.put(c, 114 dragSource.createDefaultDragGestureRecognizer(c, 115 dragWorker.getAcceptableActions(c), dgListener) 116 ); 117 } 118 else 119 { 120 hmDragGestureRecognizers.put(c, 121 dragSource.createDragGestureRecognizer (recognizerAbstractClass, 122 c, dragWorker.getAcceptableActions(c), dgListener) 123 ); 124 } 125 } 126 127 130 public void unregisterComponent(java.awt.Component c) 131 { 132 java.awt.dnd.DragGestureRecognizer recognizer = 133 (java.awt.dnd.DragGestureRecognizer )this.hmDragGestureRecognizers.remove(c); 134 if (recognizer != null) 135 recognizer.setComponent(null); 136 } 137 138 141 public class DGListener implements java.awt.dnd.DragGestureListener 142 { 143 144 151 public void dragGestureRecognized (java.awt.dnd.DragGestureEvent dragGestureEvent) 152 { 153 System.err.println("DGListener.dragGestureRecognized() dragAction:" + dragGestureEvent.getDragAction()); 154 if (dragWorker.getAcceptableActions (dragGestureEvent.getComponent()) == DnDWorkerConstants.NONE) return; 155 java.awt.datatransfer.Transferable transferable = 156 dragWorker.getTransferable(dragGestureEvent.getSourceAsDragGestureRecognizer ().getComponent ()); 157 try 158 { 159 if (transferable != null) 160 { 161 dragSource.startDrag(dragGestureEvent, 162 null, 163 dragWorker.getDragImage(dragGestureEvent.getComponent(), transferable, dragGestureEvent.getDragAction ()), 164 new java.awt.Point (0,0), 165 transferable, 166 dsListener); 167 } 168 } 169 catch (Throwable t) 170 { 171 t.printStackTrace(); 172 } 173 } 174 } 175 176 177 180 public class DSListener implements java.awt.dnd.DragSourceListener 181 { 182 183 187 public void dragDropEnd (java.awt.dnd.DragSourceDropEvent dragSourceDropEvent) 188 { 189 System.err.println("DSListener.dragDropEnd()"); 190 if (dragSourceDropEvent.getDropSuccess()) 191 { 192 dragWorker.exportDone(dragSourceDropEvent.getDragSourceContext ().getComponent (), 193 dragSourceDropEvent.getDropAction()); 194 } 195 else 196 { 197 } 199 } 200 201 204 public void dragEnter (java.awt.dnd.DragSourceDragEvent dragSourceDragEvent) 205 { 206 System.err.println("DSListener.dragEnter() dropAction:" + dragSourceDragEvent.getDropAction()); 207 217 } 218 219 220 public void dragExit (java.awt.dnd.DragSourceEvent dragSourceEvent) 221 { 222 System.err.println("DSListener.dragExit()"); 223 } 224 225 228 public void dragOver (java.awt.dnd.DragSourceDragEvent dragSourceDragEvent) 229 { 230 } 232 233 236 public void dropActionChanged (java.awt.dnd.DragSourceDragEvent dragSourceDragEvent) 237 { 238 System.err.println("DSListener.dropActionChanged() dropAction:" + dragSourceDragEvent.getDropAction()); 239 249 } 250 251 } 252 253 } 254 | Popular Tags |