com.jrefinery.chart
Class AbstractTitle

java.lang.Object
  extended by com.jrefinery.chart.AbstractTitle
All Implemented Interfaces:
java.lang.Cloneable
Direct Known Subclasses:
ImageTitle, LegendTitle, TextTitle

public abstract class AbstractTitle
extends java.lang.Object
implements java.lang.Cloneable

The base class for all chart titles.

A chart can have multiple titles, appearing at the top, bottom, left or right of the chart (defined by the constants TOP, BOTTOM, LEFT and RIGHT --- we also use the constants NORTH, SOUTH, EAST and WEST to remain consistent with java.awt.BorderLayout, as most developers will be familiar with that class).

Concrete implementations of this class will render text, images, and hence do the actual work of drawing titles.


Field Summary
static int BOTTOM
          Useful constant for the title position (also used for vertical alignment).
static int CENTER
          Useful constant for the title alignment (horizontal or vertical).
static int DEFAULT_HORIZONTAL_ALIGNMENT
          The default horizontal alignment.
static int DEFAULT_POSITION
          The default title position.
static Spacer DEFAULT_SPACER
          Default title spacer.
static int DEFAULT_VERTICAL_ALIGNMENT
          The default vertical alignment.
static int EAST
          Useful constant for the title position.
protected  int horizontalAlignment
          The horizontal alignment of the title.
static int LEFT
          Useful constant for the title position (also used for horizontal alignment).
protected  java.util.List listeners
          Storage for registered change listeners.
static int MIDDLE
          Useful constant for the title alignment (horizontal or vertical).
static int NORTH
          Useful constant for the title position.
protected  boolean notify
          Flag that controls whether or not the listener mechanism is used - useful for temporarily disabling the mechanism.
protected  int position
          The position of the title (use the constants NORTH, SOUTH, EAST and WEST, or if you prefer you can also use TOP, BOTTOM, LEFT and RIGHT).
static int RIGHT
          Useful constant for the title position (also used for horizontal alignment).
static int SOUTH
          Useful constant for the title position.
protected  Spacer spacer
          The amount of blank space to leave around the title.
static int TOP
          Useful constant for the title position (also used for vertical alignment).
protected  int verticalAlignment
          The vertical alignment of the title.
static int WEST
          Useful constant for the title position.
 
Constructor Summary
protected AbstractTitle()
          Constructs a new AbstractTitle using default attributes where necessary.
protected AbstractTitle(int position, int horizontalAlignment, int verticalAlignment)
          Constructs a new AbstractTitle, using default attributes where necessary.
protected AbstractTitle(int position, int horizontalAlignment, int verticalAlignment, Spacer spacer)
          Constructs a new AbstractTitle.
 
Method Summary
 void addChangeListener(com.jrefinery.chart.event.TitleChangeListener listener)
          Registers an object for notification of changes to the title.
 java.lang.Object clone()
          Returns a clone of the title.
abstract  void draw(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D titleArea)
          Draws the title on a Java 2D graphics device (such as the screen or a printer).
 int getHorizontalAlignment()
          Returns the horizontal alignment of the title.
 boolean getNotify()
          Returns the flag that indicates whether or not the notification mechanism is enabled.
 int getPosition()
          Returns the relative position of the title---represented by one of four integer constants defined in this class: TOP, BOTTOM, RIGHT or LEFT (or the equivalent NORTH, SOUTH, EAST and WEST).
abstract  double getPreferredHeight(java.awt.Graphics2D g2)
          Returns the preferred height of the title.
abstract  double getPreferredWidth(java.awt.Graphics2D g2)
          Returns the preferred width of the title.
 Spacer getSpacer()
          Returns the spacer (determines the blank space around the edges) for this title.
 int getVerticalAlignment()
          Returns the vertical alignment of the title.
protected static boolean isValidHorizontalAlignment(int code)
          Utility method for checking a horizontal alignment code.
abstract  boolean isValidPosition(int position)
          Returns true if the title can assume the specified location, and false otherwise.
protected static boolean isValidVerticalAlignment(int code)
          Utility method for checking a vertical alignment code.
protected  void notifyListeners(com.jrefinery.chart.event.TitleChangeEvent event)
          Notifies all registered listeners that the chart title has changed in some way.
 void removeChangeListener(com.jrefinery.chart.event.TitleChangeListener listener)
          Unregisters an object for notification of changes to the chart title.
 void setHorizontalAlignment(int alignment)
          Sets the horizontal alignment for the title, and notifies any registered listeners of the change.
 void setNotify(boolean flag)
          Sets the flag that indicates whether or not the notification mechanism is enabled.
 void setPosition(int position)
          Sets the position for the title.
 void setSpacer(Spacer spacer)
          Sets the spacer for the title, and notifies registered listeners of the change.
 void setVerticalAlignment(int alignment)
          Sets the vertical alignment for the title, and notifies any registered listeners of the change.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TOP

public static final int TOP
Useful constant for the title position (also used for vertical alignment).

See Also:
Constant Field Values

BOTTOM

public static final int BOTTOM
Useful constant for the title position (also used for vertical alignment).

See Also:
Constant Field Values

RIGHT

public static final int RIGHT
Useful constant for the title position (also used for horizontal alignment).

See Also:
Constant Field Values

LEFT

public static final int LEFT
Useful constant for the title position (also used for horizontal alignment).

See Also:
Constant Field Values

NORTH

public static final int NORTH
Useful constant for the title position.

See Also:
Constant Field Values

SOUTH

public static final int SOUTH
Useful constant for the title position.

See Also:
Constant Field Values

EAST

public static final int EAST
Useful constant for the title position.

See Also:
Constant Field Values

WEST

public static final int WEST
Useful constant for the title position.

See Also:
Constant Field Values

CENTER

public static final int CENTER
Useful constant for the title alignment (horizontal or vertical).

See Also:
Constant Field Values

MIDDLE

public static final int MIDDLE
Useful constant for the title alignment (horizontal or vertical).

See Also:
Constant Field Values

DEFAULT_POSITION

public static final int DEFAULT_POSITION
The default title position.

See Also:
Constant Field Values

DEFAULT_HORIZONTAL_ALIGNMENT

public static final int DEFAULT_HORIZONTAL_ALIGNMENT
The default horizontal alignment.

See Also:
Constant Field Values

DEFAULT_VERTICAL_ALIGNMENT

public static final int DEFAULT_VERTICAL_ALIGNMENT
The default vertical alignment.

See Also:
Constant Field Values

DEFAULT_SPACER

public static final Spacer DEFAULT_SPACER
Default title spacer.


notify

protected boolean notify
Flag that controls whether or not the listener mechanism is used - useful for temporarily disabling the mechanism.


position

protected int position
The position of the title (use the constants NORTH, SOUTH, EAST and WEST, or if you prefer you can also use TOP, BOTTOM, LEFT and RIGHT).


horizontalAlignment

protected int horizontalAlignment
The horizontal alignment of the title.


verticalAlignment

protected int verticalAlignment
The vertical alignment of the title.


spacer

protected Spacer spacer
The amount of blank space to leave around the title.


listeners

protected java.util.List listeners
Storage for registered change listeners.

Constructor Detail

AbstractTitle

protected AbstractTitle()
Constructs a new AbstractTitle using default attributes where necessary.


AbstractTitle

protected AbstractTitle(int position,
                        int horizontalAlignment,
                        int verticalAlignment)
Constructs a new AbstractTitle, using default attributes where necessary.

Parameters:
position - The relative position of the title (TOP, BOTTOM, RIGHT and LEFT).
horizontalAlignment - The horizontal alignment of the title (LEFT, CENTER or RIGHT).
verticalAlignment - The vertical alignment of the title (TOP, MIDDLE or BOTTOM).
Throws:
java.lang.IllegalArgumentException - If an invalid location or alignment value is passed.

AbstractTitle

protected AbstractTitle(int position,
                        int horizontalAlignment,
                        int verticalAlignment,
                        Spacer spacer)
Constructs a new AbstractTitle.

This class defines constants for the valid position and alignment values---an IllegalArgumentException will be thrown if invalid values are passed to this constructor.

Parameters:
position - The relative position of the title (TOP, BOTTOM, RIGHT and LEFT).
horizontalAlignment - The horizontal alignment of the title (LEFT, CENTER or RIGHT).
verticalAlignment - The vertical alignment of the title (TOP, MIDDLE or BOTTOM).
spacer - The amount of space to leave around the outside of the title.
Throws:
java.lang.IllegalArgumentException - If an invalid location or alignment value is passed.
Method Detail

getNotify

public boolean getNotify()
Returns the flag that indicates whether or not the notification mechanism is enabled.

Returns:
A boolean that indicates whether or not the notification mechanism is enabled;

setNotify

public void setNotify(boolean flag)
Sets the flag that indicates whether or not the notification mechanism is enabled. There are certain situations (such as cloning) where you want to turn notification off temporarily.

Parameters:
flag - A boolean that indicates whether or not the notification mechanism is enabled;

getPosition

public int getPosition()
Returns the relative position of the title---represented by one of four integer constants defined in this class: TOP, BOTTOM, RIGHT or LEFT (or the equivalent NORTH, SOUTH, EAST and WEST).

Returns:
The title position;

setPosition

public void setPosition(int position)
Sets the position for the title.

Parameters:
position - The relative position of the title (use one of the constants TOP, BOTTOM, RIGHT and LEFT, or the equivalent NORTH, SOUTH, EAST and WEST);

getHorizontalAlignment

public int getHorizontalAlignment()
Returns the horizontal alignment of the title. The constants LEFT, CENTER and RIGHT (defined in this class) are used.

Returns:
The horizontal alignment of the title (LEFT, CENTER or RIGHT);

setHorizontalAlignment

public void setHorizontalAlignment(int alignment)
Sets the horizontal alignment for the title, and notifies any registered listeners of the change. The constants LEFT, CENTER and RIGHT (defined in this class) can be used to specify the alignment.

Parameters:
alignment - The new horizontal alignment (LEFT, CENTER or RIGHT).

getVerticalAlignment

public int getVerticalAlignment()
Returns the vertical alignment of the title. The constants TOP, MIDDLE and BOTTOM (defined in this class) are used.

Returns:
The vertical alignment of the title (TOP, MIDDLE or BOTTOM);

setVerticalAlignment

public void setVerticalAlignment(int alignment)
Sets the vertical alignment for the title, and notifies any registered listeners of the change. The constants TOP, MIDDLE and BOTTOM (defined in this class) can be used to specify the alignment.

Parameters:
alignment - The new vertical alignment (TOP, MIDDLE or BOTTOM);

getSpacer

public Spacer getSpacer()
Returns the spacer (determines the blank space around the edges) for this title.


setSpacer

public void setSpacer(Spacer spacer)
Sets the spacer for the title, and notifies registered listeners of the change.

Parameters:
spacer - The new spacer.

isValidPosition

public abstract boolean isValidPosition(int position)
Returns true if the title can assume the specified location, and false otherwise.

Parameters:
position - The position.
Returns:
True or false, indicating whether or not the title can assume the specified position.

getPreferredWidth

public abstract double getPreferredWidth(java.awt.Graphics2D g2)
Returns the preferred width of the title. When a title is displayed at the left or right of a chart, the chart will attempt to give the title enough space for it's preferred width.


getPreferredHeight

public abstract double getPreferredHeight(java.awt.Graphics2D g2)
Returns the preferred height of the title. When a title is displayed at the top or bottom of a chart, the chart will attempt to give the title enough space for it's preferred height.


draw

public abstract void draw(java.awt.Graphics2D g2,
                          java.awt.geom.Rectangle2D titleArea)
Draws the title on a Java 2D graphics device (such as the screen or a printer).

Parameters:
g2 - The graphics device.
area - The area for drawing the title.

clone

public java.lang.Object clone()
Returns a clone of the title.

One situation when this is useful is when editing the title properties - you can edit a clone, and then it is easier to cancel the changes if necessary.

Overrides:
clone in class java.lang.Object
Returns:
A clone of the title.

addChangeListener

public void addChangeListener(com.jrefinery.chart.event.TitleChangeListener listener)
Registers an object for notification of changes to the title.

Parameters:
listener - The object that is being registered;

removeChangeListener

public void removeChangeListener(com.jrefinery.chart.event.TitleChangeListener listener)
Unregisters an object for notification of changes to the chart title.

Parameters:
listener - The object that is being unregistered;

notifyListeners

protected void notifyListeners(com.jrefinery.chart.event.TitleChangeEvent event)
Notifies all registered listeners that the chart title has changed in some way.

Parameters:
event - An object that contains information about the change to the title;

isValidHorizontalAlignment

protected static boolean isValidHorizontalAlignment(int code)
Utility method for checking a horizontal alignment code.


isValidVerticalAlignment

protected static boolean isValidVerticalAlignment(int code)
Utility method for checking a vertical alignment code.



Copyright © 2003 MBARI.

The Monterey Bay Aquarium Research Institute (MBARI) provides this documentation and code "as is", with no warranty, express or implied, of its quality or consistency. It is provided without support and without obligation on the part of MBARI to assist in its use, correction, modification, or enhancement.