com.inet.html.views.layouts
Class Layout

java.lang.Object
  extended by com.inet.html.views.layouts.Layout
Direct Known Subclasses:
BlockLayout, ControlLayout, InlineLayout, NoLayout, TableLayout

public abstract class Layout
extends java.lang.Object

Generic Layout class. Holds the size, span and offset of a view. The offset is calculated relativ to the parent of this layout's view. NOTE: The layout only contains data, which may change on resize! Everything else is calculated only once and therefore bound to the model.


Nested Class Summary
 class Layout.PositionInfo
          A simple dataholder to store position relevant data when layouting a view
static class Layout.ViewPosition
          View Positioning class
 
Field Summary
static int MARKER_OFFSET
          the default distance between a list marker and the content
 
Constructor Summary
Layout(BoxView view)
          Creates the layout and set the view, which should be layouted
 
Method Summary
 void getChildAllocation(int i, java.awt.Rectangle rect)
          Stores the position of a child to rect.
 Layout.PositionInfo getChildPosition(BoxView childView)
          Returns the layouted position information of a child of this layout
 java.util.List<Layout.PositionInfo> getChildren()
          Returns the list of all children known to this layout object.
 int getCurrentHeight()
          Returns the current height of the referenced view
 int getCurrentLeft()
          Returns the current x position of the top left corner
 float getCurrentSpan(int axis)
          This returns the size calculated for the current layout.
 int getCurrentTop()
          Returns the current y position of the top left corner
 int getCurrentWidth()
          Returns the current width of the referenced view
 int getMinimumHeight()
          Get MinimumHeight set by preLayout
 float getMinimumSpan(int axis)
          Returns the minimums span as calculated by the prelayout function
 int getMinimumWidth()
          Get MinimumWidth set by preLayout
 int getPreferredHeight()
          Get PreferredHeight set by preLayout
 float getPreferredSpan(int axis)
          This returns the pre-calculated preferred width, which is the maximim width the content of this layout may need.
 int getPreferredWidth()
          Get PreferredWidth set by preLayout
abstract  java.awt.Rectangle getSpan()
          Returns the area affected by the current layout or any of it's siblings, relative the it's own left upper corner.
 BoxView getView()
          Returns the view this layouter is responsible for
 int getViewCount()
          Returns the number of child-views known to this layout object
abstract  ViewPositionInfo getViewForPosition(java.awt.Point position, java.awt.Rectangle a)
          Finds the view and it's location for a specific point of the screen
 boolean isPreLayouted()
          Returns true, if the view this layout is responsible for, has the PRE attribute
abstract  java.awt.Rectangle layout(boolean hard)
          This method will do the final layouting
abstract  void layoutVerticalAlign(int align, int baselineOffset)
          This method performs the vertical alignment of the whole content within the box.
abstract  void layoutWidth()
          Set the width of the layouted component.
abstract  java.awt.Shape modelToView(int pos, java.awt.Shape a, javax.swing.text.Position.Bias b)
          Tries to find the rectangle representing a given model-position.
static void offsetRelative(Layout.ViewPosition info)
          Applies the relative position offset to a view
abstract  void predictWidth(int width)
          Can be used to force a view to a specified width.
abstract  void preLayout()
          This method doe's the part of the layouting, which has to be called only once per website.
static void replace(javax.swing.text.View oldView, javax.swing.text.View[] newViews)
          Replace the old view with a list of new views in the same container.
 void setCurrentHeight(int currentHeight)
          Sets the current content height for this box
 void setCurrentWidth(int currentWidth)
          Sets the current content width for this box
 void setPreLayouted()
          Marks is layout as PRE
 java.lang.String toString()
          
static void union(java.awt.Rectangle union, int x, int y, int width, int height)
          Creates a union of the two rects without the requirement for another rectangle object
NOTE: the width of both rectangles must be positive!
static void union(java.awt.Rectangle union, java.awt.Rectangle join)
          Creates a union of the two rects.
abstract  int viewToModel(float x, float y, java.awt.Shape a, javax.swing.text.Position.Bias[] biasReturn)
          Searches the view-tree for a specified point and returns the model-offset for this position.
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

MARKER_OFFSET

public static final int MARKER_OFFSET
the default distance between a list marker and the content

Constructor Detail

Layout

public Layout(BoxView view)
Creates the layout and set the view, which should be layouted

Parameters:
view - the view, which should be layouted
Method Detail

getCurrentSpan

public float getCurrentSpan(int axis)
This returns the size calculated for the current layout. It will be used for the preferred size of some view but it is - in fact - not the preferred size.

Parameters:
axis - axis constant
Returns:
current size

getPreferredSpan

public float getPreferredSpan(int axis)
This returns the pre-calculated preferred width, which is the maximim width the content of this layout may need.

Parameters:
axis - the axis constant
Returns:
preferred size

getMinimumSpan

public float getMinimumSpan(int axis)
Returns the minimums span as calculated by the prelayout function

Parameters:
axis - the axis to get the size for
Returns:
the minimum span in PX

modelToView

public abstract java.awt.Shape modelToView(int pos,
                                           java.awt.Shape a,
                                           javax.swing.text.Position.Bias b)
                                    throws javax.swing.text.BadLocationException
Tries to find the rectangle representing a given model-position. The position will be searched top-down by querying ALL subviews and sub-floats of the current view. If there is no absolute match to a leaf-view, the nearest leaf-view(if any is in range) will be returned. Since views may overlap or may be floated this method may query all views!

Parameters:
pos - the model position to be found
a - the reference area for the search process, is supposed to be the surrounding rectangle of the current view
b - the search direction, empty interface implementation, has no effect
Returns:
the root-relative rectangle for the requested position or null
Throws:
javax.swing.text.BadLocationException - will be thrown if pos is outside the model's range

viewToModel

public abstract int viewToModel(float x,
                                float y,
                                java.awt.Shape a,
                                javax.swing.text.Position.Bias[] biasReturn)
Searches the view-tree for a specified point and returns the model-offset for this position.

Parameters:
x - root-relative X offset in pixel
y - root-relative Y offset in pixel
a - the bounds of the current view
biasReturn - the search direction, empty interface implementation, has no effect
Returns:
the model position for the requested point of -1 if no leaf view was found for this position

getChildAllocation

public void getChildAllocation(int i,
                               java.awt.Rectangle rect)
Stores the position of a child to rect. This position is relative to the current view

Parameters:
i - the number of the child to be found, MUST be >=0 and < getViewCount()
rect - the Rectangle-Object to store the childs position and size

getChildren

public java.util.List<Layout.PositionInfo> getChildren()
Returns the list of all children known to this layout object.
Note: This list is NOT a clone so don't modify it!

Returns:
list of all children known to this layout object

getViewCount

public int getViewCount()
Returns the number of child-views known to this layout object

Returns:
Returns the number of child-views known to this layout object

preLayout

public abstract void preLayout()
This method doe's the part of the layouting, which has to be called only once per website. It also calculates the width, which the elements would use if there's no absolute size. E.g. imagine floats without a give size. In that case the float will use the size of it's content or, if that size is smaller, the maximum width. NOTE: The implementation has to be deepth-first!!!


layout

public abstract java.awt.Rectangle layout(boolean hard)
This method will do the final layouting

Parameters:
hard - If set to true, the status of the children will be ignored and all views will be layouted. This should be done on view-size changes. If set to false the status of the children will be respected and up-to-date views will not be layouted again.
Returns:
the area which is affectd ba this view and any of it's siblings

layoutWidth

public abstract void layoutWidth()
Set the width of the layouted component. Is required by the Float managers to determine the position of their floats


replace

public static void replace(javax.swing.text.View oldView,
                           javax.swing.text.View[] newViews)
Replace the old view with a list of new views in the same container.

Parameters:
oldView - the old view
newViews - a list of new views

getChildPosition

public Layout.PositionInfo getChildPosition(BoxView childView)
Returns the layouted position information of a child of this layout

Parameters:
childView - child to find
Returns:
position information or null, if the child was found

getView

public BoxView getView()
Returns the view this layouter is responsible for

Returns:
the view this layouter is responsible for

getPreferredWidth

public int getPreferredWidth()
Get PreferredWidth set by preLayout

Returns:
PreferredWidth

getPreferredHeight

public int getPreferredHeight()
Get PreferredHeight set by preLayout

Returns:
PreferredHeight

getMinimumWidth

public int getMinimumWidth()
Get MinimumWidth set by preLayout

Returns:
MinimumWidth

getMinimumHeight

public int getMinimumHeight()
Get MinimumHeight set by preLayout

Returns:
MinimumHeight

getCurrentTop

public int getCurrentTop()
Returns the current y position of the top left corner

Returns:
the current y position of the top left corner

getCurrentLeft

public int getCurrentLeft()
Returns the current x position of the top left corner

Returns:
the current x position of the top left corner

getCurrentWidth

public int getCurrentWidth()
Returns the current width of the referenced view

Returns:
the current width of the referenced view

getCurrentHeight

public int getCurrentHeight()
Returns the current height of the referenced view

Returns:
the current height of the referenced view

isPreLayouted

public boolean isPreLayouted()
Returns true, if the view this layout is responsible for, has the PRE attribute

Returns:
true, if the view this layout is responsible for, has the PRE attribute

setPreLayouted

public void setPreLayouted()
Marks is layout as PRE


setCurrentHeight

public void setCurrentHeight(int currentHeight)
Sets the current content height for this box

Parameters:
currentHeight - he current content height for this box

setCurrentWidth

public void setCurrentWidth(int currentWidth)
Sets the current content width for this box

Parameters:
currentWidth - the current content width for this box

predictWidth

public abstract void predictWidth(int width)
Can be used to force a view to a specified width. This will ignore the minWidh!

Parameters:
width - Width to set

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

layoutVerticalAlign

public abstract void layoutVerticalAlign(int align,
                                         int baselineOffset)
This method performs the vertical alignment of the whole content within the box. It is supposed to be called after the layout was done and after the height has been set by CSS.

Parameters:
align - The AlignValue constant
baselineOffset - The difference between the contents top and the first baseline in pixel

getViewForPosition

public abstract ViewPositionInfo getViewForPosition(java.awt.Point position,
                                                    java.awt.Rectangle a)
Finds the view and it's location for a specific point of the screen

Parameters:
position - the location to search
a - the bounds of THIS view
Returns:
The bounds and view for the position

getSpan

public abstract java.awt.Rectangle getSpan()
Returns the area affected by the current layout or any of it's siblings, relative the it's own left upper corner.
NOTE: For performance reasons the returned object is not cloned, it should not be modified!

Returns:
the area affected by the current layout or any of it's siblings

union

public static void union(java.awt.Rectangle union,
                         java.awt.Rectangle join)
Creates a union of the two rects.
NOTE: the width of both rectangles must be positive!

Parameters:
union - a rectangle, will be modified
join - a rectangle o join to the first one

union

public static void union(java.awt.Rectangle union,
                         int x,
                         int y,
                         int width,
                         int height)
Creates a union of the two rects without the requirement for another rectangle object
NOTE: the width of both rectangles must be positive!

Parameters:
union - a rectangle, will be modified
x - the x offset of the other rectangle
y - the y offset of the other rectangle
width - the width of the other rectangle
height - the height of the other rectangle

offsetRelative

public static void offsetRelative(Layout.ViewPosition info)
Applies the relative position offset to a view

Parameters:
info - the position info to be modified