微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

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,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,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,mask,true,1);
    MouseEvent mdme = new MenuDragMouseEvent(f,null,null);
    MouseEvent me = new MouseEvent(f,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 @R_444_4045@ion 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(),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,true));
    copyMenuItem.setMnemonic('y');
    copyMenuItem.addActionListener(actionListener);

    pastemenuItem = popupMenu.add(PASTE_COMMAND);
    pastemenuItem.setAccelerator(Keystroke.getKeystroke(KeyEvent.VK_V,true));
    pastemenuItem.setMnemonic('P');
    pastemenuItem.addActionListener(actionListener);

    popupMenu.addSeparator();

    selectAllMenuItem = popupMenu.add(SELECT_ALL_COMMAND);
    selectAllMenuItem.setAccelerator(Keystroke.getKeystroke(KeyEvent.VK_A,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,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,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,"Clear defended status");
  command.setAttribute(MassKeyCommand.BUTTON_TEXT,"Defended");
  command.setAttribute(MassKeyCommand.HOTKEY,"Defended");
  command.setAttribute(MassKeyCommand.KEY_COMMAND,new NamedKeystroke(Keystroke.getKeystroke('D',"Mark Defended_Active = true");
  command.setAttribute(MassKeyCommand.DECK_COUNT,"");

  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,System.currentTimeMillis(),'+');
    t.processKeyBinding(null,ke,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","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);
    }
}

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。