Class AsyncBoxView
- All Implemented Interfaces:
SwingConstants
public class AsyncBoxView extends View
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
| 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
| Modifier and Type | Field | Description |
|---|---|---|
protected AsyncBoxView.ChildLocator |
locator |
Object that manages the offsets of the children. |
Fields declared in class View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS | Modifier and Type | Field | Description |
|---|---|---|
static final int |
BadBreakWeight |
The weight to indicate a view is a bad break opportunity for the purpose of formatting. |
static final int |
ExcellentBreakWeight |
The weight to indicate a view supports breaking, and this represents a very attractive place to break. |
static final int |
ForcedBreakWeight |
The weight to indicate a view supports breaking, and must be broken to be represented properly when placed in a view that formats its children by breaking them. |
static final int |
GoodBreakWeight |
The weight to indicate a view supports breaking, but better opportunities probably exist. |
static final int |
X_AXIS |
Axis for format/break operations. |
static final int |
Y_AXIS |
Axis for format/break operations. |
Fields declared in interface SwingConstants
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST | Modifier and Type | Field | Description |
|---|---|---|
static final int |
BOTTOM |
Box-orientation constant used to specify the bottom of a box. |
static final int |
CENTER |
The central position in an area. |
static final int |
EAST |
Compass-direction east (right). |
static final int |
HORIZONTAL |
Horizontal orientation. |
static final int |
LEADING |
Identifies the leading edge of text for use with left-to-right and right-to-left languages. |
static final int |
LEFT |
Box-orientation constant used to specify the left side of a box. |
static final int |
NEXT |
Identifies the next direction in a sequence. |
static final int |
NORTH |
Compass-direction North (up). |
static final int |
NORTH_EAST |
Compass-direction north-east (upper right). |
static final int |
NORTH_WEST |
Compass-direction north west (upper left). |
static final int |
PREVIOUS |
Identifies the previous direction in a sequence. |
static final int |
RIGHT |
Box-orientation constant used to specify the right side of a box. |
static final int |
SOUTH |
Compass-direction south (down). |
static final int |
SOUTH_EAST |
Compass-direction south-east (lower right). |
static final int |
SOUTH_WEST |
Compass-direction south-west (lower left). |
static final int |
TOP |
Box-orientation constant used to specify the top of a box. |
static final int |
TRAILING |
Identifies the trailing edge of text for use with left-to-right and right-to-left languages. |
static final int |
VERTICAL |
Vertical orientation. |
static final int |
WEST |
Compass-direction west (left). |
Constructor Summary
| Constructor | Description |
|---|---|
AsyncBoxView |
Construct a box view that does asynchronous layout. |
Method Summary
| Modifier and Type | Method | Description |
|---|---|---|
protected AsyncBoxView.ChildState |
createChildState |
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 |
Fetches the allocation for the given child view. |
protected AsyncBoxView.ChildState |
getChildState |
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 |
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 |
Determines the maximum span for this view along an axis. |
float |
getMinimumSpan |
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 |
Provides a way to determine the next visually represented model location that one might place a caret. |
float |
getPreferredSpan |
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 |
Gets the nth child view. |
int |
getViewCount() |
Returns the number of views in this view. |
int |
getViewIndex |
Returns the child view index representing the given position in the model. |
protected int |
getViewIndexAtPosition |
Fetches the child view index representing the given position in the model. |
protected void |
loadChildren |
Loads all of the children to initialize the view. |
protected void |
majorRequirementChange |
Requirements changed along the major axis. |
protected void |
minorRequirementChange |
Requirements changed along the minor axis. |
Shape |
modelToView |
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it. |
void |
paint |
Render the view using the given allocation and rendering surface. |
void |
preferenceChanged |
Child views can call this on the parent to indicate that the preference has changed and should be reconsidered for layout. |
void |
replace |
Calls the superclass to update the child views, and updates the status records for the children. |
void |
setBottomInset |
Set the bottom part of the margin around the view. |
protected void |
setEstimatedMajorSpan |
Set the estimatedMajorSpan property that determines if the major span should be treated as being estimated. |
void |
setLeftInset |
Set the left part of the margin around the view. |
void |
setParent |
Sets the parent of the view. |
void |
setRightInset |
Set the right part of the margin around the view. |
void |
setSize |
Sets the size of the view. |
void |
setTopInset |
Set the top part of the margin around the view. |
protected void |
updateLayout |
Update the layout in response to receiving notification of change from the model. |
int |
viewToModel |
Provides a mapping from the view coordinate space to the logical coordinate space of the model. |
Methods declared in class 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 | Modifier and Type | Method | Description |
|---|---|---|
void |
append |
Appends a single child view. |
View |
breakView |
Tries to break this view on the given axis. |
void |
changedUpdate |
Gives notification from the document that attributes were changed in a location that this view is responsible for. |
View |
createFragment |
Creates a view that represents a portion of the element. |
protected void |
forwardUpdate |
Forwards the given DocumentEvent to the child views that need to be notified of the change to the model. |
protected void |
forwardUpdateToView |
Forwards the DocumentEvent to the give child view. |
float |
getAlignment |
Determines the desired alignment for this view along an axis. |
AttributeSet |
getAttributes() |
Fetches the attributes to use when rendering. |
int |
getBreakWeight |
Determines how attractive a break opportunity in this view is. |
Container |
getContainer() |
Fetches the container hosting the view. |
Document |
getDocument() |
Fetches the model associated with the view. |
Element |
getElement() |
Fetches the structural portion of the subject that this view is mapped to. |
int |
getEndOffset() |
Fetches the portion of the model for which this view is responsible. |
Graphics |
getGraphics() |
Fetch a Graphics for rendering. |
View |
getParent() |
Returns the parent of the view. |
int |
getResizeWeight |
Determines the resizability of the view along the given axis. |
int |
getStartOffset() |
Fetches the portion of the model for which this view is responsible. |
String |
getToolTipText |
Returns the tooltip text at the specified location. |
ViewFactory |
getViewFactory() |
Fetches the ViewFactory implementation that is feeding the view hierarchy. |
int |
getViewIndex |
Returns the child view index representing the given position in the view. |
void |
insert |
Inserts a single child view. |
void |
insertUpdate |
Gives notification that something was inserted into the document in a location that this view is responsible for. |
boolean |
isVisible() |
Returns a boolean that indicates whether the view is visible or not. |
Shape |
modelToView |
Deprecated. |
Shape |
modelToView |
Provides a mapping, for a given region, from the document model coordinate space to the view coordinate space. |
void |
remove |
Removes one of the children at the given position. |
void |
removeAll() |
Removes all of the children. |
void |
removeUpdate |
Gives notification that something was removed from the document in a location that this view is responsible for. |
protected boolean |
updateChildren |
Updates the child views in response to receiving notification that the model changed, and there is change record for the element this view is responsible for. |
int |
viewToModel |
Deprecated. |
Methods declared in class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait | Modifier and Type | Method | Description |
|---|---|---|
protected Object |
clone() |
Creates and returns a copy of this object. |
boolean |
equals |
Indicates whether some other object is "equal to" this one. |
protected void |
finalize() |
Deprecated, for removal: This API element is subject to removal in a future version. Finalization is deprecated and subject to removal in a future release. |
final Class |
getClass() |
Returns the runtime class of this Object. |
int |
hashCode() |
Returns a hash code value for this object. |
final void |
notify() |
Wakes up a single thread that is waiting on this object's monitor. |
final void |
notifyAll() |
Wakes up all threads that are waiting on this object's monitor. |
String |
toString() |
Returns a string representation of the object. |
final void |
wait() |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
final void |
wait |
Causes the current thread to wait until it is awakened, typically by being notified or interrupted, or until a certain amount of real time has elapsed. |
Field Details
locator
protected AsyncBoxView.ChildLocator locator
Constructor Details
AsyncBoxView
public AsyncBoxView(Element elem, int axis)
- Parameters:
-
elem- the element of the model to represent -
axis- the axis to tile along. This can be either X_AXIS or Y_AXIS.
Method Details
getMajorAxis
public int getMajorAxis()
- Returns:
- the major axis
getMinorAxis
public int getMinorAxis()
- Returns:
- the minor axis
getTopInset
public float getTopInset()
- Returns:
- the top part of the margin around the view
setTopInset
public void setTopInset(float i)
- Parameters:
-
i- the value of the inset
getBottomInset
public float getBottomInset()
- Returns:
- the bottom part of the margin around the view
setBottomInset
public void setBottomInset(float i)
- Parameters:
-
i- the value of the inset
getLeftInset
public float getLeftInset()
- Returns:
- the left part of the margin around the view
setLeftInset
public void setLeftInset(float i)
- Parameters:
-
i- the value of the inset
getRightInset
public float getRightInset()
- Returns:
- the right part of the margin around the view
setRightInset
public void setRightInset(float i)
- Parameters:
-
i- the value of the inset
getInsetSpan
protected float getInsetSpan(int axis)
- 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)
- Parameters:
-
isEstimated- new value for the estimatedMajorSpan property - Since:
- 1.4
getEstimatedMajorSpan
protected boolean getEstimatedMajorSpan()
- Returns:
- whether or not the major span currently estimated
- Since:
- 1.4
getChildState
protected AsyncBoxView.ChildState getChildState(int 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()
- Returns:
- the queue to use for layout
createChildState
protected AsyncBoxView.ChildState createChildState(View v)
- Parameters:
-
v- the view - Returns:
- new child state
majorRequirementChange
protected void majorRequirementChange(AsyncBoxView.ChildState cs, float delta)
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 state -
delta- the delta
minorRequirementChange
protected void minorRequirementChange(AsyncBoxView.ChildState cs)
- Parameters:
-
cs- the child state
flushRequirementChanges
protected void flushRequirementChanges()
replace
public void replace(int offset, int length, View[] views)
loadChildren
protected void loadChildren(ViewFactory f)
setParent method. Subclasses can reimplement this to initialize their child views in a different manner. The default implementation creates a child view for each child element. Normally a write-lock is held on the Document while the children are being changed, which keeps the rendering and layout threads safe. The exception to this is when the view is initialized to represent an existing element (via this method), so it is synchronized to exclude preferenceChanged while we are initializing.
- Parameters:
-
f- the view factory - See Also:
getViewIndexAtPosition
protected int getViewIndexAtPosition(int pos, Position.Bias b)
- Parameters:
-
pos- the position >= 0 -
b- the position bias - Returns:
- index of the view representing the given position, or -1 if no view represents that position
updateLayout
protected void updateLayout(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a)
- Overrides:
-
updateLayoutin classView - Parameters:
-
ec- changes to the element this view is responsible for (may be null if there were no changes). -
e- the change information from the associated document -
a- the current allocation of the view - See Also:
setParent
public void setParent(View parent)
loadChildren method if this view does not already have children. The children should not be loaded in the constructor because the act of setting the parent may cause them to try to search up the hierarchy (to get the hosting Container for example). If this view has children (the view is being moved from one place in the view hierarchy to another), the loadChildren method will not be called.preferenceChanged
public void preferenceChanged(View child, boolean width, boolean height)
- Overrides:
-
preferenceChangedin classView - Parameters:
-
child- the child view -
width- true if the width preference has changed -
height- true if the height preference has changed - See Also:
setSize
public void setSize(float width, float height)
Since the major axis is updated asynchronously and should be the sum of the tiled children the call is ignored for the major axis. Since the minor axis is flexible, work is queued to resize the children if the minor span changes.
paint
public void paint(Graphics g, Shape alloc)
This is implemented to determine whether or not the desired region to be rendered (i.e. the unclipped area) is up to date or not. If up-to-date the children are rendered. If not up-to-date, a task to build the desired area is placed on the layout queue as a high priority task. This keeps by event thread moving by rendering if ready, and postponing until a later time if not ready (since paint requests can be rescheduled).
getPreferredSpan
public float getPreferredSpan(int axis)
- Specified by:
-
getPreferredSpanin classView - Parameters:
-
axis- may be either View.X_AXIS or View.Y_AXIS - 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.
- Throws:
-
IllegalArgumentException- for an invalid axis type
getMinimumSpan
public float getMinimumSpan(int axis)
- Overrides:
-
getMinimumSpanin classView - Parameters:
-
axis- may be either View.X_AXIS or View.Y_AXIS - 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.
- Throws:
-
IllegalArgumentException- for an invalid axis type - See Also:
getMaximumSpan
public float getMaximumSpan(int axis)
- Overrides:
-
getMaximumSpanin classView - Parameters:
-
axis- may be either View.X_AXIS or View.Y_AXIS - 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.
- Throws:
-
IllegalArgumentException- for an invalid axis type - See Also:
getViewCount
public int getViewCount()
- Overrides:
-
getViewCountin classView - Returns:
- the number of views >= 0
- See Also:
getView
getChildAllocation
public Shape getChildAllocation(int index, Shape a)
- Overrides:
-
getChildAllocationin classView - Parameters:
-
index- the index of the child, >= 0 && < getViewCount() -
a- the allocation to this view. - Returns:
- the allocation to the child
getViewIndex
public int getViewIndex(int pos, Position.Bias b)
- Overrides:
-
getViewIndexin classView - Parameters:
-
pos- the position >= 0 -
b- the bias - Returns:
- index of the view representing the given position, or -1 if no view represents that position
- Since:
- 1.3
modelToView
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException
- Specified by:
-
modelToViewin classView - Parameters:
-
pos- the position to convert >= 0 -
a- the allocated region to render into -
b- the bias toward the previous character or the next character represented by the offset, in case the position is a boundary of two views. - Returns:
- the bounding box of the given position is returned
- Throws:
-
BadLocationException- if the given position does not represent a valid location in the associated document -
IllegalArgumentException- for an invalid bias argument - See Also:
viewToModel
public int viewToModel(float x, float y, Shape a, Position.Bias[] biasReturn)
This is expected to be called by the GUI thread, holding a read-lock on the associated model. It is implemented to locate the child view and determine it's allocation with a lock on the ChildLocator object, and to call viewToModel on the child view with a lock on the ChildState object to avoid interaction with the layout thread.
- Specified by:
-
viewToModelin classView - Parameters:
-
x- the X coordinate >= 0 -
y- the Y coordinate >= 0 -
a- the allocated region to render into -
biasReturn- the returned bias - 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.
getNextVisualPositionFrom
public int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationException
BadLocationException will be thrown.- Overrides:
-
getNextVisualPositionFromin classView - Parameters:
-
pos- the position to convert -
b- the bias -
a- the allocated region to render into -
direction- 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.WESTSwingConstants.EASTSwingConstants.NORTHSwingConstants.SOUTH
-
biasRet- an array contain the bias that was checked - Returns:
- the location within the model that best represents the next location visual position
- Throws:
-
BadLocationException- the given position is not a valid position within the document -
IllegalArgumentException- ifdirectionis invalid
© 1993, 2025, Oracle and/or its affiliates. All rights reserved.
Documentation extracted from Debian's OpenJDK Development Kit package.
Licensed under the GNU General Public License, version 2, with the Classpath Exception.
Various third party code in OpenJDK is licensed under different licenses (see Debian package).
Java and OpenJDK are trademarks or registered trademarks of Oracle and/or its affiliates.