public abstract class JCanvas3DAbstract
extends javax.swing.JPanel
implements javax.swing.event.AncestorListener
This class provides J3D rendering into a lightweight component which can be added to a Swing container.
It allows to run the J3D rendering loop in parallel to the Swing painting loop with synchronized minimal overlap.
The following events will be redirected to the underlying heavyweight Canvas3D object:
Serialization: JCancas3DDLAbstract does not support serialization.
javax.swing.JPanel.AccessibleJPanel
javax.swing.JComponent.AccessibleJComponent
Modifier and Type | Field and Description |
---|---|
protected java.util.concurrent.locks.ReentrantLock |
imageAccessLock
Synchronized offscreen image access.
|
protected int |
imageHeight
Height of the image which Swing is drawing.
|
protected java.util.concurrent.locks.Condition |
imagePaintCondition
Synchronized offscreen image access.
|
protected int |
imageWidth
Width of the image which Swing is drawing.
|
protected boolean |
isImageDrawn
Synchronized offscreen image access.
|
protected boolean |
isSync
Synchronized J3D and Swing render loops.
|
protected boolean |
isYup
Native offscreen image is yUp (J3D 1.5.2) or yDown (J3D 1.5.2u1).
|
protected java.awt.image.BufferedImage |
paintImage
Image of the offscreen buffer which Swing is drawing.
|
protected java.util.concurrent.locks.Condition |
syncCondition
Synchronized J3D and Swing render loops.
|
protected java.util.concurrent.locks.ReentrantLock |
syncLock
Synchronized J3D and Swing render loops.
|
accessibleContext, listenerList, TOOL_TIP_TEXT_KEY, ui, UNDEFINED_CONDITION, WHEN_ANCESTOR_OF_FOCUSED_COMPONENT, WHEN_FOCUSED, WHEN_IN_FOCUSED_WINDOW
Modifier | Constructor and Description |
---|---|
protected |
JCanvas3DAbstract()
Constructs and initializes a new JCancas3DDLAbstract object that J3D
can render into.
|
protected |
JCanvas3DAbstract(GraphicsConfigTemplate3D template)
Constructs and initializes a new JCancas3DDLAbstract object that J3D
can render into, using the specified template.
|
protected |
JCanvas3DAbstract(GraphicsConfigTemplate3D template,
java.awt.GraphicsDevice device)
Constructs and initializes a new JCancas3DDLAbstract object that J3D
can render into, using the specified template and graphics device.
|
protected |
JCanvas3DAbstract(java.awt.GraphicsDevice device)
Constructs and initializes a new JCancas3DDLAbstract object that J3D
can render into, using the specified graphics device.
|
Modifier and Type | Method and Description |
---|---|
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 offscreen buffers of the given size.
|
Canvas3D |
getOffscreenCanvas3D()
Returns the offscreen heavyweight canvas of this lightweight component.
|
protected boolean |
isReadyForDrawing()
Subclasses which overrides
paintComponent(Graphics g)
should check if the offscreen buffer is ready for drawing. |
protected void |
onOffScreenBufferCopied()
Callback used to allow an overriding subclass to execute individual code
when the offscreen buffer is copied.
|
protected void |
onOffScreenBufferCreated()
Callback used to allow an overriding subclass to execute individual code
when a new offscreen buffer is created.
|
void |
paintComponent(java.awt.Graphics g)
Just calls
super.paintComponent(g) , overriding subclasses
have to provide code to draw the offscreen image (see JCanvas3DDL). |
protected void |
processComponentEvent(java.awt.event.ComponentEvent 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 |
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)
Moves and resizes this component and creates a new offscreen buffer.
|
getAccessibleContext, getUI, getUIClassID, paramString, setUI, updateUI
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, isDoubleBuffered, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingForPrint, isPaintingOrigin, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, print, printAll, printBorder, printChildren, printComponent, processComponentKeyEvent, 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
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, transferFocusDownCycle, validate, validateTree
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, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, 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, transferFocusBackward, transferFocusUpCycle
protected java.awt.image.BufferedImage paintImage
paintComponent(Graphics)
protected volatile int imageWidth
protected volatile int imageHeight
protected java.util.concurrent.locks.ReentrantLock imageAccessLock
protected java.util.concurrent.locks.Condition imagePaintCondition
protected volatile boolean isImageDrawn
protected java.util.concurrent.locks.ReentrantLock syncLock
protected java.util.concurrent.locks.Condition syncCondition
protected volatile boolean isSync
protected volatile boolean isYup
protected JCanvas3DAbstract()
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
,
which might not be the one you should use if you are in a multiscreen environment.
The JCancas3DDLAbstract is constructed using the following default parameters:
double buffer enable : false
stereo enable : false
protected JCanvas3DAbstract(java.awt.GraphicsDevice device)
device
- the screen graphics device that will be used to construct
a GraphicsConfiguration.protected JCanvas3DAbstract(GraphicsConfigTemplate3D template)
GraphicsEnvironment.getLocalGraphicsEnvironment().getDefaultScreenDevice()
,
which might not be the one you should use if you are in a multiscreen environment.template
- The template that will be used to construct a
GraphicsConfiguration. The stereo property is forced to UNNECESSARY.protected JCanvas3DAbstract(GraphicsConfigTemplate3D template, java.awt.GraphicsDevice device)
template
- The template that will be used to construct a
GraphicsConfiguration. The stereo property is forced to UNNECESSARY.device
- the screen graphics device that will be used to construct
a GraphicsConfiguration in conjunction with the template.public void ancestorAdded(javax.swing.event.AncestorEvent event)
ancestorAdded
in interface javax.swing.event.AncestorListener
event
- public void ancestorMoved(javax.swing.event.AncestorEvent event)
ancestorMoved
in interface javax.swing.event.AncestorListener
event
- public void ancestorRemoved(javax.swing.event.AncestorEvent event)
ancestorRemoved
in interface javax.swing.event.AncestorListener
event
- public Canvas3D getOffscreenCanvas3D()
No canvas is created if this component has no parent, that is, was not added to a container.
public void setBounds(int x, int y, int width, int height)
setBounds
in class java.awt.Component
x
- the new x-coordinate of this componenty
- the new y-coordinate of this componentwidth
- the new width of this componentheight
- the new height of this componentprotected void createOffScreenBuffer(int width, int height)
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.
width
- the width of the offscreen buffers to createheight
- the height of the offscreen buffers to createprotected void onOffScreenBufferCreated()
This method is called internally on the event-dispatching thread (EDT) and should not be called by applications.
protected void onOffScreenBufferCopied()
This method is called internally on the event-dispatching thread (EDT) and should not be called by applications.
protected final boolean isReadyForDrawing()
paintComponent(Graphics g)
should check if the offscreen buffer is ready for drawing.public void paintComponent(java.awt.Graphics g)
super.paintComponent(g)
, overriding subclasses
have to provide code to draw the offscreen image (see JCanvas3DDL).paintComponent
in class javax.swing.JComponent
g
- protected void processComponentEvent(java.awt.event.ComponentEvent e)
processComponentEvent
in class java.awt.Component
e
- protected void processFocusEvent(java.awt.event.FocusEvent e)
processFocusEvent
in class java.awt.Component
e
- protected void processKeyEvent(java.awt.event.KeyEvent e)
processKeyEvent
in class javax.swing.JComponent
e
- protected void processMouseEvent(java.awt.event.MouseEvent e)
processMouseEvent
in class javax.swing.JComponent
e
- protected void processMouseMotionEvent(java.awt.event.MouseEvent e)
processMouseMotionEvent
in class javax.swing.JComponent
e
- protected void processMouseWheelEvent(java.awt.event.MouseWheelEvent e)
processMouseWheelEvent
in class java.awt.Component
e
-