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 String
getAttribute(String name)
Obtains a value of an additional attribute.Map<String,String>
getAttributes()
Obtains the names and values of all the box attributes.Color
getColor()
Obtains the box text color.Rectangular
getContentBounds()
Returns the content bounds.ContentObject
getContentObject()
Obtains the content object contained in this box.Box.DisplayType
getDisplayType()
Obtains the display type of the element according to the CSS display: property.String
getFontFamily()
Obtains the font family name used by the box.int
getHeight()
Box
getIntrinsicParent()
Gets the parent box of this box as obtained from the renderer.int
getOrder()
Gets the order of precedence of the box in the page.String
getOwnText()
Obtains the text contained directly in this box without considering its child boxes.String
getSourceNodeId()
Obtains a unique identification of the box source (e.g. the source DOM node).Rectangular
getSubstringBounds(int startPos, int endPos)
Returns the bounds of a substring of the own text of the box starting atstartPos
and ending atendPos
.String
getTagName()
When the box is generated by a DOM element, obtains the corresponding tag name.String
getText()
Obtains the complete text contained in this box.String
getText(BoxConcatenator concatenator)
Obtains the complete text contained in this box.Box.Type
getType()
Resurns the type of the box.Rectangular
getVisualBounds()
Returns the bounds of the box as they visually appear to the user.int
getWidth()
int
getX1()
int
getX2()
int
getY1()
int
getY2()
boolean
isVisible()
Checks whether the box is visible.boolean
isVisuallySeparated()
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.void
move(int xofs, int yofs)
protected void
recomputeTextStyle()
Recomputes the text style after the style of some children has changed.void
removeAttribute(String name)
void
setAttribute(String name, String value)
void
setColor(Color color)
void
setContentBounds(Rectangular contentBounds)
Sets the content bounds of the box.void
setContentObject(ContentObject contentObject)
void
setDisplayType(Box.DisplayType displayType)
void
setFontFamily(String fontFamily)
void
setIntrinsicParent(Box intrinsicParent)
void
setOrder(int order)
void
setOwnText(String text)
void
setSourceNodeId(String sourceNodeId)
void
setTagName(String tagName)
void
setType(Box.Type type)
void
setVisible(boolean visible)
void
setVisualBounds(Rectangular visualBounds)
Sets the visual bounds of the box.String
toString()
-
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:Box
Gets 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:Box
Checks 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:Box
Obtains the font family name used by the box.- Specified by:
getFontFamily
in interfaceBox
- Returns:
- The font family name.
-
setFontFamily
public void setFontFamily(String fontFamily)
-
getText
public String getText()
Description copied from interface:Box
Obtains 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:Box
Obtains 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:Box
Obtains the text contained directly in this box without considering its child boxes.- Specified by:
getOwnText
in interfaceBox
- Returns:
- a text string for leaf boxes,
null
for non-leaf boxes
-
setOwnText
public void setOwnText(String text)
-
getContentObject
public ContentObject getContentObject()
Description copied from interface:Box
Obtains the content object contained in this box.- Specified by:
getContentObject
in interfaceBox
- Returns:
- the content object or
null
when there is no object contained.
-
setContentObject
public void setContentObject(ContentObject contentObject)
-
getContentBounds
public Rectangular getContentBounds()
Description copied from interface:Box
Returns 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:
getContentBounds
in interfaceBox
- Returns:
- the content bounds of the box
-
setContentBounds
public void setContentBounds(Rectangular contentBounds)
Description copied from interface:Box
Sets the content bounds of the box.- Specified by:
setContentBounds
in interfaceBox
- Parameters:
contentBounds
- the new content bounds.
-
getVisualBounds
public Rectangular getVisualBounds()
Description copied from interface:Box
Returns the bounds of the box as they visually appear to the user.- Specified by:
getVisualBounds
in interfaceBox
- Returns:
- the visual bounds
-
setVisualBounds
public void setVisualBounds(Rectangular visualBounds)
Description copied from interface:Box
Sets the visual bounds of the box.- Specified by:
setVisualBounds
in interfaceBox
- Parameters:
visualBounds
- the new visual bounds.
-
getSubstringBounds
public Rectangular getSubstringBounds(int startPos, int endPos)
Description copied from interface:Box
Returns the bounds of a substring of the own text of the box starting atstartPos
and ending atendPos
.- Specified by:
getSubstringBounds
in 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
null
when there is no own text contained in the box
-
getIntrinsicParent
public Box getIntrinsicParent()
Description copied from interface:Box
Gets the parent box of this box as obtained from the renderer. The renturned value may benull
when the box was not obtained by rendering (e.g. a box tree loaded from the storage).- Specified by:
getIntrinsicParent
in interfaceBox
- Returns:
- the intrinsic parent box or
null
-
setIntrinsicParent
public void setIntrinsicParent(Box intrinsicParent)
-
getSourceNodeId
public String getSourceNodeId()
Description copied from interface:Box
Obtains 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:
getSourceNodeId
in interfaceBox
-
setSourceNodeId
public void setSourceNodeId(String sourceNodeId)
-
getTagName
public String getTagName()
Description copied from interface:Box
When the box is generated by a DOM element, obtains the corresponding tag name.- Specified by:
getTagName
in interfaceBox
- Returns:
- the tag name or
null
for 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:Box
Obtains 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 areclass
orhref
.- Specified by:
getAttribute
in interfaceBox
- Parameters:
name
- the attribute name- Returns:
- the attribute value or
null
if the value is not specified.
-
getAttributes
public Map<String,String> getAttributes()
Description copied from interface:Box
Obtains 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 areclass
orhref
.- Specified by:
getAttributes
in 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:Box
Resurns the type of the box.
-
setType
public void setType(Box.Type type)
-
getDisplayType
public Box.DisplayType getDisplayType()
Description copied from interface:Box
Obtains the display type of the element according to the CSS display: property.- Specified by:
getDisplayType
in 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:
getX1
in interfaceRect
- Overrides:
getX1
in classDefaultTreeContentRect<Box>
-
getY1
public int getY1()
- Specified by:
getY1
in interfaceRect
- Overrides:
getY1
in classDefaultTreeContentRect<Box>
-
getX2
public int getX2()
- Specified by:
getX2
in interfaceRect
- Overrides:
getX2
in classDefaultTreeContentRect<Box>
-
getY2
public int getY2()
- Specified by:
getY2
in interfaceRect
- Overrides:
getY2
in classDefaultTreeContentRect<Box>
-
getWidth
public int getWidth()
- Specified by:
getWidth
in interfaceRect
- Overrides:
getWidth
in classDefaultTreeContentRect<Box>
-
getHeight
public int getHeight()
- Specified by:
getHeight
in interfaceRect
- Overrides:
getHeight
in classDefaultTreeContentRect<Box>
-
move
public void move(int xofs, int yofs)
- Specified by:
move
in interfaceRect
- Overrides:
move
in classDefaultTreeContentRect<Box>
-
isVisuallySeparated
public boolean isVisuallySeparated()
Description copied from interface:Box
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.- Specified by:
isVisuallySeparated
in interfaceBox
- Returns:
true
if the box is visually separated
-
recomputeTextStyle
protected void recomputeTextStyle()
Description copied from class:DefaultTreeContentRect
Recomputes the text style after the style of some children has changed.- Overrides:
recomputeTextStyle
in classDefaultTreeContentRect<Box>
-
-