Example usage for javax.swing JMenuItem JMenuItem

List of usage examples for javax.swing JMenuItem JMenuItem

Introduction

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

Prototype

public JMenuItem(Action a) 

Source Link

Document

Creates a menu item whose properties are taken from the specified Action.

Usage

From source file:de.freese.base.swing.mac_os_x.MyApp.java

/**
 *
 *///from www.  jav  a2 s  .  c o m
public void addMenus() {
    JMenu fileMenu = new JMenu("File");
    JMenuBar mainMenuBar = new JMenuBar();
    mainMenuBar.add(fileMenu = new JMenu("File"));
    fileMenu.add(this.openMI = new JMenuItem("Open..."));
    this.openMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, MENU_MASK));
    this.openMI.addActionListener(this);

    // Quit/prefs menu items are provided on Mac OS X; only add your own on other platforms
    if (!IS_OS_MAC_OSX) {
        fileMenu.addSeparator();
        fileMenu.add(this.optionsMI = new JMenuItem("Options"));
        this.optionsMI.addActionListener(this);

        fileMenu.addSeparator();
        fileMenu.add(this.quitMI = new JMenuItem("Quit"));
        this.quitMI.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, MENU_MASK));
        this.quitMI.addActionListener(this);
    }

    mainMenuBar.add(this.helpMenu = new JMenu("Help"));
    this.helpMenu.add(this.docsMI = new JMenuItem("Online Documentation"));
    this.helpMenu.addSeparator();
    this.helpMenu.add(this.supportMI = new JMenuItem("Technical Support"));

    // About menu item is provided on Mac OS X; only add your own on other platforms
    if (!IS_OS_MAC_OSX) {
        this.helpMenu.addSeparator();
        this.helpMenu.add(this.aboutMI = new JMenuItem("About OSXAdapter"));
        this.aboutMI.addActionListener(this);
    }

    setJMenuBar(mainMenuBar);
}

From source file:com.googlecode.bpmn_simulator.gui.BPMNSimulatorFrame.java

private JMenu createMenuFile() {
    final JMenu menuFile = new JMenu(Messages.getString("Menu.file")); //$NON-NLS-1$

    final JMenuItem menuFileOpen = new JMenuItem(Messages.getString("Menu.fileOpen")); //$NON-NLS-1$
    menuFileOpen.setMnemonic(KeyEvent.VK_O);
    menuFileOpen.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.ALT_MASK));
    menuFileOpen.addActionListener(new ActionListener() {
        @Override/*from w ww .j av  a2 s  . c  o m*/
        public void actionPerformed(final ActionEvent e) {
            openFile();
        }
    });
    menuFile.add(menuFileOpen);
    menuFile.add(menuFileRecent);

    final JMenuItem menuFileReload = new JMenuItem(Messages.getString("Menu.fileReload")); //$NON-NLS-1$
    menuFileReload.setMnemonic(KeyEvent.VK_R);
    menuFileReload.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, InputEvent.ALT_MASK));
    menuFileReload.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            reloadDefinition();
        }
    });
    menuFile.add(menuFileReload);

    final JMenuItem menuFileClose = new JMenuItem(Messages.getString("Menu.fileClose")); //$NON-NLS-1$
    menuFileClose.setMnemonic(KeyEvent.VK_C);
    menuFileClose.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, InputEvent.ALT_MASK));
    menuFileClose.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            closeSource();
        }
    });
    menuFile.add(menuFileClose);

    menuFile.addSeparator();

    final JMenuItem menuFileProperties = new JMenuItem(Messages.getString("Menu.properties")); //$NON-NLS-1$
    menuFileProperties.setMnemonic(KeyEvent.VK_P);
    menuFileProperties.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.ALT_MASK));
    menuFileProperties.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showPropertiesDialog();
        }
    });
    menuFile.add(menuFileProperties);

    menuFile.addSeparator();

    final JMenuItem menuFileExport = createMenuFileExport();
    menuFile.add(menuFileExport);

    menuFile.addSeparator();

    final JMenuItem menuFilePreferences = new JMenuItem(Messages.getString("Menu.preferences")); //$NON-NLS-1$
    menuFilePreferences.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showPreferencesDialog();
        }
    });
    menuFile.add(menuFilePreferences);

    menuFile.addSeparator();

    final JMenuItem menuFileExit = new JMenuItem(Messages.getString("Menu.exit")); //$NON-NLS-1$
    menuFileExit.setMnemonic(KeyEvent.VK_E);
    menuFileExit.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK));
    menuFileExit.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            for (Frame frame : getFrames()) {
                if (frame.isActive()) {
                    frame.dispatchEvent(new WindowEvent(frame, WindowEvent.WINDOW_CLOSING));
                }
            }
        }
    });
    menuFile.add(menuFileExit);

    menuFile.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(final MenuEvent e) {
            menuFileReload.setEnabled(isSourceOpen() && currentSource.canReopen());
            menuFileClose.setEnabled(isSourceOpen());
            menuFileProperties.setEnabled(isDefinitionOpen());
            menuFileExport.setEnabled(isDefinitionOpen());
        }

        @Override
        public void menuDeselected(final MenuEvent e) {
        }

        @Override
        public void menuCanceled(final MenuEvent e) {
        }
    });

    return menuFile;
}

From source file:com.diversityarrays.kdxplore.field.FieldViewDialog.java

public FieldViewDialog(Window owner, String title, SampleGroupChoice sgcSamples, Trial trial,
        SampleGroupChoice sgcNewMedia, KDSmartDatabase db) throws IOException {
    super(owner, title, ModalityType.MODELESS);

    advanceRetreatControls = Box.createHorizontalBox();
    advanceRetreatControls.add(new JButton(retreatAction));
    advanceRetreatControls.add(new JButton(advanceAction));

    autoAdvanceControls = Box.createHorizontalBox();
    autoAdvanceControls.add(new JButton(autoAdvanceAction));

    autoAdvanceOption.addActionListener(new ActionListener() {
        @Override/*from   ww  w.  j ava  2  s . c om*/
        public void actionPerformed(ActionEvent e) {
            updateMovementControls();
        }
    });

    this.database = db;
    this.sampleGroupChoiceForSamples = sgcSamples;
    this.sampleGroupChoiceForNewMedia = sgcNewMedia;

    NumberSpinner fontSpinner = new NumberSpinner(new SpinnerNumberModel(), "0.00");

    this.fieldViewPanel = FieldViewPanel.create(database, trial, SeparatorVisibilityOption.VISIBLE, null,
            Box.createHorizontalGlue(), new JButton(showInfoAction), Box.createHorizontalGlue(),
            new JLabel("Font Size:"), fontSpinner, Box.createHorizontalGlue(), advanceRetreatControls,
            autoAdvanceOption, autoAdvanceControls);

    initialiseAction(advanceAction, "ic_object_advance_black.png", "Auto-Advance");

    this.xyProvider = fieldViewPanel.getXYprovider();
    this.traitMap = fieldViewPanel.getTraitMap();

    fieldLayoutTable = fieldViewPanel.getFieldLayoutTable();

    JScrollPane scrollPane = fieldViewPanel.getFieldTableScrollPane();
    scrollPane.setHorizontalScrollBarPolicy(JScrollPane.HORIZONTAL_SCROLLBAR_AS_NEEDED);

    fieldLayoutTable.setTransferHandler(flth);
    fieldLayoutTable.setDropMode(DropMode.ON);

    fieldLayoutTable.addMouseListener(new MouseAdapter() {
        JPopupMenu popupMenu;

        @Override
        public void mouseClicked(MouseEvent e) {
            if (!SwingUtilities.isRightMouseButton(e) || 1 != e.getClickCount()) {
                return;
            }
            Point pt = e.getPoint();
            int row = fieldLayoutTable.rowAtPoint(pt);
            if (row >= 0) {
                int col = fieldLayoutTable.columnAtPoint(pt);
                if (col >= 0) {
                    Plot plot = fieldViewPanel.getPlotAt(col, row);
                    if (plot != null) {
                        if (popupMenu == null) {
                            popupMenu = new JPopupMenu("View Attachments");
                        }
                        popupMenu.removeAll();

                        Set<File> set = plot.getMediaFiles();
                        if (Check.isEmpty(set)) {
                            popupMenu.add(new JMenuItem("No Attachments available"));
                        } else {
                            for (File file : set) {
                                Action a = new AbstractAction(file.getName()) {
                                    @Override
                                    public void actionPerformed(ActionEvent e) {
                                        try {
                                            Desktop.getDesktop().browse(file.toURI());
                                        } catch (IOException e1) {
                                            MsgBox.warn(FieldViewDialog.this, e1, file.getName());
                                        }
                                    }
                                };
                                popupMenu.add(new JMenuItem(a));
                            }
                        }
                        popupMenu.show(fieldLayoutTable, pt.x, pt.y);
                    }
                }
            }
        }

    });
    Font font = fieldLayoutTable.getFont();
    float fontSize = font.getSize2D();

    fontSizeModel = new SpinnerNumberModel(fontSize, fontSize, 50.0, 1.0);
    fontSpinner.setModel(fontSizeModel);
    fontSizeModel.addChangeListener(new ChangeListener() {
        @Override
        public void stateChanged(ChangeEvent e) {
            float fsize = fontSizeModel.getNumber().floatValue();
            System.out.println("Using fontSize=" + fsize);
            Font font = fieldLayoutTable.getFont().deriveFont(fsize);
            fieldLayoutTable.setFont(font);
            FontMetrics fm = fieldLayoutTable.getFontMetrics(font);
            int lineHeight = fm.getMaxAscent() + fm.getMaxDescent();
            fieldLayoutTable.setRowHeight(4 * lineHeight);

            //                GuiUtil.initialiseTableColumnWidths(fieldLayoutTable, false);

            fieldLayoutTable.repaint();
        }
    });

    fieldLayoutTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
    fieldLayoutTable.setResizable(true, true);
    fieldLayoutTable.getTableColumnResizer().setResizeAllColumns(true);

    advanceAction.setEnabled(false);
    fieldLayoutTable.getSelectionModel().addListSelectionListener(new ListSelectionListener() {
        @Override
        public void valueChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                handlePlotSelection();
            }
        }
    });
    TableColumnModel columnModel = fieldLayoutTable.getColumnModel();
    columnModel.addColumnModelListener(new TableColumnModelListener() {
        @Override
        public void columnSelectionChanged(ListSelectionEvent e) {
            if (!e.getValueIsAdjusting()) {
                handlePlotSelection();
            }
        }

        @Override
        public void columnRemoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnMoved(TableColumnModelEvent e) {
        }

        @Override
        public void columnMarginChanged(ChangeEvent e) {
        }

        @Override
        public void columnAdded(TableColumnModelEvent e) {
        }
    });

    PropertyChangeListener listener = new PropertyChangeListener() {
        // Use a timer and redisplay other columns when delay is GT 100 ms

        Timer timer = new Timer(true);
        TimerTask timerTask;
        long lastActive;
        boolean busy = false;
        private int eventColumnWidth;
        private TableColumn eventColumn;

        @Override
        public void propertyChange(PropertyChangeEvent evt) {
            if (busy) {
                return;
            }

            if (evt.getSource() instanceof TableColumn && "width".equals(evt.getPropertyName())) {

                eventColumn = (TableColumn) evt.getSource();
                eventColumnWidth = eventColumn.getWidth();

                lastActive = System.currentTimeMillis();
                if (timerTask == null) {
                    timerTask = new TimerTask() {
                        @Override
                        public void run() {
                            if (System.currentTimeMillis() - lastActive > 200) {
                                timerTask.cancel();
                                timerTask = null;

                                busy = true;
                                try {
                                    for (Enumeration<TableColumn> en = columnModel.getColumns(); en
                                            .hasMoreElements();) {
                                        TableColumn tc = en.nextElement();
                                        if (tc != eventColumn) {
                                            tc.setWidth(eventColumnWidth);
                                        }
                                    }
                                } finally {
                                    busy = false;
                                }
                            }
                        }
                    };
                    timer.scheduleAtFixedRate(timerTask, 100, 150);
                }
            }
        }
    };
    for (Enumeration<TableColumn> en = columnModel.getColumns(); en.hasMoreElements();) {
        TableColumn tc = en.nextElement();
        tc.addPropertyChangeListener(listener);
    }

    Map<Integer, Plot> plotById = new HashMap<>();
    for (Plot plot : fieldViewPanel.getFieldLayout()) {
        plotById.put(plot.getPlotId(), plot);
    }

    TrialItemVisitor<Sample> sampleVisitor = new TrialItemVisitor<Sample>() {
        @Override
        public void setExpectedItemCount(int count) {
        }

        @Override
        public boolean consumeItem(Sample sample) throws IOException {

            Plot plot = plotById.get(sample.getPlotId());
            if (plot == null) {
                throw new IOException("Missing plot for plotId=" + sample.getPlotId() + " sampleIdent="
                        + Util.createUniqueSampleKey(sample));
            }
            plot.addSample(sample);

            SampleCounts counts = countsByTraitId.get(sample.getTraitId());
            if (counts == null) {
                counts = new SampleCounts();
                countsByTraitId.put(sample.getTraitId(), counts);
            }
            if (sample.hasBeenScored()) {
                ++counts.scored;
            } else {
                ++counts.unscored;
            }
            return true;
        }
    };
    database.visitSamplesForTrial(sampleGroupChoiceForSamples, trial.getTrialId(),
            SampleOrder.ALL_BY_PLOT_ID_THEN_TRAIT_ID_THEN_INSTANCE_NUMBER_ORDER_THEN_SPECIMEN_NUMBER,
            sampleVisitor);

    setDefaultCloseOperation(DISPOSE_ON_CLOSE);

    this.trial = trial;

    KDClientUtils.initAction(ImageId.SETTINGS_24, showInfoAction, "Trial Summary");

    Action clear = new AbstractAction("Clear") {
        @Override
        public void actionPerformed(ActionEvent e) {
            infoTextArea.setText("");
        }
    };
    JPanel bottom = new JPanel(new BorderLayout());
    bottom.add(GuiUtil.createLabelSeparator("Plot Details", new JButton(clear)), BorderLayout.NORTH);
    bottom.add(new JScrollPane(infoTextArea), BorderLayout.CENTER);
    JSplitPane splitPane = new JSplitPane(JSplitPane.VERTICAL_SPLIT, fieldViewPanel,
            new JScrollPane(infoTextArea));
    splitPane.setResizeWeight(0.0);
    splitPane.setOneTouchExpandable(true);

    setContentPane(splitPane);

    updateMovementControls();
    pack();
}

From source file:gdt.jgui.entity.JEntityStructurePanel.java

/**
 * Get the context menu./*  w  ww  . jav a  2s  . co m*/
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    JMenu menu = new JMenu("Context");
    menu.setName("Context");
    JMenuItem facetItem = new JMenuItem("Facets");
    facetItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Properties locator = Locator.toProperties(locator$);
            String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
            String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
            JEntityFacetPanel efp = new JEntityFacetPanel();
            String efpLocator$ = efp.getLocator();
            efpLocator$ = Locator.append(efpLocator$, Entigrator.ENTIHOME, entihome$);
            efpLocator$ = Locator.append(efpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
            JConsoleHandler.execute(console, efpLocator$);
        }
    });
    menu.add(facetItem);

    JMenuItem digestItem = new JMenuItem("Digest");
    digestItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            Properties locator = Locator.toProperties(locator$);
            String entihome$ = locator.getProperty(Entigrator.ENTIHOME);
            String entityKey$ = locator.getProperty(EntityHandler.ENTITY_KEY);
            JEntityDigestDisplay edp = new JEntityDigestDisplay();
            String edpLocator$ = edp.getLocator();
            edpLocator$ = Locator.append(edpLocator$, Entigrator.ENTIHOME, entihome$);
            edpLocator$ = Locator.append(edpLocator$, EntityHandler.ENTITY_KEY, entityKey$);
            JConsoleHandler.execute(console, edpLocator$);
        }
    });
    menu.add(digestItem);
    return menu;
}

From source file:com.rapidminer.gui.new_plotter.gui.ColorSchemeDialog.java

/**
 *
 *///from w  w w . j a va2s  .  c o m
private void createComponents() {

    // creat popup menus
    {

        popupMenu = new JPopupMenu();
        removeMenuItem = new JMenuItem(I18N
                .getGUILabel("plotter.configuration_dialog.color_scheme_dialog.remove_color_menu_item.label"));
        removeMenuItem.addActionListener(new ActionListener() {

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

        });
        popupMenu.add(removeMenuItem);

        changeColorMenuItem = new JMenuItem(I18N
                .getGUILabel("plotter.configuration_dialog.color_scheme_dialog.change_color_menu_item.label"));
        changeColorMenuItem.addActionListener(new ActionListener() {

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

        });
        popupMenu.add(changeColorMenuItem);

        popupMenu.addSeparator();

        moveUpColorMenuItem = new JMenuItem(
                I18N.getGUILabel("plotter.configuration_dialog.color_scheme_dialog.move_up_menu_item.label"));
        moveUpColorMenuItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                moveSelectedColorUpAction();

            }

        });
        popupMenu.add(moveUpColorMenuItem);

        moveDownColorMenuItem = new JMenuItem(
                I18N.getGUILabel("plotter.configuration_dialog.color_scheme_dialog.move_down_menu_item.label"));
        moveDownColorMenuItem.addActionListener(new ActionListener() {

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

        });
        popupMenu.add(moveDownColorMenuItem);

    }

    JPanel containerPanel = new JPanel(new GridBagLayout());
    containerPanel.setPreferredSize(new Dimension(520, 450));

    // create containing panel
    {

        {
            JPanel configurePanel = new JPanel(new GridBagLayout());
            configurePanel.setPreferredSize(new Dimension(220, 400));
            configurePanel.setBorder(BorderFactory.createTitledBorder(I18N.getGUILabel(
                    "plotter.configuration_dialog.color_scheme_dialog.scheme_configuration_border.label")));

            // add scheme list panel
            {
                JPanel schemeComboBoxPanel = createSchemeComboBoxPanel();

                // add category choosing panel
                GridBagConstraints itemConstraint = new GridBagConstraints();
                itemConstraint.fill = GridBagConstraints.BOTH;
                itemConstraint.weightx = 1;
                itemConstraint.weighty = 1;
                itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
                itemConstraint.insets = new Insets(2, 2, 2, 5);

                configurePanel.add(schemeComboBoxPanel, itemConstraint);
            }

            {
                categoryAndGradientConfigPanel = new JPanel(new GridBagLayout());

                // add categories panel
                {
                    JPanel categoryConfigurationPanel = createColorCategoriesPanel();

                    // add category choosing panel
                    GridBagConstraints itemConstraint = new GridBagConstraints();
                    itemConstraint.fill = GridBagConstraints.BOTH;
                    itemConstraint.weightx = 1;
                    itemConstraint.weighty = 1;
                    itemConstraint.insets = new Insets(2, 2, 2, 5);
                    itemConstraint.gridwidth = GridBagConstraints.REMAINDER;

                    categoryAndGradientConfigPanel.add(categoryConfigurationPanel, itemConstraint);

                }

                // add gradient chooser panel
                {
                    JPanel gradientConfigPanel = createGradientConfigurationPanel();

                    GridBagConstraints itemConstraint = new GridBagConstraints();
                    itemConstraint.fill = GridBagConstraints.BOTH;
                    itemConstraint.weightx = 1;
                    itemConstraint.weighty = 1;
                    itemConstraint.insets = new Insets(2, 2, 2, 5);
                    itemConstraint.gridwidth = GridBagConstraints.REMAINDER;

                    categoryAndGradientConfigPanel.add(gradientConfigPanel, itemConstraint);
                }

                GridBagConstraints itemConstraint = new GridBagConstraints();
                itemConstraint.fill = GridBagConstraints.BOTH;
                itemConstraint.weightx = 1;
                itemConstraint.weighty = 1;
                itemConstraint.gridwidth = GridBagConstraints.REMAINDER;
                itemConstraint.insets = new Insets(2, 2, 2, 5);

                configurePanel.add(categoryAndGradientConfigPanel, itemConstraint);

            }

            GridBagConstraints itemConstraint = new GridBagConstraints();
            itemConstraint.fill = GridBagConstraints.BOTH;
            itemConstraint.weightx = 1;
            itemConstraint.weighty = 1;
            itemConstraint.gridwidth = GridBagConstraints.RELATIVE;
            containerPanel.add(configurePanel, itemConstraint);
        }

        createPlotPreviewPanel(containerPanel);

    }

    // create buttons
    Collection<AbstractButton> buttons = new LinkedList<AbstractButton>();
    buttons.add(makeOkButton());

    Action saveAction = new ResourceAction("plotter.configuration_dialog.color_scheme_dialog.save_button") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            save(currentColorSchemes, currentActiveColorSchemeName);

            // set new scheme
            plotConfig.setColorSchemes(currentColorSchemes, currentActiveColorSchemeName);
        }
    };
    saveButton = new JButton(saveAction);
    buttons.add(saveButton);
    saveButton.setEnabled(false);

    Action revertAction = new ResourceAction("plotter.configuration_dialog.color_scheme_dialog.revert_button") {

        private static final long serialVersionUID = 1L;

        @Override
        public void actionPerformed(ActionEvent e) {
            revert();
        }
    };
    revertButton = new JButton(revertAction);
    revertButton.setEnabled(false);
    buttons.add(revertButton);
    buttons.add(makeCancelButton("plotter.configuration_dialog.color_scheme_dialog.cancel_button"));

    layoutDefault(containerPanel, buttons);
}

From source file:com.limegroup.gnutella.gui.library.LibraryTableMediator.java

private JMenu createSearchSubMenu(LibraryTableDataLine dl) {
    JMenu menu = new JMenu(GUIMediator.getStringResource("LIBRARY_TABLE_SEARCH_POPUP_MENU"));

    if (dl != null) {
        File f = (File) dl.getInitializeObject();
        String keywords = StringUtils.createQueryString(f.getName());
        if (keywords.length() > 2)
            menu.add(new JMenuItem(new SearchAction(keywords)));

        LimeXMLDocument doc = dl.getXMLDocument();
        if (doc != null) {
            Action[] actions = ActionUtils.createSearchActions(doc);
            for (int i = 0; i < actions.length; i++)
                menu.add(new JMenuItem(actions[i]));
        }/*  ww w .j  a va  2s . c om*/
    }

    if (menu.getItemCount() == 0)
        menu.setEnabled(false);

    return menu;
}

From source file:misc.TextBatchPrintingDemo.java

/**
 * Create and return a menu item with the specified action, mnemonics and
 * keyboad accelerator./*from   ww  w  . ja va2s.c o m*/
 */
JMenuItem createMenuItem(Action action, int mnemonics, KeyStroke accel) {
    JMenuItem item = new JMenuItem(action);
    item.setMnemonic(mnemonics);
    item.setAccelerator(accel);
    return item;
}

From source file:ucar.unidata.idv.control.chart.ChartHolder.java

/**
 * Add in the zoom menu items/*  w  w w.j a  v  a2  s .c o  m*/
 *
 * @param items items
 */
private void addZoomMenuItems(List items) {
    JMenuItem mi;
    JMenu menu;

    items.add(menu = new JMenu("Zoom In"));
    menu.add(mi = new JMenuItem("All Axes"));
    mi.setActionCommand(ChartPanel.ZOOM_IN_BOTH_COMMAND);
    mi.addActionListener(chartPanel);
    menu.addSeparator();

    menu.add(mi = new JMenuItem("Domain Axis"));
    mi.setActionCommand(ChartPanel.ZOOM_IN_DOMAIN_COMMAND);
    mi.addActionListener(chartPanel);

    menu.add(mi = new JMenuItem("Range Axis"));
    mi.setActionCommand(ChartPanel.ZOOM_IN_RANGE_COMMAND);
    mi.addActionListener(chartPanel);

    items.add(menu = new JMenu("Zoom Out"));

    menu.add(mi = new JMenuItem("All Axes"));
    mi.setActionCommand(ChartPanel.ZOOM_OUT_BOTH_COMMAND);
    mi.addActionListener(chartPanel);

    menu.addSeparator();

    menu.add(mi = new JMenuItem("Domain Axis"));
    mi.setActionCommand(ChartPanel.ZOOM_OUT_DOMAIN_COMMAND);
    mi.addActionListener(chartPanel);

    menu.add(mi = new JMenuItem("Range Axis"));
    mi.setActionCommand(ChartPanel.ZOOM_OUT_RANGE_COMMAND);
    mi.addActionListener(chartPanel);

    items.add(menu = new JMenu("Auto Range"));

    menu.add(mi = new JMenuItem("All Axes"));
    mi.setActionCommand(ChartPanel.ZOOM_RESET_BOTH_COMMAND);
    mi.addActionListener(chartPanel);

    menu.addSeparator();

    menu.add(mi = new JMenuItem("Domain Axis"));
    mi.setActionCommand(ChartPanel.ZOOM_RESET_DOMAIN_COMMAND);
    mi.addActionListener(chartPanel);

    menu.add(mi = new JMenuItem("Range Axis"));
    mi.setActionCommand(ChartPanel.ZOOM_RESET_RANGE_COMMAND);
    mi.addActionListener(chartPanel);
}

From source file:com.igormaznitsa.jhexed.swing.editor.ui.MainForm.java

public MainForm(final String fileToOpen) {
    Log.info("Start in editor mode");

    this.application = null;
    this.hexLayerList = null;

    initComponents();/*w w  w .j  a v a 2  s.  c o m*/

    final JFrame theFrame = this;

    for (final javax.swing.UIManager.LookAndFeelInfo info : javax.swing.UIManager.getInstalledLookAndFeels()) {
        final JMenuItem landfItem = new JMenuItem(info.getName());
        landfItem.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(ActionEvent e) {
                try {
                    javax.swing.UIManager.setLookAndFeel(info.getClassName());
                } catch (Exception ex) {
                    Log.error("Can't change L&F", ex);
                }
                SwingUtilities.updateComponentTreeUI(theFrame);
            }
        });
        menuLANDF.add(landfItem);
    }

    popupMenu = new JPopupMenu();
    final JMenuItem comments = new JMenuItem("Comments");
    comments.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent e) {
            // open dialog for cell comment
            final CellCommentDialog commentDialog = new CellCommentDialog(theFrame,
                    "Commentaries for the cell at " + popupHex.getColumn() + "," + popupHex.getRow(),
                    cellComments.getForHex(popupHex));
            commentDialog.setVisible(true);
            final String result = commentDialog.getResult();
            if (result != null) {
                cellComments.setForHex(popupHex, result);
            }
        }
    });
    popupMenu.add(comments);

    hexMapPanelDesktop = new Desktop();
    layers = new LayerListModel(256, 128);

    try {
        this.setIconImage(ImageIO.read(this.getClass().getClassLoader()
                .getResource("com/igormaznitsa/jhexed/swing/editor/icons/logo.png")));
    } catch (Exception ex) {
        Log.error("Can't load app icon", ex);
    }

    hexMapPanel = new HexMapPanel(this.layers);
    hexMapPanel.addHexMapPanelListener(this);

    hexMapPanel.addMouseListener(this);
    hexMapPanel.addMouseMotionListener(this);
    hexMapPanel.addMouseWheelListener(this);

    this.panelMainArea.add(hexMapPanelDesktop, BorderLayout.CENTER);

    this.frameLayers = new FrameLayers(layers, hexMapPanel);
    this.frameTools = new FrameTools();
    this.frameToolOptions = new FrameToolOptions();

    hexMapPanelDesktop.addFrame(this.frameLayers);
    hexMapPanelDesktop.addFrame(this.frameTools);
    hexMapPanelDesktop.addFrame(this.frameToolOptions);

    this.frameLayers.setVisible(true);
    this.frameTools.setVisible(true);
    this.frameToolOptions.setVisible(true);

    hexMapPanelDesktop.setContentPane(hexMapPanel);

    this.dsl = new GroovyPluginBase(this, this.layers);
    this.compilerConfiguration = new CompilerConfiguration();
    this.compilerConfiguration.setScriptBaseClass(DelegatingScript.class.getName());
    this.groovyShell = new GroovyShell(this.compilerConfiguration);

    InsideApplicationBus.getInstance().addAppBusListener(this);

    loadSettings();

    resetState();

    Log.info("The MainForm created");

    registerInternalPlugins();
    registerExternalPlugins(".");

    if (fileToOpen != null) {
        Log.info("Started with parameter: " + fileToOpen);
        final File file = new File(fileToOpen);
        loadFromFile(file);
    }

    this.lookupContainer = new ObjectLookup(this, this.hexMapPanel.getHexEngine(), this,
            Log.makeApplicationLog());
    this.applicationGraphics = null;
}

From source file:com.univocity.app.swing.DataAnalysisWindow.java

private JMenuItem newJMenuItem(String label, final DaoTable table, final String engineName,
        final boolean enableUpdates, final boolean applyToAll) {
    JMenuItem item = new JMenuItem(label);
    item.addActionListener(new ActionListener() {
        @Override//from w  w  w . ja  v  a  2 s. c o  m
        public void actionPerformed(ActionEvent e) {
            Object[] primaryKey = table.getSelectedPrimaryKey();
            if (ArrayUtils.isNotEmpty(primaryKey)) {
                DataIntegrationEngine engine = Univocity.getEngine(engineName);

                String entity = table.getDatabaseName() + "." + table.getSelectedTableName();

                if (applyToAll) {
                    if (enableUpdates) {
                        engine.enableUpdateOnAllRecords(entity);
                    } else {
                        engine.disableUpdateOnAllRecords(entity);
                    }
                } else {
                    ModifiableDataset dataset = Univocity.datasetFactory().newDataset(new ArrayList<Object[]>(),
                            table.getPrimaryKeyNames());
                    dataset.insert(table.getSelectedPrimaryKey());

                    if (enableUpdates) {
                        engine.enableUpdateOnRecords(entity, dataset);
                    } else {
                        engine.disableUpdateOnRecords(entity, dataset);
                    }
                }
            }
        }
    });
    return item;
}