Example usage for javax.swing JMenu add

List of usage examples for javax.swing JMenu add

Introduction

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

Prototype

public JMenuItem add(Action a) 

Source Link

Document

Creates a new menu item attached to the specified Action object and appends it to the end of this menu.

Usage

From source file:com.evanbelcher.DrillBook.display.DBMenuBar.java

/**
 * Constructs DBMenuBar. Adds the menu and menuitems.
 *
 * @param graphicsRunner the JFrame that created this
 * @param desktop        the DBDesktopPane in the JFrame
 *///from  w ww. j  a  v a2s. co  m
public DBMenuBar(GraphicsRunner graphicsRunner, DBDesktopPane desktop) {
    super();

    gr = graphicsRunner;
    this.desktop = desktop;

    //Set up the menu
    JMenu menu = new JMenu("File");
    add(menu);

    //Set up the menu items.
    JMenuItem menuItem = new JMenuItem("New");
    menuItem.setMnemonic(KeyEvent.VK_N);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_DOWN_MASK));
    menuItem.setActionCommand("new");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem("Open");
    menuItem.setMnemonic(KeyEvent.VK_O);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_DOWN_MASK));
    menuItem.setActionCommand("open");
    menuItem.addActionListener(this);
    menuItem.setLayout(new MigLayout());
    menu.add(menuItem);

    menuItem = new JMenuItem("Save");
    menuItem.setMnemonic(KeyEvent.VK_S);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_DOWN_MASK));
    menuItem.setActionCommand("save");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem("Save As");
    menuItem.setActionCommand("saveas");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem("Print    Current Page");
    menuItem.setMnemonic(KeyEvent.VK_P);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, InputEvent.CTRL_DOWN_MASK));
    menuItem.setActionCommand("printpage");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem("Print Show");
    menuItem.setActionCommand("printshow");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem("Print Dot Sheets");
    menuItem.setActionCommand("printdotsheets");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem("Quit");
    menuItem.setMnemonic(KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, InputEvent.CTRL_DOWN_MASK));
    menuItem.setActionCommand("quit");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menu = new JMenu("Edit");
    add(menu);

    menuItem = new JMenuItem("Undo");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Z, InputEvent.CTRL_DOWN_MASK));
    menuItem.setActionCommand("undo");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem("Redo");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Y, InputEvent.CTRL_DOWN_MASK));
    menuItem.setActionCommand("redo");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menu = new JMenu("Settings");
    add(menu);

    menuItem = new JMenuItem("Toggle Gridlines");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, InputEvent.CTRL_DOWN_MASK));
    menuItem.setActionCommand("togglegrid");
    menuItem.addActionListener(this);
    menuItem.setForeground(Main.getState().getSettings().shouldShowGrid() ? Color.BLACK : Color.RED);
    menu.add(menuItem);

    menuItem = new JMenuItem("Toggle Dot Names");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, InputEvent.CTRL_DOWN_MASK));
    menuItem.setActionCommand("togglenames");
    menuItem.addActionListener(this);
    menuItem.setForeground(Main.getState().getSettings().shouldShowNames() ? Color.BLACK : Color.RED);
    menu.add(menuItem);

    menuItem = new JMenuItem("Toggle Text Box");
    menuItem.setActionCommand("toggletext");
    menuItem.addActionListener(this);
    menuItem.setForeground(Main.getState().getSettings().shouldShowText() ? Color.BLACK : Color.RED);
    menu.add(menuItem);

    menuItem = new JMenuItem("Color Code Dots by Instrument");
    menuItem.setActionCommand("colordots");
    menuItem.addActionListener(this);
    menuItem.setForeground(Main.getState().getSettings().shouldColorDots() ? Color.BLACK : Color.RED);
    menu.add(menuItem);

    menuItem = new JMenuItem();
    menuItem.setText(Main.getState().getSettings().useCollegeHashes() ? "Change to High School Hashes"
            : "Change to College Hashes");
    menuItem.setActionCommand("changehash");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem("Change Font Size");
    menuItem.setActionCommand("fontsize");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    //add(Box.createHorizontalStrut(menu.getPreferredSize().width));

    //add these to the menubar itself
    menuItem = new JMenuItem("Play");
    menuItem.setMaximumSize(new Dimension(menuItem.getPreferredSize().width, Integer.MAX_VALUE));
    menuItem.setActionCommand("play");
    menuItem.addActionListener(this);
    add(menuItem);

    add(Box.createHorizontalGlue());

    menu = new JMenu("Help");
    add(menu);

    menuItem = new JMenuItem("Help");
    menuItem.setActionCommand("help");
    menuItem.addActionListener(this);
    menu.add(menuItem);

    menuItem = new JMenuItem("About");
    menuItem.setActionCommand("about");
    menuItem.addActionListener(this);
    menu.add(menuItem);
}

From source file:de.ailis.xadrian.frames.MainFrame.java

/**
 * Creates the menu.//  ww w. j  a va 2 s  .c om
 */
private void createMenuBar() {
    // Create the menu bar
    final JMenuBar menuBar = new JMenuBar();
    setJMenuBar(menuBar);

    // Create the 'File' menu
    final JMenu fileMenu = I18N.createMenu(menuBar, "file");
    fileMenu.add(this.newAction);
    fileMenu.add(this.openAction);
    fileMenu.addSeparator();
    fileMenu.add(this.closeAction);
    fileMenu.add(this.closeAllAction);
    fileMenu.addSeparator();
    fileMenu.add(this.saveAction);
    fileMenu.add(this.saveAsAction);
    fileMenu.add(this.saveAllAction);
    fileMenu.addSeparator();
    fileMenu.add(this.printAction);
    fileMenu.addSeparator();
    final JMenu exportMenu = I18N.createMenu(fileMenu, "export");
    exportMenu.add(this.exportASCIIAction);
    exportMenu.add(this.exportTemplateCodeAction);
    final JMenu importMenu = I18N.createMenu(fileMenu, "import");
    importMenu.add(this.importTemplateCodeAction);
    fileMenu.addSeparator();
    fileMenu.add(this.exitAction);

    // Create the 'Edit' menu
    final JMenu editMenu = I18N.createMenu(menuBar, "edit");
    editMenu.add(new CopyAction(this));
    editMenu.add(this.selectAllAction);
    editMenu.addSeparator();
    editMenu.add(this.preferencesAction);

    // Create the 'Complex' menu
    final JMenu complexMenu = I18N.createMenu(menuBar, "complex");
    complexMenu.add(this.addFactoryAction);
    complexMenu.add(this.changeSectorAction);
    complexMenu.add(this.changeSunsAction);
    complexMenu.add(this.changePricesAction);
    complexMenu.add(new JCheckBoxMenuItem(this.toggleBaseComplexAction));

    // Create the 'Help' menu
    final JMenu helpMenu = I18N.createMenu(menuBar, "help");
    helpMenu.add(this.donateAction);
    helpMenu.addSeparator();
    helpMenu.add(this.homepageAction);
    helpMenu.add(this.forumAction);
    helpMenu.add(this.twitterAction);
    helpMenu.add(this.googlePlusAction);
    helpMenu.add(this.githubAction);
    helpMenu.addSeparator();
    helpMenu.add(this.aboutAction);

    installStatusHandler(menuBar);
}

From source file:blue.automation.AutomationManager.java

private JMenu buildChannelMenu(Channel channel, SoundLayer soundLayer) {

    JMenu retVal = new JMenu();

    retVal.setText(channel.getName());//  ww  w .j a  va 2  s .co m

    ParameterIdList paramIdList = soundLayer.getAutomationParameters();

    // pre effects
    EffectsChain preEffects = channel.getPreEffects();

    if (preEffects.size() > 0) {
        JMenu preMenu = new JMenu("Pre-Effects");
        retVal.add(preMenu);

        for (int i = 0; i < preEffects.size(); i++) {
            Automatable automatable = (Automatable) preEffects.getElementAt(i);

            ParameterList params = automatable.getParameterList();

            if (params.size() > 0) {
                JMenu effectMenu = new JMenu();

                if (automatable instanceof Effect) {
                    effectMenu.setText(((Effect) automatable).getName());
                } else if (automatable instanceof Send) {
                    effectMenu.setText("Send: " + ((Send) automatable).getSendChannel());
                } else {
                    effectMenu.setText("ERROR");
                }

                preMenu.add(effectMenu);

                for (int j = 0; j < params.size(); j++) {
                    Parameter param = params.getParameter(j);
                    JMenuItem paramItem = new JMenuItem();
                    paramItem.setText(param.getName());
                    paramItem.addActionListener(parameterActionListener);

                    if (param.isAutomationEnabled()) {
                        if (paramIdList.contains(param.getUniqueId())) {
                            paramItem.setForeground(Color.GREEN);
                        } else {
                            paramItem.setForeground(Color.ORANGE);
                        }

                    }

                    paramItem.putClientProperty("param", param);

                    effectMenu.add(paramItem);
                }
            }
        }
    }

    // volume
    JMenuItem volItem = new JMenuItem("Volume");
    Parameter volParam = channel.getLevelParameter();
    volItem.putClientProperty("param", volParam);
    volItem.addActionListener(parameterActionListener);

    if (volParam.isAutomationEnabled()) {
        if (paramIdList.contains(volParam.getUniqueId())) {
            volItem.setForeground(Color.GREEN);
        } else {
            volItem.setForeground(Color.ORANGE);
        }

    }

    retVal.add(volItem);

    // post effects
    EffectsChain postEffects = channel.getPostEffects();

    if (postEffects.size() > 0) {
        JMenu postMenu = new JMenu("Post-Effects");
        retVal.add(postMenu);

        for (int i = 0; i < postEffects.size(); i++) {
            Automatable automatable = (Automatable) postEffects.getElementAt(i);

            ParameterList params = automatable.getParameterList();

            if (params.size() > 0) {
                JMenu effectMenu = new JMenu();

                if (automatable instanceof Effect) {
                    effectMenu.setText(((Effect) automatable).getName());
                } else if (automatable instanceof Send) {
                    effectMenu.setText("Send: " + ((Send) automatable).getSendChannel());
                } else {
                    effectMenu.setText("ERROR");
                }

                postMenu.add(effectMenu);

                for (int j = 0; j < params.size(); j++) {
                    Parameter param = params.getParameter(j);
                    JMenuItem paramItem = new JMenuItem();
                    paramItem.setText(param.getName());
                    paramItem.addActionListener(parameterActionListener);

                    if (param.isAutomationEnabled()) {
                        if (paramIdList.contains(param.getUniqueId())) {
                            paramItem.setForeground(Color.GREEN);
                        } else {
                            paramItem.setForeground(Color.ORANGE);
                        }

                    }

                    paramItem.putClientProperty("param", param);

                    effectMenu.add(paramItem);
                }
            }
        }
    }

    return retVal;
}

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

private JMenu createMenuHelp() {
    final JMenu menuHelp = new JMenu(Messages.getString("Menu.help")); //$NON-NLS-1$

    final JMenuItem menuHelpAbout = new JMenuItem(Messages.getString("Menu.about")); //$NON-NLS-1$
    menuHelpAbout.setMnemonic(KeyEvent.VK_A);
    menuHelpAbout.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, InputEvent.ALT_MASK));
    menuHelpAbout.addActionListener(new ActionListener() {
        @Override/*from   w  w  w. j  av a 2 s  .com*/
        public void actionPerformed(final ActionEvent e) {
            showAboutDialog();
        }
    });
    menuHelp.add(menuHelpAbout);

    return menuHelp;
}

From source file:ch.fork.AdHocRailway.ui.AdHocRailway.java

private void initMenu() {
    menuBar = new JMenuBar();
    /* FILE *///from  w ww.ja v  a 2s .com
    final JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);

    final JMenuItem newItem = new JMenuItem(new NewFileAction());
    newItem.setMnemonic(KeyEvent.VK_N);
    newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, ActionEvent.CTRL_MASK));

    final JMenuItem openItem = new JMenuItem(new OpenFileAction());
    openItem.setMnemonic(KeyEvent.VK_O);
    openItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));

    final JMenuItem openDatabaseItem = new JMenuItem(new OpenDatabaseAction());

    saveItem = new JMenuItem(new SaveAction());
    saveItem.setMnemonic(KeyEvent.VK_S);
    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK));

    saveAsItem = new JMenuItem(new SaveAsAction());
    saveAsItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_S, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));

    final JMenuItem importAllItem = new JMenuItem(new ImportAllAction());
    final JMenuItem importLocomotivesItem = new JMenuItem(new ImportLocomotivesAction());
    final JMenuItem exportLocomotivesItem = new JMenuItem(new ExportLocomotivesAction());
    final JMenuItem exportAllItem = new JMenuItem(new ExportAllAction());

    final JMenu importMenu = new JMenu("Import");
    importMenu.add(importAllItem);
    importMenu.add(importLocomotivesItem);
    final JMenu exportMenu = new JMenu("Export");
    exportMenu.add(exportLocomotivesItem);
    exportMenu.add(exportAllItem);

    final JMenuItem clearLocomotivesItem = new JMenuItem(new ClearLocomotivesAction());
    final JMenuItem clearTurnoutsRoutesItem = new JMenuItem(new ClearTurnoutsAndRoutesAction());

    final JMenu clearMenu = new JMenu("Clear");
    clearMenu.add(clearLocomotivesItem);
    clearMenu.add(clearTurnoutsRoutesItem);

    final JMenuItem exitItem = new JMenuItem(new ExitAction());
    exitItem.setMnemonic(KeyEvent.VK_X);
    exitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, ActionEvent.CTRL_MASK));

    fileMenu.add(newItem);
    fileMenu.add(openItem);
    fileMenu.add(openDatabaseItem);
    fileMenu.add(saveItem);
    fileMenu.add(saveAsItem);
    fileMenu.add(new JSeparator());
    fileMenu.add(importMenu);
    fileMenu.add(exportMenu);
    fileMenu.add(clearMenu);
    fileMenu.add(new JSeparator());
    fileMenu.add(exitItem);

    /* EDIT */
    final JMenu editMenu = new JMenu("Edit");
    enableEditing = new JCheckBoxMenuItem(new EnableEditingAction());

    switchesItem = new JMenuItem(new TurnoutAction());
    routesItem = new JMenuItem(new RoutesAction());
    locomotivesItem = new JMenuItem(new LocomotivesAction());
    preferencesItem = new JMenuItem(new PreferencesAction());
    enableEditing.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, ActionEvent.ALT_MASK));

    switchesItem.setMnemonic(KeyEvent.VK_T);
    switchesItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_T, ActionEvent.ALT_MASK));
    routesItem.setMnemonic(KeyEvent.VK_R);
    routesItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, ActionEvent.ALT_MASK));
    locomotivesItem.setMnemonic(KeyEvent.VK_L);
    locomotivesItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_L, ActionEvent.ALT_MASK));
    preferencesItem.setMnemonic(KeyEvent.VK_P);
    preferencesItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, ActionEvent.ALT_MASK));
    editMenu.add(enableEditing);
    editMenu.add(new JSeparator());
    editMenu.add(switchesItem);
    editMenu.add(routesItem);
    editMenu.add(locomotivesItem);
    editMenu.add(new JSeparator());
    editMenu.add(preferencesItem);

    /* DAEMON */
    final JMenu daemonMenu = new JMenu("Device");
    daemonConnectItem = new JMenuItem(new ConnectAction());
    daemonConnectItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, ActionEvent.CTRL_MASK));
    daemonDisconnectItem = new JMenuItem(new DisconnectAction());
    daemonPowerOnItem = new JMenuItem(new PowerOnAction());
    assignAccelerator(daemonPowerOnItem, "PowerOn");
    daemonPowerOnItem.setEnabled(true);
    daemonPowerOffItem = new JMenuItem(new PowerOffAction());
    assignAccelerator(daemonPowerOffItem, "PowerOff");
    daemonPowerOffItem.setEnabled(true);
    daemonDisconnectItem.setEnabled(false);
    daemonMenu.add(daemonConnectItem);
    daemonMenu.add(daemonDisconnectItem);
    daemonMenu.add(new JSeparator());
    daemonMenu.add(daemonPowerOnItem);
    daemonMenu.add(daemonPowerOffItem);

    /* VIEW */
    final JMenu viewMenu = new JMenu("View");
    final JMenuItem refreshItem = new JMenuItem(new RefreshAction());
    final JMenuItem fullscreenItem = new JMenuItem(new ToggleFullscreenAction());

    viewMenu.add(refreshItem);
    viewMenu.add(fullscreenItem);

    /* HELP */
    // JMenu helpMenu = new JMenu("Help");
    addMenu(fileMenu);
    addMenu(editMenu);
    addMenu(daemonMenu);
    addMenu(viewMenu);
    // addMenu(helpMenu);
    setJMenuBar(menuBar);
}

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

@Override
protected JMenu createWindowMenu() {
    final JMenu menuWindow = new JMenu(Messages.getString("Menu.windows")); //$NON-NLS-1$

    final JMenuItem menuWindowElements = new JMenuItem(Messages.getString("Menu.elements")); //$NON-NLS-1$
    menuWindowElements.setMnemonic(KeyEvent.VK_E);
    menuWindowElements.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, InputEvent.ALT_MASK));
    menuWindowElements.addActionListener(new ActionListener() {
        @Override//w w w.j  ava2  s .c  o m
        public void actionPerformed(final ActionEvent e) {
            showElementsFrame();
        }
    });
    menuWindow.add(menuWindowElements);

    final JMenuItem menuWindowInstances = new JMenuItem(Messages.getString("Menu.instances")); //$NON-NLS-1$
    menuWindowInstances.setMnemonic(KeyEvent.VK_I);
    menuWindowInstances.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, InputEvent.ALT_MASK));
    menuWindowInstances.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(final ActionEvent e) {
            showInstancesFrame();
        }
    });
    menuWindow.add(menuWindowInstances);

    final JMenu menuWindowDiagram = super.createWindowMenu();
    menuWindowDiagram.setText(Messages.getString("Menu.diagrams"));
    menuWindow.add(menuWindowDiagram);

    return menuWindow;
}

From source file:org.jdal.swing.PageableTable.java

/**
 * Create the right menu bar/*w  w  w .  ja va  2 s .c  o m*/
 */
private void createMenu() {
    rightMenuBar = new JMenuBar();
    rightMenuBar.setLayout(new BoxLayout(rightMenuBar, BoxLayout.PAGE_AXIS));
    rightMenuBar.setMargin(new Insets(0, 0, 0, 0));
    // Add Visibility menu
    JMenu menu = new JMenu();
    menu.setMargin(new Insets(0, 0, 0, 0));
    menu.setIcon(visibilityMenuIcon);
    menu.setMaximumSize(new Dimension(50, 50));
    visibilityBox = new VisibilityBox(columnDescriptors);
    menu.add(visibilityBox);
    menu.getPopupMenu().addPopupMenuListener(new VisibilityPopupListener());
    JMenuItem okMenuItem = new JMenuItem(new OkVisibilityAction());
    JMenuItem cancelMenuItem = new JMenuItem(new CancelVisibilityAction());
    menu.addSeparator();
    menu.add(okMenuItem);
    menu.add(cancelMenuItem);
    rightMenuBar.add(menu);
    JMenu prefsMenu = new JMenu();
    prefsMenu.setMargin(new Insets(0, 0, 0, 0));
    prefsMenu.setIcon(userMenuIcon);
    prefsMenu.setMaximumSize(new Dimension(50, 50));
    prefsMenu.add(new JMenuItem(new LoadPreferencesAction(this, messageSource
            .getMessage("PageableTable.loadPreferences", null, "Load Preferences", Locale.getDefault()))));
    prefsMenu.add(new JMenuItem(new SavePreferencesAction(this, messageSource
            .getMessage("PageableTable.savePreferences", null, "Save Preferences", Locale.getDefault()))));
    rightMenuBar.add(prefsMenu);
    rightMenuBar.add(Box.createVerticalGlue());
    // Add menu bar to right
    add(rightMenuBar, BorderLayout.EAST);
}

From source file:com.jidesoft.spring.richclient.docking.JideApplicationLifecycleAdvisor.java

@Override
public void onPostStartup() {
    initializeRepaintManager();//from   ww w .  java 2 s .co  m
    if (devOption == false) {
        JMenuBar menuBar = Application.instance().getActiveWindow().getControl().getJMenuBar();
        for (int i = 0; i < menuBar.getMenuCount(); i++) {
            //TODO:I18N
            if (menuBar.getMenu(i).getText().equals("Admin")) {
                menuBar.getMenu(i).setVisible(false);
            }
        }
    }
    JMenuBar menuBar = Application.instance().getActiveWindow().getControl().getJMenuBar();
    for (int i = 0; i < menuBar.getMenuCount(); i++) {
        // recent games
        //TODO: I18N
        if (menuBar.getMenu(i).getText().equals("Game")) {
            for (int j = 0; j < menuBar.getMenu(i).getItemCount(); j++) {
                if (menuBar.getMenu(i).getItem(j) != null && menuBar.getMenu(i).getItem(j).getText() != null
                        && menuBar.getMenu(i).getItem(j).getText().equals("Recent Games")) {
                    JMenu menu = (JMenu) menuBar.getMenu(i).getItem(j);
                    RecentGames rg = new RecentGames();
                    ArrayList<RecentGames.RecentGameInfo> rgis = rg.getRecentGameInfo();
                    for (RecentGameInfo rgi : rgis) {
                        final RecentGameInfo frgi = rgi;
                        JMenuItem mu = new JMenuItem();
                        mu.setText("Game " + String.valueOf(rgi.getNumber()));
                        mu.addActionListener(new ActionListener() {
                            @Override
                            public void actionPerformed(ActionEvent e) {
                                LoadGame loadGame = new LoadGame(frgi.getFile());
                                loadGame.execute();
                            }
                        });
                        menu.add(mu);
                    }
                }
            }
        }

        // user guide
        //TODO:I18N
        if (menuBar.getMenu(i).getText().equals("Help")) {
            try {
                final File f = new File("JOverseerUserGuide.pdf");
                if (f.exists()) {
                    //TODO:I18N
                    JMenuItem mi = new JMenuItem("User's Guide");
                    mi.addActionListener(new ActionListener() {
                        @Override
                        public void actionPerformed(ActionEvent e) {
                            try {
                                Runtime.getRuntime()
                                        .exec("rundll32 url.dll,FileProtocolHandler " + f.getAbsolutePath());
                            } catch (Exception exc) {
                                // do nothing
                            }
                        }
                    });
                    menuBar.getMenu(i).add(new JSeparator());
                    menuBar.getMenu(i).add(mi);
                }
            } catch (Exception exc) {
                // do nothing
            }
        }

    }

    if (JOverseerJIDEClient.cmdLineArgs != null && JOverseerJIDEClient.cmdLineArgs.length == 1
            && JOverseerJIDEClient.cmdLineArgs[0].endsWith(".jov")) {
        String fname = JOverseerJIDEClient.cmdLineArgs[0];
        File f = new File(fname);
        if (f.exists()) {
            LoadGame lg = new LoadGame(fname);
            lg.loadGame();
        }
    }
}

From source file:jhplot.HPlotChart.java

/**
 * Create canvas that keeps JFreeChart panel. 
 * /*  www.  jav a 2 s  . c  o m*/
 * @param jchart 
 *           chart of JFreeChart. 
 * @param xsize
 *            size in x direction
 * @param ysize
 *            size in y direction
 */

public HPlotChart(JFreeChart jchart, int xsize, int ysize) {

    this.xsize = xsize;
    this.ysize = ysize;
    frame = new JFrame("HPloatChart");

    chart = jchart;
    cp = new ChartPanel(chart);
    cp.setPreferredSize(new Dimension(xsize, ysize));
    cp.setBackground(DEFAULT_BG_COLOR);
    cp.setLayout(new BorderLayout());
    cp.setDomainZoomable(true);
    cp.setRangeZoomable(true);

    chart.setAntiAlias(true);
    chart.setBorderPaint(DEFAULT_BG_COLOR);
    chart.setBackgroundPaint(DEFAULT_BG_COLOR);
    chart.setBorderVisible(false);

    org.jfree.chart.plot.Plot pp = (org.jfree.chart.plot.Plot) chart.getPlot();
    pp.setBackgroundPaint(DEFAULT_BG_COLOR);

    setTheme("LEGACY_THEME");
    frame.add(cp);

    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("File");
    JMenuItem item1 = new JMenuItem("Export");
    item1.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            exportDialog();
        }
    });

    JMenuItem item2 = new JMenuItem("Close");
    item2.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            close();
        }
    });

    frame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
    menu.add(item1);
    menu.add(item2);

    bar.add(menu);
    frame.setJMenuBar(bar);
    frame.setPreferredSize(new Dimension(xsize, ysize));

}

From source file:br.ufrgs.enq.jcosmo.ui.COSMOSACDialog.java

public COSMOSACDialog() {
    super("JCOSMO Simple");
    setDefaultCloseOperation(EXIT_ON_CLOSE);
    setLayout(new BorderLayout());

    db = COSMOSACDataBase.getInstance();

    COSMOSAC models[] = new COSMOSAC[5];
    models[0] = new COSMOSAC();
    models[1] = new COSMOPAC();
    models[2] = new COSMOSAC_SVP();
    models[3] = new COSMOSAC_G();
    models[4] = new PCMSAC();
    modelBox = new JComboBox(models);
    modelBox.addActionListener(this);

    JPanel north = new JPanel(new GridLayout(0, 2));
    add(north, BorderLayout.NORTH);
    JPanel northAba1 = new JPanel(new GridLayout(0, 4));
    JPanel northAba2 = new JPanel(new GridLayout(0, 2));

    //Where the GUI is created:
    JMenuBar menuBar;/*from ww w  . jav a 2  s.  c om*/
    JMenu file, help;
    JMenuItem menuItem;

    //Create the menu bar.
    menuBar = new JMenuBar();

    // the file menu
    file = new JMenu("File");
    file.setMnemonic(KeyEvent.VK_F);
    menuBar.add(file);
    menuItem = new JMenuItem("Quit", KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, ActionEvent.ALT_MASK));
    menuItem.setActionCommand(QUIT);
    menuItem.addActionListener(this);
    file.add(menuItem);

    // the help menu
    help = new JMenu("Help");
    file.setMnemonic(KeyEvent.VK_H);
    menuBar.add(help);
    menuItem = new JMenuItem("About", KeyEvent.VK_A);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));
    menuItem.setActionCommand(ABOUT);
    menuItem.addActionListener(this);
    help.add(menuItem);

    setJMenuBar(menuBar);

    listModel = new DefaultListModel();
    list = new JList(listModel);
    list.setBorder(BorderFactory.createTitledBorder("compounds"));
    list.setVisibleRowCount(2);
    list.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    JScrollPane listScrollPane = new JScrollPane(list);

    JButton addButton = new JButton("Add");
    addButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            new AddCompoundDialog(COSMOSACDialog.this);
        }
    });

    removeButton = new JButton("Remove");
    removeButton.addActionListener(this);
    visibRemove(false);

    JButton calcButton = new JButton("Calculate");
    calcButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            rebuildChart();
            rebuildSigmaProfiles();
        }
    });

    JButton refreshButton = new JButton("Refresh");
    refreshButton.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            rebuildSigmaProfiles();
        }
    });

    ignoreSGButton = new JCheckBox("Ignore SG");
    ignoreSGButton.setToolTipText("Toogles the ignore flag for the Staverman-Guggenheim term");
    ignoreSGButton.addActionListener(this);

    JPanel but = new JPanel(new GridLayout(0, 1));
    but.add(addButton, BorderLayout.EAST);
    but.add(removeButton, BorderLayout.EAST);
    but.add(modelBox);
    north.add(listScrollPane);
    north.add(but);

    northAba1.add(new JLabel("Temperature [K]"));
    northAba1.add(temperature = new JTextField(10));
    temperature.setText("298");

    northAba1.add(new JLabel("Sigma HB"));
    northAba1.add(sigmaHB = new JTextField(10));
    northAba1.add(new JLabel("Sigma HB2"));
    northAba1.add(sigmaHB2 = new JTextField(10));
    northAba1.add(new JLabel("Sigma HB3"));
    northAba1.add(sigmaHB3 = new JTextField(10));

    northAba1.add(new JLabel("Charge HB"));
    northAba1.add(chargeHB = new JTextField(10));

    northAba1.add(new JLabel("Sigma Disp"));
    northAba1.add(sigmaDisp = new JTextField(10));
    northAba1.add(new JLabel("Charge Disp"));
    northAba1.add(chargeDisp = new JTextField(10));

    northAba1.add(new JLabel("Beta"));
    northAba1.add(beta = new JTextField(10));
    northAba1.add(new JLabel("fpol"));
    northAba1.add(fpol = new JTextField(10));
    northAba1.add(new JLabel("Anorm"));
    northAba1.add(anorm = new JTextField(10));

    northAba1.add(ignoreSGButton);
    northAba1.add(calcButton);
    northAba2.add(new JLabel(""));
    northAba2.add(refreshButton);

    //      chart = new JLineChart();
    //      add(chart, BorderLayout.CENTER);
    //      chart.setTitle("Gamma Plot");
    //      chart.setSubtitle("");
    //      chart.setXAxisLabel("Mole Fraction, x_1");
    //      chart.setYAxisLabel("ln gamma, gE/RT");
    //      chart.setSource(getTitle());
    //      chart.setLegendPosition(LegendPosition.BOTTOM);
    //      chart.setShapesVisible(true);

    JFreeChart chart = ChartFactory.createXYLineChart(null, "Mole Fraction, x_1", "ln gamma, gE/RT", null,
            PlotOrientation.VERTICAL, true, true, false);
    plot = (XYPlot) chart.getPlot();
    plot.getDomainAxis().setAutoRange(false);
    plot.getDomainAxis().setRange(new Range(0.0, 1.0));

    plot.setBackgroundPaint(Color.lightGray);
    plot.setDomainGridlinePaint(Color.white);
    plot.setRangeGridlinePaint(Color.white);

    XYLineAndShapeRenderer r = (XYLineAndShapeRenderer) plot.getRenderer();
    r.setUseFillPaint(true);
    r.setBaseFillPaint(Color.white);
    r.setBaseShapesVisible(true);

    JFreeChart sigmaProfileChart = ChartFactory.createXYLineChart(null, "sigma", "P^x", null,
            PlotOrientation.VERTICAL, true, true, false);
    sigmaProfilePlot = sigmaProfileChart.getXYPlot();
    sigmaProfilePlot.getDomainAxis().setAutoRange(false);
    sigmaProfilePlot.getDomainAxis().setRange(new Range(-0.025, 0.025));

    //      sigmaProfilePlot.setBackgroundPaint(Color.lightGray);
    //      sigmaProfilePlot.setDomainGridlinePaint(Color.white);
    //      sigmaProfilePlot.setRangeGridlinePaint(Color.white);

    JFreeChart chartSegGamma = ChartFactory.createXYLineChart(null, "sigma", "Segment Gamma", null,
            PlotOrientation.VERTICAL, true, true, false);
    plotSegGamma = (XYPlot) chartSegGamma.getPlot();

    JPanel south = new JPanel();
    south.setLayout(new FlowLayout());
    south.add(new JLabel("<html>ln &gamma;<sup>&infin;</sup><sub>1</sub>:</html>"));
    south.add(lnGammaInf1Label = new JLabel());
    south.add(new JLabel("<html>ln &gamma;<sup>&infin;</sup><sub>2</sub>:</html>"));
    south.add(lnGammaInf2Label = new JLabel());
    south.add(Box.createHorizontalStrut(20));
    south.add(new JLabel("<html>&gamma;<sup>&infin;</sup><sub>1</sub>:</html>"));
    south.add(gammaInf1Label = new JLabel());
    south.add(new JLabel("<html>&gamma;<sup>&infin;</sup><sub>2</sub>:</html>"));
    south.add(gammaInf2Label = new JLabel());

    JPanel aba1 = new JPanel(new BorderLayout());
    aba1.add(northAba1, BorderLayout.NORTH);
    JPanel chartsPanel = new JPanel(new GridLayout(0, 2));
    aba1.add(chartsPanel, BorderLayout.CENTER);
    chartsPanel.add(new ChartPanel(chart));
    chartsPanel.add(new ChartPanel(chartSegGamma));
    aba1.add(south, BorderLayout.SOUTH);

    JPanel aba2 = new JPanel(new BorderLayout());
    aba2.add(northAba2, BorderLayout.NORTH);
    aba2.add(chartPanel = new ChartPanel(sigmaProfileChart), BorderLayout.CENTER);

    JTabbedPane tabbedPane = new JTabbedPane();
    tabbedPane.addTab("gamma", aba1);
    tabbedPane.addTab("sigma", aba2);
    add(tabbedPane, BorderLayout.CENTER);

    //      cosmosac.setAEffPrime(6.596176570595075);
    //      cosmosac.setCoord(11.614599507917934);
    //      cosmosac.setVnorm(56.36966406129967);
    //      cosmosac.setAnorm(41.56058649432742);
    //      cosmosac.setCHB(65330.19484947528);
    //      cosmosac.setSigmaHB(0.008292411048046008);

    //Display the window.
    setSize(800, 600);
    setLocationRelativeTo(null);
    modelBox.setSelectedIndex(0);
    setVisible(true);

    // test for a mixture
    //      addList("WATER");
    //      addList("H3O+1");
    //      addList("OH-1");
    //      addList("CL-1");
    //      addList("OXYGEN");
    //      addList("sec-butylamine");
    //      addList("hydrogen-fluoride");
    //      addList("ACETONE");
    //      addList("METHANOL");
    //      addList("ACETONE.opt");
    //      addList("METHANOL.opt");
    //      addList("METHYL-ETHYL-KETONE");
    //      addList("ETHANOL");
    //      addList("N-HEPTANE");
    //      addList("PROPIONIC-ACID");
    //      addList("EMIM");
    //      addList("NTF2");
    //      addList("DCA");
    //      addList("N-OCTANE");
    addList("ETHYLENE CARBONATE");
    addList("BENZENE");
    addList("TOLUENE");
    removeButton.setEnabled(true);
}