1 /*
2 * Copyright (c) 2000, 2014, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
57
58 /**
59 * <p>
60 * TBC
61 * </p>
62 *
63 * @since 1.3.1
64 *
65 */
66 public abstract class SunDragSourceContextPeer implements DragSourceContextPeer {
67
68 private DragGestureEvent trigger;
69 private Component component;
70 private Cursor cursor;
71 private Image dragImage;
72 private Point dragImageOffset;
73 private long nativeCtxt;
74 private DragSourceContext dragSourceContext;
75 private int sourceActions;
76
77 private static boolean dragDropInProgress = false;
78 private static boolean discardingMouseEvents = false;
79
80 /*
81 * dispatch constants
82 */
83
84 protected static final int DISPATCH_ENTER = 1;
85 protected static final int DISPATCH_MOTION = 2;
86 protected static final int DISPATCH_CHANGED = 3;
87 protected static final int DISPATCH_EXIT = 4;
88 protected static final int DISPATCH_FINISH = 5;
89 protected static final int DISPATCH_MOUSE_MOVED = 6;
90
91 /**
92 * construct a new SunDragSourceContextPeer
93 */
94
95 public SunDragSourceContextPeer(DragGestureEvent dge) {
96 trigger = dge;
97 if (trigger != null) {
364 * Filters out all mouse events that were on the java event queue when
365 * startDrag was called.
366 */
367 public static boolean checkEvent(AWTEvent event) {
368 if (discardingMouseEvents && event instanceof MouseEvent) {
369 MouseEvent mouseEvent = (MouseEvent)event;
370 if (!(mouseEvent instanceof SunDropTargetEvent)) {
371 return false;
372 }
373 }
374 return true;
375 }
376
377 public static void checkDragDropInProgress()
378 throws InvalidDnDOperationException {
379 if (dragDropInProgress) {
380 throw new InvalidDnDOperationException(getExceptionMessage(true));
381 }
382 }
383
384 private static String getExceptionMessage(boolean b) {
385 return b ? "Drag and drop in progress" : "No drag in progress";
386 }
387
388 public static int convertModifiersToDropAction(final int modifiers,
389 final int supportedActions) {
390 int dropAction = DnDConstants.ACTION_NONE;
391
392 /*
393 * Fix for 4285634.
394 * Calculate the drop action to match Motif DnD behavior.
395 * If the user selects an operation (by pressing a modifier key),
396 * return the selected operation or ACTION_NONE if the selected
397 * operation is not supported by the drag source.
398 * If the user doesn't select an operation search the set of operations
399 * supported by the drag source for ACTION_MOVE, then for
400 * ACTION_COPY, then for ACTION_LINK and return the first operation
401 * found.
402 */
403 switch (modifiers & (InputEvent.SHIFT_DOWN_MASK |
|
1 /*
2 * Copyright (c) 2000, 2020, Oracle and/or its affiliates. All rights reserved.
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * This code is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License version 2 only, as
7 * published by the Free Software Foundation. Oracle designates this
8 * particular file as subject to the "Classpath" exception as provided
9 * by Oracle in the LICENSE file that accompanied this code.
10 *
11 * This code is distributed in the hope that it will be useful, but WITHOUT
12 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
13 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
14 * version 2 for more details (a copy is included in the LICENSE file that
15 * accompanied this code).
16 *
17 * You should have received a copy of the GNU General Public License version
18 * 2 along with this work; if not, write to the Free Software Foundation,
19 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
20 *
21 * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
22 * or visit www.oracle.com if you need additional information or have any
57
58 /**
59 * <p>
60 * TBC
61 * </p>
62 *
63 * @since 1.3.1
64 *
65 */
66 public abstract class SunDragSourceContextPeer implements DragSourceContextPeer {
67
68 private DragGestureEvent trigger;
69 private Component component;
70 private Cursor cursor;
71 private Image dragImage;
72 private Point dragImageOffset;
73 private long nativeCtxt;
74 private DragSourceContext dragSourceContext;
75 private int sourceActions;
76
77 private static volatile boolean dragDropInProgress = false;
78 private static boolean discardingMouseEvents = false;
79
80 /*
81 * dispatch constants
82 */
83
84 protected static final int DISPATCH_ENTER = 1;
85 protected static final int DISPATCH_MOTION = 2;
86 protected static final int DISPATCH_CHANGED = 3;
87 protected static final int DISPATCH_EXIT = 4;
88 protected static final int DISPATCH_FINISH = 5;
89 protected static final int DISPATCH_MOUSE_MOVED = 6;
90
91 /**
92 * construct a new SunDragSourceContextPeer
93 */
94
95 public SunDragSourceContextPeer(DragGestureEvent dge) {
96 trigger = dge;
97 if (trigger != null) {
364 * Filters out all mouse events that were on the java event queue when
365 * startDrag was called.
366 */
367 public static boolean checkEvent(AWTEvent event) {
368 if (discardingMouseEvents && event instanceof MouseEvent) {
369 MouseEvent mouseEvent = (MouseEvent)event;
370 if (!(mouseEvent instanceof SunDropTargetEvent)) {
371 return false;
372 }
373 }
374 return true;
375 }
376
377 public static void checkDragDropInProgress()
378 throws InvalidDnDOperationException {
379 if (dragDropInProgress) {
380 throw new InvalidDnDOperationException(getExceptionMessage(true));
381 }
382 }
383
384 public static boolean isDragDropInProgress() {
385 return dragDropInProgress;
386 }
387
388 private static String getExceptionMessage(boolean b) {
389 return b ? "Drag and drop in progress" : "No drag in progress";
390 }
391
392 public static int convertModifiersToDropAction(final int modifiers,
393 final int supportedActions) {
394 int dropAction = DnDConstants.ACTION_NONE;
395
396 /*
397 * Fix for 4285634.
398 * Calculate the drop action to match Motif DnD behavior.
399 * If the user selects an operation (by pressing a modifier key),
400 * return the selected operation or ACTION_NONE if the selected
401 * operation is not supported by the drag source.
402 * If the user doesn't select an operation search the set of operations
403 * supported by the drag source for ACTION_MOVE, then for
404 * ACTION_COPY, then for ACTION_LINK and return the first operation
405 * found.
406 */
407 switch (modifiers & (InputEvent.SHIFT_DOWN_MASK |
|