Bug #3471


custom input boxes in actor configuration dialog

Added by Matt Jones over 15 years ago. Updated over 15 years ago.

Target version:
Start date:
Due date:
% Done:


Estimated time:


Report from Peter Reutemann:

I've encountered a similar problem as mentioned in the following thread:

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 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.

~ addStyledEntry(Settable)

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

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

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:

There are several files available for download from this web page:
contains patches for the Query/PtolemyQuery classes
(run against subversion repository August 14, 2008)
additional classes/interfaces necessary for my proposed changes
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. ;-)

Actions #1

Updated by Christopher Brooks over 15 years ago

I folded the Ptolemy changes in to the Ptolemy Tree.
One issue is that one of the files in the example code from
need to be in

I tried to put QueryInputDialogChooser into ptolemy/actor/gui/test,
but compilation fails because that class uses some package protected inner
classes in

CLASSPATH="../../../.." "/usr/bin/javac" -g -O
../../../../ptolemy/actor/gui/test/ ptolemy.gui.Query.QueryActionListener is not public in ptolemy.gui.Query; cannot be accessed from outside package
_entryBox.addActionListener( QueryActionListener(name));
../../../../ptolemy/actor/gui/test/ ptolemy.gui.Query.QueryFocusListener is not public in ptolemy.gui.Query; cannot be accessed from outside package
_entryBox.addFocusListener( QueryFocusListener(name));
../../../../ptolemy/actor/gui/test/ _notifyListeners(java.lang.String) is not public in ptolemy.gui.Query; cannot be accessed from outside package

The obvious thing is to make the package protected code non-package protected.
There are probably other, more elegant solutions though.

Actions #2

Updated by Christopher Brooks over 15 years ago

There is more to the thread at

One issue is that data.expr.CustomQueryBoxParameter imports
and thus means that data.expr depends on actor.gui.

On August 15, I folded changes in:

2008-08-15 18:40 cxh

  • [r50436] /trunk/ptolemy/actor/gui/,
    /trunk/ptolemy/data/expr/makefile, /trunk/ptolemy/gui/,
    /trunk/ptolemy/gui/makefile: Peter Reutemann: Custom query boxes
    in Kepler/Ptolemy. See

On August 16, Edward pointed out:

There is no need to modify the underlying framework to do this.
Just put a subclass of
(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.

On August 16, Peter responded with

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

On August 17, Peter wrote:
[Edward wrote:]

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:

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)


- 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).

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

Files mentioned above are available for download from this link:

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

Cheers, Peter


I'm going to try to fold in Peter's second set of changes and see what happens.

Actions #3

Updated by Christopher Brooks over 15 years ago

I'm closing this one, I checked in Peter's latest code.
I moved CustomQueryBoxParameter from data.expr to actor.gui
I added actor/gui/CustomQueryExample.tar.gz which uses Peter's
example code of how to create a CustomQuery with classes outside of the ptII tree.

Actions #4

Updated by Redmine Admin almost 11 years ago

Original Bugzilla ID was 3471


Also available in: Atom PDF