Java 类javax.swing.KeyStroke 实例源码

项目:myster    文件:MysterMenuItemFactory.java   
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;
}
项目:VASSAL-src    文件:Embellishment0.java   
/**
 * 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;
}
项目:VASSAL-src    文件:ADC2Module.java   
@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;
}
项目:AWGW    文件:WorldFrame.java   
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
    }
}
项目:vexillo    文件:GlazeToggleMenuItem.java   
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);
            }
        });
    }
}
项目:incubator-netbeans    文件:MacroShortcutsInjector.java   
@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
            }
        }
    }
}
项目:incubator-netbeans    文件:TextValueCompleter.java   
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());
    }
}
项目:incubator-netbeans    文件:TextRegionManager.java   
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;
}
项目:incubator-netbeans    文件:EditorActionUtilities.java   
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();
}
项目:VASSAL-src    文件:ADC2Module.java   
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;
}
项目:ramus    文件:FindPanel.java   
/**
 * 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);
}
项目:jaer    文件:ClassChooserDialog.java   
/** 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);
    }
项目:Logisim    文件:MenuSimulate.java   
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);
        }
    }
}
项目:powertext    文件:RTextArea.java   
/**
 * 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);

}
项目:Neukoelln_SER316    文件:HTMLEditor.java   
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));
}
项目:Neukoelln_SER316    文件:HTMLEditor.java   
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));
}
项目:incubator-netbeans    文件:GitStatusTable.java   
@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));
}
项目:FreeCol    文件:EuropePanel.java   
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);
}
项目:incubator-netbeans    文件:OptionsPanel.java   
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
    }
}
项目:incubator-netbeans    文件:NbKeymapTest.java   
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));
}
项目:incubator-netbeans    文件:CompletionLayout.java   
public void processKeyEvent(KeyEvent evt) {
          if (isVisible()) {
if (KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0).equals(
    KeyStroke.getKeyStrokeForEvent(evt))
) {
    evt.consume();
    CompletionImpl.get().hideToolTip();
}
          }
      }
项目:incubator-netbeans    文件:SwitchTabAction.java   
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
}
项目:incubator-netbeans    文件:TreeView.java   
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);
    }
}
项目:incubator-netbeans    文件:CompletionScrollPane.java   
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));
}
项目:incubator-netbeans    文件:FilterUtils.java   
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;
}
项目:ramus    文件:AbstractTableView.java   
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));
}
项目:VISNode    文件:ActionSave.java   
/**
 * 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);
    });
}
项目:VISNode    文件:ActionPasteNode.java   
/**
 * 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"));
}
项目:incubator-netbeans    文件:ActionsSupport.java   
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;
}
项目:QN-ACTR-Release    文件:Simulate.java   
/**
 * 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
}
项目:openvisualtraceroute    文件:LicenseDialog.java   
/**
 * 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);
}
项目:FreeCol    文件:FreeColPanel.java   
/**
 * 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);
}
项目:VASSAL-src    文件:DynamicProperty.java   
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();
}
项目:freecol    文件:DisplayTileTextAction.java   
/**
 * 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));
}
项目:FreeCol    文件:DisplayTileTextAction.java   
/**
 * 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));
}
项目:incubator-netbeans    文件:ETable.java   
@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
            }
        }
    }
}
项目:incubator-netbeans    文件:MultiKeymap.java   
/**
 * 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);
}
项目:incubator-netbeans    文件:MultiKeymap.java   
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;
    }
项目:ramus    文件:QualifierView.java   
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));
}
项目:ramus    文件:ElistView.java   
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);
}