[kepler-dev] Actor Parameter question
berkley at nceas.ucsb.edu
Tue Oct 16 12:26:09 PDT 2007
Sorry I missed you on IRC. I'm on pacific time so 6 am is a little
early :) Most of our developers on the west coast so we'll usually be
on IRC from 9ish am - 5ish pm.
For an example of this, take a look at
kepler/src/actors/Scatterplot/Scatterplot.xml. There's a property near
the bottom called "expression". Within that property is a nested
property that defines the style for the property editor.
value="plot(Independent, Dependent) ">
<property name="R Expression"
ptolemy.actor.gui.style.TextStyle just renders the editor in the config
dialog as a JTextArea instead of a JTextField. The height and width sub
properties tell it how big to make the JTextArea. If you run kepler and
drag a Scatterplot actor onto the canvas, then configure it, you'll see
the expression param is, in fact, a JTextArea.
So if you want to do something similar, there are two ways to go about
it, depending on how you're writing your actor. The first is if you are
coding the parameter into the moml description. You basically do the
same thing that Scatterplot did. The other way is if you want to
programmatically add the property to your actor in the Java code. The
way to do this is to create a new Attribute of the type you want (i.e.
StringAttribute) then add an attribute to that that names the style.
The code would look something like this and would go in your actors
//'this' here is your actor
Attribute a = new Attribute(this, "My new attribute");
//the container for the TextStyle is Attribute 'a'
TextStyle ts = new TextStyle(a, "Text Style");
//the container for the Parameter height is TextStyle 'ts'
Parameter height = new Parameter(ts, "height");
ts.height = height;
Parameter width = new Parameter(ts, "width");
ts.width = width;
If you didn't want to use the TextStyle, you could create your own by
overriding ptolemy.actor.gui.style.ParameterEditorStyle and set it in a
Hope that helps.
Eric Magaha wrote:
> A little confusing. I don't have access to irc.
> I looked at an actor that reads a file i.e. org.geon.BinaryFileReader.
> I looked at the code and it uses a FileParameter which extends
> StringParameter. I don't see anything about style at all.
> I did find the style classes i.e.
> ptolemy.actor.gui.style.FileChooserStyle. I can't see where it is
> referenced though.
> Can you provide more info? I think ChoiceStyle may work for me. But I
> don't know how to do this.
> On 10/15/07, *Chad Berkley* <berkley at nceas.ucsb.edu
> <mailto:berkley at nceas.ucsb.edu>> wrote:
> Hi Eric,
> If I understand you right, you just want to change the editor in the
> configuration window, right? If so, you'll want to extend
> ptolemy.actor.gui.style.ParameterEditorStyle. Once you have a new
> of editor widget, you can then set the "style" attribute on any moml
> parameter to use your new editor. If you want an example, search the
> actor library for any actor that uses one of the styles in
> ptolemy.actor.gui.style. For instance, there are several that use the
> FileChooser style to allow a user to select a file path into a
> StringAttribute. Instead of creating your own style, one of the
> existing styles may work for what you want (possibly ChoiceStyle?).
> If that's confusing, login to IRC and I can explain further.
> Eric Magaha wrote:
> > Hi,
> > I would like to create a Parameter on one of my custom actor that is
> > similar to ColorAttribute ( ptolemy.actor.gui.ColorAttribute). But I
> > want to be able to pick string items from a list in the dialog
> box that
> > will be shown.
> > I looked at ColorAttribute class and I have no idea how Query class
> > (ptolemy.gui.Query) gets called. ColorAttribute class is pretty
> > To sum up, I want a parameter that holds an ArrayType that can open a
> > dialog box where I can select string from a swing list object.
> > Is that possible?
> > Thanks,
> > Eric
> > _______________________________________________
> > Kepler-dev mailing list
> > Kepler-dev at ecoinformatics.org <mailto:Kepler-dev at ecoinformatics.org>
More information about the Kepler-dev