Renderer
Class Sandbox

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--javax.swing.JPanel
                          |
                          +--Renderer.Sandbox
All Implemented Interfaces:
javax.accessibility.Accessible, java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable

public class Sandbox
extends javax.swing.JPanel

Defines the graphical equivalent of a "world" full of "objects." It is a three-dimensional, interactive container for any number toys. The user can fly around the sandbox, view its contents from any perspective, select toys to view their history through the system, etc.

A Sandbox resides in a Playground with any number of other Sandboxes. Each depicts a slightly different interpretation of the source-text description. They can be viewed independently or synchronized.

Version:
Created 17 February 2003
Author:
Dan Tappan
See Also:
SandboxController, Attitude, ModelLibrary, Position, Toy, Playground, Serialized Form

Field Summary
private  Toy m_active_toy
           
private  SnapCanvas3D m_canvas
           
private  ModelLibrary m_model_library
           
private  MonteCarloRunSet m_monte_carlo_run_set
           
private  java.lang.String m_name
           
private  Playground m_playground
           
private  javax.media.j3d.BranchGroup m_root_branch_group
           
private  SandboxController m_sandbox_controller
           
private  java.util.Hashtable m_toys
           
private  com.sun.j3d.utils.universe.SimpleUniverse m_universe
           
private  float WORLD_GRID_SPACING
           
private  float WORLD_PEDESTAL_HEIGHT
           
private  float WORLD_PEDESTAL_OFFSET
           
protected static float WORLD_PEDESTAL_RADIUS
           
 
Fields inherited from class javax.swing.JPanel
 
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.Container
 
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
Sandbox(java.lang.String name, ModelLibrary model_library, Playground playground, MonteCarloRunSet monte_carlo_run_set, boolean is_wireframe, int instantiation_key)
          Creates a new sandbox.
 
Method Summary
 Toy addToy(java.lang.String toy_name, java.lang.String model_name, boolean is_wireframe, float transparency, javax.vecmath.Color3f override_color)
          Creates and adds a toy to this sandbox.
private  javax.media.j3d.BranchGroup buildSandboxPedestal(boolean is_wireframe)
          Builds the sandbox pedestal on which the entire "world" resides.
 void commit()
          Commits the contents of this sandbox to remain static.
 MonteCarloRunSet getMonteCarloRunSet()
          Returns the Monte Carlo run set defining the contents of this sandbox.
 java.lang.String getName()
          Returns the name of this sandbox.
 Toy getToy(java.lang.String name)
          Returns a toy.
 int getToyCount()
          Returns the number of toys in this sandbox.
 java.util.Enumeration getToyNames()
          Returns a list of the names of all toys in this sandbox.
 Attitude getViewerAttitude()
          Returns the combined attitude of the field of view and the head of the viewer in this sandbox.
 Attitude getViewerFieldOfViewAttitude()
          Returns the attitude of the field of view of the viewer in this sandbox.
 Attitude getViewerHeadAttitude()
          Returns the attitude of the head of the viewer in this sandbox.
 Position getViewerPosition()
          Returns the position of the viewer in this sandbox.
protected  void normalizeToyInteractively(int modifier_code, int key_code)
          Implements a semi-hardcoded editor to normalize the position, scaling, and dimensions of models within a standard frame.
protected  void processSelectionCallback(java.lang.String selection_identifier, java.awt.event.MouseEvent event)
          Handles a selection callback from the SandboxController in charge of this sandbox.
protected  void processSynchronizationCallback()
          Handles a synchronization callback from the SandboxController in charge of this sandbox.
 void setSize(int width, int height)
          Sets the size of the panel on which the SnapCanvas3D is located.
 java.lang.String toString()
          Returns a string representation of this object.
 void update()
          Updates this sandbox and all Toys in it.
 
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, 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, show, show, size, transferFocus, transferFocusUpCycle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

WORLD_PEDESTAL_RADIUS

protected static float WORLD_PEDESTAL_RADIUS

WORLD_PEDESTAL_HEIGHT

private float WORLD_PEDESTAL_HEIGHT

WORLD_PEDESTAL_OFFSET

private float WORLD_PEDESTAL_OFFSET

WORLD_GRID_SPACING

private float WORLD_GRID_SPACING

m_name

private java.lang.String m_name

m_toys

private java.util.Hashtable m_toys

m_root_branch_group

private javax.media.j3d.BranchGroup m_root_branch_group

m_canvas

private SnapCanvas3D m_canvas

m_sandbox_controller

private SandboxController m_sandbox_controller

m_model_library

private ModelLibrary m_model_library

m_universe

private com.sun.j3d.utils.universe.SimpleUniverse m_universe

m_playground

private Playground m_playground

m_monte_carlo_run_set

private MonteCarloRunSet m_monte_carlo_run_set

m_active_toy

private Toy m_active_toy
Constructor Detail

Sandbox

public Sandbox(java.lang.String name,
               ModelLibrary model_library,
               Playground playground,
               MonteCarloRunSet monte_carlo_run_set,
               boolean is_wireframe,
               int instantiation_key)
        throws java.lang.Exception
Creates a new sandbox. This is intended to be called from Playground only.

Parameters:
name - - the name of the sandbox, unique within the playground where it wil reside
model_library - - the system model library
playground - - the playground that will contain this sandbox
monte_carlo_run_set - - the Monte Carlo run set defining the contents of this sandbox
is_wireframe - - whether this sandbox will be rendered in wireframe
instantiation_key - - the "secret code" to prevent unintentional uses of this constructor
Throws:
java.lang.Exception - - if this constructor is called from an unapproved location
Method Detail

addToy

public Toy addToy(java.lang.String toy_name,
                  java.lang.String model_name,
                  boolean is_wireframe,
                  float transparency,
                  javax.vecmath.Color3f override_color)
           throws java.lang.Exception
Creates and adds a toy to this sandbox.

Parameters:
toy_name - - the name of the toy, unique within this sandbox
model_name - - the model name for the toy as defined in the ModelLibrary
is_wireframe - - whether this toy should be rendered in wireframe
transparency - - the transparency of this toy
override_color - - the optional color overriding the defined color of this model; otherwise null
Returns:
the toy
Throws:
java.lang.Exception - - if a toy with the given name is already present
See Also:
commit(), ModelLibrary

buildSandboxPedestal

private javax.media.j3d.BranchGroup buildSandboxPedestal(boolean is_wireframe)
Builds the sandbox pedestal on which the entire "world" resides.

Parameters:
is_wireframe - - whether the pedestal should be rendered in wireframe
Returns:
the Java3D branch group defining the pedestal

commit

public void commit()
Commits the contents of this sandbox to remain static. No additional toys can be added after this is called. This must be called to complete the creation of the sandbox; otherwise the toys will not show up and the sandbox will remain in an indeterminate state.

See Also:
addToy(java.lang.String, java.lang.String, boolean, float, javax.vecmath.Color3f)

getMonteCarloRunSet

public MonteCarloRunSet getMonteCarloRunSet()
Returns the Monte Carlo run set defining the contents of this sandbox.

Returns:
the run set

getName

public java.lang.String getName()
Returns the name of this sandbox.

Overrides:
getName in class java.awt.Component
Returns:
the name

getToy

public Toy getToy(java.lang.String name)
Returns a toy.

Parameters:
name - - the toy name
Returns:
the toy, or null if it is not present

getToyCount

public int getToyCount()
Returns the number of toys in this sandbox.

Returns:
the count

getToyNames

public java.util.Enumeration getToyNames()
Returns a list of the names of all toys in this sandbox.

Returns:
the string list

getViewerAttitude

public Attitude getViewerAttitude()
Returns the combined attitude of the field of view and the head of the viewer in this sandbox. This refers to where the body is be facing and where the head can be looking within the limitations of the body.

This is a read-only composite of two attitudes, which are combined in SandboxController.

Returns:
the attitude

getViewerFieldOfViewAttitude

public Attitude getViewerFieldOfViewAttitude()
Returns the attitude of the field of view of the viewer in this sandbox. This refers to where the body is be facing.

The return value may be modified to change the attitude. Call update() afterwards to reflect the changes.

Returns:
the attitude
See Also:
update()

getViewerHeadAttitude

public Attitude getViewerHeadAttitude()
Returns the attitude of the head of the viewer in this sandbox. This refers to where the head would be looking based on where the body is facing.

The return value may be modified to change the attitude. Call update() afterwards to reflect the changes.

Returns:
the attitude
See Also:
update()

getViewerPosition

public Position getViewerPosition()
Returns the position of the viewer in this sandbox.

Returns:
the position

normalizeToyInteractively

protected void normalizeToyInteractively(int modifier_code,
                                         int key_code)
Implements a semi-hardcoded editor to normalize the position, scaling, and dimensions of models within a standard frame. Use this in conjunction with the 1-meter cube all models must be packed into.

This is for development only.

Parameters:
modifier_code - - the key modifier for shift or non-shift
key_code - - the key code
See Also:
SandboxController.MODEL_EDIT_MODE

processSelectionCallback

protected void processSelectionCallback(java.lang.String selection_identifier,
                                        java.awt.event.MouseEvent event)
Handles a selection callback from the SandboxController in charge of this sandbox. This occurs when a toy is selected.

Parameters:
selection_identifier - - an identifier specifying what was clicked on
event - - the event that invoked this callback

processSynchronizationCallback

protected void processSynchronizationCallback()
Handles a synchronization callback from the SandboxController in charge of this sandbox. This occurs when a change made in one sandbox is meant to be reflected in all other sandboxes.


setSize

public void setSize(int width,
                    int height)
Sets the size of the panel on which the SnapCanvas3D is located. Call this after resizing the parent container.

Overrides:
setSize in class java.awt.Component
Parameters:
width - - the width in pixels
height - - the height in pixels
See Also:
SnapCanvas3D

toString

public java.lang.String toString()
Returns a string representation of this object.

Overrides:
toString in class java.awt.Component
Returns:
the String representation
See Also:
Support.toPrettyString(java.lang.String)

update

public void update()
Updates this sandbox and all Toys in it.