Class ChartPanel

  • All Implemented Interfaces:
    java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, ChartChangeListener, ChartProgressListener, OverlayChangeListener
    Direct Known Subclasses:
    OfflineRenderingChartPanel, PolarChartPanel

    public class ChartPanel
    extends javax.swing.JPanel
    implements ChartChangeListener, ChartProgressListener, java.awt.event.ActionListener, java.awt.event.MouseListener, java.awt.event.MouseMotionListener, OverlayChangeListener, java.awt.print.Printable, java.io.Serializable
    A Swing GUI component for displaying a JFreeChart object.

    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.

    See Also:
    Serialized Form
    • Nested Class Summary

      • Nested classes/interfaces inherited from class javax.swing.JPanel

        javax.swing.JPanel.AccessibleJPanel
      • 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

      Fields 
      Modifier and Type Field Description
      private java.awt.geom.Point2D anchor
      The chart anchor point.
      private JFreeChart chart
      The chart that is displayed in the panel.
      private java.awt.image.BufferedImage chartBuffer
      A buffer for the rendered chart.
      private javax.swing.event.EventListenerList chartMouseListeners
      Storage for registered (chart) mouse listeners.
      static java.lang.String COPY_COMMAND
      Copy action command.
      static boolean DEFAULT_BUFFER_USED
      Default setting for buffer usage.
      static int DEFAULT_HEIGHT
      The default panel height.
      static int DEFAULT_MAXIMUM_DRAW_HEIGHT
      The default limit above which chart scaling kicks in.
      static int DEFAULT_MAXIMUM_DRAW_WIDTH
      The default limit above which chart scaling kicks in.
      static int DEFAULT_MINIMUM_DRAW_HEIGHT
      The default limit below which chart scaling kicks in.
      static int DEFAULT_MINIMUM_DRAW_WIDTH
      The default limit below which chart scaling kicks in.
      static int DEFAULT_WIDTH
      The default panel width.
      static int DEFAULT_ZOOM_TRIGGER_DISTANCE
      The minimum size required to perform a zoom on a rectangle
      private java.io.File defaultDirectoryForSaveAs
      The default directory for saving charts to file.
      private boolean domainZoomable
      A flag that controls whether or not domain zooming is enabled.
      private boolean enforceFileExtensions
      A flag that controls whether or not file extensions are enforced.
      private boolean fillZoomRectangle
      Controls if the zoom rectangle is drawn as an outline or filled.
      private boolean horizontalAxisTrace
      A flag that controls whether or not horizontal tracing is enabled.
      private java.awt.geom.Line2D horizontalTraceLine
      A horizontal trace line.
      private ChartRenderingInfo info
      The drawing info collected the last time the chart was drawn.
      protected static java.util.ResourceBundle localizationResources
      The resourceBundle for the localization.
      private int maximumDrawHeight
      The maximum height for drawing a chart (uses scaling for bigger heights).
      private int maximumDrawWidth
      The maximum width for drawing a chart (uses scaling for bigger widths).
      private int minimumDrawHeight
      The minimum height for drawing a chart (uses scaling for smaller heights).
      private int minimumDrawWidth
      The minimum width for drawing a chart (uses scaling for smaller widths).
      private MouseWheelHandler mouseWheelHandler
      The mouse wheel handler.
      private PlotOrientation orientation
      The plot orientation.
      private int originalToolTipDismissDelay
      Original dismiss tooltip delay of ToolTipManager.sharedInstance().
      private int originalToolTipInitialDelay
      Original initial tooltip delay of ToolTipManager.sharedInstance().
      private int originalToolTipReshowDelay
      Original reshow tooltip delay of ToolTipManager.sharedInstance().
      private java.util.List<Overlay> overlays
      A list of overlays for the panel.
      private boolean ownToolTipDelaysActive
      A flag that indicates if original tooltip delays are changed.
      private int ownToolTipDismissDelay
      Own dismiss tooltip delay to be used in this chart panel.
      private int ownToolTipInitialDelay
      Own initial tooltip delay to be used in this chart panel.
      private int ownToolTipReshowDelay
      Own reshow tooltip delay to be used in this chart panel.
      private double panH
      Temporary storage for the width and height of the chart drawing area during panning.
      private java.awt.Point panLast
      The last mouse position during panning.
      private int panMask
      The mask for mouse events to trigger panning.
      private double panW
      Temporary storage for the width and height of the chart drawing area during panning.
      private javax.swing.JPopupMenu popup
      The popup menu for the frame.
      static java.lang.String PRINT_COMMAND
      Print action command.
      static java.lang.String PROPERTIES_COMMAND
      Properties action command.
      private boolean rangeZoomable
      A flag that controls whether or not range zooming is enabled.
      private boolean refreshBuffer
      A flag that indicates that the buffer should be refreshed.
      private static java.lang.String SAVE_AS_PDF_COMMAND
      Action command to save as PDF.
      private static java.lang.String SAVE_AS_PNG_COMMAND
      Action command to save as PNG.
      private static java.lang.String SAVE_AS_SVG_COMMAND
      Action command to save as SVG.
      static java.lang.String SAVE_COMMAND
      Save action command.
      private double scaleX
      The scale factor used to draw the chart.
      private double scaleY
      The scale factor used to draw the chart.
      private static long serialVersionUID
      For serialization.
      private boolean useBuffer
      A flag that controls whether the off-screen buffer is used.
      private boolean verticalAxisTrace
      A flag that controls whether or not vertical tracing is enabled.
      private java.awt.geom.Line2D verticalTraceLine
      A vertical trace line.
      static java.lang.String ZOOM_IN_BOTH_COMMAND
      Zoom in (both axes) action command.
      static java.lang.String ZOOM_IN_DOMAIN_COMMAND
      Zoom in (domain axis only) action command.
      static java.lang.String ZOOM_IN_RANGE_COMMAND
      Zoom in (range axis only) action command.
      static java.lang.String ZOOM_OUT_BOTH_COMMAND
      Zoom out (both axes) action command.
      static java.lang.String ZOOM_OUT_DOMAIN_COMMAND
      Zoom out (domain axis only) action command.
      static java.lang.String ZOOM_OUT_RANGE_COMMAND
      Zoom out (range axis only) action command.
      static java.lang.String ZOOM_RESET_BOTH_COMMAND
      Zoom reset (both axes) action command.
      static java.lang.String ZOOM_RESET_DOMAIN_COMMAND
      Zoom reset (domain axis only) action command.
      static java.lang.String ZOOM_RESET_RANGE_COMMAND
      Zoom reset (range axis only) action command.
      private boolean zoomAroundAnchor
      A flag that controls whether zoom operations are centred on the current anchor point, or the centre point of the relevant axis.
      private java.awt.Paint zoomFillPaint
      The zoom fill paint (should use transparency).
      private javax.swing.JMenuItem zoomInBothMenuItem
      Menu item for zooming in on a chart (both axes).
      private javax.swing.JMenuItem zoomInDomainMenuItem
      Menu item for zooming in on a chart (domain axis).
      private double zoomInFactor
      The factor used to zoom in on an axis range.
      private javax.swing.JMenuItem zoomInRangeMenuItem
      Menu item for zooming in on a chart (range axis).
      private javax.swing.JMenuItem zoomOutBothMenuItem
      Menu item for zooming out on a chart.
      private javax.swing.JMenuItem zoomOutDomainMenuItem
      Menu item for zooming out on a chart (domain axis).
      private double zoomOutFactor
      The factor used to zoom out on an axis range.
      private java.awt.Paint zoomOutlinePaint
      The paint used to draw the zoom rectangle outline.
      private javax.swing.JMenuItem zoomOutRangeMenuItem
      Menu item for zooming out on a chart (range axis).
      private java.awt.geom.Point2D zoomPoint
      The zoom rectangle starting point (selected by the user with a mouse click).
      private java.awt.geom.Rectangle2D zoomRectangle
      The zoom rectangle (selected by the user with the mouse).
      private javax.swing.JMenuItem zoomResetBothMenuItem
      Menu item for resetting the zoom (both axes).
      private javax.swing.JMenuItem zoomResetDomainMenuItem
      Menu item for resetting the zoom (domain axis only).
      private javax.swing.JMenuItem zoomResetRangeMenuItem
      Menu item for resetting the zoom (range axis only).
      private int zoomTriggerDistance
      The minimum distance required to drag the mouse to trigger a zoom.
      • Fields inherited from class javax.swing.JComponent

        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

        accessibleContext, 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
      • Fields inherited from interface java.awt.print.Printable

        NO_SUCH_PAGE, PAGE_EXISTS
    • Constructor Summary

      Constructors 
      Constructor Description
      ChartPanel​(JFreeChart chart)
      Constructs a panel that displays the specified chart.
      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.
      ChartPanel​(JFreeChart chart, int width, int height, int minimumDrawWidth, int minimumDrawHeight, int maximumDrawWidth, int maximumDrawHeight, boolean useBuffer, boolean properties, boolean copy, boolean save, boolean print, boolean zoom, boolean tooltips)
      Constructs a JFreeChart panel.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      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 addOverlay​(Overlay overlay)
      Add an overlay to the panel.
      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 javax.swing.JPopupMenu createPopupMenu​(boolean properties, boolean copy, boolean save, boolean print, boolean zoom)
      Creates a popup menu for the panel.
      private java.awt.Graphics2D createSVGGraphics2D​(int w, int h)  
      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 doCopy()
      Copies the current chart to the system clipboard.
      void doEditChartProperties()
      Displays a dialog that allows the user to edit the properties for the current chart.
      void doSaveAs()
      Opens a file chooser and gives the user an opportunity to save the chart in PNG format.
      private void drawHorizontalAxisTrace​(java.awt.Graphics2D g2, int x)
      Draws a vertical line used to trace the mouse position to the horizontal axis.
      private void drawVerticalAxisTrace​(java.awt.Graphics2D g2, int y)
      Draws a horizontal line used to trace the mouse position to the vertical axis.
      private void drawZoomRectangle​(java.awt.Graphics2D g2, boolean xor)
      Draws zoom rectangle (if present).
      private java.lang.String generateSVG​(int width, int height)
      Generates a string containing a rendering of the chart in SVG format.
      java.awt.geom.Point2D getAnchor()
      Returns the anchor point.
      JFreeChart getChart()
      Returns the chart contained in the panel.
      ChartRenderingInfo getChartRenderingInfo()
      Returns the chart rendering info from the most recent chart redraw.
      java.io.File getDefaultDirectoryForSaveAs()
      Returns the default directory for the "save as" option.
      int getDismissDelay()
      Returns the dismissal tooltip delay value used inside this chart panel.
      ChartEntity getEntityForPoint​(int viewX, int viewY)
      Returns the chart entity at a given point.
      boolean getFillZoomRectangle()
      Returns the flag that controls whether or not the zoom rectangle is filled when drawn.
      boolean getHorizontalAxisTrace()
      Returns the flag that controls whether or not a horizontal axis trace line is drawn over the plot area at the current mouse location.
      protected java.awt.geom.Line2D getHorizontalTraceLine()
      Returns the horizontal trace line.
      int getInitialDelay()
      Returns the initial tooltip delay value used inside this chart panel.
      java.util.EventListener[] getListeners​(java.lang.Class listenerType)
      Returns an array of the listeners of the given type registered with the panel.
      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.
      private java.awt.geom.Point2D getPointInRectangle​(int x, int y, java.awt.geom.Rectangle2D area)
      Returns a point based on (x, y) but constrained to be within the bounds of the given rectangle.
      javax.swing.JPopupMenu getPopupMenu()
      Returns the popup menu.
      boolean getRefreshBuffer()
      Returns the flag that controls whether or not the offscreen buffer needs to be refreshed.
      int getReshowDelay()
      Returns the reshow tooltip delay value used inside this chart panel.
      double getScaleX()
      Returns the X scale factor for the chart.
      double getScaleY()
      Returns the Y scale factory for the chart.
      java.awt.geom.Rectangle2D getScreenDataArea()
      Returns the data area for the chart (the area inside the axes) with the current scaling applied (that is, the area as it appears on screen).
      java.awt.geom.Rectangle2D getScreenDataArea​(int x, int y)
      Returns the data area (the area inside the axes) for the plot or subplot, with the current scaling applied.
      java.lang.String getToolTipText​(java.awt.event.MouseEvent e)
      Returns a string for the tooltip.
      boolean getVerticalAxisTrace()
      Returns the flag that controls whether or not a vertical axis trace line is drawn over the plot area at the current mouse location.
      protected java.awt.geom.Line2D getVerticalTraceLine()
      Returns the vertical trace line.
      boolean getZoomAroundAnchor()
      Returns the flag that controls whether or not zoom operations are centered around the current anchor point.
      java.awt.Paint getZoomFillPaint()
      Returns the zoom rectangle fill paint.
      double getZoomInFactor()
      Returns the zoom in factor.
      double getZoomOutFactor()
      Returns the zoom out factor.
      java.awt.Paint getZoomOutlinePaint()
      Returns the zoom rectangle outline paint.
      int getZoomTriggerDistance()
      Returns the zoom trigger distance.
      boolean isDomainZoomable()
      Returns the flag that determines whether or not zooming is enabled for the domain axis.
      boolean isEnforceFileExtensions()
      Returns true if file extensions should be enforced, and false otherwise.
      boolean isMouseWheelEnabled()
      Returns true if the mouse wheel handler is enabled, and false otherwise.
      private boolean isOrsonPDFAvailable()
      Returns true if OrsonPDF is on the classpath, and false otherwise.
      boolean isRangeZoomable()
      Returns the flag that determines whether or not zooming is enabled for the range axis.
      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 overlayChanged​(OverlayChangeEvent event)
      Handles a change to an overlay by repainting the panel.
      protected java.awt.image.BufferedImage paintChartToBuffer​(java.awt.Graphics2D g2, java.awt.Dimension bufferSize, java.awt.Dimension chartSize, java.awt.geom.Point2D anchor, ChartRenderingInfo info)
      Paints the chart to fill the entire off-screen buffer image.
      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.
      private void readObject​(java.io.ObjectInputStream stream)
      Provides serialization support.
      void removeChartMouseListener​(ChartMouseListener listener)
      Removes a listener from the list of objects listening for chart mouse events.
      void removeOverlay​(Overlay overlay)
      Removes an overlay from the panel.
      void restoreAutoBounds()
      Restores the auto-range calculation on both axes.
      void restoreAutoDomainBounds()
      Restores the auto-range calculation on the domain axis.
      void restoreAutoRangeBounds()
      Restores the auto-range calculation on the range axis.
      private void saveAsPDF​(java.io.File f)
      Saves the chart in PDF format (a filechooser will be displayed so that the user can specify the filename).
      private void saveAsSVG​(java.io.File f)
      Saves the chart in SVG format (a filechooser will be displayed so that the user can specify the filename).
      java.awt.geom.Rectangle2D scale​(java.awt.geom.Rectangle2D rect)
      Applies any scaling that is in effect for the chart drawing to the given rectangle.
      protected void setAnchor​(java.awt.geom.Point2D anchor)
      Sets the anchor point.
      void setChart​(JFreeChart chart)
      Sets the chart that is displayed in the panel.
      void setDefaultDirectoryForSaveAs​(java.io.File directory)
      Sets the default directory for the "save as" option.
      void setDismissDelay​(int delay)
      Specifies the dismissal delay value for this chart panel.
      void setDisplayToolTips​(boolean flag)
      Switches the display of tooltips for the panel on or off.
      void setDomainZoomable​(boolean flag)
      Sets the flag that controls whether or not zooming is enabled for the domain axis.
      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.
      protected void setHorizontalTraceLine​(java.awt.geom.Line2D line)
      Sets the horizontal trace line.
      void setInitialDelay​(int delay)
      Specifies the initial delay value for this chart panel.
      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 setMouseWheelEnabled​(boolean flag)
      Enables or disables mouse wheel support for the panel.
      void setMouseZoomable​(boolean flag)
      A convenience method that switches on mouse-based zooming.
      void setMouseZoomable​(boolean flag, boolean fillRectangle)
      A convenience method that switches on mouse-based zooming.
      void setPopupMenu​(javax.swing.JPopupMenu popup)
      Sets the popup menu for the panel.
      void setRangeZoomable​(boolean flag)
      A flag that controls mouse-based zooming on the vertical axis.
      void setRefreshBuffer​(boolean flag)
      Sets the refresh buffer flag.
      void setReshowDelay​(int delay)
      Specifies the amount of time before the user has to wait initialDelay milliseconds before a tooltip will be shown.
      void setVerticalAxisTrace​(boolean flag)
      A flag that controls trace lines on the vertical axis.
      protected void setVerticalTraceLine​(java.awt.geom.Line2D line)
      Sets the vertical trace line.
      void setZoomAroundAnchor​(boolean zoomAroundAnchor)
      Sets the flag that controls whether or not zoom operations are centered around the current anchor point.
      void setZoomFillPaint​(java.awt.Paint paint)
      Sets the zoom rectangle fill paint.
      void setZoomInFactor​(double factor)
      Sets the zoom in factor.
      void setZoomOutFactor​(double factor)
      Sets the zoom out factor.
      void setZoomOutlinePaint​(java.awt.Paint paint)
      Sets the zoom rectangle outline paint.
      void setZoomTriggerDistance​(int distance)
      Sets the zoom trigger distance.
      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 panel (component) location to a Java2D point.
      void updateUI()
      Updates the UI for a LookAndFeel change.
      private void writeAsPDF​(java.io.File file, int w, int h)
      Writes the current chart to the specified file in PDF format.
      private void writeObject​(java.io.ObjectOutputStream stream)
      Provides serialization support.
      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 (specified in screen coordinate space).
      void zoomInDomain​(double x, double y)
      Decreases the length of the domain axis, centered about the given coordinate on the screen.
      void zoomInRange​(double x, double y)
      Decreases the length of the range axis, centered about the given coordinate on the screen.
      void zoomOutBoth​(double x, double y)
      Zooms out on an anchor point (specified in screen coordinate space).
      void zoomOutDomain​(double x, double y)
      Increases the length of the domain axis, centered about the given coordinate on the screen.
      void zoomOutRange​(double x, double y)
      Increases the length the range axis, centered about the given coordinate on the screen.
      • Methods inherited from class javax.swing.JPanel

        getAccessibleContext, getUI, getUIClassID, paramString, setUI
      • Methods inherited from class javax.swing.JComponent

        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, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, 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
      • 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, 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, 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, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Field Detail

      • serialVersionUID

        private static final long serialVersionUID
        For serialization.
        See Also:
        Constant Field Values
      • DEFAULT_BUFFER_USED

        public static final boolean DEFAULT_BUFFER_USED
        Default setting for buffer usage. The default has been changed to true from version 1.0.13 onwards, because of a severe performance problem with drawing the zoom rectangle using XOR (which now happens only when the buffer is NOT used).
        See Also:
        Constant Field Values
      • DEFAULT_WIDTH

        public static final int DEFAULT_WIDTH
        The default panel width.
        See Also:
        Constant Field Values
      • DEFAULT_HEIGHT

        public static final int DEFAULT_HEIGHT
        The default panel height.
        See Also:
        Constant Field Values
      • DEFAULT_MINIMUM_DRAW_WIDTH

        public static final int DEFAULT_MINIMUM_DRAW_WIDTH
        The default limit below which chart scaling kicks in.
        See Also:
        Constant Field Values
      • DEFAULT_MINIMUM_DRAW_HEIGHT

        public static final int DEFAULT_MINIMUM_DRAW_HEIGHT
        The default limit below which chart scaling kicks in.
        See Also:
        Constant Field Values
      • DEFAULT_MAXIMUM_DRAW_WIDTH

        public static final int DEFAULT_MAXIMUM_DRAW_WIDTH
        The default limit above which chart scaling kicks in.
        See Also:
        Constant Field Values
      • DEFAULT_MAXIMUM_DRAW_HEIGHT

        public static final int DEFAULT_MAXIMUM_DRAW_HEIGHT
        The default limit above which chart scaling kicks in.
        See Also:
        Constant Field Values
      • DEFAULT_ZOOM_TRIGGER_DISTANCE

        public static final int DEFAULT_ZOOM_TRIGGER_DISTANCE
        The minimum size required to perform a zoom on a rectangle
        See Also:
        Constant Field Values
      • PROPERTIES_COMMAND

        public static final java.lang.String PROPERTIES_COMMAND
        Properties action command.
        See Also:
        Constant Field Values
      • COPY_COMMAND

        public static final java.lang.String COPY_COMMAND
        Copy action command.
        See Also:
        Constant Field Values
      • SAVE_COMMAND

        public static final java.lang.String SAVE_COMMAND
        Save action command.
        See Also:
        Constant Field Values
      • SAVE_AS_PNG_COMMAND

        private static final java.lang.String SAVE_AS_PNG_COMMAND
        Action command to save as PNG.
        See Also:
        Constant Field Values
      • SAVE_AS_SVG_COMMAND

        private static final java.lang.String SAVE_AS_SVG_COMMAND
        Action command to save as SVG.
        See Also:
        Constant Field Values
      • SAVE_AS_PDF_COMMAND

        private static final java.lang.String SAVE_AS_PDF_COMMAND
        Action command to save as PDF.
        See Also:
        Constant Field Values
      • PRINT_COMMAND

        public static final java.lang.String PRINT_COMMAND
        Print action command.
        See Also:
        Constant Field Values
      • ZOOM_IN_BOTH_COMMAND

        public static final java.lang.String ZOOM_IN_BOTH_COMMAND
        Zoom in (both axes) action command.
        See Also:
        Constant Field Values
      • ZOOM_IN_DOMAIN_COMMAND

        public static final java.lang.String ZOOM_IN_DOMAIN_COMMAND
        Zoom in (domain axis only) action command.
        See Also:
        Constant Field Values
      • ZOOM_IN_RANGE_COMMAND

        public static final java.lang.String ZOOM_IN_RANGE_COMMAND
        Zoom in (range axis only) action command.
        See Also:
        Constant Field Values
      • ZOOM_OUT_BOTH_COMMAND

        public static final java.lang.String ZOOM_OUT_BOTH_COMMAND
        Zoom out (both axes) action command.
        See Also:
        Constant Field Values
      • ZOOM_OUT_DOMAIN_COMMAND

        public static final java.lang.String ZOOM_OUT_DOMAIN_COMMAND
        Zoom out (domain axis only) action command.
        See Also:
        Constant Field Values
      • ZOOM_OUT_RANGE_COMMAND

        public static final java.lang.String ZOOM_OUT_RANGE_COMMAND
        Zoom out (range axis only) action command.
        See Also:
        Constant Field Values
      • ZOOM_RESET_BOTH_COMMAND

        public static final java.lang.String ZOOM_RESET_BOTH_COMMAND
        Zoom reset (both axes) action command.
        See Also:
        Constant Field Values
      • ZOOM_RESET_DOMAIN_COMMAND

        public static final java.lang.String ZOOM_RESET_DOMAIN_COMMAND
        Zoom reset (domain axis only) action command.
        See Also:
        Constant Field Values
      • ZOOM_RESET_RANGE_COMMAND

        public static final java.lang.String ZOOM_RESET_RANGE_COMMAND
        Zoom reset (range axis only) action command.
        See Also:
        Constant Field Values
      • chart

        private JFreeChart chart
        The chart that is displayed in the panel.
      • chartMouseListeners

        private transient javax.swing.event.EventListenerList chartMouseListeners
        Storage for registered (chart) mouse listeners.
      • useBuffer

        private final boolean useBuffer
        A flag that controls whether the off-screen buffer is used.
      • refreshBuffer

        private boolean refreshBuffer
        A flag that indicates that the buffer should be refreshed.
      • chartBuffer

        private transient java.awt.image.BufferedImage chartBuffer
        A buffer for the rendered chart.
      • minimumDrawWidth

        private int minimumDrawWidth
        The minimum width for drawing a chart (uses scaling for smaller widths).
      • minimumDrawHeight

        private int minimumDrawHeight
        The minimum height for drawing a chart (uses scaling for smaller heights).
      • maximumDrawWidth

        private int maximumDrawWidth
        The maximum width for drawing a chart (uses scaling for bigger widths).
      • maximumDrawHeight

        private int maximumDrawHeight
        The maximum height for drawing a chart (uses scaling for bigger heights).
      • popup

        private javax.swing.JPopupMenu popup
        The popup menu for the frame.
      • info

        private final ChartRenderingInfo info
        The drawing info collected the last time the chart was drawn.
      • anchor

        private java.awt.geom.Point2D anchor
        The chart anchor point.
      • scaleX

        private double scaleX
        The scale factor used to draw the chart.
      • scaleY

        private double scaleY
        The scale factor used to draw the chart.
      • domainZoomable

        private boolean domainZoomable
        A flag that controls whether or not domain zooming is enabled.
      • rangeZoomable

        private boolean rangeZoomable
        A flag that controls whether or not range zooming is enabled.
      • zoomPoint

        private java.awt.geom.Point2D zoomPoint
        The zoom rectangle starting point (selected by the user with a mouse click). This is a point on the screen, not the chart (which may have been scaled up or down to fit the panel).
      • zoomRectangle

        private transient java.awt.geom.Rectangle2D zoomRectangle
        The zoom rectangle (selected by the user with the mouse).
      • fillZoomRectangle

        private boolean fillZoomRectangle
        Controls if the zoom rectangle is drawn as an outline or filled.
      • zoomTriggerDistance

        private int zoomTriggerDistance
        The minimum distance required to drag the mouse to trigger a zoom.
      • horizontalAxisTrace

        private boolean horizontalAxisTrace
        A flag that controls whether or not horizontal tracing is enabled.
      • verticalAxisTrace

        private boolean verticalAxisTrace
        A flag that controls whether or not vertical tracing is enabled.
      • verticalTraceLine

        private transient java.awt.geom.Line2D verticalTraceLine
        A vertical trace line.
      • horizontalTraceLine

        private transient java.awt.geom.Line2D horizontalTraceLine
        A horizontal trace line.
      • zoomInBothMenuItem

        private javax.swing.JMenuItem zoomInBothMenuItem
        Menu item for zooming in on a chart (both axes).
      • zoomInDomainMenuItem

        private javax.swing.JMenuItem zoomInDomainMenuItem
        Menu item for zooming in on a chart (domain axis).
      • zoomInRangeMenuItem

        private javax.swing.JMenuItem zoomInRangeMenuItem
        Menu item for zooming in on a chart (range axis).
      • zoomOutBothMenuItem

        private javax.swing.JMenuItem zoomOutBothMenuItem
        Menu item for zooming out on a chart.
      • zoomOutDomainMenuItem

        private javax.swing.JMenuItem zoomOutDomainMenuItem
        Menu item for zooming out on a chart (domain axis).
      • zoomOutRangeMenuItem

        private javax.swing.JMenuItem zoomOutRangeMenuItem
        Menu item for zooming out on a chart (range axis).
      • zoomResetBothMenuItem

        private javax.swing.JMenuItem zoomResetBothMenuItem
        Menu item for resetting the zoom (both axes).
      • zoomResetDomainMenuItem

        private javax.swing.JMenuItem zoomResetDomainMenuItem
        Menu item for resetting the zoom (domain axis only).
      • zoomResetRangeMenuItem

        private javax.swing.JMenuItem zoomResetRangeMenuItem
        Menu item for resetting the zoom (range axis only).
      • defaultDirectoryForSaveAs

        private java.io.File defaultDirectoryForSaveAs
        The default directory for saving charts to file.
      • enforceFileExtensions

        private boolean enforceFileExtensions
        A flag that controls whether or not file extensions are enforced.
      • ownToolTipDelaysActive

        private boolean ownToolTipDelaysActive
        A flag that indicates if original tooltip delays are changed.
      • originalToolTipInitialDelay

        private int originalToolTipInitialDelay
        Original initial tooltip delay of ToolTipManager.sharedInstance().
      • originalToolTipReshowDelay

        private int originalToolTipReshowDelay
        Original reshow tooltip delay of ToolTipManager.sharedInstance().
      • originalToolTipDismissDelay

        private int originalToolTipDismissDelay
        Original dismiss tooltip delay of ToolTipManager.sharedInstance().
      • ownToolTipInitialDelay

        private int ownToolTipInitialDelay
        Own initial tooltip delay to be used in this chart panel.
      • ownToolTipReshowDelay

        private int ownToolTipReshowDelay
        Own reshow tooltip delay to be used in this chart panel.
      • ownToolTipDismissDelay

        private int ownToolTipDismissDelay
        Own dismiss tooltip delay to be used in this chart panel.
      • zoomInFactor

        private double zoomInFactor
        The factor used to zoom in on an axis range.
      • zoomOutFactor

        private double zoomOutFactor
        The factor used to zoom out on an axis range.
      • zoomAroundAnchor

        private boolean zoomAroundAnchor
        A flag that controls whether zoom operations are centred on the current anchor point, or the centre point of the relevant axis.
      • zoomOutlinePaint

        private transient java.awt.Paint zoomOutlinePaint
        The paint used to draw the zoom rectangle outline.
      • zoomFillPaint

        private transient java.awt.Paint zoomFillPaint
        The zoom fill paint (should use transparency).
      • localizationResources

        protected static java.util.ResourceBundle localizationResources
        The resourceBundle for the localization.
      • panW

        private double panW
        Temporary storage for the width and height of the chart drawing area during panning.
      • panH

        private double panH
        Temporary storage for the width and height of the chart drawing area during panning.
      • panLast

        private java.awt.Point panLast
        The last mouse position during panning.
      • panMask

        private int panMask
        The mask for mouse events to trigger panning.
      • overlays

        private final java.util.List<Overlay> overlays
        A list of overlays for the panel.
      • mouseWheelHandler

        private MouseWheelHandler mouseWheelHandler
        The mouse wheel handler.
    • Constructor Detail

      • ChartPanel

        public ChartPanel​(JFreeChart chart)
        Constructs a panel that displays the specified chart.
        Parameters:
        chart - the chart.
      • ChartPanel

        public ChartPanel​(JFreeChart chart,
                          boolean useBuffer)
        Constructs a panel containing a chart. The useBuffer flag controls whether or not an offscreen BufferedImage is maintained for the chart. If the buffer is used, more memory is consumed, but panel repaints will be a lot quicker in cases where the chart itself hasn't changed (for example, when another frame is moved to reveal the panel). WARNING: If you set the useBuffer flag to false, note that the mouse zooming rectangle will (in that case) be drawn using XOR, and there is a SEVERE performance problem with that on JRE6 on Windows.
        Parameters:
        chart - the chart.
        useBuffer - a flag controlling whether or not an off-screen buffer is used (read the warning above before setting this to false).
      • ChartPanel

        public ChartPanel​(JFreeChart chart,
                          boolean properties,
                          boolean save,
                          boolean print,
                          boolean zoom,
                          boolean tooltips)
        Constructs a JFreeChart panel.
        Parameters:
        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.
      • ChartPanel

        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)
        Constructs a JFreeChart panel.
        Parameters:
        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.
      • ChartPanel

        public ChartPanel​(JFreeChart chart,
                          int width,
                          int height,
                          int minimumDrawWidth,
                          int minimumDrawHeight,
                          int maximumDrawWidth,
                          int maximumDrawHeight,
                          boolean useBuffer,
                          boolean properties,
                          boolean copy,
                          boolean save,
                          boolean print,
                          boolean zoom,
                          boolean tooltips)
        Constructs a JFreeChart panel.
        Parameters:
        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.
        copy - a flag indicating whether or not a copy option 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

      • getChart

        public JFreeChart getChart()
        Returns the chart contained in the panel.
        Returns:
        The chart (possibly null).
      • setChart

        public void setChart​(JFreeChart chart)
        Sets the chart that is displayed in the panel.
        Parameters:
        chart - the chart (null permitted).
      • getMinimumDrawWidth

        public int getMinimumDrawWidth()
        Returns the minimum drawing width for charts.

        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.

        Returns:
        The minimum drawing width.
      • setMinimumDrawWidth

        public void setMinimumDrawWidth​(int width)
        Sets the minimum drawing width for the chart on this panel.

        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.

        Parameters:
        width - The width.
      • getMaximumDrawWidth

        public int getMaximumDrawWidth()
        Returns the maximum drawing width for charts.

        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.

        Returns:
        The maximum drawing width.
      • setMaximumDrawWidth

        public void setMaximumDrawWidth​(int width)
        Sets the maximum drawing width for the chart on this panel.

        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.

        Parameters:
        width - The width.
      • getMinimumDrawHeight

        public int getMinimumDrawHeight()
        Returns the minimum drawing height for charts.

        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.

        Returns:
        The minimum drawing height.
      • setMinimumDrawHeight

        public void setMinimumDrawHeight​(int height)
        Sets the minimum drawing height for the chart on this panel.

        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.

        Parameters:
        height - The height.
      • getMaximumDrawHeight

        public int getMaximumDrawHeight()
        Returns the maximum drawing height for charts.

        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.

        Returns:
        The maximum drawing height.
      • setMaximumDrawHeight

        public void setMaximumDrawHeight​(int height)
        Sets the maximum drawing height for the chart on this panel.

        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.

        Parameters:
        height - The height.
      • getScaleX

        public double getScaleX()
        Returns the X scale factor for the chart. This will be 1.0 if no scaling has been used.
        Returns:
        The scale factor.
      • getScaleY

        public double getScaleY()
        Returns the Y scale factory for the chart. This will be 1.0 if no scaling has been used.
        Returns:
        The scale factor.
      • getAnchor

        public java.awt.geom.Point2D getAnchor()
        Returns the anchor point.
        Returns:
        The anchor point (possibly null).
      • setAnchor

        protected void setAnchor​(java.awt.geom.Point2D anchor)
        Sets the anchor point. This method is provided for the use of subclasses, not end users.
        Parameters:
        anchor - the anchor point (null permitted).
      • getPopupMenu

        public javax.swing.JPopupMenu getPopupMenu()
        Returns the popup menu.
        Returns:
        The popup menu.
      • setPopupMenu

        public void setPopupMenu​(javax.swing.JPopupMenu popup)
        Sets the popup menu for the panel.
        Parameters:
        popup - the popup menu (null permitted).
      • getChartRenderingInfo

        public ChartRenderingInfo getChartRenderingInfo()
        Returns the chart rendering info from the most recent chart redraw.
        Returns:
        The chart rendering info.
      • setMouseZoomable

        public void setMouseZoomable​(boolean flag)
        A convenience method that switches on mouse-based zooming.
        Parameters:
        flag - true enables zooming and rectangle fill on zoom.
      • setMouseZoomable

        public void setMouseZoomable​(boolean flag,
                                     boolean fillRectangle)
        A convenience method that switches on mouse-based zooming.
        Parameters:
        flag - true if zooming enabled
        fillRectangle - true if zoom rectangle is filled, false if rectangle is shown as outline only.
      • isDomainZoomable

        public boolean isDomainZoomable()
        Returns the flag that determines whether or not zooming is enabled for the domain axis.
        Returns:
        A boolean.
      • setDomainZoomable

        public void setDomainZoomable​(boolean flag)
        Sets the flag that controls whether or not zooming is enabled for the domain axis. A check is made to ensure that the current plot supports zooming for the domain values.
        Parameters:
        flag - true enables zooming if possible.
      • isRangeZoomable

        public boolean isRangeZoomable()
        Returns the flag that determines whether or not zooming is enabled for the range axis.
        Returns:
        A boolean.
      • setRangeZoomable

        public void setRangeZoomable​(boolean flag)
        A flag that controls mouse-based zooming on the vertical axis.
        Parameters:
        flag - true enables zooming.
      • getFillZoomRectangle

        public boolean getFillZoomRectangle()
        Returns the flag that controls whether or not the zoom rectangle is filled when drawn.
        Returns:
        A boolean.
      • setFillZoomRectangle

        public void setFillZoomRectangle​(boolean flag)
        A flag that controls how the zoom rectangle is drawn.
        Parameters:
        flag - true instructs to fill the rectangle on zoom, otherwise it will be outlined.
      • getZoomTriggerDistance

        public int getZoomTriggerDistance()
        Returns the zoom trigger distance. This controls how far the mouse must move before a zoom action is triggered.
        Returns:
        The distance (in Java2D units).
      • setZoomTriggerDistance

        public void setZoomTriggerDistance​(int distance)
        Sets the zoom trigger distance. This controls how far the mouse must move before a zoom action is triggered.
        Parameters:
        distance - the distance (in Java2D units).
      • getHorizontalAxisTrace

        public boolean getHorizontalAxisTrace()
        Returns the flag that controls whether or not a horizontal axis trace line is drawn over the plot area at the current mouse location.
        Returns:
        A boolean.
      • setHorizontalAxisTrace

        public void setHorizontalAxisTrace​(boolean flag)
        A flag that controls trace lines on the horizontal axis.
        Parameters:
        flag - true enables trace lines for the mouse pointer on the horizontal axis.
      • getHorizontalTraceLine

        protected java.awt.geom.Line2D getHorizontalTraceLine()
        Returns the horizontal trace line.
        Returns:
        The horizontal trace line (possibly null).
      • setHorizontalTraceLine

        protected void setHorizontalTraceLine​(java.awt.geom.Line2D line)
        Sets the horizontal trace line.
        Parameters:
        line - the line (null permitted).
      • getVerticalAxisTrace

        public boolean getVerticalAxisTrace()
        Returns the flag that controls whether or not a vertical axis trace line is drawn over the plot area at the current mouse location.
        Returns:
        A boolean.
      • setVerticalAxisTrace

        public void setVerticalAxisTrace​(boolean flag)
        A flag that controls trace lines on the vertical axis.
        Parameters:
        flag - true enables trace lines for the mouse pointer on the vertical axis.
      • getVerticalTraceLine

        protected java.awt.geom.Line2D getVerticalTraceLine()
        Returns the vertical trace line.
        Returns:
        The vertical trace line (possibly null).
      • setVerticalTraceLine

        protected void setVerticalTraceLine​(java.awt.geom.Line2D line)
        Sets the vertical trace line.
        Parameters:
        line - the line (null permitted).
      • getDefaultDirectoryForSaveAs

        public java.io.File getDefaultDirectoryForSaveAs()
        Returns the default directory for the "save as" option.
        Returns:
        The default directory (possibly null).
      • setDefaultDirectoryForSaveAs

        public void setDefaultDirectoryForSaveAs​(java.io.File directory)
        Sets the default directory for the "save as" option. If you set this to null, the user's default directory will be used.
        Parameters:
        directory - the directory (null permitted).
      • isEnforceFileExtensions

        public boolean isEnforceFileExtensions()
        Returns true if file extensions should be enforced, and false otherwise.
        Returns:
        The flag.
        See Also:
        setEnforceFileExtensions(boolean)
      • setEnforceFileExtensions

        public void setEnforceFileExtensions​(boolean enforce)
        Sets a flag that controls whether or not file extensions are enforced.
        Parameters:
        enforce - the new flag value.
        See Also:
        isEnforceFileExtensions()
      • getZoomAroundAnchor

        public boolean getZoomAroundAnchor()
        Returns the flag that controls whether or not zoom operations are centered around the current anchor point.
        Returns:
        A boolean.
        See Also:
        setZoomAroundAnchor(boolean)
      • setZoomAroundAnchor

        public void setZoomAroundAnchor​(boolean zoomAroundAnchor)
        Sets the flag that controls whether or not zoom operations are centered around the current anchor point.
        Parameters:
        zoomAroundAnchor - the new flag value.
        See Also:
        getZoomAroundAnchor()
      • setZoomFillPaint

        public void setZoomFillPaint​(java.awt.Paint paint)
        Sets the zoom rectangle fill paint.
        Parameters:
        paint - the paint (null not permitted).
        See Also:
        getZoomFillPaint(), getFillZoomRectangle()
      • setZoomOutlinePaint

        public void setZoomOutlinePaint​(java.awt.Paint paint)
        Sets the zoom rectangle outline paint.
        Parameters:
        paint - the paint (null not permitted).
        See Also:
        getZoomOutlinePaint(), getFillZoomRectangle()
      • isMouseWheelEnabled

        public boolean isMouseWheelEnabled()
        Returns true if the mouse wheel handler is enabled, and false otherwise.
        Returns:
        A boolean.
      • setMouseWheelEnabled

        public void setMouseWheelEnabled​(boolean flag)
        Enables or disables mouse wheel support for the panel.
        Parameters:
        flag - a boolean.
      • addOverlay

        public void addOverlay​(Overlay overlay)
        Add an overlay to the panel.
        Parameters:
        overlay - the overlay (null not permitted).
      • removeOverlay

        public void removeOverlay​(Overlay overlay)
        Removes an overlay from the panel.
        Parameters:
        overlay - the overlay to remove (null not permitted).
      • setDisplayToolTips

        public void setDisplayToolTips​(boolean flag)
        Switches the display of tooltips for the panel on or off. Note that tooltips can only be displayed if the chart has been configured to generate tooltip items.
        Parameters:
        flag - true to enable tooltips, false to disable tooltips.
      • getToolTipText

        public java.lang.String getToolTipText​(java.awt.event.MouseEvent e)
        Returns a string for the tooltip.
        Overrides:
        getToolTipText in class javax.swing.JComponent
        Parameters:
        e - the mouse event.
        Returns:
        A tool tip or null if no tooltip is available.
      • translateJava2DToScreen

        public java.awt.Point translateJava2DToScreen​(java.awt.geom.Point2D java2DPoint)
        Translates a Java2D point on the chart to a screen location.
        Parameters:
        java2DPoint - the Java2D point.
        Returns:
        The screen location.
      • translateScreenToJava2D

        public java.awt.geom.Point2D translateScreenToJava2D​(java.awt.Point screenPoint)
        Translates a panel (component) location to a Java2D point.
        Parameters:
        screenPoint - the screen location (null not permitted).
        Returns:
        The Java2D coordinates.
      • scale

        public java.awt.geom.Rectangle2D scale​(java.awt.geom.Rectangle2D rect)
        Applies any scaling that is in effect for the chart drawing to the given rectangle.
        Parameters:
        rect - the rectangle (null not permitted).
        Returns:
        A new scaled rectangle.
      • getEntityForPoint

        public ChartEntity getEntityForPoint​(int viewX,
                                             int viewY)
        Returns the chart entity at a given point.

        This method will return null if there is (a) no entity at the given point, or (b) no entity collection has been generated.

        Parameters:
        viewX - the x-coordinate.
        viewY - the y-coordinate.
        Returns:
        The chart entity (possibly null).
      • getRefreshBuffer

        public boolean getRefreshBuffer()
        Returns the flag that controls whether or not the offscreen buffer needs to be refreshed.
        Returns:
        A boolean.
      • setRefreshBuffer

        public void setRefreshBuffer​(boolean flag)
        Sets the refresh buffer flag. This flag is used to avoid unnecessary redrawing of the chart when the offscreen image buffer is used.
        Parameters:
        flag - true indicates that the buffer should be refreshed.
      • paintComponent

        public 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). To increase performance (at the expense of memory), an off-screen buffer image can be used.
        Overrides:
        paintComponent in class javax.swing.JComponent
        Parameters:
        g - the graphics device for drawing on.
      • paintChartToBuffer

        protected java.awt.image.BufferedImage paintChartToBuffer​(java.awt.Graphics2D g2,
                                                                  java.awt.Dimension bufferSize,
                                                                  java.awt.Dimension chartSize,
                                                                  java.awt.geom.Point2D anchor,
                                                                  ChartRenderingInfo info)
        Paints the chart to fill the entire off-screen buffer image.
        Parameters:
        g2 - the graphics context to create an off-screen buffer image.
        bufferSize - the required off-screen buffer image size.
        chartSize - the size with which the chart should be drawn (apply scaling if not equal to bufferSize).
        anchor - the anchor point (in Java2D space) for the chart (null permitted).
        info - records info about the drawing (null means collect no info).
        Returns:
        the off-screen buffer image to draw onto the panel.
      • chartChanged

        public void chartChanged​(ChartChangeEvent event)
        Receives notification of changes to the chart, and redraws the chart.
        Specified by:
        chartChanged in interface ChartChangeListener
        Parameters:
        event - details of the chart change event.
      • actionPerformed

        public void actionPerformed​(java.awt.event.ActionEvent event)
        Handles action events generated by the popup menu.
        Specified by:
        actionPerformed in interface java.awt.event.ActionListener
        Parameters:
        event - the event.
      • mouseEntered

        public void mouseEntered​(java.awt.event.MouseEvent e)
        Handles a 'mouse entered' event. This method changes the tooltip delays of ToolTipManager.sharedInstance() to the possibly different values set for this chart panel.
        Specified by:
        mouseEntered in interface java.awt.event.MouseListener
        Parameters:
        e - the mouse event.
      • mouseExited

        public void mouseExited​(java.awt.event.MouseEvent e)
        Handles a 'mouse exited' event. This method resets the tooltip delays of ToolTipManager.sharedInstance() to their original values in effect before mouseEntered()
        Specified by:
        mouseExited in interface java.awt.event.MouseListener
        Parameters:
        e - the mouse event.
      • mousePressed

        public void mousePressed​(java.awt.event.MouseEvent e)
        Handles a 'mouse pressed' event.

        This event is the popup trigger on Unix/Linux. For Windows, the popup trigger is the 'mouse released' event.

        Specified by:
        mousePressed in interface java.awt.event.MouseListener
        Parameters:
        e - The mouse event.
      • getPointInRectangle

        private java.awt.geom.Point2D getPointInRectangle​(int x,
                                                          int y,
                                                          java.awt.geom.Rectangle2D area)
        Returns a point based on (x, y) but constrained to be within the bounds of the given rectangle. This method could be moved to JCommon.
        Parameters:
        x - the x-coordinate.
        y - the y-coordinate.
        area - the rectangle (null not permitted).
        Returns:
        A point within the rectangle.
      • mouseDragged

        public void mouseDragged​(java.awt.event.MouseEvent e)
        Handles a 'mouse dragged' event.
        Specified by:
        mouseDragged in interface java.awt.event.MouseMotionListener
        Parameters:
        e - the mouse event.
      • mouseReleased

        public void mouseReleased​(java.awt.event.MouseEvent e)
        Handles a 'mouse released' event. On Windows, we need to check if this is a popup trigger, but only if we haven't already been tracking a zoom rectangle.
        Specified by:
        mouseReleased in interface java.awt.event.MouseListener
        Parameters:
        e - information about the event.
      • mouseClicked

        public void mouseClicked​(java.awt.event.MouseEvent event)
        Receives notification of mouse clicks on the panel. These are translated and passed on to any registered ChartMouseListeners.
        Specified by:
        mouseClicked in interface java.awt.event.MouseListener
        Parameters:
        event - Information about the mouse event.
      • mouseMoved

        public void mouseMoved​(java.awt.event.MouseEvent e)
        Implementation of the MouseMotionListener's method.
        Specified by:
        mouseMoved in interface java.awt.event.MouseMotionListener
        Parameters:
        e - the event.
      • zoomInBoth

        public void zoomInBoth​(double x,
                               double y)
        Zooms in on an anchor point (specified in screen coordinate space).
        Parameters:
        x - the x value (in screen coordinates).
        y - the y value (in screen coordinates).
      • zoomInDomain

        public void zoomInDomain​(double x,
                                 double y)
        Decreases the length of the domain axis, centered about the given coordinate on the screen. The length of the domain axis is reduced by the value of getZoomInFactor().
        Parameters:
        x - the x coordinate (in screen coordinates).
        y - the y-coordinate (in screen coordinates).
      • zoomInRange

        public void zoomInRange​(double x,
                                double y)
        Decreases the length of the range axis, centered about the given coordinate on the screen. The length of the range axis is reduced by the value of getZoomInFactor().
        Parameters:
        x - the x-coordinate (in screen coordinates).
        y - the y coordinate (in screen coordinates).
      • zoomOutBoth

        public void zoomOutBoth​(double x,
                                double y)
        Zooms out on an anchor point (specified in screen coordinate space).
        Parameters:
        x - the x value (in screen coordinates).
        y - the y value (in screen coordinates).
      • zoomOutDomain

        public void zoomOutDomain​(double x,
                                  double y)
        Increases the length of the domain axis, centered about the given coordinate on the screen. The length of the domain axis is increased by the value of getZoomOutFactor().
        Parameters:
        x - the x coordinate (in screen coordinates).
        y - the y-coordinate (in screen coordinates).
      • zoomOutRange

        public void zoomOutRange​(double x,
                                 double y)
        Increases the length the range axis, centered about the given coordinate on the screen. The length of the range axis is increased by the value of getZoomOutFactor().
        Parameters:
        x - the x coordinate (in screen coordinates).
        y - the y-coordinate (in screen coordinates).
      • zoom

        public void zoom​(java.awt.geom.Rectangle2D selection)
        Zooms in on a selected region.
        Parameters:
        selection - the selected region.
      • restoreAutoBounds

        public void restoreAutoBounds()
        Restores the auto-range calculation on both axes.
      • restoreAutoDomainBounds

        public void restoreAutoDomainBounds()
        Restores the auto-range calculation on the domain axis.
      • restoreAutoRangeBounds

        public void restoreAutoRangeBounds()
        Restores the auto-range calculation on the range axis.
      • getScreenDataArea

        public java.awt.geom.Rectangle2D getScreenDataArea()
        Returns the data area for the chart (the area inside the axes) with the current scaling applied (that is, the area as it appears on screen).
        Returns:
        The scaled data area.
      • getScreenDataArea

        public java.awt.geom.Rectangle2D getScreenDataArea​(int x,
                                                           int y)
        Returns the data area (the area inside the axes) for the plot or subplot, with the current scaling applied.
        Parameters:
        x - the x-coordinate (for subplot selection).
        y - the y-coordinate (for subplot selection).
        Returns:
        The scaled data area.
      • getInitialDelay

        public int getInitialDelay()
        Returns the initial tooltip delay value used inside this chart panel.
        Returns:
        An integer representing the initial delay value, in milliseconds.
        See Also:
        ToolTipManager.getInitialDelay()
      • getReshowDelay

        public int getReshowDelay()
        Returns the reshow tooltip delay value used inside this chart panel.
        Returns:
        An integer representing the reshow delay value, in milliseconds.
        See Also:
        ToolTipManager.getReshowDelay()
      • getDismissDelay

        public int getDismissDelay()
        Returns the dismissal tooltip delay value used inside this chart panel.
        Returns:
        An integer representing the dismissal delay value, in milliseconds.
        See Also:
        ToolTipManager.getDismissDelay()
      • setInitialDelay

        public void setInitialDelay​(int delay)
        Specifies the initial delay value for this chart panel.
        Parameters:
        delay - the number of milliseconds to delay (after the cursor has paused) before displaying.
        See Also:
        ToolTipManager.setInitialDelay(int)
      • setReshowDelay

        public void setReshowDelay​(int delay)
        Specifies the amount of time before the user has to wait initialDelay milliseconds before a tooltip will be shown.
        Parameters:
        delay - time in milliseconds
        See Also:
        ToolTipManager.setReshowDelay(int)
      • setDismissDelay

        public void setDismissDelay​(int delay)
        Specifies the dismissal delay value for this chart panel.
        Parameters:
        delay - the number of milliseconds to delay before taking away the tooltip
        See Also:
        ToolTipManager.setDismissDelay(int)
      • getZoomInFactor

        public double getZoomInFactor()
        Returns the zoom in factor.
        Returns:
        The zoom in factor.
        See Also:
        setZoomInFactor(double)
      • setZoomInFactor

        public void setZoomInFactor​(double factor)
        Sets the zoom in factor.
        Parameters:
        factor - the factor.
        See Also:
        getZoomInFactor()
      • getZoomOutFactor

        public double getZoomOutFactor()
        Returns the zoom out factor.
        Returns:
        The zoom out factor.
        See Also:
        setZoomOutFactor(double)
      • setZoomOutFactor

        public void setZoomOutFactor​(double factor)
        Sets the zoom out factor.
        Parameters:
        factor - the factor.
        See Also:
        getZoomOutFactor()
      • drawZoomRectangle

        private void drawZoomRectangle​(java.awt.Graphics2D g2,
                                       boolean xor)
        Draws zoom rectangle (if present). The drawing is performed in XOR mode, therefore when this method is called twice in a row, the second call will completely restore the state of the canvas.
        Parameters:
        g2 - the graphics device.
        xor - use XOR for drawing?
      • drawHorizontalAxisTrace

        private void drawHorizontalAxisTrace​(java.awt.Graphics2D g2,
                                             int x)
        Draws a vertical line used to trace the mouse position to the horizontal axis.
        Parameters:
        g2 - the graphics device.
        x - the x-coordinate of the trace line.
      • drawVerticalAxisTrace

        private void drawVerticalAxisTrace​(java.awt.Graphics2D g2,
                                           int y)
        Draws a horizontal line used to trace the mouse position to the vertical axis.
        Parameters:
        g2 - the graphics device.
        y - the y-coordinate of the trace line.
      • doEditChartProperties

        public void doEditChartProperties()
        Displays a dialog that allows the user to edit the properties for the current chart.
      • doCopy

        public void doCopy()
        Copies the current chart to the system clipboard.
      • doSaveAs

        public void doSaveAs()
                      throws java.io.IOException
        Opens a file chooser and gives the user an opportunity to save the chart in PNG format.
        Throws:
        java.io.IOException - if there is an I/O error.
      • saveAsSVG

        private void saveAsSVG​(java.io.File f)
                        throws java.io.IOException
        Saves the chart in SVG format (a filechooser will be displayed so that the user can specify the filename). Note that this method only works if the JFreeSVG library is on the classpath...if this library is not present, the method will fail.
        Throws:
        java.io.IOException
      • generateSVG

        private java.lang.String generateSVG​(int width,
                                             int height)
        Generates a string containing a rendering of the chart in SVG format. This feature is only supported if the JFreeSVG library is included on the classpath.
        Returns:
        A string containing an SVG element for the current chart, or null if there is a problem with the method invocation by reflection.
      • createSVGGraphics2D

        private java.awt.Graphics2D createSVGGraphics2D​(int w,
                                                        int h)
      • saveAsPDF

        private void saveAsPDF​(java.io.File f)
        Saves the chart in PDF format (a filechooser will be displayed so that the user can specify the filename). Note that this method only works if the OrsonPDF library is on the classpath...if this library is not present, the method will fail.
      • isOrsonPDFAvailable

        private boolean isOrsonPDFAvailable()
        Returns true if OrsonPDF is on the classpath, and false otherwise. The OrsonPDF library can be found at http://www.object-refinery.com/pdf/
        Returns:
        A boolean.
      • writeAsPDF

        private void writeAsPDF​(java.io.File file,
                                int w,
                                int h)
        Writes the current chart to the specified file in PDF format. This will only work when the OrsonPDF library is found on the classpath. Reflection is used to ensure there is no compile-time dependency on OrsonPDF (which is non-free software).
        Parameters:
        file - the output file (null not permitted).
        w - the chart width.
        h - the chart height.
      • createChartPrintJob

        public void createChartPrintJob()
        Creates a print job for the chart.
      • print

        public int print​(java.awt.Graphics g,
                         java.awt.print.PageFormat pf,
                         int pageIndex)
        Prints the chart on a single page.
        Specified by:
        print in interface java.awt.print.Printable
        Parameters:
        g - the graphics context.
        pf - the page format to use.
        pageIndex - the index of the page. If not 0, nothing gets printed.
        Returns:
        The result of printing.
      • addChartMouseListener

        public void addChartMouseListener​(ChartMouseListener listener)
        Adds a listener to the list of objects listening for chart mouse events.
        Parameters:
        listener - the listener (null not permitted).
      • removeChartMouseListener

        public void removeChartMouseListener​(ChartMouseListener listener)
        Removes a listener from the list of objects listening for chart mouse events.
        Parameters:
        listener - the listener.
      • getListeners

        public java.util.EventListener[] getListeners​(java.lang.Class listenerType)
        Returns an array of the listeners of the given type registered with the panel.
        Overrides:
        getListeners in class javax.swing.JComponent
        Parameters:
        listenerType - the listener type.
        Returns:
        An array of listeners.
      • createPopupMenu

        protected javax.swing.JPopupMenu createPopupMenu​(boolean properties,
                                                         boolean save,
                                                         boolean print,
                                                         boolean zoom)
        Creates a popup menu for the panel.
        Parameters:
        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.
        Returns:
        The popup menu.
      • createPopupMenu

        protected javax.swing.JPopupMenu createPopupMenu​(boolean properties,
                                                         boolean copy,
                                                         boolean save,
                                                         boolean print,
                                                         boolean zoom)
        Creates a popup menu for the panel.
        Parameters:
        properties - include a menu item for the chart property editor.
        copy - include a menu item for copying to the clipboard.
        save - include a menu item for saving the chart.
        print - include a menu item for printing the chart.
        zoom - include menu items for zooming.
        Returns:
        The popup menu.
      • displayPopupMenu

        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.
        Parameters:
        x - horizontal position of the popup.
        y - vertical position of the popup.
      • updateUI

        public void updateUI()
        Updates the UI for a LookAndFeel change.
        Overrides:
        updateUI in class javax.swing.JPanel
      • writeObject

        private void writeObject​(java.io.ObjectOutputStream stream)
                          throws java.io.IOException
        Provides serialization support.
        Parameters:
        stream - the output stream.
        Throws:
        java.io.IOException - if there is an I/O error.
      • readObject

        private void readObject​(java.io.ObjectInputStream stream)
                         throws java.io.IOException,
                                java.lang.ClassNotFoundException
        Provides serialization support.
        Parameters:
        stream - the input stream.
        Throws:
        java.io.IOException - if there is an I/O error.
        java.lang.ClassNotFoundException - if there is a classpath problem.