Java Code Examples for java.awt.event.InputEvent.BUTTON1_MASK

The following are Jave code examples for showing how to use BUTTON1_MASK of the java.awt.event.InputEvent class. You can vote up the examples you like. Your votes will be used in our system to get more good examples.
+ Save this method
Example 1
Project: marathonv5   File: RobotDevice.java   View Source Code Vote up 7 votes
@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 2
Project: incubator-netbeans   File: BaseCaretTest.java   View Source Code Vote up 6 votes
/**
 * Folded region is double-clicked; it should be unfolded, rather than word-selected.
 */
public void testSelectFoldedRegion() throws Exception {
    env.getHierarchy().collapse(fold);
    Thread.sleep(300);
    Rectangle r = pane.modelToView(10);
    
    // 1st mouseclick on the pane, to position the caret, as if the 1st click in doubleclick was done:
    MouseEvent firstPress = new MouseEvent(pane, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 
            InputEvent.BUTTON1_MASK, r.x, r.y, 1, false);
    processEvent(firstPress);
    
    // second press of the doubleclick
    MouseEvent secondPress = new MouseEvent(pane, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), 
            InputEvent.BUTTON1_MASK, r.x, r.y, 2, false);
    processEvent(secondPress);
    
    // check that no selection is present:
    assertFalse(selectWordCalled);
    assertNull(pane.getSelectedText());
    // check that even the callable did the job:
    assertFalse(fold.isCollapsed());
}
 
Example 3
Project: openjdk-jdk10   File: Robot.java   View Source Code Vote up 6 votes
@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 4
Project: openjdk-jdk10   File: DragSourceDragEvent.java   View Source Code Vote up 6 votes
/**
 * Sets new modifiers by the old ones.
 * The mouse modifiers have higher priority than overlaying key
 * modifiers.
 */
@SuppressWarnings("deprecation")
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 5
Project: jdk8u-jdk   File: Util.java   View Source Code Vote up 6 votes
/**
 * 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 6
Project: openjdk-jdk10   File: Util.java   View Source Code Vote up 6 votes
/**
 * 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
Project: jdk8u-jdk   File: Robot.java   View Source Code Vote up 6 votes
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 8
Project: openjdk-jdk10   File: MouseModifiersInKeyEvent.java   View Source Code Vote up 6 votes
private static void test(final int mask) throws Exception {
    final Robot r = new Robot();
    r.setAutoDelay(100);
    r.setAutoWaitForIdle(true);

    EventQueue.invokeAndWait(MouseModifiersInKeyEvent::createAndShowGUI);
    r.waitForIdle();
    EventQueue.invokeAndWait(() -> bounds = f.getBounds());

    r.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);
    r.mousePress(mask);
    r.keyPress(KeyEvent.VK_A);
    r.keyRelease(KeyEvent.VK_A);

    EventQueue.invokeAndWait(() -> f.dispose());

    r.mouseRelease(mask);

    // all extended modifiers should work
    if (modifiersEX != mask) {
        System.err.println("Expected modifiersEX: " + mask);
        System.err.println("Actual modifiersEX: " + modifiersEX);
        throw new RuntimeException();
    }
    // old modifiers work only for button1
    if (modifiersEX == InputEvent.BUTTON1_DOWN_MASK) {
        if (modifiers != InputEvent.BUTTON1_MASK) {
            System.err.println("Expected modifiers: " + InputEvent.BUTTON1_MASK);
            System.err.println("Actual modifiers: " + modifiers);
            throw new RuntimeException();
        }
    }
    modifiersEX = 0;
    modifiers = 0;
}
 
Example 9
Project: OpenJSharp   File: DragSourceDragEvent.java   View Source Code Vote up 6 votes
/**
 * 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 10
Project: OpenJSharp   File: DragSourceDragEvent.java   View Source Code Vote up 6 votes
/**
 * 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
Project: OpenJSharp   File: Robot.java   View Source Code Vote up 6 votes
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 12
Project: Yass   File: FileChooserFixer.java   View Source Code Vote up 6 votes
/**
 *  Description of the Method
 *
 * @param  evt  Description of the Parameter
 */
public void mousePressed(MouseEvent evt) {
	Object src = evt.getSource();

	if (src == fileList) {
		if (evt.getModifiers() != InputEvent.BUTTON1_MASK) {
			return;
		}

		int index = fileList.locationToIndex(evt.getPoint());
		if (index < 0) {
			return;
		}
		fileList.setSelectedIndex(index);
		File[] arr = getSelectedFiles();

		if (evt.getClickCount() == 1 && arr.length == 1 && arr[0].isDirectory()) {
			fileChooser.setCurrentDirectory(arr[0]);
			filenameTextField.setText("");
		}
	}
}
 
Example 13
Project: marathonv5   File: EventQueueDevice.java   View Source Code Vote up 5 votes
private void dispatchMouseEvent(Component component, boolean popupTrigger, int clickCount, int buttons, int x, int y) {
    ensureVisible(component, new Rectangle(x, y, 50, 50));
    EventQueueWait.call_noexc(component, "requestFocusInWindow");
    int modifierEx = deviceState.getModifierEx();
    if (component != deviceState.getComponent()) {
        if (deviceState.getComponent() != null) {
            dispatchEvent(new MouseEvent(deviceState.getComponent(), MouseEvent.MOUSE_EXITED, System.currentTimeMillis(),
                    modifierEx, deviceState.x, deviceState.y, 0, popupTrigger, buttons));
        }
        dispatchEvent(new MouseEvent(component, MouseEvent.MOUSE_ENTERED, System.currentTimeMillis(), modifierEx, x, y, 0,
                popupTrigger, buttons));
    }
    for (int n = 1; n <= clickCount; n++) {
        int buttonMask = InputEvent.BUTTON1_DOWN_MASK | InputEvent.BUTTON1_MASK;
        if (buttons == 3) {
            buttonMask = InputEvent.BUTTON3_DOWN_MASK | InputEvent.BUTTON3_MASK;
        }
        dispatchEvent(new MouseEvent(component, MouseEvent.MOUSE_PRESSED, System.currentTimeMillis(), modifierEx | buttonMask,
                x, y, n, popupTrigger, buttons));
        buttonMask = InputEvent.BUTTON1_MASK;
        if (buttons == 3) {
            buttonMask = InputEvent.BUTTON3_MASK;
        }
        dispatchEvent(new MouseEvent(component, MouseEvent.MOUSE_RELEASED, System.currentTimeMillis(), modifierEx | buttonMask,
                x, y, n, false, buttons));
        dispatchEvent(new MouseEvent(component, MouseEvent.MOUSE_CLICKED, System.currentTimeMillis(), modifierEx | buttonMask,
                x, y, n, false, buttons));
    }
}
 
Example 14
Project: clickbot   File: Bot.java   View Source Code Vote up 5 votes
Bot(int numberOfLocations, int timeDelay) {
    try {
        clickBot = new Robot();
    } catch (Exception excp) {
        System.out.println("Failed instantiating Robot: " + excp);
    }
    mask = InputEvent.BUTTON1_MASK;
    clicks = 0;
    _numberOfLocations = numberOfLocations;
    _timeDelay = timeDelay;
    location = new int[numberOfLocations][];
}
 
Example 15
Project: ramus   File: Handler.java   View Source Code Vote up 5 votes
@Override
public void mouseReleased(final MouseEvent me) {
    if (!ourToolBarIsDragging)
        return;

    if ((me.getModifiers() & InputEvent.BUTTON1_MASK) != InputEvent.BUTTON1_MASK) {
        return;
    }

    hideDraggingWindow();

    final Container target = ourDockLayout.getTargetContainer();
    if (target == null)
        return;

    Point p = me.getPoint();
    p = SwingUtilities.convertPoint(ourToolBar, p, target);

    DockBoundary dock = null;

    if (!me.isControlDown()) {
        dock = getDockableBoundary(p);
        if (dock != null) {
            setDockIndex(dock.getDockIndex(p));
            setRowIndex(dock.getRowIndex(p));
            setDockEdge(dock.getEdge());
        }
    }

    if (dock != null) {
        dockToolBar(getDockEdge(), getRowIndex(), getDockIndex());
    } else {
        SwingUtilities.convertPointToScreen(p, target);
        floatToolBar(p.x, p.y, true);
    }

}
 
Example 16
Project: openjdk-jdk10   File: EventDispatcher.java   View Source Code Vote up 5 votes
/**
 * Returns a mouse button string representation. Used to print trace.
 *
 * @param button Mouse button ({@code InputEvent.BUTTON1/2/3_MASK}
 * value).
 * @return InputEvent field name.
 */
public static String getMouseButtonDescription(int button) {
    String result;
    if ((button & InputEvent.BUTTON1_MASK) != 0) {
        result = "BUTTON1";
    } else if ((button & InputEvent.BUTTON2_MASK) != 0) {
        result = "BUTTON2";
    } else if ((button & InputEvent.BUTTON3_MASK) != 0) {
        result = "BUTTON3";
    } else {
        result = "UNKNOWN_BUTTON";
    }
    return result;
}
 
Example 17
Project: incubator-netbeans   File: SortableTableModel.java   View Source Code Vote up 4 votes
public void mousePressed(MouseEvent e) {
    if ((e.getModifiers() == InputEvent.BUTTON1_MASK) && (tableHeader.getResizingColumn() == null)) {
        headerRenderer.setPressedColumn(tableHeader.columnAtPoint(e.getPoint()));
        tableHeader.repaint();
    }
}
 
Example 18
Project: ramus   File: Handler.java   View Source Code Vote up 4 votes
@Override
public void mouseDragged(final MouseEvent me) {
    ourDraggingWindow = getDraggingWindow();
    if (ourDraggingWindow == null)
        return;

    // Only allow Button 1 to perform the drag...
    if ((me.getModifiers() & InputEvent.BUTTON1_MASK) != InputEvent.BUTTON1_MASK) {
        hideDraggingWindow();
        return;
    }

    final Container target = ourDockLayout.getTargetContainer();
    if (target == null)
        return;

    Point p = me.getPoint();
    p = SwingUtilities.convertPoint(ourToolBar, p, target);

    // Make sure the DockBoundary containing this point
    // and this toolbar wishes to allow the drag operation
    // to commence or continue...
    if (!isDraggable(p, ourToolBar)) {
        hideDraggingWindow();
        return;
    }

    // Determine if this point lies within a
    // DockBoundary's dockable range...
    int orient = ToolBarLayout.HORIZONTAL;
    boolean dockable = false;

    if (!me.isControlDown()) {
        final DockBoundary dock = getDockableBoundary(p);

        if (dock != null) {
            dockable = true;
            orient = dock.getOrientation();
        }
    }

    // Present the dragging window at this point on the screen...
    SwingUtilities.convertPointToScreen(p, target);
    ourDraggingWindow.presentWindow(p, dockable, orient);
    ourToolBarIsDragging = true;

}
 
Example 19
Project: WordnetLoom   File: ViwnGraphViewModalGraphMouse.java   View Source Code Vote up 4 votes
public ViwnPickingGraphMousePlugin() {
    super(InputEvent.BUTTON1_MASK, InputEvent.BUTTON1_MASK | InputEvent.CTRL_MASK);
    cursor = Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR);
}
 
Example 20
Project: openjdk-jdk10   File: Operator.java   View Source Code Vote up 2 votes
/**
 * Returns default mouse button mask.
 *
 * @return {@code InputEvent.BUTTON*_MASK} field value
 */
public static int getDefaultMouseButton() {
    return InputEvent.BUTTON1_MASK;
}