Example usage for javax.swing JMenu JMenu

List of usage examples for javax.swing JMenu JMenu

Introduction

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

Prototype

public JMenu(Action a) 

Source Link

Document

Constructs a menu whose properties are taken from the Action supplied.

Usage

From source file:ca.phon.app.project.ProjectWindow.java

@Override
public void setJMenuBar(JMenuBar menu) {
    super.setJMenuBar(menu);

    JMenu projectMenu = new JMenu("Project");

    int projectMenuIndex = -1;
    // get the edit menu and add view commands
    for (int i = 0; i < menu.getMenuCount(); i++) {
        JMenu currentBar = menu.getMenu(i);

        if (currentBar != null && currentBar.getText() != null && currentBar.getText().equals("Workspace")) {
            projectMenuIndex = i + 1;//w  ww.j  a v a 2s .  c  o  m
        }
    }

    if (projectMenuIndex > 0) {
        menu.add(projectMenu, projectMenuIndex);
    }

    // refresh lists 
    final RefreshAction refreshItem = new RefreshAction(this);
    projectMenu.add(refreshItem);
    projectMenu.addSeparator();

    // create corpus item
    final NewCorpusAction newCorpusItem = new NewCorpusAction(this);
    projectMenu.add(newCorpusItem);

    //       create corpus item
    final NewSessionAction newSessionItem = new NewSessionAction(this);
    projectMenu.add(newSessionItem);

    projectMenu.addSeparator();

    final AnonymizeAction anonymizeParticipantInfoItem = new AnonymizeAction(this);
    projectMenu.add(anonymizeParticipantInfoItem);

    final CheckTranscriptionsAction repairItem = new CheckTranscriptionsAction(this);
    projectMenu.add(repairItem);

    // merge/split sessions
    final DeriveSessionAction deriveItem = new DeriveSessionAction(this);
    projectMenu.add(deriveItem);

    final JMenu teamMenu = new JMenu("Team");
    teamMenu.addMenuListener(new MenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            teamMenu.removeAll();
            if (getProject() != null) {
                final ProjectGitController gitController = new ProjectGitController(getProject());
                if (gitController.hasGitFolder()) {
                    teamMenu.add(new CommitAction(ProjectWindow.this));

                    teamMenu.addSeparator();

                    teamMenu.add(new PullAction(ProjectWindow.this));
                    teamMenu.add(new PushAction(ProjectWindow.this));

                } else {
                    final InitAction initRepoAct = new InitAction(ProjectWindow.this);
                    teamMenu.add(initRepoAct);
                }
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {

        }

        @Override
        public void menuCanceled(MenuEvent e) {

        }
    });
    projectMenu.addSeparator();
    projectMenu.add(teamMenu);
}

From source file:com.lfv.lanzius.server.LanziusServer.java

public void init() {

    log.info(Config.VERSION + "\n");

    docVersion = 0;//from  w w w.j av a  2 s.  c  o  m

    frame = new JFrame(Config.TITLE + " - Server Control Panel");

    frame.setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
    frame.addWindowListener(new WindowAdapter() {
        @Override
        public void windowClosing(WindowEvent e) {
            actionPerformed(new ActionEvent(itemExit, 0, null));
        }
    });

    // Create graphical terminal view
    panel = new WorkspacePanel(this);
    frame.getContentPane().add(panel);

    // Create a menu bar
    JMenuBar menuBar = new JMenuBar();

    // FILE
    JMenu fileMenu = new JMenu("File");
    fileMenu.setMnemonic(KeyEvent.VK_F);
    // Load configuration
    itemLoadConfig = new JMenuItem("Load configuration...");
    itemLoadConfig.addActionListener(this);
    fileMenu.add(itemLoadConfig);
    // Load terminal setup
    itemLoadExercise = new JMenuItem("Load exercise...");
    itemLoadExercise.addActionListener(this);
    fileMenu.add(itemLoadExercise);
    fileMenu.addSeparator();
    // Exit
    itemExit = new JMenuItem("Exit");
    itemExit.addActionListener(this);
    fileMenu.add(itemExit);
    menuBar.add(fileMenu);

    // SERVER
    JMenu serverMenu = new JMenu("Server");
    serverMenu.setMnemonic(KeyEvent.VK_S);
    // Start
    itemServerStart = new JMenuItem("Start");
    itemServerStart.addActionListener(this);
    serverMenu.add(itemServerStart);
    // Stop
    itemServerStop = new JMenuItem("Stop");
    itemServerStop.addActionListener(this);
    serverMenu.add(itemServerStop);
    // Restart
    itemServerRestart = new JMenuItem("Restart");
    itemServerRestart.addActionListener(this);
    itemServerRestart.setEnabled(false);
    serverMenu.add(itemServerRestart);
    // Monitor network connection
    itemServerMonitor = new JCheckBoxMenuItem("Monitor network");
    itemServerMonitor.addActionListener(this);
    itemServerMonitor.setState(false);
    serverMenu.add(itemServerMonitor);
    menuBar.add(serverMenu);

    // TERMINAL
    JMenu terminalMenu = new JMenu("Terminal");
    terminalMenu.setMnemonic(KeyEvent.VK_T);
    itemTerminalLink = new JMenuItem("Link...");
    itemTerminalLink.addActionListener(this);
    terminalMenu.add(itemTerminalLink);
    itemTerminalUnlink = new JMenuItem("Unlink...");
    itemTerminalUnlink.addActionListener(this);
    terminalMenu.add(itemTerminalUnlink);
    itemTerminalUnlinkAll = new JMenuItem("Unlink All");
    itemTerminalUnlinkAll.addActionListener(this);
    terminalMenu.add(itemTerminalUnlinkAll);
    itemTerminalSwap = new JMenuItem("Swap...");
    itemTerminalSwap.addActionListener(this);
    terminalMenu.add(itemTerminalSwap);
    menuBar.add(terminalMenu);

    // GROUP
    JMenu groupMenu = new JMenu("Group");
    groupMenu.setMnemonic(KeyEvent.VK_G);
    itemGroupStart = new JMenuItem("Start...");
    itemGroupStart.addActionListener(this);
    groupMenu.add(itemGroupStart);
    itemGroupPause = new JMenuItem("Pause...");
    itemGroupPause.addActionListener(this);
    groupMenu.add(itemGroupPause);
    itemGroupStop = new JMenuItem("Stop...");
    itemGroupStop.addActionListener(this);
    groupMenu.add(itemGroupStop);
    menuBar.add(groupMenu);

    frame.setJMenuBar(menuBar);

    GraphicsEnvironment graphicsEnvironment = GraphicsEnvironment.getLocalGraphicsEnvironment();
    Rectangle maximumWindowBounds = graphicsEnvironment.getMaximumWindowBounds();

    if (Config.SERVER_SIZE_FULLSCREEN) {
        maximumWindowBounds.setLocation(0, 0);
        maximumWindowBounds.setSize(Toolkit.getDefaultToolkit().getScreenSize());
        frame.setResizable(false);
        frame.setUndecorated(true);
    } else if (Config.SERVER_SIZE_100P_WINDOW) {
        // Fixes a bug in linux using gnome. With the line below the upper and
        // lower bars are respected
        maximumWindowBounds.height -= 1;
    } else if (Config.SERVER_SIZE_75P_WINDOW) {
        maximumWindowBounds.width *= 0.75;
        maximumWindowBounds.height *= 0.75;
    } else if (Config.SERVER_SIZE_50P_WINDOW) {
        maximumWindowBounds.width /= 2;
        maximumWindowBounds.height /= 2;
    }

    frame.setBounds(maximumWindowBounds);
    frame.setVisible(true);

    log.info("Starting control panel");

    // Autostart for debugging
    if (Config.SERVER_AUTOLOAD_CONFIGURATION != null)
        actionPerformed(new ActionEvent(itemLoadConfig, 0, null));

    if (Config.SERVER_AUTOSTART_SERVER)
        actionPerformed(new ActionEvent(itemServerStart, 0, null));

    if (Config.SERVER_AUTOLOAD_EXERCISE != null)
        actionPerformed(new ActionEvent(itemLoadExercise, 0, null));

    if (Config.SERVER_AUTOSTART_GROUP > 0)
        actionPerformed(new ActionEvent(itemGroupStart, 0, null));

    try {
        // Read the property files
        serverProperties = new Properties();
        serverProperties.loadFromXML(new FileInputStream("data/properties/serverproperties.xml"));
        int rcPort = Integer.parseInt(serverProperties.getProperty("RemoteControlPort", "0"));
        if (rcPort > 0) {
            groupRemoteControlListener(rcPort);
        }
        isaPeriod = Integer.parseInt(serverProperties.getProperty("ISAPeriod", "60"));
        isaNumChoices = Integer.parseInt(serverProperties.getProperty("ISANumChoices", "6"));
        for (int i = 0; i < 9; i++) {
            String tag = "ISAKeyText" + Integer.toString(i);
            String def_val = Integer.toString(i + 1);
            isakeytext[i] = serverProperties.getProperty(tag, def_val);
        }
        isaExtendedMode = serverProperties.getProperty("ISAExtendedMode", "false").equalsIgnoreCase("true");
    } catch (Exception e) {
        log.error("Unable to start remote control listener");
        log.error(e.getMessage());
    }
    isaClients = new HashSet<Integer>();
}

From source file:edu.ku.brc.af.core.SchemaI18NService.java

/**
 * Create a Locale menu with all the language locales (no Country or variant).
 * @return/*from   w w w  .  j a  v  a2s  .  com*/
 */
public JMenu createLocaleMenu(final ActionListener al) {
    JMenu menu = new JMenu("Locale"); //$NON-NLS-1$
    JMenuItem m = new JMenuItem("Choose Locale"); //$NON-NLS-1$
    m.addActionListener(al);
    menu.add(m);
    return menu;
}

From source file:com.haskins.cloudtrailviewer.sidebar.EventsChart.java

private JMenu getSessionContextMenu(ButtonGroup buttonGroup) {

    JMenu sessionContext = new JMenu("Session Context");
    sessionContext.add(getSessionIssuerMenu(buttonGroup));

    return sessionContext;
}

From source file:eu.delving.sip.frames.AllFrames.java

public JMenu getViewMenu() {
    JMenu menu = new JMenu("View");
    for (Action action : arrangements)
        menu.add(action);//from ww  w . j  a  v a 2 s. c o  m
    return menu;
}

From source file:com.raceup.fsae.test.TesterGui.java

/**
 * Creates file menu with save/exit options
 *
 * @return file menu//  ww w . ja  v a2  s .c  o m
 */
private JMenu createFileMenu() {
    JMenu menu = new JMenu("File"); // file menu

    JMenuItem item = new JMenuItem("Exit");
    item.addActionListener(e -> System.exit(0));
    menu.add(item);

    return menu;
}

From source file:net.sf.firemox.DeckBuilder.java

/**
 * Creates new form DeckBuilder/* w  ww .  jav a2s  .c o  m*/
 */
private DeckBuilder() {
    super("DeckBuilder");
    form = this;
    timerPanel = new TimerGlassPane();
    cardLoader = new CardLoader(timerPanel);
    timer = new Timer(200, cardLoader);
    setGlassPane(timerPanel);
    try {
        setIconImage(Picture.loadImage(IdConst.IMAGES_DIR + "deckbuilder.gif"));
    } catch (Exception e) {
        // IGNORING
    }

    // Load settings
    loadSettings();

    // Initialize components
    final JMenuItem newItem = UIHelper.buildMenu("menu_db_new", 'n', this);
    newItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, InputEvent.CTRL_MASK));

    final JMenuItem loadItem = UIHelper.buildMenu("menu_db_load", 'o', this);
    loadItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, InputEvent.CTRL_MASK));

    final JMenuItem saveAsItem = UIHelper.buildMenu("menu_db_saveas", 'a', this);
    saveAsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F12, 0));

    final JMenuItem saveItem = UIHelper.buildMenu("menu_db_save", 's', this);
    saveItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, InputEvent.CTRL_MASK));

    final JMenuItem quitItem = UIHelper.buildMenu("menu_db_exit", this);
    quitItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F4, InputEvent.ALT_MASK));

    final JMenuItem deckConstraintsItem = UIHelper.buildMenu("menu_db_constraints", 'c', this);
    deckConstraintsItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F3, 0));

    final JMenuItem aboutItem = UIHelper.buildMenu("menu_help_about", 'a', this);
    aboutItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, InputEvent.SHIFT_MASK));

    final JMenuItem convertDCK = UIHelper.buildMenu("menu_convert_DCK_MP", this);

    final JMenu mainMenu = UIHelper.buildMenu("menu_file");
    mainMenu.add(newItem);
    mainMenu.add(loadItem);
    mainMenu.add(saveAsItem);
    mainMenu.add(saveItem);
    mainMenu.add(new JSeparator());
    mainMenu.add(quitItem);

    super.optionMenu = new JMenu("Options");

    final JMenu convertMenu = UIHelper.buildMenu("menu_convert");
    convertMenu.add(convertDCK);

    final JMenuItem helpItem = UIHelper.buildMenu("menu_help_help", 'h', this);
    helpItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F1, 0));

    final JMenu helpMenu = new JMenu("?");
    helpMenu.add(helpItem);
    helpMenu.add(deckConstraintsItem);
    helpMenu.add(aboutItem);

    final JMenuBar menuBar = new JMenuBar();
    menuBar.add(mainMenu);
    initAbstractMenu();
    menuBar.add(optionMenu);
    menuBar.add(convertMenu);
    menuBar.add(helpMenu);
    setJMenuBar(menuBar);
    addWindowListener(this);

    // Build the panel containing amount of available cards
    final JLabel amountLeft = new JLabel("<html>0/?", SwingConstants.RIGHT);

    // Build the left list
    allListModel = new MListModel<MCardCompare>(amountLeft, false);
    leftList = new ThreadSafeJList(allListModel);
    leftList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    leftList.setLayoutOrientation(JList.VERTICAL);
    leftList.getSelectionModel().addListSelectionListener(this);
    leftList.addMouseListener(this);
    leftList.setVisibleRowCount(10);

    // Initialize the text field containing the amount to add
    addQtyTxt = new JTextField("1");

    // Build the "Add" button
    addButton = new JButton(LanguageManager.getString("db_add"));
    addButton.setMnemonic('a');
    addButton.setEnabled(false);

    // Build the panel containing : "Add" amount and "Add" button
    final Box addPanel = Box.createHorizontalBox();
    addPanel.add(addButton);
    addPanel.add(addQtyTxt);
    addPanel.setMaximumSize(new Dimension(32010, 26));

    // Build the panel containing the selected card name
    cardNameTxt = new JTextField();
    new HireListener(cardNameTxt, addButton, this, leftList);

    final JLabel searchLabel = new JLabel(LanguageManager.getString("db_search") + " : ");
    searchLabel.setLabelFor(cardNameTxt);

    // Build the panel containing search label and card name text field
    final Box searchPanel = Box.createHorizontalBox();
    searchPanel.add(searchLabel);
    searchPanel.add(cardNameTxt);
    searchPanel.setMaximumSize(new Dimension(32010, 26));

    listScrollerLeft = new JScrollPane(leftList);
    MToolKit.addOverlay(listScrollerLeft);

    // Build the left panel containing : list, available amount, "Add" panel
    final JPanel srcPanel = new JPanel(null);
    srcPanel.add(searchPanel);
    srcPanel.add(listScrollerLeft);
    srcPanel.add(amountLeft);
    srcPanel.add(addPanel);
    srcPanel.setMinimumSize(new Dimension(220, 200));
    srcPanel.setLayout(new BoxLayout(srcPanel, BoxLayout.Y_AXIS));

    // Initialize constraints
    constraintsChecker = new ConstraintsChecker();
    constraintsChecker.setBorder(new EtchedBorder());
    final JScrollPane constraintsCheckerScroll = new JScrollPane(constraintsChecker);
    MToolKit.addOverlay(constraintsCheckerScroll);

    // create a pane with the oracle text for the present card
    oracleText = new JLabel();
    oracleText.setPreferredSize(new Dimension(180, 200));
    oracleText.setVerticalAlignment(SwingConstants.TOP);

    final JScrollPane oracle = new JScrollPane(oracleText, ScrollPaneConstants.VERTICAL_SCROLLBAR_AS_NEEDED,
            ScrollPaneConstants.HORIZONTAL_SCROLLBAR_NEVER);
    MToolKit.addOverlay(oracle);

    // build some Pie Charts and a panel to display it
    initSets();
    datasets = new ChartSets();
    final JTabbedPane tabbedPane = new JTabbedPane();
    for (ChartFilter filter : ChartFilter.values()) {
        final Dataset dataSet = filter.createDataSet(this);
        final JFreeChart chart = new JFreeChart(null, null,
                filter.createPlot(dataSet, painterMapper.get(filter)), false);
        datasets.addDataSet(filter, dataSet);
        ChartPanel pieChartPanel = new ChartPanel(chart, true);
        tabbedPane.add(pieChartPanel, filter.getTitle());
    }
    // add the Constraints scroll panel and Oracle text Pane to the tabbedPane
    tabbedPane.add(constraintsCheckerScroll, LanguageManager.getString("db_constraints"));
    tabbedPane.add(oracle, LanguageManager.getString("db_text"));
    tabbedPane.setSelectedComponent(oracle);

    // The toollBar for color filtering
    toolBar = new JToolBar();
    toolBar.setFloatable(false);
    final JButton clearButton = UIHelper.buildButton("clear");
    clearButton.addActionListener(this);
    toolBar.add(clearButton);
    final JToggleButton toggleColorlessButton = new JToggleButton(
            UIHelper.getTbsIcon("mana/colorless/small/" + MdbLoader.unknownSmlMana), true);
    toggleColorlessButton.setActionCommand("0");
    toggleColorlessButton.addActionListener(this);
    toolBar.add(toggleColorlessButton);
    for (int index = 1; index < IdCardColors.CARD_COLOR_NAMES.length; index++) {
        final JToggleButton toggleButton = new JToggleButton(
                UIHelper.getTbsIcon("mana/colored/small/" + MdbLoader.coloredSmlManas[index]), true);
        toggleButton.setActionCommand(String.valueOf(index));
        toggleButton.addActionListener(this);
        toolBar.add(toggleButton);
    }

    // sorted card type combobox creation
    final List<String> idCards = new ArrayList<String>(Arrays.asList(CardFactory.exportedIdCardNames));
    Collections.sort(idCards);
    final Object[] cardTypes = ArrayUtils.addAll(new String[] { LanguageManager.getString("db_types.any") },
            idCards.toArray());
    idCardComboBox = new JComboBox(cardTypes);
    idCardComboBox.setSelectedIndex(0);
    idCardComboBox.addActionListener(this);
    idCardComboBox.setActionCommand("cardTypeFilter");

    // sorted card properties combobox creation
    final List<String> properties = new ArrayList<String>(
            CardFactory.getPropertiesName(DeckConstraints.getMinProperty(), DeckConstraints.getMaxProperty()));
    Collections.sort(properties);
    final Object[] cardProperties = ArrayUtils
            .addAll(new String[] { LanguageManager.getString("db_properties.any") }, properties.toArray());
    propertiesComboBox = new JComboBox(cardProperties);
    propertiesComboBox.setSelectedIndex(0);
    propertiesComboBox.addActionListener(this);
    propertiesComboBox.setActionCommand("propertyFilter");

    final JLabel colors = new JLabel(" " + LanguageManager.getString("colors") + " : ");
    final JLabel types = new JLabel(" " + LanguageManager.getString("types") + " : ");
    final JLabel property = new JLabel(" " + LanguageManager.getString("properties") + " : ");

    // filter Panel with colors toolBar and card type combobox
    final Box filterPanel = Box.createHorizontalBox();
    filterPanel.add(colors);
    filterPanel.add(toolBar);
    filterPanel.add(types);
    filterPanel.add(idCardComboBox);
    filterPanel.add(property);
    filterPanel.add(propertiesComboBox);

    getContentPane().add(filterPanel, BorderLayout.NORTH);

    // Destination section :

    // Build the panel containing amount of available cards
    final JLabel rightAmount = new JLabel("0/?", SwingConstants.RIGHT);
    rightAmount.setMaximumSize(new Dimension(220, 26));

    // Build the right list
    rightListModel = new MCardTableModel(new MListModel<MCardCompare>(rightAmount, true));
    rightListModel.addTableModelListener(this);
    rightList = new JTable(rightListModel);
    rightList.setShowGrid(false);
    rightList.setTableHeader(null);
    rightList.getSelectionModel().addListSelectionListener(this);
    rightList.getColumnModel().getColumn(0).setMaxWidth(25);
    rightList.setSelectionMode(ListSelectionModel.SINGLE_INTERVAL_SELECTION);

    // Build the panel containing the selected deck
    deckNameTxt = new JTextField("loading...");
    deckNameTxt.setEditable(false);
    deckNameTxt.setBorder(null);
    final JLabel deckLabel = new JLabel(LanguageManager.getString("db_deck") + " : ");
    deckLabel.setLabelFor(deckNameTxt);
    final Box deckNamePanel = Box.createHorizontalBox();
    deckNamePanel.add(deckLabel);
    deckNamePanel.add(deckNameTxt);
    deckNamePanel.setMaximumSize(new Dimension(220, 26));

    // Initialize the text field containing the amount to remove
    removeQtyTxt = new JTextField("1");

    // Build the "Remove" button
    removeButton = new JButton(LanguageManager.getString("db_remove"));
    removeButton.setMnemonic('r');
    removeButton.addMouseListener(this);
    removeButton.setEnabled(false);

    // Build the panel containing : "Remove" amount and "Remove" button
    final Box removePanel = Box.createHorizontalBox();
    removePanel.add(removeButton);
    removePanel.add(removeQtyTxt);
    removePanel.setMaximumSize(new Dimension(220, 26));

    // Build the right panel containing : list, available amount, constraints
    final JScrollPane deskListScroller = new JScrollPane(rightList);
    MToolKit.addOverlay(deskListScroller);
    deskListScroller.setBorder(BorderFactory.createLineBorder(Color.GRAY));
    deskListScroller.setMinimumSize(new Dimension(220, 200));
    deskListScroller.setMaximumSize(new Dimension(220, 32000));

    final Box destPanel = Box.createVerticalBox();
    destPanel.add(deckNamePanel);
    destPanel.add(deskListScroller);
    destPanel.add(rightAmount);
    destPanel.add(removePanel);
    destPanel.setMinimumSize(new Dimension(220, 200));
    destPanel.setMaximumSize(new Dimension(220, 32000));

    // Build the panel containing the name of card in picture
    cardPictureNameTxt = new JLabel("<html><i>no selected card</i>");
    final Box cardPictureNamePanel = Box.createHorizontalBox();
    cardPictureNamePanel.add(cardPictureNameTxt);
    cardPictureNamePanel.setMaximumSize(new Dimension(32010, 26));

    // Group the detail panels
    final JPanel viewCard = new JPanel(null);
    viewCard.add(cardPictureNamePanel);
    viewCard.add(CardView.getInstance());
    viewCard.add(tabbedPane);
    viewCard.setLayout(new BoxLayout(viewCard, BoxLayout.Y_AXIS));

    final Box mainPanel = Box.createHorizontalBox();
    mainPanel.add(destPanel);
    mainPanel.add(viewCard);

    // Add the main panel
    getContentPane().add(srcPanel, BorderLayout.WEST);
    getContentPane().add(mainPanel, BorderLayout.CENTER);

    // Size this frame
    getRootPane().setPreferredSize(new Dimension(WINDOW_WIDTH, WINDOW_HEIGHT));
    getRootPane().setMinimumSize(getRootPane().getPreferredSize());
    pack();
}

From source file:com.raceup.fsae.test.TesterGui.java

/**
 * Creates new edit menu/*from   w  w w. j  av  a  2s .  c om*/
 *
 * @return edit menu
 */
private JMenu createEditMenu() {
    JMenu menu = new JMenu("Edit"); // file menu
    JMenuItem item = new JMenuItem("Test submissions seconds wait");
    item.addActionListener(e -> {
        String userInput = JOptionPane.showInputDialog("Test submissions seconds wait",
                SECONDS_WAIT_BETWEEN_SUBMISSIONS);
        SECONDS_WAIT_BETWEEN_SUBMISSIONS = Integer.parseInt(userInput); // update
    });
    menu.add(item);
    return menu;
}

From source file:edu.brown.gui.CatalogViewer.java

/**
 * //from   ww  w. j ava  2s  .  c o  m
 */
protected void viewerInit() {
    // ----------------------------------------------
    // MENU
    // ----------------------------------------------
    JMenu menu;
    JMenuItem menuItem;

    // 
    // File Menu
    //
    menu = new JMenu("File");
    menu.getPopupMenu().setLightWeightPopupEnabled(false);
    menu.setMnemonic(KeyEvent.VK_F);
    menu.getAccessibleContext().setAccessibleDescription("File Menu");
    menuBar.add(menu);

    menuItem = new JMenuItem("Open Catalog From File");
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From File");
    menuItem.addActionListener(this.menuHandler);
    menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_FILE);
    menu.add(menuItem);

    menuItem = new JMenuItem("Open Catalog From Jar");
    menuItem.setAccelerator(
            KeyStroke.getKeyStroke(KeyEvent.VK_O, ActionEvent.CTRL_MASK | ActionEvent.SHIFT_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Open Catalog From Project Jar");
    menuItem.addActionListener(this.menuHandler);
    menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.CATALOG_OPEN_JAR);
    menu.add(menuItem);

    menu.addSeparator();

    menuItem = new JMenuItem("Quit", KeyEvent.VK_Q);
    menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_Q, ActionEvent.CTRL_MASK));
    menuItem.getAccessibleContext().setAccessibleDescription("Quit Program");
    menuItem.addActionListener(this.menuHandler);
    menuItem.putClientProperty(MenuHandler.MENU_ID, MenuOptions.QUIT);
    menu.add(menuItem);

    // ----------------------------------------------
    // CATALOG TREE PANEL
    // ----------------------------------------------
    this.catalogTree = new JTree();
    this.catalogTree.setEditable(false);
    this.catalogTree.setCellRenderer(new CatalogViewer.CatalogTreeRenderer());
    this.catalogTree.getSelectionModel().setSelectionMode(TreeSelectionModel.SINGLE_TREE_SELECTION);
    this.catalogTree.addTreeSelectionListener(new TreeSelectionListener() {
        public void valueChanged(TreeSelectionEvent e) {
            DefaultMutableTreeNode node = (DefaultMutableTreeNode) CatalogViewer.this.catalogTree
                    .getLastSelectedPathComponent();
            if (node == null)
                return;

            Object user_obj = node.getUserObject();
            String new_text = ""; // <html>";
            boolean text_mode = true;
            if (user_obj instanceof WrapperNode) {
                CatalogType catalog_obj = ((WrapperNode) user_obj).getCatalogType();
                new_text += CatalogViewer.this.getAttributesText(catalog_obj);
            } else if (user_obj instanceof AttributesNode) {
                AttributesNode wrapper = (AttributesNode) user_obj;
                new_text += wrapper.getAttributes();

            } else if (user_obj instanceof PlanTreeCatalogNode) {
                final PlanTreeCatalogNode wrapper = (PlanTreeCatalogNode) user_obj;
                text_mode = false;

                CatalogViewer.this.mainPanel.remove(0);
                CatalogViewer.this.mainPanel.add(wrapper.getPanel(), BorderLayout.CENTER);
                CatalogViewer.this.mainPanel.validate();
                CatalogViewer.this.mainPanel.repaint();

                if (SwingUtilities.isEventDispatchThread() == false) {
                    SwingUtilities.invokeLater(new Runnable() {
                        public void run() {
                            wrapper.centerOnRoot();
                        }
                    });
                } else {
                    wrapper.centerOnRoot();
                }

            } else {
                new_text += CatalogViewer.this.getSummaryText();
            }

            // Text Mode
            if (text_mode) {
                if (CatalogViewer.this.text_mode == false) {
                    CatalogViewer.this.mainPanel.remove(0);
                    CatalogViewer.this.mainPanel.add(CatalogViewer.this.textInfoPanel);
                }
                CatalogViewer.this.textInfoTextArea.setText(new_text);

                // Scroll to top
                CatalogViewer.this.textInfoTextArea.grabFocus();
            }

            CatalogViewer.this.text_mode = text_mode;
        }
    });
    this.generateCatalogTree(this.catalog, this.catalog_file_path.getName());

    //
    // Text Information Panel
    //
    this.textInfoPanel = new JPanel();
    this.textInfoPanel.setLayout(new BorderLayout());
    this.textInfoTextArea = new JTextArea();
    this.textInfoTextArea.setEditable(false);
    this.textInfoTextArea.setFont(new Font(Font.MONOSPACED, Font.PLAIN, 12));
    this.textInfoTextArea.setText(this.getSummaryText());
    this.textInfoTextArea.addFocusListener(new FocusListener() {
        @Override
        public void focusLost(FocusEvent e) {
            // TODO Auto-generated method stub
        }

        @Override
        public void focusGained(FocusEvent e) {
            CatalogViewer.this.scrollTextInfoToTop();
        }
    });
    this.textInfoScroller = new JScrollPane(this.textInfoTextArea);
    this.textInfoPanel.add(this.textInfoScroller, BorderLayout.CENTER);
    this.mainPanel = new JPanel(new BorderLayout());
    this.mainPanel.add(textInfoPanel, BorderLayout.CENTER);

    //
    // Search Toolbar
    //
    JPanel searchPanel = new JPanel();
    searchPanel.setLayout(new BorderLayout());
    JPanel innerSearchPanel = new JPanel();
    innerSearchPanel.setLayout(new BoxLayout(innerSearchPanel, BoxLayout.X_AXIS));
    innerSearchPanel.add(new JLabel("Search: "));
    this.searchField = new JTextField(30);
    innerSearchPanel.add(this.searchField);
    searchPanel.add(innerSearchPanel, BorderLayout.EAST);

    this.searchField.addKeyListener(new KeyListener() {
        private String last = null;

        @Override
        public void keyReleased(KeyEvent e) {
            String value = CatalogViewer.this.searchField.getText().toLowerCase().trim();
            if (!value.isEmpty() && (this.last == null || !this.last.equals(value))) {
                CatalogViewer.this.search(value);
            }
            this.last = value;
        }

        @Override
        public void keyTyped(KeyEvent e) {
            // Do nothing...
        }

        @Override
        public void keyPressed(KeyEvent e) {
            // Do nothing...
        }
    });

    // Putting it all together
    JScrollPane scrollPane = new JScrollPane(this.catalogTree);
    JPanel topPanel = new JPanel();
    topPanel.setLayout(new BorderLayout());
    topPanel.add(searchPanel, BorderLayout.NORTH);
    topPanel.add(scrollPane, BorderLayout.CENTER);

    JSplitPane splitPane = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, topPanel, this.mainPanel);
    splitPane.setDividerLocation(400);

    this.add(splitPane, BorderLayout.CENTER);
}

From source file:gdt.jgui.tool.JEntityEditor.java

/**
 * Get the context menu.// w  w w .  java2  s .c om
 * @return the context menu.
 */
@Override
public JMenu getContextMenu() {
    menu = new JMenu("Context");
    menu.addMenuListener(new MenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            //         System.out.println("EntityEditor:getConextMenu:menu selected");

            if (editCellItem != null)
                menu.remove(editCellItem);
            if (deleteItemsItem != null)
                menu.remove(deleteItemsItem);
            if (copyItem != null)
                menu.remove(copyItem);
            if (pasteItem != null)
                menu.remove(pasteItem);
            if (cutItem != null)
                menu.remove(cutItem);
            if (hasEditingCell()) {
                //menu.addSeparator();
                editCellItem = new JMenuItem("Edit item");
                editCellItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        String locator$ = getEditCellLocator();
                        if (locator$ != null)
                            JConsoleHandler.execute(console, locator$);
                    }
                });
                menu.add(editCellItem);
            }
            if (hasSelectedRows()) {
                deleteItemsItem = new JMenuItem("Delete items");
                deleteItemsItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int response = JOptionPane.showConfirmDialog(JEntityEditor.this,
                                "Delete selected items ?", "Confirm", JOptionPane.YES_NO_OPTION,
                                JOptionPane.QUESTION_MESSAGE);
                        if (response == JOptionPane.YES_OPTION) {
                            deleteRows();
                        }
                    }
                });
                menu.add(deleteItemsItem);
                copyItem = new JMenuItem("Copy");
                copyItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        element$ = null;
                        content = getContent(true);
                    }
                });
                menu.add(copyItem);
                cutItem = new JMenuItem("Cut");
                cutItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        int i = tabbedPane.getSelectedIndex();
                        element$ = tabbedPane.getTitleAt(i);
                        content = getContent(true);
                    }
                });
                menu.add(cutItem);
            }
            if (content != null) {
                pasteItem = new JMenuItem("Paste");
                pasteItem.addActionListener(new ActionListener() {
                    @Override
                    public void actionPerformed(ActionEvent e) {
                        pasteTable(content);
                        int j = tabbedPane.getSelectedIndex();
                        if (element$ != null) {
                            int cnt = tabbedPane.getComponentCount();
                            for (int i = 0; i < cnt; i++) {
                                if (element$.equals(tabbedPane.getTitleAt(i))) {
                                    tabbedPane.setSelectedIndex(i);
                                    cutTable(content);
                                    tabbedPane.setSelectedIndex(j);
                                }
                            }
                        }
                    }
                });
                menu.add(pasteItem);
            }
        }

        @Override
        public void menuDeselected(MenuEvent e) {
        }

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

    JMenuItem doneItem = new JMenuItem("Done");
    doneItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            save();
            console.back();

        }
    });
    menu.add(doneItem);
    JMenuItem cancelItem = new JMenuItem("Cancel");
    cancelItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            console.back();
        }
    });
    menu.add(cancelItem);
    menu.addSeparator();
    JMenuItem addItemItem = new JMenuItem("Add item");
    addItemItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            addRow();
        }
    });
    menu.add(addItemItem);
    JMenuItem addElementItem = new JMenuItem("Add element");
    addElementItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            String element$ = "new element";
            //addElement(element$);
            String locator$ = getRenameElementLocator(element$);
            JConsoleHandler.execute(console, locator$);
        }
    });
    menu.add(addElementItem);
    JMenuItem deleteElementItem = new JMenuItem("Delete element");
    deleteElementItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int response = JOptionPane.showConfirmDialog(JEntityEditor.this, "Delete element ?", "Confirm",
                    JOptionPane.YES_NO_OPTION, JOptionPane.QUESTION_MESSAGE);
            if (response == JOptionPane.YES_OPTION) {
                tabbedPane.remove(tabbedPane.getSelectedComponent());
            }
        }
    });
    menu.add(deleteElementItem);
    JMenuItem renameElementItem = new JMenuItem("Rename element");
    renameElementItem.addActionListener(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            int i = tabbedPane.getSelectedIndex();
            String locator$ = getRenameElementLocator(tabbedPane.getTitleAt(i));
            JConsoleHandler.execute(console, locator$);
        }
    });
    menu.add(renameElementItem);
    menu.addSeparator();
    if (hasEditingCell()) {
        editCellItem = new JMenuItem("Edit item");
        editCellItem.addActionListener(new ActionListener() {
            @Override
            public void actionPerformed(ActionEvent e) {
                String locator$ = getEditCellLocator();
                if (locator$ != null)
                    JConsoleHandler.execute(console, locator$);
            }
        });
        menu.add(editCellItem);
    }
    return menu;
}