custom query boxes in Ptolemy/Kepler

3 views
Skip to first unread message

Peter Reutemann

unread,
Aug 14, 2008, 5:54:06 PM8/14/08
to Ptolemy Hackers
Hi there

I've encountered a similar problem as mentioned in the following thread:
http://groups.google.com/group/comp.soft-sys.ptolemy/browse_thread/thread/dc4c136eb6870d10/75e79a2afd7cc9ab

Though using Kepler, I needed to modify the underlying Ptolemy
framework in order to allow custom input boxes in actor dialogs. But
instead of hacking the ptolemy.gui.Query and
ptolemy.actor.gui.PtolemyQuery classes whenever I'd need another
custom query box, I modified those two classes (and added
classes/interfaces) to make it a bit more flexible.

In order to get a new query box into Ptolemy, you need to modify the
following places:
- ptolemy.gui.Query
~ set(String,String)
~ getStringValue(String)

in those two methods the type of custom query chooser, e.g.,
QueryColorChooser is used to determine how to obtain/set the
string representation.

- ptolemy.actor.gui.PtolemyQuery
~ addStyledEntry(Settable)

here the type of Parameter defines what query chooser is added
for the attribute, e.g., a QueryColorChooser in case of a
ColorAttribute.

To decouple this a bit, I've come up with an interface called
"CustomQueryBoxParameter", to be implemented by types derived from
Parameter that need a custom query box. The interface consists of only
one method:
javax.swing.Box createQueryBox(PtolemyQuery query, Settable att)
This method returns a custom query box (fully configured), based on
the current query and attribute this query belongs to. This swing
element contains all the necessary logic to manipulate the data, e.g.,
a button for popping up another dialog, etc. The addStyledEntry method
of the PtolemyQuery class obtains a box from an attribute implementing
CustomQueryBoxParameter and attaches it (via the _addPair method).

The query box being returned, is a custom class derived from
javax.swing.Box, which implements another interface called
"SettableQueryChooser". This interface is used in the
set/getStringValue methods of ptolemy.gui.Query to set/get the current
string value. The actual query chooser class turns that into whatever
internal representation it uses. This interface avoids having to add
new logic to the Query class, whenever a new custom QueryChooser is
implemented.

Since I'm apparently not the only user who encountered this problem,
I'd like to contribute my code (which will hopefully trickle down to
Kepler at one stage, in case it gets accepted). Not exactly sure how
contributions work around here.

Note: my original post *with* attachments didn't come through
apparently (never showed up in the Google group), you can find my
original post including the attachments on my homepage:
http://www.scms.waikato.ac.nz/~fracpete/downloads/ptolemy/custom_query_boxes/

There are several files available for download from this web page:
- ptolemy-patch.zip
contains patches for the Query/PtolemyQuery classes
(run against subversion repository August 14, 2008)
- ptolemy-additional_classes.zip
additional classes/interfaces necessary for my proposed changes
- examples-classes.zip
contains a simple actor that uses a custom query box with a button
that pops up a JOptionPane for the user to enter some text; this is
just to demonstrate how the slightly modified framework would work
- examples.kar
a kepler archive - I know, this is not exactly the right place, but
I thought some Kepler people/developers read this mailing list as well
and might be interested in this

Hopefully, my ramblings made some sense, otherwise the code hopefully
speaks for itself. ;-)

Cheers, Peter
--
Peter Reutemann, Dept. of Computer Science, University of Waikato, NZ
http://www.cs.waikato.ac.nz/~fracpete/ Ph. +64 (7) 858-5174

----------------------------------------------------------------------------
Posted to the ptolemy-hackers mailing list. Please send administrative
mail for this list to: ptolemy-hac...@ptolemy.eecs.berkeley.edu

Matt Jones

unread,
Aug 15, 2008, 12:08:18 PM8/15/08
to Peter Reutemann, Ptolemy Hackers, kepler-dev

Edward A. Lee

unread,
Aug 16, 2008, 12:40:14 PM8/16/08
to Matt Jones, Peter Reutemann, Ptolemy Hackers, kepler-dev

There is no need to modify the underlying framework to do this.
Just put a subclass of ptolemy.actor.gui.ParameterEditorStyle
(an attribute) inside the attribute that you want a custom input
box for. Your subclass can implement that custom input box,
and it will automatically appear in the query box. This is how
the style preferences currently there are implemented.

Edward

At 09:08 AM 8/15/2008, Matt Jones wrote:
>Hi Peter,
>
>Thanks for your report. I've added your feature request to our bug list for kepler 1.1.0, and will try to get someone to review your code changes and fold them into svn.
>
><http://bugzilla.ecoinformatics.org/show_bug.cgi?id=3471>http://bugzilla.ecoinformatics.org/show_bug.cgi?id=3471
>
>Thanks,
>
>Matt


>
>On Thu, Aug 14, 2008 at 1:54 PM, Peter Reutemann <<mailto:frac...@waikato.ac.nz>frac...@waikato.ac.nz> wrote:
>Hi there
>
>I've encountered a similar problem as mentioned in the following thread:

> <http://groups.google.com/group/comp.soft-sys.ptolemy/browse_thread/thread/dc4c136eb6870d10/75e79a2afd7cc9ab>http://groups.google.com/group/comp.soft-sys.ptolemy/browse_thread/thread/dc4c136eb6870d10/75e79a2afd7cc9ab

> <http://www.scms.waikato.ac.nz/%7Efracpete/downloads/ptolemy/custom_query_boxes/>http://www.scms.waikato.ac.nz/~fracpete/downloads/ptolemy/custom_query_boxes/


>
>There are several files available for download from this web page:
>- ptolemy-patch.zip
> contains patches for the Query/PtolemyQuery classes
> (run against subversion repository August 14, 2008)
>- ptolemy-additional_classes.zip
> additional classes/interfaces necessary for my proposed changes
>- examples-classes.zip
> contains a simple actor that uses a custom query box with a button
> that pops up a JOptionPane for the user to enter some text; this is
> just to demonstrate how the slightly modified framework would work
>- examples.kar
> a kepler archive - I know, this is not exactly the right place, but
> I thought some Kepler people/developers read this mailing list as well
> and might be interested in this
>
>Hopefully, my ramblings made some sense, otherwise the code hopefully
>speaks for itself. ;-)
>
>Cheers, Peter
>--
>Peter Reutemann, Dept. of Computer Science, University of Waikato, NZ

><http://www.cs.waikato.ac.nz/%7Efracpete/>http://www.cs.waikato.ac.nz/~fracpete/ Ph. +64 (7) 858-5174


>
>----------------------------------------------------------------------------
>Posted to the ptolemy-hackers mailing list. Please send administrative

>mail for this list to: <mailto:ptolemy-hac...@ptolemy.eecs.berkeley.edu>ptolemy-hac...@ptolemy.eecs.berkeley.edu
>
>
>
>
>--
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
>Matthew B. Jones
>Director of Informatics Research and Development
>National Center for Ecological Analysis and Synthesis (NCEAS)
>UC Santa Barbara
><mailto:jo...@nceas.ucsb.edu>jo...@nceas.ucsb.edu Ph: 1-907-523-1960
><http://www.nceas.ucsb.edu/ecoinfo>http://www.nceas.ucsb.edu/ecoinfo
>~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

------------
Edward A. Lee
Robert S. Pepper Distinguished Professor
EECS Dept., 545Q Cory Hall, UC Berkeley, Berkeley, CA 94720-1770
phone: 510-643-3728, fax: 510-642-5745
e...@eecs.Berkeley.EDU, http://www.eecs.berkeley.edu/Faculty/Homepages/lee.html

Peter Reutemann

unread,
Aug 17, 2008, 12:30:46 AM8/17/08
to Ptolemy Hackers, kepler-dev, Matt Jones
> There is no need to modify the underlying framework to do this.
> Just put a subclass of ptolemy.actor.gui.ParameterEditorStyle
> (an attribute) inside the attribute that you want a custom input
> box for. Your subclass can implement that custom input box,
> and it will automatically appear in the query box. This is how
> the style preferences currently there are implemented.

Taking the FileChooserStyle as example: it calls the public
addFileChooser method of the Query class in order to be able to add
the JLabel and the QueryFileChooser box via the protected _addPair
method. Unless I'm willing to modify the Query class (adding another
public addXYZ method), I'm not able to add my own custom box outside
the ptolemy.gui package, right? And wouldn't it be also necessary to
add my own style class to the _parameterStyles member of the
ptolemy.actor.gui.style.StyleConfigurer?

Peter Reutemann

unread,
Aug 17, 2008, 11:42:56 PM8/17/08
to Edward A. Lee, Ptolemy Hackers, kepler-dev, Matt Jones
> I guess the right solution would be to add a public method like
> addPair(), which would use _addPair(), but this would be tricky
> to get right. In particular, _addPair() populates the _entries
> hashtable with objects, and I'm not sure what would be the right
> sort of object to provide for a completely custom entry...
> There might be other gotcha's as well.
>
> Unfortunately, I don't have bandwidth for this sort of thing
> right now, but if you want to take a stab at modifying the Query
> class, I would be happy to take a look...

I had another go at the ptolemy.qui.Query class and my previous
modifications, once again based on today's subversion repository. See
link at end of post for downloads.

This post is also in response to Christopher's feedback:
http://mercury.nceas.ucsb.edu/ecoinformatics/pipermail/kepler-dev/2008-August/006533.html

Here are the additional modifications:
- All inner classes of ptolemy.qui.Query are now public and static,
in case one needs to use, e.g., a QueryActionListener in a package
outside ptolemy.gui. They all contain a private member "_owner"
of type ptolemy.gui.Query.

--> ptolemy.gui.Query.diff

- An additional abstract superclass ptolemy.gui.QueryChooser
(derived from javax.swing.Box) which enables derived classes to
call _addPair and _notifyListeners of the ptolemy.gui.Query class,
even if they're outside the ptolemy.gui package.
(the QueryInputDialogChooser in the example below is now derived
from this class)

--> ptolemy-additional_classes.zip

- Updated example to demonstrate the changes. This time, there are
no classes in the ptolemy... package hierarchy anymore. The example
contains a simple actor with a parameter consisting of a text field
and a button to pop up a dialog for entering a string (which is
then displayed in the text field).

--> examples.zip (example classes)
examples.kar (Kepler archive)

Files mentioned above are available for download from this link:
http://www.scms.waikato.ac.nz/~fracpete/downloads/ptolemy/custom_query_boxes2/

Hopefully, this all makes sense to you... ;-)

Reply all
Reply to author
Forward
0 new messages