org.xhtmlrenderer.test
Class SwingImageReplacer

java.lang.Object
  extended by org.xhtmlrenderer.test.ElementReplacer
      extended by org.xhtmlrenderer.test.SwingImageReplacer

public class SwingImageReplacer
extends ElementReplacer

Author:
patrick

Constructor Summary
SwingImageReplacer()
           
 
Method Summary
 boolean accept(LayoutContext context, Element element)
           
 void clear(Element element)
           
 String getElementNameMatch()
           
 boolean isElementNameMatch()
           
protected  ReplacedElement lookupImageReplacedElement(Element e)
          Retrieves a ReplacedElement for an image from cache, or null if not found.
protected  ReplacedElement newIrreplaceableImageElement(int cssWidth, int cssHeight)
          Returns a ReplacedElement for some element in the stream which should be replaceable, but is not.
 ReplacedElement replace(LayoutContext context, BlockBox box, UserAgentCallback uac, int cssWidth, int cssHeight)
           
protected  ReplacedElement replaceImage(UserAgentCallback uac, LayoutContext context, Element elem, int cssWidth, int cssHeight)
          Handles replacement of image elements in the document.
 void reset()
           
protected  void storeImageReplacedElement(Element e, ReplacedElement cc)
          Adds a ReplacedElement containing an image to a cache of images for quick lookup.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

SwingImageReplacer

public SwingImageReplacer()
Method Detail

isElementNameMatch

public boolean isElementNameMatch()
Specified by:
isElementNameMatch in class ElementReplacer

getElementNameMatch

public String getElementNameMatch()
Specified by:
getElementNameMatch in class ElementReplacer

accept

public boolean accept(LayoutContext context,
                      Element element)
Specified by:
accept in class ElementReplacer

replace

public ReplacedElement replace(LayoutContext context,
                               BlockBox box,
                               UserAgentCallback uac,
                               int cssWidth,
                               int cssHeight)
Specified by:
replace in class ElementReplacer

clear

public void clear(Element element)
Specified by:
clear in class ElementReplacer

reset

public void reset()
Specified by:
reset in class ElementReplacer

replaceImage

protected ReplacedElement replaceImage(UserAgentCallback uac,
                                       LayoutContext context,
                                       Element elem,
                                       int cssWidth,
                                       int cssHeight)
Handles replacement of image elements in the document. May return the same ReplacedElement for a given image on multiple calls. Image will be automatically scaled to cssWidth and cssHeight assuming these are non-zero positive values. The element is assume to have a src attribute (e.g. it's an element)

Parameters:
uac - Used to retrieve images on demand from some source.
context -
elem - The element with the image reference
cssWidth - Target width of the image
cssHeight - Target height of the image @return A ReplacedElement for the image; will not be null.

storeImageReplacedElement

protected void storeImageReplacedElement(Element e,
                                         ReplacedElement cc)
Adds a ReplacedElement containing an image to a cache of images for quick lookup.

Parameters:
e - The element under which the image is keyed.
cc - The replaced element containing the image, or another ReplacedElement to be used in its place (like a placeholder if the image can't be loaded).

lookupImageReplacedElement

protected ReplacedElement lookupImageReplacedElement(Element e)
Retrieves a ReplacedElement for an image from cache, or null if not found.

Parameters:
e - The element by which the image is keyed
Returns:
The ReplacedElement for the image, or null if there is none.

newIrreplaceableImageElement

protected ReplacedElement newIrreplaceableImageElement(int cssWidth,
                                                       int cssHeight)
Returns a ReplacedElement for some element in the stream which should be replaceable, but is not. This might be the case for an element like img, where the source isn't provided.

Parameters:
cssWidth - Target width for the element.
cssHeight - Target height for the element
Returns:
A ReplacedElement to substitute for one that can't be generated.


Copyright © 2013. All Rights Reserved.