org.apache.excalibur.instrument.client
Class LineChart

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by org.apache.excalibur.instrument.client.LineChart
All Implemented Interfaces:
java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener

public class LineChart
extends javax.swing.JComponent
implements java.awt.event.MouseListener, java.awt.event.MouseMotionListener

Draws a nice pretty chart given a set of data.

Author:
Avalon Development Team
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
private  boolean m_antialias
          True if Antialiasing should be used when rendering the chart.
private  int m_averageWindow
          Number of sample points to use when calculating the moving average.
private  float[] m_averageWindowValues
          Moving average of the sample point data.
private  java.awt.Color m_crossColor
           
private  java.awt.Color m_darkGridColor
           
private  java.lang.String m_dFormat
          Format of the text which is displayed over the component as the user moves the mouse over the line chart.
private  java.text.DecimalFormat m_floatFormat
          Decimal number format.
private  java.lang.String m_format
          Format of the text which is displayed along the x (time) axis of the chart.
private  java.awt.Color m_frameColor
           
private  java.text.DecimalFormat m_intFormat
          Integer number format.
private  java.awt.Color m_lightGridColor
           
private  java.awt.Color m_lightLineColor
           
private  java.awt.Color m_lineColor
           
private  int m_lineSampleInterval
          Number of sample points between vertical lines.
private  java.awt.Color m_maskColor
           
private  java.awt.Color m_maskFrameColor
           
private  int m_max
          Maximum value in m_values.
private  int m_min
          Minimum value in m_values.
private  boolean m_mouseOver
           
private  boolean m_mousePressed
           
private  int m_mouseX
           
private  int m_mouseY
           
private  long m_sampleInterval
          The number of milliseconds represented by each data sample.
private  long m_time
          Time of the last sample point.
private  int[] m_values
          Sample point data.
private static long m_zoneOffset
          Stores the time-zone offset for this JVM.
 
Fields inherited from class javax.swing.JComponent
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
 
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
LineChart(int lineSampleInterval, long sampleInterval, java.lang.String format, java.lang.String detailFormat, int averageWindow, boolean antialias)
           
 
Method Summary
private  java.lang.String getFormattedTime(java.util.Date dTime, boolean detailed)
           
 void mouseClicked(java.awt.event.MouseEvent event)
          Called when the mouse is clicked ont the component.
 void mouseDragged(java.awt.event.MouseEvent event)
          Called when the mouse is dragged over the component.
 void mouseEntered(java.awt.event.MouseEvent event)
          Called when the mouse is enters the component.
 void mouseExited(java.awt.event.MouseEvent event)
          Called when the mouse is exits the component.
 void mouseMoved(java.awt.event.MouseEvent event)
          Called when the mouse is moved over the component.
 void mousePressed(java.awt.event.MouseEvent event)
          Called when the mouse is pressed ont the component.
 void mouseReleased(java.awt.event.MouseEvent event)
          Called when the mouse is released ont the component.
 void paintComponent(java.awt.Graphics g)
          Paints the component.
private  void paintFrame(java.awt.Graphics g, int chartLeft, int chartTop, int chartWidth, int chartHeight)
          Draws the frame around the whole chart.
private  void paintHorizontalGrid(java.awt.Graphics g, int yLabelInterval, int fontHeight, int chartLeft, int chartTop, int chartWidth, int chartHeight)
          Draws the horizontal lines which make up the background of the chart.
private  void paintOverlay(java.awt.Graphics g, int fontHeight, int chartLeft, int chartTop, int chartWidth, int chartHeight)
          Draws the overlay label at the mouse location.
private  void paintOverlayAt(java.awt.Graphics g, int fontHeight, int chartLeft, int chartTop, int chartWidth, int chartHeight, int mouseDataPointX, int mouseDataPointY, java.lang.String mouseDataPointValue, long mouseDataPointTime)
          Draws the overlay label at the specified location.
private  void paintValues(java.awt.Graphics g, int chartLeft, int chartTop, int chartWidth, int chartHeight)
          Draws the data values which to be displayed in the chart.
private  void paintVerticalGrid(java.awt.Graphics g, int fontHeight, int chartLeft, int chartTop, int chartWidth, int chartHeight)
          Draws the vertical lines which make up the background of the chart.
 void setAntialias(boolean antialias)
          Sets the antialias flag to control whether or not antialiasing will be used when rendering the component.
 void setValues(int[] values, long time)
          Sets the data samples to be displayed by the line chart.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBaseline, getBaselineResizeBehavior, getBorder, getBounds, getClientProperty, getComponentGraphics, getComponentPopupMenu, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getFontMetrics, getGraphics, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

m_zoneOffset

private static long m_zoneOffset
Stores the time-zone offset for this JVM.


m_lineColor

private java.awt.Color m_lineColor

m_lightLineColor

private java.awt.Color m_lightLineColor

m_lightGridColor

private java.awt.Color m_lightGridColor

m_darkGridColor

private java.awt.Color m_darkGridColor

m_frameColor

private java.awt.Color m_frameColor

m_crossColor

private java.awt.Color m_crossColor

m_maskFrameColor

private java.awt.Color m_maskFrameColor

m_maskColor

private java.awt.Color m_maskColor

m_lineSampleInterval

private int m_lineSampleInterval
Number of sample points between vertical lines.


m_sampleInterval

private long m_sampleInterval
The number of milliseconds represented by each data sample.


m_format

private java.lang.String m_format
Format of the text which is displayed along the x (time) axis of the chart.


m_dFormat

private java.lang.String m_dFormat
Format of the text which is displayed over the component as the user moves the mouse over the line chart.


m_averageWindow

private int m_averageWindow
Number of sample points to use when calculating the moving average.


m_antialias

private boolean m_antialias
True if Antialiasing should be used when rendering the chart.


m_time

private long m_time
Time of the last sample point.


m_values

private int[] m_values
Sample point data.


m_averageWindowValues

private float[] m_averageWindowValues
Moving average of the sample point data.


m_min

private int m_min
Minimum value in m_values.


m_max

private int m_max
Maximum value in m_values.


m_intFormat

private java.text.DecimalFormat m_intFormat
Integer number format.


m_floatFormat

private java.text.DecimalFormat m_floatFormat
Decimal number format.


m_mouseOver

private boolean m_mouseOver

m_mousePressed

private boolean m_mousePressed

m_mouseX

private int m_mouseX

m_mouseY

private int m_mouseY
Constructor Detail

LineChart

public LineChart(int lineSampleInterval,
                 long sampleInterval,
                 java.lang.String format,
                 java.lang.String detailFormat,
                 int averageWindow,
                 boolean antialias)
Parameters:
lineSampleInterval - The interval in data points at which to place vertical lines and labels along the x (time) axis.
sampleInterval - The number of milliseconds represented by each data sample.
format - Format of the text which is displayed along the x (time) axis of the chart. The text will display the time of the line chart at a particular interval. The text should take the format "{0}/{1}/{2} {3}:{4}:{5}.{6}" where {0} is replaced by the year, {1} by the month, {2} by the day, {3} by the hour, {4} by the minute, {5} by the second, and {6} by the hundereths of a second.
detailFormat - Format of the text which is displayed over the component as the user moves the mouse over the line chart. The text will display the exact value of the line chart at a particular point. The text should take the format "{0}/{1}/{2} {3}:{4}:{5}.{6}" where {0} is replaced by the year, {1} by the month, {2} by the day, {3} by the hour, {4} by the minute, {5} by the second, and {6} by the hundereths of a second.
averageWindow - Number of data points to do a moving average over when the mouse is pressed on the component.
antialias - True if Antialiasing should be used when rendering the chart.
Method Detail

setAntialias

public void setAntialias(boolean antialias)
Sets the antialias flag to control whether or not antialiasing will be used when rendering the component.

Parameters:
antialias - True to use antialiasing.

setValues

public void setValues(int[] values,
                      long time)
Sets the data samples to be displayed by the line chart.

Parameters:
values - Array of data samples.
time - The time of the start of the last sample point.

getFormattedTime

private java.lang.String getFormattedTime(java.util.Date dTime,
                                          boolean detailed)

paintHorizontalGrid

private void paintHorizontalGrid(java.awt.Graphics g,
                                 int yLabelInterval,
                                 int fontHeight,
                                 int chartLeft,
                                 int chartTop,
                                 int chartWidth,
                                 int chartHeight)
Draws the horizontal lines which make up the background of the chart.

Parameters:
g - Graphics object to paint with.
yLabelInterval - Interval at which the lines should be labeled.
fontHeight - The height of the current font.
chartLeft - Left edge of the chart.
chartTop - Top edge of the chart.
chartWidth - Width of the chart.
chartHeight - Height of the chart.

paintVerticalGrid

private void paintVerticalGrid(java.awt.Graphics g,
                               int fontHeight,
                               int chartLeft,
                               int chartTop,
                               int chartWidth,
                               int chartHeight)
Draws the vertical lines which make up the background of the chart.

Parameters:
g - Graphics object to paint with.
fontHeight - The height of the current font.
chartLeft - Left edge of the chart.
chartTop - Top edge of the chart.
chartWidth - Width of the chart.
chartHeight - Height of the chart.

paintFrame

private void paintFrame(java.awt.Graphics g,
                        int chartLeft,
                        int chartTop,
                        int chartWidth,
                        int chartHeight)
Draws the frame around the whole chart.

Parameters:
g - Graphics object to paint with.
chartLeft - Left edge of the chart.
chartTop - Top edge of the chart.
chartWidth - Width of the chart.
chartHeight - Height of the chart.

paintValues

private void paintValues(java.awt.Graphics g,
                         int chartLeft,
                         int chartTop,
                         int chartWidth,
                         int chartHeight)
Draws the data values which to be displayed in the chart.

Parameters:
g - Graphics object to paint with.
chartLeft - Left edge of the chart.
chartTop - Top edge of the chart.
chartWidth - Width of the chart.
chartHeight - Height of the chart.

paintOverlayAt

private void paintOverlayAt(java.awt.Graphics g,
                            int fontHeight,
                            int chartLeft,
                            int chartTop,
                            int chartWidth,
                            int chartHeight,
                            int mouseDataPointX,
                            int mouseDataPointY,
                            java.lang.String mouseDataPointValue,
                            long mouseDataPointTime)
Draws the overlay label at the specified location.

Parameters:
g - Graphics object to paint with.
fontHeight - The height of the current font.
chartLeft - Left edge of the chart.
chartTop - Top edge of the chart.
chartWidth - Width of the chart.
chartHeight - Height of the chart.

paintOverlay

private void paintOverlay(java.awt.Graphics g,
                          int fontHeight,
                          int chartLeft,
                          int chartTop,
                          int chartWidth,
                          int chartHeight)
Draws the overlay label at the mouse location.

Parameters:
g - Graphics object to paint with.
fontHeight - The height of the current font.
chartLeft - Left edge of the chart.
chartTop - Top edge of the chart.
chartWidth - Width of the chart.
chartHeight - Height of the chart.

paintComponent

public void paintComponent(java.awt.Graphics g)
Paints the component.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g - Graphics to paint the chart onto.

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent event)
Called when the mouse is clicked ont the component.

Specified by:
mouseClicked in interface java.awt.event.MouseListener
Parameters:
event - Event which describes the action.

mousePressed

public void mousePressed(java.awt.event.MouseEvent event)
Called when the mouse is pressed ont the component.

Specified by:
mousePressed in interface java.awt.event.MouseListener
Parameters:
event - Event which describes the action.

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent event)
Called when the mouse is released ont the component.

Specified by:
mouseReleased in interface java.awt.event.MouseListener
Parameters:
event - Event which describes the action.

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent event)
Called when the mouse is enters the component.

Specified by:
mouseEntered in interface java.awt.event.MouseListener
Parameters:
event - Event which describes the action.

mouseExited

public void mouseExited(java.awt.event.MouseEvent event)
Called when the mouse is exits the component.

Specified by:
mouseExited in interface java.awt.event.MouseListener
Parameters:
event - Event which describes the action.

mouseDragged

public void mouseDragged(java.awt.event.MouseEvent event)
Called when the mouse is dragged over the component.

Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener
Parameters:
event - Event which describes the motion.

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent event)
Called when the mouse is moved over the component.

Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener
Parameters:
event - Event which describes the motion.