com.partnersoft.v3x.gadgets
Class StackToggle
java.lang.Object
com.partnersoft.v3x.gadgets.ToggleGadget
com.partnersoft.v3x.gadgets.StackToggle
- All Implemented Interfaces:
- Toggle
public class StackToggle
- extends ToggleGadget
A toggle which maintains a sort of "stack" memory of ons and offs, and is
therefore less sensitive to weird toggling sequences that come up in
event-driven GUIs.
A common problem I've run into is where a toggle's state needs to be frobbed
by several gadgets, possibly in different threads. For example, sometimes in
a GUI a state is set on by two separate buttons, each of which turns it off
when deselected. Now if you make them mutually-exclusive, when one is
selected, then the other is selected, the second one frobs the toggle on,
since it's now active, then the first frobs the toggle off, since it's now
inactive. If the toggle is a simple boolean, the net result is an off toggle,
which is not what is wanted.
This one keeps an integer "stack" (I'm probably abusing the term here) which
increments by one for each "on" request and decrements by one for each "off"
request. If the integer is greater than zero, it is "on", else it is off.
|
Method Summary |
void |
setOn(boolean isOn)
Sets toggle state. |
| Methods inherited from class java.lang.Object |
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
StackToggle
public StackToggle()
setOn
public void setOn(boolean isOn)
- Description copied from class:
ToggleGadget
- Sets toggle state.
- Specified by:
setOn in interface Toggle- Overrides:
setOn in class ToggleGadget