org.xhtmlrenderer.swing
Class SwingReplacedElementFactory

java.lang.Object
  extended by org.xhtmlrenderer.swing.SwingReplacedElementFactory
All Implemented Interfaces:
ReplacedElementFactory

public class SwingReplacedElementFactory
extends Object
implements ReplacedElementFactory

A ReplacedElementFactory where Elements are replaced by Swing components.


Field Summary
protected  LinkedHashMap forms
          Cache of XhtmlForms keyed by Element.
protected  Map imageComponents
          Cache of image components (ReplacedElements) for quick lookup, keyed by Element.
protected  RepaintListener repaintListener
           
 
Constructor Summary
SwingReplacedElementFactory()
           
SwingReplacedElementFactory(RepaintListener repaintListener)
           
SwingReplacedElementFactory(RepaintListener listener, ImageResourceLoader irl)
           
 
Method Summary
protected  void addForm(Element e, XhtmlForm f)
          Adds a form to a local cache for quick lookup.
 ReplacedElement createReplacedElement(LayoutContext context, BlockBox box, UserAgentCallback uac, int cssWidth, int cssHeight)
          NOTE: Only block equivalent elements can be replaced.
protected  XhtmlForm getForm(Element e)
          Returns the XhtmlForm associated with an Element in cache, or null if not found.
protected  Element getParentForm(Element e, LayoutContext context)
           
protected  ReplacedElement lookupImageReplacedElement(Element e, String uri)
          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.
 void remove(Element e)
          Removes any reference to Element e.
protected  ReplacedElement replaceImage(UserAgentCallback uac, LayoutContext context, Element elem, int cssWidth, int cssHeight)
          Handles replacement of image elements in the document.
 void reset()
          Clears out any references to elements or items created by this factory so far.
 void setFormSubmissionListener(FormSubmissionListener fsl)
          Identifies the FSL which will be used for callbacks when a form submit action is executed; you can use a DefaultFormSubmissionListener if you don't want any action to be taken.
protected  void storeImageReplacedElement(Element e, ReplacedElement cc, String uri, int cssWidth, int cssHeight)
          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
 

Field Detail

imageComponents

protected Map imageComponents
Cache of image components (ReplacedElements) for quick lookup, keyed by Element.


forms

protected LinkedHashMap forms
Cache of XhtmlForms keyed by Element.


repaintListener

protected final RepaintListener repaintListener
Constructor Detail

SwingReplacedElementFactory

public SwingReplacedElementFactory()

SwingReplacedElementFactory

public SwingReplacedElementFactory(RepaintListener repaintListener)

SwingReplacedElementFactory

public SwingReplacedElementFactory(RepaintListener listener,
                                   ImageResourceLoader irl)
Method Detail

createReplacedElement

public ReplacedElement createReplacedElement(LayoutContext context,
                                             BlockBox box,
                                             UserAgentCallback uac,
                                             int cssWidth,
                                             int cssHeight)
NOTE: Only block equivalent elements can be replaced.

Specified by:
createReplacedElement in interface ReplacedElementFactory
cssWidth - The CSS width of the element in dots (or -1 if width is auto)
cssHeight - The CSS height of the element in dots (or -1 if the height should be treated as auto)
Returns:
The ReplacedElement or null if no ReplacedElement applies

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.
Returns:

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.

storeImageReplacedElement

protected void storeImageReplacedElement(Element e,
                                         ReplacedElement cc,
                                         String uri,
                                         int cssWidth,
                                         int cssHeight)
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
uri -
cssWidth -
cssHeight -

lookupImageReplacedElement

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

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

addForm

protected void addForm(Element e,
                       XhtmlForm f)
Adds a form to a local cache for quick lookup.

Parameters:
e - The element under which the form is keyed (e.g. "
" in HTML)
f - The form element being stored.

getForm

protected XhtmlForm getForm(Element e)
Returns the XhtmlForm associated with an Element in cache, or null if not found.

Parameters:
e - The Element to which the form is keyed
Returns:
The form, or null if not found.

getParentForm

protected Element getParentForm(Element e,
                                LayoutContext context)
Parameters:
e -

reset

public void reset()
Clears out any references to elements or items created by this factory so far.

Specified by:
reset in interface ReplacedElementFactory

remove

public void remove(Element e)
Description copied from interface: ReplacedElementFactory
Removes any reference to Element e.

Specified by:
remove in interface ReplacedElementFactory

setFormSubmissionListener

public void setFormSubmissionListener(FormSubmissionListener fsl)
Description copied from interface: ReplacedElementFactory
Identifies the FSL which will be used for callbacks when a form submit action is executed; you can use a DefaultFormSubmissionListener if you don't want any action to be taken.

Specified by:
setFormSubmissionListener in interface ReplacedElementFactory
Parameters:
fsl - the listener instance to receive callbacks on form submission.


Copyright © 2013. All Rights Reserved.