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.internal;
020
021 import nextapp.echo.app.HttpImageReference;
022 import nextapp.echo.app.ImageReference;
023 import nextapp.echo.app.event.ActionEvent;
024 import nextapp.echo.app.event.ActionListener;
025
026 import echopoint.model.Cursor;
027
028 /**
029 * An abstract base class for components that render images.
030 *
031 * @author Rakesh 2009-12-18
032 * @version $Id: AbstractImage.java 262 2009-12-18 21:29:16Z sptrakesh $
033 */
034 public abstract class AbstractImage extends AbstractContainer
035 {
036 /**
037 * The property for storing the action command associated with an
038 * action event for the image.
039 */
040 public static final String PROPERTY_ACTION_COMMAND = "actionCommand";
041
042 /** The image reference for the component. This property may be styled. */
043 public static final String PROPERTY_IMAGE = "url";
044
045 /** The cursor to display when hovering over the image. */
046 public static final String PROPERTY_CURSOR = "cursor";
047
048 /** The alternate text to display is the image cannot be rendered. */
049 public static final String PROPERTY_TEXT = "text";
050
051 /** The tool tip text to display is the image cannot be rendered. */
052 public static final String PROPERTY_TOOL_TIP_TEXT = "toolTipText";
053
054 /**
055 * Return the value of {@link #PROPERTY_ACTION_COMMAND} property.
056 *
057 * @return The action command value.
058 */
059 public String getActionCommand()
060 {
061 return (String) get( PROPERTY_ACTION_COMMAND );
062 }
063
064 /**
065 * Set the value of {@link #PROPERTY_ACTION_COMMAND} property.
066 *
067 * @param command The action command value to set.
068 */
069 public void setActionCommand( final String command )
070 {
071 set( PROPERTY_ACTION_COMMAND, command );
072 }
073
074 /**
075 * Return the value of {@link #PROPERTY_IMAGE} property.
076 *
077 * @return The image reference for the image.
078 */
079 public ImageReference getImage()
080 {
081 return (ImageReference) get( PROPERTY_IMAGE );
082 }
083
084 /**
085 * Set the value of {@link #PROPERTY_IMAGE} property.
086 *
087 * @param image The image reference to set.
088 */
089 public void setImage( final ImageReference image )
090 {
091 set( PROPERTY_IMAGE, image );
092 }
093
094 /**
095 * Set the value of the {@link #PROPERTY_IMAGE} property.
096 *
097 * @param url The URL for the image to use as the map region.
098 */
099 public void setImage( final String url )
100 {
101 setImage( new HttpImageReference( url ) );
102 }
103
104 /**
105 * Return the value of {@link #PROPERTY_CURSOR} property.
106 *
107 * @return The cursor style for the image.
108 */
109 public Cursor getCursor()
110 {
111 return (Cursor) get( PROPERTY_CURSOR );
112 }
113
114 /**
115 * Set the value of {@link #PROPERTY_CURSOR} property.
116 *
117 * @param cursor The cursor style to set.
118 */
119 public void setCursor( final Cursor cursor )
120 {
121 set( PROPERTY_CURSOR, cursor );
122 }
123
124 /**
125 * Return the value of {@link #PROPERTY_TEXT} property.
126 *
127 * @return The alternate text for the image.
128 */
129 public String getText()
130 {
131 return (String) get( PROPERTY_TEXT );
132 }
133
134 /**
135 * Set the value of {@link #PROPERTY_TEXT} property.
136 *
137 * @param text The alternate text to set.
138 */
139 public void setText( final String text )
140 {
141 set( PROPERTY_TEXT, text );
142 }
143
144 /**
145 * Return the value of {@link #PROPERTY_TOOL_TIP_TEXT} property.
146 *
147 * @return The tool tip text for the image.
148 */
149 public String getToolTipText()
150 {
151 return (String) get( PROPERTY_TOOL_TIP_TEXT );
152 }
153
154 /**
155 * Set the value of {@link #PROPERTY_TOOL_TIP_TEXT} property.
156 *
157 * @param text The tool tip text to set.
158 */
159 public void setToolTipText( final String text )
160 {
161 set( PROPERTY_TOOL_TIP_TEXT, text );
162 }
163
164 /**
165 * {@inheritDoc}
166 * @see #fireActionPerformed()
167 */
168 @Override
169 public void processInput( final String inputName, final Object inputValue )
170 {
171 super.processInput( inputName, inputValue );
172 fireActionPerformed();
173 }
174
175 /** {@inheritDoc} */
176 @Override
177 public void addActionListener( final ActionListener listener )
178 {
179 super.addActionListener( listener );
180 }
181
182 /** Notifies all listeners that have registered for this event type. */
183 protected void fireActionPerformed()
184 {
185 fireActionPerformed( new ActionEvent( this, getActionCommand() ) );
186 }
187
188 /** {@inheritDoc} */
189 @Override
190 public void removeActionListener( final ActionListener listener )
191 {
192 super.removeActionListener( listener );
193 }
194
195 /** {@inheritDoc} */
196 public boolean hasActionListeners()
197 {
198 return super.hasActionListeners();
199 }
200
201 /**
202 * Over-ridden to be a {@code noop} since images do not support a
203 * background image.
204 *
205 * @param backgroundImage The backgroundImage to apply.
206 */
207 @Override
208 public void setBackgroundImage( final ImageReference backgroundImage )
209 {
210 // noop
211 }
212 }