Example usage for javax.swing JMenu revalidate

List of usage examples for javax.swing JMenu revalidate

Introduction

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

Prototype

public void revalidate() 

Source Link

Document

Supports deferred automatic layout.

Usage

From source file:ca.sqlpower.swingui.object.VariablesPanel.java

@SuppressWarnings("unchecked")
private void showVarsPicker() {
    final MultiValueMap namespaces = this.variableHelper.getNamespaces();

    List<String> sortedNames = new ArrayList<String>(namespaces.keySet().size());
    sortedNames.addAll(namespaces.keySet());
    Collections.sort(sortedNames, new Comparator<String>() {
        public int compare(String o1, String o2) {
            if (o1 == null) {
                return -1;
            }//from   ww w  .  java2  s  .com
            if (o2 == null) {
                return 1;
            }
            return o1.compareTo(o2);
        };
    });

    final JPopupMenu menu = new JPopupMenu();
    for (final String name : sortedNames) {
        final JMenu subMenu = new JMenu(name);
        menu.add(subMenu);
        subMenu.addMenuListener(new MenuListener() {
            private Timer timer;

            public void menuSelected(MenuEvent e) {

                subMenu.removeAll();
                subMenu.add(new PleaseWaitAction());

                ActionListener menuPopulator = new ActionListener() {
                    public void actionPerformed(ActionEvent e) {
                        if (subMenu.isPopupMenuVisible()) {
                            subMenu.removeAll();
                            for (Object namespaceO : namespaces.getCollection(name)) {
                                String namespace = (String) namespaceO;
                                logger.debug("Resolving variables for namespace ".concat(namespace));
                                int nbItems = 0;
                                for (String key : variableHelper.keySet(namespace)) {
                                    subMenu.add(new InsertVariableAction(SPVariableHelper.getKey((String) key),
                                            (String) key));
                                    nbItems++;
                                }
                                if (nbItems == 0) {
                                    subMenu.add(new DummyAction());
                                    logger.debug("No variables found.");
                                }
                            }
                            subMenu.revalidate();
                            subMenu.getPopupMenu().pack();
                        }
                    }
                };
                timer = new Timer(700, menuPopulator);
                timer.setRepeats(false);
                timer.start();
            }

            public void menuDeselected(MenuEvent e) {
                timer.stop();
            }

            public void menuCanceled(MenuEvent e) {
                timer.stop();
            }
        });
    }

    menu.show(varNameText, 0, varNameText.getHeight());
}

From source file:base.BasePlayer.Main.java

static void removeAnnotationFile(String genomeName, String annotationFile) {

    try {/*from   ww  w.ja  va2  s . c om*/
        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 addAnnotationFile(String genomeName, File annotationFile) {
    boolean first = false;

    if (genomehash.get(genomeName) == null) {
        genomehash.put(genomeName, new ArrayList<File>());
    }/*  w  w w  .ja  va  2s .  c o  m*/
    if (genome.getItemCount() == 0) {
        first = true;
    }

    genomehash.get(genomeName).add(annotationFile);
    JMenuItem additem = new JMenuItem(
            annotationFile.getName().substring(0, annotationFile.getName().indexOf(".bed.gz")));
    additem.setName(annotationFile.getName().substring(0, annotationFile.getName().indexOf(".bed.gz")));
    additem.addMouseListener(Main.thisMainListener);

    for (int i = 1; i < genome.getItemCount(); i++) {

        if (genome.getItem(i).getName().equals(genomeName)) {
            JMenu addMenu = (JMenu) genome.getItem(i);
            addMenu.setFont(menuFont);
            if (first) {
                JMenuItem addAnnotation = new JMenuItem("Add new annotation file...");
                addAnnotation.setFont(menuFont);
                addAnnotation.addMouseListener(Main.thisMainListener);
                addAnnotation.setName("add_annotation");
                addMenu.add(addAnnotation);
                JLabel addLabel = new JLabel("  Select annotation: ");
                addLabel.setFont(menuFont);
                labels.add(addLabel);
                addMenu.add(addLabel);
                addMenu.add(new JSeparator());
            }
            additem.setFont(menuFont);
            addMenu.add(additem);
            addMenu.revalidate();
            genome.revalidate();
            break;
        }
    }
    Main.defaultAnnotation = annotationFile.getName();
    setChromDrop(genomeName);
}

From source file:org.parosproxy.paros.extension.ExtensionLoader.java

private void addMenuHelper(JMenu menu, List<JMenuItem> items, int existingCount) {
    for (JMenuItem item : items) {
        if (item != null) {
            if (item == ExtensionHookMenu.MENU_SEPARATOR) {
                menu.addSeparator();// w  ww.  j  ava2  s  .  co  m
                continue;
            }

            menu.add(item, menu.getItemCount() - existingCount);
        }
    }

    menu.revalidate();
}

From source file:org.parosproxy.paros.extension.ExtensionLoader.java

private void removeMenuHelper(JMenu menu, List<JMenuItem> items) {
    for (JMenuItem item : items) {
        if (item != null) {
            menu.remove(item);/* www  .  j a va  2 s .com*/
        }
    }
    menu.revalidate();
}

From source file:processing.app.Editor.java

protected void buildMenuBar() throws Exception {
    JMenuBar menubar = new JMenuBar();
    final JMenu fileMenu = buildFileMenu();
    fileMenu.addMenuListener(new StubMenuListener() {
        @Override//from   w w  w . j  ava2 s  .  c  o m
        public void menuSelected(MenuEvent e) {
            List<Component> components = Arrays.asList(fileMenu.getComponents());
            if (!components.contains(sketchbookMenu)) {
                fileMenu.insert(sketchbookMenu, 2);
            }
            if (!components.contains(sketchbookMenu)) {
                fileMenu.insert(examplesMenu, 3);
            }
            fileMenu.revalidate();
            validate();
        }
    });
    menubar.add(fileMenu);

    menubar.add(buildEditMenu());

    final JMenu sketchMenu = new JMenu(_("Sketch"));
    sketchMenu.addMenuListener(new StubMenuListener() {

        @Override
        public void menuSelected(MenuEvent e) {
            buildSketchMenu(sketchMenu);
            sketchMenu.revalidate();
            validate();
        }
    });
    buildSketchMenu(sketchMenu);
    menubar.add(sketchMenu);

    final JMenu toolsMenu = buildToolsMenu();
    toolsMenu.addMenuListener(new StubMenuListener() {
        @Override
        public void menuSelected(MenuEvent e) {
            List<Component> components = Arrays.asList(fileMenu.getComponents());
            int offset = 0;
            for (JMenu menu : base.getBoardsCustomMenus()) {
                if (!components.contains(menu)) {
                    toolsMenu.insert(menu, numTools + offset);
                    offset++;
                }
            }
            if (!components.contains(serialMenu)) {
                toolsMenu.insert(serialMenu, numTools + offset);
            }
            toolsMenu.revalidate();
            validate();
        }
    });
    menubar.add(toolsMenu);

    menubar.add(buildHelpMenu());
    setJMenuBar(menubar);
}

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

/**
 * Adds the action component./*w  ww  .  j av  a 2  s .c  o m*/
 *
 * @param actionComponent the action component
 */
public synchronized void addActionComponent(final ActionComponent actionComponent) {

    if (actionComponent != null) {
        Runnable runnable = new Runnable() {
            public void run() {
                // set LNF first to avoid component UI errors
                LookAndFeelUtils.setDefaultLNF();

                String menuName = actionComponent.getMenuName();
                int menuLocationIndex = actionComponent.getMenuLocationIndex();
                int toolBarIndex = actionComponent.getToolBarIndex();
                logger.info("Added to menuName = " + menuName);

                // get menu for menu name
                JMenu menu = getMenuWithName(menuName);
                // create menu item with action;
                JMenuItem menuItem = new JMenuItem(actionComponent.getAction());
                SwingUtilities.updateComponentTreeUI(menuItem);
                checkAndAddMenuItem(menu, menuItem, menuLocationIndex);

                // refresh menu
                menu.revalidate();
                SwingUtilities.updateComponentTreeUI(menu);

                // check if set to visible on toolbar
                if (actionComponent.isVisibleOnToolbar()) {
                    JideButton b = new JideButton(actionComponent.getAction());
                    // set text to be empty
                    b.setText("");
                    SwingUtilities.updateComponentTreeUI(b);
                    // check toolbar count and add button
                    checkAndAddToolbarButton(toolBar, b, toolBarIndex);
                }

                // refresh toolbar and menubar
                menuBar.revalidate();
                toolBar.revalidate();
                SwingUtilities.updateComponentTreeUI(toolBar);
                SwingUtilities.updateComponentTreeUI(menuBar);
            }
        };

        SwingUtilities.invokeLater(runnable);
    } else {
        throw new IllegalArgumentException("Argument passed can not be null : " + actionComponent);
    }
}