org.ascape.view.vis
Class ChartView

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by org.ascape.view.vis.PanelView
                      extended by org.ascape.view.vis.ChartView
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Externalizable, java.io.Serializable, java.lang.Cloneable, java.util.EventListener, java.util.Observer, javax.accessibility.Accessible, ScapeListener, HasName, ComponentView
Direct Known Subclasses:
AntChartViewElement

public class ChartView
extends PanelView
implements java.util.Observer, java.io.Externalizable

A chart view of a scape. Delegates many functions, including scape listener, to subclasses of ChartViewModel. This view uses KL Group's JChart; if you want to use other charting packages, let us know, we'd like to generalize further so that multiple charting packages can be used. Uses JFreeChart.

Since:
1.0
Version:
2.9
Author:
Miles Parker
See Also:
Serialized Form

Nested Class Summary
 class ChartView.PieChartDataset
          The Class PieChartDataset.
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
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.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
static int ALL_POINTS
          Symbol for 'display all data points.'
static int HISTOGRAM
          Histogram (bar graph) chart type.
static int PIE
          Pie chart type.
static int TIME_SERIES
          Time series (line graph) chart type.
 
Fields inherited from class org.ascape.view.vis.PanelView
delegate, iterationsPerRedraw, name, scape
 
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
ChartView()
          Construct a chart view of default time series type.
ChartView(int chartType)
          Construct a chart view with a specicifed chart type.
ChartView(int chartType, java.lang.String name)
          Construct a chart view of default time series type.
ChartView(java.lang.String name)
          Construct a chart view of default time series type.
 
Method Summary
 void addSeries(java.lang.String valueName)
          Adds a series to the chart being viewed.
 void addSeries(java.lang.String valueName, java.awt.Color color)
          Adds a series to the chart being viewed.
 void clearSeries()
          Clears all series selections from the chart being viewed.
 void displayCustomizer()
          Displays a window for altering the setting for this chart.
 com.jrefinery.chart.JFreeChart getChart()
          Gets the chart.
 int getChartType()
          Gets the chartType.
 BaseCustomizer getCustomizer()
          Returns the customizer for this view.
 DataViewSelection getDataSelection()
          Gets the dataSelection.
 int getDisplayPoints()
          Gets the displayPoints.
 javax.swing.ImageIcon getIcon()
          Return an icon that can be used to represent this frame.
 com.jrefinery.chart.JFreeChartPanel getPanel()
          Gets the panel.
 java.awt.Color getPlotBackground()
          Gets the plot background.
 double getVerticalAxisMax()
          Gets the vertical axis max.
 double getVerticalAxisMin()
          Gets the vertical axis min.
 boolean isForcePosVerticalAxisMinToZero()
          Checks if is force pos vertical axis min to zero.
 boolean isLegendShowing()
          Checks if is legend showing.
 void paintChildren(java.awt.Graphics g)
           
 void readExternal(java.io.ObjectInput in)
          The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays.
 void removeCustomizer()
          Removes the customizer for this chart.
 void removeSeries(java.lang.String valueName)
          Removes a series from the chart being viewed.
 void scapeAdded(ScapeEvent scapeEvent)
          Notifies the view that the scape has added it.
 void scapeDeserialized(ScapeEvent scapeEvent)
          Method called once a model is deserialized.
 void scapeRemoved(ScapeEvent scapeEvent)
          Notifies the listener that the scape has removed it.
 void setBackground(java.awt.Color fg)
           
 void setChartType(int chartType)
          Sets the chartType.
 void setCustomizer(ChartCustomizer customizer)
          Sets the customizer for this view.
 void setDataSelection(DataViewSelection dataSelection)
          Sets the dataSelection.
 void setDisplayPoints(int displayPoints)
          Sets the displayPoints.
 void setForcePosVerticalAxisMinToZero(boolean forcePosVerticalAxisMinToZero)
          Sets the force pos vertical axis min to zero.
 void setForeground(java.awt.Color fg)
           
 void setLegendShowing(boolean legendShowing)
          Sets the legend showing.
 void setName(java.lang.String name)
          Sets the name of this view.
 void setPlotBackground(java.awt.Color bg)
          Sets the plot background.
 void setVerticalAxisMax(double verticalAxisMax)
          Sets the vertical axis max.
 void setVerticalAxisMin(double verticalAxisMin)
          Sets the vertical axis min.
 void update(java.util.Observable observed, java.lang.Object arg)
          Notifies this view model that a change (in the selected group, typically) has occured.
 void updateScapeGraphics()
          Called when scape reports an update event.
 void writeExternal(java.io.ObjectOutput out)
          The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.
 
Methods inherited from class org.ascape.view.vis.PanelView
build, clone, environmentQuiting, forceScapeNotify, getDelegate, getIterationsPerRedraw, getName, getPreferredSizeWithin, getScape, getViewFrame, iconUpdated, isGraphic, isLifeOfScape, notifyScapeUpdated, onChangeIterationsPerRedraw, paintComponent, scapeClosing, scapeInitialized, scapeIterated, scapeNotification, scapeSetup, scapeStarted, scapeStopped, setDelegate, setIterationsPerRedraw, setMovieRecorder, setViewFrame, toString
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintImmediately, paintImmediately, 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, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update
 
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, 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, setSize, setSize, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

TIME_SERIES

public static final int TIME_SERIES
Time series (line graph) chart type. Same as JCChart.PLOT. Note: Chart types have the same ints as cooresponding JCChart chart types. Only the names have been changed to match general usage. Note that this is just for convenience and clarity; these symbols may also be translated for other charting packages. So this usage should not be relied on; whenever possible use these ChartView constants, and not their JCChart counterparts.

See Also:
Constant Field Values

HISTOGRAM

public static final int HISTOGRAM
Histogram (bar graph) chart type.

See Also:
Constant Field Values

PIE

public static final int PIE
Pie chart type.

See Also:
Constant Field Values

ALL_POINTS

public static final int ALL_POINTS
Symbol for 'display all data points.'

See Also:
Constant Field Values
Constructor Detail

ChartView

public ChartView()
Construct a chart view of default time series type.


ChartView

public ChartView(int chartType)
Construct a chart view with a specicifed chart type.

Parameters:
chartType - the charttype symbol

ChartView

public ChartView(java.lang.String name)
Construct a chart view of default time series type.

Parameters:
name - a name for the chart series

ChartView

public ChartView(int chartType,
                 java.lang.String name)
Construct a chart view of default time series type.

Parameters:
chartType - the charttype symbol
name - a name for the chart series
Method Detail

displayCustomizer

public void displayCustomizer()
Displays a window for altering the setting for this chart.


removeCustomizer

public void removeCustomizer()
Removes the customizer for this chart.


setName

public final void setName(java.lang.String name)
Sets the name of this view.

Overrides:
setName in class PanelView
Parameters:
name - a user relevant name for this view

getCustomizer

public BaseCustomizer getCustomizer()
Returns the customizer for this view.

Returns:
the customizer

setCustomizer

public void setCustomizer(ChartCustomizer customizer)
Sets the customizer for this view. Could be used to provde custom chart editors.

Parameters:
customizer - the customizer to use

getChartType

public int getChartType()
Gets the chartType.

Returns:
Returns a int

setChartType

public void setChartType(int chartType)
Sets the chartType.

Parameters:
chartType - The chartType to set

isLegendShowing

public boolean isLegendShowing()
Checks if is legend showing.

Returns:
true, if is legend showing

setLegendShowing

public void setLegendShowing(boolean legendShowing)
Sets the legend showing.

Parameters:
legendShowing - the new legend showing

addSeries

public void addSeries(java.lang.String valueName)
Adds a series to the chart being viewed. Convenience method (could also get view model and set select group.)

Parameters:
valueName - the name of the series to add

addSeries

public void addSeries(java.lang.String valueName,
                      java.awt.Color color)
Adds a series to the chart being viewed. Convenience method.

Parameters:
valueName - the name of the series to add
color - the color to use for the series in the chart

removeSeries

public void removeSeries(java.lang.String valueName)
Removes a series from the chart being viewed. Convenience method.

Parameters:
valueName - the name of the series to remove

clearSeries

public void clearSeries()
Clears all series selections from the chart being viewed. Convenience method.


scapeAdded

public void scapeAdded(ScapeEvent scapeEvent)
                throws java.util.TooManyListenersException
Notifies the view that the scape has added it. Note that it doesn't really matter what scape you add the listener to, as the chart view model will have access to every statistic available for the entire model, but all views still need to be controlled by one particular scape. One and only one scape may be added.

Specified by:
scapeAdded in interface ScapeListener
Overrides:
scapeAdded in class PanelView
Parameters:
scapeEvent - the scape added notification event
Throws:
java.util.TooManyListenersException - on attempt to add this listener to another scape when one has already been assigned
java.util.TooManyListenersException - the too many listeners exception

scapeRemoved

public void scapeRemoved(ScapeEvent scapeEvent)
Notifies the listener that the scape has removed it.

Specified by:
scapeRemoved in interface ScapeListener
Overrides:
scapeRemoved in class PanelView
Parameters:
scapeEvent - the scape removed notification event
See Also:
scapeAdded

update

public void update(java.util.Observable observed,
                   java.lang.Object arg)
Notifies this view model that a change (in the selected group, typically) has occured.

Specified by:
update in interface java.util.Observer
Parameters:
observed - the observed
arg - the arg

getDataSelection

public DataViewSelection getDataSelection()
Gets the dataSelection.

Returns:
Returns a DataViewSelection

setDataSelection

public void setDataSelection(DataViewSelection dataSelection)
Sets the dataSelection.

Parameters:
dataSelection - The dataSelection to set

getDisplayPoints

public int getDisplayPoints()
Gets the displayPoints.

Returns:
Returns a int

setDisplayPoints

public void setDisplayPoints(int displayPoints)
Sets the displayPoints.

Parameters:
displayPoints - The displayPoints to set

getPanel

public com.jrefinery.chart.JFreeChartPanel getPanel()
Gets the panel.

Returns:
the panel

getChart

public com.jrefinery.chart.JFreeChart getChart()
Gets the chart.

Returns:
the chart

getPlotBackground

public java.awt.Color getPlotBackground()
Gets the plot background.

Returns:
the plot background

setPlotBackground

public void setPlotBackground(java.awt.Color bg)
Sets the plot background.

Parameters:
bg - the new plot background

setBackground

public void setBackground(java.awt.Color fg)
Overrides:
setBackground in class javax.swing.JComponent

setForeground

public void setForeground(java.awt.Color fg)
Overrides:
setForeground in class javax.swing.JComponent

isForcePosVerticalAxisMinToZero

public boolean isForcePosVerticalAxisMinToZero()
Checks if is force pos vertical axis min to zero.

Returns:
true, if is force pos vertical axis min to zero

setForcePosVerticalAxisMinToZero

public void setForcePosVerticalAxisMinToZero(boolean forcePosVerticalAxisMinToZero)
Sets the force pos vertical axis min to zero.

Parameters:
forcePosVerticalAxisMinToZero - the new force pos vertical axis min to zero

getVerticalAxisMin

public double getVerticalAxisMin()
Gets the vertical axis min.

Returns:
the vertical axis min

setVerticalAxisMin

public void setVerticalAxisMin(double verticalAxisMin)
Sets the vertical axis min.

Parameters:
verticalAxisMin - the new vertical axis min

getVerticalAxisMax

public double getVerticalAxisMax()
Gets the vertical axis max.

Returns:
the vertical axis max

setVerticalAxisMax

public void setVerticalAxisMax(double verticalAxisMax)
Sets the vertical axis max.

Parameters:
verticalAxisMax - the new vertical axis max

updateScapeGraphics

public void updateScapeGraphics()
Description copied from class: PanelView
Called when scape reports an update event. (No need to call this method after updating panel.)

Specified by:
updateScapeGraphics in interface ComponentView
Overrides:
updateScapeGraphics in class PanelView

paintChildren

public void paintChildren(java.awt.Graphics g)
Overrides:
paintChildren in class javax.swing.JComponent

scapeDeserialized

public void scapeDeserialized(ScapeEvent scapeEvent)
Method called once a model is deserialized.

Specified by:
scapeDeserialized in interface ScapeListener
Overrides:
scapeDeserialized in class PanelView
Parameters:
scapeEvent - the scape event

writeExternal

public void writeExternal(java.io.ObjectOutput out)
                   throws java.io.IOException
Description copied from class: PanelView
The object implements the writeExternal method to save its contents by calling the methods of DataOutput for its primitive values or calling the writeObject method of ObjectOutput for objects, strings, and arrays.

Specified by:
writeExternal in interface java.io.Externalizable
Overrides:
writeExternal in class PanelView
Parameters:
out - the stream to write the object to
Throws:
java.io.IOException - Signals that an I/O exception has occurred.

readExternal

public void readExternal(java.io.ObjectInput in)
                  throws java.io.IOException,
                         java.lang.ClassNotFoundException
Description copied from class: PanelView
The object implements the readExternal method to restore its contents by calling the methods of DataInput for primitive types and readObject for objects, strings and arrays. The readExternal method must read the values in the same sequence and with the same types as were written by writeExternal.

Specified by:
readExternal in interface java.io.Externalizable
Overrides:
readExternal in class PanelView
Parameters:
in - the stream to read data from in order to restore the object
Throws:
java.io.IOException - Signals that an I/O exception has occurred.
java.lang.ClassNotFoundException - the class not found exception

getIcon

public javax.swing.ImageIcon getIcon()
Return an icon that can be used to represent this frame. Returns null in this case, use default. Implementors should specify an icon that makes sense for the view.

Specified by:
getIcon in interface ComponentView
Overrides:
getIcon in class PanelView
Returns:
the icon


Copyright © 1998-2008 The Brookings Institution, NuTech Solutions, Metascape, LLC All Rights Reserved.