public abstract class ChartView extends JComponent implements ChartModelListener
ChartView
provides logic to recalculate the scale and repaint
the chart when the component is resized or when the data model changes.
The scale value is the ratio of pixels to units, and is computed by
dividing the width (or height, depending on the orientation) of the
component in pixels by the maximum value to be plotted in this chart. The
calculation of the maximum value is a chart-specific; the method
getMaxValue()
must be overridden to perform this calculation.
The method paintChart()
should be overridden to paint the
chart and (if necessary) the chart scale. Convenience methods are provided
for rendering chart scales. By convention, chart scales appear on the left
for vertical charts and at the top for horizontal charts.
JComponent.AccessibleJComponent
Container.AccessibleAWTContainer
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
Modifier and Type | Field and Description |
---|---|
protected Chart |
chart
The chart definition for this view.
|
static int |
HORIZONTAL
A horizontal orientation.
|
protected int |
horizontalPad
The horizontal padding for this view.
|
protected LocaleManager |
lm
A cached reference to the locale manager.
|
private double |
maxValue |
protected ChartModel |
model
The data model for this view.
|
protected int |
orientation
The orientation for this view.
|
protected int |
precision
The precision for this view.
|
protected double |
scale
The scale factor for this view.
|
protected int |
scaleWidth
The width of the scale, in pixels.
|
private double |
tickInterval |
static int |
VERTICAL
A vertical orientation.
|
protected int |
verticalPad
The vertical padding for this view.
|
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
Modifier | Constructor and Description |
---|---|
protected |
ChartView(Chart chart)
Construct a new
ChartView for the specified chart
definition. |
Modifier and Type | Method and Description |
---|---|
void |
chartDataChanged(ChartModelEvent event)
Handle chart data changed events.
|
protected void |
drawHorizontalScale(Graphics gc,
int y)
A convenience method for drawing a horizontal scale with tickmarks and
tick labels.
|
protected void |
drawVerticalScale(Graphics gc,
int x)
A convenience method for drawing a vertical scale with tickmarks and
tick labels.
|
Chart |
getChart()
Get the chart definition.
|
int |
getHorizontalPad()
Get the horizontal padding.
|
protected double |
getMaxValue()
Compute the maximum value.
|
ChartModel |
getModel()
Get the data model for this view.
|
int |
getPrecision()
Get the decimal precision for this view.
|
double |
getTickInterval()
Get the tick interval for this view.
|
int |
getVerticalPad()
Get the vertical padding.
|
protected boolean |
hasScale()
Determine if this chart has a scale.
|
protected abstract void |
paintChart(Graphics gc)
Paint the chart.
|
void |
paintComponent(Graphics gc)
Paint the component.
|
private void |
recalculateScale() |
void |
setBounds(int x,
int y,
int width,
int height)
Overridden to recalculate the scale when the component geometry
changes.
|
void |
setChart(Chart chart)
Set the chart definition.
|
void |
setHorizontalPad(int hpad)
Set the horizontal padding.
|
void |
setModel(ChartModel model)
Set the data model for this view.
|
void |
setOrientation(int orientation)
Set the chart orientation.
|
void |
setPrecision(int precision)
Set the decimal precision for this view.
|
void |
setTickInterval(double tickInterval)
Set the tick interval for this view.
|
void |
setVerticalPad(int vpad)
Set the vertical padding.
|
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, 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, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, 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
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, transferFocusDownCycle, validate, validateTree
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, getAccessibleContext, 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, 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, transferFocusBackward, transferFocusUpCycle
private double maxValue
private double tickInterval
public static final int VERTICAL
public static final int HORIZONTAL
protected ChartModel model
protected double scale
protected int horizontalPad
protected int verticalPad
protected LocaleManager lm
protected int orientation
protected int precision
protected int scaleWidth
public void setChart(Chart chart)
chart
- The chart definition.public void setModel(ChartModel model)
model
- The data model.public ChartModel getModel()
public void chartDataChanged(ChartModelEvent event)
chartDataChanged
in interface ChartModelListener
event
- The event.public void paintComponent(Graphics gc)
paintComponent
in class JComponent
public void setOrientation(int orientation)
orientation
- The orientation; one of the constants
HORIZONTAL
or VERTICAL
.public void setHorizontalPad(int hpad)
hpad
- The horizontal padding, in pixels.public void setVerticalPad(int vpad)
vpad
- The vertical padding, in pixels.public int getHorizontalPad()
public int getVerticalPad()
public void setTickInterval(double tickInterval)
tickInterval
- The tick interval.public double getTickInterval()
public void setPrecision(int precision)
precision
- The precision.public int getPrecision()
protected abstract void paintChart(Graphics gc)
protected boolean hasScale()
true
.true
if the chart has a scale, false
otherwise.private void recalculateScale()
public void setBounds(int x, int y, int width, int height)
protected double getMaxValue()
0.0
.protected void drawVerticalScale(Graphics gc, int x)
gc
- The graphics context.x
- The x-coordinate of the scale.protected void drawHorizontalScale(Graphics gc, int y)
gc
- The graphics context.y
- The y-coordinate of the scale.WebARTS Library Licensed Under the GNU - General Public License. Other Libraries licensed under their respective Open Source Licenses