Package cz.vutbr.fit.layout.impl
Class DefaultBox
- java.lang.Object
-
- cz.vutbr.fit.layout.impl.DefaultTreeNode<T>
-
- cz.vutbr.fit.layout.impl.DefaultTreeContentRect<Box>
-
- cz.vutbr.fit.layout.impl.DefaultBox
-
- All Implemented Interfaces:
Box,ContentRect,GenericTreeNode<Box>,Rect
public class DefaultBox extends DefaultTreeContentRect<Box> implements Box
Default generic box implementation.- Author:
- burgetr
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface cz.vutbr.fit.layout.model.Box
Box.DisplayType, Box.Type
-
-
Field Summary
-
Fields inherited from interface cz.vutbr.fit.layout.model.ContentRect
ATTR_SAME_AS
-
-
Constructor Summary
Constructors Constructor Description DefaultBox()DefaultBox(Box src)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description StringgetAttribute(String name)Obtains a value of an additional attribute.Map<String,String>getAttributes()Obtains the names and values of all the box attributes.ColorgetColor()Obtains the box text color.RectangulargetContentBounds()Returns the content bounds.ContentObjectgetContentObject()Obtains the content object contained in this box.Box.DisplayTypegetDisplayType()Obtains the display type of the element according to the CSS display: property.StringgetFontFamily()Obtains the font family name used by the box.intgetHeight()BoxgetIntrinsicParent()Gets the parent box of this box as obtained from the renderer.intgetOrder()Gets the order of precedence of the box in the page.StringgetOwnText()Obtains the text contained directly in this box without considering its child boxes.StringgetSourceNodeId()Obtains a unique identification of the box source (e.g. the source DOM node).RectangulargetSubstringBounds(int startPos, int endPos)Returns the bounds of a substring of the own text of the box starting atstartPosand ending atendPos.StringgetTagName()When the box is generated by a DOM element, obtains the corresponding tag name.StringgetText()Obtains the complete text contained in this box.StringgetText(BoxConcatenator concatenator)Obtains the complete text contained in this box.Box.TypegetType()Resurns the type of the box.RectangulargetVisualBounds()Returns the bounds of the box as they visually appear to the user.intgetWidth()intgetX1()intgetX2()intgetY1()intgetY2()booleanisVisible()Checks whether the box is visible.booleanisVisuallySeparated()Checks if the box is separated from other contents by some visual means: a visible border at any side, visible background different from its parent or a visible content.voidmove(int xofs, int yofs)protected voidrecomputeTextStyle()Recomputes the text style after the style of some children has changed.voidremoveAttribute(String name)voidsetAttribute(String name, String value)voidsetColor(Color color)voidsetContentBounds(Rectangular contentBounds)Sets the content bounds of the box.voidsetContentObject(ContentObject contentObject)voidsetDisplayType(Box.DisplayType displayType)voidsetFontFamily(String fontFamily)voidsetIntrinsicParent(Box intrinsicParent)voidsetOrder(int order)voidsetOwnText(String text)voidsetSourceNodeId(String sourceNodeId)voidsetTagName(String tagName)voidsetType(Box.Type type)voidsetVisible(boolean visible)voidsetVisualBounds(Rectangular visualBounds)Sets the visual bounds of the box.StringtoString()-
Methods inherited from class cz.vutbr.fit.layout.impl.DefaultTreeContentRect
addUserAttribute, equals, getBackgroundColor, getBackgroundImagePng, getBorderCount, getBorderStyle, getBottomBorder, getBounds, getId, getLeftBorder, getLine, getPageIri, getRightBorder, getTextStyle, getTopBorder, getUserAttribute, hasBackground, hasBottomBorder, hashCode, hasLeftBorder, hasRightBorder, hasTopBorder, childrenChanged, isBackgroundSeparated, setBackgroundColor, setBackgroundImagePng, setBackgroundSeparated, setBorderStyle, setBounds, setId, setLine, setPageIri, setTextStyle
-
Methods inherited from class cz.vutbr.fit.layout.impl.DefaultTreeNode
appendChild, appendChildren, getDepth, getChildAt, getChildCount, getChildren, getIndex, getLeafCount, getNextSibling, getParent, getPreviousSibling, getRoot, insertChild, isLeaf, isRoot, removeAllChildren, removeChild, removeChild, setParent, setRoot
-
Methods inherited from class java.lang.Object
clone, finalize, getClass, notify, notifyAll, wait, wait, wait
-
Methods inherited from interface cz.vutbr.fit.layout.model.ContentRect
addUserAttribute, getBackgroundColor, getBackgroundImagePng, getBorderCount, getBorderStyle, getBottomBorder, getId, getLeftBorder, getLine, getPageIri, getRightBorder, getTextStyle, getTopBorder, getUserAttribute, hasBackground, hasBottomBorder, hasLeftBorder, hasRightBorder, hasTopBorder, isBackgroundSeparated, setBackgroundSeparated, setBounds, setLine
-
Methods inherited from interface cz.vutbr.fit.layout.model.GenericTreeNode
appendChild, appendChildren, getDepth, getChildAt, getChildCount, getChildren, getIndex, getLeafCount, getNextSibling, getParent, getPreviousSibling, getRoot, childrenChanged, insertChild, isLeaf, isRoot, removeAllChildren, removeChild, removeChild, setParent, setRoot
-
-
-
-
Constructor Detail
-
DefaultBox
public DefaultBox()
-
DefaultBox
public DefaultBox(Box src)
-
-
Method Detail
-
getOrder
public int getOrder()
Description copied from interface:BoxGets the order of precedence of the box in the page. A box that precedes another box in the page must have a lower order number.
-
setOrder
public void setOrder(int order)
-
isVisible
public boolean isVisible()
Description copied from interface:BoxChecks whether the box is visible.
-
setVisible
public void setVisible(boolean visible)
-
setColor
public void setColor(Color color)
-
getFontFamily
public String getFontFamily()
Description copied from interface:BoxObtains the font family name used by the box.- Specified by:
getFontFamilyin interfaceBox- Returns:
- The font family name.
-
setFontFamily
public void setFontFamily(String fontFamily)
-
getText
public String getText()
Description copied from interface:BoxObtains the complete text contained in this box. For the leaf boxes, it returns the corresponding string. For non-leaft boxes, it returns the concatentaion of the leaf box strings using the default concatenator defined byConcatenators.getDefaultBoxConcatenator().
-
getText
public String getText(BoxConcatenator concatenator)
Description copied from interface:BoxObtains the complete text contained in this box. For the leaf boxes, it returns the corresponding string. For non-leaft boxes, it returns the concatentaion of the leaf box strings using a given concatenator.
-
getOwnText
public String getOwnText()
Description copied from interface:BoxObtains the text contained directly in this box without considering its child boxes.- Specified by:
getOwnTextin interfaceBox- Returns:
- a text string for leaf boxes,
nullfor non-leaf boxes
-
setOwnText
public void setOwnText(String text)
-
getContentObject
public ContentObject getContentObject()
Description copied from interface:BoxObtains the content object contained in this box.- Specified by:
getContentObjectin interfaceBox- Returns:
- the content object or
nullwhen there is no object contained.
-
setContentObject
public void setContentObject(ContentObject contentObject)
-
getContentBounds
public Rectangular getContentBounds()
Description copied from interface:BoxReturns the content bounds. They correspond to the background bounds of the box; however, when a border is present, it is included in the contents. Moreover, the box is clipped by its clipping box.- Specified by:
getContentBoundsin interfaceBox- Returns:
- the content bounds of the box
-
setContentBounds
public void setContentBounds(Rectangular contentBounds)
Description copied from interface:BoxSets the content bounds of the box.- Specified by:
setContentBoundsin interfaceBox- Parameters:
contentBounds- the new content bounds.
-
getVisualBounds
public Rectangular getVisualBounds()
Description copied from interface:BoxReturns the bounds of the box as they visually appear to the user.- Specified by:
getVisualBoundsin interfaceBox- Returns:
- the visual bounds
-
setVisualBounds
public void setVisualBounds(Rectangular visualBounds)
Description copied from interface:BoxSets the visual bounds of the box.- Specified by:
setVisualBoundsin interfaceBox- Parameters:
visualBounds- the new visual bounds.
-
getSubstringBounds
public Rectangular getSubstringBounds(int startPos, int endPos)
Description copied from interface:BoxReturns the bounds of a substring of the own text of the box starting atstartPosand ending atendPos.- Specified by:
getSubstringBoundsin interfaceBox- Parameters:
startPos- the starting position in the own text of the box (as obtained by )endPos- the ending position in the own text of the box- Returns:
- the visual bounds in pixels or
nullwhen there is no own text contained in the box
-
getIntrinsicParent
public Box getIntrinsicParent()
Description copied from interface:BoxGets the parent box of this box as obtained from the renderer. The renturned value may benullwhen the box was not obtained by rendering (e.g. a box tree loaded from the storage).- Specified by:
getIntrinsicParentin interfaceBox- Returns:
- the intrinsic parent box or
null
-
setIntrinsicParent
public void setIntrinsicParent(Box intrinsicParent)
-
getSourceNodeId
public String getSourceNodeId()
Description copied from interface:BoxObtains a unique identification of the box source (e.g. the source DOM node). This may be used for recognizing the boxes generated by the same DOM node.- Specified by:
getSourceNodeIdin interfaceBox
-
setSourceNodeId
public void setSourceNodeId(String sourceNodeId)
-
getTagName
public String getTagName()
Description copied from interface:BoxWhen the box is generated by a DOM element, obtains the corresponding tag name.- Specified by:
getTagNamein interfaceBox- Returns:
- the tag name or
nullfor boxes that do not correspond to a DOM element.
-
setTagName
public void setTagName(String tagName)
-
getAttribute
public String getAttribute(String name)
Description copied from interface:BoxObtains a value of an additional attribute. The existing attribute names depend on the box implementation; they may correspond to HTML (DOM) attributes or they may be purely virtual. The typical attributes to be implemented areclassorhref.- Specified by:
getAttributein interfaceBox- Parameters:
name- the attribute name- Returns:
- the attribute value or
nullif the value is not specified.
-
getAttributes
public Map<String,String> getAttributes()
Description copied from interface:BoxObtains the names and values of all the box attributes. The existing attribute names depend on the box implementation; they may correspond to HTML (DOM) attributes or they may be purely virtual. The typical attributes to be implemented areclassorhref.- Specified by:
getAttributesin interfaceBox- Returns:
- A map assigning values to the individual attribute names. An empty map is returned when no attributes are defined.
-
removeAttribute
public void removeAttribute(String name)
-
getType
public Box.Type getType()
Description copied from interface:BoxResurns the type of the box.
-
setType
public void setType(Box.Type type)
-
getDisplayType
public Box.DisplayType getDisplayType()
Description copied from interface:BoxObtains the display type of the element according to the CSS display: property.- Specified by:
getDisplayTypein interfaceBox- Returns:
- The display type of NULL if the box does not correspond to an element
-
setDisplayType
public void setDisplayType(Box.DisplayType displayType)
-
getX1
public int getX1()
- Specified by:
getX1in interfaceRect- Overrides:
getX1in classDefaultTreeContentRect<Box>
-
getY1
public int getY1()
- Specified by:
getY1in interfaceRect- Overrides:
getY1in classDefaultTreeContentRect<Box>
-
getX2
public int getX2()
- Specified by:
getX2in interfaceRect- Overrides:
getX2in classDefaultTreeContentRect<Box>
-
getY2
public int getY2()
- Specified by:
getY2in interfaceRect- Overrides:
getY2in classDefaultTreeContentRect<Box>
-
getWidth
public int getWidth()
- Specified by:
getWidthin interfaceRect- Overrides:
getWidthin classDefaultTreeContentRect<Box>
-
getHeight
public int getHeight()
- Specified by:
getHeightin interfaceRect- Overrides:
getHeightin classDefaultTreeContentRect<Box>
-
move
public void move(int xofs, int yofs)- Specified by:
movein interfaceRect- Overrides:
movein classDefaultTreeContentRect<Box>
-
isVisuallySeparated
public boolean isVisuallySeparated()
Description copied from interface:BoxChecks if the box is separated from other contents by some visual means: a visible border at any side, visible background different from its parent or a visible content.- Specified by:
isVisuallySeparatedin interfaceBox- Returns:
trueif the box is visually separated
-
recomputeTextStyle
protected void recomputeTextStyle()
Description copied from class:DefaultTreeContentRectRecomputes the text style after the style of some children has changed.- Overrides:
recomputeTextStylein classDefaultTreeContentRect<Box>
-
-