Prev Class | Next Class | Frames | No Frames |
Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Object
javax.swing.text.View
javax.swing.text.CompositeView
public abstract class CompositeView
extends View
View
that manages child
View
s.
Field Summary |
Fields inherited from class javax.swing.text.View | |
BadBreakWeight , ExcellentBreakWeight , ForcedBreakWeight , GoodBreakWeight , X_AXIS , Y_AXIS |
Fields inherited from interface javax.swing.SwingConstants | |
BOTTOM , CENTER , EAST , HORIZONTAL , LEADING , LEFT , NEXT , NORTH , NORTH_EAST , NORTH_WEST , PREVIOUS , RIGHT , SOUTH , SOUTH_EAST , SOUTH_WEST , TOP , TRAILING , VERTICAL , WEST |
Constructor Summary | |
|
Method Summary | |
protected abstract void |
|
protected boolean |
|
protected short |
|
Shape |
|
protected Rectangle |
|
protected short |
|
protected int |
|
protected int |
|
int |
|
protected short |
|
protected short |
|
View |
|
protected abstract View |
|
protected View |
|
int |
|
int |
|
protected int |
|
protected abstract boolean | |
protected abstract boolean | |
protected void |
|
Shape |
|
Shape |
|
void | |
protected void |
|
protected void |
|
void | |
int |
|
Methods inherited from class java.lang.Object | |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
public CompositeView(Element element)
Creates a newCompositeView
for the givenElement
.
- Parameters:
element
- the element that is rendered by this CompositeView
protected abstract void childAllocation(int index, Rectangle a)
Computes the allocation for a childView
. The parametera
stores the allocation of thisCompositeView
and is then adjusted to hold the allocation of the child view.
- Parameters:
index
- the index of the childView
a
- the allocation of thisCompositeView
before the call, the allocation of the child on exit
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 positionpos
. Usually theView
s are laid out from the east to the west, so we unconditionally returnfalse
here. Subclasses that support bidirectional text may wish to override this method.
- Parameters:
pos
- the position in the documentbias
- the bias to be applied topos
- Returns:
true
if the nextView
is located to the EAST,false
otherwise
protected short getBottomInset()
Returns the bottom inset of thisCompositeView
.
- Returns:
- the bottom inset of this
CompositeView
public Shape getChildAllocation(int index, Shape a)
Returns the allocation for the specified childView
.
- Overrides:
- getChildAllocation in interface View
- Parameters:
index
- the index of the child viewa
- the allocation for this view
- Returns:
- the allocation for the specified child
View
protected Rectangle getInsideAllocation(Shape a)
Returns the allocation that is given to thisCompositeView
minus thisCompositeView
's insets. Also this translates from an immutable allocation to a mutable allocation that is typically reused and further narrowed, like inchildAllocation(int,Rectangle)
.
- Parameters:
a
- the allocation given to thisCompositeView
- Returns:
- the allocation that is given to this
CompositeView
minus thisCompositeView
's insets ornull
if a wasnull
protected short getLeftInset()
Returns the left inset of thisCompositeView
.
- Returns:
- the left inset of this
CompositeView
protected int getNextEastWestVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationException
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 fromb
- the bias forpos
a
- the allocated region for this viewdirection
- 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
- ifpos
is not a valid location inside the document modelIllegalArgumentException
- ifdirection
is invalid
protected int getNextNorthSouthVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationException
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 fromb
- the bias forpos
a
- the allocated region for this viewdirection
- 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
- ifpos
is not a valid location inside the document modelIllegalArgumentException
- ifdirection
is invalid
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationException
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 forgetNextNorthSouthVisualPositionFrom(int,Position.Bias,Shape,int,Position.Bias[])
andgetNextEastWestVisualPositionFrom(int,Position.Bias,Shape,int,Position.Bias[])
.
- Overrides:
- getNextVisualPositionFrom in interface View
- Parameters:
pos
- the model position to start search fromb
- the bias forpos
a
- the allocated region for this viewdirection
- 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
- ifpos
is not a valid location inside the document modelIllegalArgumentException
- ifdirection
is invalid
protected short getRightInset()
Returns the right inset of thisCompositeView
.
- Returns:
- the right inset of this
CompositeView
protected short getTopInset()
Returns the top inset of thisCompositeView
.
- Returns:
- the top inset of this
CompositeView
public View getView(int n)
Returns the child view at indexn
.
- Parameters:
n
- the index of the requested child view
- Returns:
- the child view at index
n
protected abstract View getViewAtPoint(int x, int y, Rectangle r)
Returns the childView
at the specified location.
- Parameters:
x
- the X coordinatey
- the Y coordinater
- the inner allocation of thisBoxView
on entry, the allocation of the found child on exit
- Returns:
- the child
View
at the specified location
protected View getViewAtPosition(int pos, Rectangle a)
Returns the childView
that contains the given model position. The givenRectangle
gives the parent's allocation and is changed to the child's allocation on exit.
- Parameters:
pos
- the model position to query the childView
fora
- the parent allocation on entry and the child allocation on exit
- Returns:
- the child view at the given model position
public int getViewCount()
Returns the number of child views.
- Overrides:
- getViewCount in interface View
- Returns:
- the number of child views
public int getViewIndex(int pos, Position.Bias b)
Returns the index of the child view that represents the specified model location.
- Overrides:
- getViewIndex in interface View
- Parameters:
pos
- the model location for which to determine the child view indexb
- the bias to be applied topos
- Returns:
- the index of the child view that represents the specified model location
protected int getViewIndexAtPosition(int pos)
Returns the index of the childView
for the given model position.
- Parameters:
pos
- the model position for whicht the childView
is queried
- Returns:
- the index of the child
View
for the given model position
protected abstract boolean isAfter(int x, int y, Rectangle r)
Returnstrue
if the specified point lies after the givenRectangle
,false
otherwise. "After" is typically defined as being to the right or below.
- Parameters:
x
- the X coordinate of the pointy
- the Y coordinate of the pointr
- the rectangle to test the point against
- Returns:
true
if the specified point lies after the givenRectangle
,false
otherwise
protected abstract boolean isBefore(int x, int y, Rectangle r)
Returnstrue
if the specified point lies before the givenRectangle
,false
otherwise. "Before" is typically defined as being to the left or above.
- Parameters:
x
- the X coordinate of the pointy
- the Y coordinate of the pointr
- the rectangle to test the point against
- Returns:
true
if the specified point lies before the givenRectangle
,false
otherwise
protected void loadChildren(ViewFactory f)
Loads the child views of thisCompositeView
. This method is called fromsetParent(View)
to initialize the child views of this composite view.
- Parameters:
f
- the view factory to use for creating new child views
- See Also:
setParent(View)
public Shape modelToView(int pos, Shape a, Position.Bias bias) throws BadLocationException
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.
- Overrides:
- modelToView in interface View
- Parameters:
pos
- the position of the character in the modela
- the area that is occupied by the viewbias
- eitherPosition.Bias.Forward
orPosition.Bias.Backward
depending on the preferred direction bias. Ifnull
this defaults toPosition.Bias.Forward
- Returns:
- a rectangle that gives the location of the document position inside the view coordinate space
- Throws:
BadLocationException
- ifpos
is invalidIllegalArgumentException
- if b is not one of the above listed valid values
public Shape modelToView(int p1, Position.Bias b1, int p2, Position.Bias b2, Shape a) throws BadLocationException
Maps a region in the document into the coordinate space of the View.
- Overrides:
- modelToView in interface View
- Parameters:
p1
- the beginning position inside the documentb1
- the direction bias for the beginning positionp2
- the end position inside the documentb2
- the direction bias for the end positiona
- 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
- ifp1
orp2
are invalidIllegalArgumentException
- if b1 or b2 is not one of the above listed valid values
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 childrenlength
- the number of children to removeviews
- the views that replace the removed children
protected void setInsets(short t, short l, short b, short r)
Sets the insets of thisCompositeView
.
- Parameters:
t
- the top insetl
- the left insetb
- the bottom insetr
- the right inset
protected void setParagraphInsets(AttributeSet attributes)
Sets the insets defined by attributes inattributes
. This queries the attribute keysStyleConstants.SpaceAbove
,StyleConstants.SpaceBelow
,StyleConstants.LeftIndent
andStyleConstants.RightIndent
and callssetInsets(short,short,short,short)
to actually set the insets on thisCompositeView
.
- Parameters:
attributes
- the attributes from which to query the insets
public void setParent(View parent)
Sets the parent of thisView
. In addition to setting the parent, this callsloadChildren(ViewFactory)
, if thisView
does not already have its children initialized.
- Parameters:
parent
- the parent to set
public int viewToModel(float x, float y, Shape a, Position.Bias[] b)
Maps coordinates from theView
's space into a position in the document model.
- Overrides:
- viewToModel in interface View
- Parameters:
x
- the x coordinate in the view space, x >= 0y
- the y coordinate in the view space, y >= 0a
- the allocation of thisView
b
- the bias to use
- Returns:
- the position in the document that corresponds to the screen coordinates
x, y
>= 0