org.selman.java3d.book.swingtest
Class SwingTest

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--org.selman.java3d.book.swingtest.SwingTest
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.event.ActionListener, java.util.EventListener, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class SwingTest
extends javax.swing.JPanel
implements java.awt.event.ActionListener

This example displays a Swing based application with a JMenuBar that allows you to switch between displaying a Cube and a Sphere. You can also perform a simple screen capture and start/stop rotation using menu commands.

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
 
Field Summary
 
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
SwingTest()
          Constructor.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent ae)
          AWT callback to indicate that an items has been selected from a menu.
protected  void addCanvas3D(javax.media.j3d.Canvas3D c3d)
          Callback to allow the Canvas3D to be added to a Panel.
protected  void addViewBranchGroup(javax.media.j3d.Locale locale, javax.media.j3d.BranchGroup bg)
          Adds the View side of the scenegraph to the Locale
protected  javax.media.j3d.Bounds createApplicationBounds()
          Create a Bounds object for the scene.
protected  javax.media.j3d.Background createBackground()
          Create a Background for the Canvas3D.
protected  javax.media.j3d.Canvas3D createCanvas3D(boolean offscreen)
          Create a Canvas3D.
protected  javax.media.j3d.BranchGroup createCube()
          Create a BranchGroup that contains a Cube.
protected  javax.media.j3d.Locale createLocale(javax.media.j3d.VirtualUniverse u)
          Create a Locale for the VirtualUniverse
 javax.swing.JMenuBar createMenuBar()
           
protected  javax.media.j3d.Canvas3D createOffscreenCanvas3D()
          Initialize an offscreen Canvas3D.
protected  javax.media.j3d.PhysicalBody createPhysicalBody()
          Creates the PhysicalBody for the View
protected  javax.media.j3d.PhysicalEnvironment createPhysicalEnvironment()
          Creates the PhysicalEnvironment for the View
protected  javax.media.j3d.BranchGroup createSceneBranchGroup()
          Create the scene side of the scenegraph
protected  javax.media.j3d.BranchGroup createSphere()
          Create a BranchGroup that contains a Sphere.
protected  javax.media.j3d.View createView(javax.media.j3d.ViewPlatform vp)
          Create a Java 3D View and attach it to a ViewPlatform
protected  javax.media.j3d.BranchGroup createViewBranchGroup(javax.media.j3d.TransformGroup[] tgArray, javax.media.j3d.ViewPlatform vp)
          Creates the View side BranchGroup.
protected  javax.media.j3d.ViewPlatform createViewPlatform()
          Creates the View Platform for the View
protected  javax.media.j3d.VirtualUniverse createVirtualUniverse()
          Creates the VirtualUniverse for the application.
protected  double getBackClipDistance()
          Returns the distance to the rear clipping plane.
protected  double getFrontClipDistance()
          Returns the distance to the near clipping plane.
protected  double getScale()
          Callback to get the scale factor for the View side of the scenegraph
protected  float getViewPlatformActivationRadius()
          Returns the View Platform Activation Radius
 javax.media.j3d.TransformGroup[] getViewTransformGroupArray()
          Get the TransformGroup for the View side of the scenegraph
protected  void init()
          Initialize the Java 3D rendering system and view side scenegraph.
static void main(java.lang.String[] args)
          main entry point for the application.
protected  void onSaveImage()
          Called to render the scene into the offscreen Canvas3D and save the image (as a JPEG) to disk.
protected static void registerWindowListener(javax.swing.JFrame frame)
           
protected  void removeShape(java.lang.String name)
          Removes a BranchGroup from the scene based on user data
 
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, paintComponent, 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, 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
 

Constructor Detail

SwingTest

public SwingTest()
Constructor. Set the layout algorithm for the panel and initialize the Java 3D rendering system and view side scenegraph.

Method Detail

init

protected void init()
Initialize the Java 3D rendering system and view side scenegraph.


addCanvas3D

protected void addCanvas3D(javax.media.j3d.Canvas3D c3d)
Callback to allow the Canvas3D to be added to a Panel.


createView

protected javax.media.j3d.View createView(javax.media.j3d.ViewPlatform vp)
Create a Java 3D View and attach it to a ViewPlatform


createBackground

protected javax.media.j3d.Background createBackground()
Create a Background for the Canvas3D.


createApplicationBounds

protected javax.media.j3d.Bounds createApplicationBounds()
Create a Bounds object for the scene.


createCanvas3D

protected javax.media.j3d.Canvas3D createCanvas3D(boolean offscreen)
Create a Canvas3D.

Parameters:
offscreen - true to specify an offscreen canvas

createOffscreenCanvas3D

protected javax.media.j3d.Canvas3D createOffscreenCanvas3D()
Initialize an offscreen Canvas3D.


getScale

protected double getScale()
Callback to get the scale factor for the View side of the scenegraph


getViewTransformGroupArray

public javax.media.j3d.TransformGroup[] getViewTransformGroupArray()
Get the TransformGroup for the View side of the scenegraph


addViewBranchGroup

protected void addViewBranchGroup(javax.media.j3d.Locale locale,
                                  javax.media.j3d.BranchGroup bg)
Adds the View side of the scenegraph to the Locale


createLocale

protected javax.media.j3d.Locale createLocale(javax.media.j3d.VirtualUniverse u)
Create a Locale for the VirtualUniverse


createSceneBranchGroup

protected javax.media.j3d.BranchGroup createSceneBranchGroup()
Create the scene side of the scenegraph


createCube

protected javax.media.j3d.BranchGroup createCube()
Create a BranchGroup that contains a Cube. The user data for the BranchGroup is set so the BranchGroup can be identified.


createSphere

protected javax.media.j3d.BranchGroup createSphere()
Create a BranchGroup that contains a Sphere. The user data for the BranchGroup is set so the BranchGroup can be identified.


removeShape

protected void removeShape(java.lang.String name)
Removes a BranchGroup from the scene based on user data

Parameters:
name - the user data to look for

createPhysicalBody

protected javax.media.j3d.PhysicalBody createPhysicalBody()
Creates the PhysicalBody for the View


createPhysicalEnvironment

protected javax.media.j3d.PhysicalEnvironment createPhysicalEnvironment()
Creates the PhysicalEnvironment for the View


getViewPlatformActivationRadius

protected float getViewPlatformActivationRadius()
Returns the View Platform Activation Radius


createViewPlatform

protected javax.media.j3d.ViewPlatform createViewPlatform()
Creates the View Platform for the View


getBackClipDistance

protected double getBackClipDistance()
Returns the distance to the rear clipping plane.


getFrontClipDistance

protected double getFrontClipDistance()
Returns the distance to the near clipping plane.


createViewBranchGroup

protected javax.media.j3d.BranchGroup createViewBranchGroup(javax.media.j3d.TransformGroup[] tgArray,
                                                            javax.media.j3d.ViewPlatform vp)
Creates the View side BranchGroup. The ViewPlatform is wired in beneath the TransformGroups.


createVirtualUniverse

protected javax.media.j3d.VirtualUniverse createVirtualUniverse()
Creates the VirtualUniverse for the application.


onSaveImage

protected void onSaveImage()
Called to render the scene into the offscreen Canvas3D and save the image (as a JPEG) to disk.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent ae)
AWT callback to indicate that an items has been selected from a menu.

Specified by:
actionPerformed in interface java.awt.event.ActionListener

registerWindowListener

protected static void registerWindowListener(javax.swing.JFrame frame)

createMenuBar

public javax.swing.JMenuBar createMenuBar()

main

public static void main(java.lang.String[] args)
main entry point for the application. Creates the parent JFrame, the JMenuBar and creates the JPanel which is the application itself.