org.jscience.chemistry.gui.extended.jviewer
Class JViewer

java.lang.Object
  extended by java.awt.Component
      extended by java.awt.Container
          extended by java.awt.Panel
              extended by org.jscience.chemistry.gui.extended.jviewer.JViewer
All Implemented Interfaces:
java.awt.image.ImageObserver, java.awt.MenuContainer, java.io.Serializable, javax.accessibility.Accessible

public class JViewer
extends java.awt.Panel

This class provides a viewer which can render and manipulate one or more graphics objects.

Note: Only the reference to the Tripos Java molecule's Matrix3D class keeps jviewer from being a true "object" renderer. A future effort should be to move Matrix3D from molecule to JViewer.

See Also:
IEvntHandler, IRenderer, Serialized Form

Nested Class Summary
 
Nested classes/interfaces inherited from class java.awt.Panel
java.awt.Panel.AccessibleAWTPanel
 
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.BaselineResizeBehavior, java.awt.Component.BltBufferStrategy, java.awt.Component.FlipBufferStrategy
 
Field Summary
protected  java.awt.Color backgroundColor
           
protected  java.awt.Dimension dim
           
protected  IEvntHandler eHandler
           
protected  Matrix3D localMat
           
protected  boolean needRescale
           
static int NO_TRANSFORM
          DOCUMENT ME!
protected  java.awt.Dimension offDim
           
protected  java.awt.Image offImage
           
protected  Matrix3D panelMat
           
protected  java.util.Vector renderers
           
static int ROTATE_XY
          DOCUMENT ME!
static int ROTATE_Z
          DOCUMENT ME!
static int SCALE
          DOCUMENT ME!
protected  float scaleFactor
           
protected  java.awt.Graphics theGr
           
protected  int transformMode
           
static int TRANSLATE
          DOCUMENT ME!
protected  float xTrans
           
protected  float yTrans
           
protected  float zTrans
           
 
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
JViewer()
          The default constructor.
JViewer(int w, int h)
          Constructor allowing size to be specified.
JViewer(JViewer jviewer)
          A copy constructor.
 
Method Summary
 void addRenderer(IRenderer renderer)
          Add another object renderer for the viewer to use.
protected  void computeScale()
          Determine the new scale factor to be applied to the graphics objects in response to a change in viewer size (or contents if the application called markForRescale to force a rescaling).
 java.awt.Color getBackgroundColor()
          Get the background color.
 java.util.Vector getIRenderers()
          Return the list of renderers
 int getTransformMode()
          Return the transformation mode.
 boolean handleEvent(java.awt.Event e)
          Dispatch any event to the event handler and/or picker, if registered.
 void markForRescale()
          Set the rescale flag so a new scale factor gets computed at paint time.
 java.awt.Dimension minimumSize()
          Indicate the minimum size for a JViewer.
 void paint(java.awt.Graphics g)
          Render all objects known by the gui.
 java.awt.Dimension preferredSize()
          Indicate the preferred size for a JViewer.
 void registerEHandler(IEvntHandler eh)
          Register an event handler with the gui.
 void removeAllRenderers()
          Remove all object renderers.
 boolean removeRenderer(IRenderer renderer)
          Remove the specified object renderer from the viewer's list.
 void resetView()
          Reset the view to its non-transformed state.
 void reshape(int x, int y, int w, int h)
          Update the viewer's dimension information in response to a reshaping.
 void resize(java.awt.Dimension d)
          Update the viewer's dimension information in response to a resizing.
 void resize(int w, int h)
          Update the viewer's dimension information in response to a resizing.
 void setBackgroundColor(java.awt.Color bg)
          Set the background color.
 void setRenderer(IRenderer renderer)
          Establish a new object renderer for the viewer to use.
 void setTransformMode(int mode)
          Set the transformation mode.
 boolean transform(int dx, int dy)
          Apply the current transformation in response to a mouse movement.
 void update(java.awt.Graphics g)
          DOCUMENT ME!
 
Methods inherited from class java.awt.Panel
addNotify, getAccessibleContext
 
Methods inherited from class java.awt.Container
add, add, add, add, add, addContainerListener, addImpl, addPropertyChangeListener, addPropertyChangeListener, applyComponentOrientation, areFocusTraversalKeysSet, countComponents, deliverEvent, doLayout, findComponentAt, findComponentAt, getAlignmentX, getAlignmentY, getComponent, getComponentAt, getComponentAt, getComponentCount, getComponents, getComponentZOrder, getContainerListeners, getFocusTraversalKeys, getFocusTraversalPolicy, getInsets, getLayout, getListeners, getMaximumSize, getMinimumSize, getMousePosition, getPreferredSize, insets, invalidate, isAncestorOf, isFocusCycleRoot, isFocusCycleRoot, isFocusTraversalPolicyProvider, isFocusTraversalPolicySet, layout, list, list, locate, paintComponents, paramString, print, printComponents, processContainerEvent, processEvent, remove, remove, removeAll, removeContainerListener, removeNotify, setComponentZOrder, setFocusCycleRoot, setFocusTraversalKeys, setFocusTraversalPolicy, setFocusTraversalPolicyProvider, setFont, 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, contains, createImage, createImage, createVolatileImage, createVolatileImage, disable, disableEvents, dispatchEvent, enable, enable, enableEvents, enableInputMethods, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getBaseline, getBaselineResizeBehavior, getBounds, getBounds, getColorModel, getComponentListeners, getComponentOrientation, getCursor, getDropTarget, getFocusCycleRootAncestor, getFocusListeners, getFocusTraversalKeysEnabled, getFont, getFontMetrics, getForeground, getGraphics, getGraphicsConfiguration, getHeight, getHierarchyBoundsListeners, getHierarchyListeners, getIgnoreRepaint, getInputContext, getInputMethodListeners, getInputMethodRequests, getKeyListeners, getLocale, getLocation, getLocation, getLocationOnScreen, getMouseListeners, getMouseMotionListeners, getMousePosition, getMouseWheelListeners, getName, getParent, getPeer, getPropertyChangeListeners, getPropertyChangeListeners, getSize, getSize, getToolkit, getTreeLock, getWidth, getX, getY, gotFocus, hasFocus, hide, imageUpdate, inside, isBackgroundSet, isCursorSet, isDisplayable, isDoubleBuffered, isEnabled, isFocusable, isFocusOwner, isFocusTraversable, isFontSet, isForegroundSet, isLightweight, isMaximumSizeSet, isMinimumSizeSet, isOpaque, isPreferredSizeSet, isShowing, isValid, isVisible, keyDown, keyUp, list, list, list, location, lostFocus, mouseDown, mouseDrag, mouseEnter, mouseExit, mouseMove, mouseUp, move, nextFocus, paintAll, postEvent, prepareImage, prepareImage, printAll, processComponentEvent, processFocusEvent, processHierarchyBoundsEvent, processHierarchyEvent, processInputMethodEvent, processKeyEvent, processMouseEvent, processMouseMotionEvent, processMouseWheelEvent, remove, removeComponentListener, removeFocusListener, removeHierarchyBoundsListener, removeHierarchyListener, removeInputMethodListener, removeKeyListener, removeMouseListener, removeMouseMotionListener, removeMouseWheelListener, removePropertyChangeListener, removePropertyChangeListener, repaint, repaint, repaint, repaint, requestFocus, requestFocus, requestFocusInWindow, requestFocusInWindow, setBackground, setBounds, setBounds, setComponentOrientation, setCursor, setDropTarget, setEnabled, setFocusable, setFocusTraversalKeysEnabled, setForeground, setIgnoreRepaint, setLocale, setLocation, setLocation, setMaximumSize, setMinimumSize, setName, setPreferredSize, setSize, setSize, setVisible, 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

TRANSLATE

public static final int TRANSLATE
DOCUMENT ME!

See Also:
Constant Field Values

ROTATE_XY

public static final int ROTATE_XY
DOCUMENT ME!

See Also:
Constant Field Values

ROTATE_Z

public static final int ROTATE_Z
DOCUMENT ME!

See Also:
Constant Field Values

SCALE

public static final int SCALE
DOCUMENT ME!

See Also:
Constant Field Values

NO_TRANSFORM

public static final int NO_TRANSFORM
DOCUMENT ME!

See Also:
Constant Field Values

renderers

protected java.util.Vector renderers

localMat

protected Matrix3D localMat

panelMat

protected Matrix3D panelMat

backgroundColor

protected java.awt.Color backgroundColor

transformMode

protected int transformMode

xTrans

protected float xTrans

yTrans

protected float yTrans

zTrans

protected float zTrans

eHandler

protected IEvntHandler eHandler

dim

protected java.awt.Dimension dim

offDim

protected java.awt.Dimension offDim

theGr

protected java.awt.Graphics theGr

offImage

protected java.awt.Image offImage

scaleFactor

protected float scaleFactor

needRescale

protected boolean needRescale
Constructor Detail

JViewer

public JViewer()
The default constructor.


JViewer

public JViewer(int w,
               int h)
Constructor allowing size to be specified.

Parameters:
w - width of the JViewer
h - height of the JViewer

JViewer

public JViewer(JViewer jviewer)
A copy constructor.

Parameters:
jviewer - the JViewer being copied
Method Detail

minimumSize

public java.awt.Dimension minimumSize()
Indicate the minimum size for a JViewer.

Overrides:
minimumSize in class java.awt.Container

preferredSize

public java.awt.Dimension preferredSize()
Indicate the preferred size for a JViewer.

Overrides:
preferredSize in class java.awt.Container

resetView

public void resetView()
Reset the view to its non-transformed state.


setBackgroundColor

public void setBackgroundColor(java.awt.Color bg)
Set the background color.

Parameters:
bg - the background color
See Also:
getBackgroundColor

getBackgroundColor

public java.awt.Color getBackgroundColor()
Get the background color.

Returns:
the background color
See Also:
setBackgroundColor

setTransformMode

public void setTransformMode(int mode)
Set the transformation mode.

Parameters:
mode - one of TRANSLATE, ROTATE_XY, ROTATE_Z, SCALE, or NO_TRANSFORM

getTransformMode

public int getTransformMode()
Return the transformation mode.


setRenderer

public void setRenderer(IRenderer renderer)
Establish a new object renderer for the viewer to use.

Parameters:
renderer - an implementation of the IRenderer interface
See Also:
IRenderer

getIRenderers

public java.util.Vector getIRenderers()
Return the list of renderers


addRenderer

public void addRenderer(IRenderer renderer)
Add another object renderer for the viewer to use. This allows the viewer to render and manipulate multiple objects at once.

Parameters:
renderer - an implementation of the IRenderer interface
See Also:
IRenderer

removeRenderer

public boolean removeRenderer(IRenderer renderer)
Remove the specified object renderer from the viewer's list.

Parameters:
renderer - an implementation of the IRenderer interface
Returns:
true if the object renderer was removed else false
See Also:
IRenderer

removeAllRenderers

public void removeAllRenderers()
Remove all object renderers.

See Also:
IRenderer

markForRescale

public void markForRescale()
Set the rescale flag so a new scale factor gets computed at paint time. This state will remain active until after the next paint. This method is useful when the application wants to change the contents of the viewer, since recomputation of the scale factor is required to fit the new contents to the gui. If not used, the scale factor will only get recomputed when the viewer's size changes.


computeScale

protected void computeScale()
Determine the new scale factor to be applied to the graphics objects in response to a change in viewer size (or contents if the application called markForRescale to force a rescaling).

See Also:
IRenderer, markForResize

registerEHandler

public void registerEHandler(IEvntHandler eh)
Register an event handler with the gui. The viewer does not handle events. All events are dispatched to the an event handler if registered, else to the viewer's super class.

Parameters:
eh - an implementation of the IEvntHandler interface
See Also:
IEvntHandler

resize

public void resize(java.awt.Dimension d)
Update the viewer's dimension information in response to a resizing.

Overrides:
resize in class java.awt.Component
Parameters:
d - the new dimension

resize

public void resize(int w,
                   int h)
Update the viewer's dimension information in response to a resizing.

Overrides:
resize in class java.awt.Component
Parameters:
w - the new dimension width
h - the new dimension height

reshape

public void reshape(int x,
                    int y,
                    int w,
                    int h)
Update the viewer's dimension information in response to a reshaping.

Overrides:
reshape in class java.awt.Component
Parameters:
x - x coordinate of the JViewer's origin
y - y coordinate of the JViewer's origin
w - width of the JViewer
h - height of the JViewer

paint

public void paint(java.awt.Graphics g)
Render all objects known by the gui.

Overrides:
paint in class java.awt.Container
Parameters:
g - the graphics context

update

public void update(java.awt.Graphics g)
DOCUMENT ME!

Overrides:
update in class java.awt.Container
Parameters:
g - DOCUMENT ME!

handleEvent

public boolean handleEvent(java.awt.Event e)
Dispatch any event to the event handler and/or picker, if registered.

Overrides:
handleEvent in class java.awt.Component
Parameters:
e - an event.

transform

public boolean transform(int dx,
                         int dy)
Apply the current transformation in response to a mouse movement.

Parameters:
dx - amount of movement in x
dy - amount of movement in y
Returns:
true iff successfully transform the renderers