Package uk.ac.starlink.ttools.plot
Class DefaultStyle
- java.lang.Object
-
- uk.ac.starlink.ttools.plot.DefaultStyle
-
- All Implemented Interfaces:
Style
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. TheotherAtts
attribute characterises everything apart from colour, stroke and class which distinguish one instance of this class from another, and is used by theequals(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 andotherAtts
object.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
equals(java.lang.Object o)
Returns true ifo
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 TheotherAtts
object specified at its creation matches (according toequals()
this one'sjava.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
-
Methods inherited from interface uk.ac.starlink.ttools.plot.Style
getLegendIcon
-
-
-
-
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 inBasicStroke
, 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 ofBasicStroke
's CAP_* constantsjoin
- one ofBasicStroke
'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 ifo
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 toequals()
this one's
- Overrides:
equals
in classjava.lang.Object
-
hashCode
public int hashCode()
- Overrides:
hashCode
in classjava.lang.Object
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.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 strokecap
- one ofBasicStroke
's CAP_* constantsjoin
- one ofBasicStroke
's JOIN_* constants- Returns:
- fixed stroke, may be the same as the input one
-
-