01 
02 /*
03  *  JScripter Standard 1.0 - To Script In Java
04  *  Copyright (C) 2008-2011  J.J.Liu<jianjunliu@126.com> <http://www.jscripter.org>
05  *  
06  *  This program is free software: you can redistribute it and/or modify
07  *  it under the terms of the GNU Affero General Public License as published by
08  *  the Free Software Foundation, either version 3 of the License, or
09  *  (at your option) any later version.
10  *  
11  *  This program is distributed in the hope that it will be useful,
12  *  but WITHOUT ANY WARRANTY; without even the implied warranty of
13  *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14  *  GNU Affero General Public License for more details.
15  *  
16  *  You should have received a copy of the GNU Affero General Public License
17  *  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18  */
19 
20 package jsx.ui.html;
21 
22 import jsx.client.Browser;
23 import jsx.dom.Markups;
24 import jsx.ui.Component;
25 import jsx.ui.css.Pseudo;
26 import jsx.ui.ctrl.Clickable;
27 
28 /**
29  * <p>A base class for HTML elementary button widgets.</p>
30  * 
31  * @author <a href="mailto:jianjunliu@126.com">J.J.Liu (Jianjun Liu)</a> at <a href="http://www.jscripter.org" target="_blank">http://www.jscripter.org</a>
32  */
33 public class Button extends Clickable
34 {
35     /**
36      * <p>Constructs a button widget with a value text and a title text.</p>
37      * @param value The value text for the button.
38      * @param title The title text for the button.
39      * @since 1.0
40      */
41     public Button(String value, String title) {
42         super(Markups.button(value, title));
43     }
44 
45     /**
46      * <p>Constructs a button widget with a value text.</p>
47      * @param value The value text for the button.
48      * @since 1.0
49      */
50     public Button(String value) {
51         super(Markups.button(value));
52     }
53 
54     /**
55      * <p>Initializes the current widget for the newly rendered underlying HTML element.</p>
56      * <p>This method firstly invokes the overridden method of super class for it to behave like a
57      * clickable widget. It then sets up necessary {@link Pseudo} widgets for "active" and
58      * "hover" behaviors for the button.</p>
59      * @since 1.0
60      */
61     @Override
62     protected void init() {
63         super.init();
64         Component e = unwrap();
65         e.pseudo(ACTIVE, "active").attach(e, "mousedown", "mouseup");
66         if (Browser.isIE) {
67             e.handle("losecapture", e.pseudo(ACTIVE, "active").getRemover());
68         }
69     }
70 }