jMobileCore toolkit

com.jmobilecore.ui.core
Class ScreenCanvas

java.lang.Object
  extended by javax.microedition.lcdui.Displayable
      extended by javax.microedition.lcdui.Canvas
          extended by com.jmobilecore.ui.core.PlatformCanvas
              extended by com.jmobilecore.ui.core.ScreenCanvas
Direct Known Subclasses:
ConfirmForm, ListScreen

public class ScreenCanvas
extends PlatformCanvas

A screen that contains Components.

Author:
Greg Gridin

Field Summary
protected  boolean adjustFocus
          Indicated if focus ajjustment is required
protected  int bodyOffset
          y-coordinate offset within the body of the first component to display.
protected static int CANVAS_SCROLL_STEP
          Scrolling step
protected  java.util.Vector components
          Vector of GUI components
protected  int focusedIndex
          Currently focused component.
protected  javax.microedition.lcdui.Image offScreen
          Off the screen image for double buffer painting
protected  int paintAreaHeight
          Height of the scrollable area (of current screen) in pixels
protected  Label screenTitle
          Screen title
static int SCROLL_DOWN
          Scrolling direction.
static int SCROLL_UP
          Scrolling direction.
protected  SoftKeyBar softKeyBar
          SoftKeyBar for current screen this component is not in components vector
protected  int softKeyBarHeight
          Height of the scrollbar in pixels
protected  int titleHeight
          Height of the title in pixels
 
Fields inherited from class com.jmobilecore.ui.core.PlatformCanvas
DOUBLE_BUFFER, HEIGHT, KEY_CLEAR, KEY_DOWN, KEY_ENTER, KEY_FIRE, KEY_LEFT, KEY_PHONE_OFF, KEY_PHONE_ON, KEY_RIGHT, KEY_SOFT_LEFT, KEY_SOFT_RIGHT, KEY_UNDEFINED, KEY_UP, KEY_VOLUME_DOWN, KEY_VOLUME_UP, PLATFORM, PLATFORM_BARTEO, PLATFORM_LG, PLATFORM_MOTOROLA, PLATFORM_MOTOROLA_V, PLATFORM_NOKIA, PLATFORM_NOKIA_30, PLATFORM_SAMSUNG, PLATFORM_SIEMENS, PLATFORM_SONYERICSSON, PLATFORM_SUN_WTK, WIDTH
 
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
ScreenCanvas()
          Creates a new ScreenCanvas instance.
ScreenCanvas(Label title)
          Creates a new ScreenCanvas instance.
ScreenCanvas(Label title, SoftKeyBar softKeyBar)
          Creates a new ScreenCanvas instance.
 
Method Summary
 void add(Component component)
          Adds the component to the screen.
 void add(Component component, int index)
          Adds the component to the screen at the given position.
 void changeFocus(int newIndex)
          Moves the focus to the specified component.
 void destructor()
          Class destructor.
static void drawTriangle(javax.microedition.lcdui.Graphics g, int tipX, int tipY, int maxHeight, int direction, int color)
          Support method for painting scroller
protected  int getComponentsHeight()
          Get height of all components
protected  int getFirstFocusable()
          Gets first focusable component
protected  int getLastFocusable()
          Gets the last focusable component
protected  int getNextFocusable()
          Gets next focusable component
protected  int getPreviousFocusable()
          Gets previous focusable component
protected  int getScrollDirections()
          Returns the directions the body can be scrolled in.
protected  void keyPressed(int keyCode)
          Processes a press of a key.
 void paint(javax.microedition.lcdui.Graphics g)
          Paints the screen's body, which is all of the components that have been added to the screen.
 void paintBody(javax.microedition.lcdui.Graphics g)
          Paints the screen's body, which is all of the components that have been added to the screen.
protected  void paintBodyBackground(javax.microedition.lcdui.Graphics g)
          Paints the screen's body background
protected  void paintScroller(javax.microedition.lcdui.Graphics g)
          Paint scrolling indicator(s) at the bottom of the screen to indicate that the display can scroll vertically.
protected  void recalcAdjustment()
           
 void refocus()
          Adjust the screen to make focused component visible
 void remove(Component component)
          Removes the specified component from this container.
 void remove(int index)
          Removes the component, specified by index from the screen
 void removeAll()
          Removes all the components from this container.
protected  boolean scrollDown()
          Scrolls CANVAS_SCROLL_STEP pixels down
protected  void scrollTop()
          Scrolls to the top of the screen and sets first focusable component to focused state
protected  boolean scrollUp()
          Scrolls CANVAS_SCROLL_STEP pixels up
 
Methods inherited from class javax.microedition.lcdui.Canvas
getGameAction, getHeight, getKeyCode, getKeyName, getWidth, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, hideNotify, isDoubleBuffered, keyReleased, keyRepeated, pointerDragged, pointerPressed, pointerReleased, repaint, repaint, serviceRepaints, showNotify
 
Methods inherited from class javax.microedition.lcdui.Displayable
addCommand, isShown, removeCommand, setCommandListener
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

adjustFocus

protected boolean adjustFocus
Indicated if focus ajjustment is required

See Also:
recalcAdjustment(), refocus()

bodyOffset

protected int bodyOffset
y-coordinate offset within the body of the first component to display. For example, if the screen container contains more components than can be displayed at one time vertically, this offset will be adjusted to ensure that the screen is scrolled to always display the currently-focused component.


CANVAS_SCROLL_STEP

protected static final int CANVAS_SCROLL_STEP
Scrolling step

See Also:
Constant Field Values

components

protected java.util.Vector components
Vector of GUI components


focusedIndex

protected int focusedIndex
Currently focused component. Index points to components vector


offScreen

protected javax.microedition.lcdui.Image offScreen
Off the screen image for double buffer painting


paintAreaHeight

protected int paintAreaHeight
Height of the scrollable area (of current screen) in pixels


screenTitle

protected Label screenTitle
Screen title


SCROLL_DOWN

public static final int SCROLL_DOWN
Scrolling direction. Used with drawTriangle

See Also:
Constant Field Values

SCROLL_UP

public static final int SCROLL_UP
Scrolling direction. Used with drawTriangle

See Also:
Constant Field Values

softKeyBar

protected SoftKeyBar softKeyBar
SoftKeyBar for current screen this component is not in components vector


softKeyBarHeight

protected int softKeyBarHeight
Height of the scrollbar in pixels


titleHeight

protected int titleHeight
Height of the title in pixels

Constructor Detail

ScreenCanvas

public ScreenCanvas()
Creates a new ScreenCanvas instance.


ScreenCanvas

public ScreenCanvas(Label title)
Creates a new ScreenCanvas instance.

Parameters:
title - The screen title, one line text

ScreenCanvas

public ScreenCanvas(Label title,
                    SoftKeyBar softKeyBar)
Creates a new ScreenCanvas instance.

Parameters:
title - Title for current screen
softKeyBar - Container for soft keys for current screen
Method Detail

add

public void add(Component component)
Adds the component to the screen.

More presicely it adds a component to vector of components for current screen Components are displayed in order of components one component per line

Parameters:
component - the component to be added

add

public void add(Component component,
                int index)
Adds the component to the screen at the given position.

More presicely it adds a component to vector of components for current screen Components are displayed in order of components one component per line

Parameters:
component - the component to be added
index - the position at which to insert the component, or -1 to append the component to the end

changeFocus

public void changeFocus(int newIndex)
Moves the focus to the specified component.

Parameters:
newIndex - The index of component gaining focus

destructor

public void destructor()
Class destructor. Helps VM to perform garbage collection


drawTriangle

public static void drawTriangle(javax.microedition.lcdui.Graphics g,
                                int tipX,
                                int tipY,
                                int maxHeight,
                                int direction,
                                int color)
Support method for painting scroller

See Also:
paintScroller(javax.microedition.lcdui.Graphics)

getComponentsHeight

protected int getComponentsHeight()
Get height of all components

Returns:
height in pixes of all components in vector components for current screen

getFirstFocusable

protected int getFirstFocusable()
Gets first focusable component

Returns:
index of first focusable component, if there is no focusable components returns -1

getLastFocusable

protected int getLastFocusable()
Gets the last focusable component

Returns:
index of last focusable component, if there is no focusable components returns -1

getNextFocusable

protected int getNextFocusable()
Gets next focusable component

Returns:
index of next focusable component, if there is no focusable components returns -1

getPreviousFocusable

protected int getPreviousFocusable()
Gets previous focusable component

Returns:
index of previous focusable component, if there is no previous focusable components returns -1

getScrollDirections

protected int getScrollDirections()
Returns the directions the body can be scrolled in. This should be dynamic depending upon what portion of the body area is displayed.

Returns:
The directions that the body area can be scrolled. Should be 0 if all body elements can be displayed at once, but if not it should be an appropriate bitwise or of SCROLL_UP and/or SCROLL_DOWN

keyPressed

protected void keyPressed(int keyCode)
Processes a press of a key.

Overrides:
keyPressed in class javax.microedition.lcdui.Canvas

paint

public void paint(javax.microedition.lcdui.Graphics g)
Paints the screen's body, which is all of the components that have been added to the screen.

Specified by:
paint in class javax.microedition.lcdui.Canvas
Parameters:
g - Graphics context

paintBody

public void paintBody(javax.microedition.lcdui.Graphics g)
Paints the screen's body, which is all of the components that have been added to the screen.

Parameters:
g - The graphics object to draw to.

paintBodyBackground

protected void paintBodyBackground(javax.microedition.lcdui.Graphics g)
Paints the screen's body background

Parameters:
g - Graphics context

paintScroller

protected void paintScroller(javax.microedition.lcdui.Graphics g)
Paint scrolling indicator(s) at the bottom of the screen to indicate that the display can scroll vertically.

Parameters:
g - Graphics context

recalcAdjustment

protected void recalcAdjustment()

refocus

public void refocus()
Adjust the screen to make focused component visible


remove

public void remove(Component component)
Removes the specified component from this container.

Parameters:
component - the component to be removed

remove

public void remove(int index)
Removes the component, specified by index from the screen

Parameters:
index - the index of the component to be removed.

removeAll

public void removeAll()
Removes all the components from this container.


scrollDown

protected boolean scrollDown()
Scrolls CANVAS_SCROLL_STEP pixels down

Returns:
true if scrolling is possible, false otherwise

scrollTop

protected void scrollTop()
Scrolls to the top of the screen and sets first focusable component to focused state


scrollUp

protected boolean scrollUp()
Scrolls CANVAS_SCROLL_STEP pixels up

Returns:
true if scrolling is possible, false otherwise

jMobileCore toolkit