org.zaval.lw
Class LwCheckbox
java.lang.Object
|
+--org.zaval.lw.LwCanvas
|
+--org.zaval.lw.LwPanel
|
+--org.zaval.lw.LwActContainer
|
+--org.zaval.lw.LwCheckbox
- All Implemented Interfaces:
- 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 component 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 the setBoxType method
to redefine the box view type.
It is possible to customize the box component by the setBox method. The default box
component is a LwCanvas component. The checkbox component sets eight views for the component:
- ch.on The view is used to show checkbox "on" state.
- ch.off The view is used to show checkbox "off" state.
- ch.dison The view is used to show checkbox "disabled on" state.
- ch.disoff The view is used to show checkbox "disabled off" state.
- rd.on The view is used to show radio "on" state.
- rd.off The view is used to show radio "off" state.
- rd.dison The view is used to show radio "disabled on" state.
- rd.disoff The view is used to show radio "disabled off" state.
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("ch.on", new LwImgRender("chOn.gif", LwView.ORIGINAL));
man.put("ch.off", new LwImgRender("chOff.gif", LwView.ORIGINAL));
box.setViewMan(man);
...
The component uses LwSwitchManager class to control state of the component. Use the
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.LwCanvas |
bits, bottom, height, isValidValue, left, parent, psHeight, psWidth, right, skins, temporary, top, width, x, y |
|
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,
boolean shouldBeAdded)
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 |
switched(boolean b)
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.LwPanel |
add, add, calcPreferredSize, count, get, getLayoutOffset, getLwComponentAt, getLwLayout, getPreferredSize, indexOf, insert, insert, invalidate, isInvalidatedByChild, laidout, remove, setBackground, setLwLayout, setOpaque, setSize, toFront, updateCashedPs, validate |
| Methods inherited from class org.zaval.lw.LwCanvas |
calcInsets, customize, cvp, getBackground, getBottom, getBounds, getHeight, getInsets, getLeft, getLocation, getLwParent, getOrigin, getPSImpl, getRight, getSize, getTop, getViewMan, getVisiblePart, getWidth, getX, getY, hasFocus, isEnabled, isOpaque, isValid, isVisible, paint, repaint, repaint, repaint, requestFocus, setInsets, setLocation, setLwParent, setPSSize, setViewMan, setVisible, update, viewManChanged, vrp |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface org.zaval.lw.LwComponent |
getBackground, getLwComponentAt, getLwParent, getOrigin, getViewMan, getVisiblePart, isEnabled, isOpaque, paint, repaint, repaint, repaint, setBackground, setInsets, setLwParent, setOpaque, setViewMan, setVisible, update |
| Methods inherited from interface org.zaval.lw.Layoutable |
getBounds, getHeight, getInsets, getLocation, getPreferredSize, getSize, getWidth, getX, getY, isVisible, setLocation, setSize |
RADIO
public static final int RADIO
- The radio box type.
CHECK
public static final int CHECK
- The checkbox box type.
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.
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,
boolean shouldBeAdded)
- 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
only if the given flag says it. An old box component will be removed from the child list.
- Parameters:
b - the specified component.shouldBeAdded - the specified flag that indicates if the new box component
should be inserted into the checkbox component. Use true if the box should be a
part of the checkbox 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.
switched
public void switched(boolean b)
- Invoked when the state of a switching component has been changed to "on" with
the switch manager.
- Specified by:
switched in interface Switchable
- Following copied from interface:
org.zaval.lw.Switchable
- Parameters:
state - the component state. true
if the component has "on" state and false if the
component has "off" state.
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
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
the
componentRemoved method of the manager.
- Overrides:
remove in class LwActContainer
- Following copied from interface:
org.zaval.lw.LwContainer
- Parameters:
i - 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
the
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:
LwCanvas
- Invoked with
validate method only if the component is not valid.
The method should be overridden to calculate metrical characteristics of the component to
minimize computation time of the preferred size for the component. For example, you can
calculate a preferred size inside the method and just return it by
calcPreferredSize method.
- Overrides:
recalc in class LwCanvas
|