|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjava.awt.Component
java.awt.Container
javax.swing.JComponent
org.formaria.swing.Graph
public class Graph
An component that displays data as charts/graphs. The display can be Pie, Scatter, Line, X-Y or Bar charts
Copyright (c) Formaria Ltd., 2008, This software is licensed under the GNU Public License (GPL), please see license.txt for more details. If you make commercial use of this software you must purchase a commercial license from formaria.
$Revision: 1.29 $
| Nested Class Summary | |
|---|---|
class |
Graph.SelectableArea
An area of the chart that can be selected, with information about that area |
| 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 |
BARCHART
Bar chart - with one bar per value in each series |
protected Project |
currentProject
The owner project and the context in which this object operates. |
static int |
LABELS
The labels column/field in the source data table |
static int |
LINEAR
Linear axis |
static int |
LINECHART
A simple line chart with connected points |
static int |
LOGARITHMIC
A Log10 axis |
static int |
PIECHART
A pie chart showing the first series |
static int |
SCATTERCHART
A plot with points for each x-y value pair |
static int |
SERIES
The series column/field in the source data table |
static int |
STACKEDBARCHART
Bar chart with the bars for each value in the series stacked upon one another so that there is one bar for each x value |
static int |
VALUES
The values column/field in the source data table |
| 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 | |
|---|---|
Graph()
Construct a new graph/chart |
|
| Method Summary | |
|---|---|
void |
actionPerformed(java.awt.event.ActionEvent e)
An action handler for the animation timer |
protected java.awt.Color |
darken(java.awt.Color c,
double degrees)
Darken the selected color for the sides of the pie chart |
void |
drawBarChart(java.awt.Graphics2D g2d)
Draw a simple bar chart |
protected void |
drawLegend(java.awt.Graphics2D g2d,
double x,
double y,
double w,
double h)
Draw the chart legend |
void |
drawLineChart(java.awt.Graphics2D g2d)
Draw a line chart |
void |
drawPieChart(java.awt.Graphics2D g2d)
Draw a pie chart with the first data series |
void |
drawScale(java.awt.Graphics2D g2d,
boolean isVertical)
Draw a scale |
void |
drawSelectedArea(java.awt.Graphics2D g2d)
Highlight the selected area - if any |
void |
drawStackedBarChart(java.awt.Graphics2D g2d)
Draw a stacked bar chart |
boolean |
getDrawBorder()
Get the drawBorder flag value |
protected java.awt.Color |
getGeneratedColor(int idx)
Generate an HSB color, using the index as an offset int the H color range |
protected java.awt.Color |
getGeneratedColor(int i,
int opacity)
Get a generated color with partial opacity |
boolean |
getHighlight()
Get the highlight flag value |
protected double |
getLabelHeight(java.awt.Graphics g)
Get the height of the X axis labels |
boolean |
getLabels()
Get the labels flag value |
int |
getLegendPos()
Get the legend position |
protected int |
getLegendSpace(boolean verticalSpace)
Get the space consumed by the legend |
protected int |
getLegendX(double left,
double right)
Get the legend x coordinate |
protected int |
getLegendY(double top,
double bottom)
Get the legend y coordinate |
boolean |
getMarkers()
Get the markers flag value |
double |
getMaxY()
Get the maximum Y value |
double |
getMinY()
Get the minimum Y value |
int |
getMode()
Get the current display mode of the chart |
Graph.SelectableArea |
getSelectableArea()
Get the selectable area |
java.lang.String |
getTitle()
Get the graph title |
protected double |
getYLabelWidth(java.awt.Graphics g)
Get the height of the X axis labels |
void |
paintComponent(java.awt.Graphics g)
Renders the chart image. |
void |
print(java.awt.Graphics g)
Setup the envelope component for printing |
void |
setBorderStyle(boolean value)
|
void |
setBounds(int x,
int y,
int w,
int h)
Set the bounds for this component and layout the children |
void |
setData(double[] pts,
int nSeries,
java.lang.String[] names,
boolean animate)
Set the chart data |
void |
setDataModel(DataModel xmodel)
Set the DataModel which we will be generating the table from |
void |
setDrawBorder(boolean b)
Set the drawBorder flag value |
void |
setHighlight(boolean b)
Set the highlight flag value |
void |
setLabels(boolean b)
Set the labels flag value |
void |
setLegendPos(int y)
Set the legend position |
void |
setMarkers(boolean b)
Set the markers flag value |
void |
setMaxY(double y)
Set the maximum Y value |
void |
setMinY(double y)
Set the minimum Y value |
void |
setMode(int newMode)
Set the display mode of the chart |
void |
setModelStructure(int attribute,
int value)
Define the location of the data in the model |
void |
setTitle(java.lang.String newStr)
Set the text of the form to the specified language string, the setLangString(...) function is the preferred method of setting the caption. |
void |
setXScale(double min,
double max,
int type,
java.lang.String title,
java.lang.String[] labels)
Set the Scale options |
void |
setYScale(int type,
java.lang.String title)
Set the Scale options |
void |
toggleYAxisAnimation()
Turn on/off the animation of new data |
void |
update()
Force a repaint |
| 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, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, 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, 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, setEnabled, 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, isEnabled, 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, 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 |
|---|
public static final int BARCHART
public static final int STACKEDBARCHART
public static final int LINECHART
public static final int PIECHART
public static final int SCATTERCHART
public static final int LINEAR
public static final int LOGARITHMIC
public static final int SERIES
public static final int LABELS
public static final int VALUES
protected Project currentProject
| Constructor Detail |
|---|
public Graph()
| Method Detail |
|---|
public void setModelStructure(int attribute,
int value)
attribute - the attribute being defined (LABELS, SERIES, VALUES)value - the column of field where that data can be foundpublic Graph.SelectableArea getSelectableArea()
public void actionPerformed(java.awt.event.ActionEvent e)
actionPerformed in interface java.awt.event.ActionListenere - the event
public void setBounds(int x,
int y,
int w,
int h)
setBounds in class java.awt.Componentx - the x coordinatey - the y coordinatew - the widthh - the height
public void setXScale(double min,
double max,
int type,
java.lang.String title,
java.lang.String[] labels)
min - the min valuemax - the max valuetype - the type of axistitle - the axis titlelabels - the labels for the markers in the series
public void setYScale(int type,
java.lang.String title)
type - the type of axistitle - the axis titlepublic void update()
update in interface ModelHolderpublic void setDataModel(DataModel xmodel)
setDataModel in interface ModelHolderxmodel - The DataModel of data
public void setData(double[] pts,
int nSeries,
java.lang.String[] names,
boolean animate)
nSeries - the number of seriespts - the data points in x, y pairs, a complete series at a time e.g. ax1, ay1, ax2, ay2, .... xn, yn, bx1, by1, bx2, by2names - the names of the seriesanimate - true to animate new datapublic void toggleYAxisAnimation()
public void print(java.awt.Graphics g)
print in class javax.swing.JComponentg - the graphics contextpublic void paintComponent(java.awt.Graphics g)
paintComponent in class javax.swing.JComponentg - the graphics context
public void drawScale(java.awt.Graphics2D g2d,
boolean isVertical)
g2d - the graphics contextisVertical - true to draw a vertical axis, otherwise the horizontal axis is drawnpublic void drawBarChart(java.awt.Graphics2D g2d)
g2d - the graphics contextpublic void drawStackedBarChart(java.awt.Graphics2D g2d)
g2d - the graphics contextpublic void drawLineChart(java.awt.Graphics2D g2d)
g2d - the graphics contextprotected double getLabelHeight(java.awt.Graphics g)
g - the graphics context
protected double getYLabelWidth(java.awt.Graphics g)
g - the graphics context
protected int getLegendSpace(boolean verticalSpace)
verticalSpace - true if the legend is shown horizontally below the chart
protected int getLegendX(double left,
double right)
left - the left edge of the chartright - the right edge of the chart
protected int getLegendY(double top,
double bottom)
top - the top edge of the chartbottom - the bottom edge of the chart
protected void drawLegend(java.awt.Graphics2D g2d,
double x,
double y,
double w,
double h)
g2d - the graphics contextx - the x/left positiony - the y/top positionw - the widthh - the heightpublic boolean getDrawBorder()
public void setDrawBorder(boolean b)
b - true if the border is drawnpublic boolean getLabels()
public void setLabels(boolean b)
b - true if the lables are drawn on the data pointspublic boolean getHighlight()
public void setHighlight(boolean b)
b - true if the current value is to be highlighted as the mouse is movedpublic boolean getMarkers()
public void setMarkers(boolean b)
b - true if the markers are drwan for each pointpublic double getMinY()
public void setMinY(double y)
y - the minimum valuepublic double getMaxY()
public void setMaxY(double y)
y - the maximum valuepublic int getLegendPos()
public void setLegendPos(int y)
pos - value=the legend position, 0=top left, 1=top right, 2=bottom left, 3=bottom right, 4=right margin, 5=bottom marginpublic void drawPieChart(java.awt.Graphics2D g2d)
g2d - the graphics contextpublic void drawSelectedArea(java.awt.Graphics2D g2d)
g2d - the graphics context
protected java.awt.Color darken(java.awt.Color c,
double degrees)
c - the selected colordegrees - the angle/position at which the color is used
protected java.awt.Color getGeneratedColor(int idx)
idx - the index of the color
protected java.awt.Color getGeneratedColor(int i,
int opacity)
i - the color indexopacity - the opacity in the range 0-255
public void setMode(int newMode)
newMode - the new mode: 0=BAR, 1=STACKEDBAR, 2=LINE, 3=PIE, 4=SCATTERpublic int getMode()
public void setTitle(java.lang.String newStr)
newStr - the new titlepublic java.lang.String getTitle()
public void setBorderStyle(boolean value)
value -
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||