public String contains(KeyStroke accelerator) { if (accelerator != null) { for (String actionId : db.keySet()) { if (accelerator.equals(db.get(actionId).get(this.accelerator)) || accelerator.equals(db.get(actionId).get(this.alt_accelerator))) return actionId; } } return null; }
public void keyPressed(KeyEvent e) { TreePath selectionPath = mainTree.getSelectionPath(); if (selectionPath == null || mainTree.getSelectionCount() == 0) { return; } if (mainTree.getSelectionCount() == 1) { SoapUITreeNode lastPathComponent = (SoapUITreeNode) selectionPath.getLastPathComponent(); ActionList actions = lastPathComponent.getActions(); if (actions != null) { actions.dispatchKeyEvent(e); } if (!e.isConsumed()) { KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e); if (ks.equals(UISupport.getKeyStroke("alt C"))) { mainTree.collapsePath(selectionPath); e.consume(); } else if (ks.equals(UISupport.getKeyStroke("alt E"))) { mainTree.collapsePath(selectionPath); int row = mainTree.getSelectionRows()[0]; TreePath nextPath = mainTree.getPathForRow(row + 1); TreePath path = mainTree.getPathForRow(row); while (path != null && !path.equals(nextPath)) { mainTree.expandRow(row); path = mainTree.getPathForRow(++row); } e.consume(); } } } else { TreePath[] selectionPaths = mainTree.getSelectionPaths(); List<ModelItem> targets = new ArrayList<ModelItem>(); for (TreePath treePath : selectionPaths) { SoapUITreeNode node = (SoapUITreeNode) treePath.getLastPathComponent(); targets.add(node.getModelItem()); } if (targets.size() > 0) { ActionList actions = ActionListBuilder.buildMultiActions(targets.toArray(new ModelItem[targets.size()])); if (actions.getActionCount() > 0) { actions.dispatchKeyEvent(e); } } } }
public void keyPressed(KeyEvent keyEvent) { AppLogger.finest( "keyModifiers=" + keyEvent.getModifiers() + " keyCode=" + keyEvent.getKeyCode()); int keyCode = keyEvent.getKeyCode(); if (keyCode == KeyEvent.VK_SHIFT || keyCode == KeyEvent.VK_CONTROL || keyCode == KeyEvent.VK_ALT || keyCode == KeyEvent.VK_META) return; KeyStroke pressedKeyStroke = KeyStroke.getKeyStrokeForEvent(keyEvent); if (pressedKeyStroke.equals(lastKeyStroke)) { TableCellEditor activeCellEditor = getCellEditor(); if (activeCellEditor != null) activeCellEditor.stopCellEditing(); } else { String actionId; if ((actionId = data.contains(pressedKeyStroke)) != null) { String errorMessage = "The shortcut [" + KeyStrokeUtils.getKeyStrokeDisplayableRepresentation(pressedKeyStroke) + "] is already assigned to '" + ActionProperties.getActionDescription(actionId) + "'"; tooltipBar.showErrorMessage(errorMessage); createCancelEditingStateThread(getCellEditor()); } else { lastKeyStroke = pressedKeyStroke; setText(KeyStrokeUtils.getKeyStrokeDisplayableRepresentation(lastKeyStroke)); } } keyEvent.consume(); }
public void keyPressed(KeyEvent e) { KeyStroke currentStroke = KeyStroke.getKeyStrokeForEvent(e); if (e.getKeyCode() == KeyEvent.VK_ENTER) { TreePath path = ((JTree) e.getSource()).getSelectionPath(); if (path == null) { return; } AWorkspaceTreeNode node = (AWorkspaceTreeNode) path.getLastPathComponent(); if (node instanceof IWorkspaceNodeActionListener) { ((IWorkspaceNodeActionListener) node) .handleAction( new WorkspaceActionEvent( node, WorkspaceActionEvent.WSNODE_OPEN_DOCUMENT, 0, 0, e.getComponent())); e.consume(); } } else { for (HotKeyIdentifier id : actionKeyMap.keySet()) { if (currentStroke.equals(id.getKeyStroke())) { if (id.accept(e)) { AFreeplaneAction action = WorkspaceController.getAction(actionKeyMap.get(id)); if (action != null) { action.actionPerformed(new ActionEvent(e.getSource(), 0, null)); } else { LogUtils.info("No action set for: " + id.getKeyStroke()); } } e.consume(); break; } } } }
public void keyStrokePressed(KeyStroke keystroke, KeyEvent ke) { if (!keystroke.equals(this.fullscreen_keystroke)) return; if (ke.getComponent() == this.canvas) { this.escapeFromFullsreen(); } else if (ke.getComponent() == this.scrollFrame.getView()) { this.switchToFullsreen(); } }
private void checkForEnter(KeyEvent e) { final KeyStroke keyStroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers()); if (!keyStroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK)) && e.getKeyChar() == KeyEvent.VK_ENTER) { e.consume(); sendMessage(); getChatInputEditor().setText(""); getChatInputEditor().setCaretPosition(0); } else if (keyStroke.equals( KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, KeyEvent.SHIFT_DOWN_MASK))) { final Document document = getChatInputEditor().getDocument(); try { document.insertString(getChatInputEditor().getCaretPosition(), "\n", null); getChatInputEditor().requestFocusInWindow(); chatAreaButton.getButton().setEnabled(true); } catch (BadLocationException badLoc) { } } }
/** * Tests whether there is no other already registered action with the same accelerator key * definition by this notation. Additionally, check all registered actions of this notation's * modules. * * @param keyStroke is the accelerator key to be tested * @return true if there is such a action, false otherwise */ public boolean existAcceleratorKey(final KeyStroke keyStroke) { for (final ProModAction action : notationActionsMap.values()) { final KeyStroke key = (KeyStroke) action.getValue(AbstractAction.ACCELERATOR_KEY); if (key != null && key.equals(keyStroke)) { return true; } } for (final ModuleSpecificActions moduleSpecificActions : moduleActionsMap.values()) { if (moduleSpecificActions.existAcceleratorKey(keyStroke)) { return true; } } return false; }
private void uninstallTracking() { InputMap currMap = SwingUtilities.getUIInputMap(this.jcomp, JComponent.WHEN_FOCUSED); if (currMap != null) { InputMap newMap = new InputMap(); KeyStroke[] kss = currMap.allKeys(); for (int i = 0; i < kss.length; i++) { KeyStroke stroke = kss[i]; Object val = currMap.get(stroke); if (stroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0)) && "flipTextSelection".equals(val)) { continue; } newMap.put(stroke, val); } SwingUtilities.replaceUIInputMap(this.jcomp, JComponent.WHEN_FOCUSED, newMap); } this.jcomp.getActionMap().remove("flipTextSelection"); }
public static Node findAssignedMenuItemNodeRecursively( final DefaultMutableTreeNode menubarNode, final KeyStroke keystroke) { final Enumeration<?> children = menubarNode.children(); while (children.hasMoreElements()) { final Node child = (Node) children.nextElement(); final Object childUserObject = child.getUserObject(); if (childUserObject instanceof JMenuItem) { final JMenuItem childMenuItem = (JMenuItem) childUserObject; if (keystroke.equals(childMenuItem.getAccelerator())) { return child; } } // recurse final Node assignedMenuItemNode = findAssignedMenuItemNodeRecursively(child, keystroke); if (assignedMenuItemNode != null) return assignedMenuItemNode; } return null; }
public void keyPressed(KeyEvent e) { KeyStroke keyStroke = KeyStroke.getKeyStroke(e.getKeyCode(), e.getModifiers()); boolean add = e.getKeyCode() != e.VK_SHIFT && e.getKeyCode() != e.VK_CONTROL && e.getKeyCode() != e.VK_ALT && e.getKeyCode() != e.VK_META && e.getKeyCode() != e.VK_ALT_GRAPH; if (keyStroke.equals(backspaceKS) && !key.equals("")) { // delete last key int i = key.lastIndexOf(' '); if (i < 0) key = ""; else key = key.substring(0, i); tfShortcut.setText(key); } else // add key addKeyStroke(keyStroke, add); e.consume(); }
public Component getTableCellRendererComponent( JTable table, Object value, boolean isSelected, boolean hasFocus, int rowIndex, int vColIndex) { DotBorderedCellLabel label; int columnId; columnId = convertColumnIndexToModel(vColIndex); label = cellLabels[columnId]; // action's icon column: return ImageIcon instance if (columnId == ACTION_DESCRIPTION_COLUMN_INDEX) { Pair<ImageIcon, String> description = (Pair<ImageIcon, String>) value; label.setIcon(description.first); label.setText(description.second); // set cell's foreground color label.setForeground( ThemeCache.foregroundColors[ThemeCache.ACTIVE][ThemeCache.NORMAL][ ThemeCache.PLAIN_FILE]); } // Any other column else { final KeyStroke key = (KeyStroke) value; String text = key == null ? "" : KeyStrokeUtils.getKeyStrokeDisplayableRepresentation(key); // If component's preferred width is bigger than column width then the component is not // entirely // visible so we set a tooltip text that will display the whole text when mouse is over the // component if (table.getColumnModel().getColumn(vColIndex).getWidth() < label.getPreferredSize().getWidth()) label.setToolTipText(text); // Have to set it to null otherwise the defaultRender sets the tooltip text to the last one // specified else label.setToolTipText(null); // Set label's text label.setText(text); // set cell's foreground color if (key != null) { boolean customized; switch (columnId) { case ACCELERATOR_COLUMN_INDEX: customized = !key.equals(ActionProperties.getDefaultAccelerator(data.getActionId(rowIndex))); break; case ALTERNATE_ACCELERATOR_COLUMN_INDEX: customized = !key.equals( ActionProperties.getDefaultAlternativeAccelerator( data.getActionId(rowIndex))); break; default: customized = false; } label.setForeground( ThemeCache.foregroundColors[ThemeCache.ACTIVE][ThemeCache.NORMAL][ customized ? ThemeCache.PLAIN_FILE : ThemeCache.HIDDEN_FILE]); } } // set outline for the focused cell label.setOutline( hasFocus ? ThemeCache.backgroundColors[ThemeCache.ACTIVE][ThemeCache.SELECTED] : null); // set cell's background color label.setBackground( ThemeCache.backgroundColors[ThemeCache.ACTIVE][ rowIndex % 2 == 0 ? ThemeCache.NORMAL : ThemeCache.ALTERNATE]); return label; }