Need to close the result table from my java application

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

Need to close the result table from my java application

Md Tamjidul Hoque
Hi All

         from my ImageJ java application, I am calling the "analyze
particles" application within ImageJ and as a result the "Result" table
is coming up.

Is there a way to close (or, kill)  the "Result" table from my
application? I think I need the ID or pointer of the

Result window to close it ... or so, but not sure ... any help is much
appreciated.


By the way, I have to close the "Multi Measure" Menu or Table as well
(this is unwanted) - and I am not sure why the "Multi Measure"

is appearing in one computer and not appearing in other computer for the
same code, any suggestion?

Thanks
Tamjid
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

EHB2010
have you tried using:

ImagePlus imageOfResultsTable  = WindowManager.getImage(String titleOfTheResultsTable);
imageOfResultsTable.close();

?


Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

EHB2010
I'm sorry that was bad advice. I've just had a quick look at the source code for results tables. It's actually very simple- this plugin makes invisible the results window on my system:

import ij.WindowManager;
import ij.plugin.PlugIn;
import java.awt.*;
 
public class TestPlugin_  implements PlugIn {
       
        public void run(String arg) {
               
                Frame[] arrayOfFrames = WindowManager.getNonImageWindows();
                for (int i = 0 ; i < arrayOfFrames.length ; ++i) {
                        String localName = arrayOfFrames[i].getTitle();
                        if ( localName.equalsIgnoreCase("Results")){
                                arrayOfFrames[i].setVisible(false);
                        }
                }
        }
}

BW
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

EHB2010
This post was updated on .
In reply to this post by Md Tamjidul Hoque
CONTENTS DELETED
The author has deleted this message.
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

Md Tamjidul Hoque
Many thanks.

- Tamjid

On Wed, Mar 17, 2010 at 4:43 AM, EHB2010 <[hidden email]> wrote:

> I'm sorry that was bad advice. I've just had a quick look at the source
> code
> for results tables. It's actually very simple- this plugin makes invisible
> the results window on my system:
>
> import ij.WindowManager;
> import ij.plugin.PlugIn;
> import java.awt.*;
>
> public class TestPlugin_  implements PlugIn {
>
>        public void run(String arg) {
>
>                Frame[] arrayOfFrames = WindowManager.getNonImageWindows();
>                for (int i = 0 ; i < arrayOfFrames.length ; ++i) {
>                        String localName = arrayOfFrames[i].getTitle();
>                        if ( localName.equalsIgnoreCase("Results")){
>                                arrayOfFrames[i].setVisible(false);
>                        }
>                }
>        }
> }
>
> BW
> --
> View this message in context:
> http://n2.nabble.com/Need-to-close-the-result-table-from-my-java-application-tp4713378p4745635.html
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

Bob Loushin
Thanks, BW, for pointing this out.

Like the solution that I found myself (and which I felt was unsatisfactory), this one has the problem that the Results table does not come back the next time an IJ.write() is done. Obviously, this one is better than my method, because it points the way to getting it back: do a setVisible(true) when writing to the table. I can do that in my own plugins, but if I use this in my plugins, they will cause problems when mixed with plugins that are outside my control but also use the Results table for output. Is there a still better solution, or is this a problem inherent in the Results table system itself?

Perhaps using the Results table for general output isn't a good idea. It doesn't appear that it was originally designed for that task, but I (and apparently others) have adopted it for that task because there doesn't appear to be a better solution within ImageJ. I'm still new to ImageJ. Is this the correct forum to make feature requests? If I decide to invest time in building a more complete version of this, is there a way to submit it to get it into the official build?

Bob


----- Original Message -----
From: "Tamjid" <[hidden email]>
To: [hidden email]
Sent: Wednesday, March 17, 2010 4:24:16 AM GMT -06:00 US/Canada Central
Subject: Re: Need to close the result table from my java application

Many thanks.

- Tamjid

On Wed, Mar 17, 2010 at 4:43 AM, EHB2010 <[hidden email]> wrote:

> I'm sorry that was bad advice. I've just had a quick look at the source
> code
> for results tables. It's actually very simple- this plugin makes invisible
> the results window on my system:
>
> import ij.WindowManager;
> import ij.plugin.PlugIn;
> import java.awt.*;
>
> public class TestPlugin_ implements PlugIn {
>
> public void run(String arg) {
>
> Frame[] arrayOfFrames = WindowManager.getNonImageWindows();
> for (int i = 0 ; i < arrayOfFrames.length ; ++i) {
> String localName = arrayOfFrames[i].getTitle();
> if ( localName.equalsIgnoreCase("Results")){
> arrayOfFrames[i].setVisible(false);
> }
> }
> }
> }
>
> BW
> --
> View this message in context:
> http://n2.nabble.com/Need-to-close-the-result-table-from-my-java-application-tp4713378p4745635.html 
> Sent from the ImageJ mailing list archive at Nabble.com.
>
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

David Webster
All,

I am/have been using ResultsTables to pass general, array strructurable data
form one plugin to the next. For example, one plugin  might detect objects,
the next extract object features, and a third run a pattern classifier on
those feaures. Right now, the only way to do this is to write the
ResultsTables  to a text file using a ResultsTable.save(..) and then reading
them back in using ResultsTable.open(..) . This works, but having multiple
open the results table objects would really be nice.

David Webster

On Wed, Mar 17, 2010 at 12:29 PM, Bob Loushin <[hidden email]> wrote:

> Thanks, BW, for pointing this out.
>
> Like the solution that I found myself (and which I felt was
> unsatisfactory), this one has the problem that the Results table does not
> come back the next time an IJ.write() is done. Obviously, this one is better
> than my method, because it points the way to getting it back: do a
> setVisible(true) when writing to the table. I can do that in my own plugins,
> but if I use this in my plugins, they will cause problems when mixed with
> plugins that are outside my control but also use the Results table for
> output. Is there a still better solution, or is this a problem inherent in
> the Results table system itself?
>
> Perhaps using the Results table for general output isn't a good idea. It
> doesn't appear that it was originally designed for that task, but I (and
> apparently others) have adopted it for that task because there doesn't
> appear to be a better solution within ImageJ. I'm still new to ImageJ. Is
> this the correct forum to make feature requests? If I decide to invest time
> in building a more complete version of this, is there a way to submit it to
> get it into the official build?
>
> Bob
>
>
> ----- Original Message -----
> From: "Tamjid" <[hidden email]>
> To: [hidden email]
> Sent: Wednesday, March 17, 2010 4:24:16 AM GMT -06:00 US/Canada Central
> Subject: Re: Need to close the result table from my java application
>
> Many thanks.
>
> - Tamjid
>
> On Wed, Mar 17, 2010 at 4:43 AM, EHB2010 <[hidden email]>
> wrote:
>
> > I'm sorry that was bad advice. I've just had a quick look at the source
> > code
> > for results tables. It's actually very simple- this plugin makes
> invisible
> > the results window on my system:
> >
> > import ij.WindowManager;
> > import ij.plugin.PlugIn;
> > import java.awt.*;
> >
> > public class TestPlugin_ implements PlugIn {
> >
> > public void run(String arg) {
> >
> > Frame[] arrayOfFrames = WindowManager.getNonImageWindows();
> > for (int i = 0 ; i < arrayOfFrames.length ; ++i) {
> > String localName = arrayOfFrames[i].getTitle();
> > if ( localName.equalsIgnoreCase("Results")){
> > arrayOfFrames[i].setVisible(false);
> > }
> > }
> > }
> > }
> >
> > BW
> > --
> > View this message in context:
> >
> http://n2.nabble.com/Need-to-close-the-result-table-from-my-java-application-tp4713378p4745635.html
> > Sent from the ImageJ mailing list archive at Nabble.com.
> >
>
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

EHB2010
In reply to this post by Bob Loushin
@Bob

is there a reason you need to put data into the main ResultsTable with your plugin? I create my own instance of ResultsTable for my plugins, rather than share one with other plugins. It seems to work, you would have complete control over it's visibility and it allows a separate summary table etc.

E
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

Michael Schmid
In reply to this post by Bob Loushin
Hi Bob, Tamjid, and everyone else involved:

wouldn't a simple close() instead of setVisible(false) do it?

Michael
________________________________________________________________

On 17 Mar 2010, at 20:29, Bob Loushin wrote:

> Thanks, BW, for pointing this out.
>
> Like the solution that I found myself (and which I felt was  
> unsatisfactory), this one has the problem that the Results table  
> does not come back the next time an IJ.write() is done. Obviously,  
> this one is better than my method, because it points the way to  
> getting it back: do a setVisible(true) when writing to the table. I  
> can do that in my own plugins, but if I use this in my plugins,  
> they will cause problems when mixed with plugins that are outside  
> my control but also use the Results table for output. Is there a  
> still better solution, or is this a problem inherent in the Results  
> table system itself?
>
> Perhaps using the Results table for general output isn't a good  
> idea. It doesn't appear that it was originally designed for that  
> task, but I (and apparently others) have adopted it for that task  
> because there doesn't appear to be a better solution within ImageJ.  
> I'm still new to ImageJ. Is this the correct forum to make feature  
> requests? If I decide to invest time in building a more complete  
> version of this, is there a way to submit it to get it into the  
> official build?
>
> Bob
>
>
> ----- Original Message -----
> From: "Tamjid" <[hidden email]>
> To: [hidden email]
> Sent: Wednesday, March 17, 2010 4:24:16 AM GMT -06:00 US/Canada  
> Central
> Subject: Re: Need to close the result table from my java application
>
> Many thanks.
>
> - Tamjid
>
> On Wed, Mar 17, 2010 at 4:43 AM, EHB2010  
> <[hidden email]> wrote:
>
>> I'm sorry that was bad advice. I've just had a quick look at the  
>> source
>> code
>> for results tables. It's actually very simple- this plugin makes  
>> invisible
>> the results window on my system:
>>
>> import ij.WindowManager;
>> import ij.plugin.PlugIn;
>> import java.awt.*;
>>
>> public class TestPlugin_ implements PlugIn {
>>
>> public void run(String arg) {
>>
>> Frame[] arrayOfFrames = WindowManager.getNonImageWindows();
>> for (int i = 0 ; i < arrayOfFrames.length ; ++i) {
>> String localName = arrayOfFrames[i].getTitle();
>> if ( localName.equalsIgnoreCase("Results")){
>> arrayOfFrames[i].setVisible(false);
>> }
>> }
>> }
>> }
>>
>> BW
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

EHB2010
In reply to this post by Bob Loushin
Hi Bob,

I think you are right. Making it invisible without an easy mechanism to make it visible again is a bad idea. As you don't really want to be recoding all the plugins to check if the resultTable is visible when they add to it I think maybe adding a GUI to it would be sensible? You could always automatically minimise it to the dock.

For example (almost entirely written by my GUI builder/code in italics):

To call this from your plugin use the public static method: "MyResultsTableVisibilitySetter.getTheOnlyInstance();

NB: I've made no attempt to optimise hoe this looks- it's big and ugly.


import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import ij.WindowManager;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;

public class MyResultsTableVisibilitySetter extends JFrame {
        private static final MyResultsTableVisibilitySetter THE_ONLY_INSTANCE = new MyResultsTableVisibilitySetter();
        private JPanel contentPane;
        private JToggleButton showButton;
        private JToggleButton hideButton;
        private final ButtonGroup onlyButtongroup = new ButtonGroup();

        private MyResultsTableVisibilitySetter() {
                addWindowListener(new WindowAdapter() {
                        @Override
                        public void windowClosing(WindowEvent e) {
                                do_this_windowClosing(e);
                        }
                });
                setAlwaysOnTop(true);
                setTitle("Results Table");
                setDefaultCloseOperation(JFrame.DO_NOTHING_ON_CLOSE);
                setBounds(0, 0, 450, 300);
                contentPane = new JPanel();
                setContentPane(contentPane);
                contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
                showButton = new JToggleButton("show");
                showButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                do_showButton_actionPerformed(e);
                        }
                });
                onlyButtongroup.add(showButton);
                contentPane.add(showButton);
               
                hideButton = new JToggleButton("hide");
                hideButton.addActionListener(new ActionListener() {
                        public void actionPerformed(ActionEvent e) {
                                do_hideButton_actionPerformed(e);
                        }
                });
                onlyButtongroup.add(hideButton);
                contentPane.add(hideButton);
                pack();
        }
       
        public static MyResultsTableVisibilitySetter getTheOnlyInstance() {
                THE_ONLY_INSTANCE.setVisible(true);
                return THE_ONLY_INSTANCE;
        }

        protected void do_showButton_actionPerformed(ActionEvent e) {
                boolean showTrueFalse = showButton.isSelected();
                if (showTrueFalse) {
                        Frame[] arrayOfFrames = WindowManager.getNonImageWindows();
            for (int i = 0 ; i < arrayOfFrames.length ; ++i) {
                    String localName = arrayOfFrames[i].getTitle();
                    if ( localName.equalsIgnoreCase("Results")){
                            arrayOfFrames[i].setVisible(true);
                    }
            }
                }
        }
        protected void do_hideButton_actionPerformed(ActionEvent e) {
                boolean hideTrueFalse = hideButton.isSelected();
                if (hideTrueFalse) {
                        Frame[] arrayOfFrames = WindowManager.getNonImageWindows();
            for (int i = 0 ; i < arrayOfFrames.length ; ++i) {
                    String localName = arrayOfFrames[i].getTitle();
                    if ( localName.equalsIgnoreCase("Results")){
                            arrayOfFrames[i].setVisible(false);
                    }
            }
                }
        }
        protected void do_this_windowClosing(WindowEvent e) {
                Frame[] arrayOfFrames = WindowManager.getNonImageWindows();
        for (int i = 0 ; i < arrayOfFrames.length ; ++i) {
                String localName = arrayOfFrames[i].getTitle();
                if ( localName.equalsIgnoreCase("Results")){
                        arrayOfFrames[i].setVisible(true);
                }
        }
        this.dispose();
        }
}
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

EHB2010
In reply to this post by Michael Schmid
too easy!!

in all seriousness
1) I thought it might be useful to be able to make it visible very simply again with the measurements intact. You can always call reset() on the table if you want it clear.
2) Frame doesn't have a "close()" method so I think you would have to cast it to its subtype TextWindow, which is even more wordy:

        Frame[] arrayOfFrames = WindowManager.getNonImageWindows();
        for (int i = 0 ; i < arrayOfFrames.length ; ++i) {
                String localName = arrayOfFrames[i].getTitle();
                if ( localName.equalsIgnoreCase("Results")){
                        TextWindow tw = (TextWindow) arrayOfFrames[i];
                        tw.close();
                }
        }
[is there a way of getting a TextWindow object directly?? ]
3) close() would ask if you wanted to save the data. If you're not interested in the data that could be annoying.
4) I don't know much about the plugins being used but I thought there was a risk that they'd keep recreating the results table when they were re-run and it'd keep popping up. Although I guess there's the same risk with setVisible().
5) I don't think it would save that much memory to clear the table and dispose() of the window.
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

Bob Loushin
In reply to this post by Md Tamjidul Hoque
There have been several responses to my last post on this topic, all of which offer interesting possibilities.  I appreciate all the help.  I will try to answer all of them here.  Unfortunately, that may make for a longer than normal post, but if you read to the end, it comes to a happy conclusion, at least for me :).



First, some background.  I'm relatively new to ImageJ, and I am using it because it is a useful tool to accomplish the data analysis I need to do.  Most of my training is in science, not programming, though I do have an extensive background in C++ and some knowledge of Java.  In order to use ImageJ, I need to write some plugins, so I poked through the ImageJ website until I found the ImageJ plugins tutorial and the appendix to Burger and Burge's book, both of which I've read fairly carefully.  I've also peeked into the developers API Documentation in spots, but by no means exhaustively.  So: limited knowledge of ImageJ, cookbooking from the tutorials, trying to get my analysis done as painlessly as possible.  I think that's a fairly common plug-in writer  profile.  It also explains why I'm making so many mistakes and asking so many questions :).



More unique to my case, I'm producing a tool which will be used for routine measurements/analysis by people with no programming knowledge and only as much experience with ImageJ as they need to open files and run the tools.  They will expect the user interface to be as simple as possible.



My application reqires a mechanism for presenting tables of mixed text and numbers to the user.  I'm looking for a simple mechanism, easily controlled from a plugin, that allows me to show that table to the user.  Preferably, it would be part of my plugins UI, appearing when the plugin starts, and going away when the plugin is done.  It would also be helpful if I could update specific cells of the table without rewriting the whole thing.  Superficially, the results table seems a perfect fit.  It can present a table of data to a user with only a few simple calls, it shows up when needed, it goes away when you click on the red x in the upper right corner (although I can't find  call which allows for the same thing to be accomplished from the plugin), and it comes back again when needed again.



@Michael Schmid  Yes, close() would be a great solution, but it doesn't exist, at least at the level I'm trying to get at it (Frame class).



@Gabriel Landini  Being able to read and update the data in the table would be useful, but in a very brief look at the API docs, there was no class named rt.  Did you mean this to refer to the ResultsTable class?



@EHB2010  I think creating my own private ResultsTable-like window is probably the most correct (from a programming standpoint) solution suggested, and I looked around for a method to do that when I first ran into this problem.  Unfortunately, I haven't found a mechanism for this in the docs I've mentioned above.  That is, it appears to be more of a service (with one instance that appears when triggered by calls like write or setColumnHeadings) than an object which can be created and owned.  If there is a mechanism for doing this, I would like to give it a try.  There is a ResultsTable class which appears to be used to create this service, but, strangely, it has no close method.  I suppose that sometime during the creation of the one we see on the screen, it gets wrapped or embedded in a frame or window of some sort, and that is what displays and closes it.  I haven't had the time to delve into all that yet, but would appreciate pointers.



In a separate post, you give code for adding a GUI to the table.  Thank you for investing that much time into my problem!  I will try this out, but because of a busy schedule, that may not happen until next week.  However, because of the nature of my application, I am trying to streamline the UI, not add more options to it.  I'm sure this option will be helpful for others, however.



And in another post (just in), you suggest that the table can be closed if the frame is first cast as a TextWindow.  This seems to work!  It also passes the test of having the table come back again when it is called.  And in my case, it does not ask to save data first.  I think this is the missing piece to the puzzle, at least for my current application.



Summary:  casting the Frame which contains the Results table as a TextWindow, then calling TextWindow's close, seems to answer the original problem.  It would be good if there were a getTextWindow() function in WindowManager or something under it.  It would be good if there were a method which roughly consisted of the following code, as copied from EHB2010's post (thank you!):



static IJ.closeResultsWindow() {

        Frame[] arrayOfFrames = WindowManager.getNonImageWindows();
        for (int i = 0 ; i < arrayOfFrames.length ; ++i) {
                String localName = arrayOfFrames[i].getTitle();
                if ( localName.equalsIgnoreCase("Results")){
                        TextWindow tw = (TextWindow) arrayOfFrames[i];
                        tw.close();
                }
        }
}



and assuming that using this doesn't break something else in the overall ResultsTable system.




----- Original Message -----
From: "EHB2010" <[hidden email]>
To: [hidden email]
Sent: Thursday, March 18, 2010 4:37:24 AM GMT -06:00 US/Canada Central
Subject: Re: Need to close the result table from my java application

@Bob

is there a reason you need to put data into the main ResultsTable with your
plugin? I create my own instance of ResultsTable for my plugins, rather than
share one with other plugins. It seems to work, you would have complete
control over it's visibility and it allows a separate summary table etc.

E
--
View this message in context: http://n2.nabble.com/Need-to-close-the-result-table-from-my-java-application-tp4713378p4755483.html 
Sent from the ImageJ mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

EHB2010
hi bob,

it was not my code. The GUI builder did almost all of it for me.

when you say "Unfortunately, I haven't found a mechanism for this in the docs I've mentioned above" I don't quite understand. You can create as many tables as you want for your plugin. For example run this plug in (italic portion):

import ij.plugin.PlugIn;
import ij.measure.*;

public class TestPlugin_  implements PlugIn {
        public void run(String arg) {
                for (int i = 0 ; i <  100 ; ++i) {
                        ResultsTable r = new ResultsTable();
                        r.show("table number "+i);
                }
        }
}


I'm not a programmer either, not a proper scientist either- I'm on a jaunt into science from working is hospital so I'll try not to talk too much nonsense.

However, I've been writing something which sounds like it may be similar in some respects to what you are trying to do. FWIW my advice would be collect all the measurements in a HashTable/class of your own writing so that you can have it specifically configured for your needs and write a controlling Swing GUI (with a GUI builder as it's incredibly dull) as
1) the users will like it and you can make it very simple for them to do everything. You can even select the right ImageJ tool for them etc.
2) as long as the window is alive it will maintain a reference to your HashTable of results so the results aren't Garbage Collected.
3) It will sort a lot of the threading issues for you. It'll look after itself, have it's own Event Dispatching Thread and you can start new worker threads from it to do the number crunching.
4) you can include a "draw table" button/action which takes the data from your HashTable and draws a fresh ResultsTable with all the data (or resets and redraws your original one). That way you get all the good stuff about the ResultTable class, like displaying and saving etc.
5) you don't have to delve to far into the ImageJ source code. For-instance I don't know enough of the source code to be sure which bits are and aren't thread safe (if any) so I make sure that all the interactions I make with ImageJ don't require ImageJ to be thread safe.

I guess one problem is that some of the measuring/plugins you plan on using will probably save their data to ImageJ's main results table, but you could just have an "import" button on your GUI to take the data into your HashTable.

that's my take anyway. If you go for it just remember not to use "myGUIFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)", rather add your own window listener and close it down gracefully.

Bw

eerke
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

Bob Loushin
I hadn't found much documentation on the functions in the ResultsTable class (as opposed to table which pops up when you use IJ.write) because there isn't much in either the plugins tutorial or the Appendix from Burger and Burge book referenced on the ImageJ website. I hadn't looked at the ResultsTable class in the API because I felt my issue (how to close it) was higher up, in the windowing control somewhere. Now that you've pointed this out to me, I will look more in that direction. You are right--you don't have to go too far into the code, if you happen to go in the right direction. I simply hadn't gone in the right direction. Thanks for pointing that direction out to me.

Bob

----- Original Message -----
From: "EHB2010" <[hidden email]>
To: [hidden email]
Sent: Thursday, March 18, 2010 1:44:20 PM GMT -06:00 US/Canada Central
Subject: Re: Need to close the result table from my java application

hi bob,

it was not my code. The GUI builder did almost all of it for me.

when you say "Unfortunately, I haven't found a mechanism for this in the
docs I've mentioned above" I don't quite understand. You can create as many
tables as you want for your plugin. For example run this plug in (italic
portion):

import ij.plugin.PlugIn;
import ij.measure.*;

public class TestPlugin_ implements PlugIn {
public void run(String arg) {
for (int i = 0 ; i < 100 ; ++i) {
ResultsTable r = new ResultsTable();
r.show("table number "+i);
}
}
}

I'm not a programmer either, not a proper scientist either- I'm on a jaunt
into science from working is hospital so I'll try not to talk too much
nonsense.

However, I've been writing something which sounds like it may be similar in
some respects to what you are trying to do. FWIW my advice would be collect
all the measurements in a HashTable/class of your own writing so that you
can have it specifically configured for your needs and write a controlling
Swing GUI (with a GUI builder as it's incredibly dull) as
1) the users will like it and you can make it very simple for them to do
everything. You can even select the right ImageJ tool for them etc.
2) as long as the window is alive it will maintain a reference to your
HashTable of results so the results aren't Garbage Collected.
3) It will sort a lot of the threading issues for you. It'll look after
itself, have it's own Event Dispatching Thread and you can start new worker
threads from it to do the number crunching.
4) you can include a "draw table" button/action which takes the data from
your HashTable and draws a fresh ResultsTable with all the data (or resets
and redraws your original one). That way you get all the good stuff about
the ResultTable class, like displaying and saving etc.
5) you don't have to delve to far into the ImageJ source code. For-instance
I don't know enough of the source code to be sure which bits are and aren't
thread safe (if any) so I make sure that all the interactions I make with
ImageJ don't require ImageJ to be thread safe.

I guess one problem is that some of the measuring/plugins you plan on using
will probably save their data to ImageJ's main results table, but you could
just have an "import" button on your GUI to take the data into your
HashTable.

that's my take anyway. If you go for it just remember not to use
"myGUIFrame.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE)", rather add
your own window listener and close it down gracefully.

Bw

eerke

--
View this message in context: http://n2.nabble.com/Need-to-close-the-result-table-from-my-java-application-tp4713378p4758502.html 
Sent from the ImageJ mailing list archive at Nabble.com.
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

Michael Schmid
In reply to this post by Bob Loushin
Hi Bob,

the TextWindow class has a close() method. So you probably need  
something like the following:

   Frame frame = WindowManager.getFrame("Results");
   if (frame instanceof TextWindow) {
     TextWindow textWindow = (TextWindow)Frame;
     textWindow.close();
   } else {
     SOME ERROR HANDLING (either frame=null or there is a non-
TextWindow window named 'Results')
   }

TextWindow.close should take care of the rest: If the title is  
"Results", it puts the results counter to zero and clears the  
textPanel associated with the results.

Michael
________________________________________________________________

On 18 Mar 2010, at 16:34, Bob Loushin wrote:

> @Michael Schmid  Yes, close() would be a great solution, but it  
> doesn't exist, at least at the level I'm trying to get at it (Frame  
> class).
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

Rasband, Wayne (NIH/NIMH) [E]
On Mar 19, 2010, at 5:50 AM, Michael Schmid wrote:

> Hi Bob,
>
> the TextWindow class has a close() method. So you probably need  
> something like the following:
>
>   Frame frame = WindowManager.getFrame("Results");
>   if (frame instanceof TextWindow) {
>     TextWindow textWindow = (TextWindow)Frame;
>     textWindow.close();
>   } else {
>     SOME ERROR HANDLING (either frame=null or there is a non-
> TextWindow window named 'Results')
>   }
>
> TextWindow.close should take care of the rest: If the title is  
> "Results", it puts the results counter to zero and clears the  
> textPanel associated with the results.

In ImageJ 1.43s or later you can close the "Results" window using:

   TextWindow win = ResultsTable.getResultsWindow();
   if (win!=null) win.close();

or use

   TextWindow win = ResultsTable.getResultsWindow();
   if (win!=null) win.close(false);

if you do not want the "save changes" dialog to be shown.

-wayne


>
> Michael
> ________________________________________________________________
>
> On 18 Mar 2010, at 16:34, Bob Loushin wrote:
>
>> @Michael Schmid  Yes, close() would be a great solution, but it  
>> doesn't exist, at least at the level I'm trying to get at it (Frame  
>> class).
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

Bob Loushin
Thanks, Wayne!

--------------------------------------------------
From: "Rasband, Wayne (NIH/NIMH) [E]" <[hidden email]>
Sent: Saturday, March 20, 2010 1:10 PM
To: <[hidden email]>
Subject: Re: Need to close the result table from my java application

> On Mar 19, 2010, at 5:50 AM, Michael Schmid wrote:
>
>> Hi Bob,
>>
>> the TextWindow class has a close() method. So you probably need  
>> something like the following:
>>
>>   Frame frame = WindowManager.getFrame("Results");
>>   if (frame instanceof TextWindow) {
>>     TextWindow textWindow = (TextWindow)Frame;
>>     textWindow.close();
>>   } else {
>>     SOME ERROR HANDLING (either frame=null or there is a non-
>> TextWindow window named 'Results')
>>   }
>>
>> TextWindow.close should take care of the rest: If the title is  
>> "Results", it puts the results counter to zero and clears the  
>> textPanel associated with the results.
>
> In ImageJ 1.43s or later you can close the "Results" window using:
>
>   TextWindow win = ResultsTable.getResultsWindow();
>   if (win!=null) win.close();
>
> or use
>
>   TextWindow win = ResultsTable.getResultsWindow();
>   if (win!=null) win.close(false);
>
> if you do not want the "save changes" dialog to be shown.
>
> -wayne
>
>
>>
>> Michael
>> ________________________________________________________________
>>
>> On 18 Mar 2010, at 16:34, Bob Loushin wrote:
>>
>>> @Michael Schmid  Yes, close() would be a great solution, but it  
>>> doesn't exist, at least at the level I'm trying to get at it (Frame  
>>> class).
>
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

Md Tamjidul Hoque
In reply to this post by Rasband, Wayne (NIH/NIMH) [E]
Many thanks Wayne.

- Tamjid

Rasband, Wayne (NIH/NIMH) [E] wrote:

> On Mar 19, 2010, at 5:50 AM, Michael Schmid wrote:
>
>  
>> Hi Bob,
>>
>> the TextWindow class has a close() method. So you probably need  
>> something like the following:
>>
>>   Frame frame = WindowManager.getFrame("Results");
>>   if (frame instanceof TextWindow) {
>>     TextWindow textWindow = (TextWindow)Frame;
>>     textWindow.close();
>>   } else {
>>     SOME ERROR HANDLING (either frame=null or there is a non-
>> TextWindow window named 'Results')
>>   }
>>
>> TextWindow.close should take care of the rest: If the title is  
>> "Results", it puts the results counter to zero and clears the  
>> textPanel associated with the results.
>>    
>
> In ImageJ 1.43s or later you can close the "Results" window using:
>
>    TextWindow win = ResultsTable.getResultsWindow();
>    if (win!=null) win.close();
>
> or use
>
>    TextWindow win = ResultsTable.getResultsWindow();
>    if (win!=null) win.close(false);
>
> if you do not want the "save changes" dialog to be shown.
>
> -wayne
>
>
>  
>> Michael
>> ________________________________________________________________
>>
>> On 18 Mar 2010, at 16:34, Bob Loushin wrote:
>>
>>    
>>> @Michael Schmid  Yes, close() would be a great solution, but it  
>>> doesn't exist, at least at the level I'm trying to get at it (Frame  
>>> class).
>>>      
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

Md Tamjidul Hoque
In reply to this post by Rasband, Wayne (NIH/NIMH) [E]
Hi Wayne

            Problem #1:
            ========
             with the following line the result-table window is now
suddenly reappearing (which was not happening before with the same code
same ImageJ version) in my java application and I do not want it be
displayed:
             .......
            Line# X:  IJ.run("Set Measurements...", "  redirect=None
decimal=2"); // This is just to minimize the possible computation and
insertion of the computed result into the ResultTable.
            ........
            interestingly the result-table shows the previous run
results (expect in the case where ImageJ is just been reloaded) - as the
above line is called before any calculation - so just thought to report

            this assuming there might be a bug.

            Also, if I turn off the above line then things are all ok
(i.e. the result-table window is not dispalyed), though I call the
following line at the middle of the code later:

           Line# Y: IJ.run("Set Measurements...", "area mean min shape
redirect=None decimal=9");


           Problem #2:
           ========
            To turn off the ResultWindow I am using the following code
as you advised before:
   

          TextWindow win = ResultsTable.getResultsWindow();
          if (win!=null) win.close(false);


           But, within my batch mode java application (where noting is
displayed per operations) - the screen is blinking (due to close it as
early as possible but the same procedure is in a loop) very
           badly. Could there a better option, such as setting the
resultTable  window invisible or so?
     

Thanks
Tamjid

 
Rasband, Wayne (NIH/NIMH) [E] wrote:

> On Mar 19, 2010, at 5:50 AM, Michael Schmid wrote:
>
>  
>> Hi Bob,
>>
>> the TextWindow class has a close() method. So you probably need  
>> something like the following:
>>
>>   Frame frame = WindowManager.getFrame("Results");
>>   if (frame instanceof TextWindow) {
>>     TextWindow textWindow = (TextWindow)Frame;
>>     textWindow.close();
>>   } else {
>>     SOME ERROR HANDLING (either frame=null or there is a non-
>> TextWindow window named 'Results')
>>   }
>>
>> TextWindow.close should take care of the rest: If the title is  
>> "Results", it puts the results counter to zero and clears the  
>> textPanel associated with the results.
>>    
>
> In ImageJ 1.43s or later you can close the "Results" window using:
>
>    TextWindow win = ResultsTable.getResultsWindow();
>    if (win!=null) win.close();
>
> or use
>
>    TextWindow win = ResultsTable.getResultsWindow();
>    if (win!=null) win.close(false);
>
> if you do not want the "save changes" dialog to be shown.
>
> -wayne
>
>
>  
>> Michael
>> ________________________________________________________________
>>
>> On 18 Mar 2010, at 16:34, Bob Loushin wrote:
>>
>>    
>>> @Michael Schmid  Yes, close() would be a great solution, but it  
>>> doesn't exist, at least at the level I'm trying to get at it (Frame  
>>> class).
>>>      
>
>  
Reply | Threaded
Open this post in threaded view
|

Re: Need to close the result table from my java application

Md Tamjidul Hoque
Ok, to solve problem #2 (may be temporarily), I am using

... win.setVisible(false); //  it will be in a loop unfortunately

in the first place and

... win.close(false);

at the end.

Any suggestion is welcome.

- Tamjid

Md Tamjidul Hoque wrote:

> Hi Wayne
>
>             Problem #1:
>             ========
>              with the following line the result-table window is now
> suddenly reappearing (which was not happening before with the same
> code same ImageJ version) in my java application and I do not want it
> be displayed:
>              .......
>             Line# X:  IJ.run("Set Measurements...", "  redirect=None
> decimal=2"); // This is just to minimize the possible computation and
> insertion of the computed result into the ResultTable.
>             ........
>             interestingly the result-table shows the previous run
> results (expect in the case where ImageJ is just been reloaded) - as
> the above line is called before any calculation - so just thought to
> report
>
>             this assuming there might be a bug.
>
>             Also, if I turn off the above line then things are all ok
> (i.e. the result-table window is not dispalyed), though I call the
> following line at the middle of the code later:
>
>            Line# Y: IJ.run("Set Measurements...", "area mean min shape
> redirect=None decimal=9");
>
>
>            Problem #2:
>            ========
>             To turn off the ResultWindow I am using the following code
> as you advised before:
>    
>           TextWindow win = ResultsTable.getResultsWindow();
>           if (win!=null) win.close(false);
>
>            But, within my batch mode java application (where noting is
> displayed per operations) - the screen is blinking (due to close it as
> early as possible but the same procedure is in a loop) very
>            badly. Could there a better option, such as setting the
> resultTable  window invisible or so?
>      
>
> Thanks
> Tamjid
>
>  
> Rasband, Wayne (NIH/NIMH) [E] wrote:
>> On Mar 19, 2010, at 5:50 AM, Michael Schmid wrote:
>>
>>  
>>> Hi Bob,
>>>
>>> the TextWindow class has a close() method. So you probably need  
>>> something like the following:
>>>
>>>   Frame frame = WindowManager.getFrame("Results");
>>>   if (frame instanceof TextWindow) {
>>>     TextWindow textWindow = (TextWindow)Frame;
>>>     textWindow.close();
>>>   } else {
>>>     SOME ERROR HANDLING (either frame=null or there is a non-
>>> TextWindow window named 'Results')
>>>   }
>>>
>>> TextWindow.close should take care of the rest: If the title is  
>>> "Results", it puts the results counter to zero and clears the  
>>> textPanel associated with the results.
>>>    
>>
>> In ImageJ 1.43s or later you can close the "Results" window using:
>>
>>    TextWindow win = ResultsTable.getResultsWindow();
>>    if (win!=null) win.close();
>>
>> or use
>>
>>    TextWindow win = ResultsTable.getResultsWindow();
>>    if (win!=null) win.close(false);
>>
>> if you do not want the "save changes" dialog to be shown.
>>
>> -wayne
>>
>>
>>  
>>> Michael
>>> ________________________________________________________________
>>>
>>> On 18 Mar 2010, at 16:34, Bob Loushin wrote:
>>>
>>>    
>>>> @Michael Schmid  Yes, close() would be a great solution, but it  
>>>> doesn't exist, at least at the level I'm trying to get at it (Frame  
>>>> class).
>>>>      
>>
>>  
>