Java Swing Mouse mapDragOperationFromModifiers(MouseEvent me, TransferHandler th)

Here you can find the source of mapDragOperationFromModifiers(MouseEvent me, TransferHandler th)

Description

map Drag Operation From Modifiers

License

Open Source License

Declaration

public static int mapDragOperationFromModifiers(MouseEvent me,
            TransferHandler th) 

Method Source Code

//package com.java2s;
/*/*from w w  w  .  j a  v a  2  s.com*/
 * @(#)QuaquaUtilities.java  
 *
 * Copyright (c) 2003-2010 Werner Randelshofer, Immensee, Switzerland.
 * All rights reserved.
 *
 * You may not use, copy or modify this file, except in compliance with the
 * license agreement you entered into with Werner Randelshofer.
 * For details see accompanying license terms.
 */

import java.awt.dnd.DnDConstants;

import java.awt.event.*;

import javax.swing.*;

public class Main {
    public static int mapDragOperationFromModifiers(MouseEvent me,
            TransferHandler th) {
        return convertModifiersToDropAction(me.getModifiersEx(),
                th.getSourceActions((JComponent) me.getSource()));
    }

    public static int convertModifiersToDropAction(final int modifiers,
            final int supportedActions) {
        int dropAction = DnDConstants.ACTION_NONE;

        /*
         * Fix for 4285634.
         * Calculate the drop action to match Motif DnD behavior.
         * If the user selects an operation (by pressing a modifier key),
         * return the selected operation or ACTION_NONE if the selected
         * operation is not supported by the drag source.
         * If the user doesn't select an operation search the set of operations
         * supported by the drag source for ACTION_MOVE, then for
         * ACTION_COPY, then for ACTION_LINK and return the first operation
         * found.
         */
        switch (modifiers
                & (InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK)) {
        case InputEvent.SHIFT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK:
            dropAction = DnDConstants.ACTION_LINK;
            break;
        case InputEvent.CTRL_DOWN_MASK:
            dropAction = DnDConstants.ACTION_COPY;
            break;
        case InputEvent.SHIFT_DOWN_MASK:
            dropAction = DnDConstants.ACTION_MOVE;
            break;
        default:
            if ((supportedActions & DnDConstants.ACTION_MOVE) != 0) {
                dropAction = DnDConstants.ACTION_MOVE;
            } else if ((supportedActions & DnDConstants.ACTION_COPY) != 0) {
                dropAction = DnDConstants.ACTION_COPY;
            } else if ((supportedActions & DnDConstants.ACTION_LINK) != 0) {
                dropAction = DnDConstants.ACTION_LINK;
            }
        }

        return dropAction & supportedActions;
    }
}

Related

  1. isLeftMouseButton(MouseEvent anEvent)
  2. isLeftMouseButton(MouseEvent e)
  3. isPopupTrigger(final MouseEvent e)
  4. isPrimaryMouseButton(MouseEvent e)
  5. makeMouseOverBorder(final JComponent b)
  6. paintBandTitle(Graphics g, Rectangle titleRectangle, String title, boolean isUnderMouse, boolean hasExpandIcon)
  7. parentMouseEvent(JComponent c, MouseEvent m)
  8. passBehind(MouseEvent e)
  9. propagate(MouseEvent e, Component c)