org.opensourcephysics.display3d.simple3d
Class DrawingPanel3D

java.lang.Object
  extended byjava.awt.Component
      extended byjava.awt.Container
          extended byjavax.swing.JComponent
              extended byjavax.swing.JPanel
                  extended byorg.opensourcephysics.display3d.simple3d.DrawingPanel3D
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, DrawingPanel3D, java.util.EventListener, java.awt.image.ImageObserver, org.opensourcephysics.display3d.core.interaction.InteractionSource, java.awt.MenuContainer, java.awt.print.Printable, Renderable, java.io.Serializable

public class DrawingPanel3D
extends javax.swing.JPanel
implements Renderable, DrawingPanel3D, java.awt.print.Printable, java.awt.event.ActionListener

Title: DrawingPanel3D

Description: The simple3D implementation of a DrawingPanel3D.

Interaction: The panel has only one target, the panel itself. If enabled, the panel issues MOUSE_ENTER, MOUSE_EXIT, MOUSE_MOVED, and MOUSE_DRAGGED InteractionEvents with target=null. When the ALT key is held, the panel also issues MOUSE_PRESSED, MOUSE_DRAGGED (again), and MOUSE_RELEASED InteractionEvents. In this second case, the getInfo() method of the event returns a double[3] with the coordinates of the point selected.

Even if the panel is disabled, the panel can be panned, zoomed and (in 3D modes) rotated and the elements in it can be enabled.

The interaction capabilities are not XML serialized.

Copyright: Open Source Physics project

See Also:
Serialized Form

Nested Class Summary
 
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
 
Nested classes inherited from class org.opensourcephysics.display3d.core.DrawingPanel3D
DrawingPanel3D.Loader
 
Field Summary
protected  TextPanel blMessageBox
           
protected  TextPanel brMessageBox
           
protected  org.opensourcephysics.display3d.simple3d.DrawingPanel3D.GlassPanel glassPanel
           
protected  OSPLayout glassPanelLayout
           
protected  TextPanel tlMessageBox
           
protected  TextPanel trMessageBox
           
protected  java.awt.Rectangle viewRect
           
 
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 org.opensourcephysics.display3d.core.DrawingPanel3D
BOTTOM_LEFT, BOTTOM_RIGHT, TARGET_PANEL, TOP_LEFT, TOP_RIGHT
 
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
DrawingPanel3D()
           
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent evt)
          Performs an action for the update timer by rendering a new background image
 void addElement(Element element)
          Adds an Element to this DrawingPanel3D.
 void addInteractionListener(org.opensourcephysics.display3d.core.interaction.InteractionListener listener)
           
 Camera getCamera()
          Provides the Camera object used to project the scene in 3D modes.
 java.awt.Component getComponent()
          Getting the pointer to the real JPanel in it
 java.util.ArrayList getElements()
          Gets the (cloned) list of Elements.
 org.opensourcephysics.display3d.core.interaction.InteractionTarget getInteractionTarget(int target)
           
static XML.ObjectLoader getLoader()
          Returns an XML.ObjectLoader to save and load object data.
 double getPreferredMaxX()
          Gets the preferred maximum in the X coordinate
 double getPreferredMaxY()
          Gets the preferred maximum in the Y coordinate
 double getPreferredMaxZ()
          Gets the preferred maximum in the Z coordinate
 double getPreferredMinX()
          Gets the preferred minimum in the X coordinate
 double getPreferredMinY()
          Gets the preferred minimum in the Y coordinate
 double getPreferredMinZ()
          Gets the preferred minimum in the Z coordinate
 VisualizationHints getVisualizationHints()
          Provides the list of visualization hints that the panel uses to display the 3D scene
 boolean isSquareAspect()
          Whether the panel tries to keep a square aspect.
 void paintComponent(java.awt.Graphics g)
          Paints the component by copying the offscreen image into the graphics context.
 int print(java.awt.Graphics g, java.awt.print.PageFormat pageFormat, int pageIndex)
           
 void removeAllElements()
          Removes all Elements from this DrawingPanel3D
 void removeElement(Element element)
          Removes an Element from this DrawingPanel3D
 void removeInteractionListener(org.opensourcephysics.display3d.core.interaction.InteractionListener listener)
           
 java.awt.image.BufferedImage render()
          Renders a representation of the object onscreen.
 java.awt.Image render(java.awt.Image image)
          Renders a representation of the object onto an image.
 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 setPreferredMinMax(double minX, double maxX, double minY, double maxY, double minZ, double maxZ)
          Sets the preferred extrema for the panel.
 void setSquareAspect(boolean square)
          Whether the panel should try to keep a square aspect.
 void zoomToFit()
          Sets the preferred min and max in each dimension so that all elements currently in the panel are visible.
 
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, setVisible, 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, setBounds, setBounds, 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
 
Methods inherited from interface org.opensourcephysics.display3d.core.DrawingPanel3D
repaint
 

Field Detail

trMessageBox

protected TextPanel trMessageBox

tlMessageBox

protected TextPanel tlMessageBox

brMessageBox

protected TextPanel brMessageBox

blMessageBox

protected TextPanel blMessageBox

glassPanel

protected org.opensourcephysics.display3d.simple3d.DrawingPanel3D.GlassPanel glassPanel

glassPanelLayout

protected OSPLayout glassPanelLayout

viewRect

protected java.awt.Rectangle viewRect
Constructor Detail

DrawingPanel3D

public DrawingPanel3D()
Method Detail

actionPerformed

public void actionPerformed(java.awt.event.ActionEvent evt)
Performs an action for the update timer by rendering a new background image

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
evt -

setIgnoreRepaint

public void setIgnoreRepaint(boolean ignoreRepaint)

paintComponent

public void paintComponent(java.awt.Graphics g)
Paints the component by copying the offscreen image into the graphics context.

Parameters:
g - Graphics

render

public java.awt.Image render(java.awt.Image image)
Description copied from interface: Renderable
Renders a representation of the object onto an image.

Specified by:
render in interface Renderable
Parameters:
image -
Returns:
the image buffer

render

public java.awt.image.BufferedImage render()
Description copied from interface: Renderable
Renders a representation of the object onscreen.

Specified by:
render in interface Renderable

getComponent

public java.awt.Component getComponent()
Description copied from interface: DrawingPanel3D
Getting the pointer to the real JPanel in it

Specified by:
getComponent in interface DrawingPanel3D
Returns:
JFrame

setPreferredMinMax

public void setPreferredMinMax(double minX,
                               double maxX,
                               double minY,
                               double maxY,
                               double minZ,
                               double maxZ)
Description copied from interface: DrawingPanel3D
Sets the preferred extrema for the panel. This resets the camera of the panel to its default.

Specified by:
setPreferredMinMax in interface DrawingPanel3D
Parameters:
minX - double
maxX - double
minY - double
maxY - double
minZ - double
maxZ - double
See Also:
Camera

getPreferredMinX

public final double getPreferredMinX()
Description copied from interface: DrawingPanel3D
Gets the preferred minimum in the X coordinate

Specified by:
getPreferredMinX in interface DrawingPanel3D
Returns:
double

getPreferredMaxX

public final double getPreferredMaxX()
Description copied from interface: DrawingPanel3D
Gets the preferred maximum in the X coordinate

Specified by:
getPreferredMaxX in interface DrawingPanel3D
Returns:
double

getPreferredMinY

public final double getPreferredMinY()
Description copied from interface: DrawingPanel3D
Gets the preferred minimum in the Y coordinate

Specified by:
getPreferredMinY in interface DrawingPanel3D
Returns:
double

getPreferredMaxY

public final double getPreferredMaxY()
Description copied from interface: DrawingPanel3D
Gets the preferred maximum in the Y coordinate

Specified by:
getPreferredMaxY in interface DrawingPanel3D
Returns:
double

getPreferredMinZ

public final double getPreferredMinZ()
Description copied from interface: DrawingPanel3D
Gets the preferred minimum in the Z coordinate

Specified by:
getPreferredMinZ in interface DrawingPanel3D
Returns:
double

getPreferredMaxZ

public final double getPreferredMaxZ()
Description copied from interface: DrawingPanel3D
Gets the preferred maximum in the Z coordinate

Specified by:
getPreferredMaxZ in interface DrawingPanel3D
Returns:
double

zoomToFit

public void zoomToFit()
Description copied from interface: DrawingPanel3D
Sets the preferred min and max in each dimension so that all elements currently in the panel are visible.

Specified by:
zoomToFit in interface DrawingPanel3D

setSquareAspect

public void setSquareAspect(boolean square)
Description copied from interface: DrawingPanel3D
Whether the panel should try to keep a square aspect. Default value is true.

Specified by:
setSquareAspect in interface DrawingPanel3D
Parameters:
square - boolean

isSquareAspect

public boolean isSquareAspect()
Description copied from interface: DrawingPanel3D
Whether the panel tries to keep a square aspect.

Specified by:
isSquareAspect in interface DrawingPanel3D
Returns:
boolean

getVisualizationHints

public VisualizationHints getVisualizationHints()
Description copied from interface: DrawingPanel3D
Provides the list of visualization hints that the panel uses to display the 3D scene

Specified by:
getVisualizationHints in interface DrawingPanel3D
Returns:
VisualizationHints
See Also:
VisualizationHints

getCamera

public Camera getCamera()
Description copied from interface: DrawingPanel3D
Provides the Camera object used to project the scene in 3D modes.

Specified by:
getCamera in interface DrawingPanel3D
Returns:
Camera
See Also:
Camera

addElement

public void addElement(Element element)
Description copied from interface: DrawingPanel3D
Adds an Element to this DrawingPanel3D.

Specified by:
addElement in interface DrawingPanel3D
Parameters:
element - Element
See Also:
Element

removeElement

public void removeElement(Element element)
Description copied from interface: DrawingPanel3D
Removes an Element from this DrawingPanel3D

Specified by:
removeElement in interface DrawingPanel3D
Parameters:
element - Element
See Also:
Element

removeAllElements

public void removeAllElements()
Description copied from interface: DrawingPanel3D
Removes all Elements from this DrawingPanel3D

Specified by:
removeAllElements in interface DrawingPanel3D
See Also:
Element

getElements

public java.util.ArrayList getElements()
Description copied from interface: DrawingPanel3D
Gets the (cloned) list of Elements. (Should be synchronized.)

Specified by:
getElements in interface DrawingPanel3D
Returns:
cloned list

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. The location must be one of the following:

Parameters:
msg -
location -

getInteractionTarget

public org.opensourcephysics.display3d.core.interaction.InteractionTarget getInteractionTarget(int target)
Specified by:
getInteractionTarget in interface org.opensourcephysics.display3d.core.interaction.InteractionSource

addInteractionListener

public void addInteractionListener(org.opensourcephysics.display3d.core.interaction.InteractionListener listener)
Specified by:
addInteractionListener in interface org.opensourcephysics.display3d.core.interaction.InteractionSource

removeInteractionListener

public void removeInteractionListener(org.opensourcephysics.display3d.core.interaction.InteractionListener listener)
Specified by:
removeInteractionListener in interface org.opensourcephysics.display3d.core.interaction.InteractionSource

print

public int print(java.awt.Graphics g,
                 java.awt.print.PageFormat pageFormat,
                 int pageIndex)
          throws java.awt.print.PrinterException
Specified by:
print in interface java.awt.print.Printable
Throws:
java.awt.print.PrinterException

getLoader

public static XML.ObjectLoader getLoader()
Returns an XML.ObjectLoader to save and load object data.

Returns:
the XML.ObjectLoader