org.fit.cssbox.layout
Class ContentImage

java.lang.Object
  extended by org.fit.cssbox.layout.ReplacedContent
      extended by org.fit.cssbox.layout.ContentImage
All Implemented Interfaces:
ImageObserver
Direct Known Subclasses:
BackgroundImage, ReplacedImage

public abstract class ContentImage
extends ReplacedContent
implements ImageObserver

Generic image used in the page content (used by ReplacedImage and BackgroundImage).

Author:
burgetr

Field Summary
protected  boolean abort
           
protected  boolean caching
           
protected  Container container
           
protected  int DEFAULT_IMAGE_HEIGHT
          Used when there are no image data
protected  int DEFAULT_IMAGE_WIDTH
          Used when there are no image data
protected  int height
           
protected  Image image
           
protected  boolean loadImages
           
protected  int loadTimeout
          Image loading timeout [ms]
protected  ImageObserver observer
           
protected  Toolkit toolkit
           
protected  URL url
           
protected  int width
           
 
Fields inherited from class org.fit.cssbox.layout.ReplacedContent
def_height, def_width, owner
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
ContentImage(ElementBox owner)
           
 
Method Summary
 void abort()
          Aborts waiting for image data to determine width and/or height.
 void dispose()
          Releases the image resources.
 BufferedImage getBufferedImage()
          Gets the loaded image as BufferedImage object.
 Container getContainer()
          Gets the container.
 Image getImage()
          Gets the image.
 ImageObserver getImageObserver()
          Gets the image observer.
 float getIntrinsicRatio()
           
 int getIntrinsicWidth()
           
 int getIntrinsicHeight()
           
 URL getUrl()
          Gets the url.
 boolean imageUpdate(Image img, int flags, int x, int y, int newWidth, int newHeight)
           
 boolean isCaching()
          Checks if caching is used when loading images.
protected  Image loadImage(boolean cache)
           
protected  void repaint(int t)
          Fires repaint event within t milliseconds.
 void reset()
          Resets all data to default state, releases the image resources.
 void setCaching(boolean val)
          Sets the caching.
 void setContainer(Container container)
          Sets the component's container used by internal ImageObserver when there is need to repaint (e.g. animated gif).
 void setImageObserver(ImageObserver observer)
          Sets the image observer.
 
Methods inherited from class org.fit.cssbox.layout.ReplacedContent
absolutePositions, doLayout, draw, getOwner, loadSizeDefs, setOwner
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_IMAGE_WIDTH

protected final int DEFAULT_IMAGE_WIDTH
Used when there are no image data

See Also:
Constant Field Values

DEFAULT_IMAGE_HEIGHT

protected final int DEFAULT_IMAGE_HEIGHT
Used when there are no image data

See Also:
Constant Field Values

loadTimeout

protected int loadTimeout
Image loading timeout [ms]


loadImages

protected boolean loadImages

caching

protected boolean caching

url

protected URL url

image

protected Image image

width

protected int width

height

protected int height

observer

protected ImageObserver observer

container

protected Container container

toolkit

protected Toolkit toolkit

abort

protected boolean abort
Constructor Detail

ContentImage

public ContentImage(ElementBox owner)
Method Detail

setContainer

public void setContainer(Container container)
Sets the component's container used by internal ImageObserver when there is need to repaint (e.g. animated gif). If not set, rendering may not work correctly. Null does not cause NullPointerException

Parameters:
container - the new container
See Also:
ImageObserver, Container

getContainer

public Container getContainer()
Gets the container. May return null.

Returns:
the container

repaint

protected void repaint(int t)
Fires repaint event within t milliseconds.

Parameters:
t - the time to repaint within.
See Also:
Component.repaint(long, int, int, int, int)

loadImage

protected Image loadImage(boolean cache)

isCaching

public boolean isCaching()
Checks if caching is used when loading images.

Returns:
true, if caching is used
See Also:
setCaching(boolean)

setCaching

public void setCaching(boolean val)
Sets the caching. If set to true, image is checked, if present in cache. If not, it is loaded and placed to cache. If set to False image is just loaded, any cache and caching is avoided.

Parameters:
val - indicates, whether use cache. Default is true.
See Also:
Toolkit.getImage(URL), Toolkit.createImage(URL)

getUrl

public URL getUrl()
Gets the url.

Returns:
the url of the image.

getImage

public Image getImage()
Gets the image.

Returns:
the image.

getBufferedImage

public BufferedImage getBufferedImage()
Gets the loaded image as BufferedImage object. May return null if no data available.

Returns:
the buffered image.

setImageObserver

public void setImageObserver(ImageObserver observer)
Sets the image observer.

Parameters:
observer - the new image observer.
See Also:
ImageObserver

getImageObserver

public ImageObserver getImageObserver()
Gets the image observer.

Returns:
the image observer
See Also:
ImageObserver

getIntrinsicHeight

public int getIntrinsicHeight()
Specified by:
getIntrinsicHeight in class ReplacedContent
Returns:
the intrinsic height of the contents

getIntrinsicWidth

public int getIntrinsicWidth()
Specified by:
getIntrinsicWidth in class ReplacedContent
Returns:
the intrinsic width of the contents

getIntrinsicRatio

public float getIntrinsicRatio()
Specified by:
getIntrinsicRatio in class ReplacedContent
Returns:
the intrinsic width/height ratio. If the object has no ratio, 0 is returned

dispose

public void dispose()
Releases the image resources.


reset

public void reset()
Resets all data to default state, releases the image resources.


abort

public void abort()
Aborts waiting for image data to determine width and/or height. This method is called from ImageObserver. If custom ImageObserver is provided and ABORT or ERROR flags are set during loading, call this method to abort waiting. Otherwise infinite loop will be created, resulting in dead-lock.

See Also:
ImageObserver, ImageObserver.ABORT, ImageObserver.ERROR

imageUpdate

public boolean imageUpdate(Image img,
                           int flags,
                           int x,
                           int y,
                           int newWidth,
                           int newHeight)
Specified by:
imageUpdate in interface ImageObserver


Copyright © 2014. All rights reserved.