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

public Class AsyncBoxView

extends View
Class Inheritance
Known Direct Subclasses
javax.swing.text.ZoneView.Zone
Imports
java.util.*, .List, java.awt.*, javax.swing.SwingUtilities, javax.swing.event.DocumentEvent

A box that does layout asynchronously. This is useful to keep the GUI event thread moving by not doing any layout on it. The layout is done on a granularity of operations on the child views. After each child view is accessed for some part of layout (a potentially time consuming operation) the remaining tasks can be abandoned or a new higher priority task (i.e. to service a synchronous request or a visible area) can be taken on.

While the child view is being accessed a read lock is acquired on the associated document so that the model is stable while being accessed.

Author
Timothy Prinzing
Since
1.3

Nested and Inner Type Summary

Modifier and TypeClass and Description
public class
AsyncBoxView.ChildLocator

A class to manage the effective position of the child views in a localized area while changes are being made around the localized area.

public class
AsyncBoxView.ChildState

A record representing the layout state of a child view.

pack-priv class
AsyncBoxView.FlushTask

Task to flush requirement changes upward

Field Summary

Modifier and TypeField and Description
pack-priv int
axis

The major axis against which the children are tiled.

pack-priv float
pack-priv AsyncBoxView.ChildState
changing

Child that is actively changing size.

pack-priv boolean
estimatedMajorSpan

Is the span along the major axis estimated?

pack-priv Runnable
pack-priv float
protected AsyncBoxView.ChildLocator
locator

Object that manages the offsets of the children.

pack-priv boolean
pack-priv float
majorSpan

Current span along the major axis.

pack-priv boolean
pack-priv float
minorSpan

Current span along the minor axis.

pack-priv AsyncBoxView.ChildState
pack-priv AsyncBoxView.ChildState
pack-priv float
pack-priv List<AsyncBoxView.ChildState>
stats

The children and their layout statistics.

pack-priv float
Inherited from javax.swing.text.View:
BadBreakWeightExcellentBreakWeightfirstUpdateIndexForcedBreakWeightGoodBreakWeightlastUpdateIndexsharedBiasReturnX_AXISY_AXIS

Constructor Summary

AccessConstructor and Description
public
AsyncBoxView(Element
the element of the model to represent
elem
,
int
the axis to tile along. This can be either X_AXIS or Y_AXIS.
axis
)

Construct a box view that does asynchronous layout.

Method Summary

Modifier and TypeMethod and Description
protected AsyncBoxView.ChildState

Returns:

new child state
createChildState
(View
the view
v
)

New ChildState records are created through this method to allow subclasses the extend the ChildState records to do/hold more.

protected void
flushRequirementChanges()

Publish the changes in preferences upward to the parent view.

public float

Returns:

the bottom part of the margin around the view
getBottomInset
()

Get the bottom part of the margin around the view.

public Shape

Returns:

the allocation to the child
getChildAllocation
(int
the index of the child, >= 0 && < getViewCount()
index
,
Shape
the allocation to this view.
a
)

Overrides javax.swing.text.View.getChildAllocation.

Fetches the allocation for the given child view.

protected AsyncBoxView.ChildState

Returns:

the object representing the layout state of of the child at the given index
getChildState
(int
the child index. This should be a value >= 0 and < getViewCount().
index
)

Fetch the object representing the layout state of of the child at the given index.

protected boolean

Returns:

whether or not the major span currently estimated
getEstimatedMajorSpan
()

Is the major span currently estimated?

protected float

Returns:

the span along an axis that is taken up by the insets
getInsetSpan
(int
the axis to determine the total insets along, either X_AXIS or Y_AXIS.
axis
)

Fetch the span along an axis that is taken up by the insets.

protected LayoutQueue

Returns:

the queue to use for layout
getLayoutQueue
()

Fetch the queue to use for layout.

public float

Returns:

the left part of the margin around the view
getLeftInset
()

Get the left part of the margin around the view.

public int

Returns:

the major axis
getMajorAxis
()

Fetch the major axis (the axis the children are tiled along).

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.

public int

Returns:

the minor axis
getMinorAxis
()

Fetch the minor axis (the axis orthogonal to the tiled axis).

public int

Returns:

the location within the model that best represents the next location visual position
getNextVisualPositionFrom
(int
the position to convert
pos
,
Position.Bias b, Shape
the allocated region to render into
a
,
int
the direction from the current position that can be thought of as the arrow keys typically found on a keyboard; this may be one of the following:
  • SwingConstants.WEST
  • SwingConstants.EAST
  • SwingConstants.NORTH
  • SwingConstants.SOUTH
direction
,
Position.Bias[]
an array contain the bias that was checked
biasRet
)

Overrides javax.swing.text.View.getNextVisualPositionFrom.

Provides a way to determine the next visually represented model location that one might place a caret.

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 float

Returns:

the right part of the margin around the view
getRightInset
()

Get the right part of the margin around the view.

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
)

Retrieves the size of the view along an axis.

public float

Returns:

the top part of the margin around the view
getTopInset
()

Get the top part of the margin around the view.

public View

Returns:

the view
getView
(int
the number of the view to get, >= 0 && < getViewCount()
n
)

Overrides javax.swing.text.View.getView.

Gets the nth child view.

public int

Returns:

the number of views >= 0
getViewCount
()

Overrides javax.swing.text.View.getViewCount.

Returns the number of views in this view.

public int

Returns:

index of the view representing the given position, or -1 if no view represents that position
getViewIndex
(int
the position >= 0
pos
,
Position.Bias b)

Overrides javax.swing.text.View.getViewIndex.

Returns the child view index representing the given position in the model.

protected synchronized int

Returns:

index of the view representing the given position, or -1 if no view represents that position
getViewIndexAtPosition
(int
the position >= 0
pos
,
Position.Bias
the position bias
b
)

Fetches the child view index representing the given position in the model.

protected void
loadChildren(ViewFactory
the view factory
f
)

Loads all of the children to initialize the view.

protected synchronized void
majorRequirementChange(AsyncBoxView.ChildState
the child state
cs
,
float
the delta
delta
)

Requirements changed along the major axis.

protected synchronized void
minorRequirementChange(AsyncBoxView.ChildState
the child state
cs
)

Requirements changed along the minor axis.

public Shape

Returns:

the bounding box of the given position is returned
modelToView
(int
the position to convert >= 0
pos
,
Shape
the allocated region to render into
a
,
Position.Bias
the bias toward the previous character or the next character represented by the offset, in case the position is a boundary of two views.
b
)

Implements abstract javax.swing.text.View.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
alloc
)

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

Render the view using the given allocation and rendering surface.

public synchronized void
preferenceChanged(View
the child view
child
,
boolean
true if the width preference has changed
width
,
boolean
true if the height preference has changed
height
)

Overrides javax.swing.text.View.preferenceChanged.

Child views can call this on the parent to indicate that the preference has changed and should be reconsidered for layout.

public void
replace(int
the starting offset into the child views >= 0
offset
,
int
the number of existing views to replace >= 0
length
,
View[]
the child views to insert
views
)

Overrides javax.swing.text.View.replace.

Calls the superclass to update the child views, and updates the status records for the children.

public void
setBottomInset(float
the value of the inset
i
)

Set the bottom part of the margin around the view.

protected void
setEstimatedMajorSpan(boolean
new value for the estimatedMajorSpan property
isEstimated
)

Set the estimatedMajorSpan property that determines if the major span should be treated as being estimated.

public void
setLeftInset(float
the value of the inset
i
)

Set the left part of the margin around the view.

public void
setParent(View
the parent of the view, null if none
parent
)

Overrides javax.swing.text.View.setParent.

Sets the parent of the view.

public void
setRightInset(float
the value of the inset
i
)

Set the right part of the margin around the view.

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.

public void
setTopInset(float
the value of the inset
i
)

Set the top part of the margin around the view.

protected void
updateLayout(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
)

Overrides javax.swing.text.View.updateLayout.

Update the layout in response to receiving notification of change from the model.

public int

Returns:

the location within the model that best represents the given point in the view >= 0. The biasReturn argument will be filled in to indicate that the point given is closer to the next character in the model or the previous character in the model.
viewToModel
(float
the X coordinate >= 0
x
,
float
the Y coordinate >= 0
y
,
Shape
the allocated region to render into
a
,
Position.Bias[] biasReturn)

Implements abstract javax.swing.text.View.viewToModel.

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

Inherited from javax.swing.text.View:
appendbreakViewcalculateUpdateIndexeschangedUpdatecreateFragmentforwardUpdateforwardUpdateToViewgetAlignmentgetAttributesgetBreakWeightgetContainergetDocumentgetElementgetEndOffsetgetGraphicsgetParentgetResizeWeightgetStartOffsetgetToolTipTextgetViewFactorygetViewIndexinsertinsertUpdateisVisiblemodelToViewmodelToViewremoveremoveAllremoveUpdateupdateAfterChangeupdateChildrenviewToModel