iglu.polka
Class GraphData2D

java.lang.Object
  |
  +--iglu.polka.GraphData2D

public class GraphData2D
extends java.lang.Object

A collection of data for a two-dimensional graph. Describes how the data should be drawn and stores the data itself. This class is synchronized across methods that change or access the data points.

Author:
Travis Bauer

Field Summary
private  java.awt.Color color
          The color of this line on the graph
private  java.util.LinkedList dataChangeListeners
          The data to be drawn.
private  boolean drawIcons
          Size of the icon.
private  boolean drawLabels
          Should the point labels be drawn.
private  boolean drawLines
          Should lines be drawn between the points.
private  java.awt.Font labelFont
          What font to use.
private  java.util.Hashtable labels
          The labels to draw.
private  java.util.TreeSet points
          The points on the graph.
 
Constructor Summary
GraphData2D()
          Creates new GraphData2D
 
Method Summary
 void addDataChangeListener(DataChangeListener dcl)
          Add a listener to fire when the line is changed.
 void addPoint(double x, double y)
          Add a point
 void addPoint(double x, double y, java.lang.String label)
          Add a point
 void addPoint(java.awt.geom.Point2D.Double point)
          Add a point to the graph.
 void addPoint(java.awt.geom.Point2D.Double point, java.lang.String label)
          Add a point and associate it with the given label.
 void clearAllPoints()
          Clears all points in the line, but keeps all line drawing information.
 void clearDataChangeListeners()
           
 OrderedPoint2D closestPoint(double x, double y)
          returns the closest point according to the virtual (not screen) coordinates
 void fireDataChange()
          Call the listeners because the data was changed.
 java.awt.Color getColor()
          The color of the line
 boolean getDrawIcons()
          Should the icons be drawn?
 boolean getDrawLabels()
          Should the line labels be drawn?
 boolean getDrawLines()
          Should lines be drawn between the points?
 java.lang.String getLabelFor(OrderedPoint2D point)
          Get a label for the given point.
 java.util.Iterator pointIterator()
          Get an iterator over the points.
 void setColor(java.awt.Color c)
          The color of the line
 void setDrawIcons(boolean drawIcons)
          Should the icons be drawn.
 void setDrawLabels(boolean drawLabels)
          Sets whether the labels are drawn.
 void setDrawLines(boolean drawLines)
          Sets whether the lines are drawn.
 void setLableFont(java.awt.Font newFont)
          Set the font to use to draw labels.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

dataChangeListeners

private java.util.LinkedList dataChangeListeners
The data to be drawn.


drawLines

private boolean drawLines
Should lines be drawn between the points.


labels

private java.util.Hashtable labels
The labels to draw.


labelFont

private java.awt.Font labelFont
What font to use.


drawLabels

private boolean drawLabels
Should the point labels be drawn.


drawIcons

private boolean drawIcons
Size of the icon. Currently, the only possible icon is a little circle


points

private java.util.TreeSet points
The points on the graph.


color

private java.awt.Color color
The color of this line on the graph

Constructor Detail

GraphData2D

public GraphData2D()
Creates new GraphData2D

Method Detail

setLableFont

public void setLableFont(java.awt.Font newFont)
Set the font to use to draw labels.

Parameters:
newFont -

addPoint

public void addPoint(java.awt.geom.Point2D.Double point)
Add a point to the graph. Note:The points will be drawn in order by their X values. You can add points in any order you wish, and the system will sort them by X value for drawing.

Parameters:
point -

addPoint

public void addPoint(java.awt.geom.Point2D.Double point,
                     java.lang.String label)
Add a point and associate it with the given label.

Parameters:
point -
label -

addPoint

public void addPoint(double x,
                     double y)
Add a point


addPoint

public void addPoint(double x,
                     double y,
                     java.lang.String label)
Add a point


clearAllPoints

public void clearAllPoints()
Clears all points in the line, but keeps all line drawing information.


setColor

public void setColor(java.awt.Color c)
The color of the line

Parameters:
c - a Color value

getColor

public java.awt.Color getColor()
The color of the line

Returns:
a Color value

setDrawLines

public void setDrawLines(boolean drawLines)
Sets whether the lines are drawn.

Parameters:
drawLines -

getDrawLines

public boolean getDrawLines()
Should lines be drawn between the points?


setDrawIcons

public void setDrawIcons(boolean drawIcons)
Should the icons be drawn. Currently, only ovals are used as icons


getDrawIcons

public boolean getDrawIcons()
Should the icons be drawn?


setDrawLabels

public void setDrawLabels(boolean drawLabels)
Sets whether the labels are drawn.


getDrawLabels

public boolean getDrawLabels()
Should the line labels be drawn?


pointIterator

public java.util.Iterator pointIterator()
Get an iterator over the points.


getLabelFor

public java.lang.String getLabelFor(OrderedPoint2D point)
Get a label for the given point. Returns an empty string if there is no label.

Parameters:
point -

closestPoint

public OrderedPoint2D closestPoint(double x,
                                   double y)
returns the closest point according to the virtual (not screen) coordinates


addDataChangeListener

public void addDataChangeListener(DataChangeListener dcl)
Add a listener to fire when the line is changed.

Parameters:
dcl -

clearDataChangeListeners

public void clearDataChangeListeners()

fireDataChange

public void fireDataChange()
Call the listeners because the data was changed.