001    /*
002     * Copyright 2006 Google Inc.
003     * 
004     * Licensed under the Apache License, Version 2.0 (the "License"); you may not
005     * use this file except in compliance with the License. You may obtain a copy of
006     * the License at
007     * 
008     * http://www.apache.org/licenses/LICENSE-2.0
009     * 
010     * Unless required by applicable law or agreed to in writing, software
011     * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
012     * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
013     * License for the specific language governing permissions and limitations under
014     * the License.
015     */
016    package com.google.gwt.user.client.ui;
017    
018    import com.google.gwt.user.client.DOM;
019    import com.google.gwt.user.client.Element;
020    
021    /**
022     * A standard push-button widget.
023     * 
024     * <p>
025     * <img class='gallery' src='Button.png'/>
026     * </p>
027     * 
028     * <h3>CSS Style Rules</h3>
029     * <ul class="css">
030     * <li>.gwt-Button { }</li>
031     * </ul>
032     * 
033     * <h3>Example</h3>
034     * {@link com.google.gwt.examples.ButtonExample code}
035     */
036    public class Button extends ButtonBase {
037    
038      static native void click(Element button) /*-{
039        button.click();
040      }-*/;
041    
042      /**
043       * Creates a button with no caption.
044       */
045      public Button() {
046        super(DOM.createButton());
047        setStyleName("gwt-Button");
048      }
049    
050      /**
051       * Creates a button with the given HTML caption.
052       * 
053       * @param html the HTML caption
054       */
055      public Button(String html) {
056        this();
057        setHTML(html);
058      }
059    
060      /**
061       * Creates a button with the given HTML caption and click listener.
062       * 
063       * @param html the HTML caption
064       * @param listener the click listener
065       */
066      public Button(String html, ClickListener listener) {
067        this(html);
068        setHTML(html);
069        addClickListener(listener);
070      }
071    
072      /**
073       * Programmatic equivalent of the user clicking the button.
074       */
075      public void click() {
076        click(getElement());
077      }
078    }