Class DynamicEditorIcon

  • All Implemented Interfaces:
    java.lang.Cloneable, Changeable, Debuggable, DebugListener, Derivable, IconAttribute, ModelErrorHandler, MoMLExportable, Moveable, Nameable
    Direct Known Subclasses:
    ImageIcon, PDFIcon, ShapeIcon, TableIcon, TextIcon, XMLIcon

    public class DynamicEditorIcon
    extends EditorIcon
    An icon that provides for the possibility that figures may be dynamically updated. While some icons are generally 'static' and it is simplest to regenerate new figures when their attributes change, other icons are more 'dynamic'. For instance, some icons might display live video or a live plot. This icon provides some basic infrastructure for dealing with such cases. The main difficulty is that, by design, an icon cannot keep track of the figures it creates, otherwise there is a possibility for memory leaks or inconsistencies in the case of multiple views. This class solves the problem by using a WeakReferences to keep track of generated figures. These references do not prevent objects from being garbage collected. This class also provides a 'safe' iterator that can be used to traverse the weak references without the normal associated nastiness.
    Since:
    Ptolemy II 4.0
    Version:
    $Id$
    Author:
    Steve Neuendorffer
    Pt.AcceptedRating:
    Red (johnr)
    Pt.ProposedRating:
    Yellow (eal)
    • Field Detail

      • _figures

        protected java.util.List _figures
        A list of weak references to figures that this has created.
    • Constructor Detail

      • DynamicEditorIcon

        public DynamicEditorIcon​(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.
    • 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)
      • _addLiveFigure

        protected void _addLiveFigure​(Figure newFigure)
        Add the figure to the list of figures managed by this icon. A WeakReference object will be created that points to the figure which will not prevent it from being garbage collected. This method should be called in the createBackgroundFigure method with the figure that will be returned.
        Parameters:
        newFigure - A newly manufactured figure.
      • _liveFigureIterator

        protected java.util.Iterator _liveFigureIterator()
        Return a regular iterator over the figures created by this icon which have not been garbage collected. The objects returned by the iterator are Figures, not WeakReferences. Furthermore, the objects returned by this iterator are guaranteed to not be null.
        Returns:
        an iterator.
      • _trimLiveFigures

        protected void _trimLiveFigures()
        Trim the list of figures to discard entries that are no longer live.