org.apache.wicket.markup.html.image.resource
Class LocalizedImageResource

java.lang.Object
  extended by org.apache.wicket.markup.html.image.resource.LocalizedImageResource
All Implemented Interfaces:
Serializable, IClusterable, IRequestListener, IResourceListener

public final class LocalizedImageResource
extends Object
implements IClusterable, IResourceListener

THIS CLASS IS INTENDED FOR INTERNAL USE IN IMPLEMENTING LOCALE SENSITIVE COMPONENTS THAT USE IMAGE RESOURCES AND SHOULD NOT BE USED DIRECTLY BY END-USERS.

This class contains the logic for extracting static image resources referenced by the SRC attribute of component tags and keeping these static image resources in sync with the component locale.

If no image is specified by the SRC attribute of an IMG tag, then any VALUE attribute is inspected. If there is a VALUE attribute, it must be of the form "[factoryName]:[sharedImageName]?:[specification]". [factoryName] is the name of a resource factory that has been added to Application (for example, DefaultButtonImageResourceFactory is installed by default under the name "buttonFactory"). The [sharedImageName] value is optional and gives a name under which a given generated image is shared. For example, a cancel button image generated by the VALUE attribute "buttonFactory:cancelButton:Cancel" is shared under the name "cancelButton" and this specification will cause a component to reference the same image resource no matter what page it appears on, which is a very convenient and efficient way to create and share images. The [specification] string which follows the second colon is passed directly to the image factory and its format is dependent on the specific image factory. For details on the default buttonFactory, see DefaultButtonImageResourceFactory.

Finally, if there is no SRC attribute and no VALUE attribute, the Image component's model is inspected. If the model contains a resource or resource reference, this image is used, otherwise the model is converted to a String and that value is used as a path to load the image.

Author:
Jonathan Locke
See Also:
Serialized Form

Field Summary
 
Fields inherited from interface org.apache.wicket.IResourceListener
INTERFACE
 
Constructor Summary
LocalizedImageResource(Component component)
          Constructor
 
Method Summary
 void bind()
          Binds this resource if it is shared
 Resource getResource()
          return the resource
 ResourceReference getResourceReference()
          return the resource
 boolean isStateless()
           
 void onResourceRequested()
          Called when a resource is requested.
 void setResource(Resource resource)
           
 void setResourceReference(ResourceReference resourceReference)
           
 void setResourceReference(ResourceReference resourceReference, ValueMap resourceParameters)
           
 void setSrcAttribute(ComponentTag tag)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

LocalizedImageResource

public LocalizedImageResource(Component component)
Constructor

Parameters:
component - The component that owns this localized image resource
Method Detail

bind

public final void bind()
Binds this resource if it is shared


onResourceRequested

public final void onResourceRequested()
Description copied from interface: IResourceListener
Called when a resource is requested.

Specified by:
onResourceRequested in interface IResourceListener
See Also:
IResourceListener.onResourceRequested()

setResource

public final void setResource(Resource resource)
Parameters:
resource - The resource to set.

setResourceReference

public final void setResourceReference(ResourceReference resourceReference)
Parameters:
resourceReference - The resource to set.

isStateless

public final boolean isStateless()
Returns:
true if it has a resourceReference. (it points to a shared resource)

setResourceReference

public final void setResourceReference(ResourceReference resourceReference,
                                       ValueMap resourceParameters)
Parameters:
resourceReference - The resource to set.
resourceParameters - The resource parameters for the shared resource

setSrcAttribute

public final void setSrcAttribute(ComponentTag tag)
Parameters:
tag - The tag to inspect for an optional src attribute that might reference an image.
Throws:
WicketRuntimeException - Thrown if an image is required by the caller, but none can be found.

getResource

public final Resource getResource()
return the resource

Returns:
resource or null if there is none

getResourceReference

public final ResourceReference getResourceReference()
return the resource

Returns:
resource or null if there is none


Copyright © 2004-2011 Apache Software Foundation. All Rights Reserved.