APIdia Launch Partner
Top Description Fields Constructors Methods
javax.swing.text

public Class BoxView

extends CompositeView
Class Inheritance
Known Direct Subclasses
javax.swing.text.FlowView, javax.swing.text.ParagraphView.Row, javax.swing.text.TableView, javax.swing.text.TableView.TableRow, javax.swing.text.TableView.TableCell, javax.swing.text.WrappedPlainView, javax.swing.text.ZoneView, javax.swing.text.html.BlockView, javax.swing.text.html.FrameSetView, javax.swing.text.html.TableView, javax.swing.text.html.TableView.RowView
Imports
java.io.PrintStream, java.util.Vector, java.awt.*, javax.swing.event.DocumentEvent, javax.swing.SizeRequirements

A view that arranges its children into a box shape by tiling its children along an axis. The box is somewhat like that found in TeX where there is alignment of the children, flexibility of the children is considered, etc. This is a building block that might be useful to represent things like a collection of lines, paragraphs, lists, columns, pages, etc. The axis along which the children are tiled is considered the major axis. The orthogonal axis is the minor axis.

Layout for each axis is handled separately by the methods layoutMajorAxis and layoutMinorAxis. Subclasses can change the layout algorithm by reimplementing these methods. These methods will be called as necessary depending upon whether or not there is cached layout information and the cache is considered valid. These methods are typically called if the given size along the axis changes, or if layoutChanged is called to force an updated layout. The layoutChanged method invalidates cached layout information, if there is any. The requirements published to the parent view are calculated by the methods calculateMajorAxisRequirements and calculateMinorAxisRequirements. If the layout algorithm is changed, these methods will likely need to be reimplemented.

Author
Timothy Prinzing

Field Summary

Modifier and TypeField and Description
pack-priv boolean
pack-priv int
pack-priv int[]
pack-priv SizeRequirements
pack-priv boolean
pack-priv int
pack-priv int[]
pack-priv boolean
pack-priv int[]
pack-priv SizeRequirements
pack-priv boolean
pack-priv int
pack-priv int[]
pack-priv Rectangle
tempRect

used in paint.

Constructor Summary

AccessConstructor and Description
public
BoxView(Element
the element this view is responsible for
elem
,
int
either View.X_AXIS or View.Y_AXIS
axis
)

Constructs a BoxView.

Method Summary

Modifier and TypeMethod and Description
protected void
baselineLayout(int
the total span given to the view, which would be used to layout the children
targetSpan
,
int
the axis being studied, either View.X_AXIS or View.Y_AXIS
axis
,
int[]
an empty array filled by this method with values specifying the location of each child view
offsets
,
int[]
an empty array filled by this method with values specifying the extent of each child view
spans
)

Computes the location and extent of each child view in this BoxView given the targetSpan, which is the width (or height) of the region we have to work with.

protected SizeRequirements

Returns:

the newly initialized SizeRequirements object
baselineRequirements
(int
the axis being studied
axis
,
SizeRequirements
the SizeRequirements object; if null one will be created
r
)

Calculates the size requirements for this BoxView by examining the size of each child view.

protected SizeRequirements

Returns:

the newly initialized SizeRequirements object
calculateMajorAxisRequirements
(int
the axis being studied
axis
,
SizeRequirements
the SizeRequirements object; if null one will be created
r
)

Calculates the size requirements for the major axis axis.

protected SizeRequirements

Returns:

the newly initialized SizeRequirements object
calculateMinorAxisRequirements
(int
the axis being studied
axis
,
SizeRequirements
the SizeRequirements object; if null one will be created
r
)

Calculates the size requirements for the minor axis axis.

pack-priv void
checkRequests(int
the axis being studied
axis
)

Checks the request cache and update if needed.

protected void
childAllocation(int
the index of the child view to allocate, >= 0 && < getViewCount()
index
,
Rectangle
the allocated region
alloc
)

Implements abstract javax.swing.text.CompositeView.childAllocation.

Allocates a region for a child view.

protected boolean

Returns:

true if the Views surrounding the View responding for rendering position and bias are laid out in descending order; otherwise false
flipEastAndWestAtEnds
(int
position into the model
position
,
Position.Bias
either Position.Bias.Forward or Position.Bias.Backward
bias
)

Overrides javax.swing.text.CompositeView.flipEastAndWestAtEnds.

Determines in which direction the next view lays.

protected void
forwardUpdate(DocumentEvent.ElementChange
changes to the element this view is responsible for (may be null if there were no changes)
ec
,
DocumentEvent
the change information from the associated document
e
,
Shape
the current allocation of the view
a
,
ViewFactory
the factory to use to rebuild if the view has children
f
)

Overrides javax.swing.text.View.forwardUpdate.

Forwards the given DocumentEvent to the child views that need to be notified of the change to the model.

public float

Returns:

the desired alignment >= 0.0f && <= 1.0f; this should be a value between 0.0 and 1.0 where 0 indicates alignment at the origin and 1.0 indicates alignment to the full span away from the origin; an alignment of 0.5 would be the center of the view
getAlignment
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.View.getAlignment.

Determines the desired alignment for this view along an axis.

public int

Returns:

the major axis of the box, either View.X_AXIS or View.Y_AXIS
getAxis
()

Fetches the tile axis property.

public Shape

Returns:

the allocation to the child; or null if a is null; or null if the layout is invalid
getChildAllocation
(int
the index of the child, >= 0 && > getViewCount()
index
,
Shape
the allocation to this view
a
)

Overrides javax.swing.text.CompositeView.getChildAllocation.

Fetches the allocation for the given child view.

public int

Returns:

the current height of the box
getHeight
()

Returns the current height of the box.

public float

Returns:

the span the view would like to be rendered into >= 0; typically the view is told to render into the span that is returned, although there is no guarantee; the parent may choose to resize or break the view
getMaximumSpan
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.View.getMaximumSpan.

Determines the maximum span for this view along an axis.

public float

Returns:

the span the view would like to be rendered into >= 0; typically the view is told to render into the span that is returned, although there is no guarantee; the parent may choose to resize or break the view
getMinimumSpan
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.View.getMinimumSpan.

Determines the minimum span for this view along an axis.

protected int

Returns:

the offset (location) for the specified child
getOffset
(int
the axis being studied
axis
,
int
the index of the requested child
childIndex
)

Fetches the offset of a particular child's current layout.

public float

Returns:

the span the view would like to be rendered into >= 0; typically the view is told to render into the span that is returned, although there is no guarantee; the parent may choose to resize or break the view
getPreferredSpan
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Implements abstract javax.swing.text.View.getPreferredSpan.

Determines the preferred span for this view along an axis.

public int

Returns:

the weight
getResizeWeight
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Overrides javax.swing.text.View.getResizeWeight.

Gets the resize weight.

protected int

Returns:

the span (width or height) of the specified child
getSpan
(int
the axis being studied
axis
,
int
the index of the requested child
childIndex
)

Fetches the span of a particular child's current layout.

pack-priv float

Returns:

the current span of the view along the given axis, >= 0
getSpanOnAxis
(int
may be either View.X_AXIS or View.Y_AXIS
axis
)

Returns the size of the view along an axis.

protected View

Returns:

the view
getViewAtPoint
(int
the X coordinate >= 0
x
,
int
the Y coordinate >= 0
y
,
Rectangle
the parents inner allocation on entry, which should be changed to the child's allocation on exit
alloc
)

Implements abstract javax.swing.text.CompositeView.getViewAtPoint.

Fetches the child view at the given coordinates.

public int

Returns:

the current width of the box
getWidth
()

Returns the current width of the box.

protected boolean

Returns:

true if the point lies after the region else false
isAfter
(int
the X coordinate >= 0
x
,
int
the Y coordinate >= 0
y
,
Rectangle
the allocated region; this is the area inside of the insets
innerAlloc
)

Implements abstract javax.swing.text.CompositeView.isAfter.

Determines if a point falls after an allocated region.

protected boolean

Returns:

true if allocations still valid
isAllocationValid
()

Are the allocations for the children still valid?

protected boolean

Returns:

true if the point lies before the region else false
isBefore
(int
the X coordinate >= 0
x
,
int
the Y coordinate >= 0
y
,
Rectangle
the allocated region; this is the area inside of the insets
innerAlloc
)

Implements abstract javax.swing.text.CompositeView.isBefore.

Determines if a point falls before an allocated region.

protected boolean

Returns:

true if the layout is valid along the given axis, otherwise false
isLayoutValid
(int
either View.X_AXIS or View.Y_AXIS
axis
)

Determines if the layout is valid along the given axis.

protected void
layout(int
the width (inside of the insets) >= 0
width
,
int
the height (inside of the insets) >= 0
height
)

Perform layout on the box

public void
layoutChanged(int
either View.X_AXIS or View.Y_AXIS
axis
)

Invalidates the layout along an axis.

protected void
layoutMajorAxis(int
the total span given to the view, which would be used to layout the children
targetSpan
,
int
the axis being laid out
axis
,
int[]
the offsets from the origin of the view for each of the child views; this is a return value and is filled in by the implementation of this method
offsets
,
int[]
the span of each child view; this is a return value and is filled in by the implementation of this method
spans
)

Performs layout for the major axis of the box (i.e. the axis that it represents).

protected void
layoutMinorAxis(int
the total span given to the view, which would be used to layout the children
targetSpan
,
int
the axis being laid out
axis
,
int[]
the offsets from the origin of the view for each of the child views; this is a return value and is filled in by the implementation of this method
offsets
,
int[]
the span of each child view; this is a return value and is filled in by the implementation of this method
spans
)

Performs layout for the minor axis of the box (i.e. the axis orthogonal to the axis that it represents).

public Shape

Returns:

the bounding box of the given position
modelToView
(int
the position to convert >= 0
pos
,
Shape
the allocated region to render into
a
,
Position.Bias b)

Overrides javax.swing.text.CompositeView.modelToView.

Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.

public void
paint(Graphics
the rendering surface to use
g
,
Shape
the allocated region to render into
allocation
)

Implements abstract javax.swing.text.View.paint.

Renders the BoxView using the given rendering surface and area on that surface.

protected void
paintChild(Graphics
the graphics context
g
,
Rectangle
the allocated region to paint into
alloc
,
int
the child index, >= 0 && < getViewCount()
index
)

Paints a child.

public void
preferenceChanged(View
the child view
child
,
boolean
true if the width preference should change
width
,
boolean
true if the height preference should change
height
)

Overrides javax.swing.text.View.preferenceChanged.

This is called by a child to indicate its preferred span has changed.

public void
replace(int
the starting index into the child views to insert the new views; this should be a value >= 0 and <= getViewCount
index
,
int
the number of existing child views to remove; This should be a value >= 0 and <= (getViewCount() - offset)
length
,
View[]
the child views to add; this value can be nullto indicate no children are being added (useful to remove)
elems
)

Overrides javax.swing.text.CompositeView.replace.

Invalidates the layout and resizes the cache of requests/allocations.

public void
setAxis(int
either View.X_AXIS or View.Y_AXIS
axis
)

Sets the tile axis property.

public void
setSize(float
the width >= 0
width
,
float
the height >= 0
height
)

Overrides javax.swing.text.View.setSize.

Sets the size of the view.

pack-priv void
setSpanOnAxis(int
may be either View.X_AXIS or View.Y_AXIS
axis
,
float
the span to layout to >= 0
span
)

Sets the size of the view along an axis.

pack-priv void
updateChildSizes()

Propagates the current allocations to the child views.

pack-priv int[]

Returns:

the new layout array
updateLayoutArray
(int[]
the original layout array
oldArray
,
int
location where new views will be inserted
offset
,
int
the number of child views being inserted; therefore the number of blank spaces to leave in the new array at location offset
nInserted
)

Resizes the given layout array to match the new number of child views.

public int

Returns:

the location within the model that best represents the given point in the view >= 0
viewToModel
(float
x coordinate of the view location to convert >= 0
x
,
float
y coordinate of the view location to convert >= 0
y
,
Shape
the allocated region to render into
a
,
Position.Bias[] bias)

Overrides javax.swing.text.CompositeView.viewToModel.

Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Inherited from javax.swing.text.CompositeView:
getBottomInsetgetInsideAllocationgetLeftInsetgetNextEastWestVisualPositionFromgetNextNorthSouthVisualPositionFromgetNextVisualPositionFromgetRightInsetgetTopInsetgetViewgetViewAtPositiongetViewCountgetViewIndexgetViewIndexAtPositionloadChildrenmodelToViewsetInsetssetParagraphInsetssetParent

Field Detail

majorAllocValidback to summary
pack-priv boolean majorAllocValid
majorAxisback to summary
pack-priv int majorAxis
majorOffsetsback to summary
pack-priv int[] majorOffsets
majorRequestback to summary
pack-priv SizeRequirements majorRequest
majorReqValidback to summary
pack-priv boolean majorReqValid
majorSpanback to summary
pack-priv int majorSpan
majorSpansback to summary
pack-priv int[] majorSpans
minorAllocValidback to summary
pack-priv boolean minorAllocValid
minorOffsetsback to summary
pack-priv int[] minorOffsets
minorRequestback to summary
pack-priv SizeRequirements minorRequest
minorReqValidback to summary
pack-priv boolean minorReqValid
minorSpanback to summary
pack-priv int minorSpan
minorSpansback to summary
pack-priv int[] minorSpans
tempRectback to summary
pack-priv Rectangle tempRect

used in paint.

Constructor Detail

BoxViewback to summary
public BoxView(Element elem, int axis)

Constructs a BoxView.

Parameters
elem:Element

the element this view is responsible for

axis:int

either View.X_AXIS or View.Y_AXIS

Method Detail

baselineLayoutback to summary
protected void baselineLayout(int targetSpan, int axis, int[] offsets, int[] spans)

Computes the location and extent of each child view in this BoxView given the targetSpan, which is the width (or height) of the region we have to work with.

Parameters
targetSpan:int

the total span given to the view, which would be used to layout the children

axis:int

the axis being studied, either View.X_AXIS or View.Y_AXIS

offsets:int[]

an empty array filled by this method with values specifying the location of each child view

spans:int[]

an empty array filled by this method with values specifying the extent of each child view

baselineRequirementsback to summary
protected SizeRequirements baselineRequirements(int axis, SizeRequirements r)

Calculates the size requirements for this BoxView by examining the size of each child view.

Parameters
axis:int

the axis being studied

r:SizeRequirements

the SizeRequirements object; if null one will be created

Returns:SizeRequirements

the newly initialized SizeRequirements object

calculateMajorAxisRequirementsback to summary
protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements r)

Calculates the size requirements for the major axis axis.

Parameters
axis:int

the axis being studied

r:SizeRequirements

the SizeRequirements object; if null one will be created

Returns:SizeRequirements

the newly initialized SizeRequirements object

See Also
javax.swing.SizeRequirements
calculateMinorAxisRequirementsback to summary
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r)

Calculates the size requirements for the minor axis axis.

Parameters
axis:int

the axis being studied

r:SizeRequirements

the SizeRequirements object; if null one will be created

Returns:SizeRequirements

the newly initialized SizeRequirements object

See Also
javax.swing.SizeRequirements
checkRequestsback to summary
pack-priv void checkRequests(int axis)

Checks the request cache and update if needed.

Parameters
axis:int

the axis being studied

Exceptions
IllegalArgumentException:
if axis is neither View.X_AXIS nor View.Y_AXIS
childAllocationback to summary
protected void childAllocation(int index, Rectangle alloc)

Implements abstract javax.swing.text.CompositeView.childAllocation.

Allocates a region for a child view.

Parameters
index:int

the index of the child view to allocate, >= 0 && < getViewCount()

alloc:Rectangle

the allocated region

flipEastAndWestAtEndsback to summary
protected boolean flipEastAndWestAtEnds(int position, Position.Bias bias)

Overrides javax.swing.text.CompositeView.flipEastAndWestAtEnds.

Determines in which direction the next view lays. Consider the View at index n. Typically the Views are laid out from left to right, so that the View to the EAST will be at index n + 1, and the View to the WEST will be at index n - 1. In certain situations, such as with bidirectional text, it is possible that the View to EAST is not at index n + 1, but rather at index n - 1, or that the View to the WEST is not at index n - 1, but index n + 1. In this case this method would return true, indicating the Views are laid out in descending order. Otherwise the method would return false indicating the Views are laid out in ascending order.

If the receiver is laying its Views along the Y_AXIS, this will return the value from invoking the same method on the View responsible for rendering position and bias. Otherwise this will return false.

Parameters
position:int

position into the model

bias:Position.Bias

either Position.Bias.Forward or Position.Bias.Backward

Returns:boolean

true if the Views surrounding the View responding for rendering position and bias are laid out in descending order; otherwise false

forwardUpdateback to summary
protected void forwardUpdate(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a, ViewFactory f)

Overrides javax.swing.text.View.forwardUpdate.

Forwards the given DocumentEvent to the child views that need to be notified of the change to the model. If a child changed its requirements and the allocation was valid prior to forwarding the portion of the box from the starting child to the end of the box will be repainted.

Parameters
ec:DocumentEvent.ElementChange

changes to the element this view is responsible for (may be null if there were no changes)

e:DocumentEvent

the change information from the associated document

a:Shape

the current allocation of the view

f:ViewFactory

the factory to use to rebuild if the view has children

Since
1.3
See Also
insertUpdate, removeUpdate, changedUpdate
getAlignmentback to summary
public float getAlignment(int axis)

Overrides javax.swing.text.View.getAlignment.

Determines the desired alignment for this view along an axis. This is implemented to give the total alignment needed to position the children with the alignment points lined up along the axis orthogonal to the axis that is being tiled. The axis being tiled will request to be centered (i.e. 0.5f).

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the desired alignment >= 0.0f && <= 1.0f; this should be a value between 0.0 and 1.0 where 0 indicates alignment at the origin and 1.0 indicates alignment to the full span away from the origin; an alignment of 0.5 would be the center of the view

Exceptions
IllegalArgumentException:
for an invalid axis
getAxisback to summary
public int getAxis()

Fetches the tile axis property. This is the axis along which the child views are tiled.

Returns:int

the major axis of the box, either View.X_AXIS or View.Y_AXIS

Since
1.3
getChildAllocationback to summary
public Shape getChildAllocation(int index, Shape a)

Overrides javax.swing.text.CompositeView.getChildAllocation.

Fetches the allocation for the given child view. This enables finding out where various views are located. This is implemented to return null if the layout is invalid, otherwise the superclass behavior is executed.

Parameters
index:int

the index of the child, >= 0 && > getViewCount()

a:Shape

the allocation to this view

Returns:Shape

the allocation to the child; or null if a is null; or null if the layout is invalid

getHeightback to summary
public int getHeight()

Returns the current height of the box. This is the height that it was last allocated.

Returns:int

the current height of the box

getMaximumSpanback to summary
public float getMaximumSpan(int axis)

Overrides javax.swing.text.View.getMaximumSpan.

Determines the maximum span for this view along an axis.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the span the view would like to be rendered into >= 0; typically the view is told to render into the span that is returned, although there is no guarantee; the parent may choose to resize or break the view

Exceptions
IllegalArgumentException:
for an invalid axis type
getMinimumSpanback to summary
public float getMinimumSpan(int axis)

Overrides javax.swing.text.View.getMinimumSpan.

Determines the minimum span for this view along an axis.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the span the view would like to be rendered into >= 0; typically the view is told to render into the span that is returned, although there is no guarantee; the parent may choose to resize or break the view

Exceptions
IllegalArgumentException:
for an invalid axis type
getOffsetback to summary
protected int getOffset(int axis, int childIndex)

Fetches the offset of a particular child's current layout.

Parameters
axis:int

the axis being studied

childIndex:int

the index of the requested child

Returns:int

the offset (location) for the specified child

getPreferredSpanback to summary
public float getPreferredSpan(int axis)

Implements abstract javax.swing.text.View.getPreferredSpan.

Determines the preferred span for this view along an axis.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the span the view would like to be rendered into >= 0; typically the view is told to render into the span that is returned, although there is no guarantee; the parent may choose to resize or break the view

Exceptions
IllegalArgumentException:
for an invalid axis type
getResizeWeightback to summary
public int getResizeWeight(int axis)

Overrides javax.swing.text.View.getResizeWeight.

Gets the resize weight. A value of 0 or less is not resizable.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

Returns:int

the weight

Exceptions
IllegalArgumentException:
for an invalid axis
getSpanback to summary
protected int getSpan(int axis, int childIndex)

Fetches the span of a particular child's current layout.

Parameters
axis:int

the axis being studied

childIndex:int

the index of the requested child

Returns:int

the span (width or height) of the specified child

getSpanOnAxisback to summary
pack-priv float getSpanOnAxis(int axis)

Returns the size of the view along an axis. This is implemented to return zero.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

Returns:float

the current span of the view along the given axis, >= 0

getViewAtPointback to summary
protected View getViewAtPoint(int x, int y, Rectangle alloc)

Implements abstract javax.swing.text.CompositeView.getViewAtPoint.

Fetches the child view at the given coordinates.

Parameters
x:int

the X coordinate >= 0

y:int

the Y coordinate >= 0

alloc:Rectangle

the parents inner allocation on entry, which should be changed to the child's allocation on exit

Returns:View

the view

getWidthback to summary
public int getWidth()

Returns the current width of the box. This is the width that it was last allocated.

Returns:int

the current width of the box

isAfterback to summary
protected boolean isAfter(int x, int y, Rectangle innerAlloc)

Implements abstract javax.swing.text.CompositeView.isAfter.

Determines if a point falls after an allocated region.

Parameters
x:int

the X coordinate >= 0

y:int

the Y coordinate >= 0

innerAlloc:Rectangle

the allocated region; this is the area inside of the insets

Returns:boolean

true if the point lies after the region else false

isAllocationValidback to summary
protected boolean isAllocationValid()

Are the allocations for the children still valid?

Returns:boolean

true if allocations still valid

isBeforeback to summary
protected boolean isBefore(int x, int y, Rectangle innerAlloc)

Implements abstract javax.swing.text.CompositeView.isBefore.

Determines if a point falls before an allocated region.

Parameters
x:int

the X coordinate >= 0

y:int

the Y coordinate >= 0

innerAlloc:Rectangle

the allocated region; this is the area inside of the insets

Returns:boolean

true if the point lies before the region else false

isLayoutValidback to summary
protected boolean isLayoutValid(int axis)

Determines if the layout is valid along the given axis.

Parameters
axis:int

either View.X_AXIS or View.Y_AXIS

Returns:boolean

true if the layout is valid along the given axis, otherwise false

Since
1.4
layoutback to summary
protected void layout(int width, int height)

Perform layout on the box

Parameters
width:int

the width (inside of the insets) >= 0

height:int

the height (inside of the insets) >= 0

layoutChangedback to summary
public void layoutChanged(int axis)

Invalidates the layout along an axis. This happens automatically if the preferences have changed for any of the child views. In some cases the layout may need to be recalculated when the preferences have not changed. The layout can be marked as invalid by calling this method. The layout will be updated the next time the setSize method is called on this view (typically in paint).

Parameters
axis:int

either View.X_AXIS or View.Y_AXIS

Since
1.3
layoutMajorAxisback to summary
protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans)

Performs layout for the major axis of the box (i.e. the axis that it represents). The results of the layout (the offset and span for each children) are placed in the given arrays which represent the allocations to the children along the major axis.

Parameters
targetSpan:int

the total span given to the view, which would be used to layout the children

axis:int

the axis being laid out

offsets:int[]

the offsets from the origin of the view for each of the child views; this is a return value and is filled in by the implementation of this method

spans:int[]

the span of each child view; this is a return value and is filled in by the implementation of this method

layoutMinorAxisback to summary
protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans)

Performs layout for the minor axis of the box (i.e. the axis orthogonal to the axis that it represents). The results of the layout (the offset and span for each children) are placed in the given arrays which represent the allocations to the children along the minor axis.

Parameters
targetSpan:int

the total span given to the view, which would be used to layout the children

axis:int

the axis being laid out

offsets:int[]

the offsets from the origin of the view for each of the child views; this is a return value and is filled in by the implementation of this method

spans:int[]

the span of each child view; this is a return value and is filled in by the implementation of this method

modelToViewback to summary
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException

Overrides javax.swing.text.CompositeView.modelToView.

Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it. This makes sure the allocation is valid before calling the superclass.

Parameters
pos:int

the position to convert >= 0

a:Shape

the allocated region to render into

Returns:Shape

the bounding box of the given position

Exceptions
BadLocationException:
if the given position does not represent a valid location in the associated document
See Also
View#modelToView
paintback to summary
public void paint(Graphics g, Shape allocation)

Implements abstract javax.swing.text.View.paint.

Renders the BoxView using the given rendering surface and area on that surface. Only the children that intersect the clip bounds of the given Graphics will be rendered.

Parameters
g:Graphics

the rendering surface to use

allocation:Shape

the allocated region to render into

See Also
View#paint
paintChildback to summary
protected void paintChild(Graphics g, Rectangle alloc, int index)

Paints a child. By default that is all it does, but a subclass can use this to paint things relative to the child.

Parameters
g:Graphics

the graphics context

alloc:Rectangle

the allocated region to paint into

index:int

the child index, >= 0 && < getViewCount()

preferenceChangedback to summary
public void preferenceChanged(View child, boolean width, boolean height)

Overrides javax.swing.text.View.preferenceChanged.

This is called by a child to indicate its preferred span has changed. This is implemented to throw away cached layout information so that new calculations will be done the next time the children need an allocation.

Parameters
child:View

the child view

width:boolean

true if the width preference should change

height:boolean

true if the height preference should change

replaceback to summary
public void replace(int index, int length, View[] elems)

Overrides javax.swing.text.CompositeView.replace.

Invalidates the layout and resizes the cache of requests/allocations. The child allocations can still be accessed for the old layout, but the new children will have an offset and span of 0.

Parameters
index:int

the starting index into the child views to insert the new views; this should be a value >= 0 and <= getViewCount

length:int

the number of existing child views to remove; This should be a value >= 0 and <= (getViewCount() - offset)

elems:View[]

the child views to add; this value can be nullto indicate no children are being added (useful to remove)

setAxisback to summary
public void setAxis(int axis)

Sets the tile axis property. This is the axis along which the child views are tiled.

Parameters
axis:int

either View.X_AXIS or View.Y_AXIS

Since
1.3
setSizeback to summary
public void setSize(float width, float height)

Overrides javax.swing.text.View.setSize.

Sets the size of the view. This should cause layout of the view if the view caches any layout information. This is implemented to call the layout method with the sizes inside of the insets.

Parameters
width:float

the width >= 0

height:float

the height >= 0

setSpanOnAxisback to summary
pack-priv void setSpanOnAxis(int axis, float span)

Sets the size of the view along an axis. This should cause layout of the view along the given axis.

Parameters
axis:int

may be either View.X_AXIS or View.Y_AXIS

span:float

the span to layout to >= 0

updateChildSizesback to summary
pack-priv void updateChildSizes()

Propagates the current allocations to the child views.

updateLayoutArrayback to summary
pack-priv int[] updateLayoutArray(int[] oldArray, int offset, int nInserted)

Resizes the given layout array to match the new number of child views. The current number of child views are used to produce the new array. The contents of the old array are inserted into the new array at the appropriate places so that the old layout information is transferred to the new array.

Parameters
oldArray:int[]

the original layout array

offset:int

location where new views will be inserted

nInserted:int

the number of child views being inserted; therefore the number of blank spaces to leave in the new array at location offset

Returns:int[]

the new layout array

viewToModelback to summary
public int viewToModel(float x, float y, Shape a, Position.Bias[] bias)

Overrides javax.swing.text.CompositeView.viewToModel.

Provides a mapping from the view coordinate space to the logical coordinate space of the model.

Parameters
x:float

x coordinate of the view location to convert >= 0

y:float

y coordinate of the view location to convert >= 0

a:Shape

the allocated region to render into

Returns:int

the location within the model that best represents the given point in the view >= 0

See Also
View#viewToModel