|
||||||||||
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 | +--org.jfree.chart.ChartPanel
A Swing GUI component for displaying a JFreeChart
.
The panel registers with the chart to receive notification of changes to any component of the chart. The chart is redrawn automatically whenever this notification is received.
Field Summary |
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.print.Printable |
NO_SUCH_PAGE, PAGE_EXISTS |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary | |
ChartPanel(JFreeChart chart)
Constructs a JFreeChart panel. |
|
ChartPanel(JFreeChart chart,
boolean useBuffer)
Constructs a panel containing a chart. |
|
ChartPanel(JFreeChart chart,
boolean properties,
boolean save,
boolean print,
boolean zoom,
boolean tooltips)
Constructs a JFreeChart panel. |
|
ChartPanel(JFreeChart chart,
int width,
int height,
int minimumDrawWidth,
int minimumDrawHeight,
int maximumDrawWidth,
int maximumDrawHeight,
boolean useBuffer,
boolean properties,
boolean save,
boolean print,
boolean zoom,
boolean tooltips)
Constructs a JFreeChart panel. |
Method Summary | |
void |
actionPerformed(java.awt.event.ActionEvent event)
Handles action events generated by the popup menu. |
void |
addChartMouseListener(ChartMouseListener listener)
Adds a listener to the list of objects listening for chart mouse events. |
void |
autoRangeBoth()
Restores the auto-range calculation on both axes. |
void |
autoRangeHorizontal()
Restores the auto-range calculation on the horizontal axis. |
void |
autoRangeVertical()
Restores the auto-range calculation on the vertical axis. |
void |
chartChanged(ChartChangeEvent event)
Receives notification of changes to the chart, and redraws the chart. |
void |
chartProgress(ChartProgressEvent event)
Receives notification of a chart progress event. |
void |
createChartPrintJob()
Creates a print job for the chart. |
protected javax.swing.JPopupMenu |
createPopupMenu(boolean properties,
boolean save,
boolean print,
boolean zoom)
Creates a popup menu for the panel. |
protected void |
displayPopupMenu(int x,
int y)
The idea is to modify the zooming options depending on the type of chart being displayed by the panel. |
void |
doSaveAs()
Opens a file chooser and gives the user an opportunity to save the chart in PNG format. |
JFreeChart |
getChart()
Returns the chart contained in the panel. |
ChartRenderingInfo |
getChartRenderingInfo()
Returns the chart rendering info from the most recent chart redraw. |
ChartEntity |
getEntityForPoint(int viewX,
int viewY)
Returns the chart entity at a given point. |
int |
getMaximumDrawHeight()
Returns the maximum drawing height for charts. |
int |
getMaximumDrawWidth()
Returns the maximum drawing width for charts. |
int |
getMinimumDrawHeight()
Returns the minimum drawing height for charts. |
int |
getMinimumDrawWidth()
Returns the minimum drawing width for charts. |
javax.swing.JPopupMenu |
getPopupMenu()
Returns the popup menu. |
java.awt.geom.Rectangle2D |
getScaledDataArea()
Returns the data area for the chart (the area inside the axes) with the current scaling applied. |
java.lang.String |
getToolTipText(java.awt.event.MouseEvent e)
Returns a string for the tooltip. |
boolean |
isEnforceFileExtensions()
Returns true if file extensions should be enforced, and false
otherwise. |
void |
mouseClicked(java.awt.event.MouseEvent event)
Receives notification of mouse clicks on the panel. |
void |
mouseDragged(java.awt.event.MouseEvent e)
Handles a 'mouse dragged' event. |
void |
mouseEntered(java.awt.event.MouseEvent e)
Handles a 'mouse entered' event. |
void |
mouseExited(java.awt.event.MouseEvent e)
Handles a 'mouse exited' event. |
void |
mouseMoved(java.awt.event.MouseEvent e)
Implementation of the MouseMotionListener's method |
void |
mousePressed(java.awt.event.MouseEvent e)
Handles a 'mouse pressed' event. |
void |
mouseReleased(java.awt.event.MouseEvent e)
Handles a 'mouse released' event. |
void |
paintComponent(java.awt.Graphics g)
Paints the component by drawing the chart to fill the entire component, but allowing for the insets (which will be non-zero if a border has been set for this component). |
int |
print(java.awt.Graphics g,
java.awt.print.PageFormat pf,
int pageIndex)
Prints the chart on a single page. |
void |
removeChartMouseListener(ChartMouseListener listener)
Removes a listener from the list of objects listening for chart mouse events. |
void |
setChart(JFreeChart chart)
Sets the chart that is displayed in the panel. |
void |
setDisplayToolTips(boolean flag)
Switches chart tooltip generation on or off. |
void |
setEnforceFileExtensions(boolean enforce)
Sets a flag that controls whether or not file extensions are enforced. |
void |
setFillZoomRectangle(boolean flag)
A flag that controls how the zoom rectangle is drawn. |
void |
setHorizontalAxisTrace(boolean flag)
A flag that controls trace lines on the horizontal axis. |
void |
setHorizontalZoom(boolean flag)
A flag that controls mouse-based zooming on the horizontal axis. |
void |
setMaximumDrawHeight(int height)
Sets the maximum drawing height for the chart on this panel. |
void |
setMaximumDrawWidth(int width)
Sets the maximum drawing width for the chart on this panel. |
void |
setMinimumDrawHeight(int height)
Sets the minimum drawing height for the chart on this panel. |
void |
setMinimumDrawWidth(int width)
Sets the minimum drawing width for the chart on this panel. |
void |
setMouseZoomable(boolean flag)
A flag that controls mouse-based zooming. |
void |
setMouseZoomable(boolean flag,
boolean fillRectangle)
Controls mouse zooming and how the zoom rectangle is displayed |
void |
setPopupMenu(javax.swing.JPopupMenu popup)
Sets the popup menu for the panel. |
void |
setRefreshBuffer(boolean flag)
Sets the refresh buffer flag. |
void |
setVerticalAxisTrace(boolean flag)
A flag that controls trace lines on the vertical axis. |
void |
setVerticalZoom(boolean flag)
A flag that controls mouse-based zooming on the vertical axis. |
java.awt.Point |
translateJava2DToScreen(java.awt.geom.Point2D java2DPoint)
Translates a Java2D point on the chart to a screen location. |
java.awt.geom.Point2D |
translateScreenToJava2D(java.awt.Point screenPoint)
Translates a screen location to a Java2D point. |
void |
zoom(java.awt.geom.Rectangle2D selection)
Zooms in on a selected region. |
void |
zoomInBoth(double x,
double y)
Zooms in on an anchor point (measured in Java2D coordinates). |
void |
zoomInHorizontal(double x)
Decreases the range on the horizontal axis, centered about a Java2D x coordinate. |
void |
zoomInVertical(double y)
Decreases the range on the vertical axis, centered about a Java2D y coordinate. |
void |
zoomOutBoth(double x,
double y)
Zooms out on an anchor point (measured in Java2D coordinates). |
void |
zoomOutHorizontal(double x)
Increases the range on the horizontal axis, centered about a Java2D x coordinate. |
void |
zoomOutVertical(double y)
Increases the range on the vertical axis, centered about a Java2D y coordinate. |
Methods inherited from class javax.swing.JPanel |
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update |
Methods inherited from class java.awt.Container |
add, add, add, add, add, addContainerListener, addImpl, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setBounds, 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 |
Constructor Detail |
public ChartPanel(JFreeChart chart)
chart
- the chart.public ChartPanel(JFreeChart chart, boolean useBuffer)
chart
- the chart.useBuffer
- a flag controlling whether or not an off-screen buffer is used.public ChartPanel(JFreeChart chart, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips)
chart
- the chart.properties
- a flag indicating whether or not the chart property
editor should be available via the popup menu.save
- a flag indicating whether or not save options should be
available via the popup menu.print
- a flag indicating whether or not the print option
should be available via the popup menu.zoom
- a flag indicating whether or not zoom options should
be added to the popup menu.tooltips
- a flag indicating whether or not tooltips should be
enabled for the chart.public ChartPanel(JFreeChart chart, int width, int height, int minimumDrawWidth, int minimumDrawHeight, int maximumDrawWidth, int maximumDrawHeight, boolean useBuffer, boolean properties, boolean save, boolean print, boolean zoom, boolean tooltips)
chart
- the chart.width
- the preferred width of the panel.height
- the preferred height of the panel.minimumDrawWidth
- the minimum drawing width.minimumDrawHeight
- the minimum drawing height.maximumDrawWidth
- the maximum drawing width.maximumDrawHeight
- the maximum drawing height.useBuffer
- a flag that indicates whether to use the off-screen
buffer to improve performance (at the expense of memory).properties
- a flag indicating whether or not the chart property
editor should be available via the popup menu.save
- a flag indicating whether or not save options should be
available via the popup menu.print
- a flag indicating whether or not the print option
should be available via the popup menu.zoom
- a flag indicating whether or not zoom options should be added to the
popup menu.tooltips
- a flag indicating whether or not tooltips should be enabled for the chart.Method Detail |
public JFreeChart getChart()
public void setChart(JFreeChart chart)
chart
- The chart.public int getMinimumDrawWidth()
If the width available on the panel is less than this, then the chart is drawn at the minimum width then scaled down to fit.
public void setMinimumDrawWidth(int width)
At the time the chart is drawn on the panel, if the available width is less than this amount, the chart will be drawn using the minimum width then scaled down to fit the available space.
width
- The width.public int getMaximumDrawWidth()
If the width available on the panel is greater than this, then the chart is drawn at the maximum width then scaled up to fit.
public void setMaximumDrawWidth(int width)
At the time the chart is drawn on the panel, if the available width is greater than this amount, the chart will be drawn using the maximum width then scaled up to fit the available space.
width
- The width.public void setMinimumDrawHeight(int height)
At the time the chart is drawn on the panel, if the available height is less than this amount, the chart will be drawn using the minimum height then scaled down to fit the available space.
height
- The height.public int getMinimumDrawHeight()
If the height available on the panel is less than this, then the chart is drawn at the minimum height then scaled down to fit.
public int getMaximumDrawHeight()
If the height available on the panel is greater than this, then the chart is drawn at the maximum height then scaled up to fit.
public void setMaximumDrawHeight(int height)
At the time the chart is drawn on the panel, if the available height is greater than this amount, the chart will be drawn using the maximum height then scaled up to fit the available space.
height
- The height.public javax.swing.JPopupMenu getPopupMenu()
public void setPopupMenu(javax.swing.JPopupMenu popup)
popup
- the new popup menu.public ChartRenderingInfo getChartRenderingInfo()
public void setMouseZoomable(boolean flag)
flag
- true
enables zooming and rectangle fill on zoom.public void setMouseZoomable(boolean flag, boolean fillRectangle)
flag
- true
if zooming enabledfillRectangle
- true
if zoom rectangle is filled,
false if rectangle is shown as outline only.public void setHorizontalZoom(boolean flag)
flag
- true
enables zooming on HorizontalValuePlots.public void setFillZoomRectangle(boolean flag)
flag
- true
instructs to fill the rectangle on
zoom, otherwise it will be outlined.public void setVerticalZoom(boolean flag)
flag
- true
enables zooming on VerticalValuePlots.public void setHorizontalAxisTrace(boolean flag)
flag
- true
enables trace lines for the mouse
pointer on the horizontal axis.public void setVerticalAxisTrace(boolean flag)
flag
- true
enables trace lines for the mouse
pointer on the vertical axis.public boolean isEnforceFileExtensions()
true
if file extensions should be enforced, and false
otherwise.
public void setEnforceFileExtensions(boolean enforce)
enforce
- the new flag value.public void setDisplayToolTips(boolean flag)
flag
- the flag.public java.lang.String getToolTipText(java.awt.event.MouseEvent e)
getToolTipText
in class javax.swing.JComponent
e
- the mouse event.
null
if no tooltip is available.public java.awt.Point translateJava2DToScreen(java.awt.geom.Point2D java2DPoint)
java2DPoint
- the Java2D point.
public java.awt.geom.Point2D translateScreenToJava2D(java.awt.Point screenPoint)
screenPoint
- the screen location.
public ChartEntity getEntityForPoint(int viewX, int viewY)
This method will return null if there is (a) no entity at the given point, or (b) no entity collection has been generated.
viewX
- the x-coordinate.viewY
- the y-coordinate.
public void setRefreshBuffer(boolean flag)
flag
- true
indicate, that the buffer should be refreshed.public void paintComponent(java.awt.Graphics g)
paintComponent
in class javax.swing.JComponent
g
- the graphics device for drawing on.public void chartChanged(ChartChangeEvent event)
chartChanged
in interface ChartChangeListener
event
- details of the chart change event.public void chartProgress(ChartProgressEvent event)
chartProgress
in interface ChartProgressListener
event
- the event.public void actionPerformed(java.awt.event.ActionEvent event)
actionPerformed
in interface java.awt.event.ActionListener
event
- the event.public void mouseEntered(java.awt.event.MouseEvent e)
This method does nothing, but is required for implementation of the MouseListener interface.
mouseEntered
in interface java.awt.event.MouseListener
e
- the mouse event.public void mouseExited(java.awt.event.MouseEvent e)
This method does nothing, but is required for implementation of the MouseListener interface.
mouseExited
in interface java.awt.event.MouseListener
e
- the mouse event.public void mousePressed(java.awt.event.MouseEvent e)
This event is the popup trigger on Unix/Linux. For Windows, the popup trigger is the 'mouse released' event.
mousePressed
in interface java.awt.event.MouseListener
e
- The mouse event.public void mouseReleased(java.awt.event.MouseEvent e)
On Windows, we need to check if this is a popup trigger, but only if we haven't already been tracking a zoom rectangle.
mouseReleased
in interface java.awt.event.MouseListener
e
- Information about the event.public void mouseClicked(java.awt.event.MouseEvent event)
mouseClicked
in interface java.awt.event.MouseListener
event
- Information about the mouse event.public void mouseMoved(java.awt.event.MouseEvent e)
mouseMoved
in interface java.awt.event.MouseMotionListener
e
- the event.public void mouseDragged(java.awt.event.MouseEvent e)
mouseDragged
in interface java.awt.event.MouseMotionListener
e
- the mouse event.public void zoomInBoth(double x, double y)
x
- The x value.y
- The y value.public void zoomInHorizontal(double x)
The range on the x axis is halved.
x
- The x coordinate in Java2D space.public void zoomInVertical(double y)
The range on the y axis is halved.
y
- The y coordinate in Java2D space.public void zoomOutBoth(double x, double y)
x
- The x value.y
- The y value.public void zoomOutHorizontal(double x)
The range on the x axis is doubled.
x
- The x coordinate in Java2D space.public void zoomOutVertical(double y)
The range on the y axis is doubled.
y
- the y coordinate in Java2D space.public void zoom(java.awt.geom.Rectangle2D selection)
selection
- the selected region.public void autoRangeBoth()
public void autoRangeHorizontal()
public void autoRangeVertical()
public java.awt.geom.Rectangle2D getScaledDataArea()
public void doSaveAs() throws java.io.IOException
java.io.IOException
- if there is an I/O error.public void createChartPrintJob()
public int print(java.awt.Graphics g, java.awt.print.PageFormat pf, int pageIndex)
print
in interface java.awt.print.Printable
g
- the graphics context.pf
- the page format to use.pageIndex
- the index of the page. If not 0
, nothing gets print.
public void addChartMouseListener(ChartMouseListener listener)
listener
- the listener.public void removeChartMouseListener(ChartMouseListener listener)
listener
- the listener.protected javax.swing.JPopupMenu createPopupMenu(boolean properties, boolean save, boolean print, boolean zoom)
properties
- include a menu item for the chart property editor.save
- include a menu item for saving the chart.print
- include a menu item for printing the chart.zoom
- include menu items for zooming.
protected void displayPopupMenu(int x, int y)
x
- horizontal position of the popup.y
- vertical position of the popup.
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |