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.AccessibleJComponentNested classes/interfaces inherited from class java.awt.Container
Container.AccessibleAWTContainerNested classes/interfaces inherited from class java.awt.Component
Component.AccessibleAWTComponent, Component.BaselineResizeBehavior, Component.BltBufferStrategy, Component.FlipBufferStrategy -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected DataSetprotected AffineTransformprotected PlotParametersprotected AffineTransformstatic final Stringstatic final Stringstatic final Stringstatic final Stringstatic final StringFields inherited from class javax.swing.JComponent
listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOWFields inherited from class java.awt.Component
accessibleContext, BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENTFields 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 TypeMethodDescriptionvoidbuttonPressed(CommonToolBar toolbar, ToolBarButton button) voiddataSetChanged(DataSet dataSet) A data set changedvoiddoButtonAction(String command) voidThis 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 boundaryvoidlocalToWorld(Point pp, Point2D.Double wp) This converts a screen or pixel point to a world point.voidlocalToWorld(Rectangle pr, Rectangle2D.Double wr) This converts a screen or pixel rectangle to a world rectangle.voidThe mouse has been clicked on the plot canvasvoidThe mouse has been dragged over the plot canvasvoidThe mouse has entered the area of the plot canvasvoidThe mouse has exited the area of the plot canvasvoidThe mouse has moved over the plot canvasvoidThe mouse has been pressed on plot canvasvoidThe mouse has been released on plot canvas.voidneedsRedraw(boolean rescale) Data is being added, possibly very quickly, so lets schedule a redrawvoidPaint the canvasvoidprint()PrintvoidrecenterAtClick(Point pp) Center the plot world at the click.voidremoteFirePropertyChange(String propName, Object oldValue, Object newValue) Used so another object can tell the plot canvas to fire a propert change eventvoidscale(double amount) Scale the canvas by a given amountprotected voidvoidsetDataSet(DataSet ds) Set a new data set for the canvasvoidSet the parent component, probably a PlotPanelvoidSet which toggle button is selectedvoidSet the world system based on the dataset This is where the plot limits are set.voidShow the data editorvoidShow the plot preferences dialogvoidvoidTake a picture, sanve as pngvoidtoggleButtonActivated(CommonToolBar toolbar, ToolBarToggleButton button) voidworldToLocal(Point pp, Point2D.Double wp) This converts a world point to a screen or pixel point.voidMethods 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, updateUIMethods 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, validateTreeMethods 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:
paintComponentin 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- iftruethe 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:
mouseDraggedin interfaceMouseMotionListener- Parameters:
e- the mouseEvent
-
mouseMoved
The mouse has moved over the plot canvas- Specified by:
mouseMovedin 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:
mouseClickedin interfaceMouseListener- Parameters:
e- the mouseEvent
-
mousePressed
The mouse has been pressed on plot canvas- Specified by:
mousePressedin interfaceMouseListener- Parameters:
e- the mouseEvent
-
mouseReleased
The mouse has been released on plot canvas. A release comes before the click- Specified by:
mouseReleasedin interfaceMouseListener- Parameters:
e- the mouseEvent
-
mouseEntered
The mouse has entered the area of the plot canvas- Specified by:
mouseEnteredin interfaceMouseListener- Parameters:
e- the mouseEvent
-
mouseExited
The mouse has exited the area of the plot canvas- Specified by:
mouseExitedin 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:IRubberbandedThis just signals that we are done rubber banding.- Specified by:
doneRubberbandingin 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:
buttonPressedin interfaceIToolBarListener
-
doButtonAction
-
print
public void print()Print -
getSavePngFile
-
takePicture
public void takePicture()Take a picture, sanve as png -
toggleButtonActivated
- Specified by:
toggleButtonActivatedin 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:
tableChangedin 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:DataChangeListenerA data set changed- Specified by:
dataSetChangedin interfaceDataChangeListener- Parameters:
dataSet- the dataSet that changed
-