fds.micro.ui
Class AbstractPanel

java.lang.Object
  extended byjavax.microedition.lcdui.Displayable
      extended byjavax.microedition.lcdui.Canvas
          extended byfds.micro.ui.AbstractPanel
Direct Known Subclasses:
RowPanel, XYPanel

public abstract class AbstractPanel
extends javax.microedition.lcdui.Canvas

This class implement the basic behaviour for panels that manages components derivated from fds.micro.ui.Component.

It inherits from javax.microedition.lcdui.Canvas. Please see this super-class for generic details.

Warning: Use this class only if you want to have control on rendering. If possible, always prefer javax.microedition.lcdui.Form class.

If you want to write your own container you must respect following rules:

Example of paint() method in fds.micro.ui.AbstractPanel sub-class:

 public void paint(Graphics g) {
     // Layout if necessary
     if( ! this.layoutDone) {
         doLayout();
     }
 
     // Paint components
     super.paint(g);
 }
 

Author:
Frédéric DE STEUR

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
AbstractPanel()
          Build an empty panel.
 
Method Summary
 void addContainerListener(ContainerListener listener)
          Add a listener object that will receive container events produced by this panel.
 void append(Component component)
          Add a component to the container.
 boolean contains(Component component)
          Tests if the specified component is a component in this container.
 java.lang.Object getComponent(int index)
          Gives the component of specified index.
 java.lang.Object[] getComponents()
          Get components within this container.
 int getCount()
          Get the number of components in this container.
 int getFocusIndex()
          Get the index of component that currently have the focus.
 int indexOf(Component component)
          Searches for the first occurence of the given component, testing for equality using the equals method.
 int indexOf(Component component, int index)
          Searches for the first occurence of the given component, beginning the search at index, and testing for equality using the equals method.
 void insert(Component component, int index)
          Inserts the specified component as a component in this container at the specified index (paint order).
 boolean isEmpty()
          Tests if this container has no components.
 int lastIndexOf(Component component)
          Returns the index of the last occurrence of the specified component in this container.
 int lastIndexOf(Component component, int index)
          Returns the index of the last occurrence of the specified component in this container, starting from the specified index.
 void remove(int index)
          Remove a component from the container.
 void removeAll()
          Remove all components from the container.
 void removeContainerListener(ContainerListener listener)
          Remove an container listener.
 Component replace(Component component, int index)
          Replace a component into the container at a given position.
 void setBackground(int red, int green, int blue)
          Set the background color.
 void setComponents(java.lang.Object[] list)
          Reset the container with given components.
 void setFocusIndex(int index)
          Set the index of the component that have the focus.
If the component doesn't manage the focus, the next one is searched.
If no component at all manages the focus, the focus index is set to -1 (no focus).
 void setFocusIndex(int index, boolean ascending)
          Set the index of the component that have the focus.
If the component doesn't manage the focus, the next/prev one is searched (next if ascending, prev if not).
If no component at all manages the focus, the focus index is set to -1 (no focus).
 
Methods inherited from class javax.microedition.lcdui.Canvas
getGameAction, getHeight, getKeyCode, getKeyName, getWidth, hasPointerEvents, hasPointerMotionEvents, hasRepeatEvents, isDoubleBuffered, repaint, repaint, serviceRepaints
 
Methods inherited from class javax.microedition.lcdui.Displayable
addCommand, isShown, removeCommand, setCommandListener
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractPanel

public AbstractPanel()
Build an empty panel.

Method Detail

addContainerListener

public void addContainerListener(ContainerListener listener)
Add a listener object that will receive container events produced by this panel.

Parameters:
listener - The listener to add.

append

public void append(Component component)
Add a component to the container. This component will be the last painted, and have its coordinates already set. The focus is set on the new added component.

Parameters:
component - The component to add.

contains

public boolean contains(Component component)
Tests if the specified component is a component in this container.

Parameters:
component - A component.
Returns:
true if the specified component is a component in this container, false otherwise.

getComponent

public java.lang.Object getComponent(int index)
Gives the component of specified index.

Parameters:
index - The index of wanted component.
Returns:
The component found at specified index.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.

getComponents

public java.lang.Object[] getComponents()
Get components within this container.

Returns:
An array that contains all components (in paint order).

getCount

public int getCount()
Get the number of components in this container.

Returns:
The number of components.

getFocusIndex

public int getFocusIndex()
Get the index of component that currently have the focus.

Returns:
The component index, or -1 if no component have the focus (empty container, or non-managing-focus components).

indexOf

public int indexOf(Component component)
Searches for the first occurence of the given component, testing for equality using the equals method.

Parameters:
component - A component.
Returns:
the index of the first occurrence of the component in this container, or -1 if the component is not found.

indexOf

public int indexOf(Component component,
                   int index)
Searches for the first occurence of the given component, beginning the search at index, and testing for equality using the equals method.

Parameters:
component - A component.
index - the index to start searching from.
Returns:
the index of the first occurrence of the component argument in this container at position index or later in the container. Returns -1 if the component is not found.

insert

public void insert(Component component,
                   int index)
Inserts the specified component as a component in this container at the specified index (paint order). Each component in this container with an index greater or equal to the specified index is shifted upward. to have an index one greater than the value it had previously.

Parameters:
component - The component to insert.
index - Where to insert the new component.

isEmpty

public boolean isEmpty()
Tests if this container has no components.

Returns:
true if this container has no components, false otherwise.

lastIndexOf

public int lastIndexOf(Component component)
Returns the index of the last occurrence of the specified component in this container.

Parameters:
component - A component.
Returns:
the index of the last occurrence of the specified object in this vector, or -1 if the component is not found.

lastIndexOf

public int lastIndexOf(Component component,
                       int index)
Returns the index of the last occurrence of the specified component in this container, starting from the specified index.

Parameters:
component - A component.
index - the index to start searching from.
Returns:
the index of the last occurrence of the specified component in this container at position less than index in the container. Returns -1 if the object is not found.

remove

public void remove(int index)
Remove a component from the container.

Parameters:
index - The index of the component (First = 0).
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.

removeAll

public void removeAll()
Remove all components from the container.


removeContainerListener

public void removeContainerListener(ContainerListener listener)
Remove an container listener.

Parameters:
listener - The listener to remove.

replace

public Component replace(Component component,
                         int index)
Replace a component into the container at a given position. This method have no effect on the focus.

Parameters:
component - The new component to set.
index - The index of the component (First = 0).
Returns:
The component that was present at given index before replacement.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if the index was invalid.

setBackground

public void setBackground(int red,
                          int green,
                          int blue)
Set the background color.

Parameters:
red - The red component of the color.
green - The green component of the color.
blue - The blue component of the color.

setComponents

public void setComponents(java.lang.Object[] list)
Reset the container with given components. The focus is set on first component.

Parameters:
list - Component list to set in container, in paint order (old ones are lost). If null or empty, the effect is equivalent than removeAll().

setFocusIndex

public void setFocusIndex(int index)
Set the index of the component that have the focus.
If the component doesn't manage the focus, the next one is searched.
If no component at all manages the focus, the focus index is set to -1 (no focus).

Parameters:
index - The index of component that newly have the focus, or a negative value to remove the focus.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if given index is too high.

setFocusIndex

public void setFocusIndex(int index,
                          boolean ascending)
Set the index of the component that have the focus.
If the component doesn't manage the focus, the next/prev one is searched (next if ascending, prev if not).
If no component at all manages the focus, the focus index is set to -1 (no focus).

Parameters:
index - The index of component that newly have the focus, or a negative value to remove the focus.
ascending - Must be true to search next component if targeted one don't manage the focus, otherwise the previous one is searched.
Throws:
java.lang.ArrayIndexOutOfBoundsException - if given index is too high.