com.inet.html.views.layouts
Class StackManager

java.lang.Object
  extended by com.inet.html.views.layouts.StackManager

public class StackManager
extends java.lang.Object

This class gathers all informations about floats on a site. It helps to find wrapping edges and new line positions. Here's a list of rules, which have to be fulfilled by floats and flowing content. (This list is not equal to the spec, it's was generated by observing the Gecko 1.9 Behavior) - A flow-line will be terminated if it hits a float-right - A flow-line will start after a flow-left( except if there's an earlier flow-right, than it starts at the beginning of the box and ends at the flow-right) - All floats generated in a flow-line will be placed AFTER the end of this line(the end means: end of the box, flow-content on the next line, ...) --> A float cannot influence the content layouted before this float! - A higher position is better than a position more to the left or the the right - A float cannot be placed higher than any float generated before - Absolute- or Float-Blocks are the root for their inner floats! - if the parent has no size yet, all sub-floats are layouted like inline-blocks and taken out of the flow after any boundary is reached(this case is really hard to control) - if there is any limit given by the parent the floats try to limit ther width to this size What this Class needs to place a new line: - current box position and width - minimum y to start searching - minimum width to place the content(there's no sense in placing a new line which is to small to hold content) When to notify this class(add floats an start placing them)? - Generating a new float - Starting a box - Start of a new line When to query this class(get lines respecting the floats)? - Start of a new line - Adding content which changes the baseline/height of a line Remember: Floats are boxes with a predefined Width. They do not belong to the text flow but will influence it. Float-positions are unique among it's absolute parent's space. Floats can never overlap except by using negative margins!


Nested Class Summary
static class StackManager.LineSpaceInfo
          The LineSpaceInfo contains all informations, which are required to place a new line or a snippet of content.
 
Field Summary
static byte CLEAR_BOTH
          Request the StackManager to fetch the top-most position for the current element, where is no float on either side
static byte CLEAR_LEFT
          Request the StackManager to fetch the top-most position for the current element, where is no float to the left
static byte CLEAR_NONE
          Request the StackManager to fetch the top-most position for the current element
static byte CLEAR_RIGHT
          Request the StackManager to fetch the top-most position for the current element, where is no float to the rigth
static int MODE_ALL_NON_NEGATIVE
          internal mode to iterate over all elements in this stack manager
static int MODE_FLOATING
          Constant to address all floats and absolute positioned views with auto z-index
static int MODE_NEGATIVE
          Constant to address all absolute positioned views with negative z-index
static int MODE_NEUTRAL
          Constant to address all absolute positioned views unset z-index, ignored on paint, used on getSpan
static int MODE_POSITIVE
          Constant to address all absolute positioned views with positive z-index
 
Constructor Summary
StackManager(BoxView root)
          Creates a float manager bound to a root block element
 
Method Summary
 void addView(BoxView box, BlockView outerBox, int topY)
          Adds a new float
 void addView(BoxView box, BlockView outerBox, int x, int y)
          Adds a position relative.
 void clear()
          Removes all known float informations
 void clearMyFloats(BoxView parent)
          Removes all floats with parent set as their parent.
 StackManager.LineSpaceInfo findClearSpace(java.awt.Rectangle minRequired, java.awt.Rectangle bounds, int clear, int textAlign)
          Tries to find a position, where there is enough room to place the content.
 StackManager.LineSpaceInfo findLineSpace(java.awt.Rectangle minRequired, java.awt.Rectangle bounds, int clear, int textAlign)
          Tries to find a position, where there is enough room to place the content.
 int getAvailableVSpace(int y, int leftX, int rightX)
          Returns the available vertical space within the selected bounds
 int getBottomPosition(BlockView parent)
          The difference between the top of the root-View and the bottom of the lowest float in pixel.
 com.inet.html.views.layouts.StackManager.PositionInfo getNextFloatBelow(int y, int leftX, int rightX, boolean typeleft)
          Tries to find the next lower float of the requested type
 java.awt.Point getPositionInfo(BoxView child)
          Tries to find the location information about a child.
 java.awt.Rectangle getSpan()
          Returns the maximum span in positive direction of the floats handled by this manager
 java.awt.Rectangle getSpan(int mode)
          Returns the span of a stack group
 ViewPositionInfo getViewForPosition(java.awt.Point position, java.awt.Rectangle a, int mode)
          Finds the view and it's location for a specific point of the screen
 boolean hasViews()
          Returns the number of floats currently managed by this instance
 java.awt.Shape modelToView(int pos, java.awt.Shape a, javax.swing.text.Position.Bias b, int mode)
          Tries to resolve a model offset to a screen location
 void notifyBlockFinished(boolean hard)
          Notifies the manager, that the containing block, which holds this manager, has finished layouting.
 void notifyNewLine(float topY)
          placed the recently added floats
 void paint(java.awt.Graphics g, java.awt.Shape allocation, int mode)
          Paint the Blocks of this manager
 int viewToModel(float x, float y, java.awt.Shape a, javax.swing.text.Position.Bias[] biasReturn, int mode)
          Tries to resolve a position to a model offset
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

CLEAR_NONE

public static final byte CLEAR_NONE
Request the StackManager to fetch the top-most position for the current element

See Also:
Constant Field Values

CLEAR_LEFT

public static final byte CLEAR_LEFT
Request the StackManager to fetch the top-most position for the current element, where is no float to the left

See Also:
Constant Field Values

CLEAR_RIGHT

public static final byte CLEAR_RIGHT
Request the StackManager to fetch the top-most position for the current element, where is no float to the rigth

See Also:
Constant Field Values

CLEAR_BOTH

public static final byte CLEAR_BOTH
Request the StackManager to fetch the top-most position for the current element, where is no float on either side

See Also:
Constant Field Values

MODE_NEGATIVE

public static final int MODE_NEGATIVE
Constant to address all absolute positioned views with negative z-index

See Also:
Constant Field Values

MODE_FLOATING

public static final int MODE_FLOATING
Constant to address all floats and absolute positioned views with auto z-index

See Also:
Constant Field Values

MODE_NEUTRAL

public static final int MODE_NEUTRAL
Constant to address all absolute positioned views unset z-index, ignored on paint, used on getSpan

See Also:
Constant Field Values

MODE_POSITIVE

public static final int MODE_POSITIVE
Constant to address all absolute positioned views with positive z-index

See Also:
Constant Field Values

MODE_ALL_NON_NEGATIVE

public static final int MODE_ALL_NON_NEGATIVE
internal mode to iterate over all elements in this stack manager

See Also:
Constant Field Values
Constructor Detail

StackManager

public StackManager(BoxView root)
Creates a float manager bound to a root block element

Parameters:
root - the root block element
Method Detail

getPositionInfo

public java.awt.Point getPositionInfo(BoxView child)
Tries to find the location information about a child.

Parameters:
child - the child to search for
Returns:
the location information or null

addView

public void addView(BoxView box,
                    BlockView outerBox,
                    int topY)
Adds a new float

Parameters:
box - new floating box
outerBox - parent of this float
topY - the highest position this float may have

addView

public void addView(BoxView box,
                    BlockView outerBox,
                    int x,
                    int y)
Adds a position relative. Required to handle the paint order correctly

Parameters:
box - new floating box
outerBox - parent of this float
x - the layouted position of the element
y - the layouted position of the element

paint

public void paint(java.awt.Graphics g,
                  java.awt.Shape allocation,
                  int mode)
Paint the Blocks of this manager

Parameters:
g - the graphics to pain to
allocation - the location to draw at
mode - the part of the views, which have to be painted
See Also:
MODE_NEGATIVE, MODE_FLOATING, MODE_POSITIVE

viewToModel

public int viewToModel(float x,
                       float y,
                       java.awt.Shape a,
                       javax.swing.text.Position.Bias[] biasReturn,
                       int mode)
Tries to resolve a position to a model offset

Parameters:
x - the x coordinate
y - the y coordinate
a - the shape to search in
biasReturn - the direction of the returned offset
mode - the mode constant to address a certain stack group
Returns:
the model offset
See Also:
MODE_NEGATIVE, MODE_FLOATING, MODE_NEUTRAL, MODE_POSITIVE

modelToView

public java.awt.Shape modelToView(int pos,
                                  java.awt.Shape a,
                                  javax.swing.text.Position.Bias b,
                                  int mode)
                           throws javax.swing.text.BadLocationException
Tries to resolve a model offset to a screen location

Parameters:
pos - the model offset
a - the shape to place the location into
b - the caret direction
mode - the mode constant to address a certain stack group
Returns:
the bounds of the box at this offset or null
Throws:
javax.swing.text.BadLocationException - thrown if there are model errors
See Also:
MODE_NEGATIVE, MODE_FLOATING, MODE_NEUTRAL, MODE_POSITIVE

getNextFloatBelow

public com.inet.html.views.layouts.StackManager.PositionInfo getNextFloatBelow(int y,
                                                                               int leftX,
                                                                               int rightX,
                                                                               boolean typeleft)
Tries to find the next lower float of the requested type

Parameters:
y - Y index to start from
leftX - Left border of the space to search
rightX - Right border of the space to search
typeleft - true if searching for left-floats, false otherwise
Returns:
The requested float or null if none was found

getAvailableVSpace

public int getAvailableVSpace(int y,
                              int leftX,
                              int rightX)
Returns the available vertical space within the selected bounds

Parameters:
y - Y index to start from
leftX - left bound
rightX - right bound
Returns:
the available height, may be MAX_INT

findLineSpace

public StackManager.LineSpaceInfo findLineSpace(java.awt.Rectangle minRequired,
                                                java.awt.Rectangle bounds,
                                                int clear,
                                                int textAlign)
Tries to find a position, where there is enough room to place the content. This method searches top-down and returns the first possibile position for the content.

Parameters:
minRequired - The minimum of required space to place the content
bounds - Maximum ABSOULTE bounds to place the content. The height will be ignored, it's up to the layout to deal with heights beyond its box. The upper bound has to be the top
clear - The clear attribute of the requesting element
textAlign - The text-align attribute of the requesting element
Returns:
LineSpaceInfo with the required information to place the content

findClearSpace

public StackManager.LineSpaceInfo findClearSpace(java.awt.Rectangle minRequired,
                                                 java.awt.Rectangle bounds,
                                                 int clear,
                                                 int textAlign)
Tries to find a position, where there is enough room to place the content. This method searches top-down and returns the first possibile position for the content.

Parameters:
minRequired - The minimum of required space to place the content
bounds - Maximum ABSOULTE bounds to place the content. The height will be ignored, it's up to the layout to deal with heights beyond its box. The upper bound has to be the top
clear - The clear attribute of the requesting element
textAlign - The text-align attribute of the requesting element
Returns:
LineSpaceInfo with the required information to place the content

notifyNewLine

public void notifyNewLine(float topY)
placed the recently added floats

Parameters:
topY - The highest position possible for the recently added floats

getBottomPosition

public int getBottomPosition(BlockView parent)
The difference between the top of the root-View and the bottom of the lowest float in pixel. Only direct children of the parent will be relevant in this search!

Parameters:
parent - The parent view
Returns:
Number of pixel or 0 if no float has been placed

clear

public void clear()
Removes all known float informations


clearMyFloats

public void clearMyFloats(BoxView parent)
Removes all floats with parent set as their parent.

Parameters:
parent - the parent

hasViews

public boolean hasViews()
Returns the number of floats currently managed by this instance

Returns:
number of floats

getViewForPosition

public ViewPositionInfo getViewForPosition(java.awt.Point position,
                                           java.awt.Rectangle a,
                                           int mode)
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
mode - the part of the views, which have to be painted
Returns:
The bounds and view for the position
See Also:
MODE_NEGATIVE, MODE_FLOATING, MODE_POSITIVE, MODE_ALL_NON_NEGATIVE

getSpan

public java.awt.Rectangle getSpan()
Returns the maximum span in positive direction of the floats handled by this manager

Returns:
the maximum span in positive direction of the floats handled by this manager

notifyBlockFinished

public void notifyBlockFinished(boolean hard)
Notifies the manager, that the containing block, which holds this manager, has finished layouting. This requests the manager to place all recent positioned elements

Parameters:
hard - set to true, if the status of the childviews should be overridden, and all children are requested to update their layout

getSpan

public java.awt.Rectangle getSpan(int mode)
Returns the span of a stack group

Parameters:
mode - the mode constant to address a certain stack group
Returns:
the span of the group, never null
See Also:
MODE_NEGATIVE, MODE_FLOATING, MODE_NEUTRAL, MODE_POSITIVE