de.pxlab.gui
Class JChart

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by de.pxlab.gui.JChart
All Implemented Interfaces:
java.awt.event.ComponentListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener
Direct Known Subclasses:
GammaChart, YxyChart

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

This class paints a 2D chart with independent axis models for each axis.

Version:
0.2.3
Author:
H. Irtel
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
static int SAMPLE_LINE
           
static int SAMPLE_POINTS
           
 
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
JChart(AxisModel xm, int nxt, AxisModel ym, int nyt, double y2xr)
          Create a 2D-chart with the given parameters.
JChart(AxisModel xm, int nxt, AxisModel ym, int nyt, double y2xr, ChartListener cl)
          Create a 2D-chart with the given parameters.
 
Method Summary
 void clearSample()
           
 void componentHidden(java.awt.event.ComponentEvent e)
           
 void componentMoved(java.awt.event.ComponentEvent e)
           
 void componentResized(java.awt.event.ComponentEvent e)
          The ComponentListener is implemented for detecting size changes which require a recomputation of the chart's geometry.
 void componentShown(java.awt.event.ComponentEvent e)
           
 java.awt.Dimension getMinimumSize()
          Return the minimum size of the chart.
 java.awt.Dimension getPreferredSize()
          Return the preferred size of the chart.
 double getXValue()
          Return the current chart position's x coordinate.
 double getYValue()
          Return the current chart position's y coordinate.
 boolean isEnabled()
           
 void mouseClicked(java.awt.event.MouseEvent e)
           
 void mouseDragged(java.awt.event.MouseEvent e)
           
 void mouseEntered(java.awt.event.MouseEvent e)
           
 void mouseExited(java.awt.event.MouseEvent e)
           
 void mouseMoved(java.awt.event.MouseEvent e)
           
 void mousePressed(java.awt.event.MouseEvent e)
           
 void mouseReleased(java.awt.event.MouseEvent e)
           
 void paintComponent(java.awt.Graphics g)
          Paint the chart's geometry including the curent color marker and the valid color region.
 void setChartMouseExtension(ChartMouseExtension p)
          Set this chart's mouse extension hook to the given extension object.
 void setChartPaintExtension(ChartPaintExtension p)
          Set this chart's paint extension hook to the given extension object.
 void setEnabled(boolean e)
           
 void setFirstXLabelAtTick(int n)
          Set the index of the x ticks where the first label appears.
 void setFirstYLabelAtTick(int n)
          Set the index of the y ticks where the first label appears.
 void setLabelPrecision(int x)
          Set the number of decimal digits to be printed in the labels.
 void setMarkSize(int s)
          Set the size of the marker which marks the current position.
 void setNumberOfLargeXTicks(int nxt)
           
 void setNumberOfLargeYTicks(int nyt)
           
 void setPreferredHorizontalSpacing(int leftBorder, int gridWidth, int rightBorder)
          Set the preferred horizontal spacing of the chart.
 void setPreferredVerticalSpacing(int topBorder, int gridHeight, int bottomBorder)
          Set the preferred vertical spacing of the chart.
 void setSample(double[] a, int s)
          Set the sample coordinates.
 void setShowPosition(boolean a)
          If this method is called with a true argument then the most recent or 'current' position is marked in the chart.
 void setShowSample(boolean a)
           
 void setShowSample(boolean a, int t)
           
 void setTitle(java.lang.String t)
          Set the title line of this chart.
 void setValidRegion(double[] a)
          Set the chart's valid region.
 void setValue(double x, double y)
          Set the chart position to (x,y).
 void setXAxisModel(AxisModel m)
           
 void setXLabelAtEveryTick(int n)
          Set the number of index steps between successive labels.
 void setXLabelPrecision(int x)
          Set the number of decimal digits to be printed in the labels.
 void setYAxisModel(AxisModel m)
           
 void setYLabelAtEveryTick(int n)
          Set the number of index steps between successive labels.
 void setYLabelPrecision(int x)
          Set the number of decimal digits to be printed in the labels.
 void setYUnitToXUnitRatio(double y2xr)
           
 int xTransform(double x)
          Transform the model's x coordinate to the chart's horizontal pixel position.
 int yTransform(double y)
          Transform the model's y coordinate to the chart's vertical pixel position.
 
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, getNextFocusableComponent, getPopupLocation, 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, 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, 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

SAMPLE_POINTS

public static final int SAMPLE_POINTS
See Also:
Constant Field Values

SAMPLE_LINE

public static final int SAMPLE_LINE
See Also:
Constant Field Values
Constructor Detail

JChart

public JChart(AxisModel xm,
              int nxt,
              AxisModel ym,
              int nyt,
              double y2xr)
Create a 2D-chart with the given parameters.

Parameters:
xm - AxisModel for the x-axis
nxt - number of large x-axis ticks
ym - AxisModel for the y-axis
nyt - number of large y-axis ticks
y2xr - ratio of y-axis steps to x-axis steps on the screen

JChart

public JChart(AxisModel xm,
              int nxt,
              AxisModel ym,
              int nyt,
              double y2xr,
              ChartListener cl)
Create a 2D-chart with the given parameters.

Parameters:
xm - AxisModel for the x-axis
nxt - number of large x-axis ticks
ym - AxisModel for the y-axis
nyt - number of large y-axis ticks
y2xr - ratio of y-axis steps to x-axis steps on the screen
cl - ChartListener for this chart
Method Detail

setEnabled

public void setEnabled(boolean e)
Overrides:
setEnabled in class javax.swing.JComponent

isEnabled

public boolean isEnabled()
Overrides:
isEnabled in class java.awt.Component

setXAxisModel

public void setXAxisModel(AxisModel m)

setYAxisModel

public void setYAxisModel(AxisModel m)

setNumberOfLargeXTicks

public void setNumberOfLargeXTicks(int nxt)

setNumberOfLargeYTicks

public void setNumberOfLargeYTicks(int nyt)

setYUnitToXUnitRatio

public void setYUnitToXUnitRatio(double y2xr)

getXValue

public double getXValue()
Return the current chart position's x coordinate.


getYValue

public double getYValue()
Return the current chart position's y coordinate.


setValue

public void setValue(double x,
                     double y)
Set the chart position to (x,y). Note that this method does not result in a message to the ChartListener.


setPreferredHorizontalSpacing

public void setPreferredHorizontalSpacing(int leftBorder,
                                          int gridWidth,
                                          int rightBorder)
Set the preferred horizontal spacing of the chart.


setPreferredVerticalSpacing

public void setPreferredVerticalSpacing(int topBorder,
                                        int gridHeight,
                                        int bottomBorder)
Set the preferred vertical spacing of the chart.


getPreferredSize

public java.awt.Dimension getPreferredSize()
Return the preferred size of the chart.

Overrides:
getPreferredSize in class javax.swing.JComponent

getMinimumSize

public java.awt.Dimension getMinimumSize()
Return the minimum size of the chart.

Overrides:
getMinimumSize in class javax.swing.JComponent

setLabelPrecision

public void setLabelPrecision(int x)
Set the number of decimal digits to be printed in the labels.


setTitle

public void setTitle(java.lang.String t)
Set the title line of this chart.


setXLabelPrecision

public void setXLabelPrecision(int x)
Set the number of decimal digits to be printed in the labels.


setYLabelPrecision

public void setYLabelPrecision(int x)
Set the number of decimal digits to be printed in the labels.


setFirstXLabelAtTick

public void setFirstXLabelAtTick(int n)
Set the index of the x ticks where the first label appears.


setFirstYLabelAtTick

public void setFirstYLabelAtTick(int n)
Set the index of the y ticks where the first label appears.


setXLabelAtEveryTick

public void setXLabelAtEveryTick(int n)
Set the number of index steps between successive labels.


setYLabelAtEveryTick

public void setYLabelAtEveryTick(int n)
Set the number of index steps between successive labels.


setMarkSize

public void setMarkSize(int s)
Set the size of the marker which marks the current position.


paintComponent

public void paintComponent(java.awt.Graphics g)
Paint the chart's geometry including the curent color marker and the valid color region.

Overrides:
paintComponent in class javax.swing.JComponent

setShowPosition

public void setShowPosition(boolean a)
If this method is called with a true argument then the most recent or 'current' position is marked in the chart.


setChartPaintExtension

public void setChartPaintExtension(ChartPaintExtension p)
Set this chart's paint extension hook to the given extension object. The extension object's method extendedPaint() is called whenever the chart is painted. Paint extension is switched off by sending a null pointer to this method.


setChartMouseExtension

public void setChartMouseExtension(ChartMouseExtension p)
Set this chart's mouse extension hook to the given extension object. Mouse extension is switched off by sending a null pointer to this method.


setShowSample

public void setShowSample(boolean a)

setShowSample

public void setShowSample(boolean a,
                          int t)

setSample

public void setSample(double[] a,
                      int s)
Set the sample coordinates. Note that coordinates are given in the axis models' coordinates.


clearSample

public void clearSample()

setValidRegion

public void setValidRegion(double[] a)
Set the chart's valid region. The valid region is a region which may restrict the cursor movement within the chart. The cursor crosshair is switched off when it leaves the valid region. The input array is an array of pairs of doubles which hold the x- and y-coordinate of the valid region vertex points. Coordinates are given in the axis models' space.


xTransform

public int xTransform(double x)
Transform the model's x coordinate to the chart's horizontal pixel position.


yTransform

public int yTransform(double y)
Transform the model's y coordinate to the chart's vertical pixel position.


mouseDragged

public void mouseDragged(java.awt.event.MouseEvent e)
Specified by:
mouseDragged in interface java.awt.event.MouseMotionListener

mouseMoved

public void mouseMoved(java.awt.event.MouseEvent e)
Specified by:
mouseMoved in interface java.awt.event.MouseMotionListener

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

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

componentResized

public void componentResized(java.awt.event.ComponentEvent e)
The ComponentListener is implemented for detecting size changes which require a recomputation of the chart's geometry.

Specified by:
componentResized in interface java.awt.event.ComponentListener

componentHidden

public void componentHidden(java.awt.event.ComponentEvent e)
Specified by:
componentHidden in interface java.awt.event.ComponentListener

componentMoved

public void componentMoved(java.awt.event.ComponentEvent e)
Specified by:
componentMoved in interface java.awt.event.ComponentListener

componentShown

public void componentShown(java.awt.event.ComponentEvent e)
Specified by:
componentShown in interface java.awt.event.ComponentListener