Class WImage
- java.lang.Object
-
- com.github.bordertech.wcomponents.AbstractWComponent
-
- com.github.bordertech.wcomponents.WBeanComponent
-
- com.github.bordertech.wcomponents.WImage
-
- All Implemented Interfaces:
AjaxTarget
,BeanAware
,BeanBound
,BeanProviderBound
,DataBound
,Targetable
,WComponent
,WebComponent
,Serializable
- Direct Known Subclasses:
WEditableImage
public class WImage extends WBeanComponent implements Targetable, AjaxTarget
The WImage component provides a way for applications to display images within their application. It may either serve up a pre-defined image which is part of the application, or generate the image dynamically.
// Example of using a pre-defined image included in the applications class-path new WImage("/com/mycompany/myapp/somePackage/logo.png", "Application logo");
// Example of using a dynamic image WImage image = new WImage(); image.setImage(new com.github.bordertech.wcomponents.Image() { public Dimension getSize() { // Both width and height are unknown return new Dimension(-1, -1); } public String getString() { return "Include a relevant description of the image here"; } public String getMimeType() { // e.g. if serving up a PNG image return "image/png"; } public byte[] getBytes() { // read in or create the image binary data here. } });
- Since:
- 1.0.0
- Author:
- Kishan Bisht
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
WImage.ImageModel
Holds the extrinsic state information of a WImage.-
Nested classes/interfaces inherited from class com.github.bordertech.wcomponents.AbstractWComponent
AbstractWComponent.WComponentRef
-
-
Field Summary
-
Fields inherited from interface com.github.bordertech.wcomponents.WComponent
DEFAULT_APPLICATION_ID, DEFAULT_INTERNAL_ID, DEFAULT_NO_ID, ID_CONTEXT_SEPERATOR, ID_FRAMEWORK_ASSIGNED_SEPERATOR, ID_VALIDATION_PATTERN
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description String
getAlternativeText()
Retrieve the alternative text for the image.String
getCacheKey()
Retrieves the cache key for this image.protected WImage.ImageModel
getComponentModel()
Returns the effective component model for this component.Image
getImage()
Retrieves the current image.String
getImageUrl()
protected WImage.ImageModel
getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified.Dimension
getSize()
Retrieve the image size.String
getTargetId()
Returns the id to use to target this component.String
getTargetUrl()
Creates a dynamic URL that the image can be loaded from.void
handleRequest(Request request)
When an img element is included in the html output of a page, the browser will make a second request to get the image contents.protected WImage.ImageModel
newComponentModel()
Creates a new component model appropriate for this component.void
setAlternativeText(String text)
void
setCacheKey(String cacheKey)
A cache key is used to enable the caching of images on the client agent.void
setImage(Image image)
Sets the image.void
setImageUrl(String imageUrl)
Sets the image to an external URL.void
setSize(Dimension size)
String
toString()
Creates a String representation of this component; usually for debugging purposes.-
Methods inherited from class com.github.bordertech.wcomponents.WBeanComponent
addBeanToScratchMap, doUpdateBeanValue, getBean, getBeanFromScratchMap, getBeanId, getBeanProperty, getBeanProvider, getBeanScratchMap, getBeanValue, getData, isBeanInScratchMap, isChanged, isSearchAncestors, isUseRequestScopeScratchMap, removeBeanFromScratchMap, resetData, setBean, setBeanId, setBeanProperty, setBeanProvider, setData, setSearchAncestors, updateBeanValue
-
Methods inherited from class com.github.bordertech.wcomponents.AbstractWComponent
addHtmlClass, addHtmlClass, addNotify, afterPaint, assertAddSupported, beforePaint, createErrorDiagnostic, createErrorDiagnostic, forward, getAccessibleText, getAttribute, getBaseUrl, getDefaultModel, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getScratchMap, getTabIndex, getTag, getTemplate, getTemplateMarkUp, getToolTip, hasNoComponentModel, hasTabIndex, initialiseComponentModel, invokeLater, invokeLaters, isDebugStructure, isDefaultState, isFlagSet, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, paintComponent, preparePaint, preparePaintComponent, removeAttribute, removeComponentModel, removeHtmlClass, removeHtmlClass, removeNotify, replaceWComponent, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFlag, setFocussed, setHidden, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showErrorIndicatorsForComponent, showWarningIndicators, showWarningIndicatorsForComponent, tidyUpUIContext, tidyUpUIContextForTree, validate, validateComponent, writeReplace
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface com.github.bordertech.wcomponents.WComponent
addHtmlClass, addHtmlClass, forward, getAccessibleText, getAttribute, getBaseUrl, getEnvironment, getHeaders, getHtmlClass, getHtmlClasses, getId, getIdName, getInternalId, getLabel, getName, getParent, getTabIndex, getTag, getToolTip, hasTabIndex, invokeLater, isDefaultState, isHidden, isInitialised, isLocked, isTracking, isTrackingEnabled, isValidate, isVisible, paint, preparePaint, removeAttribute, removeHtmlClass, removeHtmlClass, reset, serviceRequest, setAccessibleText, setAttribute, setEnvironment, setFocussed, setHtmlClass, setHtmlClass, setIdName, setInitialised, setLocked, setTag, setToolTip, setTrackingEnabled, setValidate, setVisible, showErrorIndicators, showWarningIndicators, tidyUpUIContextForTree, validate
-
-
-
-
Constructor Detail
-
WImage
public WImage()
Creates a WImage with no content.
-
WImage
public WImage(String imageResource, String description)
Creates a WImage with the given static content. This is provided as a convenience method for when the image is included as static content in the class path rather than in the web application's resources.
The mime type for the image is looked up from the "mimeType.*" mapping configuration parameters using the resource's file extension.
- Parameters:
imageResource
- the resource path to the image file.description
- the image description.
-
WImage
public WImage(ImageResource image)
Creates a WImage with the given image resource.- Parameters:
image
- the image resource
-
-
Method Detail
-
getTargetUrl
public String getTargetUrl()
Creates a dynamic URL that the image can be loaded from. In fact the URL points to the main application servlet, but includes a non-null for the parameter associated with this WComponent (ie, its label). The handleRequest method below detects this when the browser requests the image- Returns:
- the url to load the image from
-
handleRequest
public void handleRequest(Request request)
When an img element is included in the html output of a page, the browser will make a second request to get the image contents. The handleRequest method has been overridden to detect whether the request is the "image content fetch" request by looking for the parameter that we encode in the image url.- Specified by:
handleRequest
in interfaceWComponent
- Overrides:
handleRequest
in classAbstractWComponent
- Parameters:
request
- the request being responded to.
-
setImage
public void setImage(Image image)
Sets the image.- Parameters:
image
- the image to set.
-
setImageUrl
public void setImageUrl(String imageUrl)
Sets the image to an external URL.- Parameters:
imageUrl
- the image URL.
-
getImageUrl
public String getImageUrl()
- Returns:
- the image to an external URL.
-
getImage
public Image getImage()
Retrieves the current image.- Returns:
- the current image.
-
getCacheKey
public String getCacheKey()
Retrieves the cache key for this image. This is used to enable caching of the image on the client agent.- Returns:
- the cacheKey
-
setCacheKey
public void setCacheKey(String cacheKey)
A cache key is used to enable the caching of images on the client agent.The cache key should be unique for each image.
- Parameters:
cacheKey
- the cacheKey to set.
-
getSize
public Dimension getSize()
Retrieve the image size.Returns the size set via
setSize(Dimension)
. If this has not been set and an image resource is provideing the image then the size of the image resource is returned. Otherwise return null.- Returns:
- the size of the image.
-
setSize
public void setSize(Dimension size)
- Parameters:
size
- the size of the image.
-
getAlternativeText
public String getAlternativeText()
Retrieve the alternative text for the image.Returns the alternative text set via
setAlternativeText(String)
. If this has not been set and an image resource is providing the image then the description of the image resource is returned. Otherwise return null.- Returns:
- the alternative text for the image.
-
setAlternativeText
public void setAlternativeText(String text)
- Parameters:
text
- the alternative text for the image
-
getTargetId
public String getTargetId()
Returns the id to use to target this component.- Specified by:
getTargetId
in interfaceTargetable
- Returns:
- this component's target id.
-
toString
public String toString()
Description copied from class:AbstractWComponent
Creates a String representation of this component; usually for debugging purposes.- Overrides:
toString
in classAbstractWComponent
- Returns:
- a String representation of this component, for debugging purposes.
-
newComponentModel
protected WImage.ImageModel newComponentModel()
Creates a new component model appropriate for this component.- Overrides:
newComponentModel
in classWBeanComponent
- Returns:
- a new ImageModel.
-
getComponentModel
protected WImage.ImageModel getComponentModel()
Returns the effective component model for this component. Subclass may override this method to narrow the return type to their specific model type.- Overrides:
getComponentModel
in classWBeanComponent
- Returns:
- the effective component model
-
getOrCreateComponentModel
protected WImage.ImageModel getOrCreateComponentModel()
Retrieves the model for this component so that it can be modified. If this method is called during request processing, and a session specific model does not yet exist, then a new model is created. Subclasses may override this method to narrow the return type to their specific model type.- Overrides:
getOrCreateComponentModel
in classWBeanComponent
- Returns:
- the model for this component
-
-