mome.keyb
Class XCanvas

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Canvas
          extended by mome.keyb.XCanvas

public class XCanvas
extends Canvas

A Canvas subclass that translates key events to commands and issues them to commands execution thread and implements double buffering.

It uses KeyProcessor to map key (game action) or sequence of keys and/or game actions to command. KeyProcessor can be set and returned by setKeyProcessor(KeyProcessor), getKeyProcessor() methods respectively. It also uses Executor to issue found command to the commands execution thread. Executor can be set and returned by setExecutor(Executor), getExecutor() methods respectively.

To realize double buffering it contains methods getGraphics() to get Graphics instance associated with buffer. and flushGraphics() to flush contents of the buffer.

Version:
0.9
Author:
Sergio Morozov

Field Summary
 
Fields inherited from class javax.microedition.lcdui.Canvas
DOWN, FIRE, GAME_A, GAME_B, GAME_C, GAME_D, KEY_NUM0, KEY_NUM1, KEY_NUM2, KEY_NUM3, KEY_NUM4, KEY_NUM5, KEY_NUM6, KEY_NUM7, KEY_NUM8, KEY_NUM9, KEY_POUND, KEY_STAR, LEFT, RIGHT, UP
 
Constructor Summary
XCanvas()
          Instantiates XCanvas with initial not full screen mode, null KeyProcessor and null Executor.
XCanvas(boolean fullScreen)
          Instantiates XCanvas with null KeyProcessor and null Executor.
 
Method Summary
 void flushGraphics()
          Flushes buffer.
 Object getCommand(int key)
          Returns command associated with given key game action mapped to given key or given game action constant.
protected  Executor getExecutor()
          Returns Executor invoked for processing commands.
 Graphics getGraphics()
          Returns Graphics instance associated with buffer.
protected  KeyProcessor getKeyProcessor()
          Returns KeyProcessor invoked to map keys or sequences of keys pressed to commands.
protected  void keyPressed(int key)
          Looks up the command associated with key or sequence of keys pressed and if found, issues it to the executor.
protected  void keyReleased(int key)
          Sets last found command to null.
protected  void keyRepeated(int key)
          Issues the last found command.
protected  void paint(Graphics g)
          Draws rendered buffer.
 void setExecutor(Executor executor)
          Sets Executor to be used for processing commands.
 void setKeyProcessor(KeyProcessor keyProc)
          Sets KeyProcessor to be used to map keys or sequences of keys pressed to commands.
protected  void sizeChanged(int width, int height)
          Adjusts buffers
 
Methods inherited from class javax.microedition.lcdui.Canvas
getGameAction, getKeyCode, getKeyName, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, hideNotify, isDoubleBuffered, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, serviceRepaints, setFullScreenMode, showNotify
 
Methods inherited from class javax.microedition.lcdui.Displayable
addCommand, getHeight, getTicker, getTitle, getWidth, isShown, removeCommand, setCommandListener, setTicker, setTitle
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

XCanvas

public XCanvas(boolean fullScreen)
Instantiates XCanvas with null KeyProcessor and null Executor.

Parameters:
fullScreen - if true Xcanvas will start with full-screen mode.

XCanvas

public XCanvas()
Instantiates XCanvas with initial not full screen mode, null KeyProcessor and null Executor.

Method Detail

getGraphics

public Graphics getGraphics()
Returns Graphics instance associated with buffer.

Returns:
Graphics instance associated with buffer.

setExecutor

public void setExecutor(Executor executor)
Sets Executor to be used for processing commands.

Parameters:
executor - the executor to be used for processing commands.

getExecutor

protected Executor getExecutor()
Returns Executor invoked for processing commands.

Returns:
executor invoked for processing commands

setKeyProcessor

public void setKeyProcessor(KeyProcessor keyProc)
Sets KeyProcessor to be used to map keys or sequences of keys pressed to commands.

Parameters:
keyProc - KeyProcessor to be invoked.

getKeyProcessor

protected KeyProcessor getKeyProcessor()
Returns KeyProcessor invoked to map keys or sequences of keys pressed to commands.

Returns:
KeyProcessor invoked to map keys or sequences of keys pressed to commands.

getCommand

public Object getCommand(int key)
Returns command associated with given key game action mapped to given key or given game action constant.

Parameters:
key - key code or game action constant based on which to look up a command.
Returns:
object identifying command associated with given key or game action mapped to key or game action directly or null if command not found.

keyPressed

protected void keyPressed(int key)
Looks up the command associated with key or sequence of keys pressed and if found, issues it to the executor. Does nothing if KeyProcessor or Executor is set to null.

Overrides:
keyPressed in class Canvas
See Also:
Canvas.keyPressed(int)

keyReleased

protected void keyReleased(int key)
Sets last found command to null.

Overrides:
keyReleased in class Canvas
See Also:
Canvas.keyReleased(int)

keyRepeated

protected void keyRepeated(int key)
Issues the last found command.

Overrides:
keyRepeated in class Canvas
See Also:
Canvas.keyRepeated(int)

sizeChanged

protected void sizeChanged(int width,
                           int height)
Adjusts buffers

Overrides:
sizeChanged in class Canvas
See Also:
Canvas.sizeChanged(int, int)

paint

protected void paint(Graphics g)
Draws rendered buffer.

Specified by:
paint in class Canvas
See Also:
Canvas.paint(javax.microedition.lcdui.Graphics)

flushGraphics

public void flushGraphics()
Flushes buffer.