com.odesys.chart
Class Chart

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--java.awt.Panel
                    |
                    +--com.odesys.chart.Chart
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, ModelChangeListener, java.io.Serializable
Direct Known Subclasses:
BarChart, BubbleChart, LineChart, PieChart

public abstract class Chart
extends java.awt.Panel
implements ModelChangeListener

Chart is the abstract superclass of all charts. It is responsible for arranging the views (chart and legend), double buffering, proper updating, showing tooltips etc. All jdk 1.0 compliant implementations should extend the Chart subclasses to add specific Event handling and user interaction.

See Also:
Serialized Form

Inner classes inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
Inner classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Inner classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent
 
Field Summary
static java.awt.Font nullFont
           
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Chart()
          Creates a Chart instance.
 
Method Summary
abstract  ChartView createChartView()
          Factory method that should be implemented by the subclasses.
abstract  ChartModel createDefaultModel()
          Factory method that should be implemented by the subclasses.
abstract  ChartView createLegendView()
          Factory method that should be implemented by the subclasses.
 void drawChart(java.awt.Graphics g)
          Draws this Chart in the specified Graphics context
 void drawChildView(java.awt.Graphics g, ChartView view)
          Draws the specified ChartView in the specified Graphics context.
 void drawTooltip(java.awt.Graphics g)
          Utility method that draws the current tooltip
abstract  java.lang.Object fromPoint(java.awt.Point p)
          Gets the Object associated with the Point specified as a parameter.
 java.awt.Image getBackgroundImage()
          Gets the background image of this Chart.
 ChartView getChartView()
          Gets the ChartView of this Chart.
 java.awt.FontMetrics getFontMetrics(java.awt.Font font)
           
 ChartView getLegendView()
          Gets the specific ChartView of this Chart that draws the Legend.
 int getMinSize()
          Returns the width or the height of this Chart depending on which one is less.
 ChartModel getModel()
          Gets the data Model of this Chart.
 boolean isLegendVisible()
          Determines whether this Chart's Legend is visible.
 void layout()
          Positions the child ChartViews within this Chart
 void layout(java.awt.Graphics g)
          Updates the layout of this Chart so it is drawn best in the specified Graphics context.
 void modelChanged(ModelChangedEvent e)
          Called when the ChartModel was changed and the Chart should be updated.
 boolean mouseDown(java.awt.Event e, int x, int y)
          Overriden to allow for the tooltip support.
 boolean mouseExit(java.awt.Event e, int x, int y)
          Overriden to allow for the tooltip support.
 boolean mouseMove(java.awt.Event e, int x, int y)
          Overriden to allow for the tooltip support.
 void paint(java.awt.Graphics g)
          Draws this Chart in the specified Graphics context using double buffering.
 void setBackgroundImage(java.awt.Image image)
          Sets the background image of this Chart.
 void setFont(java.awt.Font font)
          Sets the Font of this Chart.
 void setLegendVisible(boolean visible)
          Shows or hides the Legend of this Chart depending on the value of parameter visible.
 void setModel(ChartModel model)
          Sets the data Model of this Chart.
 void setTooltip(java.lang.String text, int x, int y)
          Sets the text and the position of the tooltip to be displayed on this Chart.
abstract  java.lang.String tooltipFor(java.lang.Object target)
          Gets the tooltip text for the Object specified as a parameter.
 java.awt.Point translate(java.awt.Point p, ChartView target)
          Translates the point to the coordinate system of the target ChartView.
 void update(java.awt.Graphics g)
           
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getPreferredSize, insets, invalidate, isAncestorOf, list, list, locate, minimumSize, paintComponents, paramString, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, getBackground, getBounds, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isDisplayable, isDoubleBuffered, isEnabled, isFocusTraversable, isLightweight, isOpaque, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDrag, mouseEnter, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, reshape, resize, resize, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setForeground, setLocale, setLocation, setLocation, setName, setSize, setSize, setVisible, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

nullFont

public static final java.awt.Font nullFont
Constructor Detail

Chart

public Chart()
Creates a Chart instance.
Method Detail

createChartView

public abstract ChartView createChartView()
Factory method that should be implemented by the subclasses. It returns a ChartView instance specific to the particular Chart subclass (e.g. PieChartView for the PieChart).

createLegendView

public abstract ChartView createLegendView()
Factory method that should be implemented by the subclasses. It returns a ChartView instance that is used as a Legend for the specific Chart. Usually returns a LegendView instance.

createDefaultModel

public abstract ChartModel createDefaultModel()
Factory method that should be implemented by the subclasses. It returns a ChartModel instance specific to the particular Chart subclass (e.g. PieChartModel for the PieChart).

fromPoint

public abstract java.lang.Object fromPoint(java.awt.Point p)
Gets the Object associated with the Point specified as a parameter.
Parameters:
p - The Point we need to find an Object for.
Returns:
The Object that is associated with the specified Point or null.

tooltipFor

public abstract java.lang.String tooltipFor(java.lang.Object target)
Gets the tooltip text for the Object specified as a parameter.
Parameters:
target - The Object we need Tooltip text for.
Returns:
Tooltip text for the specified Object.

getChartView

public ChartView getChartView()
Gets the ChartView of this Chart. The ChartView is responsible for drawing the chart picture in the Graphics context of this Chart.

getLegendView

public ChartView getLegendView()
Gets the specific ChartView of this Chart that draws the Legend.

setModel

public void setModel(ChartModel model)
              throws java.lang.IllegalArgumentException
Sets the data Model of this Chart. Throws IllegalArgumentException if the ChartModel passed as a parameter is not appropriate for this Chart instance.

getModel

public ChartModel getModel()
Gets the data Model of this Chart.

modelChanged

public void modelChanged(ModelChangedEvent e)
Called when the ChartModel was changed and the Chart should be updated.
Specified by:
modelChanged in interface ModelChangeListener

layout

public void layout()
Positions the child ChartViews within this Chart
Overrides:
layout in class java.awt.Container

update

public void update(java.awt.Graphics g)
Overrides:
update in class java.awt.Container

paint

public void paint(java.awt.Graphics g)
Draws this Chart in the specified Graphics context using double buffering. Creates a Graphics context for the back buffer, delegates to drawChart() and then draws the back buffer.
Overrides:
paint in class java.awt.Container

drawChart

public void drawChart(java.awt.Graphics g)
Draws this Chart in the specified Graphics context

drawChildView

public void drawChildView(java.awt.Graphics g,
                          ChartView view)
Draws the specified ChartView in the specified Graphics context.

setBackgroundImage

public void setBackgroundImage(java.awt.Image image)
Sets the background image of this Chart.

getBackgroundImage

public java.awt.Image getBackgroundImage()
Gets the background image of this Chart.

getMinSize

public int getMinSize()
Returns the width or the height of this Chart depending on which one is less.
Returns:
Math.min(width, height).

setFont

public void setFont(java.awt.Font font)
Sets the Font of this Chart. The acctual Font is scaled automaticaly based upon the size of the Chart.
Overrides:
setFont in class java.awt.Container

setTooltip

public void setTooltip(java.lang.String text,
                       int x,
                       int y)
Sets the text and the position of the tooltip to be displayed on this Chart. Only one tooltip at a time can be shown. Passing null value for the text causes the tooltip to disappear.

drawTooltip

public void drawTooltip(java.awt.Graphics g)
Utility method that draws the current tooltip

setLegendVisible

public void setLegendVisible(boolean visible)
Shows or hides the Legend of this Chart depending on the value of parameter visible.

isLegendVisible

public boolean isLegendVisible()
Determines whether this Chart's Legend is visible.

translate

public java.awt.Point translate(java.awt.Point p,
                                ChartView target)
Translates the point to the coordinate system of the target ChartView.

mouseMove

public boolean mouseMove(java.awt.Event e,
                         int x,
                         int y)
Overriden to allow for the tooltip support. All overrides should call the superclass implementation.
Overrides:
mouseMove in class java.awt.Component

mouseDown

public boolean mouseDown(java.awt.Event e,
                         int x,
                         int y)
Overriden to allow for the tooltip support. All overrides should call the superclass implementation.
Overrides:
mouseDown in class java.awt.Component

mouseExit

public boolean mouseExit(java.awt.Event e,
                         int x,
                         int y)
Overriden to allow for the tooltip support. All overrides should call the superclass implementation.
Overrides:
mouseExit in class java.awt.Component

getFontMetrics

public java.awt.FontMetrics getFontMetrics(java.awt.Font font)
Overrides:
getFontMetrics in class java.awt.Component

layout

public void layout(java.awt.Graphics g)
Updates the layout of this Chart so it is drawn best in the specified Graphics context. This method is used when the Chart needs to be drawn in a Graphics context diferent from the one obtained for this Component.
Parameters:
g - The Graphics context.