001: /*
002: * Copyright 2000,2005 wingS development team.
003: *
004: * This file is part of wingS (http://wingsframework.org).
005: *
006: * wingS is free software; you can redistribute it and/or modify
007: * it under the terms of the GNU Lesser General Public License
008: * as published by the Free Software Foundation; either version 2.1
009: * of the License, or (at your option) any later version.
010: *
011: * Please see COPYING for the complete licence.
012: */
013: package org.wings;
014:
015: import javax.swing.*;
016: import java.awt.event.ActionEvent;
017:
018: /**
019: * Simple Button widget.
020: * <p/>
021: * This is also a button for usage in a renderer (e.g {@link org.wings.table.STableCellRenderer}).
022: * This button implementation encodes its action command into the low level
023: * event and fires the encoded action command and not the actual action command,
024: * if an low level event triggers a button press.
025: *
026: * @author <a href="mailto:armin.haaf@mercatis.de">Armin Haaf</a>
027: */
028: public class SButton extends SAbstractButton {
029:
030: /**
031: * Creates a button with text.
032: *
033: * @param text the text of the button
034: */
035: public SButton(String text) {
036: super (text);
037: }
038:
039: /**
040: * Creates a button where properties are taken from the
041: * Action supplied.
042: *
043: * @param action the Action used to specify the new button
044: */
045: public SButton(Action action) {
046: super (action);
047: }
048:
049: /**
050: * Creates a button with no set text or icon.
051: */
052: public SButton() {
053: super ();
054: }
055:
056: /**
057: * Creates a button with a icon
058: *
059: * @param i the Icon image to display on the button
060: */
061: public SButton(SIcon i) {
062: super ();
063: setIcon(i);
064: }
065:
066: /**
067: * Creates a button with initial text and an icon.
068: *
069: * @param text the text of the button
070: * @param i the Icon image to display on the button
071: */
072:
073: public SButton(String text, SIcon i) {
074: super (text);
075: setIcon(i);
076: }
077:
078: protected void setGroup(SButtonGroup g) {
079: if (g != null) {
080: throw new IllegalArgumentException(
081: "SButton doesn't support button groups, use SToggleButton");
082: } // end of if ()
083: }
084:
085: /**
086: * Returns the state of the button. This can be true if the button is selected, otherwise false.
087: *
088: * @return true if the button is selected, false if not
089: */
090: public boolean isSelected() {
091: return false;
092: }
093:
094: private String actionCommandToFire;
095:
096: public void processLowLevelEvent(String action, String[] values) {
097: processKeyEvents(values);
098: if (action.endsWith("_keystroke"))
099: return;
100:
101: // got an event, that is a select...
102: SForm.addArmedComponent(this );
103:
104: if (getShowAsFormComponent() && getActionCommand() != null) {
105: actionCommandToFire = getActionCommand();
106: } else {
107: actionCommandToFire = values[0];
108: }
109: }
110:
111: public void fireFinalEvents() {
112: fireActionPerformed(new ActionEvent(this ,
113: ActionEvent.ACTION_PERFORMED, actionCommandToFire));
114: if (getGroup() != null) {
115: getGroup().fireDelayedFinalEvents();
116: }
117: }
118:
119: public String getSelectionParameter() {
120: return getActionCommand() != null ? getActionCommand() : "1";
121: }
122: }
|