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:nz.govt.natlib.ndha.manualdeposit.dialogs.About.java

@SuppressWarnings("serial")
private void formComponentResized(java.awt.event.ComponentEvent evt) {
    paintImage();/*from  w w w  .  java  2  s .c  om*/
    Action updateDividersAction = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            Timer t = (Timer) e.getSource();
            t.stop();
            paintImage();
            repaint();
        }
    };
    new Timer(200, updateDividersAction).start();
}

From source file:de.codesourcery.eve.skills.ui.components.impl.ItemBrowserComponent.java

@Override
protected JPanel createPanel() {

    final JPanel result = new JPanel();
    result.setLayout(new GridBagLayout());

    treeModelBuilder = new MarketGroupTreeModelBuilder(dataModel);

    treeModelBuilder.attach(itemTree);/*from ww w . j  a va 2 s .  c  o m*/

    itemTree.getSelectionModel().addTreeSelectionListener(new TreeSelectionListener() {

        @Override
        public void valueChanged(TreeSelectionEvent e) {
            if (e.getPath() != null) {
                treeSelectionChanged((ITreeNode) e.getPath().getLastPathComponent());
            } else {
                treeSelectionChanged(null);
            }
        }
    });

    itemTree.setCellRenderer(new DefaultTreeCellRenderer() {
        public java.awt.Component getTreeCellRendererComponent(JTree tree, Object value, boolean sel,
                boolean expanded, boolean leaf, int row, boolean hasFocus) {
            super.getTreeCellRendererComponent(tree, value, sel, expanded, leaf, row, hasFocus);
            final ITreeNode node = (ITreeNode) value;
            if (node.getValue() instanceof MarketGroup) {
                setText(((MarketGroup) node.getValue()).getName());
            } else if (node.getValue() instanceof InventoryType) {
                setText(((InventoryType) node.getValue()).getName());
            }
            return this;
        };
    });

    // text area
    itemDetails.setLineWrap(true);
    itemDetails.setWrapStyleWord(true);
    itemDetails.setEditable(false);

    // context menu
    final PopupMenuBuilder menuBuilder = new PopupMenuBuilder();
    menuBuilder.addItem("Refine...", new AbstractAction() {

        @Override
        public boolean isEnabled() {
            return getSelectedType() != null && selectionProvider.getSelectedItem() != null;
        }

        private InventoryType getSelectedType() {
            final TreePath selection = itemTree.getSelectionPath();
            if (selection != null && selection.getPathCount() > 0) {
                final ITreeNode node = (ITreeNode) selection.getLastPathComponent();
                if (node.getValue() instanceof InventoryType) {
                    return (InventoryType) node.getValue();
                }
            }
            return null;
        }

        @Override
        public void actionPerformed(ActionEvent e) {
            final ICharacter currentCharacter = selectionProvider.getSelectedItem();
            final InventoryType t = getSelectedType();
            if (t != null && currentCharacter != null) {

                final RefiningComponent comp = new RefiningComponent(currentCharacter);
                comp.setModal(true);
                comp.setItemsToRefine(Collections.singletonList(new ItemWithQuantity(getSelectedType(), 1)));
                ComponentWrapper.wrapComponent(comp).setVisible(true);
            }

        }
    });
    menuBuilder.attach(itemTree);

    result.add(new JScrollPane(itemTree), constraints(0, 0).resizeBoth().end());
    result.add(new JScrollPane(itemDetails), constraints(1, 0).resizeBoth().end());
    return result;
}

From source file:net.sf.jabref.importer.ImportCustomizationDialog.java

/**
 *
 * @param frame//from  ww  w  .  j  a  v  a2  s  .c om
 */
public ImportCustomizationDialog(final JabRefFrame frame) {
    super(frame, Localization.lang("Manage custom imports"), false);

    ImportTableModel tableModel = new ImportTableModel();
    customImporterTable = new JTable(tableModel);
    TableColumnModel cm = customImporterTable.getColumnModel();
    cm.getColumn(0).setPreferredWidth(COL_0_WIDTH);
    cm.getColumn(1).setPreferredWidth(COL_1_WIDTH);
    cm.getColumn(2).setPreferredWidth(COL_2_WIDTH);
    cm.getColumn(3).setPreferredWidth(COL_3_WIDTH);
    JScrollPane sp = new JScrollPane(customImporterTable, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED,
            JScrollPane.HORIZONTAL_SCROLLBAR_NEVER);
    customImporterTable.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    customImporterTable.setPreferredScrollableViewportSize(getSize());
    if (customImporterTable.getRowCount() > 0) {
        customImporterTable.setRowSelectionInterval(0, 0);
    }

    JButton addFromFolderButton = new JButton(Localization.lang("Add from folder"));
    addFromFolderButton.addActionListener(e -> {
        CustomImporter importer = new CustomImporter();
        importer.setBasePath(FileDialogs.getNewDir(frame,
                new File(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)), Collections.emptyList(),
                Localization.lang("Select Classpath of New Importer"), JFileChooser.CUSTOM_DIALOG, false));
        String chosenFileStr = null;
        if (importer.getBasePath() != null) {
            chosenFileStr = FileDialogs.getNewFile(frame, importer.getFileFromBasePath(),
                    Collections.singletonList(".class"), Localization.lang("Select new ImportFormat subclass"),
                    JFileChooser.CUSTOM_DIALOG, false);
        }
        if (chosenFileStr != null) {
            try {
                importer.setClassName(pathToClass(importer.getFileFromBasePath(), new File(chosenFileStr)));
                importer.setName(importer.getInstance().getFormatName());
                importer.setCliId(importer.getInstance().getId());
                addOrReplaceImporter(importer);
                customImporterTable.revalidate();
                customImporterTable.repaint();
            } catch (Exception exc) {
                JOptionPane.showMessageDialog(frame,
                        Localization.lang("Could not instantiate %0", chosenFileStr));
            } catch (NoClassDefFoundError exc) {
                JOptionPane.showMessageDialog(frame, Localization.lang(
                        "Could not instantiate %0. Have you chosen the correct package path?", chosenFileStr));
            }

        }
    });
    addFromFolderButton
            .setToolTipText(Localization.lang("Add a (compiled) custom ImportFormat class from a class path.")
                    + "\n" + Localization.lang("The path need not be on the classpath of JabRef."));

    JButton addFromJarButton = new JButton(Localization.lang("Add from jar"));
    addFromJarButton.addActionListener(e -> {
        String basePath = FileDialogs.getNewFile(frame,
                new File(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)), Arrays.asList(".zip", ".jar"),
                Localization.lang("Select a Zip-archive"), JFileChooser.CUSTOM_DIALOG, false);

        if (basePath != null) {
            try (ZipFile zipFile = new ZipFile(new File(basePath), ZipFile.OPEN_READ)) {
                ZipFileChooser zipFileChooser = new ZipFileChooser(this, zipFile);
                zipFileChooser.setVisible(true);
                customImporterTable.revalidate();
                customImporterTable.repaint(10);
            } catch (IOException exc) {
                LOGGER.info("Could not open Zip-archive.", exc);
                JOptionPane.showMessageDialog(frame, Localization.lang("Could not open %0", basePath) + "\n"
                        + Localization.lang("Have you chosen the correct package path?"));
            } catch (NoClassDefFoundError exc) {
                LOGGER.info("Could not instantiate Zip-archive reader.", exc);
                JOptionPane.showMessageDialog(frame, Localization.lang("Could not instantiate %0", basePath)
                        + "\n" + Localization.lang("Have you chosen the correct package path?"));
            }
        }
    });
    addFromJarButton
            .setToolTipText(Localization.lang("Add a (compiled) custom ImportFormat class from a Zip-archive.")
                    + "\n" + Localization.lang("The Zip-archive need not be on the classpath of JabRef."));

    JButton showDescButton = new JButton(Localization.lang("Show description"));
    showDescButton.addActionListener(e -> {
        int row = customImporterTable.getSelectedRow();
        if (row == -1) {
            JOptionPane.showMessageDialog(frame, Localization.lang("Please select an importer."));
        } else {
            CustomImporter importer = ((ImportTableModel) customImporterTable.getModel()).getImporter(row);
            try {
                ImportFormat importFormat = importer.getInstance();
                JOptionPane.showMessageDialog(frame, importFormat.getDescription());
            } catch (IOException | ClassNotFoundException | InstantiationException
                    | IllegalAccessException exc) {
                LOGGER.warn("Could not instantiate importer " + importer.getName(), exc);
                JOptionPane.showMessageDialog(frame, Localization.lang("Could not instantiate %0 %1",
                        importer.getName() + ":\n", exc.getMessage()));
            }
        }
    });

    JButton removeButton = new JButton(Localization.lang("Remove"));
    removeButton.addActionListener(e -> {
        int row = customImporterTable.getSelectedRow();
        if (row == -1) {
            JOptionPane.showMessageDialog(frame, Localization.lang("Please select an importer."));
        } else {
            customImporterTable.removeRowSelectionInterval(row, row);
            Globals.prefs.customImports
                    .remove(((ImportTableModel) customImporterTable.getModel()).getImporter(row));
            Globals.IMPORT_FORMAT_READER.resetImportFormats();
            customImporterTable.revalidate();
            customImporterTable.repaint();
        }
    });

    Action closeAction = new AbstractAction() {

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

    JButton closeButton = new JButton(Localization.lang("Close"));
    closeButton.addActionListener(closeAction);

    JButton helpButton = new HelpAction(HelpFile.CUSTOM_IMPORTS).getHelpButton();

    // Key bindings:
    JPanel mainPanel = new JPanel();
    ActionMap am = mainPanel.getActionMap();
    InputMap im = mainPanel.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    am.put("close", closeAction);
    mainPanel.setLayout(new BorderLayout());
    mainPanel.add(sp, BorderLayout.CENTER);
    JPanel buttons = new JPanel();
    ButtonBarBuilder bb = new ButtonBarBuilder(buttons);
    buttons.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    bb.addGlue();
    bb.addButton(addFromFolderButton);
    bb.addButton(addFromJarButton);
    bb.addButton(showDescButton);
    bb.addButton(removeButton);
    bb.addButton(closeButton);
    bb.addUnrelatedGap();
    bb.addButton(helpButton);
    bb.addGlue();

    getContentPane().add(mainPanel, BorderLayout.CENTER);
    getContentPane().add(buttons, BorderLayout.SOUTH);
    this.setSize(getSize());
    pack();
    this.setLocationRelativeTo(frame);
    new FocusRequester(customImporterTable);
}

From source file:net.sf.jabref.gui.openoffice.OpenOfficePanel.java

private void initPanel() {

    connect.addActionListener(e -> connect(true));
    manualConnect.addActionListener(e -> connect(false));

    selectDocument.setToolTipText(Localization.lang("Select which open Writer document to work on"));
    selectDocument.addActionListener(e -> {

        try {//ww w .j a  v a 2  s.c o  m
            ooBase.selectDocument();
            frame.output(Localization.lang("Connected to document") + ": "
                    + ooBase.getCurrentDocumentTitle().orElse(""));
        } catch (UnknownPropertyException | WrappedTargetException | IndexOutOfBoundsException
                | NoSuchElementException | NoDocumentException ex) {
            JOptionPane.showMessageDialog(frame, ex.getMessage(), Localization.lang("Error"),
                    JOptionPane.ERROR_MESSAGE);
            LOGGER.warn("Problem connecting", ex);
        }

    });

    setStyleFile.addActionListener(event -> {

        if (styleDialog == null) {
            styleDialog = new StyleSelectDialog(frame, preferences, loader);
        }
        styleDialog.setVisible(true);
        styleDialog.getStyle().ifPresent(selectedStyle -> {
            style = selectedStyle;
            try {
                style.ensureUpToDate();
            } catch (IOException e) {
                LOGGER.warn("Unable to reload style file '" + style.getPath() + "'", e);
            }
            frame.setStatus(Localization.lang("Current style is '%0'", style.getName()));
        });

    });

    pushEntries.setToolTipText(Localization.lang("Cite selected entries between parenthesis"));
    pushEntries.addActionListener(e -> pushEntries(true, true, false));
    pushEntriesInt.setToolTipText(Localization.lang("Cite selected entries with in-text citation"));
    pushEntriesInt.addActionListener(e -> pushEntries(false, true, false));
    pushEntriesEmpty.setToolTipText(
            Localization.lang("Insert a citation without text (the entry will appear in the reference list)"));
    pushEntriesEmpty.addActionListener(e -> pushEntries(false, false, false));
    pushEntriesAdvanced.setToolTipText(Localization.lang("Cite selected entries with extra information"));
    pushEntriesAdvanced.addActionListener(e -> pushEntries(false, true, true));

    update.setToolTipText(Localization.lang("Ensure that the bibliography is up-to-date"));
    Action updateAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                if (style == null) {
                    style = loader.getUsedStyle();
                } else {
                    style.ensureUpToDate();
                }

                ooBase.updateSortedReferenceMarks();

                List<BibDatabase> databases = getBaseList();
                List<String> unresolvedKeys = ooBase.refreshCiteMarkers(databases, style);
                ooBase.rebuildBibTextSection(databases, style);
                if (!unresolvedKeys.isEmpty()) {
                    JOptionPane.showMessageDialog(frame, Localization.lang(
                            "Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current database.",
                            unresolvedKeys.get(0)), Localization.lang("Unable to synchronize bibliography"),
                            JOptionPane.ERROR_MESSAGE);
                }
            } catch (UndefinedCharacterFormatException ex) {
                reportUndefinedCharacterFormat(ex);
            } catch (UndefinedParagraphFormatException ex) {
                reportUndefinedParagraphFormat(ex);
            } catch (ConnectionLostException ex) {
                showConnectionLostErrorMessage();
            } catch (IOException ex) {
                JOptionPane.showMessageDialog(frame,
                        Localization.lang(
                                "You must select either a valid style file, or use one of the default styles."),
                        Localization.lang("No valid style file defined"), JOptionPane.ERROR_MESSAGE);
                LOGGER.warn("Problem with style file", ex);
            } catch (BibEntryNotFoundException ex) {
                JOptionPane.showMessageDialog(frame, Localization.lang(
                        "Your OpenOffice/LibreOffice document references the BibTeX key '%0', which could not be found in your current database.",
                        ex.getBibtexKey()), Localization.lang("Unable to synchronize bibliography"),
                        JOptionPane.ERROR_MESSAGE);
                LOGGER.debug("BibEntry not found", ex);
            } catch (Exception ex) {
                LOGGER.warn("Could not update bibliography", ex);
            }
        }
    };
    update.addActionListener(updateAction);

    merge.setToolTipText(Localization.lang("Combine pairs of citations that are separated by spaces only"));
    merge.addActionListener(e -> {
        try {
            ooBase.combineCiteMarkers(getBaseList(), style);
        } catch (UndefinedCharacterFormatException ex) {
            reportUndefinedCharacterFormat(ex);
        } catch (Exception ex) {
            LOGGER.warn("Problem combining cite markers", ex);
        }

    });
    settingsB.addActionListener(e -> showSettingsPopup());
    manageCitations.addActionListener(e -> {
        try {
            CitationManager cm = new CitationManager(frame, ooBase);
            cm.showDialog();
        } catch (NoSuchElementException | WrappedTargetException | UnknownPropertyException ex) {
            LOGGER.warn("Problem showing citation manager", ex);
        }
    });

    selectDocument.setEnabled(false);
    pushEntries.setEnabled(false);
    pushEntriesInt.setEnabled(false);
    pushEntriesEmpty.setEnabled(false);
    pushEntriesAdvanced.setEnabled(false);
    update.setEnabled(false);
    merge.setEnabled(false);
    manageCitations.setEnabled(false);
    diag = new JDialog((JFrame) null, "OpenOffice/LibreOffice panel", false);

    FormBuilder mainBuilder = FormBuilder.create()
            .layout(new FormLayout("fill:pref:grow", "p,p,p,p,p,p,p,p,p,p"));

    FormBuilder topRowBuilder = FormBuilder.create()
            .layout(new FormLayout("fill:pref:grow, 1dlu, fill:pref:grow, 1dlu, fill:pref:grow, "
                    + "1dlu, fill:pref:grow, 1dlu, fill:pref:grow", "pref"));
    topRowBuilder.add(connect).xy(1, 1);
    topRowBuilder.add(manualConnect).xy(3, 1);
    topRowBuilder.add(selectDocument).xy(5, 1);
    topRowBuilder.add(update).xy(7, 1);
    topRowBuilder.add(help).xy(9, 1);
    mainBuilder.add(topRowBuilder.getPanel()).xy(1, 1);
    mainBuilder.add(setStyleFile).xy(1, 2);
    mainBuilder.add(pushEntries).xy(1, 3);
    mainBuilder.add(pushEntriesInt).xy(1, 4);
    mainBuilder.add(pushEntriesAdvanced).xy(1, 5);
    mainBuilder.add(pushEntriesEmpty).xy(1, 6);
    mainBuilder.add(merge).xy(1, 7);
    mainBuilder.add(manageCitations).xy(1, 8);
    mainBuilder.add(settingsB).xy(1, 9);

    JPanel content = new JPanel();
    comp.setContentContainer(content);
    content.setLayout(new BorderLayout());
    content.add(mainBuilder.getPanel(), BorderLayout.CENTER);

    frame.getTabbedPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW)
            .put(Globals.getKeyPrefs().getKey(KeyBinding.REFRESH_OO), "Refresh OO");
    frame.getTabbedPane().getActionMap().put("Refresh OO", updateAction);

}

From source file:userinterface.properties.GUIGraphHandler.java

private void initComponents() {
    theTabs = new JTabbedPane() {

        @Override/*from   w  w  w .  ja  va 2s. co  m*/
        public String getTitleAt(int index) {
            try {
                TabClosePanel panel = (TabClosePanel) getTabComponentAt(index);
                return panel.getTitle();
            } catch (Exception e) {
                return "";
            }
        }

        @Override
        public String getToolTipTextAt(int index) {
            return ((TabClosePanel) getTabComponentAt(index)).getToolTipText();
        }

        @Override
        public void setTitleAt(int index, String title) {

            if (((TabClosePanel) getTabComponentAt(index)) == null) {
                return;
            }

            ((TabClosePanel) getTabComponentAt(index)).setTitle(title);
        }

        @Override
        public void setIconAt(int index, Icon icon) {
            ((TabClosePanel) getTabComponentAt(index)).setIcon(icon);
        }

        @Override
        public void setToolTipTextAt(int index, String toolTipText) {
            ((TabClosePanel) getTabComponentAt(index)).setToolTip(toolTipText);
        }

    };

    theTabs.addMouseListener(this);
    theTabs.addMouseWheelListener(new MouseWheelListener() {

        @Override
        public void mouseWheelMoved(MouseWheelEvent e) {
            if (e.getPreciseWheelRotation() > 0.0) {

                if (theTabs.getSelectedIndex() != (theTabs.getTabCount() - 1))
                    theTabs.setSelectedIndex(theTabs.getSelectedIndex() + 1);
            } else {

                if (theTabs.getSelectedIndex() != 0)
                    theTabs.setSelectedIndex(theTabs.getSelectedIndex() - 1);
            }
        }
    });

    setLayout(new BorderLayout());
    add(theTabs, BorderLayout.CENTER);

    graphOptions = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            GraphOptions graphOptions = options.get(theTabs.getSelectedIndex());
            graphOptions.setVisible(true);
        }
    };

    graphOptions.putValue(Action.NAME, "Graph options");
    graphOptions.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_G));
    graphOptions.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallOptions.png"));
    graphOptions.putValue(Action.LONG_DESCRIPTION, "Displays the options dialog for the graph.");

    zoomIn = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel mgm = models.get(theTabs.getSelectedIndex());

            if (mgm instanceof ChartPanel)
                ((ChartPanel) mgm).zoomInBoth(-1, -1);
            else if (mgm instanceof Graph3D) {
                double rho = ((Graph3D) mgm).getChart3DPanel().getViewPoint().getRho();
                ((Graph3D) mgm).getChart3DPanel().getViewPoint().setRho(rho - 5);
                ((Graph3D) mgm).getChart3DPanel().repaint();
            }
        }
    };

    zoomIn.putValue(Action.NAME, "In");
    zoomIn.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_I));
    zoomIn.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallPlayerFwd.png"));
    zoomIn.putValue(Action.LONG_DESCRIPTION, "Zoom in on the graph.");

    zoomOut = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel mgm = models.get(theTabs.getSelectedIndex());

            if (mgm instanceof ChartPanel)
                ((ChartPanel) mgm).zoomOutBoth(-1, -1);
            else if (mgm instanceof Graph3D) {
                double rho = ((Graph3D) mgm).getChart3DPanel().getViewPoint().getRho();
                ((Graph3D) mgm).getChart3DPanel().getViewPoint().setRho(rho + 5);
                ((Graph3D) mgm).getChart3DPanel().repaint();
            }
        }
    };

    zoomOut.putValue(Action.NAME, "Out");
    zoomOut.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_O));
    zoomOut.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallPlayerRew.png"));
    zoomOut.putValue(Action.LONG_DESCRIPTION, "Zoom out of the graph.");

    zoomDefault = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel mgm = models.get(theTabs.getSelectedIndex());

            if (mgm instanceof ChartPanel)
                ((ChartPanel) mgm).restoreAutoBounds();
            else if (mgm instanceof Graph3D) {
                ((Graph3D) mgm).getChart3DPanel().zoomToFit();
                ((Graph3D) mgm).getChart3DPanel().getDrawable()
                        .setViewPoint(new ViewPoint3D(-Math.PI / 2, Math.PI * 1.124, 70.0, 0.0));
                ((Graph3D) mgm).getChart3DPanel().repaint();

            }
        }
    };

    zoomDefault.putValue(Action.NAME, "Default");
    zoomDefault.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_D));
    zoomDefault.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallPlayerStart.png"));
    zoomDefault.putValue(Action.LONG_DESCRIPTION, "Set the default zoom for the graph.");

    importXML = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (plug.showOpenFileDialog(graFilter) != JFileChooser.APPROVE_OPTION)
                return;
            try {
                Graph mgm = Graph.load(plug.getChooserFile());
                addGraph(mgm);
            } catch (GraphException ex) {
                plug.error("Could not import PRISM graph file:\n" + ex.getMessage());
            }
        }
    };
    importXML.putValue(Action.NAME, "PRISM graph (*.gra)");
    importXML.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_I));
    importXML.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileGraph.png"));
    importXML.putValue(Action.LONG_DESCRIPTION, "Imports a saved PRISM graph from a file.");

    addFunction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {

            plotNewFunction();
        }
    };
    addFunction.putValue(Action.NAME, "Plot function");
    addFunction.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
    addFunction.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFunction.png"));
    addFunction.putValue(Action.LONG_DESCRIPTION, "Plots a new specified function on the current graph");

    exportXML = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (plug.showSaveFileDialog(graFilter) != JFileChooser.APPROVE_OPTION)
                return;
            Graph mgm = (Graph) models.get(theTabs.getSelectedIndex());
            try {
                mgm.save(plug.getChooserFile());
            } catch (PrismException ex) {
                plug.error("Could not export PRISM graph file:\n" + ex.getMessage());
            }
        }
    };
    exportXML.putValue(Action.NAME, "PRISM graph (*.gra)");
    exportXML.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_X));
    exportXML.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileGraph.png"));
    exportXML.putValue(Action.LONG_DESCRIPTION, "Export graph as a PRISM graph file.");

    exportImageJPG = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel model = getModel(theTabs.getSelectedIndex());

            GUIImageExportDialog imageDialog = new GUIImageExportDialog(plug.getGUI(), model,
                    GUIImageExportDialog.JPEG);
            saveImage(imageDialog);
        }
    };
    exportImageJPG.putValue(Action.NAME, "JPEG Interchange Format (*.jpg, *.jpeg)");
    exportImageJPG.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_J));
    exportImageJPG.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileImage.png"));
    exportImageJPG.putValue(Action.LONG_DESCRIPTION, "Export graph as a JPEG file.");

    exportImagePNG = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel model = getModel(theTabs.getSelectedIndex());
            GUIImageExportDialog imageDialog = new GUIImageExportDialog(plug.getGUI(), model,
                    GUIImageExportDialog.PNG);
            saveImage(imageDialog);

        }
    };
    exportImagePNG.putValue(Action.NAME, "Portable Network Graphics (*.png)");
    exportImagePNG.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
    exportImagePNG.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileImage.png"));
    exportImagePNG.putValue(Action.LONG_DESCRIPTION, "Export graph as a Portable Network Graphics file.");

    exportPDF = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (plug.showSaveFileDialog(pdfFilter) != JFileChooser.APPROVE_OPTION)
                return;

            JPanel mgm = models.get(theTabs.getSelectedIndex());

            if (mgm instanceof ChartPanel)
                Graph.exportToPDF(plug.getChooserFile(), ((ChartPanel) mgm).getChart());
            else if (mgm instanceof Graph3D) {

                Graph3D.exportToPDF(plug.getChooserFile(), ((Graph3D) mgm).getChart3DPanel());
            }

        }
    };
    exportPDF.putValue(Action.NAME, "Portable document format (*.pdf)");
    exportPDF.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
    exportPDF.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFilePdf.png"));
    exportPDF.putValue(Action.LONG_DESCRIPTION, "Export the graph as a Portable document format file.");

    exportImageEPS = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel model = getModel(theTabs.getSelectedIndex());

            if (model instanceof ChartPanel) {

                GUIImageExportDialog imageDialog = new GUIImageExportDialog(plug.getGUI(), (ChartPanel) model,
                        GUIImageExportDialog.EPS);

                saveImage(imageDialog);

            }
        }
    };
    exportImageEPS.putValue(Action.NAME, "Encapsulated PostScript (*.eps)");
    exportImageEPS.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_E));
    exportImageEPS.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFilePdf.png"));
    exportImageEPS.putValue(Action.LONG_DESCRIPTION, "Export graph as an Encapsulated PostScript file.");

    exportMatlab = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            if (plug.showSaveFileDialog(matlabFilter) != JFileChooser.APPROVE_OPTION)
                return;

            JPanel mgm = models.get(theTabs.getSelectedIndex());

            if (mgm instanceof Graph) {

                try {

                    ((Graph) mgm).exportToMatlab(plug.getChooserFile());

                } catch (IOException ex) {
                    plug.error("Could not export Matlab file:\n" + ex.getMessage());
                }

            } else if (mgm instanceof Graph3D) {

                try {

                    ((Graph3D) mgm).exportToMatlab(plug.getChooserFile());

                } catch (IOException e1) {

                    plug.error("Could not export Matlab file:\n" + e1.getMessage());
                    e1.printStackTrace();
                }
            }

        }
    };
    exportMatlab.putValue(Action.NAME, "Matlab file (*.m)");
    exportMatlab.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_M));
    exportMatlab.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallFileMatlab.png"));
    exportMatlab.putValue(Action.LONG_DESCRIPTION, "Export graph as a Matlab file.");

    exportGnuplot = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {

            if (plug.showSaveFileDialog(gnuplotFilter) != JFileChooser.APPROVE_OPTION)
                return;

            JPanel mgm = models.get(theTabs.getSelectedIndex());

            if (mgm instanceof ChartPanel) {

                try {
                    if (mgm instanceof Graph && !(mgm instanceof ParametricGraph)) {

                        ((Graph) mgm).exportToGnuplot(plug.getChooserFile());
                    } else if (mgm instanceof ParametricGraph) {

                        ((ParametricGraph) mgm).exportToGnuplot(plug.getChooserFile());
                    } else if (mgm instanceof Histogram) {
                        ((Histogram) mgm).exportToGnuplot(plug.getChooserFile());
                    }

                } catch (IOException ex) {
                    plug.error("Could not export Gnuplot file:\n" + ex.getMessage());
                }
            }

            else if (mgm instanceof Graph3D) {

                try {

                    ((Graph3D) mgm).exportToGnuplot(plug.getChooserFile());

                } catch (IOException ex) {

                    plug.error("Could not export Gnuplot file:\n" + ex.getMessage());
                    ex.printStackTrace();
                }
            }

        }
    };

    exportGnuplot.putValue(Action.NAME, "GNU Plot file(*.gnuplot)");
    exportGnuplot.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_G));
    exportGnuplot.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallgnuplot.png"));
    exportGnuplot.putValue(Action.LONG_DESCRIPTION, "Export graph as a GNU plot file.");

    printGraph = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel graph = models.get(theTabs.getSelectedIndex());

            if (graph instanceof ChartPanel) {

                if (graph instanceof Graph) {

                    if (!((Graph) graph).getDisplaySettings().getBackgroundColor().equals(Color.white)) {
                        if (plug.questionYesNo(
                                "Your graph has a coloured background, this background will show up on the \n"
                                        + "printout. Would you like to make the current background colour white?") == 0) {

                            ((Graph) graph).getDisplaySettings().setBackgroundColor(Color.white);
                        }
                    }

                } else if (graph instanceof Histogram) {

                    if (!((Histogram) graph).getDisplaySettings().getBackgroundColor().equals(Color.white)) {
                        if (plug.questionYesNo(
                                "Your graph has a coloured background, this background will show up on the \n"
                                        + "printout. Would you like to make the current background colour white?") == 0) {
                            ((Histogram) graph).getDisplaySettings().setBackgroundColor(Color.white);
                        }
                    }

                }

                ((ChartPanel) graph).createChartPrintJob();
            }

            if (graph instanceof Graph3D) {

                ((Graph3D) graph).createPrintJob();
            }
        }
    };

    printGraph.putValue(Action.NAME, "Print graph");
    printGraph.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_P));
    printGraph.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallPrint.png"));
    printGraph.putValue(Action.LONG_DESCRIPTION, "Print the graph to a printer or file");

    deleteGraph = new AbstractAction() {
        public void actionPerformed(ActionEvent e) {
            JPanel graph = models.get(theTabs.getSelectedIndex());

            models.remove(theTabs.getSelectedIndex());
            options.remove(theTabs.getSelectedIndex());
            theTabs.remove(graph);
        }
    };
    deleteGraph.putValue(Action.NAME, "Delete graph");
    deleteGraph.putValue(Action.MNEMONIC_KEY, new Integer(KeyEvent.VK_D));
    deleteGraph.putValue(Action.SMALL_ICON, GUIPrism.getIconFromImage("smallDelete.png"));
    deleteGraph.putValue(Action.LONG_DESCRIPTION, "Deletes the graph.");

    zoomMenu = new JMenu("Zoom");
    zoomMenu.setMnemonic('Z');
    zoomMenu.setIcon(GUIPrism.getIconFromImage("smallView.png"));
    zoomMenu.add(zoomIn);
    zoomMenu.add(zoomOut);
    zoomMenu.add(zoomDefault);

    exportMenu = new JMenu("Export graph");
    exportMenu.setMnemonic('E');
    exportMenu.setIcon(GUIPrism.getIconFromImage("smallExport.png"));
    exportMenu.add(exportXML);
    exportMenu.add(exportImagePNG);
    exportMenu.add(exportPDF);
    exportMenu.add(exportImageEPS);
    exportMenu.add(exportImageJPG);

    exportMenu.add(exportMatlab);
    exportMenu.add(exportGnuplot);

    importMenu = new JMenu("Import graph");
    importMenu.setMnemonic('I');
    importMenu.setIcon(GUIPrism.getIconFromImage("smallImport.png"));
    importMenu.add(importXML);

    graphMenu.add(graphOptions);
    graphMenu.add(zoomMenu);
    graphMenu.addSeparator();
    graphMenu.add(printGraph);
    graphMenu.add(deleteGraph);
    graphMenu.addSeparator();
    graphMenu.add(exportMenu);
    graphMenu.add(importMenu);
    graphMenu.add(addFunction);

    /* Tab context menu */
    backMenu.add(importXML);
}

From source file:latexstudio.editor.DropboxRevisionsTopComponent.java

public void updateRevisionsList(String path) {
    DbxClient client = DbxUtil.getDbxClient();
    List<DbxEntry.File> entries = null;

    if (path != null) {
        try {//from   w  w  w  .j  a  va  2  s.co  m
            entries = client.getRevisions(path);
        } catch (DbxException ex) {
            DbxUtil.showDbxAccessDeniedPrompt();
        }
    }

    dlm.clear();
    DefaultTableModel model = new DefaultTableModel() {
        @Override
        public boolean isCellEditable(int row, int column) {
            return column == REVIEW_COLUMN;
        }
    };
    model.addColumn(REVISION_COLUMN_NAME);
    model.addColumn(MODIFIED_COLUMN_NAME);
    model.addColumn(FILE_SIZE_COLUMN_NAME);
    model.addColumn(REVIEW_COLUMN_NAME);

    if (entries != null && entries.size() > 0) {
        for (DbxEntry.File dbxEntry : entries) {
            dlm.addElement(new DbxEntryRevision(dbxEntry));
            model.addRow(new Object[] { dbxEntry.rev, dbxEntry.lastModified, dbxEntry.humanSize,
                    REVIEW_BUTTON_LABEL });
        }
    }

    Action showVersion = new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            // Resolving which row has been double-clicked
            JTable table = (JTable) e.getSource();
            int row = Integer.valueOf(e.getActionCommand());
            // Finding revision using information from the clicked row
            String revisionNumber = table.getValueAt(row, REVISION_COLUMN).toString();
            loadRevision(revisionNumber);
        }
    };

    jTable1.setModel(model);
    ButtonColumn buttonColumn = new ButtonColumn(jTable1, showVersion, REVIEW_COLUMN);
    buttonColumn.setMnemonic(KeyEvent.VK_D);
}

From source file:net.sf.jabref.gui.journals.ManageJournalsPanel.java

public ManageJournalsPanel(final JabRefFrame frame) {
    this.frame = frame;

    personalFile.setEditable(false);/* w w  w  .j  a  va2  s.  c  o m*/

    ButtonGroup group = new ButtonGroup();
    group.add(newFile);
    group.add(oldFile);
    addExtPan.setLayout(new BorderLayout());
    JButton addExt = new JButton(IconTheme.JabRefIcon.ADD.getIcon());
    addExtPan.add(addExt, BorderLayout.EAST);
    addExtPan.setToolTipText(Localization.lang("Add"));
    FormLayout layout = new FormLayout("1dlu, 8dlu, left:pref, 4dlu, fill:200dlu:grow, 4dlu, fill:pref",
            "pref, pref, pref, 20dlu, 20dlu, fill:200dlu, 4dlu, pref");
    FormBuilder builder = FormBuilder.create().layout(layout);

    builder.addSeparator(Localization.lang("Built-in journal list")).xyw(2, 1, 6);
    JLabel description = new JLabel(
            "<HTML>" + Localization.lang("JabRef includes a built-in list of journal abbreviations.") + "<br>"
                    + Localization.lang(
                            "You can add additional journal names by setting up a personal journal list,<br>as "
                                    + "well as linking to external journal lists.")
                    + "</HTML>");
    description.setBorder(BorderFactory.createEmptyBorder(5, 0, 5, 0));
    builder.add(description).xyw(2, 2, 6);
    JButton viewBuiltin = new JButton(Localization.lang("View"));
    builder.add(viewBuiltin).xy(7, 2);
    builder.addSeparator(Localization.lang("Personal journal list")).xyw(2, 3, 6);

    builder.add(newFile).xy(3, 4);
    builder.add(newNameTf).xy(5, 4);
    JButton browseNew = new JButton(Localization.lang("Browse"));
    builder.add(browseNew).xy(7, 4);
    builder.add(oldFile).xy(3, 5);
    builder.add(personalFile).xy(5, 5);
    JButton browseOld = new JButton(Localization.lang("Browse"));
    builder.add(browseOld).xy(7, 5);

    userPanel.setLayout(new BorderLayout());
    builder.add(userPanel).xyw(2, 6, 4);
    ButtonStackBuilder butBul = new ButtonStackBuilder();
    butBul.addButton(add);
    butBul.addButton(remove);

    butBul.addGlue();
    builder.add(butBul.getPanel()).xy(7, 6);

    builder.addSeparator(Localization.lang("External files")).xyw(2, 8, 6);
    externalFilesPanel.setLayout(new BorderLayout());

    setLayout(new BorderLayout());
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    add(builder.getPanel(), BorderLayout.NORTH);
    add(externalFilesPanel, BorderLayout.CENTER);
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    JButton ok = new JButton(Localization.lang("OK"));
    bb.addButton(ok);
    JButton cancel = new JButton(Localization.lang("Cancel"));
    bb.addButton(cancel);
    bb.addUnrelatedGap();

    JButton help = new HelpAction(HelpFile.JOURNAL_ABBREV).getHelpButton();
    bb.addButton(help);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    dialog = new JDialog(frame, Localization.lang("Journal abbreviations"), false);
    dialog.getContentPane().add(this, BorderLayout.CENTER);
    dialog.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);

    // Set up panel for editing a single journal, to be used in a dialog box:
    FormLayout layout2 = new FormLayout("right:pref, 4dlu, fill:180dlu", "p, 2dlu, p");
    FormBuilder builder2 = FormBuilder.create().layout(layout2);
    builder2.add(Localization.lang("Journal name")).xy(1, 1);
    builder2.add(nameTf).xy(3, 1);
    builder2.add(Localization.lang("ISO abbreviation")).xy(1, 3);
    builder2.add(abbrTf).xy(3, 3);
    journalEditPanel = builder2.getPanel();

    viewBuiltin.addActionListener(e -> {
        JTable table = new JTable(JournalAbbreviationsUtil.getTableModel(Globals.journalAbbreviationLoader
                .getRepository(JournalAbbreviationPreferences.fromPreferences(Globals.prefs))
                .getAbbreviations()));
        JScrollPane pane = new JScrollPane(table);
        JOptionPane.showMessageDialog(null, pane, Localization.lang("Journal list preview"),
                JOptionPane.INFORMATION_MESSAGE);
    });

    browseNew.addActionListener(e -> {
        Path old = null;
        if (!newNameTf.getText().isEmpty()) {
            old = Paths.get(newNameTf.getText());
        }
        String name = FileDialogs.getNewFile(frame, old.toFile(), null, JFileChooser.SAVE_DIALOG, false);
        if (name != null) {
            newNameTf.setText(name);
            newFile.setSelected(true);
        }
    });

    browseOld.addActionListener(e -> {
        Path old = null;
        if (!personalFile.getText().isEmpty()) {
            old = Paths.get(personalFile.getText());
        }
        String name = FileDialogs.getNewFile(frame, old.toFile(), null, JFileChooser.OPEN_DIALOG, false);
        if (name != null) {
            personalFile.setText(name);
            oldFile.setSelected(true);
            oldFile.setEnabled(true);
            setupUserTable();
        }
    });

    ok.addActionListener(e -> {
        if (readyToClose()) {
            storeSettings();
            dialog.dispose();
        }
    });

    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            dialog.dispose();
        }
    };
    cancel.addActionListener(cancelAction);

    add.addActionListener(tableModel);
    remove.addActionListener(tableModel);
    addExt.addActionListener(e -> {
        externals.add(new ExternalFileEntry());
        buildExternalsPanel();
    });

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

    int xSize = getPreferredSize().width;
    dialog.setSize(xSize + 10, 700);
}

From source file:org.pgptool.gui.ui.mainframe.MainFrameView.java

@SuppressWarnings("serial")
private void initTableKeyListener() {
    InputMap inputMap = table.getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
    inputMap.put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), DELETE);
    table.getActionMap().put(DELETE, new AbstractAction() {
        @Override/*www. ja  v a 2 s .c  o  m*/
        public void actionPerformed(ActionEvent e) {
            if (pm == null) {
                return;
            }
            pm.actionDelete.actionPerformed(e);
        }
    });

    InputMap inputMap2 = table.getInputMap(JTable.WHEN_ANCESTOR_OF_FOCUSED_COMPONENT);
    inputMap2.put(KeyStroke.getKeyStroke(KeyEvent.VK_ENTER, 0), CHOOSE);
    table.getActionMap().put(CHOOSE, new AbstractAction() {
        @Override
        public void actionPerformed(ActionEvent e) {
            if (pm == null) {
                return;
            }
            pm.actionOpen.actionPerformed(e);
        }
    });
}

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

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

        @Override//from   www .j a va  2  s .  com
        public void actionPerformed(ActionEvent e) {
            runScript();
        }
    });
}

From source file:org.gofleet.module.routing.RoutingMap.java

private Map<String, String> getValues(LatLon from) {
    final Map<String, String> mapa = new HashMap<String, String>();
    final JDialog frame = new JDialog(basicWindow.getFrame(), "Configuration");
    JPanel panel = new JPanel(new GridLayout(0, 2));
    int width = 10;

    final JTextField maxDistance = new JTextField(width);
    maxDistance.setText("10");
    final JTextField maxTime = new JTextField(width);
    maxTime.setText("8");
    final JTextField origin_x = new JTextField(width / 2);
    origin_x.setText((new Double(from.getX())).toString());
    final JTextField origin_y = new JTextField(width / 2);
    origin_y.setText((new Double(from.getY())).toString());
    final JTextField startTime = new JTextField(width);
    startTime.setText("7");
    final JTextField timeSpentOnStop = new JTextField(width);
    timeSpentOnStop.setText("1");
    JLabel lmaxDistance = new JLabel("Maximum Distance (km)");
    lmaxDistance.setLabelFor(maxDistance);
    JLabel lmaxTime = new JLabel("Maximum Time (hours)");
    lmaxTime.setLabelFor(maxTime);//from w w  w.  j  a  v a  2 s .  c  o  m
    JLabel lorigin = new JLabel("Point of Origin");
    lorigin.setLabelFor(origin_x);
    JLabel lstartTime = new JLabel("Start Time of Plan (0-24)");
    lstartTime.setLabelFor(startTime);
    JLabel ltimeSpentOnStop = new JLabel("Time Spent on Stop (hours)");
    ltimeSpentOnStop.setLabelFor(timeSpentOnStop);

    JButton close = new JButton("OK");
    close.addActionListener(new AbstractAction() {

        private static final long serialVersionUID = -8912729211256933464L;

        @Override
        public void actionPerformed(ActionEvent arg0) {
            try {
                mapa.put("maxDistance", maxDistance.getText());
                mapa.put("maxTime", maxTime.getText());
                mapa.put("origin_x", origin_x.getText());
                mapa.put("origin_y", origin_y.getText());
                mapa.put("startTime", startTime.getText());
                mapa.put("timeSpentOnStop", timeSpentOnStop.getText());
                frame.dispose();
            } catch (Throwable t) {
                log.error("Error configuring New Route Plan" + t);
                JOptionPane.showMessageDialog(RoutingMap.this, "Some values are wrong. Check them again.");
            }
        }
    });

    panel.add(lmaxDistance);
    panel.add(maxDistance);
    panel.add(lmaxTime);
    panel.add(maxTime);
    panel.add(lorigin);
    JPanel panel_origin = new JPanel();
    panel_origin.add(origin_x);
    panel_origin.add(origin_y);
    panel.add(panel_origin);
    panel.add(lstartTime);
    panel.add(startTime);
    panel.add(ltimeSpentOnStop);
    panel.add(timeSpentOnStop);
    panel.add(close);
    frame.add(panel, BorderLayout.CENTER);
    frame.pack();
    frame.setModalityType(ModalityType.APPLICATION_MODAL);
    frame.setVisible(true);

    return mapa;
}