Class DrawingPanel3D
java.lang.Object
java.awt.Component
java.awt.Container
javax.swing.JComponent
javax.swing.JPanel
org.opensourcephysics.display3d.simple3d.DrawingPanel3D
- All Implemented Interfaces:
ActionListener,ImageObserver,MenuContainer,Printable,Serializable,EventListener,Accessible,Renderable,DrawingPanel3D,InteractionSource
public class DrawingPanel3D
extends JPanel
implements Renderable, DrawingPanel3D, Printable, 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
- Version:
- June 2005
- Author:
- Francisco Esquembre
- See Also:
-
Nested Class Summary
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.FlipBufferStrategyNested classes/interfaces inherited from interface org.opensourcephysics.display3d.core.DrawingPanel3D
DrawingPanel3D.Loader -
Field Summary
FieldsModifier and TypeFieldDescriptionprotected MessageDrawableprotected VideoToolThe video capture tool for this panel.protected RectangleFields 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 org.opensourcephysics.display3d.core.DrawingPanel3D
AMBIENT_LIGHT, BACKGROUND, BOTTOM_LEFT, BOTTOM_RIGHT, DIRECTIONAL_LIGHT, MODE_XYZ, MODE_XZY, MODE_YXZ, MODE_YZX, MODE_ZXY, MODE_ZYX, POINT_LIGHT, SPOT_LIGHT, TARGET_PANEL, TOP_LEFT, TOP_RIGHTFields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTHFields inherited from interface java.awt.print.Printable
NO_SUCH_PAGE, PAGE_EXISTS -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionvoidPerforms an action for the update timer by rendering a new background imagevoidaddElement(Element element) Adds an Element to this DrawingPanel3D.voidaddInteractionListener(InteractionListener listener) Adds the specified interaction listener to receive interaction events to any of its targets from this source.intReturns the axes modeReturns the background imageProvides the Camera object used to project the scene in 3D modes.Getting the pointer to the real JPanel in itGets the (cloned) list of Elements.getInteractionTarget(int target) Gives access to one of the targets of this source.static XML.ObjectLoaderReturns an XML.ObjectLoader to save and load object data.final doubleGets the preferred maximum in the X coordinatefinal doubleGets the preferred maximum in the Y coordinatefinal doubleGets the preferred maximum in the Z coordinatefinal doubleGets the preferred minimum in the X coordinatefinal doubleGets the preferred minimum in the Y coordinatefinal doubleGets the preferred minimum in the Z coordinatedoubleGets the scale factor in the X axisdoubleGets the scale factor in the Y axisdoubleGets the scale factor in the Z axisGets the video capture tool.Provides the list of visualization hints that the panel uses to display the 3D scenevoidInvalidates this component.booleanWhether the panel tries to keep a square aspect.voidPaints the component by copying the offscreen image into the graphics context.intprint(Graphics g, PageFormat pageFormat, int pageIndex) voidRemoves all Elements from this DrawingPanel3DvoidremoveElement(Element element) Removes an Element from this DrawingPanel3DvoidremoveInteractionListener(InteractionListener listener) Removes the specified interaction listenerrender()Renders a representation of the object onscreen.render(BufferedImage image) Renders a representation of the object onto an image.voidsetAxesMode(int mode) Sets the axes modevoidsetBackgroundImage(String _imageFile) Sets the background imagevoidsetLightEnabled(boolean _state, int nlight) Enable disable a lightvoidsetMessage(String msg) Shows a message in a yellow text box in the lower right hand corner.voidsetMessage(String msg, int location) Shows a message in a yellow text box.voidsetPreferredMinMax(double minX, double maxX, double minY, double maxY, double minZ, double maxZ) Sets the preferred extrema for the panel.voidsetScaleFactor(double factorX, double factorY, double factorZ) Sets the scale factor of the scene in X,Y,Z axis.voidsetSquareAspect(boolean square) Whether the panel should try to keep a square aspect.voidsetVideoTool(VideoTool videoCap) Sets the video capture tool.voidSets 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, 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, getHeight, getInheritsPopupMenu, getInputMap, getInputMap, getInputVerifier, getInsets, getInsets, getListeners, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPopupLocation, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getTransferHandler, getVerifyInputWhenFocusTarget, getVetoableChangeListeners, getVisibleRect, getWidth, getX, getY, grabFocus, hide, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, 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, setVisible, 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, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, transferFocusDownCycle, validate, validateTreeMethods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addHierarchyBoundsListener, addHierarchyListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addMouseWheelListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, createVolatileImage, createVolatileImage, disableEvents, dispatchEvent, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getForeground, getGraphicsConfiguration, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, resize, resize, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, setLocale, setLocation, setLocation, setMixingCutoutShape, setName, setSize, setSize, show, show, size, toString, transferFocus, transferFocusBackward, transferFocusUpCycleMethods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, waitMethods inherited from interface org.opensourcephysics.display3d.core.DrawingPanel3D
repaint
-
Field Details
-
viewRect
-
messages
-
vidCap
The video capture tool for this panel.
-
-
Constructor Details
-
DrawingPanel3D
public DrawingPanel3D()Constructor DrawingPanel3D
-
-
Method Details
-
actionPerformed
Performs an action for the update timer by rendering a new background image- Specified by:
actionPerformedin interfaceActionListener- Parameters:
evt-
-
paintComponent
Paints the component by copying the offscreen image into the graphics context.- Overrides:
paintComponentin classJComponent- Parameters:
g- Graphics
-
invalidate
public void invalidate()Invalidates this component. This component and all parents above it are marked as needing to be laid out. This method can be called often, so it needs to execute quickly.- Overrides:
invalidatein classContainer- Since:
- JDK1.0
- See Also:
-
render
Description copied from interface:RenderableRenders a representation of the object onto an image.- Specified by:
renderin interfaceDrawingPanel3D- Specified by:
renderin interfaceRenderable- Parameters:
image- Image- Returns:
- the image buffer
-
render
Description copied from interface:RenderableRenders a representation of the object onscreen.- Specified by:
renderin interfaceDrawingPanel3D- Specified by:
renderin interfaceRenderable- Returns:
- BufferedImage the generated image
-
getComponent
Description copied from interface:DrawingPanel3DGetting the pointer to the real JPanel in it- Specified by:
getComponentin interfaceDrawingPanel3D- Returns:
- JFrame
-
setBackgroundImage
Description copied from interface:DrawingPanel3DSets the background image- Specified by:
setBackgroundImagein interfaceDrawingPanel3D
-
getBackgroundImage
Description copied from interface:DrawingPanel3DReturns the background image- Specified by:
getBackgroundImagein interfaceDrawingPanel3D
-
setPreferredMinMax
public void setPreferredMinMax(double minX, double maxX, double minY, double maxY, double minZ, double maxZ) Description copied from interface:DrawingPanel3DSets the preferred extrema for the panel. This resets the camera of the panel to its default.- Specified by:
setPreferredMinMaxin interfaceDrawingPanel3D- Parameters:
minX- doublemaxX- doubleminY- doublemaxY- doubleminZ- doublemaxZ- double- See Also:
-
getPreferredMinX
public final double getPreferredMinX()Description copied from interface:DrawingPanel3DGets the preferred minimum in the X coordinate- Specified by:
getPreferredMinXin interfaceDrawingPanel3D- Returns:
- double
-
getPreferredMaxX
public final double getPreferredMaxX()Description copied from interface:DrawingPanel3DGets the preferred maximum in the X coordinate- Specified by:
getPreferredMaxXin interfaceDrawingPanel3D- Returns:
- double
-
getPreferredMinY
public final double getPreferredMinY()Description copied from interface:DrawingPanel3DGets the preferred minimum in the Y coordinate- Specified by:
getPreferredMinYin interfaceDrawingPanel3D- Returns:
- double
-
getPreferredMaxY
public final double getPreferredMaxY()Description copied from interface:DrawingPanel3DGets the preferred maximum in the Y coordinate- Specified by:
getPreferredMaxYin interfaceDrawingPanel3D- Returns:
- double
-
getPreferredMinZ
public final double getPreferredMinZ()Description copied from interface:DrawingPanel3DGets the preferred minimum in the Z coordinate- Specified by:
getPreferredMinZin interfaceDrawingPanel3D- Returns:
- double
-
getPreferredMaxZ
public final double getPreferredMaxZ()Description copied from interface:DrawingPanel3DGets the preferred maximum in the Z coordinate- Specified by:
getPreferredMaxZin interfaceDrawingPanel3D- Returns:
- double
-
zoomToFit
public void zoomToFit()Description copied from interface:DrawingPanel3DSets the preferred min and max in each dimension so that all elements currently in the panel are visible.- Specified by:
zoomToFitin interfaceDrawingPanel3D
-
setSquareAspect
public void setSquareAspect(boolean square) Description copied from interface:DrawingPanel3DWhether the panel should try to keep a square aspect. Default value is true.- Specified by:
setSquareAspectin interfaceDrawingPanel3D- Parameters:
square- boolean
-
isSquareAspect
public boolean isSquareAspect()Description copied from interface:DrawingPanel3DWhether the panel tries to keep a square aspect.- Specified by:
isSquareAspectin interfaceDrawingPanel3D- Returns:
- boolean
-
getVisualizationHints
Description copied from interface:DrawingPanel3DProvides the list of visualization hints that the panel uses to display the 3D scene- Specified by:
getVisualizationHintsin interfaceDrawingPanel3D- Returns:
- VisualizationHints
- See Also:
-
getCamera
Description copied from interface:DrawingPanel3DProvides the Camera object used to project the scene in 3D modes.- Specified by:
getCamerain interfaceDrawingPanel3D- Returns:
- Camera
- See Also:
-
getVideoTool
Gets the video capture tool. May be null.- Specified by:
getVideoToolin interfaceDrawingPanel3D- Returns:
- the video capture tool
-
setVideoTool
Sets the video capture tool. May be set to null.- Specified by:
setVideoToolin interfaceDrawingPanel3D- Parameters:
videoCap- the video capture tool
-
addElement
Description copied from interface:DrawingPanel3DAdds an Element to this DrawingPanel3D.- Specified by:
addElementin interfaceDrawingPanel3D- Parameters:
element- Element- See Also:
-
removeElement
Description copied from interface:DrawingPanel3DRemoves an Element from this DrawingPanel3D- Specified by:
removeElementin interfaceDrawingPanel3D- Parameters:
element- Element- See Also:
-
removeAllElements
public void removeAllElements()Description copied from interface:DrawingPanel3DRemoves all Elements from this DrawingPanel3D- Specified by:
removeAllElementsin interfaceDrawingPanel3D- See Also:
-
getElements
Description copied from interface:DrawingPanel3DGets the (cloned) list of Elements. (Should be synchronized.)- Specified by:
getElementsin interfaceDrawingPanel3D- Returns:
- cloned list
-
setScaleFactor
public void setScaleFactor(double factorX, double factorY, double factorZ) Description copied from interface:DrawingPanel3DSets the scale factor of the scene in X,Y,Z axis.- Specified by:
setScaleFactorin interfaceDrawingPanel3D- Parameters:
factorX- doublefactorY- doublefactorZ- double
-
getScaleFactorX
public double getScaleFactorX()Description copied from interface:DrawingPanel3DGets the scale factor in the X axis- Specified by:
getScaleFactorXin interfaceDrawingPanel3D- Returns:
- double
-
getScaleFactorY
public double getScaleFactorY()Description copied from interface:DrawingPanel3DGets the scale factor in the Y axis- Specified by:
getScaleFactorYin interfaceDrawingPanel3D- Returns:
- double
-
getScaleFactorZ
public double getScaleFactorZ()Description copied from interface:DrawingPanel3DGets the scale factor in the Z axis- Specified by:
getScaleFactorZin interfaceDrawingPanel3D- Returns:
- double
-
setAxesMode
public void setAxesMode(int mode) Description copied from interface:DrawingPanel3DSets the axes mode- Specified by:
setAxesModein interfaceDrawingPanel3D- Parameters:
mode- int
-
getAxesMode
public int getAxesMode()Description copied from interface:DrawingPanel3DReturns the axes mode- Specified by:
getAxesModein interfaceDrawingPanel3D
-
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. The location must be one of the following:- DrawingPanel3D.BOTTOM_LEFT;
- DrawingPanel3D.BOTTOM_RIGHT;
- DrawingPanel3D.TOP_RIGHT;
- DrawingPanel3D.TOP_LEFT;
- Parameters:
msg-location-
-
getInteractionTarget
Description copied from interface:InteractionSourceGives access to one of the targets of this source. Sources should document the list of their available targets.- Specified by:
getInteractionTargetin interfaceInteractionSource- Parameters:
target- An integer number that identifies the target in the source.- Returns:
- InteractionTarget
-
addInteractionListener
Description copied from interface:InteractionSourceAdds the specified interaction listener to receive interaction events to any of its targets from this source.- Specified by:
addInteractionListenerin interfaceInteractionSource- Parameters:
listener- An object that implements the InteractionListener interface- See Also:
-
removeInteractionListener
Description copied from interface:InteractionSourceRemoves the specified interaction listener- Specified by:
removeInteractionListenerin interfaceInteractionSource- See Also:
-
print
- Specified by:
printin interfacePrintable- Throws:
PrinterException
-
setLightEnabled
public void setLightEnabled(boolean _state, int nlight) Description copied from interface:DrawingPanel3DEnable disable a light- Specified by:
setLightEnabledin interfaceDrawingPanel3D
-
getLoader
Returns an XML.ObjectLoader to save and load object data.- Returns:
- the XML.ObjectLoader
-