waba.ui
Class PushButtonGroup

java.lang.Object
  |
  +--waba.ui.Control
        |
        +--waba.ui.PushButtonGroup

public class PushButtonGroup
extends Control

Group or matrix of pushbuttons in just one control. Is one of the most versatiles controls of superwaba. Created by guich from the original WExtras class Pushbutton of Stefan Kellner. here is a example of constructor:

 new PushButtonGroup(new String[]{"Button1","Button2","Button3"},false,-1,-1,4,0,false,PushButtonGroup.NORMAL)
 

Note: the width of each button is calculated based on its caption size plus the insideGap. Now, the height is calculated based on the font's size or on the height you specified.


Field Summary
static byte BUTTON
          the button will be selected and unselected immediatly, acting like a real button
static byte CHECK
          one click in the button will select it and another click will unselect it.
 boolean[] hidden
          The boolean array that defines which buttons are hidden.
 int maxWidth
           
protected  java.lang.String[] names
           
static byte NORMAL
          normal: only one selected at a time
 
Fields inherited from class waba.ui.Control
AFTER, appId, appObj, asContainer, asWindow, backColor, backDis, BEFORE, BOTTOM, CENTER, clearValueInt, clearValueStr, enabled, FILL, FIT, fm, fmH, focusLess, focusTraversable, font, foreColor, foreDis, height, highlightRectsCount, isHighlighting, LEFT, parent, PREFERRED, RANGE, RIGHT, SAME, TOP, uiCE, uiFlat, uiPalm, uiVista, visible, width, x, x2, y, y2
 
Constructor Summary
PushButtonGroup(java.lang.String[] names, boolean atLeastOne, int selected, int gap, int insideGap, int rows, boolean allSameWidth, byte type)
          Create the button matrix.
PushButtonGroup(java.lang.String[] names, int gap, int rows)
          Create the button matrix, with insideGap = 4, selected = -1, atLeastOne = false, allSameWidth = true and type = BUTTON.
PushButtonGroup(java.lang.String[] names, int gap, int insideGap, int rows)
          Create the button matrix, with selected = -1, atLeastOne = false, allSameWidth = false and type = BUTTON.
 
Method Summary
 void clear()
          Clears this control, selecting index clearValueInt.
 int getPreferredHeight()
          Returns the preffered height of this control.
 int getPreferredWidth()
          Returns the preffered width of this control.
 int getSelected()
          returns the index of the selected button
 java.lang.String getSelectedCaption()
          Returns the caption of the selected button, or null if no button is selected
 void onBoundsChanged()
          Called after a setRect.
protected  void onColorsChanged(boolean colorsChanged)
          Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.
 void onEvent(Event event)
          Called to process key, pen, control and other posted events.
protected  void onFontChanged()
          Called after a setFont
 void onPaint(Graphics g)
          Called to draw the control.
 void setColor(int index, Color fore, Color back)
          Sets a button's index color.
 void setCursorColor(Color color)
          Sets the cursor color for this PushButtonGroup.
 void setNames(java.lang.String[] newNames)
          Sets the names.
 void setSelected(int ind)
          sets the selected button index.
 void setSimpleBorder(boolean simple)
          Uses the old style border
 
Methods inherited from class waba.ui.Control
addTimer, changeHighlighted, contains, createGraphics, drawHighlight, getAbsoluteRect, getBackColor, getFont, getFontMetrics, getForeColor, getNext, getParent, getParentWindow, getPos, getRect, getSize, isDisplayed, isEnabled, isVisible, onWindowPaintFinished, postEvent, removeTimer, repaint, repaintNow, requestFocus, setBackColor, setBackForeColors, setEnabled, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setVisible, translateFromOrigin, uiStyleChanged
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

NORMAL

public static final byte NORMAL
normal: only one selected at a time

BUTTON

public static final byte BUTTON
the button will be selected and unselected immediatly, acting like a real button

CHECK

public static final byte CHECK
one click in the button will select it and another click will unselect it. However, only one button can be selected at a time

names

protected java.lang.String[] names

maxWidth

public int maxWidth

hidden

public boolean[] hidden
The boolean array that defines which buttons are hidden. If you want to hide a button, just access this and set an array index to true. Note that you must also explicitly call the repaint function to update the control. Sample: pbg.hidden[5] = true; // hides button 5 pbg.repaint();
Since:
SuperWaba 5.0
Constructor Detail

PushButtonGroup

public PushButtonGroup(java.lang.String[] names,
                       boolean atLeastOne,
                       int selected,
                       int gap,
                       int insideGap,
                       int rows,
                       boolean allSameWidth,
                       byte type)
Create the button matrix.
Parameters:
names - captions of the buttons. You can specify some names as null so the button is not displayed. This is good if you're creating a button matrix and want to hide some buttons. You can also use the hidden property to dynamically show/hide buttons.
atLeastOne - if true, at least one button must be selected
selected - default index to appear selected, or -1 if none
gap - space between the buttons, -1 glue them.
insideGap - Space between the text and the button border. The ideal is 4. If allSameWidth is true, it is only used to compute the preferred width and may be overriden; otherwise, it is used as the internal gap.
rows - if > 1, creates a button matrix
allSameWidth - if true, all the buttons will have the width of the most large one.
type - can be NORMAL, BUTTON or CHECK

PushButtonGroup

public PushButtonGroup(java.lang.String[] names,
                       int gap,
                       int rows)
Create the button matrix, with insideGap = 4, selected = -1, atLeastOne = false, allSameWidth = true and type = BUTTON.
Parameters:
names - captions of the buttons. You can specify some names as null so the button is not displayed. This is good if you're creating a button matrix and want to hide some buttons. You can also use the hidden property to dynamically show/hide buttons.
gap - space between the buttons, -1 glue them.
rows - if > 1, creates a button matrix

PushButtonGroup

public PushButtonGroup(java.lang.String[] names,
                       int gap,
                       int insideGap,
                       int rows)
Create the button matrix, with selected = -1, atLeastOne = false, allSameWidth = false and type = BUTTON.
Parameters:
names - captions of the buttons. You can specify some names as null so the button is not displayed. This is good if you're creating a button matrix and want to hide some buttons. You can also use the hidden property to dynamically show/hide buttons.
gap - space between the buttons, -1 glue them.
insideGap - Space between the text and the button border. The ideal is 4. If allSameWidth is true, it is only used to compute the preferred width and may be overriden; otherwise, it is used as the internal gap.
rows - if > 1, creates a button matrix
Method Detail

setNames

public void setNames(java.lang.String[] newNames)
Sets the names. Note that it must have the same number of elements passed in the constructor, and that the bounds are NOT recomputed. Repaint is called.

setColor

public void setColor(int index,
                     Color fore,
                     Color back)
Sets a button's index color. The other buttons will remain with the default color. Pass null to restore the default color.

setSimpleBorder

public void setSimpleBorder(boolean simple)
Uses the old style border

getSelected

public int getSelected()
returns the index of the selected button

getSelectedCaption

public java.lang.String getSelectedCaption()
Returns the caption of the selected button, or null if no button is selected
Since:
SuperWaba 4.01

setCursorColor

public void setCursorColor(Color color)
Sets the cursor color for this PushButtonGroup. The default is equal to the background slightly darker. Make sure you tested it in 2,4 and 8bpp devices.

getPreferredWidth

public int getPreferredWidth()
Description copied from class: Control
Returns the preffered width of this control.
Overrides:
getPreferredWidth in class Control

getPreferredHeight

public int getPreferredHeight()
Description copied from class: Control
Returns the preffered height of this control.
Overrides:
getPreferredHeight in class Control

onFontChanged

protected void onFontChanged()
Description copied from class: Control
Called after a setFont
Overrides:
onFontChanged in class Control

onColorsChanged

protected void onColorsChanged(boolean colorsChanged)
Description copied from class: Control
Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled
Overrides:
onColorsChanged in class Control

onBoundsChanged

public void onBoundsChanged()
Description copied from class: Control
Called after a setRect.
Overrides:
onBoundsChanged in class Control

onPaint

public void onPaint(Graphics g)
Description copied from class: Control
Called to draw the control. When this method is called, the graphics object passed has been translated into the coordinate system of the control and the area behind the control has already been painted. The background is painted by the top-level window control.
Overrides:
onPaint in class Control
Tags copied from class: Control
Parameters:
g - the graphics object for drawing
See Also:
Graphics

setSelected

public void setSelected(int ind)
sets the selected button index. Note. if there are any null or hidden buttons, you must count them too to compute the correct index.

onEvent

public void onEvent(Event event)
Description copied from class: Control
Called to process key, pen, control and other posted events.
Overrides:
onEvent in class Control
Tags copied from class: Control
Parameters:
event - the event to process
See Also:
Event, KeyEvent, PenEvent

clear

public void clear()
Clears this control, selecting index clearValueInt. Note that if atLeastOne is true, setting clearValueInt to -1 will have no effect.
Overrides:
clear in class Control