Example usage for javax.swing JMenu getItem

List of usage examples for javax.swing JMenu getItem

Introduction

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

Prototype

public JMenuItem getItem(int pos) 

Source Link

Document

Returns the JMenuItem at the specified position.

Usage

From source file:org.f2o.absurdum.puck.gui.PuckFrame.java

/**
 * Instances and shows Puck's main frame.
 */// w  w w  .j  av a 2  s.c  o  m
public PuckFrame() {

    super();

    setLookAndFeel(PuckConfiguration.getInstance().getProperty("look"));

    /*
    LookAndFeelInfo[] lfs = UIManager.getInstalledLookAndFeels();
    for ( int i = 0 ; i < lfs.length ; i++ )
    {
       if ( lfs[i].getName().toLowerCase().contains("nimbus") )
       {
    try 
    {
       UIManager.setLookAndFeel(lfs[i].getClassName());
    } 
    catch (Exception e) //class not found, instantiation exception, etc. (shouldn't happen)
    {
       e.printStackTrace();
    }
            
       }
    }
    */

    setSize(PuckConfiguration.getInstance().getIntegerProperty("windowWidth"),
            PuckConfiguration.getInstance().getIntegerProperty("windowHeight"));
    setLocation(PuckConfiguration.getInstance().getIntegerProperty("windowLocationX"),
            PuckConfiguration.getInstance().getIntegerProperty("windowLocationY"));
    //setSize(600,600);
    if (PuckConfiguration.getInstance().getBooleanProperty("windowMaximized"))
        maximizeIfPossible();
    //setTitle(Messages.getInstance().getMessage("frame.title"));
    refreshTitle();
    left = new JPanel();
    right = new JPanel();
    JScrollPane rightScroll = new JScrollPane(right);
    rightScroll.getVerticalScrollBar().setUnitIncrement(16); //faster scrollbar (by default it was very slow, maybe because component inside is not text component!)
    split = new JSplitPane(JSplitPane.HORIZONTAL_SPLIT, left, rightScroll) {
        //dynamic resizing of right panel
        /*
        public void setDividerLocation ( int pixels )
        {
              if ( propPanel != null )
              {
          double rightPartSize = getContentPane().getWidth() - pixels - 15;
          System.out.println("rps=" + rightPartSize);
          System.out.println("mnw=" + this.getMinimumSize().getWidth());
          Dimension propPanSize = propPanel.getSize();
          int propPanHeight = 0;
          if (propPanSize != null) propPanHeight = (int) propPanSize.getHeight();
          //propPanel.revalidate();
          System.out.println("h " + propPanHeight);
          //if ( rightPartSize >= propPanel.getMinimumSize().getWidth() )
             propPanel.setPreferredSize(new Dimension((int)rightPartSize,propPanHeight));
             //propPanel.setMinimumSize(new Dimension((int)rightPartSize,propPanHeight));
             //propPanel.setMaximumSize(new Dimension((int)rightPartSize,propPanHeight));
             //propPanel.setSize(new Dimension((int)rightPartSize,propPanHeight));
             propPanel.revalidate();
              }
              super.setDividerLocation(pixels);
        }
        */

    };
    split.setContinuousLayout(true);
    split.setResizeWeight(0.60);
    final int dividerLoc = PuckConfiguration.getInstance().getIntegerProperty("dividerLocation", 0);

    /*
    SwingUtilities.invokeLater(new Runnable(){
    public void run()
    {
    */

    /*   
    }
    });
    */
    split.setOneTouchExpandable(true);
    getContentPane().add(split);

    System.out.println(Toolkit.getDefaultToolkit().getBestCursorSize(20, 20));
    //it's 32x32. Will have to do it.

    //Image img = Toolkit.getDefaultToolkit().createImage( getClass().getResource("addCursor32.png") );

    //Image img = Toolkit.getDefaultToolkit().createImage("addCursor32.png");

    left.setLayout(new BorderLayout());

    //right.setLayout(new BoxLayout(right,BoxLayout.LINE_AXIS));
    if (PuckConfiguration.getInstance().getBooleanProperty("dynamicFormResizing"))
        right.setLayout(new BorderLayout());
    else
        right.setLayout(new FlowLayout());

    propPanel = new PropertiesPanel();
    right.add(propPanel);

    graphPanel = new GraphEditingPanel(propPanel);
    graphPanel.setGrid(Boolean.valueOf(PuckConfiguration.getInstance().getProperty("showGrid")).booleanValue());
    graphPanel.setSnapToGrid(
            Boolean.valueOf(PuckConfiguration.getInstance().getProperty("snapToGrid")).booleanValue());
    propPanel.setGraphEditingPanel(graphPanel);
    tools = new PuckToolBar(graphPanel, propPanel, this);
    left.add(tools, BorderLayout.WEST);
    left.add(graphPanel, BorderLayout.CENTER);

    /*
    Action testAction = 
    new AbstractAction()
    {
       public void actionPerformed ( ActionEvent evt )
       {
          System.out.println("Puck!");
       }
    }
    ;
    testAction.putValue(Action.NAME,"Print Puck");
            
    tools.add(testAction);
    */

    /*
    public void saveChanges ( )
    {
       if ( editingFileName == null )
       {
    //save as... code
       }
       else
       {
    File f = new File(editingFileName);
    try
    {
       Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
       d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d));
       Transformer t = TransformerFactory.newInstance().newTransformer();
       Source s = new DOMSource(d);
       Result r = new StreamResult(f);
       t.transform(s,r);
       editingFileName = f.toString();
       refreshTitle();
    }
    catch ( Exception e )
    {
       JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE);
       e.printStackTrace();
    }
       }
    }
    */

    JMenuBar mainMenuBar = new JMenuBar();
    JMenu fileMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file"));
    fileMenu.setMnemonic(KeyEvent.VK_F);
    saveMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.save"));
    saveMenuItem.setMnemonic(KeyEvent.VK_S);
    saveMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            if (editingFileName == null)
                JOptionPane.showMessageDialog(PuckFrame.this, "File has no name!", "Whoops!",
                        JOptionPane.ERROR_MESSAGE);
            /*
            File f = new File(editingFileName);
            try
            {
             Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
             d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d));
             Transformer t = TransformerFactory.newInstance().newTransformer();
             Source s = new DOMSource(d);
             Result r = new StreamResult(f);
             t.transform(s,r);
             editingFileName = f.toString();
             refreshTitle();
            }
            catch ( Exception e )
            {
             JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE);
             e.printStackTrace();
            }
            */
            try {
                saveChangesInCurrentFile();
            } catch (Exception e) {
                JOptionPane.showMessageDialog(PuckFrame.this, e.getLocalizedMessage(), "Whoops!",
                        JOptionPane.ERROR_MESSAGE);
                e.printStackTrace();
            }
        }
    });
    JMenu newMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.new"));
    JMenuItem newBlankMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.new.blank"));
    //newBlankMenuItem.setMnemonic(KeyEvent.VK_N);
    newBlankMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            GraphElementPanel.emptyQueue(); //stop deferred loads
            graphPanel.clear();
            propPanel.clear();
            JSyntaxBSHCodeFrame.closeAllInstances();
            WorldPanel wp = new WorldPanel(graphPanel);
            WorldNode wn = new WorldNode(wp);
            graphPanel.setWorldNode(wn);
            propPanel.show(graphPanel.getWorldNode());
            resetCurrentlyEditingFile();
            refreshTitle();
            //revalidate(); //only since java 1.7
            //invalidate();
            //validate();
            split.revalidate(); //JComponents do have it before java 1.7 (not JFrame)
        }
    });
    newMenu.add(newBlankMenuItem);
    JMenu templateMenus = new WorldTemplateMenuBuilder(this).getMenu();
    if (templateMenus != null) {
        for (int i = 0; i < templateMenus.getItemCount(); i++) {
            if (i == 0)
                newMenu.add(new JSeparator());
            newMenu.add(templateMenus.getItem(i));
        }
    }
    JMenuItem saveAsMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.saveas"));
    saveAsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            /*
            JFileChooser jfc = new JFileChooser(".");
            int opt = jfc.showSaveDialog(PuckFrame.this);
            if ( opt == JFileChooser.APPROVE_OPTION )
            {
             File f = jfc.getSelectedFile();
             try
             {
                Document d = DocumentBuilderFactory.newInstance().newDocumentBuilder().newDocument();
                d.appendChild(graphPanel.getWorldNode().getAssociatedPanel().getXML(d));
                Transformer t = TransformerFactory.newInstance().newTransformer();
                Source s = new DOMSource(d);
                Result r = new StreamResult(f);
                t.transform(s,r);
                editingFileName = f.toString();
                saveMenuItem.setEnabled(true);
                refreshTitle();
             }
             catch ( Exception e )
             {
                JOptionPane.showMessageDialog(PuckFrame.this,e,"Whoops!",JOptionPane.ERROR_MESSAGE);
                e.printStackTrace();
             }
            }
            */
            try {
                saveAs();
                saveMenuItem.setEnabled(true);
            } catch (Exception e) {
                JOptionPane.showMessageDialog(PuckFrame.this, e.getLocalizedMessage(), "Whoops!",
                        JOptionPane.ERROR_MESSAGE);
                e.printStackTrace();
            }
            //saveAs(saveMenuItem);
        }
    });
    JMenuItem openMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.open"));
    openMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            //graphPanel.setVisible(false);
            //propPanel.setVisible(false);

            JFileChooser jfc = new JFileChooser(".");
            jfc.setFileFilter(new FiltroFicheroMundo());
            int opt = jfc.showOpenDialog(PuckFrame.this);
            if (opt == JFileChooser.APPROVE_OPTION) {
                File f = jfc.getSelectedFile();
                openFileOrShowError(f);
            }

            //graphPanel.setVisible(true);
            //propPanel.setVisible(true);
        }
    });
    openRecentMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.recent"));
    JMenuItem exitMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.file.exit"));
    exitMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {

            /*
            int opt = JOptionPane.showConfirmDialog(PuckFrame.this,Messages.getInstance().getMessage("exit.sure.text"),Messages.getInstance().getMessage("exit.sure.title"),JOptionPane.YES_NO_OPTION,JOptionPane.QUESTION_MESSAGE);
                    
            if ( opt == JOptionPane.YES_OPTION )
             System.exit(0);
            */
            userExit();

        }
    });
    JMenu exportMenu = new JMenu(UIMessages.getInstance().getMessage("menu.file.export"));
    JMenuItem exportAppletMenuItem = new JMenuItem(
            UIMessages.getInstance().getMessage("menu.file.export.applet"));
    exportAppletMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent evt) {
            ExportAppletDialog dial = new ExportAppletDialog(PuckFrame.this);
            dial.setVisible(true);
        }
    });
    exportMenu.add(exportAppletMenuItem);

    fileMenu.add(newMenu);
    fileMenu.add(openMenuItem);
    fileMenu.add(openRecentMenu);
    updateRecentMenu();
    fileMenu.add(new JSeparator());
    saveMenuItem.setEnabled(false);
    fileMenu.add(saveMenuItem);
    fileMenu.add(saveAsMenuItem);
    fileMenu.add(exportMenu);
    fileMenu.add(new JSeparator());
    fileMenu.add(exitMenuItem);

    mainMenuBar.add(fileMenu);

    /**
     * Create an Edit menu to support cut/copy/paste.
     */

    JMenu editMenu = new JMenu(UIMessages.getInstance().getMessage("menu.edit"));
    editMenu.setMnemonic(KeyEvent.VK_E);

    JMenuItem findMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.find.entity"));
    findMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            showFindEntityDialog();
        }
    });
    editMenu.add(findMenuItem);
    editMenu.add(new JSeparator());

    JMenuItem aMenuItem = new JMenuItem(new CutAction());
    aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.cut"));
    aMenuItem.setMnemonic(KeyEvent.VK_T);
    editMenu.add(aMenuItem);

    aMenuItem = new JMenuItem(new CopyAction());
    aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.copy"));
    aMenuItem.setMnemonic(KeyEvent.VK_C);
    editMenu.add(aMenuItem);

    aMenuItem = new JMenuItem(new PasteAction());
    aMenuItem.setText(UIMessages.getInstance().getMessage("menuaction.paste"));
    aMenuItem.setMnemonic(KeyEvent.VK_P);
    editMenu.add(aMenuItem);

    mainMenuBar.add(editMenu);

    JMenu optionsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options"));
    JMenu gridMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options.grid"));
    optionsMenu.add(gridMenu);
    final JCheckBoxMenuItem showGridItem = new JCheckBoxMenuItem(
            UIMessages.getInstance().getMessage("menu.options.grid.show"));
    showGridItem.setSelected(
            Boolean.valueOf(PuckConfiguration.getInstance().getProperty("showGrid")).booleanValue());
    gridMenu.add(showGridItem);
    showGridItem.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                graphPanel.setGrid(true);
                PuckConfiguration.getInstance().setProperty("showGrid", "true");
            } else if (e.getStateChange() == ItemEvent.DESELECTED) {
                graphPanel.setGrid(false);
                PuckConfiguration.getInstance().setProperty("showGrid", "false");
            }
            graphPanel.repaint();
        }
    });
    final JCheckBoxMenuItem snapToGridItem = new JCheckBoxMenuItem(
            UIMessages.getInstance().getMessage("menu.options.grid.snap"));
    snapToGridItem.setSelected(
            Boolean.valueOf(PuckConfiguration.getInstance().getProperty("snapToGrid")).booleanValue());
    gridMenu.add(snapToGridItem);
    snapToGridItem.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent e) {
            if (e.getStateChange() == ItemEvent.SELECTED) {
                graphPanel.setSnapToGrid(true);
                PuckConfiguration.getInstance().setProperty("snapToGrid", "true");
            } else if (e.getStateChange() == ItemEvent.DESELECTED) {
                graphPanel.setSnapToGrid(false);
                PuckConfiguration.getInstance().setProperty("snapToGrid", "false");
            }
            graphPanel.repaint();
        }
    });

    JMenuItem translationModeMenu = new JMenu(UIMessages.getInstance().getMessage("menu.options.translation"));
    ButtonGroup translationGroup = new ButtonGroup();
    final JRadioButtonMenuItem holdMenuItem = new JRadioButtonMenuItem(
            UIMessages.getInstance().getMessage("menu.options.translation.hold"));
    final JRadioButtonMenuItem pushMenuItem = new JRadioButtonMenuItem(
            UIMessages.getInstance().getMessage("menu.options.translation.push"));
    pushMenuItem.setSelected("push".equals(PuckConfiguration.getInstance().getProperty("translateMode")));
    if (!pushMenuItem.isSelected())
        holdMenuItem.setSelected(true);
    translationGroup.add(holdMenuItem);
    translationGroup.add(pushMenuItem);
    holdMenuItem.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent arg0) {
            if (holdMenuItem.isSelected())
                PuckConfiguration.getInstance().setProperty("translateMode", "hold");
            else
                PuckConfiguration.getInstance().setProperty("translateMode", "push");
        }
    });
    translationModeMenu.add(holdMenuItem);
    translationModeMenu.add(pushMenuItem);
    optionsMenu.add(translationModeMenu);

    JMenuItem toolSelectionModeMenu = new JMenu(
            UIMessages.getInstance().getMessage("menu.options.toolselection"));
    ButtonGroup toolSelectionGroup = new ButtonGroup();
    final JRadioButtonMenuItem oneUseMenuItem = new JRadioButtonMenuItem(
            UIMessages.getInstance().getMessage("menu.options.toolselection.oneuse"));
    final JRadioButtonMenuItem multipleUseMenuItem = new JRadioButtonMenuItem(
            UIMessages.getInstance().getMessage("menu.options.toolselection.multipleuse"));
    multipleUseMenuItem.setSelected(
            "multipleUse".equalsIgnoreCase(PuckConfiguration.getInstance().getProperty("toolSelectionMode")));
    if (!multipleUseMenuItem.isSelected())
        oneUseMenuItem.setSelected(true);
    toolSelectionGroup.add(oneUseMenuItem);
    toolSelectionGroup.add(multipleUseMenuItem);
    oneUseMenuItem.addItemListener(new ItemListener() {
        public void itemStateChanged(ItemEvent arg0) {
            if (oneUseMenuItem.isSelected())
                PuckConfiguration.getInstance().setProperty("toolSelectionMode", "oneUse");
            else
                PuckConfiguration.getInstance().setProperty("toolSelectionMode", "multipleUse");
        }
    });
    toolSelectionModeMenu.add(oneUseMenuItem);
    toolSelectionModeMenu.add(multipleUseMenuItem);
    optionsMenu.add(toolSelectionModeMenu);

    JMenuItem sizesMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.iconsizes"));
    sizesMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            IconSizesDialog dial = new IconSizesDialog(PuckFrame.this, true);
            dial.setVisible(true);
        }
    });
    optionsMenu.add(sizesMenuItem);

    JMenuItem showHideMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.showhide"));
    showHideMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            ShowHideDialog dial = new ShowHideDialog(PuckFrame.this, true);
            dial.setVisible(true);
        }
    });
    optionsMenu.add(showHideMenuItem);

    JMenuItem mapColorsMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.options.mapcolors"));
    mapColorsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            MapColorsDialog dial = new MapColorsDialog(PuckFrame.this, true);
            dial.setVisible(true);
        }
    });
    optionsMenu.add(mapColorsMenuItem);

    String skinList = PuckConfiguration.getInstance().getProperty("availableSkins");
    if (skinList != null && skinList.trim().length() > 0) {
        JMenu skinsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.skins"));
        StringTokenizer st = new StringTokenizer(skinList, ", ");
        ButtonGroup skinButtons = new ButtonGroup();
        while (st.hasMoreTokens()) {
            final String nextSkin = st.nextToken();
            final JRadioButtonMenuItem skinMenuItem = new JRadioButtonMenuItem(nextSkin);
            skinMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    setSkin(nextSkin);
                    skinMenuItem.setSelected(true);
                }
            });
            if (nextSkin.equals(PuckConfiguration.getInstance().getProperty("skin")))
                skinMenuItem.setSelected(true);
            skinsMenu.add(skinMenuItem);
            skinButtons.add(skinMenuItem);
        }
        optionsMenu.add(skinsMenu);
    }

    JMenu lookFeelMenu = new JMenu(UIMessages.getInstance().getMessage("menu.looks"));
    ButtonGroup lookButtons = new ButtonGroup();
    final JRadioButtonMenuItem defaultLookMenuItem = new JRadioButtonMenuItem(
            UIMessages.getInstance().getMessage("menu.looks.default"));
    if ("default".equals(PuckConfiguration.getInstance().getProperty("look"))) {
        defaultLookMenuItem.setSelected(true);
    }
    lookFeelMenu.add(defaultLookMenuItem);
    lookButtons.add(defaultLookMenuItem);
    defaultLookMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setLookAndFeel("default");
            defaultLookMenuItem.setSelected(true);
        }
    });
    final JRadioButtonMenuItem systemLookMenuItem = new JRadioButtonMenuItem(
            UIMessages.getInstance().getMessage("menu.looks.system"));
    if ("system".equals(PuckConfiguration.getInstance().getProperty("look"))) {
        systemLookMenuItem.setSelected(true);
    }
    lookFeelMenu.add(systemLookMenuItem);
    lookButtons.add(systemLookMenuItem);
    systemLookMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            setLookAndFeel("system");
            systemLookMenuItem.setSelected(true);
        }
    });
    String additionalLookList = PuckConfiguration.getInstance().getProperty("additionalLooks");
    if (additionalLookList != null && additionalLookList.trim().length() > 0) {
        StringTokenizer st = new StringTokenizer(additionalLookList, ", ");
        while (st.hasMoreTokens()) {
            final String nextLook = st.nextToken();
            final JRadioButtonMenuItem lookMenuItem = new JRadioButtonMenuItem(nextLook);
            lookMenuItem.addActionListener(new ActionListener() {
                public void actionPerformed(ActionEvent e) {
                    setLookAndFeel(nextLook);
                    lookMenuItem.setSelected(true);
                }
            });
            if (nextLook.equals(PuckConfiguration.getInstance().getProperty("look"))) {
                lookMenuItem.setSelected(true);
            }
            lookFeelMenu.add(lookMenuItem);
            lookButtons.add(lookMenuItem);
        }
    }
    optionsMenu.add(lookFeelMenu);

    optionsMenu.add(new UILanguageSelectionMenu(this));

    mainMenuBar.add(optionsMenu);

    JMenu toolsMenu = new JMenu(UIMessages.getInstance().getMessage("menu.tools"));

    final JMenuItem verbListMenuItem = new JMenuItem(
            UIMessages.getInstance().getMessage("menu.tools.verblist"));
    verbListMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            WorldPanel wp = (WorldPanel) graphPanel.getWorldNode().getAssociatedPanel();
            VerbListFrame vlf = VerbListFrame.getInstance(wp.getSelectedLanguageCode());
            vlf.setVisible(true);
        }
    });
    toolsMenu.add(verbListMenuItem);

    final JMenuItem validateMenuItem = new JMenuItem(
            UIMessages.getInstance().getMessage("menu.tools.validatebsh"));
    validateMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            BeanShellCodeValidator bscv = new BeanShellCodeValidator(graphPanel);
            if (!bscv.validate()) {
                BeanShellErrorsDialog bsed = new BeanShellErrorsDialog(PuckFrame.this, bscv.getErrorText());
                bsed.setVisible(true);
                //JOptionPane.showMessageDialog(PuckFrame.this, bscv.getErrorText());
            } else {
                JOptionPane.showMessageDialog(PuckFrame.this,
                        UIMessages.getInstance().getMessage("bsh.code.ok"), "OK!",
                        JOptionPane.INFORMATION_MESSAGE);
                //JOptionPane.showMessageDialog(PuckFrame.this, bscv.getErrorText());
            }
        }
    });
    toolsMenu.add(validateMenuItem);

    mainMenuBar.add(toolsMenu);

    JMenu helpMenu = new JMenu(UIMessages.getInstance().getMessage("menu.help"));
    //JHelpAction.startHelpWorker("help/PUCKHelp.hs");
    //JHelpAction helpTocAction = JHelpAction.getShowHelpInstance(Messages.getInstance().getMessage("menu.help.toc"));
    //JHelpAction helpContextSensitiveAction = JHelpAction.getTrackInstance(Messages.getInstance().getMessage("menu.help.context"));
    //final JMenuItem helpTocMenuItem = new JMenuItem(helpTocAction);
    //final JMenuItem helpContextSensitiveMenuItem = new JMenuItem(helpContextSensitiveAction);
    //helpMenu.add(helpTocMenuItem);
    //helpMenu.add(helpContextSensitiveMenuItem);

    final JMenuItem helpMenuItem = new JMenuItem(UIMessages.getInstance().getMessage("menu.help.toc"));
    helpMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            DocumentationLinkDialog dial = new DocumentationLinkDialog(PuckFrame.this, true);
            dial.setVisible(true);
        }
    });
    helpMenu.add(helpMenuItem);

    mainMenuBar.add(helpMenu);

    MenuMnemonicOnTheFly.setMnemonics(mainMenuBar);

    this.setJMenuBar(mainMenuBar);

    //setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);

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

    propPanel.show(graphPanel.getWorldNode());

    setVisible(true);

    SwingUtilities.invokeLater(new Runnable() {
        public void run() {
            if (dividerLoc > 0)
                split.setDividerLocation(dividerLoc);
            else
                split.setDividerLocation(0.60);
        }
    });

}

From source file:org.rdv.datapanel.DigitalTabularDataPanel.java

private void addColumn() {
    if (columnGroupCount == MAX_COLUMN_GROUP_COUNT) {
        return;/*from   www .j  a  v a 2s  .c om*/
    }

    if (columnGroupCount != 0) {
        panelBox.add(Box.createHorizontalStrut(7));
    }

    final int tableIndex = columnGroupCount;

    final DataTableModel tableModel = new DataTableModel();
    final JTable table = new JTable(tableModel);

    table.setDragEnabled(true);
    table.setName(DigitalTabularDataPanel.class.getName() + " JTable #" + Integer.toString(columnGroupCount));

    if (showThresholdCheckBoxGroup.isSelected()) {
        tableModel.setThresholdVisible(true);
    }

    if (showMinMaxCheckBoxGroup.isSelected()) {
        tableModel.setMaxMinVisible(true);

        table.getColumn("Min").setCellRenderer(doubleCellRenderer);
        table.getColumn("Max").setCellRenderer(doubleCellRenderer);
    }

    table.getColumn("Value").setCellRenderer(dataCellRenderer);

    tables.add(table);
    tableModels.add(tableModel);

    JScrollPane tableScrollPane = new JScrollPane(table);
    panelBox.add(tableScrollPane);

    // popup menu for panel
    JPopupMenu popupMenu = new JPopupMenu();

    final JMenuItem copyMenuItem = new JMenuItem("Copy");
    copyMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            TransferHandler.getCopyAction().actionPerformed(
                    new ActionEvent(table, ae.getID(), ae.getActionCommand(), ae.getWhen(), ae.getModifiers()));
        }
    });
    popupMenu.add(copyMenuItem);

    popupMenu.addSeparator();

    JMenuItem printMenuItem = new JMenuItem("Print...");
    printMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            try {
                table.print(JTable.PrintMode.FIT_WIDTH);
            } catch (PrinterException pe) {
            }
        }
    });
    popupMenu.add(printMenuItem);
    popupMenu.addSeparator();

    final JCheckBoxMenuItem showMaxMinMenuItem = new JCheckBoxMenuItem("Show min/max columns", false);
    showMaxMinMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setMaxMinVisible(showMaxMinMenuItem.isSelected());
        }
    });
    showMinMaxCheckBoxGroup.addCheckBox(showMaxMinMenuItem);
    popupMenu.add(showMaxMinMenuItem);

    final JCheckBoxMenuItem showThresholdMenuItem = new JCheckBoxMenuItem("Show threshold columns", false);
    showThresholdMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent ae) {
            setThresholdVisible(showThresholdMenuItem.isSelected());
        }
    });
    showThresholdCheckBoxGroup.addCheckBox(showThresholdMenuItem);
    popupMenu.add(showThresholdMenuItem);

    popupMenu.addSeparator();

    JMenuItem blankRowMenuItem = new JMenuItem("Insert blank row");
    blankRowMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            tableModel.addBlankRow();
        }
    });
    popupMenu.add(blankRowMenuItem);

    final JMenuItem removeSelectedRowsMenuItem = new JMenuItem("Remove selected rows");
    removeSelectedRowsMenuItem.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            removeSelectedRows(tableIndex);
        }
    });
    popupMenu.add(removeSelectedRowsMenuItem);

    popupMenu.addSeparator();

    JMenu numberOfColumnsMenu = new JMenu("Number of columns");
    numberOfColumnsMenu.addMenuListener(new MenuListener() {
        public void menuSelected(MenuEvent me) {
            JMenu menu = (JMenu) me.getSource();
            for (int j = 0; j < MAX_COLUMN_GROUP_COUNT; j++) {
                JMenuItem menuItem = menu.getItem(j);
                boolean selected = (j == (columnGroupCount - 1));
                menuItem.setSelected(selected);
            }
        }

        public void menuDeselected(MenuEvent me) {
        }

        public void menuCanceled(MenuEvent me) {
        }
    });

    for (int i = 0; i < MAX_COLUMN_GROUP_COUNT; i++) {
        final int number = i + 1;
        JRadioButtonMenuItem item = new JRadioButtonMenuItem(Integer.toString(number));
        item.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent ae) {
                setNumberOfColumns(number);
            }
        });
        numberOfColumnsMenu.add(item);
    }
    popupMenu.add(numberOfColumnsMenu);

    popupMenu.addPopupMenuListener(new PopupMenuListener() {
        public void popupMenuWillBecomeVisible(PopupMenuEvent arg0) {
            boolean anyRowsSelected = table.getSelectedRowCount() > 0;
            copyMenuItem.setEnabled(anyRowsSelected);
            removeSelectedRowsMenuItem.setEnabled(anyRowsSelected);
        }

        public void popupMenuWillBecomeInvisible(PopupMenuEvent arg0) {
        }

        public void popupMenuCanceled(PopupMenuEvent arg0) {
        }
    });

    // set component popup and mouselistener to trigger it
    table.setComponentPopupMenu(popupMenu);
    tableScrollPane.setComponentPopupMenu(popupMenu);

    panelBox.revalidate();

    columnGroupCount++;

    properties.setProperty("numberOfColumns", Integer.toString(columnGroupCount));
}

From source file:processing.app.Base.java

private void filterVisibilityOfSubsequentBoardMenus(List<JMenu> boardsCustomMenus, TargetBoard board,
        int fromIndex) {
    for (int i = fromIndex; i < boardsCustomMenus.size(); i++) {
        JMenu menu = boardsCustomMenus.get(i);
        for (int m = 0; m < menu.getItemCount(); m++) {
            JMenuItem menuItem = menu.getItem(m);
            menuItem.setVisible(menuItem.getAction().getValue("board").equals(board));
        }/*from w w w  . j  a va2s.  com*/
        menu.setVisible(ifThereAreVisibleItemsOn(menu));

        if (menu.isVisible()) {
            JMenuItem visibleSelectedOrFirstMenuItem = selectVisibleSelectedOrFirstMenuItem(menu);
            if (!visibleSelectedOrFirstMenuItem.isSelected()) {
                visibleSelectedOrFirstMenuItem.setSelected(true);
                visibleSelectedOrFirstMenuItem.getAction().actionPerformed(null);
            }
        }
    }
}

From source file:processing.app.Base.java

private static boolean ifThereAreVisibleItemsOn(JMenu menu) {
    for (int i = 0; i < menu.getItemCount(); i++) {
        if (menu.getItem(i).isVisible()) {
            return true;
        }/* ww  w .  j  a  v  a 2  s  .  c om*/
    }
    return false;
}

From source file:processing.app.Base.java

private static JMenuItem selectVisibleSelectedOrFirstMenuItem(JMenu menu) {
    JMenuItem firstVisible = null;
    for (int i = 0; i < menu.getItemCount(); i++) {
        JMenuItem item = menu.getItem(i);
        if (item != null && item.isVisible()) {
            if (item.isSelected()) {
                return item;
            }/*from   ww w . j a va  2s .c  om*/
            if (firstVisible == null) {
                firstVisible = item;
            }
        }
    }

    if (firstVisible != null) {
        return firstVisible;
    }

    throw new IllegalStateException("Menu has no enabled items");
}

From source file:processing.app.Base.java

private static JMenuItem selectFirstEnabledMenuItem(JMenu menu) {
    for (int i = 1; i < menu.getItemCount(); i++) {
        JMenuItem item = menu.getItem(i);
        if (item != null && item.isEnabled()) {
            return item;
        }//from  w w w  .j  a v  a 2  s  . com
    }
    throw new IllegalStateException("Menu has no enabled items");
}

From source file:processing.app.Editor.java

protected JMenu buildToolsMenu() throws Exception {
    toolsMenu = new JMenu(_("Tools"));

    addInternalTools(toolsMenu);/*  ww w. j a v a  2  s  .  c  o  m*/

    JMenuItem item = newJMenuItemShift(_("Serial Monitor"), 'M');
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleSerial();
        }
    });
    toolsMenu.add(item);

    addTools(toolsMenu, BaseNoGui.getToolsFolder());
    File sketchbookTools = new File(BaseNoGui.getSketchbookFolder(), "tools");
    addTools(toolsMenu, sketchbookTools);

    toolsMenu.addSeparator();

    numTools = toolsMenu.getItemCount();

    // XXX: DAM: these should probably be implemented using the Tools plugin
    // API, if possible (i.e. if it supports custom actions, etc.)

    for (JMenu menu : base.getBoardsCustomMenus()) {
        toolsMenu.add(menu);
    }

    if (serialMenu == null)
        serialMenu = new JMenu(_("Port"));
    populatePortMenu();
    toolsMenu.add(serialMenu);
    toolsMenu.addSeparator();

    JMenu programmerMenu = new JMenu(_("Programmer"));
    base.rebuildProgrammerMenu(programmerMenu);
    toolsMenu.add(programmerMenu);

    item = new JMenuItem(_("Burn Bootloader"));
    item.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            handleBurnBootloader();
        }
    });
    toolsMenu.add(item);

    toolsMenu.addMenuListener(new StubMenuListener() {
        public void menuSelected(MenuEvent e) {
            //System.out.println("Tools menu selected.");
            populatePortMenu();
            for (Component c : toolsMenu.getMenuComponents()) {
                if ((c instanceof JMenu) && c.isVisible()) {
                    JMenu menu = (JMenu) c;
                    String name = menu.getText();
                    if (name == null)
                        continue;
                    String basename = name;
                    int index = name.indexOf(':');
                    if (index > 0)
                        basename = name.substring(0, index);
                    String sel = null;
                    int count = menu.getItemCount();
                    for (int i = 0; i < count; i++) {
                        JMenuItem item = menu.getItem(i);
                        if (item != null && item.isSelected()) {
                            sel = item.getText();
                            if (sel != null)
                                break;
                        }
                    }
                    if (sel == null) {
                        if (!name.equals(basename))
                            menu.setText(basename);
                    } else {
                        if (sel.length() > 50)
                            sel = sel.substring(0, 50) + "...";
                        String newname = basename + ": \"" + sel + "\"";
                        if (!name.equals(newname))
                            menu.setText(newname);
                    }
                }
            }
        }
    });

    return toolsMenu;
}

From source file:uk.nhs.cfh.dsp.srth.desktop.uiframework.utils.ActionComponentManager.java

/**
 * Reset quit menu menu item.// w ww .  j  a v  a2 s.c  o  m
 */
private synchronized void resetQuitMenuMenuItem() {
    // get file menu
    JMenu fileMenu = getMenuWithName("File");
    int itemCount = fileMenu.getItemCount();
    for (int i = 0; i < itemCount; i++) {
        JMenuItem item = fileMenu.getItem(i);
        if ("exitMenuItem".equals(item.getName())) {
            // reset item to last item
            fileMenu.insert(item, itemCount);
        }
    }
}