JCanvas3DOB

com.interactivemesh.j3d.community.gui
Class JCanvas3DOBAbstract

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by javax.swing.JComponent
              extended by javax.swing.JPanel
                  extended by com.interactivemesh.j3d.community.gui.JCanvas3DOBAbstract
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, java.util.EventListener, javax.accessibility.Accessible, javax.swing.event.AncestorListener
Direct Known Subclasses:
JCanvas3DOB

public abstract class JCanvas3DOBAbstract
extends javax.swing.JPanel
implements javax.swing.event.AncestorListener

This class provides Java 3D rendering into a lightweight component which can be added to a Swing container.

It allows to run the Java 3D rendering loop in parallel to the Swing painting loop with synchronized minimal overlapping.

The following events will be redirected to the underlying heavyweight Canvas3D object:

Serialization: JCanvas3DOBAbstract does not support serialization.

Since:
Java 3D 1.5
See Also:
Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class javax.swing.JPanel
javax.swing.JPanel.AccessibleJPanel
 
Nested classes/interfaces inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Nested classes/interfaces inherited from class java.awt.Container
java.awt.Container.AccessibleAWTContainer
 
Nested classes/interfaces inherited from class java.awt.Component
java.awt.Component.AccessibleAWTComponent, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  int imageHeight
          The height of the image which Swing is drawing.
protected  int imageWidth
          The width of the image which Swing is drawing.
protected  java.awt.image.BufferedImage paintImage
          That image of the off-screen buffers which Swing is drawing.
 
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.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
protected JCanvas3DOBAbstract()
          Constructs and initializes a new JCanvas3DOBAbstract object that Java 3D can render into.
protected JCanvas3DOBAbstract(javax.media.j3d.GraphicsConfigTemplate3D template)
          Constructs and initializes a new JCanvas3DOBAbstract object that Java 3D can render into, using the specified template.
protected JCanvas3DOBAbstract(javax.media.j3d.GraphicsConfigTemplate3D template, java.awt.GraphicsDevice device)
          Constructs and initializes a new JCanvas3DOBAbstract object that Java 3D can render into, using the specified template and graphics device.
protected JCanvas3DOBAbstract(java.awt.GraphicsDevice device)
          Constructs and initializes a new JCanvas3DOBAbstract object that Java 3D can render into, using the specified graphics device.
 
Method Summary
 void ancestorAdded(javax.swing.event.AncestorEvent event)
          Called when the source or one of its ancestors is made visible either by setVisible(true) being called or by its being added to the component hierarchy.
 void ancestorMoved(javax.swing.event.AncestorEvent event)
          Called when either the source or one of its ancestors is moved.
 void ancestorRemoved(javax.swing.event.AncestorEvent event)
          Called when the source or one of its ancestors is made invisible either by setVisible(false) being called or by its being remove from the component hierarchy.
protected  void createOffScreenBuffer(int width, int height)
          Creates new off-screen buffers of the given size.
 javax.media.j3d.Canvas3D getOffscreenCanvas3D()
          Returns the off-screen heavyweight canvas of this lightweight component.
protected  boolean isReadyForDrawing()
          Subclasses which overrides paintComponent(Graphics g) should check if the off-screen buffer is ready for drawing.
protected  void offScreenBufferCopied()
          Callback used to allow an overriding subclass to execute individual code when the off-screen buffers were copied.
protected  void offScreenBufferCreated()
          Callback used to allow an overriding subclass to execute individual code when new off-screen buffers were created.
 void paintComponent(java.awt.Graphics g)
          Flips and paints the result of the 3D rendering.
protected  void processComponentKeyEvent(java.awt.event.KeyEvent e)
          Redirects event to canvas and to superclass.
protected  void processFocusEvent(java.awt.event.FocusEvent e)
          Redirects event to canvas and to superclass.
protected  void processInputMethodEvent(java.awt.event.InputMethodEvent e)
          Redirects event to canvas and to superclass.
protected  void processKeyEvent(java.awt.event.KeyEvent e)
          Redirects event to canvas and to superclass.
protected  void processMouseEvent(java.awt.event.MouseEvent e)
          Redirects event to canvas and to superclass.
protected  void processMouseMotionEvent(java.awt.event.MouseEvent e)
          Redirects event to canvas and to superclass.
protected  void processMouseWheelEvent(java.awt.event.MouseWheelEvent e)
          Redirects event to canvas and to superclass.
 void setBounds(int x, int y, int width, int height)
          
 
Methods inherited from class javax.swing.JPanel
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, disable, enable, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getActionForKeyStroke, getActionMap, getAlignmentX, getAlignmentY, getAncestorListeners, getAutoscrolls, 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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processKeyBinding, 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, update
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getLayout, getMousePosition, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, minimumSize, paintComponents, preferredSize, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setComponentZOrder, setFocusCycleRoot, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setLayout, 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, 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, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hasFocus, hide, 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, processHierarchyBoundsEvent, processHierarchyEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setFocusable, setFocusTraversalKeysEnabled, setIgnoreRepaint, 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
 

Field Detail

paintImage

protected java.awt.image.BufferedImage paintImage
That image of the off-screen buffers which Swing is drawing.

See Also:
paintComponent(Graphics)

imageWidth

protected volatile int imageWidth
The width of the image which Swing is drawing.


imageHeight

protected volatile int imageHeight
The height of the image which Swing is drawing.

Constructor Detail

JCanvas3DOBAbstract

protected JCanvas3DOBAbstract()
Constructs and initializes a new JCanvas3DOBAbstract object that Java 3D can render into. The screen device is obtained from GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(), which might not be the one you should use if you are in a multiscreen environment. The JCanvas3DOBAbstract is constructed using the following default parameters:
double buffer enable : false
stereo enable : false


JCanvas3DOBAbstract

protected JCanvas3DOBAbstract(java.awt.GraphicsDevice device)
Constructs and initializes a new JCanvas3DOBAbstract object that Java 3D can render into, using the specified graphics device.

Parameters:
device - the screen graphics device that will be used to construct a GraphicsConfiguration.

JCanvas3DOBAbstract

protected JCanvas3DOBAbstract(javax.media.j3d.GraphicsConfigTemplate3D template)
Constructs and initializes a new JCanvas3DOBAbstract object that Java 3D can render into, using the specified template. The screen device is obtained from GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice(), which might not be the one you should use if you are in a multiscreen environment.

Parameters:
template - The template that will be used to construct a GraphicsConfiguration. The stereo and doublebuffer properties are forced to UNNECESSARY.

JCanvas3DOBAbstract

protected JCanvas3DOBAbstract(javax.media.j3d.GraphicsConfigTemplate3D template,
                              java.awt.GraphicsDevice device)
Constructs and initializes a new JCanvas3DOBAbstract object that Java 3D can render into, using the specified template and graphics device.

Parameters:
template - The template that will be used to construct a GraphicsConfiguration. The stereo and doublebuffer properties are forced to UNNECESSARY.
device - the screen graphics device that will be used to construct a GraphicsConfiguration in conjunction with the template.
Method Detail

ancestorAdded

public void ancestorAdded(javax.swing.event.AncestorEvent event)
Called when the source or one of its ancestors is made visible either by setVisible(true) being called or by its being added to the component hierarchy. The method is only called if the source has actually become visible. For this to be true all its parents must be visible and it must be in a hierarchy rooted at a Window.

Specified by:
ancestorAdded in interface javax.swing.event.AncestorListener
Parameters:
event -

ancestorMoved

public void ancestorMoved(javax.swing.event.AncestorEvent event)
Called when either the source or one of its ancestors is moved.

Specified by:
ancestorMoved in interface javax.swing.event.AncestorListener
Parameters:
event -

ancestorRemoved

public void ancestorRemoved(javax.swing.event.AncestorEvent event)
Called when the source or one of its ancestors is made invisible either by setVisible(false) being called or by its being remove from the component hierarchy. The method is only called if the source has actually become invisible. For this to be true at least one of its parents must by invisible or it is not in a hierarchy rooted at a Window.

Specified by:
ancestorRemoved in interface javax.swing.event.AncestorListener
Parameters:
event -

getOffscreenCanvas3D

public javax.media.j3d.Canvas3D getOffscreenCanvas3D()
Returns the off-screen heavyweight canvas of this lightweight component. No canvas is created if this component has no parent, that is, was not added to a container.

Returns:
the heavyweight canvas that lies in the deepness of this Component.

setBounds

public void setBounds(int x,
                      int y,
                      int width,
                      int height)

Overrides:
setBounds in class java.awt.Component
Parameters:
x -
y -
width -
height -

createOffScreenBuffer

protected void createOffScreenBuffer(int width,
                                     int height)
Creates new off-screen buffers of the given size. This method is called internally whenever this panel is added to a parent or is resized.

Subclasses should call and/or override this method according to its individual needs. In case of overriding calling super.createOffScreenBuffer(canvasWidth, canvasHeight) has to be the last thing to do.

Parameters:
width - the width of the off-screen buffers to create
height - the height of the off-screen buffers to create

offScreenBufferCreated

protected void offScreenBufferCreated()
Callback used to allow an overriding subclass to execute individual code when new off-screen buffers were created.

This method is called internally by the event-dispatching thread (EDT) and should not be called by applications.


offScreenBufferCopied

protected void offScreenBufferCopied()
Callback used to allow an overriding subclass to execute individual code when the off-screen buffers were copied.

This method is called internally by the event-dispatching thread (EDT) and should not be called by applications.


isReadyForDrawing

protected final boolean isReadyForDrawing()
Subclasses which overrides paintComponent(Graphics g) should check if the off-screen buffer is ready for drawing.

Returns:
true if off-screen buffer can be drawn

paintComponent

public void paintComponent(java.awt.Graphics g)
Flips and paints the result of the 3D rendering.

Overrides:
paintComponent in class javax.swing.JComponent
Parameters:
g -

processComponentKeyEvent

protected void processComponentKeyEvent(java.awt.event.KeyEvent e)
Redirects event to canvas and to superclass.

Overrides:
processComponentKeyEvent in class javax.swing.JComponent
Parameters:
e -

processFocusEvent

protected void processFocusEvent(java.awt.event.FocusEvent e)
Redirects event to canvas and to superclass.

Overrides:
processFocusEvent in class java.awt.Component
Parameters:
e -

processInputMethodEvent

protected void processInputMethodEvent(java.awt.event.InputMethodEvent e)
Redirects event to canvas and to superclass.

Overrides:
processInputMethodEvent in class java.awt.Component
Parameters:
e -

processKeyEvent

protected void processKeyEvent(java.awt.event.KeyEvent e)
Redirects event to canvas and to superclass.

Overrides:
processKeyEvent in class javax.swing.JComponent
Parameters:
e -

processMouseEvent

protected void processMouseEvent(java.awt.event.MouseEvent e)
Redirects event to canvas and to superclass.

Overrides:
processMouseEvent in class javax.swing.JComponent
Parameters:
e -

processMouseMotionEvent

protected void processMouseMotionEvent(java.awt.event.MouseEvent e)
Redirects event to canvas and to superclass.

Overrides:
processMouseMotionEvent in class javax.swing.JComponent
Parameters:
e -

processMouseWheelEvent

protected void processMouseWheelEvent(java.awt.event.MouseWheelEvent e)
Redirects event to canvas and to superclass.

Overrides:
processMouseWheelEvent in class java.awt.Component
Parameters:
e -

JCanvas3DOB