java.awt.event.KeyEvent Java Examples

The following examples show how to use java.awt.event.KeyEvent. 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: bug4983388.java    From TencentKona-8 with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {

        SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
        try {
            UIManager.setLookAndFeel("com.sun.java.swing.plaf.gtk.GTKLookAndFeel");
        } catch (UnsupportedLookAndFeelException | ClassNotFoundException ex) {
            System.err.println("GTKLookAndFeel is not supported on this platform. Using defailt LaF for this platform.");
        }

        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });

        Robot robot = new Robot();
        Util.hitMnemonics(robot, KeyEvent.VK_F);

        toolkit.realSync();

        if (!bMenuSelected) {
            throw new RuntimeException("shortcuts on menus do not work");
        }
    }
 
Example #2
Source File: Generator.java    From marathonv5 with Apache License 2.0 6 votes vote down vote up
private List<Integer> tryRobotWith(Robot robot, List<Integer> asciiKeycodes, boolean withShift) {
    List<Integer> succeeded = new ArrayList<Integer>();
    for (Integer keyCode : asciiKeycodes) {
        try {
            if (withShift) {
                robot.keyPress(KeyEvent.VK_SHIFT);
            }
            robot.keyPress(keyCode);
            robot.keyRelease(keyCode);
            succeeded.add(keyCode);
        } catch (Throwable t) {
        } finally {
            if (withShift) {
                robot.keyRelease(KeyEvent.VK_SHIFT);
            }
        }
    }
    return succeeded;
}
 
Example #3
Source File: Utils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static void stepChooseComponet( String name, TestData data )
{
    JFrameOperator installerMain = new JFrameOperator(MAIN_FRAME_TITLE);

    new JButtonOperator(installerMain, "Customize...").push();
    JDialogOperator customizeInstallation = new JDialogOperator("Customize Installation");
    JListOperator featureList = new JListOperator(customizeInstallation);
    featureList.selectItem(name);

    featureList.pressKey(KeyEvent.VK_SPACE);

    // Check prelude
    data.m_bPreludePresents = ( -1 != featureList.findItemIndex( "Prelude" ) );

    new JButtonOperator(customizeInstallation, "OK").push();
}
 
Example #4
Source File: KeyboardState.java    From Repeat with Apache License 2.0 6 votes vote down vote up
public KeyboardState changeWith(KeyStroke stroke) {
	int key = stroke.getKey();
	boolean pressed = stroke.isPressed();

	if (key == KeyEvent.VK_SHIFT) {
		return withShiftLocked(pressed);
	} else if (key == KeyEvent.VK_NUM_LOCK) {
		return withNumslock(pressed);
	} else if (key == KeyEvent.VK_CAPS_LOCK) {
		return withCapslock(pressed);
	} else if (key == KeyEvent.VK_SCROLL_LOCK) {
		return withScrollLock(pressed);
	}

	return this;
}
 
Example #5
Source File: PortecleJDialog.java    From portecle with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Get cancel button.
 *
 * @return
 */
protected JButton getCancelButton()
{
	Action cancelAction = new AbstractAction()
	{
		@Override
		public void actionPerformed(ActionEvent evt)
		{
			cancelPressed();
		}
	};

	JButton jbCancel = new JButton(RB.getString("PortecleJDialog.jbCancel.text"));

	jbCancel.addActionListener(cancelAction);

	jbCancel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
	    ESC_KEY);
	jbCancel.getActionMap().put(ESC_KEY, cancelAction);

	return jbCancel;
}
 
Example #6
Source File: GameWindow.java    From dungeon with BSD 3-Clause "New" or "Revised" License 6 votes vote down vote up
/**
 * Handles a key press in the text field. This method checks for a command history access by the keys UP, DOWN, or TAB
 * and, if this is the case, processes this query.
 *
 * @param event the KeyEvent.
 */
private void textFieldKeyPressed(KeyEvent event) {
  int keyCode = event.getKeyCode();
  if (isUpDownOrTab(keyCode)) { // Check if the event is of interest.
    GameState gameState = Game.getGameState();
    if (gameState != null) {
      CommandHistory commandHistory = gameState.getCommandHistory();
      if (keyCode == KeyEvent.VK_UP) {
        textField.setText(commandHistory.getCursor().moveUp().getSelectedCommand());
      } else if (keyCode == KeyEvent.VK_DOWN) {
        textField.setText(commandHistory.getCursor().moveDown().getSelectedCommand());
      } else if (keyCode == KeyEvent.VK_TAB) {
        // Using the empty String to get the last similar command will always retrieve the last command.
        // Therefore, there is no need to check if there is something in the text field.
        String lastSimilarCommand = commandHistory.getLastSimilarCommand(getTrimmedTextFieldText());
        if (lastSimilarCommand != null) {
          textField.setText(lastSimilarCommand);
        }
      }
    }
  }
}
 
Example #7
Source File: AWTKeyStroke.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Returns the integer constant for the KeyEvent.VK field named
 * <code>key</code>. This will throw an
 * <code>IllegalArgumentException</code> if <code>key</code> is
 * not a valid constant.
 */
private static int getVKValue(String key) {
    VKCollection vkCollect = getVKCollection();

    Integer value = vkCollect.findCode(key);

    if (value == null) {
        int keyCode = 0;
        final String errmsg = "String formatted incorrectly";

        try {
            keyCode = KeyEvent.class.getField(key).getInt(KeyEvent.class);
        } catch (NoSuchFieldException nsfe) {
            throw new IllegalArgumentException(errmsg);
        } catch (IllegalAccessException iae) {
            throw new IllegalArgumentException(errmsg);
        }
        value = Integer.valueOf(keyCode);
        vkCollect.put(key, value);
    }
    return value.intValue();
}
 
Example #8
Source File: MainPanel.java    From javagame with MIT License 6 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyReleased(KeyEvent e) {
    int keyCode = e.getKeyCode();

    if (keyCode == KeyEvent.VK_LEFT) {
        leftKey.release();
    }
    if (keyCode == KeyEvent.VK_RIGHT) {
        rightKey.release();
    }
    if (keyCode == KeyEvent.VK_UP) {
        upKey.release();
    }
    if (keyCode == KeyEvent.VK_DOWN) {
        downKey.release();
    }
    if (keyCode == KeyEvent.VK_SPACE) {
        spaceKey.release();
    }
}
 
Example #9
Source File: bug7055065.java    From jdk8u-jdk with GNU General Public License v2.0 6 votes vote down vote up
public static void main(String[] args) throws Exception {
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    Robot robot = new Robot();

    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            createAndShowUI();
        }
    });

    toolkit.realSync();
    clickCell(robot, 1, 1);
    Util.hitKeys(robot, KeyEvent.VK_BACK_SPACE, KeyEvent.VK_BACK_SPACE,
            KeyEvent.VK_BACK_SPACE);

    toolkit.realSync();
    clickColumnHeader(robot, 1);

    toolkit.realSync();
    clickColumnHeader(robot, 1);
}
 
Example #10
Source File: PinPadPanelImpl.java    From freehealth-connector with GNU Affero General Public License v3.0 6 votes vote down vote up
public void eventDispatched(AWTEvent event) {
   if (event instanceof KeyEvent) {
      KeyEvent key = (KeyEvent)event;
      if (key.getID() == 401) {
         if (key.getKeyCode() == 8) {
            PinPadPanelImpl.this.processBackspace();
         } else if (key.getKeyCode() == 10) {
            PinPadPanelImpl.this.validateGoButton();
            if (PinPadPanelImpl.this.btnGo.isEnabled()) {
               ActionEvent action = new ActionEvent(PinPadPanelImpl.this.btnGo, 1001, PinPadPanelImpl.this.btnGo.getActionCommand(), System.currentTimeMillis(), 16);
               PinPadPanelImpl.this.actionListenerGoButton.actionPerformed(action);
            }
         } else {
            PinPadPanelImpl.this.processContent(Character.toString(key.getKeyChar()));
         }
      }
   }

}
 
Example #11
Source File: MenuItemLayoutHelper.java    From hottub with GNU General Public License v2.0 6 votes vote down vote up
private String getAccText(String acceleratorDelimiter) {
    String accText = "";
    KeyStroke accelerator = mi.getAccelerator();
    if (accelerator != null) {
        int modifiers = accelerator.getModifiers();
        if (modifiers > 0) {
            accText = KeyEvent.getKeyModifiersText(modifiers);
            accText += acceleratorDelimiter;
        }
        int keyCode = accelerator.getKeyCode();
        if (keyCode != 0) {
            accText += KeyEvent.getKeyText(keyCode);
        } else {
            accText += accelerator.getKeyChar();
        }
    }
    return accText;
}
 
Example #12
Source File: StandardEditingPopupMenu.java    From importer-exporter with Apache License 2.0 5 votes vote down vote up
public void init(Component component) {
	cut = new JMenuItem();
	copy = new JMenuItem();		
	paste = new JMenuItem();
	selectAll = new JMenuItem();

	cut.setActionCommand((String)TransferHandler.getCutAction().getValue(Action.NAME));
	copy.setActionCommand((String)TransferHandler.getCopyAction().getValue(Action.NAME));
	paste.setActionCommand((String)TransferHandler.getPasteAction().getValue(Action.NAME));

	cut.addActionListener(new TransferActionListener());
	copy.addActionListener(new TransferActionListener());
	paste.addActionListener(new TransferActionListener());

	if (component instanceof JTextComponent) {
		selectAll.setAction(new TextSelectAllAction());

		if (component instanceof JPasswordField) {
			cut.setEnabled(false);
			copy.setEnabled(false);
		}
	} else if (component instanceof JList)
		selectAll.setAction(new ListSelectAllAction());		

	cut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
	copy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
	paste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));
	selectAll.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()));

	add(cut);
	add(copy);
	add(paste);
	addSeparator();
	add(selectAll);
}
 
Example #13
Source File: ProfilerPopup.java    From visualvm with GNU General Public License v2.0 5 votes vote down vote up
public boolean dispatchKeyEvent(KeyEvent e) {
    if (skippingEvents || e.isConsumed()) return false;
    
    if (e.getID() == KeyEvent.KEY_PRESSED && e.getKeyCode() == KeyEvent.VK_ESCAPE)
        if (SwingUtilities.getRootPane(this) != e.getSource()) { // Closing JPopupMenu using the ESC key
            e.consume();
            if (DEBUG) System.err.println(">>> Closed by ESC"); // NOI18N
            ProfilerPopup.this.hide();
            return true;
        }
    
    return false;
}
 
Example #14
Source File: TableListener.java    From hortonmachine with GNU General Public License v3.0 5 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if (e.getKeyCode() == KeyEvent.VK_CONTROL) {
        pressed = true;
    }
    if (pressed && e.getKeyCode() == KeyEvent.VK_V) {
        adaptee.pasteClipboard();
    }
}
 
Example #15
Source File: DefaultKeyboardFocusManager.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
private void pumpApprovedKeyEvents() {
    KeyEvent ke;
    do {
        ke = null;
        synchronized (this) {
            if (enqueuedKeyEvents.size() != 0) {
                ke = enqueuedKeyEvents.getFirst();
                if (typeAheadMarkers.size() != 0) {
                    TypeAheadMarker marker = typeAheadMarkers.getFirst();
                    // Fixed 5064013: may appears that the events have the same time
                    // if (ke.getWhen() >= marker.after) {
                    // The fix is rolled out.

                    if (ke.getWhen() > marker.after) {
                        ke = null;
                    }
                }
                if (ke != null) {
                    if (focusLog.isLoggable(PlatformLogger.Level.FINER)) {
                        focusLog.finer("Pumping approved event {0}", ke);
                    }
                    enqueuedKeyEvents.removeFirst();
                }
            }
        }
        if (ke != null) {
            preDispatchKeyEvent(ke);
        }
    } while (ke != null);
}
 
Example #16
Source File: bug4220171.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {

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

        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {

            public void run() {
                createAndShowGUI();
            }
        });

        toolkit.realSync();

        clickMouse(robot, 0, 0);
        Util.hitKeys(robot, KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_ENTER);
        toolkit.realSync();
        checkCell(0, 0);

        clickMouse(robot, 0, 1);
        Util.hitKeys(robot, KeyEvent.VK_D, KeyEvent.VK_E, KeyEvent.VK_ENTER);
        toolkit.realSync();
        checkCell(0, 1);

        clickMouse(robot, 1, 0);
        Util.hitKeys(robot, KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_ENTER);
        toolkit.realSync();
        checkCell(1, 0);

        clickMouse(robot, 1, 1);
        Util.hitKeys(robot, KeyEvent.VK_4, KeyEvent.VK_5, KeyEvent.VK_ENTER);
        toolkit.realSync();
        checkCell(1, 1);
    }
 
Example #17
Source File: DeadKeyMacOSXInputText.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

        if (OSInfo.getOSType() != OSInfo.OSType.MACOSX) {
            return;
        }

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

        createAndShowGUI();

        // Pressed keys: Alt + E + A
        // Results:  ALT + VK_DEAD_ACUTE + a with accute accent
        robot.keyPress(KeyEvent.VK_ALT);
        robot.keyPress(KeyEvent.VK_E);
        robot.keyRelease(KeyEvent.VK_E);
        robot.keyRelease(KeyEvent.VK_ALT);

        robot.keyPress(KeyEvent.VK_A);
        robot.keyRelease(KeyEvent.VK_A);
        toolkit.realSync();

        if (state != 3) {
            throw new RuntimeException("Wrong number of key events.");
        }
    }
 
Example #18
Source File: DockManagerImpl.java    From consulo with Apache License 2.0 5 votes vote down vote up
@Override
public boolean dispatch(AWTEvent e) {
  if (e instanceof KeyEvent) {
    if (myCurrentDragSession != null) {
      stopCurrentDragSession();
    }
  }
  return false;
}
 
Example #19
Source File: DDateTimeChooser.java    From keystore-explorer with GNU General Public License v3.0 5 votes vote down vote up
private void calendarKeyboardNavigation(KeyEvent evt) {
	int day = getSelectedDayOfMonth();

	switch (evt.getKeyCode()) {
	case KeyEvent.VK_LEFT: {
		if (day > 1) {
			setSelectedDay(day - 1);
		}
		break;
	}
	case KeyEvent.VK_RIGHT: {
		if (day < lastDayOfSelectedMonth) {
			setSelectedDay(day + 1);
		}
		break;
	}
	case KeyEvent.VK_UP: {
		if (day > 7) {
			setSelectedDay(day - 7);
		}
		break;
	}
	case KeyEvent.VK_DOWN: {
		if (day <= (lastDayOfSelectedMonth - 7)) {
			setSelectedDay(day + 7);
		}
		break;
	}
	}
}
 
Example #20
Source File: GeneralAngular.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testCompletion(EditorOperator eo, int lineNumber) throws Exception {
    waitScanFinished();
    String rawLine = eo.getText(lineNumber);
    int start = rawLine.indexOf("<!--cc;");
    String rawConfig = rawLine.substring(start + 2);
    String[] config = rawConfig.split(";");
    eo.setCaretPosition(lineNumber, Integer.parseInt(config[1]));
    type(eo, config[2]);
    eo.pressKey(KeyEvent.VK_ESCAPE);
    int back = Integer.parseInt(config[3]);
    for (int i = 0; i < back; i++) {
        eo.pressKey(KeyEvent.VK_LEFT);
    }

    eo.typeKey(' ', InputEvent.CTRL_MASK);
    CompletionInfo completion = getCompletion();
    CompletionJListOperator cjo = completion.listItself;
    checkCompletionItems(cjo, config[4].split(","));
    completion.listItself.hideAll();

    if (config[5].length() > 0) {
        String prefix = Character.toString(config[5].charAt(0));
        type(eo, prefix);
        eo.typeKey(' ', InputEvent.CTRL_MASK);
        completion = getCompletion();
        cjo = completion.listItself;
        checkCompletionMatchesPrefix(cjo.getCompletionItems(), prefix);
        evt.waitNoEvent(500);
        cjo.clickOnItem(config[5]);
        eo.pressKey(KeyEvent.VK_ENTER);
        assertTrue("Wrong completion result", eo.getText(lineNumber).contains(config[6].replaceAll("|", "")));
        completion.listItself.hideAll();
    }

    eo.setCaretPositionToEndOfLine(eo.getLineNumber());
    String l = eo.getText(eo.getLineNumber());
    for (int i = 0; i < l.length() - 1; i++) {
        eo.pressKey(KeyEvent.VK_BACK_SPACE);
    }
}
 
Example #21
Source File: KeyStrokeAdapter.java    From consulo with Apache License 2.0 5 votes vote down vote up
/**
 * @param event the specified key event to process
 * @return a key stroke or {@code null} if it is not applicable
 * @see KeyStroke#getKeyStrokeForEvent(KeyEvent)
 */
public static KeyStroke getDefaultKeyStroke(KeyEvent event) {
  if (event == null || event.isConsumed()) return null;
  // On Windows and Mac it is preferable to use normal key code here
  boolean extendedKeyCodeFirst = !SystemInfo.isWindows && !SystemInfo.isMac && event.getModifiers() == 0;
  KeyStroke stroke = getKeyStroke(event, extendedKeyCodeFirst);
  return stroke != null ? stroke : getKeyStroke(event, !extendedKeyCodeFirst);
}
 
Example #22
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyReleased(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT) {
        leftPressed = false;
    }
    if (key == KeyEvent.VK_RIGHT) {
        rightPressed = false;
    }
    if (key == KeyEvent.VK_UP) {
        upPressed = false;
    }
}
 
Example #23
Source File: MainPanel.java    From javagame with MIT License 5 votes vote down vote up
/**
 * �L�[�������ꂽ��L�[�̏�Ԃ��u�����ꂽ�v�ɕς���
 * 
 * @param e �L�[�C�x���g
 */
public void keyPressed(KeyEvent e) {
    int key = e.getKeyCode();

    if (key == KeyEvent.VK_LEFT) {
        leftPressed = true;
    }
    if (key == KeyEvent.VK_RIGHT) {
        rightPressed = true;
    }
    if (key == KeyEvent.VK_UP) {
        upPressed = true;
    }
}
 
Example #24
Source File: bug4458079.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    SwingUtilities.invokeAndWait(new Runnable() {
        public void run() {
            new bug4458079().createAndShowGUI();
        }
    });
    SunToolkit toolkit = (SunToolkit) Toolkit.getDefaultToolkit();
    toolkit.realSync();

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

    Util.hitMnemonics(robot, KeyEvent.VK_M);

    toolkit.realSync();
    Thread.sleep(1000);

    Util.hitKeys(robot, KeyEvent.VK_DOWN);
    Util.hitKeys(robot, KeyEvent.VK_ENTER);

    toolkit.realSync();
    Thread.sleep(1000);

    if (!itemASelected) {
        throw new RuntimeException("Test failed: arrow key traversal in JMenu broken!");
    }
}
 
Example #25
Source File: bug4220171.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String args[]) throws Exception {

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

        javax.swing.SwingUtilities.invokeAndWait(new Runnable() {

            public void run() {
                createAndShowGUI();
            }
        });

        toolkit.realSync();

        clickMouse(robot, 0, 0);
        Util.hitKeys(robot, KeyEvent.VK_A, KeyEvent.VK_B, KeyEvent.VK_ENTER);
        toolkit.realSync();
        checkCell(0, 0);

        clickMouse(robot, 0, 1);
        Util.hitKeys(robot, KeyEvent.VK_D, KeyEvent.VK_E, KeyEvent.VK_ENTER);
        toolkit.realSync();
        checkCell(0, 1);

        clickMouse(robot, 1, 0);
        Util.hitKeys(robot, KeyEvent.VK_1, KeyEvent.VK_2, KeyEvent.VK_ENTER);
        toolkit.realSync();
        checkCell(1, 0);

        clickMouse(robot, 1, 1);
        Util.hitKeys(robot, KeyEvent.VK_4, KeyEvent.VK_5, KeyEvent.VK_ENTER);
        toolkit.realSync();
        checkCell(1, 1);
    }
 
Example #26
Source File: bug8021253.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {

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

        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                createAndShowGUI();
            }
        });

        toolkit.realSync();

        SwingUtilities.invokeAndWait(new Runnable() {
            public void run() {
                fileChooser.setSelectedFile(file);
            }
        });

        toolkit.realSync();

        robot.keyPress(KeyEvent.VK_ENTER);
        robot.keyRelease(KeyEvent.VK_ENTER);
        toolkit.realSync();

        if (!defaultKeyPressed) {
            throw new RuntimeException("Default button is not pressed");
        }
    }
 
Example #27
Source File: TopComponentTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testToStringOfDelegateContainsNameOfOriginalAction() throws Exception {
    SaveAction sa = SaveAction.get(SaveAction.class);
    Action a = sa.createContextAwareInstance(Lookup.EMPTY);
    if (a.toString().indexOf("SaveAction") == -1) {
        fail("We need name of the original action:\n" + a.toString());
    }

    SaveAction.cnt = 0;
    CharSequence log = Log.enable("org.netbeans.ui", Level.FINER);
    
    final TopComponent tc = new TopComponent();
    final KeyEvent ke = new KeyEvent(tc, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), KeyEvent.CTRL_MASK, 0, 'S');
    final KeyStroke ks = KeyStroke.getKeyStrokeForEvent(ke);
    MockServices.setServices(MyKM.class);
    SwingUtilities.invokeAndWait(new Runnable() {

        public void run() {
            tc.setActivatedNodes( new Node[0] );
            tc.processKeyBinding(ks, ke, JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, true);
        }
        
    });
    
    if (log.toString().indexOf("SaveAction") == -1 
            && SaveAction.cnt == 1 ) { //make sure the action was actually invoked
        fail(log.toString());
    }
}
 
Example #28
Source File: WComponentPeer.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
@Override
@SuppressWarnings("fallthrough")
public void handleEvent(AWTEvent e) {
    int id = e.getID();

    if ((e instanceof InputEvent) && !((InputEvent)e).isConsumed() &&
        ((Component)target).isEnabled())
    {
        if (e instanceof MouseEvent && !(e instanceof MouseWheelEvent)) {
            handleJavaMouseEvent((MouseEvent) e);
        } else if (e instanceof KeyEvent) {
            if (handleJavaKeyEvent((KeyEvent)e)) {
                return;
            }
        }
    }

    switch(id) {
        case PaintEvent.PAINT:
            // Got native painting
            paintPending = false;
            // Fallthrough to next statement
        case PaintEvent.UPDATE:
            // Skip all painting while layouting and all UPDATEs
            // while waiting for native paint
            if (!isLayouting && ! paintPending) {
                paintArea.paint(target,shouldClearRectBeforePaint());
            }
            return;
        case FocusEvent.FOCUS_LOST:
        case FocusEvent.FOCUS_GAINED:
            handleJavaFocusEvent((FocusEvent)e);
        default:
        break;
    }

    // Call the native code
    nativeHandleEvent(e);
}
 
Example #29
Source File: SwingDemo.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
public boolean dispatchKeyEvent(KeyEvent e) {
  if (e.getID() == KeyEvent.KEY_TYPED) {
    if (e.getKeyChar() == 'c') {
      connect();
    }
    if (e.getKeyChar() == 'd') {
      disconnect();
    }
  }
  return false;
}
 
Example #30
Source File: TraitScreen.java    From open-ig with GNU Lesser General Public License v3.0 5 votes vote down vote up
@Override
public boolean keyboard(KeyEvent e) {
	if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
		e.consume();
		cancel.onClick.invoke();
		return true;
	}
	return false;
}