Example usage for javax.swing InputMap put

List of usage examples for javax.swing InputMap put

Introduction

In this page you can find the example usage for javax.swing InputMap put.

Prototype

public void put(KeyStroke keyStroke, Object actionMapKey) 

Source Link

Document

Adds a binding for keyStroke to actionMapKey .

Usage

From source file:edu.ku.brc.ui.UIHelper.java

/**
 * Helper for adding KeyBindings.//  w  w  w.  j  a v a 2s.  co m
 * @param comp the component (usually a JButton)
 * @param action the action to be invoked
 * @param actionName the name to put into the map for the action
 * @param keyCode the key code
 * @param modifier the modifer
 */
public static void addKeyBinding(final JComponent comp, final Action action, final String actionName,
        final int keyCode, final int modifier) {
    KeyStroke ctrlS = KeyStroke.getKeyStroke(keyCode, modifier);
    InputMap inputMap = comp.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    inputMap.put(ctrlS, actionName);
    ActionMap actionMap = comp.getActionMap();
    actionMap.put(actionName, action);
}

From source file:com.haulmont.cuba.desktop.sys.DesktopWindowManager.java

protected void assignDialogShortcuts(final JDialog dialog, JPanel panel, final Action[] actions) {
    ClientConfig clientConfig = configuration.getConfig(ClientConfig.class);

    InputMap inputMap = panel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    ActionMap actionMap = panel.getActionMap();

    String commitShortcut = getConfigValueIfConnected(clientConfig::getCommitShortcut,
            "cuba.gui.commitShortcut", "CTRL-ENTER");

    KeyCombination okCombination = KeyCombination.create(commitShortcut);
    KeyStroke okKeyStroke = DesktopComponentsHelper.convertKeyCombination(okCombination);

    inputMap.put(okKeyStroke, "okAction");
    actionMap.put("okAction", new javax.swing.AbstractAction() {
        @Override//from   ww w. j a v  a  2  s.  co m
        public void actionPerformed(ActionEvent e) {
            for (Action action : actions) {
                if (action instanceof DialogAction) {
                    switch (((DialogAction) action).getType()) {
                    case OK:
                    case YES:
                        action.actionPerform(null);
                        dialog.setVisible(false);
                        cleanupAfterModalDialogClosed(null);
                        return;
                    }
                }
            }
        }
    });

    String closeShortcut = getConfigValueIfConnected(clientConfig::getCloseShortcut, "cuba.gui.closeShortcut",
            "ESCAPE");

    KeyCombination closeCombination = KeyCombination.create(closeShortcut);
    KeyStroke closeKeyStroke = DesktopComponentsHelper.convertKeyCombination(closeCombination);

    inputMap.put(closeKeyStroke, "closeAction");
    actionMap.put("closeAction", new javax.swing.AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (actions.length == 1) {
                actions[0].actionPerform(null);
                dialog.setVisible(false);
                cleanupAfterModalDialogClosed(null);
            } else {
                for (Action action : actions) {
                    if (action instanceof DialogAction) {
                        switch (((DialogAction) action).getType()) {
                        case CANCEL:
                        case CLOSE:
                        case NO:
                            action.actionPerform(null);
                            dialog.setVisible(false);
                            cleanupAfterModalDialogClosed(null);
                            return;
                        }
                    }
                }
            }
        }
    });
}

From source file:edu.ku.brc.ui.UIRegistry.java

/**
 * Adds Key navigation bindings to a component. (Is this needed?)
 * @param comp the component/*from w ww  .  jav  a2s .c  om*/
 */
public void addNavBindings(JComponent comp) {
    InputMap inputMap = comp.getInputMap();

    //Ctrl-b to go backward one character
    KeyStroke key = KeyStroke.getKeyStroke(KeyEvent.VK_B, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    inputMap.put(key, DefaultEditorKit.backwardAction);

    //Ctrl-f to go forward one character
    key = KeyStroke.getKeyStroke(KeyEvent.VK_F, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    inputMap.put(key, DefaultEditorKit.forwardAction);

    //Ctrl-p to go up one line
    key = KeyStroke.getKeyStroke(KeyEvent.VK_P, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    inputMap.put(key, DefaultEditorKit.upAction);

    //Ctrl-n to go down one line
    key = KeyStroke.getKeyStroke(KeyEvent.VK_N, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    inputMap.put(key, DefaultEditorKit.downAction);
}

From source file:net.java.sip.communicator.impl.gui.main.chat.ChatPanel.java

/**
 * Sets the chat session to associate to this chat panel.
 * @param chatSession the chat session to associate to this chat panel
 *///  w w w .  j  av a2s.  com
public void setChatSession(ChatSession chatSession) {
    if (this.chatSession != null) {
        // remove old listener
        this.chatSession.removeChatTransportChangeListener(this);
    }

    this.chatSession = chatSession;
    this.chatSession.addChatTransportChangeListener(this);

    if ((this.chatSession != null) && this.chatSession.isContactListSupported()) {
        topPanel.remove(conversationPanelContainer);

        TransparentPanel rightPanel = new TransparentPanel(new BorderLayout());
        Dimension chatConferencesListsPanelSize = new Dimension(150, 25);
        Dimension chatContactsListsPanelSize = new Dimension(150, 175);
        Dimension rightPanelSize = new Dimension(150, 200);
        rightPanel.setMinimumSize(rightPanelSize);
        rightPanel.setPreferredSize(rightPanelSize);

        TransparentPanel contactsPanel = new TransparentPanel(new BorderLayout());
        contactsPanel.setMinimumSize(chatContactsListsPanelSize);
        contactsPanel.setPreferredSize(chatContactsListsPanelSize);

        conferencePanel.setMinimumSize(chatConferencesListsPanelSize);
        conferencePanel.setPreferredSize(chatConferencesListsPanelSize);

        this.chatContactListPanel = new ChatRoomMemberListPanel(this);
        this.chatContactListPanel.setOpaque(false);

        topSplitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT);
        topSplitPane.setBorder(null); // remove default borders
        topSplitPane.setOneTouchExpandable(true);
        topSplitPane.setOpaque(false);
        topSplitPane.setResizeWeight(1.0D);

        Color msgNameBackground = Color.decode(ChatHtmlUtils.MSG_NAME_BACKGROUND);

        // add border to the divider
        if (topSplitPane.getUI() instanceof BasicSplitPaneUI) {
            ((BasicSplitPaneUI) topSplitPane.getUI()).getDivider()
                    .setBorder(BorderFactory.createLineBorder(msgNameBackground));
        }

        ChatTransport chatTransport = chatSession.getCurrentChatTransport();

        JPanel localUserLabelPanel = new JPanel(new BorderLayout());
        JLabel localUserLabel = new JLabel(chatTransport.getProtocolProvider().getAccountID().getDisplayName());

        localUserLabel.setFont(localUserLabel.getFont().deriveFont(Font.BOLD));
        localUserLabel.setHorizontalAlignment(SwingConstants.CENTER);
        localUserLabel.setBorder(BorderFactory.createEmptyBorder(2, 0, 3, 0));
        localUserLabel.setForeground(Color.decode(ChatHtmlUtils.MSG_IN_NAME_FOREGROUND));

        localUserLabelPanel.add(localUserLabel, BorderLayout.CENTER);
        localUserLabelPanel.setBackground(msgNameBackground);

        JButton joinConference = new JButton(
                GuiActivator.getResources().getI18NString("service.gui.JOIN_VIDEO"));

        joinConference.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent arg0) {
                showChatConferenceDialog();
            }
        });
        contactsPanel.add(localUserLabelPanel, BorderLayout.NORTH);
        contactsPanel.add(chatContactListPanel, BorderLayout.CENTER);

        conferencePanel.add(joinConference, BorderLayout.CENTER);

        rightPanel.add(conferencePanel, BorderLayout.NORTH);
        rightPanel.add(contactsPanel, BorderLayout.CENTER);

        topSplitPane.setLeftComponent(conversationPanelContainer);
        topSplitPane.setRightComponent(rightPanel);

        topPanel.add(topSplitPane);

    } else {
        if (topSplitPane != null) {
            if (chatContactListPanel != null) {
                topSplitPane.remove(chatContactListPanel);
                chatContactListPanel = null;
            }

            this.messagePane.remove(topSplitPane);
            topSplitPane = null;
        }

        topPanel.add(conversationPanelContainer);
    }

    if (chatSession instanceof MetaContactChatSession) {
        // The subject panel is added here, because it's specific for the
        // multi user chat and is not contained in the single chat chat panel.
        if (subjectPanel != null) {
            this.remove(subjectPanel);
            subjectPanel = null;

            this.revalidate();
            this.repaint();
        }

        writeMessagePanel.initPluginComponents();
        writeMessagePanel.setTransportSelectorBoxVisible(true);

        //Enables to change the protocol provider by simply pressing the
        // CTRL-P key combination
        ActionMap amap = this.getActionMap();

        amap.put("ChangeProtocol", new ChangeTransportAction());

        InputMap imap = this.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

        imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_P, KeyEvent.CTRL_DOWN_MASK), "ChangeProtocol");
    } else if (chatSession instanceof ConferenceChatSession) {
        ConferenceChatSession confSession = (ConferenceChatSession) chatSession;

        writeMessagePanel.setTransportSelectorBoxVisible(false);

        confSession.addLocalUserRoleListener(this);
        confSession.addMemberRoleListener(this);

        ChatRoom room = ((ChatRoomWrapper) chatSession.getDescriptor()).getChatRoom();
        room.addMemberPropertyChangeListener(this);

        setConferencesPanelVisible(room.getCachedConferenceDescriptionSize() > 0);
        subjectPanel = new ChatRoomSubjectPanel((ConferenceChatSession) chatSession);

        // The subject panel is added here, because it's specific for the
        // multi user chat and is not contained in the single chat chat panel.
        this.add(subjectPanel, BorderLayout.NORTH);

        this.revalidate();
        this.repaint();
    }

    if (chatContactListPanel != null) {
        // Initialize chat participants' panel.
        Iterator<ChatContact<?>> chatParticipants = chatSession.getParticipants();

        while (chatParticipants.hasNext())
            chatContactListPanel.addContact(chatParticipants.next());
    }
}

From source file:com.projity.pm.graphic.frames.GraphicManager.java

private void addCtrlAccel(int vk, String actionConstant, Action action) {
    RootPaneContainer root = (RootPaneContainer) container;
    InputMap inputMap = root.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    KeyStroke key = KeyStroke.getKeyStroke(vk, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()); //claur use getMenuShortcutKeyMask so it work on Mac too.
    inputMap.put(key, actionConstant);
    if (action == null)
        action = menuManager.getActionFromId(actionConstant);
    root.getRootPane().getActionMap().put(actionConstant, action);
}

From source file:dk.dma.epd.ship.EPDShip.java

private void makeKeyBindings() {
    JPanel content = (JPanel) mainFrame.getContentPane();
    InputMap inputMap = content.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    @SuppressWarnings("serial")
    Action zoomIn = new AbstractAction() {
        @Override/* www  . j ava2s . c om*/
        public void actionPerformed(ActionEvent actionEvent) {
            mainFrame.getChartPanel().doZoom(0.5f);
        }
    };

    @SuppressWarnings("serial")
    Action zoomOut = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            mainFrame.getChartPanel().doZoom(2f);
        }
    };

    @SuppressWarnings("serial")
    Action centreOnShip = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            mainFrame.saveCentreOnShip();
        }
    };

    @SuppressWarnings("serial")
    Action newRoute = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            // newRouteBtn.requestFocusInWindow();
            mainFrame.getTopPanel().activateNewRouteButton();
        }
    };

    @SuppressWarnings("serial")
    Action routes = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            RouteManagerDialog routeManagerDialog = new RouteManagerDialog(mainFrame);
            routeManagerDialog.setVisible(true);
        }
    };

    @SuppressWarnings("serial")
    Action ais = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            mainFrame.getTopPanel().getAisDialog().setVisible(true);
        }
    };

    @SuppressWarnings("serial")
    Action panUp = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            mainFrame.getChartPanel().pan(1);
        }
    };
    @SuppressWarnings("serial")
    Action panDown = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            mainFrame.getChartPanel().pan(2);
        }
    };

    @SuppressWarnings("serial")
    Action panLeft = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            mainFrame.getChartPanel().pan(3);
        }
    };
    @SuppressWarnings("serial")
    Action panRight = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent actionEvent) {
            mainFrame.getChartPanel().pan(4);
        }
    };

    inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_ADD, 0), "ZoomIn");
    inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_SUBTRACT, 0), "ZoomOut");
    inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_C, 0), "centre");
    inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_UP, 0), "panUp");
    inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_DOWN, 0), "panDown");
    inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_LEFT, 0), "panLeft");
    inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_RIGHT, 0), "panRight");
    inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_KP_UP, 0), "panUp");
    inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_KP_DOWN, 0), "panDown");
    inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_KP_LEFT, 0), "panLeft");
    inputMap.put(KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_KP_RIGHT, 0), "panRight");
    inputMap.put(KeyStroke.getKeyStroke("control N"), "newRoute");
    inputMap.put(KeyStroke.getKeyStroke("control R"), "routes");
    inputMap.put(KeyStroke.getKeyStroke("control M"), "msi-nm");
    inputMap.put(KeyStroke.getKeyStroke("control A"), "ais");

    content.getActionMap().put("ZoomOut", zoomOut);
    content.getActionMap().put("ZoomIn", zoomIn);
    content.getActionMap().put("centre", centreOnShip);
    content.getActionMap().put("newRoute", newRoute);
    content.getActionMap().put("routes", routes);
    content.getActionMap().put("ais", ais);
    content.getActionMap().put("panUp", panUp);
    content.getActionMap().put("panDown", panDown);
    content.getActionMap().put("panLeft", panLeft);
    content.getActionMap().put("panRight", panRight);

}

From source file:edu.ku.brc.specify.tasks.subpane.qb.QueryBldrPane.java

/**
 * create the query builder UI.//from   ww  w .ja  va2s . co m
 */
protected void createUI() {
    removeAll();

    JMenuItem saveItem = new JMenuItem(UIRegistry.getResourceString("QB_SAVE"));
    Action saveActionListener = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (saveQuery(false)) {
                try {
                    String selId = null;
                    if (selectedQFP != null && selectedQFP.getQueryField() != null) {
                        selId = selectedQFP.getQueryField().getStringId();
                    }
                    final String selectedFldId = selId;
                    setupUI(true);
                    SwingUtilities.invokeLater(new Runnable() {

                        /* (non-Javadoc)
                         * @see java.lang.Runnable#run()
                         */
                        @Override
                        public void run() {
                            if (selectedFldId != null) {
                                for (QueryFieldPanel qfp : queryFieldItems) {
                                    if (qfp.getQueryField() != null
                                            && selectedFldId.equals(qfp.getQueryField().getStringId())) {
                                        selectQFP(qfp);
                                        return;
                                    }
                                }
                                selectQFP(queryFieldItems.get(0));
                            }
                        }

                    });
                } catch (Exception ex) {

                }
                setSaveBtnEnabled(false);
            }
        }
    };
    saveItem.addActionListener(saveActionListener);

    JMenuItem saveAsItem = new JMenuItem(UIRegistry.getResourceString("QB_SAVE_AS"));
    Action saveAsActionListener = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (saveQuery(true)) {
                setSaveBtnEnabled(false);
            }
        }
    };
    saveAsItem.addActionListener(saveAsActionListener);
    JComponent[] itemSample = { saveItem, saveAsItem };
    saveBtn = new DropDownButton(UIRegistry.getResourceString("QB_SAVE"), null, 1,
            java.util.Arrays.asList(itemSample));
    saveBtn.addActionListener(saveActionListener);
    String ACTION_KEY = "SAVE";
    KeyStroke ctrlS = KeyStroke.getKeyStroke(KeyEvent.VK_S,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    InputMap inputMap = saveBtn.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(ctrlS, ACTION_KEY);
    ActionMap actionMap = saveBtn.getActionMap();
    actionMap.put(ACTION_KEY, saveActionListener);
    ACTION_KEY = "SAVE_AS";
    KeyStroke ctrlA = KeyStroke.getKeyStroke(KeyEvent.VK_A,
            Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
    inputMap.put(ctrlA, ACTION_KEY);
    actionMap.put(ACTION_KEY, saveAsActionListener);
    saveBtn.setActionMap(actionMap);

    UIHelper.setControlSize(saveBtn);
    //saveBtn.setOverrideBorder(true, BasicBorders.getButtonBorder());

    listBoxPanel = new JPanel(new HorzLayoutManager(2, 2));

    Vector<TableQRI> list = new Vector<TableQRI>();
    for (int k = 0; k < tableTree.getKids(); k++) {
        list.add(tableTree.getKid(k).getTableQRI());
    }

    Collections.sort(list);
    DefaultListModel model = new DefaultListModel();
    for (TableQRI qri : list) {
        model.addElement(qri);
    }

    tableList = new JList(model);
    QryListRenderer qr = new QryListRenderer(IconManager.IconSize.Std16);
    qr.setDisplayKidIndicator(false);
    tableList.setCellRenderer(qr);

    JScrollPane spt = new JScrollPane(tableList, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    Dimension pSize = spt.getPreferredSize();
    pSize.height = 200;
    spt.setPreferredSize(pSize);

    JPanel topPanel = new JPanel(new BorderLayout());

    scrollPane = new JScrollPane(listBoxPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_NEVER,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_ALWAYS);

    tableList.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                int inx = tableList.getSelectedIndex();
                if (inx > -1) {
                    fillNextList(tableList);
                } else {
                    listBoxPanel.removeAll();
                }
            }
        }
    });

    addBtn = new JButton(IconManager.getImage("PlusSign", IconManager.IconSize.Std16));
    addBtn.setEnabled(false);
    addBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            BaseQRI qri = (BaseQRI) listBoxList.get(currentInx).getSelectedValue();
            if (qri.isInUse) {
                return;
            }

            try {
                FieldQRI fieldQRI = buildFieldQRI(qri);
                if (fieldQRI == null) {
                    throw new Exception("null FieldQRI");
                }
                SpQueryField qf = new SpQueryField();
                qf.initialize();
                qf.setFieldName(fieldQRI.getFieldName());
                qf.setStringId(fieldQRI.getStringId());
                query.addReference(qf, "fields");

                if (!isExportMapping) {
                    addQueryFieldItem(fieldQRI, qf, false);
                } else {
                    addNewMapping(fieldQRI, qf, null, false);
                }
            } catch (Exception ex) {
                log.error(ex);
                UsageTracker.incrHandledUsageCount();
                edu.ku.brc.exceptions.ExceptionTracker.getInstance().capture(QueryBldrPane.class, ex);
                return;
            }
        }
    });

    contextPanel = new JPanel(new BorderLayout());
    contextPanel.add(createLabel("Search Context", SwingConstants.CENTER), BorderLayout.NORTH); // I18N
    contextPanel.add(spt, BorderLayout.CENTER);
    contextPanel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));

    JPanel schemaPanel = new JPanel(new BorderLayout());
    schemaPanel.add(scrollPane, BorderLayout.CENTER);

    topPanel.add(contextPanel, BorderLayout.WEST);
    topPanel.add(schemaPanel, BorderLayout.CENTER);
    add(topPanel, BorderLayout.NORTH);

    queryFieldsPanel = new JPanel();
    queryFieldsPanel.setLayout(new NavBoxLayoutManager(0, 2));
    queryFieldsScroll = new JScrollPane(queryFieldsPanel, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    queryFieldsScroll.setBorder(null);
    add(queryFieldsScroll);

    //if (!isExportMapping)
    //{
    final JPanel mover = buildMoverPanel(false);
    add(mover, BorderLayout.EAST);
    // }

    String searchLbl = schemaMapping == null ? getResourceString("QB_SEARCH")
            : getResourceString("QB_EXPORT_PREVIEW");
    searchBtn = createButton(searchLbl);
    searchBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            //               int m = ae.getModifiers();
            //               boolean ors = (m & ActionEvent.ALT_MASK) > 0 && (m & ActionEvent.CTRL_MASK) > 0 && (m & ActionEvent.SHIFT_MASK) > 0;
            //               if (ors)
            //               {
            //                  System.out.println("Disjunctional conjoinment desire gesture detected");
            //               }
            //               doSearch(ors);
            doSearch(false);
        }
    });
    distinctChk = createCheckBox(UIRegistry.getResourceString("QB_DISTINCT"));
    distinctChk.setVisible(schemaMapping == null);
    if (schemaMapping == null) {
        distinctChk.setSelected(false);
        distinctChk.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                new SwingWorker() {

                    /* (non-Javadoc)
                     * @see edu.ku.brc.helpers.SwingWorker#construct()
                     */
                    @Override
                    public Object construct() {
                        if (distinctChk.isSelected()) {
                            UsageTracker.incrUsageCount("QB.DistinctOn");
                        } else {
                            UsageTracker.incrUsageCount("QB.DistinctOff");
                        }
                        if ((isTreeLevelSelected() || isAggFieldSelected()) && countOnly
                                && distinctChk.isSelected()) {
                            countOnlyChk.setSelected(false);
                            countOnly = false;
                        }
                        query.setCountOnly(countOnly);
                        query.setSelectDistinct(distinctChk.isSelected());
                        setSaveBtnEnabled(thereAreItems());
                        return null;
                    }
                }.start();
            }
        });
    }
    countOnlyChk = createCheckBox(UIRegistry.getResourceString("QB_COUNT_ONLY"));
    countOnlyChk.setSelected(false);
    countOnlyChk.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            new SwingWorker() {

                /* (non-Javadoc)
                 * @see edu.ku.brc.helpers.SwingWorker#construct()
                 */
                @Override
                public Object construct() {
                    //Don't allow change while query is running.
                    if (runningResults.get() == null) {
                        countOnly = !countOnly;
                        if (countOnly) {
                            UsageTracker.incrUsageCount("QB.CountOnlyOn");
                        } else {
                            UsageTracker.incrUsageCount("QB.CountOnlyOff");
                        }
                        if ((isTreeLevelSelected() || isAggFieldSelected()) && countOnly
                                && (distinctChk.isSelected() || searchSynonymyChk.isSelected())) {
                            distinctChk.setSelected(false);
                            searchSynonymyChk.setSelected(false);
                        }
                    } else {
                        //This might be awkward and/or klunky...
                        countOnlyChk.setSelected(countOnly);
                    }
                    query.setCountOnly(countOnly);
                    query.setSelectDistinct(distinctChk.isSelected());
                    setSaveBtnEnabled(thereAreItems());
                    return null;
                }
            }.start();
        }
    });

    searchSynonymyChk = createCheckBox(UIRegistry.getResourceString("QB_SRCH_SYNONYMS"));
    searchSynonymyChk.setSelected(searchSynonymy);
    searchSynonymyChk.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            new SwingWorker() {

                /* (non-Javadoc)
                 * @see edu.ku.brc.helpers.SwingWorker#construct()
                 */
                @Override
                public Object construct() {
                    searchSynonymy = !searchSynonymy;
                    if (!searchSynonymy) {
                        UsageTracker.incrUsageCount("QB.SearchSynonymyOff");
                    } else {
                        UsageTracker.incrUsageCount("QB.SearchSynonymyOn");
                    }
                    if (isTreeLevelSelected() && countOnly && searchSynonymyChk.isSelected()) {
                        countOnlyChk.setSelected(false);
                        countOnly = false;
                    }
                    query.setSearchSynonymy(searchSynonymy);
                    setSaveBtnEnabled(thereAreItems());
                    return null;
                }
            }.start();
        }
    });

    smushedChk = createCheckBox(UIRegistry.getResourceString("QB_SMUSH_RESULTS"));
    smushedChk.setVisible(isSmushableContext());
    if (isSmushableContext()) {
        smushedChk.setSelected(smushed);
        smushedChk.setToolTipText(
                String.format(UIRegistry.getResourceString("QB_SMUSH_RESULTS_HINT"), getCatalogNumberTitle()));
        smushedChk.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                new SwingWorker() {

                    /*
                     * (non-Javadoc)
                     * 
                     * @see edu.ku.brc.helpers.SwingWorker#construct()
                     */
                    @Override
                    public Object construct() {
                        smushed = !smushed;
                        if (!smushed) {
                            UsageTracker.incrUsageCount("QB.SmushedOff");
                        } else {
                            UsageTracker.incrUsageCount("QB.SmushedOn");
                        }
                        query.setSmushed(smushed);
                        setSaveBtnEnabled(thereAreItems());
                        return null;
                    }
                }.start();
            }
        });
    }

    PanelBuilder outer = new PanelBuilder(
            new FormLayout("p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 6dlu, p", "p"));

    CellConstraints cc = new CellConstraints();
    outer.add(smushedChk, cc.xy(1, 1));
    outer.add(searchSynonymyChk, cc.xy(3, 1));
    outer.add(distinctChk, cc.xy(5, 1));
    outer.add(countOnlyChk, cc.xy(7, 1));
    outer.add(searchBtn, cc.xy(9, 1));
    outer.add(saveBtn, cc.xy(11, 1));

    JPanel bottom = new JPanel(new BorderLayout());
    bottom.add(outer.getPanel(), BorderLayout.EAST);

    JButton helpBtn = UIHelper.createHelpIconButton(getHelpBtnContext());
    bottom.add(helpBtn, BorderLayout.WEST);
    add(bottom, BorderLayout.SOUTH);

    setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}

From source file:edu.ku.brc.specify.tasks.subpane.wb.WorkbenchPaneSS.java

/**
 * Adds a Key mappings.//w  w  w  .  j  a v a 2s  .  c o  m
 * @param comp comp
 * @param keyCode keyCode
 * @param actionName actionName
 * @param action action 
 * @return the action
 */
public Action addRecordKeyMappings(final JComponent comp, final int keyCode, final String actionName,
        final Action action, int modifiers) {
    InputMap inputMap = comp.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    ActionMap actionMap = comp.getActionMap();

    inputMap.put(KeyStroke.getKeyStroke(keyCode, modifiers), actionName);
    actionMap.put(actionName, action);

    //UIRegistry.registerAction(actionName, action);
    return action;
}

From source file:com.openbravo.pos.sales.JRetailPanelTakeAway.java

/**
 * Creates new form JTicketView/*from  w w w . j  a  va  2 s  .  c o  m*/
 */
public JRetailPanelTakeAway() {
    initComponents();

    tnbbutton = new ThumbNailBuilderPopularItems(110, 57, "com/openbravo/images/bluetoit.png");
    TextListener txtL;
    // cusName = (JTextField) m_jCboCustName.getEditor().getEditorComponent();
    // cusPhoneNo= (JTextField) m_jCboContactNo.getEditor().getEditorComponent();
    itemName = (JTextField) m_jCboItemName.getEditor().getEditorComponent();
    m_jTxtItemCode.setFocusable(true);
    // m_jTxtCustomerId.setFocusable(true);
    txtL = new TextListener();
    // m_jCreditAllowed.setVisible(false);
    // m_jCreditAllowed.setSelected(false);
    //       cusPhoneNo.addFocusListener(txtL);
    //cusName.addFocusListener(txtL);

    itemName.addFocusListener(txtL);
    Action doMorething = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            //    m_jPrice.setEnabled(true);
            //     m_jPrice.setFocusable(true);
            m_jKeyFactory.setFocusable(true);
            m_jKeyFactory.setText(null);
            java.awt.EventQueue.invokeLater(new Runnable() {
                public void run() {
                    m_jKeyFactory.requestFocus();
                }
            });

        }
    };

    //        InputMap imap = m_jPrice.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    //     imap.put(KeyStroke.getKeyStroke(KeyEvent.VK_B, Event.CTRL_MASK), "doMorething");
    //    m_jPrice.getActionMap().put("doMorething",doMorething);

    //   Action doLastBill = new AbstractAction() {
    //   public void actionPerformed(ActionEvent e) {
    //        m_jLastBillActionPerformed(e);
    //        stateToZero();
    //       }
    //   };

    //   InputMap imapLastBill = m_jLastBill.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    //  imapLastBill.put(KeyStroke.getKeyStroke("F7"), "doLastBill");
    //  m_jLastBill.getActionMap().put("doLastBill",doLastBill);

    Action cashNoBill = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            //  cashPayment(3);
            //  setPrinterOn();
        }
    };
    InputMap imapCashNoBill = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    imapCashNoBill.put(KeyStroke.getKeyStroke("F1"), "cashNoBill");
    m_jAction.getActionMap().put("cashNoBill", cashNoBill);
    // };
    Action cashReceipt = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            //   cashPayment(2);
        }
    };
    InputMap imapCashReceipt = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    imapCashReceipt.put(KeyStroke.getKeyStroke("F2"), "cashReceipt");
    m_jAction.getActionMap().put("cashReceipt", cashReceipt);

    Action docashPrint = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            //  cashPayment(1);
        }
    };

    InputMap imapCashPrint = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    imapCashPrint.put(KeyStroke.getKeyStroke("F3"), "docashPrint");
    m_jAction.getActionMap().put("docashPrint", docashPrint);
    Action doCardnobill = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            //m_jCloseShiftActionPerformed(e);
            //     cardPayment(1);
        }
    };

    InputMap imapCardnoBill = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    imapCardnoBill.put(KeyStroke.getKeyStroke("F4"), "doCardnobill");
    m_jAction.getActionMap().put("doCardnobill", doCardnobill);

    Action doNonChargablePrint = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            try {
                closeTicketNonChargable(m_oTicket, m_oTicketExt, m_aPaymentInfo);
            } catch (BasicException ex) {
                logger.info("exception in closeTicketNonChargable" + ex.getMessage());
                Logger.getLogger(JRetailPanelTakeAway.class.getName()).log(Level.SEVERE, null, ex);
            }
        }
    };

    InputMap imapNonChargablePrint = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    imapNonChargablePrint.put(KeyStroke.getKeyStroke("F7"), "doNonChargablePrint");
    m_jAction.getActionMap().put("doNonChargablePrint", doNonChargablePrint);

    Action doCreditreceipt = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            //            m_jCreditAmount.setText(Double.toString(m_oTicket.getTotal()));
            //
            //            try {
            //                    closeCreditTicket(m_oTicket, m_oTicketExt, m_aPaymentInfo);
            //                } catch (BasicException ex) {
            //                    Logger.getLogger(JRetailPanelTakeAway.class.getName()).log(Level.SEVERE, null, ex);
            //                }
        }
    };
    InputMap imapCreditReceipt = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    imapCreditReceipt.put(KeyStroke.getKeyStroke("F5"), "doCreditreceipt");
    m_jAction.getActionMap().put("doCreditreceipt", doCreditreceipt);

    Action doHomeDeliveryNotPaid = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            // m_jHomeDelivery.setSelected(true);
            if (getEditSale() == "Edit") {
                //  getServiceCharge("Y");
                printPartialTotals();
                try {
                    closeTicketHomeDelivery(m_oTicket, m_oTicketExt, m_aPaymentInfo);
                } catch (BasicException ex) {
                    logger.info("exception in closeTicketHomeDelivery" + ex.getMessage());
                    Logger.getLogger(JRetailPanelTakeAway.class.getName()).log(Level.SEVERE, null, ex);
                }
            }
        }
    };

    InputMap imapCardPrint = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    imapCardPrint.put(KeyStroke.getKeyStroke("F6"), "doHomeDeliveryNotPaid");
    m_jAction.getActionMap().put("doHomeDeliveryNotPaid", doHomeDeliveryNotPaid);

    Action doLogout = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            m_jLogoutActionPerformed(e);

        }
    };

    InputMap imapLog = m_jLogout.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    imapLog.put(KeyStroke.getKeyStroke("F12"), "doLogout");
    m_jLogout.getActionMap().put("doLogout", doLogout);

    Action doupArrow = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            //                m_jUpActionPerformed(e);
        }
    };
    InputMap imapUpArrow = m_jPlus.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    imapUpArrow.put(KeyStroke.getKeyStroke(KeyEvent.VK_UP, 0), "doupArrow");
    m_jPlus.getActionMap().put("doupArrow", doupArrow);

    //       Action doCustomer = new AbstractAction() {
    //       public void actionPerformed(ActionEvent e) {
    //
    ////              m_jTxtCustomerId.setFocusable(true);
    //
    //        //    cusPhoneNo.setFocusable(true);
    //       //     cusName.setFocusable(true);
    //            stateToBarcode();
    //            }
    //        };

    //        InputMap imapCustomer= m_jTxtCustomerId.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    //        imapCustomer.put(KeyStroke.getKeyStroke("F8"), "doCustomer");
    //        m_jTxtCustomerId.getActionMap().put("doCustomer",
    //                doCustomer);

    Action doItem = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            itemName.setFocusable(true);
            m_jTxtItemCode.setFocusable(true);
            stateToItem();

        }
    };

    InputMap imapItem = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    imapItem.put(KeyStroke.getKeyStroke("F9"), "doItem");
    m_jAction.getActionMap().put("doItem", doItem);

    //        Action doHomeDelivery = new AbstractAction() {
    //       public void actionPerformed(ActionEvent e) {
    ////            m_jHomeDelivery.setFocusable(true);
    //        //    m_jHomeDelivery.setSelected(true);
    //      //      m_jHomeDeliveryActionPerformed(e);
    //      //      m_jTxtAdvance.setFocusable(true);
    //            stateToHomeDelivery();
    //            }
    //        };
    //
    //        InputMap imapHomeDelivery= m_jHomeDelivery.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    //        imapHomeDelivery.put(KeyStroke.getKeyStroke(KeyEvent.VK_H, KeyEvent.ALT_MASK), "doHomeDelivery");
    //        m_jHomeDelivery.getActionMap().put("doHomeDelivery",
    //                doHomeDelivery);
    //

    Action doPayment = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            //           m_jCash.setFocusable(true);
            //       m_jCard.setFocusable(true);
            //       m_jCheque.setFocusable(true);
            //       m_jtxtChequeNo.setFocusable(true);
            //       m_jFoodCoupon.setFocusable(true);
            //      m_jVoucher.setFocusable(true);
            //      m_jCreditAmount.setFocusable(true);
            stateToPayment();
        }
    };

    InputMap imapPayment = m_jAction.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    imapPayment.put(KeyStroke.getKeyStroke("F11"), "doPayment");
    m_jAction.getActionMap().put("doPayment", doPayment);

    Action doDownpArrow = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            //               m_jDownActionPerformed(e);
        }
    };

    InputMap imapArrow = m_jMinus.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    imapArrow.put(KeyStroke.getKeyStroke(KeyEvent.VK_DOWN, 0), "doDownpArrow");
    m_jMinus.getActionMap().put("doDownpArrow", doDownpArrow);

    itemName.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {

            if (!itemName.getText().equals("") || !itemName.getText().equals(null)) {

                incProductByItemDetails(pdtId);
                //  itemName.setText("");
                //          m_jCboItemName.setSelectedIndex(-1);

                ArrayList<String> itemCode = new ArrayList<String>();
                ArrayList<String> itemName1 = new ArrayList<String>();

                vItemName.removeAllElements();
                try {
                    productListDetails = (ArrayList<ProductInfoExt>) dlSales.getProductDetails();
                } catch (BasicException ex) {
                    Logger.getLogger(JRetailPanelTakeAway.class.getName()).log(Level.SEVERE, null, ex);
                }

                for (ProductInfoExt product : productListDetails) {
                    itemCode.add(product.getItemCode());
                    itemName1.add(product.getName());
                }

                String[] productName = itemName1.toArray(new String[itemName1.size()]);

                for (int i = 0; i < itemName1.size(); i++) {
                    vItemName.addElement(productName[i]);
                }
                itemName = (JTextField) m_jCboItemName.getEditor().getEditorComponent();

            } else {
                pdtId = "";
                ArrayList<String> itemCode = new ArrayList<String>();
                ArrayList<String> itemName1 = new ArrayList<String>();

                vItemName.removeAllElements();
                try {
                    productListDetails = (ArrayList<ProductInfoExt>) dlSales.getProductDetails();
                } catch (BasicException ex) {
                    Logger.getLogger(JRetailPanelTakeAway.class.getName()).log(Level.SEVERE, null, ex);
                }

                for (ProductInfoExt product : productListDetails) {
                    itemCode.add(product.getItemCode());
                    itemName1.add(product.getName());
                }

                String[] productName = itemName1.toArray(new String[itemName1.size()]);
                for (int i = 0; i < itemName1.size(); i++) {
                    vItemName.addElement(productName[i]);
                }
                itemName = (JTextField) m_jCboItemName.getEditor().getEditorComponent();

            }
        }
    });

}

From source file:net.sourceforge.pmd.util.designer.Designer.java

private static void makeTextComponentUndoable(JTextComponent textConponent) {
    final UndoManager undoManager = new UndoManager();
    textConponent.getDocument().addUndoableEditListener(new UndoableEditListener() {
        @Override//from   ww  w . j a v a2 s . c  o  m
        public void undoableEditHappened(UndoableEditEvent evt) {
            undoManager.addEdit(evt.getEdit());
        }
    });
    ActionMap actionMap = textConponent.getActionMap();
    InputMap inputMap = textConponent.getInputMap();
    actionMap.put("Undo", new AbstractAction("Undo") {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undoManager.canUndo()) {
                    undoManager.undo();
                }
            } catch (CannotUndoException e) {
                throw new RuntimeException(e);
            }
        }
    });
    inputMap.put(KeyStroke.getKeyStroke("control Z"), "Undo");

    actionMap.put("Redo", new AbstractAction("Redo") {
        @Override
        public void actionPerformed(ActionEvent evt) {
            try {
                if (undoManager.canRedo()) {
                    undoManager.redo();
                }
            } catch (CannotRedoException e) {
                throw new RuntimeException(e);
            }
        }
    });
    inputMap.put(KeyStroke.getKeyStroke("control Y"), "Redo");
}