List of usage examples for javax.swing JMenu removeAll
public void removeAll()
From source file:processing.app.Base.java
public void rebuildExamplesMenu(JMenu menu) { if (menu == null) { return;//from w w w . ja va 2 s . c o m } menu.removeAll(); // Add examples from distribution "example" folder JMenuItem label = new JMenuItem(tr("Built-in Examples")); label.setEnabled(false); menu.add(label); boolean found = addSketches(menu, BaseNoGui.getExamplesFolder()); if (found) { menu.addSeparator(); } // Libraries can come from 4 locations: collect info about all four String boardId = null; String referencedPlatformName = null; String myArch = null; TargetPlatform targetPlatform = BaseNoGui.getTargetPlatform(); if (targetPlatform != null) { myArch = targetPlatform.getId(); boardId = BaseNoGui.getTargetBoard().getName(); String core = BaseNoGui.getBoardPreferences().get("build.core", "arduino"); if (core.contains(":")) { String refcore = core.split(":")[0]; TargetPlatform referencedPlatform = BaseNoGui.getTargetPlatform(refcore, myArch); if (referencedPlatform != null) { referencedPlatformName = referencedPlatform.getPreferences().get("name"); } } } // Divide the libraries into 7 lists, corresponding to the 4 locations // with the retired IDE libs further divided into their own list, and // any incompatible sketchbook libs further divided into their own list. // The 7th list of "other" libraries should always be empty, but serves // as a safety feature to prevent any library from vanishing. LibraryList allLibraries = BaseNoGui.librariesIndexer.getInstalledLibraries(); LibraryList ideLibs = new LibraryList(); LibraryList retiredIdeLibs = new LibraryList(); LibraryList platformLibs = new LibraryList(); LibraryList referencedPlatformLibs = new LibraryList(); LibraryList sketchbookLibs = new LibraryList(); LibraryList sketchbookIncompatibleLibs = new LibraryList(); LibraryList otherLibs = new LibraryList(); for (UserLibrary lib : allLibraries) { // Get the library's location - used for sorting into categories Location location = lib.getLocation(); // Is this library compatible? List<String> arch = lib.getArchitectures(); boolean compatible; if (myArch == null || arch == null || arch.contains("*")) { compatible = true; } else { compatible = arch.contains(myArch); } // IDE Libaries (including retired) if (location == Location.IDE_BUILTIN) { if (compatible) { // only compatible IDE libs are shown if (lib.getTypes().contains("Retired")) { retiredIdeLibs.add(lib); } else { ideLibs.add(lib); } } // Platform Libraries } else if (location == Location.CORE) { // all platform libs are assumed to be compatible platformLibs.add(lib); // Referenced Platform Libraries } else if (location == Location.REFERENCED_CORE) { // all referenced platform libs are assumed to be compatible referencedPlatformLibs.add(lib); // Sketchbook Libraries (including incompatible) } else if (location == Location.SKETCHBOOK) { if (compatible) { // libraries promoted from sketchbook (behave as builtin) if (!lib.getTypes().isEmpty() && lib.getTypes().contains("Arduino") && lib.getArchitectures().contains("*")) { ideLibs.add(lib); } else { sketchbookLibs.add(lib); } } else { sketchbookIncompatibleLibs.add(lib); } // Other libraries of unknown type (should never occur) } else { otherLibs.add(lib); } } // Add examples from libraries if (!ideLibs.isEmpty()) { ideLibs.sort(); label = new JMenuItem(tr("Examples for any board")); label.setEnabled(false); menu.add(label); } for (UserLibrary lib : ideLibs) { addSketchesSubmenu(menu, lib); } if (!retiredIdeLibs.isEmpty()) { retiredIdeLibs.sort(); JMenu retired = new JMenu(tr("RETIRED")); menu.add(retired); for (UserLibrary lib : retiredIdeLibs) { addSketchesSubmenu(retired, lib); } } if (!platformLibs.isEmpty()) { menu.addSeparator(); platformLibs.sort(); label = new JMenuItem(I18n.format(tr("Examples for {0}"), boardId)); label.setEnabled(false); menu.add(label); for (UserLibrary lib : platformLibs) { addSketchesSubmenu(menu, lib); } } if (!referencedPlatformLibs.isEmpty()) { menu.addSeparator(); referencedPlatformLibs.sort(); label = new JMenuItem(I18n.format(tr("Examples for {0}"), referencedPlatformName)); label.setEnabled(false); menu.add(label); for (UserLibrary lib : referencedPlatformLibs) { addSketchesSubmenu(menu, lib); } } if (!sketchbookLibs.isEmpty()) { menu.addSeparator(); sketchbookLibs.sort(); label = new JMenuItem(tr("Examples from Custom Libraries")); label.setEnabled(false); menu.add(label); for (UserLibrary lib : sketchbookLibs) { addSketchesSubmenu(menu, lib); } } if (!sketchbookIncompatibleLibs.isEmpty()) { sketchbookIncompatibleLibs.sort(); JMenu incompatible = new JMenu(tr("INCOMPATIBLE")); menu.add(incompatible); for (UserLibrary lib : sketchbookIncompatibleLibs) { addSketchesSubmenu(incompatible, lib); } } if (!otherLibs.isEmpty()) { menu.addSeparator(); otherLibs.sort(); label = new JMenuItem(tr("Examples from Other Libraries")); label.setEnabled(false); menu.add(label); for (UserLibrary lib : otherLibs) { addSketchesSubmenu(menu, lib); } } }
From source file:processing.app.Editor.java
protected void buildSketchMenu(JMenu sketchMenu) { sketchMenu.removeAll(); JMenuItem item = newJMenuItem(_("Verify / Compile"), 'R'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleRun(false, Editor.this.presentHandler, Editor.this.runHandler); }/* w w w. ja v a2s . co m*/ }); sketchMenu.add(item); item = newJMenuItem(_("Upload"), 'U'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleExport(false); } }); sketchMenu.add(item); item = newJMenuItemShift(_("Upload Using Programmer"), 'U'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleExport(true); } }); sketchMenu.add(item); item = newJMenuItemAlt(_("Export compiled Binary"), 'S'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleRun(false, new ShouldSaveReadOnly(), Editor.this.presentAndSaveHandler, Editor.this.runAndSaveHandler); } }); sketchMenu.add(item); // item = new JMenuItem("Stop"); // item.addActionListener(new ActionListener() { // public void actionPerformed(ActionEvent e) { // handleStop(); // } // }); // sketchMenu.add(item); sketchMenu.addSeparator(); item = newJMenuItem(_("Show Sketch Folder"), 'K'); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { Base.openFolder(sketch.getFolder()); } }); sketchMenu.add(item); item.setEnabled(Base.openFolderAvailable()); if (importMenu == null) { importMenu = new JMenu(_("Include Library")); MenuScroller.setScrollerFor(importMenu); base.rebuildImportMenu(importMenu); } sketchMenu.add(importMenu); item = new JMenuItem(_("Add File...")); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { sketch.handleAddFile(); } }); sketchMenu.add(item); }