ptolemy.vergil.icon
Class SVGIcon

java.lang.Object
  extended by ptolemy.kernel.util.NamedObj
      extended by ptolemy.kernel.util.Attribute
          extended by ptolemy.vergil.icon.EditorIcon
              extended by ptolemy.vergil.icon.SVGIcon
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, Changeable, Debuggable, DebugListener, Derivable, ModelErrorHandler, MoMLExportable, Moveable, Nameable, ValueListener

public class SVGIcon
extends EditorIcon
implements ValueListener

This class is intended to eventually replace XMLIcon, however, the current version doesn't work very well, so it isn't used.

Since:
Ptolemy II 4.0
Version:
$Id: SVGIcon.java 57040 2010-01-27 20:52:32Z cxh $
Author:
Edward A. Lee
See Also:
Serialized Form
Accepted Rating:
Red (johnr)
Proposed Rating:
Yellow (eal)

Nested Class Summary
 
Nested classes/interfaces inherited from class ptolemy.kernel.util.NamedObj
NamedObj.ContainedObjectsIterator
 
Field Summary
private  ConfigurableAttribute _description
           
private  ConfigurableAttribute _smallIconDescription
           
 
Fields inherited from class ptolemy.vergil.icon.EditorIcon
_containerToBe, _iconCache
 
Fields inherited from class ptolemy.kernel.util.NamedObj
_changeListeners, _changeLock, _changeRequests, _debugging, _debugListeners, _elementName, _isPersistent, _verbose, _workspace, ATTRIBUTES, CLASSNAME, COMPLETE, CONTENTS, DEEP, FULLNAME, LINKS
 
Constructor Summary
SVGIcon(NamedObj container, java.lang.String name)
          Create a new icon with the given name in the given container.
SVGIcon(Workspace workspace, java.lang.String name)
          Construct an icon in the specified workspace and name.
 
Method Summary
private  void _bindToContainer(NamedObj container)
          Establish this icon as a listener for changes in attributes named "_iconDescription" and "_smallIconDescription" in the specified container.
private  void _createAttribute(java.lang.String type, java.util.Map attributes, java.lang.String content)
          Create a new attribute and insert it in this icon.
private  void _generateContents(XmlElement root)
          Given the root of an XML tree, populate this icon with attributes for each graphical element.
private static java.lang.String _getAttribute(java.util.Map map, java.lang.String name, java.lang.String defaultValue)
          Extract the named attribute from the attribute map and return the value as a string.
private static double _getDouble(java.util.Map map, java.lang.String name, double defaultValue)
          Extract the named attribute from the attribute map and return the value as a double.
private static void _processFilledShapeAttributeAttributes(FilledShapeAttribute attribute, java.util.Map attributes)
          Set the attributes of a FilledShapeAttribute from the specified map of SVG attribute values.
private static void _processLocation(Attribute attribute, java.util.Map attributes)
          Set the location of an Attribute from the specified map of SVG attribute values.
private static void _processShapeAttributeAttributes(ShapeAttribute attribute, java.util.Map attributes)
          Set the attributes of a ShapeAttribute from the specified map of SVG attribute values.
private  void _updateContents()
          Update the contents of the icon based on the SVG data in the associated "_iconDescription" parameter, if there is one.
 java.lang.Object clone(Workspace workspace)
          Clone the object into the specified workspace.
 void setContainer(NamedObj container)
          Override the base class to establish this as a listener to icon descriptions in the container.
 void setContainerToBe(NamedObj container)
          Indicate that the container of this icon will eventually be the specified object.
 void valueChanged(Settable settable)
          React to the fact that the value of an attribute named "_iconDescription" contained by the same container has changed value by redrawing the figure.
 
Methods inherited from class ptolemy.vergil.icon.EditorIcon
_createDefaultBackgroundFigure, _isPropertySet, _recreateFigure, createBackgroundFigure, createFigure, createIcon, getContainerOrContainerToBe
 
Methods inherited from class ptolemy.kernel.util.Attribute
_checkContainer, _getContainedObject, _propagateExistence, getContainer, moveDown, moveToFirst, moveToIndex, moveToLast, moveUp, setName, updateContent
 
Methods inherited from class ptolemy.kernel.util.NamedObj
_addAttribute, _adjustOverride, _attachText, _cloneFixAttributeFields, _debug, _debug, _debug, _debug, _debug, _description, _exportMoMLContents, _getIndentPrefix, _isMoMLSuppressed, _markContentsDerived, _propagateValue, _recordDecoratedAttributes, _removeAttribute, _splitName, _stripNumericSuffix, _validateSettables, addChangeListener, addDebugListener, attributeChanged, attributeList, attributeList, attributeTypeChanged, clone, containedObjectsIterator, deepContains, depthInHierarchy, description, description, event, executeChangeRequests, exportMoML, exportMoML, exportMoML, exportMoML, exportMoML, exportMoMLPlain, getAttribute, getAttribute, getAttributes, getChangeListeners, getClassName, getDecoratorAttribute, getDecoratorAttributes, getDerivedLevel, getDerivedList, getDisplayName, getElementName, getFullName, getModelErrorHandler, getName, getName, getPrototypeList, getSource, handleModelError, isDeferringChangeRequests, isOverridden, isPersistent, lazyContainedObjectsIterator, message, propagateExistence, propagateValue, propagateValues, removeChangeListener, removeDebugListener, requestChange, setClassName, setDeferringChangeRequests, setDerivedLevel, setDisplayName, setModelErrorHandler, setPersistent, setSource, sortContainedObjects, toplevel, toString, uniqueName, validateSettables, workspace
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

_description

private ConfigurableAttribute _description

_smallIconDescription

private ConfigurableAttribute _smallIconDescription
Constructor Detail

SVGIcon

public SVGIcon(Workspace workspace,
               java.lang.String name)
        throws IllegalActionException
Construct an icon in the specified workspace and name. This constructor is typically used in conjunction with setContainerToBe() and createFigure() to create an icon and generate a figure without having to have write access to the workspace. If the workspace argument is null, then use the default workspace. The object is added to the directory of the workspace.

Parameters:
workspace - The workspace that will list the attribute.
name - The name of this attribute.
Throws:
IllegalActionException - If the specified name contains a period.
See Also:
Increment the version number of the workspace.

SVGIcon

public SVGIcon(NamedObj container,
               java.lang.String name)
        throws NameDuplicationException,
               IllegalActionException
Create a new icon with the given name in the given container. By default, the icon contains no graphic objects.

Parameters:
container - The container for this attribute.
name - The name of this attribute.
Throws:
IllegalActionException - If thrown by the parent class or while setting an attribute.
NameDuplicationException - If the name coincides with an attribute already in the container.
Method Detail

clone

public java.lang.Object clone(Workspace workspace)
                       throws java.lang.CloneNotSupportedException
Clone the object into the specified workspace. The new object is not added to the directory of that workspace (you must do this yourself if you want it there). The result is an object with no container.

Overrides:
clone in class EditorIcon
Parameters:
workspace - The workspace for the cloned object.
Returns:
The new Attribute.
Throws:
java.lang.CloneNotSupportedException - Not thrown in this base class
See Also:
NamedObj.exportMoML(Writer, int, String), NamedObj.setDeferringChangeRequests(boolean)

setContainer

public void setContainer(NamedObj container)
                  throws IllegalActionException,
                         NameDuplicationException
Override the base class to establish this as a listener to icon descriptions in the container.

Overrides:
setContainer in class Attribute
Parameters:
container - The container to attach this attribute to..
Throws:
IllegalActionException - If this attribute is not of the expected class for the container, or it has no name, or the attribute and container are not in the same workspace, or the proposed container would result in recursive containment.
NameDuplicationException - If the container already has an attribute with the name of this attribute.
See Also:
Attribute.getContainer()

setContainerToBe

public void setContainerToBe(NamedObj container)
Indicate that the container of this icon will eventually be the specified object. This rather specialized method is used to create an icon and generate a figure without having to have write access to the workspace. To use it, use the constructor that takes a workspace and a name, then call this method to indicate what the container will be. You can then call createFigure() or createBackgroundFigure(), and the appropriate figure for the container specified here will be used. Then queue a ChangeRequest that sets the container to the same specified container. Once the container has been set by calling setContainer(), then the object specified to this method is no longer relevant.

Overrides:
setContainerToBe in class EditorIcon
Parameters:
container - The container that will eventually be set.
See Also:
EditorIcon.getContainerOrContainerToBe()

valueChanged

public void valueChanged(Settable settable)
React to the fact that the value of an attribute named "_iconDescription" contained by the same container has changed value by redrawing the figure.

Specified by:
valueChanged in interface ValueListener
Parameters:
settable - The object that has changed value.

_bindToContainer

private void _bindToContainer(NamedObj container)
Establish this icon as a listener for changes in attributes named "_iconDescription" and "_smallIconDescription" in the specified container.


_createAttribute

private void _createAttribute(java.lang.String type,
                              java.util.Map attributes,
                              java.lang.String content)
Create a new attribute and insert it in this icon. This method must be called at a time when this thread can get write access on the workspace. For example, it is safe to call it from within a change request, or from within attributeChanged(), or from within notification of change to a parameter. The first argument is a string representation of the SVG element type, the second is a hashtable containing attributes of the object, and the third is the PC data within the element, if there is any. Any attributes that are not recognized will be ignored.


_generateContents

private void _generateContents(XmlElement root)
Given the root of an XML tree, populate this icon with attributes for each graphical element.


_getAttribute

private static java.lang.String _getAttribute(java.util.Map map,
                                              java.lang.String name,
                                              java.lang.String defaultValue)
Extract the named attribute from the attribute map and return the value as a string. If the named attribute is not present, then return the default.

Parameters:
map - The attribute map.
name - The element name.
defaultValue - The default value.
Returns:
The double specified by this attribute.

_getDouble

private static double _getDouble(java.util.Map map,
                                 java.lang.String name,
                                 double defaultValue)
Extract the named attribute from the attribute map and return the value as a double. If the named attribute is not present, then return the default.

Parameters:
map - The attribute map.
name - The element name.
defaultValue - The default value.
Returns:
The double specified by this attribute.

_processFilledShapeAttributeAttributes

private static void _processFilledShapeAttributeAttributes(FilledShapeAttribute attribute,
                                                           java.util.Map attributes)
Set the attributes of a FilledShapeAttribute from the specified map of SVG attribute values.


_processShapeAttributeAttributes

private static void _processShapeAttributeAttributes(ShapeAttribute attribute,
                                                     java.util.Map attributes)
Set the attributes of a ShapeAttribute from the specified map of SVG attribute values.


_processLocation

private static void _processLocation(Attribute attribute,
                                     java.util.Map attributes)
Set the location of an Attribute from the specified map of SVG attribute values.


_updateContents

private void _updateContents()
                      throws java.lang.Exception
Update the contents of the icon based on the SVG data in the associated "_iconDescription" parameter, if there is one.

Throws:
java.lang.Exception