org.writersforge.catalan.layout
Class LayoutArea

java.lang.Object
  extended byorg.writersforge.catalan.layout.LayoutArea
Direct Known Subclasses:
LayoutGroup, LayoutPadding, LayoutShape, LayoutText

public abstract class LayoutArea
extends java.lang.Object

Lightweight component for expressing final renderable content. The LayoutArea contains the visible text, an immutable Constraint object to define where the area wants to appear, and positioning extents to declare where the area really is in the final rendered product. By default, the text is managed as a simple String, but more complex inlined stylings can be managed with the optional StyledText property.

LayoutArea implements the Composite pattern, which treats each object as a potential node in a larger tree. Leaf nodes are interchangeable with branch nodes, although in the case of LayoutArea, each area is either one or the other. Thus, a text area (LayoutText) is a node and cannot contain children, while a group area (LayoutGroup) is a branch and can contain children, but not content.

LayoutArea objects are created by a RenderTemplate and populated with constraints; the LayoutEngine analyzes the constraints and fills up all the final extents.

Author:
jsheets

Constructor Summary
LayoutArea(AreaStyle style)
          Creates a new instance of LayoutArea.
 
Method Summary
 void addChildren(LayoutArea area)
          Appends a new child LayoutArea object into this area.
 void addChildren(LayoutArea[] areas)
          Appends an array of child LayoutArea objects into this area.
 boolean canBreakAt(int height)
          Determines if this area can be broken at the given height, measured from the top of the area.
 LayoutArea[] getChildren()
          Getter for property children, the child layout areas.
 LayoutArea getChildren(int index)
          Indexed getter for property children, the child layout areas.
 java.awt.Rectangle getExtents()
          Getter for property extents, the actual extents for this area.
 int getHeight()
          Getter for property height, the final calculated height to render this area.
 java.lang.String getHint()
          Getter for property hint, an optional field for descriptive info.
 java.awt.Rectangle getRenderableExtents()
          Retrieves a Rectangle of the valid rendering extents for this area, the normal extents minus the insets.
 AreaStyle getStyle()
          Getter for property style, the layout constraints set up by the template for this area.
 int getWidth()
          Getter for property width, the final calculated width to render this area.
 int getX()
          Getter for property x, the final calculated x-axis origin to render this area.
 int getY()
          Getter for property y, the final calculated y-axis origin to render this area.
 boolean isBreakable()
          Getter for property breakable, whether the area can be split or not.
 boolean isRenderable()
          Determines if this area has renderable content.
 void setChildren(int index, LayoutArea areas)
          Indexed setter for property children, the child layout areas.
 void setChildren(LayoutArea[] areas)
          Setter for property children, the child layout areas.
 void setExtents(java.awt.Rectangle extents)
          Setter for property extents, the actual extents for this area.
 void setHeight(int height)
          Setter for property height, the final calculated height to render this area.
 void setHint(java.lang.String hint)
          Setter for property hint, an optional field for descriptive info.
 void setWidth(int width)
          Setter for property width, the final calculated width to render this area.
 void setX(int x)
          Setter for property x, the final calculated x-axis origin to render this area.
 void setY(int y)
          Setter for property y, the final calculated y-axis origin to render this area.
 java.lang.String toString()
          Converts the area object into String form.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

LayoutArea

public LayoutArea(AreaStyle style)
Creates a new instance of LayoutArea.

Parameters:
style - the base style for this area
Method Detail

getStyle

public AreaStyle getStyle()
Getter for property style, the layout constraints set up by the template for this area.

Returns:
Value of property style.

isRenderable

public boolean isRenderable()
Determines if this area has renderable content. Layout engines can use this to optimize area traversals. Areas which are not renderable should not expect to pass through to the Renderer. The default value of this property is true, so any derived area which does not want to be renderable should override this method.

Returns:
true if this area has visible content

setWidth

public void setWidth(int width)
Setter for property width, the final calculated width to render this area.

Parameters:
width - New value of property width.

getWidth

public int getWidth()
Getter for property width, the final calculated width to render this area.

Returns:
Value of property width.

setHeight

public void setHeight(int height)
Setter for property height, the final calculated height to render this area.

Parameters:
height - New value of property height.

getHeight

public int getHeight()
Getter for property height, the final calculated height to render this area.

Returns:
Value of property height.

setX

public void setX(int x)
Setter for property x, the final calculated x-axis origin to render this area.

Parameters:
x - New value of property x.

getX

public int getX()
Getter for property x, the final calculated x-axis origin to render this area.

Returns:
Value of property x.

setY

public void setY(int y)
Setter for property y, the final calculated y-axis origin to render this area.

Parameters:
y - New value of property y.

getY

public int getY()
Getter for property y, the final calculated y-axis origin to render this area.

Returns:
Value of property y.

getExtents

public java.awt.Rectangle getExtents()
Getter for property extents, the actual extents for this area. Returns the internal Rectangle, so any changes made to it will affect the LayoutArea.

Returns:
Value of property extents.

setExtents

public void setExtents(java.awt.Rectangle extents)
Setter for property extents, the actual extents for this area.

Parameters:
extents - New value of property extents.

getRenderableExtents

public java.awt.Rectangle getRenderableExtents()
Retrieves a Rectangle of the valid rendering extents for this area, the normal extents minus the insets. The returned Rectangle is a copy, so any changes made to it will not be reflected in the area.

Returns:
the valid renderable extents

isBreakable

public boolean isBreakable()
Getter for property breakable, whether the area can be split or not. An autosized text area (with height constraints set to zero) is always breakable. Non-autosized text areas respond normally to the set breakable property.

Returns:
Value of property breakable.

canBreakAt

public boolean canBreakAt(int height)
Determines if this area can be broken at the given height, measured from the top of the area. The default implementation simply passes through the value of the breakable property. Subclasses such as LayoutGroup might override this method to account for more subtle breakage rules.

Parameters:
height - the height to attempt the break at
Returns:
Value of property breakable.

setHint

public void setHint(java.lang.String hint)
Setter for property hint, an optional field for descriptive info.

Parameters:
hint - New value of property hint.

getHint

public java.lang.String getHint()
Getter for property hint, an optional field for descriptive info.

Returns:
Value of property hint.

getChildren

public LayoutArea getChildren(int index)
Indexed getter for property children, the child layout areas.

Parameters:
index - Index of the property.
Returns:
Value of the property at index.

getChildren

public LayoutArea[] getChildren()
Getter for property children, the child layout areas.

Returns:
Value of property children.

setChildren

public void setChildren(int index,
                        LayoutArea areas)
Indexed setter for property children, the child layout areas.

Parameters:
index - Index of the property.
areas - New value of the property at index.

setChildren

public void setChildren(LayoutArea[] areas)
Setter for property children, the child layout areas.

Parameters:
areas - New value of property children.

addChildren

public void addChildren(LayoutArea area)
Appends a new child LayoutArea object into this area.

Parameters:
area - new LayoutArea object to append

addChildren

public void addChildren(LayoutArea[] areas)
Appends an array of child LayoutArea objects into this area.

Parameters:
areas - new LayoutArea objects to append

toString

public java.lang.String toString()
Converts the area object into String form. This implementation uses the value of getHint() if it's set. Otherwise, it creates a generic description. Thus, the toString() value can be set explicitly with setHint(), implicitly through AreaStyle.getDescription(), or generically as a fallback.

Returns:
the String representation of this object