Venice 0.751beta

nz.org.venice.chart
Class Chart

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended bynz.org.venice.chart.Chart
All Implemented Interfaces:
java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.event.MouseListener, java.io.Serializable

public class Chart
extends javax.swing.JComponent
implements java.awt.event.MouseListener

New swing component that allows creation of charts. This charting component supports graphing levels and also highlighting of a graph region.

See Also:
ChartModule, Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
 
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
Chart()
          Create a new Chart component.
 
Method Summary
 void add(Graph graph, int index)
          Chart a new graph at the given level.
 java.lang.Comparable calculateEndX()
          Find the highest X value in all the graphs we are going to chart
 java.lang.Comparable calculateStartX()
          Find the lowest X value in all the graphs we are going to chart
 void clearHighlightedRegion()
          Clear the highlighted region.
 boolean contains(int x, int y)
          Return whether the x,y coordinate is within this component.
 int count()
          Return the number of graphs in the chart.
 boolean dataAvailable()
           
 boolean dataAvailable(Graph g)
           
 ChartDrawingModel getChartDrawingModel()
           
 double getDifference(java.lang.Integer x, java.lang.Integer y, int index)
          Generate the equation of the line passing through points specified by index, and return the difference between those points and x,y
 java.lang.Comparable getEndX()
          Get the last X value that appears in the chart.
 java.awt.Color getGraphColour(Graph graph)
          Return the colour that the given graph will be drawn.
 java.lang.Comparable getHighlightedEnd()
          Get the end X of the highlighted region.
 java.lang.Comparable getHighlightedStart()
          Get the start X of the highlighted region.
 java.awt.image.BufferedImage getImage()
           
 int getLevelAtPoint(int point)
           
 java.util.Vector getLevels()
          Return all the graphs for each level.
 boolean getOrientation()
          Return the viewing orientation
 int getSpanDays()
           
 java.lang.Comparable getStartX()
          Get the first X value that appears in the chart.
 java.util.Vector getSymbols()
          Return the window symbols.
 java.lang.String getTitle()
          Return the window title.
 ChartTracking getTracker()
           
 java.lang.String getUIClassID()
          Returns a string that specifies the name of the l&f class that renders this component.
 java.lang.Comparable getXAtPoint(int x)
          Return the X value at the given x coordinate.
 java.util.Vector getXRange()
          Get the range of X values which appear in the chart.
 java.lang.Double getYAtPoint(int y)
          Return the Y value at the given y coordinate.
 void handleAnnotation(Graph graph, boolean enabled)
          Set whether the given graph should display its annotations.
 boolean isAnnotated(Graph graph)
          Query whether the given graph is displaying its annotations.
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 Coordinate move(java.lang.Integer x, java.lang.Integer y)
          Find the line intersecting at x,y.
 void moveTo(int daysFromStart)
           
 void remove(Graph graph)
          Remove the graph from the chart.
 void replace(Graph oldGraph, Graph newGraph)
          Replace the graph from the chart with another graph
 void resetBuffer()
          Reset the double buffer, forcing the graph to redraw.
 void setChartDrawingModel(ChartDrawingModel drawnElements)
           
 void setDrawnLineEnd(java.lang.Comparable dataX, java.lang.Double dataY, java.lang.Integer absY)
          Sets the end point of a drawn line.
 void setDrawnLineStart(java.lang.Comparable dataX, java.lang.Double dataY, java.lang.Integer absY)
          Sets the end point of a drawn line.
 void setErase(java.lang.Comparable dataX, java.lang.Double dataY, java.lang.Integer absY)
          Find the graph element intersecting at x,y and delete it
 void setHighlightedEnd(java.lang.Comparable x)
          Sets the end X point of the highlighted region.
 void setHighlightedStart(java.lang.Comparable x)
          Sets the start X point of the highlighted region.
 void setOrientation(boolean orientation)
          Set the viewing orientation of the chart.
 void setPoint(java.lang.Comparable dataX, java.lang.Double dataY, java.lang.Integer absY)
          Puts a point on a chart.
 void setPoint(Coordinate coord)
          Puts a point on a chart.
 void setText(java.lang.String text, java.lang.Comparable dataX, java.lang.Double dataY, java.lang.Integer absY)
          Put text at x,y.
 void setTracker(ChartTracking tracker)
           
 void setUI(BasicChartUI ui)
          Sets the L&F object that renders this component.
protected  void setXRange(java.lang.Comparable startX, java.lang.Comparable endX)
           
 void updateCursor()
           
 void updateUI()
          Resets the UI property to a value from the current look and feel.
 void zoomToDefaultRegion()
          Draw the graph back at its default zoom.
 void zoomToHighlightedRegion()
          Draw the graph zoomed into the given highlighted region.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, 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
 

Constructor Detail

Chart

public Chart()
Create a new Chart component.

Method Detail

getSpanDays

public int getSpanDays()
Returns:
difference in days between startX and endX

moveTo

public void moveTo(int daysFromStart)

setXRange

protected void setXRange(java.lang.Comparable startX,
                         java.lang.Comparable endX)

getXRange

public java.util.Vector getXRange()
Get the range of X values which appear in the chart.

Returns:
Vector of Comparables

getStartX

public java.lang.Comparable getStartX()
Get the first X value that appears in the chart.


getEndX

public java.lang.Comparable getEndX()
Get the last X value that appears in the chart.

Returns:
TradingDate (Comparable) or null

calculateStartX

public java.lang.Comparable calculateStartX()
Find the lowest X value in all the graphs we are going to chart

Returns:
TradingDate (Comparable) or null

calculateEndX

public java.lang.Comparable calculateEndX()
Find the highest X value in all the graphs we are going to chart

Returns:
TradingDate (Comparable) or null

handleAnnotation

public void handleAnnotation(Graph graph,
                             boolean enabled)
Set whether the given graph should display its annotations.

Parameters:
graph - the graph to modify
enabled - true to turn on graph annotations; false to turn them off

isAnnotated

public boolean isAnnotated(Graph graph)
Query whether the given graph is displaying its annotations.

Parameters:
graph - the graph to query
Returns:
true if the graph is displaying its annotations; false otherwise

add

public void add(Graph graph,
                int index)
Chart a new graph at the given level. If the chart does not contain the level, create a new one.

Parameters:
graph - the new graph to chart
index - the level index

count

public int count()
Return the number of graphs in the chart.

Returns:
the number of graphs in the chart

remove

public void remove(Graph graph)
Remove the graph from the chart. If the graph was an only member of its level, then the level will also be removed.

Parameters:
graph - the graph to remove

replace

public void replace(Graph oldGraph,
                    Graph newGraph)
Replace the graph from the chart with another graph

Parameters:
oldGraph - the graph to remove
newGraph - the replacemnet graph

getLevels

public java.util.Vector getLevels()
Return all the graphs for each level.

Returns:
A Vector where each element represents a a graph level. Each element in the Vector is another Vector containing the graphs at that level.

getGraphColour

public java.awt.Color getGraphColour(Graph graph)
Return the colour that the given graph will be drawn. Note that the graph may choose to override this colour.

Parameters:
graph - the graph to query
Returns:
the colour the graph may be drawn as

setUI

public void setUI(BasicChartUI ui)
Sets the L&F object that renders this component.

Parameters:
ui - the ButtonUI L&F object

updateUI

public void updateUI()
Resets the UI property to a value from the current look and feel.


getXAtPoint

public java.lang.Comparable getXAtPoint(int x)
Return the X value at the given x coordinate.

Parameters:
x - an x coordinate on the screen
Returns:
the X value at the x coordinate

getYAtPoint

public java.lang.Double getYAtPoint(int y)
Return the Y value at the given y coordinate.

Parameters:
y - an x coordinate on the screen
Returns:
the Y value at the y coordinate

contains

public boolean contains(int x,
                        int y)
Return whether the x,y coordinate is within this component.

Parameters:
x - the x coordinate
y - the y coordinate
Returns:
true if the point is within this component; false otherwise.

getUIClassID

public java.lang.String getUIClassID()
Returns a string that specifies the name of the l&f class that renders this component.

Returns:
String "ChartUI"

setHighlightedStart

public void setHighlightedStart(java.lang.Comparable x)
Sets the start X point of the highlighted region. Also resets the end point of the highlighted region to the start point. This creates a highlighted region 1 pixel thick.

Parameters:
x - the starting x value

setHighlightedEnd

public void setHighlightedEnd(java.lang.Comparable x)
Sets the end X point of the highlighted region.

Parameters:
x - the starting x value

setDrawnLineStart

public void setDrawnLineStart(java.lang.Comparable dataX,
                              java.lang.Double dataY,
                              java.lang.Integer absY)
Sets the end point of a drawn line. The line will now stretch from the start to the end point.

Parameters:
dataX - the x data point corresponding to the start of the line
dataY - the y data point corresponding to the start of the line.
absY - the absolute y coordinate of the start of the line

setDrawnLineEnd

public void setDrawnLineEnd(java.lang.Comparable dataX,
                            java.lang.Double dataY,
                            java.lang.Integer absY)
Sets the end point of a drawn line. The line will now stretch from the start to the end point.

Parameters:
dataX - the x data point corresponding to the end of the line
dataY - the y data point corresponding to the end of the line.
absY - the absolute y coordinate of the end of the line

setPoint

public void setPoint(Coordinate coord)
Puts a point on a chart.

Parameters:
coord - the coordinate

setPoint

public void setPoint(java.lang.Comparable dataX,
                     java.lang.Double dataY,
                     java.lang.Integer absY)
Puts a point on a chart.

Parameters:
dataX - the x coordinate
dataY - the relative y coordinate
absY - the absolute y coordinate

setTracker

public void setTracker(ChartTracking tracker)

getTracker

public ChartTracking getTracker()

updateCursor

public void updateCursor()

getDifference

public double getDifference(java.lang.Integer x,
                            java.lang.Integer y,
                            int index)
Generate the equation of the line passing through points specified by index, and return the difference between those points and x,y

Parameters:
x - the x coordinate
y - the y coordinate
index - the index a drawn line

setErase

public void setErase(java.lang.Comparable dataX,
                     java.lang.Double dataY,
                     java.lang.Integer absY)
Find the graph element intersecting at x,y and delete it

Parameters:
dataX - the x data corresponding to the selected point
dataY - the y data corresponding to the selected point
absY - the y coordinate of the selected point

move

public Coordinate move(java.lang.Integer x,
                       java.lang.Integer y)
Find the line intersecting at x,y. Return the coordinate of the end point which the user has chosen.

Parameters:
x - The X Coordinate of the selected point.
y - The Y Coordinate of the selected point.

setText

public void setText(java.lang.String text,
                    java.lang.Comparable dataX,
                    java.lang.Double dataY,
                    java.lang.Integer absY)
Put text at x,y.

Parameters:
text - The text to place on the chart
dataX - The relative X coordinate of the selected point
dataY - The relative Y coordinate of the selected point
absY - The absolute y coordinate of the selected point

getHighlightedStart

public java.lang.Comparable getHighlightedStart()
Get the start X of the highlighted region.

Returns:
the start X

getHighlightedEnd

public java.lang.Comparable getHighlightedEnd()
Get the end X of the highlighted region.

Returns:
the end X

getChartDrawingModel

public ChartDrawingModel getChartDrawingModel()

setChartDrawingModel

public void setChartDrawingModel(ChartDrawingModel drawnElements)

clearHighlightedRegion

public void clearHighlightedRegion()
Clear the highlighted region.


zoomToHighlightedRegion

public void zoomToHighlightedRegion()
                             throws ChartOutOfBoundsException
Draw the graph zoomed into the given highlighted region.

Throws:
ChartOutOfBoundsException

zoomToDefaultRegion

public void zoomToDefaultRegion()
Draw the graph back at its default zoom.


resetBuffer

public void resetBuffer()
Reset the double buffer, forcing the graph to redraw.


getTitle

public java.lang.String getTitle()
Return the window title.

Returns:
the window title

getSymbols

public java.util.Vector getSymbols()
Return the window symbols.

Returns:
the window symbols

mouseClicked

public void mouseClicked(java.awt.event.MouseEvent e)
Specified by:
mouseClicked in interface java.awt.event.MouseListener

mouseEntered

public void mouseEntered(java.awt.event.MouseEvent e)
Specified by:
mouseEntered in interface java.awt.event.MouseListener

mouseExited

public void mouseExited(java.awt.event.MouseEvent e)
Specified by:
mouseExited in interface java.awt.event.MouseListener

mousePressed

public void mousePressed(java.awt.event.MouseEvent e)
Specified by:
mousePressed in interface java.awt.event.MouseListener

mouseReleased

public void mouseReleased(java.awt.event.MouseEvent e)
Specified by:
mouseReleased in interface java.awt.event.MouseListener

getImage

public java.awt.image.BufferedImage getImage()

dataAvailable

public boolean dataAvailable(Graph g)

dataAvailable

public boolean dataAvailable()

setOrientation

public void setOrientation(boolean orientation)
Set the viewing orientation of the chart. Normal orientation is top to bottom.

Parameters:
orientation - A boolean value. If true, chart is drawn from top to bottom, otherwise bottom up.

getOrientation

public boolean getOrientation()
Return the viewing orientation


getLevelAtPoint

public int getLevelAtPoint(int point)

Venice 0.751beta