KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > wings > SButton


1 /*
2  * $Id: SButton.java,v 1.8 2005/02/03 12:44:31 hengels 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
17 import javax.swing.*;
18 import java.awt.event.ActionEvent JavaDoc;
19
20 /**
21  * A button implementation.
22  * This is also a button for usage in a renderer (e.g {@link org.wings.table.STableCellRenderer}).
23  * This button implementation encodes its action command into the low level
24  * event and fires the encoded action command and not the actual action command,
25  * if an low level event triggers a button press.
26  *
27  * @author <a HREF="mailto:armin.haaf@mercatis.de">Armin Haaf</a>
28  * @version $Revision: 1.8 $
29  */

30 public class SButton extends SAbstractButton {
31
32     /**
33      * Creates a button with text.
34      *
35      * @param text the text of the button
36      */

37     public SButton(String JavaDoc text) {
38         super(text);
39     }
40
41     /**
42      * Creates a button where properties are taken from the
43      * Action supplied.
44      *
45      * @param action the Action used to specify the new button
46      */

47     public SButton(Action action) {
48         super(action);
49     }
50
51     /**
52      * Creates a button with no set text or icon.
53      */

54     public SButton() {
55         super();
56     }
57
58     /**
59      * Creates a button with a icon
60      *
61      * @param i the Icon image to display on the button
62      */

63     public SButton(SIcon i) {
64         super();
65         setIcon(i);
66     }
67
68     /**
69      * Creates a button with initial text and an icon.
70      *
71      * @param text the text of the button
72      * @param i the Icon image to display on the button
73      */

74
75     public SButton(String JavaDoc text, SIcon i) {
76         super(text);
77         setIcon(i);
78     }
79
80     protected void setGroup(SButtonGroup g) {
81         if (g != null) {
82             throw new IllegalArgumentException JavaDoc("SButton doesn't support button groups, use SToggleButton");
83         } // end of if ()
84
}
85
86     public boolean isSelected() {
87         return false;
88     }
89
90     private String JavaDoc actionCommandToFire;
91
92     public void processLowLevelEvent(String JavaDoc action, String JavaDoc[] values) {
93         processKeyEvents(values);
94
95         // got an event, that is a select...
96
SForm.addArmedComponent(this);
97
98         if (getShowAsFormComponent() &&
99                 getActionCommand() != null) {
100             actionCommandToFire = getActionCommand();
101         } else {
102             actionCommandToFire = values[0];
103         }
104     }
105
106     public void fireFinalEvents() {
107         requestFocus();
108         fireActionPerformed(new ActionEvent JavaDoc(this, ActionEvent.ACTION_PERFORMED, actionCommandToFire));
109         if (getGroup() != null) {
110             getGroup().fireDelayedFinalEvents();
111         }
112     }
113
114     public String JavaDoc getSelectionParameter() {
115         return getActionCommand() != null ? getActionCommand() : "1";
116     }
117 }
118
Popular Tags