JIDE 3.5.15

com.jidesoft.chart.event
Class ChartValueReporter

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 com.jidesoft.chart.event.ChartValueReporter
All Implemented Interfaces:
MouseListener, MouseMotionListener, ImageObserver, MenuContainer, Serializable, EventListener, Accessible

public class ChartValueReporter
extends JPanel
implements MouseListener, MouseMotionListener

A ChartValueReporter shows the position of the 'focus' point as x and y coordinates. ChartValueReporter supports numeric and time axes. To display a formatted string for a time axis, use something like the following:

chartValueReporter.setFormatString("x = %1$tH:%1$tM; y = %2$.3f");

This displays the hours and minutes of the time on the x axis, along with a numeric value for the y axis, given to 3 decimal places.

See Also:
Formatter, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, 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
ChartValueReporter(Chart newChart)
          Constructs a ChartValueReporter that reports the value around the cursor point of the supplied chart.
ChartValueReporter(ChartCrossHair crossHair)
          This constructor acknowledges the fact that a ChartValueReporter is often used in conjunction with a CrossHair.
 
Method Summary
protected  void clearChartValue()
          Clears the reported value and resets the last known cursor position.
 Double getChartX()
          Returns the x coordinate (in user coordinates) of the current chart value
 Double getChartY()
          Returns the y coordinate (in user coordinates) of the current chart value
 String getFormatString()
          Returns the format string used for reporting the current value in the chart
 ChartModel getModel()
          Returns the model of interest, if any
 String getNoSelectionText()
          Returns the text used when there is no point selected and no chart value to report
 void mouseClicked(MouseEvent e)
          Not used
 void mouseDragged(MouseEvent e)
          Not used
 void mouseEntered(MouseEvent e)
          Not used
 void mouseExited(MouseEvent e)
          Clears the reported value when the mouse exits the chart
 void mouseMoved(MouseEvent e)
          Updates the reported value when the mouse moves
 void mousePressed(MouseEvent e)
          Not used
 void mouseReleased(MouseEvent e)
          Not used
 void setFormatString(String formatString)
          Sets the format string used for displaying the current chart value.
 void setModel(ChartModel model)
          If you set the model of the ChartValueReporter, then only points from that model will be reported.
 void setNoSelectionText(String noSelectionText)
          Set the text to use when no point is selected and there is no chart value to report.
protected  void setText(String text)
          Sets the text of the ChartValueReporter to be the specified value
 void update()
          Update the reported value using the latest known cursor position.
protected  void updateChartValue(double x, double y)
          Updates the reported value with the supplied x and y coordinates
 
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, 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, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, 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, 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
 
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
 

Constructor Detail

ChartValueReporter

public ChartValueReporter(Chart newChart)
Constructs a ChartValueReporter that reports the value around the cursor point of the supplied chart.

When you use this constructor, you will need to register the instance as a MouseListener and a MouseMotionListener on the chart

Parameters:
newChart - the Chart instance for which we wish to create a ChartValueReporter

ChartValueReporter

public ChartValueReporter(ChartCrossHair crossHair)
This constructor acknowledges the fact that a ChartValueReporter is often used in conjunction with a CrossHair. As the CrossHair will already need to be registered as a MouseListener and a MouseMotionListener on the chart, it is more efficient for the reporter to listen to property changes on the CrossHair to decide when it needs to be updated. (This is especially the case when the crossHair has the SnapToPoints property set to true.) The constructor auto-registers the instance as a listener on the CrossHair, so you don't have to do it.

Parameters:
crossHair - the crossHair that is being used on the chart of interest.
Method Detail

clearChartValue

protected void clearChartValue()
Clears the reported value and resets the last known cursor position.


updateChartValue

protected void updateChartValue(double x,
                                double y)
Updates the reported value with the supplied x and y coordinates

Parameters:
x - the x value in user coordinate space
y - the y value in user coordinate space

setText

protected void setText(String text)
Sets the text of the ChartValueReporter to be the specified value

Parameters:
text - the updated text to display

getFormatString

public String getFormatString()
Returns the format string used for reporting the current value in the chart

Returns:
the format string

setFormatString

public void setFormatString(String formatString)
Sets the format string used for displaying the current chart value. The string used should be suitable for displaying two floating point values. For example, it could be "x = %.3f, y = %.3f"

Parameters:
formatString - the format string to use

getNoSelectionText

public String getNoSelectionText()
Returns the text used when there is no point selected and no chart value to report

Returns:
the text used when there is no selection in the corresponding chart

setNoSelectionText

public void setNoSelectionText(String noSelectionText)
Set the text to use when no point is selected and there is no chart value to report.

Parameters:
noSelectionText - the text to use when no point is selected

getChartX

public Double getChartX()
Returns the x coordinate (in user coordinates) of the current chart value

Returns:
the x coordinate

getChartY

public Double getChartY()
Returns the y coordinate (in user coordinates) of the current chart value

Returns:
the y coordinate

mouseClicked

public void mouseClicked(MouseEvent e)
Not used

Specified by:
mouseClicked in interface MouseListener

mousePressed

public void mousePressed(MouseEvent e)
Not used

Specified by:
mousePressed in interface MouseListener

mouseReleased

public void mouseReleased(MouseEvent e)
Not used

Specified by:
mouseReleased in interface MouseListener

mouseDragged

public void mouseDragged(MouseEvent e)
Not used

Specified by:
mouseDragged in interface MouseMotionListener

mouseEntered

public void mouseEntered(MouseEvent e)
Not used

Specified by:
mouseEntered in interface MouseListener

mouseExited

public void mouseExited(MouseEvent e)
Clears the reported value when the mouse exits the chart

Specified by:
mouseExited in interface MouseListener

mouseMoved

public void mouseMoved(MouseEvent e)
Updates the reported value when the mouse moves

Specified by:
mouseMoved in interface MouseMotionListener

getModel

public ChartModel getModel()
Returns the model of interest, if any

Returns:
the model of interest

setModel

public void setModel(ChartModel model)
If you set the model of the ChartValueReporter, then only points from that model will be reported. Otherwise points from the nearest model will be reported.

Parameters:
model - the model from which points should be reported

update

public void update()
Update the reported value using the latest known cursor position. You should not need to call this method directly.


JIDE 3.5.15