org.zkoss.zul
Class Image

java.lang.Object
  extended by org.zkoss.zk.ui.AbstractComponent
      extended by org.zkoss.zk.ui.HtmlBasedComponent
          extended by org.zkoss.zul.impl.XulElement
              extended by org.zkoss.zul.Image
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable, HtmlBasedComponent, Component, Scope, ComponentCtrl, Image, XulElement
Direct Known Subclasses:
Captcha, Imagemap, ThemeImage

public class Image
extends XulElement
implements Image

An image.

Note: IE 5.5/6 (not 7) has a bug that failed to render PNG with alpha transparency. See http://homepage.ntlworld.com/bobosola/index.htm for details. Thus, if you want to display such image, you have to use the alphafix mold. <image mold="alphafix"/>

Author:
tomyeh
See Also:
Serialized Form

Nested Class Summary
protected  class Image.ExtraCtrl
          A utility class to implement AbstractComponent.getExtraCtrl().
 
Nested classes/interfaces inherited from class org.zkoss.zk.ui.AbstractComponent
AbstractComponent.Children
 
Field Summary
 
Fields inherited from class org.zkoss.zk.ui.HtmlBasedComponent
_zclass, RS_NO_DISPLAY, RS_NO_HEIGHT, RS_NO_WIDTH
 
Fields inherited from class org.zkoss.zk.ui.AbstractComponent
_visible
 
Fields inherited from interface org.zkoss.zk.ui.Component
APPLICATION_SCOPE, COMPONENT_SCOPE, DESKTOP_SCOPE, PAGE_SCOPE, REQUEST_SCOPE, SESSION_SCOPE, SPACE_SCOPE
 
Constructor Summary
Image()
           
Image(java.lang.String src)
           
 
Method Summary
 java.lang.String getAlign()
          Returns the alignment.
 java.lang.String getBorder()
          Returns the width of the border.
 Image getContent()
          Returns the content set by setContent(org.zkoss.image.Image).
 java.lang.String getHover()
          Returns the URI of the hover image.
 java.lang.String getHspace()
          Returns number of pixels of extra space to the left and right side of the image.
 java.lang.String getInnerAttrs()
          Generates the Client-Side-Action attributes to the interior tag.
 java.lang.String getOuterAttrs()
          Returns the exterior attributes for generating the enclosing HTML tag; never return null.
 java.lang.String getSrc()
          Returns the source URI of the image.
 java.lang.String getVspace()
          Returns number of pixels of extra space to the top and bottom side of the image.
 boolean isChildable()
          Default: not childable.
protected  java.lang.Object newExtraCtrl()
          Used by AbstractComponent.getExtraCtrl() to create a client control.
 void setAlign(java.lang.String align)
          Sets the alignment: one of top, texttop, middle, absmiddle, bottom, absbottom, baseline, left, right and center.
 void setBorder(java.lang.String border)
          Sets the width of the border.
 void setContent(Image image)
          Sets the content directly.
 void setContent(java.awt.image.RenderedImage image)
          Sets the content directly with the rendered image.
 void setHover(java.lang.String src)
          Sets the image URI.
 void setHoverContent(Image image)
          Sets the content of the hover image directly.
 void setHoverContent(java.awt.image.RenderedImage image)
          Sets the content of the hover image directly with the rendered image.
 void setHspace(java.lang.String hspace)
          Sets number of pixels of extra space to the left and right side of the image.
 void setSrc(java.lang.String src)
          Sets the source URI of the image.
 void setVspace(java.lang.String vspace)
          Sets number of pixels of extra space to the top and bottom side of the image.
 void smartUpdate(java.lang.String attr, java.lang.String value)
          Smart-updates a property with the specified value.
 
Methods inherited from class org.zkoss.zul.impl.XulElement
getAction, getActionAttrs, getAllOnClickAttrs, getContext, getCtrlKeys, getPopup, getTooltip, setAction, setContext, setContext, setCtrlKeys, setPopup, setPopup, setTooltip, setTooltip
 
Methods inherited from class org.zkoss.zk.ui.HtmlBasedComponent
focus, getAllOnClickAttrs, getDraggable, getDroppable, getHeight, getLeft, getMoldSclass, getRealSclass, getRealStyle, getRealStyleFlags, getSclass, getStyle, getTooltiptext, getTop, getWidth, getZclass, getZindex, getZIndex, redraw, setClass, setDraggable, setDroppable, setFocus, setHeight, setLeft, setMoldSclass, setSclass, setStyle, setTooltiptext, setTop, setWidth, setZclass, setZindex, setZIndex
 
Methods inherited from class org.zkoss.zk.ui.AbstractComponent
addAnnotation, addAnnotation, addEventHandler, addEventListener, addForward, addForward, addForward, addForward, addMoved, addSharedAnnotationMap, addSharedEventHandlerMap, appendAsapAttr, appendAsapAttr, appendChild, applyProperties, clone, containsVariable, detach, equals, getAnnotatedProperties, getAnnotatedPropertiesBy, getAnnotation, getAnnotation, getAnnotations, getAnnotations, getAttribute, getAttribute, getAttributes, getAttributes, getChildren, getCommand, getDefinition, getDesktop, getEventHandler, getEventHandlerNames, getExtraCtrl, getFellow, getFellowIfAny, getFellows, getFirstChild, getId, getLastChild, getListenerIterator, getMold, getMoldURI, getNamespace, getNextSibling, getPage, getParent, getPreviousSibling, getRoot, getSpaceOwner, getUuid, getVariable, hasFellow, insertBefore, invalidate, isAsapRequired, isInvalidated, isListenerAvailable, isVisible, newChildren, onChildAdded, onChildRemoved, onDrawNewChild, onPageAttached, onPageDetached, onWrongValue, removeAttribute, removeAttribute, removeChild, removeEventListener, removeForward, removeForward, response, sessionDidActivate, sessionWillPassivate, setAttribute, setAttribute, setComponentDefinition, setId, setMold, setPage, setPageBefore, setParent, setVariable, setVisible, smartUpdate, smartUpdate, smartUpdateDeferred, smartUpdateValues, toString, unsetVariable
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.zkoss.zul.impl.api.XulElement
getAction, getContext, getCtrlKeys, getPopup, getTooltip, setAction, setContext, setContext, setCtrlKeys, setPopup, setPopup, setTooltip, setTooltip
 
Methods inherited from interface org.zkoss.zk.ui.api.HtmlBasedComponent
focus, getHeight, getLeft, getSclass, getStyle, getTooltiptext, getTop, getWidth, getZclass, getZindex, getZIndex, setDraggable, setDroppable, setFocus, setHeight, setLeft, setSclass, setStyle, setTooltiptext, setTop, setWidth, setZclass, setZindex, setZIndex
 
Methods inherited from interface org.zkoss.zk.ui.Component
addEventListener, addForward, addForward, addForward, addForward, appendChild, applyProperties, clone, containsVariable, detach, getAttribute, getAttribute, getAttributes, getAttributes, getChildren, getDefinition, getDesktop, getFellow, getFellowIfAny, getFellows, getFirstChild, getId, getLastChild, getListenerIterator, getMold, getNamespace, getNextSibling, getPage, getParent, getPreviousSibling, getRoot, getSpaceOwner, getUuid, getVariable, insertBefore, invalidate, isInvalidated, isListenerAvailable, isVisible, redraw, removeAttribute, removeAttribute, removeChild, removeEventListener, removeForward, removeForward, setAttribute, setAttribute, setId, setMold, setPage, setPageBefore, setParent, setVariable, setVisible, unsetVariable
 

Constructor Detail

Image

public Image()

Image

public Image(java.lang.String src)
Method Detail

getAlign

public java.lang.String getAlign()
Returns the alignment.

Default: null (use browser default).

Specified by:
getAlign in interface Image

setAlign

public void setAlign(java.lang.String align)
Sets the alignment: one of top, texttop, middle, absmiddle, bottom, absbottom, baseline, left, right and center.

Specified by:
setAlign in interface Image

getBorder

public java.lang.String getBorder()
Returns the width of the border.

Default: null (use browser default).

Specified by:
getBorder in interface Image

setBorder

public void setBorder(java.lang.String border)
Sets the width of the border.

Specified by:
setBorder in interface Image

getHspace

public java.lang.String getHspace()
Returns number of pixels of extra space to the left and right side of the image.

Default: null (use browser default).

Specified by:
getHspace in interface Image

setHspace

public void setHspace(java.lang.String hspace)
Sets number of pixels of extra space to the left and right side of the image.

Specified by:
setHspace in interface Image

getVspace

public java.lang.String getVspace()
Returns number of pixels of extra space to the top and bottom side of the image.

Default: null (use browser default).

Specified by:
getVspace in interface Image

setVspace

public void setVspace(java.lang.String vspace)
Sets number of pixels of extra space to the top and bottom side of the image.

Specified by:
setVspace in interface Image

getSrc

public java.lang.String getSrc()
Returns the source URI of the image.

Default: null.

Specified by:
getSrc in interface Image

setSrc

public void setSrc(java.lang.String src)
Sets the source URI of the image.

Calling this method implies setContent(null). In other words, the last invocation of setSrc(java.lang.String) overrides the previous setContent(org.zkoss.image.Image), if any.

Specified by:
setSrc in interface Image
Parameters:
src - the URI of the image source
See Also:
setContent(org.zkoss.image.Image), setContent(RenderedImage)

setContent

public void setContent(Image image)
Sets the content directly.

Default: null.

Calling this method implies setSrc(null). In other words, the last invocation of setContent(org.zkoss.image.Image) overrides the previous setSrc(java.lang.String), if any.

Specified by:
setContent in interface Image
Parameters:
image - the image to display.
See Also:
setSrc(java.lang.String)

setContent

public void setContent(java.awt.image.RenderedImage image)
Sets the content directly with the rendered image. It actually encodes the rendered image to an PNG image (Image) with Images.encode(java.lang.String, java.awt.image.RenderedImage, float, boolean), and then invoke setContent(org.zkoss.image.Image).

If you want more control such as different format, quality, and naming, you can use Images directly.

Specified by:
setContent in interface Image
Since:
3.0.7

getContent

public Image getContent()
Returns the content set by setContent(org.zkoss.image.Image).

Note: it won't fetch what is set thru by setSrc(java.lang.String). It simply returns what is passed to setContent(org.zkoss.image.Image).

Specified by:
getContent in interface Image

getHover

public java.lang.String getHover()
Returns the URI of the hover image. The hover image is used when the mouse is moving over this component.

Default: null.

Specified by:
getHover in interface Image
Since:
3.5.0

setHover

public void setHover(java.lang.String src)
Sets the image URI. The hover image is used when the mouse is moving over this component.

Calling this method implies setHoverContent(null). In other words, the last invocation of setHover(java.lang.String) overrides the previous setHoverContent(org.zkoss.image.Image), if any.

Specified by:
setHover in interface Image
Since:
3.5.0
See Also:
setHoverContent(org.zkoss.image.Image), setHoverContent(RenderedImage)

setHoverContent

public void setHoverContent(Image image)
Sets the content of the hover image directly. The hover image is used when the mouse is moving over this component.

Default: null.

Calling this method implies setHover(null). In other words, the last invocation of setHoverContent(org.zkoss.image.Image) overrides the previous setHover(java.lang.String), if any.

Specified by:
setHoverContent in interface Image
Parameters:
image - the image to display.
Since:
3.5.0
See Also:
setHover(java.lang.String)

setHoverContent

public void setHoverContent(java.awt.image.RenderedImage image)
Sets the content of the hover image directly with the rendered image. The hover image is used when the mouse is moving over this component.

It actually encodes the rendered image to an PNG image (Image) with Images.encode(java.lang.String, java.awt.image.RenderedImage, float, boolean), and then invoke setHoverContent(org.zkoss.image.Image).

If you want more control such as different format, quality, and naming, you can use Images directly.

Specified by:
setHoverContent in interface Image
Since:
3.5.0

getOuterAttrs

public java.lang.String getOuterAttrs()
Description copied from class: HtmlBasedComponent
Returns the exterior attributes for generating the enclosing HTML tag; never return null.

Used only by component developers.

Default: Generates the tooltip text, style, sclass, draggable and droppable attribute if necessary. In other words, the corresponding attribute is generated if HtmlBasedComponent.getTooltiptext(), HtmlBasedComponent.getRealStyle(), HtmlBasedComponent.getSclass(), HtmlBasedComponent.getDraggable(), HtmlBasedComponent.getDroppable() are defined.

You have to call both HtmlBasedComponent.getOuterAttrs() and HtmlBasedComponent.getInnerAttrs() to generate complete attributes.

For simple components that all attributes are put on the outest HTML element, all you need is as follows.

<xx id="${self.uuid}"${self.outerAttrs}${self.innerAttrs}>

If you want to put attributes in a nested HTML element, you shall use the following pattern. Notice: if HtmlBasedComponent.getInnerAttrs() in a different tag, the tag must be named with "${self.uuid}!real".

<xx id="${self.uuid}"${self.outerAttrs}>
 <yy id="${self.uuid}!real"${self.innerAttrs}>...

Note: This class handles non-deferrable event listeners automatically. However, you have to invoke AbstractComponent.appendAsapAttr(java.lang.StringBuffer, java.lang.String) for each event the component handles in HtmlBasedComponent.getOuterAttrs() as follows.


        appendAsapAttr(sb, Events.ON_OPEN);
  appendAsapAttr(sb, Events.ON_CHANGE);

Theorectically, you could put any attributes in either HtmlBasedComponent.getInnerAttrs() or HtmlBasedComponent.getOuterAttrs(). However, zkau.js assumes all attributes are put at the outer one. If you want something different, you have to provide your own setAttr (refer to how checkbox is implemented).

Overrides:
getOuterAttrs in class XulElement

getInnerAttrs

public java.lang.String getInnerAttrs()
Description copied from class: XulElement
Generates the Client-Side-Action attributes to the interior tag. Reason: onfocus is the main use.

Overrides:
getInnerAttrs in class XulElement

isChildable

public boolean isChildable()
Default: not childable.

Specified by:
isChildable in interface Component
Overrides:
isChildable in class AbstractComponent

smartUpdate

public void smartUpdate(java.lang.String attr,
                        java.lang.String value)
Description copied from interface: ComponentCtrl
Smart-updates a property with the specified value. Called by component developers to do precise-update.

The second invocation with the same property will replace the previous call. In other words, the same property will be set only once in each execution.

This method has no effect if Component.invalidate() is ever invoked (in the same execution), since Component.invalidate() assumes the whole content shall be redrawn and all smart updates to this components can be ignored,

Once this method is called, all invocations to ComponentCtrl.smartUpdate(java.lang.String, java.lang.String) will then be ignored, and Component.redraw(java.io.Writer) will be invoked later.

It can be called only in the request-processing and event-processing phases; excluding the redrawing phase.

There are two ways to draw a component, one is to invoke Component.invalidate(), and the other is ComponentCtrl.smartUpdate(java.lang.String, java.lang.String). While Component.invalidate() causes the whole content to redraw, ComponentCtrl.smartUpdate(java.lang.String, java.lang.String) let component developer control which part to redraw.

Specified by:
smartUpdate in interface ComponentCtrl
Overrides:
smartUpdate in class AbstractComponent
value - the new value. If null, it means removing the property.
See Also:
ComponentCtrl.smartUpdateDeferred(java.lang.String, org.zkoss.zk.ui.util.DeferredValue), ComponentCtrl.smartUpdateValues(java.lang.String, java.lang.Object[])

newExtraCtrl

protected java.lang.Object newExtraCtrl()
Description copied from class: HtmlBasedComponent
Used by AbstractComponent.getExtraCtrl() to create a client control. It is used only by component developers.

Defaut: creates an instance of HtmlBasedComponent.ExtraCtrl.

Overrides:
newExtraCtrl in class HtmlBasedComponent


Copyright © 2005-2009 Potix Corporation. All Rights Reserved.