1 7 8 package java.awt.dnd; 9 10 import java.awt.event.InputEvent ; 11 12 54 55 public class DragSourceDragEvent extends DragSourceEvent { 56 57 private static final long serialVersionUID = 481346297933902471L; 58 59 94 95 public DragSourceDragEvent(DragSourceContext dsc, int dropAction, 96 int action, int modifiers) { 97 super(dsc); 98 99 targetActions = action; 100 gestureModifiers = modifiers; 101 this.dropAction = dropAction; 102 if ((modifiers & ~(JDK_1_3_MODIFIERS | JDK_1_4_MODIFIERS)) != 0) { 103 invalidModifiers = true; 104 } else if ((getGestureModifiers() != 0) && (getGestureModifiersEx() == 0)) { 105 setNewModifiers(); 106 } else if ((getGestureModifiers() == 0) && (getGestureModifiersEx() != 0)) { 107 setOldModifiers(); 108 } else { 109 invalidModifiers = true; 110 } 111 } 112 113 145 public DragSourceDragEvent(DragSourceContext dsc, int dropAction, 146 int action, int modifiers, int x, int y) { 147 super(dsc, x, y); 148 149 targetActions = action; 150 gestureModifiers = modifiers; 151 this.dropAction = dropAction; 152 if ((modifiers & ~(JDK_1_3_MODIFIERS | JDK_1_4_MODIFIERS)) != 0) { 153 invalidModifiers = true; 154 } else if ((getGestureModifiers() != 0) && (getGestureModifiersEx() == 0)) { 155 setNewModifiers(); 156 } else if ((getGestureModifiers() == 0) && (getGestureModifiersEx() != 0)) { 157 setOldModifiers(); 158 } else { 159 invalidModifiers = true; 160 } 161 } 162 163 168 public int getTargetActions() { 169 return targetActions; 170 } 171 172 173 private static final int JDK_1_3_MODIFIERS = InputEvent.SHIFT_DOWN_MASK - 1; 174 private static final int JDK_1_4_MODIFIERS = 175 ((InputEvent.ALT_GRAPH_DOWN_MASK << 1) - 1) & ~JDK_1_3_MODIFIERS; 176 177 188 189 public int getGestureModifiers() { 190 return invalidModifiers ? gestureModifiers : gestureModifiers & JDK_1_3_MODIFIERS; 191 } 192 193 205 206 public int getGestureModifiersEx() { 207 return invalidModifiers ? gestureModifiers : gestureModifiers & JDK_1_4_MODIFIERS; 208 } 209 210 215 public int getUserAction() { return dropAction; } 216 217 225 public int getDropAction() { 226 return dropAction & targetActions & getDragSourceContext().getSourceActions(); 227 } 228 229 232 233 238 private int targetActions = DnDConstants.ACTION_NONE; 239 240 245 private int dropAction = DnDConstants.ACTION_NONE; 246 247 253 private int gestureModifiers = 0; 254 255 260 private boolean invalidModifiers; 261 262 267 private void setNewModifiers() { 268 if ((gestureModifiers & InputEvent.BUTTON1_MASK) != 0) { 269 gestureModifiers |= InputEvent.BUTTON1_DOWN_MASK; 270 } 271 if ((gestureModifiers & InputEvent.BUTTON2_MASK) != 0) { 272 gestureModifiers |= InputEvent.BUTTON2_DOWN_MASK; 273 } 274 if ((gestureModifiers & InputEvent.BUTTON3_MASK) != 0) { 275 gestureModifiers |= InputEvent.BUTTON3_DOWN_MASK; 276 } 277 if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) { 278 gestureModifiers |= InputEvent.SHIFT_DOWN_MASK; 279 } 280 if ((gestureModifiers & InputEvent.CTRL_MASK) != 0) { 281 gestureModifiers |= InputEvent.CTRL_DOWN_MASK; 282 } 283 if ((gestureModifiers & InputEvent.ALT_GRAPH_MASK) != 0) { 284 gestureModifiers |= InputEvent.ALT_GRAPH_DOWN_MASK; 285 } 286 } 287 288 291 private void setOldModifiers() { 292 if ((gestureModifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) { 293 gestureModifiers |= InputEvent.BUTTON1_MASK; 294 } 295 if ((gestureModifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) { 296 gestureModifiers |= InputEvent.BUTTON2_MASK; 297 } 298 if ((gestureModifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) { 299 gestureModifiers |= InputEvent.BUTTON3_MASK; 300 } 301 if ((gestureModifiers & InputEvent.SHIFT_DOWN_MASK) != 0) { 302 gestureModifiers |= InputEvent.SHIFT_MASK; 303 } 304 if ((gestureModifiers & InputEvent.CTRL_DOWN_MASK) != 0) { 305 gestureModifiers |= InputEvent.CTRL_MASK; 306 } 307 if ((gestureModifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) { 308 gestureModifiers |= InputEvent.ALT_GRAPH_MASK; 309 } 310 } 311 } 312 | Popular Tags |