Class PicAttributeSet

  • All Implemented Interfaces:
    PicObjectConstants

    public class PicAttributeSet
    extends java.lang.Object
    implements PicObjectConstants
    a class that stores non-default graphical attributes (e.g. "fill", "stroke", etc... ) in a hashtable. If a key is not found in the map, we look up the resolving parent.
    • Field Detail

      • DEFAULT_SET

        public static final jpicedt.graphic.model.DefaultAttributeSet DEFAULT_SET
        an immutable attribute set that serves as the resolving parent if no resolving parent is explicitly set
      • map

        protected java.util.HashMap map
        a map holding name/value pairs
      • parent

        protected PicAttributeSet parent
        if non-null, used as the resolving parent when name is not found in current set
    • Constructor Detail

      • PicAttributeSet

        public PicAttributeSet()
        Create a new PicAttributeSet with DEFAULT_SET as the resolving parent.
        See Also:
        PicObjectConstants
      • PicAttributeSet

        public PicAttributeSet​(PicAttributeSet src)
        cloning constructor
        Parameters:
        src - the attribute set to be cloned ; set the resolving parent to the resolving parent of the source.
    • Method Detail

      • getResolveParent

        public PicAttributeSet getResolveParent()
        Returns the resolving parent, or DEFAULT_SET if it's null.
      • setResolveParent

        public void setResolveParent​(PicAttributeSet parent)
        set the resolving parent.
        Parameters:
        parent - if null, set the parent to DEFAULT_SET.
      • copyAttributes

        public PicAttributeSet copyAttributes()
        return a copy of this PicAttributeSet with the same resolving parent as the source, and which is guaranteed not to change over time.
      • getAttribute

        public java.lang.Object getAttribute​(PicAttributeName name)
        Returns the attribute with the given name, possibly resolving to parent if "name" is not defined in this set.
      • setAttribute

        public void setAttribute​(PicAttributeName name,
                                 java.lang.Object value)
        Add a new name/value pair to the set if it's present nor in the set, nor in the resolving parent, otherwise modify the value for the given name. If the pair then exists in the resolving parent, remove it from this set.
        Parameters:
        name - attribute name
        value - attribute value
        Throws:
        java.lang.IllegalArgumentException - if value's runtime type is not an allowed class for the given attribute name
        See Also:
        PicObjectConstants
      • setAttributes

        public void setAttributes​(PicAttributeSet src)
        Sets several name/value pairs at a time from the given set. Key present in this set, yet which are not found in the given set, aren't overriden. Hence only non-default value are copied (in the sense that the resolving parent is the "default" set).
      • getAttributeCount

        public int getAttributeCount()
        Returns the number of attributes contained in this set ; this doesn't include the attributes of the resolving parent.
      • getAttributeNames

        public java.util.Iterator getAttributeNames()
        Returns an iterator over the names of the attributes in this attribute set ; this doesn't iterate over the keys of the resolving parent.
      • toString

        public java.lang.String toString()
        Returns a text representation of this attribute set, for debugging purpose
        Overrides:
        toString in class java.lang.Object