Java Code Examples for javax.swing.KeyStroke

The following are top voted examples for showing how to use javax.swing.KeyStroke. These examples are extracted from open source projects. You can vote up the examples you like and your votes will be used in our system to generate more good examples.
Example 1
Project: ramus   File: FindPanel.java   View source code 7 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 2
Project: myster   File: MysterMenuItemFactory.java   View source code 6 votes vote down vote up
public void makeMenuItem(JFrame frame, JMenu menu) {
    if ("-".equals(name)) {
        menu.addSeparator();
        return;
    }
    
    JMenuItem menuItem = new JMenuItem(com.myster.util.I18n.tr(name));
    if (shortcut != -1) {
        int shiftMask = useShift ? InputEvent.SHIFT_DOWN_MASK : 0;
        menuItem.setAccelerator(KeyStroke.getKeyStroke(shortcut, InputEvent.CTRL_DOWN_MASK|shiftMask));
    }

    if (action != null) {
        menuItem.addActionListener(action);
    }

    menuItem.setEnabled(!isDisabled);

    menu.add(menuItem);
    return;
}
 
Example 3
Project: VASSAL-src   File: Embellishment0.java   View source code 6 votes vote down vote up
/**
 * If the argument GamePiece contains a Layer whose "activate" command matches
 * the given keystroke, and whose active status matches the boolean argument,
 * return that Layer
 */
public static Embellishment getLayerWithMatchingActivateCommand(GamePiece piece, KeyStroke stroke, boolean active) {
  for (Embellishment layer = (Embellishment) Decorator.getDecorator(piece, Embellishment.class); layer != null; layer = (Embellishment) Decorator
      .getDecorator(layer.piece, Embellishment.class)) {
    for (int i = 0; i < layer.activateKey.length(); ++i) {
      if (stroke.equals(KeyStroke.getKeyStroke(layer.activateKey.charAt(i), layer.activateModifiers))) {
        if (active && layer.isActive()) {
          return layer;
        }
        else if (!active && !layer.isActive()) {
          return layer;
        }
        break;
      }
    }
  }
  return null;
}
 
Example 4
Project: VASSAL-src   File: ADC2Module.java   View source code 6 votes vote down vote up
@Override
public Obscurable getHiddenDecorator() throws IOException {
  Obscurable p;
  SequenceEncoder se = new SequenceEncoder(';');
  se.append(new NamedKeyStroke(KeyStroke.getKeyStroke('H', InputEvent.CTRL_MASK))); // key command
  se.append(getHiddenSymbol().getFileName()); // hide image
  se.append("Hide Piece"); // menu name
  BufferedImage image = getSymbol().getImage();
  se.append("G" + getFlagLayer(new Dimension(image.getWidth(), image.getHeight()), StateFlag.MARKER)); // display style
  se.append(getHiddenName()); // mask name
  if (getOwner() == Player.NO_PLAYERS || getOwner() == Player.ALL_PLAYERS) {
    se.append("side:");
  }
  else {
    se.append("sides:" + getOwner().getName()); // owning player
  }
  p = new Obscurable();
  p.mySetType(Obscurable.ID + se.getValue());
  return p;
}
 
Example 5
Project: AWGW   File: WorldFrame.java   View source code 6 votes vote down vote up
private void configureMenuItem(JMenuItem item, String resource, ActionListener listener) {
    configureAbstractButton(item, resource);
    item.addActionListener(listener);
    try {
        String accel = resources.getString(resource + ".accel");
        String metaPrefix = "@";
        if (accel.startsWith(metaPrefix)) {
            int menuMask = getToolkit().getMenuShortcutKeyMask();
            KeyStroke key = KeyStroke.getKeyStroke(
                    KeyStroke.getKeyStroke(accel.substring(metaPrefix.length())).getKeyCode(), menuMask);
            item.setAccelerator(key);
        } else {
            item.setAccelerator(KeyStroke.getKeyStroke(accel));
        }
    } catch (MissingResourceException ex) {
        // no accelerator
    }
}
 
Example 6
Project: vexillo   File: GlazeToggleMenuItem.java   View source code 6 votes vote down vote up
public GlazeToggleMenuItem(final FlagFrame frame) {
	setText("Glaze");
	if (!OSUtils.isMacOS()) setMnemonic(KeyEvent.VK_G);
	setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SLASH, 0));
	if (frame == null) {
		setEnabled(false);
	} else {
		addActionListener(new ActionListener() {
			public void actionPerformed(ActionEvent event) {
				boolean g = !frame.isGlazed();
				frame.setGlaze(g);
				setSelected(g);
			}
		});
	}
}
 
Example 7
Project: incubator-netbeans   File: MacroShortcutsInjector.java   View source code 6 votes vote down vote up
@Override
public void afterLoad(Map<Collection<KeyStroke>, MultiKeyBinding> map, MimePath mimePath, String profile, boolean defaults) {
    Map<String, MacroDescription> macros = new HashMap<String, MacroDescription>();
    if (!collectMacroActions(mimePath, macros)) {
        return;
    }
    
    for(MacroDescription macro : macros.values()) {
        List<? extends MultiKeyBinding> shortcuts = macro.getShortcuts();
        for(MultiKeyBinding shortcut : shortcuts) {
            Collection<KeyStroke> keys = shortcut.getKeyStrokeList();

            // A macro shortcut never replaces shortcuts for ordinary editor actions
            if (!map.containsKey(keys)) {
                map.put(keys, shortcut);
                if (LOG.isLoggable(Level.FINE)) {
                    LOG.fine("afterLoad: injecting " + keys + " for macro '" //NOI18N
                        + macro.getName() + "'; mimePath='" + mimePath.getPath() + "'"); //NOI18N
                }
            } else {
                LOG.warning("Shortcut " + keys + " is bound to '" + map.get(keys).getActionName() //NOI18N
                    + "' for '" + mimePath.getPath() + "' and will not be assigned to '" + macro.getName() + "' macro!"); //NOI18N
            }
        }
    }
}
 
Example 8
Project: incubator-netbeans   File: TextValueCompleter.java   View source code 6 votes vote down vote up
private void showPopup() {
    hidePopup();
    if (completionListModel.getSize() == 0) {
        return;
    }
    // figure out where the text field is,
    // and where its bottom left is
    java.awt.Point los = field.getLocationOnScreen();
    int popX = los.x;
    int popY = los.y + field.getHeight();
    popup = PopupFactory.getSharedInstance().getPopup(field, listScroller, popX, popY);
    field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),ACTION_HIDEPOPUP);
    field.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),ACTION_FILLIN);
    popup.show();
    if (completionList.getSelectedIndex() != -1) {
        completionList.ensureIndexIsVisible(completionList.getSelectedIndex());
    }
}
 
Example 9
Project: incubator-netbeans   File: TextRegionManager.java   View source code 6 votes vote down vote up
Object findActionKey(JTextComponent component) {
    KeyStroke keyStroke;
    switch (actionType) {
        case TAB:
            keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0);
            break;
        case SHIFT_TAB:
            keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_MASK);
            break;
        case ENTER:
            keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0);
            break;
        default:
            throw new IllegalArgumentException();
    }
    // Assume the 'a' character will trigger defaultKeyTypedAction
    Object key = component.getInputMap().get(keyStroke);
    return key;
}
 
Example 10
Project: incubator-netbeans   File: EditorActionUtilities.java   View source code 6 votes vote down vote up
public static String appendKeyMnemonic(StringBuilder sb, KeyStroke key) {
    String sk = org.openide.util.Utilities.keyToString(key);
    int mods = key.getModifiers();
    if ((mods & KeyEvent.CTRL_MASK) != 0) {
        sb.append("Ctrl+"); // NOI18N
    }
    if ((mods & KeyEvent.ALT_MASK) != 0) {
        sb.append("Alt+"); // NOI18N
    }
    if ((mods & KeyEvent.SHIFT_MASK) != 0) {
        sb.append("Shift+"); // NOI18N
    }
    if ((mods & KeyEvent.META_MASK) != 0) {
        sb.append("Meta+"); // NOI18N
    }

    int i = sk.indexOf('-'); //NOI18N
    if (i != -1) {
        sk = sk.substring(i + 1);
    }
    sb.append(sk);

    return sb.toString();
}
 
Example 11
Project: VASSAL-src   File: ADC2Module.java   View source code 6 votes vote down vote up
public DynamicProperty getDynamicPropertyDecorator() {
  SequenceEncoder type = new SequenceEncoder(';');
  type.append("Layer");
  SequenceEncoder constraints = new SequenceEncoder(',');
  constraints.append(true).append(0).append(1).append(true);
  type.append(constraints.getValue());
  SequenceEncoder command = new SequenceEncoder(':');
  KeyStroke stroke = KeyStroke.getKeyStroke('=', InputEvent.SHIFT_DOWN_MASK);
  SequenceEncoder change = new SequenceEncoder(',');
  change.append('I').append(1);
  command.append("Draw on top").append(stroke.getKeyCode() + "," + stroke.getModifiers()).append(change.getValue());
  type.append(new SequenceEncoder(command.getValue(), ',').getValue());
  DynamicProperty dp = new DynamicProperty();
  dp.mySetType(DynamicProperty.ID + type.getValue());
  return dp;
}
 
Example 12
Project: jaer   File: ClassChooserDialog.java   View source code 6 votes vote down vote up
/** Creates new model dialog ClassChooserDialog.
     * @param parent parent Frame
     @param subclassOf a Class that will be used to search the classpath for sublasses of this class; these class names are displayed on the left.
     @param classNames a list of class names that are already chosen, displayed on the right.
     @param defaultClassNames the defaults passed to ClassChooserPanel which replace the chosen list if the Defaults button is pressed.
     */
    public ClassChooserDialog(Frame parent, Class subclassOf, ArrayList<String> classNames, ArrayList<String> defaultClassNames) {
        super(parent, true);
        initComponents();
//        cancelButton.requestFocusInWindow();
        chooserPanel=new ClassChooserPanel(subclassOf,classNames,defaultClassNames);
        businessPanel.add(chooserPanel,BorderLayout.CENTER);
        pack();
        //  Handle escape key to close the dialog
        // from http://forum.java.sun.com/thread.jspa?threadID=462776&messageID=2123119
        
        KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
        Action escapeAction = new AbstractAction() {
            @Override public void actionPerformed(ActionEvent e) {
                dispose();
            }
        };
        getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escape, "ESCAPE");
        getRootPane().getActionMap().put("ESCAPE", escapeAction);
    }
 
Example 13
Project: Logisim   File: MenuSimulate.java   View source code 6 votes vote down vote up
private void recreateStateMenu(JMenu menu, ArrayList<CircuitStateMenuItem> items, int code) {
	menu.removeAll();
	menu.setEnabled(items.size() > 0);
	boolean first = true;
	int mask = getToolkit().getMenuShortcutKeyMask();
	for (int i = items.size() - 1; i >= 0; i--) {
		JMenuItem item = items.get(i);
		menu.add(item);
		if (first) {
			item.setAccelerator(KeyStroke.getKeyStroke(code, mask));
			first = false;
		} else {
			item.setAccelerator(null);
		}
	}
}
 
Example 14
Project: powertext   File: RTextArea.java   View source code 5 votes vote down vote up
/**
 * Sets the properties of one of the actions this text area owns.
 *
 * @param action The action to modify; for example, {@link #CUT_ACTION}.
 * @param name The new name for the action.
 * @param mnemonic The new mnemonic for the action.
 * @param accelerator The new accelerator key for the action.
 */
public static void setActionProperties(int action, String name,
						Integer mnemonic, KeyStroke accelerator) {

	Action tempAction = null;

	switch (action) {
		case CUT_ACTION:
			tempAction = cutAction;
			break;
		case COPY_ACTION:
			tempAction = copyAction;
			break;
		case PASTE_ACTION:
			tempAction = pasteAction;
			break;
		case DELETE_ACTION:
			tempAction = deleteAction;
			break;
		case SELECT_ALL_ACTION:
			tempAction = selectAllAction;
			break;
		case UNDO_ACTION:
		case REDO_ACTION:
		default:
			return;
	}

	tempAction.putValue(Action.NAME, name);
	tempAction.putValue(Action.SHORT_DESCRIPTION, name);
	tempAction.putValue(Action.ACCELERATOR_KEY, accelerator);
	tempAction.putValue(Action.MNEMONIC_KEY, mnemonic);

}
 
Example 15
Project: Neukoelln_SER316   File: HTMLEditor.java   View source code 5 votes vote down vote up
public UndoAction() {
	super(Local.getString("Undo"));
	setEnabled(false);
	putValue(
		Action.SMALL_ICON,
		new ImageIcon(cl.getResource("resources/icons/undo16.png")));
	putValue(
		Action.ACCELERATOR_KEY,
		KeyStroke.getKeyStroke(KeyEvent.VK_Z, KeyEvent.CTRL_MASK));
}
 
Example 16
Project: Neukoelln_SER316   File: HTMLEditor.java   View source code 5 votes vote down vote up
public RedoAction() {
	super(Local.getString("Redo"));
	setEnabled(false);
	putValue(
		Action.SMALL_ICON,
		new ImageIcon(cl.getResource("resources/icons/redo16.png")));
	putValue(
		Action.ACCELERATOR_KEY,
		KeyStroke.getKeyStroke(
			KeyEvent.VK_Z,
			KeyEvent.CTRL_MASK + KeyEvent.SHIFT_MASK));
}
 
Example 17
Project: incubator-netbeans   File: GitStatusTable.java   View source code 5 votes vote down vote up
@Override
protected void setModelProperties () {
    Node.Property [] properties = new Node.Property[3];
    properties[0] = new ColumnDescriptor<>(GitStatusNode.NameProperty.NAME, String.class, GitStatusNode.NameProperty.DISPLAY_NAME, GitStatusNode.NameProperty.DESCRIPTION);
    properties[1] = new ColumnDescriptor<>(GitStatusNode.GitStatusProperty.NAME, String.class, GitStatusNode.GitStatusProperty.DISPLAY_NAME, GitStatusNode.GitStatusProperty.DESCRIPTION);
    properties[2] = new ColumnDescriptor<>(GitStatusNode.PathProperty.NAME, String.class, GitStatusNode.PathProperty.DISPLAY_NAME, GitStatusNode.PathProperty.DESCRIPTION);
    tableModel.setProperties(properties);
    getTable().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
            KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), "DeleteAction");
    getTable().getActionMap().put("DeleteAction", SystemAction.get(DeleteLocalAction.class));
}
 
Example 18
Project: FreeCol   File: EuropePanel.java   View source code 5 votes vote down vote up
public EuropeButton(String text, int keyEvent, String command,
                    ActionListener listener) {
    setOpaque(true);
    setText(text);
    setActionCommand(command);
    addActionListener(listener);
    InputMap closeInputMap = new ComponentInputMap(this);
    closeInputMap.put(KeyStroke.getKeyStroke(keyEvent, 0, false),
                      "pressed");
    closeInputMap.put(KeyStroke.getKeyStroke(keyEvent, 0, true),
                      "released");
    SwingUtilities.replaceUIInputMap(this,
                                     JComponent.WHEN_IN_FOCUSED_WINDOW,
                                     closeInputMap);
}
 
Example 19
Project: incubator-netbeans   File: OptionsPanel.java   View source code 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_LEFT, 0), "PREVIOUS");//NOI18N
        getActionMap ().put ("PREVIOUS", new PreviousAction ());//NOI18N
        
        inputMap.put (KeyStroke.getKeyStroke (KeyEvent.VK_RIGHT, 0),"NEXT");//NOI18N
        getActionMap ().put ("NEXT", new NextAction ());//NOI18N
    }
}
 
Example 20
Project: incubator-netbeans   File: NbKeymapTest.java   View source code 5 votes vote down vote up
public void testKeymapMasksShortcut() throws Exception {
    make("Shortcuts/C-A.instance").setAttribute("instanceCreate", new DummyAction("one"));
    make("Shortcuts/C-C S-B.instance").setAttribute("instanceCreate", new DummyAction("two"));
    make("Shortcuts/C-C S-C.instance").setAttribute("instanceCreate", new DummyAction("four"));
    make("Keymaps/NetBeans/C-C S-B.removed");
    make("Keymaps/NetBeans/C-A.removed");
    make("Keymaps/Eclipse/C-A.instance").setAttribute("instanceCreate", new DummyAction("three"));
    NbKeymap km = new NbKeymap();
    KeyStroke controlA = KeyStroke.getKeyStroke(KeyEvent.VK_A, KeyEvent.CTRL_MASK);
    
    assertNull("should be masked", km.getAction(controlA));
    
    KeyStroke controlC = KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.CTRL_MASK);
    KeyStroke shiftB = KeyStroke.getKeyStroke(KeyEvent.VK_B, KeyEvent.SHIFT_MASK);
    KeyStroke shiftC = KeyStroke.getKeyStroke(KeyEvent.VK_C, KeyEvent.SHIFT_MASK);
    
    Action a = km.getAction(controlC);
    assertNotNull("other binding must prevail", a);
    a.actionPerformed(null);
    
    assertNull("should be masked", km.getAction(shiftB));

    a = km.getAction(controlC);
    a.actionPerformed(null);
    assertEquals("four", km.getAction(shiftC).getValue(Action.NAME));
    
    FileUtil.getConfigFile("Keymaps").setAttribute("currentKeymap", "Eclipse");
    assertTrue(km.waitFinished());
    assertEquals("three", km.getAction(controlA).getValue(Action.NAME));
}
 
Example 21
Project: incubator-netbeans   File: CompletionLayout.java   View source code 5 votes vote down vote up
public void processKeyEvent(KeyEvent evt) {
          if (isVisible()) {
if (KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0).equals(
	KeyStroke.getKeyStrokeForEvent(evt))
) {
    evt.consume();
    CompletionImpl.get().hideToolTip();
}
          }
      }
 
Example 22
Project: incubator-netbeans   File: SwitchTabAction.java   View source code 5 votes vote down vote up
public SwitchTabAction(Terminal context) {
    super(context);

    KeyStroke[] keyStrokes = new KeyStroke[10];
    for (int i = 0; i < 10; i++) {
        keyStrokes[i] = KeyStroke.getKeyStroke(KeyEvent.VK_0 + i, InputEvent.ALT_MASK);
    }
    putValue(ACCELERATOR_KEY, keyStrokes);

    putValue(NAME, getMessage("CTL_SwitchTab")); //NOI18N
}
 
Example 23
Project: incubator-netbeans   File: TreeView.java   View source code 5 votes vote down vote up
ExplorerTree(TreeModel model) {
    super(model);
    toggleClickCount = 0;

    // fix for #18292
    // default action map for JTree defines these shortcuts
    // but we use our own mechanism for handling them
    // following lines disable default L&F handling (if it is
    // defined on Ctrl-c, Ctrl-v and Ctrl-x)
    getInputMap().put(KeyStroke.getKeyStroke("control C"), "none"); // NOI18N
    getInputMap().put(KeyStroke.getKeyStroke("control V"), "none"); // NOI18N
    getInputMap().put(KeyStroke.getKeyStroke("control X"), "none"); // NOI18N
    getInputMap().put(KeyStroke.getKeyStroke("COPY"), "none"); // NOI18N
    getInputMap().put(KeyStroke.getKeyStroke("PASTE"), "none"); // NOI18N
    getInputMap().put(KeyStroke.getKeyStroke("CUT"), "none"); // NOI18N

    if (Utilities.isMac()) {
        getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.META_MASK), "none"); // NOI18N
        getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.META_MASK), "none"); // NOI18N
        getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_V, InputEvent.META_MASK), "none"); // NOI18N
    }

    setupSearch();

    if (!GraphicsEnvironment.isHeadless()) {
        setDragEnabled(true);
    }
}
 
Example 24
Project: incubator-netbeans   File: CompletionScrollPane.java   View source code 5 votes vote down vote up
private void registerKeybinding(int action, String actionName, KeyStroke stroke, String editorActionName, JTextComponent component){
    KeyStroke[] keys = findEditorKeys(editorActionName, stroke, component);
    for (KeyStroke key : keys) {
        getInputMap().put(key, actionName);
    }
    getActionMap().put(actionName, new CompletionPaneAction(action));
}
 
Example 25
Project: incubator-netbeans   File: FilterUtils.java   View source code 5 votes vote down vote up
public KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
    if (!FILTER_ACTION_KEY.equals(actionKey)) return null;
    
    KeyStroke ks = KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_MASK);
    actionMap.put(actionKey, action);
    inputMap.put(ks, actionKey);

    return ks;
}
 
Example 26
Project: ramus   File: AbstractTableView.java   View source code 5 votes vote down vote up
public ExpandAction() {
    this.putValue(ACTION_COMMAND_KEY, "ExpandAll");
    this.putValue(
            SMALL_ICON,
            new ImageIcon(getClass().getResource(
                    "/com/ramussoft/gui/table/expand.png")));
    this.putValue(
            ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_E, KeyEvent.CTRL_MASK
                    | KeyEvent.SHIFT_MASK));
}
 
Example 27
Project: VISNode   File: ActionSave.java   View source code 5 votes vote down vote up
/**
 * Creates a new action
 */
public ActionSave() {
    super();
    putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl S"));
    putValue(SMALL_ICON, IconFactory.get().create("fa:floppy-o"));
    Messages.get().message("save").subscribe((msg) -> {
        putValue(NAME, msg);
    });
}
 
Example 28
Project: VISNode   File: ActionPasteNode.java   View source code 5 votes vote down vote up
/**
 * Creates a new action
 */
public ActionPasteNode() {
    super();
    putValue(SMALL_ICON, IconFactory.get().create("fa:clipboard"));
    Messages.get().message("paste").subscribe((msg) -> {
        putValue(NAME, msg);
    });
    putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke("ctrl V"));
}
 
Example 29
Project: incubator-netbeans   File: ActionsSupport.java   View source code 5 votes vote down vote up
public static KeyStroke registerAction(String actionKey, Action action, ActionMap actionMap, InputMap inputMap) {
    for (ActionsSupportProvider provider : Lookup.getDefault().lookupAll(ActionsSupportProvider.class)) {
        KeyStroke ks = provider.registerAction(actionKey, action, actionMap, inputMap);
        if (ks != null) return ks;
    }
    return null;
}
 
Example 30
Project: QN-ACTR-Release   File: Simulate.java   View source code 5 votes vote down vote up
/**
 * Defines an <code>Action</code> object with a default
 * description string and default icon.
 */
public Simulate(Mediator mediator) {
	super("Simulate", "Sim", mediator);
	putValue(SHORT_DESCRIPTION, "solve simulating model");
	putValue(MNEMONIC_KEY, new Integer(KeyEvent.VK_S));
	putValue(ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.ALT_MASK));
	setEnabled(false);
	
	//JOptionPane.showMessageDialog(null, "Simulate(Mediator mediator) ", "Simulate.java", JOptionPane.INFORMATION_MESSAGE); // CAO
}
 
Example 31
Project: openvisualtraceroute   File: LicenseDialog.java   View source code 5 votes vote down vote up
/**
 * Constructor
 */
public LicenseDialog(final Window parent) {
	super(parent, Resources.getLabel("license.button"), ModalityType.APPLICATION_MODAL);
	getContentPane().add(createHeaderPanel(false, null), BorderLayout.NORTH);
	final JTextArea license = new JTextArea(30, 50);
	license.setEditable(false);
	// read the license file and add its content to the JTextArea
	for (final String line : Util.readUTF8File(Resources.class.getResourceAsStream("/" + Resources.RESOURCE_PATH + "/License.txt"))) {
		license.append("   " + line + "\n");
	}
	// scroll to the top of the JTextArea
	license.setCaretPosition(0);
	// the all thing in a ScrollPane
	final JScrollPane scroll = new JScrollPane(license);
	getContentPane().add(scroll, BorderLayout.CENTER);
	final JPanel donatePanel = new JPanel(new BorderLayout(5, 10));
	final JLabel donate = new JLabel(Resources.getLabel("donate"));
	donatePanel.add(donate, BorderLayout.NORTH);
	final JPanel center = new JPanel();
	center.setLayout(new FlowLayout());
	center.add(new JLabel(Resources.getImageIcon("donate.png")));
	center.add(new HyperlinkLabel(Resources.getLabel("donate.label"), Env.INSTANCE.getDonateUrl()));
	donatePanel.add(center, BorderLayout.CENTER);
	final JButton close = new JButton(Resources.getLabel("close.button"));
	close.addActionListener(e -> LicenseDialog.this.dispose());
	donatePanel.add(close, BorderLayout.SOUTH);
	getContentPane().add(donatePanel, BorderLayout.SOUTH);
	SwingUtilities4.setUp(this);
	getRootPane().registerKeyboardAction(e -> dispose(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_IN_FOCUSED_WINDOW);
}
 
Example 32
Project: FreeCol   File: FreeColPanel.java   View source code 5 votes vote down vote up
/**
 * Make the given button the CANCEL button.
 *
 * @param cancelButton an {@code AbstractButton} value
 */
public final void setCancelComponent(AbstractButton cancelButton) {
    if (cancelButton == null) throw new NullPointerException();

    InputMap inputMap
        = getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, true),
                 "release");

    Action cancelAction = cancelButton.getAction();
    getActionMap().put("release", cancelAction);
}
 
Example 33
Project: VASSAL-src   File: DynamicProperty.java   View source code 5 votes vote down vote up
public Command myKeyEvent(KeyStroke stroke) {
  final ChangeTracker tracker = new ChangeTracker(this);
  for (DynamicKeyCommand dkc : keyCommands) {
    if (dkc.matches(stroke)) {
      setValue(dkc.propChanger.getNewValue(value));
    }
  }

  return tracker.getChangeCommand();
}
 
Example 34
Project: freecol   File: DisplayTileTextAction.java   View source code 5 votes vote down vote up
/**
 * Creates this action
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param type a {@code DisplayText} value
 */
public DisplayTileTextAction(FreeColClient freeColClient,
                             DisplayText type) {
    super(freeColClient, id + type.getKey(),
          ClientOptions.DISPLAY_TILE_TEXT);
    display = type;
    setAccelerator(KeyStroke.getKeyStroke(accelerators[type.ordinal()],
            KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK));
}
 
Example 35
Project: FreeCol   File: DisplayTileTextAction.java   View source code 5 votes vote down vote up
/**
 * Creates this action
 *
 * @param freeColClient The {@code FreeColClient} for the game.
 * @param type a {@code DisplayText} value
 */
public DisplayTileTextAction(FreeColClient freeColClient,
                             DisplayText type) {
    super(freeColClient, id + type.getKey(),
          ClientOptions.DISPLAY_TILE_TEXT);
    display = type;
    setAccelerator(KeyStroke.getKeyStroke(accelerators[type.ordinal()],
            KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK));
}
 
Example 36
Project: incubator-netbeans   File: ETable.java   View source code 5 votes vote down vote up
@Override
public void actionPerformed(ActionEvent e) {
    if (isEditing() || editorComp != null) {
        removeEditor();
        return;
    } else {
        Component c = KeyboardFocusManager.getCurrentKeyboardFocusManager().getFocusOwner();
        
        InputMap imp = getRootPane().getInputMap(WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
        ActionMap am = getRootPane().getActionMap();
        
        KeyStroke escape = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
        Object key = imp.get(escape);
        if (key == null) {
            //Default for NbDialog
            key = "Cancel";
        }
        if (key != null) {
            Action a = am.get(key);
            if (a != null) {
                String commandKey = (String)a.getValue(Action.ACTION_COMMAND_KEY);
                if (commandKey == null) {
                    commandKey = key.toString();
                }
                a.actionPerformed(new ActionEvent(this,
                ActionEvent.ACTION_PERFORMED, commandKey)); //NOI18N
            }
        }
    }
}
 
Example 37
Project: incubator-netbeans   File: MultiKeymap.java   View source code 5 votes vote down vote up
/**
 * Add a context key to the global context maintained by the NbKeymap. 
 *
 * @param key a key to be added to the global context.
 */
private void shiftGlobalContext(KeyStroke key) {
    List globalContextList = getGlobalContextList();
    if (globalContextList != null) {
        globalContextList.add(key);
        
        StringBuffer text = new StringBuffer();
        for (Iterator it = globalContextList.iterator(); it.hasNext();) {
            text.append(getKeyText((KeyStroke)it.next())).append(' ');
        }
        StatusDisplayer.getDefault().setStatusText(text.toString());        
    }
    // Shift the locally maintained mirror context as well
    contextKeys.add(key);
}
 
Example 38
Project: incubator-netbeans   File: MultiKeymap.java   View source code 5 votes vote down vote up
private Action getActionImpl(KeyStroke key) {
        Action a = null;
        if (context != null) {
            a = context.getAction(key);
            // Commented out the next part to allow the other
            // keystroke processors to work when the editor does not have an action
            // for the particular keystroke.
/*            if (a == null) { // possibly ignore modifier keystrokes
                switch (key.getKeyCode()) {
                case KeyEvent.VK_SHIFT:
                case KeyEvent.VK_CONTROL:
                case KeyEvent.VK_ALT:
                case KeyEvent.VK_META:
                    return EMPTY_ACTION;
                }
                if (key.isOnKeyRelease()
                    || (key.getKeyChar() != 0 && key.getKeyChar() != KeyEvent.CHAR_UNDEFINED)
                ) {
                    return EMPTY_ACTION; // ignore releasing and typed events
                }
            }
 */
        } else {
            a = delegate.getAction(key);
        }

        if (LOG.isLoggable(Level.FINE)) {
            String msg = "MultiKeymap.getActionImpl():\n  KEY=" + key + "\n  ACTION=" + a; // NOI18N
            if (LOG.isLoggable(Level.FINEST)) {
                LOG.log(Level.INFO, msg, new Exception());
            } else {
                LOG.fine(msg + "\n\n"); // NOI18N
            }
        }
        return a;
    }
 
Example 39
Project: ramus   File: QualifierView.java   View source code 5 votes vote down vote up
public OpenQualifierAction() {
    putValue(ACTION_COMMAND_KEY, "Action.OpenQualifier");
    putValue(
            SMALL_ICON,
            new ImageIcon(getClass().getResource(
                    "/com/ramussoft/gui/open.png")));
    this.putValue(
            ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_O, KeyEvent.CTRL_MASK
                    | KeyEvent.SHIFT_MASK));
}
 
Example 40
Project: ramus   File: ElistView.java   View source code 5 votes vote down vote up
public DeleteElementListAction() {
    putValue(ACTION_COMMAND_KEY, "Action.DeleteElementList");
    putValue(
            SMALL_ICON,
            new ImageIcon(getClass().getResource(
                    "/com/ramussoft/gui/table/delete.png")));
    putValue(ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0));
    setEnabled(false);
}