Package adams.gui.visualization.core
Class PlotPanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- adams.gui.visualization.core.PlotPanel
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,Accessible
- Direct Known Subclasses:
BoxPlotGraph
,HistogramPanel
,ProbabilityPlotPanel
,ScatterPlotPanel
,VersusFitPanel
,VersusOrderPanel
,ZScorePanel
public class PlotPanel extends JPanel
A panel that contains a drawing (= content) area with (usually) two axes. Display and parametrization of top/bottom/left/right axis is possible.- Version:
- $Revision$
- Author:
- fracpete (fracpete at waikato dot ac dot nz)
- See Also:
- Serialized Form
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanel
-
Nested classes/interfaces inherited from class javax.swing.JComponent
JComponent.AccessibleJComponent
-
Nested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainer
-
Nested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy
-
-
Field Summary
Fields Modifier and Type Field Description protected AxisPanel
m_AxisBottom
the bottom axis panel.protected AxisPanel
m_AxisLeft
the left axis panel.protected AxisPanel
m_AxisRight
the right axis panel.protected AxisPanel
m_AxisTop
the top axis panel.protected int
m_AxisWidth
the width of the axes.protected Color
m_BackgroundColor
the background color.protected JPanel
m_CornerBottomLeft
the bottom-left corner panel.protected JPanel
m_CornerBottomRight
the bottom-right corner panel.protected JPanel
m_CornerTopLeft
the top-left corner panel.protected JPanel
m_CornerTopRight
the top-right corner panel.protected Boolean
m_Debug
whether debug mode is on.protected Color
m_ForegroundColor
the foregorund color.protected Color
m_GridColor
the color for the grid.protected Set<MouseListener>
m_MouseClickListeners
the mouse click listeners.protected Set<PaintListener>
m_PaintListeners
the paint listeners.protected ContentPanel
m_PanelContent
the content panel for drawing.protected List<Axis>
m_ToolTipAxes
the vector with the axes that make up the values in the tooltip.-
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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description void
addHitDetector(HitDetector detector)
Adds the detector to the internal list of detectors.void
addMouseClickListener(MouseListener l)
Adds the given listener to the internal list of mouse click listeners.void
addMouseMovementTracker(MouseMovementTracker l)
Adds the given listener to the internal list of mouse movement tracking listeners.void
addPaintListener(PaintListener l)
Adds the given listener to the internal list of paint listeners.void
addPanningListener(PlotPanelPanningListener l)
Adds the given listener to the internal list of panning listeners.protected void
addPrintScreenListener(JComponent comp)
Adds a "print screen" listener to the container.void
addToolTipAxis(Axis axis)
Adds the axis at the end of the vector with the axes making up the tooltip of values of the content panel.void
addZoom(double top, double left, double bottom, double right)
Adds a zoom.void
addZoom(int top, int left, int bottom, int right)
Adds a zoom.void
addZoomListener(PlotPanelZoomListener l)
Adds the given listener to the internal list of zoom listeners.void
clearHitDetectors()
Removes all hit detectors.void
clearPanning()
Clears the panning.void
clearToolTipAxes()
Removes display of tool tips for all axis.void
clearZoom()
Clears the zoom.protected JPanel
createCornerPanel()
Creates a corner panel (square panel that cannot be resized).int
getActualAxisWidth(Axis axis)
Returns the actual size of the specified axis, depending on visibility.AxisPanel
getAxis(Axis axis)
Returns the specified axis.PopupMenuCustomizer
getAxisPopupMenuCustomizer(Axis axis)
Returns the current axis customizer, can be null.Visibility
getAxisVisibility(Axis axis)
Returns the visibility of the specified axis.int
getAxisWidth(Axis axis)
Returns the size of the specified axis.Color
getBackgroundColor()
Returns the current background color in use.ContentPanel
getContent()
Returns the content panel.Color
getForegroundColor()
Returns the current foreground color in use.Color
getGridColor()
Returns the color used for painting the coordinates grid.PopupMenuCustomizer
getPopupMenuCustomizer()
Returns the current customizer, can be null.TipTextCustomizer
getTipTextCustomizer()
Returns the current tip text customizer, can be null.boolean
hasToolTipAxis(Axis axis)
Checks whether the specified axis is used in making up the tooltip.protected void
initGUI()
Initializes the GUI components.protected void
initialize()
Initializes the members.boolean
isPanned()
Returns true if any of the axis has a pixel offset != 0.boolean
isPanningEnabled()
Returns whether panning is enabled.boolean
isZoomed()
Returns true if any of the axis is zoomed.boolean
isZoomingEnabled()
Returns whether zooming is enabled.void
notifyMouseClickListeners(MouseEvent e)
Notifies all mouse click listeners.void
notifyPaintListeners(Graphics g, PaintEvent.PaintMoment moment)
Notifies all paint listeners.void
removeHitDetector(HitDetector detector)
Removes the detector from the internal list of detectors.void
removeMouseClickListener(MouseListener l)
Removes the given listener from the internal list of mouse click listeners.void
removeMouseMovementTracker(MouseMovementTracker l)
Removes the given listener from the internal list of mouse movement tracking listeners.void
removePaintListener(PaintListener l)
Removes the given listener from the internal list of paint listeners.void
removePanningListener(PlotPanelPanningListener l)
Removes the given listener from the internal list of panning listeners.void
removeToolTipAxis(Axis axis)
Removes the axis from the vector with the axes making up the tooltip of values of the content panel.void
removeZoomListener(PlotPanelZoomListener l)
Removes the given listener from the internal list of zoom listeners.void
setAxisPopupMenuCustomizer(Axis axis, PopupMenuCustomizer value)
Sets the class to customize the right-click popup menu of an axis.void
setAxisVisibility(Axis axis, Visibility visible)
Sets the visibility state of the specified axis.void
setAxisWidth(Axis axis, int width)
Sets the size of the specified axis.void
setAxisWidths(int value)
Sets the widht of all the axes.void
setBackgroundColor(Color value)
Sets the background color to use.void
setForegroundColor(Color value)
Sets the foreground color to use.void
setGridColor(Color value)
Sets the color to use for painting the coordinates grid.void
setPanningEnabled(boolean value)
Sets whether panning is enabled or not.void
setPopupMenuCustomizer(PopupMenuCustomizer value)
Sets the class to customize the right-click popup menu.void
setTipTextCustomizer(TipTextCustomizer value)
Sets the class for customizing the tip text.void
setZoomingEnabled(boolean value)
Sets whether zooming is enabled or not.String
toString()
Returns a short description of the panel.protected void
updateCorner(Axis axis)
Updates the dimensions of the corner panels.protected void
updateCornerPanel(JPanel panel, int width, int height)
updates the dimensions of the corner panel.void
updateCorners()
Updates all the corners-
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
-
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, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintComponent, 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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
m_AxisBottom
protected AxisPanel m_AxisBottom
the bottom axis panel.
-
m_AxisTop
protected AxisPanel m_AxisTop
the top axis panel.
-
m_AxisLeft
protected AxisPanel m_AxisLeft
the left axis panel.
-
m_AxisRight
protected AxisPanel m_AxisRight
the right axis panel.
-
m_PanelContent
protected ContentPanel m_PanelContent
the content panel for drawing.
-
m_AxisWidth
protected int m_AxisWidth
the width of the axes.
-
m_CornerTopLeft
protected JPanel m_CornerTopLeft
the top-left corner panel.
-
m_CornerTopRight
protected JPanel m_CornerTopRight
the top-right corner panel.
-
m_CornerBottomLeft
protected JPanel m_CornerBottomLeft
the bottom-left corner panel.
-
m_CornerBottomRight
protected JPanel m_CornerBottomRight
the bottom-right corner panel.
-
m_PaintListeners
protected Set<PaintListener> m_PaintListeners
the paint listeners.
-
m_MouseClickListeners
protected Set<MouseListener> m_MouseClickListeners
the mouse click listeners.
-
m_ToolTipAxes
protected List<Axis> m_ToolTipAxes
the vector with the axes that make up the values in the tooltip.
-
m_Debug
protected Boolean m_Debug
whether debug mode is on.
-
m_GridColor
protected Color m_GridColor
the color for the grid.
-
m_BackgroundColor
protected Color m_BackgroundColor
the background color.
-
m_ForegroundColor
protected Color m_ForegroundColor
the foregorund color.
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.
-
createCornerPanel
protected JPanel createCornerPanel()
Creates a corner panel (square panel that cannot be resized).- Returns:
- the corner panel
-
updateCornerPanel
protected void updateCornerPanel(JPanel panel, int width, int height)
updates the dimensions of the corner panel.- Parameters:
panel
- the panel to updatedwidth
- the new widthheight
- the new height
-
initGUI
protected void initGUI()
Initializes the GUI components.
-
addPrintScreenListener
protected void addPrintScreenListener(JComponent comp)
Adds a "print screen" listener to the container.- Parameters:
comp
- the component to add the listener to
-
setForegroundColor
public void setForegroundColor(Color value)
Sets the foreground color to use.- Parameters:
value
- the color to use
-
getForegroundColor
public Color getForegroundColor()
Returns the current foreground color in use.- Returns:
- the color in use
-
setBackgroundColor
public void setBackgroundColor(Color value)
Sets the background color to use.- Parameters:
value
- the color to use
-
getBackgroundColor
public Color getBackgroundColor()
Returns the current background color in use.- Returns:
- the color in use
-
setAxisWidths
public void setAxisWidths(int value)
Sets the widht of all the axes.- Parameters:
value
- the width to set
-
setAxisWidth
public void setAxisWidth(Axis axis, int width)
Sets the size of the specified axis.- Parameters:
axis
- the axis to set the width forwidth
- the width
-
updateCorner
protected void updateCorner(Axis axis)
Updates the dimensions of the corner panels.- Parameters:
axis
- the axis to update
-
updateCorners
public void updateCorners()
Updates all the corners
-
getAxisWidth
public int getAxisWidth(Axis axis)
Returns the size of the specified axis.- Parameters:
axis
- the axis to get the width for- Returns:
- the width
-
getActualAxisWidth
public int getActualAxisWidth(Axis axis)
Returns the actual size of the specified axis, depending on visibility.- Parameters:
axis
- the axis to get the width for- Returns:
- the actual width
-
getAxis
public AxisPanel getAxis(Axis axis)
Returns the specified axis.- Parameters:
axis
- the axis to return- Returns:
- the corresponding axis
-
setAxisVisibility
public void setAxisVisibility(Axis axis, Visibility visible)
Sets the visibility state of the specified axis.- Parameters:
axis
- the axis to hide/showvisible
- the state
-
getAxisVisibility
public Visibility getAxisVisibility(Axis axis)
Returns the visibility of the specified axis.- Parameters:
axis
- the axis to retrieve the visibility state for- Returns:
- the state
-
setZoomingEnabled
public void setZoomingEnabled(boolean value)
Sets whether zooming is enabled or not.- Parameters:
value
- if true then zooming is enabled
-
isZoomingEnabled
public boolean isZoomingEnabled()
Returns whether zooming is enabled.- Returns:
- true if zooming is enabled
-
isZoomed
public boolean isZoomed()
Returns true if any of the axis is zoomed.- Returns:
- true if the graph was zoomed
-
clearZoom
public void clearZoom()
Clears the zoom.
-
setPanningEnabled
public void setPanningEnabled(boolean value)
Sets whether panning is enabled or not.- Parameters:
value
- if true then panning is enabled
-
isPanningEnabled
public boolean isPanningEnabled()
Returns whether panning is enabled.- Returns:
- true if panning is enabled
-
isPanned
public boolean isPanned()
Returns true if any of the axis has a pixel offset != 0.- Returns:
- true if the graph was panned
-
clearPanning
public void clearPanning()
Clears the panning.
-
getContent
public ContentPanel getContent()
Returns the content panel.- Returns:
- the panel to draw on
-
addPaintListener
public void addPaintListener(PaintListener l)
Adds the given listener to the internal list of paint listeners.- Parameters:
l
- the listener to add
-
removePaintListener
public void removePaintListener(PaintListener l)
Removes the given listener from the internal list of paint listeners.- Parameters:
l
- the listener to remove
-
notifyPaintListeners
public void notifyPaintListeners(Graphics g, PaintEvent.PaintMoment moment)
Notifies all paint listeners.- Parameters:
g
- the graphics context of the paint updatemoment
- the paint moment, indicating which paintlets are to be executed
-
addMouseClickListener
public void addMouseClickListener(MouseListener l)
Adds the given listener to the internal list of mouse click listeners.- Parameters:
l
- the listener to add
-
removeMouseClickListener
public void removeMouseClickListener(MouseListener l)
Removes the given listener from the internal list of mouse click listeners.- Parameters:
l
- the listener to remove
-
notifyMouseClickListeners
public void notifyMouseClickListeners(MouseEvent e)
Notifies all mouse click listeners.- Parameters:
e
- the event
-
addZoomListener
public void addZoomListener(PlotPanelZoomListener l)
Adds the given listener to the internal list of zoom listeners.- Parameters:
l
- the listener to add
-
removeZoomListener
public void removeZoomListener(PlotPanelZoomListener l)
Removes the given listener from the internal list of zoom listeners.- Parameters:
l
- the listener to remove
-
addPanningListener
public void addPanningListener(PlotPanelPanningListener l)
Adds the given listener to the internal list of panning listeners.- Parameters:
l
- the listener to add
-
removePanningListener
public void removePanningListener(PlotPanelPanningListener l)
Removes the given listener from the internal list of panning listeners.- Parameters:
l
- the listener to remove
-
addMouseMovementTracker
public void addMouseMovementTracker(MouseMovementTracker l)
Adds the given listener to the internal list of mouse movement tracking listeners.- Parameters:
l
- the listener to add
-
removeMouseMovementTracker
public void removeMouseMovementTracker(MouseMovementTracker l)
Removes the given listener from the internal list of mouse movement tracking listeners.- Parameters:
l
- the listener to remove
-
clearToolTipAxes
public void clearToolTipAxes()
Removes display of tool tips for all axis.
-
addToolTipAxis
public void addToolTipAxis(Axis axis)
Adds the axis at the end of the vector with the axes making up the tooltip of values of the content panel. If the axis already existed, then it will be deleted first before added at the end.- Parameters:
axis
- the axis to add
-
removeToolTipAxis
public void removeToolTipAxis(Axis axis)
Removes the axis from the vector with the axes making up the tooltip of values of the content panel.- Parameters:
axis
- the axis to remove
-
hasToolTipAxis
public boolean hasToolTipAxis(Axis axis)
Checks whether the specified axis is used in making up the tooltip.- Parameters:
axis
- the axis to check- Returns:
- true if the axis is used in making up the toolip
-
setGridColor
public void setGridColor(Color value)
Sets the color to use for painting the coordinates grid.- Parameters:
value
- the color to use
-
getGridColor
public Color getGridColor()
Returns the color used for painting the coordinates grid.- Returns:
- the color in use
-
setPopupMenuCustomizer
public void setPopupMenuCustomizer(PopupMenuCustomizer value)
Sets the class to customize the right-click popup menu.- Parameters:
value
- the customizer
-
getPopupMenuCustomizer
public PopupMenuCustomizer getPopupMenuCustomizer()
Returns the current customizer, can be null.- Returns:
- the customizer
-
setAxisPopupMenuCustomizer
public void setAxisPopupMenuCustomizer(Axis axis, PopupMenuCustomizer value)
Sets the class to customize the right-click popup menu of an axis.- Parameters:
axis
- the axis to set the customizer forvalue
- the customizer
-
getAxisPopupMenuCustomizer
public PopupMenuCustomizer getAxisPopupMenuCustomizer(Axis axis)
Returns the current axis customizer, can be null.- Parameters:
axis
- the axis to get the customizer for- Returns:
- the customizer
-
setTipTextCustomizer
public void setTipTextCustomizer(TipTextCustomizer value)
Sets the class for customizing the tip text.- Parameters:
value
- the customizer
-
getTipTextCustomizer
public TipTextCustomizer getTipTextCustomizer()
Returns the current tip text customizer, can be null.- Returns:
- the customizer
-
clearHitDetectors
public void clearHitDetectors()
Removes all hit detectors.
-
addHitDetector
public void addHitDetector(HitDetector detector)
Adds the detector to the internal list of detectors.- Parameters:
detector
- the detector to add
-
removeHitDetector
public void removeHitDetector(HitDetector detector)
Removes the detector from the internal list of detectors.- Parameters:
detector
- the detector to remover
-
addZoom
public void addZoom(double top, double left, double bottom, double right)
Adds a zoom.- Parameters:
top
- the top valueleft
- the left valuebottom
- the bottom valueright
- the right value
-
addZoom
public void addZoom(int top, int left, int bottom, int right)
Adds a zoom.- Parameters:
top
- the top positionleft
- the left positionbottom
- the bottom positionright
- the right position
-
-