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 package echopoint.internal;
019
020 import nextapp.echo.app.Alignment;
021 import nextapp.echo.app.Border;
022 import nextapp.echo.app.Component;
023 import nextapp.echo.app.Extent;
024 import nextapp.echo.app.ImageReference;
025 import nextapp.echo.app.Insets;
026 import nextapp.echo.app.event.ActionEvent;
027 import nextapp.echo.app.event.ActionListener;
028
029 import java.util.EventListener;
030
031 /**
032 * An abstract super class for container components. Defines the standard
033 * style properties supported by container components.
034 *
035 * <p>The following style properites are supported by this component in
036 * addition to those supported by {@link nextapp.echo.app.Component}:</p>
037 * <ul>
038 * <li><code>alignment</code> - The alignment style to apply to the
039 * container element.</li>
040 * <li><code>backgroundImage</code> - A image to set as the background for
041 * the container element.</li>
042 * <li><code>border</code> - The border style to apply to the
043 * container element.</li>
044 * <li><code>insets</code> - The insets to apply for the content embedded
045 * in the container element.</li>
046 * <li><code>height</code> - The height of the container element.
047 * Scrollbars are displayed is needed.</li>
048 * <li><code>width</code> - The width of the container element.
049 * Scrollbars are displayed is needed.</li>
050 * </ul>
051 *
052 * @author Rakesh 2008-07-14
053 * @version $Id: AbstractContainer.java 120 2009-02-20 15:43:33Z sptrakesh $
054 */
055 public class AbstractContainer extends Component
056 {
057 private static final long serialVersionUID = 1l;
058
059 /** The property name for the action command to be updated from client. */
060 public static final String ACTION_COMMAND_PROPERTY = "actionCommand";
061
062 /** The constant used to track changes to the action listener list. */
063 public static final String ACTION_LISTENERS_CHANGED_PROPERTY = "actionListeners";
064
065 /**
066 * The name of the action event registered in the peer when action
067 * listeners are added or removed.
068 */
069 public static final String INPUT_ACTION = "action";
070
071 /** The alignment style for this component. */
072 public static final String PROPERTY_ALIGNMENT = "alignment";
073
074 /** The background image for this component. */
075 public static final String PROPERTY_BACKGROUND_IMAGE = "backgroundImage";
076
077 /** The border style for this component. */
078 public static final String PROPERTY_BORDER = "border";
079
080 /** The insets style for this component. */
081 public static final String PROPERTY_INSETS = "insets";
082
083 /** The height style for this component. */
084 public static final String PROPERTY_HEIGHT = "height";
085
086 /** The width style for this component. */
087 public static final String PROPERTY_WIDTH = "width";
088
089 /**
090 * Return the alignment property for this component.
091 *
092 * @return The alignment specified for this component.
093 */
094 public Alignment getAlignment()
095 {
096 return (Alignment) get( PROPERTY_ALIGNMENT );
097 }
098
099 /**
100 * Set the alignment style for this component.
101 *
102 * @param alignment The alignment style to apply.
103 */
104 public void setAlignment( final Alignment alignment )
105 {
106 set( PROPERTY_ALIGNMENT, alignment );
107 }
108
109 /**
110 * Return the backgroundImage property for this component.
111 *
112 * @return The backgroundImage specified for this component.
113 */
114 public ImageReference getBackgroundImage()
115 {
116 return (ImageReference) get( PROPERTY_BACKGROUND_IMAGE );
117 }
118
119 /**
120 * Set the backgroundImage style for this component.
121 *
122 * @param backgroundImage The backgroundImage style to apply.
123 */
124 public void setBackgroundImage( final ImageReference backgroundImage )
125 {
126 set( PROPERTY_BACKGROUND_IMAGE, backgroundImage );
127 }
128
129 /**
130 * Return the border property for this component.
131 *
132 * @return The border specified for this component.
133 */
134 public Border getBorder()
135 {
136 return (Border) get( PROPERTY_BORDER );
137 }
138
139 /**
140 * Set the border style for this component.
141 *
142 * @param border The border style to apply.
143 */
144 public void setBorder( final Border border )
145 {
146 set( PROPERTY_BORDER, border );
147 }
148
149 /**
150 * Return the insets property for this component.
151 *
152 * @return The insets specified for this component.
153 */
154 public Insets getInsets()
155 {
156 return (Insets) get( PROPERTY_INSETS );
157 }
158
159 /**
160 * Set the insets style for this component.
161 *
162 * @param insets The insets style to apply.
163 */
164 public void setInsets( final Insets insets )
165 {
166 set( PROPERTY_INSETS, insets );
167 }
168
169 /**
170 * Return the height property for this component.
171 *
172 * @return The height specified for this component.
173 */
174 public Extent getHeight()
175 {
176 return (Extent) get( PROPERTY_HEIGHT );
177 }
178
179 /**
180 * Set the height style for this component.
181 *
182 * @param height The height style to apply.
183 */
184 public void setHeight( final Extent height )
185 {
186 set( PROPERTY_HEIGHT, height );
187 }
188
189 /**
190 * Return the width property for this component.
191 *
192 * @return The width specified for this component.
193 */
194 public Extent getWidth()
195 {
196 return (Extent) get( PROPERTY_WIDTH );
197 }
198
199 /**
200 * Set the width style for this component.
201 *
202 * @param width The width style to apply.
203 */
204 public void setWidth( final Extent width )
205 {
206 set( PROPERTY_WIDTH, width );
207 }
208
209 /**
210 * Notifies all listeners that have registered for this event type.
211 *
212 * @param event The {@link nextapp.echo.app.event.ActionEvent} to send
213 */
214 protected void fireActionPerformed( final ActionEvent event )
215 {
216 if ( ! hasEventListenerList() ) return;
217
218 EventListener[] listeners =
219 getEventListenerList().getListeners( ActionListener.class );
220 for ( EventListener listener : listeners )
221 {
222 ( (ActionListener) listener ).actionPerformed( event );
223 }
224 }
225
226 /**
227 * Add the specified action listener to this component.
228 *
229 * @see nextapp.echo.app.Component#firePropertyChange(String, Object, Object)
230 * @param listener The action listener to add.
231 */
232 protected void addActionListener( final ActionListener listener )
233 {
234 getEventListenerList().addListener( ActionListener.class, listener );
235 firePropertyChange( ACTION_LISTENERS_CHANGED_PROPERTY, null, listener );
236 }
237
238 /**
239 * Remove the specified action listener from the component.
240 *
241 * @see nextapp.echo.app.Component#firePropertyChange(String, Object, Object)
242 * @param listener The listener that is to be removed.
243 */
244 protected void removeActionListener( final ActionListener listener )
245 {
246 if ( ! hasEventListenerList() ) return;
247
248 getEventListenerList().removeListener( ActionListener.class, listener );
249 firePropertyChange( ACTION_LISTENERS_CHANGED_PROPERTY, listener, null );
250 }
251
252 /**
253 * Determines if the button has any {@link
254 * nextapp.echo.app.event.ActionListener}s registered.
255 *
256 * @return true if any action listeners are registered
257 */
258 protected boolean hasActionListeners()
259 {
260 return ( hasEventListenerList() &&
261 getEventListenerList().getListenerCount( ActionListener.class ) != 0 );
262 }
263 }