Class ContentPanel
- java.lang.Object
-
- java.awt.Component
-
- java.awt.Container
-
- javax.swing.JComponent
-
- javax.swing.JPanel
-
- adams.gui.core.BasePanel
-
- adams.gui.visualization.core.plot.ContentPanel
-
- All Implemented Interfaces:
ImageObserver
,MenuContainer
,Serializable
,EventListener
,Accessible
,ChangeListener
public class ContentPanel extends BasePanel implements ChangeListener
A specialized panel that can notify listeners of paint updates.- 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 int
m_BottomPixelOffset
the original pixel offset for the bottom axis.protected boolean
m_Dragged
whether dragging has happened at all.protected JComponentWriterFileChooser
m_FileChooser
the filechooser for saving the panel.protected DecimalFormat
m_Format
for outputting the values.protected HashSet<HitDetector>
m_HitDetectors
the hit detectors.protected int
m_LeftPixelOffset
the original pixel offset for the left axis.protected HashSet<MouseMovementTracker>
m_MouseMovementTrackers
the mouse movement trackers.protected PlotPanel
m_Owner
the owner of the panel.protected boolean
m_Panning
whether the graph is currently moved around.protected boolean
m_PanningEnabled
whether panning is enabled.protected HashSet<PlotPanelPanningListener>
m_PanningListeners
the panning listeners.protected Point
m_PanningStart
the starting mouse position of panning.protected PopupMenuCustomizer
m_PopupMenuCustomizer
an optional customizer for the right-click popup.protected int
m_RightPixelOffset
the original pixel offset for the right axis.protected ContentPanel
m_Self
the panel itself.protected TipTextCustomizer
m_TipTextCustomizer
for post-processing the tiptext.protected int
m_TopPixelOffset
the original pixel offset for the top axis.protected Point
m_ZoomBottomRight
the bottom right corner of the zoom box.protected Color
m_ZoomBoxColor
the color of the zoom box.protected boolean
m_Zooming
whether the zoom box is currently been drawn.protected boolean
m_ZoomingEnabled
whether zooming is enabled.protected HashSet<PlotPanelZoomListener>
m_ZoomListeners
the zoom listeners.protected Point
m_ZoomTopLeft
the top left corner of the zoom box.-
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
-
-
Constructor Summary
Constructors Constructor Description ContentPanel(PlotPanel owner)
Initializes the panel.
-
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
addMouseMovementTracker(MouseMovementTracker l)
Adds the given listener to the internal list of mouse movement tracking listeners.void
addPanningListener(PlotPanelPanningListener l)
Adds the given listener to the internal list of panning listeners.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.protected void
clearBackground(Graphics g)
Clears the background.void
clearHitDetectors()
Removes all hit detectors.void
clearPanning()
Clears the panning.void
clearZoom()
Clears the zoom.void
copyPlot()
Copies the plot to the clipboard.void
copyRanges()
Copies the ranges to the clipboard.protected void
detectHits(MouseEvent e)
Runs the mouseevent through all registered hit detectors.protected void
doPaint(Graphics g)
Performs the actual painting.protected void
editPaintlet(Paintlet paintlet)
Allows the user to edit the paintlet.protected JComponentWriterFileChooser
getFileChooser()
Returns the filechooser for saving the plot as image.PlotPanel
getOwner()
Returns the plot panel this panel belongs to.BasePopupMenu
getPopupMenu(MouseEvent e)
Returns the popup menu, potentially customized.PopupMenuCustomizer
getPopupMenuCustomizer()
Returns the current customizer, can be null.TipTextCustomizer
getTipTextCustomizer()
Returns the current tip text customizer, can be null.String
getToolTipText(MouseEvent event)
Returns the values as tooltip.Color
getZoomBoxColor()
Returns the color for the zoom box currently in use.protected void
initGUI()
Initializes the widgets.protected void
initialize()
Initializes the members.boolean
isPanningEnabled()
Returns whether panning is enabled.boolean
isZoomingEnabled()
Returns whether zooming is enabled.void
notifyMouseMovementTrackers(MouseEvent e)
Notifies all mouse movement tracking listeners.void
notifyPanningListeners(PlotPanelPanningEvent.PanningEventType type)
Notifies all panning listeners.void
notifyZoomListeners(PlotPanelZoomEvent.ZoomEventType type)
Notifies all zoom listeners.protected double[]
order(double value1, double value2)
swaps points if necessary, s.t., first is the smaller one.protected int[]
order(int value1, int value2)
swaps points if necessary, s.t., first is the smaller one.void
paintComponent(Graphics g)
paints the panel and notifies all listeners.protected void
paintCoordinatesGrid(Graphics g)
Paints the coordinates grid according to the ticks of the axes.protected void
paintZoomBox(Graphics g)
Paints the zoom box, if necessary (i.e., currently zooming/dragging).void
pasteRanges()
Pastes the ranges from the clipboard.void
popZoom()
Pops the current zoom.void
printComponent(Graphics g)
prints the panel and notifies all listeners.void
removeHitDetector(HitDetector detector)
Removes the detector from the internal list of detectors.void
removeMouseMovementTracker(MouseMovementTracker l)
Removes the given listener from the internal list of mouse movement tracking listeners.void
removePanningListener(PlotPanelPanningListener l)
Removes the given listener from the internal list of panning listeners.void
removeZoomListener(PlotPanelZoomListener l)
Removes the given listener from the internal list of zoom listeners.void
savePlot()
Displays a save dialog for saving the plot to a file.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
setZoomBoxColor(Color value)
Sets the color for the zoom box.void
setZoomingEnabled(boolean value)
Sets whether zooming is enabled or not.void
stateChanged(ChangeEvent e)
In case an axis changes its type, e.g., log instead of percentage.-
Methods inherited from class adams.gui.core.BasePanel
afterHide, afterShow, beforeHide, beforeShow, closeParent, finishInit, getParentChild, getParentDialog, getParentFrame, getParentInternalFrame, getParentTitle, initFileChooser, main, printErrorMessage, printException, saveComponent, setEnabledCascade, setEnabledCascade, setParentTitle, setVisible
-
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, 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, 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, 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, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
-
-
-
Field Detail
-
m_Owner
protected PlotPanel m_Owner
the owner of the panel.
-
m_Self
protected ContentPanel m_Self
the panel itself.
-
m_Format
protected DecimalFormat m_Format
for outputting the values.
-
m_ZoomingEnabled
protected boolean m_ZoomingEnabled
whether zooming is enabled.
-
m_ZoomBoxColor
protected Color m_ZoomBoxColor
the color of the zoom box.
-
m_Zooming
protected boolean m_Zooming
whether the zoom box is currently been drawn.
-
m_Dragged
protected boolean m_Dragged
whether dragging has happened at all.
-
m_ZoomTopLeft
protected Point m_ZoomTopLeft
the top left corner of the zoom box.
-
m_ZoomBottomRight
protected Point m_ZoomBottomRight
the bottom right corner of the zoom box.
-
m_PopupMenuCustomizer
protected PopupMenuCustomizer m_PopupMenuCustomizer
an optional customizer for the right-click popup.
-
m_PanningEnabled
protected boolean m_PanningEnabled
whether panning is enabled.
-
m_Panning
protected boolean m_Panning
whether the graph is currently moved around.
-
m_PanningStart
protected Point m_PanningStart
the starting mouse position of panning.
-
m_LeftPixelOffset
protected int m_LeftPixelOffset
the original pixel offset for the left axis.
-
m_RightPixelOffset
protected int m_RightPixelOffset
the original pixel offset for the right axis.
-
m_TopPixelOffset
protected int m_TopPixelOffset
the original pixel offset for the top axis.
-
m_BottomPixelOffset
protected int m_BottomPixelOffset
the original pixel offset for the bottom axis.
-
m_TipTextCustomizer
protected TipTextCustomizer m_TipTextCustomizer
for post-processing the tiptext.
-
m_HitDetectors
protected HashSet<HitDetector> m_HitDetectors
the hit detectors.
-
m_ZoomListeners
protected HashSet<PlotPanelZoomListener> m_ZoomListeners
the zoom listeners.
-
m_PanningListeners
protected HashSet<PlotPanelPanningListener> m_PanningListeners
the panning listeners.
-
m_MouseMovementTrackers
protected HashSet<MouseMovementTracker> m_MouseMovementTrackers
the mouse movement trackers.
-
m_FileChooser
protected JComponentWriterFileChooser m_FileChooser
the filechooser for saving the panel.
-
-
Constructor Detail
-
ContentPanel
public ContentPanel(PlotPanel owner)
Initializes the panel.- Parameters:
owner
- the plot panel this panel belongs to
-
-
Method Detail
-
initialize
protected void initialize()
Initializes the members.- Overrides:
initialize
in classBasePanel
-
getOwner
public PlotPanel getOwner()
Returns the plot panel this panel belongs to.- Returns:
- the owning panel
-
getFileChooser
protected JComponentWriterFileChooser getFileChooser()
Returns the filechooser for saving the plot as image.
-
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
-
popZoom
public void popZoom()
Pops the current zoom.
-
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
-
clearPanning
public void clearPanning()
Clears the panning.
-
order
protected int[] order(int value1, int value2)
swaps points if necessary, s.t., first is the smaller one.- Parameters:
value1
- the first valuevalue2
- the second value- Returns:
- the ordered values
-
order
protected double[] order(double value1, double value2)
swaps points if necessary, s.t., first is the smaller one.- Parameters:
value1
- the first valuevalue2
- the second value- Returns:
- the ordered values
-
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
-
setZoomBoxColor
public void setZoomBoxColor(Color value)
Sets the color for the zoom box.- Parameters:
value
- the color to use
-
getZoomBoxColor
public Color getZoomBoxColor()
Returns the color for the zoom box currently in use.- 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
-
getPopupMenu
public BasePopupMenu getPopupMenu(MouseEvent e)
Returns the popup menu, potentially customized.- Parameters:
e
- the mouse event- Returns:
- the popup menu
- See Also:
m_PopupMenuCustomizer
-
clearBackground
protected void clearBackground(Graphics g)
Clears the background.- Parameters:
g
- the graphics context
-
paintCoordinatesGrid
protected void paintCoordinatesGrid(Graphics g)
Paints the coordinates grid according to the ticks of the axes.- Parameters:
g
- the graphics context
-
paintZoomBox
protected void paintZoomBox(Graphics g)
Paints the zoom box, if necessary (i.e., currently zooming/dragging).- Parameters:
g
- the graphics context
-
doPaint
protected void doPaint(Graphics g)
Performs the actual painting.- Parameters:
g
- the graphics context
-
paintComponent
public void paintComponent(Graphics g)
paints the panel and notifies all listeners.- Overrides:
paintComponent
in classJComponent
- Parameters:
g
- the graphics context
-
printComponent
public void printComponent(Graphics g)
prints the panel and notifies all listeners.- Overrides:
printComponent
in classJComponent
- Parameters:
g
- the graphics context
-
editPaintlet
protected void editPaintlet(Paintlet paintlet)
Allows the user to edit the paintlet. Only updates the options.- Parameters:
paintlet
- the paintlet to edit
-
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
-
getToolTipText
public String getToolTipText(MouseEvent event)
Returns the values as tooltip.- Overrides:
getToolTipText
in classJComponent
- Parameters:
event
- the event that triggered this method- Returns:
- the tool tip
-
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
-
detectHits
protected void detectHits(MouseEvent e)
Runs the mouseevent through all registered hit detectors.- Parameters:
e
- the mouse event for the detectors to analyze
-
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
-
notifyZoomListeners
public void notifyZoomListeners(PlotPanelZoomEvent.ZoomEventType type)
Notifies all zoom listeners.- Parameters:
type
- the event type
-
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
-
notifyPanningListeners
public void notifyPanningListeners(PlotPanelPanningEvent.PanningEventType type)
Notifies all panning listeners.- Parameters:
type
- the event type
-
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
-
notifyMouseMovementTrackers
public void notifyMouseMovementTrackers(MouseEvent e)
Notifies all mouse movement tracking listeners.- Parameters:
e
- the mouse event
-
stateChanged
public void stateChanged(ChangeEvent e)
In case an axis changes its type, e.g., log instead of percentage.- Specified by:
stateChanged
in interfaceChangeListener
- Parameters:
e
- the event
-
copyRanges
public void copyRanges()
Copies the ranges to the clipboard.
-
pasteRanges
public void pasteRanges()
Pastes the ranges from the clipboard.
-
copyPlot
public void copyPlot()
Copies the plot to the clipboard.
-
savePlot
public void savePlot()
Displays a save dialog for saving the plot to a file.
-
-