Hi all,
I'm writing a Jython script to do some measurements, and save the results, and need the capability to prompt the user for a date (in addition to sample ID, etc.). Does anyone have or know of a simple date chooser that would work with the AWT toolkit included with ImageJ? I could add 3 "drop-downs" for year, month, and day to a generic dialog, but I'd really like to find something like a single jar file with a calendar-style display implemented in Java/AWT, that I could simply import and use. Thanks, *-- Jim Passmore* Research Associate Sealed Air Corporation -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Hi Jim,
Maybe the Clock.txt macro in the IJ resources/macro directory would give you some inspiration? Best Gareth |
In reply to this post by Jim Passmore-2
Googling "Java Date Chooser" and following one or two links yields this:
http://www.roseindia.net/tutorial/java/swing/datePicker.html It's functional more than it is pretty. Shouldn't take much to adapt to your needs. -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
In reply to this post by Jim Passmore-2
Hi Jim,
> Does anyone have or know of a simple date chooser that would work with > the AWT toolkit included with ImageJ? For what it's worth, I just added support for java.util.Date objects to ImageJ2 [1]. So now in an ImageJ2 command you can write: @Parameter private Date myDate; ...and it will be automatically harvested from the user before the command is executed. (See the HelloWorld example [2] for an intro to ImageJ2 commands.) The support uses JDatePicker [3], which provides a fairly simple Swing widget (i.e., compatible with AWT) for selecting dates. The project is a single JAR file with no dependencies, and available from Maven Central. Of course, I know this doesn't help you directly with a Jython script intended for use in ImageJ1. But I wanted to let you know that you inspired an improvement to ImageJ2, which will make this sort of thing easier in the future. Regards, Curtis [1] https://github.com/imagej/imagej/commit/17416aa74557f2f06a5233538920ba74c50f7def [2] https://github.com/imagej/imagej-tutorials/blob/master/simple-commands/src/main/java/HelloWorld.java [3] http://jdatepicker.org/ On Mon, Sep 30, 2013 at 7:31 PM, Jim Passmore <[hidden email]> wrote: > Hi all, > I'm writing a Jython script to do some measurements, and save the results, > and need the capability to prompt the user for a date (in addition to > sample ID, etc.). > > Does anyone have or know of a simple date chooser that would work with the > AWT toolkit included with ImageJ? I could add 3 "drop-downs" for year, > month, and day to a generic dialog, but I'd really like to find something > like a single jar file with a calendar-style display implemented in > Java/AWT, that I could simply import and use. > > Thanks, > > *-- > Jim Passmore* > Research Associate > Sealed Air Corporation > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Curtis,
> The support uses JDatePicker [3], which provides a fairly simple Swing > widget (i.e., compatible with AWT) for selecting dates. The project is a > single JAR file with no dependencies, and available from Maven Central. A bit of a delay, but I wanted to thank you for this link. I had looked at several Java "date pickers" but hadn't found one as simple to drop in and use as this one. > > Of course, I know this doesn't help you directly with a Jython script > intended for use in ImageJ1. But I wanted to let you know that you inspired > an improvement to ImageJ2, which will make this sort of thing easier in the > future. > ... > [3] http://jdatepicker.org/ Actually, it *did* help directly. I put the jar into my Fiji.app/jars directory, then was able to call it in jython. Works like a charm. I've copied example code below in case someone wants to use it, or adapt to one of the other scripting languages. (Watch for line breaks!) Thanks again, Jim ======================================================== from javax.swing import JFrame from net.sourceforge.jdatepicker import JDateComponentFactory class DatePicker(JFrame): def __init__(self, win_title): self.panel = JDateComponentFactory().createJDatePanel() self.panel.setShowYearButtons(True) self.getContentPane().add(self.panel) self.setTitle(win_title) self.setSize(300,250) self.setAlwaysOnTop(True) def get_date(self): months = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'] self.setVisible(True) while self.isShowing(): day, month, year = self.panel.getModel().getDay(), self.panel.getModel().getMonth(), self.panel.getModel().getYear() self.dispose() return str(day) + '-' + months[month] + '-' + str(year) if __name__ == '__main__': my_date = DatePicker('Date collected') print "date = " + my_date.get_date() ======================================================== On Tue, Oct 1, 2013 at 11:53 AM, Curtis Rueden <[hidden email]> wrote: > > Hi Jim, > > > Does anyone have or know of a simple date chooser that would work with > > the AWT toolkit included with ImageJ? > > For what it's worth, I just added support for java.util.Date objects to > ImageJ2 [1]. So now in an ImageJ2 command you can write: > > @Parameter > private Date myDate; > > ...and it will be automatically harvested from the user before the command > is executed. (See the HelloWorld example [2] for an intro to ImageJ2 > commands.) > > The support uses JDatePicker [3], which provides a fairly simple Swing > widget (i.e., compatible with AWT) for selecting dates. The project is a > single JAR file with no dependencies, and available from Maven Central. > > Of course, I know this doesn't help you directly with a Jython script > intended for use in ImageJ1. But I wanted to let you know that you inspired > an improvement to ImageJ2, which will make this sort of thing easier in the > future. > > Regards, > Curtis > > [1] > https://github.com/imagej/imagej/commit/17416aa74557f2f06a5233538920ba74c50f7def > [2] > https://github.com/imagej/imagej-tutorials/blob/master/simple-commands/src/main/java/HelloWorld.java > [3] http://jdatepicker.org/ > > > On Mon, Sep 30, 2013 at 7:31 PM, Jim Passmore <[hidden email]> wrote: > > > Hi all, > > I'm writing a Jython script to do some measurements, and save the results, > > and need the capability to prompt the user for a date (in addition to > > sample ID, etc.). > > > > Does anyone have or know of a simple date chooser that would work with the > > AWT toolkit included with ImageJ? I could add 3 "drop-downs" for year, > > month, and day to a generic dialog, but I'd really like to find something > > like a single jar file with a calendar-style display implemented in > > Java/AWT, that I could simply import and use. > > > > Thanks, > > > > *-- > > Jim Passmore* > > Research Associate > > Sealed Air Corporation > > > > -- > > ImageJ mailing list: http://imagej.nih.gov/ij/list.html > > > > -- > ImageJ mailing list: http://imagej.nih.gov/ij/list.html -- ImageJ mailing list: http://imagej.nih.gov/ij/list.html |
Free forum by Nabble | Edit this page |