01: /*
02: * Copyright Javelin Software, All rights reserved.
03: */
04:
05: package com.javelin.swinglets;
06:
07: import java.awt.*;
08: import java.awt.event.*;
09: import java.util.*;
10: import java.io.*;
11:
12: /**
13: * SToggleButton defines a button that has a selected state.
14: * <p>
15: * The value is Boolean.TRUE.toString() or Boolean.FALSE.toString() if it is selected.
16: *
17: * @author Robin Sharp
18: */
19:
20: public class SToggleButton extends SAbstractButton {
21:
22: /**
23: * Creates a SToggleButton with the following text and if selected.
24: */
25: public SToggleButton(String text, boolean selected) {
26: super (text);
27: setSelected(selected);
28: }
29:
30: /**
31: * Creates a SToggleButton with the following text, and unselected.
32: */
33: public SToggleButton(String text) {
34: this (text, false);
35: }
36:
37: /**
38: * Creates a SToggleButton and if selected.
39: */
40: public SToggleButton(boolean selected) {
41: this ("", selected);
42: }
43:
44: /**
45: * Creates a SToggleButton unselected.
46: */
47: public SToggleButton() {
48: this (false);
49: }
50:
51: /**
52: * Returns the name of the L&F class that renders this component.
53: */
54: public Class getUIClass() {
55: return SToggleButton.class;
56: }
57:
58: /**
59: * Process the event and
60: */
61: public void processActionEvent(ActionEvent event) {
62: setValueAsText(event.getActionCommand());
63: super .processActionEvent(event);
64: }
65:
66: /**
67: * Set the value as Text. This sets the selected property to true if the
68: * text matches Boolean.TRUE.toString().
69: */
70: public SComponent setValueAsText(String text) {
71: if (text != null && text.equals(getName())) {
72: setSelected(!isSelected());
73: }
74: return this ;
75: }
76:
77: // PRIVATE /////////////////////////////////////////////////////////////
78:
79: }
|