0N/A/*
2362N/A * Copyright (c) 1997, 2006, Oracle and/or its affiliates. All rights reserved.
0N/A * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
0N/A *
0N/A * This code is free software; you can redistribute it and/or modify it
0N/A * under the terms of the GNU General Public License version 2 only, as
2362N/A * published by the Free Software Foundation. Oracle designates this
0N/A * particular file as subject to the "Classpath" exception as provided
2362N/A * by Oracle in the LICENSE file that accompanied this code.
0N/A *
0N/A * This code is distributed in the hope that it will be useful, but WITHOUT
0N/A * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
0N/A * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
0N/A * version 2 for more details (a copy is included in the LICENSE file that
0N/A * accompanied this code).
0N/A *
0N/A * You should have received a copy of the GNU General Public License version
0N/A * 2 along with this work; if not, write to the Free Software Foundation,
0N/A * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
0N/A *
2362N/A * Please contact Oracle, 500 Oracle Parkway, Redwood Shores, CA 94065 USA
2362N/A * or visit www.oracle.com if you need additional information or have any
2362N/A * questions.
0N/A */
0N/A
0N/Apackage java.awt.dnd;
0N/A
0N/Aimport java.awt.event.InputEvent;
0N/A
0N/A/**
0N/A * The <code>DragSourceDragEvent</code> is
0N/A * delivered from the <code>DragSourceContextPeer</code>,
0N/A * via the <code>DragSourceContext</code>, to the <code>DragSourceListener</code>
0N/A * registered with that <code>DragSourceContext</code> and with its associated
0N/A * <code>DragSource</code>.
0N/A * <p>
0N/A * The <code>DragSourceDragEvent</code> reports the <i>target drop action</i>
0N/A * and the <i>user drop action</i> that reflect the current state of
0N/A * the drag operation.
0N/A * <p>
0N/A * <i>Target drop action</i> is one of <code>DnDConstants</code> that represents
0N/A * the drop action selected by the current drop target if this drop action is
0N/A * supported by the drag source or <code>DnDConstants.ACTION_NONE</code> if this
0N/A * drop action is not supported by the drag source.
0N/A * <p>
0N/A * <i>User drop action</i> depends on the drop actions supported by the drag
0N/A * source and the drop action selected by the user. The user can select a drop
0N/A * action by pressing modifier keys during the drag operation:
0N/A * <pre>
0N/A * Ctrl + Shift -> ACTION_LINK
0N/A * Ctrl -> ACTION_COPY
0N/A * Shift -> ACTION_MOVE
0N/A * </pre>
0N/A * If the user selects a drop action, the <i>user drop action</i> is one of
0N/A * <code>DnDConstants</code> that represents the selected drop action if this
0N/A * drop action is supported by the drag source or
0N/A * <code>DnDConstants.ACTION_NONE</code> if this drop action is not supported
0N/A * by the drag source.
0N/A * <p>
0N/A * If the user doesn't select a drop action, the set of
0N/A * <code>DnDConstants</code> that represents the set of drop actions supported
0N/A * by the drag source is searched for <code>DnDConstants.ACTION_MOVE</code>,
0N/A * then for <code>DnDConstants.ACTION_COPY</code>, then for
0N/A * <code>DnDConstants.ACTION_LINK</code> and the <i>user drop action</i> is the
0N/A * first constant found. If no constant is found the <i>user drop action</i>
0N/A * is <code>DnDConstants.ACTION_NONE</code>.
0N/A *
0N/A * @since 1.2
0N/A *
0N/A */
0N/A
0N/Apublic class DragSourceDragEvent extends DragSourceEvent {
0N/A
0N/A private static final long serialVersionUID = 481346297933902471L;
0N/A
0N/A /**
0N/A * Constructs a <code>DragSourceDragEvent</code>.
0N/A * This class is typically
0N/A * instantiated by the <code>DragSourceContextPeer</code>
0N/A * rather than directly
0N/A * by client code.
0N/A * The coordinates for this <code>DragSourceDragEvent</code>
0N/A * are not specified, so <code>getLocation</code> will return
0N/A * <code>null</code> for this event.
0N/A * <p>
0N/A * The arguments <code>dropAction</code> and <code>action</code> should
0N/A * be one of <code>DnDConstants</code> that represents a single action.
0N/A * The argument <code>modifiers</code> should be either a bitwise mask
0N/A * of old <code>java.awt.event.InputEvent.*_MASK</code> constants or a
0N/A * bitwise mask of extended <code>java.awt.event.InputEvent.*_DOWN_MASK</code>
0N/A * constants.
0N/A * This constructor does not throw any exception for invalid <code>dropAction</code>,
0N/A * <code>action</code> and <code>modifiers</code>.
0N/A *
0N/A * @param dsc the <code>DragSourceContext</code> that is to manage
0N/A * notifications for this event.
0N/A * @param dropAction the user drop action.
0N/A * @param action the target drop action.
0N/A * @param modifiers the modifier keys down during event (shift, ctrl,
0N/A * alt, meta)
0N/A * Either extended _DOWN_MASK or old _MASK modifiers
0N/A * should be used, but both models should not be mixed
0N/A * in one event. Use of the extended modifiers is
0N/A * preferred.
0N/A *
0N/A * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>.
0N/A *
0N/A * @see java.awt.event.InputEvent
0N/A * @see DragSourceEvent#getLocation
0N/A */
0N/A
0N/A public DragSourceDragEvent(DragSourceContext dsc, int dropAction,
0N/A int action, int modifiers) {
0N/A super(dsc);
0N/A
0N/A targetActions = action;
0N/A gestureModifiers = modifiers;
0N/A this.dropAction = dropAction;
0N/A if ((modifiers & ~(JDK_1_3_MODIFIERS | JDK_1_4_MODIFIERS)) != 0) {
0N/A invalidModifiers = true;
0N/A } else if ((getGestureModifiers() != 0) && (getGestureModifiersEx() == 0)) {
0N/A setNewModifiers();
0N/A } else if ((getGestureModifiers() == 0) && (getGestureModifiersEx() != 0)) {
0N/A setOldModifiers();
0N/A } else {
0N/A invalidModifiers = true;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Constructs a <code>DragSourceDragEvent</code> given the specified
0N/A * <code>DragSourceContext</code>, user drop action, target drop action,
0N/A * modifiers and coordinates.
0N/A * <p>
0N/A * The arguments <code>dropAction</code> and <code>action</code> should
0N/A * be one of <code>DnDConstants</code> that represents a single action.
0N/A * The argument <code>modifiers</code> should be either a bitwise mask
0N/A * of old <code>java.awt.event.InputEvent.*_MASK</code> constants or a
0N/A * bitwise mask of extended <code>java.awt.event.InputEvent.*_DOWN_MASK</code>
0N/A * constants.
0N/A * This constructor does not throw any exception for invalid <code>dropAction</code>,
0N/A * <code>action</code> and <code>modifiers</code>.
0N/A *
0N/A * @param dsc the <code>DragSourceContext</code> associated with this
0N/A * event.
0N/A * @param dropAction the user drop action.
0N/A * @param action the target drop action.
0N/A * @param modifiers the modifier keys down during event (shift, ctrl,
0N/A * alt, meta)
0N/A * Either extended _DOWN_MASK or old _MASK modifiers
0N/A * should be used, but both models should not be mixed
0N/A * in one event. Use of the extended modifiers is
0N/A * preferred.
0N/A * @param x the horizontal coordinate for the cursor location
0N/A * @param y the vertical coordinate for the cursor location
0N/A *
0N/A * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>.
0N/A *
0N/A * @see java.awt.event.InputEvent
0N/A * @since 1.4
0N/A */
0N/A public DragSourceDragEvent(DragSourceContext dsc, int dropAction,
0N/A int action, int modifiers, int x, int y) {
0N/A super(dsc, x, y);
0N/A
0N/A targetActions = action;
0N/A gestureModifiers = modifiers;
0N/A this.dropAction = dropAction;
0N/A if ((modifiers & ~(JDK_1_3_MODIFIERS | JDK_1_4_MODIFIERS)) != 0) {
0N/A invalidModifiers = true;
0N/A } else if ((getGestureModifiers() != 0) && (getGestureModifiersEx() == 0)) {
0N/A setNewModifiers();
0N/A } else if ((getGestureModifiers() == 0) && (getGestureModifiersEx() != 0)) {
0N/A setOldModifiers();
0N/A } else {
0N/A invalidModifiers = true;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * This method returns the target drop action.
0N/A *
0N/A * @return the target drop action.
0N/A */
0N/A public int getTargetActions() {
0N/A return targetActions;
0N/A }
0N/A
0N/A
0N/A private static final int JDK_1_3_MODIFIERS = InputEvent.SHIFT_DOWN_MASK - 1;
0N/A private static final int JDK_1_4_MODIFIERS =
0N/A ((InputEvent.ALT_GRAPH_DOWN_MASK << 1) - 1) & ~JDK_1_3_MODIFIERS;
0N/A
0N/A /**
0N/A * This method returns an <code>int</code> representing
0N/A * the current state of the input device modifiers
0N/A * associated with the user's gesture. Typically these
0N/A * would be mouse buttons or keyboard modifiers.
0N/A * <P>
0N/A * If the <code>modifiers</code> passed to the constructor
0N/A * are invalid, this method returns them unchanged.
0N/A *
0N/A * @return the current state of the input device modifiers
0N/A */
0N/A
0N/A public int getGestureModifiers() {
0N/A return invalidModifiers ? gestureModifiers : gestureModifiers & JDK_1_3_MODIFIERS;
0N/A }
0N/A
0N/A /**
0N/A * This method returns an <code>int</code> representing
0N/A * the current state of the input device extended modifiers
0N/A * associated with the user's gesture.
0N/A * See {@link InputEvent#getModifiersEx}
0N/A * <P>
0N/A * If the <code>modifiers</code> passed to the constructor
0N/A * are invalid, this method returns them unchanged.
0N/A *
0N/A * @return the current state of the input device extended modifiers
0N/A * @since 1.4
0N/A */
0N/A
0N/A public int getGestureModifiersEx() {
0N/A return invalidModifiers ? gestureModifiers : gestureModifiers & JDK_1_4_MODIFIERS;
0N/A }
0N/A
0N/A /**
0N/A * This method returns the user drop action.
0N/A *
0N/A * @return the user drop action.
0N/A */
0N/A public int getUserAction() { return dropAction; }
0N/A
0N/A /**
0N/A * This method returns the logical intersection of
0N/A * the target drop action and the set of drop actions supported by
0N/A * the drag source.
0N/A *
0N/A * @return the logical intersection of the target drop action and
0N/A * the set of drop actions supported by the drag source.
0N/A */
0N/A public int getDropAction() {
0N/A return targetActions & getDragSourceContext().getSourceActions();
0N/A }
0N/A
0N/A /*
0N/A * fields
0N/A */
0N/A
0N/A /**
0N/A * The target drop action.
0N/A *
0N/A * @serial
0N/A */
0N/A private int targetActions = DnDConstants.ACTION_NONE;
0N/A
0N/A /**
0N/A * The user drop action.
0N/A *
0N/A * @serial
0N/A */
0N/A private int dropAction = DnDConstants.ACTION_NONE;
0N/A
0N/A /**
0N/A * The state of the input device modifiers associated with the user
0N/A * gesture.
0N/A *
0N/A * @serial
0N/A */
0N/A private int gestureModifiers = 0;
0N/A
0N/A /**
0N/A * Indicates whether the <code>gestureModifiers</code> are invalid.
0N/A *
0N/A * @serial
0N/A */
0N/A private boolean invalidModifiers;
0N/A
0N/A /**
0N/A * Sets new modifiers by the old ones.
0N/A * The mouse modifiers have higher priority than overlaying key
0N/A * modifiers.
0N/A */
0N/A private void setNewModifiers() {
0N/A if ((gestureModifiers & InputEvent.BUTTON1_MASK) != 0) {
0N/A gestureModifiers |= InputEvent.BUTTON1_DOWN_MASK;
0N/A }
0N/A if ((gestureModifiers & InputEvent.BUTTON2_MASK) != 0) {
0N/A gestureModifiers |= InputEvent.BUTTON2_DOWN_MASK;
0N/A }
0N/A if ((gestureModifiers & InputEvent.BUTTON3_MASK) != 0) {
0N/A gestureModifiers |= InputEvent.BUTTON3_DOWN_MASK;
0N/A }
0N/A if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) {
0N/A gestureModifiers |= InputEvent.SHIFT_DOWN_MASK;
0N/A }
0N/A if ((gestureModifiers & InputEvent.CTRL_MASK) != 0) {
0N/A gestureModifiers |= InputEvent.CTRL_DOWN_MASK;
0N/A }
0N/A if ((gestureModifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
0N/A gestureModifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
0N/A }
0N/A }
0N/A
0N/A /**
0N/A * Sets old modifiers by the new ones.
0N/A */
0N/A private void setOldModifiers() {
0N/A if ((gestureModifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
0N/A gestureModifiers |= InputEvent.BUTTON1_MASK;
0N/A }
0N/A if ((gestureModifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
0N/A gestureModifiers |= InputEvent.BUTTON2_MASK;
0N/A }
0N/A if ((gestureModifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
0N/A gestureModifiers |= InputEvent.BUTTON3_MASK;
0N/A }
0N/A if ((gestureModifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
0N/A gestureModifiers |= InputEvent.SHIFT_MASK;
0N/A }
0N/A if ((gestureModifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
0N/A gestureModifiers |= InputEvent.CTRL_MASK;
0N/A }
0N/A if ((gestureModifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
0N/A gestureModifiers |= InputEvent.ALT_GRAPH_MASK;
0N/A }
0N/A }
0N/A}