001 /*
002 * This file is part of the Echo Point Project. This project is a
003 * collection of Components that have extended the Echo Web Application
004 * Framework Version 3.
005 *
006 * Version: MPL 1.1
007 *
008 * The contents of this file are subject to the Mozilla Public License Version
009 * 1.1 (the "License"); you may not use this file except in compliance with
010 * the License. You may obtain a copy of the License at
011 * http://www.mozilla.org/MPL/
012 *
013 * Software distributed under the License is distributed on an "AS IS" basis,
014 * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
015 * for the specific language governing rights and limitations under the
016 * License.
017 */
018
019 package echopoint;
020
021 import echopoint.internal.AbstractContainer;
022 import nextapp.echo.app.Component;
023 import nextapp.echo.app.ImageReference;
024 import nextapp.echo.app.event.ActionEvent;
025 import nextapp.echo.app.event.ActionListener;
026
027 /**
028 * A button component that by default appears like the system and browser
029 * default. Style configuration allows it to appear more like a {@link
030 * nextapp.echo.app.Button} (although without supporting a background image).
031 *
032 * <p>The following code shows sample usage of this component.</p>
033 * <pre>
034 * import echopoint.PushButton;
035 *
036 * ...
037 * final PushButton button = new PushButton( "Push Button" );
038 * button.setToolTipText( "Push button to see effect." );
039 * button.setWidth( 200 );
040 * button.setActionCommand( "buttonClicked" );
041 * button.addActionListener( ... );
042 *
043 * final Column column = new Columnn();
044 * column.add( button );
045 * </pre>
046 *
047 * @author Rakesh 2009-02-24
048 * @version $Id: PushButton.java 125 2009-02-27 18:51:23Z sptrakesh $
049 */
050 public class PushButton extends AbstractContainer
051 {
052 private static final long serialVersionUID = 1l;
053
054 /**
055 * The property for storing the action command associated with an
056 * action event for the image.
057 */
058 public static final String PROPERTY_ACTION_COMMAND = "actionCommand";
059
060 /** The property for the text displayed in the button. */
061 public static final String PROPERTY_TEXT = "text";
062
063 /** The property for the tooltip displayed when hovering over the button. */
064 public static final String PROPERTY_TOOL_TIP_TEXT = "toolTipText";
065
066 /** Default constructor. No special actions needed. */
067 public PushButton() {}
068
069 /**
070 * Create a new button instance with the specified text.
071 *
072 * @param text The text to display in the button.
073 */
074 public PushButton( final String text )
075 {
076 setText( text );
077 }
078
079 /**
080 * Return the value of {@link #PROPERTY_ACTION_COMMAND} property.
081 *
082 * @return The action command value.
083 */
084 public String getActionCommand()
085 {
086 return (String) get( PROPERTY_ACTION_COMMAND );
087 }
088
089 /**
090 * Set the value of {@link #PROPERTY_ACTION_COMMAND} property.
091 *
092 * @param command The action command value to set.
093 */
094 public void setActionCommand( final String command )
095 {
096 set( PROPERTY_ACTION_COMMAND, command );
097 }
098
099 /**
100 * Return the value of {@link #PROPERTY_TEXT} property used to display
101 * text in the button.
102 *
103 * @return The action command value.
104 */
105 public String getText()
106 {
107 return (String) get( PROPERTY_TEXT );
108 }
109
110 /**
111 * Set the value of {@link #PROPERTY_TEXT} property.
112 *
113 * @param command The action command value to set.
114 */
115 public void setText( final String command )
116 {
117 set( PROPERTY_TEXT, command );
118 }
119
120 /**
121 * Return the value of {@link #PROPERTY_TOOL_TIP_TEXT} property used to display
122 * text in the button.
123 *
124 * @return The action command value.
125 */
126 public String getToolTipText()
127 {
128 return (String) get( PROPERTY_TOOL_TIP_TEXT );
129 }
130
131 /**
132 * Set the value of {@link #PROPERTY_TOOL_TIP_TEXT} property.
133 *
134 * @param command The action command value to set.
135 */
136 public void setToolTipText( final String command )
137 {
138 set( PROPERTY_TOOL_TIP_TEXT, command );
139 }
140
141 /**
142 * Over-ridden to always return {@code null} since this component does not
143 * support background images.
144 *
145 * @return Returns {@code null}.
146 */
147 @Override
148 public ImageReference getBackgroundImage() { return null; }
149
150 /**
151 * Over-ridden to not do anything since this component does not support
152 * background images.
153 *
154 * @param backgroundImage The backgroundImage style to apply.
155 */
156 @Override
157 public void setBackgroundImage( final ImageReference backgroundImage )
158 {
159 // noop
160 }
161
162 /**
163 * Always returns {@code false} since push button does not allow child
164 * components.
165 *
166 * @param component The component to check.
167 * @return Returns {@code false}.
168 */
169 @Override
170 public boolean isValidChild( final Component component )
171 {
172 return false;
173 }
174
175 /** {@inheritDoc} */
176 @Override
177 public void addActionListener( final ActionListener listener )
178 {
179 super.addActionListener( listener );
180 }
181
182 /** {@inheritDoc} */
183 @Override
184 public void removeActionListener( final ActionListener listener )
185 {
186 super.removeActionListener( listener );
187 }
188
189 /** {@inheritDoc} */
190 @Override
191 public void processInput( final String inputName, final Object inputValue )
192 {
193 super.processInput( inputName, inputValue );
194 fireActionPerformed( new ActionEvent( this, getActionCommand() ) );
195 }
196 }