public void testCreatesTheItemShopMenu() { ItemShop building = new ItemShop(); building.stockItems(Item.BLOCKABALL, Item.HEALVIAL); JMenu menu = _constructor.createBuildingMenu(building, null); Assert.assertNotNull(menu); Assert.assertEquals(building.getName(), menu.getName()); Assert.assertEquals(building.getName(), menu.getText()); Assert.assertEquals(2, menu.getItemCount()); for (int i = 0; i < menu.getItemCount(); i++) { JMenuItem menuItem = menu.getItem(i); Action action = menuItem.getAction(); Assert.assertNotNull(action); Assert.assertEquals(ItemAction.class, action.getClass()); String name = menuItem.getName(); if (name.equals(Item.BLOCKABALL.toString())) { Assert.assertEquals(Item.BLOCKABALL.getWellFormattedString(), menuItem.getText()); } else if (name.equals(Item.HEALVIAL.toString())) { Assert.assertEquals(Item.HEALVIAL.getWellFormattedString(), menuItem.getText()); } else { Assert.fail("Name: " + name + " Text: " + menuItem.getText()); } } }
void windowMenu_menuSelected(MenuEvent e) { // <<TODO:MAINTAINABILITY>> This algorithm is not robust. It assumes // the Window // menu has exactly one "regular" menu item (newWindowMenuItem). [Jon // Aquino] if (windowMenu.getItemCount() > 0 && windowMenu.getItem(0) != null && windowMenu .getItem(0) .getText() .equals(AbstractPlugIn.createName(CloneWindowPlugIn.class))) { JMenuItem newWindowMenuItem = windowMenu.getItem(0); windowMenu.removeAll(); windowMenu.add(newWindowMenuItem); windowMenu.addSeparator(); } else { // ezLink doesn't have a Clone Window menu [Jon Aquino] windowMenu.removeAll(); } // final TaskComponent[] frames = (TaskComponent[]) desktopPane.getAllFrames(); final JInternalFrame[] frames = desktopPane.getAllFrames(); for (int i = 0; i < frames.length; i++) { JMenuItem menuItem = new JMenuItem(); // Increase truncation threshold from 20 to 40, for eziLink [Jon // Aquino] menuItem.setText(GUIUtil.truncateString(frames[i].getTitle(), 40)); associate(menuItem, frames[i]); windowMenu.add(menuItem); } if (windowMenu.getItemCount() == 0) { // For ezLink [Jon Aquino] windowMenu.add(new JMenuItem("(No Windows)")); } }
public void testCreatesBlockamonMenuCorrectly() { Blockamon blockamon = new Blockamon(ElementType.BUG); _player.addToParty(blockamon); JMenu menu = _constructor.createBlockamonMenu(); assertNameAndText(menu, "Blockamon", "Blockamon"); assertEquals("Number of menu items was not correct", 2, menu.getItemCount()); JMenuItem blockamonMenuItem = menu.getItem(0); assertNameAndText( blockamonMenuItem, blockamon.elementType() + "0", blockamon.name() + ", " + blockamon.level() + ", " + blockamon.currentHp() + "/" + blockamon.maxHp()); assertNotNull("Blockamon menu action not set", blockamonMenuItem.getAction()); assertEquals(BlockamonAction.class, blockamonMenuItem.getAction().getClass()); JMenuItem backItemMenu = menu.getItem(1); assertNotNull("Back item menu was not added", backItemMenu); assertEquals("Back item text was not right", "Back", backItemMenu.getText()); assertNotNull("Back action was not set", backItemMenu.getAction()); assertEquals(BackAction.class, backItemMenu.getAction().getClass()); }
public void testCreatesItemMenuWithItemsCorrectly() { _player.addItem(Item.BLOCKABALL); _player.addItem(Item.HEALVIAL); JMenu menu = _constructor.createItemMenu(); assertNameAndText(menu, "Items", "Items"); assertEquals("Number of menus was not correct", 3, menu.getItemCount()); assertAllItemsHaveNames(menu); JMenuItem blockaballItemMenu = getWithName(menu, "BLOCKABALL"); assertNotNull("Blockaball item menu was not added", blockaballItemMenu); assertEquals("Blockaball text was not right", "Blockaball", blockaballItemMenu.getText()); assertNotNull("Blockaball action was not set", blockaballItemMenu.getAction()); assertEquals(ItemAction.class, blockaballItemMenu.getAction().getClass()); JMenuItem healVialItemMenu = getWithName(menu, "HEALVIAL"); assertNotNull("HealVial item menu was not added", healVialItemMenu); assertEquals("HealVial text was not right", "Heal Vial", healVialItemMenu.getText()); assertNotNull("HealVial action was not set", healVialItemMenu.getAction()); assertEquals(ItemAction.class, healVialItemMenu.getAction().getClass()); JMenuItem backItemMenu = getWithName(menu, "Back"); assertNotNull("Back item menu was not added", backItemMenu); assertEquals("Back item text was not right", "Back", backItemMenu.getText()); assertNotNull("Back action was not set", backItemMenu.getAction()); assertEquals(BackAction.class, backItemMenu.getAction().getClass()); }
public void adjustListMenuBar() { JMenuItem menuItem; Action act; String itemLabel; boolean enableState; boolean inEditState; boolean allowAdds; ICFInternetTopProjectObj selectedObj = getSwingFocusAsTopProject(); CFJPanel.PanelMode mode = getPanelMode(); if (mode == CFJPanel.PanelMode.Edit) { inEditState = true; if (getSwingContainer() != null) { allowAdds = true; } else { allowAdds = false; } } else { inEditState = false; allowAdds = false; } if (selectedObj == null) { enableState = false; } else { enableState = true; } if (actionViewSelected != null) { actionViewSelected.setEnabled(enableState); } if (actionEditSelected != null) { actionEditSelected.setEnabled(inEditState && enableState); } if (actionDeleteSelected != null) { actionDeleteSelected.setEnabled(inEditState && enableState); } if (actionAddTopProject != null) { actionAddTopProject.setEnabled(allowAdds); } if (menuAdd != null) { menuAdd.setEnabled(allowAdds); } if (menuSelected != null) { menuSelected.setEnabled(enableState); int itemCount = menuSelected.getItemCount(); for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) { menuItem = menuSelected.getItem(itemIdx); act = menuItem.getAction(); if (act != null) { if (act == actionViewSelected) { menuItem.setEnabled(enableState); } else if (act == actionEditSelected) { menuItem.setEnabled(inEditState && enableState); } else if (act == actionDeleteSelected) { menuItem.setEnabled(inEditState && enableState); } } } } }
public void testCreatesTheHealingCenterMenu() { Building building = new HealingCenter(); JMenu menu = _constructor.createBuildingMenu(building, null); Assert.assertNotNull(menu); Assert.assertEquals(building.getName(), menu.getName()); Assert.assertEquals(building.getName(), menu.getText()); Assert.assertEquals(1, menu.getItemCount()); for (int i = 0; i < menu.getItemCount(); i++) { JMenuItem menuItem = menu.getItem(i); Action action = menuItem.getAction(); Assert.assertNotNull(action); Assert.assertEquals(HealAction.class, action.getClass()); Assert.assertEquals("Heal", menuItem.getName()); Assert.assertEquals("Heal", menuItem.getText()); } }
public void testCreatesItemMenuWithNoItemsCorrectly() { JMenu menu = _constructor.createItemMenu(); assertNameAndText(menu, "Items", "Items"); assertEquals("Number of menus was not correct", 1, menu.getItemCount()); JMenuItem backButton = menu.getItem(0); assertNameAndText(backButton, "Back", "Back"); assertNotNull("Back button was not added", backButton); assertNotNull("Back button action was not set", backButton.getAction()); assertEquals(BackAction.class, backButton.getAction().getClass()); }
public void testCreatesBattleMenu() { JMenu menu = _constructor.createBattleMenu(); assertNameAndText(menu, "Battle", "Actions"); Assert.assertEquals(4, menu.getItemCount()); assertNameAndText(menu.getItem(0), "Attack", "Attack"); assertNameAndText(menu.getItem(1), "Bag", "Bag"); assertNameAndText(menu.getItem(2), "Blockamon", "Blockamon"); assertNameAndText(menu.getItem(3), "Flee", "Flee"); }
public void testCreatesOutOfBattleMenu() { JMenu menu = _constructor.createOutOfBattleMenu(); assertNameAndText(menu, "OutOfBattle", "Actions"); Assert.assertEquals(5, menu.getItemCount()); assertNameAndText(menu.getItem(0), "Blockamon", "Blockamon"); assertNameAndText(menu.getItem(1), "Bag", "Bag"); assertNameAndText(menu.getItem(2), "Money", "Money"); JMenuItem saveMenuItem = menu.getItem(3); Action saveMenuAction = saveMenuItem.getAction(); Assert.assertNotNull(saveMenuAction); Assert.assertEquals(saveMenuAction.getClass(), SaveAction.class); assertNameAndText(saveMenuItem, "Save", "Save"); assertNameAndText(menu.getItem(4), "Load", "Load"); }
private JMenuItem getWithName(JMenu menu, String name) { int numOfItems = menu.getItemCount(); JMenuItem menuItem = null; for (int i = 0; i < numOfItems; i++) { JMenuItem item = menu.getItem(i); if (item == null) { continue; } if (item.getName() == null) { continue; } if (item.getName().equals(name)) { menuItem = item; i = numOfItems; } } return menuItem; }
public void adjustFinderMenuBar() { JMenuItem menuItem; Action act; String itemLabel; ICFSecurityServiceTypeObj selectedObj = getSwingFocusAsServiceType(); boolean enableState; if (selectedObj == null) { enableState = false; } else { enableState = true; } if (actionViewSelected != null) { actionViewSelected.setEnabled(enableState); } if (actionEditSelected != null) { actionEditSelected.setEnabled(enableState); } if (actionDeleteSelected != null) { actionDeleteSelected.setEnabled(enableState); } if (actionAddServiceType != null) { actionAddServiceType.setEnabled(true); } if (menuFile != null) { int itemCount = menuFile.getItemCount(); for (int itemIdx = 0; itemIdx < itemCount; itemIdx++) { menuItem = menuFile.getItem(itemIdx); act = menuItem.getAction(); if (act != null) { if (act == actionViewSelected) { menuItem.setEnabled(enableState); } else if (act == actionEditSelected) { menuItem.setEnabled(enableState); } else if (act == actionDeleteSelected) { menuItem.setEnabled(enableState); } else if (act == actionAddServiceType) { menuItem.setEnabled(true); } } } } }
/** * Fired by a view when the figure seleciton changes. Since Commands and Tools are Actions and * they are registered to hear these events, they will handle themselves. So selection sensitive * menuitems will update their own states. * * @see DrawingEditor */ public void figureSelectionChanged(DrawingView view) { JMenuBar mb = getJMenuBar(); CommandMenu editMenu = (CommandMenu) mb.getMenu(EDIT_MENU); // make sure it does exist if (editMenu != null) { editMenu.checkEnabled(); } CommandMenu alignmentMenu = (CommandMenu) mb.getMenu(ALIGNMENT_MENU); // make sure it does exist if (alignmentMenu != null) { alignmentMenu.checkEnabled(); } JMenu attributeMenu = mb.getMenu(ATTRIBUTES_MENU); // make sure it does exist if (attributeMenu != null) { for (int i = 0; i < attributeMenu.getItemCount(); i++) { JMenuItem currentMenu = attributeMenu.getItem(i); if (currentMenu instanceof CommandMenu) { ((CommandMenu) currentMenu).checkEnabled(); } } } }
protected JMenu buildEditMenu() { JMenu editMenu = original(); if (editMenu.getItemCount() > 0) editMenu.addSeparator(); JMenuItem findMenuItem = new JMenuItem("Find", new ImageIcon(this.getClass().getResource("images/find.gif"))); findMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_F, ActionEvent.CTRL_MASK)); findMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { actions.find(); } }); editMenu.add(findMenuItem); JMenuItem findNextMenuItem = new JMenuItem("Find Next"); findNextMenuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_G, ActionEvent.CTRL_MASK)); findNextMenuItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent ae) { actions.findNext(); } }); editMenu.add(findNextMenuItem); return editMenu; }
// {{{ update() method public void update(JMenu menu) { final View view = GUIUtilities.getView(menu); String path; if (dir == null) { path = view.getBuffer().getDirectory(); } else path = dir; JMenuItem mi = new JMenuItem(path + ':'); mi.setActionCommand(path); mi.setIcon(FileCellRenderer.openDirIcon); // {{{ ActionListeners ActionListener fileListener = new ActionListener() { public void actionPerformed(ActionEvent evt) { jEdit.openFile(view, evt.getActionCommand()); } }; ActionListener dirListener = new ActionListener() { public void actionPerformed(ActionEvent evt) { VFSBrowser.browseDirectory(view, evt.getActionCommand()); } }; // }}} mi.addActionListener(dirListener); menu.add(mi); menu.addSeparator(); if (dir == null && !(view.getBuffer().getVFS() instanceof FileVFS)) { mi = new JMenuItem(jEdit.getProperty("directory.not-local")); mi.setEnabled(false); menu.add(mi); return; } File directory = new File(path); JMenu current = menu; // for filtering out backups String backupPrefix = jEdit.getProperty("backup.prefix"); String backupSuffix = jEdit.getProperty("backup.suffix"); File[] list = directory.listFiles(); if (list == null || list.length == 0) { mi = new JMenuItem(jEdit.getProperty("directory.no-files")); mi.setEnabled(false); menu.add(mi); } else { int maxItems = jEdit.getIntegerProperty("menu.spillover", 20); Arrays.sort(list, new StandardUtilities.StringCompare<File>(true)); for (int i = 0; i < list.length; i++) { File file = list[i]; String name = file.getName(); // skip marker files if (name.endsWith(".marks")) continue; // skip autosave files if (name.startsWith("#") && name.endsWith("#")) continue; // skip backup files if ((backupPrefix.length() != 0 && name.startsWith(backupPrefix)) || (backupSuffix.length() != 0 && name.endsWith(backupSuffix))) continue; // skip directories // if(file.isDirectory()) // continue; mi = new JMenuItem(name); mi.setActionCommand(file.getPath()); mi.addActionListener(file.isDirectory() ? dirListener : fileListener); mi.setIcon(file.isDirectory() ? FileCellRenderer.dirIcon : FileCellRenderer.fileIcon); if (current.getItemCount() >= maxItems && i != list.length - 1) { // current.addSeparator(); JMenu newCurrent = new JMenu(jEdit.getProperty("common.more")); current.add(newCurrent); current = newCurrent; } current.add(mi); } } } // }}}
@Override public void run() { if (androidMode.getSDK() == null) return; final Devices devices = Devices.getInstance(); java.util.List<Device> deviceList = devices.findMultiple(false); Device selectedDevice = devices.getSelectedDevice(); if (deviceList.size() == 0) { // if (deviceMenu.getItem(0).isEnabled()) { if (0 < deviceMenu.getItemCount()) { deviceMenu.removeAll(); JMenuItem noDevicesItem = new JMenuItem("No connected devices"); noDevicesItem.setEnabled(false); deviceMenu.add(noDevicesItem); } devices.setSelectedDevice(null); } else { deviceMenu.removeAll(); if (selectedDevice == null) { selectedDevice = deviceList.get(0); devices.setSelectedDevice(selectedDevice); } else { // check if selected device is still connected boolean found = false; for (Device device : deviceList) { if (device.equals(selectedDevice)) { found = true; break; } } if (!found) { selectedDevice = deviceList.get(0); devices.setSelectedDevice(selectedDevice); } } for (final Device device : deviceList) { final JCheckBoxMenuItem deviceItem = new JCheckBoxMenuItem(device.getName()); deviceItem.setEnabled(true); if (device.equals(selectedDevice)) deviceItem.setState(true); // prevent checkboxmenuitem automatic state changing onclick deviceItem.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { if (device.equals(devices.getSelectedDevice())) deviceItem.setState(true); else deviceItem.setState(false); } }); deviceItem.addActionListener( new ActionListener() { @Override public void actionPerformed(ActionEvent e) { devices.setSelectedDevice(device); for (int i = 0; i < deviceMenu.getItemCount(); i++) { ((JCheckBoxMenuItem) deviceMenu.getItem(i)).setState(false); } deviceItem.setState(true); } }); deviceMenu.add(deviceItem); } } }
public int getItemCount() { return jMenu.getItemCount(); }
private void assertAllItemsHaveNames(JMenu menu) { for (int i = 0; i < menu.getItemCount(); i++) { assertNotNull("Item at position " + i + " did not have a name", menu.getItem(i).getName()); } }
/** * Returns a menu with items that control this track. * * @param trackerPanel the tracker panel * @return a menu */ public JMenu getMenu(TrackerPanel trackerPanel) { if (inspectorItem == null) { // create the model inspector item inspectorItem = new JMenuItem(); inspectorItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { positionInspector(); getInspector().setVisible(true); } }); // create the useDefaultRefFrameItem item useDefaultRefFrameItem = new JCheckBoxMenuItem(); useDefaultRefFrameItem.setSelected(!useDefaultReferenceFrame); useDefaultRefFrameItem.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { setUseDefaultReferenceFrame(!useDefaultRefFrameItem.isSelected()); if (ParticleModel.this.trackerPanel.getCoords() instanceof ReferenceFrame) { lastValidFrame = -1; refreshSteps(); } } }); } inspectorItem.setText( TrackerRes.getString("ParticleModel.MenuItem.InspectModel")); // $NON-NLS-1$ useDefaultRefFrameItem.setText( TrackerRes.getString("ParticleModel.MenuItem.UseDefaultReferenceFrame")); // $NON-NLS-1$ // assemble the menu JMenu menu = super.getMenu(trackerPanel); // remove unwanted menu items and separators menu.remove(autotrackItem); menu.remove(deleteStepItem); menu.remove(clearStepsItem); menu.remove(lockedItem); menu.remove(autoAdvanceItem); menu.remove(markByDefaultItem); menu.insert(inspectorItem, 0); if (menu.getItemCount() > 1) menu.insertSeparator(1); // // find visible item and insert useDefaultRefFrameItem after it // for (int i=0; i<menu.getMenuComponentCount(); i++) { // if (menu.getMenuComponent(i)==visibleItem) { // menu.insert(useDefaultRefFrameItem, i+1); // break; // } // } // eliminate any double separators Object prevItem = inspectorItem; int n = menu.getItemCount(); for (int j = 1; j < n; j++) { Object item = menu.getItem(j); if (item == null && prevItem == null) { // found extra separator menu.remove(j - 1); j = j - 1; n = n - 1; } prevItem = item; } return menu; }