KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > google > gwt > user > client > ui > ToggleButton


1 /*
2  * Copyright 2006 Google Inc.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License"); you may not
5  * use this file except in compliance with the License. You may obtain a copy of
6  * the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
12  * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
13  * License for the specific language governing permissions and limitations under
14  * the License.
15  */

16
17 package com.google.gwt.user.client.ui;
18
19 /**
20  * A <code>ToggleButton</code> is a stylish stateful button which allows the
21  * user to toggle between <code>up</code> and <code>down</code> states.
22  *
23  * <p>
24  * <img class='gallery' SRC='ToggleButton.png'/>
25  * </p>
26  *
27  * <h3>CSS Style Rules</h3>
28  * <ul class="css">
29  * <li>.gwt-ToggleButton-up/down/up-hovering/down-hovering/up-disabled/down-disabled {.html-face}</li>
30  * </ul>
31  *
32  * <p>
33  * <h3>Example</h3> {@example com.google.gwt.examples.ToggleButtonExample}
34  * </p>
35  */

36 public class ToggleButton extends CustomButton {
37   private static String JavaDoc STYLENAME_DEFAULT = "gwt-ToggleButton";
38
39   {
40     setStyleName(STYLENAME_DEFAULT);
41   }
42
43   /**
44    * Constructor for <code>ToggleButton</code>.
45    */

46   public ToggleButton() {
47     super();
48   }
49
50   /**
51    * Constructor for <code>ToggleButton</code>. The supplied image is used to
52    * construct the default face.
53    *
54    * @param upImage image for the default face of the button
55    */

56   public ToggleButton(Image upImage) {
57     super(upImage);
58   }
59
60   /**
61    * Constructor for <code>ToggleButton</code>. The supplied image is used to
62    * construct the default face of the button.
63    *
64    * @param upImage image for the default (up) face of the button
65    * @param listener the click listener
66    */

67   public ToggleButton(Image upImage, ClickListener listener) {
68     super(upImage, listener);
69   }
70
71   /**
72    * Constructor for <code>ToggleButton</code>.
73    *
74    * @param upImage image for the default(up) face of the button
75    * @param downImage image for the down face of the button
76    */

77   public ToggleButton(Image upImage, Image downImage) {
78     super(upImage, downImage);
79   }
80
81   /**
82    * Constructor for <code>ToggleButton</code>.
83    *
84    * @param upImage image for the default(up) face of the button
85    * @param downImage image for the down face of the button
86    * @param listener clickListener
87    */

88   public ToggleButton(Image upImage, Image downImage, ClickListener listener) {
89     super(upImage, downImage, listener);
90   }
91
92   /**
93    * Constructor for <code>ToggleButton</code>. The supplied text is used to
94    * construct the default face of the button.
95    *
96    * @param upText the text for the default (up) face of the button.
97    */

98   public ToggleButton(String JavaDoc upText) {
99     super(upText);
100   }
101
102   /**
103    * Constructor for <code>ToggleButton</code>. The supplied text is used to
104    * construct the default face of the button.
105    *
106    * @param upText the text for the default (up) face of the button
107    * @param listener the click listener
108    */

109   public ToggleButton(String JavaDoc upText, ClickListener listener) {
110     super(upText, listener);
111   }
112
113   /**
114    * Constructor for <code>ToggleButton</code>.
115    *
116    * @param upText the text for the default (up) face of the button
117    * @param downText the text for down face of the button
118    */

119   public ToggleButton(String JavaDoc upText, String JavaDoc downText) {
120     super(upText, downText);
121   }
122
123   public boolean isDown() {
124     // Changes access to public.
125
return super.isDown();
126   }
127   
128   public void setDown(boolean down) {
129     // Changes access to public.
130
super.setDown(down);
131   }
132   
133   protected void onClick() {
134     toggleDown();
135     super.onClick();
136   }
137 }
138
Popular Tags