Java Code Examples for javax.swing.JMenu#removeAll()

The following examples show how to use javax.swing.JMenu#removeAll() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: MenuSimulate.java    From Logisim with GNU General Public License v3.0 6 votes vote down vote up
private void recreateStateMenu(JMenu menu, ArrayList<CircuitStateMenuItem> items, int code) {
	menu.removeAll();
	menu.setEnabled(items.size() > 0);
	boolean first = true;
	int mask = (Main.JAVA_VERSION < 10.0) ? 128 : getToolkit().getMenuShortcutKeyMaskEx();
	for (int i = items.size() - 1; i >= 0; i--) {
		JMenuItem item = items.get(i);
		menu.add(item);
		if (first) {
			item.setAccelerator(KeyStroke.getKeyStroke(code, mask));
			first = false;
		} else {
			item.setAccelerator(null);
		}
	}
}
 
Example 2
Source File: ParticleDataTrack.java    From tracker with GNU General Public License v3.0 6 votes vote down vote up
/**
 * Returns a menu with items associated with this track's point properties.
 * 
 * @param trackerPanel the tracker panel
 * @return a menu
 */
protected JMenu getPointMenu(TrackerPanel trackerPanel) {
   // prepare menu items
   colorItem.setText(TrackerRes.getString("TTrack.MenuItem.Color")); //$NON-NLS-1$
   footprintMenu.setText(TrackerRes.getString("TTrack.MenuItem.Footprint")); //$NON-NLS-1$
   velocityMenu.setText(TrackerRes.getString("PointMass.MenuItem.Velocity")); //$NON-NLS-1$
   accelerationMenu.setText(TrackerRes.getString("PointMass.MenuItem.Acceleration")); //$NON-NLS-1$
	JMenu menu = getLeader()!=this? super.getMenu(trackerPanel): new JMenu();
	menu.setText(getPointName());
   menu.setIcon(getFootprint().getIcon(21, 16));
	menu.removeAll();
	menu.add(colorItem);
	menu.add(footprintMenu);
	menu.addSeparator();
	menu.add(velocityMenu);
	menu.add(accelerationMenu);		
   if (trackerPanel.isEnabled("model.stamp")) { //$NON-NLS-1$
		menu.addSeparator();
		menu.add(stampItem);
   }
	return menu;
}
 
Example 3
Source File: ComponentSource.java    From LoboBrowser with MIT License 6 votes vote down vote up
private void populateSearchers() {
  final JMenu searchersMenu = this.searchersMenu;
  searchersMenu.removeAll();
  final ToolsSettings settings = ToolsSettings.getInstance();
  final Collection<SearchEngine> searchEngines = settings.getSearchEngines();
  final SearchEngine selectedEngine = settings.getSelectedSearchEngine();
  if (searchEngines != null) {
    for (final SearchEngine se : searchEngines) {
      final SearchEngine finalSe = se;
      final JRadioButtonMenuItem item = new JRadioButtonMenuItem();
      item.setAction(new AbstractAction() {
        private static final long serialVersionUID = -3263394523150719487L;

        public void actionPerformed(final ActionEvent e) {
          settings.setSelectedSearchEngine(finalSe);
          settings.save();
          ComponentSource.this.updateSearchButtonTooltip();
        }
      });
      item.setSelected(se == selectedEngine);
      item.setText(se.getName());
      item.setToolTipText(se.getDescription());
      searchersMenu.add(item);
    }
  }
}
 
Example 4
Source File: ComponentSource.java    From LoboBrowser with MIT License 6 votes vote down vote up
public void populateRecentHosts() {
  final JMenu recentHostsMenu = this.recentHostsMenu;
  recentHostsMenu.removeAll();
  final Collection<HostEntry> hostEntries = NavigationHistory.getInstance().getRecentHostEntries(PREFERRED_MAX_MENU_SIZE);
  for (final HostEntry entry : hostEntries) {
    final String urlText = "http://" + entry.host;
    try {
      final URL url = new URL(urlText);
      final long elapsed = System.currentTimeMillis() - entry.timestamp;
      final String menuText = entry.host + " (" + Timing.getElapsedText(elapsed) + " ago)";
      final Action action = this.actionPool.createNavigateAction(url);
      final JMenuItem menuItem = menuItem(menuText, action);
      menuItem.setToolTipText(url.toExternalForm());
      recentHostsMenu.add(menuItem);
    } catch (final MalformedURLException mfu) {
      logger.log(Level.WARNING, "populateRecentHosts(): Bad URL=" + urlText, mfu);
    }
  }
}
 
Example 5
Source File: ComponentSource.java    From LoboBrowser with MIT License 6 votes vote down vote up
public void populateForwardMore() {
  final List<NavigationEntry> entries = this.window.getForwardNavigationEntries();
  final JMenu forwardMoreMenu = this.forwardMoreMenu;
  forwardMoreMenu.removeAll();
  for (final NavigationEntry entry : entries) {
    final String method = entry.getMethod();
    if ("GET".equals(method)) {
      final String title = entry.getTitle();
      final URL url = entry.getUrl();
      final String text = (title == null) || (title.length() == 0) ? url.toExternalForm() : title;
      final Action action = this.actionPool.createGoToAction(entry);
      final JMenuItem menuItem = menuItem(text, action);
      menuItem.setToolTipText(url.toExternalForm());
      forwardMoreMenu.add(menuItem);
    }
  }
}
 
Example 6
Source File: ComponentSource.java    From LoboBrowser with MIT License 6 votes vote down vote up
public void populateBackMore() {
  final List<NavigationEntry> entries = this.window.getBackNavigationEntries();
  final JMenu backMoreMenu = this.backMoreMenu;
  backMoreMenu.removeAll();
  for (final NavigationEntry entry : entries) {
    final String method = entry.getMethod();
    if ("GET".equals(method)) {
      final String title = entry.getTitle();
      final URL url = entry.getUrl();
      final String text = (title == null) || (title.length() == 0) ? url.toExternalForm() : title;
      final Action action = this.actionPool.createGoToAction(entry);
      final JMenuItem menuItem = menuItem(text, action);
      menuItem.setToolTipText(url.toExternalForm());
      backMoreMenu.add(menuItem);
    }
  }
  // backMoreMenu.revalidate();
}
 
Example 7
Source File: RecentItems.java    From Cognizant-Intelligent-Test-Scripter with Apache License 2.0 6 votes vote down vote up
/**
 * Add list orecentProjFile recent projects as Menu Items to the Recent
 * projects menu
 *
 *
 * @param recentProj instance orecentProjFile the menu to address
 * <code>Recent Projects</code>
 */
public void updateMenu(JMenu recentProj) {
    recentProj.removeAll();
    try {
        for (String file : recentProjects) {
            recentItemMenu = new JMenuItem();
            recentItemMenu.setFont(new java.awt.Font("sansserif", 0, 11));
            recentItemMenu.setText(toName(file));
            recentItemMenu.setToolTipText(file);
            recentProj.add(recentItemMenu);
            addlistener(recentItemMenu);
        }
    } catch (Exception ex) {
        Logger.getLogger(RecentItems.class.getName()).log(Level.SEVERE, null, ex);
    }
}
 
Example 8
Source File: BindAction.java    From netbeans with Apache License 2.0 6 votes vote down vote up
private void createBindingsSubmenu(JMenu menu) {
    if (menu.getMenuComponentCount() > 0)
        menu.removeAll();

    Node[] nodes = getActivatedNodes();
    if (nodes.length != 1)
        return;

    RADComponentCookie radCookie = nodes[0].getCookie(RADComponentCookie.class);
    if (radCookie == null)
        return;

    BindingProperty[][] bindingProps = radCookie.getRADComponent().getBindingProperties();
    BindingProperty[] props = bindingProps[(bindingProps[0].length==0) ? 1 : 0];
    if (props.length > 0) {
        for (BindingProperty prop : props) {
            BindingMenuItem mi = new BindingMenuItem(prop);
            mi.addActionListener(mi);
            menu.add(mi);
        }
    } else {
        JMenuItem item = new JMenuItem(NbBundle.getMessage(BindAction.class, "MSG_NoBinding")); // NOI18N
        item.setEnabled(false);
        menu.add(item);
    }
}
 
Example 9
Source File: HubsMenu.java    From arcusplatform with Apache License 2.0 6 votes vote down vote up
private void rebuild(Store<HubModel> hubs, JMenu menu) {
   menu.removeAll();
   menu.add(registerHub);
   menu.add(registerHubLegacy);
   menu.add(reloadHub);
   menu.addSeparator();
   menu.add(decodeHubInfo);
   menu.addSeparator();

   if(hubs.size() == 0) {
      JMenuItem emptyMenu = new JMenuItem("Account has no hubs");
      emptyMenu.setEnabled(false);
      menu.add(emptyMenu);
   }
   else {
      for(HubModel hub: hubs.values()) {
         menu.add(new HubMenu(hub));
      }
   }
}
 
Example 10
Source File: Debug.java    From netcdf-java with BSD 3-Clause "New" or "Revised" License 5 votes vote down vote up
/**
 * Construct cascading pull-aside menus using the values of the debug flags
 * in the Preferences object.
 * 
 * @param topMenu attach the menus as children of this one.
 */
public static void constructMenu(JMenu topMenu) {
  if (debug)
    System.out.println("Debug.constructMenu ");

  if (topMenu.getItemCount() > 0)
    topMenu.removeAll();

  try {
    addToMenu(topMenu, store); // recursive
  } catch (BackingStoreException e) {
  }

  topMenu.revalidate();
}
 
Example 11
Source File: NameSet.java    From audiveris with GNU Affero General Public License v3.0 5 votes vote down vote up
/**
 * Feed a menu with the dynamic content of this NameSet.
 *
 * @param menu         the menu to be fed, if null it is allocated by this method
 * @param itemListener the listener to be called on item selection
 * @return the menu properly dynamized
 */
public JMenu feedMenu (JMenu menu,
                       final ActionListener itemListener)
{
    final JMenu finalMenu = (menu != null) ? menu : new JMenu(setName);

    MenuListener menuListener = new AbstractMenuListener()
    {
        @Override
        public void menuSelected (MenuEvent e)
        {
            // Clean up the whole menu
            finalMenu.removeAll();

            // Rebuild the whole list of menu items on the fly
            synchronized (NameSet.this) {
                for (String f : names) {
                    JMenuItem menuItem = new JMenuItem(f);
                    menuItem.addActionListener(itemListener);
                    finalMenu.add(menuItem);
                }
            }
        }
    };

    // Listener to menu selection, to modify content on-the-fly
    finalMenu.addMenuListener(menuListener);

    return finalMenu;
}
 
Example 12
Source File: MenuManager.java    From jeveassets with GNU General Public License v2.0 5 votes vote down vote up
public static void update(final Program program, final Class<?> clazz) {
	MenuManager<?> menuManager = MANAGERS.get(clazz);
	if (menuManager != null) {
		menuManager.updateMainTableMenu();
	} else { //No table menu
		JMenu jMenu = program.getMainWindow().getMenu().getTableMenu();
		jMenu.removeAll();
		jMenu.setEnabled(false);
	}
}
 
Example 13
Source File: ComponentSource.java    From LoboBrowser with MIT License 5 votes vote down vote up
public void populateRecentBookmarks() {
  final JMenu bookmarksMenu = this.recentBookmarksMenu;
  bookmarksMenu.removeAll();
  final Collection<HistoryEntry<BookmarkInfo>> historyEntries = BookmarksHistory.getInstance().getRecentEntries(PREFERRED_MAX_MENU_SIZE);
  for (final HistoryEntry<BookmarkInfo> hentry : historyEntries) {
    final BookmarkInfo binfo = hentry.getItemInfo();
    String text = binfo.getTitle();
    final URL url = binfo.getUrl();
    final String urlText = url.toExternalForm();
    if ((text == null) || (text.length() == 0)) {
      text = urlText;
    }
    final long elapsed = System.currentTimeMillis() - hentry.getTimetstamp();
    text = text + " (" + Timing.getElapsedText(elapsed) + " ago)";
    final Action action = this.actionPool.createBookmarkNavigateAction(url);
    final JMenuItem menuItem = ComponentSource.menuItem(text, action);
    final StringBuffer toolTipText = new StringBuffer();
    toolTipText.append("<html>");
    toolTipText.append(urlText);
    final String description = binfo.getDescription();
    if ((description != null) && (description.length() != 0)) {
      toolTipText.append("<br>");
      toolTipText.append(description);
    }
    menuItem.setToolTipText(toolTipText.toString());
    bookmarksMenu.add(menuItem);
  }
}
 
Example 14
Source File: MainWindow.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private void loadStartQueueMenu(JMenu menu) {
	menu.removeAll();
	ArrayList<DownloadQueue> queues = XDMApp.getInstance().getQueueList();
	for (int i = 0; i < queues.size(); i++) {
		DownloadQueue q = queues.get(i);
		if (!q.isRunning()) {
			JMenuItem mitem = new JMenuItem(q.getName());
			mitem.setForeground(ColorResource.getLightFontColor());
			mitem.setName("START:" + q.getQueueId());
			mitem.addActionListener(this);
			menu.add(mitem);
		}
	}
}
 
Example 15
Source File: MainWindow.java    From xdm with GNU General Public License v2.0 5 votes vote down vote up
private void loadStopQueueMenu(JMenu menu) {
	menu.removeAll();
	ArrayList<DownloadQueue> queues = XDMApp.getInstance().getQueueList();
	for (int i = 0; i < queues.size(); i++) {
		DownloadQueue q = queues.get(i);
		if (q.isRunning()) {
			JMenuItem mitem = new JMenuItem(q.getName());
			mitem.setForeground(ColorResource.getLightFontColor());
			mitem.setName("STOP:" + q.getQueueId());
			mitem.addActionListener(this);
			menu.add(mitem);
		}
	}
}
 
Example 16
Source File: NewFile.java    From netbeans with Apache License 2.0 4 votes vote down vote up
@Messages({
    "LBL_NewFileAction_File_PopupName=Other...",
    "NewFile.please_wait=Please wait..."
})
private void fillSubMenu(final JMenu menuItem, final Lookup lookup) {
    menuItem.removeAll();
    JMenuItem wait = new JMenuItem(NewFile_please_wait());
    wait.setEnabled(false);
    menuItem.add(wait);
    final Pair<List<Project>, List<FileObject>> data = ActionsUtil.mineFromLookup(lookup);
    RP.post(new Runnable() {
        @Override public void run() {
            Project projects[] = ActionsUtil.getProjects(data);
            final Project project = projects.length > 0 ? projects[0] : null;
            final List<TemplateItem> items = OpenProjectList.prepareTemplates(project, getLookup());
            EventQueue.invokeLater(new Runnable() {
                @Override public void run() {
                    menuItem.removeAll();
                    ActionListener menuListener = new PopupListener();
                    for (TemplateItem i : items) {
                        JMenuItem item = new JMenuItem(
                                LBL_NewFileAction_Template_PopupName(i.displayName),
                                i.icon);
                        item.addActionListener(menuListener);
                        item.putClientProperty(TEMPLATE_PROPERTY, i.template);
                        item.putClientProperty(IN_PROJECT_PROPERTY, project != null);
                        menuItem.add(item);
                    }
                    if (!items.isEmpty()) {
                        menuItem.add(new Separator());
                    }
                    JMenuItem fileItem = new JMenuItem(LBL_NewFileAction_File_PopupName(), (Icon) getValue(Action.SMALL_ICON));
                    fileItem.addActionListener(menuListener);
                    fileItem.putClientProperty(TEMPLATE_PROPERTY, null);
                    fileItem.putClientProperty(IN_PROJECT_PROPERTY, project != null);
                    menuItem.add(fileItem);
                    // #205616 - need to refresh please wait node
                    menuItem.getPopupMenu().pack();
                }
            });
        }
    });
}
 
Example 17
Source File: DynaMenuModel.java    From netbeans with Apache License 2.0 4 votes vote down vote up
public void loadSubmenu(List<Object> cInstances, JMenu m, boolean remove, Map<Object,FileObject> cookiesToFiles) {
    // clear first - refresh the menu's content
    boolean addSeparator = false;
    Icon curIcon = null;
    Iterator it = cInstances.iterator();
    menuItems = new ArrayList<JComponent>(cInstances.size());
    actionToMenuMap.clear();
    while (it.hasNext()) {
        Object obj = it.next();
        if (obj instanceof Action) {
            FileObject file = cookiesToFiles.get(obj);
            if (file != null) {
                AcceleratorBinding.setAccelerator((Action) obj, file);
            }
        }
        if (obj instanceof Presenter.Menu) {
            // does this still apply??
            obj = ((Presenter.Menu)obj).getMenuPresenter();
        }
        if (obj instanceof DynamicMenuContent) {
            if(addSeparator) {
                menuItems.add(null);
                addSeparator = false;
            }
            DynamicMenuContent mn = (DynamicMenuContent)obj;
            JComponent[] itms = convertArray(mn.getMenuPresenters());
            actionToMenuMap.put(mn, itms);
            Iterator itx = Arrays.asList(itms).iterator();
            while (itx.hasNext()) {
                JComponent comp = (JComponent)itx.next();
                menuItems.add(comp);
                // check icon
                isWithIcons = checkIcon(comp, isWithIcons);
            }
            continue;
        } 
        
        
        if (obj instanceof JMenuItem) {
            if(addSeparator) {
                menuItems.add(null);
                addSeparator = false;
            }
            // check icon
            isWithIcons = checkIcon(obj, isWithIcons);
            menuItems.add((JMenuItem)obj);
        } else if (obj instanceof JSeparator) {
            addSeparator = menuItems.size() > 0;
        } else if (obj instanceof Action) {
            if(addSeparator) {
                menuItems.add(null);
                addSeparator = false;
            }
            Action a = (Action)obj;
            Actions.MenuItem item = new Actions.MenuItem(a, true);
            // check icon
            isWithIcons = checkIcon(item, isWithIcons);
            actionToMenuMap.put(item, new JComponent[] {item});
            menuItems.add(item);
        }
    }
    
    if (isWithIcons) {
        menuItems = alignVertically(menuItems);
    }
    
    if (remove) {
        m.removeAll();
    }
    
    // fill menu with built items
    JComponent curItem = null;
    boolean wasSeparator = false;
    for (Iterator<JComponent> iter = menuItems.iterator(); iter.hasNext(); ) {
        curItem = iter.next();
        if (curItem == null) {
            // null means separator
            curItem = createSeparator();
        }
        m.add(curItem);
        boolean isSeparator = curItem instanceof JSeparator;
        if (isSeparator && wasSeparator) {
            curItem.setVisible(false);
        }
        if (!(curItem instanceof InvisibleMenuItem)) {
            wasSeparator = isSeparator;
        }
    }
}
 
Example 18
Source File: AbstractMenuFactory.java    From netbeans with Apache License 2.0 4 votes vote down vote up
protected void depopulateMenu (String containerCtx, JMenu menu) {
    menu.removeAll();
}
 
Example 19
Source File: UI.java    From Girinoscope with Apache License 2.0 4 votes vote down vote up
private void createDynamicDeviceMenu(final JMenu girinoMenu) {
    Device selectedDevice = null;
    String deviceName = settings.get("device", null);
    for (final Device otherDevice : Device.DEVICES) {
        if (Objects.equals(deviceName, otherDevice.id)) {
            selectedDevice = otherDevice;
            break;
        }
    }

    final JMenu menu = new JMenu("Device");
    ButtonGroup group = new ButtonGroup();
    for (final Device newDevice : Device.DEVICES) {
        Action setDevice = new AbstractAction(newDevice.description) {

            @Override
            public void actionPerformed(ActionEvent event) {
                synchronized (UI.this) {
                    device = newDevice;
                    parameters = newDevice.getDefaultParameters(new EnumMap<Parameter, Integer>(Parameter.class));
                }
                graphPane.setFrameFormat(device.getFrameFormat());
                graphPane.setThreshold(parameters.get(Parameter.THRESHOLD));
                graphPane.setWaitDuration(parameters.get(Parameter.WAIT_DURATION));

                yAxisBuilder.load(settings, device.id + ".");
                graphPane.setYCoordinateSystem(yAxisBuilder.build());

                girinoMenu.removeAll();
                girinoMenu.add(menu);
                girinoMenu.add(createSerialMenu());
                if (device.isUserConfigurable(Parameter.PRESCALER)) {
                    girinoMenu.add(createPrescalerMenu(device));
                }
                if (device.isUserConfigurable(Parameter.TRIGGER_EVENT)) {
                    girinoMenu.add(createTriggerEventMenu());
                }
                if (device.isUserConfigurable(Parameter.VOLTAGE_REFERENCE)) {
                    girinoMenu.add(createVoltageReferenceMenu());
                }

                settings.put("device", device.id);
            }
        };
        AbstractButton button = new JCheckBoxMenuItem(setDevice);
        if (selectedDevice == null && device == null || newDevice == selectedDevice) {
            button.doClick();
        }

        group.add(button);

        menu.add(button);
    }
}