javax.swing.text
Class TextLayoutStrategy

java.lang.Object
  |
  +--javax.swing.text.FlowView.FlowStrategy
        |
        +--javax.swing.text.TextLayoutStrategy

class TextLayoutStrategy
extends javax.swing.text.FlowView.FlowStrategy

A flow strategy that uses java.awt.font.LineBreakMeasureer to produce java.awt.font.TextLayout for i18n capable rendering. If the child view being placed into the flow is of type GlyphView and can be rendered by TextLayout, a GlyphPainter that uses TextLayout is plugged into the GlyphView.

Version:
1.17 12/03/01
Author:
Timothy Prinzing

Field Summary
private  java.awt.font.LineBreakMeasurer measurer
           
private  javax.swing.text.TextLayoutStrategy.AttributedSegment text
           
 
Constructor Summary
TextLayoutStrategy()
          Constructs a layout strategy for paragraphs based upon java.awt.font.LineBreakMeasurer.
 
Method Summary
protected  void adjustRow(FlowView fv, int rowIndex, int desiredSpan, int x)
          Adjusts the given row if possible to fit within the layout span.
 void changedUpdate(FlowView fv, DocumentEvent e, Rectangle alloc)
          Gives notification from the document that attributes were changed in a location that this view is responsible for.
protected  View createView(FlowView fv, int startOffset, int spanLeft, int rowIndex)
          Creates a unidirectional view that can be used to represent the current chunk.
(package private)  int getLimitingOffset(View v, int startOffset, int spanLeft, boolean requireNextWord)
          Calculate the limiting offset for the next view fragment.
 void insertUpdate(FlowView fv, DocumentEvent e, Rectangle alloc)
          Gives notification that something was inserted into the document in a location that the given flow view is responsible for.
 void layout(FlowView fv)
          Does a a full layout on the given View.
protected  int layoutRow(FlowView fv, int rowIndex, int p0)
          Creates a row of views that will fit within the layout span of the row.
 void removeUpdate(FlowView fv, DocumentEvent e, Rectangle alloc)
          Gives notification that something was removed from the document in a location that the given flow view is responsible for.
(package private)  void sync(FlowView fv)
          Synchronize the strategy with its FlowView.
 
Methods inherited from class javax.swing.text.FlowStrategy
getLogicalView
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

measurer

private java.awt.font.LineBreakMeasurer measurer

text

private javax.swing.text.TextLayoutStrategy.AttributedSegment text
Constructor Detail

TextLayoutStrategy

public TextLayoutStrategy()
Constructs a layout strategy for paragraphs based upon java.awt.font.LineBreakMeasurer.

Method Detail

insertUpdate

public void insertUpdate(FlowView fv,
                         DocumentEvent e,
                         Rectangle alloc)
Gives notification that something was inserted into the document in a location that the given flow view is responsible for. The strategy should update the appropriate changed region (which depends upon the strategy used for repair).

Overrides:
insertUpdate in class javax.swing.text.FlowView.FlowStrategy
Parameters:
e - the change information from the associated document
alloc - the current allocation of the view inside of the insets. This value will be null if the view has not yet been displayed.
See Also:
View.insertUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)

removeUpdate

public void removeUpdate(FlowView fv,
                         DocumentEvent e,
                         Rectangle alloc)
Gives notification that something was removed from the document in a location that the given flow view is responsible for.

Overrides:
removeUpdate in class javax.swing.text.FlowView.FlowStrategy
Parameters:
e - the change information from the associated document
alloc - the current allocation of the view inside of the insets.
See Also:
View.removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)

changedUpdate

public void changedUpdate(FlowView fv,
                          DocumentEvent e,
                          Rectangle alloc)
Gives notification from the document that attributes were changed in a location that this view is responsible for.

Overrides:
changedUpdate in class javax.swing.text.FlowView.FlowStrategy
See Also:
View.changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)

layout

public void layout(FlowView fv)
Does a a full layout on the given View. This causes all of the rows (child views) to be rebuilt to match the given constraints for each row. This is called by a FlowView.layout to update the child views in the flow.

Overrides:
layout in class javax.swing.text.FlowView.FlowStrategy

layoutRow

protected int layoutRow(FlowView fv,
                        int rowIndex,
                        int p0)
Creates a row of views that will fit within the layout span of the row. This is implemented to execute the superclass functionality (which fills the row with child views or view fragments) and follow that with bidi reordering of the unidirectional view fragments.

Overrides:
layoutRow in class javax.swing.text.FlowView.FlowStrategy
Parameters:
rowIndex - the index of the row to fill in with views. The row is assumed to be empty on entry.
p0 - The current position in the children of this views element from which to start.
Returns:
the position to start the next row

adjustRow

protected void adjustRow(FlowView fv,
                         int rowIndex,
                         int desiredSpan,
                         int x)
Adjusts the given row if possible to fit within the layout span. Since all adjustments were already calculated by the LineBreakMeasurer, this is implemented to do nothing.

Overrides:
adjustRow in class javax.swing.text.FlowView.FlowStrategy
Parameters:
desiredSpan - the current layout span >= 0
x - the location r starts at.

createView

protected View createView(FlowView fv,
                          int startOffset,
                          int spanLeft,
                          int rowIndex)
Creates a unidirectional view that can be used to represent the current chunk. This can be either an entire view from the logical view, or a fragment of the view.

Overrides:
createView in class javax.swing.text.FlowView.FlowStrategy
Parameters:
fv - the view holding the flow
startOffset - the start location for the view being created
spanLeft - the about of span left to fill in the row
rowIndex - the row the view will be placed into

getLimitingOffset

int getLimitingOffset(View v,
                      int startOffset,
                      int spanLeft,
                      boolean requireNextWord)
Calculate the limiting offset for the next view fragment. At most this would be the entire view (i.e. the limiting offset would be the end offset in that case). If the range contains a tab or a direction change, that will limit the offset to something less. This value is then fed to the LineBreakMeasurer as a limit to consider in addition to the remaining span.

Parameters:
v - the logical view representing the starting offset.
startOffset - the model location to start at.

sync

void sync(FlowView fv)
Synchronize the strategy with its FlowView. Allows the strategy to update its state to account for changes in that portion of the model represented by the FlowView. Also allows the strategy to update the FlowView in response to these changes.



comments?