Ejemplo n.º 1
0
  /**
   * If 'applet' is not null, creates a new ImageJ frame that runs as an applet. If 'mode' is
   * ImageJ.EMBEDDED and 'applet is null, creates an embedded (non-standalone) version of ImageJ.
   */
  public ImageJ(java.applet.Applet applet, int mode) {
    super("ImageJ");
    embedded = applet == null && (mode == EMBEDDED || mode == NO_SHOW);
    this.applet = applet;
    String err1 = Prefs.load(this, applet);
    if (IJ.isLinux()) {
      backgroundColor = new Color(240, 240, 240);
      setBackground(backgroundColor);
    }
    Menus m = new Menus(this, applet);
    String err2 = m.addMenuBar();
    m.installPopupMenu(this);
    setLayout(new GridLayout(2, 1));

    // Tool bar
    toolbar = new Toolbar();
    toolbar.addKeyListener(this);
    add(toolbar);

    // Status bar
    statusBar = new Panel();
    statusBar.setLayout(new BorderLayout());
    statusBar.setForeground(Color.black);
    statusBar.setBackground(backgroundColor);
    statusLine = new Label();
    statusLine.setFont(SansSerif12);
    statusLine.addKeyListener(this);
    statusLine.addMouseListener(this);
    statusBar.add("Center", statusLine);
    progressBar = new ProgressBar(120, 20);
    progressBar.addKeyListener(this);
    progressBar.addMouseListener(this);
    statusBar.add("East", progressBar);
    statusBar.setSize(toolbar.getPreferredSize());
    add(statusBar);

    IJ.init(this, applet);
    addKeyListener(this);
    addWindowListener(this);
    setFocusTraversalKeysEnabled(false);

    Point loc = getPreferredLocation();
    Dimension tbSize = toolbar.getPreferredSize();
    int ijWidth = tbSize.width + 10;
    int ijHeight = 100;
    setCursor(Cursor.getDefaultCursor()); // work-around for JDK 1.1.8 bug
    if (mode != NO_SHOW) {
      if (IJ.isWindows())
        try {
          setIcon();
        } catch (Exception e) {
        }
      setBounds(loc.x, loc.y, ijWidth, ijHeight); // needed for pack to work
      setLocation(loc.x, loc.y);
      pack();
      setResizable(!(IJ.isMacintosh() || IJ.isWindows())); // make resizable on Linux
      show();
    }
    if (err1 != null) IJ.error(err1);
    if (err2 != null) {
      IJ.error(err2);
      IJ.runPlugIn("ij.plugin.ClassChecker", "");
    }
    m.installStartupMacroSet();
    if (IJ.isMacintosh() && applet == null) {
      Object qh = null;
      qh = IJ.runPlugIn("MacAdapter", "");
      if (qh == null) IJ.runPlugIn("QuitHandler", "");
    }
    if (applet == null) IJ.runPlugIn("ij.plugin.DragAndDrop", "");
    String str = m.getMacroCount() == 1 ? " macro" : " macros";
    IJ.showStatus(version() + m.getPluginCount() + " commands; " + m.getMacroCount() + str);
    // if (applet==null && !embedded && Prefs.runSocketListener)
    //	new SocketListener();
    configureProxy();
    if (applet == null) loadCursors();
  }
Ejemplo n.º 2
0
  /**
   * If 'applet' is not null, creates a new ImageJ frame that runs as an applet. If 'mode' is
   * ImageJ.EMBEDDED and 'applet is null, creates an embedded (non-standalone) version of ImageJ.
   */
  public ImageJ(java.applet.Applet applet, int mode) {
    super("ImageJ");
    if ((mode & DEBUG) != 0) IJ.setDebugMode(true);
    mode = mode & 255;
    if (IJ.debugMode) IJ.log("ImageJ starting in debug mode: " + mode);
    embedded = applet == null && (mode == EMBEDDED || mode == NO_SHOW);
    this.applet = applet;
    String err1 = Prefs.load(this, applet);
    setBackground(backgroundColor);
    Menus m = new Menus(this, applet);
    String err2 = m.addMenuBar();
    m.installPopupMenu(this);
    setLayout(new BorderLayout());

    // Tool bar
    toolbar = new Toolbar();
    toolbar.addKeyListener(this);
    add("Center", toolbar);

    // Status bar
    statusBar = new Panel();
    statusBar.setLayout(new BorderLayout());
    statusBar.setForeground(Color.black);
    statusBar.setBackground(backgroundColor);
    statusLine = new JLabel();
    statusLine.setFont(new Font("SansSerif", Font.PLAIN, 13));
    statusLine.addKeyListener(this);
    statusLine.addMouseListener(this);
    statusBar.add("Center", statusLine);
    progressBar = new ProgressBar(120, 20);
    progressBar.addKeyListener(this);
    progressBar.addMouseListener(this);
    statusBar.add("East", progressBar);
    add("South", statusBar);

    IJ.init(this, applet);
    addKeyListener(this);
    addWindowListener(this);
    setFocusTraversalKeysEnabled(false);
    m.installStartupMacroSet(); // add custom tools
    runStartupMacro();

    Point loc = getPreferredLocation();
    Dimension tbSize = toolbar.getPreferredSize();
    setCursor(Cursor.getDefaultCursor()); // work-around for JDK 1.1.8 bug
    if (mode != NO_SHOW) {
      if (IJ.isWindows())
        try {
          setIcon();
        } catch (Exception e) {
        }
      setLocation(loc.x, loc.y);
      setResizable(!IJ.isMacOSX());
      pack();
      setVisible(true);
    }
    if (err1 != null) IJ.error(err1);
    if (err2 != null) {
      IJ.error(err2);
      IJ.runPlugIn("ij.plugin.ClassChecker", "");
    }
    if (IJ.isMacintosh() && applet == null) {
      Object qh = null;
      qh = IJ.runPlugIn("MacAdapter", "");
      if (qh == null) IJ.runPlugIn("QuitHandler", "");
    }
    if (applet == null) IJ.runPlugIn("ij.plugin.DragAndDrop", "");
    String str = m.getMacroCount() == 1 ? " macro" : " macros";
    IJ.showStatus(version() + m.getPluginCount() + " commands; " + m.getMacroCount() + str);
    configureProxy();
    if (applet == null) loadCursors();
  }
Ejemplo n.º 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;
 }