edu.umd.cs.jazz.util
Class ZBasicComponent

java.lang.Object
  |
  +--java.awt.Component
        |
        +--java.awt.Container
              |
              +--javax.swing.JComponent
                    |
                    +--edu.umd.cs.jazz.util.ZBasicComponent

public class ZBasicComponent
extends javax.swing.JComponent

A ZBasicComponent is a simple Swing component that can be used to render onto for Jazz. It extends JComponent, and overrides the appropriate methods so that whenever Java requests that this widget gets redrawn, the requests are forwarded on to Jazz to render appropriately. It also defines a very simple Jazz scenegraph consisting of a root, a camera, and one node. Finally, it supports capturing the current camera view onto an Image (i.e., a screengrab).

See Also:
Serialized Form

Inner classes inherited from class javax.swing.JComponent
javax.swing.JComponent.AccessibleJComponent
 
Field Summary
protected  ZCamera camera
          The camera in the scenegraph
protected  ZNode layer
          The single node that camera looks onto.
protected  ZRootNode root
          The root of the scenegraph
protected  ZSurface surface
          The surface associated with the component
 
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
 
Constructor Summary
ZBasicComponent()
          The default constructor for a ZBasicComponent.
ZBasicComponent(ZRootNode aRoot, ZNode layer)
          A constructor for a ZBasicComponent that uses an existing scenegraph.
 
Method Summary
 ZCamera getCamera()
          Return the camera associated with the primary surface.
 ZNode getLayer()
          Return the "layer".
 ZRootNode getRoot()
          Return the root of the scenegraph.
 java.awt.Image getScreenImage(int maxDim)
          Generate a copy of the view in the current camera scaled so that the aspect ratio of the screen is maintained, and the larger dimension is scaled to match the specified parameter.
 java.awt.Image getScreenImage(int w, int h)
          Generate a copy of the current camera scaled to the specified dimensions.
 ZSurface getSurface()
          Return the surface.
 boolean isFocusTraversable()
           
 void paintComponent(java.awt.Graphics g)
          This renders the Jazz scene attached to this component by passing on the Swing paint request to the underlying Jazz surface.
 void setBackground(java.awt.Color background)
          Sets the background color of this component.
 void setBounds(int x, int y, int w, int h)
          This captures changes in the component's bounds so the underlying Jazz camera can be updated to mirror bounds change.
 void setCamera(ZCamera aCamera)
          Sets the camera.
 void setLayer(ZNode aLayer)
          Sets the layer.
 void setRoot(ZRootNode aRoot)
          Sets the root.
 void setSurface(ZSurface aSurface)
          Sets the surface.
 
Methods inherited from class javax.swing.JComponent
addAncestorListener, addNotify, addPropertyChangeListener, addVetoableChangeListener, computeVisibleRect, contains, createToolTip, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, fireVetoableChange, getAccessibleContext, getActionForKeyStroke, getAlignmentX, getAlignmentY, getAutoscrolls, getBorder, getBounds, getClientProperty, getComponentGraphics, getConditionForKeyStroke, getDebugGraphicsOptions, getGraphics, getHeight, getInsets, getInsets, getLocation, getMaximumSize, getMinimumSize, getNextFocusableComponent, getPreferredSize, getRegisteredKeyStrokes, getRootPane, getSize, getToolTipLocation, getToolTipText, getToolTipText, getTopLevelAncestor, getUIClassID, getVisibleRect, getWidth, getX, getY, grabFocus, hasFocus, isDoubleBuffered, isFocusCycleRoot, isLightweightComponent, isManagingFocus, isOpaque, isOptimizedDrawingEnabled, isPaintingTile, isRequestFocusEnabled, isValidateRoot, paint, paintBorder, paintChildren, paintImmediately, paintImmediately, paramString, processComponentKeyEvent, processFocusEvent, processKeyEvent, processMouseMotionEvent, putClientProperty, registerKeyboardAction, registerKeyboardAction, removeAncestorListener, removeNotify, removePropertyChangeListener, removeVetoableChangeListener, repaint, repaint, requestDefaultFocus, requestFocus, resetKeyboardActions, reshape, revalidate, scrollRectToVisible, setAlignmentX, setAlignmentY, setAutoscrolls, setBorder, setDebugGraphicsOptions, setDoubleBuffered, setEnabled, setFont, setForeground, setMaximumSize, setMinimumSize, setNextFocusableComponent, setOpaque, setPreferredSize, setRequestFocusEnabled, setToolTipText, setUI, setVisible, unregisterKeyboardAction, update, updateUI
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getLayout, insets, invalidate, isAncestorOf, layout, list, list, locate, minimumSize, paintComponents, preferredSize, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, setLayout, validate, validateTree
 
Methods inherited from class java.awt.Component
action, add, addComponentListener, addFocusListener, addInputMethodListener, addKeyListener, addMouseListener, addMouseMotionListener, addPropertyChangeListener, bounds, checkImage, checkImage, coalesceEvents, contains, createImage, createImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, getBackground, getBounds, getColorModel, getComponentOrientation, getCursor, getDropTarget, getFont, getFontMetrics, getForeground, getInputContext, getInputMethodRequests, getLocale, getLocation, getLocationOnScreen, getName, getParent, getPeer, getSize, getToolkit, getTreeLock, gotFocus, handleEvent, hide, imageUpdate, inside, isDisplayable, isEnabled, isLightweight, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processInputMethodEvent, processMouseEvent, remove, removeComponentListener, removeFocusListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removePropertyChangeListener, repaint, repaint, repaint, resize, resize, setBounds, setComponentOrientation, setCursor, setDropTarget, setLocale, setLocation, setLocation, setName, setSize, setSize, show, show, size, toString, transferFocus
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

root

protected ZRootNode root
The root of the scenegraph

camera

protected ZCamera camera
The camera in the scenegraph

surface

protected ZSurface surface
The surface associated with the component

layer

protected ZNode layer
The single node that camera looks onto. It is considered to be the "layer" because many applications will put content under this node which can then be hidden or revealed like a layer.
Constructor Detail

ZBasicComponent

public ZBasicComponent()
The default constructor for a ZBasicComponent. This creates a simple scenegraph with a root, camera, surface, and layer. These 4 scenegraph elements are accessible to the application through get methods.
See Also:
getRoot(), getSurface(), getCamera(), getLayer()

ZBasicComponent

public ZBasicComponent(ZRootNode aRoot,
                       ZNode layer)
A constructor for a ZBasicComponent that uses an existing scenegraph. This creates a new camera and surface. The camera is inserted into the scenegraph under the root, and the specified layer is added to the camera's paint start point list. The scenegraph elements are accessible to the application through get methods.
Parameters:
aRoot - The existing root of the scenegraph this component is attached to
layer - The existing layer node of the scenegraph that this component's camera looks onto
See Also:
getRoot(), getSurface(), getCamera(), getLayer()
Method Detail

paintComponent

public void paintComponent(java.awt.Graphics g)
This renders the Jazz scene attached to this component by passing on the Swing paint request to the underlying Jazz surface.
Parameters:
g - The graphics to be painted onto
Overrides:
paintComponent in class javax.swing.JComponent

setBounds

public void setBounds(int x,
                      int y,
                      int w,
                      int h)
This captures changes in the component's bounds so the underlying Jazz camera can be updated to mirror bounds change.
Parameters:
x - The X-coord of the top-left corner of the component
y - The Y-coord of the top-left corner of the component
width - The width of the component
height - The Height of the component
Overrides:
setBounds in class java.awt.Component

setBackground

public void setBackground(java.awt.Color background)
Sets the background color of this component. Actually - this is implemented by changing the fill color of the camera associated with this component since the camera controls the rendering onto this component.
Parameters:
background - The new color to use for this component's background
Overrides:
setBackground in class javax.swing.JComponent

setSurface

public void setSurface(ZSurface aSurface)
Sets the surface.
Parameters:
surface - the surface

getSurface

public ZSurface getSurface()
Return the surface.
Returns:
the surface

setCamera

public void setCamera(ZCamera aCamera)
Sets the camera.
Parameters:
camera - the camera

getCamera

public ZCamera getCamera()
Return the camera associated with the primary surface.
Returns:
the camera

setRoot

public void setRoot(ZRootNode aRoot)
Sets the root.
Parameters:
root - the root

getRoot

public ZRootNode getRoot()
Return the root of the scenegraph.
Returns:
the root

setLayer

public void setLayer(ZNode aLayer)
Sets the layer.
Parameters:
layer - the layer

getLayer

public ZNode getLayer()
Return the "layer". That is, the single node that the camera looks onto to start.
Returns:
the node

isFocusTraversable

public boolean isFocusTraversable()
Overrides:
isFocusTraversable in class javax.swing.JComponent

getScreenImage

public java.awt.Image getScreenImage(int maxDim)
Generate a copy of the view in the current camera scaled so that the aspect ratio of the screen is maintained, and the larger dimension is scaled to match the specified parameter.
Returns:
An image of the camera

getScreenImage

public java.awt.Image getScreenImage(int w,
                                     int h)
Generate a copy of the current camera scaled to the specified dimensions.
Parameters:
w - Width of the image
h - Height of the image
Returns:
An image of the camera