Class DefaultStyle

  • All Implemented Interfaces:
    Style
    Direct Known Subclasses:
    BarStyle, MarkStyle

    public abstract class DefaultStyle
    extends java.lang.Object
    implements Style
    Convenience partial implementation of Style which has a defined colour and stroke style, with other attributes given by a single object. The otherAtts attribute characterises everything apart from colour, stroke and class which distinguish one instance of this class from another, and is used by the equals(java.lang.Object) implementation to determine object equality. otherAtts probably ought to be immutable.
    Since:
    16 Nov 2005
    Author:
    Mark Taylor
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      protected DefaultStyle​(java.awt.Color color, java.lang.Object otherAtts)
      Constructs a style given a colour, style and otherAtts object.
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      boolean equals​(java.lang.Object o)
      Returns true if o satisfies the following conditions It has the same class as this one It has the same colour as this one It has the same stroke as this one The otherAtts object specified at its creation matches (according to equals() this one's
      java.awt.Color getColor()
      Returns the colour of this style.
      float[] getDash()
      Returns the dash pattern associated with this style.
      int getLineWidth()
      Returns the line width associated with this style.
      java.lang.Object getOtherAtts()
      Returns the object which distinguishes this object from other ones of the same colour and class.
      java.awt.Stroke getStroke​(int cap, int join)
      Returns a stroke suitable for drawing lines in this style.
      static java.awt.Stroke getStroke​(java.awt.Stroke stroke, int cap, int join)
      Returns a stroke which resembles a given template but has specified end cap and line join policies.
      int hashCode()  
      void setColor​(java.awt.Color color)
      Sets the colour of this style.
      void setDash​(float[] dash)
      Sets the dash pattern associated with this style.
      void setLineWidth​(int width)
      Sets the line width associated with this style.
      java.lang.String toString()  
      • Methods inherited from class java.lang.Object

        clone, finalize, getClass, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • DefaultStyle

        protected DefaultStyle​(java.awt.Color color,
                               java.lang.Object otherAtts)
        Constructs a style given a colour, style and otherAtts object.
        Parameters:
        color - initial colour
        otherAtts - object distinguishing this instance
    • Method Detail

      • setColor

        public void setColor​(java.awt.Color color)
        Sets the colour of this style.
        Parameters:
        color - new colour
      • getColor

        public java.awt.Color getColor()
        Returns the colour of this style.
        Returns:
        colour
      • setLineWidth

        public void setLineWidth​(int width)
        Sets the line width associated with this style.
        Parameters:
        width - line width (>=1)
      • getLineWidth

        public int getLineWidth()
        Returns the line width associated with this style.
        Returns:
        line width
      • setDash

        public void setDash​(float[] dash)
        Sets the dash pattern associated with this style. This is like the dash array in BasicStroke, except that it is multiplied by the line width before use. May be null for a solid line.
        Parameters:
        dash - dash array
      • getDash

        public float[] getDash()
        Returns the dash pattern associated with this style. May be null for a solid line.
        Returns:
        dash array
      • getStroke

        public java.awt.Stroke getStroke​(int cap,
                                         int join)
        Returns a stroke suitable for drawing lines in this style. The line join and cap policy must be provided.
        Parameters:
        cap - one of BasicStroke's CAP_* constants
        join - one of BasicStroke's JOIN_* constants
        Returns:
        stroke
      • getOtherAtts

        public java.lang.Object getOtherAtts()
        Returns the object which distinguishes this object from other ones of the same colour and class.
        Returns:
        otherAtts object
      • equals

        public boolean equals​(java.lang.Object o)
        Returns true if o satisfies the following conditions
        1. It has the same class as this one
        2. It has the same colour as this one
        3. It has the same stroke as this one
        4. The otherAtts object specified at its creation matches (according to equals() this one's
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object
      • getStroke

        public static java.awt.Stroke getStroke​(java.awt.Stroke stroke,
                                                int cap,
                                                int join)
        Returns a stroke which resembles a given template but has specified end cap and line join policies.
        Parameters:
        stroke - template stroke
        cap - one of BasicStroke's CAP_* constants
        join - one of BasicStroke's JOIN_* constants
        Returns:
        fixed stroke, may be the same as the input one