java.awt.event.InputEvent Java Examples

The following examples show how to use java.awt.event.InputEvent. 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: AWTKeyStroke.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
private static int mapNewModifiers(int modifiers) {
    if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0) {
        modifiers |= InputEvent.SHIFT_MASK;
    }
    if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0) {
        modifiers |= InputEvent.ALT_MASK;
    }
    if ((modifiers & InputEvent.ALT_GRAPH_DOWN_MASK) != 0) {
        modifiers |= InputEvent.ALT_GRAPH_MASK;
    }
    if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0) {
        modifiers |= InputEvent.CTRL_MASK;
    }
    if ((modifiers & InputEvent.META_DOWN_MASK) != 0) {
        modifiers |= InputEvent.META_MASK;
    }

    return modifiers;
}
 
Example #2
Source File: RemovedComponentMouseListener.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        new RemovedComponentMouseListener();
    });

    Robot r = Util.createRobot();
    r.setAutoDelay(100);
    r.waitForIdle();
    Util.pointOnComp(button, r);

    r.waitForIdle();
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.waitForIdle();
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.waitForIdle();
    if (!mouseReleasedReceived) {
        throw new RuntimeException("mouseReleased event was not received");
    }
}
 
Example #3
Source File: RemovedComponentMouseListener.java    From dragonwell8_jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        new RemovedComponentMouseListener();
    });

    Robot r = Util.createRobot();
    r.setAutoDelay(100);
    r.waitForIdle();
    Util.pointOnComp(button, r);

    r.waitForIdle();
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.waitForIdle();
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.waitForIdle();
    if (!mouseReleasedReceived) {
        throw new RuntimeException("mouseReleased event was not received");
    }
}
 
Example #4
Source File: SlowPanelIteration.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) throws Exception {
    Robot r = new Robot();
    // accessibility tool will need time to react to our clicks
    r.setAutoDelay(200);
    try {
        EventQueue.invokeAndWait(SlowPanelIteration::showUI);
        for (int i = 0; i < 10; ++i) {
            go = new CountDownLatch(1);
            r.mouseMove(center.x, center.y);
            r.mousePress(InputEvent.BUTTON1_DOWN_MASK);
            r.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
            if (!go.await(10, TimeUnit.SECONDS)) {
                throw new RuntimeException("Too slow operation");
            }
        }
    } finally {
        EventQueue.invokeAndWait(SlowPanelIteration::dispose);
    }
}
 
Example #5
Source File: SortableTableModel.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void mouseClicked(MouseEvent e) {
    if (e.getModifiers() == InputEvent.BUTTON1_MASK) {
        int column = tableHeader.columnAtPoint(e.getPoint());
        int sortingColumn = headerRenderer.getSortingColumn();

        if (column == sortingColumn) {
            headerRenderer.reverseSortingOrder();
        } else {
            headerRenderer.setSortingColumn(column);

            if (getInitialSorting(column)) {
                headerRenderer.setSortingOrder(SORT_ORDER_ASC); // Default sort order for strings is Ascending
            } else {
                headerRenderer.setSortingOrder(SORT_ORDER_DESC); // Default sort order for numbers is Descending
            }
        }

        tableHeader.repaint();

        sortByColumn(column, headerRenderer.getSortingOrder());
    }
}
 
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: bug6800513.java    From openjdk-jdk8u with GNU General Public License v2.0 6 votes vote down vote up
public static void clickOnMenu() throws Exception {
    Rectangle bounds = Util.invokeOnEDT(new Callable<Rectangle>() {
        @Override
        public Rectangle call() throws Exception {
            return new Rectangle(menu.getLocationOnScreen(), menu.getSize());
        }
    });

    Robot robot = new Robot();
    robot.setAutoDelay(100);

    robot.mouseMove(bounds.x + bounds.width / 2, bounds.y + bounds.height / 2);

    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
 
Example #8
Source File: TestJQuery.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testCCMethod() {
    startTest();
    EditorOperator eo = new EditorOperator("test.js");
    cleanFile(eo);
    type(eo, "\n\n");
    eo.setCaretPositionToLine(1);
    type(eo, "$(\"\").b");

    eo.typeKey(' ', InputEvent.CTRL_MASK);
    evt.waitNoEvent(100);

    CompletionInfo completion = getCompletion();
    String[] res = {"before", "bind", "blur"};
    CompletionJListOperator cjo = completion.listItself;
    checkCompletionItems(cjo, res);
    String[] res2 = {"add"};
    checkCompletionDoesntContainItems(cjo, res2);
    completion.listItself.hideAll();

    endTest();
}
 
Example #9
Source File: DisposeFrameOnDragTest.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Throwable {

        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                constructTestUI();
            }
        });

        Util.waitForIdle(null);
        try {
            Point loc = textArea.getLocationOnScreen();
            Util.drag(new Robot(),
                    new Point((int) loc.x + 3, (int) loc.y + 3),
                    new Point((int) loc.x + 40, (int) loc.y + 40),
                    InputEvent.BUTTON1_MASK);
        } catch (AWTException ex) {
            throw new RuntimeException("Could not initiate a drag operation");
        }
        Util.waitForIdle(null);
    }
 
Example #10
Source File: DragSourceDragEvent.java    From openjdk-jdk8u 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 #11
Source File: XEmbedHelper.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Converts XEMBED modifiers mask into AWT InputEvent mask
     */
    int getModifiers(int state) {
        int mods = 0;
        if ((state & XEMBED_MODIFIER_SHIFT) != 0) {
            mods |= InputEvent.SHIFT_DOWN_MASK;
        }
        if ((state & XEMBED_MODIFIER_CONTROL) != 0) {
            mods |= InputEvent.CTRL_DOWN_MASK;
        }
        if ((state & XEMBED_MODIFIER_ALT) != 0) {
            mods |= InputEvent.ALT_DOWN_MASK;
        }
        // FIXME: What is super/hyper?
        // FIXME: Experiments show that SUPER is ALT. So what is Alt then?
        if ((state & XEMBED_MODIFIER_SUPER) != 0) {
            mods |= InputEvent.ALT_DOWN_MASK;
        }
//         if ((state & XEMBED_MODIFIER_HYPER) != 0) {
//             mods |= InputEvent.DOWN_MASK;
//         }
        return mods;
    }
 
Example #12
Source File: URIListBetweenJVMsTest.java    From openjdk-8 with GNU General Public License v2.0 6 votes vote down vote up
public URIListBetweenJVMsTest (Point targetFrameLocation, Point dragSourcePoint,
        int transferredFilesNumber)
        throws InterruptedException
{
    TargetFileListFrame targetFrame = new TargetFileListFrame(targetFrameLocation,
            transferredFilesNumber);

    Util.waitForIdle(null);

    final Robot robot = Util.createRobot();

    robot.mouseMove((int)dragSourcePoint.getX(),(int)dragSourcePoint.getY());
    sleep(100);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    sleep(100);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    sleep(100);

    Util.drag(robot, dragSourcePoint, targetFrame.getDropTargetPoint(),
            InputEvent.BUTTON1_MASK);

}
 
Example #13
Source File: Robot.java    From jdk1.8-source-analysis with Apache License 2.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 #14
Source File: CPlatformResponder.java    From jdk8u60 with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Handles scroll events.
 */
void handleScrollEvent(final int x, final int y, final int modifierFlags,
                       final double deltaX, final double deltaY) {
    final int buttonNumber = CocoaConstants.kCGMouseButtonCenter;
    int jmodifiers = NSEvent.nsToJavaMouseModifiers(buttonNumber,
                                                    modifierFlags);
    final boolean isShift = (jmodifiers & InputEvent.SHIFT_DOWN_MASK) != 0;

    // Vertical scroll.
    if (!isShift && deltaY != 0.0) {
        dispatchScrollEvent(x, y, jmodifiers, deltaY);
    }
    // Horizontal scroll or shirt+vertical scroll.
    final double delta = isShift && deltaY != 0.0 ? deltaY : deltaX;
    if (delta != 0.0) {
        jmodifiers |= InputEvent.SHIFT_DOWN_MASK;
        dispatchScrollEvent(x, y, jmodifiers, delta);
    }
}
 
Example #15
Source File: ExpressionLangTest.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testBeansCompletionOpenBraces() {
    startTest();
    EditorOperator eo = new EditorOperator("index.jsp");
    eo.setCaretPositionToLine(18);
    type(eo, "${");
    eo.typeKey(' ', InputEvent.CTRL_MASK);
    evt.waitNoEvent(1000);
    CompletionInfo completion = getCompletion();
    CompletionJListOperator cjo = completion.listItself;
    checkCompletionItems(cjo, new String[]{"simplebean", "innerBean", "header"});
    eo.pressKey(KeyEvent.VK_ESCAPE);
    type(eo, "s");
    eo.typeKey(' ', InputEvent.CTRL_MASK);
    evt.waitNoEvent(1000);
    completion = getCompletion();
    cjo = completion.listItself;
    checkCompletionItems(cjo, new String[]{"simplebean", "Short"});
    this.clearLine(eo);
    endTest();
}
 
Example #16
Source File: XEmbedHelper.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
/**
     * Converts XEMBED modifiers mask into AWT InputEvent mask
     */
    int getModifiers(int state) {
        int mods = 0;
        if ((state & XEMBED_MODIFIER_SHIFT) != 0) {
            mods |= InputEvent.SHIFT_DOWN_MASK;
        }
        if ((state & XEMBED_MODIFIER_CONTROL) != 0) {
            mods |= InputEvent.CTRL_DOWN_MASK;
        }
        if ((state & XEMBED_MODIFIER_ALT) != 0) {
            mods |= InputEvent.ALT_DOWN_MASK;
        }
        // FIXME: What is super/hyper?
        // FIXME: Experiments show that SUPER is ALT. So what is Alt then?
        if ((state & XEMBED_MODIFIER_SUPER) != 0) {
            mods |= InputEvent.ALT_DOWN_MASK;
        }
//         if ((state & XEMBED_MODIFIER_HYPER) != 0) {
//             mods |= InputEvent.DOWN_MASK;
//         }
        return mods;
    }
 
Example #17
Source File: Keybind.java    From runelite with BSD 2-Clause "Simplified" License 6 votes vote down vote up
public static String getModifiersExText(int modifiers)
{
	StringBuilder buf = new StringBuilder();
	if ((modifiers & InputEvent.META_DOWN_MASK) != 0)
	{
		buf.append("Meta+");
	}
	if ((modifiers & InputEvent.CTRL_DOWN_MASK) != 0)
	{
		buf.append("Ctrl+");
	}
	if ((modifiers & InputEvent.ALT_DOWN_MASK) != 0)
	{
		buf.append("Alt+");
	}
	if ((modifiers & InputEvent.SHIFT_DOWN_MASK) != 0)
	{
		buf.append("Shift+");
	}

	if (buf.length() > 0)
	{
		buf.setLength(buf.length() - 1); // remove trailing '+'
	}
	return buf.toString();
}
 
Example #18
Source File: RemovedComponentMouseListener.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(() -> {
        new RemovedComponentMouseListener();
    });

    Robot r = Util.createRobot();
    r.setAutoDelay(100);
    r.waitForIdle();
    Util.pointOnComp(button, r);

    r.waitForIdle();
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.waitForIdle();
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.waitForIdle();
    if (!mouseReleasedReceived) {
        throw new RuntimeException("mouseReleased event was not received");
    }
}
 
Example #19
Source File: WMouseDragGestureRecognizer.java    From openjdk-8-source with GNU General Public License v2.0 6 votes vote down vote up
/**
 * determine the drop action from the event
 */

protected int mapDragOperationFromModifiers(MouseEvent e) {
    int mods = e.getModifiersEx();
    int btns = mods & ButtonMask;

    // Prohibit multi-button drags.
    if (!(btns == InputEvent.BUTTON1_DOWN_MASK ||
          btns == InputEvent.BUTTON2_DOWN_MASK ||
          btns == InputEvent.BUTTON3_DOWN_MASK)) {
        return DnDConstants.ACTION_NONE;
    }

    return
        SunDragSourceContextPeer.convertModifiersToDropAction(mods,
                                                              getSourceActions());
}
 
Example #20
Source File: TableSorter.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public void addMouseListenerToHeaderInTable(JTable table) {
    final TableSorter sorter = this;
    final JTable tableView = table;
    tableView.setColumnSelectionAllowed(false);
    MouseAdapter listMouseListener = new MouseAdapter() {

        @Override
        public void mouseClicked(MouseEvent e) {
            TableColumnModel columnModel = tableView.getColumnModel();
            int viewColumn = columnModel.getColumnIndexAtX(e.getX());
            int column = tableView.convertColumnIndexToModel(viewColumn);
            if (e.getClickCount() == 1 && column != -1) {
                System.out.println("Sorting ...");
                int shiftPressed = e.getModifiers() & InputEvent.SHIFT_MASK;
                boolean ascending = (shiftPressed == 0);
                sorter.sortByColumn(column, ascending);
            }
        }
    };
    JTableHeader th = tableView.getTableHeader();
    th.addMouseListener(listMouseListener);
}
 
Example #21
Source File: bug7170657.java    From jdk8u-dev-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(final String[] args) {
    final int mask = InputEvent.META_DOWN_MASK | InputEvent.CTRL_MASK;

    Frame f = new Frame();

    MouseEvent mwe = new MouseWheelEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                         1, 1, 1);
    MouseEvent mdme = new MenuDragMouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1,
                                             true, null, null);
    MouseEvent me = new MouseEvent(f, 1, 1, mask, 1, 1, 1, 1, 1, true,
                                   MouseEvent.NOBUTTON);

    test(f, mwe);
    test(f, mdme);
    test(f, me);

    if (FAILED) {
        throw new RuntimeException("Wrong mouse event");
    }
}
 
Example #22
Source File: bug6263446.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
private static void click(int times) {
    robot.delay(500);
    for (int i = 0; i < times; i++) {
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
    }
}
 
Example #23
Source File: EventQueueDevice.java    From marathonv5 with Apache License 2.0 5 votes vote down vote up
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 #24
Source File: ShortcutProvider.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public static Set<String> getSet() {
    if (shortcutSet == null) {
        shortcutSet = new LinkedHashSet<String>();

        //CTRL
        for (int i = 0; i < letters.length; i++) {
            shortcutSet.add(KeyStrokeUtils.getKeyStrokeAsText(KeyStroke.getKeyStroke(letters[i], InputEvent.CTRL_MASK)));
        }

        if (Utilities.isMac())
            //META
            for (int i = 0; i < letters.length; i++) {
                shortcutSet.add(KeyStrokeUtils.getKeyStrokeAsText(KeyStroke.getKeyStroke(letters[i], InputEvent.META_MASK)));
            }
        else
            //ALT
            for (int i = 0; i < letters.length; i++) {
                shortcutSet.add(KeyStrokeUtils.getKeyStrokeAsText(KeyStroke.getKeyStroke(letters[i], InputEvent.ALT_MASK)));
            }

        //CTRL+SHIFT
        for (int i = 0; i < letters.length; i++) {
            shortcutSet.add(KeyStrokeUtils.getKeyStrokeAsText(KeyStroke.getKeyStroke(letters[i], InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK)));

        }

        if (Utilities.isMac())
            //SHIFT+META
            for (int i = 0; i < letters.length; i++) {
                shortcutSet.add(KeyStrokeUtils.getKeyStrokeAsText(KeyStroke.getKeyStroke(letters[i], InputEvent.SHIFT_MASK | InputEvent.META_MASK)));
            }
        else
            //SHIFT+ALT
            for (int i = 0; i < letters.length; i++) {
                shortcutSet.add(KeyStrokeUtils.getKeyStrokeAsText(KeyStroke.getKeyStroke(letters[i], InputEvent.SHIFT_MASK | InputEvent.ALT_MASK)));
            }
    }
    return shortcutSet;
}
 
Example #25
Source File: MissedDragExitTest.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Throwable {
    try {

        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                initAndShowUI();
            }
        });

        Robot r = new Robot();
        Util.waitForIdle(r);
        Util.drag(r,
                new Point(FRAME_LOCATION + FRAME_SIZE / 3, FRAME_LOCATION + FRAME_SIZE / 3),
                new Point(FRAME_LOCATION + FRAME_SIZE / 3 * 2, FRAME_LOCATION + FRAME_SIZE / 3 * 2),
                InputEvent.BUTTON1_MASK);
        Util.waitForIdle(r);

        if (!dragExitCalled) {
            throw new RuntimeException("Failed. Drag exit was not called" );
        }
    } finally {
        if (f != null) {
            f.dispose();
        }
    }
}
 
Example #26
Source File: Util.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Moves mouse pointer in the center of a given {@code comp} component
 * and performs a left mouse button click using the {@code robot} parameter
 * with the {@code delay} delay between press and release.
 */
public static void clickOnComp(final Component comp, final Robot robot, int delay) {
    pointOnComp(comp, robot);
    robot.delay(delay);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.delay(delay);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
 
Example #27
Source File: ResourceBundleSupport.java    From pentaho-reporting with GNU Lesser General Public License v2.1 5 votes vote down vote up
/**
 * Returns the plattforms default menu shortcut keymask.
 *
 * @return the default key mask.
 */
private int getMenuKeyMask() {
  try {
    return Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
  } catch ( UnsupportedOperationException he ) {
    // headless exception extends UnsupportedOperation exception,
    // but the HeadlessException is not defined in older JDKs...
    return InputEvent.CTRL_MASK;
  }
}
 
Example #28
Source File: MissingDragExitEventTest.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(final String[] args) throws Exception {
    try {
        final Robot r = new Robot();
        r.setAutoDelay(50);
        r.mouseMove(100, 100);
        Util.waitForIdle(r);

        SwingUtilities.invokeAndWait(new Runnable() {
            @Override
            public void run() {
                initAndShowUI();
            }
        });

        final Point inside = new Point(frame.getLocationOnScreen());
        inside.translate(20, SIZE / 2);
        final Point outer = new Point(inside);
        outer.translate(-40, 0);
        r.mouseMove(inside.x, inside.y);
        r.mousePress(InputEvent.BUTTON1_MASK);
        try {
            for (int i = 0; i < 3; ++i) {
                Util.mouseMove(r, inside, outer);
                Util.mouseMove(r, outer, inside);
            }
        } finally {
            r.mouseRelease(InputEvent.BUTTON1_MASK);
        }
        sleep();

        if (FAILED || !MOUSE_ENTERED || !MOUSE_ENTERED_DT || !MOUSE_EXIT
                || !MOUSE_EXIT_TD) {
            throw new RuntimeException("Failed");
        }
    } finally {
        if (frame != null) {
            frame.dispose();
        }
    }
}
 
Example #29
Source File: bug4743225.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String... args) throws Exception {

        Robot robot = new Robot();
        robot.setAutoDelay(20);
        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();

        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                new bug4743225().setVisible(true);
            }
        });
        toolkit.realSync();

        // calling this method from main thread is ok
        Point point = cb.getLocationOnScreen();
        robot.mouseMove(point.x + 10, point.y + 10);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        toolkit.realSync();

        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                if(getPopup().getList().getLastVisibleIndex() == 3) {
                    flag = true;
                }
            }
        });

        if (!flag) {
            throw new RuntimeException("The ComboBox popup wasn't correctly updated");
        }
    }
 
Example #30
Source File: InstancesListControllerUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if ((e.getKeyCode() == KeyEvent.VK_CONTEXT_MENU)
            || ((e.getKeyCode() == KeyEvent.VK_F10) && (e.getModifiers() == InputEvent.SHIFT_MASK))) {
        int selectedRow = instancesListTable.getSelectedRow();

        if (selectedRow != -1) {
            Rectangle rowBounds = instancesListTable.getCellRect(selectedRow, 0, true);
            showTablePopup(instancesListTable, rowBounds.x + (rowBounds.width / 2), rowBounds.y + (rowBounds.height / 2));
        }
    } else if (KeyStroke.getAWTKeyStroke(e.getKeyCode(), e.getModifiers()).equals(COPY_ID_KEYSTROKE)) {
        copyIdToClipboard();
    }
}