Login  Register

Macro "call" mechanism unusual "feature" / Accessing image properties

Posted by Joachim Wesner on Mar 15, 2008; 9:30pm
URL: http://imagej.273.s1.nabble.com/select-without-clicking-for-clearSelection-of-TextPanel-tp3696867p3696868.html

Hi list,

while writing a simple class that allows to access general image properties
via the "call" mechanism to a static Java method, (If anybody interested, I
attach it) I noted an unusual "feature"
of that call mechanism:

If you call a method that returns a string (which in my case may only be a
status value if the property setting succeded or not), but do NOT use the
result in the macro,
 i.e. only do (in my case)

call ("ImpProps.setProperty", "foo", "bar");

instead of

result=call ("ImpProps.setProperty", "foo", "bar");

the "Log" window always comes up, showing that otherwise ignored result
string. Is this intended? Useful?


Sincerely

Joachim


import ij.*;

/**
 * This simple class can be called from an ImageJ macro via the "call"
mechanism to
 * get and set the (string) properties of the active image (ImagePlus).
 *
 * call("ImpProps.setProperty", "<key>", "<value>");
 *        set property <key> to <value>, returns <value> if successful,
 *        "" otherwise (no active image)
 *
 * call("ImpProps.getProperty", "<key>");
 *        returns value of property <key> if set, "" otherwise (not found
or no active image)
 *
 * @see    ij.ImagePlus#setProperty
 * @see    ij.ImagePlus#getProperty
 *
 * @author Joachim Wesner
 * @author Leica Microsystems CMS GmbH
 * @author [hidden email]
 * @version 2008-3-15
 *
 * This class can be compiled with ImageJ's Plugins>Compile and Run
command.
 */

public class ImpProps {

          public static String getProperty(String arg1) {
                   ImagePlus imp = IJ.getImage();
                   if (imp == null)
                             return "";
                   Object prop = imp.getProperty(arg1);
                   if (prop != null && prop instanceof String)
                             return (String)prop;
                   else
                             return "";
          }

          public static String setProperty(String arg1, String arg2) {

                   ImagePlus imp = IJ.getImage();
                   if (imp == null)
                             return "";
                   imp.setProperty(arg1, arg2);
                   return arg2;

          }
}


______________________________________________________________________
This email has been scanned by the MessageLabs Email Security System.
For more information please visit http://www.messagelabs.com/email 
______________________________________________________________________