Package cnuphys.splot.plot
Class PlotCanvas
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
cnuphys.splot.plot.PlotCanvas
- All Implemented Interfaces:
DataChangeListener
,IRubberbanded
,IToolBarListener
,MouseListener
,MouseMotionListener
,ImageObserver
,MenuContainer
,Serializable
,EventListener
,TableModelListener
public class PlotCanvas
extends JComponent
implements MouseListener, MouseMotionListener, IRubberbanded, IToolBarListener, TableModelListener, DataChangeListener
- See Also:
-
Nested Class Summary
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
FieldsModifier and TypeFieldDescriptionprotected DataSet
protected AffineTransform
protected PlotParameters
protected AffineTransform
static final String
static final String
static final String
static final String
static final String
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
ConstructorsConstructorDescriptionPlotCanvas
(DataSet dataSet, String plotTitle, String xLabel, String yLabel) Create a plot canvas for plotting a dataset -
Method Summary
Modifier and TypeMethodDescriptionvoid
buttonPressed
(CommonToolBar toolbar, ToolBarButton button) void
dataSetChanged
(DataSet dataSet) A data set changedvoid
doButtonAction
(String command) void
This just signals that we are done rubber banding.Get the active plot areaGet the underlying datasetGet the canvas's color gradientGet the last updated location stringGet the plot parametersGet the canavas's plot ticksgetTitle()
Get the plot titlegetType()
Get the DataSet typegetWorld()
Get the world boundaryvoid
localToWorld
(Point pp, Point2D.Double wp) This converts a screen or pixel point to a world point.void
localToWorld
(Rectangle pr, Rectangle2D.Double wr) This converts a screen or pixel rectangle to a world rectangle.void
The mouse has been clicked on the plot canvasvoid
The mouse has been dragged over the plot canvasvoid
The mouse has entered the area of the plot canvasvoid
The mouse has exited the area of the plot canvasvoid
The mouse has moved over the plot canvasvoid
The mouse has been pressed on plot canvasvoid
The mouse has been released on plot canvas.void
needsRedraw
(boolean rescale) Data is being added, possibly very quickly, so lets schedule a redrawvoid
Paint the canvasvoid
print()
Printvoid
recenterAtClick
(Point pp) Center the plot world at the click.void
remoteFirePropertyChange
(String propName, Object oldValue, Object newValue) Used so another object can tell the plot canvas to fire a propert change eventvoid
scale
(double amount) Scale the canvas by a given amountprotected void
void
setDataSet
(DataSet ds) Set a new data set for the canvasvoid
Set the parent component, probably a PlotPanelvoid
Set which toggle button is selectedvoid
Set the world system based on the dataset This is where the plot limits are set.void
Show the data editorvoid
Show the plot preferences dialogvoid
void
Take a picture, sanve as pngvoid
toggleButtonActivated
(CommonToolBar toolbar, ToolBarToggleButton button) void
worldToLocal
(Point pp, Point2D.Double wp) This converts a world point to a screen or pixel point.void
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, getUI, getUIClassID, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setComponentPopupMenu, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFocusTraversalKeys, setFont, setForeground, setInheritsPopupMenu, setInputMap, setInputVerifier, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setTransferHandler, setUI, setVerifyInputWhenFocusTarget, setVisible, unregisterKeyboardAction, update, updateUI
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, getAccessibleContext, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, 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 Details
-
DONEDRAWINGPROP
- See Also:
-
TITLECHANGEPROP
- See Also:
-
XLABELCHANGEPROP
- See Also:
-
YLABELCHANGEPROP
- See Also:
-
DATACLEAREDPROP
- See Also:
-
_localToWorld
-
_worldToLocal
-
_dataSet
-
_parameters
-
-
Constructor Details
-
PlotCanvas
Create a plot canvas for plotting a dataset- Parameters:
dataSet
- the dataset to plot. It might contain many curvesplotTitle
- the plot titlexLabel
- the x axis labelyLabel
- the y axis label
-
-
Method Details
-
getType
Get the DataSet type- Returns:
- the data set type
-
getTitle
Get the plot title- Returns:
- the plot title
-
getParameters
Get the plot parameters- Returns:
- the plot parameters
-
setParent
Set the parent component, probably a PlotPanel- Parameters:
parent
- the optional parent component
-
setDataSet
Set a new data set for the canvas- Parameters:
ds
- the new dataset
-
getDataSet
Get the underlying dataset- Returns:
- the underlying dataset
-
getWorld
Get the world boundary- Returns:
- the world boundary
-
setWorldSystem
public void setWorldSystem()Set the world system based on the dataset This is where the plot limits are set. -
paintComponent
Paint the canvas- Overrides:
paintComponent
in classJComponent
- Parameters:
g
- the graphics context
-
needsRedraw
public void needsRedraw(boolean rescale) Data is being added, possibly very quickly, so lets schedule a redraw- Parameters:
rescale
- iftrue
the world system will also be rescaled
-
getActiveBounds
Get the active plot area- Returns:
- the active plot area
-
setAffineTransforms
protected void setAffineTransforms() -
mouseDragged
The mouse has been dragged over the plot canvas- Specified by:
mouseDragged
in interfaceMouseMotionListener
- Parameters:
e
- the mouseEvent
-
mouseMoved
The mouse has moved over the plot canvas- Specified by:
mouseMoved
in interfaceMouseMotionListener
- Parameters:
e
- the mouseEvent
-
getLocationString
Get the last updated location string- Returns:
-
mouseClicked
The mouse has been clicked on the plot canvas- Specified by:
mouseClicked
in interfaceMouseListener
- Parameters:
e
- the mouseEvent
-
mousePressed
The mouse has been pressed on plot canvas- Specified by:
mousePressed
in interfaceMouseListener
- Parameters:
e
- the mouseEvent
-
mouseReleased
The mouse has been released on plot canvas. A release comes before the click- Specified by:
mouseReleased
in interfaceMouseListener
- Parameters:
e
- the mouseEvent
-
mouseEntered
The mouse has entered the area of the plot canvas- Specified by:
mouseEntered
in interfaceMouseListener
- Parameters:
e
- the mouseEvent
-
mouseExited
The mouse has exited the area of the plot canvas- Specified by:
mouseExited
in interfaceMouseListener
- Parameters:
e
- the mouseEvent
-
localToWorld
This converts a screen or pixel point to a world point.- Parameters:
pp
- contains the local (screen-pixel) point.wp
- will hold the resultant world point.
-
localToWorld
This converts a screen or pixel rectangle to a world rectangle.- Parameters:
pr
- contains the local (screen-pixel) rectangle.wr
- will hold the resultant world rectangle.
-
worldToLocal
This converts a world point to a screen or pixel point.- Parameters:
pp
- will hold the resultant local (screen-pixel) point.wp
- contains world point.
-
worldToLocal
-
doneRubberbanding
public void doneRubberbanding()Description copied from interface:IRubberbanded
This just signals that we are done rubber banding.- Specified by:
doneRubberbanding
in interfaceIRubberbanded
-
recenterAtClick
Center the plot world at the click.- Parameters:
pp
-
-
scale
public void scale(double amount) Scale the canvas by a given amount- Parameters:
amount
- the factor to scale by
-
buttonPressed
- Specified by:
buttonPressed
in interfaceIToolBarListener
-
doButtonAction
-
print
public void print()Print -
getSavePngFile
-
takePicture
public void takePicture()Take a picture, sanve as png -
toggleButtonActivated
- Specified by:
toggleButtonActivated
in interfaceIToolBarListener
-
showPreferencesEditor
public void showPreferencesEditor()Show the plot preferences dialog -
showDataEditor
public void showDataEditor()Show the data editor -
remoteFirePropertyChange
Used so another object can tell the plot canvas to fire a propert change event- Parameters:
propName
-oldValue
-newValue
-
-
tableChanged
- Specified by:
tableChanged
in interfaceTableModelListener
-
getPlotTicks
Get the canavas's plot ticks- Returns:
- the plot ticks
-
getGradient
Get the canvas's color gradient- Returns:
- the color gradient
-
setSelectedToggle
Set which toggle button is selected -
dataSetChanged
Description copied from interface:DataChangeListener
A data set changed- Specified by:
dataSetChanged
in interfaceDataChangeListener
- Parameters:
dataSet
- the dataSet that changed
-