コード例 #1
0
 void updateMenus() {
   if (IJ.debugMode) {
     long start = System.currentTimeMillis();
     Menus.updateImageJMenus();
     IJ.log("Refresh Menus: " + (System.currentTimeMillis() - start) + " ms");
   } else Menus.updateImageJMenus();
 }
コード例 #2
0
ファイル: User_Plugins.java プロジェクト: hgrecco/fiji
  /** 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();
  }
コード例 #3
0
 public boolean install(String path) {
   boolean isURL = path.contains("://");
   String lcPath = path.toLowerCase();
   if (isURL) path = Opener.updateUrl(path);
   boolean isTool =
       lcPath.endsWith("tool.ijm")
           || lcPath.endsWith("tool.txt")
           || lcPath.endsWith("tool.class")
           || lcPath.endsWith("tool.jar");
   boolean isMacro = lcPath.endsWith(".txt") || lcPath.endsWith(".ijm");
   byte[] data = null;
   String name = path;
   if (isURL) {
     int index = path.lastIndexOf("/");
     if (index != -1 && index <= path.length() - 1) name = path.substring(index + 1);
     data = download(path, name);
   } else {
     File f = new File(path);
     name = f.getName();
     data = download(f);
   }
   if (data == null) return false;
   if (name.endsWith(".txt") && !name.contains("_"))
     name = name.substring(0, name.length() - 4) + ".ijm";
   if (name.endsWith(".zip")) {
     if (!name.contains("_")) {
       IJ.error("Plugin Installer", "No underscore in file name:\n \n  " + name);
       return false;
     }
     name = name.substring(0, name.length() - 4) + ".jar";
   }
   String dir = null;
   boolean isLibrary = name.endsWith(".jar") && !name.contains("_");
   if (isLibrary) {
     dir = Menus.getPlugInsPath() + "jars";
     File f = new File(dir);
     if (!f.exists()) {
       boolean ok = f.mkdir();
       if (!ok) dir = Menus.getPlugInsPath();
     }
   }
   if (isTool) {
     dir = Menus.getPlugInsPath() + "Tools" + File.separator;
     File f = new File(dir);
     if (!f.exists()) {
       boolean ok = f.mkdir();
       if (!ok) dir = null;
     }
     if (dir != null && isMacro) {
       String name2 = getToolName(data);
       if (name2 != null) name = name2;
     }
   }
   if (dir == null) {
     SaveDialog sd =
         new SaveDialog("Save Plugin, Macro or Script...", Menus.getPlugInsPath(), name, null);
     String name2 = sd.getFileName();
     if (name2 == null) return false;
     dir = sd.getDirectory();
   }
   // IJ.log(dir+"   "+Menus.getPlugInsPath());
   if (!savePlugin(new File(dir, name), data)) return false;
   if (name.endsWith(".java")) IJ.runPlugIn("ij.plugin.Compiler", dir + name);
   Menus.updateImageJMenus();
   if (isTool) {
     if (isMacro) IJ.runPlugIn("ij.plugin.Macro_Runner", "Tools/" + name);
     else if (name.endsWith(".class")) {
       name = name.replaceAll("_", " ");
       name = name.substring(0, name.length() - 6);
       IJ.run(name);
     }
   }
   return true;
 }