List of usage examples for javax.swing KeyStroke toString
public String toString()
From source file:Main.java
/** * Registers an action for a key-stroke in a component. * @param actionName The name for the action related to the keystroke. If null, the keystroke description is used. * @param focusType e.g. {@link JComponent#WHEN_FOCUSED} * @param ks The keystroke that activates the action. *//*from w w w . j a va2 s . c om*/ public static void setKeyAction(JComponent component, Action action, String actionName, int focusType, KeyStroke ks) { if (actionName == null) { actionName = ks.toString(); } component.getInputMap(focusType).put(ks, actionName); component.getActionMap().put(actionName, action); }
From source file:com.qtplaf.library.util.StringUtils.java
/** * Returns a string representation of a key stroke. * /*from ww w .j a v a2s. c o m*/ * @param keyStroke The key stroke. * @return The string representation. */ public static String toString(KeyStroke keyStroke) { String[] tokens = split(keyStroke.toString(), " "); StringBuilder b = new StringBuilder(); for (String token : tokens) { if (token.equals("typed") || token.equals("released") || token.equals("pressed")) { continue; } if (b.length() > 0) { b.append(" "); } b.append(capitalize(token.toLowerCase())); } return b.toString(); }
From source file:com.net2plan.gui.GUINet2Plan.java
private void showKeyCombinations() { Component component = container.getComponent(0); if (!(component instanceof IGUIModule)) { ErrorHandling.showErrorDialog("No tool is active", "Unable to show key associations"); return;//from ww w . j a v a2s . co m } final JDialog dialog = new JDialog(); dialog.setTitle("Key combinations"); SwingUtils.configureCloseDialogOnEscape(dialog); dialog.setModalityType(Dialog.ModalityType.APPLICATION_MODAL); dialog.setSize(new Dimension(500, 300)); dialog.setLocationRelativeTo(null); dialog.setDefaultCloseOperation(WindowConstants.HIDE_ON_CLOSE); dialog.setLayout(new MigLayout("fill, insets 0 0 0 0")); final String[] tableHeader = StringUtils.arrayOf("Key combination", "Action"); DefaultTableModel model = new ClassAwareTableModel(); model.setDataVector(new Object[1][tableHeader.length], tableHeader); AdvancedJTable table = new AdvancedJTable(model); JScrollPane scrollPane = new JScrollPane(table); dialog.add(scrollPane, "grow"); RowSorter<TableModel> sorter = new TableRowSorter<TableModel>(model); table.setRowSorter(sorter); table.getTableHeader().addMouseListener(new ColumnFitAdapter()); IGUIModule module = (IGUIModule) component; Map<String, KeyStroke> keyCombinations = module.getKeyCombinations(); if (!keyCombinations.isEmpty()) { model.removeRow(0); for (Entry<String, KeyStroke> keyCombination : keyCombinations.entrySet()) { String description = keyCombination.getKey(); KeyStroke keyStroke = keyCombination.getValue(); model.addRow(StringUtils.arrayOf(description, keyStroke.toString().replaceAll(" pressed ", " "))); } } dialog.setVisible(true); }
From source file:com.t3.client.ui.T3Frame.java
private void updateKeyStrokes(JComponent c) { c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).clear(); Map<KeyStroke, MacroButton> keyStrokeMap = MacroButtonHotKeyManager.getKeyStrokeMap(); if (c.getActionMap().keys() != null) { for (Object o : c.getActionMap().keys()) { // We're looking for MacroButton here, but we're adding AbstractActions below... Is this right? XXX if (o instanceof MacroButton) { if (log.isInfoEnabled()) log.info("Removing MacroButton " + ((MacroButton) o).getButtonText()); c.getActionMap().remove(o); }//from ww w .ja va 2 s . c om } } for (KeyStroke keyStroke : keyStrokeMap.keySet()) { final MacroButton button = keyStrokeMap.get(keyStroke); if (button != null) { c.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, button); c.getActionMap().put(button, new MTButtonHotKeyAction(button)); } else { // This shouldn't be possible... log.error("No MacroButton found for keyStroke " + keyStroke.toString()); } } }
From source file:org.sleeksnap.gui.options.HotkeyPanel.java
public static String formatKeyStroke(final KeyStroke stroke) { if (stroke == null) { return Language.getString("hotkeyNotSet"); }//from w ww . j av a2s .c o m String s = stroke.toString(); s = s.replace("released ", ""); s = s.replace("typed ", ""); s = s.replace("pressed ", ""); final StringBuilder out = new StringBuilder(); final String[] split = s.split(" "); for (int i = 0; i < split.length; i++) { String str = split[i]; if (str.contains("_")) { str = str.replace('_', ' '); } out.append(Util.ucwords(str)); if (i != (split.length - 1)) { out.append(" + "); } } return out.toString(); }
From source file:org.zaproxy.zap.extension.keyboard.ExtensionKeyboard.java
private KeyboardMapping menuToMapping(ZapMenuItem menuItem) { KeyStroke ks = this.getKeyboardParam().getShortcut(menuItem.getIdenfifier()); if (ks != null) { if (ks.getKeyCode() == 0) { // Used to indicate no accelerator should be used logger.debug("Cleaning menu " + menuItem.getIdenfifier() + " accelerator"); menuItem.setAccelerator(null); } else {//from w w w .jav a 2 s.com logger.debug("Setting menu " + menuItem.getIdenfifier() + " accelerator to " + ks.toString()); menuItem.setAccelerator(ks); } } return new KeyboardMapping(menuItem); }
From source file:org.zaproxy.zap.extension.keyboard.ExtensionKeyboard.java
private KeyboardShortcut menuToShortcut(ZapMenuItem menuItem, boolean reset) { if (reset) {// w ww.j a v a 2 s . co m return new KeyboardShortcut(menuItem.getIdenfifier(), menuItem.getText(), menuItem.getDefaultAccelerator()); } KeyStroke ks = this.getKeyboardParam().getShortcut(menuItem.getIdenfifier()); if (ks != null) { if (ks.getKeyCode() == 0) { // Used to indicate no accelerator should be used logger.debug("Cleaning menu " + menuItem.getIdenfifier() + " accelerator"); menuItem.setAccelerator(null); } else { logger.debug("Setting menu " + menuItem.getIdenfifier() + " accelerator to " + ks.toString()); menuItem.setAccelerator(ks); } } return new KeyboardShortcut(menuItem.getIdenfifier(), menuItem.getText(), menuItem.getAccelerator()); }