javax.swing.text

Class FlowView.FlowStrategy

public static class FlowView.FlowStrategy extends Object

A strategy for translating the logical views of a FlowView into the real views.
Constructor Summary
FlowStrategy()
Creates a new instance of FlowStragegy.
Method Summary
protected voidadjustRow(FlowView fv, int rowIndex, int desiredSpan, int x)
Tries to adjust the specified row to fit within the desired span.
voidchangedUpdate(FlowView fv, DocumentEvent e, Rectangle alloc)
Receives notification from a FlowView that some attributes have changed in the document at a location that the FlowView is responsible for.
protected ViewcreateView(FlowView fv, int startOffset, int spanLeft, int rowIndex)
Creates physical views that form the rows of the flow view.
protected ViewgetLogicalView(FlowView fv)
Returns the logical view of the managed FlowView.
voidinsertUpdate(FlowView fv, DocumentEvent e, Rectangle alloc)
Receives notification from a FlowView that some content has been inserted into the document at a location that the FlowView is responsible for.
voidlayout(FlowView fv)
Performs the layout for the whole view.
protected intlayoutRow(FlowView fv, int rowIndex, int pos)
Lays out one row of the flow view.
voidremoveUpdate(FlowView fv, DocumentEvent e, Rectangle alloc)
Receives notification from a FlowView that some content has been removed from the document at a location that the FlowView is responsible for.

Constructor Detail

FlowStrategy

public FlowStrategy()
Creates a new instance of FlowStragegy.

Method Detail

adjustRow

protected void adjustRow(FlowView fv, int rowIndex, int desiredSpan, int x)
Tries to adjust the specified row to fit within the desired span. The default implementation iterates through the children of the specified row to find the view that has the highest break weight and - if there is more than one view with such a break weight - which is nearest to the end of the row. If there is such a view that has a break weight > {@link View#BadBreakWeight}, this view is broken using the {@link View#breakView(int, int, float, float)} method and this view and all views after the now broken view are replaced by the broken view.

Parameters: fv the flow view rowIndex the index of the row to be adjusted desiredSpan the layout span x the X location at which the row starts

changedUpdate

public void changedUpdate(FlowView fv, DocumentEvent e, Rectangle alloc)
Receives notification from a FlowView that some attributes have changed in the document at a location that the FlowView is responsible for. The default implementation simply calls {@link #layout}.

Parameters: fv the flow view that sends the notification e the document event describing the change alloc the current allocation of the flow view

createView

protected View createView(FlowView fv, int startOffset, int spanLeft, int rowIndex)
Creates physical views that form the rows of the flow view. This can be an entire view from the logical view (if it fits within the available span), a fragment of such a view (if it doesn't fit in the available span and can be broken down) or null (if it does not fit in the available span and also cannot be broken down). The default implementation fetches the logical view at the specified startOffset. If that view has a different startOffset than specified in the argument, a fragment is created using {@link View#createFragment(int, int)} that has the correct startOffset and the logical view's endOffset.

Parameters: fv the flow view startOffset the start offset for the view to be created spanLeft the available span rowIndex the index of the row

Returns: a view to fill the row with, or null if there is no view or view fragment that fits in the available span

getLogicalView

protected View getLogicalView(FlowView fv)
Returns the logical view of the managed FlowView.

Parameters: fv the flow view for which to return the logical view

Returns: the logical view of the managed FlowView

insertUpdate

public void insertUpdate(FlowView fv, DocumentEvent e, Rectangle alloc)
Receives notification from a FlowView that some content has been inserted into the document at a location that the FlowView is responsible for. The default implementation simply calls {@link #layout}.

Parameters: fv the flow view that sends the notification e the document event describing the change alloc the current allocation of the flow view

layout

public void layout(FlowView fv)
Performs the layout for the whole view. By default this rebuilds all the physical views from the logical views of the managed FlowView. This is called by {@link FlowView#layout} to update the layout of the view.

Parameters: fv the flow view for which we perform the layout

layoutRow

protected int layoutRow(FlowView fv, int rowIndex, int pos)
Lays out one row of the flow view. This is called by {@link #layout} to fill one row with child views until the available span is exhausted. The default implementation fills the row by calling {@link #createView(FlowView, int, int, int)} until the available space is exhausted, a forced break is encountered or there are no more views in the logical view. If the available space is exhausted, {@link #adjustRow(FlowView, int, int, int)} is called to fit the row into the available span.

Parameters: fv the flow view for which we perform the layout rowIndex the index of the row pos the model position for the beginning of the row

Returns: the start position of the next row

removeUpdate

public void removeUpdate(FlowView fv, DocumentEvent e, Rectangle alloc)
Receives notification from a FlowView that some content has been removed from the document at a location that the FlowView is responsible for. The default implementation simply calls {@link #layout}.

Parameters: fv the flow view that sends the notification e the document event describing the change alloc the current allocation of the flow view