Example usage for javax.swing KeyStroke getKeyStroke

List of usage examples for javax.swing KeyStroke getKeyStroke

Introduction

In this page you can find the example usage for javax.swing KeyStroke getKeyStroke.

Prototype

public static KeyStroke getKeyStroke(int keyCode, int modifiers) 

Source Link

Document

Returns a shared instance of a KeyStroke, given a numeric key code and a set of modifiers.

Usage

From source file:net.sf.clichart.main.ChartFrame.java

private void createMenu() {
    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);/*from  www.java 2s  . c o m*/

    JMenu fileMenu = new JMenu("File");
    menuBar.add(fileMenu);

    JMenuItem saveItem = new JMenuItem("Save as...", KeyEvent.VK_S);
    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));
    saveItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            saveChart();
        }
    });
    fileMenu.add(saveItem);

    JMenuItem exitItem = new JMenuItem("Exit", KeyEvent.VK_Q);
    exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
    exitItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);
        }
    });
    fileMenu.addSeparator();
    fileMenu.add(exitItem);

}

From source file:eu.lp0.cursus.ui.AboutDialog.java

private void initialise() {
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    setTitle(Messages.getString("about.title", Constants.APP_DESC)); //$NON-NLS-1$
    DefaultUnitConverter duc = DefaultUnitConverter.getInstance();

    FormLayout layout = new FormLayout("2dlu, pref, fill:pref:grow, max(30dlu;pref), 2dlu", //$NON-NLS-1$
            "2dlu, max(15dlu;pref), 2dlu, max(15dlu;pref), 2dlu, fill:max(100dlu;pref):grow, 2dlu, max(16dlu;pref), 2dlu"); //$NON-NLS-1$
    getContentPane().setLayout(layout);/*from  w w  w.  j  a v a  2s. c  o m*/

    JLabel lblName = new JLabel(Constants.APP_NAME + ": " + Messages.getString("about.description")); //$NON-NLS-1$ //$NON-NLS-2$
    getContentPane().add(lblName, "2, 2, 3, 1"); //$NON-NLS-1$

    getContentPane().add(new LinkJButton(Constants.APP_URL), "2, 4"); //$NON-NLS-1$

    JScrollPane scrCopying = new JScrollPane(ScrollPaneConstants.VERTICAL_SCROLLBAR_ALWAYS,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_AS_NEEDED);
    getContentPane().add(scrCopying, "2, 6, 3, 1"); //$NON-NLS-1$

    JTextArea txtCopying = new JTextArea(loadResources("COPYRIGHT", "LICENCE")); //$NON-NLS-1$ //$NON-NLS-2$
    txtCopying.setFont(Font.decode(Font.MONOSPACED));
    txtCopying.setEditable(false);
    scrCopying.setViewportView(txtCopying);
    scrCopying.setPreferredSize(
            new Dimension(scrCopying.getPreferredSize().width, duc.dialogUnitYAsPixel(100, scrCopying)));

    Action actClose = new CloseDialogAction(this);
    JButton btnClose = new JButton(actClose);
    getContentPane().add(btnClose, "4, 8"); //$NON-NLS-1$

    getRootPane().setDefaultButton(btnClose);
    getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), CloseDialogAction.class.getName());
    getRootPane().getActionMap().put(CloseDialogAction.class.getName(), actClose);

    pack();
    setMinimumSize(getSize());
    setSize(getSize().width, getSize().height * 3 / 2);
    btnClose.requestFocusInWindow();
}

From source file:com.github.alexfalappa.nbspringboot.projects.customizer.CfgPropsDialog.java

/** Creates new form CfgPropsDialog */
public CfgPropsDialog(java.awt.Dialog parent) {
    super(parent, true);
    initComponents();/*w ww .j av  a 2  s.c o  m*/
    // retrieve some flads from prefs
    final Preferences prefs = NbPreferences.forModule(PrefConstants.class);
    final boolean bDeprLast = prefs.getBoolean(PREF_DEPR_SORT_LAST, true);
    bDeprErrorShow = prefs.getBoolean(PREF_DEPR_ERROR_SHOW, false);
    // setup props sorting
    this.sortedProps = new TreeSet<>(new ConfigurationMetadataComparator(bDeprLast));
    // setup property list
    lCfgProps.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                final ConfigurationMetadataProperty selectedValue = lCfgProps.getSelectedValue();
                if (selectedValue != null) {
                    tpDetails.setText(Utils.cfgPropDetailsHtml(selectedValue));
                    tpDetails.setCaretPosition(0);
                }
            }
        }
    });
    // set default button
    rootPane.setDefaultButton(bOk);
    // close dialog with ESC key
    final ActionListener escAction = new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent ae) {
            CfgPropsDialog.this.setVisible(false);
        }
    };
    rootPane.registerKeyboardAction(escAction, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_IN_FOCUSED_WINDOW);
}

From source file:com.nvinayshetty.DTOnator.Ui.InputWindow.java

public InputWindow(PsiClass mClass) {
    this.mClass = mClass;
    project = mClass.getProject();//from   w w w . j  av a2  s  .  com
    mFile = mClass.getContainingFile();
    setContentPane(contentPane);
    inputFeedText.getRootPane().setSize(750, 400);
    setSize(1000, 600);
    setTitle("Generate DTO");
    getRootPane().setDefaultButton(buttonOk);
    initButtons();
    initListeners();
    setDefaultConditions();
    setDefaultCloseOperation(WindowConstants.DISPOSE_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            onCancel();
        }
    });
    contentPane.registerKeyboardAction(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            onCancel();
        }
    }, KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
}

From source file:fxts.stations.util.preferences.PreferencesSheetPanel.java

/**
 * Constructor PreferencesSheetPanel.//from   w ww .j a  v a2 s.c  o m
 *
 * @param aUserName parent dialog included this panel.
 */
public PreferencesSheetPanel(String aUserName) {
    mUserName = aUserName;
    try {
        mResMan = ResourceManager.getManager("fxts.stations.util.preferences.resources.Resources");
    } catch (Exception e) {
        mLogger.error("The fatal error");
        e.printStackTrace();
    }
    mResMan.addLocaleListener(this);

    //Define table
    mTableModel = new PrefTableModel();
    mTable = new AAJTable(mTableModel);
    mTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN);
    PreferencesTableCellRenderer renderer = new PreferencesTableCellRenderer();
    mTable.setDefaultRenderer(AValueEditorPanel.class, renderer);
    mEditor = new PreferencesTableCellEditor();
    mTable.setDefaultEditor(AValueEditorPanel.class, mEditor);
    //Do not change columns order
    mTable.getTableHeader().setReorderingAllowed(false);
    //Assign exterior a table
    mTable.setBorder(new EtchedBorder());
    //Prepare to used Escape key
    mDefaultEditingCancelAction = SwingUtilities.getUIActionMap(mTable).get("cancel");
    AbstractAction exitAction = new AbstractAction() {
        /**
         * Invoked when an action occurs.
         */
        public void actionPerformed(ActionEvent aEvent) {
            if (mEditor.isEditing()) {
                mEditor.cancelCellEditing();
                if (mDefaultEditingCancelAction != null) {
                    mDefaultEditingCancelAction.actionPerformed(aEvent);
                }
            } else {
                mDefaultExitAction.actionPerformed(aEvent);
            }
        }
    };
    KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    mTable.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(keyStroke, "ExitAction");
    SwingUtilities.getUIActionMap(mTable).put("ExitAction", exitAction);
    super.setViewportView(mTable);
}

From source file:com.mirth.connect.client.ui.Mirth.java

/**
 * Create the alternate key bindings for the menu shortcut key mask. This is called if the menu
 * shortcut key mask is not the CTRL key (i.e. COMMAND on OSX)
 *///from w w  w .ja v a 2  s. c  om
private static void createAlternateKeyBindings() {
    int acceleratorKey = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
    // Add the common KeyBindings for macs
    KeyBinding[] defaultBindings = {
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_C, acceleratorKey), DefaultEditorKit.copyAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_V, acceleratorKey), DefaultEditorKit.pasteAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_X, acceleratorKey), DefaultEditorKit.cutAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_A, acceleratorKey),
                    DefaultEditorKit.selectAllAction),
            // deleteNextWordAction and deletePrevWordAction were not available in Java 1.5
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, acceleratorKey),
                    DefaultEditorKit.deleteNextWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_BACK_SPACE, acceleratorKey),
                    DefaultEditorKit.deletePrevWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, acceleratorKey),
                    DefaultEditorKit.nextWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT, acceleratorKey),
                    DefaultEditorKit.nextWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, acceleratorKey),
                    DefaultEditorKit.previousWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT, acceleratorKey),
                    DefaultEditorKit.previousWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, acceleratorKey | InputEvent.SHIFT_MASK),
                    DefaultEditorKit.selectionNextWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_KP_RIGHT, acceleratorKey | InputEvent.SHIFT_MASK),
                    DefaultEditorKit.selectionNextWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, acceleratorKey | InputEvent.SHIFT_MASK),
                    DefaultEditorKit.selectionPreviousWordAction),
            new KeyBinding(KeyStroke.getKeyStroke(KeyEvent.VK_KP_LEFT, acceleratorKey | InputEvent.SHIFT_MASK),
                    DefaultEditorKit.selectionPreviousWordAction) };

    keyMapBindings(new javax.swing.JTextField(), defaultBindings);
    keyMapBindings(new javax.swing.JPasswordField(), defaultBindings);
    keyMapBindings(new javax.swing.JTextPane(), defaultBindings);
    keyMapBindings(new javax.swing.JTextArea(), defaultBindings);
    keyMapBindings(new com.mirth.connect.client.ui.components.MirthTextField(), defaultBindings);
    keyMapBindings(new com.mirth.connect.client.ui.components.MirthPasswordField(), defaultBindings);
    keyMapBindings(new com.mirth.connect.client.ui.components.MirthTextPane(), defaultBindings);
    keyMapBindings(new com.mirth.connect.client.ui.components.MirthTextArea(), defaultBindings);
}

From source file:ee.ioc.cs.vsle.editor.Editor.java

/**
 * Creates Action objects and initializes Input and Action mappings
 */// w  w  w.  ja  v a 2 s .c o  m
private void initActions() {
    JRootPane rp = getRootPane();

    ActionMap am = rp.getActionMap();
    InputMap im = rp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    am.put(DeleteAction.class, deleteAction);
    am.put(CloneAction.class, cloneAction);

    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DeleteAction.class);
    im.put(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK), CloneAction.class);
}

From source file:edu.harvard.mcz.imagecapture.BulkMediaFrame.java

private void init() {
    thisFrame = this;
    setTitle("BulkMedia Preparation");
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setBounds(100, 100, 902, 174);//from w  ww  . j  ava 2 s. c  o m

    JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic(KeyEvent.VK_F);
    menuBar.add(mnFile);

    JMenuItem mntmPrepareDirectory = new JMenuItem("Prepare Directory");
    mntmPrepareDirectory.setMnemonic(KeyEvent.VK_D);
    mntmPrepareDirectory.addActionListener(new PrepareDirectoryAction());
    mnFile.add(mntmPrepareDirectory);

    JMenuItem mntmNewMenuItem = new JMenuItem("Exit");
    mntmNewMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            done();
        }
    });

    JMenuItem mntmNewMenuItem_1 = new JMenuItem("Edit Properties");
    mntmNewMenuItem_1.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            PropertiesEditor p = new PropertiesEditor();
            p.pack();
            p.setVisible(true);
        }
    });
    mnFile.add(mntmNewMenuItem_1);
    mntmNewMenuItem.setMnemonic(KeyEvent.VK_X);
    mntmNewMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, InputEvent.CTRL_MASK));
    mnFile.add(mntmNewMenuItem);
    contentPane = new JPanel();
    contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
    setContentPane(contentPane);
    contentPane.setLayout(new BorderLayout(0, 0));

    JPanel panel = new JPanel();
    contentPane.add(panel, BorderLayout.CENTER);
    panel.setLayout(new GridLayout(3, 2, 0, 0));

    JLabel lblBaseUri = new JLabel("Base URI (first part of path to images on the web)");
    lblBaseUri.setHorizontalAlignment(SwingConstants.TRAILING);
    panel.add(lblBaseUri, "2, 2");

    textField = new JTextField();
    textField.setEditable(false);
    textField.setText(Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_IMAGEBASEURI));
    panel.add(textField);
    textField.setColumns(10);

    JLabel lblNewLabel = new JLabel("Local Path To Base (local mount path that maps to base URI)");
    lblNewLabel.setHorizontalAlignment(SwingConstants.TRAILING);
    panel.add(lblNewLabel);

    textField_1 = new JTextField();
    textField_1.setEditable(false);
    textField_1.setText(Singleton.getSingletonInstance().getProperties().getProperties()
            .getProperty(ImageCaptureProperties.KEY_IMAGEBASE));
    panel.add(textField_1);
    textField_1.setColumns(10);

    JLabel lblBeforeExitingWait = new JLabel(
            "Before exiting wait for both the Done and Thumbnails Built messages.");
    panel.add(lblBeforeExitingWait);

    JLabel lblThumbnailGenerationIs = new JLabel("Thumbnail generation is not reported on the progress bar.");
    panel.add(lblThumbnailGenerationIs);

    progressBar = new JProgressBar();
    progressBar.setStringPainted(false);
    contentPane.add(progressBar, BorderLayout.NORTH);

    JPanel panel_1 = new JPanel();
    contentPane.add(panel_1, BorderLayout.SOUTH);

    JButton btnPrepareDirectory = new JButton("Run");
    btnPrepareDirectory.setToolTipText("Select a directory and prepare a bulk media file for images therein.");
    panel_1.add(btnPrepareDirectory);
    btnPrepareDirectory.addActionListener(new PrepareDirectoryAction());
    btnPrepareDirectory.setPreferredSize(new Dimension(80, 25));

    JButton btnExit = new JButton("Exit");
    btnExit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            done();
        }
    });
    panel_1.add(btnExit);
}

From source file:com.mirth.connect.client.ui.components.rsta.RSTAPreferences.java

static RSTAPreferences fromJSON(String keyStrokesJSON, String findReplaceJSON, String toggleOptionsJSON,
        String autoCompleteJSON) {
    ObjectMapper mapper = new ObjectMapper();

    Map<String, KeyStroke> keyStrokeMap = new HashMap<String, KeyStroke>();
    if (StringUtils.isNotBlank(keyStrokesJSON)) {
        try {//  w  ww  . j  av  a2s. c  om
            ObjectNode keyStrokesNode = (ObjectNode) mapper.readTree(keyStrokesJSON);

            for (Iterator<Entry<String, JsonNode>> it = keyStrokesNode.fields(); it.hasNext();) {
                Entry<String, JsonNode> entry = it.next();
                KeyStroke keyStroke = null;

                if (!entry.getValue().isNull()) {
                    ArrayNode arrayNode = (ArrayNode) entry.getValue();
                    if (arrayNode.size() > 1) {
                        keyStroke = KeyStroke.getKeyStroke(arrayNode.get(0).asInt(), arrayNode.get(1).asInt());
                    }
                }

                keyStrokeMap.put(entry.getKey(), keyStroke);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    FindReplaceProperties findReplaceProperties = FindReplaceProperties.fromJSON(findReplaceJSON);

    Map<String, Boolean> toggleOptions = new HashMap<String, Boolean>();
    if (StringUtils.isNotBlank(toggleOptionsJSON)) {
        try {
            ObjectNode toggleOptionsNode = (ObjectNode) mapper.readTree(toggleOptionsJSON);

            for (Iterator<Entry<String, JsonNode>> it = toggleOptionsNode.fields(); it.hasNext();) {
                Entry<String, JsonNode> entry = it.next();

                if (!entry.getValue().isNull()) {
                    toggleOptions.put(entry.getKey(), entry.getValue().asBoolean());
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    AutoCompleteProperties autoCompleteProperties = AutoCompleteProperties.fromJSON(autoCompleteJSON);

    return new RSTAPreferences(keyStrokeMap, findReplaceProperties, toggleOptions, autoCompleteProperties);
}

From source file:com.github.benchdoos.weblocopener.weblocOpener.gui.EditDialog.java

private void initGui(String pathToEditingFile) {
    setIconImage(Toolkit.getDefaultToolkit().getImage(getClass().getResource("/images/icon96.png")));

    this.path = pathToEditingFile;
    setContentPane(contentPane);//ww  w.  j a va  2 s .  c  o m

    getRootPane().setDefaultButton(buttonOK);

    buttonOK.addActionListener(e -> onOK());

    buttonCancel.addActionListener(e -> onCancel());

    // call onCancel() when cross is clicked
    setDefaultCloseOperation(WindowConstants.EXIT_ON_CLOSE);
    addWindowListener(new WindowAdapter() {
        @Override
        public void windowActivated(WindowEvent e) {
            if (textField.getText().isEmpty()) {
                fillTextFieldWithClipboard();
            }
            super.windowActivated(e);
        }

        @Override
        public void windowClosing(WindowEvent e) {
            onCancel();
        }
    });

    // call onCancel() on ESCAPE
    contentPane.registerKeyboardAction(e -> onCancel(), KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0),
            JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);

    createWeblocFileTextPane.setBackground(new Color(232, 232, 232));

    initTextField(pathToEditingFile);

    pack();

    /*setMinimumSize(getSize());
    setPreferredSize(getSize());*/

    setSize(DEFAULT_APPLICATION_WIDTH, 200);
    setResizable(false); //TODO fix setMaximumSize

    setLocation(FrameUtils.getFrameOnCenterLocationPoint(this));
}