List of usage examples for javax.swing KeyStroke getKeyStroke
public static KeyStroke getKeyStroke(int keyCode, int modifiers)
From source file:com.mirth.connect.manager.HeapSizeDialog.java
public HeapSizeDialog(String heapSize) { super(PlatformUI.MANAGER_DIALOG, true); managerController = ManagerController.getInstance(); getRootPane().registerKeyboardAction(new ActionListener() { @Override//from ww w. j a v a 2s. com public void actionPerformed(ActionEvent e) { dispose(); } }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); setResizable(false); setBackground(Color.white); setTitle("Web Start Settings"); getContentPane().setBackground(Color.white); initComponents(); this.heapSize = StringUtils.isEmpty(heapSize) ? "512m" : heapSize; String heapSizeOption = HeapSize.toDisplayName(heapSize); if (StringUtils.isBlank(heapSizeOption)) { heapSizeOption = this.heapSize; } // Add any non-default properties to the model String property = (String) managerController.getServerProperties() .getProperty(ManagerConstants.ADMINISTRATOR_MAX_HEAP_SIZE); if (!heapSizeComboboxModel.contains(property) && !heapSizeComboboxModel.contains(HeapSize.toDisplayName(property))) { heapSizeComboboxModel.add(formatCustomProperty(property)); } // Resort list by sizes List<String> mbList = new ArrayList<String>(); List<String> gbList = new ArrayList<String>(); for (String size : heapSizeComboboxModel) { if (size.contains("M")) { mbList.add(size); } else { gbList.add(size); } } Collections.sort(mbList); Collections.sort(gbList); mbList.addAll(gbList); heapSizeComboBox = new JComboBox(mbList.toArray()); heapSizeComboBox.getModel().setSelectedItem(formatCustomProperty(heapSizeOption)); initLayout(); pack(); setLocationRelativeTo(PlatformUI.MANAGER_DIALOG); setVisible(true); }
From source file:CheckBoxMenuItemExample.java
public CheckBoxMenuItemExample() { menuBar = new JMenuBar(); JMenu justifyMenu = new JMenu("Justify"); ActionListener actionPrinter = new ActionListener() { public void actionPerformed(ActionEvent e) { try { pane.getStyledDocument().insertString(0, "Action [" + e.getActionCommand() + "] performed!\n", null);//w w w. j a v a 2 s . com } catch (Exception ex) { ex.printStackTrace(); } } }; JCheckBoxMenuItem leftJustify = new JCheckBoxMenuItem("Left", new ImageIcon("1.gif")); leftJustify.setHorizontalTextPosition(JMenuItem.RIGHT); leftJustify .setAccelerator(KeyStroke.getKeyStroke('L', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); leftJustify.addActionListener(actionPrinter); JCheckBoxMenuItem rightJustify = new JCheckBoxMenuItem("Right", new ImageIcon("2.gif")); rightJustify.setHorizontalTextPosition(JMenuItem.RIGHT); rightJustify .setAccelerator(KeyStroke.getKeyStroke('R', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); rightJustify.addActionListener(actionPrinter); JCheckBoxMenuItem centerJustify = new JCheckBoxMenuItem("Center", new ImageIcon("3.gif")); centerJustify.setHorizontalTextPosition(JMenuItem.RIGHT); centerJustify .setAccelerator(KeyStroke.getKeyStroke('M', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); centerJustify.addActionListener(actionPrinter); JCheckBoxMenuItem fullJustify = new JCheckBoxMenuItem("Full", new ImageIcon("4.gif")); fullJustify.setHorizontalTextPosition(JMenuItem.RIGHT); fullJustify .setAccelerator(KeyStroke.getKeyStroke('F', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask())); fullJustify.addActionListener(actionPrinter); justifyMenu.add(leftJustify); justifyMenu.add(rightJustify); justifyMenu.add(centerJustify); justifyMenu.add(fullJustify); menuBar.add(justifyMenu); menuBar.setBorder(new BevelBorder(BevelBorder.RAISED)); }
From source file:com.willwinder.universalgcodesender.MainWindow.java
/** * @param args the command line arguments */// ww w . j a v a 2 s. c o m public static void main(String args[]) { /* Set the Nimbus look and feel */ //<editor-fold defaultstate="collapsed" desc=" Look and feel setting code (optional) "> /* If Nimbus (introduced in Java SE 6) is not available, stay with the default look and feel. * For details see http://download.oracle.com/javase/tutorial/uiswing/lookandfeel/plaf.html */ try { for (javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) { if ("Nimbus".equals(info.getName())) { javax.swing.UIManager.setLookAndFeel(info.getClassName()); break; } } } catch (ClassNotFoundException ex) { java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (InstantiationException ex) { java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (IllegalAccessException ex) { java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } catch (javax.swing.UnsupportedLookAndFeelException ex) { java.util.logging.Logger.getLogger(MainWindow.class.getName()).log(java.util.logging.Level.SEVERE, null, ex); } //</editor-fold> // Fix look and feel to use CMD+C/X/V/A instead of CTRL if (SystemUtils.IS_OS_MAC) { Collection<InputMap> ims = new ArrayList<>(); ims.add((InputMap) UIManager.get("TextField.focusInputMap")); ims.add((InputMap) UIManager.get("TextArea.focusInputMap")); ims.add((InputMap) UIManager.get("EditorPane.focusInputMap")); ims.add((InputMap) UIManager.get("FormattedTextField.focusInputMap")); ims.add((InputMap) UIManager.get("PasswordField.focusInputMap")); ims.add((InputMap) UIManager.get("TextPane.focusInputMap")); int c = KeyEvent.VK_C; int v = KeyEvent.VK_V; int x = KeyEvent.VK_X; int a = KeyEvent.VK_A; int meta = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask(); for (InputMap im : ims) { im.put(KeyStroke.getKeyStroke(c, meta), DefaultEditorKit.copyAction); im.put(KeyStroke.getKeyStroke(v, meta), DefaultEditorKit.pasteAction); im.put(KeyStroke.getKeyStroke(x, meta), DefaultEditorKit.cutAction); im.put(KeyStroke.getKeyStroke(a, meta), DefaultEditorKit.selectAllAction); } } /* Create the form */ GUIBackend backend = new GUIBackend(); final MainWindow mw = new MainWindow(backend); /* Apply the settings to the MainWindow bofore showing it */ mw.arrowMovementEnabled.setSelected(mw.settings.isManualModeEnabled()); mw.stepSizeSpinner.setValue(mw.settings.getManualModeStepSize()); boolean unitsAreMM = mw.settings.getDefaultUnits().equals("mm"); mw.mmRadioButton.setSelected(unitsAreMM); mw.inchRadioButton.setSelected(!unitsAreMM); mw.fileChooser = new JFileChooser(mw.settings.getLastOpenedFilename()); mw.commPortComboBox.setSelectedItem(mw.settings.getPort()); mw.baudrateSelectionComboBox.setSelectedItem(mw.settings.getPortRate()); mw.scrollWindowCheckBox.setSelected(mw.settings.isScrollWindowEnabled()); mw.showVerboseOutputCheckBox.setSelected(mw.settings.isVerboseOutputEnabled()); mw.showCommandTableCheckBox.setSelected(mw.settings.isCommandTableEnabled()); mw.showCommandTableCheckBoxActionPerformed(null); mw.firmwareComboBox.setSelectedItem(mw.settings.getFirmwareVersion()); mw.setSize(mw.settings.getMainWindowSettings().width, mw.settings.getMainWindowSettings().height); mw.setLocation(mw.settings.getMainWindowSettings().xLocation, mw.settings.getMainWindowSettings().yLocation); mw.addComponentListener(new ComponentListener() { @Override public void componentResized(ComponentEvent ce) { mw.settings.getMainWindowSettings().height = ce.getComponent().getSize().height; mw.settings.getMainWindowSettings().width = ce.getComponent().getSize().width; } @Override public void componentMoved(ComponentEvent ce) { mw.settings.getMainWindowSettings().xLocation = ce.getComponent().getLocation().x; mw.settings.getMainWindowSettings().yLocation = ce.getComponent().getLocation().y; } @Override public void componentShown(ComponentEvent ce) { } @Override public void componentHidden(ComponentEvent ce) { } }); /* Display the form */ java.awt.EventQueue.invokeLater(new Runnable() { @Override public void run() { mw.setVisible(true); } }); mw.initFileChooser(); Runtime.getRuntime().addShutdownHook(new Thread() { @Override public void run() { if (mw.fileChooser.getSelectedFile() != null) { mw.settings.setLastOpenedFilename(mw.fileChooser.getSelectedFile().getAbsolutePath()); } mw.settings.setDefaultUnits(mw.inchRadioButton.isSelected() ? "inch" : "mm"); mw.settings.setManualModeStepSize(mw.getStepSize()); mw.settings.setManualModeEnabled(mw.arrowMovementEnabled.isSelected()); mw.settings.setPort(mw.commPortComboBox.getSelectedItem().toString()); mw.settings.setPortRate(mw.baudrateSelectionComboBox.getSelectedItem().toString()); mw.settings.setScrollWindowEnabled(mw.scrollWindowCheckBox.isSelected()); mw.settings.setVerboseOutputEnabled(mw.showVerboseOutputCheckBox.isSelected()); mw.settings.setCommandTableEnabled(mw.showCommandTableCheckBox.isSelected()); mw.settings.setFirmwareVersion(mw.firmwareComboBox.getSelectedItem().toString()); SettingsFactory.saveSettings(mw.settings); if (mw.pendantUI != null) { mw.pendantUI.stop(); } } }); // Check command line for a file to open. boolean open = false; for (String arg : args) { if (open) { try { backend.setGcodeFile(new File(arg)); } catch (Exception ex) { Logger.getLogger(MainWindow.class.getName()).log(Level.SEVERE, null, ex); System.exit(1); } } if (arg.equals("--open") || arg.equals("-o")) { open = true; } } }
From source file:com.github.alexfalappa.nbspringboot.codegen.SpringDependencyDialog.java
/** Creates new form NewOkCancelDialog */ public SpringDependencyDialog(java.awt.Frame parent) { super(parent, true); initComponents();/*from ww w. j av a2s. c o m*/ // Close the dialog when Esc is pressed String cancelName = "cancel"; InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT); inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), cancelName); ActionMap actionMap = rootPane.getActionMap(); actionMap.put(cancelName, new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { doClose(RET_CANCEL); } }); }
From source file:com.sshtools.common.ui.NewWindowAction.java
/** * Creates a new NewWindowAction object. * * @param application/*from ww w . jav a 2 s . c o m*/ */ public NewWindowAction(SshToolsApplication application) { this.application = application; putValue(Action.NAME, "New Window"); putValue(Action.SMALL_ICON, getIcon("/com/sshtools/common/ui/newwindow.png")); putValue(LARGE_ICON, getIcon("/com/sshtools/common/ui/largenewwindow.png")); putValue(Action.SHORT_DESCRIPTION, "Create new window"); putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_W, KeyEvent.ALT_MASK)); putValue(Action.LONG_DESCRIPTION, "Create a new SSHTerm window"); putValue(Action.MNEMONIC_KEY, new Integer('w')); putValue(Action.ACTION_COMMAND_KEY, "new-window"); putValue(StandardAction.ON_MENUBAR, new Boolean(true)); putValue(StandardAction.MENU_NAME, "File"); putValue(StandardAction.MENU_ITEM_GROUP, new Integer(0)); putValue(StandardAction.MENU_ITEM_WEIGHT, new Integer(90)); putValue(StandardAction.ON_TOOLBAR, new Boolean(true)); putValue(StandardAction.TOOLBAR_GROUP, new Integer(0)); putValue(StandardAction.TOOLBAR_WEIGHT, new Integer(90)); }
From source file:FramewithMenuShortcut.java
public FramewithMenuShortcut(String title) { JMenu fileMenu = new JMenu("File"); // Create File menu JMenu elementMenu = new JMenu("Elements"); // Create Elements menu fileMenu.setMnemonic('F'); // Create shortcut elementMenu.setMnemonic('E'); // Create shortcut setDefaultCloseOperation(EXIT_ON_CLOSE); setJMenuBar(menuBar);//from w w w . j a va2 s . com newItem = fileMenu.add("New"); openItem = fileMenu.add("Open"); closeItem = fileMenu.add("Close"); fileMenu.addSeparator(); saveItem = fileMenu.add("Save"); saveAsItem = fileMenu.add("Save As..."); fileMenu.addSeparator(); printItem = fileMenu.add("Print"); elementMenu.add(lineItem = new JRadioButtonMenuItem("Line", true)); elementMenu.add(rectangleItem = new JRadioButtonMenuItem("Rectangle", false)); elementMenu.add(circleItem = new JRadioButtonMenuItem("Circle", false)); ButtonGroup types = new ButtonGroup(); types.add(lineItem); types.add(rectangleItem); types.add(circleItem); elementMenu.addSeparator(); elementMenu.add(redItem = new JCheckBoxMenuItem("Red", false)); elementMenu.add(yellowItem = new JCheckBoxMenuItem("Yellow", false)); menuBar.add(fileMenu); menuBar.add(elementMenu); newItem.setAccelerator(KeyStroke.getKeyStroke('N', CTRL_DOWN_MASK)); openItem.setAccelerator(KeyStroke.getKeyStroke('O', CTRL_DOWN_MASK)); saveItem.setAccelerator(KeyStroke.getKeyStroke('S', CTRL_DOWN_MASK)); printItem.setAccelerator(KeyStroke.getKeyStroke('P', CTRL_DOWN_MASK)); lineItem.setAccelerator(KeyStroke.getKeyStroke('L', CTRL_DOWN_MASK)); rectangleItem.setAccelerator(KeyStroke.getKeyStroke('E', CTRL_DOWN_MASK)); circleItem.setAccelerator(KeyStroke.getKeyStroke('I', CTRL_DOWN_MASK)); elementMenu.addSeparator(); redItem.setAccelerator(KeyStroke.getKeyStroke('R', CTRL_DOWN_MASK)); yellowItem.setAccelerator(KeyStroke.getKeyStroke('Y', CTRL_DOWN_MASK)); menuBar.add(fileMenu); menuBar.add(elementMenu); }
From source file:Main.java
public FramewithMenuShortcut() { JMenu fileMenu = new JMenu("File"); // Create File menu JMenu elementMenu = new JMenu("Elements"); // Create Elements menu fileMenu.setMnemonic('F'); // Create shortcut elementMenu.setMnemonic('E'); // Create shortcut setDefaultCloseOperation(EXIT_ON_CLOSE); setJMenuBar(menuBar);/*w ww.j a v a 2 s.c om*/ newItem = fileMenu.add("New"); openItem = fileMenu.add("Open"); closeItem = fileMenu.add("Close"); fileMenu.addSeparator(); saveItem = fileMenu.add("Save"); saveAsItem = fileMenu.add("Save As..."); fileMenu.addSeparator(); printItem = fileMenu.add("Print"); elementMenu.add(lineItem = new JRadioButtonMenuItem("Line", true)); elementMenu.add(rectangleItem = new JRadioButtonMenuItem("Rectangle", false)); elementMenu.add(circleItem = new JRadioButtonMenuItem("Circle", false)); ButtonGroup types = new ButtonGroup(); types.add(lineItem); types.add(rectangleItem); types.add(circleItem); elementMenu.addSeparator(); elementMenu.add(redItem = new JCheckBoxMenuItem("Red", false)); elementMenu.add(yellowItem = new JCheckBoxMenuItem("Yellow", false)); menuBar.add(fileMenu); menuBar.add(elementMenu); newItem.setAccelerator(KeyStroke.getKeyStroke('N', CTRL_DOWN_MASK)); openItem.setAccelerator(KeyStroke.getKeyStroke('O', CTRL_DOWN_MASK)); saveItem.setAccelerator(KeyStroke.getKeyStroke('S', CTRL_DOWN_MASK)); printItem.setAccelerator(KeyStroke.getKeyStroke('P', CTRL_DOWN_MASK)); lineItem.setAccelerator(KeyStroke.getKeyStroke('L', CTRL_DOWN_MASK)); rectangleItem.setAccelerator(KeyStroke.getKeyStroke('E', CTRL_DOWN_MASK)); circleItem.setAccelerator(KeyStroke.getKeyStroke('I', CTRL_DOWN_MASK)); elementMenu.addSeparator(); redItem.setAccelerator(KeyStroke.getKeyStroke('R', CTRL_DOWN_MASK)); yellowItem.setAccelerator(KeyStroke.getKeyStroke('Y', CTRL_DOWN_MASK)); menuBar.add(fileMenu); menuBar.add(elementMenu); }
From source file:com.sshtools.sshterm.FullScreenAction.java
public FullScreenAction(SshToolsApplication application, SshToolsApplicationContainer container) { this.application = application; this.container = container; putValue(Action.NAME, NAME_FULL_SCREEN); putValue(Action.SMALL_ICON, getIcon(SMALL_ICON_FULL_SCREEN)); putValue(LARGE_ICON, getIcon(LARGE_ICON_FULL_SCREEN)); putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.ALT_MASK)); putValue(Action.SHORT_DESCRIPTION, SHORT_DESCRIPTION_FULL_SCREEN); putValue(Action.LONG_DESCRIPTION, LONG_DESCRIPTION_FULL_SCREEN); putValue(Action.MNEMONIC_KEY, new Integer(MNEMONIC_KEY_FULL_SCREEN)); putValue(Action.ACTION_COMMAND_KEY, ACTION_COMMAND_KEY_FULL_SCREEN); putValue(StandardAction.ON_MENUBAR, new Boolean(true)); putValue(StandardAction.MENU_NAME, "View"); putValue(StandardAction.MENU_ITEM_GROUP, new Integer(20)); putValue(StandardAction.MENU_ITEM_WEIGHT, new Integer(20)); putValue(StandardAction.ON_TOOLBAR, new Boolean(true)); putValue(StandardAction.TOOLBAR_GROUP, new Integer(5)); putValue(StandardAction.TOOLBAR_WEIGHT, new Integer(30)); }
From source file:com.sshtools.powervnc.VncFullScreenAction.java
public VncFullScreenAction(SshToolsApplication application, SshToolsApplicationContainer container) { this.application = application; this.container = container; putValue(Action.NAME, NAME_FULL_SCREEN); putValue(Action.SMALL_ICON, getIcon(SMALL_ICON_FULL_SCREEN)); putValue(LARGE_ICON, getIcon(LARGE_ICON_FULL_SCREEN)); putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_F, KeyEvent.ALT_MASK)); putValue(Action.SHORT_DESCRIPTION, SHORT_DESCRIPTION_FULL_SCREEN); putValue(Action.LONG_DESCRIPTION, LONG_DESCRIPTION_FULL_SCREEN); putValue(Action.MNEMONIC_KEY, new Integer(MNEMONIC_KEY_FULL_SCREEN)); putValue(Action.ACTION_COMMAND_KEY, ACTION_COMMAND_KEY_FULL_SCREEN); putValue(StandardAction.ON_MENUBAR, new Boolean(true)); putValue(StandardAction.MENU_NAME, "View"); putValue(StandardAction.MENU_ITEM_GROUP, new Integer(20)); putValue(StandardAction.MENU_ITEM_WEIGHT, new Integer(20)); putValue(StandardAction.ON_TOOLBAR, new Boolean(true)); putValue(StandardAction.TOOLBAR_GROUP, new Integer(5)); putValue(StandardAction.TOOLBAR_WEIGHT, new Integer(30)); }
From source file:com.microsoft.alm.plugin.idea.common.ui.common.forms.TfsLoginForm.java
@Override public void addActionListener(final ActionListener listener) { // Hook up listener to all actions signInLink.addActionListener(listener); serverUrl.registerKeyboardAction(listener, LoginForm.CMD_SIGN_IN, KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), JComponent.WHEN_IN_FOCUSED_WINDOW); }