fds.micro.ui
Class ExclusiveChoice

java.lang.Object
  extended byfds.micro.ui.Component
      extended byfds.micro.ui.ExclusiveChoice

public class ExclusiveChoice
extends Component

This class implements an component that provide a way to select an exclusive choice between several ones. You can choose the rendering type to use: Radio buttons or a field with buttons to change the value.
An object of this class is dedicated to be used within an object of fds.micro.ui.AbstractPanel sub-class (J2ME).

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

You can read below a typical use within a class that inherit fds.micro.ui.RowPanel:

Construction

 ...
 // Add an exclusive choice in field mode
 final String options = new String[] {"One", "Two", "Three", "Four", "Five"};
 this.choice = new ExclusiveChoice(options, true); // Radio buttons
 this.choice.setMarkColor(255, 0, 0); // Red dot when an option is selected
 this.choice.setForeground(0, 0, 255); // Blue option labels
 this.choice.setFocusColor(0, 0, 255); // Blue focus color
 this.choice.setMaxCols(3); // Display options on 3 columns
 this.choice.setMaxRows(-1); // Use as many rows as necessary to display all options
 append(choice);
 ...
 
Usage
 ...
 // Here we want to know which option is selected
 int selIndex = this.choice.getSelectedIndex();
 switch(selIndex) {
     case 0:
         ...
         break;
     ...
     default:
     ...
 }
 ...
 

Author:
Frédéric DE STEUR

Field Summary
 
Fields inherited from class fds.micro.ui.Component
INTERN_BOTTOM_VALIGN, INTERN_CENTER_HALIGN, INTERN_CENTER_VALIGN, INTERN_LEFT_HALIGN, INTERN_RIGHT_HALIGN, INTERN_TOP_VALIGN
 
Constructor Summary
ExclusiveChoice(java.lang.String[] labels)
          Build an exclusive choice component rendered by radio buttons, and selects the first one.
ExclusiveChoice(java.lang.String[] labels, boolean radio)
          Build an exclusive choice component and selects the first one.
ExclusiveChoice(java.lang.String[] labels, boolean radio, int selectedIndex)
          Build an exclusive choice component and selects the specified one.
ExclusiveChoice(java.lang.String[] labels, int selectedIndex)
          Build an exclusive choice component rendered by radio buttons, and selects the specified one.
 
Method Summary
 void addValueChangeListener(ValueChangeListener listener)
          Add a listener object that will receive events produced by this component when the value is changed.
 int getChoiceCount()
          Get the number of possible choices.
 javax.microedition.lcdui.Font getFont()
          Get the font used to display choice values.
 int getMaxCols()
          Get the number of maximum columns for displaying radio buttons (a -1 value means no limit).
 int getMaxRows()
          Get the number of maximum rows for displaying radio buttons (a -1 value means no limit).
 int getSelectedIndex()
          Get the index of currently selected choice.
 java.lang.String getSelectedValue()
          Get the text value of currently selected choice.
 int getXInset()
          Get the number of pixels used to separate columns of radio buttons.
 int getYInset()
          Get the number of pixels used to separate rows of radio buttons.
 boolean isBoxOpaque()
          Get the check box opacity flag for box background (field entry zone, or radio button boxes).
 void keyPressed(int keyCode, int gameAction)
          Called to notify the component that a key is pressed.
 void pointerPressed(int xpos, int ypos)
          Called to notify the component that pointer device was pressed.
 void removeValueChangListener(ValueChangeListener listener)
          Remove a listener.
 void setBoxBackground(int red, int green, int blue)
          Set the color of the box background (radio circle or field box).
 void setBoxBackgroundOff(int red, int green, int blue)
          Set the color of the box background (radio circle or field box) in case of the component is disabled.
 void setBoxColor(int red, int green, int blue)
          Set the color of the box (radio circle or field box).
 void setBoxOpaque(boolean boxOpaque)
          Set/reset the opacity flag for box background (field entry zone, or radio button boxes).
 void setFont(javax.microedition.lcdui.Font font)
          Change the font used to display choice values.
 void setForeground(int red, int green, int blue)
          Set the color used to draw the texts.
 void setForegroundOff(int red, int green, int blue)
          Set the color used to draw the texts in case the component is disabled.
 void setMarkColor(int red, int green, int blue)
          Set the color used to draw the selected mark (only used if rendered by radio buttons).
 void setMaxCols(int maxCols)
          Change the number of maximum columns for displaying radio buttons.
 void setMaximumSize(int width, int height)
          Set the maximum size for this component.
 void setMaxRows(int maxRows)
          Change the number of maximum rows for displaying radio buttons.
 void setSelectedIndex(int selectedIndex)
          Change the currently selected choice.
 void setSelectedValue(java.lang.String value)
          Change the currently selected value.
 void setXInset(int xInset)
          Change the number of pixels used to separate columns of radio buttons.
 void setYInset(int yInset)
          Change the number of pixels used to separate rows of radio buttons.
 
Methods inherited from class fds.micro.ui.Component
addFocusListener, addItemListener, equals, getHAlign, getHeight, getParent, getVAlign, getWidth, getX, getY, isDisabled, isHaveFocus, isHidden, isManageFocus, isOpaque, removeFocusListener, removeItemListener, setBackground, setDisabled, setFocusColor, setHAlign, setHidden, setLocation, setManageFocus, setOpaque, setVAlign
 
Methods inherited from class java.lang.Object
getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ExclusiveChoice

public ExclusiveChoice(java.lang.String[] labels)
Build an exclusive choice component rendered by radio buttons, and selects the first one.

Parameters:
labels - Labels to be displayed as choices.

ExclusiveChoice

public ExclusiveChoice(java.lang.String[] labels,
                       boolean radio)
Build an exclusive choice component and selects the first one.

Parameters:
labels - Labels to be displayed as choices.
radio - Must be true to display the choices as radio buttons, otherwise a field will be displayed.

ExclusiveChoice

public ExclusiveChoice(java.lang.String[] labels,
                       boolean radio,
                       int selectedIndex)
Build an exclusive choice component and selects the specified one.

Parameters:
labels - Labels to be displayed as choices.
radio - Must be true to display the choices as radio buttons, otherwise a field will be displayed.
selectedIndex - The initially selected index.

ExclusiveChoice

public ExclusiveChoice(java.lang.String[] labels,
                       int selectedIndex)
Build an exclusive choice component rendered by radio buttons, and selects the specified one.

Parameters:
labels - Labels to be displayed as choices.
selectedIndex - The initially selected index.
Method Detail

addValueChangeListener

public void addValueChangeListener(ValueChangeListener listener)
Add a listener object that will receive events produced by this component when the value is changed.

Parameters:
listener - The listener to add.

getChoiceCount

public int getChoiceCount()
Get the number of possible choices.

Returns:
The number of choices.

getFont

public javax.microedition.lcdui.Font getFont()
Get the font used to display choice values.

Returns:
Returns the font.

getMaxCols

public int getMaxCols()
Get the number of maximum columns for displaying radio buttons (a -1 value means no limit).

Returns:
Returns the number of maximum columns.

getMaxRows

public int getMaxRows()
Get the number of maximum rows for displaying radio buttons (a -1 value means no limit).

Returns:
Returns the number of maximum rows.

getSelectedIndex

public int getSelectedIndex()
Get the index of currently selected choice.

Returns:
Returns the selected index.

getSelectedValue

public java.lang.String getSelectedValue()
Get the text value of currently selected choice.

Returns:
Returns the label of currently selected value.

getXInset

public int getXInset()
Get the number of pixels used to separate columns of radio buttons.

Returns:
Returns the space (in pixels) between columns of radio buttons.

getYInset

public int getYInset()
Get the number of pixels used to separate rows of radio buttons.

Returns:
Returns the space (in pixels) between rows of radio buttons.

isBoxOpaque

public boolean isBoxOpaque()
Get the check box opacity flag for box background (field entry zone, or radio button boxes).

Returns:
Returns true if box background are filled.

keyPressed

public void keyPressed(int keyCode,
                       int gameAction)
Called to notify the component that a key is pressed.

Specified by:
keyPressed in class Component
Parameters:
keyCode - The key code.
gameAction - Game action corresponding to the key code.

pointerPressed

public void pointerPressed(int xpos,
                           int ypos)
Called to notify the component that pointer device was pressed.

Specified by:
pointerPressed in class Component
Parameters:
xpos - The X position of pointer on parent Canvas.
ypos - The Y position of pointer on parent Canvas.

removeValueChangListener

public void removeValueChangListener(ValueChangeListener listener)
Remove a listener.

Parameters:
listener - The listener to remove.

setBoxBackground

public void setBoxBackground(int red,
                             int green,
                             int blue)
Set the color of the box background (radio circle or field box).

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

setBoxBackgroundOff

public void setBoxBackgroundOff(int red,
                                int green,
                                int blue)
Set the color of the box background (radio circle or field box) in case of the component is disabled.

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

setBoxColor

public void setBoxColor(int red,
                        int green,
                        int blue)
Set the color of the box (radio circle or field box).

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

setBoxOpaque

public void setBoxOpaque(boolean boxOpaque)
Set/reset the opacity flag for box background (field entry zone, or radio button boxes).

Parameters:
boxOpaque - Must be true to fill box background.

setFont

public void setFont(javax.microedition.lcdui.Font font)
Change the font used to display choice values.

Parameters:
font - The font to set.

setForeground

public void setForeground(int red,
                          int green,
                          int blue)
Set the color used to draw the texts.

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

setForegroundOff

public void setForegroundOff(int red,
                             int green,
                             int blue)
Set the color used to draw the texts in case the component is disabled.

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

setMarkColor

public void setMarkColor(int red,
                         int green,
                         int blue)
Set the color used to draw the selected mark (only used if rendered by radio buttons).

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

setMaxCols

public void setMaxCols(int maxCols)
Change the number of maximum columns for displaying radio buttons.

Parameters:
maxCols - The number of maximum columns (a -1 value means no limit).

setMaximumSize

public void setMaximumSize(int width,
                           int height)
Set the maximum size for this component.

Overrides:
setMaximumSize in class Component
Parameters:
width - The maximum width.
height - The maximum height.

setMaxRows

public void setMaxRows(int maxRows)
Change the number of maximum rows for displaying radio buttons.

Parameters:
maxRows - The number of maximum rows (a -1 value means no limit).

setSelectedIndex

public void setSelectedIndex(int selectedIndex)
Change the currently selected choice.

Parameters:
selectedIndex - The index to set as selected one.

setSelectedValue

public void setSelectedValue(java.lang.String value)
Change the currently selected value.

Parameters:
value - The value to set. Must be an existing one, otherwise this method have no effect.

setXInset

public void setXInset(int xInset)
Change the number of pixels used to separate columns of radio buttons.

Parameters:
xInset - The space (in pixels) between columns of radio buttons.

setYInset

public void setYInset(int yInset)
Change the number of pixels used to separate rows of radio buttons.

Parameters:
yInset - The space (in pixels) between rows of radio buttons.