Package org.opensourcephysics.display
Class DrawingPanel
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.opensourcephysics.display.DrawingPanel
- All Implemented Interfaces:
ActionListener,ImageObserver,MenuContainer,Serializable,EventListener,Accessible,OSPRuntime.Disposable,Renderable
- Direct Known Subclasses:
InteractivePanel,TTrack.TextLineLabel
public class DrawingPanel
extends JPanel
implements OSPRuntime.Disposable, ActionListener, Renderable
DrawingPanel renders drawable objects on its canvas. DrawingPanel provides
drawable objects with methods that transform from world coordinates to pixel
coordinates. World coordinates are defined by xmin, xmax, ymin, and ymax.
These values are recalculated on-the-fly from preferred values if the aspect
ratio is unity; otherwise, preferred values are used.
If xmax>xmin then the coordinate scale increases from right to left. If
xmax<xmin then the coordinate scale increases from left to right. If
ymax>ymin then the coordinate scale increases from bottom to top. If
ymax<ymin then the coordinate scale increases from top to bottom.
- Version:
- 1.0
- Author:
- Wolfgang Christian, Joshua Gould
- See Also:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionclassclassZoomBox creates an on-screen rectangle using XORMode for fast redrawing.Nested classes/interfaces inherited from class javax.swing.JPanel
JPanel.AccessibleJPanelNested 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 booleanprotected booleanprotected booleanprotected JMenuItemthe menu items for the boxprotected doubleprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected booleanprotected Colorstatic final intDeprecated.static final intDeprecated.protected intprotected intprotected booleanprotected CoordinateStringBuilderprotected longprotected Windowprotected DecimalFormatprotected Dimensionedbooleanprotected doubleprotected doubleprotected doubleprotected doubleprotected booleanprotected booleanprotected booleanprotected PropertyChangeListenerprotected doubleprotected booleanbooleanprotected intprotected intprotected intprotected intprotected booleanprotected booleanprotected MessageDrawablestatic final booleanprotected MouseInputAdapterprotected BufferedImageprotected MouseInputAdapterprotected booleanprotected double[]protected AffineTransformprotected JPopupMenuprotected JMenuItemthe menu items for the boxprotected static booleanprotected intprotected Timerprotected intprotected intprotected JMenuItemthe menu items for the boxprotected DecimalFormatprotected booleanprotected JMenuItemthe menu items for the boxprotected booleanstatic final intDeprecated.static final intDeprecated.protected intprotected intprotected VideoToolprotected Rectangleprotected BufferedImageprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected doubleprotected DrawingPanel.ZoomBoxprotected intprotected intprotected JMenuItemthe menu items for the boxprotected JMenuItemthe menu items for the boxprotected TimerFields 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, WIDTHFields inherited from interface org.opensourcephysics.display.OSPRuntime.Disposable
allocated -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidPerforms the action for the refresh timer by rendering (redrawing) the panel.voidaddDrawable(Drawable drawable) Adds a drawable object to the drawable list.voidaddDrawableAtIndex(int index, Drawable drawable) Adds a drawable object to the drawable list at the given index.voidaddDrawables(Collection<Drawable> drawables) Adds a collection of drawable objects to the drawable list.voidvoidRemoves the option controller.protected voidBuilds the default popup menu for this panel.protected booleanChecks the image to see if the working image has the correct Dimension.voidclear()Removes all drawable objects from the drawable list.protected voidComputes the size of the gutters.voidvoiddispose()voidenableInspector(boolean isEnabled) Enables the popup inspector option.Finds the clipping rectangle if this panel is within a scroll pane viewport.protected voidfirePropertyChange(String propertyName, Object oldValue, Object newValue) doubleGets the ratio of pixels per unit in the x and y directions.intGets the bottom gutter of this DrawingPanel.Gets the CoordinateStringBuilder that converts mouse events into a string showing world coordinates.Gets the object that sets the gutters for this panel.Gets the cloned list of Drawable objects.getDrawables(Class<T> type) Gets Drawable objects of an assignable type.getDrawables(Class<T> type, boolean allowSubtypes, Drawable except, ArrayList<T> ret) getDrawablesExcept(Class<?> type) getDrawablesExcept(Class<T> type, Drawable except) <T extends Drawable>
TgetFirstDrawable(Class<T> type) int[]Gets the gutters.intdoubleGets the ratio of the drawing image to the panel.intGets the left gutter of this DrawingPanel.static XML.ObjectLoaderReturns an XML.ObjectLoader to save and load object data.doubleGets the larger of x or y pixels per world unit.Gets the rectangle that bounds all measurable objects.getObjectOfClass(Class<T> type) Gets objects of a specific class from the drawables list.double[]Retrieves the 6 specifiable values in the pixel transformation matrix and places them into an array of double precisions values.Gets the affine transformation that converts from world to pixel coordinates.Gets the popup menu.doubleGets the preferred x world coordinate for the right-hand side of the drawing area.doubleGets the preferred x world coordinate for the left-hand side of the drawing area.doubleGets the preferred y world coordinate for the top of the drawing area.doubleGets the preferred y world coordinate for the bottom of the drawing area.intGets the right gutter of this DrawingPanel.getScale()Gets the scale that will be used when the panel is drawn.protected JMenuItemgetSnapshotItem(ActionListener listener) intGets the bottom gutter of this DrawingPanel.Gets the video capture tool.protected RectangleGets the clipping rectangle within a scroll pane viewport.intgetWidth()doublegetXMax()Gets the x world coordinate for the right-hand side of the drawing area.doublegetXMin()Gets the x world coordinate for the left-hand side of the drawing area.doubleGets the number of pixels per world unit in the x direction.doublegetYMax()Gets the y world coordinate for the top of the drawing area.doublegetYMin()Gets the y world coordinate for the bottom of the drawing area.doubleGets the number of pixels per world unit in the y direction.Returns the internal ZoomBox objectbooleanDetermines if the user can examine and change the scale at run-time by right-clicking.voidHides the drawing panel properties inspector.voidInvalidate the offscreen image so that it is rendered during the next repaint operation if buffering is enabled.booleanGets the adjustableGutter flag.booleanGets flag for shape antialiasing.booleanGets flag for text antialiasing.booleanDetermines if the x axis autoscale property is true.booleanDetermines if the horizontal maximum value is autoscaled.booleanDetermines if the horizontal minimum value is autoscaled.booleanDetermines if the y axis autoscale property is true.booleanDetermines if the vertical maximum value is autoscaled.booleanDetermines if the vertical minimum value is autoscaled.booleanbooleanGets the clip at gutter flag.booleanDetermines if the scale is fixed.booleanGets the iconified flag from the top level frame.booleanGets the logScaleX value.booleanGets the logScaleY value.booleanisPointInside(double x, double y) Determines if the x and y point is inside.booleanReturns true if mouse coordinates are displayedbooleanDetermines if the number of pixels per unit is the same for both x and y.protected booleanbooleanisZoom()Determines if the user can change scale by dragging the mouse.booleanReturns true if an event starts or ends a zoom operation.voidlimitAutoscaleX(double floor, double ceil) Limits the xmin and xmax values during autoscaling so that the mininimum value will be no greater than the floor and the maximum value will be no smaller than the ceil.voidlimitAutoscaleY(double floor, double ceil) Limits ymin and ymax values during autoscaling so that the mininimum value will be no greater than the floor and the maximum value will be no smaller than the ceil.voidmeasure()Sets the scale based on the max and min values of all measurable objects.voidvoidPaints this component.protected voidpaintDrawableList(Graphics g, ArrayList<Drawable> tempList) Paints all the drawable objects in the panel.protected voidPaints everything inside this component.protected voidPaints before the panel iterates through its list of Drawables.protected voidPaints after the panel iterates through its list of Drawables.doublepixToX(int pix) Converts pixel to x world units.doublepixToY(int pix) Converts pixel to x world units.double[]project(double[] coordinate, double[] pixel) Projects a 2D or 3D world coordinate to a pixel coordinate.voidreceiveToolReply(Job job) voidRecomputes the pixel transforamtion based on the current minimum and maximum values and the gutters.protected voidRefreshes the decimal separators.protected voidRefreshes the user interface in response to display changes such as Language.voidremoveDrawable(Drawable drawable) Removes a drawable object from the drawable list.<T extends Drawable>
voidremoveDrawables(Class<T> c) Removes all objects assignable to the given class from the drawable list.<T extends Drawable>
voidremoveObjectsOfClass(Class<T> c) Removes all objects of the given class from the drawable list.voidRemoves the option controller.render()Paints all drawables onto an offscreen image buffer and copies this image onto the screen.render(BufferedImage image) Paints all drawables onto an image.voidrepaint()voidrepaint(int x, int y, int w, int h) voidvoidvoidreplaceDrawable(Drawable oldDrawable, Drawable newDrawable) Replaces a drawable object with another drawable.voidResets the gutters to their preferred values.voidscale()Sets axis scales if autoscale is true using the max and min values of the measurable objects.protected voidSets axis scales if autoscale is true using the max and min values of the objects in the given list.protected voidscaleX()Sets the x axis scale based on the max and min values of all measurable objects.protected voidSets the x axis scale based on the max and/or min values of all measurable objects.protected voidscaleY()Sets the y axis scale based on the max and min values of all measurable objects.protected voidSets the y axis scale based on the max and min values of all measurable objects.voidsetAdjustableGutter(boolean adjustable) Sets adjustable gutters.voidsetAntialiasShapeOn(boolean on) Set flag for shape antialiasing.voidsetAntialiasTextOn(boolean on) Set flag for text antialiasing.voidsetAutoscaleMargin(double _autoscaleMargin) Sets the size of the margin during an autoscale operation.voidsetAutoscaleX(boolean autoscale) Autoscale the x axis using min and max values.voidsetAutoscaleY(boolean autoscale) Autoscale the y axis using min and max values.voidsetBounds(int x, int y, int width, int height) Moves and resizes this component.voidvoidsetBuffered(boolean _buffered) Sets the buffered image option.voidsetClipAtGutter(boolean clip) Sets the panel to exclude the gutter from the drawing.voidSets the CoordinateStringBuilder that converts mouse events into a string showing world coordinates.voidSets a custom properties inspector window.voidsetFixedScale(boolean fixed) Sets the fixed scale property.voidsetFontFactor(double factor) Sets the font factor.protected voidsetFontLevel(int level) Sets the font level.voidsetGutters(int[] gutters) Sets the gutters using the given array.voidsetGutters(int left, int top, int right, int bottom) Sets gutters around the drawing area.voidsetMessage(String msg) Shows a message in a yellow text box in the lower right hand corner.booleansetMessage(String msg, int location) Shows a message in a yellow text box.voidsetMouseCursor(Cursor cursor) Sets the mouse cursor.protected voidvoidsetPaintDrawables(boolean b) A method to allow bypassing of paintEverything()voidCalculates min and max values and the affine transformation based on the current size of the panel and the squareAspect boolean.voidsetPixelsPerUnit(boolean enable, double xPixPerUnit, double yPixPerUnit) Sets the scale using pixels per unit.voidsetPopupMenu(JPopupMenu menu) Sets the popup menu.voidsetPreferredGutters(int left, int top, int right, int bottom) Sets preferred gutters around the drawing area.voidsetPreferredMinMax(double xmin, double xmax, double ymin, double ymax) Sets the preferred scale in the vertical and horizontal direction.voidsetPreferredMinMax(double xmin, double xmax, double ymin, double ymax, boolean invalidateImage) Sets the preferred scale in the vertical and horizontal direction.voidsetPreferredMinMaxX(double xmin, double xmax) Sets the preferred scale in the horizontal direction.voidsetPreferredMinMaxY(double ymin, double ymax) Sets the preferred scale in the vertical direction.voidsetShowCoordinates(boolean show) Show the coordinates in the text box in the lower left hand corner.voidsetSquareAspect(boolean val) Sets the aspect ratio for horizontal to vertical to unity whentrue<\code>.voidsetVideoTool(VideoTool videoCap) Sets the video tool.voidsetVisible(boolean vis) Makes the component visible or invisible.voidsetXLeftMarginPercentage(double _percentage) Sets the extra percentage on the X left margin during an autoscale operation.voidsetXMarginPercentage(double _percentage) Sets the extra percentage on the X left and right margins during an autoscale operation.voidsetXMarginPercentage(double _leftPercentage, double _rightPercentage) Sets the extra percentage on the X left and right margins during an autoscale operation.voidsetXRightMarginPercentage(double _percentage) Sets the extra percentage on the X left margin during an autoscale operation.voidsetYBottomMarginPercentage(double _percentage) Sets the extra percentage on the X left margin during an autoscale operation.voidsetYMarginPercentage(double _percentage) Sets the extra percentage on the Y top and bottom margin during an autoscale operation.voidsetYMarginPercentage(double _bottomPercentage, double _topPercentage) Sets the extra percentage on the Y top and bottom margin during an autoscale operation.voidsetYTopMarginPercentage(double _percentage) Sets the extra percentage on the Y top margin during an autoscale operation.voidsetZoom(boolean _enableZoom) Sets the zoom option to allow the user to change scale by dragging the mouse.voidShows the drawing panel properties inspector.voidsnapshot()Creates a snapshot using an image of the content.voidValidate the offscreen image to insure that the render method will execute.floatxToGraphics(double x) Converts x from world to graphics device units.intxToPix(double x) Converts x from world to pixel units.floatyToGraphics(double y) Converts y from world to graphics device units.intyToPix(double y) Converts y from world to pixel units.protected voidzoomIn()Zooms in to the current zoom box.protected voidzoomOut()Zooms out by a factor of two.Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUIMethods 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, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, 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, unregisterKeyboardAction, updateMethods 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, 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, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycle
-
Field Details
-
messagesAsJLabels
public static final boolean messagesAsJLabels- See Also:
-
RECORD_PAINT_TIMES
protected static boolean RECORD_PAINT_TIMES -
currentTime
protected long currentTime -
BOTTOM_LEFT
Deprecated.- See Also:
-
BOTTOM_RIGHT
Deprecated.- See Also:
-
TOP_RIGHT
Deprecated.- See Also:
-
TOP_LEFT
Deprecated.- See Also:
-
isInteractive
public boolean isInteractive -
isDisposed
protected boolean isDisposed -
propertiesItem
the menu items for the box -
autoscaleItem
the menu items for the box -
scaleItem
the menu items for the box -
zoomInItem
the menu items for the box -
zoomOutItem
the menu items for the box -
snapshotItem
the menu items for the box -
leftGutter
protected int leftGutter -
topGutter
protected int topGutter -
rightGutter
protected int rightGutter -
bottomGutter
protected int bottomGutter -
leftGutterPreferred
protected int leftGutterPreferred -
topGutterPreferred
protected int topGutterPreferred -
rightGutterPreferred
protected int rightGutterPreferred -
bottomGutterPreferred
protected int bottomGutterPreferred -
clipAtGutter
protected boolean clipAtGutter -
adjustableGutter
protected boolean adjustableGutter -
lastWidth
protected int lastWidth -
lastHeight
protected int lastHeight -
bgColor
-
antialiasTextOn
protected boolean antialiasTextOn -
antialiasShapeOn
protected boolean antialiasShapeOn -
squareAspect
protected boolean squareAspect -
autoscaleX
protected boolean autoscaleX -
autoscaleY
protected boolean autoscaleY -
autoscaleXMin
protected boolean autoscaleXMin -
autoscaleXMax
protected boolean autoscaleXMax -
autoscaleYMin
protected boolean autoscaleYMin -
autoscaleYMax
protected boolean autoscaleYMax -
autoscaleMargin
protected double autoscaleMargin -
xminPreferred
protected double xminPreferred -
xmaxPreferred
protected double xmaxPreferred -
yminPreferred
protected double yminPreferred -
ymaxPreferred
protected double ymaxPreferred -
xfloor
protected double xfloor -
xceil
protected double xceil -
yfloor
protected double yfloor -
yceil
protected double yceil -
xmin
protected double xmin -
xmax
protected double xmax -
ymin
protected double ymin -
ymax
protected double ymax -
fixedPixelPerUnit
protected boolean fixedPixelPerUnit -
xPixPerUnit
protected double xPixPerUnit -
yPixPerUnit
protected double yPixPerUnit -
pixelTransform
-
pixelMatrix
protected double[] pixelMatrix -
drawableList
-
offscreenImage
-
workingImage
-
messages
-
scientificFormat
-
decimalFormat
-
mouseController
-
showCoordinates
protected boolean showCoordinates -
optionController
-
zoomBox
-
enableZoom
protected boolean enableZoom -
fixedScale
protected boolean fixedScale -
customInspector
-
dimensionSetter
-
viewRect
-
coordinateStrBuilder
-
refreshDelay
protected int refreshDelay -
refreshTimer
-
vidCap
-
imageRatio
protected double imageRatio -
xLeftMarginPercentage
protected double xLeftMarginPercentage -
xRightMarginPercentage
protected double xRightMarginPercentage -
yTopMarginPercentage
protected double yTopMarginPercentage -
yBottomMarginPercentage
protected double yBottomMarginPercentage -
logScaleX
protected boolean logScaleX -
logScaleY
protected boolean logScaleY -
zoomDelay
protected int zoomDelay -
zoomCount
protected int zoomCount -
zoomTimer
-
dxmin
protected double dxmin -
dxmax
protected double dxmax -
dymin
protected double dymin -
dymax
protected double dymax -
guiChangeListener
-
paintDrawables
protected boolean paintDrawables -
displayCoordsOnMouseMoved
public boolean displayCoordsOnMouseMoved
-
-
Constructor Details
-
DrawingPanel
public DrawingPanel()DrawingPanel constructor.
-
-
Method Details
-
getGlassPane
-
dispose
public void dispose()- Specified by:
disposein interfaceOSPRuntime.Disposable
-
setMouseListeners
protected void setMouseListeners() -
addMessageLabel
-
setFontLevel
protected void setFontLevel(int level) Sets the font level.- Parameters:
level- the level
-
setFontFactor
public void setFontFactor(double factor) Sets the font factor.- Parameters:
factor- the factor
-
refreshGUI
protected void refreshGUI()Refreshes the user interface in response to display changes such as Language. -
refreshDecimalSeparators
protected void refreshDecimalSeparators()Refreshes the decimal separators. -
buildPopupMenu
protected void buildPopupMenu()Builds the default popup menu for this panel. -
getSnapshotItem
-
setAutoscaleMargin
public void setAutoscaleMargin(double _autoscaleMargin) Sets the size of the margin during an autoscale operation.- Parameters:
_autoscaleMargin-
-
setXMarginPercentage
public void setXMarginPercentage(double _percentage) Sets the extra percentage on the X left and right margins during an autoscale operation.- Parameters:
_percentage-
-
setXMarginPercentage
public void setXMarginPercentage(double _leftPercentage, double _rightPercentage) Sets the extra percentage on the X left and right margins during an autoscale operation.- Parameters:
_percentage-
-
setXLeftMarginPercentage
public void setXLeftMarginPercentage(double _percentage) Sets the extra percentage on the X left margin during an autoscale operation.- Parameters:
_percentage-
-
setXRightMarginPercentage
public void setXRightMarginPercentage(double _percentage) Sets the extra percentage on the X left margin during an autoscale operation.- Parameters:
_percentage-
-
setYMarginPercentage
public void setYMarginPercentage(double _percentage) Sets the extra percentage on the Y top and bottom margin during an autoscale operation.- Parameters:
_percentage-
-
setYMarginPercentage
public void setYMarginPercentage(double _bottomPercentage, double _topPercentage) Sets the extra percentage on the Y top and bottom margin during an autoscale operation.- Parameters:
_percentage-
-
setYTopMarginPercentage
public void setYTopMarginPercentage(double _percentage) Sets the extra percentage on the Y top margin during an autoscale operation.- Parameters:
_percentage-
-
setYBottomMarginPercentage
public void setYBottomMarginPercentage(double _percentage) Sets the extra percentage on the X left margin during an autoscale operation.- Parameters:
_percentage-
-
setClipAtGutter
public void setClipAtGutter(boolean clip) Sets the panel to exclude the gutter from the drawing.- Parameters:
clip-true<\code> to clip;false<\code> otherwise
-
isClipAtGutter
public boolean isClipAtGutter()Gets the clip at gutter flag.- Returns:
true<\code> if drawing is clipped at the gutter;false<\code> otherwise
-
setAdjustableGutter
public void setAdjustableGutter(boolean adjustable) Sets adjustable gutters. Axes are allowed to adjust the gutter size.- Parameters:
fixed-true<\code> if gutters remain constant
-
isAdjustableGutter
public boolean isAdjustableGutter()Gets the adjustableGutter flag. Adjustable gutters change as the panel is resized.- Returns:
true<\code> if gutters are adjustable
-
setMouseCursor
Sets the mouse cursor.- Parameters:
cursor-
-
checkWorkingImage
protected boolean checkWorkingImage()Checks the image to see if the working image has the correct Dimension. Checking is done in the event dispatch thread.- Returns:
true <\code> if the offscreen image matches the panel;false <\code> otherwise
-
actionPerformed
Performs the action for the refresh timer by rendering (redrawing) the panel.- Specified by:
actionPerformedin interfaceActionListener- Parameters:
evt-
-
isIconified
public boolean isIconified()Gets the iconified flag from the top level frame.- Returns:
- boolean true if frame is iconified; false otherwise
-
render
Paints all drawables onto an offscreen image buffer and copies this image onto the screen.- Specified by:
renderin interfaceRenderable- Returns:
- the image buffer
-
render
Paints all drawables onto an image.- Specified by:
renderin interfaceRenderable- Parameters:
image-- Returns:
- the image buffer
-
getWidth
public int getWidth()- Overrides:
getWidthin classJComponent
-
getHeight
public int getHeight()- Overrides:
getHeightin classJComponent
-
getImageRatio
public double getImageRatio()Gets the ratio of the drawing image to the panel.- Returns:
- double
-
invalidateImage
public void invalidateImage()Invalidate the offscreen image so that it is rendered during the next repaint operation if buffering is enabled. -
validateImage
public void validateImage()Validate the offscreen image to insure that the render method will execute. -
isValidImage
protected boolean isValidImage() -
paint
- Overrides:
paintin classJComponent
-
setPaintDrawables
public void setPaintDrawables(boolean b) A method to allow bypassing of paintEverything()- Parameters:
b-
-
paintComponent
Paints this component.- Overrides:
paintComponentin classJComponent- Parameters:
g-
-
getViewRect
Gets the clipping rectangle within a scroll pane viewport.- Returns:
- the clipping rectangle
-
findViewRect
Finds the clipping rectangle if this panel is within a scroll pane viewport. -
computeGutters
protected void computeGutters()Computes the size of the gutters. Objects, such as axes, can perform this method by implementing the Dimensioned interface. -
paintFirst
Paints before the panel iterates through its list of Drawables.- Parameters:
g- Graphics
-
paintLast
Paints after the panel iterates through its list of Drawables.- Parameters:
g- Graphics
-
paintEverything
Paints everything inside this component.- Parameters:
g-
-
setAutoscaleX
public void setAutoscaleX(boolean autoscale) Autoscale the x axis using min and max values. from measurable objects.- Parameters:
autoscale-
-
isAutoscaleX
public boolean isAutoscaleX()Determines if the x axis autoscale property is true.- Returns:
true<\code> if autoscaled.
-
isAutoscaleXMax
public boolean isAutoscaleXMax()Determines if the horizontal maximum value is autoscaled.- Returns:
true<\code> if xmax is autoscaled.
-
isAutoscaleXMin
public boolean isAutoscaleXMin()Determines if the horizontal minimum value is autoscaled.- Returns:
true<\code> if xmin is autoscaled.
-
setAutoscaleY
public void setAutoscaleY(boolean autoscale) Autoscale the y axis using min and max values. from measurable objects.- Parameters:
autoscale-
-
isAutoscaleY
public boolean isAutoscaleY()Determines if the y axis autoscale property is true.- Returns:
true<\code> if autoscaled.
-
isAutoscaleYMax
public boolean isAutoscaleYMax()Determines if the vertical maximum value is autoscaled.- Returns:
true<\code> if ymax is autoscaled.
-
isAutoscaleYMin
public boolean isAutoscaleYMin()Determines if the vertical minimum value is autoscaled.- Returns:
true<\code> if ymin is autoscaled.
-
isLogScaleX
public boolean isLogScaleX()Gets the logScaleX value.- Returns:
- boolean
-
isLogScaleY
public boolean isLogScaleY()Gets the logScaleY value.- Returns:
- boolean
-
setBounds
public void setBounds(int x, int y, int width, int height) Moves and resizes this component. The new location of the top-left corner is specified byxandy, and the new size is specified bywidthandheight. -
setBounds
-
setBuffered
public void setBuffered(boolean _buffered) Sets the buffered image option. Buffered panels copy the offscreen image into the panel during a repaint unless the image has been invalidated. Use the render() method to draw the image immediately.- Parameters:
_buffered-
-
isBuffered
public boolean isBuffered() -
setVisible
public void setVisible(boolean vis) Makes the component visible or invisible. OverridesJComponent.setVisible.- Overrides:
setVisiblein classJComponent- Parameters:
vis- true to make the component visible; false to make it invisible
-
limitAutoscaleX
public void limitAutoscaleX(double floor, double ceil) Limits the xmin and xmax values during autoscaling so that the mininimum value will be no greater than the floor and the maximum value will be no smaller than the ceil. Setting a floor or ceil value toDouble.NaN<\code> will disable that limit.- Parameters:
floor- the xfloor valueceil- the xceil value
-
limitAutoscaleY
public void limitAutoscaleY(double floor, double ceil) Limits ymin and ymax values during autoscaling so that the mininimum value will be no greater than the floor and the maximum value will be no smaller than the ceil. Setting a floor or ceil value toDouble.NaN<\code> will disable that limit.- Parameters:
floor- the yfloor valueceil- the yceil value
-
setPixelsPerUnit
public void setPixelsPerUnit(boolean enable, double xPixPerUnit, double yPixPerUnit) Sets the scale using pixels per unit.- Parameters:
enable- boolean enable fixed pixels per unitxPixPerUnit- doubleyPixPerUnit- double
-
setPreferredMinMax
public void setPreferredMinMax(double xmin, double xmax, double ymin, double ymax, boolean invalidateImage) Sets the preferred scale in the vertical and horizontal direction.- Parameters:
xmin-xmax-ymin-ymax-invalidateImage- invalidates image if min/max have changed
-
setPreferredMinMax
public void setPreferredMinMax(double xmin, double xmax, double ymin, double ymax) Sets the preferred scale in the vertical and horizontal direction.- Parameters:
xmin-xmax-ymin-ymax-
-
setPreferredMinMaxX
public void setPreferredMinMaxX(double xmin, double xmax) Sets the preferred scale in the horizontal direction.- Parameters:
xmin- the minimum valuexmax- the maximum value
-
setPreferredMinMaxY
public void setPreferredMinMaxY(double ymin, double ymax) Sets the preferred scale in the vertical direction.- Parameters:
ymin-ymax-
-
setSquareAspect
public void setSquareAspect(boolean val) Sets the aspect ratio for horizontal to vertical to unity whentrue<\code>.- Parameters:
val-
-
isSquareAspect
public boolean isSquareAspect()Determines if the number of pixels per unit is the same for both x and y.- Returns:
true<\code> if squareAspect
-
setAntialiasTextOn
public void setAntialiasTextOn(boolean on) Set flag for text antialiasing. -
isAntialiasTextOn
public boolean isAntialiasTextOn()Gets flag for text antialiasing. -
setAntialiasShapeOn
public void setAntialiasShapeOn(boolean on) Set flag for shape antialiasing. -
isAntialiasShapeOn
public boolean isAntialiasShapeOn()Gets flag for shape antialiasing. -
isPointInside
public boolean isPointInside(double x, double y) Determines if the x and y point is inside.- Parameters:
x- the coordinate in world unitsy- the coordinate in world units- Returns:
true<\code> if point is inside;false<\code> otherwise
-
isFixedScale
public boolean isFixedScale()Determines if the scale is fixed.- Returns:
true<\code> if scale is fixed
-
setFixedScale
public void setFixedScale(boolean fixed) Sets the fixed scale property. If fixed, the user cannot change the scale.- Parameters:
fixed-true<\code> to prevent user changes to scale
-
isZoom
public boolean isZoom()Determines if the user can change scale by dragging the mouse.- Returns:
true<\code> if zoom is enabled and scale is not fixed
-
setZoom
public void setZoom(boolean _enableZoom) Sets the zoom option to allow the user to change scale by dragging the mouse.- Parameters:
_enableZoom-true<\code> if zoom is enabled
-
zoomOut
protected void zoomOut()Zooms out by a factor of two. -
getZoomBox
Returns the internal ZoomBox object- Returns:
- ZoomBox
-
zoomIn
protected void zoomIn()Zooms in to the current zoom box. -
snapshot
public void snapshot()Creates a snapshot using an image of the content. -
hasInspector
public boolean hasInspector()Determines if the user can examine and change the scale at run-time by right-clicking.- Returns:
true<\code> if inspector is enabled
-
enableInspector
public void enableInspector(boolean isEnabled) Enables the popup inspector option. The default inspector shows a popup menu by right-clicking.- Parameters:
isEnabled-true<\code> if the inspector option is enabled;false<\code> otherwise
-
getPopupMenu
Gets the popup menu. -
setPopupMenu
Sets the popup menu. -
showInspector
public void showInspector()Shows the drawing panel properties inspector. -
hideInspector
public void hideInspector()Hides the drawing panel properties inspector. -
setCustomInspector
Sets a custom properties inspector window.- Parameters:
w- the new inspector window
-
setVideoTool
Sets the video tool. May be set to null.- Parameters:
videoCap- the video capture tool
-
getVideoTool
Gets the video capture tool. May be null.- Returns:
- the video capture tool
-
getAspectRatio
public double getAspectRatio()Gets the ratio of pixels per unit in the x and y directions.- Returns:
- the aspect ratio
-
getXPixPerUnit
public double getXPixPerUnit()Gets the number of pixels per world unit in the x direction.- Returns:
- pixels per unit
-
getYPixPerUnit
public double getYPixPerUnit()Gets the number of pixels per world unit in the y direction. Y pixels per unit is positive if y increases from bottom to top.- Returns:
- pixels per unit
-
getMaxPixPerUnit
public double getMaxPixPerUnit()Gets the larger of x or y pixels per world unit.- Returns:
- pixels per unit
-
getXMin
public double getXMin()Gets the x world coordinate for the left-hand side of the drawing area.- Returns:
- xmin
-
getPreferredXMin
public double getPreferredXMin()Gets the preferred x world coordinate for the left-hand side of the drawing area.- Returns:
- xmin
-
getXMax
public double getXMax()Gets the x world coordinate for the right-hand side of the drawing area.- Returns:
- xmax
-
getPreferredXMax
public double getPreferredXMax()Gets the preferred x world coordinate for the right-hand side of the drawing area.- Returns:
- xmin
-
getYMax
public double getYMax()Gets the y world coordinate for the top of the drawing area.- Returns:
- ymax
-
getPreferredYMax
public double getPreferredYMax()Gets the preferred y world coordinate for the top of the drawing area.- Returns:
- xmin
-
getYMin
public double getYMin()Gets the y world coordinate for the bottom of the drawing area.- Returns:
- ymin
-
getPreferredYMin
public double getPreferredYMin()Gets the preferred y world coordinate for the bottom of the drawing area.- Returns:
- xmin
-
getCoordinateStringBuilder
Gets the CoordinateStringBuilder that converts mouse events into a string showing world coordinates.- Returns:
- CoordinateStringBuilder
-
setCoordinateStringBuilder
Sets the CoordinateStringBuilder that converts mouse events into a string showing world coordinates. -
getScale
Gets the scale that will be used when the panel is drawn.- Returns:
- Rectangle2D
-
getMeasure
Gets the rectangle that bounds all measurable objects.- Returns:
- Rectangle2D
-
getPixelTransform
Gets the affine transformation that converts from world to pixel coordinates.- Returns:
- the affine transformation -- NOT A CLONE!
-
getPixelTransform
-
getPixelMatrix
public double[] getPixelMatrix()Retrieves the 6 specifiable values in the pixel transformation matrix and places them into an array of double precisions values. The values are stored in the array as { m00 m10 m01 m11 m02 m12 }.- Returns:
- the transformation matrix
-
setPixelScale
public void setPixelScale()Calculates min and max values and the affine transformation based on the current size of the panel and the squareAspect boolean. -
recomputeTransform
public void recomputeTransform()Recomputes the pixel transforamtion based on the current minimum and maximum values and the gutters. -
project
public double[] project(double[] coordinate, double[] pixel) Projects a 2D or 3D world coordinate to a pixel coordinate. An (x, y) point will project to (xpix, ypix). An (x, y, z) point will project to (xpix, ypix). An (x, y, delta_x, delta_y) point will project to (xpix, ypix, delta_xpix, delta_ypix). An (x, y, z, delta_x, delta_y, delta_z) point will project to (xpix, ypix, delta_xpix, delta_ypix).- Parameters:
coordinate-pixel-- Returns:
- pixel
-
pixToX
public double pixToX(int pix) Converts pixel to x world units.- Parameters:
pix-- Returns:
- x panel units
-
xToPix
public int xToPix(double x) Converts x from world to pixel units.- Parameters:
x-- Returns:
- the pixel value of the x coordinate
-
xToGraphics
public float xToGraphics(double x) Converts x from world to graphics device units.- Parameters:
x-- Returns:
- the graphics device value of the x coordinate
-
pixToY
public double pixToY(int pix) Converts pixel to x world units.- Parameters:
pix-- Returns:
- x panel units
-
yToPix
public int yToPix(double y) Converts y from world to pixel units.- Parameters:
y-- Returns:
- the pixel value of the y coordinate
-
yToGraphics
public float yToGraphics(double y) Converts y from world to graphics device units.- Parameters:
y-- Returns:
- the graphics device value of the x coordinate
-
scale
public void scale()Sets axis scales if autoscale is true using the max and min values of the measurable objects. -
scale
Sets axis scales if autoscale is true using the max and min values of the objects in the given list. -
measure
public void measure()Sets the scale based on the max and min values of all measurable objects. Autoscale flags are not respected. -
scaleX
protected void scaleX()Sets the x axis scale based on the max and min values of all measurable objects. Autoscale flag is not respected. -
scaleX
Sets the x axis scale based on the max and/or min values of all measurable objects. Autoscale flag is not respected. -
scaleY
protected void scaleY()Sets the y axis scale based on the max and min values of all measurable objects. Autoscale flag is not respected. -
scaleY
Sets the y axis scale based on the max and min values of all measurable objects. Autoscale flag is not respected. -
paintDrawableList
Paints all the drawable objects in the panel.- Parameters:
g-
-
getDimensionSetter
Gets the object that sets the gutters for this panel.- Returns:
- Dimensioned
-
addDrawable
Adds a drawable object to the drawable list.- Parameters:
drawable-
-
addDrawables
Adds a collection of drawable objects to the drawable list.- Parameters:
drawables-
-
addDrawableAtIndex
Adds a drawable object to the drawable list at the given index.- Parameters:
drawable-
-
replaceDrawable
Replaces a drawable object with another drawable.- Parameters:
oldDrawable- DrawablenewDrawable- Drawable
-
removeDrawable
Removes a drawable object from the drawable list.- Parameters:
drawable-
-
removeObjectsOfClass
Removes all objects of the given class from the drawable list. Assignable subclasses are NOT removed. Interfaces CANNOT be specified.- Parameters:
c- the class- See Also:
-
removeDrawables
Removes all objects assignable to the given class from the drawable list. Interfaces can be specified.- Parameters:
c- the class- See Also:
-
removeOptionController
public void removeOptionController()Removes the option controller. The option controller may interfere with other mouse actions -
addOptionController
public void addOptionController()Removes the option controller. The option controller may interfere with other mouse actions -
clear
public void clear()Removes all drawable objects from the drawable list. -
getDrawables
Gets the cloned list of Drawable objects. This is a shallow clone. The same objects will be in both the drawable list and the cloned list.- Returns:
- cloned list
-
getDrawablesNoClone
-
getDrawables
Gets Drawable objects of an assignable type. The list contains objects that are assignable from the class or interface. Returns a shallow clone. The same objects will be in the drawable list and the cloned list.- Parameters:
type- the type of Drawable object- Returns:
- the cloned list
- See Also:
-
getFirstDrawable
-
getDrawablesExcept
-
getObjectOfClass
Gets objects of a specific class from the drawables list. Assignable subclasses are NOT returned. Interfaces CANNOT be specified. The same objects will be in the drawable list and the cloned list.- Parameters:
type- the class of the object, which may be null to include all types- Returns:
- the list
- See Also:
-
getDrawablesExcept
-
getDrawables
-
getGutters
public int[] getGutters()Gets the gutters. -
setGutters
public void setGutters(int[] gutters) Sets the gutters using the given array.- Parameters:
gutters- int[]
-
setGutters
public void setGutters(int left, int top, int right, int bottom) Sets gutters around the drawing area.- Parameters:
left-top-right-bottom-
-
setPreferredGutters
public void setPreferredGutters(int left, int top, int right, int bottom) Sets preferred gutters around the drawing area.- Parameters:
left-top-right-bottom-
-
resetGutters
public void resetGutters()Resets the gutters to their preferred values. -
getBottomGutter
public int getBottomGutter()Gets the bottom gutter of this DrawingPanel.- Returns:
- bottom gutter
-
getTopGutter
public int getTopGutter()Gets the bottom gutter of this DrawingPanel.- Returns:
- right gutter
-
getLeftGutter
public int getLeftGutter()Gets the left gutter of this DrawingPanel.- Returns:
- left gutter
-
getRightGutter
public int getRightGutter()Gets the right gutter of this DrawingPanel.- Returns:
- right gutter
-
setMessage
Shows a message in a yellow text box in the lower right hand corner.- Parameters:
msg-
-
setMessage
Shows a message in a yellow text box. Check for the last message being the same at this location. location 0=bottom left location 1=bottom right location 2=top right location 3=top left- Parameters:
msg-location-- Returns:
- true if the message changed; false if display was skipped
-
setShowCoordinates
public void setShowCoordinates(boolean show) Show the coordinates in the text box in the lower left hand corner.- Parameters:
show-
-
isZoomEvent
Returns true if an event starts or ends a zoom operation. Used by OptionController. Method added by D Brown 04 Nov 2011.- Parameters:
e- a mouse event- Returns:
- true if a zoom event
-
repaint
public void repaint(int x, int y, int w, int h) -
repaint
public void repaint() -
repaintIfNecessary
public void repaintIfNecessary() -
isShowCoordinates
public boolean isShowCoordinates()Returns true if mouse coordinates are displayed- Returns:
trueif mouse coordinates are displayed
-
displayCoordinates
-
repaintForZoom
public void repaintForZoom() -
getLoader
Returns an XML.ObjectLoader to save and load object data.- Returns:
- the XML.ObjectLoader
-
transformPath
-
transformShape
-
dref
-
firePropertyChange
- Overrides:
firePropertyChangein classComponent
-
receiveToolReply
-