Commit c7a17c9d authored by Andreas Tille's avatar Andreas Tille
Browse files

New upstream version 1.52r

parent 8a4f9e86
Loading
Loading
Loading
Loading
+31 −10
Original line number Diff line number Diff line
@@ -131,6 +131,17 @@ public class Executer implements Runnable {
					className = className.substring(0, argStart);
				}
			}
			if (Prefs.nonBlockingFilterDialogs) {
				// we have the plugin class name, let us see whether it is allowed to run it
				ImagePlus imp = WindowManager.getCurrentImage();
				boolean imageLocked = imp!=null && imp.isLockedByAnotherThread();
				if (imageLocked && !allowedWithLockedImage(className)) {
					IJ.beep();
					IJ.showStatus("\""+cmd + "\" blocked because \"" + imp.getTitle() + "\" is locked");
					return;
				}
			}
			// run the plugin
			if (IJ.shiftKeyDown() && className.startsWith("ij.plugin.Macro_Runner") && !Menus.getShortcuts().contains("*"+cmd))
    			IJ.open(IJ.getDirectory("plugins")+arg);
    		else
@@ -161,6 +172,16 @@ public class Executer implements Runnable {
	 	}
    }

	/** If the foreground image is locked during a filter operation with NonBlockingGenericDialog,
	 *  the following plugins are allowed */
	boolean allowedWithLockedImage(String className) {
		return className.equals("ij.plugin.Zoom") ||
				className.equals("ij.plugin.frame.ContrastAdjuster") ||
				className.equals("ij.plugin.SimpleCommands") ||  //includes Plugins>Utiltites>Reset (needed to reset a locked image)
				className.equals("ij.plugin.WindowOrganizer") ||
				className.equals("ij.plugin.URLOpener");
	}

    /** Opens a .lut file from the ImageJ/luts directory and returns 'true' if successful. */
    public static boolean loadLut(String name) {
		String path = IJ.getDirectory("luts")+name.replace(" ","_")+".lut";
+84 −2
Original line number Diff line number Diff line
@@ -24,6 +24,7 @@ import java.net.*;
import javax.net.ssl.*;
import java.security.cert.*;
import java.security.KeyStore;
import java.nio.ByteBuffer;


/** This class consists of static utility methods. */
@@ -564,10 +565,53 @@ public class IJ {
		'row1' and 'row2' must be in the range 0-Analyzer.getCounter()-1. */
	public static void deleteRows(int row1, int row2) {
		ResultsTable rt = Analyzer.getResultsTable();
		int tableSize = rt.size();
		rt.deleteRows(row1, row2);
		ImagePlus imp = WindowManager.getCurrentImage();
		if (imp!=null)
			Overlay.updateTableOverlay(imp, row1, row2, tableSize);
		rt.show("Results");
	}
	
	/** Returns a measurement result, where 'measurement' is "Area", 
	 * "Mean", "StdDev", "Mode", "Min", "Max", "X", "Y", "XM", "YM",
	 * "Perim.", "BX", "BY", "Width", "Height", "Major", "Minor", "Angle",
	 * "Circ.", "Feret", "IntDen", "Median", "Skew", "Kurt", "%Area",
	 * "RawIntDen", "Ch", "Slice", "Frame", "FeretX", "FeretY",
	 * "FeretAngle", "MinFeret", "AR", "Round", "Solidity", "MinThr"
	 * or "MaxThr". Add " raw" to the argument to disable calibration,
	 * for example IJ.getValue("Mean raw"). Add " limit" to enable
	 * the "limit to threshold" option.
	*/
	public static double getValue(ImagePlus imp, String measurement) {
		String options = "";
		int index = measurement.indexOf(" ");
		if (index>0) {
			if (index<measurement.length()-1)
				options = measurement.substring(index+1, measurement.length());
			measurement = measurement.substring(0, index);
		}
		int measurements = Measurements.ALL_STATS + Measurements.SLICE;
		if (options.contains("limit"))
			measurements += Measurements.LIMIT;
		Calibration cal = null;
		if (options.contains("raw")) {
			cal = imp.getCalibration();
			imp.setCalibration(null);
		}
		ImageStatistics stats = imp.getStatistics(measurements);
		ResultsTable rt = new ResultsTable();
		Analyzer analyzer = new Analyzer(imp, measurements, rt);
		analyzer.saveResults(stats, imp.getRoi());
		double value = Double.NaN;
		try {
			value = rt.getValue(measurement, 0);
		} catch (Exception e) {};
		if (cal!=null)
			imp.setCalibration(cal);
		return value;
	}

	/** Returns a reference to the "Results" window TextPanel.
		Opens the "Results" window if it is currently not open.
		Returns null if the "ImageJ" window is not open. */
@@ -894,6 +938,14 @@ public class IJ {
		return str;
	}

	/** Pad 's' with leading zeros to the specified number of digits. */
	public static String pad(String s, int digits) {
		String str = ""+s;
		while (str.length()<digits)
			str = "0"+str;
		return str;
	}

	/** Adds the specified class to a Vector to keep it from being garbage
	collected, which would cause the classes static fields to be reset. 
	Probably not needed with Java 1.2 or later. */
@@ -1644,8 +1696,8 @@ public class IJ {
		return ImageJ.VERSION+build;
	}

	/** Returns the path to the home ("user.home"), startup, ImageJ, plugins, macros, 
		luts, temp, current or image directory if <code>title</code> is "home", "startup", 
	/** Returns the path to the home ("user.home"), downloads, startup, ImageJ, plugins, macros, 
		luts, temp, current or image directory if <code>title</code> is "home", "downloads", "startup", 
		"imagej", "plugins", "macros", "luts", "temp", "current", "default", "image", otherwise, 
		displays a dialog and returns the path to the directory selected by the user. 
		Returns null if the specified directory is not found or the user
@@ -1665,6 +1717,8 @@ public class IJ {
				return null;
		} else if (title2.equals("home"))
			return System.getProperty("user.home") + File.separator;
		else if (title2.equals("downloads"))
			return System.getProperty("user.home")+File.separator+"Downloads"+File.separator;
		else if (title2.equals("startup"))
			return Prefs.getImageJDir();
		else if (title2.equals("imagej"))
@@ -2063,6 +2117,34 @@ public class IJ {
		return str;
	}
	
	public static ByteBuffer openAsByteBuffer(String path) {
		if (path==null || path.equals("")) {
			OpenDialog od = new OpenDialog("Open as ByteBuffer", "");
			String directory = od.getDirectory();
			String name = od.getFileName();
			if (name==null) return null;
			path = directory + name;
		}
		File file = new File(path);
		if (!file.exists()) {
			error("OpenAsByteBuffer", "File not found");
			return null;
		}
		int len = (int)file.length();
		byte[] buffer = new byte[len];
		try {
			InputStream in = new BufferedInputStream(new FileInputStream(path));
			DataInputStream dis = new DataInputStream(in);
			dis.readFully(buffer);
			dis.close();
		}
		catch (Exception e) {
			error("OpenAsByteBuffer", e.getMessage());
			return null;
		}
		return ByteBuffer.wrap(buffer);
	}

	/** Creates a new image.
	*  @param title   image name
	*  @param width  image width in pixels
+6 −3
Original line number Diff line number Diff line
@@ -77,8 +77,8 @@ public class ImageJ extends Frame implements ActionListener,
	MouseListener, KeyListener, WindowListener, ItemListener, Runnable {

	/** Plugins should call IJ.getVersion() or IJ.getFullVersion() to get the version string. */
	public static final String VERSION = "1.52p";
	public static final String BUILD = "";  //61
	public static final String VERSION = "1.52r";
	public static final String BUILD = ""; //57
	public static Color backgroundColor = new Color(237,237,237);
	/** SansSerif, 12-point, plain font. */
	public static final Font SansSerif12 = new Font("SansSerif", Font.PLAIN, 12);
@@ -265,6 +265,8 @@ public class ImageJ extends Frame implements ActionListener,
			props.put("proxySet", "true");
			props.put("http.proxyHost", server);
			props.put("http.proxyPort", ""+port);
			props.put("https.proxyHost", server);
			props.put("https.proxyPort", ""+port);
		}
		//new ProxySettings().logProperties();
	}
@@ -281,7 +283,8 @@ public class ImageJ extends Frame implements ActionListener,
		int ijY = Prefs.getInt(IJ_Y,-99);
		Rectangle maxBounds = GUI.getMaxWindowBounds();
		//System.out.println("getPreferredLoc1: "+ijX+" "+ijY+" "+maxBounds);
		if (ijX>=maxBounds.x && ijY>=maxBounds.y && ijX<(maxBounds.x+maxBounds.width-75))
		if (ijX>=maxBounds.x && ijY>=maxBounds.y && ijX<(maxBounds.x+maxBounds.width-75)
		&& ijY<(maxBounds.y+maxBounds.height-75))
			return new Point(ijX, ijY);
		Dimension tbsize = toolbar.getPreferredSize();
		int ijWidth = tbsize.width+10;
+256 −216
Original line number Diff line number Diff line
@@ -58,7 +58,9 @@ public class ImagePlus implements ImageObserver, Measurements, Cloneable {
	protected boolean compositeImage;
	protected int width;
	protected int height;
	protected boolean locked = false;
	protected boolean locked;
	private int lockedCount;
	private Thread lockingThread;
	protected int nChannels = 1;
	protected int nSlices = 1;
	protected int nFrames = 1;
@@ -160,38 +162,77 @@ public class ImagePlus implements ImageObserver, Measurements, Cloneable {
    	ID = --currentID;
	}

	/** Locks the image so other threads can test to see if it
		is in use. Returns true if the image was successfully locked.
		Beeps, displays a message in the status bar, and returns
		false if the image is already locked. */
	/** Locks the image so other threads can test to see if it is in use.
	 * One thread can lock an image multiple times, then it has to unlock
	 * it as many times until it is unlocked. This allows nested locking
	 * within a thread.
	 * Returns true if the image was successfully locked.
	 * Beeps, displays a message in the status bar, and returns
	 * false if the image is already locked by another thread.
	*/
	public synchronized boolean lock() {
		return lock(true);
	}

	/** Similar to lock, but doesn't beep and display an error
	 * message if the attempt to lock the image fails.
	*/
	public synchronized boolean lockSilently() {
		return lock(false);
	}

	private synchronized boolean lock(boolean loud) {
		if (locked) {
			if (Thread.currentThread()==lockingThread) {
				lockedCount++; //allow locking multiple times by the same thread
				return true;
			} else {
				if (loud) {
					IJ.beep();
					IJ.showStatus("\"" + title + "\" is locked");
					if (IJ.debugMode) IJ.log(title + " is locked by " + lockingThread + "; refused locking by " + Thread.currentThread().getName());
					if (IJ.macroRunning())
						IJ.wait(500);
				}
				return false;
			}
		} else {
				locked = true;
			locked = true;  //we could use 'lockedCount instead, but subclasses might use
			lockedCount = 1;
			lockingThread = Thread.currentThread();
			if (win instanceof StackWindow)
				((StackWindow)win).setSlidersEnabled(false);
			if (IJ.debugMode) IJ.log(title + ": locked" + (loud ? "" : "silently") + " by " + Thread.currentThread().getName());
			return true;
		}
	}

	/** Similar to lock, but doesn't beep and display an error
		message if the attempt to lock the image fails. */
	public synchronized boolean lockSilently() {
		if (locked)
			return false;
	/** Unlocks the image.
	 * In case the image had been locked several times by the current thread,
	 * it gets unlocked only after as many unlock operations as there were
	 * previous lock operations.
	*/
	public synchronized void unlock() {
		if (Thread.currentThread()==lockingThread && lockedCount>1)
			lockedCount--;
		else {
        	locked = true;
			if (IJ.debugMode) IJ.log(title + ": lock silently");
			return true;
			locked = false;
			lockedCount = 0;
			lockingThread = null;
			if (win instanceof StackWindow)
				((StackWindow)win).setSlidersEnabled(true);
			if (IJ.debugMode) IJ.log(title + ": unlocked");
		}
	}

	/** Unlocks the image. */
	public synchronized void unlock() {
		locked = false;
	/** Returns 'true' if the image is locked. */
	public boolean isLocked() {
		return locked;
	}

	/** Returns 'true' if the image was locked on another thread. */
	public boolean isLockedByAnotherThread() {
		return locked && Thread.currentThread()!=lockingThread;
	}

	private void waitForImage(Image image) {
@@ -535,14 +576,7 @@ public class ImagePlus implements ImageObserver, Measurements, Cloneable {
		height = newHeight;
		setStackNull();
		LookUpTable lut = new LookUpTable(image);
		int type = GRAY8;
		if (lut.getMapSize() > 0) {
			if (lut.isGrayscale())
				type = GRAY8;
			else
				type = COLOR_256;
		} else
			type = COLOR_RGB;
		int type = lut.getMapSize()>0?GRAY8:COLOR_RGB;
		if (image!=null && type==COLOR_RGB)
			ip = new ColorProcessor(image);
		if (ip==null && image!=null)
@@ -1268,6 +1302,17 @@ public class ImagePlus implements ImageObserver, Measurements, Cloneable {
		typeSet = true;
	}
	
	public void setTypeToColor256() {
		if (imageType==ImagePlus.GRAY8) {
			ImageProcessor ip2 = getProcessor();
			if (ip2!=null && ip2.getMinThreshold()==ImageProcessor.NO_THRESHOLD && ip2.isColorLut() && !ip2.isPseudoColorLut()) {
				imageType = COLOR_256;
				typeSet = true;
			}
		}
	}
	

 	/** Returns the string value from the "Info" property string
	 * associated with 'key', or null if the key is not found.
	 * Works with DICOM tags and Bio-Formats metadata.
@@ -2030,7 +2075,7 @@ public class ImagePlus implements ImageObserver, Measurements, Cloneable {
			path = url;
			url2 = url;
		} else if (fi!=null && !((fi.directory==null||fi.directory.equals("")))) {
			path = fi.directory+fi.fileName;
			path = fi.getFilePath();
		} else if (fi!=null && fi.url!=null && !fi.url.equals("")) {
			path = fi.url;
			url2 = fi.url;
@@ -2627,11 +2672,6 @@ public class ImagePlus implements ImageObserver, Measurements, Cloneable {
		listeners.removeElement(listener);
	}

	/** Returns 'true' if the image is locked. */
	public boolean isLocked() {
		return locked;
	}
	
	public void setOpenAsHyperStack(boolean openAsHyperStack) {
		this.openAsHyperStack = openAsHyperStack;
	}
+0 −7
Original line number Diff line number Diff line
@@ -1231,13 +1231,6 @@ public class Menus {
    		else if (stack.isLab())
    			type = LAB_STACK;
    	}
		if (type==ImagePlus.GRAY8) {
			ImageProcessor ip = imp.getProcessor();
			if (ip!=null && ip.getMinThreshold()==ImageProcessor.NO_THRESHOLD && ip.isColorLut() && !ip.isPseudoColorLut()) {
				type = ImagePlus.COLOR_256;
				imp.setType(ImagePlus.COLOR_256);
			}
		}
    	switch (type) {
    		case ImagePlus.GRAY8:
				gray8Item.setState(true);
Loading