com.swfm.mica.core
Class MiCanvas

java.lang.Object
  extended bycom.swfm.mica.core.MiCanvas
All Implemented Interfaces:
MiiCommandHandler, java.lang.Runnable

public class MiCanvas
extends java.lang.Object
implements java.lang.Runnable, MiiCommandHandler

This class provides an absract interface to the wrapper/driver classes that interact with the native system's canvas/panel widget. There are drivers for AWT, AWT 10.02 and Swing.

This class also manages the runtime thread and handles events and modifies the graphics display list. As such it handles the synchronization between the redraw thread(s) and event thread(s) of the native system and this Mica-specific part-modifying thread.

Version:
%I% %G%
Author:
Michael L. Davis

Field Summary
static int ANIMATIONS_PER_SECOND
           
static int CYCLES_PER_GRAPHICS_UPDATE
           
static java.lang.String Mi_ANTI_ALIASING
           
static java.lang.String Mi_DOUBLE_BUFFERING
           
 
Constructor Summary
MiCanvas(MiiCanvas nativeComponent)
          Constructs a new MiCanvas.
MiCanvas(MiiCanvas nativeComponent, MiBounds deviceBounds)
          Constructs a new MiCanvas of the given size and location.
 
Method Summary
 void boundsHasChanged(java.awt.Rectangle newBounds, boolean awtThread)
           
 java.awt.Image createImage(int width, int height)
           
 void dispose()
           
 void forceRedraw()
           
 void freeAccessLock()
          Free one lock that was obtained using getAccessLock.
 int freeAccessLocks(java.lang.Thread thread)
          Free all of the locks this thread has on this canvas.
 void freeze(boolean flag)
           
 void getAccessLock()
          Waits, if necessary, and obtains a lock on this canvas.
 boolean getAccessLockIfPossible()
           
 void getAccessLocks(int numLocksToGet)
          Get number of locks.
 MiAnimationManager getAnimationManager()
          Returns the animation manager for this canvas.
 MiBounds getCanvasBounds()
          Get the bounds of the canvas in pixels.
 boolean getDrawingEnabled()
           
 boolean getEventDispatchingEnabled()
           
 boolean getEventHandlingEnabled()
           
 java.awt.Graphics getGraphics()
           
 java.awt.Dimension getMinimumSize()
          Returns the minimum size of this canvas.
 int getMouseAppearance()
          Returns the appearance of the mouse cursor in this canvas.
 MiiCanvas getNativeComponent()
           
 java.awt.Dimension getPreferredSize()
          Returns the preferred size of this canvas.
 MiRenderer getRenderer()
          Returns the renderer for this canvas.
static MiBounds getScreenBounds()
          Get the bounds of the entire screen in pixels.
 MiWindow getWindow()
           
 boolean handleEvent(java.awt.Event evt)
          Process the awt.event as per the awt.Component API.
 boolean hasBoundsChanged(int x, int y, int width, int height)
           
 boolean isDoubleBuffered()
          Get whether this canvas is double-buffered.
 boolean isFrozen()
           
 MiPartModifierThread makeNewRunningThread()
          Makes and returns a new event-processing scene-graph modifying thread.
 void notifySelf()
          Wakes up any threads waiting on this canvas.
 boolean paint(java.awt.Graphics g)
          Causes the canvas to be redrawn as per the awt.Component API.
 void processCommand(java.lang.String arg)
          Processes the given command.
 void pushBackEvent(MiEvent event)
           
 void run()
          Runs the event-processing scene-graph modifying thread as part of the awt.Runnable interface.
 void setCanvasBounds(MiBounds deviceBounds)
          Sets the bounds of the canvas, in pixels.
 void setDoubleBuffered(boolean flag)
          Set whether this canvas is double-buffered.
 void setDrawingEnabled(boolean flag)
           
 void setEventDispatchingEnabled(boolean flag)
           
 void setEventHandlingEnabled(boolean flag)
           
 void setMouseAppearance(int appearance)
          Sets the appearance of the mouse cursor within the bounds of this canvas.
 void setRenderingHints(java.util.HashMap hints)
          Sets default rendering hints.
 void setWindow(MiWindow window)
          Sets the (root) window associated with this canvas.
 void start()
          Starts the event-processing scene-graph modifying thread as part of the awt.Runnable interface.
 void stop()
          Stops the event-processing scene-graph modifying thread as part of the awt.Runnable interface.
 java.lang.String toString()
           
 void update(java.awt.Graphics g)
          Causes the canvas to be redrawn as per the awt.Component API.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

Mi_DOUBLE_BUFFERING

public static java.lang.String Mi_DOUBLE_BUFFERING

Mi_ANTI_ALIASING

public static java.lang.String Mi_ANTI_ALIASING

ANIMATIONS_PER_SECOND

public static int ANIMATIONS_PER_SECOND

CYCLES_PER_GRAPHICS_UPDATE

public static int CYCLES_PER_GRAPHICS_UPDATE
Constructor Detail

MiCanvas

public MiCanvas(MiiCanvas nativeComponent)
Constructs a new MiCanvas.


MiCanvas

public MiCanvas(MiiCanvas nativeComponent,
                MiBounds deviceBounds)
Constructs a new MiCanvas of the given size and location.

Parameters:
deviceBounds - the size of the canvas
Method Detail

getNativeComponent

public MiiCanvas getNativeComponent()

setEventHandlingEnabled

public void setEventHandlingEnabled(boolean flag)

getEventHandlingEnabled

public boolean getEventHandlingEnabled()

setRenderingHints

public void setRenderingHints(java.util.HashMap hints)
Sets default rendering hints. These can be ovreridden on a MiPart by part basis.

Parameters:
hints - a list of keyword/values (for example a list of java.awt.RenderingHints.Key/Objects)

setDoubleBuffered

public void setDoubleBuffered(boolean flag)
Set whether this canvas is double-buffered. If the canvas is indeed double-buffered then everything drawn to it is drawn to the buffer first and then the buffer is copied to the screen.

Parameters:
flag - true if double-buffered

isDoubleBuffered

public boolean isDoubleBuffered()
Get whether this canvas is double-buffered.

Returns:
true if double-buffered

setEventDispatchingEnabled

public void setEventDispatchingEnabled(boolean flag)

getEventDispatchingEnabled

public boolean getEventDispatchingEnabled()

setDrawingEnabled

public void setDrawingEnabled(boolean flag)

getDrawingEnabled

public boolean getDrawingEnabled()

setWindow

public void setWindow(MiWindow window)
Sets the (root) window associated with this canvas. This window will process events and draw the contents of this canvas.

Parameters:
window - the root window
See Also:
MiWindow

getWindow

public MiWindow getWindow()

getAnimationManager

public MiAnimationManager getAnimationManager()
Returns the animation manager for this canvas.

Returns:
the animation manager
See Also:
MiAnimationManager

makeNewRunningThread

public MiPartModifierThread makeNewRunningThread()
Makes and returns a new event-processing scene-graph modifying thread. This is used for synchronous method calls made by the origonal event-processing scene-graph when it wants to pause the original thread but still keep graphics and animations running. For example it is used for modal dialogs.

Returns:
the thread
See Also:
MiPartModifierThread

setMouseAppearance

public void setMouseAppearance(int appearance)
Sets the appearance of the mouse cursor within the bounds of this canvas.

Parameters:
appearance - the cursor appearance

getMouseAppearance

public int getMouseAppearance()
Returns the appearance of the mouse cursor in this canvas.

Returns:
the animation manager
See Also:
MiAnimationManager

setCanvasBounds

public void setCanvasBounds(MiBounds deviceBounds)
Sets the bounds of the canvas, in pixels.

Parameters:
deviceBounds - the bounds of this canvas

getCanvasBounds

public MiBounds getCanvasBounds()
Get the bounds of the canvas in pixels.

Returns:
the bounds of this canvas

getScreenBounds

public static MiBounds getScreenBounds()
Get the bounds of the entire screen in pixels.

Returns:
the bounds of the entire screen

getRenderer

public MiRenderer getRenderer()
Returns the renderer for this canvas.

Returns:
the renderer
See Also:
MiRenderer

notifySelf

public void notifySelf()
Wakes up any threads waiting on this canvas.


getAccessLock

public void getAccessLock()
Waits, if necessary, and obtains a lock on this canvas. This should be done before any, and most especially any long term, synchonizations on this canvas. This permits a caller to grab hold of this canvas and it's scene- graph using a thread that is not normally associated with this canvas. A single thread may have multiple locks on a single canvas.

See Also:
freeAccessLock()

getAccessLockIfPossible

public boolean getAccessLockIfPossible()

freeAccessLock

public void freeAccessLock()
Free one lock that was obtained using getAccessLock.

See Also:
getAccessLock()

getAccessLocks

public void getAccessLocks(int numLocksToGet)
Get number of locks. This is used in conjunction with (after) the freeAccessLocks method.

See Also:
freeAccessLocks(java.lang.Thread)

freeAccessLocks

public int freeAccessLocks(java.lang.Thread thread)
Free all of the locks this thread has on this canvas. This is used in conjunction with (before) the getAccessLocks method. This is used when a thread wants to wait on some event and temporarily free it's locks on this canvas.

See Also:
getAccessLocks(int)

freeze

public void freeze(boolean flag)

isFrozen

public boolean isFrozen()

getPreferredSize

public java.awt.Dimension getPreferredSize()
Returns the preferred size of this canvas. This routine is in support of the Component API.

Returns:
the preferred size

getMinimumSize

public java.awt.Dimension getMinimumSize()
Returns the minimum size of this canvas. This routine is in support of the Component API.

Returns:
the minimum size

start

public void start()
Starts the event-processing scene-graph modifying thread as part of the awt.Runnable interface.


stop

public void stop()
Stops the event-processing scene-graph modifying thread as part of the awt.Runnable interface.


dispose

public void dispose()

run

public void run()
Runs the event-processing scene-graph modifying thread as part of the awt.Runnable interface.

Specified by:
run in interface java.lang.Runnable

handleEvent

public boolean handleEvent(java.awt.Event evt)
Process the awt.event as per the awt.Component API.

Parameters:
evt - the awt.Event event

pushBackEvent

public void pushBackEvent(MiEvent event)

update

public void update(java.awt.Graphics g)
Causes the canvas to be redrawn as per the awt.Component API.

Parameters:
g - the awt.graphics renderer

getGraphics

public java.awt.Graphics getGraphics()

createImage

public java.awt.Image createImage(int width,
                                  int height)

paint

public boolean paint(java.awt.Graphics g)
Causes the canvas to be redrawn as per the awt.Component API.

Parameters:
g - the awt.graphics renderer

hasBoundsChanged

public boolean hasBoundsChanged(int x,
                                int y,
                                int width,
                                int height)

boundsHasChanged

public void boundsHasChanged(java.awt.Rectangle newBounds,
                             boolean awtThread)

forceRedraw

public void forceRedraw()

toString

public java.lang.String toString()

processCommand

public void processCommand(java.lang.String arg)
Description copied from interface: MiiCommandHandler
Processes the given command.

Specified by:
processCommand in interface MiiCommandHandler