iglu.polka
Class PLineGraph

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--iglu.polka.PLineGraph
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class PLineGraph
extends javax.swing.JPanel

Draw 2D data sets. These sets are implemented by GraphData2D. This graph adds itself as a data change listener on all added data sets and redraws itself whenever some of its data is changed. Various options for controlling appearance are included, but many more could be added.

Version:
1.0
Author:
Travis Bauer
See Also:
GraphData2D, Serialized Form

Field Summary
private  double closestDistance
          distance to the closes point from the mouse
private  OrderedPoint2D closestPoint
          the closes point if it's turned on
private  boolean drawAxes
          Should be axes be drawn.
private  java.awt.Color graphcolor
          Color of the graph
private  boolean highlightClosest
           
private  double highX
          High end of the X range.
private  double highY
          High end of the y range.
(package private)  java.awt.Insets insets
          The spaces around the edge of the JLabel where we can't draw.
private  java.util.LinkedList lines
          The lines in the graph.
private  double lowX
          Low end of the X range.
private  double lowY
          The low end of the Y range.
private  double pixelDist
           
private  boolean pointTracking
           
(package private)  double xScale
          How to transform the x points to pixel values.
(package private)  double yScale
          How to transform the y values to pixel values.
 
Fields inherited from class javax.swing.JPanel
 
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.Container
 
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
PLineGraph(double lowX, double highX, double lowY, double highY)
          Creates new PLineGraph
 
Method Summary
 void addLine(GraphData2D gd)
          add a new line to the graph.
 void clearLines()
          Erase all the points and their labels.
protected  OrderedPoint2D closestScreenPoint(GraphData2D gd, int x, int y)
           
private  int drawableX(double x)
          Change a point X value to a pixel X value.
private  int drawableY(double y)
          Change a point Y value to a pixel Y value.
 void enableHighlightClosestPoint()
           
 void enablePointTracking(double nPixelDist)
          install the listeners so that the graph keeps track of the closest point to the mouse, and its distance
 double getClosestDistance()
           
 OrderedPoint2D getClosestPoint()
           
 java.awt.Color getColor()
          Get the background color
static void main(java.lang.String[] argv)
          Draws a simple three point graph.
 void paint(java.awt.Graphics g)
          Draws the graph.
protected  void paintALine(GraphData2D gd, java.awt.Graphics g)
          Draws one dataset.
 void removeLine(GraphData2D gd)
           
 void setColor(java.awt.Color nc)
          Set the background color
 void setDomain(double lowX, double highX)
          Set the X values for the graph.
 void setDrawAxes(boolean drawAxes)
          Sets whether the axes are drawn.
 void setRange(double lowY, double highY)
          Set the Y values for the graph.
 double virtualX(int x)
          Returns the virtual value of X, given a drawable X
 double virtualY(int y)
          Returns the virtual value of Y, given a drawable Y
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, paintBorder, paintChildren, paintComponent, paintImmediately, paintImmediately, 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
 

Field Detail

lowY

private double lowY
The low end of the Y range.


highY

private double highY
High end of the y range.


lowX

private double lowX
Low end of the X range.


highX

private double highX
High end of the X range.


drawAxes

private boolean drawAxes
Should be axes be drawn.


graphcolor

private java.awt.Color graphcolor
Color of the graph


lines

private java.util.LinkedList lines
The lines in the graph. A collection of GraphData2D


closestPoint

private OrderedPoint2D closestPoint
the closes point if it's turned on


closestDistance

private double closestDistance
distance to the closes point from the mouse


pointTracking

private boolean pointTracking

highlightClosest

private boolean highlightClosest

pixelDist

private double pixelDist

insets

java.awt.Insets insets
The spaces around the edge of the JLabel where we can't draw.


xScale

double xScale
How to transform the x points to pixel values.


yScale

double yScale
How to transform the y values to pixel values.

Constructor Detail

PLineGraph

public PLineGraph(double lowX,
                  double highX,
                  double lowY,
                  double highY)
Creates new PLineGraph

Parameters:
lowX -
highX -
lowY -
highY -
Method Detail

setColor

public void setColor(java.awt.Color nc)
Set the background color


getColor

public java.awt.Color getColor()
Get the background color


setRange

public void setRange(double lowY,
                     double highY)
Set the Y values for the graph.

Parameters:
lowY -
highY -

setDomain

public void setDomain(double lowX,
                      double highX)
Set the X values for the graph.

Parameters:
lowX -
highX -

clearLines

public void clearLines()
Erase all the points and their labels. Does not redraw the graph.


removeLine

public void removeLine(GraphData2D gd)

addLine

public void addLine(GraphData2D gd)
add a new line to the graph. Registers a listener with the data set so that when it is changed, the graph will be redrawn

Parameters:
gd -

setDrawAxes

public void setDrawAxes(boolean drawAxes)
Sets whether the axes are drawn.

Parameters:
drawAxes -

paint

public void paint(java.awt.Graphics g)
Draws the graph. You should probably never call this function. Call repaint instead.

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

paintALine

protected void paintALine(GraphData2D gd,
                          java.awt.Graphics g)
Draws one dataset. Follows stipulations specified by the GraphData2D.

Parameters:
gd -
g -

drawableX

private int drawableX(double x)
Change a point X value to a pixel X value.

Parameters:
x -

virtualX

public double virtualX(int x)
Returns the virtual value of X, given a drawable X


drawableY

private int drawableY(double y)
Change a point Y value to a pixel Y value.

Parameters:
y -

virtualY

public double virtualY(int y)
Returns the virtual value of Y, given a drawable Y


enablePointTracking

public void enablePointTracking(double nPixelDist)
install the listeners so that the graph keeps track of the closest point to the mouse, and its distance


enableHighlightClosestPoint

public void enableHighlightClosestPoint()

closestScreenPoint

protected OrderedPoint2D closestScreenPoint(GraphData2D gd,
                                            int x,
                                            int y)

getClosestPoint

public OrderedPoint2D getClosestPoint()

getClosestDistance

public double getClosestDistance()

main

public static void main(java.lang.String[] argv)
Draws a simple three point graph.

Parameters:
argv -