Login  Register

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

Posted by Bob Loushin on Mar 18, 2010; 3:34pm
URL: http://imagej.273.s1.nabble.com/Need-to-close-the-result-table-from-my-java-application-tp3687988p3687989.html

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.