示例#1
0
 public Point getPreferredLocation() {
   Rectangle maxBounds = GUI.getMaxWindowBounds();
   int ijX = Prefs.getInt(IJ_X, -99);
   int ijY = Prefs.getInt(IJ_Y, -99);
   if (ijX >= maxBounds.x && ijY >= maxBounds.y && ijX < (maxBounds.x + maxBounds.width - 75))
     return new Point(ijX, ijY);
   Dimension tbsize = toolbar.getPreferredSize();
   int ijWidth = tbsize.width + 10;
   double percent = maxBounds.width > 832 ? 0.8 : 0.9;
   ijX = (int) (percent * (maxBounds.width - ijWidth));
   if (ijX < 10) ijX = 10;
   return new Point(ijX, maxBounds.y);
 }
示例#2
0
 public Point getPreferredLocation() {
   if (!IJ.isJava14()) return new Point(0, 0);
   GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
   Rectangle maxBounds = ge.getMaximumWindowBounds();
   int ijX = Prefs.getInt(IJ_X, -99);
   int ijY = Prefs.getInt(IJ_Y, -99);
   if (ijX >= 0 && ijY > 0 && ijX < (maxBounds.x + maxBounds.width - 75))
     return new Point(ijX, ijY);
   Dimension tbsize = toolbar.getPreferredSize();
   int ijWidth = tbsize.width + 10;
   double percent = maxBounds.width > 832 ? 0.8 : 0.9;
   ijX = (int) (percent * (maxBounds.width - ijWidth));
   if (ijX < 10) ijX = 10;
   return new Point(ijX, maxBounds.y);
 }
示例#3
0
 void configureProxy() {
   if (Prefs.useSystemProxies) {
     try {
       System.setProperty("java.net.useSystemProxies", "true");
     } catch (Exception e) {
     }
   } else {
     String server = Prefs.get("proxy.server", null);
     if (server == null || server.equals("")) return;
     int port = (int) Prefs.get("proxy.port", 0);
     if (port == 0) return;
     Properties props = System.getProperties();
     props.put("proxySet", "true");
     props.put("http.proxyHost", server);
     props.put("http.proxyPort", "" + port);
   }
   // new ProxySettings().logProperties();
 }
示例#4
0
 /** Quit using a separate thread, hopefully avoiding thread deadlocks. */
 public void run() {
   quitting = true;
   boolean changes = false;
   int[] wList = WindowManager.getIDList();
   if (wList != null) {
     for (int i = 0; i < wList.length; i++) {
       ImagePlus imp = WindowManager.getImage(wList[i]);
       if (imp != null && imp.changes == true) {
         changes = true;
         break;
       }
     }
   }
   Frame[] frames = WindowManager.getNonImageWindows();
   if (frames != null) {
     for (int i = 0; i < frames.length; i++) {
       if (frames[i] != null && (frames[i] instanceof Editor)) {
         if (((Editor) frames[i]).fileChanged()) {
           changes = true;
           break;
         }
       }
     }
   }
   if (windowClosed
       && !changes
       && Menus.window.getItemCount() > Menus.WINDOW_MENU_ITEMS
       && !(IJ.macroRunning() && WindowManager.getImageCount() == 0)) {
     GenericDialog gd = new GenericDialog("ImageJ", this);
     gd.addMessage("Are you sure you want to quit ImageJ?");
     gd.showDialog();
     quitting = !gd.wasCanceled();
     windowClosed = false;
   }
   if (!quitting) return;
   if (!WindowManager.closeAllWindows()) {
     quitting = false;
     return;
   }
   // IJ.log("savePreferences");
   if (applet == null) {
     saveWindowLocations();
     Prefs.savePreferences();
   }
   IJ.cleanup();
   // setVisible(false);
   // IJ.log("dispose");
   dispose();
   if (exitWhenQuitting) System.exit(0);
 }
示例#5
0
 private void loadCursors() {
   Toolkit toolkit = Toolkit.getDefaultToolkit();
   String path = Prefs.getImageJDir() + "images/crosshair-cursor.gif";
   File f = new File(path);
   if (!f.exists()) return;
   // Image image = toolkit.getImage(path);
   ImageIcon icon = new ImageIcon(path);
   Image image = icon.getImage();
   if (image == null) return;
   int width = icon.getIconWidth();
   int height = icon.getIconHeight();
   Point hotSpot = new Point(width / 2, height / 2);
   Cursor crosshairCursor = toolkit.createCustomCursor(image, hotSpot, "crosshair-cursor.gif");
   ImageCanvas.setCursor(crosshairCursor, 0);
 }
示例#6
0
 void saveWindowLocations() {
   Window win = WindowManager.getWindow("B&C");
   if (win != null) Prefs.saveLocation(ContrastAdjuster.LOC_KEY, win.getLocation());
   win = WindowManager.getWindow("Threshold");
   if (win != null) Prefs.saveLocation(ThresholdAdjuster.LOC_KEY, win.getLocation());
   win = WindowManager.getWindow("Results");
   if (win != null) {
     Prefs.saveLocation(TextWindow.LOC_KEY, win.getLocation());
     Dimension d = win.getSize();
     Prefs.set(TextWindow.WIDTH_KEY, d.width);
     Prefs.set(TextWindow.HEIGHT_KEY, d.height);
   }
   win = WindowManager.getWindow("Log");
   if (win != null) {
     Prefs.saveLocation(TextWindow.LOG_LOC_KEY, win.getLocation());
     Dimension d = win.getSize();
     Prefs.set(TextWindow.LOG_WIDTH_KEY, d.width);
     Prefs.set(TextWindow.LOG_HEIGHT_KEY, d.height);
   }
   win = WindowManager.getWindow("ROI Manager");
   if (win != null) Prefs.saveLocation(RoiManager.LOC_KEY, win.getLocation());
 }
示例#7
0
 void saveWindowLocations() {
   Frame frame = WindowManager.getFrame("B&C");
   if (frame != null) Prefs.saveLocation(ContrastAdjuster.LOC_KEY, frame.getLocation());
   frame = WindowManager.getFrame("Threshold");
   if (frame != null) Prefs.saveLocation(ThresholdAdjuster.LOC_KEY, frame.getLocation());
   frame = WindowManager.getFrame("Results");
   if (frame != null) {
     Prefs.saveLocation(TextWindow.LOC_KEY, frame.getLocation());
     Dimension d = frame.getSize();
     Prefs.set(TextWindow.WIDTH_KEY, d.width);
     Prefs.set(TextWindow.HEIGHT_KEY, d.height);
   }
   frame = WindowManager.getFrame("Log");
   if (frame != null) {
     Prefs.saveLocation(TextWindow.LOG_LOC_KEY, frame.getLocation());
     Dimension d = frame.getSize();
     Prefs.set(TextWindow.LOG_WIDTH_KEY, d.width);
     Prefs.set(TextWindow.LOG_HEIGHT_KEY, d.height);
   }
 }
示例#8
0
 public void run(String arg) {
   if (arg.equals("menus")) {
     updateMenus();
     return;
   }
   if (IJ.getApplet() != null) return;
   URL url = getClass().getResource("/ij/IJ.class");
   String ij_jar = url == null ? null : url.toString().replaceAll("%20", " ");
   if (ij_jar == null || !ij_jar.startsWith("jar:file:")) {
     error("Could not determine location of ij.jar");
     return;
   }
   int exclamation = ij_jar.indexOf('!');
   ij_jar = ij_jar.substring(9, exclamation);
   if (IJ.debugMode) IJ.log("Updater (jar loc): " + ij_jar);
   File file = new File(ij_jar);
   if (!file.exists()) {
     error("File not found: " + file.getPath());
     return;
   }
   if (!file.canWrite()) {
     String msg = "No write access: " + file.getPath();
     error(msg);
     return;
   }
   String[] list = openUrlAsList(IJ.URL + "/download/jars/list.txt");
   int count = list.length + 3;
   String[] versions = new String[count];
   String[] urls = new String[count];
   String uv = getUpgradeVersion();
   if (uv == null) return;
   versions[0] = "v" + uv;
   urls[0] = IJ.URL + "/upgrade/ij.jar";
   if (versions[0] == null) return;
   for (int i = 1; i < count - 2; i++) {
     String version = list[i - 1];
     versions[i] = version.substring(0, version.length() - 1); // remove letter
     urls[i] =
         IJ.URL + "/download/jars/ij" + version.substring(1, 2) + version.substring(3, 6) + ".jar";
   }
   versions[count - 2] = "daily build";
   urls[count - 2] = IJ.URL + "/ij.jar";
   versions[count - 1] = "previous";
   urls[count - 1] = IJ.URL + "/upgrade/ij2.jar";
   int choice = showDialog(versions);
   if (choice == -1 || !Commands.closeAll()) return;
   // System.out.println("choice: "+choice);
   // for (int i=0; i<urls.length; i++) System.out.println("  "+i+" "+urls[i]);
   byte[] jar = null;
   if ("daily build".equals(versions[choice]) && notes != null && notes.contains(" </title>"))
     jar = getJar("http://wsr.imagej.net/download/daily-build/ij.jar");
   if (jar == null) jar = getJar(urls[choice]);
   if (jar == null) {
     error("Unable to download ij.jar from " + urls[choice]);
     return;
   }
   Prefs.savePreferences();
   // System.out.println("saveJar: "+file);
   saveJar(file, jar);
   if (choice < count - 2) // force macro Function Finder to download fresh list
   new File(IJ.getDirectory("macros") + "functions.html").delete();
   System.exit(0);
 }
示例#9
0
 public void run(String arg) {
   if (arg.equals("menus")) {
     updateMenus();
     return;
   }
   if (IJ.getApplet() != null) return;
   // File file = new File(Prefs.getHomeDir() + File.separator + "ij.jar");
   // if (isMac() && !file.exists())
   //	file = new File(Prefs.getHomeDir() + File.separator +
   // "ImageJ.app/Contents/Resources/Java/ij.jar");
   URL url = getClass().getResource("/ij/IJ.class");
   String ij_jar = url == null ? null : url.toString().replaceAll("%20", " ");
   if (ij_jar == null || !ij_jar.startsWith("jar:file:")) {
     error("Could not determine location of ij.jar");
     return;
   }
   int exclamation = ij_jar.indexOf('!');
   ij_jar = ij_jar.substring(9, exclamation);
   if (IJ.debugMode) IJ.log("Updater: " + ij_jar);
   File file = new File(ij_jar);
   if (!file.exists()) {
     error("File not found: " + file.getPath());
     return;
   }
   if (!file.canWrite()) {
     String msg = "No write access: " + file.getPath();
     if (IJ.isVista()) msg += Prefs.vistaHint;
     error(msg);
     return;
   }
   String[] list = openUrlAsList(IJ.URL + "/download/jars/list.txt");
   int count = list.length + 2;
   String[] versions = new String[count];
   String[] urls = new String[count];
   String uv = getUpgradeVersion();
   if (uv == null) return;
   versions[0] = "v" + uv;
   urls[0] = IJ.URL + "/upgrade/ij.jar";
   if (versions[0] == null) return;
   for (int i = 1; i < count - 1; i++) {
     String version = list[i - 1];
     versions[i] = version.substring(0, version.length() - 1); // remove letter
     urls[i] =
         IJ.URL + "/download/jars/ij" + version.substring(1, 2) + version.substring(3, 6) + ".jar";
   }
   versions[count - 1] = "daily build";
   urls[count - 1] = IJ.URL + "/ij.jar";
   int choice = showDialog(versions);
   if (choice == -1) return;
   if (!versions[choice].startsWith("daily")
       && versions[choice].compareTo("v1.39") < 0
       && Menus.getCommands().get("ImageJ Updater") == null) {
     String msg =
         "This command is not available in versions of ImageJ prior\n"
             + "to 1.39 so you will need to install the plugin version at\n"
             + "<"
             + IJ.URL
             + "/plugins/imagej-updater.html>.";
     if (!IJ.showMessageWithCancel("Update ImageJ", msg)) return;
   }
   byte[] jar = getJar(urls[choice]);
   // file.renameTo(new File(file.getParent()+File.separator+"ij.bak"));
   if (version().compareTo("1.37v") >= 0) Prefs.savePreferences();
   // if (!renameJar(file)) return; // doesn't work on Vista
   saveJar(file, jar);
   if (choice < count - 1) // force macro Function Finder to download fresh list
   new File(IJ.getDirectory("macros") + "functions.html").delete();
   System.exit(0);
 }
示例#10
0
 public static void main(String args[]) {
   if (System.getProperty("java.version").substring(0, 3).compareTo("1.5") < 0) {
     javax.swing.JOptionPane.showMessageDialog(
         null, "ImageJ " + VERSION + " requires Java 1.5 or later.");
     System.exit(0);
   }
   boolean noGUI = false;
   int mode = STANDALONE;
   arguments = args;
   // System.setProperty("file.encoding", "UTF-8");
   int nArgs = args != null ? args.length : 0;
   boolean commandLine = false;
   for (int i = 0; i < nArgs; i++) {
     String arg = args[i];
     if (arg == null) continue;
     if (args[i].startsWith("-")) {
       if (args[i].startsWith("-batch")) noGUI = true;
       else if (args[i].startsWith("-debug")) IJ.setDebugMode(true);
       else if (args[i].startsWith("-ijpath") && i + 1 < nArgs) {
         if (IJ.debugMode) IJ.log("-ijpath: " + args[i + 1]);
         Prefs.setHomeDir(args[i + 1]);
         commandLine = true;
         args[i + 1] = null;
       } else if (args[i].startsWith("-port")) {
         int delta = (int) Tools.parseDouble(args[i].substring(5, args[i].length()), 0.0);
         commandLine = true;
         if (delta == 0) mode = EMBEDDED;
         else if (delta > 0 && DEFAULT_PORT + delta < 65536) port = DEFAULT_PORT + delta;
       }
     }
   }
   // If existing ImageJ instance, pass arguments to it and quit.
   boolean passArgs = mode == STANDALONE && !noGUI;
   if (IJ.isMacOSX() && !commandLine) passArgs = false;
   if (passArgs && isRunning(args)) return;
   ImageJ ij = IJ.getInstance();
   if (!noGUI && (ij == null || (ij != null && !ij.isShowing()))) {
     ij = new ImageJ(null, mode);
     ij.exitWhenQuitting = true;
   }
   int macros = 0;
   for (int i = 0; i < nArgs; i++) {
     String arg = args[i];
     if (arg == null) continue;
     if (arg.startsWith("-")) {
       if ((arg.startsWith("-macro") || arg.startsWith("-batch")) && i + 1 < nArgs) {
         String arg2 = i + 2 < nArgs ? args[i + 2] : null;
         Prefs.commandLineMacro = true;
         if (noGUI && args[i + 1].endsWith(".js")) Interpreter.batchMode = true;
         IJ.runMacroFile(args[i + 1], arg2);
         break;
       } else if (arg.startsWith("-eval") && i + 1 < nArgs) {
         String rtn = IJ.runMacro(args[i + 1]);
         if (rtn != null) System.out.print(rtn);
         args[i + 1] = null;
       } else if (arg.startsWith("-run") && i + 1 < nArgs) {
         IJ.run(args[i + 1]);
         args[i + 1] = null;
       }
     } else if (macros == 0 && (arg.endsWith(".ijm") || arg.endsWith(".txt"))) {
       IJ.runMacroFile(arg);
       macros++;
     } else if (arg.length() > 0 && arg.indexOf("ij.ImageJ") == -1) {
       File file = new File(arg);
       IJ.open(file.getAbsolutePath());
     }
   }
   if (IJ.debugMode && IJ.getInstance() == null) new JavaProperties().run("");
   if (noGUI) System.exit(0);
 }
示例#11
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();
  }
示例#12
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();
  }