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:
- javax.accessibility.Accessible, java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.awt.print.Printable, Renderable, java.io.Serializable
- Direct Known Subclasses:
- InteractivePanel
- public class DrawingPanel
- extends javax.swing.JPanel
- implements java.awt.print.Printable, java.awt.event.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 recaclucated 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 xmaxymin then the coordinate scale increases from bottom to top.
If ymax
- See Also:
- Serialized Form
Nested Class Summary |
class |
DrawingPanel.ZoomBox
ZoomBox creates an on-screen rectangle using XORMode for fast redrawing. |
Nested classes inherited from class javax.swing.JPanel |
javax.swing.JPanel.AccessibleJPanel |
Nested classes inherited from class javax.swing.JComponent |
javax.swing.JComponent.AccessibleJComponent |
Nested classes inherited from class java.awt.Container |
java.awt.Container.AccessibleAWTContainer |
Nested classes inherited from class java.awt.Component |
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy |
Fields inherited from class javax.swing.JComponent |
accessibleContext, 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 |
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT |
Fields inherited from interface java.awt.print.Printable |
NO_SUCH_PAGE, PAGE_EXISTS |
Fields inherited from interface java.awt.image.ImageObserver |
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH |
Constructor Summary |
DrawingPanel()
DrawingPanel constructor. |
Method Summary |
void |
actionPerformed(java.awt.event.ActionEvent evt)
Performs the action for the refresh timer by refreshing the data in the DataTable. |
void |
addDrawable(Drawable drawable)
Adds a drawable object to the drawable list. |
void |
addDrawables(java.util.Collection drawables)
Adds a collection of drawable objects to the drawable list. |
protected void |
buildPopupmenu()
Builds the default popup menu for this panel. |
protected boolean |
checkWorkingImage()
Checks the image to see if the working image has the correct Dimension. |
void |
clear()
Removes all drawable objects from the drawable list. |
protected void |
computeGutters()
Computes the size of the gutters. |
void |
enableInspector(boolean isEnabled)
Enables the popup inspector option. |
protected java.awt.Rectangle |
findViewRect()
Finds the clipping rectangle if this panel is within a scroll pane viewport. |
double |
getAspectRatio()
Gets the ratio of pixels per unit in the x and y directions. |
int |
getBottomGutter()
Gets the bottom gutter of this DrawingPanel. |
org.opensourcephysics.display.axes.CoordinateStringBuilder |
getCoordinateStringBuilder()
Gets the CoordinateStringBuilder that converts mouse events into a string showing world coordinates. |
Dimensioned |
getDimensionSetter()
Gets the object that sets the gutters for this panel. |
java.util.ArrayList |
getDrawables()
Gets the cloned list of Drawable objects. |
java.util.ArrayList |
getDrawables(java.lang.Class c)
Gets Drawable objects of an assignable type. |
javax.swing.JPanel |
getGlassPanel()
Gets the glass panel. |
int[] |
getGutters()
Gets the gutters. |
int |
getLeftGutter()
Gets the left gutter of this DrawingPanel. |
static XML.ObjectLoader |
getLoader()
Returns an XML.ObjectLoader to save and load object data. |
double |
getMaxPixPerUnit()
Gets the larger of x or y pixels per world unit. |
java.awt.geom.Rectangle2D |
getMeasure()
Gets the rectangle that bounds all measurable objects. |
java.util.ArrayList |
getObjectOfClass(java.lang.Class c)
Gets objects of a specific class from the drawables list. |
double[] |
getPixelMatrix()
Retrieves the 6 specifiable values in the pixel transformation
matrix and places them into an array of double precisions values. |
java.awt.geom.AffineTransform |
getPixelTransform()
Gets the affine transformation that converts from world to pixel coordinates. |
javax.swing.JPopupMenu |
getPopupMenu()
Gets the popup menu. |
double |
getPreferredXMax()
Gets the preferred x world coordinate for the right-hand side of the drawing area. |
double |
getPreferredXMin()
Gets the preferred x world coordinate for the left-hand side of the drawing area. |
double |
getPreferredYMax()
Gets the preferred y world coordinate for the top of the drawing area. |
double |
getPreferredYMin()
Gets the preferred y world coordinate for the bottom of the drawing area. |
int |
getRightGutter()
Gets the right gutter of this DrawingPanel. |
java.awt.geom.Rectangle2D |
getScale()
Gets the scale that will be used when the panel is drawn. |
int |
getTopGutter()
Gets the bottom gutter of this DrawingPanel. |
VideoCaptureTool |
getVideoCaptureTool()
Gets the video capture tool. |
protected java.awt.Rectangle |
getViewRect()
Gets the clipping rectance within a scroll pane viewport. |
double |
getXMax()
Gets the x world coordinate for the right-hand side of the drawing area. |
double |
getXMin()
Gets the x world coordinate for the left-hand side of the drawing area. |
double |
getXPixPerUnit()
Gets the number of pixels per world unit in the x direction. |
double |
getYMax()
Gets the y world coordinate for the top of the drawing area. |
double |
getYMin()
Gets the y world coordinate for the bottom of the drawing area. |
double |
getYPixPerUnit()
Gets the number of pixels per world unit in the y direction. |
boolean |
hasInspector()
Determines if the user can examine and change the scale at run-time by right-clicking. |
void |
hideInspector()
Hides the drawing panel properties inspector. |
void |
invalidateImage()
Invalidate the offscreen image so that it is rendered during the next repaint operation if buffering is enabled. |
boolean |
isAntialiasShapeOn()
Gets flag for shape antialiasing. |
boolean |
isAntialiasTextOn()
Gets flag for text antialiasing. |
boolean |
isAutoscaleX()
Determines if the x axis autoscale property is true. |
boolean |
isAutoscaleY()
Determines if the y axis autoscale property is true. |
boolean |
isBuffered()
|
boolean |
isClipAtGutter()
Gets the clip at gutter flag. |
boolean |
isIconified()
Gets the iconified flag from the top level frame. |
boolean |
isPointInside(double x,
double y)
Determines if the x and y point is inside. |
boolean |
isSquareAspect()
Determines if the number of pixels per unit is the same for both x and y. |
boolean |
isZoom()
Determines if the user can change scale by dragging the mouse. |
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. |
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. |
void |
measure()
Sets the scale based on the max and min values of all measurable objects. |
void |
paintComponent(java.awt.Graphics g)
Paints this component. |
protected void |
paintDrawableList(java.awt.Graphics g,
java.util.ArrayList tempList)
Paints all the drawable objects in the panel. |
protected void |
paintEverything(java.awt.Graphics g)
Paints everything inside this component. |
protected void |
paintFirst(java.awt.Graphics g)
Paints before the panel iterates through its list of Drawables. |
protected void |
paintLast(java.awt.Graphics g)
Paints after the panel iterates through its list of Drawables. |
double |
pixToX(int pix)
Converts pixel to x world units. |
double |
pixToY(int pix)
Converts pixel to x world units. |
int |
print(java.awt.Graphics g,
java.awt.print.PageFormat pageFormat,
int pageIndex)
Draws the panel into a graphics object suitable for printing. |
double[] |
project(double[] coordinate,
double[] pixel)
Projects a 2D or 3D world coordinate to a pixel coordinate. |
void |
removeDrawable(Drawable drawable)
Removes a drawable object from the drawable list. |
void |
removeDrawables(java.lang.Class c)
Removes all objects assignable to the given class from the drawable list. |
void |
removeObjectsOfClass(java.lang.Class c)
Removes all objects of the given class from the drawable list. |
void |
removeOptionController()
Removes the option controller. |
java.awt.image.BufferedImage |
render()
Paints all drawables onto an offscreen image buffer and copies this image onto the screen. |
java.awt.Image |
render(java.awt.Image image)
Paints all drawables onto an image. |
void |
replaceDrawable(Drawable oldDrawable,
Drawable newDrawable)
Replaces a drawable object with another drawable. |
void |
scale()
Sets axis scales if autoscale is true using the max and min values of the measurable objects. |
protected void |
scale(java.util.ArrayList tempList)
Sets axis scales if autoscale is true using the max and min values of the objects in the given list. |
protected void |
scaleX()
Sets the x axis scale based on the max and min values of all measurable objects. |
protected void |
scaleY()
Sets the y axis scale based on the max and min values of all measurable objects. |
void |
setAntialiasShapeOn(boolean on)
Set flag for shape antialiasing. |
void |
setAntialiasTextOn(boolean on)
Set flag for text antialiasing. |
void |
setAutoscaleMargin(double _autoscaleMargin)
Sets the size of the margin during an autoscale operation. |
void |
setAutoscaleX(boolean autoscale)
Autoscale the x axis using min and max values. |
void |
setAutoscaleY(boolean autoscale)
Autoscale the y axis using min and max values. |
void |
setBounds(int x,
int y,
int width,
int height)
Moves and resizes this component. |
void |
setBounds(java.awt.Rectangle r)
|
void |
setBuffered(boolean _buffered)
Sets the buffered image option. |
void |
setClipAtGutter(boolean clip)
Sets the panel to exclude the gutter from the drawing. |
void |
setCoordinateStringBuilder(org.opensourcephysics.display.axes.CoordinateStringBuilder builder)
Sets the CoordinateStringBuilder that converts mouse events into a string showing world coordinates. |
void |
setCustomInspector(java.awt.Window w)
Sets a custom properties inspector window. |
protected void |
setFontLevel(int level)
Sets the font level. |
void |
setGutters(int[] gutters)
Sets the gutters using the given array. |
void |
setGutters(int left,
int top,
int right,
int bottom)
Sets gutters around the drawing area. |
void |
setIgnoreRepaint(boolean ignoreRepaint)
|
void |
setMessage(java.lang.String msg)
Shows a message in a yellow text box in the lower right hand corner. |
void |
setMessage(java.lang.String msg,
int location)
Shows a message in a yellow text box. |
void |
setMouseCursor(java.awt.Cursor cursor)
Sets the mouse cursor. |
void |
setPixelScale()
Calculates min and max values and the affine transformation based on the
current size of the panel and the squareAspect boolean. |
void |
setPixelsPerUnit(boolean enable,
double xPixPerUnit,
double yPixPerUnit)
Sets the scale using pixels per unit. |
void |
setPopupMenu(javax.swing.JPopupMenu menu)
Sets the popup menu. |
void |
setPreferredMinMax(double xmin,
double xmax,
double ymin,
double ymax)
Sets the preferred scale in the vertical and horizontal direction. |
void |
setPreferredMinMaxX(double xmin,
double xmax)
Sets the preferred scale in the horizontal direction. |
void |
setPreferredMinMaxY(double ymin,
double ymax)
Sets the preferred scale in the vertical direction. |
void |
setShowCoordinates(boolean show)
Show the coordinates in the text box in the lower left hand corner. |
void |
setSquareAspect(boolean val)
Sets the aspect ratio for horizontal to vertical to unity when true<\code>. |
void |
setVideoCaptureTool(VideoCaptureTool videoCap)
Sets the video capture tool. |
void |
setVisible(boolean isVisible)
Makes the component visible or invisible. |
void |
setZoom(boolean _enableZoom)
Sets the zoom option to allow the user to change scale by dragging the mouse while pressing the shift. |
void |
showInspector()
Shows the drawing panel properties inspector. |
void |
snapshot()
Creates a snapshot using an image of the content. |
int |
xToPix(double x)
Converts x from world to pixel units. |
int |
yToPix(double y)
Converts y from world to pixel units. |
protected void |
zoomIn()
Zooms in on next click-drag. |
protected void |
zoomOut()
Zooms out by increasing the preferred min/max values by a factor of two. |
Methods inherited from class javax.swing.JPanel |
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI |
Methods inherited from class javax.swing.JComponent |
addAncestorListener, addNotify, addPropertyChangeListener, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getDefaultLocale, getGraphics, getHeight, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getPropertyChangeListeners, getPropertyChangeListeners, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, isDoubleBuffered, isLightweightComponent, isManagingFocus, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isPreferredSizeSet, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, processKeyBinding, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setActionMap, setAlignmentX, setAlignmentY, setAutoscrolls, setBackground, setBorder, setDebugGraphicsOptions, setDefaultLocale, setDoubleBuffered, setEnabled, setFont, setForeground, 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, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setLayout, transferFocusBackward, 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, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMouseWheelListeners, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, 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, processMouseEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, repaint, repaint, repaint, resize, resize, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusUpCycle |
Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait |
BOTTOM_LEFT
public static final int BOTTOM_LEFT
- Message box location
- See Also:
- Constant Field Values
BOTTOM_RIGHT
public static final int BOTTOM_RIGHT
- Message box location
- See Also:
- Constant Field Values
TOP_RIGHT
public static final int TOP_RIGHT
- Message box location
- See Also:
- Constant Field Values
TOP_LEFT
public static final int TOP_LEFT
- Message box location
- See Also:
- Constant Field Values
popupmenu
protected javax.swing.JPopupMenu popupmenu
propertiesItem
protected javax.swing.JMenuItem propertiesItem
leftGutter
protected int leftGutter
topGutter
protected int topGutter
rightGutter
protected int rightGutter
bottomGutter
protected int bottomGutter
width
protected int width
height
protected int height
bgColor
protected java.awt.Color bgColor
antialiasTextOn
protected boolean antialiasTextOn
antialiasShapeOn
protected boolean antialiasShapeOn
squareAspect
protected boolean squareAspect
autoscaleX
protected boolean autoscaleX
autoscaleY
protected boolean autoscaleY
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
protected java.awt.geom.AffineTransform pixelTransform
pixelMatrix
protected double[] pixelMatrix
drawableList
protected java.util.ArrayList drawableList
validImage
protected boolean validImage
offscreenImage
protected java.awt.image.BufferedImage offscreenImage
workingImage
protected java.awt.image.BufferedImage workingImage
trMessageBox
protected TextPanel trMessageBox
tlMessageBox
protected TextPanel tlMessageBox
brMessageBox
protected TextPanel brMessageBox
blMessageBox
protected TextPanel blMessageBox
scientificFormat
protected java.text.DecimalFormat scientificFormat
decimalFormat
protected java.text.DecimalFormat decimalFormat
mouseController
protected MouseController mouseController
showCoordinates
protected boolean showCoordinates
optionController
protected org.opensourcephysics.display.DrawingPanel.OptionController optionController
zoomBox
protected DrawingPanel.ZoomBox zoomBox
enableZoom
protected boolean enableZoom
zoomMode
protected boolean zoomMode
customInspector
protected java.awt.Window customInspector
clipAtGutter
protected boolean clipAtGutter
dimensionSetter
protected Dimensioned dimensionSetter
viewRect
protected java.awt.Rectangle viewRect
coordinateStrBuilder
protected org.opensourcephysics.display.axes.CoordinateStringBuilder coordinateStrBuilder
glassPanel
protected org.opensourcephysics.display.DrawingPanel.GlassPanel glassPanel
glassPanelLayout
protected OSPLayout glassPanelLayout
DrawingPanel
public DrawingPanel()
- DrawingPanel constructor.
setFontLevel
protected void setFontLevel(int level)
- Sets the font level.
- Parameters:
level
- the level
buildPopupmenu
protected void buildPopupmenu()
- Builds the default popup menu for this panel.
setAutoscaleMargin
public void setAutoscaleMargin(double _autoscaleMargin)
- Sets the size of the margin during an autoscale operation.
- Parameters:
_autoscaleMargin
-
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
setGutters
public void setGutters(int left,
int top,
int right,
int bottom)
- Sets gutters around the drawing area.
- Parameters:
left
- top
- right
- bottom
-
setMouseCursor
public void setMouseCursor(java.awt.Cursor cursor)
- Sets the mouse cursor.
- Parameters:
cursor
-
checkWorkingImage
protected boolean checkWorkingImage()
- Checks the image to see if the working image has the correct Dimension.
- Returns:
true <\code> if the offscreen image matches the panel; false <\code> otherwise
actionPerformed
public void actionPerformed(java.awt.event.ActionEvent evt)
- Performs the action for the refresh timer by refreshing the data in the DataTable.
- Specified by:
actionPerformed
in interface java.awt.event.ActionListener
- 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
public java.awt.image.BufferedImage render()
- Paints all drawables onto an offscreen image buffer and copies this image onto the screen.
- Specified by:
render
in interface Renderable
- Returns:
- the image buffer
render
public java.awt.Image render(java.awt.Image image)
- Paints all drawables onto an image.
- Specified by:
render
in interface Renderable
- Parameters:
image
-
- Returns:
- the image buffer
invalidateImage
public void invalidateImage()
- Invalidate the offscreen image so that it is rendered during the next repaint operation if buffering is enabled.
paintComponent
public void paintComponent(java.awt.Graphics g)
- Paints this component.
- Parameters:
g
-
getViewRect
protected java.awt.Rectangle getViewRect()
- Gets the clipping rectance within a scroll pane viewport.
- Returns:
- the clipping rectangle
findViewRect
protected java.awt.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, perform this function
by implementing the Dimensioned interface.
paintFirst
protected void paintFirst(java.awt.Graphics g)
- Paints before the panel iterates through its list of Drawables.
- Parameters:
g
- Graphics
paintLast
protected void paintLast(java.awt.Graphics g)
- Paints after the panel iterates through its list of Drawables.
- Parameters:
g
- Graphics
paintEverything
protected void paintEverything(java.awt.Graphics g)
- 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.
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.
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 by
x
and y
, and the
new size is specified by width
and height
.
- Parameters:
x
- The new x-coordinate of this component.y
- The new y-coordinate of this component.width
- The new width
of this component.height
- The new height
of this
component.
setBounds
public void setBounds(java.awt.Rectangle r)
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 isVisible)
- Makes the component visible or invisible.
Overrides
JComponent.setVisible
.
- Parameters:
isVisible
- 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 to
Double.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 to
Double.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)
- 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 when
true<\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
isZoom
public boolean isZoom()
- Determines if the user can change scale by dragging the mouse.
- Returns:
true<\code> if zoom is enabled
setZoom
public void setZoom(boolean _enableZoom)
- Sets the zoom option to allow the user to change scale by dragging the mouse while pressing the shift.
- Parameters:
_enableZoom
- true<\code> if zoom is enabled; false<\code> otherwise
zoomOut
protected void zoomOut()
- Zooms out by increasing the preferred min/max values by a factor of two.
zoomIn
protected void zoomIn()
- Zooms in on next click-drag.
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
public javax.swing.JPopupMenu getPopupMenu()
- Gets the popup menu.
setPopupMenu
public void setPopupMenu(javax.swing.JPopupMenu menu)
- 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
public void setCustomInspector(java.awt.Window w)
- Sets a custom properties inspector window.
- Parameters:
w
- the new inspector window
setVideoCaptureTool
public void setVideoCaptureTool(VideoCaptureTool videoCap)
- Sets the video capture tool. May be set to null.
- Parameters:
videoCap
- the video capture tool
getVideoCaptureTool
public VideoCaptureTool getVideoCaptureTool()
- 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
public org.opensourcephysics.display.axes.CoordinateStringBuilder getCoordinateStringBuilder()
- Gets the CoordinateStringBuilder that converts mouse events into a string showing world coordinates.
- Returns:
- CoordinateStringBuilder
setCoordinateStringBuilder
public void setCoordinateStringBuilder(org.opensourcephysics.display.axes.CoordinateStringBuilder builder)
- Sets the CoordinateStringBuilder that converts mouse events into a string showing world coordinates.
getScale
public java.awt.geom.Rectangle2D getScale()
- Gets the scale that will be used when the panel is drawn.
- Returns:
- Rectangle2D
getMeasure
public java.awt.geom.Rectangle2D getMeasure()
- Gets the rectangle that bounds all measurable objects.
- Returns:
- Rectangle2D
getPixelTransform
public java.awt.geom.AffineTransform getPixelTransform()
- Gets the affine transformation that converts from world to pixel coordinates.
- Returns:
- the affine transformation
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.
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
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
scale
public void scale()
- Sets axis scales if autoscale is true using the max and min values of the measurable objects.
scale
protected void scale(java.util.ArrayList tempList)
- 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.
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.
paintDrawableList
protected void paintDrawableList(java.awt.Graphics g,
java.util.ArrayList tempList)
- Paints all the drawable objects in the panel.
- Parameters:
g
-
getGlassPanel
public javax.swing.JPanel getGlassPanel()
- Gets the glass panel.
The glass panel is a trasparent panel that contians the messages boxes and other compotnents.
- Returns:
- JPanel
setIgnoreRepaint
public void setIgnoreRepaint(boolean ignoreRepaint)
getDimensionSetter
public Dimensioned getDimensionSetter()
- Gets the object that sets the gutters for this panel.
- Returns:
- Dimensioned
addDrawable
public void addDrawable(Drawable drawable)
- Adds a drawable object to the drawable list.
- Parameters:
drawable
-
addDrawables
public void addDrawables(java.util.Collection drawables)
- Adds a collection of drawable objects to the drawable list.
- Parameters:
drawables
-
replaceDrawable
public void replaceDrawable(Drawable oldDrawable,
Drawable newDrawable)
- Replaces a drawable object with another drawable.
- Parameters:
oldDrawable
- DrawablenewDrawable
- Drawable
removeDrawable
public void removeDrawable(Drawable drawable)
- Removes a drawable object from the drawable list.
- Parameters:
drawable
-
removeObjectsOfClass
public void removeObjectsOfClass(java.lang.Class c)
- 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(Class c)
removeDrawables
public void removeDrawables(java.lang.Class c)
- Removes all objects assignable to the given class from the drawable list.
Interfaces can be specified.
- Parameters:
c
- the class- See Also:
removeObjectsOfClass(Class c)
removeOptionController
public void removeOptionController()
- Removes the option controller.
The option controller may interfere with other mouse ac
clear
public void clear()
- Removes all drawable objects from the drawable list.
getDrawables
public java.util.ArrayList 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
getDrawables
public java.util.ArrayList getDrawables(java.lang.Class c)
- 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:
c
- the type of Drawable object
- Returns:
- the cloned list
- See Also:
getObjectOfClass(Class c)
getObjectOfClass
public java.util.ArrayList getObjectOfClass(java.lang.Class c)
- 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:
c
- the class of the object
- Returns:
- the list
- See Also:
getDrawables(Class c)
print
public int print(java.awt.Graphics g,
java.awt.print.PageFormat pageFormat,
int pageIndex)
throws java.awt.print.PrinterException
- Draws the panel into a graphics object suitable for printing.
- Specified by:
print
in interface java.awt.print.Printable
- Parameters:
g
- pageFormat
- pageIndex
-
- Returns:
- status code
- Throws:
java.awt.print.PrinterException
getGutters
public int[] getGutters()
- Gets the gutters.
setGutters
public void setGutters(int[] gutters)
- Sets the gutters using the given array.
- Parameters:
gutters
- int[]
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
public void setMessage(java.lang.String msg)
- Shows a message in a yellow text box in the lower right hand corner.
- Parameters:
msg
-
setMessage
public void setMessage(java.lang.String msg,
int location)
- Shows a message in a yellow text box.
location 0=bottom left
location 1=bottom right
location 2=top right
location 3=top left
- Parameters:
msg
- location
-
setShowCoordinates
public void setShowCoordinates(boolean show)
- Show the coordinates in the text box in the lower left hand corner.
- Parameters:
show
-
getLoader
public static XML.ObjectLoader getLoader()
- Returns an XML.ObjectLoader to save and load object data.
- Returns:
- the XML.ObjectLoader