Java 类java.awt.event.InputEvent 实例源码

项目:jdk8u-jdk    文件:URIListToFileListBetweenJVMsTest.java   
public URIListToFileListBetweenJVMsTest(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);

}
项目:incubator-netbeans    文件:PopupMenuAction.java   
public State keyPressed (Widget widget, WidgetKeyEvent event) {
        if (event.getKeyCode () == KeyEvent.VK_CONTEXT_MENU  ||  ((event.getModifiers () & InputEvent.SHIFT_MASK) == InputEvent.SHIFT_MASK  &&  event.getKeyCode () == KeyEvent.VK_F10)) {
            JPopupMenu popupMenu = provider.getPopupMenu (widget, null);
            if (popupMenu != null) {
                JComponent view = widget.getScene ().getView ();
                if (view != null) {
//                    Rectangle visibleRect = view.getVisibleRect ();
//                    popupMenu.show (view, visibleRect.x + 10, visibleRect.y + 10);
                    Rectangle bounds = widget.getBounds ();
                    Point location = new Point (bounds.x + 5, bounds.y + 5);
                    location = widget.convertLocalToScene (location);
                    location = widget.getScene ().convertSceneToView (location);
                    popupMenu.show (view, location.x, location.y);
                }
            }
            return State.CONSUMED;
        }
        return State.REJECTED;
    }
项目:incubator-netbeans    文件:WheelPanAction.java   
public State mouseWheelMoved (Widget widget, WidgetMouseWheelEvent event) {
    JComponent view = widget.getScene ().getView ();
    Rectangle visibleRect = view.getVisibleRect ();
    int amount = event.getWheelRotation () * 64;

    switch (event.getModifiers () & (InputEvent.SHIFT_MASK | InputEvent.CTRL_MASK | InputEvent.ALT_MASK)) {
        case InputEvent.SHIFT_MASK:
            visibleRect.x += amount;
            break;
        case 0:
            visibleRect.y += amount;
            break;
        default:
            return State.REJECTED;
    }

    view.scrollRectToVisible (visibleRect);
    return State.CONSUMED;
}
项目:jdk8u-jdk    文件:RemovedComponentMouseListener.java   
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");
    }
}
项目:VASSAL-src    文件:ADC2Module.java   
public Obscurable getPieceValueMask() throws IOException {
  if (getOwner().useHiddenPieces()) {
    SequenceEncoder se = new SequenceEncoder(';');
    se.append(new NamedKeyStroke(KeyStroke.getKeyStroke('I', InputEvent.CTRL_MASK))); // key command
    se.append(getImageName()); // hide image
    se.append("Hide Info"); // menu name
    BufferedImage image = getSymbol().getImage();
    se.append("G" + getFlagLayer(new Dimension(image.getWidth(), image.getHeight()), StateFlag.INFO)); // display style
    if (name == null)
      se.append(getName());
    else
      se.append("Unknown Piece"); // mask name
    se.append("sides:" + getOwner().getName()); // owning player
    Obscurable p = new Obscurable();
    p.mySetType(Obscurable.ID + se.getValue());
    return p;
  }
  else {
    return null;
  }
}
项目:Logisim    文件:LineTool.java   
private void updateMouse(Canvas canvas, int mx, int my, int mods) {
    if (active) {
        boolean shift = (mods & InputEvent.SHIFT_DOWN_MASK) != 0;
        Location newEnd;
        if (shift) {
            newEnd = LineUtil.snapTo8Cardinals(mouseStart, mx, my);
        } else {
            newEnd = Location.create(mx, my);
        }

        if ((mods & InputEvent.CTRL_DOWN_MASK) == 0) {
            int x = newEnd.getX();
            int y = newEnd.getY();
            x = canvas.snapX(x);
            y = canvas.snapY(y);
            newEnd = Location.create(x, y);
        }

        if (!newEnd.equals(mouseEnd)) {
            mouseEnd = newEnd;
            repaintArea(canvas);
        }
    }
    lastMouseX = mx;
    lastMouseY = my;
}
项目:Logisim    文件:TextFieldCaret.java   
@Override
public void keyTyped(KeyEvent e) {
    int ign = InputEvent.ALT_DOWN_MASK | InputEvent.CTRL_DOWN_MASK | InputEvent.META_DOWN_MASK;
    if ((e.getModifiersEx() & ign) != 0)
        return;

    char c = e.getKeyChar();
    if (c == '\n') {
        stopEditing();
    } else if (c != KeyEvent.CHAR_UNDEFINED && !Character.isISOControl(c)) {
        if (pos < curText.length()) {
            curText = curText.substring(0, pos) + c + curText.substring(pos);
        } else {
            curText += c;
        }
        ++pos;
        field.setText(curText);
    }
}
项目:openjdk-jdk10    文件:Robot.java   
@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;
}
项目:openjdk-jdk10    文件:Util.java   
/**
 * 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);
}
项目:OpenJSharp    文件:CPlatformResponder.java   
/**
 * 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);
    }
}
项目:jdk8u-jdk    文件:MissingEventsOnModalDialogTest.java   
public static void mouseDND(Robot robot, int x1, int y1, int x2, int y2) {

        int N = 20;
        int x = x1;
        int y = y1;
        int dx = (x2 - x1) / N;
        int dy = (y2 - y1) / N;

        robot.mousePress(InputEvent.BUTTON1_MASK);

        for (int i = 0; i < N; i++) {
            robot.mouseMove(x += dx, y += dy);
        }

        robot.mouseRelease(InputEvent.BUTTON1_MASK);
    }
项目:openjdk-jdk10    文件:DragSourceDragEvent.java   
/**
 * Sets old modifiers by the new ones.
 */
@SuppressWarnings("deprecation")
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;
    }
}
项目:Logisim    文件:InputEventUtil.java   
public static int fromString(String str) {
    int ret = 0;
    StringTokenizer toks = new StringTokenizer(str);
    while (toks.hasMoreTokens()) {
        String s = toks.nextToken();
        if (s.equals(CTRL))
            ret |= InputEvent.CTRL_DOWN_MASK;
        else if (s.equals(SHIFT))
            ret |= InputEvent.SHIFT_DOWN_MASK;
        else if (s.equals(ALT))
            ret |= InputEvent.ALT_DOWN_MASK;
        else if (s.equals(BUTTON1))
            ret |= InputEvent.BUTTON1_DOWN_MASK;
        else if (s.equals(BUTTON2))
            ret |= InputEvent.BUTTON2_DOWN_MASK;
        else if (s.equals(BUTTON3))
            ret |= InputEvent.BUTTON3_DOWN_MASK;
        else
            throw new NumberFormatException("InputEventUtil");
    }
    return ret;
}
项目:incubator-netbeans    文件:KeyboardPopupSwitcherTestHid.java   
@Override
public boolean dispatchKeyEvent(java.awt.event.KeyEvent e) {
    boolean isCtrl = e.getModifiers() == InputEvent.CTRL_MASK;
    boolean isCtrlShift = e.getModifiers() == (InputEvent.CTRL_MASK | InputEvent.SHIFT_MASK);
    boolean doPopup = (e.getKeyCode() == KeyEvent.VK_TAB) &&
            (isCtrl || isCtrlShift);
    if (doPopup && !KeyboardPopupSwitcher.isShown()) {
        // create popup with our SwitcherTable
        KeyboardPopupSwitcher.showPopup(new Model( items1, items2, true ), KeyEvent.VK_CONTROL, e.getKeyCode(), (e.getModifiers() & InputEvent.SHIFT_MASK)==0);
        return true;
    }
    if( KeyboardPopupSwitcher.isShown() ) {
        KeyboardPopupSwitcher.doProcessShortcut( e );
    }

    return false;
}
项目:marathonv5    文件:NativeEventsTest.java   
public void enteredGeneratesSameEvents() throws Throwable {
    events = MouseEvent.MOUSE_ENTERED;
    SwingUtilities.invokeAndWait(new Runnable() {
        @Override public void run() {
            actionsArea.setText("");
        }
    });
    driver = new JavaDriver();
    WebElement b = driver.findElement(By.name("click-me"));
    WebElement t = driver.findElement(By.name("actions"));

    Point location = EventQueueWait.call_noexc(button, "getLocationOnScreen");
    Dimension size = EventQueueWait.call_noexc(button, "getSize");
    Robot r = new Robot();
    r.setAutoDelay(10);
    r.setAutoWaitForIdle(true);
    r.keyPress(KeyEvent.VK_ALT);
    r.mouseMove(location.x + size.width / 2, location.y + size.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);
    r.keyRelease(KeyEvent.VK_ALT);
    new EventQueueWait() {
        @Override public boolean till() {
            return actionsArea.getText().length() > 0;
        }
    }.wait("Waiting for actionsArea failed?");
    String expected = t.getText();
    tclear();
    Point location2 = EventQueueWait.call_noexc(actionsArea, "getLocationOnScreen");
    Dimension size2 = EventQueueWait.call_noexc(actionsArea, "getSize");
    r.mouseMove(location2.x + size2.width / 2, location2.y + size2.height / 2);
    r.mousePress(InputEvent.BUTTON1_MASK);
    r.mouseRelease(InputEvent.BUTTON1_MASK);

    new Actions(driver).moveToElement(t).keyDown(Keys.ALT).moveToElement(b).click().keyUp(Keys.ALT).perform();
    AssertJUnit.assertEquals(expected, t.getText());

}
项目:openjdk-jdk10    文件:bug8072767.java   
public static void main(String[] args) throws Exception {
    Robot robot = new Robot();
    robot.setAutoDelay(50);
    SwingUtilities.invokeAndWait(bug8072767::createAndShowGUI);
    robot.waitForIdle();
    SwingUtilities.invokeAndWait(() -> {
        point = table.getLocationOnScreen();
        Rectangle rect = table.getCellRect(0, 0, true);
        point.translate(rect.width / 2, rect.height / 2);
    });
    robot.mouseMove(point.x, point.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.waitForIdle();

    robot.keyPress(KeyEvent.VK_1);
    robot.keyRelease(KeyEvent.VK_1);
    robot.waitForIdle();

    SwingUtilities.invokeAndWait(() -> {
        point = frame.getLocationOnScreen();
        point.translate(frame.getWidth() / 2, frame.getHeight() / 2);
    });

    robot.mouseMove(point.x, point.y);
    robot.mousePress(InputEvent.BUTTON1_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
    robot.waitForIdle();

    SwingUtilities.invokeAndWait(() -> {
        testPass = TEST2.equals(table.getValueAt(0, 0));
        frame.dispose();
    });

    if (!testPass) {
        throw new RuntimeException("Table cell is not edited!");
    }
}
项目:jdk8u-jdk    文件:bug7170657.java   
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");
    }
}
项目:openjdk-jdk10    文件:WMouseDragGestureRecognizer.java   
/**
 * 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());
}
项目:OpenJSharp    文件:DragGestureRecognizer.java   
/**
 * Deserializes this <code>DragGestureRecognizer</code>. This method first
 * performs default deserialization for all non-<code>transient</code>
 * fields. This object's <code>DragGestureListener</code> is then
 * deserialized as well by using the next object in the stream.
 *
 * @since 1.4
 */
@SuppressWarnings("unchecked")
private void readObject(ObjectInputStream s)
    throws ClassNotFoundException, IOException
{
    ObjectInputStream.GetField f = s.readFields();

    DragSource newDragSource = (DragSource)f.get("dragSource", null);
    if (newDragSource == null) {
        throw new InvalidObjectException("null DragSource");
    }
    dragSource = newDragSource;

    component = (Component)f.get("component", null);
    sourceActions = f.get("sourceActions", 0) & (DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK);
    events = (ArrayList<InputEvent>)f.get("events", new ArrayList<>(1));

    dragGestureListener = (DragGestureListener)s.readObject();
}
项目:incubator-netbeans    文件:OptionsPanel.java   
public OptionsPanel (String categoryID, CategoryModel categoryModel) {
this.categoryModel = categoryModel;
       // init UI components, layout and actions, and add some default values
       initUI(categoryID);        
       if (getActionMap().get("SEARCH_OPTIONS") == null) {//NOI18N
           InputMap inputMap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

           if(Utilities.isMac()) {
               inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.META_MASK), "SEARCH_OPTIONS");//NOI18N
               // Mac cloverleaf symbol
               hintText = Bundle.Filter_Textfield_Hint("\u2318+F");
           } else {
               inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_F, InputEvent.CTRL_MASK), "SEARCH_OPTIONS");//NOI18N
               hintText = Bundle.Filter_Textfield_Hint("Ctrl+F");
           }
           getActionMap().put("SEARCH_OPTIONS", new SearchAction());//NOI18N
       }
   }
项目:OpenJSharp    文件:DragGestureEvent.java   
/**
 * Constructs a <code>DragGestureEvent</code> object given by the
 * <code>DragGestureRecognizer</code> instance firing this event,
 * an {@code act} parameter representing
 * the user's preferred action, an {@code ori} parameter
 * indicating the origin of the drag, and a {@code List} of
 * events that comprise the gesture({@code evs} parameter).
 * <P>
 * @param dgr The <code>DragGestureRecognizer</code> firing this event
 * @param act The user's preferred action.
 *            For information on allowable values, see
 *            the class description for {@link DragGestureEvent}
 * @param ori The origin of the drag
 * @param evs The <code>List</code> of events that comprise the gesture
 * <P>
 * @throws IllegalArgumentException if any parameter equals {@code null}
 * @throws IllegalArgumentException if the act parameter does not comply with
 *                                  the values given in the class
 *                                  description for {@link DragGestureEvent}
 * @see java.awt.dnd.DnDConstants
 */

public DragGestureEvent(DragGestureRecognizer dgr, int act, Point ori,
                        List<? extends InputEvent> evs)
{
    super(dgr);

    if ((component = dgr.getComponent()) == null)
        throw new IllegalArgumentException("null component");
    if ((dragSource = dgr.getDragSource()) == null)
        throw new IllegalArgumentException("null DragSource");

    if (evs == null || evs.isEmpty())
        throw new IllegalArgumentException("null or empty list of events");

    if (act != DnDConstants.ACTION_COPY &&
        act != DnDConstants.ACTION_MOVE &&
        act != DnDConstants.ACTION_LINK)
        throw new IllegalArgumentException("bad action");

    if (ori == null) throw new IllegalArgumentException("null origin");

    events     = evs;
    action     = act;
    origin     = ori;
}
项目:openjdk-jdk10    文件:RemovedComponentMouseListener.java   
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");
    }
}
项目:jdk8u-jdk    文件:DragInterceptorAppletTest.java   
public DragInterceptorAppletTest(Point targetFrameLocation, Point dragSourcePoint)
        throws InterruptedException
{
    DragInterceptorFrame targetFrame = new DragInterceptorFrame(targetFrameLocation);

    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);

    sleep(2000);
    ProcessCommunicator.destroyProcess();
}
项目:OpenJSharp    文件:XEmbedHelper.java   
/**
     * 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;
    }
项目:openjdk-jdk10    文件:SystemSelectionAWTTest.java   
public void doTest() throws Exception {
    ExtendedRobot robot = new ExtendedRobot();

    frame.setLocation(100, 100);
    robot.waitForIdle(2000);

    Point tf1Location = tf1.getLocationOnScreen();
    Dimension tf1Size = tf1.getSize();
    checkSecurity();

    if (clip != null) {
        robot.mouseMove(tf1Location.x + 5, tf1Location.y + tf1Size.height / 2);
        robot.waitForIdle(2000);
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.waitForIdle(20);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
        robot.waitForIdle(20);
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.waitForIdle(20);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
        robot.waitForIdle(2000);

        getClipboardContent();
        compareText();

        robot.mouseMove(tf1Location.x + tf1Size.width / 2, tf1Location.y + tf1Size.height / 2);
        robot.waitForIdle(2000);
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.waitForIdle(20);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
        robot.waitForIdle(20);
        robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
        robot.waitForIdle(20);
        robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
        robot.waitForIdle(2000);

        getClipboardContent();
        compareText();
    }
}
项目:ripme    文件:ContextMenuMouseListener.java   
@Override
public void mouseClicked(MouseEvent e) {
    if (e.getModifiers() == InputEvent.BUTTON3_MASK) {
        if (!(e.getSource() instanceof JTextComponent)) {
            return;
        }

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

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

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

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

        int nx = e.getX();

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

        popup.show(e.getComponent(), nx, e.getY() - popup.getSize().height);
    }
}
项目:incubator-netbeans    文件:JPQLEditorTopComponent.java   
public JPQLEditorPopupMouseAdapter() {
    super();
    popupMenu = new JPopupMenu();
    ActionListener actionListener = new PopupActionListener();
    runJPQLMenuItem = popupMenu.add(RUN_JPQL_COMMAND);
    runJPQLMenuItem.setMnemonic('Q');
    runJPQLMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, false));
    runJPQLMenuItem.addActionListener(actionListener);

    popupMenu.addSeparator();

    cutMenuItem = popupMenu.add(CUT_COMMAND);
    cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK, true));
    cutMenuItem.setMnemonic('t');
    cutMenuItem.addActionListener(actionListener);

    copyMenuItem = popupMenu.add(COPY_COMMAND);
    copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK, true));
    copyMenuItem.setMnemonic('y');
    copyMenuItem.addActionListener(actionListener);

    pasteMenuItem = popupMenu.add(PASTE_COMMAND);
    pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK, true));
    pasteMenuItem.setMnemonic('P');
    pasteMenuItem.addActionListener(actionListener);

    popupMenu.addSeparator();

    selectAllMenuItem = popupMenu.add(SELECT_ALL_COMMAND);
    selectAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK, true));
    selectAllMenuItem.setMnemonic('A');
    selectAllMenuItem.addActionListener(actionListener);
}
项目:openjdk-jdk10    文件:ExtraMouseClick.java   
public void smallWin32Drag(int pixelsX, int pixelsY){
    // by the X-axis
    robot.mouseMove(fp.x + frame.getWidth()/2, fp.y + frame.getHeight()/2 );
    //drag for a short distance
    robot.mousePress(InputEvent.BUTTON1_MASK );
    System.out.println(" pixelsX = "+ pixelsX +" pixelsY = " +pixelsY);
    for (int i = 1; i<=pixelsX;i++){
        System.out.println("Moving a mouse by X");
        robot.mouseMove(fp.x + frame.getWidth()/2 + i, fp.y + frame.getHeight()/2 );
    }
    robot.mouseRelease(InputEvent.BUTTON1_MASK );
    robot.delay(1000);
    if (!dragged){
        throw new RuntimeException("Test failed. Dragged event (by the X-axis) didn't occur in the SMUDGE area. Dragged = "+dragged);
    }

    // the same with Y-axis
    robot.mouseMove(fp.x + frame.getWidth()/2, fp.y + frame.getHeight()/2 );
    robot.mousePress(InputEvent.BUTTON1_MASK );
    for (int i = 1; i<=pixelsY;i++){
        System.out.println("Moving a mouse by Y");
        robot.mouseMove(fp.x + frame.getWidth()/2, fp.y + frame.getHeight()/2 + i );
    }
    robot.mouseRelease(InputEvent.BUTTON1_MASK );
    robot.delay(1000);
    if (!dragged){
        throw new RuntimeException("Test failed. Dragged event (by the Y-axis) didn't occur in the SMUDGE area. Dragged = "+dragged);
    }
}
项目:jdk8u-jdk    文件:Util.java   
public static void clickOnTitle(final Window decoratedWindow, final Robot robot) {
    if (decoratedWindow instanceof Frame || decoratedWindow instanceof Dialog) {
        Point p = getTitlePoint(decoratedWindow);
        robot.mouseMove(p.x, p.y);
        robot.delay(50);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.delay(50);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
    }
}
项目:openjdk-jdk10    文件:RemoveDropTargetCrashTest.java   
private static void pressOnButton(Robot robot, Point clickPoint)
        throws InterruptedException {
    go = new CountDownLatch(1);
    robot.mouseMove(clickPoint.x, clickPoint.y);
    robot.mousePress(InputEvent.BUTTON1_DOWN_MASK);
    robot.mouseRelease(InputEvent.BUTTON1_DOWN_MASK);
    if (!go.await(10, TimeUnit.SECONDS)) {
        throw new RuntimeException("Button was not pressed");
    }
}
项目:openjdk-jdk10    文件:bug6538132.java   
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            bug6538132.createGui();
        }
    });
    if(isWinLaf) {
        ExtendedRobot robot = new ExtendedRobot();
        robot.setAutoDelay(10);
        robot.waitForIdle();
        Point p1 = menu1.getLocationOnScreen();
        final int x1 = p1.x + menu1.getWidth() / 2;
        final int y1 = p1.y + menu1.getHeight() / 2;
        robot.glide(0, 0, x1, y1);
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        assertPopupOpen();
        Point p2 = menu2.getLocationOnScreen();
        final int x2 = p2.x + menu2.getWidth() / 2;
        final int y2 = p2.y + menu2.getHeight() / 2;
        robot.glide(x1, y1, x2, y2);
        assertPopupOpen();
        robot.keyPress(KeyEvent.VK_ESCAPE);
        robot.keyRelease(KeyEvent.VK_ESCAPE);
        assertPopupNotOpen();
        robot.glide(x2, y2, x1, y1);
        assertPopupNotOpen();
        robot.mousePress(InputEvent.BUTTON1_MASK);
        robot.mouseRelease(InputEvent.BUTTON1_MASK);
        assertPopupOpen();
    }
}
项目:jdk8u-jdk    文件:bug6495920.java   
public void secondHidePopup() {
    Point point = this.panel.getLocation();
    SwingUtilities.convertPointToScreen(point, this.panel);

    robot.mouseMove(point.x - 1, point.y - 1);
    Thread.currentThread().setUncaughtExceptionHandler(this);
    robot.mousePress(InputEvent.BUTTON1_MASK); // causes second AssertionError on EDT
    robot.mouseRelease(InputEvent.BUTTON1_MASK);
}
项目:VASSAL-src    文件:ADC2Module.java   
private void configureStatusFlagButtons() throws IOException {
  String imageName;
  MassKeyCommand command;

  imageName = StateFlag.ATTACK.getStatusIconName();
  command = new MassKeyCommand();
  insertComponent(command, getMainMap());
  command.setAttribute(MassKeyCommand.TOOLTIP, "Clear attacked status");
  command.setAttribute(MassKeyCommand.BUTTON_TEXT, "Attacked");
  command.setAttribute(MassKeyCommand.HOTKEY, null);
  command.setAttribute(MassKeyCommand.ICON, imageName);
  command.setAttribute(MassKeyCommand.NAME, "Attacked");
  command.setAttribute(MassKeyCommand.KEY_COMMAND, new NamedKeyStroke(KeyStroke.getKeyStroke('A', InputEvent.CTRL_DOWN_MASK)));
  command.setAttribute(MassKeyCommand.PROPERTIES_FILTER, "Mark Attacked_Active = true");
  command.setAttribute(MassKeyCommand.DECK_COUNT, -1);
  command.setAttribute(MassKeyCommand.REPORT_SINGLE, Boolean.TRUE);
  command.setAttribute(MassKeyCommand.REPORT_FORMAT, "");

  imageName = StateFlag.DEFEND.getStatusIconName();
  command = new MassKeyCommand();
  insertComponent(command, getMainMap());
  command.setAttribute(MassKeyCommand.TOOLTIP, "Clear defended status");
  command.setAttribute(MassKeyCommand.BUTTON_TEXT, "Defended");
  command.setAttribute(MassKeyCommand.HOTKEY, null);
  command.setAttribute(MassKeyCommand.ICON, imageName);
  command.setAttribute(MassKeyCommand.NAME, "Defended");
  command.setAttribute(MassKeyCommand.KEY_COMMAND, new NamedKeyStroke(KeyStroke.getKeyStroke('D', InputEvent.CTRL_DOWN_MASK)));
  command.setAttribute(MassKeyCommand.PROPERTIES_FILTER, "Mark Defended_Active = true");
  command.setAttribute(MassKeyCommand.DECK_COUNT, -1);
  command.setAttribute(MassKeyCommand.REPORT_SINGLE, Boolean.TRUE);
  command.setAttribute(MassKeyCommand.REPORT_FORMAT, "");

  MultiActionButton button = new MultiActionButton();
  insertComponent(button, getMainMap());
  button.setAttribute(MultiActionButton.BUTTON_TEXT, "");
  button.setAttribute(MultiActionButton.TOOLTIP, "Clear combat status flags.");
  button.setAttribute(MultiActionButton.BUTTON_ICON, StateFlag.COMBAT.getStatusIconName());
  button.setAttribute(MultiActionButton.BUTTON_HOTKEY, KeyStroke.getKeyStroke('C', InputEvent.CTRL_DOWN_MASK));
  button.setAttribute(MultiActionButton.MENU_ITEMS, StringArrayConfigurer.arrayToString(new String[] {"Attacked", "Defended"}));
}
项目:Logisim    文件:InputEventUtil.java   
public static String toString(int mods) {
    ArrayList<String> arr = new ArrayList<String>();
    if ((mods & InputEvent.CTRL_DOWN_MASK) != 0)
        arr.add(CTRL);
    if ((mods & InputEvent.ALT_DOWN_MASK) != 0)
        arr.add(ALT);
    if ((mods & InputEvent.SHIFT_DOWN_MASK) != 0)
        arr.add(SHIFT);
    if ((mods & InputEvent.BUTTON1_DOWN_MASK) != 0)
        arr.add(BUTTON1);
    if ((mods & InputEvent.BUTTON2_DOWN_MASK) != 0)
        arr.add(BUTTON2);
    if ((mods & InputEvent.BUTTON3_DOWN_MASK) != 0)
        arr.add(BUTTON3);

    Iterator<String> it = arr.iterator();
    if (it.hasNext()) {
        StringBuilder ret = new StringBuilder();
        ret.append(it.next());
        while (it.hasNext()) {
            ret.append(" ");
            ret.append(it.next());
        }
        return ret.toString();
    } else {
        return "";
    }
}
项目:incubator-netbeans    文件:ETableTest.java   
/**
 * Test of processKeyBinding method, of class org.netbeans.swing.etable.ETable.
 */
public void testProcessKeyBinding() {
    System.out.println("testProcessKeyBinding");
    final boolean []called = new boolean[1];
    ETable t = new ETable() {
        void updatePreferredWidths() {
            super.updatePreferredWidths();
            called[0] = true;
        }
    };
    KeyEvent ke = new KeyEvent(t, 0, System.currentTimeMillis(), InputEvent.CTRL_MASK, 0, '+');
    t.processKeyBinding(null, ke, 0, true);
    assertTrue("update pref size not called", called[0]);
}
项目:VASSAL-src    文件:PropertySheet.java   
/** Changes the "type" definition this decoration, which discards all value data and structures.
 *  Format: definition; name; keystroke
 */
public void mySetType(String s) {

  s = s.substring(ID.length());
  SequenceEncoder.Decoder st = new SequenceEncoder.Decoder(s, TYPE_DELIMITOR);

  m_definition = st.nextToken();
  menuName = st.nextToken();
  final String launchKeyToken = st.nextToken("");
  commitStyle = st.nextInt(COMMIT_DEFAULT);
  String red = st.hasMoreTokens() ? st.nextToken() : "";
  String green = st.hasMoreTokens() ? st.nextToken() : "";
  String blue = st.hasMoreTokens() ? st.nextToken() : "";
  final String launchKeyStrokeToken = st.nextToken("");

  backgroundColor = red.equals("") ? null : new Color(atoi(red), atoi(green), atoi(blue));
  frame = null;

  // Handle conversion from old character only key
  if (launchKeyStrokeToken.length() > 0) {
    launchKeyStroke = NamedHotKeyConfigurer.decode(launchKeyStrokeToken);
  }
  else if (launchKeyToken.length() > 0) {
    launchKeyStroke = new NamedKeyStroke(launchKeyToken.charAt(0), InputEvent.CTRL_MASK);
  }
  else {
    launchKeyStroke = new NamedKeyStroke('P', InputEvent.CTRL_MASK);
  }
}
项目:jmt    文件:ActionCut.java   
/**
 * Defines an <code>Action</code> object with a default
 * description string and default icon.
 */
public ActionCut(Mediator mediator) {
    super("Cut", "Cut", mediator);
    putValue(SHORT_DESCRIPTION, "Cut");
    putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_T));
    putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    setEnabled(false);
}
项目:incubator-netbeans    文件:KeyStrokeUtils.java   
/**
 * Convert human-readable keystroke name to {@link KeyStroke} object.
 */
public static @CheckForNull KeyStroke getKeyStroke(
        @NonNull String keyStroke) {

    int modifiers = 0;
    while (true) {
        if (keyStroke.startsWith(EMACS_CTRL)) {
            modifiers |= InputEvent.CTRL_DOWN_MASK;
            keyStroke = keyStroke.substring(EMACS_CTRL.length());
        } else if (keyStroke.startsWith(EMACS_ALT)) {
            modifiers |= InputEvent.ALT_DOWN_MASK;
            keyStroke = keyStroke.substring(EMACS_ALT.length());
        } else if (keyStroke.startsWith(EMACS_SHIFT)) {
            modifiers |= InputEvent.SHIFT_DOWN_MASK;
            keyStroke = keyStroke.substring(EMACS_SHIFT.length());
        } else if (keyStroke.startsWith(EMACS_META)) {
            modifiers |= InputEvent.META_DOWN_MASK;
            keyStroke = keyStroke.substring(EMACS_META.length());
        } else if (keyStroke.startsWith(STRING_ALT)) {
            modifiers |= InputEvent.ALT_DOWN_MASK;
            keyStroke = keyStroke.substring(STRING_ALT.length());
        } else if (keyStroke.startsWith(STRING_META)) {
            modifiers |= InputEvent.META_DOWN_MASK;
            keyStroke = keyStroke.substring(STRING_META.length());
        } else {
            break;
        }
    }
    KeyStroke ks = Utilities.stringToKey (keyStroke);
    if (ks == null) { // Return null to indicate an invalid keystroke
        return null;
    } else {
        KeyStroke result = KeyStroke.getKeyStroke (ks.getKeyCode (), modifiers);
        return result;
    }
}
项目:QN-ACTR-Release    文件:ActionPaste.java   
/**
 * Defines an <code>Action</code> object with a default
 * description string and default icon.
 */
public ActionPaste(Mediator mediator) {
    super("Paste", "Paste", mediator);
    putValue(SHORT_DESCRIPTION, "Paste");
    //Conti Andrea
    //putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_V));
    putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
    putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK));
    //end
    setEnabled(false);
}
项目:intellij-randomness    文件:DataGroupAction.java   
@Override
@SuppressWarnings("PMD.ConfusingTernary") // != 0 for binary mask is expected
public final void actionPerformed(final AnActionEvent event) {
    super.actionPerformed(event);

    if ((event.getModifiers() & (InputEvent.SHIFT_MASK | InputEvent.SHIFT_DOWN_MASK)) != 0) {
        getInsertArrayAction().actionPerformed(event);
    } else if ((event.getModifiers() & (InputEvent.CTRL_MASK | InputEvent.CTRL_DOWN_MASK)) != 0) {
        getSettingsAction().actionPerformed(event);
    } else {
        getInsertAction().actionPerformed(event);
    }
}