- java.lang.Object
-
- javax.swing.text.View
-
- javax.swing.text.AsyncBoxView
-
- All Implemented Interfaces:
SwingConstants
public class AsyncBoxView extends View
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.
- Since:
- 1.3
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description 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.class
AsyncBoxView.ChildState
A record representing the layout state of a child view.
-
Field Summary
Fields Modifier and Type Field Description protected AsyncBoxView.ChildLocator
locator
Object that manages the offsets of the children.-
Fields declared in class javax.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
-
Fields declared in 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
Constructors Constructor Description AsyncBoxView(Element elem, int axis)
Construct a box view that does asynchronous layout.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected AsyncBoxView.ChildState
createChildState(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.float
getBottomInset()
Get the bottom part of the margin around the view.Shape
getChildAllocation(int index, Shape a)
Fetches the allocation for the given child view.protected AsyncBoxView.ChildState
getChildState(int index)
Fetch the object representing the layout state of of the child at the given index.protected boolean
getEstimatedMajorSpan()
Is the major span currently estimated?protected float
getInsetSpan(int axis)
Fetch the span along an axis that is taken up by the insets.protected LayoutQueue
getLayoutQueue()
Fetch the queue to use for layout.float
getLeftInset()
Get the left part of the margin around the view.int
getMajorAxis()
Fetch the major axis (the axis the children are tiled along).float
getMaximumSpan(int axis)
Determines the maximum span for this view along an axis.float
getMinimumSpan(int axis)
Determines the minimum span for this view along an axis.int
getMinorAxis()
Fetch the minor axis (the axis orthogonal to the tiled axis).int
getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet)
Provides a way to determine the next visually represented model location that one might place a caret.float
getPreferredSpan(int axis)
Determines the preferred span for this view along an axis.float
getRightInset()
Get the right part of the margin around the view.float
getTopInset()
Get the top part of the margin around the view.View
getView(int n)
Gets the nth child view.int
getViewCount()
Returns the number of views in this view.int
getViewIndex(int pos, Position.Bias b)
Returns the child view index representing the given position in the model.protected int
getViewIndexAtPosition(int pos, Position.Bias b)
Fetches the child view index representing the given position in the model.protected void
loadChildren(ViewFactory f)
Loads all of the children to initialize the view.protected void
majorRequirementChange(AsyncBoxView.ChildState cs, float delta)
Requirements changed along the major axis.protected void
minorRequirementChange(AsyncBoxView.ChildState cs)
Requirements changed along the minor axis.Shape
modelToView(int pos, Shape a, Position.Bias b)
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.void
paint(Graphics g, Shape alloc)
Render the view using the given allocation and rendering surface.void
preferenceChanged(View child, boolean width, boolean height)
Child views can call this on the parent to indicate that the preference has changed and should be reconsidered for layout.void
replace(int offset, int length, View[] views)
Calls the superclass to update the child views, and updates the status records for the children.void
setBottomInset(float i)
Set the bottom part of the margin around the view.protected void
setEstimatedMajorSpan(boolean isEstimated)
Set the estimatedMajorSpan property that determines if the major span should be treated as being estimated.void
setLeftInset(float i)
Set the left part of the margin around the view.void
setParent(View parent)
Sets the parent of the view.void
setRightInset(float i)
Set the right part of the margin around the view.void
setSize(float width, float height)
Sets the size of the view.void
setTopInset(float i)
Set the top part of the margin around the view.protected void
updateLayout(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a)
Update the layout in response to receiving notification of change from the model.int
viewToModel(float x, float y, Shape a, Position.Bias[] biasReturn)
Provides a mapping from the view coordinate space to the logical coordinate space of the model.-
Methods declared in class javax.swing.text.View
append, breakView, changedUpdate, createFragment, forwardUpdate, forwardUpdateToView, getAlignment, getAttributes, getBreakWeight, getContainer, getDocument, getElement, getEndOffset, getGraphics, getParent, getResizeWeight, getStartOffset, getToolTipText, getViewFactory, getViewIndex, insert, insertUpdate, isVisible, modelToView, modelToView, remove, removeAll, removeUpdate, updateChildren, viewToModel
-
-
-
-
Field Detail
-
locator
protected AsyncBoxView.ChildLocator locator
Object that manages the offsets of the children. All locking for management of child locations is on this object.
-
-
Constructor Detail
-
AsyncBoxView
public AsyncBoxView(Element elem, int axis)
Construct a box view that does asynchronous layout.- Parameters:
elem
- the element of the model to representaxis
- the axis to tile along. This can be either X_AXIS or Y_AXIS.
-
-
Method Detail
-
getMajorAxis
public int getMajorAxis()
Fetch the major axis (the axis the children are tiled along). This will have a value of either X_AXIS or Y_AXIS.- Returns:
- the major axis
-
getMinorAxis
public int getMinorAxis()
Fetch the minor axis (the axis orthogonal to the tiled axis). This will have a value of either X_AXIS or Y_AXIS.- Returns:
- the minor axis
-
getTopInset
public float getTopInset()
Get the top part of the margin around the view.- Returns:
- the top part of the margin around the view
-
setTopInset
public void setTopInset(float i)
Set the top part of the margin around the view.- Parameters:
i
- the value of the inset
-
getBottomInset
public float getBottomInset()
Get the bottom part of the margin around the view.- Returns:
- the bottom part of the margin around the view
-
setBottomInset
public void setBottomInset(float i)
Set the bottom part of the margin around the view.- Parameters:
i
- the value of the inset
-
getLeftInset
public float getLeftInset()
Get the left part of the margin around the view.- Returns:
- the left part of the margin around the view
-
setLeftInset
public void setLeftInset(float i)
Set the left part of the margin around the view.- Parameters:
i
- the value of the inset
-
getRightInset
public float getRightInset()
Get the right part of the margin around the view.- Returns:
- the right part of the margin around the view
-
setRightInset
public void setRightInset(float i)
Set the right part of the margin around the view.- Parameters:
i
- the value of the inset
-
getInsetSpan
protected float getInsetSpan(int axis)
Fetch the span along an axis that is taken up by the insets.- Parameters:
axis
- the axis to determine the total insets along, either X_AXIS or Y_AXIS.- Returns:
- the span along an axis that is taken up by the insets
- Since:
- 1.4
-
setEstimatedMajorSpan
protected void setEstimatedMajorSpan(boolean isEstimated)
Set the estimatedMajorSpan property that determines if the major span should be treated as being estimated. If this property is true, the value of setSize along the major axis will change the requirements along the major axis and incremental changes will be ignored until all of the children have been updated (which will cause the property to automatically be set to false). If the property is false the value of the majorSpan will be considered to be accurate and incremental changes will be added into the total as they are calculated.- Parameters:
isEstimated
- new value for the estimatedMajorSpan property- Since:
- 1.4
-
getEstimatedMajorSpan
protected boolean getEstimatedMajorSpan()
Is the major span currently estimated?- Returns:
- whether or not the major span currently estimated
- Since:
- 1.4
-
getChildState
protected AsyncBoxView.ChildState getChildState(int index)
Fetch the object representing the layout state of of the child at the given index.- Parameters:
index
- the child index. This should be a value >= 0 and < getViewCount().- Returns:
- the object representing the layout state of of the child at the given index
-
getLayoutQueue
protected LayoutQueue getLayoutQueue()
Fetch the queue to use for layout.- Returns:
- the queue to use for layout
-
createChildState
protected AsyncBoxView.ChildState createChildState(View v)
New ChildState records are created through this method to allow subclasses the extend the ChildState records to do/hold more.- Parameters:
v
- the view- Returns:
- new child state
-
majorRequirementChange
protected void majorRequirementChange(AsyncBoxView.ChildState cs, float delta)
Requirements changed along the major axis. This is called by the thread doing layout for the given ChildState object when it has completed fetching the child views new preferences. Typically this would be the layout thread, but might be the event thread if it is trying to update something immediately (such as to perform a model/view translation).This is implemented to mark the major axis as having changed so that a future check to see if the requirements need to be published to the parent view will consider the major axis. If the span along the major axis is not estimated, it is updated by the given delta to reflect the incremental change. The delta is ignored if the major span is estimated.
- Parameters:
cs
- the child statedelta
- the delta
-
minorRequirementChange
protected void minorRequirementChange(AsyncBoxView.ChildState cs)
Requirements changed along the minor axis. This is called by the thread doing layout for the given ChildState object when it has completed fetching the child views new preferences. Typically this would be the layout thread, but might be the GUI thread if it is trying to update something immediately (such as to perform a model/view translation).- Parameters:
cs
- the child state
-
flushRequirementChanges
protected void flushRequirementChanges()
Publish the changes in preferences upward to the parent view. This is normally called by the layout thread.
-
replace
public void replace(int offset, int length,
-
-