- 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 SummaryNested Classes Modifier and Type Class Description classAsyncBoxView.ChildLocatorA class to manage the effective position of the child views in a localized area while changes are being made around the localized area.classAsyncBoxView.ChildStateA record representing the layout state of a child view.
- 
Field SummaryFields Modifier and Type Field Description protected AsyncBoxView.ChildLocatorlocatorObject that manages the offsets of the children.Fields declared in class javax.swing.text.ViewBadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXISFields declared in interface javax.swing.SwingConstantsBOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
- 
Constructor SummaryConstructors Constructor Description AsyncBoxView(Element elem, int axis)Construct a box view that does asynchronous layout.
- 
Method SummaryModifier and Type Method Description protected AsyncBoxView.ChildStatecreateChildState(View v)New ChildState records are created through this method to allow subclasses the extend the ChildState records to do/hold more.protected voidflushRequirementChanges()Publish the changes in preferences upward to the parent view.floatgetBottomInset()Get the bottom part of the margin around the view.ShapegetChildAllocation(int index, Shape a)Fetches the allocation for the given child view.protected AsyncBoxView.ChildStategetChildState(int index)Fetch the object representing the layout state of of the child at the given index.protected booleangetEstimatedMajorSpan()Is the major span currently estimated?protected floatgetInsetSpan(int axis)Fetch the span along an axis that is taken up by the insets.protected LayoutQueuegetLayoutQueue()Fetch the queue to use for layout.floatgetLeftInset()Get the left part of the margin around the view.intgetMajorAxis()Fetch the major axis (the axis the children are tiled along).floatgetMaximumSpan(int axis)Determines the maximum span for this view along an axis.floatgetMinimumSpan(int axis)Determines the minimum span for this view along an axis.intgetMinorAxis()Fetch the minor axis (the axis orthogonal to the tiled axis).intgetNextVisualPositionFrom(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.floatgetPreferredSpan(int axis)Determines the preferred span for this view along an axis.floatgetRightInset()Get the right part of the margin around the view.floatgetTopInset()Get the top part of the margin around the view.ViewgetView(int n)Gets the nth child view.intgetViewCount()Returns the number of views in this view.intgetViewIndex(int pos, Position.Bias b)Returns the child view index representing the given position in the model.protected intgetViewIndexAtPosition(int pos, Position.Bias b)Fetches the child view index representing the given position in the model.protected voidloadChildren(ViewFactory f)Loads all of the children to initialize the view.protected voidmajorRequirementChange(AsyncBoxView.ChildState cs, float delta)Requirements changed along the major axis.protected voidminorRequirementChange(AsyncBoxView.ChildState cs)Requirements changed along the minor axis.ShapemodelToView(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.voidpaint(Graphics g, Shape alloc)Render the view using the given allocation and rendering surface.voidpreferenceChanged(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.voidreplace(int offset, int length, View[] views)Calls the superclass to update the child views, and updates the status records for the children.voidsetBottomInset(float i)Set the bottom part of the margin around the view.protected voidsetEstimatedMajorSpan(boolean isEstimated)Set the estimatedMajorSpan property that determines if the major span should be treated as being estimated.voidsetLeftInset(float i)Set the left part of the margin around the view.voidsetParent(View parent)Sets the parent of the view.voidsetRightInset(float i)Set the right part of the margin around the view.voidsetSize(float width, float height)Sets the size of the view.voidsetTopInset(float i)Set the top part of the margin around the view.protected voidupdateLayout(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a)Update the layout in response to receiving notification of change from the model.intviewToModel(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.Viewappend, 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 Details- 
locatorObject that manages the offsets of the children. All locking for management of child locations is on this object.
 
- 
- 
Constructor Details- 
AsyncBoxViewConstruct a box view that does asynchronous layout.- 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- 
getMajorAxispublic 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
 
- 
getMinorAxispublic 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
 
- 
getTopInsetpublic float getTopInset()Get the top part of the margin around the view.- Returns:
- the top part of the margin around the view
 
- 
setTopInsetpublic void setTopInset(float i)Set the top part of the margin around the view.- Parameters:
- i- the value of the inset
 
- 
getBottomInsetpublic float getBottomInset()Get the bottom part of the margin around the view.- Returns:
- the bottom part of the margin around the view
 
- 
setBottomInsetpublic void setBottomInset(float i)Set the bottom part of the margin around the view.- Parameters:
- i- the value of the inset
 
- 
getLeftInsetpublic float getLeftInset()Get the left part of the margin around the view.- Returns:
- the left part of the margin around the view
 
- 
setLeftInsetpublic void setLeftInset(float i)Set the left part of the margin around the view.- Parameters:
- i- the value of the inset
 
- 
getRightInsetpublic float getRightInset()Get the right part of the margin around the view.- Returns:
- the right part of the margin around the view
 
- 
setRightInsetpublic void setRightInset(float i)Set the right part of the margin around the view.- Parameters:
- i- the value of the inset
 
- 
getInsetSpanprotected 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
 
- 
setEstimatedMajorSpanprotected 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
 
- 
getEstimatedMajorSpanprotected boolean getEstimatedMajorSpan()Is the major span currently estimated?- Returns:
- whether or not the major span currently estimated
- Since:
- 1.4
 
- 
getChildStateFetch 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
 
- 
getLayoutQueueFetch the queue to use for layout.- Returns:
- the queue to use for layout
 
- 
createChildStateNew 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
 
- 
majorRequirementChangeRequirements 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 state
- delta- the delta
 
- 
minorRequirementChangeRequirements 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
 
- 
flushRequirementChangesprotected void flushRequirementChanges()Publish the changes in preferences upward to the parent view. This is normally called by the layout thread.
- 
replaceCalls the superclass to update the child views, and updates the status records for the children. This is expected to be called while a write lock is held on the model so that interaction with the layout thread will not happen (i.e. the layout thread acquires a read lock before doing anything).
- 
loadChildrenLoads all of the children to initialize the view. This is called by thesetParentmethod. 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:
- setParent(javax.swing.text.View)
 
- 
getViewIndexAtPositionFetches the child view index representing the given position in the model. This is implemented to fetch the view in the case where there is a child view for each child element.- 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
 
- 
updateLayoutUpdate the layout in response to receiving notification of change from the model. This is implemented to note the change on the ChildLocator so that offsets of the children will be correctly computed.- Overrides:
- updateLayoutin class- View
- 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:
- View.insertUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory),- View.removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory),- View.changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
 
- 
setParentSets the parent of the view. This is reimplemented to provide the superclass behavior as well as calling theloadChildrenmethod 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), theloadChildrenmethod will not be called.
- 
preferenceChangedChild views can call this on the parent to indicate that the preference has changed and should be reconsidered for layout. This is reimplemented to queue new work on the layout thread. This method gets messaged from multiple threads via the children.- Overrides:
- preferenceChangedin class- View
- Parameters:
- child- the child view
- width- true if the width preference has changed
- height- true if the height preference has changed
- See Also:
- JComponent.revalidate()
 
- 
setSizepublic void setSize(float width, float height)Sets the size of the view. This should cause layout of the view if the view caches any layout information.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. 
- 
paintRender the view using the given allocation and rendering surface.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). - Specified by:
- paintin class- View
- Parameters:
- g- the rendering surface to use
- alloc- the allocated region to render into
- See Also:
- View.paint(java.awt.Graphics, java.awt.Shape)
 
- 
getPreferredSpanpublic float getPreferredSpan(int axis)Determines the preferred span for this view along an axis.- Specified by:
- getPreferredSpanin class- View
- 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
 
- 
getMinimumSpanpublic float getMinimumSpan(int axis)Determines the minimum span for this view along an axis.- Overrides:
- getMinimumSpanin class- View
- 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:
- View.getPreferredSpan(int)
 
- 
getMaximumSpanpublic float getMaximumSpan(int axis)Determines the maximum span for this view along an axis.- Overrides:
- getMaximumSpanin class- View
- 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:
- View.getPreferredSpan(int)
 
- 
getViewCountpublic int getViewCount()Returns the number of views in this view. Since the default is to not be a composite view this returns 0.- Overrides:
- getViewCountin class- View
- Returns:
- the number of views >= 0
- See Also:
- View.getViewCount()
 
- 
getViewGets the nth child view. Since there are no children by default, this returns null.
- 
getChildAllocationFetches the allocation for the given child view. This enables finding out where various views are located, without assuming the views store their location. This returns null since the default is to not have any child views.- Overrides:
- getChildAllocationin class- View
- Parameters:
- index- the index of the child, >= 0 && < getViewCount()
- a- the allocation to this view.
- Returns:
- the allocation to the child
 
- 
getViewIndexReturns the child view index representing the given position in the model. By default a view has no children so this is implemented to return -1 to indicate there is no valid child index for any position.- Overrides:
- getViewIndexin class- View
- 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
 
- 
modelToViewProvides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.- Specified by:
- modelToViewin class- View
- 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:
- View.viewToModel(float, float, java.awt.Shape, javax.swing.text.Position.Bias[])
 
- 
viewToModelProvides a mapping from the view coordinate space to the logical coordinate space of the model. 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.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 class- View
- 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.
 
- 
getNextVisualPositionFrompublic int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationExceptionProvides a way to determine the next visually represented model location that one might place a caret. Some views may not be visible, they might not be in the same order found in the model, or they just might not allow access to some of the locations in the model. This method enables specifying a position to convert within the range of >=0. If the value is -1, a position will be calculated automatically. If the value < -1, theBadLocationExceptionwill be thrown.- Overrides:
- getNextVisualPositionFromin class- View
- Parameters:
- pos- the position to convert
- 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.WEST
- SwingConstants.EAST
- SwingConstants.NORTH
- SwingConstants.SOUTH
 
- biasRet- an array contain the bias that was checked
- b- the bias
- 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- if- directionis invalid
 
 
-