org.opensourcephysics.display
Class DrawingFrame

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Window
              extended by java.awt.Frame
                  extended by javax.swing.JFrame
                      extended by org.opensourcephysics.display.OSPFrame
                          extended by org.opensourcephysics.display.DrawingFrame
All Implemented Interfaces:
java.awt.datatransfer.ClipboardOwner, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible, javax.swing.RootPaneContainer, javax.swing.WindowConstants, AppFrame, Hidable
Direct Known Subclasses:
Complex2DFrame, ComplexPlotFrame, DisplayFrame, FFT2DFrame, FFTFrame, HistogramFrame, LatticeFrame, ParticleFrame, PlotFrame, RasterFrame, Scalar2DFrame, Vector2DFrame, VideoFrame

public class DrawingFrame
extends OSPFrame
implements java.awt.datatransfer.ClipboardOwner

Drawing Frame: a frame that contains a drawing panel.

Version:
1.1
Author:
Wolfgang Christian
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.BaselineResizeBehavior
 
Field Summary
 
Fields inherited from class org.opensourcephysics.display.OSPFrame
constructorThreadGroup
 
Fields inherited from class javax.swing.JFrame
EXIT_ON_CLOSE
 
Fields inherited from class java.awt.Frame
CROSSHAIR_CURSOR, DEFAULT_CURSOR, E_RESIZE_CURSOR, HAND_CURSOR, ICONIFIED, MAXIMIZED_BOTH, MAXIMIZED_HORIZ, MAXIMIZED_VERT, MOVE_CURSOR, N_RESIZE_CURSOR, NE_RESIZE_CURSOR, NORMAL, NW_RESIZE_CURSOR, S_RESIZE_CURSOR, SE_RESIZE_CURSOR, SW_RESIZE_CURSOR, TEXT_CURSOR, W_RESIZE_CURSOR, WAIT_CURSOR
 
Fields inherited from class java.awt.Component
BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT
 
Fields inherited from interface javax.swing.WindowConstants
DISPOSE_ON_CLOSE, DO_NOTHING_ON_CLOSE, HIDE_ON_CLOSE
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
DrawingFrame()
          DrawingFrame constructor that creates a default DrawingPanel.
DrawingFrame(DrawingPanel drawingPanel)
          DrawingFrame constructor specifying the DrawingPanel that will be placed in the center of the content pane.
DrawingFrame(java.lang.String title, DrawingPanel _drawingPanel)
          DrawingFrame constructor specifying the title and the DrawingPanel that will be placed in the center of the content pane.
 
Method Summary
 void addDrawable(Drawable drawable)
          Adds a drawable object to the frame's drawing panel.
 void clearDataAndRepaint()
          Clears data and repaints the drawing panel within this frame.
 void clearDrawables()
          Clears Drawable objects added by the user from this frame.
 DrawableAxes getAxes()
           
 java.util.ArrayList<Drawable> getDrawables()
          Gets Drawable previously objects added by the user.
<T extends Drawable>
java.util.ArrayList<T>
getDrawables(java.lang.Class<T> c)
          Gets Drawable objects added by the user of an assignable type.
 DrawingPanel getDrawingPanel()
          Gets the drawing panel.
static XML.ObjectLoader getLoader()
          Returns an XML.ObjectLoader to save and load data for this program.
<T extends Drawable>
java.util.ArrayList<T>
getObjectOfClass(java.lang.Class<T> c)
          Gets objects of a specific class from the drawing panel.
 void inspectXML()
          Inspects the drawing frame by using an xml document tree.
 void invalidateImage()
          Invalidates image buffers if a drawing panel buffered.
 boolean isAutoscaleX()
          Determines if the panel's x axis autoscale property is true.
 boolean isAutoscaleY()
          Determines if the y axis autoscale property is true.
 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 lostOwnership(java.awt.datatransfer.Clipboard clipboard, java.awt.datatransfer.Transferable contents)
          Implementation of ClipboardOwner interface.
 void paint(java.awt.Graphics g)
          This is a hack to fix a bug when the reload button is pressed in browsers running JDK 1.4.
 void removeDrawable(Drawable drawable)
          Removes a drawable object to the frame's drawing panel.
<T extends Drawable>
void
removeObjectsOfClass(java.lang.Class<T> c)
          Removes all objects of the given class from the drawable list.
 void render()
          Renders the drawing panel if the frame is showing and not iconified.
 void replaceAction(XMLControlElement control)
          Replaces the drawables with the drawables found in the specified XML control.
 void replaceDrawable(Drawable oldDrawable, Drawable newDrawable)
          Replaces a Drawable object with another Drawable.
 void saveXML()
           
 void setAutoscaleX(boolean autoscale)
          Autoscale the drawing panel's x axis using min and max values.
 void setAutoscaleY(boolean autoscale)
          Autoscale the y axis using min and max values.
 void setCartesian(java.lang.String xLabel, java.lang.String yLabel, java.lang.String plotTitle)
          Converts to cartesian coordinates.
 void setCustomInspector(java.awt.Window w)
          Sets a custom properties inspector window.
 void setDrawingPanel(DrawingPanel _drawingPanel)
          Adds the drawing panel to the the frame.
 void setEnabledCopy(boolean enable)
          Enables the copy edit menu item.
 void setEnabledPaste(boolean enable)
          Enables the paste edit menu item.
 void setEnabledReplace(boolean enable)
          Enables the replace edit menu item.
 void setInteractiveMouseHandler(InteractiveMouseHandler handler)
          Sets the interactive mouse handler if the drawing panel is an interactive panel.
 void setInteriorBackground(java.awt.Color color)
          Sets the interior background color for the current drawing panel.
 void setLogScale(boolean logX, boolean logY)
          Sets Cartesian axes to log scale.
 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 at the given location.
 void setPixelsPerUnit(boolean enable, double xPixPerUnit, double yPixPerUnit)
          Sets the scale using pixels per unit.
 void setPolar(java.lang.String plotTitle, double deltaR)
          Converts to polar coordinates.
 void setPreferredMinMax(double xmin, double xmax, double ymin, double ymax)
          Sets the drawing panel's preferred scale.
 void setPreferredMinMaxX(double xmin, double xmax)
          Sets the drawing panel's preferred scale in the horizontal direction.
 void setPreferredMinMaxY(double ymin, double ymax)
          Sets the drawing panel's preferred scale in the vertical direction.
 void setSquareAspect(boolean isSquare)
          Sets the aspect ratio for horizontal to vertical to unity when true<\code>.
 void setXLabel(java.lang.String label)
          Sets the label for the X (horizontal) axis.
 void setYLabel(java.lang.String label)
          Sets the label for the Y (vertical) axis.
 
Methods inherited from class org.opensourcephysics.display.OSPFrame
addButton, addChildFrame, bufferStrategyShow, clearChildFrames, clearData, createBufferStrategy, dispose, getChildFrames, getChooser, getConstructorThreadGroup, getMenu, isAnimated, isAutoclear, isIconified, isKeepHidden, parseXMLMenu, parseXMLMenu, removeMenu, removeMenuItem, setAnimated, setAutoclear, setDefaultCloseOperation, setKeepHidden, setSize, setTitle, setVisible, show, wishesToExit
 
Methods inherited from class javax.swing.JFrame
getAccessibleContext, getContentPane, getDefaultCloseOperation, getGlassPane, getGraphics, getJMenuBar, getLayeredPane, getRootPane, getTransferHandler, isDefaultLookAndFeelDecorated, remove, repaint, setContentPane, setDefaultLookAndFeelDecorated, setGlassPane, setIconImage, setJMenuBar, setLayeredPane, setLayout, setTransferHandler, update
 
Methods inherited from class java.awt.Frame
addNotify, getCursorType, getExtendedState, getFrames, getIconImage, getMaximizedBounds, getMenuBar, getState, getTitle, isResizable, isUndecorated, remove, removeNotify, setCursor, setExtendedState, setMaximizedBounds, setMenuBar, setResizable, setState, setUndecorated
 
Methods inherited from class java.awt.Window
addPropertyChangeListener, addPropertyChangeListener, addWindowFocusListener, addWindowListener, addWindowStateListener, applyResourceBundle, applyResourceBundle, createBufferStrategy, createBufferStrategy, getBufferStrategy, getFocusableWindowState, getFocusCycleRootAncestor, getFocusOwner, getFocusTraversalKeys, getGraphicsConfiguration, getIconImages, getInputContext, getListeners, getLocale, getModalExclusionType, getMostRecentFocusOwner, getOwnedWindows, getOwner, getOwnerlessWindows, getToolkit, getWarningString, getWindowFocusListeners, getWindowListeners, getWindows, getWindowStateListeners, hide, isActive, isAlwaysOnTop, isAlwaysOnTopSupported, isFocusableWindow, isFocusCycleRoot, isFocused, isLocationByPlatform, isShowing, pack, postEvent, removeWindowFocusListener, removeWindowListener, removeWindowStateListener, reshape, setAlwaysOnTop, setBounds, setBounds, setCursor, setFocusableWindowState, setFocusCycleRoot, setIconImages, setLocationByPlatform, setLocationRelativeTo, setMinimumSize, setModalExclusionType, setSize, toBack, toFront
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalPolicy, getInsets, getLayout, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, transferFocusBackward, transferFocusDownCycle, validate
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, contains, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, dispatchEvent, enable, enable, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getTreeLock, getWidth, getX, getY, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, prepareImage, prepareImage, printAll, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocusInWindow, resize, resize, setBackground, setComponentOrientation, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setName, setPreferredSize, show, size, toString, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.opensourcephysics.display.AppFrame
getDefaultCloseOperation
 
Methods inherited from interface java.awt.MenuContainer
getFont, postEvent
 

Constructor Detail

DrawingFrame

public DrawingFrame()
DrawingFrame constructor that creates a default DrawingPanel. The default DrawingPanel is an InteractivePanel.


DrawingFrame

public DrawingFrame(DrawingPanel drawingPanel)
DrawingFrame constructor specifying the DrawingPanel that will be placed in the center of the content pane.

Parameters:
drawingPanel -

DrawingFrame

public DrawingFrame(java.lang.String title,
                    DrawingPanel _drawingPanel)
DrawingFrame constructor specifying the title and the DrawingPanel that will be placed in the center of the content pane.

Parameters:
title -
_drawingPanel -
Method Detail

render

public void render()
Renders the drawing panel if the frame is showing and not iconified.

Overrides:
render in class OSPFrame

invalidateImage

public void invalidateImage()
Invalidates image buffers if a drawing panel buffered.

Overrides:
invalidateImage in class OSPFrame

getDrawingPanel

public DrawingPanel getDrawingPanel()
Gets the drawing panel.

Returns:
the drawingPanel

setXLabel

public void setXLabel(java.lang.String label)
Sets the label for the X (horizontal) axis.

Parameters:
label - the label

setYLabel

public void setYLabel(java.lang.String label)
Sets the label for the Y (vertical) axis.

Parameters:
label - the label

setPolar

public void setPolar(java.lang.String plotTitle,
                     double deltaR)
Converts to polar coordinates.

Parameters:
plotTitle - String
deltaR - double

setCartesian

public void setCartesian(java.lang.String xLabel,
                         java.lang.String yLabel,
                         java.lang.String plotTitle)
Converts to cartesian coordinates.

Parameters:
xLabel - String
yLabel - String
plotTitle - String

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 value
ceil - 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 value
ceil - the yceil value

setAutoscaleX

public void setAutoscaleX(boolean autoscale)
Autoscale the drawing panel's x axis using min and max values. from measurable objects.

Parameters:
autoscale -

isAutoscaleX

public boolean isAutoscaleX()
Determines if the panel's 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.

setSquareAspect

public void setSquareAspect(boolean isSquare)
Sets the aspect ratio for horizontal to vertical to unity when true<\code>.

Parameters:
isSquare - boolean

setLogScale

public void setLogScale(boolean logX,
                        boolean logY)
Sets Cartesian axes to log scale.

Parameters:
logX -
logY -

setPixelsPerUnit

public void setPixelsPerUnit(boolean enable,
                             double xPixPerUnit,
                             double yPixPerUnit)
Sets the scale using pixels per unit.

Parameters:
enable - boolean enable fixed pixels per unit
xPixPerUnit - double
yPixPerUnit - double

setPreferredMinMax

public void setPreferredMinMax(double xmin,
                               double xmax,
                               double ymin,
                               double ymax)
Sets the drawing panel's preferred scale.

Parameters:
xmin -
xmax -
ymin -
ymax -

setPreferredMinMaxY

public void setPreferredMinMaxY(double ymin,
                                double ymax)
Sets the drawing panel's preferred scale in the vertical direction.

Parameters:
ymin -
ymax -

setPreferredMinMaxX

public void setPreferredMinMaxX(double xmin,
                                double xmax)
Sets the drawing panel's preferred scale in the horizontal direction.

Parameters:
xmin - the minimum value
xmax - the maximum value

clearDataAndRepaint

public void clearDataAndRepaint()
Clears data and repaints the drawing panel within this frame.

Overrides:
clearDataAndRepaint in class OSPFrame

clearDrawables

public void clearDrawables()
Clears Drawable objects added by the user from this frame.


addDrawable

public void addDrawable(Drawable drawable)
Adds a drawable object to the frame's drawing panel.

Parameters:
drawable -

replaceDrawable

public void replaceDrawable(Drawable oldDrawable,
                            Drawable newDrawable)
Replaces a Drawable object with another Drawable.

Parameters:
oldDrawable - Drawable
newDrawable - Drawable

removeDrawable

public void removeDrawable(Drawable drawable)
Removes a drawable object to the frame's drawing panel.

Parameters:
drawable -

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 at the given location. location 0=bottom left location 1=bottom right location 2=top right location 3=top left

Parameters:
msg -
location -

getObjectOfClass

public <T extends Drawable> java.util.ArrayList<T> getObjectOfClass(java.lang.Class<T> c)
Gets objects of a specific class from the drawing panel. 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

getDrawables

public java.util.ArrayList<Drawable> getDrawables()
Gets Drawable previously objects added by the user.

Returns:
the list

getAxes

public DrawableAxes getAxes()

getDrawables

public <T extends Drawable> java.util.ArrayList<T> getDrawables(java.lang.Class<T> c)
Gets Drawable objects added by the user of an assignable type. The list contains objects that are assignable from the class or interface.

Parameters:
c - the type of Drawable object
Returns:
the cloned list
See Also:
getObjectOfClass(Class c)

removeObjectsOfClass

public <T extends Drawable> void removeObjectsOfClass(java.lang.Class<T> 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

setInteractiveMouseHandler

public void setInteractiveMouseHandler(InteractiveMouseHandler handler)
Sets the interactive mouse handler if the drawing panel is an interactive panel. Throws an invalid cast exception if the panel is not of the correct type.

Parameters:
handler - the mouse handler

setDrawingPanel

public void setDrawingPanel(DrawingPanel _drawingPanel)
Adds the drawing panel to the the frame. The panel is added to the center of the frame's content pane.

Parameters:
_drawingPanel -

setInteriorBackground

public void setInteriorBackground(java.awt.Color color)
Sets the interior background color for the current drawing panel. The interior of a PlottingaPanel is the area inside the axes where is displayed. The interior of a DrawingPanel is the entire panel.


paint

public void paint(java.awt.Graphics g)
This is a hack to fix a bug when the reload button is pressed in browsers running JDK 1.4.

Overrides:
paint in class java.awt.Window
Parameters:
g -

setEnabledPaste

public void setEnabledPaste(boolean enable)
Enables the paste edit menu item.

Parameters:
enable - boolean

setEnabledReplace

public void setEnabledReplace(boolean enable)
Enables the replace edit menu item.

Parameters:
enable - boolean

replaceAction

public void replaceAction(XMLControlElement control)
Replaces the drawables with the drawables found in the specified XML control.

Parameters:
control - XMLControlElement

lostOwnership

public void lostOwnership(java.awt.datatransfer.Clipboard clipboard,
                          java.awt.datatransfer.Transferable contents)
Implementation of ClipboardOwner interface. Override this method to receive notification that data copied to the clipboard has changed.

Specified by:
lostOwnership in interface java.awt.datatransfer.ClipboardOwner
Parameters:
clipboard - Clipboard
contents - Transferable

setEnabledCopy

public void setEnabledCopy(boolean enable)
Enables the copy edit menu item.

Parameters:
enable - boolean

setCustomInspector

public void setCustomInspector(java.awt.Window w)
Sets a custom properties inspector window.

Parameters:
w - the new inspector window

inspectXML

public void inspectXML()
Inspects the drawing frame by using an xml document tree.


saveXML

public void saveXML()

getLoader

public static XML.ObjectLoader getLoader()
Returns an XML.ObjectLoader to save and load data for this program.

Returns:
the object loader