Example usage for javax.swing JRootPane getInputMap

List of usage examples for javax.swing JRootPane getInputMap

Introduction

In this page you can find the example usage for javax.swing JRootPane getInputMap.

Prototype

public final InputMap getInputMap(int condition) 

Source Link

Document

Returns the InputMap that is used during condition.

Usage

From source file:com.osparking.attendant.AttListForm.java

/**
 * Creates new form AttListForm//from   w  w w .j  av a 2  s.  c  o m
 */
public AttListForm(IMainGUI mainGUI, String loginID, String loginPW, boolean isManager) {
    // Mark the first row as selected in default
    this.mainGUI = mainGUI;

    try {
        initComponents();
        setLocation(0, 0);
        setIconImages(OSPiconList);

        // Reset search column combobox items
        searchCriteriaComboBox.removeAllItems();
        searchCriteriaComboBox.addItem(new ConvComboBoxItem(LOGIN_ID_LABEL, LOGIN_ID_LABEL.getContent()));
        searchCriteriaComboBox.addItem(new ConvComboBoxItem(NAME_LABEL, NAME_LABEL.getContent()));

        // Make last 8 digits of the user ID visible on the user password label.
        String id = loginID;
        if (loginID.length() > 8) {
            id = ".." + loginID.substring(loginID.length() - 8);
        }
        userPWLabel.setText(id + " " + MY_PW_LABEL.getContent());

        this.loginID = loginID;
        this.loginPW = loginPW;
        this.isManager = isManager;
        initComponentsUser();

        // limit maximun allowed length of user IDa
        userIDText.setDocument(new JTextFieldLimit(20));

        ListSelectionModel model = usersTable.getSelectionModel();
        model.addListSelectionListener(new AttendantRowSelectionListener());

        setFormMode(FormMode.NormalMode);
        loadAttendantTable("");

        int selectIndex = searchRow(loginID);

        if (rowHidden(usersTable, selectIndex)) {
            usersTable.changeSelection(selectIndex, 0, false, false);
        } else {
            usersTable.setRowSelectionInterval(selectIndex, selectIndex);
        }

        usersTable.requestFocus();
        usersTable.getRowSorter().addRowSorterListener(new RowSorterListener() {
            @Override
            public void sorterChanged(final RowSorterEvent e) {
                SwingUtilities.invokeLater(new Runnable() {
                    public void run() {
                        if (e.getType() == RowSorterEvent.Type.SORTED) {
                            if (usersTable.getSelectedRow() != -1) {
                                usersTable.scrollRectToVisible(
                                        usersTable.getCellRect(usersTable.getSelectedRow(), 0, false));
                            }
                        }
                    }
                });
            }
        });
    } catch (Exception ex) {
        logParkingException(Level.SEVERE, ex, "(AttListForm Constructor ID: " + loginID + ")");
    }

    JComponent pane = (JComponent) this.getContentPane();
    pane.getInputMap().put(null, MUTEX_DEBUG_SEQ_VALUE);

    addWindowListener(new WindowAdapter() {
        public void windowOpened(WindowEvent e) {
            searchText.requestFocus();
        }
    });
    attachEnterHandler(searchText);
    adminAuth2CheckBox.setSelected(isManager);

    KeyStroke controlF = KeyStroke.getKeyStroke("control F");
    JRootPane rootPane = getRootPane();
    rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(controlF, "myAction");
    rootPane.getActionMap().put("myAction", new Ctrl_F_Action(searchText));
}

From source file:org.apache.jmeter.gui.action.SearchTreeDialog.java

@Override
protected JRootPane createRootPane() {
    JRootPane rootPane = new JRootPane();
    // Hide Window on ESC
    Action escapeAction = new AbstractAction("ESCAPE") {

        private static final long serialVersionUID = -6543764044868772971L;

        @Override/*from  w  w w . ja  v a  2 s  .  com*/
        public void actionPerformed(ActionEvent actionEvent) {
            setVisible(false);
        }
    };
    // Do search on Enter
    Action enterAction = new AbstractAction("ENTER") {

        private static final long serialVersionUID = -3661361497864527363L;

        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            doSearch(actionEvent);
        }
    };
    ActionMap actionMap = rootPane.getActionMap();
    actionMap.put(escapeAction.getValue(Action.NAME), escapeAction);
    actionMap.put(enterAction.getValue(Action.NAME), enterAction);
    InputMap inputMap = rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStrokes.ESC, escapeAction.getValue(Action.NAME));
    inputMap.put(KeyStrokes.ENTER, enterAction.getValue(Action.NAME));

    return rootPane;
}

From source file:org.ngrinder.recorder.ui.AboutDialog.java

private void initKeyStroke() {
    addKeyListener(new KeyAdapter() {
        @Override/*ww  w  . ja  va  2 s  .c  om*/
        public void keyPressed(KeyEvent e) {
            if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
                dispose();
            }
        }
    });

    JRootPane rootPane = getRootPane();
    rootPane.getActionMap().put("ESCAPE", new AbstractAction() {
        private static final long serialVersionUID = 421791976774749694L;

        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    });

    KeyStroke keyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0, false);
    rootPane.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(keyStroke, "ESCAPE");
}

From source file:org.omegat.gui.scripting.ScriptingWindow.java

private void addRunShortcutToOmegaT() {
    JRootPane appliRootPane = Core.getMainWindow().getApplicationFrame().getRootPane();
    appliRootPane.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT).put(
            KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.CTRL_DOWN_MASK | InputEvent.ALT_DOWN_MASK, false),
            "RUN_CURRENT_SCRIPT");
    appliRootPane.getActionMap().put("RUN_CURRENT_SCRIPT", new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override/*  ww w.ja va 2s .co m*/
        public void actionPerformed(ActionEvent e) {
            runScript();
        }
    });
}

From source file:pcgen.gui2.tools.Utility.java

/**
 * Add a keyboard shortcut to allow ESC to close the dialog.
 *
 * @param dialog The dialog to be updated.
 *///www .  ja va  2s.  c  o  m
public static void installEscapeCloseOperation(final JDialog dialog) {
    JRootPane root = dialog.getRootPane();
    root.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(escapeStroke, dispatchWindowClosingActionMapKey);
    Action dispatchClosing = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent event) {
            dialog.dispatchEvent(new WindowEvent(dialog, WindowEvent.WINDOW_CLOSING));
        }
    };
    root.getActionMap().put(dispatchWindowClosingActionMapKey, dispatchClosing);
}