javax.swing.KeyStroke Java Examples

The following examples show how to use javax.swing.KeyStroke. 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: EditorKeyboardHandler.java    From blog-codes with Apache License 2.0 6 votes vote down vote up
/**
 * Return JTree's input map.
 */
protected InputMap getInputMap(int condition)
{
	InputMap map = super.getInputMap(condition);

	if (condition == JComponent.WHEN_FOCUSED && map != null)
	{
		map.put(KeyStroke.getKeyStroke("control S"), "save");
		map.put(KeyStroke.getKeyStroke("control shift S"), "saveAs");
		map.put(KeyStroke.getKeyStroke("control N"), "new");
		map.put(KeyStroke.getKeyStroke("control O"), "open");

		map.put(KeyStroke.getKeyStroke("control Z"), "undo");
		map.put(KeyStroke.getKeyStroke("control Y"), "redo");
		map
				.put(KeyStroke.getKeyStroke("control shift V"),
						"selectVertices");
		map.put(KeyStroke.getKeyStroke("control shift E"), "selectEdges");
	}

	return map;
}
 
Example #2
Source File: frmReleaseNote.java    From Course_Generator with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Manage low level key strokes ESCAPE : Close the window
 *
 * @return
 */
protected JRootPane createRootPane() {
	JRootPane rootPane = new JRootPane();
	KeyStroke strokeEscape = KeyStroke.getKeyStroke("ESCAPE");

	@SuppressWarnings("serial")
	Action actionListener = new AbstractAction() {
		public void actionPerformed(ActionEvent actionEvent) {
			setVisible(false);
		}
	};

	InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
	inputMap.put(strokeEscape, "ESCAPE");
	rootPane.getActionMap().put("ESCAPE", actionListener);

	return rootPane;
}
 
Example #3
Source File: FreeColAction.java    From freecol with GNU General Public License v2.0 6 votes vote down vote up
/**
 * Creates a new {@code FreeColAction}.
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param id The object identifier for this action.
 */
protected FreeColAction(FreeColClient freeColClient, String id) {
    super(Messages.getName(id));

    this.freeColClient = freeColClient;

    putValue(ACTION_ID, id);

    String shortDescription = Messages.getDescription(id);
    if (!shortDescription.equals(Messages.descriptionKey(id))) {
        putValue(SHORT_DESCRIPTION, shortDescription);
    }

    String acceleratorKey = id + ".accelerator";
    String accelerator = Messages.message(acceleratorKey);
    if (!accelerator.equals(acceleratorKey)) {
        setAccelerator(KeyStroke.getKeyStroke(accelerator));
    }
}
 
Example #4
Source File: FindPanel.java    From ramus with GNU General Public License v3.0 6 votes vote down vote up
/**
 * This method initializes this
 *
 * @return void
 */
private void initialize() {
    setLayout(new BorderLayout());
    this.setSize(581, 39);
    this.add(getJPanel(), java.awt.BorderLayout.WEST);
    setFocusable(true);
    final AbstractAction aa = new AbstractAction() {

        /**
         *
         */
        private static final long serialVersionUID = 1L;

        public void actionPerformed(ActionEvent e) {
            findNext(jTextField.getText(), jCheckBox.isSelected());
        }

    };

    this.getInputMap().put(KeyStroke.getKeyStroke("F3"), "FindNext");
    this.getActionMap().put("FindNext", aa);
    getJTextField().getInputMap().put(KeyStroke.getKeyStroke("F3"),
            "FindNext");
    getJTextField().getActionMap().put("FindNext", aa);
}
 
Example #5
Source File: CompareResultImages.java    From diirt with MIT License 6 votes vote down vote up
/**
 * Creates new form CompareResultImages
 */
public CompareResultImages() {
    initComponents();
    toReviewList.setModel(new DefaultListModel());
    fillList();
    setSize(800, 600);
    setExtendedState(getExtendedState() | MAXIMIZED_BOTH);
    actualImage.setStretch(false);
    referenceImage.setStretch(false);
    acceptAction.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke("control D"));

    InputMap keyMap = new ComponentInputMap(acceptButton);
    keyMap.put(KeyStroke.getKeyStroke("control D"), "accept");

    ActionMap actionMap = new ActionMapUIResource();
    actionMap.put("accept", acceptAction);

    SwingUtilities.replaceUIActionMap(acceptButton, actionMap);
    SwingUtilities.replaceUIInputMap(acceptButton, JComponent.WHEN_IN_FOCUSED_WINDOW, keyMap);
}
 
Example #6
Source File: ConfirmDialog.java    From rapidminer-studio with GNU Affero General Public License v3.0 6 votes vote down vote up
@Override
protected JButton makeCancelButton() {
	ResourceAction cancelAction = new ResourceAction("cancel") {

		private static final long serialVersionUID = -8887199234055845095L;

		@Override
		public void loggedActionPerformed(ActionEvent e) {
			returnOption = CANCEL_OPTION;
			cancel();
		}
	};
	JButton cancelButton = new JButton(cancelAction);
	getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(
			KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false), "CANCEL");
	getRootPane().getActionMap().put("CANCEL", cancelAction);

	return cancelButton;
}
 
Example #7
Source File: Actions.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/** Same method as above, but works just with plain actions.
 */
private static String findKey(Action action) {
    if (action == null) {
        return null;
    }

    KeyStroke accelerator = (KeyStroke) action.getValue(Action.ACCELERATOR_KEY);

    if (accelerator == null) {
        return null;
    }

    int modifiers = accelerator.getModifiers();
    String acceleratorText = ""; // NOI18N

    if (modifiers > 0) {
        acceleratorText = KeyEvent.getKeyModifiersText(modifiers);
        acceleratorText += "+"; // NOI18N
    } else if (accelerator.getKeyCode() == KeyEvent.VK_UNDEFINED) {
        return ""; // NOI18N
    }

    acceleratorText += KeyEvent.getKeyText(accelerator.getKeyCode());

    return acceleratorText;
}
 
Example #8
Source File: testRefactor.java    From netbeans with Apache License 2.0 6 votes vote down vote up
public void testInstantRefactor() {
    startTest();
    createSampleProject("NB Project Generators", testRefactor.TEST_BASE_NAME + testRefactor.name_iterator);
    openFile("generators|NetBeansModule.groovy", testRefactor.TEST_BASE_NAME + testRefactor.name_iterator);
    waitScanFinished();
    EditorOperator ep = new EditorOperator("NetBeansModule.groovy");
    ep.setCaretPosition(7, 7);
    evt.waitNoEvent(2000);
    new org.netbeans.jellytools.actions.Action(null, null, KeyStroke.getKeyStroke(KeyEvent.VK_R, 2)).performShortcut(ep);
    type(ep, "packg");
    ep.pressKey(KeyEvent.VK_ENTER);
    assertTrue("file not refactored - contains old value: \n" + ep.getText(), !ep.getText().contains("pkgs"));
    assertTrue("file not refactored - does not contain new value: \n" + ep.getText(), ep.getText().contains("packg"));
    testRefactor.name_iterator++;
    endTest();
}
 
Example #9
Source File: DropdownButton.java    From netbeans with Apache License 2.0 6 votes vote down vote up
Popup() {
    super(" "); // NOI18N
    
    // See GenericToolbar.addImpl()
    putClientProperty("MetalListener", new Object()); // NOI18N
    
    setModel(new DefaultButtonModel() {
        public boolean isRollover() {
            return super.isRollover() || pushed;
        }
    });
    
    setHorizontalAlignment(LEADING);
    setDefaultCapable(false);
    
    getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, false), NO_ACTION);
    getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_SPACE, 0, true), NO_ACTION);
}
 
Example #10
Source File: MelodyPanel.java    From javamelody with Apache License 2.0 6 votes vote down vote up
final MButton createRefreshButton() {
	final MButton refreshButton = new MButton(getString("Actualiser"),
			ImageIconCache.getImageIcon("action_refresh.png"));
	refreshButton.setToolTipText(getString("Rafraichir") + " (F5)");
	refreshButton.setActionCommand("refresh");
	refreshButton.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
			.put(KeyStroke.getKeyStroke("F5"), "doRefresh");
	refreshButton.getActionMap().put("doRefresh", new AbstractAction() {
		private static final long serialVersionUID = 1L;

		@Override
		public void actionPerformed(ActionEvent e) {
			refreshButton.doClick();
		}
	});
	return refreshButton;
}
 
Example #11
Source File: KeyStrokeUtils.java    From netbeans with Apache License 2.0 6 votes vote down vote up
/**
 * Convert an array of {@link KeyStroke key stroke} to a string composed of
 * human-readable names of these key strokes, delimited by {@code delim}.
 */
public static String getKeyStrokesAsText(
        @NullAllowed KeyStroke[] keyStrokes, @NonNull String delim) {
    if (keyStrokes == null) {
        return "";                                                  //NOI18N
    }
    if (keyStrokes.length == 0) {
        return "";                                                  //NOI18N
    }
    StringBuilder sb = new StringBuilder(getKeyStrokeAsText(keyStrokes[0]));
    int i, k = keyStrokes.length;
    for (i = 1; i < k; i++) {
        sb.append(delim).append(getKeyStrokeAsText(keyStrokes[i]));
    }
    return new String(sb);
}
 
Example #12
Source File: ControllersGlobalTest.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void testGoToController() {
    EditorOperator app = new EditorOperator("app.js");
    app.setCaretPosition("rl1", true);
    new org.netbeans.jellytools.actions.Action(null, null, KeyStroke.getKeyStroke(KeyEvent.VK_B, 2)).performShortcut(app);
    evt.waitNoEvent(500);
    EditorOperator ed = new EditorOperator("controllers.js");
    int position = ed.txtEditorPane().getCaretPosition();
    ed.setCaretPosition(5, 10);
    int expectedPosition = ed.txtEditorPane().getCaretPosition();
    assertTrue("Incorrect caret position. Expected position " + expectedPosition + " but was " + position, position == expectedPosition);
}
 
Example #13
Source File: CodeTemplateManagerOperation.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private static String getExpandKeyStrokeText(KeyStroke keyStroke) {
    String expandKeyStrokeText;
    if (keyStroke.equals(KeyStroke.getKeyStroke(' '))) { //NOI18N
        expandKeyStrokeText = "SPACE"; // NOI18N
    } else if (keyStroke.equals(KeyStroke.getKeyStroke(new Character(' '), InputEvent.SHIFT_MASK))) { //NOI18N
        expandKeyStrokeText = "Shift-SPACE"; // NOI18N
    } else if (keyStroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0))) {
        expandKeyStrokeText = "TAB"; // NOI18N
    } else if (keyStroke.equals(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0))) {
        expandKeyStrokeText = "ENTER"; // NOI18N
    } else {
        expandKeyStrokeText = keyStroke.toString();
    }
    return expandKeyStrokeText;
}
 
Example #14
Source File: ButtonEsc.java    From megamek with GNU General Public License v2.0 5 votes vote down vote up
/** 
 * Constructs a {@link javax.swing.JButton JButton} that will react
 * to ESC key presses by calling the 
 * {@link javax.swing.AbstractAction Action}
 * <code>escAction</code> when the button is in a focused window
 */
public ButtonEsc(AbstractAction escAction) {
    super(escAction);
    
    // Link ESC to the escAction
    getActionMap().put(MYACTION, escAction);
    InputMap imap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), MYACTION);
}
 
Example #15
Source File: JPQLEditorTopComponent.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public JPQLEditorPopupMouseAdapter() {
    super();
    popupMenu = new JPopupMenu();
    ActionListener actionListener = new PopupActionListener();
    runJPQLMenuItem = popupMenu.add(RUN_JPQL_COMMAND);
    runJPQLMenuItem.setMnemonic('Q');
    runJPQLMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_H, InputEvent.ALT_MASK | InputEvent.SHIFT_MASK, false));
    runJPQLMenuItem.addActionListener(actionListener);

    popupMenu.addSeparator();

    cutMenuItem = popupMenu.add(CUT_COMMAND);
    cutMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK, true));
    cutMenuItem.setMnemonic('t');
    cutMenuItem.addActionListener(actionListener);

    copyMenuItem = popupMenu.add(COPY_COMMAND);
    copyMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_MASK, true));
    copyMenuItem.setMnemonic('y');
    copyMenuItem.addActionListener(actionListener);

    pasteMenuItem = popupMenu.add(PASTE_COMMAND);
    pasteMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_MASK, true));
    pasteMenuItem.setMnemonic('P');
    pasteMenuItem.addActionListener(actionListener);

    popupMenu.addSeparator();

    selectAllMenuItem = popupMenu.add(SELECT_ALL_COMMAND);
    selectAllMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.CTRL_MASK, true));
    selectAllMenuItem.setMnemonic('A');
    selectAllMenuItem.addActionListener(actionListener);
}
 
Example #16
Source File: NbEditorToolBar.java    From netbeans with Apache License 2.0 5 votes vote down vote up
/** Attempt to find the editor keystroke for the given action. */
private KeyStroke[] findEditorKeys(String editorActionName, KeyStroke defaultKey) {
    KeyStroke[] ret = new KeyStroke[] { defaultKey };
    JTextComponent comp = getComponent();
    if (editorActionName != null && comp != null) {
        TextUI textUI = comp.getUI();
        Keymap km = comp.getKeymap();
        if (textUI != null && km != null) {
            EditorKit kit = textUI.getEditorKit(comp);
            if (kit instanceof BaseKit) {
                Action a = ((BaseKit)kit).getActionByName(editorActionName);
                if (a != null) {
                    KeyStroke[] keys = km.getKeyStrokesForAction(a);
                    if (keys != null && keys.length > 0) {
                        ret = keys;
                    } else {
                        // try kit's keymap
                        Keymap km2 = ((BaseKit)kit).getKeymap();
                        KeyStroke[] keys2 = km2.getKeyStrokesForAction(a);
                        if (keys2 != null && keys2.length > 0) {
                            ret = keys2;
                        }                            
                    }
                }
            }
        }
    }
    return ret;
}
 
Example #17
Source File: FPortecle.java    From portecle with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct action.
 */
public ExamineCsrAction()
{
	putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(
	    RB.getString("FPortecle.ExamineCsrAction.accelerator").charAt(0), InputEvent.CTRL_MASK));
	putValue(LONG_DESCRIPTION, RB.getString("FPortecle.ExamineCsrAction.statusbar"));
	putValue(MNEMONIC_KEY, Integer.valueOf(RB.getString("FPortecle.ExamineCsrAction.mnemonic").charAt(0)));
	putValue(NAME, RB.getString("FPortecle.ExamineCsrAction.text"));
	putValue(SHORT_DESCRIPTION, RB.getString("FPortecle.ExamineCsrAction.tooltip"));
	putValue(SMALL_ICON, new ImageIcon(getResImage("FPortecle.ExamineCsrAction.image")));
	setEnabled(true);
}
 
Example #18
Source File: DefaultInputHandler.java    From rapidminer-studio with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Adds a key binding to this input handler. The key binding is a list of white space separated
 * key strokes of the form <i>[modifiers+]key</i> where modifier is C for Control, A for Alt, or
 * S for Shift, and key is either a character (a-z) or a field name in the KeyEvent class
 * prefixed with VK_ (e.g., BACK_SPACE)
 * 
 * @param keyBinding
 *            The key binding
 * @param action
 *            The action
 */
@Override
@SuppressWarnings("unchecked")
public void addKeyBinding(String keyBinding, ActionListener action) {
	Hashtable<KeyStroke, Object> current = bindings;

	StringTokenizer st = new StringTokenizer(keyBinding);
	while (st.hasMoreTokens()) {
		KeyStroke keyStroke = parseKeyStroke(st.nextToken());
		if (keyStroke == null) {
			return;
		}

		if (st.hasMoreTokens()) {
			Object o = current.get(keyStroke);
			if (o instanceof Hashtable) {
				current = (Hashtable<KeyStroke, Object>) o;
			} else {
				o = new Hashtable<>();
				current.put(keyStroke, o);
				current = (Hashtable<KeyStroke, Object>) o;
			}
		} else {
			current.put(keyStroke, action);
		}
	}
}
 
Example #19
Source File: OptionsPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
private void initActions () {
    if (getActionMap ().get("PREVIOUS") == null) {//NOI18N
        InputMap inputMap = getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
        
        inputMap.put (KeyStroke.getKeyStroke (KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK | KeyEvent.SHIFT_DOWN_MASK), "PREVIOUS");//NOI18N
        getActionMap ().put ("PREVIOUS", new PreviousAction ());//NOI18N
        
        inputMap.put (KeyStroke.getKeyStroke (KeyEvent.VK_TAB, KeyEvent.CTRL_DOWN_MASK),"NEXT");//NOI18N
        getActionMap ().put ("NEXT", new NextAction ());//NOI18N
    }
}
 
Example #20
Source File: CycleGroupAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
private void initKeyStroke(KeyStroke keyStroke) {
	if (keyStroke == null) {
		return;
	}

	setKeyBindingData(new KeyBindingData(keyStroke));
}
 
Example #21
Source File: ProgressPanel.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void open(JComponent progressComponent) {
    holder.add(progressComponent, BorderLayout.CENTER);

    DialogDescriptor dd = new DialogDescriptor(
            this,
            NbBundle.getMessage(ProgressPanel.class, "MSG_PleaseWait"),
            true,
            new Object[0],
            DialogDescriptor.NO_OPTION,
            DialogDescriptor.DEFAULT_ALIGN,
            null,
            null,
            true);
    dialog = DialogDisplayer.getDefault().createDialog(dd);
    if (dialog instanceof JDialog) {
        JDialog jDialog = ((JDialog)dialog);
        jDialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
        JRootPane rootPane = jDialog.getRootPane();
        rootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "cancel"); // NOI18N
        rootPane.getActionMap().put("cancel", new AbstractAction() { // NOI18N
            public void actionPerformed(ActionEvent event) {
                if (cancelButton.isEnabled()) {
                    cancelButton.doClick();
                }
            }
        });
    }
    dialog.setResizable(false);
    dialog.setVisible(true);
}
 
Example #22
Source File: FPortecle.java    From portecle with GNU General Public License v2.0 5 votes vote down vote up
/**
 * Construct action.
 */
public ExamineCertSSLAction()
{
	putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(
	    RB.getString("FPortecle.ExamineCertSSLAction.accelerator").charAt(0), InputEvent.CTRL_MASK));
	putValue(LONG_DESCRIPTION, RB.getString("FPortecle.ExamineCertSSLAction.statusbar"));
	putValue(MNEMONIC_KEY, Integer.valueOf(RB.getString("FPortecle.ExamineCertSSLAction.mnemonic").charAt(0)));
	putValue(NAME, RB.getString("FPortecle.ExamineCertSSLAction.text"));
	putValue(SHORT_DESCRIPTION, RB.getString("FPortecle.ExamineCertSSLAction.tooltip"));
	putValue(SMALL_ICON, new ImageIcon(getResImage("FPortecle.ExamineCertSSLAction.image")));
	setEnabled(true);
}
 
Example #23
Source File: PopupManager.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public @Override void keyPressed(KeyEvent e){
    if (e != null && popup != null && popup.isShowing()) {
        
        // get popup's registered keyboard actions
        ActionMap am = popup.getActionMap();
        InputMap  im = popup.getInputMap();
        
        // check whether popup registers keystroke
        KeyStroke ks = KeyStroke.getKeyStrokeForEvent(e);
        Object obj = im.get(ks);
        LOG.log(Level.FINE, "Keystroke for event {0}: {1}; action-map-key={2}", new Object [] { e, ks, obj }); //NOI18N
        if (shouldPopupReceiveForwardedKeyboardAction(obj)) {
            // if yes, gets the popup's action for this keystroke, perform it 
            // and consume key event
            Action action = am.get(obj);
            LOG.log(Level.FINE, "Popup component''s action: {0}, {1}", new Object [] { action, action != null ? action.getValue(Action.NAME) : null }); //NOI18N

            /* Make sure to use the popup as the source of the action, since the popup is
            also providing the event. Not doing this, and instead invoking actionPerformed
            with a null ActionEvent, was one part of the problem seen in NETBEANS-403. */
            if (SwingUtilities.notifyAction(action, ks, e, popup, e.getModifiers())) {
              e.consume();
              return;
            }
        }

        if (e.getKeyCode() != KeyEvent.VK_CONTROL &&
            e.getKeyCode() != KeyEvent.VK_SHIFT &&
            e.getKeyCode() != KeyEvent.VK_ALT &&
            e.getKeyCode() != KeyEvent.VK_ALT_GRAPH &&
            e.getKeyCode() != KeyEvent.VK_META
        ) {
            // hide tooltip if any was shown
            Utilities.getEditorUI(textComponent).getToolTipSupport().setToolTipVisible(false);
        }
    }
}
 
Example #24
Source File: OurUtil.java    From org.alloytools.alloy with Apache License 2.0 5 votes vote down vote up
/**
 * Construct a new JMenuItem then add it to an existing JMenu.
 *
 * @param parent - the JMenu to add this JMenuItem into (or null if you don't
 *            want to add it to any JMenu yet)
 * @param label - the text to show on the menu
 * @param attrs - a list of attributes to apply onto the new JMenuItem
 *            <p>
 *            If one positive number a is supplied, we call setMnemonic(a)
 *            <p>
 *            If two positive numbers a and b are supplied, and a!=VK_ALT, and
 *            a!=VK_SHIFT, we call setMnemoic(a) and setAccelerator(b)
 *            <p>
 *            If two positive numbers a and b are supplied, and a==VK_ALT or
 *            a==VK_SHIFT, we call setAccelerator(a | b)
 *            <p>
 *            If an ActionListener is supplied, we call addActionListener(x)
 *            <p>
 *            If an Boolean x is supplied, we call setEnabled(x)
 *            <p>
 *            If an Icon x is supplied, we call setIcon(x)
 */
public static JMenuItem menuItem(JMenu parent, String label, Object... attrs) {
    JMenuItem m = new JMenuItem(label, null);
    int accelMask = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    boolean hasMnemonic = false;
    for (Object x : attrs) {
        if (x instanceof Character || x instanceof Integer) {
            int k = (x instanceof Character) ? ((int) ((Character) x)) : ((Integer) x).intValue();
            if (k < 0)
                continue;
            if (k == KeyEvent.VK_ALT) {
                hasMnemonic = true;
                accelMask = accelMask | InputEvent.ALT_MASK;
                continue;
            }
            if (k == KeyEvent.VK_SHIFT) {
                hasMnemonic = true;
                accelMask = accelMask | InputEvent.SHIFT_MASK;
                continue;
            }
            if (!hasMnemonic) {
                m.setMnemonic(k);
                hasMnemonic = true;
            } else
                m.setAccelerator(KeyStroke.getKeyStroke(k, accelMask));
        }
        if (x instanceof ActionListener)
            m.addActionListener((ActionListener) x);
        if (x instanceof Icon)
            m.setIcon((Icon) x);
        if (x instanceof Boolean)
            m.setEnabled((Boolean) x);
    }
    if (parent != null)
        parent.add(m);
    return m;
}
 
Example #25
Source File: InstancesListControllerUI.java    From netbeans with Apache License 2.0 5 votes vote down vote up
public void keyPressed(KeyEvent e) {
    if ((e.getKeyCode() == KeyEvent.VK_CONTEXT_MENU)
            || ((e.getKeyCode() == KeyEvent.VK_F10) && (e.getModifiers() == InputEvent.SHIFT_MASK))) {
        int selectedRow = instancesListTable.getSelectedRow();

        if (selectedRow != -1) {
            Rectangle rowBounds = instancesListTable.getCellRect(selectedRow, 0, true);
            showTablePopup(instancesListTable, rowBounds.x + (rowBounds.width / 2), rowBounds.y + (rowBounds.height / 2));
        }
    } else if (KeyStroke.getAWTKeyStroke(e.getKeyCode(), e.getModifiers()).equals(COPY_ID_KEYSTROKE)) {
        copyIdToClipboard();
    }
}
 
Example #26
Source File: bug6474153.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
private static void checkArray(JTextComponent.KeyBinding[] keyActionArray) {
    if (keyActionArray.length != 1) {
        throw new RuntimeException("Wrong array lenght!");
    }
    if (!DefaultEditorKit.upAction.equals(keyActionArray[0].actionName)) {
        throw new RuntimeException("Wrong action name!");
    }
    if (!KeyStroke.getKeyStroke("UP").equals(keyActionArray[0].key)) {
        throw new RuntimeException("Wrong keystroke!");
    }
}
 
Example #27
Source File: AbstractTableView.java    From ramus with GNU General Public License v3.0 5 votes vote down vote up
public SetElementIconAction() {
    this.putValue(ACTION_COMMAND_KEY, "SetElementIcon");
    this.putValue(
            SMALL_ICON,
            new ImageIcon(getClass().getResource(
                    "/com/ramussoft/gui/set-icon.png")));
    this.putValue(ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_I, KeyEvent.CTRL_MASK));
}
 
Example #28
Source File: TextManager.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
private TextManager(final JTextComponent component) {
	this.component = component;

	ListenerClass listener = new ListenerClass();

	component.addMouseListener(listener);

	jPopupMenu = new JPopupMenu();

	jCut = new JMenuItem(GuiShared.get().cut());
	jCut.setIcon(Images.EDIT_CUT.getIcon());
	jCut.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_DOWN_MASK));
	jCut.setActionCommand(CopyPopupAction.CUT.name());
	jCut.addActionListener(listener);

	jCopy = new JMenuItem(GuiShared.get().copy());
	jCopy.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.CTRL_DOWN_MASK));
	jCopy.setIcon(Images.EDIT_COPY.getIcon());
	jCopy.setActionCommand(CopyPopupAction.COPY.name());
	jCopy.addActionListener(listener);

	jPaste = new JMenuItem(GuiShared.get().paste());
	jPaste.setIcon(Images.EDIT_PASTE.getIcon());
	jPaste.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_DOWN_MASK));
	jPaste.setActionCommand(CopyPopupAction.PASTE.name());
	jPaste.addActionListener(listener);

	CompoundUndoManager undoManager = new CompoundUndoManager(component);

	jUndo = new JMenuItem(undoManager.getUndoAction());
	jUndo.setIcon(Images.EDIT_UNDO.getIcon());

	jRedo = new JMenuItem(undoManager.getRedoAction()); 
	jRedo.setIcon(Images.EDIT_REDO.getIcon());
}
 
Example #29
Source File: PasteAction.java    From ghidra with Apache License 2.0 5 votes vote down vote up
public PasteAction(SymbolTreePlugin plugin, SymbolTreeProvider provider) {
	super("Paste Symbols", plugin.getName());
	setPopupMenuData(new MenuData(new String[] { "Paste" }, PASTE_ICON, "cut/paste"));
	setKeyBindingData(
		new KeyBindingData(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.CTRL_DOWN_MASK),
			KeyBindingPrecedence.ActionMapLevel));
}
 
Example #30
Source File: ExportAction.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public ExportAction() {
    putValue(Action.SHORT_DESCRIPTION, "Export current graph as an SVG file");
    putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.CTRL_MASK));
    lookup = Utilities.actionsGlobalContext();
    result = lookup.lookup(new Lookup.Template<ExportCookie>(ExportCookie.class));
    result.addLookupListener(this);
    resultChanged(null);
}