net.sourceforge.jeuclid.elements
Class AbstractJEuclidElement

java.lang.Object
  extended by net.sourceforge.jeuclid.dom.AbstractPartialNodeImpl
      extended by net.sourceforge.jeuclid.dom.AbstractPartialElementImpl
          extended by net.sourceforge.jeuclid.dom.AbstractChangeTrackingElement
              extended by net.sourceforge.jeuclid.elements.AbstractJEuclidElement
All Implemented Interfaces:
ChangeTrackingInterface, DisplayableNode, JEuclidElement, JEuclidNode, Element, MathMLElement, Node
Direct Known Subclasses:
AbstractContainer, AbstractInvisibleJEuclidElement, AbstractRoot, AbstractScriptElement, AbstractTokenWithTextLayout, AbstractUnderOver, Mfrac, Mo, Mspace, Mtable, Mtr

public abstract class AbstractJEuclidElement
extends AbstractChangeTrackingElement
implements JEuclidElement

The basic class for all math elements. Every element class inherits from this class. It provides basic functionality for drawing.

Version:
$Revision: 446 $
Author:
Unknown, Max Berger

Nested Class Summary
 
Nested classes/interfaces inherited from class net.sourceforge.jeuclid.dom.AbstractPartialElementImpl
AbstractPartialElementImpl.AttributeNodeMap, AbstractPartialElementImpl.AttrImpl
 
Nested classes/interfaces inherited from class net.sourceforge.jeuclid.dom.AbstractPartialNodeImpl
AbstractPartialNodeImpl.NodeList
 
Field Summary
static String ALIGN_AXIS
          value for axis alignment.
static String ALIGN_BASELINE
          value for baseline alignment.
static String ALIGN_BOTTOM
          value for bottom alignment.
static String ALIGN_CENTER
          value for center alignment.
static String ALIGN_LEFT
          value for left alignment.
static String ALIGN_RIGHT
          value for right alignment.
static String ALIGN_TOP
          value for top alignment.
static String ATTR_CLASS
          Constant for class attribute.
static String ATTR_DEPRECATED_BACKGROUND
          Constant for background attribute.
static String ATTR_DEPRECATED_COLOR
          Constant for color attribute.
static String ATTR_DEPRECATED_FONTFAMILY
          Constant for fontfamily attribute.
static String ATTR_DEPRECATED_FONTSIZE
          Constant for fontsize attribute.
static String ATTR_DEPRECATED_FONTSTYLE
          Constant for fontstyle attribute.
static String ATTR_DEPRECATED_FONTWEIGHT
          Constant for fontweight attribute.
static String ATTR_HREF
          Constant for href attribute.
static String ATTR_ID
          Constant for id attribute.
static String ATTR_MATHBACKGROUND
          The mathbackground attribute.
static String ATTR_MATHCOLOR
          Constant for mathcolor attribute.
static String ATTR_MATHSIZE
          Constant for mathsize attribute.
static String ATTR_MATHVARIANT
          Constant for mathvariant attribute.
static String ATTR_STYLE
          Constant for style attribute.
static String ATTR_XREF
          Constant for xref attribute.
static int TRIVIAL_SPACE_MAX
          largest value for all trivial spaces (= spaces that can be ignored / shortened).
static String URI
          The URI from MathML.
 
Fields inherited from interface org.w3c.dom.Node
ATTRIBUTE_NODE, CDATA_SECTION_NODE, COMMENT_NODE, DOCUMENT_FRAGMENT_NODE, DOCUMENT_NODE, DOCUMENT_POSITION_CONTAINED_BY, DOCUMENT_POSITION_CONTAINS, DOCUMENT_POSITION_DISCONNECTED, DOCUMENT_POSITION_FOLLOWING, DOCUMENT_POSITION_IMPLEMENTATION_SPECIFIC, DOCUMENT_POSITION_PRECEDING, DOCUMENT_TYPE_NODE, ELEMENT_NODE, ENTITY_NODE, ENTITY_REFERENCE_NODE, NOTATION_NODE, PROCESSING_INSTRUCTION_NODE, TEXT_NODE
 
Constructor Summary
AbstractJEuclidElement(MathBase base)
          Creates a math element.
 
Method Summary
 void addMathElement(MathMLElement child)
          Add a math element as a child.
 void addText(String text)
          Add the content of a String to this element.
abstract  float calculateAscentHeight(Graphics2D g)
          Returns the current height of the upper part (over the base line).
abstract  float calculateDescentHeight(Graphics2D g)
          Calculates descent height (under the base line) of the element.
 float calculateHeight(Graphics2D g)
          Calculates the current height of the element.
abstract  float calculateWidth(Graphics2D g)
          Caculates width of the element.
protected  void changeHook()
          Called on any change.
 void debug(Graphics2D g, float posX, float posY)
          Paints a border around this element as debug information.
protected  int getAbsoluteScriptLevel()
          Retrieve the absolute script level.
 float getAscentHeight(Graphics2D g)
          Returns the current height of the upper part of this component from the baseline.
 Color getBackgroundColor()
          Returns background color of the element.
 String getClassName()
          The class attribute of the element.
 MathMLNodeList getContents()
          Returns the children as a MathML NodeList.
 float getDescentHeight(Graphics2D g)
          Returns the current height of the lower part of this component from the baseline.
 Font getFont()
          Gets the used font.
 FontMetrics getFontMetrics(Graphics2D g)
          Gets the font metrics of the used font.
 float getFontsizeInPoint()
          Gets the size of the actual font used (including scriptsizemultiplier).
 Color getForegroundColor()
          Gets the color that this element is supposed to use for rendering its foreground elements.
 float getGlobalLineCorrector()
          Returns value of the vertical shift for the specific elements in the line.
 float getHeight(Graphics2D g)
          Return the current height of this element.
 String getHref()
          The xlink:href attribute of the element.
 String getId()
          The element's identifier.
 int getIndexOfMathElement(JEuclidElement element)
          Gets index of child element.
protected  int getInheritedScriptlevel()
          Retrieves the scriptlevel from the parent node.
protected  String getMathAttribute(String attrName)
          retrieve an attribute from the MathML or default namespace.
 String getMathbackground()
          Returns value of mathbackground attribute.
 MathBase getMathBase()
          Gets the math base.
 String getMathcolor()
          Returns value of mathcolor attribute.
 JEuclidElement getMathElement(int index)
          Gets a child from this element.
 int getMathElementCount()
          Returns the count of childs from this element.
 String getMathElementStyle()
          A string identifying the element's style attribute.
 String getMathsize()
          Retrieve the mathsize attribute.
 float getMathsizeInPoint()
          Get the actual mathsize in points.
 String getMathvariant()
          Returns value of mathvariant attribute (style of the element).
 MathVariant getMathvariantAsVariant()
          Gets the current mathvariant.
 float getMiddleShift(Graphics2D g)
          Returns the distance of the baseline and the middleline.
 MathMLMathElement getOwnerMathElement()
          The MathMLMathElement corresponding to the nearest math element ancestor of this element.
 float getPaintedPosX()
          Returns the last X position this node was painted on.
 float getPaintedPosY()
          Returns the last Y position this node was painted on.
 JEuclidElement getParent()
          Returns parent of this element.
 int getScriptlevelForChild(JEuclidElement child)
          Retrieves the scriptlevel for a certain child.
 float getScriptSizeMultiplier()
          Gets value of scriptsize attribute.
 String getText()
          Returns the text content of this element.
 float getWidth(Graphics2D g)
          Returns the current width of this element.
 float getXCenter(Graphics2D g)
          Returns the center X coordinate of the content.
 String getXref()
          The xref attribute of the element.
 boolean hasChildPostscripts(JEuclidElement child)
          returns true is the child has postscripts attached to it.
 boolean hasChildPrescripts(JEuclidElement child)
          returns true is the child has prescripts attached to it.
 boolean isCalculatingSize()
          returns true if the parent is currently calculating its size.
 boolean isChildBlock(JEuclidElement child)
          Returns true if the child should be displayed as a block (not inline).
 void paint(Graphics2D g, float posX, float posY)
          Paints this element.
protected  void recalculateSize()
          Reset element sizes.
 void setCalculatingSize(boolean ncalculatingSize)
          
 void setClassName(String className)
          setter for the className attribute.
protected  void setDefaultMathAttribute(String key, String value)
          Sets default values for math attributes.
 void setFakeParent(JEuclidElement parent)
          Sets the parent of this element.
 void setGlobalLineCorrector(float corrector)
          Sets value of the vertical shift for the specific elements in the line.
 void setHref(String href)
          setter for the href attribute.
 void setId(String id)
          setter for the id attribute.
 void setMathAttributes(AttributeMap attributes)
          convenience method to set multiple attributes at once.
 void setMathbackground(String mathbackground)
          Sets the value of the machbackground attribute.
 void setMathBase(MathBase base)
          Sets the base for this element.
 void setMathcolor(String mathcolor)
          Sets value of math color attribute.
 void setMathElement(int index, MathMLElement newElement)
          Sets a specific child to the newElement, creating other subelements as necessary.
 void setMathElementStyle(String mathElementStyle)
          setter for the mathElementStyle attribute.
 void setMathsize(String mathsize)
          Sets mathsize to a new value.
 void setMathvariant(String mathvariant)
          Sets value of mathvariant attribute (style of the element).
 void setScriptSizeMultiplier(float scriptsizemultiplier)
          Sets value of scriptsize attribute.
 void setXref(String xref)
          setter for the xref attribute.
 
Methods inherited from class net.sourceforge.jeuclid.dom.AbstractChangeTrackingElement
addListener, appendChild, fireChanged, fireChangeForSubTree, replaceChild, setAttribute, setTextContent
 
Methods inherited from class net.sourceforge.jeuclid.dom.AbstractPartialElementImpl
getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getAttributes, getElementsByTagName, getElementsByTagNameNS, getLocalName, getNodeName, getNodeType, getSchemaTypeInfo, hasAttribute, hasAttributeNS, removeAttribute, removeAttributeNode, removeAttributeNS, setAttributeNode, setAttributeNodeNS, setAttributeNS, setIdAttribute, setIdAttributeNode, setIdAttributeNS, toString
 
Methods inherited from class net.sourceforge.jeuclid.dom.AbstractPartialNodeImpl
cloneNode, compareDocumentPosition, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getNamespaceURI, getNextSibling, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, setNodeValue, setPrefix, setUserData
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 
Methods inherited from interface org.w3c.dom.Element
getAttribute, getAttributeNode, getAttributeNodeNS, getAttributeNS, getElementsByTagName, getElementsByTagNameNS, getSchemaTypeInfo, getTagName, hasAttribute, hasAttributeNS, removeAttribute, removeAttributeNode, removeAttributeNS, setAttribute, setAttributeNode, setAttributeNodeNS, setAttributeNS, setIdAttribute, setIdAttributeNode, setIdAttributeNS
 
Methods inherited from interface org.w3c.dom.Node
appendChild, cloneNode, compareDocumentPosition, getAttributes, getBaseURI, getChildNodes, getFeature, getFirstChild, getLastChild, getLocalName, getNamespaceURI, getNextSibling, getNodeName, getNodeType, getNodeValue, getOwnerDocument, getParentNode, getPrefix, getPreviousSibling, getTextContent, getUserData, hasAttributes, hasChildNodes, insertBefore, isDefaultNamespace, isEqualNode, isSameNode, isSupported, lookupNamespaceURI, lookupPrefix, normalize, removeChild, replaceChild, setNodeValue, setPrefix, setTextContent, setUserData
 
Methods inherited from interface net.sourceforge.jeuclid.dom.ChangeTrackingInterface
addListener, fireChanged, fireChangeForSubTree
 

Field Detail

ATTR_MATHVARIANT

public static final String ATTR_MATHVARIANT
Constant for mathvariant attribute.

See Also:
Constant Field Values

ATTR_MATHCOLOR

public static final String ATTR_MATHCOLOR
Constant for mathcolor attribute.

See Also:
Constant Field Values

ATTR_MATHSIZE

public static final String ATTR_MATHSIZE
Constant for mathsize attribute.

See Also:
Constant Field Values

ATTR_DEPRECATED_FONTFAMILY

public static final String ATTR_DEPRECATED_FONTFAMILY
Constant for fontfamily attribute.

See Also:
Constant Field Values

ATTR_DEPRECATED_FONTSTYLE

public static final String ATTR_DEPRECATED_FONTSTYLE
Constant for fontstyle attribute.

See Also:
Constant Field Values

ATTR_DEPRECATED_FONTWEIGHT

public static final String ATTR_DEPRECATED_FONTWEIGHT
Constant for fontweight attribute.

See Also:
Constant Field Values

ATTR_DEPRECATED_FONTSIZE

public static final String ATTR_DEPRECATED_FONTSIZE
Constant for fontsize attribute.

See Also:
Constant Field Values

ATTR_DEPRECATED_COLOR

public static final String ATTR_DEPRECATED_COLOR
Constant for color attribute.

See Also:
Constant Field Values

ATTR_DEPRECATED_BACKGROUND

public static final String ATTR_DEPRECATED_BACKGROUND
Constant for background attribute.

See Also:
Constant Field Values

ATTR_CLASS

public static final String ATTR_CLASS
Constant for class attribute.

See Also:
Constant Field Values

ATTR_STYLE

public static final String ATTR_STYLE
Constant for style attribute.

See Also:
Constant Field Values

ATTR_ID

public static final String ATTR_ID
Constant for id attribute.

See Also:
Constant Field Values

ATTR_HREF

public static final String ATTR_HREF
Constant for href attribute.

See Also:
Constant Field Values

ATTR_XREF

public static final String ATTR_XREF
Constant for xref attribute.

See Also:
Constant Field Values

ATTR_MATHBACKGROUND

public static final String ATTR_MATHBACKGROUND
The mathbackground attribute.

See Also:
Constant Field Values

ALIGN_TOP

public static final String ALIGN_TOP
value for top alignment.

See Also:
Constant Field Values

ALIGN_BOTTOM

public static final String ALIGN_BOTTOM
value for bottom alignment.

See Also:
Constant Field Values

ALIGN_CENTER

public static final String ALIGN_CENTER
value for center alignment.

See Also:
Constant Field Values

ALIGN_BASELINE

public static final String ALIGN_BASELINE
value for baseline alignment.

See Also:
Constant Field Values

ALIGN_AXIS

public static final String ALIGN_AXIS
value for axis alignment.

See Also:
Constant Field Values

ALIGN_LEFT

public static final String ALIGN_LEFT
value for left alignment.

See Also:
Constant Field Values

ALIGN_RIGHT

public static final String ALIGN_RIGHT
value for right alignment.

See Also:
Constant Field Values

TRIVIAL_SPACE_MAX

public static final int TRIVIAL_SPACE_MAX
largest value for all trivial spaces (= spaces that can be ignored / shortened).

See Also:
Constant Field Values

URI

public static final String URI
The URI from MathML.

See Also:
Constant Field Values
Constructor Detail

AbstractJEuclidElement

public AbstractJEuclidElement(MathBase base)
Creates a math element.

Parameters:
base - The base for the math element tree.
Method Detail

recalculateSize

protected void recalculateSize()
Reset element sizes.


changeHook

protected void changeHook()
Called on any change. Please override!

Overrides:
changeHook in class AbstractChangeTrackingElement

getFontsizeInPoint

public float getFontsizeInPoint()
Gets the size of the actual font used (including scriptsizemultiplier).

Specified by:
getFontsizeInPoint in interface JEuclidNode
Returns:
size of the current font.

getFont

public Font getFont()
Gets the used font. Everything regardes font, processed by MathBase object.

Returns:
Font Font object.

getMathvariantAsVariant

public MathVariant getMathvariantAsVariant()
Gets the current mathvariant.

Specified by:
getMathvariantAsVariant in interface JEuclidElement
Returns:
the current MathVariant

getAbsoluteScriptLevel

protected int getAbsoluteScriptLevel()
Retrieve the absolute script level. For most items this will ask the parent item.

Returns:
the absolute script level.
See Also:
getInheritedScriptlevel()

getInheritedScriptlevel

protected int getInheritedScriptlevel()
Retrieves the scriptlevel from the parent node.

Returns:
the scriptlevel of the parent node

getScriptlevelForChild

public int getScriptlevelForChild(JEuclidElement child)
Retrieves the scriptlevel for a certain child. Some attributes increase the scriptlevel for some of their children.

Specified by:
getScriptlevelForChild in interface JEuclidElement
Parameters:
child - element node of the child.
Returns:
the scriptlevel for this particular child.

addMathElement

public final void addMathElement(MathMLElement child)
Add a math element as a child.

Parameters:
child - Math element object.

getMathElement

public JEuclidElement getMathElement(int index)
Gets a child from this element.

Please note, that unlike the MathML DOM model functions this function uses a 0-based index.

Specified by:
getMathElement in interface JEuclidElement
Parameters:
index - Index of the child (0-based).
Returns:
The child MathElement object.

setMathElement

public void setMathElement(int index,
                           MathMLElement newElement)
Sets a specific child to the newElement, creating other subelements as necessary.

Specified by:
setMathElement in interface JEuclidElement
Parameters:
index - the index to set (0=the firt child)
newElement - new element to be set as child.

getIndexOfMathElement

public int getIndexOfMathElement(JEuclidElement element)
Gets index of child element.

Specified by:
getIndexOfMathElement in interface JEuclidElement
Parameters:
element - Child element.
Returns:
Index of the element, -1 if element was not found

getMathElementCount

public int getMathElementCount()
Returns the count of childs from this element.

Specified by:
getMathElementCount in interface JEuclidElement
Returns:
Count of childs.

addText

public void addText(String text)
Add the content of a String to this element.

Parameters:
text - String with text of this object.

getText

public String getText()
Returns the text content of this element.

Returns:
Text content.

setMathBase

public void setMathBase(MathBase base)
Sets the base for this element.

Parameters:
base - Math base object.

getMathBase

public MathBase getMathBase()
Gets the math base.

Specified by:
getMathBase in interface JEuclidElement
Returns:
Math base object.

setFakeParent

public void setFakeParent(JEuclidElement parent)
Sets the parent of this element.

Specified by:
setFakeParent in interface JEuclidElement
Parameters:
parent - Parent element

getParent

public JEuclidElement getParent()
Returns parent of this element.

Specified by:
getParent in interface JEuclidElement
Returns:
Parent element.

setMathvariant

public void setMathvariant(String mathvariant)
Sets value of mathvariant attribute (style of the element).

Parameters:
mathvariant - Value of mathvariant.

getMathvariant

public String getMathvariant()
Returns value of mathvariant attribute (style of the element).

Returns:
Value of mathvariant.

getScriptSizeMultiplier

public float getScriptSizeMultiplier()
Gets value of scriptsize attribute.

Returns:
Value of scriptsize attribute.

setScriptSizeMultiplier

public void setScriptSizeMultiplier(float scriptsizemultiplier)
Sets value of scriptsize attribute.

Parameters:
scriptsizemultiplier - Value of scriptsize attribute.

getFontMetrics

public FontMetrics getFontMetrics(Graphics2D g)
Gets the font metrics of the used font.

Parameters:
g - Graphics2D context to use.
Returns:
Font metrics.

setMathcolor

public void setMathcolor(String mathcolor)
Sets value of math color attribute.

Parameters:
mathcolor - Color object.

getMathcolor

public String getMathcolor()
Returns value of mathcolor attribute.

Returns:
Color as string.

getMathsize

public String getMathsize()
Retrieve the mathsize attribute.

Returns:
the mathsize attribute.

setMathsize

public void setMathsize(String mathsize)
Sets mathsize to a new value.

Parameters:
mathsize - value of mathsize.

getMathsizeInPoint

public float getMathsizeInPoint()
Get the actual mathsize in points. This does not include scriptsizemultiplier.

Specified by:
getMathsizeInPoint in interface JEuclidNode
Returns:
mathsize in points.

setDefaultMathAttribute

protected void setDefaultMathAttribute(String key,