|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Object java.awt.Component java.awt.Container javax.swing.JComponent javax.swing.JPanel jwo.utils.gui.JWGraph
Simple graph object. Originally based on the code given in the tutorial Chart your way to custom graph components, by Maria Winslow, 1997 (JavaWorld, July, 1997). See www.javaworld.com/javaworld/jw-07-1997/jw-07-step.html. Modified to use Swing and additional axis labelling.
Nested Class Summary |
Nested classes inherited from class javax.swing.JPanel |
JPanel.AccessibleJPanel |
Nested classes inherited from class javax.swing.JComponent |
JComponent.AccessibleJComponent |
Nested classes inherited from class java.awt.Container |
Container.AccessibleAWTContainer |
Nested classes inherited from class java.awt.Component |
Component.AccessibleAWTComponent, Component.BltBufferStrategy, Component.FlipBufferStrategy |
Field Summary | |
protected int |
bottom
Bottom position of graph. |
protected int |
centreX
X coord of centre of graph. |
protected int |
centreY
Y coord of centre of graph. |
static int |
INTERVAL
Measurement scale of data. |
protected Vector |
items
Array of graphic items in graph. |
protected int |
left
Left position of graph. |
static int |
NOMINAL
Measurement scale of data. |
protected Image |
offscreenImage
Image for offscreen double buffering. |
protected Graphics |
og
Offscreen double buffering context. |
static int |
ORDINAL
Measurement scale of data. |
static int |
RATIO
Measurement scale of data. |
protected int |
right
Right position of graph. |
protected int |
top
Top position of graph. |
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 | |
JWGraph()
Minimal advance graph layout (axes only). |
|
JWGraph(String title,
float yMin,
float yMax)
Lays out the graph title, labels etc. |
|
JWGraph(String title,
float xMin,
float xMax,
float yMin,
float yMax)
Lays out the graph title, labels etc. |
|
JWGraph(String title,
float rMin,
float rMax,
float thetaMin,
float thetaMax,
boolean polar)
Lays out the graph title, labels etc as a polar plot. |
|
JWGraph(String title,
float xMin,
float xMax,
float yMin,
float yMax,
String[] labels)
Lays out the graph title, labels etc. |
|
JWGraph(String title,
float xMin,
float xMax,
float yMin,
float yMax,
String[] labels,
int measurementScale)
Lays out the graph title, labels etc. |
|
JWGraph(String title,
float xMin,
float xMax,
String[] labels,
float yMin,
float yMax)
Lays out the graph title, labels etc. |
|
JWGraph(String title,
float xMin,
float xMax,
String[] labels,
float yMin,
float yMax,
int measurementScale)
Lays out the graph title, labels etc. |
Method Summary | |
void |
addItem(float xValue,
float yValue)
Adds a graphical element to the graph. |
void |
addItem(float xValue,
float yValue,
Color col)
Adds a (coloured) graphical element to the graph. |
void |
erase()
Clears the current graph area and redraws it. |
FontMetrics |
getFM()
Reports the font metric used by the graph. |
Dimension |
getPreferredSize()
Reports the preferred size of the graph |
float |
getXMax()
Reports the maximum X value of the graph. |
int |
getXMeasurementScale()
Reports on the measurement scale of the data on the X-axis. |
float |
getXMin()
Reports the minimum X value of the graph. |
float |
getYMax()
Reports the maximum Y value of the graph. |
int |
getYMeasurementScale()
Reports on the measurement scale of the data on the Y-axis. |
float |
getYMin()
Reports the minimum Y value of the graph. |
Color |
makeTransparent(Color inColour)
Modifies a given colour by the currently set opacity level. |
void |
paintComponent(Graphics g)
Overrides the paint method to draw the graph components. |
void |
removeItem(float xValue,
float yValue)
Removes graphical element(s) from the graph (identified by x,y values). |
void |
removeItems()
Removes all graphical elements from the graph. |
void |
setAspectRatio(float aspectRatio)
Sets the aspect ratio for the graph. |
void |
setOpacity(int opacity)
Sets the opacity level for the graph. |
void |
setTitle(String title)
Sets the title of the graph and updates the display. |
void |
setXAxis(float min,
float max)
Sets the x-axis to the given range. |
void |
setXAxis(float min,
float max,
String[] xLabels,
int scale)
Sets the x-axis to the given range using the given measurement scale. |
void |
setXMeasurementScale(int scale)
Sets the measurement scale of the data on the X-axis. |
void |
setYAxis(float min,
float max)
Sets the y-axis to the given range. |
void |
setYAxis(float min,
float max,
int scale)
Sets the y-axis to the given range using the given measurement scale. |
void |
setYMeasurementScale(int scale)
Sets the measurement scale of the data on the Y-axis. |
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 |
public static final int NOMINAL
public static final int ORDINAL
public static final int INTERVAL
public static final int RATIO
protected Image offscreenImage
protected Graphics og
protected int top
protected int bottom
protected int left
protected int right
protected int centreX
protected int centreY
protected Vector items
Constructor Detail |
public JWGraph()
public JWGraph(String title, float yMin, float yMax)
title
- Title of the graph.yMin
- Minimum Y value.yMax
- Maximum Y value.public JWGraph(String title, float xMin, float xMax, float yMin, float yMax)
title
- Title of the graph.xMin
- Minimum X value.xMax
- Maximum X value.yMin
- Minimum Y value.yMax
- Maximum Y value.public JWGraph(String title, float xMin, float xMax, float yMin, float yMax, String[] labels)
title
- Title of the graph.xMin
- Minimum X value.xMax
- Maximum X value.yMin
- Minimum Y value.yMax
- Maximum Y value.labels
- Array holding labels for Y axis.public JWGraph(String title, float xMin, float xMax, float yMin, float yMax, String[] labels, int measurementScale)
title
- Title of the graph.xMin
- Minimum X value.xMax
- Maximum X value.yMin
- Minimum Y value.yMax
- Maximum Y value.labels
- Array holding labels for Y axis.measurementScale
- Measurement scale of the labelled axis.public JWGraph(String title, float xMin, float xMax, String[] labels, float yMin, float yMax)
title
- Title of the graph.xMin
- Minimum X value.xMax
- Maximum X value.labels
- Array holding lables of X axis.yMin
- Minimum Y value.yMax
- Maximum Y value.public JWGraph(String title, float xMin, float xMax, String[] labels, float yMin, float yMax, int measurementScale)
title
- Title of the graph.xMin
- Minimum X value.xMax
- Maximum X value.labels
- Array holding lables of X axis.yMin
- Minimum Y value.yMax
- Maximum Y value.measurementScale
- Measurement scale of the labelled axis.public JWGraph(String title, float rMin, float rMax, float thetaMin, float thetaMax, boolean polar)
title
- Title of the graph.rMin
- Minimum X value.rMax
- Maximum X value.thetaMin
- Starting angular value.thetaMax
- Ending angular value.polar
- Indicates a polar plot.Method Detail |
public void setOpacity(int opacity)
opacity
- Opacity level for items drawn on graph from 0 (invisible) to 255 (opaque).public void erase()
public Color makeTransparent(Color inColour)
inColour
- Colour to modify.
public void setAspectRatio(float aspectRatio)
aspectRatio
- Ratio of width over height or 0 for no fixed ratio.public void addItem(float xValue, float yValue)
xValue
- x-value associated with item.yValue
- y-value associated with item.public void addItem(float xValue, float yValue, Color col)
xValue
- x-value associated with item.yValue
- y-value associated with item.col
- Colour of item.public void removeItem(float xValue, float yValue)
xValue
- x-value associated with item.yValue
- y-value associated with item.public void removeItems()
public float getYMin()
public float getYMax()
public float getXMin()
public float getXMax()
public FontMetrics getFM()
public int getXMeasurementScale()
public int getYMeasurementScale()
public void setXMeasurementScale(int scale)
scale
- Mesurement scale (NOMINAL, ORDINAL,
INTERVAL or RATIO).public void setYMeasurementScale(int scale)
scale
- Mesurement scale (NOMINAL, ORDINAL,
INTERVAL or RATIO).public void setXAxis(float min, float max)
min
- Minimum axis value.max
- Maximum axis value.public void setXAxis(float min, float max, String[] xLabels, int scale)
min
- Minimum axis value.max
- Maximum axis value.xLabels
- Labels for x axis.scale
- Axis measurement scale.public void setYAxis(float min, float max)
min
- Minimum axis value.max
- Maximum axis value.public void setYAxis(float min, float max, int scale)
min
- Minimum axis value.max
- Maximum axis value.scale
- Axis measurement scale.public void setTitle(String title)
title
- New title to display.public void paintComponent(Graphics g)
g
- Graphics context to paint to.public Dimension getPreferredSize()
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |