javax.swing.text

Class FlowView

public abstract class FlowView extends BoxView

A View that can flows it's children into it's layout space. The FlowView manages a set of logical views (that are the children of the {@link #layoutPool} field). These are translated at layout time into a set of physical views. These are the views that are managed as the real child views. Each of these child views represents a row and are laid out within a box using the superclasses behaviour. The concrete implementation of the rows must be provided by subclasses.
Nested Class Summary
static classFlowView.FlowStrategy
A strategy for translating the logical views of a FlowView into the real views.
Field Summary
protected ViewlayoutPool
Represents the logical child elements of this view, encapsulated within one parent view (an instance of a package private LogicalView class).
protected intlayoutSpan
The span of the FlowView that should be flowed.
protected FlowView.FlowStrategystrategy
The FlowStrategy to use for translating between the logical and physical view.
Constructor Summary
FlowView(Element element, int axis)
Creates a new FlowView for the given Element and axis.
Method Summary
protected SizeRequirementscalculateMinorAxisRequirements(int axis, SizeRequirements r)
Calculates the size requirements of this BoxView along its minor axis, that is the axis opposite to the axis specified in the constructor.
voidchangedUpdate(DocumentEvent changes, Shape a, ViewFactory vf)
Receice notification that some attributes changed in the region that this view is responsible for.
protected abstract ViewcreateRow()
Creates a new view that represents a row within a flow.
intgetFlowAxis()
Returns the axis along which the view should be flowed.
intgetFlowSpan(int index)
Returns the span of the flow for the specified child view.
intgetFlowStart(int index)
Returns the location along the flow axis where the flow span starts given a child view index.
protected intgetViewIndexAtPosition(int pos)
Returns the index of the child View for the given model position.
voidinsertUpdate(DocumentEvent changes, Shape a, ViewFactory vf)
Receice notification that some content has been inserted in the region that this view is responsible for.
protected voidlayout(int width, int height)
Performs the layout of this view.
protected voidloadChildren(ViewFactory vf)
Loads the children of this view.
voidremoveUpdate(DocumentEvent changes, Shape a, ViewFactory vf)
Receice notification that some content has been removed from the region that this view is responsible for.

Field Detail

layoutPool

protected View layoutPool
Represents the logical child elements of this view, encapsulated within one parent view (an instance of a package private LogicalView class). These will be translated to a set of real views that are then displayed on screen. This translation is performed by the inner class {@link FlowStrategy}.

layoutSpan

protected int layoutSpan
The span of the FlowView that should be flowed.

strategy

protected FlowView.FlowStrategy strategy
The FlowStrategy to use for translating between the logical and physical view.

Constructor Detail

FlowView

public FlowView(Element element, int axis)
Creates a new FlowView for the given Element and axis.

Parameters: element the element that is rendered by this FlowView axis the axis along which the view is tiled, either View.X_AXIS or View.Y_AXIS, the flow axis is orthogonal to this one

Method Detail

calculateMinorAxisRequirements

protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r)
Calculates the size requirements of this BoxView along its minor axis, that is the axis opposite to the axis specified in the constructor. This is overridden and forwards the request to the logical view.

Parameters: axis the axis that is examined r the SizeRequirements object to hold the result, if null, a new one is created

Returns: the size requirements for this BoxView along the specified axis

changedUpdate

public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory vf)
Receice notification that some attributes changed in the region that this view is responsible for. This calls {@link FlowStrategy#changedUpdate}.

Parameters: changes the document event describing the changes a the current allocation of the view vf the view factory that is used for creating new child views

createRow

protected abstract View createRow()
Creates a new view that represents a row within a flow.

Returns: a view for a new row

getFlowAxis

public int getFlowAxis()
Returns the axis along which the view should be flowed. This is orthogonal to the axis along which the boxes are tiled.

Returns: the axis along which the view should be flowed

getFlowSpan

public int getFlowSpan(int index)
Returns the span of the flow for the specified child view. A flow layout can be shaped by providing different span values for different child indices. The default implementation returns the entire available span inside the view.

Parameters: index the index of the child for which to return the span

Returns: the span of the flow for the specified child view

getFlowStart

public int getFlowStart(int index)
Returns the location along the flow axis where the flow span starts given a child view index. The flow can be shaped by providing different values here.

Parameters: index the index of the child for which to return the flow location

Returns: the location along the flow axis where the flow span starts

getViewIndexAtPosition

protected int getViewIndexAtPosition(int pos)
Returns the index of the child View for the given model position. This is implemented to iterate over the children of this view (the rows) and return the index of the first view that contains the given position.

Parameters: pos the model position for whicht the child View is queried

Returns: the index of the child View for the given model position

insertUpdate

public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory vf)
Receice notification that some content has been inserted in the region that this view is responsible for. This calls {@link FlowStrategy#insertUpdate}.

Parameters: changes the document event describing the changes a the current allocation of the view vf the view factory that is used for creating new child views

layout

protected void layout(int width, int height)
Performs the layout of this view. If the span along the flow axis changed, this first calls {@link FlowStrategy#layout} in order to rebuild the rows of this view. Then the superclass's behaviour is called to arrange the rows within the box.

Parameters: width the width of the view height the height of the view

loadChildren

protected void loadChildren(ViewFactory vf)
Loads the children of this view. The FlowView does not directly load its children. Instead it creates a logical view ({@link #layoutPool}) which is filled by the logical child views. The real children are created at layout time and each represent one row. This method is called by {@link View#setParent} in order to initialize the view.

Parameters: vf the view factory to use for creating the child views

removeUpdate

public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory vf)
Receice notification that some content has been removed from the region that this view is responsible for. This calls {@link FlowStrategy#removeUpdate}.

Parameters: changes the document event describing the changes a the current allocation of the view vf the view factory that is used for creating new child views