Example usage for javax.swing JMenu getItemCount

List of usage examples for javax.swing JMenu getItemCount

Introduction

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

Prototype

@BeanProperty(bound = false)
public int getItemCount() 

Source Link

Document

Returns the number of items on the menu, including separators.

Usage

From source file:Main.java

public static void setFont(Container container, Font font) {
    container.setFont(font);/*from   ww  w  . java2 s. 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.
 */// w  w  w  .  j a va 2  s .  com
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:Main.java

public Main() {
    setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
    JMenuBar bar = new JMenuBar();
    JMenu menu = new JMenu("File");
    ComponentOrientation ori = ComponentOrientation.LEFT_TO_RIGHT;

    menu.applyComponentOrientation(ori);
    bar.add(menu);//ww  w . j a  v a 2 s .  com

    menu.add(new JMenuItem("Close"));
    menu.add(new JSeparator()); // SEPARATOR
    menu.add(new JMenuItem("Exit"));

    setJMenuBar(bar);
    add(new JLabel("A placeholder"));

    pack();
    setSize(300, 300);
    setVisible(true);

    System.out.println(menu.getItemCount());

}

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);
                }//from  ww w.  ja va 2s . co m
            }
        }
    }
}

From source file:com.frostwire.gui.library.LibraryDeviceTableMediator.java

private JMenu createSearchSubMenu(LibraryDeviceTableDataLine dl) {
    JMenu menu = new SkinMenu(I18n.tr("Search"));

    if (dl != null) {
        String str = buildQueryString(dl.getInitializeObject());
        String keywords = QueryUtils.createQueryString(str);
        if (keywords.length() > 0)
            menu.add(new SkinMenuItem(new SearchAction(keywords)));
    }/*w  w w .ja v a 2 s  . co m*/

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

    return menu;
}

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

private JMenu createAdvancedMenu(LibraryTableDataLine dl) {
    JMenu menu = new JMenu(GUIMediator.getStringResource("GENERAL_ADVANCED_SUB_MENU"));
    if (dl != null) {
        menu.add(new JMenuItem(LICENSE_ACTION));
        menu.add(new JMenuItem(BITZI_LOOKUP_ACTION));
        menu.add(new JMenuItem(MAGNET_LOOKUP_ACTION));
        menu.add(new JMenuItem(COPY_MAGNET_TO_CLIPBOARD_ACTION));
        File file = getFile(TABLE.getSelectedRow());
        menu.setEnabled(RouterService.getFileManager().isFileShared(file));
    }//from   w w  w .  java  2 s .c om

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

    return menu;
}

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

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

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

        LimeXMLDocument doc = dl.getXMLDocument();
        if (doc != null) {
            Action[] actions = ActionUtils.createSearchActions(doc);
            for (int i = 0; i < actions.length; i++)
                menu.add(new JMenuItem(actions[i]));
        }//from  www .  ja  va 2s .  co m
    }

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

    return menu;
}

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

/**
 * Clear all technical analysis information.
 *//*  w  ww  .j  a va  2s  .co 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 {/*from   ww  w . j a  va  2  s  .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 {/*from www. j a  v  a  2s.  c  o  m*/
        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();
}