genopt.gui.chart
Class LineChart

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by genopt.gui.chart.LineChart
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class LineChart
extends javax.swing.JComponent

Object for displaying an online line chart.

This project was carried out at:

and supported by

GenOpt Copyright (c) 1998-2011, The Regents of the University of California, through Lawrence Berkeley National Laboratory (subject to receipt of any required approvals from the U.S. Dept. of Energy). All rights reserved.

Version:
GenOpt(R) 3.1.0 (December 8, 2011)

Author:
Michael Wetter
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
protected  int chartDX
          x extension of chart
protected  int chartDY
          y extension of the chart
protected  boolean chartInitialized
           
protected  java.awt.Font foLa
          label Font
protected  java.awt.Font foSuTi
          sub title Font
protected  java.awt.Font foTi
          title Font
protected  java.awt.font.FontRenderContext frc
          FontRenderContext of Graphics2D
protected  int ins
          inset around everything
protected  int insChaNorth
          inset of the chart on the north side
protected  int insChaWest
          inset of the chart on the west side
protected  int[] insNameNorth
          inset of each serie name on the north side
protected  int[] insNameWest
          inset of each serie name on the west side
protected  int insXLabNorth
          inset of x-axis label on the north side
protected  int insY0LabNorth
          inset of the y0 label on the north side
protected  int insY1LabNorth
          inset of the y1 label on the north side
protected  int insYHalfLabNorth
          inset of the y half label on the north side
protected  int[] insYLab
          inset of each y-axis label
static int INTEGER
           
protected  int labAsc
          ascent of label
private static double LG_10
          the natural logarithm (base e) of 10
private static double LN10
          Natural logarithmus of 10
protected static int MANTISSA_LENGTH
          lenght of mantissa field
protected  int MINPOI
          number of points for which the graph is drawn
protected  int nSer
          number of data series in the chart
protected static int NSERMAX
          maximum number of data serie that can be displayed at once
private static int NUMBER_OF_COLORS
          the number of available colors
protected static int NUMBER_OF_DIGITS
          number of digits after decimal point
static int NUMBER_OF_MINOR_Y_GRIDLINES
           
static int SCIENTIFIC
           
private static long serialVersionUID
          The serial version number
protected  DataSerie[] serie
          the data serie
private static java.awt.Color[] STANDARD_COLOR
          the standard color to be assigned
protected  java.awt.font.TextLayout subTitLay
          sub title TextLayout
protected  java.lang.String titLab
          title label
protected  java.awt.font.TextLayout titLay
          title TextLayout
protected  double x0
          x-axis minimum in displayed units (not pixels)
protected  double x0Last
          x-axis minimum of the last rendering in displayed units (not pixels)
protected  double x1
          x-axis maximum in displayed units (not pixels)
protected  double x1Last
          x-axis maximum of the last rendering in displayed units (not pixels)
protected  java.lang.String xAxiLab
          x-axis label
private  double xAxiLen
          x-axis lenght in x units
protected  double[] xAxiTic
          x-axis ticks
protected  int xNumFor
          number format of x-axis label
protected  double[] y0
          y-axis minimum in displayed units (not pixels)
protected  double[] y0Last
          y-axis minimum of the last rendering in displayed units (not pixels)
protected  double[] y1
          y-axis maximum in displayed units (not pixels)
protected  double[] y1Last
          y-axis maximum of the last rendering in displayed units (not pixels)
protected  double[] yAxiLenVal
          y-axis lenght in displayed units (not pixels)
 
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()
          Constructor.
 
Method Summary
 void add(DataSerie ds)
          adds a data serie to the chart
protected  void computeXAxisTicks()
          gets the x maximum label
protected  void drawBox(java.awt.Graphics g)
          draws the box around the chart
protected  void drawLegend(java.awt.Graphics g)
          draws the chart label
protected  void drawTitle(java.awt.Graphics2D g)
          draws the chart title
protected  void drawWholeChart(java.awt.Graphics2D g)
          draws the whole chart
protected  java.lang.String getAxisLabel(double x)
          gets an axis label
private  int getLabelStringWidth(java.lang.String label)
           
protected  int getMaxPoints()
          gets the maximal number of data in all series
static double[] getTicks(double xMin, double xMax)
          gets the label ticks
protected  java.lang.String[] getXAxisLabel()
          gets the x axis labels
protected  int getXPointOffset(double x)
          gets the offset of an x-value, measured in pixels from the west border of the chart surrounding box
protected  int getYPointOffset(double y, int i)
          gets the offset of an y-value, measured in pixels from the north border of the chart surrounding box
protected  void initialize(java.awt.Graphics g)
          initializes the space of the chart (used if no data are available yet)
protected static boolean isEven(int i)
          checks whether argument is an even number or an odd number
 void paint(java.awt.Graphics g)
          paints the chart (or the message if chart cannot be initialize yet)
 void removeAllSeries()
          clears all data series
 void renderNewPoints()
          renders the new data points without repainting the whole chart
private  boolean requireRescale()
          checks if the chart requires a rescaling
private  void safeDrawChartLines(java.awt.Graphics g)
          draws the lines of the chart
 void setSerie(DataSerie ds)
          sets new values of a serie.
 void setSubTitle()
          sets the sub title
 void setTitle(java.lang.String title)
          sets the title
 void setXAxisLabel(java.lang.String label)
          sets the x-axis label
 void setXNumberFormat(int format)
          sets the number format for the x-axis label
private  void storeScale()
          stores the current values of the x and y scale
protected  void updateInsets()
          updates the insets around the chart
protected  void updateYScale()
          updates the y min values and the y axis length (in displayed units)
 
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, paintBorder, paintChildren, paintComponent, 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, transferFocusBackward, 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, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

serialVersionUID

private static final long serialVersionUID
The serial version number

See Also:
Constant Field Values

LN10

private static final double LN10
Natural logarithmus of 10


INTEGER

public static final int INTEGER
See Also:
Constant Field Values

SCIENTIFIC

public static final int SCIENTIFIC
See Also:
Constant Field Values

NUMBER_OF_MINOR_Y_GRIDLINES

public static final int NUMBER_OF_MINOR_Y_GRIDLINES
See Also:
Constant Field Values

chartInitialized

protected boolean chartInitialized

serie

protected DataSerie[] serie
the data serie


nSer

protected int nSer
number of data series in the chart


NSERMAX

protected static final int NSERMAX
maximum number of data serie that can be displayed at once

See Also:
Constant Field Values

frc

protected java.awt.font.FontRenderContext frc
FontRenderContext of Graphics2D


titLab

protected java.lang.String titLab
title label


xAxiLab

protected java.lang.String xAxiLab
x-axis label


xAxiTic

protected double[] xAxiTic
x-axis ticks


x0

protected double x0
x-axis minimum in displayed units (not pixels)


x1

protected double x1
x-axis maximum in displayed units (not pixels)


x0Last

protected double x0Last
x-axis minimum of the last rendering in displayed units (not pixels)


x1Last

protected double x1Last
x-axis maximum of the last rendering in displayed units (not pixels)


yAxiLenVal

protected double[] yAxiLenVal
y-axis lenght in displayed units (not pixels)


y0

protected double[] y0
y-axis minimum in displayed units (not pixels)


y1

protected double[] y1
y-axis maximum in displayed units (not pixels)


y0Last

protected double[] y0Last
y-axis minimum of the last rendering in displayed units (not pixels)


y1Last

protected double[] y1Last
y-axis maximum of the last rendering in displayed units (not pixels)


foTi

protected java.awt.Font foTi
title Font


titLay

protected java.awt.font.TextLayout titLay
title TextLayout


subTitLay

protected java.awt.font.TextLayout subTitLay
sub title TextLayout


foSuTi

protected java.awt.Font foSuTi
sub title Font


foLa

protected java.awt.Font foLa
label Font


labAsc

protected int labAsc
ascent of label


ins

protected int ins
inset around everything


insChaWest

protected int insChaWest
inset of the chart on the west side


insChaNorth

protected int insChaNorth
inset of the chart on the north side


insXLabNorth

protected int insXLabNorth
inset of x-axis label on the north side


insY0LabNorth

protected int insY0LabNorth
inset of the y0 label on the north side


insYHalfLabNorth

protected int insYHalfLabNorth
inset of the y half label on the north side


insY1LabNorth

protected int insY1LabNorth
inset of the y1 label on the north side


insYLab

protected int[] insYLab
inset of each y-axis label


insNameNorth

protected int[] insNameNorth
inset of each serie name on the north side


insNameWest

protected int[] insNameWest
inset of each serie name on the west side


xNumFor

protected int xNumFor
number format of x-axis label


chartDX

protected int chartDX
x extension of chart


chartDY

protected int chartDY
y extension of the chart


MINPOI

protected final int MINPOI
number of points for which the graph is drawn

See Also:
Constant Field Values

MANTISSA_LENGTH

protected static int MANTISSA_LENGTH
lenght of mantissa field


NUMBER_OF_DIGITS

protected static int NUMBER_OF_DIGITS
number of digits after decimal point


LG_10

private static double LG_10
the natural logarithm (base e) of 10


STANDARD_COLOR

private static final java.awt.Color[] STANDARD_COLOR
the standard color to be assigned


NUMBER_OF_COLORS

private static final int NUMBER_OF_COLORS
the number of available colors


xAxiLen

private double xAxiLen
x-axis lenght in x units

Constructor Detail

LineChart

public LineChart()
Constructor.

Method Detail

setXNumberFormat

public final void setXNumberFormat(int format)
sets the number format for the x-axis label

Parameters:
format - the number format

setSubTitle

public final void setSubTitle()
sets the sub title


setTitle

public final void setTitle(java.lang.String title)
sets the title

Parameters:
title - the title of the chart

setXAxisLabel

public final void setXAxisLabel(java.lang.String label)
sets the x-axis label

Parameters:
label - the x-axis label

removeAllSeries

public final void removeAllSeries()
clears all data series


add

public final void add(DataSerie ds)
               throws java.lang.IllegalArgumentException
adds a data serie to the chart

Parameters:
ds - the data serie
Throws:
if - the name of the serie is not unique
java.lang.IllegalArgumentException

setSerie

public final void setSerie(DataSerie ds)
                    throws java.lang.IllegalArgumentException
sets new values of a serie. The serie is identified by its name

Parameters:
ds - the data serie
Throws:
java.lang.IllegalArgumentException - if the serie is not registered yet

getAxisLabel

protected final java.lang.String getAxisLabel(double x)
gets an axis label

Parameters:
x - the number to be parsed

getTicks

public static final double[] getTicks(double xMin,
                                      double xMax)
gets the label ticks

Parameters:
xMin - the minimum data point of the axis
xMax - the maximum data point of the axis

getXAxisLabel

protected final java.lang.String[] getXAxisLabel()
gets the x axis labels


computeXAxisTicks

protected final void computeXAxisTicks()
gets the x maximum label


updateYScale

protected final void updateYScale()
updates the y min values and the y axis length (in displayed units)


getLabelStringWidth

private int getLabelStringWidth(java.lang.String label)

updateInsets

protected final void updateInsets()
updates the insets around the chart


isEven

protected static final boolean isEven(int i)
checks whether argument is an even number or an odd number

Parameters:
i - the argument to be tested
Returns:
true if i is even, false otherwise

getMaxPoints

protected final int getMaxPoints()
gets the maximal number of data in all series

Returns:
the maximal number of data in all series

paint

public void paint(java.awt.Graphics g)
paints the chart (or the message if chart cannot be initialize yet)

Overrides:
paint in class javax.swing.JComponent
Parameters:
g - the Graphics Object

requireRescale

private final boolean requireRescale()
checks if the chart requires a rescaling

Returns:
true if the chart requires a rescaling false otherwise

renderNewPoints

public final void renderNewPoints()
renders the new data points without repainting the whole chart


safeDrawChartLines

private void safeDrawChartLines(java.awt.Graphics g)
draws the lines of the chart

Parameters:
g - reference to graphics object

drawTitle

protected void drawTitle(java.awt.Graphics2D g)
draws the chart title

Parameters:
g - the Graphics Object

drawLegend

protected final void drawLegend(java.awt.Graphics g)
draws the chart label

Parameters:
g - the Graphics Object

drawBox

protected final void drawBox(java.awt.Graphics g)
draws the box around the chart

Parameters:
g - the Graphics Object

getXPointOffset

protected final int getXPointOffset(double x)
gets the offset of an x-value, measured in pixels from the west border of the chart surrounding box

Parameters:
x - the x-value (not in pixels)
Returns:
the offset

getYPointOffset

protected final int getYPointOffset(double y,
                                    int i)
gets the offset of an y-value, measured in pixels from the north border of the chart surrounding box

Parameters:
y - the function value f(x)
i - the number of the data serie to which the point belongs to
Returns:
the offset

storeScale

private final void storeScale()
stores the current values of the x and y scale


drawWholeChart

protected final void drawWholeChart(java.awt.Graphics2D g)
draws the whole chart

Parameters:
g - the Graphics Object

initialize

protected void initialize(java.awt.Graphics g)
initializes the space of the chart (used if no data are available yet)

Parameters:
g - the Graphics Object