Java Code Examples for java.awt.KeyboardFocusManager#addKeyEventDispatcher()

The following examples show how to use java.awt.KeyboardFocusManager#addKeyEventDispatcher() . 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: ShortcutAndMenuKeyEventProcessor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public static synchronized void install() {
    if(installed) {
        return;
    }
    
    ShortcutAndMenuKeyEventProcessor instance = getDefault();
    
    KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    keyboardFocusManager.addKeyEventDispatcher(instance);
    keyboardFocusManager.addKeyEventPostProcessor(instance);
    // #63252: Disable focus traversal functionality of Ctrl+Tab and Ctrl+Shift+Tab,
    // to allow our own document switching (RecentViewListAction)
    defaultForward = keyboardFocusManager.getDefaultFocusTraversalKeys(
                        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS);
    defaultBackward = keyboardFocusManager.getDefaultFocusTraversalKeys(
                        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS);
    keyboardFocusManager.setDefaultFocusTraversalKeys(
        KeyboardFocusManager.FORWARD_TRAVERSAL_KEYS,
        Collections.singleton(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, 0))
    );                
    keyboardFocusManager.setDefaultFocusTraversalKeys(
        KeyboardFocusManager.BACKWARD_TRAVERSAL_KEYS,
        Collections.singleton(AWTKeyStroke.getAWTKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK))
    );                
}
 
Example 2
Source File: SwingMain.java    From chip8 with MIT License 6 votes vote down vote up
/**
 * Creates new form SwingMain
 */
public SwingMain() {
    this.chip8Runner = new Thread(() -> {
        while (true) {
            try {
                if (running) {
                    if (pause == false || step) {
                        step = false;
                        chip8.cycle();
                        ((Chip8Model) jTable1.getModel()).update(chip8);
                    }
                    outputPanel.repaint();
                }
                sleep(1);
            } catch (InterruptedException ex) {
                Logger.getLogger(SwingMain.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    });
    initComponents();
    KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    manager.addKeyEventDispatcher(new KeyEventDispatcher() {
        @Override
        public boolean dispatchKeyEvent(KeyEvent e) {
            switch (e.getID()) {
                case KeyEvent.KEY_PRESSED:
                    Input.press(e.getKeyChar() + "");
                    break;
                case KeyEvent.KEY_RELEASED:
                    Input.unpress();
                    break;
                default:
                    break;
            }
            return false;
        }
    });
}
 
Example 3
Source File: MegaMekGUI.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
public void createController() {
    controller = new MegaMekController();
    KeyboardFocusManager kbfm = KeyboardFocusManager
            .getCurrentKeyboardFocusManager();
    kbfm.addKeyEventDispatcher(controller);

    KeyBindParser.parseKeyBindings(controller);
}
 
Example 4
Source File: SwingDemo.java    From jfxvnc with Apache License 2.0 5 votes vote down vote up
public SwingDemo(boolean singleFrame) {
  JFrame frame = new JFrame("SwingDemo");
  frame.setSize(900, 700);
  frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
  KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
  manager.addKeyEventDispatcher(new KeyDispatcher());

  if (singleFrame) {
    frame.setContentPane(createVncView());
    frame.setBackground(Color.GRAY);
    frame.setVisible(true);
    return;
  }

  JDesktopPane pane = new JDesktopPane();
  frame.setContentPane(pane);

  iframe = new JInternalFrame("VNC", true, true, true, true);
  iframe.setSize(850, 650);
  iframe.setOpaque(false);
  iframe.addInternalFrameListener(this);
  iframe.setContentPane(createVncView());
  pane.add(iframe);
  frame.setVisible(true);
  iframe.setVisible(true);

}
 
Example 5
Source File: JSettlersFrame.java    From settlers-remake with MIT License 5 votes vote down vote up
JSettlersFrame() throws HeadlessException {
	setTitle("JSettlers - Version: " + CommitInfo.COMMIT_HASH_SHORT);

	SettingsManager settingsManager = SettingsManager.getInstance();

	UiPlayer uiPlayer = settingsManager.getPlayer();
	multiPlayerConnector = new MultiplayerConnector(settingsManager.getServer(), uiPlayer.getId(), uiPlayer.getName());
	mainPanel = new MainMenuPanel(this, multiPlayerConnector);

	showMainMenu();
	setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
	setPreferredSize(new Dimension(1200, 800));
	pack();
	setLocationRelativeTo(null);

	fullScreen = settingsManager.getFullScreenMode();
	updateFullScreenMode();

	KeyboardFocusManager keyboardFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
	keyboardFocusManager.addKeyEventDispatcher(e -> {
		if (e.getID() == KeyEvent.KEY_PRESSED) {
			if (e.isAltDown() && e.getKeyCode() == KeyEvent.VK_ENTER) {
				toogleFullScreenMode();
				return true; // consume this key event.
			}
		}
		return false;
	});
}
 
Example 6
Source File: MainFrameMenu.java    From jpexs-decompiler with GNU General Public License v3.0 4 votes vote down vote up
private void registerHotKeys() {

        KeyboardFocusManager manager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
        manager.addKeyEventDispatcher(keyEventDispatcher = this::dispatchKeyEvent);
    }
 
Example 7
Source File: SwingGameController.java    From magarena with GNU General Public License v3.0 4 votes vote down vote up
private void setControlKeyMonitor() {
    isControlKeyDown = false;
    final KeyboardFocusManager kbFocusManager = KeyboardFocusManager.getCurrentKeyboardFocusManager();
    kbFocusManager.removeKeyEventDispatcher(keyEventDispatcher);
    kbFocusManager.addKeyEventDispatcher(keyEventDispatcher);
}