public abstract class ViewFactoryBase extends TreeViewFactory
Modifier and Type | Class and Description |
---|---|
protected static class |
ViewFactoryBase.When |
ViewFactory.Effect
docType, isDummyDocType, settings
doc, docView
properties
Modifier | Constructor and Description |
---|---|
protected |
ViewFactoryBase(DocumentView documentView)
Constructs a styled view factory for use by specified DocumentView.
|
Modifier and Type | Method and Description |
---|---|
protected static void |
addAttributeDependencies(String xpathString,
StyleSheet styleSheet,
AttributeDependency dependent,
HashMap<AttributeDependency,AttributeDependency> dependOnAttribute) |
protected static void |
addAttributeDependencies(StyleValue val,
StyleSheet styleSheet,
AttributeDependency dependent,
HashMap<AttributeDependency,AttributeDependency> dependOnAttribute) |
protected void |
addCounterActions(Element element,
boolean isReset,
StyleValue value,
Element parent) |
void |
addDependency(Namespace elementNS,
String elementLP,
Namespace attributeNS,
String attributeLP)
Explicitly register a dependency between an element and one of its
attributes.
|
void |
addDependencyOnChildren(Namespace elementNS,
String elementLP)
Explicitly register a dependency between an element and its children.
|
void |
addIntrinsicStyleSpecs(StyleSpecs intrinsicStyleSpecs)
Equivalent to
addIntrinsicStyleSpecs(intrinsicStyleSpecs, false) . |
void |
addIntrinsicStyleSpecs(StyleSpecs intrinsicStyleSpecs,
boolean after)
Adds specified intrinsic style specs to the list used by this factory.
|
protected void |
addSiblingDependency(Name name,
ViewFactoryBase.When dep) |
protected Style |
adjustMarginForListMarker(ListStyle listStyle,
int listBulletWidth,
Style style) |
protected void |
analyzeDependencies() |
protected static void |
appendDecodedURI(Element element,
StyleValue func,
StringBuilder buffer) |
protected void |
appendProperty(Element element,
StyleValue func,
StringBuilder buffer) |
void |
applyStyleDefaults()
Rebuilds the whole node view tree.
|
ViewFactory.Effect |
attributeChanged(AttributeEvent event,
int viewIndex)
Invoked by the DocumentView when an element attribute has changed.
|
void |
beginRebuildView(Node node)
Invoked by the DocumentView at the beginning of rebuildView.
|
protected StyleValue |
callFunction(StyleValue val,
Node node) |
protected void |
clearSharedStyles() |
protected String |
concatenate(StyleValue[] args,
Node node) |
protected String |
contentToToolTip(StyleValue val,
Element element) |
TextNodeView |
createCommentView(Comment comment,
ElementView parentView)
Creates an TextNodeView for specified comment node.
|
protected CustomViewManager |
createCustomViewManager() |
ElementView |
createElementView(Element element,
ElementView parentView)
Creates an ElementView for specified element.
|
protected ExprContextImpl |
createExprContext() |
TextNodeView |
createProcessingInstructionView(ProcessingInstruction pi,
ElementView parentView)
Creates an TextNodeView for specified processing instruction node.
|
protected abstract ElementView |
createStyledElementView(Style style,
ViewParameters param,
StyleSpec spec,
Style styleBefore,
ViewParameters paramBefore,
StyleSpec specBefore,
Style styleAfter,
ViewParameters paramAfter,
StyleSpec specAfter,
Element element,
ElementView parentView) |
protected abstract TextNodeView |
createStyledTextNodeView(Style style,
ViewParameters param,
StyleSpec spec,
TextNode textNode,
ElementView parentView) |
protected abstract TextNodeView |
createStyledTextView(Style style,
Text text,
ElementView parentView) |
protected TextNodeView |
createTextNodeView(TextNode textNode,
ElementView parentView) |
TextNodeView |
createTextView(Text text,
ElementView parentView)
Creates an TextNodeView for specified text node.
|
protected TextNodeView |
createTreeCommentView(Comment comment,
ElementView parentView) |
protected ElementView |
createTreeElementView(Element element,
ElementView parentView) |
protected TextNodeView |
createTreePIView(ProcessingInstruction pi,
ElementView parentView) |
protected TextNodeView |
createTreeTextView(Text text,
ElementView parentView) |
protected boolean |
dependOnChildren(Element element) |
protected ViewFactoryBase.When |
dependOnSiblings(Node node) |
protected int |
doGetBorderRadius(StyleValue val,
Element element,
FontMetrics metrics,
int parentRadius) |
protected boolean |
elementHasEmbeddedEditor(Element element) |
void |
endRebuildView(Node node)
Invoked by the DocumentView at the end of rebuildView.
|
protected String |
evalXPath(StringExpr expr,
XNode context) |
StyleSpecs[] |
getAllIntrinsicStyleSpecs(boolean after)
Returns the list of intrinsic style specs used by this factory.
|
protected static AttributeDependency |
getAttributeDependent(Selector.Test[] tests) |
protected BackgroundPaint |
getBackgroundPaint(StyleSpec spec,
Element element,
FontMetrics metrics,
Style style,
Style parentStyle) |
protected int[] |
getBorderRadius(StyleValue val,
Element element,
FontMetrics metrics,
int parentRadiusH,
int parentRadiusV) |
protected Style.BorderStyle |
getBorderStyle(StyleValue val,
Element element,
Style.BorderStyle parentBorderStyle) |
protected int |
getBorderWidth(StyleValue val,
Element element,
Style parentStyle,
FontMetrics metrics) |
CustomViewManager |
getCustomViewManager()
Returns the cutom view manager used by this view factory.
|
Style |
getDefaultStyle()
Returns ``default style'' used by this factory.
|
protected static Name |
getMatchedName(Selector.Test[] tests) |
StyleSheet |
getStyleSheet()
Returns style sheet currently used by this factory.
|
boolean |
hasDependency(Name elementName,
Name attributeName)
Returns
true if the styled view of the element having
specified name depends on the value of the attribute having specified
name. |
boolean |
hasDependencyOnChildren(Namespace elementNS,
String elementLP)
Returns
true if specified element has a dependency
on its children; otherwise returns false . |
protected void |
initExtensions() |
protected void |
initSharedStyles() |
protected static StyleValue |
injectListStyleType(StyleValue listItemCounter,
StyleValue listStyleType) |
protected StyleValue |
invokeExtension(StyleValue[] args,
Node node) |
protected static String |
listToFontFamily(StyleValue value) |
protected static int |
maxBorderWidth(int w1,
int w2,
int w3,
int w4) |
protected void |
registerCounterActions(Element element,
StyleSpec spec,
StyleSpec specBefore,
StyleSpec specAfter) |
void |
removeDependency(Namespace elementNS,
String elementLP,
Namespace attributeNS,
String attributeLP)
Unregister a dependency between an element and one of its
attributes previously registered using
addDependency(com.xmlmind.xml.name.Namespace, java.lang.String, com.xmlmind.xml.name.Namespace, java.lang.String) . |
void |
removeDependencyOnChildren(Namespace elementNS,
String elementLP)
Unregister a dependency between an element and its children
previously registered using
addDependencyOnChildren(com.xmlmind.xml.name.Namespace, java.lang.String) . |
protected void |
reportError(String message,
Throwable e) |
Style |
resetBox(Style style)
Return a shared copy of specified style after resetting
its CSS box properties (if any).
|
protected void |
resetStyleSheetState() |
void |
setDefaultStyle(Style style)
Specifies style properties inherited by the style of the root element
of the document.
|
void |
setDocument(Document document)
Invoked by the DocumentView to notify this factory that specified
document is displayed.
|
void |
setStyleSheet(StyleSheet sheet)
Changes current style sheet to specified one and rebuilds the whole
node view tree.
|
Style |
shareStyle(Style style)
Returns a shared copy of specified style.
|
void |
specToStyle(StyleSpec spec,
Style parentStyle,
StyleValue.Keyword parentDisplay,
Element element,
Style style,
ViewParameters param) |
Style |
specToStyle(StyleSpec spec,
Style parentStyle,
StyleValue.Keyword parentDisplay,
Element element,
ViewParameters param) |
protected void |
toString(StyleValue val,
Node node,
StringBuilder buffer) |
boolean |
treeChanged(TreeEvent event,
int viewIndex)
Invoked by the DocumentView when the child nodes of an element have
been modified.
|
protected void |
unregisterCounterActions(Element element) |
applySettings, createCharView, createTextNodeOutline, createWordView, directionalityAttributeChanged, getSettings, hasPreserveSpace, setSettings
getDocument, getDocumentView
getProperties, getProperty, getPropertyCount, hasProperty, putProperties, putProperty, removeAllProperties, removeProperty
public static final int MIN_FONT_SIZE
public static final int MAX_FONT_SIZE
protected Style defaultStyle
protected CustomViewManager customViewManager
protected StyleSheet styleSheet
protected boolean useRebuildExprContext
protected ExprContextImpl rebuildExprContext
protected HashMap<AttributeDependency,AttributeDependency> dependOnAttribute
protected IdentityHashMap<Name,Name> dependOnChildren
protected IdentityHashMap<Name,ViewFactoryBase.When> dependOnSiblings
protected boolean hasStructureDependencies
protected StyleValueParser styleValueParser
protected Class<?>[] extensionClasses
protected Object[] extensions
protected StyleSpecs[] stylersBefore
protected StyleSpecs[] stylersAfter
protected static final Pattern XPATH_ATTRIBUTE_PATTERN
protected AttributeDependency attrDependencyProbe
protected ViewFactoryBase(DocumentView documentView)
protected CustomViewManager createCustomViewManager()
protected void initSharedStyles()
protected void clearSharedStyles()
public void setDefaultStyle(Style style)
public Style getDefaultStyle()
public void applyStyleDefaults()
public StyleSheet getStyleSheet()
null
if this factory has been used to create a tree view
of the document.public void setStyleSheet(StyleSheet sheet)
sheet
- new style sheet; may be null
in which case
this factory will create a tree viewprotected void resetStyleSheetState()
protected void initExtensions()
protected void analyzeDependencies()
protected static final AttributeDependency getAttributeDependent(Selector.Test[] tests)
protected static final Name getMatchedName(Selector.Test[] tests)
protected void addSiblingDependency(Name name, ViewFactoryBase.When dep)
protected static final void addAttributeDependencies(StyleValue val, StyleSheet styleSheet, AttributeDependency dependent, HashMap<AttributeDependency,AttributeDependency> dependOnAttribute)
protected static final void addAttributeDependencies(String xpathString, StyleSheet styleSheet, AttributeDependency dependent, HashMap<AttributeDependency,AttributeDependency> dependOnAttribute)
public void addDependency(Namespace elementNS, String elementLP, Namespace attributeNS, String attributeLP)
XHTML example: by registering a dependency between element p and attribute align, each time attribute align is changed, the view of its element p is automatically rebuild.
Note that there is no need to register dependencies
automatically found by examining the stylesheet at stylesheet load time
(that is, when setStyleSheet(com.xmlmind.xmledit.stylesheet.StyleSheet)
is used). XHTML examples:
p[align=center] { text-align: center; } a:after { content: attr(title); }
When above style sheet is loaded by this StyledViewFactory, a dependency is automatically registered between p and align and another dependency is registered between a and title.
elementNS
- element namespace. null
means any.elementLP
- element local name. null
means any.attributeNS
- attribute namespace. null
means any.attributeLP
- attribute local name. null
means any.public void removeDependency(Namespace elementNS, String elementLP, Namespace attributeNS, String attributeLP)
addDependency(com.xmlmind.xml.name.Namespace, java.lang.String, com.xmlmind.xml.name.Namespace, java.lang.String)
.elementNS
- element namespace. null
means any.elementLP
- element local name. null
means any.attributeNS
- attribute namespace. null
means any.attributeLP
- attribute local name. null
means any.public boolean hasDependency(Name elementName, Name attributeName)
true
if the styled view of the element having
specified name depends on the value of the attribute having specified
name. Returns false
if this is not the case.public void addDependencyOnChildren(Namespace elementNS, String elementLP)
elementNS
- element namespace. null
means any.elementLP
- element local name. null
means any.public void removeDependencyOnChildren(Namespace elementNS, String elementLP)
addDependencyOnChildren(com.xmlmind.xml.name.Namespace, java.lang.String)
.elementNS
- element namespace. null
means any.elementLP
- element local name. null
means any.public boolean hasDependencyOnChildren(Namespace elementNS, String elementLP)
true
if specified element has a dependency
on its children; otherwise returns false
.elementNS
- element namespace. null
means any.elementLP
- element local name. null
means any.public CustomViewManager getCustomViewManager()
public void addIntrinsicStyleSpecs(StyleSpecs intrinsicStyleSpecs)
addIntrinsicStyleSpecs(intrinsicStyleSpecs, false)
.public void addIntrinsicStyleSpecs(StyleSpecs intrinsicStyleSpecs, boolean after)
Note that this list is automatically emptied each time the style sheet used by this factory is changed.
intrinsicStyleSpecs
- the intrinsic style specs to be
registered with this factoryafter
- if true
the intrinsic style specs
are to be applied after the stylesheet; if false
the intrinsic style specs are to be applied before the stylesheetgetAllIntrinsicStyleSpecs(boolean)
public StyleSpecs[] getAllIntrinsicStyleSpecs(boolean after)
after
- if true
returns the intrinsic style specs
applied after the stylesheet; if false
returns the intrinsic style specs applied before the stylesheetnull
if this list is empty.addIntrinsicStyleSpecs(com.xmlmind.xmledit.stylesheet.StyleSpecs)
public Style shareStyle(Style style)
A shared style must not be modified.
public Style resetBox(Style style)
public void setDocument(Document document)
ViewFactory
setDocument
in class TreeViewFactory
document
- document displayed by DocumentView; null
if DocumentView is empty.public void beginRebuildView(Node node)
ViewFactory
Default implementation does nothing at all.
beginRebuildView
in class ViewFactory
DocumentView.rebuildView(com.xmlmind.xml.doc.Node)
,
ViewFactory.endRebuildView(com.xmlmind.xml.doc.Node)
public void endRebuildView(Node node)
ViewFactory
Default implementation does nothing at all.
endRebuildView
in class ViewFactory
DocumentView.rebuildView(com.xmlmind.xml.doc.Node)
,
ViewFactory.beginRebuildView(com.xmlmind.xml.doc.Node)
public ViewFactory.Effect attributeChanged(AttributeEvent event, int viewIndex)
ViewFactory
This default implementation returns ViewFactory.Effect.REBUILD
.
attributeChanged
in class TreeViewFactory
event
- specifies the attribute changeviewIndex
- can be used to access the view of the element for
which an attribute has changed (with
event.getElementSource().getDocumentListenerData(viewIndex)
)ViewFactory.Effect.SKIP
or ViewFactory.Effect.REFRESH
or
ViewFactory.Effect.REBUILD
Node.getDocumentListenerData(int)
public boolean treeChanged(TreeEvent event, int viewIndex)
ViewFactory
This default implementation returns false
.
This method is needed to properly support the :first-child, :last-child, :empty, etc, pseudo-classes in styled view factories.
treeChanged
in class ViewFactory
event
- specifies which child nodes have been modifiedviewIndex
- can be used to access the view of the element in which
child nodes have changed (with
event.getElementSource().getDocumentListenerData(viewIndex)
)true
if the view of the element is to be rebuilt
from scratch; false
if suffice to update the view of the
element (e.g. add a view for a newly added child node)Node.getDocumentListenerData(int)
protected boolean elementHasEmbeddedEditor(Element element)
protected final boolean dependOnChildren(Element element)
protected final ViewFactoryBase.When dependOnSiblings(Node node)
public TextNodeView createTextView(Text text, ElementView parentView)
ViewFactory
createTextView
in class TreeViewFactory
text
- text node for which a view is to be createdparentView
- view of parent element; may be useful for some
factoriesprotected TextNodeView createTreeTextView(Text text, ElementView parentView)
protected abstract TextNodeView createStyledTextView(Style style, Text text, ElementView parentView)
public TextNodeView createCommentView(Comment comment, ElementView parentView)
ViewFactory
createCommentView
in class TreeViewFactory
comment
- comment node for which a view is to be createdparentView
- view of parent element; may be useful for some
factoriespublic TextNodeView createProcessingInstructionView(ProcessingInstruction pi, ElementView parentView)
ViewFactory
createProcessingInstructionView
in class TreeViewFactory
pi
- processing instruction node for which a view is to be createdparentView
- view of parent element; may be useful for some
factoriesprotected TextNodeView createTextNodeView(TextNode textNode, ElementView parentView)
protected TextNodeView createTreeCommentView(Comment comment, ElementView parentView)
protected TextNodeView createTreePIView(ProcessingInstruction pi, ElementView parentView)
protected abstract TextNodeView createStyledTextNodeView(Style style, ViewParameters param, StyleSpec spec, TextNode textNode, ElementView parentView)
public ElementView createElementView(Element element, ElementView parentView)
ViewFactory
createElementView
in class TreeViewFactory
element
- element for which a view is to be createdparentView
- view of parent element; may be useful for some
factoriesStyledViewFactory
does this for
display: none)protected ElementView createTreeElementView(Element element, ElementView parentView)
protected abstract ElementView createStyledElementView(Style style, ViewParameters param, StyleSpec spec, Style styleBefore, ViewParameters paramBefore, StyleSpec specBefore, Style styleAfter, ViewParameters paramAfter, StyleSpec specAfter, Element element, ElementView parentView)
protected void unregisterCounterActions(Element element)
protected void registerCounterActions(Element element, StyleSpec spec, StyleSpec specBefore, StyleSpec specAfter)
protected void addCounterActions(Element element, boolean isReset, StyleValue value, Element parent)
protected final String contentToToolTip(StyleValue val, Element element)
protected static final void appendDecodedURI(Element element, StyleValue func, StringBuilder buffer)
protected final void appendProperty(Element element, StyleValue func, StringBuilder buffer)
protected Style adjustMarginForListMarker(ListStyle listStyle, int listBulletWidth, Style style)
protected static final StyleValue injectListStyleType(StyleValue listItemCounter, StyleValue listStyleType)
public final Style specToStyle(StyleSpec spec, Style parentStyle, StyleValue.Keyword parentDisplay, Element element, ViewParameters param)
public final void specToStyle(StyleSpec spec, Style parentStyle, StyleValue.Keyword parentDisplay, Element element, Style style, ViewParameters param)
protected static final String listToFontFamily(StyleValue value)
protected int getBorderWidth(StyleValue val, Element element, Style parentStyle, FontMetrics metrics)
protected static final int maxBorderWidth(int w1, int w2, int w3, int w4)
protected Style.BorderStyle getBorderStyle(StyleValue val, Element element, Style.BorderStyle parentBorderStyle)
protected int[] getBorderRadius(StyleValue val, Element element, FontMetrics metrics, int parentRadiusH, int parentRadiusV)
protected int doGetBorderRadius(StyleValue val, Element element, FontMetrics metrics, int parentRadius)
protected BackgroundPaint getBackgroundPaint(StyleSpec spec, Element element, FontMetrics metrics, Style style, Style parentStyle)
protected StyleValue callFunction(StyleValue val, Node node)
protected StyleValue invokeExtension(StyleValue[] args, Node node)
protected String concatenate(StyleValue[] args, Node node)
protected void toString(StyleValue val, Node node, StringBuilder buffer)
protected String evalXPath(StringExpr expr, XNode context)
protected ExprContextImpl createExprContext()