@Test public void testSetGetName() { Menu testMenu = new Menu(12345); testMenu.setName("Denny's Menu"); assertEquals("Denny's Menu", testMenu.getName()); }
@Test public void toJson() { Button menuButton = new Button(new ArrayList<Menu>()); Menu menu1 = new Menu(); menu1.setType(Constants.EVENT_CLICK); menu1.setName("今日歌曲"); menu1.setKey("V1001_TODAY_MUSIC"); menuButton.addMenu(menu1); Menu menu2 = new Menu(); menu2.setType(Constants.EVENT_CLICK); menu2.setName("歌手简介"); menu2.setKey("V1001_TODAY_SINGER"); menuButton.addMenu(menu2); Menu menu3 = new Menu(); menu3.setName("歌手简介"); List<Menu> subs = Lists.newArrayList(); menu3.setSub_button(subs); Menu sub1 = new Menu(); sub1.setType(Constants.EVENT_VIEW); sub1.setName("搜索"); sub1.setUrl("http://www.soso.com/"); subs.add(sub1); Menu sub2 = new Menu(); sub2.setType(Constants.EVENT_VIEW); sub2.setName("视频"); sub2.setUrl("http://v.qq.com/"); subs.add(sub2); Menu sub3 = new Menu(); sub3.setType(Constants.EVENT_CLICK); sub3.setName("赞一下我们"); sub3.setKey("V1001_GOOD"); subs.add(sub3); menuButton.addMenu(menu3); String json = JSON.toJSONString(menuButton); System.out.println(json); }
void install() { subMenus.clear(); if (text != null) { Tokenizer tok = new Tokenizer(); pgm = tok.tokenize(text); } if (macrosMenu != null) IJ.showStatus(""); int[] code = pgm.getCode(); Symbol[] symbolTable = pgm.getSymbolTable(); int count = 0, token, nextToken, address; String name; Symbol symbol; shortcutsInUse = null; inUseCount = 0; nShortcuts = 0; toolCount = 0; macroStarts = new int[MAX_MACROS]; macroNames = new String[MAX_MACROS]; boolean isPluginsMacrosMenu = false; if (macrosMenu != null) { int itemCount = macrosMenu.getItemCount(); isPluginsMacrosMenu = macrosMenu == Menus.getMacrosMenu(); int baseCount = isPluginsMacrosMenu ? MACROS_MENU_COMMANDS : Editor.MACROS_MENU_ITEMS; if (itemCount > baseCount) { for (int i = itemCount - 1; i >= baseCount; i--) macrosMenu.remove(i); } } if (pgm.hasVars() && pgm.macroCount() > 0 && pgm.getGlobals() == null) new Interpreter().saveGlobals(pgm); ArrayList tools = new ArrayList(); for (int i = 0; i < code.length; i++) { token = code[i] & TOK_MASK; if (token == MACRO) { nextToken = code[i + 1] & TOK_MASK; if (nextToken == STRING_CONSTANT) { if (count == MAX_MACROS) { if (isPluginsMacrosMenu) IJ.error("Macro Installer", "Macro sets are limited to " + MAX_MACROS + " macros."); break; } address = code[i + 1] >> TOK_SHIFT; symbol = symbolTable[address]; name = symbol.str; macroStarts[count] = i + 2; macroNames[count] = name; if (name.indexOf('-') != -1 && (name.indexOf("Tool") != -1 || name.indexOf("tool") != -1)) { tools.add(name); toolCount++; } else if (name.startsWith("AutoRun")) { if (autoRunCount == 0 && !openingStartupMacrosInEditor) { new MacroRunner(pgm, macroStarts[count], name, (String) null); if (name.equals("AutoRunAndHide")) autoRunAndHideCount++; } autoRunCount++; count--; } else if (name.equals("Popup Menu")) installPopupMenu(name, pgm); else if (!name.endsWith("Tool Selected")) { if (macrosMenu != null) { addShortcut(name); int pos = name.indexOf(">"); boolean inSubMenu = name.startsWith("<") && (pos > 1); if (inSubMenu) { Menu parent = macrosMenu; Menu subMenu = null; String parentStr = name.substring(1, pos).trim(); String childStr = name.substring(pos + 1).trim(); MenuItem mnuItem = new MenuItem(); mnuItem.setActionCommand(name); mnuItem.setLabel(childStr); for (int jj = 0; jj < subMenus.size(); jj++) { String aName = subMenus.get(jj).getName(); if (aName.equals(parentStr)) subMenu = subMenus.get(jj); } if (subMenu == null) { subMenu = new Menu(parentStr); subMenu.setName(parentStr); subMenu.addActionListener(this); subMenus.add(subMenu); parent.add(subMenu); } subMenu.add(mnuItem); } else macrosMenu.add(new MenuItem(name)); } } // IJ.log(count+" "+name+" "+macroStarts[count]); count++; } } else if (token == EOF) break; } nMacros = count; if (toolCount > 0 && (isPluginsMacrosMenu || macrosMenu == null) && installTools) { Toolbar tb = Toolbar.getInstance(); if (toolCount == 1) tb.addMacroTool((String) tools.get(0), this); else { for (int i = 0; i < tools.size(); i++) { String toolName = (String) tools.get(i); if (toolName.startsWith("Abort Macro or Plugin") && toolCount > 6) toolName = "Unused " + toolName; tb.addMacroTool(toolName, this, i); } } if (toolCount > 1 && Toolbar.getToolId() >= Toolbar.CUSTOM1) tb.setTool(Toolbar.RECTANGLE); tb.repaint(); } if (macrosMenu != null) this.instance = this; if (shortcutsInUse != null && text != null) IJ.showMessage( "Install Macros", (inUseCount == 1 ? "This keyboard shortcut is" : "These keyboard shortcuts are") + " already in use:" + shortcutsInUse); if (nMacros == 0 && fileName != null) { if (text == null || text.length() == 0) return; int dotIndex = fileName.lastIndexOf('.'); if (dotIndex > 0) anonymousName = fileName.substring(0, dotIndex); else anonymousName = fileName; if (macrosMenu != null) macrosMenu.add(new MenuItem(anonymousName)); macroNames[0] = anonymousName; nMacros = 1; } String word = nMacros == 1 ? " macro" : " macros"; if (isPluginsMacrosMenu) IJ.showStatus(nMacros + word + " installed"); }