Example usage for javax.swing AbstractAction AbstractAction

List of usage examples for javax.swing AbstractAction AbstractAction

Introduction

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

Prototype

public AbstractAction() 

Source Link

Document

Creates an Action .

Usage

From source file:org.esa.s1tbx.ocean.worldwind.layers.Level2ProductLayer.java

public JPanel getControlPanel(final WorldWindowGLCanvas wwd) {
    theControlLevel2Panel = new JPanel(new GridLayout(7, 1, 5, 5));
    theControlLevel2Panel.setVisible(false);
    final JRadioButton owiBtn = new JRadioButton("OWI");
    owiBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            theSelectedComp = "owi";
            setComponentVisible("owi", wwd);
            theArrowsCB.setEnabled(true);
        }//  www . j  av  a 2s. c om
    });

    final JRadioButton oswBtn = new JRadioButton("OSW");
    oswBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            theSelectedComp = "osw";
            setComponentVisible("osw", wwd);
            theArrowsCB.setEnabled(false);

            //SystemUtils.LOG.info("theSurfaceProductHash " + theSurfaceProductHash);
            //SystemUtils.LOG.info("theSurfaceSequenceHash " + theSurfaceSequenceHash);
        }
    });

    final JRadioButton rvlBtn = new JRadioButton("RVL");
    rvlBtn.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {
            theSelectedComp = "rvl";
            //System.out.println("rvl:");
            //setComponentVisible("owi", false, getWwd());
            //setComponentVisible("osw", false, getWwd());
            setComponentVisible("rvl", wwd);
            theArrowsCB.setEnabled(false);
        }
    });

    final ButtonGroup group = new ButtonGroup();
    group.add(owiBtn);
    group.add(oswBtn);
    group.add(rvlBtn);
    owiBtn.setSelected(true);

    theSelectedComp = "owi";

    final JPanel componentTypePanel = new JPanel(new GridLayout(1, 4, 5, 5));
    componentTypePanel.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
    componentTypePanel.add(new JLabel("Component:"));
    componentTypePanel.add(owiBtn);
    componentTypePanel.add(oswBtn);
    componentTypePanel.add(rvlBtn);
    theControlLevel2Panel.add(componentTypePanel);

    final JPanel arrowDisplayPanel = new JPanel(new GridLayout(1, 2, 5, 5));

    theArrowsCB = new JCheckBox(new AbstractAction() {
        public void actionPerformed(ActionEvent actionEvent) {
            // Simply enable or disable the layer based on its toggle button.
            if (((JCheckBox) actionEvent.getSource()).isSelected())
                theOWIArrowsDisplayed = true;
            else
                theOWIArrowsDisplayed = false;

            wwd.redrawNow();
        }
    });

    arrowDisplayPanel.add(new JLabel("Display Wind Vectors:"));
    arrowDisplayPanel.add(theArrowsCB);
    theControlLevel2Panel.add(arrowDisplayPanel);

    /*
    final JPanel subsectionPanel = new JPanel(new GridLayout(1, 2, 5, 5));
    JComboBox sectionDropDown = new JComboBox();
    sectionDropDown.addItem("001");
    sectionDropDown.addActionListener(new ActionListener() {
    public void actionPerformed(ActionEvent e) {
        SystemUtils.LOG.info("drop down changed");
    }
    });
            
    subsectionPanel.add(new JLabel("Subsection:"));
    subsectionPanel.add(sectionDropDown);
            
    theControlLevel2Panel.add(subsectionPanel);
    */

    final JPanel maxPanel = new JPanel(new GridLayout(1, 2, 5, 5));
    maxPanel.add(new JLabel("Max OWI Wind Speed:"));

    final JSpinner maxSP = new JSpinner(new SpinnerNumberModel(10, 0, 10, 1));
    maxSP.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            int newValue = (Integer) ((JSpinner) e.getSource()).getValue();

            theOWILimitChanged = true;
        }
    });
    maxPanel.add(maxSP);
    theControlLevel2Panel.add(maxPanel);

    final JPanel minPanel = new JPanel(new GridLayout(1, 2, 5, 5));
    minPanel.add(new JLabel("Min OWI Wind Speed:"));

    final JSpinner minSP = new JSpinner(new SpinnerNumberModel(0, 0, 10, 1));
    minSP.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            theOWILimitChanged = true;
        }
    });
    minPanel.add(minSP);
    theControlLevel2Panel.add(minPanel);

    final JPanel maxRVLPanel = new JPanel(new GridLayout(1, 2, 5, 5));
    maxRVLPanel.add(new JLabel("Max RVL Rad Vel.:"));

    final JSpinner maxRVLSP = new JSpinner(new SpinnerNumberModel(6, 0, 10, 1));
    maxRVLSP.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            int newValue = (Integer) ((JSpinner) e.getSource()).getValue();
            theRVLLimitChanged = true;
        }
    });
    maxRVLPanel.add(maxRVLSP);
    theControlLevel2Panel.add(maxRVLPanel);

    final JButton updateButton = new JButton("Update");
    updateButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent actionEvent) {

            if (theOWILimitChanged) {

                //double minValue = ((Integer) minSP.getValue()) * 1.0e4;
                //double maxValue = ((Integer) maxSP.getValue()) * 1.0e4;
                double minValue = ((Integer) minSP.getValue());
                double maxValue = ((Integer) maxSP.getValue());
                recreateColorBarAndGradient(minValue, maxValue, "owi", wwd,
                        theSelectedComp.equalsIgnoreCase("owi"));
            }

            if (theRVLLimitChanged) {
                //SystemUtils.LOG.info("theRVLLimitChanged");

                //double minValue = ((Integer) minSP.getValue()) * 1.0e4;
                //double maxValue = ((Integer) maxSP.getValue()) * 1.0e4;

                double maxValue = ((Integer) maxRVLSP.getValue());
                double minValue = -1 * maxValue;

                recreateColorBarAndGradient(minValue, maxValue, "rvl", wwd,
                        theSelectedComp.equalsIgnoreCase("rvl"));
            }

            theOWILimitChanged = false;
            theRVLLimitChanged = false;
        }
    });
    theControlLevel2Panel.add(updateButton);

    createColorBarLegend(0, 10, "OWI Wind Speed", "owi");
    createColorBarLegend(0, 10, "OSW Wave Height.", "osw");
    createColorBarLegend(-6, 6, "RVL Rad. Vel.", "rvl");
    //addRenderable(theColorBarLegendHash.get("owi"));

    return theControlLevel2Panel;
}

From source file:org.nuclos.client.ui.collect.CollectController.java

/**
 * alternative entry point: lookup a <code>Collectable</code> (in a foreign entity).
 *///from   w  w w  .j  a v  a 2s  .c o  m
public void runLookupCollectable(final ICollectableListOfValues clctlovSource) throws CommonBusinessException {

    // show the internal frame in the front of the modal layer:
    final MainFrameTab ifrm = this.getTab();

    ifrm.setVisible(true);

    if (!clctlovSource.isSearchComponent()) {
        String label = getSpringLocaleDelegate().getMessage("CollectController.41", "Auswahl bernehmen");
        String description = getSpringLocaleDelegate().getMessage("CollectController.42",
                "Findet die bernahme in einem Unterformular statt werden mittels Mehrfachauswahl zustzliche Datenstze im Unterformular erzeugt.");
        if (clctlovSource instanceof CollectableListOfValues) {
            final CollectableListOfValues clov = (CollectableListOfValues) clctlovSource;
            if (clov.getValueListProvider() instanceof DatasourceBasedCollectableFieldsProvider) {
                ss.setValueListProviderDatasource(
                        ((DatasourceBasedCollectableFieldsProvider) clov.getValueListProvider())
                                .getDatasourceVO());
                ss.setValueListProviderDatasourceParameter(
                        ((DatasourceBasedCollectableFieldsProvider) clov.getValueListProvider())
                                .getValueListParameter());
            } else if (clov
                    .getValueListProvider() instanceof CollectableFieldsProviderCache.CachingCollectableFieldsProvider) {
                CollectableFieldsProvider delegate = ((CollectableFieldsProviderCache.CachingCollectableFieldsProvider) clov
                        .getValueListProvider()).getDelegate();
                if (delegate instanceof DatasourceBasedCollectableFieldsProvider) {
                    ss.setValueListProviderDatasource(
                            ((DatasourceBasedCollectableFieldsProvider) delegate).getDatasourceVO());
                    ss.setValueListProviderDatasourceParameter(
                            ((DatasourceBasedCollectableFieldsProvider) delegate).getValueListParameter());
                }
            }
        } else if (clctlovSource instanceof EntityListOfValues) {
            label = getSpringLocaleDelegate().getMessage("CollectController.lookup.generation",
                    "Objekte ausw\u00e4hlen");
            description = getSpringLocaleDelegate().getMessage(
                    "CollectController.lookup.generation.description",
                    "Parameterobjekte fr die Objektgenerierung ausw\u00e4hlen.");
        }
        final JMenuItem miPopupApplySelection = new JMenuItem(label);
        miPopupApplySelection.setToolTipText(description);

        getResultPanel().popupmenuRow.removeAll();//.addSeparator();
        getResultPanel().popupmenuRow.add(miPopupApplySelection);
        miPopupApplySelection.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                acceptLookedUpCollectable(clctlovSource);
                getTab().dispose();
            }
        });
    }

    // remove mouse listener for double click in table:
    getResultPanel().removeDoubleClickMouseListener(this.getMouseListenerForTableDoubleClick());

    // add alternative mouse listener for foreign key lookup:
    foreignKeyMouseListenerForTableDoubleClick = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent ev) {
            if (SwingUtilities.isLeftMouseButton(ev) && ev.getClickCount() == 2) {
                int iRow = getResultTable().rowAtPoint(ev.getPoint());
                if (iRow >= 0 && iRow < getResultTable().getRowCount()) {
                    getResultTable().getSelectionModel().setSelectionInterval(iRow, iRow);
                    SwingUtilities.invokeLater(new Runnable() {
                        @Override
                        public void run() {
                            acceptLookedUpCollectable(clctlovSource);
                            getTab().dispose();
                        }
                    });
                }
            }
        }
    };

    getResultPanel().addDoubleClickMouseListener(foreignKeyMouseListenerForTableDoubleClick);
    // @see NUCLOS-432
    //getResultTable().setSelectionMode(ListSelectionModel.SINGLE_SELECTION);

    getResultTable().getActionMap().put(KeyBindingProvider.EDIT_2.getKey(), new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            acceptLookedUpCollectable(clctlovSource);
            getTab().dispose();
        }
    });

    if (this.isSearchPanelAvailable()) {
        if (ss.getValueListProviderDatasource() != null) {
            this.runViewAll();
        } else {
            this.runSearch();
        }
    } else {
        this.runViewAll();
    }

    final Boolean modalLookup = (Boolean) clctlovSource
            .getProperty(ICollectableListOfValues.PROPERTY_MODAL_LOOKUP);
    if (Boolean.TRUE.equals(modalLookup)) {
        JDialog d = new JDialog(Main.getInstance().getMainFrame(), ifrm.getTitle(), true);
        FrameUtils.externalizeIntoWindow(ifrm, d);
        d.pack();
        d.setVisible(true);
    }
}

From source file:net.sf.jabref.gui.BasePanel.java

private void createMainTable() {
    database.registerListener(tableModel.getListSynchronizer());
    database.registerListener(SpecialFieldDatabaseChangeListener.getInstance());

    tableFormat = new MainTableFormat(database);
    tableFormat.updateTableFormat();//from   w  ww.  ja  va 2 s  .  c o m
    mainTable = new MainTable(tableFormat, tableModel, frame, this);

    selectionListener = new MainTableSelectionListener(this, mainTable);
    mainTable.updateFont();
    mainTable.addSelectionListener(selectionListener);
    mainTable.addMouseListener(selectionListener);
    mainTable.addKeyListener(selectionListener);
    mainTable.addFocusListener(selectionListener);

    // Add the listener that will take care of highlighting groups as the selection changes:
    groupsHighlightListener = listEvent -> {
        HighlightMatchingGroupPreferences highlightMatchingGroupPreferences = new HighlightMatchingGroupPreferences(
                Globals.prefs);
        if (highlightMatchingGroupPreferences.isAny()) {
            getGroupSelector().showMatchingGroups(mainTable.getSelectedEntries(), false);
        } else if (highlightMatchingGroupPreferences.isAll()) {
            getGroupSelector().showMatchingGroups(mainTable.getSelectedEntries(), true);
        } else {
            // no highlight
            getGroupSelector().showMatchingGroups(null, true);
        }
    };
    mainTable.addSelectionListener(groupsHighlightListener);

    mainTable.getActionMap().put(Actions.CUT, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCommand(Actions.CUT);
            } catch (Throwable ex) {
                LOGGER.warn("Could not cut", ex);
            }
        }
    });
    mainTable.getActionMap().put(Actions.COPY, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCommand(Actions.COPY);
            } catch (Throwable ex) {
                LOGGER.warn("Could not copy", ex);
            }
        }
    });
    mainTable.getActionMap().put(Actions.PASTE, new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                runCommand(Actions.PASTE);
            } catch (Throwable ex) {
                LOGGER.warn("Could not paste", ex);
            }
        }
    });

    mainTable.addKeyListener(new KeyAdapter() {

        @Override
        public void keyPressed(KeyEvent e) {
            final int keyCode = e.getKeyCode();
            final TreePath path = frame.getGroupSelector().getSelectionPath();
            final GroupTreeNodeViewModel node = path == null ? null
                    : (GroupTreeNodeViewModel) path.getLastPathComponent();

            if (e.isControlDown()) {
                switch (keyCode) {
                // The up/down/left/rightkeystrokes are displayed in the
                // GroupSelector's popup menu, so if they are to be changed,
                // edit GroupSelector.java accordingly!
                case KeyEvent.VK_UP:
                    e.consume();
                    if (node != null) {
                        frame.getGroupSelector().moveNodeUp(node, true);
                    }
                    break;
                case KeyEvent.VK_DOWN:
                    e.consume();
                    if (node != null) {
                        frame.getGroupSelector().moveNodeDown(node, true);
                    }
                    break;
                case KeyEvent.VK_LEFT:
                    e.consume();
                    if (node != null) {
                        frame.getGroupSelector().moveNodeLeft(node, true);
                    }
                    break;
                case KeyEvent.VK_RIGHT:
                    e.consume();
                    if (node != null) {
                        frame.getGroupSelector().moveNodeRight(node, true);
                    }
                    break;
                case KeyEvent.VK_PAGE_DOWN:
                    frame.nextTab.actionPerformed(null);
                    e.consume();
                    break;
                case KeyEvent.VK_PAGE_UP:
                    frame.prevTab.actionPerformed(null);
                    e.consume();
                    break;
                default:
                    break;
                }
            } else if (keyCode == KeyEvent.VK_ENTER) {
                e.consume();
                try {
                    runCommand(Actions.EDIT);
                } catch (Throwable ex) {
                    LOGGER.warn("Could not run action based on key press", ex);
                }
            }
        }
    });
}

From source file:edu.ucla.stat.SOCR.chart.Chart.java

/**
 * add the tabs to the toolbar/*w  w w  .  j  a v a  2s  .  c o m*/
 * @param toolBar
 */
protected void createActionComponents(JToolBar toolBar) {
    JButton button = null;

    toolBar.setFloatable(false);

    /**************** Demo Tab****************/
    if (useStaticExample) {
        exampleStaticAction = new AbstractAction() {
            public void actionPerformed(ActionEvent e) {
                // Create First Example
                reset();
                resetTable();
                resetMappingList();
                resetExample();
                if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) == ALL)
                    setMixPanel();

                updateStatus(url);
                validate();
            }

        };
        button = toolBar.add(exampleStaticAction);
        button.setText(EXAMPLE);
        button.setToolTipText(chartDescription);
    }

    /**************** DO-CHART Tab ****************/
    computeAction = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            doChart();
        }
    };

    button = toolBar.add(computeAction);
    button.setText(DOCHART);
    button.setToolTipText("Press this Button to Generate the Chart");

    /**************** CLEAR Tab****************/
    clearAction = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {

            /* somehow reset has to be called more than once to set to the correct header. I'll leave it like this before I figure out why. annie che 20051123 -_- */
            reset(); // Need to work out what this means
            //   reset();

            resetTable();
            //                update the mapping panel for this table change
            resetTableColumns(dataTable.getColumnCount());

            resetMappingList();
            resetChart();
            ChartExampleData exampleNull = new ChartExampleData(0, 0);
            /* A Null Example (with no data) is used here
            to reset the table so that when "CLEAR" button is pressed, the cells of dataTable is NOT null. 
            annieche 20060110. */
            updateExample(exampleNull);
            if (tabbedPanelContainer.getTitleAt(tabbedPanelContainer.getSelectedIndex()) == ALL)
                setMixPanel();

            updateStatus("The Chart has been reset!");
            //updateExample(exampleNull);
        }

    };

    if (CLEAR_BUTTON) {
        button = toolBar.add(clearAction);
        button.setText(CLEAR);
        button.setToolTipText("Clears All Windows");
    }

    /**************** TEST Tab ****************/
    testAction = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            doTest();
        }
    };
    if (TEST_API) {
        button = toolBar.add(testAction);
        button.setText(TEST);
        button.setToolTipText("Press this Button to test the API");
    }

}

From source file:edmondskarp.Gui.EdmondsKarpGui.java

private void setupUndoHotkeys() {
    String UNDO = "Undo action key";
    String REDO = "Redo action key";
    Action undoAction = new AbstractAction() {
        @Override// w w  w.  j ava 2s  . com
        public void actionPerformed(ActionEvent e) {
            controller.restoreState(true);
        }
    };
    Action redoAction = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            controller.restoreState(false);
        }
    };

    myPanel.getActionMap().put(UNDO, undoAction);
    myPanel.getActionMap().put(REDO, redoAction);

    InputMap[] inputMaps = new InputMap[] { myPanel.getInputMap(JComponent.WHEN_FOCUSED),
            myPanel.getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT),
            myPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW), };
    for (InputMap i : inputMaps) {
        i.put(KeyStroke.getKeyStroke("control Z"), UNDO);
        i.put(KeyStroke.getKeyStroke("control Y"), REDO);
        i.put(KeyStroke.getKeyStroke(KeyEvent.VK_Z, Toolkit.getDefaultToolkit().getMenuShortcutKeyMask()),
                UNDO);
    }
}

From source file:org.nuclos.client.ui.collect.SubForm.java

/**
 * create an Tablecelleditor for the given component
 * @param clctcomp/*from   w w  w. ja  v  a2s . com*/
 * @return the newly created table cell editor
 */
private CollectableComponentTableCellEditor createTableCellEditor(final CollectableComponent clctcomp) {
    if (getColumn(clctcomp.getFieldName()) != null) {
        final Map<String, Object> properties = getColumn(clctcomp.getFieldName()).getProperties();
        for (String property : properties.keySet()) {
            clctcomp.setProperty(property, properties.get(property));
        }
    }
    final CollectableComponentTableCellEditor result = new CollectableComponentTableCellEditor(clctcomp,
            clctcomp.isSearchComponent());

    result.addCollectableComponentModelListener(getCollectableTableCellEditorChangeListener());

    // @see NUCLOS-603. checkboxes and options should setvalue directly.
    if (clctcomp instanceof CollectableCheckBox) {
        ((CollectableCheckBox) clctcomp).getJCheckBox().addItemListener(new ItemListener() {
            @Override
            public void itemStateChanged(ItemEvent e) {
                SwingUtilities.invokeLater(new Runnable() { //@see NUCLOSINT-1635
                    public void run() {
                        try {
                            if (getSubformTable().getModel() instanceof SubFormTableModel) {
                                int row = getSubformTable().getSelectedRow();
                                int column = ((SubFormTableModel) getSubformTable().getModel())
                                        .findColumnByFieldName(clctcomp.getFieldName());
                                if (row != -1 && column != -1) {
                                    if (getSubformTable().getModel() instanceof SearchConditionTableModel)
                                        getSubformTable().setValueAt(clctcomp.getSearchCondition(), row,
                                                column);
                                    else
                                        getSubformTable().setValueAt(clctcomp.getField(), row, column);
                                }
                            }
                        } catch (CollectableFieldFormatException e1) {
                            LOG.warn("could not set value for " + clctcomp.getFieldName(), e1);
                        }
                    }
                });
            }
        });
    }
    if (clctcomp instanceof CollectableOptionGroup) {
        ((CollectableOptionGroup) clctcomp).getOptionGroup().addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    if (getSubformTable().getModel() instanceof SubFormTableModel) {
                        int row = getSubformTable().getSelectedRow();
                        int column = ((SubFormTableModel) getSubformTable().getModel())
                                .findColumnByFieldName(clctcomp.getFieldName());
                        if (row != -1 && column != -1)
                            getSubformTable().setValueAt(clctcomp.getField(), row, column);
                    }

                } catch (CollectableFieldFormatException e1) {
                    LOG.warn("could not set value for " + clctcomp.getFieldName(), e1);
                }
            }
        });
    }

    // textarea have to handle Tab in an subform differently.
    if (clctcomp instanceof NuclosCollectableTextArea) {
        ((NuclosCollectableTextArea) clctcomp).overrideActionMap(new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                Component c = (Component) ((NuclosCollectableTextArea) clctcomp).getJTextArea().getParent();
                c.dispatchEvent(
                        new KeyEvent(c, KeyEvent.KEY_PRESSED, System.currentTimeMillis(), 0, KeyEvent.VK_TAB));
            }
        }, new AbstractAction() {
            @Override
            public void actionPerformed(ActionEvent evt) {
                Component c = (Component) ((NuclosCollectableTextArea) clctcomp).getJTextArea().getParent();
                c.dispatchEvent(new KeyEvent(c, KeyEvent.KEY_PRESSED, System.currentTimeMillis(),
                        KeyEvent.SHIFT_MASK, KeyEvent.VK_TAB));
            }
        });
    }
    if (clctcomp instanceof DynamicRowHeightChangeProvider) {
        ((DynamicRowHeightChangeProvider) clctcomp).addDynamicRowHeightChangeListener(this);
    }

    return result;
}

From source file:org.nuclos.client.main.MainController.java

private Action createEntityAction(EntityMetaDataVO entitymetavo, String label, final boolean isNew,
        final Long processId, final String customUsage) {
    String entity = entitymetavo.getEntity();
    if (!getSecurityCache().isReadAllowedForEntity(entity)) {
        return null;
    }//from ww w.jav a  2  s . com

    if (isNew && entitymetavo.isStateModel()
            && !getSecurityCache().isNewAllowedForModuleAndProcess(IdUtils.unsafeToId(entitymetavo.getId()),
                    IdUtils.unsafeToId(processId))) {
        return null;
    }

    Action action = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent evt) {
            cmdCollectMasterData(evt, isNew, processId, customUsage);
        }
    };
    Pair<String, Character> nameAndMnemonic = MenuGenerator.getMnemonic(label);
    action.putValue(Action.NAME,
            customUsage == null ? nameAndMnemonic.x : String.format("%s (%s)", nameAndMnemonic.x, customUsage));
    if (nameAndMnemonic.y != null) {
        action.putValue(Action.MNEMONIC_KEY, (int) nameAndMnemonic.y.charValue());
    }
    action.setEnabled(true);
    action.putValue(Action.SMALL_ICON,
            MainFrame.resizeAndCacheTabIcon(Main.getInstance().getMainFrame().getEntityIcon(entity)));
    action.putValue(Action.ACTION_COMMAND_KEY, entity);
    if (!isNew && processId == null) {
        if (!StringUtils.isNullOrEmpty(entitymetavo.getAccelerator())
                && entitymetavo.getAcceleratorModifier() != null) {
            int keycode = entitymetavo.getAccelerator().charAt(0);
            if (keycode > 90)
                keycode -= 32;

            action.putValue(Action.ACCELERATOR_KEY,
                    KeyStroke.getKeyStroke(keycode, entitymetavo.getAcceleratorModifier().intValue()));
        } else if (!StringUtils.isNullOrEmpty(entitymetavo.getAccelerator())) {
            action.putValue(Action.ACCELERATOR_KEY,
                    KeyStroke.getKeyStroke(entitymetavo.getAccelerator().charAt(0)));
        }
    }

    return action;
}

From source file:org.nuclos.client.ui.collect.CollectController.java

protected void setupShortcutsForTabs(MainFrameTab ifrm) {
    final Action actSelectSearchTab = new AbstractAction() {

        @Override/*www. j a v  a  2 s  .co m*/
        public void actionPerformed(ActionEvent ev) {
            if (getCollectPanel().isTabbedPaneEnabledAt(CollectPanel.TAB_SEARCH)) {
                getCollectPanel().setTabbedPaneSelectedComponent(getSearchPanel());
            }
        }
    };

    final Action actSelectResultTab = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            if (getCollectPanel().isTabbedPaneEnabledAt(CollectPanel.TAB_RESULT)) {
                getCollectPanel().setTabbedPaneSelectedComponent(getResultPanel());
            }
        }
    };

    final Action actSelectDetailsTab = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent ev) {
            if (getCollectPanel().isTabbedPaneEnabledAt(CollectPanel.TAB_DETAILS)) {
                getCollectPanel().setTabbedPaneSelectedComponent(getDetailsPanel());
            }
        }
    };

    final String sKeySelectSearchTab = "SelectSearchTab";
    ifrm.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0), sKeySelectSearchTab);
    ifrm.getRootPane().getActionMap().put(sKeySelectSearchTab, actSelectSearchTab);

    final String sKeySelectResultTab = "SelectResultTab";
    ifrm.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0), sKeySelectResultTab);
    ifrm.getRootPane().getActionMap().put(sKeySelectResultTab, actSelectResultTab);

    /**
     * inner class SelectTabAction
     */
    class SelectTabAction extends AbstractAction {

        private int iDirection;

        /**
         * @param iDirection -1 for previous tab, +1 for next tab
         */
        SelectTabAction(int iDirection) {
            this.iDirection = iDirection;
        }

        @Override
        public void actionPerformed(ActionEvent ev) {
            int iExternalTabIndex = getCollectPanel().getTabbedPaneSelectedIndex();

            // try to find the next enabled tab in the given direction.
            // If the selected tab is the only enabled tab, do nothing:
            for (int i = 0; i < getCollectPanel().getTabCount() - 1; ++i) {
                int iInternalTabIndex = getCollectPanel().getTabIndexOf(iExternalTabIndex);
                iInternalTabIndex = (iInternalTabIndex + iDirection + getCollectPanel().getTabCount())
                        % getCollectPanel().getTabCount();
                iExternalTabIndex = getCollectPanel().getExternalTabIndexOf(iInternalTabIndex);
                if (getCollectPanel().isTabbedPaneEnabledAt(iExternalTabIndex)) {
                    getCollectPanel().setTabbedPaneSelectedIndex(iExternalTabIndex);
                    break;
                }
            }
        }
    } // inner class SelectTabAction

    final String sKeySelectPreviousTab = "SelectPreviousTab";
    ifrm.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_LEFT, KeyEvent.ALT_DOWN_MASK), sKeySelectPreviousTab);
    ifrm.getRootPane().getActionMap().put(sKeySelectPreviousTab, new SelectTabAction(-1));

    final String sKeySelectNextTab = "SelectNextTab";
    ifrm.getRootPane().getInputMap(JComponent.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT)
            .put(KeyStroke.getKeyStroke(KeyEvent.VK_RIGHT, KeyEvent.ALT_DOWN_MASK), sKeySelectNextTab);
    ifrm.getRootPane().getActionMap().put(sKeySelectNextTab, new SelectTabAction(+1));
}

From source file:br.com.atmatech.sac.view.ViewAtendimento.java

private void inicializaAtalhos() {
    KeyStroke keyStrokeJBalterar = KeyStroke.getKeyStroke(KeyEvent.VK_F2, 0);
    String actionNameJBalterar = "TECLA_F2";
    InputMap inputMapJBalterar = jBalterar.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    inputMapJBalterar.put(keyStrokeJBalterar, actionNameJBalterar);
    ActionMap actionMapJBMARCA = jBalterar.getActionMap();
    actionMapJBMARCA.put(actionNameJBalterar, acaojBnovo);

    //Atalho excluir
    KeyStroke keyStrokeJBexcluir = KeyStroke.getKeyStroke(KeyEvent.VK_F4, 0);
    String actionNameJBexcluir = "F4";
    InputMap inputMapJBexcluir = jBexcluir.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    inputMapJBexcluir.put(keyStrokeJBexcluir, actionNameJBexcluir);
    ActionMap actionMapJBexcluir = jBexcluir.getActionMap();
    actionMapJBexcluir.put(actionNameJBexcluir, acaoJBexcluir);

    //aTALHO AJUDA
    KeyStroke keyStrokeJBajuda = KeyStroke.getKeyStroke(KeyEvent.VK_F9, 0);
    String actionNameJBajuda = "TECLA_F9";
    InputMap inputMapJBajuda = jBajuda.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);

    inputMapJBajuda.put(keyStrokeJBajuda, actionNameJBajuda);
    ActionMap actionMapJBajuda = jBajuda.getActionMap();
    actionMapJBajuda.put(actionNameJBajuda, acaoJBajuda);

    //Atalho enter
    InputMap inputMapJBenter = this.jDcombocliente.getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMapJBenter.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), "forward");
    this.jDcombocliente.getRootPane().setInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW, inputMapJBenter);
    this.jDcombocliente.getRootPane().getActionMap().put("forward", new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override// ww w  . j a v  a 2 s .  c  om
        public void actionPerformed(ActionEvent e) {
            selecionaCliente();
        }

    });
}

From source file:nz.govt.natlib.ndha.manualdeposit.ManualDepositMain.java

@SuppressWarnings("serial")
private void stopEditingTree() {
    treeFileSystem.stopEditing();//  w  w w .java 2s. c  om
    Action stopEditingAction = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            Timer t = (Timer) e.getSource();
            t.stop();
            try {
                treeFileSystem.stopEditing();
            } catch (Exception ex) {
            }
        }
    };
    new Timer(100, stopEditingAction).start();
}