[kepler-dev] Icons within Kepler

Christopher Brooks cxh at eecs.berkeley.edu
Thu Sep 23 13:16:30 PDT 2010


Hi Michal,
See section 5.7 of Volume 1 of the Ptolemy Design Doc at
http://ptolemy.eecs.berkeley.edu/ptolemyII/designdoc.htm

On 9/23/10 2:32 AM, Michal Owsiak wrote:
> Hello all,
>
> I have few questions related to icons management within Kepler.
>
> I am trying to set actor's Icon and I am using following way to set it:
>
> _attachText("_iconDescription", "<svg>\n"
> + "<rect x=\"-20\" y=\"-15\" " + "width=\"40\" height=\"30\" "
> + "style=\"fill:lightGrey\"/>\n" + "<rect x=\"-15\" y=\"-10\" "
> + "width=\"30\" height=\"20\" " + "style=\"fill:white\"/>\n"
> + "<line x1=\"-13\" y1=\"-6\" x2=\"-4\" y2=\"-6\" "
> + "style=\"stroke:grey\"/>\n"
> + "<line x1=\"-13\" y1=\"-2\" x2=\"0\" y2=\"-2\" "
> + "style=\"stroke:grey\"/>\n"
> + "<line x1=\"-13\" y1=\"2\" x2=\"-8\" y2=\"2\" "
> + "style=\"stroke:grey\"/>\n"
> + "<line x1=\"-13\" y1=\"6\" x2=\"4\" y2=\"6\" "
> + "style=\"stroke:grey\"/>\n" + "</svg>\n");
>
> I'd like to have the same icon as Display actor has.
>
> Is it mandatory to subclass from certain class in order to use this method for setting actor's icon?

_iconDescription is an annotation that is added to the actor and then
read by vergil to display the icon.  So, you need not extend any particular class.

When I search ptII for _iconDescription, I see ptolemy.vergil.icon.XMLIcon uses it, so
take a look at that file.

>
> Another question is:
>
> How can I refer to icons that are contained within kepler-icons.jar? Is it possible to retrieve them through the Kepler engine? Are they stored somewhere and are accessible via class/icon name?

There are at least two ways that icons are stored:
1) the _iconDescription attribute
2) some classes have a separate .xml file.  For example ptolemy/actor/lib/Accumulator.java
has AccumulatorIcon.xml.
Search the tree for Icon.xml.  MoMLParser does something with Icon.xml

Icons can also be image files or pdfs.

I don't have kepler-icons.jar.  Are the icon files .xml files?

> Another question is. I'd like to set JFrame icon to the icon that is used by Kepler itself using setIconImage. However, I don't know how to refer to this icon.

This would probably be an image file, not an xml file.

I'm not sure if this would work, but you can search for things in the classpath
See java ClassLoader.getResource.  See also ptolemy.util.FileUtilities, there are methods
that access things in the Classpath.  I vaguely remember that Kepler has other
ways of getting resources, try the Kepler website.

>
> How can I retrieve Image object for the icon that is used for main Kepler windows? How can I find it's (icon's) package name?

   cd ~/src/kepler
   find . -name "*.gif"
yields
./common/configs/ptolemy/configs/kepler/KeplerSmallIcon.gif

I'm not sure, but I think getResource("ptolemy/configs/kepler/KeplerSmallIcon.gif")
might do it.

Searching the web for
   java Image getResource
yields
   http://download.oracle.com/javase/tutorial/uiswing/components/icon.html

   find . -name "*.png"
yields
   ./common/resources/images/KeplerLogoNew.png

Running
   find . -name "*.java" > /tmp/j
   cat /tmp/j | xargs grep KeplerLogo
Indicates that KeplerLogoNew.png is used here:
./gui/src/org/kepler/gui/WelcomeScreen.java:						+ "common/resources/images/KeplerLogoNew.png";

I'm not sure about how resources are found in Kepler.

>
> And the last question. If I want to add new icon into Kepler how should I proceed if I don't want to put the icon into kepler-icons.jar? Is there any way to do that?

In Ptolemy, if the icon is an image file then you can use getResource() and find it
via the classpath.

Hope this helps,

_Christopher
>
> Thanks in advance
>
> Cheers
>
> Michal
>

-- 
Christopher Brooks, PMP                       University of California
CHESS Executive Director                      US Mail: 337 Cory Hall
Programmer/Analyst CHESS/Ptolemy/Trust        Berkeley, CA 94720-1774
ph: 510.643.9841 fax:510.642.2718	      (Office: 545Q Cory)
home: (F-Tu) 707.665.0131 cell: 707.332.0670


More information about the Kepler-dev mailing list