KickJava   Java API By Example, From Geeks To Geeks.

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


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 package com.google.gwt.user.client.ui;
17
18 import com.google.gwt.user.client.DOM;
19 import com.google.gwt.user.client.Element;
20
21 /**
22  * A standard push-button widget.
23  *
24  * <p>
25  * <img class='gallery' SRC='Button.png'/>
26  * </p>
27  *
28  * <h3>CSS Style Rules</h3>
29  * <ul class="css">
30  * <li>.gwt-Button { }</li>
31  * </ul>
32  *
33  * <p>
34  * <h3>Example</h3> {@example com.google.gwt.examples.ButtonExample}
35  * </p>
36  */

37 public class Button extends ButtonBase {
38
39   static native void click(Element button) /*-{
40     button.click();
41   }-*/
;
42
43   static native void adjustType(Element button) /*-{
44     // Check before setting this attribute, as not all browsers define it.
45     if (button.type == 'submit') {
46       try {
47         button.setAttribute("type", "button");
48       } catch (e) {
49       }
50     }
51   }-*/
;
52
53   /**
54    * Creates a button with no caption.
55    */

56   public Button() {
57     super(DOM.createButton());
58     adjustType(getElement());
59     setStyleName("gwt-Button");
60   }
61
62   /**
63    * Creates a button with the given HTML caption.
64    *
65    * @param html the HTML caption
66    */

67   public Button(String JavaDoc html) {
68     this();
69     setHTML(html);
70   }
71
72   /**
73    * Creates a button with the given HTML caption and click listener.
74    *
75    * @param html the HTML caption
76    * @param listener the click listener
77    */

78   public Button(String JavaDoc html, ClickListener listener) {
79     this(html);
80     addClickListener(listener);
81   }
82
83   /**
84    * Programmatic equivalent of the user clicking the button.
85    */

86   public void click() {
87     click(getElement());
88   }
89 }
90
Popular Tags