jdk/src/share/classes/java/awt/dnd/DragSourceDragEvent.java
author dav
Thu, 29 May 2008 13:48:51 +0400
changeset 638 69a80895db21
parent 2 90ce3da70b43
child 5506 202f599c92aa
permissions -rw-r--r--
6691328: DragSourceContext returns unexpected cursor Summary: make the code to be executed if other options don't suit Reviewed-by: dcherepanov
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
2
90ce3da70b43 Initial load
duke
parents:
diff changeset
     1
/*
90ce3da70b43 Initial load
duke
parents:
diff changeset
     2
 * Copyright 1997-2006 Sun Microsystems, Inc.  All Rights Reserved.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     3
 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
90ce3da70b43 Initial load
duke
parents:
diff changeset
     4
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
     5
 * This code is free software; you can redistribute it and/or modify it
90ce3da70b43 Initial load
duke
parents:
diff changeset
     6
 * under the terms of the GNU General Public License version 2 only, as
90ce3da70b43 Initial load
duke
parents:
diff changeset
     7
 * published by the Free Software Foundation.  Sun designates this
90ce3da70b43 Initial load
duke
parents:
diff changeset
     8
 * particular file as subject to the "Classpath" exception as provided
90ce3da70b43 Initial load
duke
parents:
diff changeset
     9
 * by Sun in the LICENSE file that accompanied this code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    10
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    11
 * This code is distributed in the hope that it will be useful, but WITHOUT
90ce3da70b43 Initial load
duke
parents:
diff changeset
    12
 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    13
 * FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
90ce3da70b43 Initial load
duke
parents:
diff changeset
    14
 * version 2 for more details (a copy is included in the LICENSE file that
90ce3da70b43 Initial load
duke
parents:
diff changeset
    15
 * accompanied this code).
90ce3da70b43 Initial load
duke
parents:
diff changeset
    16
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    17
 * You should have received a copy of the GNU General Public License version
90ce3da70b43 Initial load
duke
parents:
diff changeset
    18
 * 2 along with this work; if not, write to the Free Software Foundation,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    19
 * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    20
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    21
 * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa Clara,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    22
 * CA 95054 USA or visit www.sun.com if you need additional information or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    23
 * have any questions.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    24
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    25
90ce3da70b43 Initial load
duke
parents:
diff changeset
    26
package java.awt.dnd;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    27
90ce3da70b43 Initial load
duke
parents:
diff changeset
    28
import java.awt.event.InputEvent;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    29
90ce3da70b43 Initial load
duke
parents:
diff changeset
    30
/**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    31
 * The <code>DragSourceDragEvent</code> is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    32
 * delivered from the <code>DragSourceContextPeer</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    33
 * via the <code>DragSourceContext</code>, to the <code>DragSourceListener</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    34
 * registered with that <code>DragSourceContext</code> and with its associated
90ce3da70b43 Initial load
duke
parents:
diff changeset
    35
 * <code>DragSource</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    36
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    37
 * The <code>DragSourceDragEvent</code> reports the <i>target drop action</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    38
 * and the <i>user drop action</i> that reflect the current state of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    39
 * the drag operation.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    40
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    41
 * <i>Target drop action</i> is one of <code>DnDConstants</code> that represents
90ce3da70b43 Initial load
duke
parents:
diff changeset
    42
 * the drop action selected by the current drop target if this drop action is
90ce3da70b43 Initial load
duke
parents:
diff changeset
    43
 * supported by the drag source or <code>DnDConstants.ACTION_NONE</code> if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    44
 * drop action is not supported by the drag source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    45
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    46
 * <i>User drop action</i> depends on the drop actions supported by the drag
90ce3da70b43 Initial load
duke
parents:
diff changeset
    47
 * source and the drop action selected by the user. The user can select a drop
90ce3da70b43 Initial load
duke
parents:
diff changeset
    48
 * action by pressing modifier keys during the drag operation:
90ce3da70b43 Initial load
duke
parents:
diff changeset
    49
 * <pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    50
 *   Ctrl + Shift -> ACTION_LINK
90ce3da70b43 Initial load
duke
parents:
diff changeset
    51
 *   Ctrl         -> ACTION_COPY
90ce3da70b43 Initial load
duke
parents:
diff changeset
    52
 *   Shift        -> ACTION_MOVE
90ce3da70b43 Initial load
duke
parents:
diff changeset
    53
 * </pre>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    54
 * If the user selects a drop action, the <i>user drop action</i> is one of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    55
 * <code>DnDConstants</code> that represents the selected drop action if this
90ce3da70b43 Initial load
duke
parents:
diff changeset
    56
 * drop action is supported by the drag source or
90ce3da70b43 Initial load
duke
parents:
diff changeset
    57
 * <code>DnDConstants.ACTION_NONE</code> if this drop action is not supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    58
 * by the drag source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    59
 * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    60
 * If the user doesn't select a drop action, the set of
90ce3da70b43 Initial load
duke
parents:
diff changeset
    61
 * <code>DnDConstants</code> that represents the set of drop actions supported
90ce3da70b43 Initial load
duke
parents:
diff changeset
    62
 * by the drag source is searched for <code>DnDConstants.ACTION_MOVE</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    63
 * then for <code>DnDConstants.ACTION_COPY</code>, then for
90ce3da70b43 Initial load
duke
parents:
diff changeset
    64
 * <code>DnDConstants.ACTION_LINK</code> and the <i>user drop action</i> is the
90ce3da70b43 Initial load
duke
parents:
diff changeset
    65
 * first constant found. If no constant is found the <i>user drop action</i>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    66
 * is <code>DnDConstants.ACTION_NONE</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    67
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    68
 * @since 1.2
90ce3da70b43 Initial load
duke
parents:
diff changeset
    69
 *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    70
 */
90ce3da70b43 Initial load
duke
parents:
diff changeset
    71
90ce3da70b43 Initial load
duke
parents:
diff changeset
    72
public class DragSourceDragEvent extends DragSourceEvent {
90ce3da70b43 Initial load
duke
parents:
diff changeset
    73
90ce3da70b43 Initial load
duke
parents:
diff changeset
    74
    private static final long serialVersionUID = 481346297933902471L;
90ce3da70b43 Initial load
duke
parents:
diff changeset
    75
90ce3da70b43 Initial load
duke
parents:
diff changeset
    76
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
    77
     * Constructs a <code>DragSourceDragEvent</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    78
     * This class is typically
90ce3da70b43 Initial load
duke
parents:
diff changeset
    79
     * instantiated by the <code>DragSourceContextPeer</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    80
     * rather than directly
90ce3da70b43 Initial load
duke
parents:
diff changeset
    81
     * by client code.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    82
     * The coordinates for this <code>DragSourceDragEvent</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    83
     * are not specified, so <code>getLocation</code> will return
90ce3da70b43 Initial load
duke
parents:
diff changeset
    84
     * <code>null</code> for this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    85
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    86
     * The arguments <code>dropAction</code> and <code>action</code> should
90ce3da70b43 Initial load
duke
parents:
diff changeset
    87
     * be one of <code>DnDConstants</code> that represents a single action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    88
     * The argument <code>modifiers</code> should be either a bitwise mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
    89
     * of old <code>java.awt.event.InputEvent.*_MASK</code> constants or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
    90
     * bitwise mask of extended <code>java.awt.event.InputEvent.*_DOWN_MASK</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
    91
     * constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    92
     * This constructor does not throw any exception for invalid <code>dropAction</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
    93
     * <code>action</code> and <code>modifiers</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    94
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
    95
     * @param dsc the <code>DragSourceContext</code> that is to manage
90ce3da70b43 Initial load
duke
parents:
diff changeset
    96
     *            notifications for this event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    97
     * @param dropAction the user drop action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    98
     * @param action the target drop action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
    99
     * @param modifiers the modifier keys down during event (shift, ctrl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   100
     *        alt, meta)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   101
     *        Either extended _DOWN_MASK or old _MASK modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   102
     *        should be used, but both models should not be mixed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   103
     *        in one event. Use of the extended modifiers is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   104
     *        preferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   105
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   106
     * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   107
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   108
     * @see java.awt.event.InputEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   109
     * @see DragSourceEvent#getLocation
90ce3da70b43 Initial load
duke
parents:
diff changeset
   110
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   111
90ce3da70b43 Initial load
duke
parents:
diff changeset
   112
    public DragSourceDragEvent(DragSourceContext dsc, int dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   113
                               int action, int modifiers) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   114
        super(dsc);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   115
90ce3da70b43 Initial load
duke
parents:
diff changeset
   116
        targetActions    = action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   117
        gestureModifiers = modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   118
        this.dropAction  = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   119
        if ((modifiers & ~(JDK_1_3_MODIFIERS | JDK_1_4_MODIFIERS)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   120
            invalidModifiers = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   121
        } else if ((getGestureModifiers() != 0) && (getGestureModifiersEx() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   122
            setNewModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   123
        } else if ((getGestureModifiers() == 0) && (getGestureModifiersEx() != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   124
            setOldModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   125
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   126
            invalidModifiers = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   127
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   128
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   129
90ce3da70b43 Initial load
duke
parents:
diff changeset
   130
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   131
     * Constructs a <code>DragSourceDragEvent</code> given the specified
90ce3da70b43 Initial load
duke
parents:
diff changeset
   132
     * <code>DragSourceContext</code>, user drop action, target drop action,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   133
     * modifiers and coordinates.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   134
     * <p>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   135
     * The arguments <code>dropAction</code> and <code>action</code> should
90ce3da70b43 Initial load
duke
parents:
diff changeset
   136
     * be one of <code>DnDConstants</code> that represents a single action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   137
     * The argument <code>modifiers</code> should be either a bitwise mask
90ce3da70b43 Initial load
duke
parents:
diff changeset
   138
     * of old <code>java.awt.event.InputEvent.*_MASK</code> constants or a
90ce3da70b43 Initial load
duke
parents:
diff changeset
   139
     * bitwise mask of extended <code>java.awt.event.InputEvent.*_DOWN_MASK</code>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   140
     * constants.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   141
     * This constructor does not throw any exception for invalid <code>dropAction</code>,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   142
     * <code>action</code> and <code>modifiers</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   143
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   144
     * @param dsc the <code>DragSourceContext</code> associated with this
90ce3da70b43 Initial load
duke
parents:
diff changeset
   145
     *        event.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   146
     * @param dropAction the user drop action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   147
     * @param action the target drop action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   148
     * @param modifiers the modifier keys down during event (shift, ctrl,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   149
     *        alt, meta)
90ce3da70b43 Initial load
duke
parents:
diff changeset
   150
     *        Either extended _DOWN_MASK or old _MASK modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   151
     *        should be used, but both models should not be mixed
90ce3da70b43 Initial load
duke
parents:
diff changeset
   152
     *        in one event. Use of the extended modifiers is
90ce3da70b43 Initial load
duke
parents:
diff changeset
   153
     *        preferred.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   154
     * @param x   the horizontal coordinate for the cursor location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   155
     * @param y   the vertical coordinate for the cursor location
90ce3da70b43 Initial load
duke
parents:
diff changeset
   156
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   157
     * @throws <code>IllegalArgumentException</code> if <code>dsc</code> is <code>null</code>.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   158
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   159
     * @see java.awt.event.InputEvent
90ce3da70b43 Initial load
duke
parents:
diff changeset
   160
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   161
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   162
    public DragSourceDragEvent(DragSourceContext dsc, int dropAction,
90ce3da70b43 Initial load
duke
parents:
diff changeset
   163
                               int action, int modifiers, int x, int y) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   164
        super(dsc, x, y);
90ce3da70b43 Initial load
duke
parents:
diff changeset
   165
90ce3da70b43 Initial load
duke
parents:
diff changeset
   166
        targetActions    = action;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   167
        gestureModifiers = modifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   168
        this.dropAction  = dropAction;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   169
        if ((modifiers & ~(JDK_1_3_MODIFIERS | JDK_1_4_MODIFIERS)) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   170
            invalidModifiers = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   171
        } else if ((getGestureModifiers() != 0) && (getGestureModifiersEx() == 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   172
            setNewModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   173
        } else if ((getGestureModifiers() == 0) && (getGestureModifiersEx() != 0)) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   174
            setOldModifiers();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   175
        } else {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   176
            invalidModifiers = true;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   177
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   178
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   179
90ce3da70b43 Initial load
duke
parents:
diff changeset
   180
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   181
     * This method returns the target drop action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   182
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   183
     * @return the target drop action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   184
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   185
    public int getTargetActions() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   186
        return targetActions;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   187
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   188
90ce3da70b43 Initial load
duke
parents:
diff changeset
   189
90ce3da70b43 Initial load
duke
parents:
diff changeset
   190
    private static final int JDK_1_3_MODIFIERS = InputEvent.SHIFT_DOWN_MASK - 1;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   191
    private static final int JDK_1_4_MODIFIERS =
90ce3da70b43 Initial load
duke
parents:
diff changeset
   192
            ((InputEvent.ALT_GRAPH_DOWN_MASK << 1) - 1) & ~JDK_1_3_MODIFIERS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   193
90ce3da70b43 Initial load
duke
parents:
diff changeset
   194
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   195
     * This method returns an <code>int</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   196
     * the current state of the input device modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   197
     * associated with the user's gesture. Typically these
90ce3da70b43 Initial load
duke
parents:
diff changeset
   198
     * would be mouse buttons or keyboard modifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   199
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   200
     * If the <code>modifiers</code> passed to the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   201
     * are invalid, this method returns them unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   202
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   203
     * @return the current state of the input device modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   204
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   205
90ce3da70b43 Initial load
duke
parents:
diff changeset
   206
    public int getGestureModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   207
        return invalidModifiers ? gestureModifiers : gestureModifiers & JDK_1_3_MODIFIERS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   208
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   209
90ce3da70b43 Initial load
duke
parents:
diff changeset
   210
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   211
     * This method returns an <code>int</code> representing
90ce3da70b43 Initial load
duke
parents:
diff changeset
   212
     * the current state of the input device extended modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   213
     * associated with the user's gesture.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   214
     * See {@link InputEvent#getModifiersEx}
90ce3da70b43 Initial load
duke
parents:
diff changeset
   215
     * <P>
90ce3da70b43 Initial load
duke
parents:
diff changeset
   216
     * If the <code>modifiers</code> passed to the constructor
90ce3da70b43 Initial load
duke
parents:
diff changeset
   217
     * are invalid, this method returns them unchanged.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   218
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   219
     * @return the current state of the input device extended modifiers
90ce3da70b43 Initial load
duke
parents:
diff changeset
   220
     * @since 1.4
90ce3da70b43 Initial load
duke
parents:
diff changeset
   221
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   222
90ce3da70b43 Initial load
duke
parents:
diff changeset
   223
    public int getGestureModifiersEx() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   224
        return invalidModifiers ? gestureModifiers : gestureModifiers & JDK_1_4_MODIFIERS;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   225
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   226
90ce3da70b43 Initial load
duke
parents:
diff changeset
   227
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   228
     * This method returns the user drop action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   229
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   230
     * @return the user drop action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   231
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   232
    public int getUserAction() { return dropAction; }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   233
90ce3da70b43 Initial load
duke
parents:
diff changeset
   234
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   235
     * This method returns the logical intersection of
90ce3da70b43 Initial load
duke
parents:
diff changeset
   236
     * the target drop action and the set of drop actions supported by
90ce3da70b43 Initial load
duke
parents:
diff changeset
   237
     * the drag source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   238
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   239
     * @return the logical intersection of the target drop action and
90ce3da70b43 Initial load
duke
parents:
diff changeset
   240
     *         the set of drop actions supported by the drag source.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   241
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   242
    public int getDropAction() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   243
        return targetActions & getDragSourceContext().getSourceActions();
90ce3da70b43 Initial load
duke
parents:
diff changeset
   244
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   245
90ce3da70b43 Initial load
duke
parents:
diff changeset
   246
    /*
90ce3da70b43 Initial load
duke
parents:
diff changeset
   247
     * fields
90ce3da70b43 Initial load
duke
parents:
diff changeset
   248
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   249
90ce3da70b43 Initial load
duke
parents:
diff changeset
   250
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   251
     * The target drop action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   252
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   253
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   254
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   255
    private int     targetActions    = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   256
90ce3da70b43 Initial load
duke
parents:
diff changeset
   257
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   258
     * The user drop action.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   259
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   260
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   261
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   262
    private int     dropAction       = DnDConstants.ACTION_NONE;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   263
90ce3da70b43 Initial load
duke
parents:
diff changeset
   264
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   265
     * The state of the input device modifiers associated with the user
90ce3da70b43 Initial load
duke
parents:
diff changeset
   266
     * gesture.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   267
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   268
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   269
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   270
    private int     gestureModifiers = 0;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   271
90ce3da70b43 Initial load
duke
parents:
diff changeset
   272
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   273
     * Indicates whether the <code>gestureModifiers</code> are invalid.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   274
     *
90ce3da70b43 Initial load
duke
parents:
diff changeset
   275
     * @serial
90ce3da70b43 Initial load
duke
parents:
diff changeset
   276
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   277
    private boolean invalidModifiers;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   278
90ce3da70b43 Initial load
duke
parents:
diff changeset
   279
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   280
     * Sets new modifiers by the old ones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   281
     * The mouse modifiers have higher priority than overlaying key
90ce3da70b43 Initial load
duke
parents:
diff changeset
   282
     * modifiers.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   283
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   284
    private void setNewModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   285
        if ((gestureModifiers & InputEvent.BUTTON1_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   286
            gestureModifiers |= InputEvent.BUTTON1_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   287
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   288
        if ((gestureModifiers & InputEvent.BUTTON2_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   289
            gestureModifiers |= InputEvent.BUTTON2_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   290
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   291
        if ((gestureModifiers & InputEvent.BUTTON3_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   292
            gestureModifiers |= InputEvent.BUTTON3_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   293
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   294
        if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   295
            gestureModifiers |= InputEvent.SHIFT_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   296
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   297
        if ((gestureModifiers & InputEvent.CTRL_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   298
            gestureModifiers |= InputEvent.CTRL_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   299
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   300
        if ((gestureModifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   301
            gestureModifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   302
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   303
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   304
90ce3da70b43 Initial load
duke
parents:
diff changeset
   305
    /**
90ce3da70b43 Initial load
duke
parents:
diff changeset
   306
     * Sets old modifiers by the new ones.
90ce3da70b43 Initial load
duke
parents:
diff changeset
   307
     */
90ce3da70b43 Initial load
duke
parents:
diff changeset
   308
    private void setOldModifiers() {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   309
        if ((gestureModifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   310
            gestureModifiers |= InputEvent.BUTTON1_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   311
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   312
        if ((gestureModifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   313
            gestureModifiers |= InputEvent.BUTTON2_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   314
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   315
        if ((gestureModifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   316
            gestureModifiers |= InputEvent.BUTTON3_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   317
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   318
        if ((gestureModifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   319
            gestureModifiers |= InputEvent.SHIFT_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   320
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   321
        if ((gestureModifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   322
            gestureModifiers |= InputEvent.CTRL_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   323
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   324
        if ((gestureModifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
90ce3da70b43 Initial load
duke
parents:
diff changeset
   325
            gestureModifiers |= InputEvent.ALT_GRAPH_MASK;
90ce3da70b43 Initial load
duke
parents:
diff changeset
   326
        }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   327
    }
90ce3da70b43 Initial load
duke
parents:
diff changeset
   328
}