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:Main.java

public static void setFont(Container container, Font font) {
    container.setFont(font);//from w w w.ja v  a  2s  .c  o  m
    trySetBorderFont(font, container);
    Component[] components = container.getComponents();
    for (Component component : components) {
        component.setFont(font);
        if (component instanceof Container) {
            setFont((Container) component, font);
        }
        trySetBorderFont(font, component);
        if (component instanceof JTable) {
            JTable table = (JTable) component;
            table.getTableHeader().setFont(font);
        }
    }

    if (container instanceof JMenu) {
        JMenu jMenu = (JMenu) container;
        for (int i = 0; i < jMenu.getItemCount(); i++) {
            JMenuItem mi = jMenu.getItem(i);
            mi.setFont(font);
        }
    }
}

From source file:Main.java

/**
 * Creates a copy of this menu item, whose contents update automatically
 * whenever the original menu item changes.
 *//* ww w  .ja  v  a  2  s  .  co  m*/
public static JMenuItem cloneMenuItem(final JMenuItem item) {
    if (item == null)
        return null;
    JMenuItem jmi;
    if (item instanceof JMenu) {
        final JMenu menu = (JMenu) item;
        final JMenu jm = new JMenu();
        final int count = menu.getItemCount();
        for (int i = 0; i < count; i++) {
            final JMenuItem ijmi = cloneMenuItem(menu.getItem(i));
            if (ijmi == null)
                jm.addSeparator();
            else
                jm.add(ijmi);
        }
        jmi = jm;
    } else
        jmi = new JMenuItem();
    final ActionListener[] l = item.getActionListeners();
    for (int i = 0; i < l.length; i++)
        jmi.addActionListener(l[i]);
    jmi.setActionCommand(item.getActionCommand());
    syncMenuItem(item, jmi);
    linkMenuItem(item, jmi);
    return jmi;
}

From source file:com.digitalgeneralists.assurance.ui.MainWindow.java

private void setMenuState(int menuIndex, Boolean enabled, Boolean ignoreExceptions) {
    JMenu relevantMenu = this.menuBar.getMenu(menuIndex);

    if (relevantMenu != null) {
        for (int i = 0; i < relevantMenu.getItemCount(); i++) {
            JMenuItem item = relevantMenu.getItem(i);
            // NOTE: I don't like how Swing manages menus.
            if (item != null) {
                if (ignoreExceptions
                        || (!AssuranceActions.newScanDefinitonAction.equals(item.getActionCommand()))) {
                    item.setEnabled(enabled);
                }// w  w  w.  j a  v a 2 s  .  co  m
            }
        }
    }
}

From source file:jchrest.gui.Shell.java

private JMenu createShellMenu() {
    JMenuItem exit = new JMenuItem("Exit", new ImageIcon(Shell.class.getResource("icons/Stop16.gif")));
    exit.addActionListener(new ActionListener() {
        public void actionPerformed(ActionEvent e) {
            System.exit(0);/*from  w ww.j a  v a  2s .  c  om*/
        }
    });

    JMenu menu = new JMenu("Shell");
    menu.setMnemonic(KeyEvent.VK_S);
    menu.add(new AboutAction(this));
    menu.getItem(0).setMnemonic(KeyEvent.VK_A);
    menu.add(new LookFeelAction(this));
    menu.getItem(1).setMnemonic(KeyEvent.VK_T);
    menu.add(new JSeparator());
    menu.add(exit);
    menu.getItem(3).setMnemonic(KeyEvent.VK_X);

    menu.getItem(0).setAccelerator(KeyStroke.getKeyStroke('A', java.awt.Event.CTRL_MASK, false));
    menu.getItem(3).setAccelerator(KeyStroke.getKeyStroke('X', java.awt.Event.CTRL_MASK, false));
    return menu;
}

From source file:jchrest.gui.Shell.java

private JMenu createModelMenu(int time) {
    JMenu menu = new JMenu("Model");
    menu.setMnemonic(KeyEvent.VK_M);
    menu.add(new ClearModelAction(this));
    menu.getItem(0).setMnemonic(KeyEvent.VK_C);

    JMenu submenu = new JMenu("Save");
    submenu.setMnemonic(KeyEvent.VK_S);
    submenu.add(new SaveModelAsVnaAction(this, time));
    submenu.getItem(0).setMnemonic(KeyEvent.VK_N);
    submenu.add(new SaveModelSemanticLinksAsVnaAction(this, time));
    submenu.getItem(1).setMnemonic(KeyEvent.VK_L);
    menu.add(submenu);/*from w  ww. ja  v a  2  s .c om*/

    menu.add(new ModelPropertiesAction(this));
    menu.getItem(2).setMnemonic(KeyEvent.VK_P);
    menu.add(new JSeparator());
    menu.add(new ModelInformationAction(this, time));
    menu.getItem(4).setMnemonic(KeyEvent.VK_I);
    menu.add(new ViewModelAction(this));
    menu.getItem(5).setMnemonic(KeyEvent.VK_V);

    return menu;
}

From source file:edu.ku.brc.specify.tools.ireportspecify.MainFrameSpecify.java

/**
 * Re maps help links for a couple items on iReport Help menu
 *///from   w w w  . jav  a2 s . c  o  m
public void fixUpHelpLinks() {
    int helpMenuIdx = 9;
    int homePageItemIdx = 0;
    int helpItemIdx = 1;
    final String jasperHomePage = "http://jasperforge.org/";

    JMenuBar mb = getJMenuBar();
    JMenu hm = mb.getMenu(helpMenuIdx);
    homePageItem = hm.getItem(homePageItemIdx);
    //remove original listener linked to bad url
    ActionListener[] als = homePageItem.getActionListeners();
    for (int l = 0; l < als.length; l++) {
        homePageItem.removeActionListener(als[l]);
    }
    //add new listener
    homePageItem.addActionListener(new ActionListener() {

        @Override
        public void actionPerformed(ActionEvent arg0) {
            openUrl(jasperHomePage);
        }

    });

    JMenuItem helpPageItem = hm.getItem(helpItemIdx);
    als = helpPageItem.getActionListeners();
    //remove original listener linked to bad url
    for (int l = 0; l < als.length; l++) {
        helpPageItem.removeActionListener(als[l]);
    }
    HelpMgr.registerComponent(helpPageItem, "iReport");

    setIconImage(IconManager.getIcon("SPIReports", IconManager.IconSize.NonStd).getImage());

}

From source file:org.yccheok.jstock.gui.charting.ChartJDialog.java

/**
 * Clear all technical analysis information.
 *///from   w  w w. j  a v  a 2 s .c  o  m
private void clearAll() {
    for (int i = 0; i < this.activeTAExs.size(); i++) {
        final TAEx taEx = this.activeTAExs.get(i);
        if (taEx.ta == TA.SMA) {
            this.updateSMA((Integer) taEx.parameter, false);
            i--;
        } else if (taEx.ta == TA.RSI) {
            this.updateRSI((Integer) taEx.parameter, false);
            i--;
        } else if (taEx.ta == TA.CCI) {
            this.updateCCI((Integer) taEx.parameter, false);
            i--;
        } else if (taEx.ta == TA.EMA) {
            this.updateEMA((Integer) taEx.parameter, false);
            i--;
        } else if (taEx.ta == TA.MFI) {
            this.updateMFI((Integer) taEx.parameter, false);
            i--;
        } else if (taEx.ta == TA.MACD) {
            this.updateMACD((MACD.Period) taEx.parameter, false);
            i--;
        } else {
            assert (false);
        }
    }
    // Update menus.
    for (int i = 0, count = jMenu2.getItemCount(); i < count; i++) {
        final JMenuItem item = jMenu2.getItem(i);
        if (item instanceof JMenu) {
            final JMenu m = (JMenu) item;
            for (int j = 0, count2 = m.getItemCount(); j < count2; j++) {
                JMenuItem item2 = m.getItem(j);
                if (item2 instanceof javax.swing.JCheckBoxMenuItem) {
                    m.getItem(j).setSelected(false);
                }
            }
        }

    }
}

From source file:base.BasePlayer.Main.java

static void removeAnnotationFile(String genomeName, String annotationFile) {

    try {/*  ww  w.  ja va  2s . c o m*/
        if (genomehash.get(genomeName) == null) {
            return;
        }
        for (int i = 1; i < genome.getItemCount(); i++) {
            if (genome.getItem(i).getName().equals(genomeName)) {
                JMenu addMenu = (JMenu) genome.getItem(i);
                for (int j = 0; j < addMenu.getItemCount(); j++) {
                    if (addMenu.getItem(j) == null || addMenu.getItem(j).getText() == null) {
                        continue;
                    }

                    if (annotationFile.contains(addMenu.getItem(j).getText())) {
                        addMenu.remove(j);
                        addMenu.revalidate();
                        break;
                    }
                }
                break;
            }
        }
        for (int i = 0; i < genomehash.get(genomeName).size(); i++) {

            if (genomehash.get(genomeName).get(i).getName().contains(annotationFile.replace(".gff3.gz", ""))) {
                genomehash.get(genomeName).remove(i);
                break;
            }
        }

        Main.defaultAnnotation = "";
        setChromDrop(genomeName);
    } catch (Exception e) {
        e.printStackTrace();
    }
}

From source file:base.BasePlayer.Main.java

static void setFonts() {
    if (Settings.bold.isSelected()) {
        menuFont = new Font("SansSerif", Font.BOLD, Main.defaultFontSize);
        menuFontBold = new Font("SansSerif", Font.BOLD, Main.defaultFontSize + 1);

    } else {/* www. j  a  v  a  2  s  .c om*/
        menuFont = new Font("SansSerif", Font.PLAIN, Main.defaultFontSize);
        menuFontBold = new Font("SansSerif", Font.BOLD, Main.defaultFontSize);
    }

    Draw.defaultFont = menuFont.deriveFont((float) Main.defaultFontSize - 1);

    for (int i = 0; i < menubar.getComponentCount(); i++) {
        menubar.getComponent(i).setFont(Main.menuFont);
    }

    Draw.loadingFont = menuFont.deriveFont((float) (Main.defaultFontSize * 1.5));//      
    buttonHeight = (int) (Main.defaultFontSize * 1.5);
    buttonWidth = Main.defaultFontSize * 6;
    //searchField.setMargin(new Insets(0,Main.defaultFontSize+8, 0, 0));
    searchField.setBorder(null);
    searchField.setBorder(BorderFactory.createCompoundBorder(searchField.getBorder(),
            BorderFactory.createEmptyBorder(0, Main.defaultFontSize + 12, 0, 0)));
    buttonDimension = new Dimension(buttonWidth, buttonHeight);

    ChromDraw.seqFont = ChromDraw.seqFont.deriveFont((float) (Main.defaultFontSize + 2));
    bedCanvas.buf.setFont(Draw.defaultFont);
    bedCanvas.nodebuf.setFont(Draw.defaultFont);
    bedCanvas.fm = bedCanvas.nodebuf.getFontMetrics();
    for (int i = 0; i < bedCanvas.bedTrack.size(); i++) {
        for (int c = 0; c < bedCanvas.bedTrack.get(i).getPopup().getComponentCount(); c++) {
            bedCanvas.bedTrack.get(i).getPopup().getComponent(c).setFont(menuFont);

        }
        if (bedCanvas.bedTrack.get(i).getSelector() != null) {
            bedCanvas.bedTrack.get(i).getSelector().setFonts(menuFont);
        }
        bedCanvas.bedTrack.get(i).getLimitField().setPreferredSize(new Dimension(
                bedCanvas.buf.getFontMetrics().stringWidth("__Value limit__"), Main.defaultFontSize + 6));
        bedCanvas.bedTrack.get(i).getLimitField().setMinimumSize(new Dimension(
                bedCanvas.buf.getFontMetrics().stringWidth("__Value limit__"), Main.defaultFontSize + 6));

    }
    for (int i = 0; i < Control.controlData.fileArray.size(); i++) {
        for (int c = 0; c < Control.controlData.fileArray.get(i).getPopupMenu().getComponentCount(); c++) {
            Control.controlData.fileArray.get(i).getPopupMenu().getComponent(c).setFont(menuFont);

        }
    }
    Average.setFonts(menuFont);
    SampleDialog.setFonts(menuFont);
    menubar.setMargin(new Insets(0, 2, 0, 2));
    filemenu.setMinimumSize(filemenu.getPreferredSize());
    toolmenu.setMinimumSize(toolmenu.getPreferredSize());
    help.setMinimumSize(help.getPreferredSize());
    manage.setPreferredSize(new Dimension(
            bedCanvas.buf.getFontMetrics().stringWidth("Variant Managerrrrrrrr") + 4, buttonHeight));

    manage.setMinimumSize(new Dimension(
            bedCanvas.buf.getFontMetrics().stringWidth("Variant Managerrrrrrrrr") + 4, buttonHeight));
    chromlabel.setPreferredSize(
            new Dimension(bedCanvas.buf.getFontMetrics().stringWidth("..Chrom..") + 4, buttonHeight));
    chromlabel.setMinimumSize(
            new Dimension(bedCanvas.buf.getFontMetrics().stringWidth("..Chrom..") + 4, buttonHeight));
    for (int i = 0; i < panel.getComponentCount(); i++) {
        panel.getComponent(i).setFont(Main.menuFont);
    }
    for (int i = 0; i < filemenu.getItemCount(); i++) {
        if (filemenu.getItem(i) != null) {
            filemenu.getItem(i).setFont(Main.menuFont);
        }
    }
    for (int i = 0; i < toolmenu.getItemCount(); i++) {
        if (toolmenu.getItem(i) != null) {
            toolmenu.getItem(i).setFont(Main.menuFont);

        }
    }
    Main.area.setFont(Main.menuFont);
    for (int i = 0; i < help.getItemCount(); i++) {
        if (help.getItem(i) != null) {
            help.getItem(i).setFont(Main.menuFont);
        }
    }
    for (int i = 0; i < genome.getItemCount(); i++) {
        genome.getItem(i).setFont(Main.menuFont);
        if (genome.getItem(i) instanceof JMenu) {
            JMenu menu = (JMenu) genome.getItem(i);
            for (int j = 0; j < menu.getItemCount(); j++) {
                if (menu.getItem(j) != null) {
                    menu.getItem(j).setFont(Main.menuFont);
                }
            }
        }
    }
    for (int i = 0; i < labels.size(); i++) {
        labels.get(i).setFont(Main.menuFont);
    }

    VariantCaller.setFonts(menuFont);
    PeakCaller.setFonts(menuFont);
    for (int i = 0; i < Main.drawCanvas.splits.size(); i++) {
        Main.drawCanvas.splits.get(i).getExonImageBuffer().setFont(Draw.defaultFont);
        Main.drawCanvas.splits.get(i).getReadBuffer().setFont(Draw.defaultFont);
        Main.drawCanvas.splits.get(i).getSelectbuf().setFont(Draw.defaultFont);
    }

    for (int i = 0; i < chrompan.getComponentCount(); i++) {
        if (chrompan.getComponent(i).getName() != null) {
            chrompan.getComponent(i).setFont(menuFontBold);
        } else {
            chrompan.getComponent(i).setFont(menuFont);
        }
    }
    if (AddGenome.tree != null) {
        AddGenome.setFonts(menuFont);
    }
    Settings.setFonts(menuFont);
    chromDraw.selectImageBuffer.setFont(Draw.defaultFont);
    chromDraw.chromImageBuffer.setFont(Draw.defaultFont);
    manage.setToolTipText("No variants on screen");
    manage.setMargin(new Insets(0, 4, 0, 4));
    zoomout.setPreferredSize(
            new Dimension(bedCanvas.buf.getFontMetrics().stringWidth("Zoom outtttttt") + 4, buttonHeight));
    zoomout.setMinimumSize(
            new Dimension(bedCanvas.buf.getFontMetrics().stringWidth("Zoom outtttttt") + 4, buttonHeight));
    zoomout.setMargin(new Insets(0, 4, 0, 4));
    fieldDimension = new Dimension(
            widthLabel.getFontMetrics(widthLabel.getFont()).stringWidth("chrX:000,000,000-000,000,000bp") + 4,
            buttonHeight);
    positionField.setPreferredSize(fieldDimension);
    positionField.setMinimumSize(fieldDimension);
    controlDraw.buf.setFont(Draw.defaultFont);
    controlDraw.nodebuf.setFont(Draw.defaultFont);
    controlDraw.fm = controlDraw.buf.getFontMetrics();
    controlDraw.repaint();
    letterlength = chromosomeDropdown.getFontMetrics(chromosomeDropdown.getFont()).stringWidth("E");
    chromosomeDropdown.setPopupWidth(textlength * letterlength + 25);
    chromosomeDropdown.revalidate();
    chromosomeDropdown.repaint();
    chromosomeDropdown.setPreferredSize(new Dimension(Main.defaultFontSize * 5, buttonHeight));
    geneDropdown.setPopupWidth(annolength * letterlength);
    refDropdown.setPopupWidth(reflength * letterlength);
    //searchField.setMargin(new Insets(0,buttonHeight+4, 0, 0));
    searchField.setPreferredSize(fieldDimension);
    searchField.setMinimumSize(fieldDimension);
    widthLabel.setPreferredSize(new Dimension(
            widthLabel.getFontMetrics(widthLabel.getFont())
                    .stringWidth("000,000,000bp (Right click to cancel zoom)  NNNNNNNNNNNNNNNNNNNNNNNN") + 10,
            buttonHeight));
    widthLabel.setMinimumSize(new Dimension(
            widthLabel.getFontMetrics(widthLabel.getFont()).stringWidth("000,000,000bp") + 10, buttonHeight));
    back.setFont(menuFont);
    back.setPreferredSize(new Dimension(back.getFontMetrics(back.getFont()).stringWidth(".<<.") + 10,
            buttonDimension.height));
    forward.setFont(menuFont);
    forward.setPreferredSize(new Dimension(forward.getFontMetrics(forward.getFont()).stringWidth(".>>.") + 10,
            buttonDimension.height));
    chromDraw.bounds = chromDraw.chromImageBuffer.getFontMetrics()
            .getStringBounds("K", chromDraw.chromImageBuffer).getWidth();
    chromDraw.cytoHeight = defaultFontSize + 10;
    chromDraw.exonDrawY = defaultFontSize * 2 + 10;
    drawCanvas.sidebuf.setFont(Draw.defaultFont);
    drawCanvas.buf.setFont(Draw.defaultFont);
    drawCanvas.varStringLen = drawCanvas.buf.getFontMetrics().stringWidth(drawCanvas.varloadString);
    if (VariantHandler.filters != null) {
        VariantHandler.setFonts(menuFont);
    }
    chromDraw.updateExons = true;
    chromDraw.repaint();

    for (int i = 0; i < Main.drawCanvas.sampleList.size(); i++) {
        if (Main.drawCanvas.sampleList.get(i).getreadHash() != null) {

            for (int j = 0; j < Main.drawCanvas.splits.size(); j++) {
                if (Main.drawCanvas.sampleList.get(i).getreadHash()
                        .get(Main.drawCanvas.splits.get(j)) == null) {
                    continue;
                }
                double temp = (Main.drawCanvas.sampleList.get(i).getreadHash()
                        .get(Main.drawCanvas.splits.get(j)).readHeight + 2)
                        / (double) Main.drawCanvas.sampleList.get(i).getreadHash()
                                .get(Main.drawCanvas.splits.get(j)).readwheel;
                Main.drawCanvas.sampleList.get(i).getreadHash()
                        .get(Main.drawCanvas.splits.get(j)).readfont = new Font("SansSerif", Font.BOLD,
                                defaultFontSize);
                Main.drawCanvas.sampleList.get(i).getreadHash()
                        .get(Main.drawCanvas.splits.get(j)).readHeight = defaultFontSize;
                Main.drawCanvas.sampleList.get(i).getreadHash()
                        .get(Main.drawCanvas.splits.get(j)).readwheel = (int) ((Main.drawCanvas.sampleList
                                .get(i).getreadHash().get(Main.drawCanvas.splits.get(j)).readHeight + 2)
                                / (double) temp);
                Draw.updateReads = true;
                Main.drawCanvas.repaint();
            }
        }
    }

    splitPane.setDividerLocation(Main.chrompan.getComponentCount() * (Main.defaultFontSize + 6));
    splitPane.revalidate();
}

From source file:org.esa.snap.graphbuilder.rcp.dialogs.support.GraphPanel.java

private static JMenu getMenuFolder(final String folderName, final JMenu currentMenu) {
    int insertPnt = 0;
    for (int i = 0; i < currentMenu.getItemCount(); ++i) {
        JMenuItem item = currentMenu.getItem(i);
        if (item instanceof JMenu) {
            int comp = item.getText().compareToIgnoreCase(folderName);
            if (comp == 0) {
                return (JMenu) item;
            } else if (comp < 0) {
                insertPnt++;//from   w  w w.  ja  v a2  s . co  m
            }
        }
    }

    final JMenu newMenu = new JMenu(folderName);
    newMenu.setIcon(folderIcon);
    currentMenu.insert(newMenu, insertPnt);
    return newMenu;
}