Package org.xhtmlrenderer.swing
Class SwingReplacedElementFactory
java.lang.Object
org.xhtmlrenderer.swing.SwingReplacedElementFactory
- All Implemented Interfaces:
ReplacedElementFactory
- Direct Known Subclasses:
ImageMapReplacedElementFactory
A ReplacedElementFactory where Elements are replaced by Swing components.
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionprivate static final record
-
Field Summary
FieldsModifier and TypeFieldDescriptionCache of XhtmlForms keyed by Element.private FormSubmissionListener
private final Map
<SwingReplacedElementFactory.CacheKey, ReplacedElement> Cache of image components (ReplacedElements) for quick lookup, keyed by Element.private final ImageResourceLoader
protected final RepaintListener
-
Constructor Summary
ConstructorsConstructorDescriptionSwingReplacedElementFactory
(RepaintListener repaintListener) SwingReplacedElementFactory
(RepaintListener listener, ImageResourceLoader irl) -
Method Summary
Modifier and TypeMethodDescriptionprotected void
Adds a form to a local cache for quick lookup.createReplacedElement
(LayoutContext context, BlockBox box, UserAgentCallback uac, int cssWidth, int cssHeight) NOTE: Only block equivalent elements can be replaced.protected XhtmlForm
Returns the XhtmlForm associated with an Element in cache, or null if not found.protected Element
getParentForm
(Element e, LayoutContext context) protected ReplacedElement
Retrieves a ReplacedElement for an image from cache, or null if not found.private ReplacedElement
lookupImageReplacedElement
(Element elem, String ruri, int cssWidth, int cssHeight) protected ReplacedElement
newIrreplaceableImageElement
(int cssWidth, int cssHeight) Returns a ReplacedElement for some element in the stream which should be replaceable, but is not.void
Removes any reference toElement
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
Identifies the FSL which will be used for callbacks when a form submit action is executed; you can use aDefaultFormSubmissionListener
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.
-
Field Details
-
imageComponents
Cache of image components (ReplacedElements) for quick lookup, keyed by Element. -
forms
Cache of XhtmlForms keyed by Element. -
formSubmissionListener
-
repaintListener
-
imageResourceLoader
-
-
Constructor Details
-
SwingReplacedElementFactory
public SwingReplacedElementFactory() -
SwingReplacedElementFactory
-
SwingReplacedElementFactory
-
-
Method Details
-
createReplacedElement
public ReplacedElement createReplacedElement(LayoutContext context, BlockBox box, UserAgentCallback uac, int cssWidth, int cssHeight) Description copied from interface:ReplacedElementFactory
NOTE: Only block equivalent elements can be replaced.- Specified by:
createReplacedElement
in interfaceReplacedElementFactory
- Parameters:
cssWidth
- The CSS width of the element in dots (or-1
if width isauto
)cssHeight
- The CSS height of the element in dots (or-1
if the height should be treated asauto
)- Returns:
- The
ReplacedElement
ornull
if noReplacedElement
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 assumed to have a src attribute (e.g. it's an<img>
element).- Parameters:
uac
- Used to retrieve images on demand from some source.elem
- The element with the image referencecssWidth
- Target width of the imagecssHeight
- Target height of the image @return A ReplacedElement for the image; will not be null.
-
lookupImageReplacedElement
private ReplacedElement lookupImageReplacedElement(Element elem, String ruri, int cssWidth, int cssHeight) -
newIrreplaceableImageElement
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
-
lookupImageReplacedElement
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.
-
addForm
Adds a form to a local cache for quick lookup.- Parameters:
e
- The element under which the form is keyed (e.g.<form>
in HTML)f
- The form element being stored.
-
getForm
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
-
reset
public void reset()Clears out any references to elements or items created by this factory so far.- Specified by:
reset
in interfaceReplacedElementFactory
-
remove
Description copied from interface:ReplacedElementFactory
Removes any reference toElement
e
.- Specified by:
remove
in interfaceReplacedElementFactory
-
setFormSubmissionListener
Description copied from interface:ReplacedElementFactory
Identifies the FSL which will be used for callbacks when a form submit action is executed; you can use aDefaultFormSubmissionListener
if you don't want any action to be taken.- Specified by:
setFormSubmissionListener
in interfaceReplacedElementFactory
- Parameters:
fsl
- the listener instance to receive callbacks on form submission.
-