toggle ActionBar AlwaysOnTop, and the API

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

toggle ActionBar AlwaysOnTop, and the API

b holi
Jerome,

Thank you for the javascript to close an ActionBar.  With that instructive
example in hand, I was able to determine the call to keep an ActionBar
window on top:

    WindowManager.getFrame(title).setAlwaysOnTop(true);

This brings two questions to mind.

1. I did not find the setAlwaysOnTop() method in the ImageJ API, whereas I
did find the dispose() method.  I use the macro language (but not Java) and
can see that using javascript to make calls to the API empowers the macro
language greatly.  But how does someone with no Java background go about
identifying available methods like setAlwaysOnTop() that are not present in
the API?

2. How does one access the boolean value of setAlwaysOnTop(), using
javascript?  I found the js valueOf() method will pull it out, but only if
it is known beforehand. I want to toggle this, and wrote a macro to do so
using a dialog checkbox.  Below is a generic dialog version, a variation of
which I call from a button in an ActionBar.  A true toggle function that
reads, then toggles, the boolean value would be preferable.


// for windows other than 'ImageJ'
Dialog.create("Toggle window 'AlwaysOnTop'");
    Dialog.addMessage("Enter a window's title and set its 'AlwaysOnTop'
status.\n     The title is the name which appears in the title bar.\n ");
    Dialog.addString("Window title" "", 20);
    Dialog.addMessage("");
    Dialog.addCheckbox("   if checked, this window will remain above all
other windows", false);
    Dialog.addMessage("");
Dialog.show();

title = Dialog.getString;
topStatus = Dialog.getCheckbox;

jsTop = 'title="'+title+'";'+
'WindowManager.getFrame(title).setAlwaysOnTop(true);';

jsNotTop = 'title="'+title+'";'+
'WindowManager.getFrame(title).setAlwaysOnTop(false);';

if (topStatus==1)
    eval('script',jsTop);
else eval('script',jsNotTop);
____________


Regards,
Bruce




On Wed, Feb 11, 2009 at 5:27 PM, Jerome Mutterer
<[hidden email]>wrote:

> Dear Bruce,
>
> You can close an ActionBar using javascript, and you can call javascript
> from a macro with the eval function. This will look like this:
>
> title = 'Demo'; // the ActionBar's title
> if (isOpen(title)) {
> js ='title="'+title+'";'+
> 'WindowManager.getFrame(title).dispose();'+
> 'WindowManager.removeWindow(WindowManager.getFrame(title));';
> eval ('script',js);
> }
>
> Sincerely,
>
> Jerome
>
>
> On Wed, Feb 11, 2009 at 11:34 PM, b holi <[hidden email]> wrote:
>
> > Can ActionBar windows be closed programmatically?
> >
> >
> > Regards,
> >
> > Bruce
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: toggle ActionBar AlwaysOnTop, and the API

jmutterer
Dear Bruce,
to toggle the 'on top' property of a window, you can take advantage of the
isAlwaysOnTop method of the Window class.
The javascript looks like :

title="test";
WindowManager.getFrame(title).setAlwaysOnTop(!WindowManager.getFrame(title).isAlwaysOnTop());

it will set 'alwaysontop' to 0 if it's 1, and 1 if it's 0.

Now about the API, ImageJ's API only contains ImageJ specific information.
You have to look at the Java API for more general methods, like those of the
java.awt.Window class. You can find these in the Java API at
http://java.sun.com/javase/reference/api.jsp
There, choose your version of java and select the 'java.awt' package and
finally the 'Window' class. Here you find all available information about
java.awt.Windows and what you can do with these.
Because you are new to Java, note that in the javascript above, you invoke
methods (setAlwaysOnTop and isAlwaysOnTop) of the java.awt.Window class on
an object of the java.awt.Frame class (WindowManager.getFrame() returns a
Frame). This is possible because the java.awt.Frame class is a subclass of
the java.awt.Window class and therefore Frames have inherited methods from
Windows.

Jerome.

On Sat, Feb 14, 2009 at 4:16 AM, b holi <[hidden email]> wrote:

> Jerome,
>
> Thank you for the javascript to close an ActionBar.  With that instructive
> example in hand, I was able to determine the call to keep an ActionBar
> window on top:
>
>    WindowManager.getFrame(title).setAlwaysOnTop(true);
>
> This brings two questions to mind.
>
> 1. I did not find the setAlwaysOnTop() method in the ImageJ API, whereas I
> did find the dispose() method.  I use the macro language (but not Java) and
> can see that using javascript to make calls to the API empowers the macro
> language greatly.  But how does someone with no Java background go about
> identifying available methods like setAlwaysOnTop() that are not present in
> the API?
>
> 2. How does one access the boolean value of setAlwaysOnTop(), using
> javascript?  I found the js valueOf() method will pull it out, but only if
> it is known beforehand. I want to toggle this, and wrote a macro to do so
> using a dialog checkbox.  Below is a generic dialog version, a variation of
> which I call from a button in an ActionBar.  A true toggle function that
> reads, then toggles, the boolean value would be preferable.
>
>
> // for windows other than 'ImageJ'
> Dialog.create("Toggle window 'AlwaysOnTop'");
>    Dialog.addMessage("Enter a window's title and set its 'AlwaysOnTop'
> status.\n     The title is the name which appears in the title bar.\n ");
>    Dialog.addString("Window title" "", 20);
>    Dialog.addMessage("");
>    Dialog.addCheckbox("   if checked, this window will remain above all
> other windows", false);
>    Dialog.addMessage("");
> Dialog.show();
>
> title = Dialog.getString;
> topStatus = Dialog.getCheckbox;
>
> jsTop = 'title="'+title+'";'+
> 'WindowManager.getFrame(title).setAlwaysOnTop(true);';
>
> jsNotTop = 'title="'+title+'";'+
> 'WindowManager.getFrame(title).setAlwaysOnTop(false);';
>
> if (topStatus==1)
>    eval('script',jsTop);
> else eval('script',jsNotTop);
> ____________
>
>
> Regards,
> Bruce
>
>
>
>
> On Wed, Feb 11, 2009 at 5:27 PM, Jerome Mutterer
> <[hidden email]>wrote:
>
> > Dear Bruce,
> >
> > You can close an ActionBar using javascript, and you can call javascript
> > from a macro with the eval function. This will look like this:
> >
> > title = 'Demo'; // the ActionBar's title
> > if (isOpen(title)) {
> > js ='title="'+title+'";'+
> > 'WindowManager.getFrame(title).dispose();'+
> > 'WindowManager.removeWindow(WindowManager.getFrame(title));';
> > eval ('script',js);
> > }
> >
> > Sincerely,
> >
> > Jerome
> >
> >
> > On Wed, Feb 11, 2009 at 11:34 PM, b holi <[hidden email]> wrote:
> >
> > > Can ActionBar windows be closed programmatically?
> > >
> > >
> > > Regards,
> > >
> > > Bruce
> > >
> >
>
Reply | Threaded
Open this post in threaded view
|

Menu suggestions

Gabriel Landini
On Saturday 14 February 2009, Jerome Mutterer wrote:
> title="test";
> WindowManager.getFrame(title).setAlwaysOnTop(!WindowManager.getFrame(title)
>.isAlwaysOnTop());
>
> it will set 'alwaysontop' to 0 if it's 1, and 1 if it's 0.

I think this would be a useful option to have in Edit>Options>Misc...

Another useful thing would be to include the Calculator Plus entry next (i.e.
after) the  Image Calculator one in the Process menu entry.
I found this item in the IJ Notes page which might be relevant:

"An updated Menus class, contributed by Johannes Schindelin, provides better
Fiji compatibility and allows plugins to be installed in more menus."

Any suggestions on how to add a new item to the standard menu structure using
this new class?

Cheers

Gabriel
Reply | Threaded
Open this post in threaded view
|

Re: Menu suggestions

dscho
Hi,

On Sat, 14 Feb 2009, Gabriel Landini wrote:

> I think this would be a useful option to have in Edit>Options>Misc...
>
> [...]
>
> "An updated Menus class, contributed by Johannes Schindelin, provides better
> Fiji compatibility and allows plugins to be installed in more menus."
>
> Any suggestions on how to add a new item to the standard menu structure
> using this new class?

Sorry, you cannot extend the dialog shown by Edit>Options>Misc...  
However, you can add another plugin that you insert into the Edit>Options
menu using a line in plugins.config like this:

        Edit>Options, "ActionBar...", ActionBar_Options

(this assumes that you have a plugin class named ActionBar_Options, and
that you bundle all your classes into a .jar file).

Ciao,
Dscho
Reply | Threaded
Open this post in threaded view
|

Re: Menu suggestions

Gabriel Landini
On Saturday 14 February 2009, Dscho wrote:
> Sorry, you cannot extend the dialog shown by Edit>Options>Misc...
> However, you can add another plugin that you insert into the Edit>Options
> menu using a line in plugins.config like this:
>
> Edit>Options, "ActionBar...", ActionBar_Options
>
> (this assumes that you have a plugin class named ActionBar_Options, and
> that you bundle all your classes into a .jar file).

Can this also be used to add macros and js to the menu? Or does it only
support classes?
I tried adding the new exact erode, but nothing happens:
Process>Binary, "Erode exact", Erode_exact.js
(in the plugins.config file)
Or can the class that executes the js file be called there? If so can somebody
show how?

Cheers

G.