public void actionPerformed(ActionEvent arg0) {

    if (form.getFrame().isVisible()) {
      form.getFrame().setVisible(false);
      putValue(Action.NAME, SHOW_NAME);
      putValue(SHORT_DESCRIPTION, SHOW_DESC);
      putValue(SMALL_ICON, SHOW_ICON);
      menuItem.setLabel(SHOW_NAME);
    } else {
      form.getFrame().setVisible(true);
      putValue(Action.NAME, HIDE_NAME);
      putValue(SHORT_DESCRIPTION, HIDE_DESC);
      putValue(SMALL_ICON, HIDE_ICON);
      menuItem.setLabel(HIDE_NAME);
    }
  }
예제 #2
0
파일: MacTray.java 프로젝트: ufoe/desktop
  @Override
  public void updateStatusText() {

    UpdateStatusTextRequest menu = new UpdateStatusTextRequest(processesText);
    synchronized (itemStatus) {
      itemStatus.setLabel(menu.getStatusText());
    }
  }
예제 #3
0
  /** Install the plugins now */
  public void run(String arg) {
    if ("update".equals(arg)) {
      Menus.updateImageJMenus();
      ClassLoader loader = IJ.getClassLoader();
      if (loader != null && (loader instanceof FijiClassLoader)) return;
    }
    FijiClassLoader classLoader = new FijiClassLoader(true);
    try {
      classLoader.addPath(path);
    } catch (IOException e) {
    }

    try {
      // IJ.setClassLoader(classLoader);
      Class ij = Class.forName("ij.IJ");
      java.lang.reflect.Method method =
          ij.getDeclaredMethod("setClassLoader", new Class[] {ClassLoader.class});
      method.setAccessible(true);
      method.invoke(null, new Object[] {classLoader});
    } catch (Exception e) {
      e.printStackTrace();
    }

    installScripts();
    installPlugins(path, ".", menuPath);
    /* make sure "Update Menus" runs _this_ plugin */
    Menus.getCommands().put("Update Menus", "fiji.User_Plugins(\"update\")");
    Menus.getCommands().put("Refresh Menus", "fiji.User_Plugins(\"update\")");
    Menus.getCommands().put("Compile and Run...", "fiji.Compile_and_Run");
    if (IJ.getInstance() != null) {
      Menu help = Menus.getMenuBar().getHelpMenu();
      for (int i = help.getItemCount() - 1; i >= 0; i--) {
        MenuItem item = help.getItem(i);
        String name = item.getLabel();
        if (name.equals("Update Menus")) item.setLabel("Refresh Menus");
      }
    }

    // make sure "Edit>Options>Memory & Threads runs Fiji's plugin
    Menus.getCommands().put("Memory & Threads...", "fiji.Memory");

    SampleImageLoader.install();
    Main.installRecentCommands();
  }
 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");
 }