select without clicking for clearSelection() of TextPanel?

Previous Topic Next Topic
 
classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

select without clicking for clearSelection() of TextPanel?

Andy Puckett
Does anyone know of a way to select lines of a TextPanel for use with  
clearSelection(), but without using the mouse?  I need to be able to  
remove the last line that was added with appendLine(), but  
automatically from within my plugin.

The best I have been able to do is to use setLine() to replace it with  
a blank line, but this is unsatisfying when more lines are then  
appended after it.

Thanks,
Andy
Reply | Threaded
Open this post in threaded view
|

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

Joachim Wesner
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 
______________________________________________________________________
Reply | Threaded
Open this post in threaded view
|

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

Wayne Rasband
This is a "feature" that allows you to enter an expression or  
function call and have the output displayed in the log window by  
pressing ctrl-r (Macros>Run Macro). For example, enter

    2+2
    sqrt(2)
    getInfo("java.version")
    call("ij.IJ.freeMemory")

press ctrl-r (Macros>Run Macro) and

    4
    1.4142
    1.5.0_07
    5421K of 710MB (<1%)

is displayed in the Log window. Press ctrl-e (Macros>Evaluate Line)  
and the last expression or function entered is evaluated.

-wayne

On Mar 15, 2008, at 5:30 PM, Joachim Wesner wrote:

> 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
> ______________________________________________________________________