Java Code Examples for java.awt.event.InputEvent#BUTTON3_MASK

The following examples show how to use java.awt.event.InputEvent#BUTTON3_MASK . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: Robot.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 2
Source File: DragSourceDragEvent.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets new modifiers by the old ones.
 * The mouse modifiers have higher priority than overlaying key
 * modifiers.
 */
private void setNewModifiers() {
    if ((gestureModifiers & InputEvent.BUTTON1_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON1_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON2_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON2_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON3_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON3_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) {
        gestureModifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.CTRL_MASK) != 0) {
        gestureModifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        gestureModifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
    }
}
 
Example 3
Source File: Robot.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 4
Source File: DragSourceDragEvent.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets old modifiers by the new ones.
 */
private void setOldModifiers() {
    if ((gestureModifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON1_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON2_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON3_MASK;
    }
    if ((gestureModifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.SHIFT_MASK;
    }
    if ((gestureModifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.CTRL_MASK;
    }
    if ((gestureModifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.ALT_GRAPH_MASK;
    }
}
 
Example 5
Source File: DragSourceDragEvent.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets new modifiers by the old ones.
 * The mouse modifiers have higher priority than overlaying key
 * modifiers.
 */
private void setNewModifiers() {
    if ((gestureModifiers & InputEvent.BUTTON1_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON1_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON2_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON2_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON3_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON3_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) {
        gestureModifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.CTRL_MASK) != 0) {
        gestureModifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        gestureModifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
    }
}
 
Example 6
Source File: Util.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Drags from one point to another with the specified mouse button pressed.
 *
 * @param robot a robot to use for moving the mouse, etc.
 * @param startPoint a start point of the drag
 * @param endPoint an end point of the drag
 * @param button one of {@code InputEvent.BUTTON1_MASK},
 *     {@code InputEvent.BUTTON2_MASK}, {@code InputEvent.BUTTON3_MASK}
 *
 * @throws IllegalArgumentException if {@code button} is not one of
 *     {@code InputEvent.BUTTON1_MASK}, {@code InputEvent.BUTTON2_MASK},
 *     {@code InputEvent.BUTTON3_MASK}
 */
public static void drag(Robot robot, Point startPoint, Point endPoint, int button) {
    if (!(button == InputEvent.BUTTON1_MASK || button == InputEvent.BUTTON2_MASK
            || button == InputEvent.BUTTON3_MASK))
    {
        throw new IllegalArgumentException("invalid mouse button");
    }

    robot.mouseMove(startPoint.x, startPoint.y);
    robot.mousePress(button);
    try {
        mouseMove(robot, startPoint, endPoint);
    } finally {
        robot.mouseRelease(button);
    }
}
 
Example 7
Source File: DragSourceDragEvent.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets old modifiers by the new ones.
 */
private void setOldModifiers() {
    if ((gestureModifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON1_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON2_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON3_MASK;
    }
    if ((gestureModifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.SHIFT_MASK;
    }
    if ((gestureModifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.CTRL_MASK;
    }
    if ((gestureModifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.ALT_GRAPH_MASK;
    }
}
 
Example 8
Source File: DragSourceDragEvent.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets new modifiers by the old ones.
 * The mouse modifiers have higher priority than overlaying key
 * modifiers.
 */
private void setNewModifiers() {
    if ((gestureModifiers & InputEvent.BUTTON1_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON1_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON2_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON2_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON3_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON3_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) {
        gestureModifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.CTRL_MASK) != 0) {
        gestureModifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        gestureModifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
    }
}
 
Example 9
Source File: DragSourceDragEvent.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets old modifiers by the new ones.
 */
private void setOldModifiers() {
    if ((gestureModifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON1_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON2_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON3_MASK;
    }
    if ((gestureModifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.SHIFT_MASK;
    }
    if ((gestureModifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.CTRL_MASK;
    }
    if ((gestureModifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.ALT_GRAPH_MASK;
    }
}
 
Example 10
Source File: DragSourceDragEvent.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
/**
 * Sets old modifiers by the new ones.
 */
private void setOldModifiers() {
    if ((gestureModifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON1_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON2_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON3_MASK;
    }
    if ((gestureModifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.SHIFT_MASK;
    }
    if ((gestureModifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.CTRL_MASK;
    }
    if ((gestureModifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
        gestureModifiers |= InputEvent.ALT_GRAPH_MASK;
    }
}
 
Example 11
Source File: DragSourceDragEvent.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Sets new modifiers by the old ones.
 * The mouse modifiers have higher priority than overlaying key
 * modifiers.
 */
private void setNewModifiers() {
    if ((gestureModifiers & InputEvent.BUTTON1_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON1_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON2_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON2_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON3_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON3_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) {
        gestureModifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.CTRL_MASK) != 0) {
        gestureModifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        gestureModifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
    }
}
 
Example 12
Source File: Robot.java    From openjdk-jdk9 with GNU General Public License v2.0 6 votes vote down vote up
@SuppressWarnings("deprecation")
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 13
Source File: RobotDevice.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
@Override
public void click(Component component, Buttons button, int clickCount, int xoffset, int yoffset) {
    ensureVisible(component, new Rectangle(xoffset, yoffset, 50, 50));
    int b = InputEvent.BUTTON1_MASK;
    if (button.getButton() == 0) {
        b = InputEvent.BUTTON1_MASK;
    } else if (button.getButton() == 1) {
        b = InputEvent.BUTTON2_MASK;
    } else if (button.getButton() == 2) {
        b = InputEvent.BUTTON3_MASK;
    }
    Point compLocation = component.getLocationOnScreen();
    int x = compLocation.x + xoffset;
    int y = compLocation.y + yoffset;
    robotXmouseMove(x, y);
    for (int i = 0; i < clickCount; i++) {
        robotXmousePress(b);
        robotXmouseRelease(b);
    }
}
 
Example 14
Source File: Robot.java    From jdk8u_jdk with GNU General Public License v2.0 6 votes vote down vote up
private static synchronized void initLegalButtonMask() {
    if (LEGAL_BUTTON_MASK != 0) return;

    int tmpMask = 0;
    if (Toolkit.getDefaultToolkit().areExtraMouseButtonsEnabled()){
        if (Toolkit.getDefaultToolkit() instanceof SunToolkit) {
            final int buttonsNumber = ((SunToolkit)(Toolkit.getDefaultToolkit())).getNumberOfButtons();
            for (int i = 0; i < buttonsNumber; i++){
                tmpMask |= InputEvent.getMaskForButton(i+1);
            }
        }
    }
    tmpMask |= InputEvent.BUTTON1_MASK|
        InputEvent.BUTTON2_MASK|
        InputEvent.BUTTON3_MASK|
        InputEvent.BUTTON1_DOWN_MASK|
        InputEvent.BUTTON2_DOWN_MASK|
        InputEvent.BUTTON3_DOWN_MASK;
    LEGAL_BUTTON_MASK = tmpMask;
}
 
Example 15
Source File: DragSourceDragEvent.java    From jdk-1.7-annotated with Apache License 2.0 6 votes vote down vote up
/**
 * Sets new modifiers by the old ones.
 * The mouse modifiers have higher priority than overlaying key
 * modifiers.
 */
private void setNewModifiers() {
    if ((gestureModifiers & InputEvent.BUTTON1_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON1_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON2_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON2_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.BUTTON3_MASK) != 0) {
        gestureModifiers |= InputEvent.BUTTON3_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.SHIFT_MASK) != 0) {
        gestureModifiers |= InputEvent.SHIFT_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.CTRL_MASK) != 0) {
        gestureModifiers |= InputEvent.CTRL_DOWN_MASK;
    }
    if ((gestureModifiers & InputEvent.ALT_GRAPH_MASK) != 0) {
        gestureModifiers |= InputEvent.ALT_GRAPH_DOWN_MASK;
    }
}
 
Example 16
Source File: DragGestureAdapter.java    From ghidra with Apache License 2.0 5 votes vote down vote up
/**
	 * A <code>DragGestureRecognizer</code> has detected a 
	 * platform-dependent Drag and Drop action initiating gesture
	 * and is notifying this Listener in order for it to initiate
	 * the action for the user.
	 * <p>The <code>DragGestureRecognizer</code> hides the platform-specific
	 * events that initate a drag and drop operation.
	 * 
	 * @param e event describing the gesture that has just occurred
	 */
    public void dragGestureRecognized(DragGestureEvent e) {

        // check input event: if any button other than MB1 is pressed,
        // don't attempt to process the drag and drop event.
        InputEvent ie = e.getTriggerEvent();
        int modifiers = ie.getModifiers();
        if ((modifiers & InputEvent.BUTTON2_MASK) != 0 ||
            (modifiers & InputEvent.BUTTON3_MASK) != 0) {
            return;
        }
        int dragAction = dragComponent.getDragAction();
        
        if ( ((e.getDragAction() & dragAction) == 0) || 
            !dragComponent.isStartDragOk(e)) {
            return;
        }
        
        Transferable t = dragComponent.getTransferable(e.getDragOrigin());
        
        DragSourceListener l = dragComponent.getDragSourceListener();
        if (t == null || l == null) {
            return;
        }
//        transferable = t;
        try {
            e.startDrag(DragSource.DefaultCopyNoDrop, t, l);
        } catch (InvalidDnDOperationException exc) {
            // the Drag and Drop system is unable to initiate a drag operation
            Msg.error(this, "Exception occurred during drag initiation: " + exc, exc);

            //            transferable = null;
        }
    }
 
Example 17
Source File: ContextMenuMouseListener.java    From aurous-app with GNU General Public License v2.0 5 votes vote down vote up
@Override
public void mouseClicked(final MouseEvent e) {
	if (e.getModifiers() == InputEvent.BUTTON3_MASK) {
		if (!(e.getSource() instanceof JTextComponent)) {
			return;
		}

		this.textComponent = (JTextComponent) e.getSource();
		this.textComponent.requestFocus();

		final boolean enabled = this.textComponent.isEnabled();
		final boolean editable = this.textComponent.isEditable();
		final boolean nonempty = !((this.textComponent.getText() == null) || this.textComponent
				.getText().equals(""));
		final boolean marked = this.textComponent.getSelectedText() != null;

		final boolean pasteAvailable = Toolkit.getDefaultToolkit()
				.getSystemClipboard().getContents(null)
				.isDataFlavorSupported(DataFlavor.stringFlavor);

		this.undoAction
		.setEnabled(enabled
				&& editable
				&& ((this.lastActionSelected == Actions.CUT) || (this.lastActionSelected == Actions.PASTE)));
		this.cutAction.setEnabled(enabled && editable && marked);
		this.copyAction.setEnabled(enabled && marked);
		this.pasteAction.setEnabled(enabled && editable && pasteAvailable);
		this.selectAllAction.setEnabled(enabled && nonempty);

		int nx = e.getX();

		if (nx > 500) {
			nx = nx - this.popup.getSize().width;
		}

		this.popup.show(e.getComponent(), nx,
				e.getY() - this.popup.getSize().height);
	}
}
 
Example 18
Source File: EditablePlot.java    From OpenDA with GNU Lesser General Public License v3.0 4 votes vote down vote up
public void mouseReleased(MouseEvent event) {
    if ((event.getModifiers() & InputEvent.BUTTON3_MASK)!= 0) {
        EditablePlot.this._edit(event.getX(), event.getY());
    }
}
 
Example 19
Source File: StringUtils.java    From xyTalk-pc with GNU Affero General Public License v3.0 4 votes vote down vote up
public static String keyStroke2String(KeyStroke key) {
StringBuilder s = new StringBuilder(50);
int m = key.getModifiers();

if ((m & (InputEvent.SHIFT_DOWN_MASK | InputEvent.SHIFT_MASK)) != 0) {
    s.append("shift ");
}
if ((m & (InputEvent.CTRL_DOWN_MASK | InputEvent.CTRL_MASK)) != 0) {
    s.append("ctrl ");
}
if ((m & (InputEvent.META_DOWN_MASK | InputEvent.META_MASK)) != 0) {
    s.append("meta ");
}
if ((m & (InputEvent.ALT_DOWN_MASK | InputEvent.ALT_MASK)) != 0) {
    s.append("alt ");
}
if ((m & (InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK)) != 0) {
    s.append("button1 ");
}
if ((m & (InputEvent.BUTTON2_DOWN_MASK | InputEvent.BUTTON2_MASK)) != 0) {
    s.append("button2 ");
}
if ((m & (InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK)) != 0) {
    s.append("button3 ");
}

switch (key.getKeyEventType()) {
case KeyEvent.KEY_TYPED:
    s.append("typed ");
    s.append(key.getKeyChar()).append(" ");
    break;
case KeyEvent.KEY_PRESSED:
    s.append("pressed ");
    s.append(getKeyText(key.getKeyCode())).append(" ");
    break;
case KeyEvent.KEY_RELEASED:
    s.append("released ");
    s.append(getKeyText(key.getKeyCode())).append(" ");
    break;
default:
    s.append("unknown-event-type ");
    break;
}

return s.toString();
   }
 
Example 20
Source File: bug7146377.java    From openjdk-8-source with GNU General Public License v2.0 4 votes vote down vote up
private static boolean oldIsRightMouseButton(MouseEvent e) {
    return ((e.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK);
}