com.jrefinery.chart
Class ImageTitle

java.lang.Object
  extended by com.jrefinery.chart.AbstractTitle
      extended by com.jrefinery.chart.ImageTitle
All Implemented Interfaces:
java.lang.Cloneable

public class ImageTitle
extends AbstractTitle

A chart title that displays an image. This is useful, for example, if you have an image of your corporate logo and want to use as a footnote or part of a title in a chart you create.

ImageTitle needs an image passed to it in the constructor. For ImageTitle to work, you must have already loaded this image from its source (disk or URL). It is recomended you use something like Toolkit.getDefaultToolkit().getImage() to get the image. Then, use MediaTracker or some other message to make sure the image is fully loaded from disk.


Field Summary
protected  int height
          The height used to draw the image (may involve scaling).
protected  java.awt.Image image
          The title image.
protected  int width
          The width used to draw the image (may involve scaling).
 
Fields inherited from class com.jrefinery.chart.AbstractTitle
BOTTOM, CENTER, DEFAULT_HORIZONTAL_ALIGNMENT, DEFAULT_POSITION, DEFAULT_SPACER, DEFAULT_VERTICAL_ALIGNMENT, EAST, horizontalAlignment, LEFT, listeners, MIDDLE, NORTH, notify, position, RIGHT, SOUTH, spacer, TOP, verticalAlignment, WEST
 
Constructor Summary
ImageTitle(java.awt.Image image)
          Constructs a new ImageTitle.
ImageTitle(java.awt.Image image, int position, int horizontalAlignment, int verticalAlignment)
          Constructs a new ImageTitle.
ImageTitle(java.awt.Image image, int height, int width, int position, int horizontalAlignment, int verticalAlignment, Spacer spacer)
          Constructs a new ImageTitle with the given image scaled to the given width and height in the given location.
 
Method Summary
 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).
protected  Size2D drawHorizontal(java.awt.Graphics2D g2, java.awt.geom.Rectangle2D chartArea)
          Draws the title on a Java 2D graphics device (such as the screen or a printer).
 java.awt.Image getImage()
          Returns the image for the title.
 double getPreferredHeight(java.awt.Graphics2D g2)
          Returns the preferred height of the title.
 double getPreferredWidth(java.awt.Graphics2D g2)
          Returns the preferred width of the title.
 boolean isValidPosition(int position)
          Returns true for all positions, since an image can be displayed anywhere.
 void setImage(java.awt.Image image)
          Sets the image for the title and notifies registered listeners that the title has been modified.
 
Methods inherited from class com.jrefinery.chart.AbstractTitle
addChangeListener, clone, getHorizontalAlignment, getNotify, getPosition, getSpacer, getVerticalAlignment, isValidHorizontalAlignment, isValidVerticalAlignment, notifyListeners, removeChangeListener, setHorizontalAlignment, setNotify, setPosition, setSpacer, setVerticalAlignment
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

image

protected java.awt.Image image
The title image.


height

protected int height
The height used to draw the image (may involve scaling).


width

protected int width
The width used to draw the image (may involve scaling).

Constructor Detail

ImageTitle

public ImageTitle(java.awt.Image image)
Constructs a new ImageTitle.

Parameters:
image - The image.
position - The title position (LEFT, RIGHT, TOP, BOTTOM).

ImageTitle

public ImageTitle(java.awt.Image image,
                  int position,
                  int horizontalAlignment,
                  int verticalAlignment)
Constructs a new ImageTitle.

Parameters:
image - The image.
position - The title position (LEFT, RIGHT, TOP, BOTTOM).

ImageTitle

public ImageTitle(java.awt.Image image,
                  int height,
                  int width,
                  int position,
                  int horizontalAlignment,
                  int verticalAlignment,
                  Spacer spacer)
Constructs a new ImageTitle with the given image scaled to the given width and height in the given location.

Parameters:
image - The image.
width - The width used to draw the image.
height - The height used to draw the image.
position - The title position (LEFT, RIGHT, TOP, BOTTOM).
Method Detail

getImage

public java.awt.Image getImage()
Returns the image for the title.

Returns:
The image for the title.

setImage

public void setImage(java.awt.Image image)
Sets the image for the title and notifies registered listeners that the title has been modified.

Parameters:
image - The new image.

draw

public 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).

Specified by:
draw in class AbstractTitle
Parameters:
g2 - The graphics device;
chartArea - The area within which the title (and plot) should be drawn.

isValidPosition

public boolean isValidPosition(int position)
Returns true for all positions, since an image can be displayed anywhere.

Specified by:
isValidPosition in class AbstractTitle
Parameters:
position - The position.
Returns:
True or false, indicating whether or not the title can assume the specified position.

getPreferredWidth

public double getPreferredWidth(java.awt.Graphics2D g2)
Returns the preferred width of the title.

Specified by:
getPreferredWidth in class AbstractTitle
Parameters:
g2 - The graphics device.

getPreferredHeight

public double getPreferredHeight(java.awt.Graphics2D g2)
Returns the preferred height of the title.

Specified by:
getPreferredHeight in class AbstractTitle
Parameters:
g2 - The graphics device.

drawHorizontal

protected Size2D drawHorizontal(java.awt.Graphics2D g2,
                                java.awt.geom.Rectangle2D chartArea)
Draws the title on a Java 2D graphics device (such as the screen or a printer).

Parameters:
g2 - The graphics device.
chartArea - The area within which the title (and plot) should be drawn.
Returns:
The area used by the title.


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.