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:fi.smaa.jsmaa.gui.SMAA2GUIFactory.java

@Override
protected JMenu buildResultsMenu() {
    JMenu resultsMenu = new JMenu("Results");
    resultsMenu.setMnemonic('r');
    JMenuItem cwItem = new JMenuItem("Central weight vectors",
            ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_CENTRALWEIGHTS));
    cwItem.setMnemonic('c');
    JMenuItem racsItem = new JMenuItem("Rank acceptability indices",
            ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_RANKACCEPTABILITIES));
    racsItem.setMnemonic('r');

    cwItem.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            Focuser.focus(tree, treeModel, treeModel.getCentralWeightsNode());
        }//from  w ww.  j a va2s  .co  m
    });

    racsItem.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            Focuser.focus(tree, treeModel, treeModel.getRankAcceptabilitiesNode());
        }
    });

    resultsMenu.add(cwItem);
    resultsMenu.add(racsItem);
    return resultsMenu;
}

From source file:org.nuxeo.launcher.sync.NuxeoSyncFrame.java

protected Action createLaunchBrowserAction() {
    return new AbstractAction() {
        private static final long serialVersionUID = 1L;

        @Override/* w  w w  .  j  av  a  2  s. c  om*/
        public void actionPerformed(ActionEvent event) {
            try {
                Desktop.getDesktop().browse(java.net.URI.create(getController().getLauncher().getURL()));
            } catch (Exception e) {
                setError("an error occurred while launching browser", e);
            }
        }
    };
}

From source file:fi.smaa.jsmaa.gui.SMAATRIGUIFactory.java

@Override
protected JMenu buildResultsMenu() {
    JMenu resultsMenu = new JMenu("Results");
    resultsMenu.setMnemonic('r');
    JMenuItem racsItem = new JMenuItem("Category acceptability indices",
            ImageFactory.IMAGELOADER.getIcon(FileNames.ICON_RANKACCEPTABILITIES));
    racsItem.setMnemonic('r');

    racsItem.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            Focuser.focus(tree, treeModel, treeModel.getCatAccNode());
        }/*from   www .  jav  a2  s . c  o  m*/
    });

    resultsMenu.add(racsItem);
    return resultsMenu;
}

From source file:be.nbb.demetra.dfm.output.FactorChart.java

private JMenu buildMenu() {
    JMenu result = new JMenu();

    result.add(new AbstractAction() {
        @Override/*from w  w w  . j  a v a  2  s. co  m*/
        public void actionPerformed(ActionEvent e) {
            TsCollection col = TsFactory.instance.createTsCollection();
            col.add(TsFactory.instance.createTs("factor", null, data.factor));
            col.add(TsFactory.instance.createTs("filtered", null, data.filtered));
            col.add(TsFactory.instance.createTs("lower", null, data.lower));
            col.add(TsFactory.instance.createTs("upper", null, data.upper));
            Transferable t = TssTransferSupport.getInstance().fromTsCollection(col);
            Toolkit.getDefaultToolkit().getSystemClipboard().setContents(t, null);
        }
    }).setText("Copy all series");

    JMenu export = new JMenu("Export image to");
    export.add(ChartCommand.printImage().toAction(chartPanel)).setText("Printer...");
    export.add(ChartCommand.copyImage().toAction(chartPanel)).setText("Clipboard");
    export.add(ChartCommand.saveImage().toAction(chartPanel)).setText("File...");
    result.add(export);

    return result;
}

From source file:com.haulmont.cuba.desktop.gui.components.DesktopLookupField.java

protected void initClearShortcut() {
    JComponent editor = (JComponent) comboBox.getEditor().getEditorComponent();
    KeyStroke clearKeyStroke = KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, InputEvent.SHIFT_DOWN_MASK, false);
    editor.getInputMap(JComponent.WHEN_FOCUSED).put(clearKeyStroke, "clearShortcut");
    editor.getActionMap().put("clearShortcut", new AbstractAction() {
        @Override//from  ww w  .  j  a va 2 s .  c om
        public void actionPerformed(ActionEvent e) {
            if (!isRequired() && isEditable() && isEnabled()) {
                setValue(null);

                fireUserSelectionListeners();
            }
        }
    });
}

From source file:net.sf.jabref.gui.plaintextimport.TextInputDialog.java

private void jbInit() {
    getContentPane().setLayout(new BorderLayout());
    StringBuilder typeStr = new StringBuilder("Plain text import");
    if (entry.getType() != null) {
        typeStr.append(' ').append(Localization.lang("for")).append(' ').append(entry.getType());
    }/*from   ww  w  .ja va2s  . c  o m*/

    this.setTitle(typeStr.toString());
    getContentPane().add(panel1, BorderLayout.CENTER);

    initRawPanel();
    initButtonPanel();
    initSourcePanel();

    JTabbedPane tabbed = new JTabbedPane();

    tabbed.add(rawPanel, Localization.lang("Raw source"));
    tabbed.add(sourcePanel, Localization.lang("BibTeX source"));

    // Panel Layout
    panel1.setLayout(new BorderLayout());
    panel1.add(tabbed, BorderLayout.CENTER);
    panel1.add(buttons, BorderLayout.SOUTH);

    // Key bindings:
    ActionMap am = buttons.getActionMap();
    InputMap im = buttons.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", new AbstractAction() {

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

From source file:org.omegat.gui.issues.IssuesPanelController.java

@SuppressWarnings("serial")
synchronized void init() {
    if (frame != null) {
        // Regenerate menu bar to reflect current prefs
        frame.setJMenuBar(generateMenuBar());
        return;// ww  w .ja v  a2  s  .  c o  m
    }

    frame = new JFrame(OStrings.getString("ISSUES_WINDOW_TITLE"));
    StaticUIUtils.setEscapeClosable(frame);
    StaticUIUtils.setWindowIcon(frame);
    if (Platform.isMacOSX()) {
        OSXIntegration.enableFullScreen(frame);
    }
    panel = new IssuesPanel();
    frame.add(panel);

    frame.setJMenuBar(generateMenuBar());

    frame.setPreferredSize(new Dimension(600, 400));
    frame.pack();
    frame.setLocationRelativeTo(parent);
    panel.innerSplitPane.setDividerLocation(INNER_SPLIT_INITIAL_RATIO);
    panel.outerSplitPane.setDividerLocation(OUTER_SPLIT_INITIAL_RATIO);

    StaticUIUtils.persistGeometry(frame, Preferences.ISSUES_WINDOW_GEOMETRY_PREFIX, () -> {
        Preferences.setPreference(Preferences.ISSUES_WINDOW_DIVIDER_LOCATION_BOTTOM,
                panel.outerSplitPane.getDividerLocation());
    });

    try {
        int bottomDL = Integer
                .parseInt(Preferences.getPreference(Preferences.ISSUES_WINDOW_DIVIDER_LOCATION_BOTTOM));
        panel.outerSplitPane.setDividerLocation(bottomDL);
    } catch (NumberFormatException e) {
        // Ignore
    }

    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            reset();
        }
    });

    if (Preferences.isPreference(Preferences.PROJECT_FILES_USE_FONT)) {
        String fontName = Preferences.getPreference(Preferences.TF_SRC_FONT_NAME);
        int fontSize = Integer.parseInt(Preferences.getPreference(Preferences.TF_SRC_FONT_SIZE));
        setFont(new Font(fontName, Font.PLAIN, fontSize));
    }

    panel.table.getSelectionModel().addListSelectionListener(e -> {
        if (!e.getValueIsAdjusting()) {
            viewSelectedIssueDetail();
            selectedEntry = getSelectedIssue().map(IIssue::getSegmentNumber).orElse(-1);
        }
    });

    panel.table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0),
            ACTION_KEY_JUMP_TO_SELECTED_ISSUE);
    panel.table.getActionMap().put(ACTION_KEY_JUMP_TO_SELECTED_ISSUE, new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            jumpToSelectedIssue();
        }
    });

    // Swap focus between the Types list and Issues table; don't allow
    // tabbing within the table because it's pointless. Maybe this would be
    // better accomplished by adjusting the focus traversal policy?
    panel.table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, KeyEvent.SHIFT_DOWN_MASK),
            ACTION_KEY_FOCUS_ON_TYPES_LIST);
    panel.table.getInputMap().put(KeyStroke.getKeyStroke(KeyEvent.VK_TAB, 0), ACTION_KEY_FOCUS_ON_TYPES_LIST);
    panel.table.getActionMap().put(ACTION_KEY_FOCUS_ON_TYPES_LIST, new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (panel.typeList.isVisible()) {
                panel.typeList.requestFocusInWindow();
            }
        }
    });

    panel.closeButton.addActionListener(e -> StaticUIUtils.closeWindowByEvent(frame));

    MouseAdapter adapter = new MouseAdapter() {
        @Override
        public void mouseClicked(MouseEvent e) {
            if (e.getClickCount() == 2 && e.getButton() == MouseEvent.BUTTON1) {
                jumpToSelectedIssue();
            } else if (e.getButton() == MouseEvent.BUTTON1 && mouseoverCol == IssueColumn.ACTION_BUTTON.index) {
                doPopup(e);
            }
        }

        @Override
        public void mousePressed(MouseEvent e) {
            if (e.isPopupTrigger()) {
                doPopup(e);
            }
        }

        @Override
        public void mouseReleased(MouseEvent e) {
            if (e.isPopupTrigger()) {
                doPopup(e);
            }
        }

        @Override
        public void mouseExited(MouseEvent e) {
            updateRollover();
        }

        @Override
        public void mouseMoved(MouseEvent e) {
            updateRollover();
        }

        private void doPopup(MouseEvent e) {
            getIssueAt(e.getPoint()).ifPresent(issue -> showPopupMenu(e.getComponent(), e.getPoint(), issue));
        }
    };
    panel.table.addMouseListener(adapter);
    panel.table.addMouseMotionListener(adapter);

    panel.typeList.addListSelectionListener(e -> {
        if (!e.getValueIsAdjusting()) {
            updateFilter();
            selectedType = getSelectedType().orElse(null);
        }
    });

    panel.jumpButton.addActionListener(e -> jumpToSelectedIssue());

    panel.reloadButton.addActionListener(e -> refreshData(selectedEntry, selectedType));

    panel.showAllButton.addActionListener(e -> showAll());

    colSizer = TableColumnSizer.autoSize(panel.table, IssueColumn.DESCRIPTION.index, true);

    CoreEvents.registerProjectChangeListener(e -> {
        switch (e) {
        case CLOSE:
            SwingUtilities.invokeLater(() -> {
                filePattern = ALL_FILES_PATTERN;
                instructions = NO_INSTRUCTIONS;
                reset();
                frame.setVisible(false);
            });
            break;
        case MODIFIED:
            if (frame.isVisible()) {
                SwingUtilities.invokeLater(() -> refreshData(selectedEntry, selectedType));
            }
            break;
        default:
        }
    });

    CoreEvents.registerFontChangedEventListener(f -> {
        if (!Preferences.isPreference(Preferences.PROJECT_FILES_USE_FONT)) {
            f = new JTable().getFont();
        }
        setFont(f);
        viewSelectedIssueDetail();
    });
}

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

private void setupActions() {

    wordList.addListSelectionListener(e -> {
        wordEditField.setText(wordList.getSelectedValue());
        wordEditField.selectAll();/* w  w  w  . ja v a2 s  . c  o  m*/
        new FocusRequester(wordEditField);
    });

    newWord.addActionListener(e -> newWordAction());

    ActionListener wordEditFieldListener = e -> actOnWordEdit();
    wordEditField.addActionListener(wordEditFieldListener);

    removeWord.addActionListener(e -> {
        int index = wordList.getSelectedIndex();
        if (index == -1) {
            return;
        }
        wordListModel.remove(index);
        wordEditField.setText("");
        if (!wordListModel.isEmpty()) {
            wordList.setSelectedIndex(Math.min(index, wordListModel.size() - 1));
        }
    });

    fieldList.addListSelectionListener(e -> {
        currentField = fieldList.getSelectedValue();
        fieldNameField.setText("");
        setupWordSelector();
    });

    newField.addActionListener(e -> {
        if (!fieldListModel.get(0).equals(FIELD_FIRST_LINE)) {
            // only add <field name> once
            fieldListModel.add(0, FIELD_FIRST_LINE);
        }
        fieldList.setSelectedIndex(0);
        fPane.getVerticalScrollBar().setValue(0);
        fieldNameField.setEnabled(true);
        fieldNameField.setText(currentField);
        fieldNameField.selectAll();

        new FocusRequester(fieldNameField);
    });

    fieldNameField.addActionListener(e -> fieldNameField.transferFocus());

    fieldNameField.addFocusListener(new FieldNameFocusAdapter());

    removeField.addActionListener(e -> {
        int index = fieldList.getSelectedIndex();
        if (index == -1) {
            return;
        }
        String fieldName = fieldListModel.get(index);
        removedFields.add(fieldName);
        fieldListModel.remove(index);
        wordListModels.remove(fieldName);
        fieldNameField.setText("");
        if (!fieldListModel.isEmpty()) {
            fieldList.setSelectedIndex(Math.min(index, wordListModel.size() - 1));
        }
    });

    ok.addActionListener(e -> {
        try {
            applyChanges();
            dispose();
        } catch (Exception ex) {
            LOGGER.info("Could not apply changes in \"Manage content selectors\"", ex);
            JOptionPane.showMessageDialog(frame, Localization.lang("Could not apply changes."));
        }
    });

    apply.addActionListener(e -> {
        // Store if an entry is currently being edited:
        if (!"".equals(wordEditField.getText())) {
            wordEditFieldListener.actionPerformed(null);
        }
        try {
            applyChanges();
        } catch (Exception ex) {
            LOGGER.info("Could not apply changes in \"Manage content selectors\"", ex);
            JOptionPane.showMessageDialog(frame, Localization.lang("Could not apply changes."));
        }
    });

    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dispose();
        }
    };
    cancelAction.putValue(Action.NAME, Localization.lang("Cancel"));
    cancel.setAction(cancelAction);
}

From source file:org.geopublishing.atlasStyler.swing.PolygonSymbolEditGUI.java

/**
 * This method initializes jButton/* w w w  .  j  ava2 s . c o  m*/
 * 
 * @return javax.swing.JButton
 */
private ColorButton getJButtonStrokeColor() {
    if (jButtonStrokeColor == null) {
        jButtonStrokeColor = new ColorButton();

        jButtonStrokeColor.setAction(new AbstractAction() {

            @Override
            public void actionPerformed(ActionEvent e) {

                Fill fill = symbolizer.getFill();

                Color color = null;
                if (fill != null && fill.getColor() != null) {
                    String substring = fill.getColor().toString();
                    color = Color.decode(substring);
                }

                Color newColor = AVSwingUtil.showColorChooser(PolygonSymbolEditGUI.this,
                        AtlasStylerVector.R("Stroke.ColorChooserDialog.Title"), color);

                if (newColor != null) {
                    String rgb = Integer.toHexString(newColor.getRGB());
                    rgb = "#" + rgb.substring(2, rgb.length());
                    symbolizer.getStroke().setColor(ASUtil.ff2.literal(rgb));

                    PolygonSymbolEditGUI.this.firePropertyChange(PROPERTY_UPDATED, null, null);

                    jButtonStrokeColor.setColor(newColor);

                }

            }

        });

        Stroke s = symbolizer.getStroke();
        if (s != null) {
            jButtonStrokeColor.setColor(StylingUtil.getColorFromExpression(s.getColor()));
        } else {
            jButtonStrokeColor.setEnabled(false);
        }

    }
    return jButtonStrokeColor;
}

From source file:org.drugis.addis.gui.WelcomeDialog.java

private void showExampleInfo(String helpText) {
    final JDialog dialog = new JDialog(this);
    dialog.setLocationByPlatform(true);/* ww  w  .  ja v  a2  s . c  om*/
    dialog.setPreferredSize(new Dimension(500, 250));

    JComponent helpPane = TextComponentFactory.createTextPane(helpText, true);

    JButton closeButton = new JButton("Close");
    closeButton.setMnemonic('c');
    closeButton.addActionListener(new AbstractAction() {
        public void actionPerformed(ActionEvent arg0) {
            dialog.dispose();
        }
    });

    JPanel panel = new JPanel(new BorderLayout());
    panel.add(helpPane, BorderLayout.CENTER);
    panel.add(closeButton, BorderLayout.SOUTH);

    dialog.add(panel);
    dialog.pack();
    dialog.setVisible(true);
}