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(String name, Icon icon) 

Source Link

Document

Creates an Action with the specified name and small icon.

Usage

From source file:org.geopublishing.atlasViewer.swing.AtlasChartJPanel.java

/**
 * Creates a {@link JToolBar} that has buttons to interact with the Chart
 * and it's SelectionModel./*from w ww. j a v a  2  s. c  o m*/
 * 
 * @return
 */
public JToolBar getToolBar() {
    if (toolBar == null) {

        toolBar = new JToolBar();
        toolBar.setFloatable(false);

        ButtonGroup bg = new ButtonGroup();

        /**
         * Add an Action to ZOOM/MOVE in the chart
         */
        JToggleButton zoomToolButton = new SmallToggleButton(new AbstractAction("", ICON_ZOOM) {

            @Override
            public void actionPerformed(ActionEvent e) {
                getSelectableChartPanel().setWindowSelectionMode(WindowSelectionMode.ZOOM_IN_CHART);
            }

        }, GpCoreUtil.R("AtlasChartJPanel.zoom.tt"));
        toolBar.add(zoomToolButton);
        bg.add(zoomToolButton);

        toolBar.addSeparator();

        /**
         * Add an Action not change the selection but just move through the
         * chart
         */
        JToggleButton setSelectionButton = new SmallToggleButton(new AbstractAction("", ICON_SELECTION_SET) {

            @Override
            public void actionPerformed(ActionEvent e) {
                getSelectableChartPanel().setWindowSelectionMode(WindowSelectionMode.SELECT_SET);
            }

        });
        setSelectionButton.setToolTipText(MapPaneToolBar.R("MapPaneButtons.Selection.SetSelection.TT"));
        toolBar.add(setSelectionButton);
        bg.add(setSelectionButton);

        /**
         * Add an Action to ADD the selection.
         */
        JToggleButton addSelectionButton = new SmallToggleButton(new AbstractAction("", ICON_SELECTION_ADD) {

            @Override
            public void actionPerformed(ActionEvent e) {
                getSelectableChartPanel().setWindowSelectionMode(WindowSelectionMode.SELECT_ADD);
            }

        });
        addSelectionButton.setToolTipText(MapPaneToolBar.R("MapPaneButtons.Selection.AddSelection.TT"));
        toolBar.add(addSelectionButton);
        bg.add(addSelectionButton);

        /**
         * Add an Action to REMOVE the selection.
         */
        JToggleButton removeSelectionButton = new SmallToggleButton(
                new AbstractAction("", ICON_SELECTION_REMOVE) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        getSelectableChartPanel().setWindowSelectionMode(WindowSelectionMode.SELECT_REMOVE);
                    }

                });
        removeSelectionButton.setToolTipText(MapPaneToolBar.R("MapPaneButtons.Selection.RemoveSelection.TT"));
        toolBar.add(removeSelectionButton);
        bg.add(removeSelectionButton);

        toolBar.addSeparator();

        /**
         * Add a normal Button to clear the selection. The Chart's selection
         * models are cleared. If a relation to a JMapPane exists, they will
         * be synchronized.
         */
        final SmallButton clearSelectionButton = new SmallButton(new AbstractAction("", ICON_SELECTION_CLEAR) {

            @Override
            public void actionPerformed(ActionEvent e) {
                // getSelectionModel().clearSelection();

                // get the selectionmodel(s) of the chart
                List<FeatureDatasetSelectionModel<?, ?, ?>> datasetSelectionModelFor = FeatureChartUtil
                        .getFeatureDatasetSelectionModelFor(getSelectableChartPanel().getChart());

                for (FeatureDatasetSelectionModel dsm : datasetSelectionModelFor) {
                    dsm.clearSelection();
                }

            }

        }, MapPaneToolBar.R("MapPaneButtons.Selection.ClearSelection.TT"));

        {
            // Add listeners to the selection model, so we knwo when to
            // disable/enable the button

            // get the selectionmodel(s) of the chart
            List<FeatureDatasetSelectionModel<?, ?, ?>> datasetSelectionModelFor = FeatureChartUtil
                    .getFeatureDatasetSelectionModelFor(getSelectableChartPanel().getChart());
            for (final FeatureDatasetSelectionModel selModel : datasetSelectionModelFor) {
                DatasetSelectionListener listener_ClearSelectionButtonEnbled = new DatasetSelectionListener() {

                    @Override
                    public void selectionChanged(DatasetSelectionChangeEvent e) {
                        if (!e.getSource().getValueIsAdjusting()) {

                            // Update the clearSelectionButton
                            clearSelectionButton.setEnabled(selModel.getSelectedFeatures().size() > 0);
                        }
                    }
                };
                insertedListeners.add(listener_ClearSelectionButtonEnbled);
                selModel.addSelectionListener(listener_ClearSelectionButtonEnbled);

                clearSelectionButton.setEnabled(selModel.getSelectedFeatures().size() > 0);
            }
        }

        toolBar.add(clearSelectionButton);

        toolBar.addSeparator();

        /**
         * Add a normal Button which opens the Chart'S print dialog
         */
        SmallButton printChartButton = new SmallButton(new AbstractAction("", Icons.ICON_PRINT_24) {

            @Override
            public void actionPerformed(ActionEvent e) {

                getSelectableChartPanel().createChartPrintJob();

            }

        });
        printChartButton.setToolTipText(GpCoreUtil.R("AtlasChartJPanel.PrintChartButton.TT"));
        toolBar.add(printChartButton);

        /**
         * Add a normal Button which opens the Chart's export/save dialog
         */
        SmallButton saveChartAction = new SmallButton(new AbstractAction("", Icons.ICON_SAVEAS_24) {

            @Override
            public void actionPerformed(ActionEvent e) {

                try {
                    getSelectableChartPanel().doSaveAs();
                } catch (IOException e1) {
                    LOGGER.info("Saving a chart to file failed", e1);
                    ExceptionDialog.show(AtlasChartJPanel.this, e1);
                }

            }

        });
        saveChartAction.setToolTipText(GpCoreUtil.R("AtlasChartJPanel.SaveChartButton.TT"));
        toolBar.add(saveChartAction);

        //
        // A JButton to open the attribute table
        //
        {
            final JButton openTable = new JButton();
            openTable.setAction(new AbstractAction(GpCoreUtil.R("LayerToolMenu.table"), Icons.ICON_TABLE) {

                @Override
                public void actionPerformed(final ActionEvent e) {
                    AVDialogManager.dm_AttributeTable.getInstanceFor(styledLayer, AtlasChartJPanel.this,
                            styledLayer, mapLegend);
                }
            });
            toolBar.addSeparator();
            toolBar.add(openTable);
        }

        /*
         * Select/set data points button is activated by default
         */
        getSelectableChartPanel().setWindowSelectionMode(WindowSelectionMode.SELECT_SET);
        setSelectionButton.setSelected(true);

    }
    return toolBar;
}

From source file:org.interreg.docexplore.authoring.AuthoringToolFrame.java

public AuthoringToolFrame(final DocExploreDataLink link, final Startup startup) throws Exception {
    super("Authoring Tool");
    setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    this.startup = startup;
    this.displayHelp = startup.showHelp;

    startup.screen.setText("Initializing history");
    this.historyManager = new HistoryManager(50, new File(DocExploreTool.getHomeDir(), ".at-cache"));
    this.historyDialog = new JDialog(this, XMLResourceBundle.getBundledString("generalHistory"));
    historyDialog.add(new HistoryPanel(historyManager));
    historyDialog.pack();//from  ww  w.  ja v  a2s . c  om

    setJMenuBar(this.menu = new AuthoringMenu(this));

    startup.screen.setText("Initializing plugins");
    plugins = new Vector<MetaDataPlugin>();
    List<PluginConfig> pluginConfigs = startup.filterPlugins(MetaDataPlugin.class);
    for (PluginConfig config : pluginConfigs) {
        MetaDataPlugin plugin = null;
        if ((plugin = (MetaDataPlugin) config.clazz.newInstance()) != null) {
            plugins.add(plugin);
            plugin.setHost(config.jarFile, config.dependencies);
            System.out.println(
                    "Loaded plugin '" + plugin.getName() + "' (" + plugin.getClass().getSimpleName() + ")");
        }
    }

    startup.screen.setText("Initializing filters");
    //filter = new FilterPanel(link);
    this.importOptions = new ImportOptions(this);
    startup.screen.setText("Initializing styles");
    this.styleManager = new StyleManager(this);

    startup.screen.setText("Creating explorer data link");
    this.linkExplorer = new DataLinkExplorer(this, link, null);

    //linkExplorer.toolPanel.add(filter);
    //linkExplorer.setFilter(filter);

    startup.screen.setText("Creating explorer");
    //this.fileExplorer = new FileExplorer(this);

    this.explorer = new JPanel(new BorderLayout());
    explorer.add(
            new JLabel("<html><font style=\"font-size:16\">"
                    + XMLResourceBundle.getBundledString("generalLibraryLabel") + "</font></html>"),
            BorderLayout.NORTH);
    explorer.add(linkExplorer, BorderLayout.CENTER);
    //explorer.addTab(XMLResourceBundle.getBundledString("generalFilesLabel"), fileExplorer);

    startup.screen.setText("Creating editor data link");
    recovery = defaultFile.exists();
    DataLink fslink = new DataLinkFS2Source(defaultFile.getAbsolutePath()).getDataLink();
    fslink.setProperty("autoWrite", false);
    final DocExploreDataLink editorLink = new DocExploreDataLink();
    final JLabel titleLabel = new JLabel();
    editorLink.addListener(new DocExploreDataLink.Listener() {
        public void dataLinkChanged(DataLink link) {
            String bookName = "";
            try {
                List<Integer> books = editorLink.getLink().getAllBookIds();
                if (!books.isEmpty()) {
                    Book book = editorLink.getBook(books.get(0));
                    bookName = book.getName();
                    MetaDataKey key = editorLink.getOrCreateKey("styles", "");
                    List<MetaData> mds = book.getMetaDataListForKey(key);
                    MetaData md = null;
                    if (mds.isEmpty()) {
                        md = new MetaData(editorLink, key, "");
                        book.addMetaData(md);
                    } else
                        md = mds.get(0);
                    styleManager.setMD(md);
                }
            } catch (Exception e) {
                e.printStackTrace();
            }

            String linkTitle = menu.curFile == null ? null : menu.curFile.getAbsolutePath();
            titleLabel.setText("<html><font style=\"font-size:14\">"
                    + XMLResourceBundle.getBundledString("generalPresentationLabel") + " : <b>" + bookName
                    + "</b>" + (linkTitle != null ? " (" + linkTitle + ")" : "") + "</font></html>");
            setTitle(XMLResourceBundle.getBundledString("frameTitle") + " "
                    + (linkTitle != null ? linkTitle : ""));
            historyManager.reset(-1);
            repaint();
        }
    });
    editorLink.setLink(fslink);

    startup.screen.setText("Creating editor");
    this.editor = new DataLinkExplorer(this, editorLink, new BookImporter());
    for (ExplorerView view : editor.views)
        if (view instanceof PageEditorView) {
            this.mdEditor = new MetaDataEditor(((PageEditorView) view).editor);
        }
    editor.addListener(new Explorer.Listener() {
        @Override
        public void exploringChanged(Object object) {
            try {
                boolean isRegion = object instanceof Region;
                int div = splitPane.getDividerLocation();
                mdEditor.setDocument(null);
                if (isRegion)
                    mdEditor.setDocument((Region) object);
                if (isRegion != regionMode)
                    splitPane.setRightComponent(isRegion ? mdEditor : explorer);
                regionMode = isRegion;
                validate();
                splitPane.setDividerLocation(div);
            } catch (Exception e) {
                ErrorHandler.defaultHandler.submit(e);
            }
        }
    });
    final JButton editBook = new JButton(new AbstractAction("", ImageUtils.getIcon("pencil-24x24.png")) {
        @Override
        public void actionPerformed(ActionEvent e) {
            try {
                Book book = editorLink.getBook(editorLink.getLink().getAllBookIds().get(0));
                String name = JOptionPane.showInputDialog(AuthoringToolFrame.this,
                        XMLResourceBundle.getBundledString("collectionAddBookMessage"), book.getName());
                if (name == null)
                    return;
                book.setName(name);
                editorLink.notifyDataLinkChanged();
                editor.refreshPath();
            } catch (Exception ex) {
                ErrorHandler.defaultHandler.submit(ex);
            }
        }
    });
    editBook.setToolTipText(XMLResourceBundle.getBundledString("generalToolbarEdit"));

    this.splitPane = new JSplitPane();
    JPanel editorPanel = new JPanel(new BorderLayout());
    JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.LEFT));
    titlePanel.add(titleLabel);
    titlePanel.add(editBook);
    //editorPanel.add(titlePanel, BorderLayout.NORTH);
    editorPanel.add(editor, BorderLayout.CENTER);
    splitPane.setLeftComponent(editorPanel);
    splitPane.setRightComponent(explorer);

    getContentPane().setLayout(new BorderLayout());
    add(titlePanel, BorderLayout.NORTH);
    add(splitPane, BorderLayout.CENTER);

    this.clipboard = new MetaDataClipboard(this, new File(DocExploreTool.getHomeDir(), ".at-clipboard"));

    startup.screen.setText("Initializing exporter");
    this.readerExporter = new ReaderExporter(this);
    this.webExporter = new WebExporter(this);

    addWindowListener(new WindowAdapter() {
        public void windowClosing(WindowEvent e) {
            quit();
        }

        public void windowOpened(WindowEvent e) {
            splitPane.setDividerLocation(getWidth() / 2);
        }
    });
    this.oldSize = getWidth();
    addComponentListener(new ComponentAdapter() {
        public void componentResized(ComponentEvent e) {
            splitPane.setDividerLocation(splitPane.getDividerLocation() * getWidth() / oldSize);
            oldSize = getWidth();
        }
    });
}

From source file:com.intuit.tank.tools.debugger.ActionProducer.java

/**
 * /* ww  w.  java  2 s.c  o  m*/
 * @return
 */
public Action getOpenAction() {
    Action ret = actionMap.get(ACTION_OPEN);
    if (ret == null) {
        ret = new AbstractAction(ACTION_OPEN, getIcon("script_go.png", IconSize.SMALL)) {
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent event) {
                try {
                    int option = jFileChooser.showOpenDialog(debuggerFrame);
                    if (option != JFileChooser.CANCEL_OPTION) {
                        File selectedFile = jFileChooser.getSelectedFile();
                        try {
                            String scriptXml = FileUtils.readFileToString(selectedFile);
                            setFromString(scriptXml);
                            debuggerFrame.setScriptSource(
                                    new ScriptSource(selectedFile.getAbsolutePath(), SourceType.file));
                        } catch (Exception e) {
                            LOG.error("Error reading file " + selectedFile.getName() + ": " + e);
                            JOptionPane.showMessageDialog(debuggerFrame, e.getMessage(),
                                    "Error unmarshalling xml", JOptionPane.ERROR_MESSAGE);
                        }
                    }
                } catch (HeadlessException e) {
                    showError("Error opening file: " + e);
                }
            }
        };
        ret.putValue(Action.SHORT_DESCRIPTION, "Open Agent xml from filesystem.");
        ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('O', menuActionMods));
        ret.putValue(Action.MNEMONIC_KEY, new Integer('O'));
        actionMap.put(ACTION_OPEN, ret);
    }
    return ret;
}

From source file:com.stonelion.zooviewer.ui.JZVNodePanel.java

private Action getRefreshAction() {
    if (this.refreshAction == null) {
        String actionCommand = bundle.getString(REFRESH_NODE_KEY);
        String actionKey = bundle.getString(REFRESH_NODE_KEY + ".action");
        this.refreshAction = new AbstractAction(actionCommand, Icons.REFRESH) {
            /**/*from w ww  .j a  v a2 s  . c o m*/
             *
             */
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent e) {
                model.refresh(nodes[0].getPath(), true);
            }
        };

        this.refreshAction.putValue(Action.ACTION_COMMAND_KEY, actionKey);
        this.getInputMap(WHEN_IN_FOCUSED_WINDOW).put(KeyStroke.getKeyStroke(KeyEvent.VK_DELETE, 0), actionKey);
        this.getActionMap().put(actionKey, this.refreshAction);
    }
    return this.refreshAction;
}

From source file:de.tor.tribes.ui.views.DSWorkbenchSOSRequestAnalyzer.java

private void buildMenu() {
    JXTaskPane viewPane = new JXTaskPane();
    viewPane.setTitle("Ansicht");
    JXButton toSosView = new JXButton(
            new ImageIcon(DSWorkbenchTagFrame.class.getResource("/res/ui/axe24.png")));
    toSosView.setToolTipText("Eingelesene SOS-Anfragen anzeigen");
    toSosView.addMouseListener(new MouseAdapter() {

        @Override/*w  w w .j a  va 2  s  .  co  m*/
        public void mouseReleased(MouseEvent e) {
            jScrollPane6.setViewportView(jAttacksTable);
        }
    });
    viewPane.getContentPane().add(toSosView);

    JXButton toSupportView = new JXButton(
            new ImageIcon(DSWorkbenchTagFrame.class.getResource("/res/ui/sword24.png")));
    toSupportView.setToolTipText("Errechnete Untersttzungen anzeigen");
    toSupportView.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            jScrollPane6.setViewportView(jSupportsTable);
        }
    });

    viewPane.getContentPane().add(toSupportView);

    JXTaskPane transferPane = new JXTaskPane();
    transferPane.setTitle("bertragen");
    JXButton toSupport = new JXButton(
            new ImageIcon(DSWorkbenchTagFrame.class.getResource("/res/ui/support_tool.png")));
    toSupport.setToolTipText(
            "bertrgt den ersten Angriff der gewhlten SOS-Anfrage in das Untersttzungswerkzeug");
    toSupport.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            transferToSupportTool();
        }
    });

    transferPane.getContentPane().add(toSupport);

    JXButton toRetime = new JXButton(
            new ImageIcon(DSWorkbenchTagFrame.class.getResource("/res/ui/re-time.png")));
    toRetime.setToolTipText(
            "bertrgt den gewhlten Angriff in den ReTimer. Anschlieend muss dort noch die vermutete Einheit gewhlt werden!");
    toRetime.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            transferToRetimeTool();
        }
    });

    transferPane.getContentPane().add(toRetime);

    JXButton toBrowser = new JXButton(
            new ImageIcon(DSWorkbenchTagFrame.class.getResource("/res/ui/att_browser.png")));
    toBrowser.setToolTipText("bertrgt die gewhlten Untersttzungen in den Browser");
    toBrowser.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            transferToBrowser();
        }
    });

    transferPane.getContentPane().add(toBrowser);

    transferPane.getContentPane().add(new JXButton(new AbstractAction(null,
            new ImageIcon(DSWorkbenchTagFrame.class.getResource("/res/ui/sos_clipboard.png"))) {

        @Override
        public Object getValue(String key) {
            if (key.equals(Action.SHORT_DESCRIPTION)) {
                return "Untersttzungsanfragen fr die gewhlten, unvollstndigen Verteidigungen erstellen"
                        + " und in die Zwischenablage kopieren";
            }
            return super.getValue(key);
        }

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

    JXTaskPane miscPane = new JXTaskPane();
    miscPane.setTitle("Sonstiges");
    JXButton reAnalyzeButton = new JXButton(
            new ImageIcon(DSWorkbenchTagFrame.class.getResource("/res/ui/reanalyze.png")));
    reAnalyzeButton.setToolTipText(
            "Analysiert die eingelesenen Angriffe erneut, z.B. wenn man die Truppenzahlen in den Einstellungen gendert hat.");
    reAnalyzeButton.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            analyzeData(true);
        }
    });
    miscPane.getContentPane().add(reAnalyzeButton);
    JXButton setSelectionSecured = new JXButton(
            new ImageIcon(DSWorkbenchTagFrame.class.getResource("/res/ui/save.png")));
    setSelectionSecured.setToolTipText(
            "Die gewhlten Eintrge manuell auf 'Sicher' setzen, z.B. weil man sie ignorieren mchte oder bereits gengend Untersttzungen laufen.");
    setSelectionSecured.addMouseListener(new MouseAdapter() {

        @Override
        public void mouseReleased(MouseEvent e) {
            setSelectionSecured();
        }
    });
    miscPane.getContentPane().add(setSelectionSecured);
    clickAccount = new ClickAccountPanel();
    profileQuickchangePanel = new ProfileQuickChangePanel();
    centerPanel.setupTaskPane(clickAccount, profileQuickchangePanel, viewPane, transferPane, miscPane);
}

From source file:com.intuit.tank.tools.debugger.ActionProducer.java

/**
 * //ww w.  ja  v  a2s .  co  m
 * @return
 */
public Action getReloadAction() {
    Action ret = actionMap.get(ACTION_RELOAD);
    if (ret == null) {
        ret = new AbstractAction(ACTION_RELOAD, getIcon("refresh.png", IconSize.SMALL)) {
            private static final long serialVersionUID = 1L;

            @Override
            public void actionPerformed(ActionEvent event) {
                try {
                    final ScriptSource scriptSource = debuggerFrame.getScriptSource();
                    if (scriptSource != null) {
                        debuggerFrame.startWaiting();
                        setFromString(null);
                        // get script in thread
                        new Thread(new Runnable() {
                            public void run() {
                                try {
                                    String scriptXml = null;
                                    if (scriptSource.getSource() == SourceType.file) {
                                        scriptXml = FileUtils.readFileToString(new File(scriptSource.getId()));
                                    } else if (scriptSource.getSource() == SourceType.script) {
                                        scriptXml = scriptServiceClient
                                                .downloadHarnessXml(Integer.parseInt(scriptSource.getId()));
                                    } else if (scriptSource.getSource() == SourceType.project) {
                                        scriptXml = projectServiceClient.downloadTestScriptForProject(
                                                Integer.parseInt(scriptSource.getId()));
                                    }
                                    if (scriptXml != null) {
                                        setFromString(scriptXml);
                                    }
                                } catch (Exception e1) {
                                    e1.printStackTrace();
                                    debuggerFrame.stopWaiting();
                                    showError("Error opening from source: " + e1);
                                } finally {
                                    debuggerFrame.stopWaiting();
                                }
                            }
                        }).start();

                    } else {
                        JOptionPane.showMessageDialog(debuggerFrame,
                                "Scripts can only be reloaded if they have been loaded first.",
                                "Load Script from source", JOptionPane.ERROR_MESSAGE);
                    }
                } catch (HeadlessException e) {
                    showError("Error opening file: " + e);
                }
            }
        };
        ret.putValue(Action.SHORT_DESCRIPTION, "Reload scrpt from source.");
        ret.putValue(Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke('R', menuActionMods));
        ret.putValue(Action.MNEMONIC_KEY, new Integer('R'));
        ret.setEnabled(false);
        actionMap.put(ACTION_RELOAD, ret);
    }
    return ret;
}

From source file:com.opendoorlogistics.studio.appframe.AppFrame.java

private void initMenus(ActionFactory actionBuilder, MenuFactory menuBuilder, List<? extends Action> fileActions,
        List<? extends Action> editActions) {
    final JMenuBar menuBar = new JMenuBar();
    class AddSpace {
        void add() {
            JMenu dummy = new JMenu();
            dummy.setEnabled(false);//from w ww . java  2s.  co m
            menuBar.add(dummy);
        }
    }
    AddSpace addSpace = new AddSpace();

    // add file menu ... build on the fly for recent files..
    setJMenuBar(menuBar);
    final JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic('F');
    mnFile.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            initFileMenu(mnFile, fileActions, actionBuilder, menuBuilder);
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void menuCanceled(MenuEvent e) {
            // TODO Auto-generated method stub

        }
    });
    initFileMenu(mnFile, fileActions, actionBuilder, menuBuilder);
    menuBar.add(mnFile);
    addSpace.add();

    // add edit menu
    JMenu mnEdit = new JMenu("Edit");
    mnEdit.setMnemonic('E');
    menuBar.add(mnEdit);
    addSpace.add();
    for (Action action : editActions) {
        mnEdit.add(action);
        //         if (action.accelerator != null) {
        //            item.setAccelerator(action.accelerator);
        //         }
    }

    // add run scripts menu (hidden until a datastore is loaded)
    mnScripts = new JMenu(appPermissions.isScriptEditingAllowed() ? "Run script" : "Run");
    mnScripts.setMnemonic('R');
    mnScripts.setVisible(false);
    mnScripts.addMenuListener(new MenuListener() {

        private void addScriptNode(JMenu parentMenu, boolean usePopupForChildren, ScriptNode node) {
            if (node.isAvailable() == false) {
                return;
            }
            if (node.isRunnable()) {
                parentMenu.add(new AbstractAction(node.getDisplayName(), node.getIcon()) {

                    @Override
                    public void actionPerformed(ActionEvent e) {
                        postScriptExecution(node.getFile(), node.getLaunchExecutorId());
                    }
                });
            } else if (node.getChildCount() > 0) {
                JMenu newParent = parentMenu;
                if (usePopupForChildren) {
                    newParent = new JMenu(node.getDisplayName());
                    parentMenu.add(newParent);
                }
                ;
                for (int i = 0; i < node.getChildCount(); i++) {
                    addScriptNode(newParent, true, (ScriptNode) node.getChildAt(i));
                }
            }
        }

        @Override
        public void menuSelected(MenuEvent e) {
            mnScripts.removeAll();
            ScriptNode[] scripts = scriptsPanel.getScripts();
            for (final ScriptNode item : scripts) {
                addScriptNode(mnScripts, scripts.length > 1, item);
            }
            mnScripts.validate();
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    menuBar.add(mnScripts);
    addSpace.add();

    // add create script menu
    if (appPermissions.isScriptEditingAllowed()) {
        JMenu scriptsMenu = menuBuilder.createScriptCreationMenu(this, scriptManager);
        if (scriptsMenu != null) {
            menuBar.add(scriptsMenu);
        }
        addSpace.add();
    }

    // tools menu
    JMenu tools = new JMenu("Tools");
    menuBar.add(tools);
    JMenu memoryCache = new JMenu("Memory cache");
    tools.add(memoryCache);
    memoryCache.add(new AbstractAction("View cache statistics") {

        @Override
        public void actionPerformed(ActionEvent e) {
            TextInformationDialog dlg = new TextInformationDialog(AppFrame.this, "Memory cache statistics",
                    ApplicationCache.singleton().getUsageReport());
            dlg.setMinimumSize(new Dimension(400, 400));
            dlg.setLocationRelativeTo(AppFrame.this);
            dlg.setVisible(true);
        }
    });
    memoryCache.add(new AbstractAction("Clear memory cache") {

        @Override
        public void actionPerformed(ActionEvent e) {
            ApplicationCache.singleton().clearCache();
        }
    });
    addSpace.add();

    // add window menu
    JMenu mnWindow = menuBuilder.createWindowsMenu(this);
    mnWindow.add(new AbstractAction("Show all tables") {

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

    JMenu mnResizeTo = new JMenu("Resize application to...");
    for (final int[] size : new int[][] { new int[] { 1280, 720 }, new int[] { 1920, 1080 } }) {
        mnResizeTo.add(new AbstractAction("" + size[0] + " x " + size[1]) {

            @Override
            public void actionPerformed(ActionEvent e) {
                // set standard layout
                setSize(size[0], size[1]);
                splitterMain.setDividerLocation(0.175);
                splitterLeftSide.setDividerLocation(0.3);
            }
        });
    }
    mnWindow.add(mnResizeTo);
    menuBar.add(mnWindow);
    addSpace.add();

    menuBar.add(menuBuilder.createHelpMenu(actionBuilder, this));

    addSpace.add();

}

From source file:com.opendoorlogistics.studio.AppFrame.java

private void initMenus() {
    final JMenuBar menuBar = new JMenuBar();
    class AddSpace {
        void add() {
            JMenu dummy = new JMenu();
            dummy.setEnabled(false);/*from   w  ww  . ja  v a  2  s.  c  o m*/
            menuBar.add(dummy);
        }
    }
    AddSpace addSpace = new AddSpace();

    // add file menu ... build on the fly for recent files..
    setJMenuBar(menuBar);
    final JMenu mnFile = new JMenu("File");
    mnFile.setMnemonic('F');
    mnFile.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            initFileMenu(mnFile);
        }

        @Override
        public void menuDeselected(MenuEvent e) {
            // TODO Auto-generated method stub

        }

        @Override
        public void menuCanceled(MenuEvent e) {
            // TODO Auto-generated method stub

        }
    });
    initFileMenu(mnFile);
    menuBar.add(mnFile);
    addSpace.add();

    // add edit menu
    JMenu mnEdit = new JMenu("Edit");
    mnEdit.setMnemonic('E');
    menuBar.add(mnEdit);
    addSpace.add();
    for (MyAction action : editActions) {
        JMenuItem item = mnEdit.add(action);
        if (action.accelerator != null) {
            item.setAccelerator(action.accelerator);
        }
    }

    // add run scripts menu (hidden until a datastore is loaded)
    mnScripts = new JMenu("Run script");
    mnScripts.setMnemonic('R');
    mnScripts.setVisible(false);
    mnScripts.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            mnScripts.removeAll();
            for (final ScriptNode item : scriptsPanel.getScripts()) {
                if (item.isAvailable() == false) {
                    continue;
                }
                if (item.isRunnable()) {
                    mnScripts.add(new AbstractAction(item.getDisplayName(), item.getIcon()) {

                        @Override
                        public void actionPerformed(ActionEvent e) {
                            scriptManager.executeScript(item.getFile(), item.getLaunchExecutorId());
                        }
                    });
                } else if (item.getChildCount() > 0) {
                    JMenu popup = new JMenu(item.getDisplayName());
                    mnScripts.add(popup);
                    for (int i = 0; i < item.getChildCount(); i++) {
                        final ScriptNode child = (ScriptNode) item.getChildAt(i);
                        if (child.isRunnable()) {
                            popup.add(new AbstractAction(child.getDisplayName(), child.getIcon()) {

                                @Override
                                public void actionPerformed(ActionEvent e) {
                                    scriptManager.executeScript(child.getFile(), child.getLaunchExecutorId());
                                }
                            });
                        }

                    }
                }
            }
            mnScripts.validate();
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

        @Override
        public void menuCanceled(MenuEvent e) {
        }
    });
    menuBar.add(mnScripts);
    addSpace.add();

    // add create script menu
    menuBar.add(initCreateScriptsMenu());
    addSpace.add();

    // add window menu
    JMenu mnWindow = new JMenu("Window");
    mnWindow.setMnemonic('W');
    menuBar.add(mnWindow);
    addSpace.add();
    initWindowMenus(mnWindow);

    menuBar.add(initHelpMenu());

    addSpace.add();

}

From source file:org.geopublishing.atlasViewer.swing.AtlasChartJPanel.java

/**
 * If {@link #previewMapPane} and {@link #mapLegend} are both not <code>null</code>
 * , this method adds a {@link JButton}/*w ww . j a  v  a2s  . co m*/
 * 
 * @param atlasChartPanel
 */
public void addZoomToFeatureExtends(final SelectableXMapPane myMapPane, final MapLegend mapLegend,
        final StyledFeaturesInterface<?> styledFeatures, AtlasChartJPanel atlasChartPanel) {
    if (myMapPane != null && mapLegend != null) {

        /**
         * Add a normal Button to zoom to the BBOX of the selected objects.
         */
        final SmallButton zoomToSelectionButton = new SmallButton(
                new AbstractAction("", SelectableChartPanel.ICON_ZOOM_TO_SELECTED) {

                    @Override
                    public void actionPerformed(final ActionEvent e) {

                        final StyledLayerSelectionModel<?> anySelectionModel = myMapPane != null
                                ? mapLegend.getRememberSelection(styledFeatures.getId())
                                : null;

                        if ((anySelectionModel instanceof StyledFeatureLayerSelectionModel)) {
                            final StyledFeatureLayerSelectionModel selectionModel = (StyledFeatureLayerSelectionModel) anySelectionModel;

                            final Vector<String> selectionIDs = selectionModel.getSelection();

                            try {

                                /*
                                 * Creating a set of FeatureIdImpl which can
                                 * be used for a FidFilter
                                 */
                                final HashSet<Identifier> setOfIdentifiers = new HashSet<Identifier>();
                                for (final String idString : selectionIDs) {
                                    setOfIdentifiers.add(new FeatureIdImpl(idString));
                                }

                                final FeatureCollection<SimpleFeatureType, SimpleFeature> selectedFeatures = styledFeatures
                                        .getFeatureSource()
                                        .getFeatures(FeatureUtil.FILTER_FACTORY2.id(setOfIdentifiers));
                                myMapPane.zoomTo(selectedFeatures);
                                myMapPane.refresh();

                            } catch (final IOException e1) {
                                throw new RuntimeException("While zooming to the selected features.", e1);
                            }

                        }

                    }

                });
        // zoomToSelectionButton.setBorder(BorderFactory
        // .createRaisedBevelBorder());
        zoomToSelectionButton.setToolTipText(GeotoolsGUIUtil
                .R("schmitzm.geotools.gui.SelectableFeatureTablePane.button.zoomToSelection.tt"));
        final JToolBar toolBar = atlasChartPanel.getToolBar();
        toolBar.add(zoomToSelectionButton, 6);

        {
            // Add listeners to the selection model, so we know when to
            // disable/enable the button

            // get the selectionmodel(s) of the chart
            List<FeatureDatasetSelectionModel<?, ?, ?>> datasetSelectionModelFor = FeatureChartUtil
                    .getFeatureDatasetSelectionModelFor(atlasChartPanel.getChart());
            for (final FeatureDatasetSelectionModel selModel : datasetSelectionModelFor) {

                DatasetSelectionListener listener_ZoomToSelectionButtonEnbled = new DatasetSelectionListener() {

                    @Override
                    public void selectionChanged(DatasetSelectionChangeEvent e) {
                        if (!e.getSource().getValueIsAdjusting()) {

                            // Update the clearSelectionButton
                            zoomToSelectionButton.setEnabled(selModel.getSelectedFeatures().size() > 0);
                        }
                    }
                };
                insertedListeners.add(listener_ZoomToSelectionButtonEnbled);
                selModel.addSelectionListener(listener_ZoomToSelectionButtonEnbled);

                zoomToSelectionButton.setEnabled(selModel.getSelectedFeatures().size() > 0);
            }
        }
    }
}

From source file:com.intuit.tank.proxy.ProxyApp.java

/**
 * //from  w ww  . j a v  a2 s .co  m
 */
@SuppressWarnings("serial")
private void createActions() {

    startAction = new AbstractAction("Start Recording", loadImage("icons/16/control_play_blue.png")) {
        public void actionPerformed(ActionEvent arg0) {
            try {
                start();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(ProxyApp.this, "Error statrting proxy: " + e.toString(), "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }

    };
    startAction.putValue(javax.swing.Action.SHORT_DESCRIPTION, "Start Recording");

    stopAction = new AbstractAction("Stop Recording", loadImage("icons/16/control_stop_blue.png")) {
        public void actionPerformed(ActionEvent arg0) {
            try {
                stop();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(ProxyApp.this, "Error stopping proxy: " + e.toString(), "Error",
                        JOptionPane.ERROR_MESSAGE);
            }
        }

    };
    stopAction.setEnabled(false);
    stopAction.putValue(javax.swing.Action.SHORT_DESCRIPTION, "Stop Recording");

    pauseAction = new AbstractAction("Pause Recording", loadImage("icons/16/control_pause_blue.png")) {
        public void actionPerformed(ActionEvent arg0) {
            pause();
        }
    };
    pauseAction.setEnabled(false);
    pauseAction.putValue(javax.swing.Action.SHORT_DESCRIPTION, "Pause Recording");

    settingsAction = new AbstractAction("Settings", loadImage("icons/16/cog.png")) {
        public void actionPerformed(ActionEvent arg0) {
            showSettings();
        }

    };
    settingsAction.putValue(javax.swing.Action.SHORT_DESCRIPTION, "Settings");

    filterAction = new AbstractAction("Run Filters", loadImage("icons/16/filter.png")) {
        public void actionPerformed(ActionEvent arg0) {
            filter();
        }

    };
    filterAction.putValue(javax.swing.Action.SHORT_DESCRIPTION, "Run Filters");
    filterAction.setEnabled(false);

    saveAction = new AbstractAction("Save", loadImage("icons/16/save_as.png")) {
        public void actionPerformed(ActionEvent arg0) {
            save();
        }

    };
    saveAction.setEnabled(false);
    saveAction.putValue(javax.swing.Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_S, keyMask));
    saveAction.putValue(javax.swing.Action.SHORT_DESCRIPTION, "Save");

    openAction = new AbstractAction("Open Recording...", loadImage("icons/16/folder_go.png")) {
        public void actionPerformed(ActionEvent arg0) {
            openRecording();
        }

    };
    openAction.putValue(javax.swing.Action.ACCELERATOR_KEY, KeyStroke.getKeyStroke(KeyEvent.VK_O, keyMask));
    openAction.putValue(javax.swing.Action.SHORT_DESCRIPTION, "Open Recording...");

    showHostsAction = new AbstractAction("Hosts...", loadImage("icons/16/page_add.png")) {
        public void actionPerformed(ActionEvent arg0) {
            showHosts();
        }

    };
    showHostsAction.putValue(javax.swing.Action.ACCELERATOR_KEY,
            KeyStroke.getKeyStroke(KeyEvent.VK_H, keyMask));
    showHostsAction.putValue(javax.swing.Action.SHORT_DESCRIPTION, "Show Hosts...");

    fileChooser = new JFileChooser(new File("."));
    fileChooser.setDialogTitle("Open Recording...");
    fileChooser.setFileFilter(new XmlFileFilter());
}