javax.swing.text

Class CompositeView

public abstract class CompositeView extends View

An abstract base implementation of {@link View} that manages child Views.
Constructor Summary
CompositeView(Element element)
Creates a new CompositeView for the given Element.
Method Summary
protected abstract voidchildAllocation(int index, Rectangle a)
Computes the allocation for a child View.
protected booleanflipEastAndWestAtEnds(int pos, Position.Bias bias)
Determines if the next view in horinzontal direction is located to the east or west of the view at position pos.
protected shortgetBottomInset()
Returns the bottom inset of this CompositeView.
ShapegetChildAllocation(int index, Shape a)
Returns the allocation for the specified child View.
protected RectanglegetInsideAllocation(Shape a)
Returns the allocation that is given to this CompositeView minus this CompositeView's insets.
protected shortgetLeftInset()
Returns the left inset of this CompositeView.
protected intgetNextEastWestVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
Returns the next model location that is visible in east or west direction.
protected intgetNextNorthSouthVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
Returns the next model location that is visible in north or south direction.
intgetNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
Returns the next model location that is visible in eiter north / south direction or east / west direction.
protected shortgetRightInset()
Returns the right inset of this CompositeView.
protected shortgetTopInset()
Returns the top inset of this CompositeView.
ViewgetView(int n)
Returns the child view at index n.
protected abstract ViewgetViewAtPoint(int x, int y, Rectangle r)
Returns the child View at the specified location.
protected ViewgetViewAtPosition(int pos, Rectangle a)
Returns the child View that contains the given model position.
intgetViewCount()
Returns the number of child views.
intgetViewIndex(int pos, Position.Bias b)
Returns the index of the child view that represents the specified model location.
protected intgetViewIndexAtPosition(int pos)
Returns the index of the child View for the given model position.
protected abstract booleanisAfter(int x, int y, Rectangle r)
Returns true if the specified point lies after the given Rectangle, false otherwise.
protected abstract booleanisBefore(int x, int y, Rectangle r)
Returns true if the specified point lies before the given Rectangle, false otherwise.
protected voidloadChildren(ViewFactory f)
Loads the child views of this CompositeView.
ShapemodelToView(int pos, Shape a, Position.Bias bias)
Maps a position in the document into the coordinate space of the View.
ShapemodelToView(int p1, Position.Bias b1, int p2, Position.Bias b2, Shape a)
Maps a region in the document into the coordinate space of the View.
voidreplace(int offset, int length, View[] views)
Replaces child views by some other child views.
protected voidsetInsets(short t, short l, short b, short r)
Sets the insets of this CompositeView.
protected voidsetParagraphInsets(AttributeSet attributes)
Sets the insets defined by attributes in attributes.
voidsetParent(View parent)
Sets the parent of this View.
intviewToModel(float x, float y, Shape a, Position.Bias[] b)
Maps coordinates from the View's space into a position in the document model.

Constructor Detail

CompositeView

public CompositeView(Element element)
Creates a new CompositeView for the given Element.

Parameters: element the element that is rendered by this CompositeView

Method Detail

childAllocation

protected abstract void childAllocation(int index, Rectangle a)
Computes the allocation for a child View. The parameter a stores the allocation of this CompositeView and is then adjusted to hold the allocation of the child view.

Parameters: index the index of the child View a the allocation of this CompositeView before the call, the allocation of the child on exit

flipEastAndWestAtEnds

protected boolean flipEastAndWestAtEnds(int pos, Position.Bias bias)
Determines if the next view in horinzontal direction is located to the east or west of the view at position pos. Usually the Views are laid out from the east to the west, so we unconditionally return false here. Subclasses that support bidirectional text may wish to override this method.

Parameters: pos the position in the document bias the bias to be applied to pos

Returns: true if the next View is located to the EAST, false otherwise

getBottomInset

protected short getBottomInset()
Returns the bottom inset of this CompositeView.

Returns: the bottom inset of this CompositeView

getChildAllocation

public Shape getChildAllocation(int index, Shape a)
Returns the allocation for the specified child View.

Parameters: index the index of the child view a the allocation for this view

Returns: the allocation for the specified child View

getInsideAllocation

protected Rectangle getInsideAllocation(Shape a)
Returns the allocation that is given to this CompositeView minus this CompositeView's insets. Also this translates from an immutable allocation to a mutable allocation that is typically reused and further narrowed, like in {@link #childAllocation}.

Parameters: a the allocation given to this CompositeView

Returns: the allocation that is given to this CompositeView minus this CompositeView's insets or null if a was null

getLeftInset

protected short getLeftInset()
Returns the left inset of this CompositeView.

Returns: the left inset of this CompositeView

getNextEastWestVisualPositionFrom

protected int getNextEastWestVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
Returns the next model location that is visible in east or west direction. This is used to determine the placement of the caret when navigating around the document with the arrow keys.

Parameters: pos the model position to start search from b the bias for pos a the allocated region for this view direction the direction from the current position, can be one of the following:

biasRet the bias of the return value gets stored here

Returns: the position inside the model that represents the next visual location

Throws: BadLocationException if pos is not a valid location inside the document model IllegalArgumentException if direction is invalid

getNextNorthSouthVisualPositionFrom

protected int getNextNorthSouthVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
Returns the next model location that is visible in north or south direction. This is used to determine the placement of the caret when navigating around the document with the arrow keys.

Parameters: pos the model position to start search from b the bias for pos a the allocated region for this view direction the direction from the current position, can be one of the following:

biasRet the bias of the return value gets stored here

Returns: the position inside the model that represents the next visual location

Throws: BadLocationException if pos is not a valid location inside the document model IllegalArgumentException if direction is invalid

getNextVisualPositionFrom

public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
Returns the next model location that is visible in eiter north / south direction or east / west direction. This is used to determine the placement of the caret when navigating around the document with the arrow keys. This is a convenience method for {@link #getNextNorthSouthVisualPositionFrom} and {@link #getNextEastWestVisualPositionFrom}.

Parameters: pos the model position to start search from b the bias for pos a the allocated region for this view direction the direction from the current position, can be one of the following:

biasRet the bias of the return value gets stored here

Returns: the position inside the model that represents the next visual location

Throws: BadLocationException if pos is not a valid location inside the document model IllegalArgumentException if direction is invalid

getRightInset

protected short getRightInset()
Returns the right inset of this CompositeView.

Returns: the right inset of this CompositeView

getTopInset

protected short getTopInset()
Returns the top inset of this CompositeView.

Returns: the top inset of this CompositeView

getView

public View getView(int n)
Returns the child view at index n.

Parameters: n the index of the requested child view

Returns: the child view at index n

getViewAtPoint

protected abstract View getViewAtPoint(int x, int y, Rectangle r)
Returns the child View at the specified location.

Parameters: x the X coordinate y the Y coordinate r the inner allocation of this BoxView on entry, the allocation of the found child on exit

Returns: the child View at the specified location

getViewAtPosition

protected View getViewAtPosition(int pos, Rectangle a)
Returns the child View that contains the given model position. The given Rectangle gives the parent's allocation and is changed to the child's allocation on exit.

Parameters: pos the model position to query the child View for a the parent allocation on entry and the child allocation on exit

Returns: the child view at the given model position

getViewCount

public int getViewCount()
Returns the number of child views.

Returns: the number of child views

getViewIndex

public int getViewIndex(int pos, Position.Bias b)
Returns the index of the child view that represents the specified model location.

Parameters: pos the model location for which to determine the child view index b the bias to be applied to pos

Returns: the index of the child view that represents the specified model location

getViewIndexAtPosition

protected int getViewIndexAtPosition(int pos)
Returns the index of the child View for the given model 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

isAfter

protected abstract boolean isAfter(int x, int y, Rectangle r)
Returns true if the specified point lies after the given Rectangle, false otherwise. "After" is typically defined as being to the right or below.

Parameters: x the X coordinate of the point y the Y coordinate of the point r the rectangle to test the point against

Returns: true if the specified point lies after the given Rectangle, false otherwise

isBefore

protected abstract boolean isBefore(int x, int y, Rectangle r)
Returns true if the specified point lies before the given Rectangle, false otherwise. "Before" is typically defined as being to the left or above.

Parameters: x the X coordinate of the point y the Y coordinate of the point r the rectangle to test the point against

Returns: true if the specified point lies before the given Rectangle, false otherwise

loadChildren

protected void loadChildren(ViewFactory f)
Loads the child views of this CompositeView. This method is called from {@link #setParent} to initialize the child views of this composite view.

Parameters: f the view factory to use for creating new child views

See Also: CompositeView

modelToView

public Shape modelToView(int pos, Shape a, Position.Bias bias)
Maps a position in the document into the coordinate space of the View. The output rectangle usually reflects the font height but has a width of zero.

Parameters: pos the position of the character in the model a the area that is occupied by the view bias either {@link Position.Bias#Forward} or {@link Position.Bias#Backward} depending on the preferred direction bias. If null this defaults to Position.Bias.Forward

Returns: a rectangle that gives the location of the document position inside the view coordinate space

Throws: BadLocationException if pos is invalid IllegalArgumentException if b is not one of the above listed valid values

modelToView

public Shape modelToView(int p1, Position.Bias b1, int p2, Position.Bias b2, Shape a)
Maps a region in the document into the coordinate space of the View.

Parameters: p1 the beginning position inside the document b1 the direction bias for the beginning position p2 the end position inside the document b2 the direction bias for the end position a the area that is occupied by the view

Returns: a rectangle that gives the span of the document region inside the view coordinate space

Throws: BadLocationException if p1 or p2 are invalid IllegalArgumentException if b1 or b2 is not one of the above listed valid values

replace

public void replace(int offset, int length, View[] views)
Replaces child views by some other child views. If there are no views to remove (length == 0), the result is a simple insert, if there are no children to add (view == null) the result is a simple removal.

Parameters: offset the start offset from where to remove children length the number of children to remove views the views that replace the removed children

setInsets

protected void setInsets(short t, short l, short b, short r)
Sets the insets of this CompositeView.

Parameters: t the top inset l the left inset b the bottom inset r the right inset

setParagraphInsets

protected void setParagraphInsets(AttributeSet attributes)
Sets the insets defined by attributes in attributes. This queries the attribute keys {@link StyleConstants#SpaceAbove}, {@link StyleConstants#SpaceBelow}, {@link StyleConstants#LeftIndent} and {@link StyleConstants#RightIndent} and calls {@link #setInsets} to actually set the insets on this CompositeView.

Parameters: attributes the attributes from which to query the insets

setParent

public void setParent(View parent)
Sets the parent of this View. In addition to setting the parent, this calls {@link #loadChildren}, if this View does not already have its children initialized.

Parameters: parent the parent to set

viewToModel

public int viewToModel(float x, float y, Shape a, Position.Bias[] b)
Maps coordinates from the View's space into a position in the document model.

Parameters: x the x coordinate in the view space, x >= 0 y the y coordinate in the view space, y >= 0 a the allocation of this View b the bias to use

Returns: the position in the document that corresponds to the screen coordinates x, y >= 0