|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object | +--java.awt.Component | +--java.awt.Container | +--javax.swing.JComponent | +--javax.swing.JPanel | +--org.sape.carbon.services.swing.graph.GraphCanvas
This class provides a consistent space within to graph real numbers. It provides features such as auto-centering and real-time scaling. A user of this graph provides data by creating one or more tracks and then adding real points to those. Calling translate periodically allows you to create a scrolling graph as well.
This graph will also maintain tick marks that resize and can be stuck to the sides of the screen so they are always visible even if the origin is off-screen.
Copyright 2001 Sapient
Nested Class Summary | |
static class |
GraphCanvas.Track
|
Field Summary | |
protected Color |
backgroundColor
The background color for this graph |
protected static NumberFormat |
bigNumberLabelFormat
|
private static double |
BORDER_PERCENT
The portion of the entire height that should be researved as a border, above and below the highest and lowest track points |
protected Rectangle2D |
graphBounds
The current graph bounds that are visible |
protected static NumberFormat |
labelFormat
|
private Map |
tracks
A list of Track's that are a part of this graph |
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 | |
GraphCanvas()
Instantiates a graph canvas |
Method Summary | |
void |
addPoint(String track,
Point2D point)
|
void |
addTrack(String trackName)
|
void |
addTrack(String trackName,
Color color)
|
void |
clear()
|
void |
clearAll()
|
void |
clipOld()
|
protected void |
drawAxes(Graphics2D g,
AffineTransform transform)
This draws the axes |
protected void |
drawKey(Graphics2D g,
AffineTransform transform)
Draw the key to the tracks by calling thier toString |
protected void |
drawLines(Graphics2D g,
AffineTransform transform)
This draws the tick marks in the graph |
protected void |
drawTracks(Graphics2D g,
AffineTransform transform)
|
static Point2D |
floorPoint(Point2D point,
Rectangle2D rect)
This finds the closest point on a rectangle's edge to a point outside the rectangle or if that point is within the rectangle it is returned. |
Rectangle2D |
getGraphBounds()
Gets the bounds of the graphing space that are currently showing on the screen. |
GraphCanvas.Track |
getTrack(String trackName)
|
AffineTransform |
getTransform()
|
static void |
main(String[] args)
|
void |
paint(Graphics gg)
|
void |
setBackgroundColor(Color color)
Sets the background color of this graph |
void |
setGraphBounds(Rectangle2D rect)
Sets the bounds that this graph is displaying |
void |
translate(double x,
double y)
Translates the main graph rect by x and y, horizontally and vertically respectively. |
void |
verticalBound()
Bounds the graph to the limits of the tracks verticaly providing a useful scaling. |
Methods inherited from class javax.swing.JPanel |
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
Field Detail |
private Map tracks
protected Rectangle2D graphBounds
private static final double BORDER_PERCENT
protected Color backgroundColor
protected static NumberFormat labelFormat
protected static NumberFormat bigNumberLabelFormat
Constructor Detail |
public GraphCanvas()
Method Detail |
public void setBackgroundColor(Color color)
Sets the background color of this graph
color
- the Color to set the background topublic Rectangle2D getGraphBounds()
public void setGraphBounds(Rectangle2D rect)
rect
- the Rectangle2D of the desired graph pointspublic AffineTransform getTransform()
public void clear()
public void addTrack(String trackName)
public void addTrack(String trackName, Color color)
public void addPoint(String track, Point2D point)
public GraphCanvas.Track getTrack(String trackName)
public void clearAll()
public void paint(Graphics gg)
paint
in class JComponent
protected void drawKey(Graphics2D g, AffineTransform transform)
Draw the key to the tracks by calling thier toString
transform
- the Affine Transform to use to determine how to drawprotected void drawTracks(Graphics2D g, AffineTransform transform)
protected void drawAxes(Graphics2D g, AffineTransform transform)
public static Point2D floorPoint(Point2D point, Rectangle2D rect)
This finds the closest point on a rectangle's edge to a point outside the rectangle or if that point is within the rectangle it is returned.
point
- The point to rectangularly floorrect
- The rectangle to floor withinprotected void drawLines(Graphics2D g, AffineTransform transform)
This draws the tick marks in the graph
public void verticalBound()
Bounds the graph to the limits of the tracks verticaly providing a useful scaling. A more intelligent implementation could have minimum bounds to limit the bouncyness to startup.
public void clipOld()
public void translate(double x, double y)
Translates the main graph rect by x and y, horizontally and vertically respectively.
public static void main(String[] args) throws Exception
Exception
|
|||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES All Classes | ||||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |