org.zaval.lw
Class LwCheckbox

java.lang.Object
  |
  +--org.zaval.util.ValidationObject
        |
        +--org.zaval.lw.LwCanvas
              |
              +--org.zaval.lw.LwPanel
                    |
                    +--org.zaval.lw.LwActContainer
                          |
                          +--org.zaval.lw.LwCheckbox
All Implemented Interfaces:
Drawable, java.util.EventListener, Layoutable, LayoutContainer, LwComponent, LwComposite, LwContainer, LwKeyListener, LwMouseListener, Switchable, Validationable

public class LwCheckbox
extends LwActContainer
implements LwMouseListener, LwKeyListener, Switchable

The class represents a switching GUI componenent that can have one of two states: "on" or "off". The component is a container that consists of a label component and a box component. It is possible to use any light weight component as the label or the box. The box component is used to indicate a state of the component. The component supports two box view types:

Use appropriate constants to construct necessary checkbox or setBoxType method to redefine the box view type.

It is possible to customize the box component by setBox method. The default box component is a LwCanvas component. The checkbox component sets eight views for the component:

The sample below illustrates how the box view can be customized:
   ...
   LwCheckbox   checkbox = new LwCheckbox("Checkbox");
   LwComponent  box = checkbox.getBox();
   LwAdvViewMan man = new LwAdvViewMan();
   man.put("check.on", LwImgRender("chOn.gif"));
   man.put("check.off", LwImgRender("chOff.gif"));
   box.setViewMan(man);
   ...
 

The component uses LwSwitchManager class to control state of the component. Use setSwitchManager method to define the switch manager and getSwitchManager to get the current switch manager. Use the switch manager to listen action events that are performed whenever the state of the component has been changed.


Field Summary
static int CHECK
          The checkbox box type.
static int RADIO
          The radio box type.
 
Fields inherited from class org.zaval.lw.LwPanel
children
 
Fields inherited from class org.zaval.lw.LwCanvas
bits, height, insets, parent, psHeight, psWidth, skins, width, x, y
 
Fields inherited from class org.zaval.util.ValidationObject
isValidFlag
 
Constructor Summary
LwCheckbox()
          Constructs a checkbox component with no label.
LwCheckbox(LwComponent c, int type)
          Constructs a checkbox component with the specified component as a label and the given box view type.
LwCheckbox(java.lang.String lab)
          Constructs a checkbox component with the specified label text.
LwCheckbox(java.lang.String lab, int type)
          Constructs a checkbox component with the specified label text and the given box view type.
 
Method Summary
 LwComponent getBox()
          Gets the component that is used as a the box component with the component.
 int getBoxType()
          Gets the box view type.
 boolean getState()
          Gets the state of the checkbox.
 LwSwitchManager getSwitchManager()
          Gets the switch manager that is used with the checkbox.
 void keyPressed(LwKeyEvent e)
          Invoked when a key has been pressed.
 void keyReleased(LwKeyEvent e)
          Invoked when a key has been released.
 void keyTyped(LwKeyEvent e)
          Invoked when a key has been typed.
 void mouseClicked(LwMouseEvent e)
          Invoked when the mouse button has been clicked on a light weight component.
 void mouseEntered(LwMouseEvent e)
          Invoked when the mouse enters a light weight component.
 void mouseExited(LwMouseEvent e)
          Invoked when the mouse exits a light weight component.
 void mousePressed(LwMouseEvent e)
          Invoked when the mouse button has been pressed on a light weight component.
 void mouseReleased(LwMouseEvent e)
          Invoked when the mouse button has been released on a light weight component.
protected  void recalc()
          Invoked with validate method only if the component is not valid.
 void remove(int i)
          Removes the component, specified by the index, from this container.
 void removeAll()
          Removes all child components from this container.
 void setBox(int i)
          Sets a child component as the box component by the specified child index.
 void setBox(LwComponent b)
          Sets the specified component as the box component.
 void setBoxType(int t)
          Sets the specified box view type.
 void setEnabled(boolean b)
          Enables or disables this component.
 void setState(boolean b)
          Sets the specified state of the checkbox.
 void setSwitchManager(LwSwitchManager m)
          Sets the specified switch manager to control state of the component.
 void switchedOff()
          Invoked when the state of a switching component has been changed to "off" with the switch manager.
 void switchedOn()
          Invoked when the state of a switching component has been changed to "on" with the switch manager.
 void sync()
          Invoked whenever it is necessary to set appropriate box view for the current state.
 
Methods inherited from class org.zaval.lw.LwActContainer
canHaveFocus, catchInput, getDefaultLayout, getFocusComponent, getRectColor, paintOnTop, setAsFocusComponent, setRectColor
 
Methods inherited from class org.zaval.lw.LwPanel
add, add, calcPreferredSize, count, get, getLayoutOffset, getLwComponentAt, getLwLayout, indexOf, insert, insert, invalidate, remove, setBackground, setLwLayout, setOpaque, toFront, updateCashedPs
 
Methods inherited from class org.zaval.lw.LwCanvas
getBackground, getBounds, getHeight, getInsets, getLocation, getLwParent, getOrigin, getPreferredSize, getSize, getViewMan, getVisiblePart, getWidth, getX, getY, hasFocus, isEnabled, isOpaque, isVisible, paint, repaint, repaint, requestFocus, setInsets, setLocation, setLwParent, setPSSize, setSize, setViewMan, setVisible, toString, update, validate, viewManChanged, vrp
 
Methods inherited from class org.zaval.util.ValidationObject
isValid
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.zaval.lw.LwContainer
add, add, getLwLayout, indexOf, insert, setLwLayout
 
Methods inherited from interface org.zaval.lw.LwComponent
getLwComponentAt, getLwParent, getViewMan, getVisiblePart, setBackground, setLwParent, setViewMan, setVisible
 
Methods inherited from interface org.zaval.lw.Drawable
getBackground, getOrigin, isEnabled, isOpaque, paint, repaint, repaint, setOpaque, update
 
Methods inherited from interface org.zaval.util.Validationable
invalidate, isValid, validate
 
Methods inherited from interface org.zaval.lw.Layoutable
getBounds, getHeight, getInsets, getLocation, getPreferredSize, getSize, getWidth, getX, getY, isVisible, setLocation, setSize
 
Methods inherited from interface org.zaval.lw.LayoutContainer
count, get, getLayoutOffset
 

Field Detail

RADIO

public static final int RADIO
The radio box type.

CHECK

public static final int CHECK
The checkbox box type.
Constructor Detail

LwCheckbox

public LwCheckbox()
Constructs a checkbox component with no label.

LwCheckbox

public LwCheckbox(java.lang.String lab)
Constructs a checkbox component with the specified label text. In this case the component creates appropriate LwLabel component with the text and uses it as the checkbox label.
Parameters:
lab - the specified label text.

LwCheckbox

public LwCheckbox(java.lang.String lab,
                  int type)
Constructs a checkbox component with the specified label text and the given box view type. The component creates appropriate LwLabel component with the text and uses it as the checkbox label. It is necessary to use RADIO or CHECK as the box view type.
Parameters:
lab - the specified label text.
type - the box view type.

LwCheckbox

public LwCheckbox(LwComponent c,
                  int type)
Constructs a checkbox component with the specified component as a label and the given box view type. The component uses the component as the checkbox label. It is possible to use RADIO or CHECK as the box view type.
Parameters:
c - the specified component to be used as the checkbox label.
type - the box view type.
Method Detail

setBoxType

public void setBoxType(int t)
Sets the specified box view type. It is possible to use RADIO or CHECK as the box view type.
Parameters:
t - the specified box view type.

getBoxType

public int getBoxType()
Gets the box view type.
Returns:
a box view type.

setBox

public void setBox(int i)
Sets a child component as the box component by the specified child index. The box component indicates the current state of the checkbox.
Parameters:
i - the specified child index.

setBox

public void setBox(LwComponent b)
Sets the specified component as the box component. The box component indicates the current state of the checkbox. The new box component will be inserted as a child of the component and an old box component will be removed from the child list.
Parameters:
b - the specified component.

getBox

public LwComponent getBox()
Gets the component that is used as a the box component with the component.
Returns:
a box component.

setSwitchManager

public void setSwitchManager(LwSwitchManager m)
Sets the specified switch manager to control state of the component.
Parameters:
m - the specified switch manager. It is impossible to use null value as the switch manager, in this case IllegalArgumentException will be thrown.

getSwitchManager

public LwSwitchManager getSwitchManager()
Gets the switch manager that is used with the checkbox.
Returns:
a switch manager

setState

public void setState(boolean b)
Sets the specified state of the checkbox. The method calls appropriate method of the checkbox switch manager.
Parameters:
b - the specified state. Use true to set "on" state and false to set "off" state.

getState

public boolean getState()
Gets the state of the checkbox. The method calls appropriate method of the checkbox switch manager.
Returns:
a state of the checkbox.

switchedOn

public void switchedOn()
Invoked when the state of a switching component has been changed to "on" with the switch manager.
Specified by:
switchedOn in interface Switchable

switchedOff

public void switchedOff()
Invoked when the state of a switching component has been changed to "off" with the switch manager.
Specified by:
switchedOff in interface Switchable

sync

public void sync()
Invoked whenever it is necessary to set appropriate box view for the current state.

setEnabled

public void setEnabled(boolean b)
Description copied from interface: LwComponent
Enables or disables this component. An enabled component can participate in events handling and performing processes. Component is enabled initially by default.
Overrides:
setEnabled in class LwCanvas
Following copied from interface: org.zaval.lw.LwComponent
Parameters:
b - if the value is true - enables the component; otherwise disables this component.

mouseClicked

public void mouseClicked(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse button has been clicked on a light weight component.
Specified by:
mouseClicked in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

mouseReleased

public void mouseReleased(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse button has been released on a light weight component.
Specified by:
mouseReleased in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

mousePressed

public void mousePressed(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse button has been pressed on a light weight component.
Specified by:
mousePressed in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

keyPressed

public void keyPressed(LwKeyEvent e)
Description copied from interface: LwKeyListener
Invoked when a key has been pressed.
Specified by:
keyPressed in interface LwKeyListener
Following copied from interface: org.zaval.lw.event.LwKeyListener
Parameters:
e - the specified key event.

remove

public void remove(int i)
Description copied from interface: LwContainer
Removes the component, specified by the index, from this container. The layout manager of this container should be informed by calling componentRemoved method of the manager.
Overrides:
remove in class LwActContainer
Following copied from interface: org.zaval.lw.LwContainer
Parameters:
index - the index of the component to be removed.

removeAll

public void removeAll()
Description copied from interface: LwContainer
Removes all child components from this container. The layout manager of this container should be informed by calling componentRemoved method of the manager for every child component that has been removed.
Overrides:
removeAll in class LwActContainer

mouseEntered

public void mouseEntered(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse enters a light weight component.
Specified by:
mouseEntered in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

mouseExited

public void mouseExited(LwMouseEvent e)
Description copied from interface: LwMouseListener
Invoked when the mouse exits a light weight component.
Specified by:
mouseExited in interface LwMouseListener
Following copied from interface: org.zaval.lw.event.LwMouseListener
Parameters:
e - the specified mouse event.

keyReleased

public void keyReleased(LwKeyEvent e)
Description copied from interface: LwKeyListener
Invoked when a key has been released.
Specified by:
keyReleased in interface LwKeyListener
Following copied from interface: org.zaval.lw.event.LwKeyListener
Parameters:
e - the specified key event.

keyTyped

public void keyTyped(LwKeyEvent e)
Description copied from interface: LwKeyListener
Invoked when a key has been typed.
Specified by:
keyTyped in interface LwKeyListener
Following copied from interface: org.zaval.lw.event.LwKeyListener
Parameters:
e - the specified key event.

recalc

protected void recalc()
Description copied from class: LwPanel
Invoked with validate method only if the component is not valid. The method should not be overrided for this container like it can be done for LwCanvas, because the method starts validating and layouting of the child components.
Overrides:
recalc in class LwPanel


Copyright © Zaval Creative Engineering Group, 2000-2005.
http://www.zaval.org