KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SToggleButton


1 /*
2  * $Id: SToggleButton.java,v 1.7 2005/05/24 12:02:39 neurolabs Exp $
3  * Copyright 2000,2005 wingS development team.
4  *
5  * This file is part of wingS (http://www.j-wings.org).
6  *
7  * wingS is free software; you can redistribute it and/or modify
8  * it under the terms of the GNU Lesser General Public License
9  * as published by the Free Software Foundation; either version 2.1
10  * of the License, or (at your option) any later version.
11  *
12  * Please see COPYING for the complete licence.
13  */

14 package org.wings;
15
16 import org.wings.plaf.ToggleButtonCG;
17
18 import javax.swing.*;
19
20 /**
21  * @author <a HREF="mailto:haaf@mercatis.de">Armin Haaf</a>
22  * @version $Revision: 1.7 $
23  */

24 public class SToggleButton extends SAbstractButton {
25
26     public SToggleButton(String JavaDoc text) {
27         super(text);
28     }
29
30     public SToggleButton(SIcon icon) {
31         super();
32         setIcon(icon);
33     }
34
35     /**
36      * Creates a button where properties are taken from the
37      * Action supplied.
38      *
39      * @param action the Action used to specify the new button
40      */

41     public SToggleButton(Action action) {
42         super(action);
43     }
44
45     public SToggleButton() {
46     }
47
48     public void setCG(ToggleButtonCG cg) {
49         super.setCG(cg);
50     }
51
52     public void processLowLevelEvent(String JavaDoc action, String JavaDoc[] values) {
53         processKeyEvents(values);
54
55         boolean origSelected = isSelected();
56
57         if (getGroup() != null) {
58             getGroup().setDelayEvents(true);
59             setSelected(parseSelectionToggle(values[0]));
60             getGroup().setDelayEvents(false);
61         } else {
62             setSelected(parseSelectionToggle(values[0]));
63         } // end of else
64

65
66         if (isSelected() != origSelected) {
67             // got an event, that is a select...
68
SForm.addArmedComponent(this);
69         } // end of if ()
70
}
71
72     /**
73      * in form components the parameter value of an button is the button
74      * text. So just toggle selection, in process request, if it is a request
75      * for me.
76      */

77     protected boolean parseSelectionToggle(String JavaDoc toggleParameter) {
78         // a button/image in a form has no value, so just toggle selection...
79
if (getShowAsFormComponent()) {
80             return !isSelected();
81         } // end of if ()
82

83         if ("1".equals(toggleParameter))
84             return true;
85         else if ("0".equals(toggleParameter))
86             return false;
87
88
89         // don't change...
90
return isSelected();
91     }
92
93 }
94
95
96
Popular Tags