public class GapBoxView extends View implements ViewLayoutState.Parent, ViewLayoutState, EstimatedSpanView
AsyncBoxView
holding its children in GapObjectArray
and capable of posting complex layout changes
into a separate layout thread.
The operation of this view relies on the presence
of LockView
under the root view in the view hierarchy.
All the view operation is expected to be single-threaded.
The view can only work with document instances
extending AbstractDocument
The view effectively only operates with preferred spans
of its children. However it can be extended
to consider minimum and maximum spans as well
if the particular layout algorithm would require it.
This view implementation separates information
related to its children from the information required
for its own operation. The children are kept in a separate object.
The view allows to release its children after the layout information
for the whole view was determined but the view is not actively
being rendered. Releasing of the children saves memory
without loosing valuable information
about view's own layout.
The view does not initialize its children
upon call to GapBoxView.setParent(javax.swing.text.View)
thus saving memory and cpu time.
Only if it was previously asked for some information
related to children (e.g. getViewCount()
)
or for preferred, minimum or maximum span of this view
it will initialize them during setParent()
.
Once the parent view was set then the children
are populated immediately once anyone asks
for children related information or for spans.
The view can be constructed and work with element parameter being null.
The following things need to be ensured when using the view in such setup:
getDocument()
,
getStartOffset()
,
getEndOffset()
,
getAttributes()
must be overriden to not delegate to element.
insertUpdate()
and removeUpdate()
methods will not find any element changes.
reloadChildren()
should be revisited
whether it will create possible children in a proper way.
Various constraints for using of this view implementation:
ViewLayoutState.Parent.majorAxisPreferenceChanged()
synchronously.
ViewLayoutState.Parent
Modifier and Type | Field and Description |
---|---|
protected static int |
GAP_BOX_VIEW_LAST_USED_STATUS_BIT
Last bit in
statusBits used for operation
of this view. |
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
BOTTOM, CENTER, EAST, HORIZONTAL, LEADING, LEFT, NEXT, NORTH, NORTH_EAST, NORTH_WEST, PREVIOUS, RIGHT, SOUTH, SOUTH_EAST, SOUTH_WEST, TOP, TRAILING, VERTICAL, WEST
Constructor and Description |
---|
GapBoxView(Element elem,
int majorAxis)
Construct a composite box view over the given element.
|
Modifier and Type | Method and Description |
---|---|
void |
appendChildToStringBuffer(StringBuffer sb,
int childIndex,
int indent) |
void |
changedUpdate(DocumentEvent e,
Shape a,
ViewFactory f) |
String |
childrenToString() |
String |
childrenToString(int indent) |
String |
childToString(int childIndex) |
protected void |
clearStatusBits(int bits) |
protected ViewLayoutState |
createChild(View v)
New ViewLayoutState records are created through
this method to allow subclasses the extend
the ViewLayoutState records to do/hold more
|
protected View |
createCustomView(ViewFactory f,
int startOffset,
int maxEndOffset,
int elementIndex)
Create custom child view starting at
startOffset . |
protected ViewLayoutState |
createDefaultChild(View v)
Return default implementation of the view layout state wrapper.
|
protected void |
customInsertUpdate(DocumentEvent evt,
Shape a,
ViewFactory f) |
protected void |
customReloadChildren(int index,
int removeLength,
int startOffset,
int endOffset)
Loads child views in a custom way.
|
protected void |
customRemoveUpdate(DocumentEvent evt,
Shape a,
ViewFactory f) |
protected void |
directUpdateLayout()
This method is called when this view is not acting as active
layout state and its layout becomes invalid.
|
protected void |
elementReloadChildren(int index,
int removeLength,
int elementCount)
Loads child views by tracking child elements of the element
this view was created for.
|
float |
getAlignment(int axis) |
protected ViewLayoutState |
getChild(int index)
Fetch the object representing the layout state of
of the child at the given index.
|
Shape |
getChildAllocation(int index,
Shape a)
Fetches the allocation for the given child view.
|
protected int |
getChildIndex(ViewLayoutState child)
Get the index of the given child layout state in this view.
|
protected int |
getChildIndexNoCheck(ViewLayoutState child)
Get the index of the given child layout state in this view.
|
int |
getEndOffset(int childViewIndex) |
protected int[] |
getInsertUpdateRebuildOffsetRange(DocumentEvent evt)
Get the offset area in which the views should be rebuilt
in reaction to insert update in the underlying document.
|
ViewInsets |
getInsets()
Get the insets.
|
protected float |
getInsetSpan(int axis)
Get the span along an axis that is taken up by the view insets.
|
double |
getLayoutMajorAxisPreferredSpan()
Get the preferred span along major axis.
|
double |
getLayoutMajorAxisRawOffset()
Get the raw visual offset of the view along the parent view's
major axis.
|
float |
getLayoutMinorAxisAlignment()
Get alignment along the minor axis.
|
float |
getLayoutMinorAxisMaximumSpan()
Get the maximum span of the view along minor axis.
|
float |
getLayoutMinorAxisMinimumSpan()
Get the minimum span of the view along minor axis.
|
float |
getLayoutMinorAxisPreferredSpan()
Get the preferred span of the view along minor axis.
|
protected int |
getLayoutStateMajorAxis() |
protected int |
getLayoutStateMinorAxis() |
protected ViewLayoutState.Parent |
getLayoutStateParent() |
int |
getMajorAxis()
Fetch the major axis (the axis the children
are tiled along).
|
protected float |
getMajorAxisInsetSpan()
Get the span along major axis that is taken up by the view insets.
|
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 orthoginal
to the tiled axis).
|
protected float |
getMinorAxisInsetSpan()
Get the span along minor axis that is taken up by the view insets.
|
float |
getMinorAxisSpan(ViewLayoutState child)
Get span of the given child along the minor axis of this view.
|
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.
|
protected int[] |
getRemoveUpdateRebuildOffsetRange(DocumentEvent evt)
Get the offset area in which the views should be rebuilt
in reaction to insert update in the underlying document.
|
protected int |
getReplaceEstimatedThreshold()
Get minimum number of children that must be added at once
by replace() so that the addition is treated as a lengthy
operation which means that all the added children will
have the estimated span flag turned on and
#scheduleResetChildrenEstimatedSpan(int)
will be called to walk through the added children
and reset their estimated span to false. |
int |
getStartOffset(int childViewIndex) |
protected int |
getStatusBits(int bits) |
View |
getView()
Get the view that this layout state is wrapping.
|
View |
getView(int index)
Returns the view in this container with the particular index.
|
int |
getViewCount()
Returns the number of child views of this view.
|
int |
getViewIndex(int offset)
Returns the child view index representing the given position in
the model.
|
int |
getViewIndex(int offset,
Position.Bias b)
Returns the child view index representing the given position in
the model.
|
int |
getViewIndexAtPoint(float x,
float y,
Shape a)
Fetches the child view index at the given point.
|
int |
getViewRawIndex()
Get the raw index of the view (wrapped by this layout state)
in its parent view.
|
void |
insertUpdate(DocumentEvent evt,
Shape a,
ViewFactory f) |
boolean |
isActiveLayoutState() |
boolean |
isChildrenLayoutNecessary()
Test whether complete layout of the children necessary.
|
protected boolean |
isChildrenResizeDisabled()
Return true if the children should not be attempted to resize
once
setSize() is called on this view. |
boolean |
isEstimatedSpan()
Check whether this view is currently
in a mode when it just estimates its span.
|
boolean |
isFlyweight()
Check whether this layout state and its associated
view is flyweight (there is just one immutable shared instance of it).
|
protected boolean |
isLayoutMinorAxisPreferenceChanged(boolean majorAxesOrthogonal)
Test whether the preference along the layout state minor axis
has really changed.
|
boolean |
isLayoutValid()
Check whether there are any layout duties present.
|
protected boolean |
isMajorAxisPreferenceChanged() |
protected boolean |
isMinorAxisPreferenceChanged() |
boolean |
isRepaintPending() |
boolean |
isRepaintTillEnd() |
protected boolean |
isStatusBitsNonZero(int bits) |
protected boolean |
isXLayoutStateMajorAxis() |
void |
layoutInvalid(ViewLayoutState child)
Called by children to mark layout of this view invalid.
|
void |
majorAxisPreferenceChanged(ViewLayoutState child,
double majorAxisSpanDelta)
Preference of one of the children has changed along the major axis.
|
void |
markChildrenLayoutNecessary()
Mark that a complete layout of children is necessary.
|
protected void |
markLayoutInvalid() |
protected void |
markMajorAxisPreferenceChanged() |
protected void |
markMinorAxisPreferenceChanged() |
protected boolean |
markRepaint(int childIndex,
boolean repaintTillEnd)
Mark that the child with the given index should be repainted.
|
protected void |
markRepaintPending() |
protected void |
markSizeInvalid(int childIndex,
int count)
This method marks sizes of all the children as invalid
so the next layout update will resize each children.
|
void |
markViewSizeInvalid()
Parent calls this method to mark the current size of the view as invalid
so that the next layout update of this layout state
will call
View.setSize()
using ViewLayoutState.getLayoutMajorAxisPreferredSpan() for major axis span
and ViewLayoutState.Parent.getMinorAxisSpan(ViewLayoutState)
for minor axis span. |
void |
minorAxisPreferenceChanged(ViewLayoutState child)
Preference of one of the children has 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 |
offsetRebuild(int startOffset,
int endOffset)
Rebuild based on specification of the offset range.
|
void |
paint(Graphics g,
Shape a)
Render the view using the given allocation and
rendering surface.
|
void |
preferenceChanged(View childView,
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.
|
protected void |
processRepaint(ViewLayoutState.Parent lsParent)
Process pending repaint requests from children.
|
protected Rectangle |
reallocate(Shape a)
Reallocate the view to the new size given by the passed shape.
|
void |
rebuild(int index,
int count)
Remove the child views in the given index range
and let the default building mechanism to build the child views.
|
void |
releaseChildren()
Ask for releasing of the children.
|
protected void |
reloadChildren(int index,
int removeLength,
int startOffset,
int endOffset)
Load the children in the selected range of offsets.
|
void |
removeUpdate(DocumentEvent evt,
Shape a,
ViewFactory f) |
void |
repaint(ViewLayoutState child,
double majorAxisOffset,
double majorAxisSpan,
float minorAxisOffset,
float minorAxisSpan)
Inform the parent that the child layout state needs a repaint.
|
void |
replace(int index,
int length,
View[] views) |
protected void |
resetAxesPreferenceChanged() |
protected void |
resetEstimatedSpan(int childIndex,
int count)
Set estimated span flag to false on the given children views.
|
protected void |
resetRepaintPending() |
ViewLayoutState |
selectLayoutMajorAxis(int axis)
Select which axis will be used as major axis by this layout state.
|
void |
setEstimatedSpan(boolean estimatedSpan)
Set whether this view uses estimated span computation
instead of exact measurements.
|
void |
setLayoutMajorAxisRawOffset(double majorAxisRawOffset)
Parent can set the view's raw offset along the parent view's
major axis using this method.
|
void |
setParent(View parent)
Sets the parent of the view.
|
void |
setSize(float width,
float height)
Sets the size of the view.
|
protected void |
setSpanOnMajorAxis(float targetMajorAxisSpan) |
protected void |
setSpanOnMinorAxis(float targetMinorAxisSpan) |
protected void |
setStatusBits(int bits) |
void |
setViewRawIndex(int viewRawIndex)
Parent can set the index of the view (wrapped by this layout state)
in itself.
|
String |
toString() |
protected void |
unloadChildren()
Subclasses may override this method and deallocate resources
bound to presence of children.
|
void |
updateLayout()
Do actual layout updating.
|
protected void |
updateLayout(DocumentEvent.ElementChange ec,
DocumentEvent e,
Shape a)
Update the layout in response to receiving notification of
change from the model.
|
protected boolean |
useCustomReloadChildren() |
void |
viewPreferenceChanged(boolean width,
boolean height)
Notify this layout state that the preferences has changed
for the view that it wraps.
|
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.
|
append, breakView, createFragment, forwardUpdate, forwardUpdateToView, getAttributes, getBreakWeight, getContainer, getDocument, getElement, getEndOffset, getGraphics, getParent, getResizeWeight, getStartOffset, getToolTipText, getViewFactory, getViewIndex, insert, isVisible, modelToView, modelToView, remove, removeAll, updateChildren, viewToModel
protected static final int GAP_BOX_VIEW_LAST_USED_STATUS_BIT
statusBits
used for operation
of this view. Subclasses may use higher bits if they want.public GapBoxView(Element elem, int majorAxis)
elem
- the element of the model to represent.majorAxis
- the axis to tile along. This can be
either X_AXIS or Y_AXIS.public float getPreferredSpan(int axis)
getPreferredSpan
in class View
axis
- may be either View.X_AXIS or View.Y_AXISIllegalArgumentException
- for an invalid axis typepublic float getMinimumSpan(int axis)
getMinimumSpan
in class View
axis
- may be either View.X_AXIS
or
View.Y_AXIS
public float getMaximumSpan(int axis)
getMaximumSpan
in class View
axis
- may be either View.X_AXIS
or
View.Y_AXIS
public float getAlignment(int axis)
getAlignment
in class View
public ViewInsets getInsets()
public final int getMajorAxis()
public final int getMinorAxis()
public int getViewCount()
getViewCount
in class View
GapBoxView.getView(int)
public View getView(int index)
protected int getReplaceEstimatedThreshold()
#scheduleResetChildrenEstimatedSpan(int)
will be called to walk through the added children
and reset their estimated span to false.public final boolean isEstimatedSpan()
EstimatedSpanView
isEstimatedSpan
in interface EstimatedSpanView
public void setEstimatedSpan(boolean estimatedSpan)
EstimatedSpanView
setEstimatedSpan
in interface EstimatedSpanView
estimatedSpan
- whether view will estimate
the spans or use exact measurements.protected void resetEstimatedSpan(int childIndex, int count)
setEstimatedSpan()
and from children.replace()
if the number of added
children exceeds threshold count.
public void rebuild(int index, int count)
It is necessary to call updateLayout()
on this view at some point later so that the possible
layout changes are done.
index
- index of the first child view to be rebuiltcount
- number of chilren in the children array to be rebuilt.
If index + count
is past the end of the children available
the value of count will be decreased accordingly.public void offsetRebuild(int startOffset, int endOffset)
startOffset
- starting offset of the area in which the views
should be rebuilt.endOffset
- ending offset of the area in which the views
should be rebuilt.public void setParent(View parent)
getViewCount()
)
or for preferred, minimum or maximum span of this view.public final boolean isActiveLayoutState()
public void releaseChildren()
public final View getView()
ViewLayoutState
getView
in interface ViewLayoutState
public ViewLayoutState selectLayoutMajorAxis(int axis)
ViewLayoutState
selectLayoutMajorAxis
in interface ViewLayoutState
axis
- major axis either View.X_AXIS
or View.Y_AXIS
.
A view (e.g. a flyweight view)
that implements this interface can decide to only allow
one axis as the major one.
That should mostly be fine because usually the view is tiled
only along one axis.
The view may throw IllegalStateException
in such case.
public boolean isFlyweight()
ViewLayoutState
isFlyweight
in interface ViewLayoutState
public void updateLayout()
ViewLayoutState
View.setSize()
being called on them
by changing its preferred span along an axis.
For such views the actual internal updating must be done twice
(because of another call to parent.preferenceChanged()
).
ViewLayoutState.isLayoutValid()
must return true.
updateLayout
in interface ViewLayoutState
protected void updateLayout(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a)
updateLayout
in class View
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 documenta
- the current allocation of the viewGapBoxView.insertUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
,
GapBoxView.removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
,
GapBoxView.changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
public void layoutInvalid(ViewLayoutState child)
layoutInvalid
in interface ViewLayoutState.Parent
protected void markLayoutInvalid()
protected void directUpdateLayout()
protected void processRepaint(ViewLayoutState.Parent lsParent)
protected boolean markRepaint(int childIndex, boolean repaintTillEnd)
childIndex
- index of child that should be marked for repaint.repaintTillEnd
- if set to true then all children following
the child should be repainted as well.public final boolean isRepaintPending()
protected final void markRepaintPending()
protected void resetRepaintPending()
public final boolean isRepaintTillEnd()
protected boolean isLayoutMinorAxisPreferenceChanged(boolean majorAxesOrthogonal)
public boolean isLayoutValid()
ViewLayoutState
isLayoutValid
in interface ViewLayoutState
true
here.public double getLayoutMajorAxisPreferredSpan()
ViewLayoutState
If the preferred span of the wrapped view changes
then the value of the major axis span must change as well
typically once the next layout state update takes place.
The wrapped view should call View.preferenceChanged
in its parent once its preferred span changes.
The parent view will later call
i.e. updateLayout()
to update
the variable holding the preferred span along major axis.
Parent.majorAxisPreferenceChanged()
must be called immediately after that change
to notify the parent.
Although the value is returned as double
(see ViewLayoutState.getLayoutMajorAxisRawOffset()
)
it can be maintained as float if the resolution of the float
is sufficient to create proper deltas
in Parent#majorAxisPreferenceChanged()
.
For example if a document has millions of lines it's necessary
to maintain line offsets in document view as doubles
but assuming that each line is only up to several tenths of pixels high
it's enough to hold line height as float in line view layout state.
getLayoutMajorAxisPreferredSpan
in interface ViewLayoutState
public float getLayoutMinorAxisPreferredSpan()
ViewLayoutState
If there is a dedicated variable for this value then
that variable should be updated during ViewLayoutState.updateLayout()
which usually happens some time after the view
has called View.preferenceChanged()
in the parent.
After the value gets updated the layout state must immediately call
Parent.minorAxisPreferenceChanged()
to notify the parent about the change of minor span.
getLayoutMinorAxisPreferredSpan
in interface ViewLayoutState
public float getLayoutMinorAxisMinimumSpan()
ViewLayoutState
GapBoxView
implementations
do not use the minimum span of their children
so the particular layout state may decide not to cache
the minimum span value and return preferred span instead
to save memory that would otherwise be used for caching variables.
If there is a dedicated variable for this value then
that variable should be updated during ViewLayoutState.updateLayout()
which usually happens once the view
has called View.preferenceChanged()
in the parent.
After the value gets updated the layout state must immediately call
Parent.minorAxisPreferenceChanged()
to notify the parent about the change of minor span.
getLayoutMinorAxisMinimumSpan
in interface ViewLayoutState
public float getLayoutMinorAxisMaximumSpan()
ViewLayoutState
GapBoxView
implementations
do not use the maximum span of their children
the particular layout state may decide not to cache
the maximum span value and return preferred span instead
to save memory that would otherwise be used for caching variables.
If there is a dedicated variable for this value then
that variable gets updated by ViewLayoutState.updateLayout()
which usually happens once the view
has called View.preferenceChanged()
in the parent.
After the value gets updated the layout state must immediately call
Parent.minorAxisPreferenceChanged()
to notify the parent about the change of minor span.
getLayoutMinorAxisMaximumSpan
in interface ViewLayoutState
public float getLayoutMinorAxisAlignment()
ViewLayoutState
If there is a dedicated variable for this value then
that variable gets updated by ViewLayoutState.updateLayout()
which usually happens once the view
has called View.preferenceChanged()
in its parent view which in turn calls ViewLayoutState.viewPreferenceChanged(boolean,boolean)
.
After the value gets updated the layout state must call
Parent.minorAxisPreferenceChanged()
to notify the parent about the change of minor span.
getLayoutMinorAxisAlignment
in interface ViewLayoutState
public double getLayoutMajorAxisRawOffset()
ViewLayoutState
Double is chosen instead of float because for y as major axis
the truncation could occur when computing the offset
for large files with many lines or for very long lines.
The resolution of mantissa of floats is 23 bits
so assuming the line height is e.g. 17 pixels
and we have more than 250.000 lines in the docuemnt
(which is a lot to write but not so much for e.g.
generated xml files) the last bit would be lost
resulting in every odd line being shifted one
pixel above incorrectly.
The views can still decide to use floats for internal storage
of this value if the precision is sufficient.
getLayoutMajorAxisRawOffset
in interface ViewLayoutState
public void setLayoutMajorAxisRawOffset(double majorAxisRawOffset)
ViewLayoutState
setLayoutMajorAxisRawOffset
in interface ViewLayoutState
majorAxisRawOffset
- raw offset value along the major axis.
It is not particularly useful without postprocessing by the parent.protected final ViewLayoutState.Parent getLayoutStateParent()
protected final boolean isXLayoutStateMajorAxis()
protected final int getLayoutStateMajorAxis()
protected final int getLayoutStateMinorAxis()
public int getViewRawIndex()
ViewLayoutState
getViewRawIndex
in interface ViewLayoutState
public void setViewRawIndex(int viewRawIndex)
ViewLayoutState
setViewRawIndex
in interface ViewLayoutState
viewRawIndex
- raw index value. It can differ from
the real index because parent could preprocess
it because of possible use of a gap translation.public void viewPreferenceChanged(boolean width, boolean height)
ViewLayoutState
View.preferenceChanged()
in its parent.
viewPreferenceChanged
in interface ViewLayoutState
width
- true if the width preference has changedheight
- true if the height preference has changedpublic void markViewSizeInvalid()
ViewLayoutState
View.setSize()
using ViewLayoutState.getLayoutMajorAxisPreferredSpan()
for major axis span
and ViewLayoutState.Parent.getMinorAxisSpan(ViewLayoutState)
for minor axis span.
markViewSizeInvalid
in interface ViewLayoutState
public void majorAxisPreferenceChanged(ViewLayoutState child, double majorAxisSpanDelta)
majorAxisPreferenceChanged
in interface ViewLayoutState.Parent
child
- child layout state which preference has changed.majorAxisSpanDelta
- delta between the new span and the original span.public void minorAxisPreferenceChanged(ViewLayoutState child)
minorAxisPreferenceChanged
in interface ViewLayoutState.Parent
child
- child layout state which preference has changed.public float getMinorAxisSpan(ViewLayoutState child)
getMinorAxisSpan
in interface ViewLayoutState.Parent
child
- child layout state for which the span is being
determined.public void repaint(ViewLayoutState child, double majorAxisOffset, double majorAxisSpan, float minorAxisOffset, float minorAxisSpan)
ViewLayoutState.Parent
updateLayout()
.
repaint
in interface ViewLayoutState.Parent
child
- child that needs its area to be repainted.majorAxisOffset
- offset along the major axis defining
the begining of the repaint region. If the allocation
has changed along the major axis the view is fully repainted
(see majorAxisPreferenceChanged()
).
majorAxisSpan
- span along the major axis
that should be repainted. If it is set to zero then
it means that the end of the repaint region along the major axis
span is determined by the span allocated for the child
in this parent.minorAxisOffset
- offset along the minor axis
defining the begining of the repaint region.minorAxisSpan
- span along the minor axis
that should be repainted. If it is set to zero then
it means that the end of the repaint region along the minor axis
span is determined by the span of this parent.public final boolean isChildrenLayoutNecessary()
public final void markChildrenLayoutNecessary()
public void preferenceChanged(View childView, boolean width, boolean height)
preferenceChanged
in class View
childView
- the child view of this view or null to signal
change in this view.width
- true if the width preference has changedheight
- true if the height preference has changedJComponent.revalidate()
public void setSize(float width, float height)
The propagation of this operation to child views can be done asynchronously if appropriate.
protected void setSpanOnMajorAxis(float targetMajorAxisSpan)
protected void setSpanOnMinorAxis(float targetMinorAxisSpan)
protected void markSizeInvalid(int childIndex, int count)
count
- >0 total number of child views of this view. It's given
as parameter because subclasses will typically decide their
behavior based on the total view count.protected boolean isChildrenResizeDisabled()
setSize()
is called on this view.
setSize()
e.g. this should *not* be used if line-wrapping is turned on.public Shape getChildAllocation(int index, Shape a)
getChildAllocation
in class View
index
- the index of the child, >= 0 and < getViewCount()a
- the allocation to this view.public int getViewIndexAtPoint(float x, float y, Shape a)
x
- the X coordinate >= 0y
- the Y coordinate >= 0a
- the allocation to thid viewpublic int getViewIndex(int offset, Position.Bias b)
getViewIndex
in class View
offset
- the position >= 0.b
- either forward or backward bias.public int getViewIndex(int offset)
offset
- the position >= 0.public void paint(Graphics g, Shape a)
paint
in class View
g
- the rendering surface to usea
- the allocated region to render intoView.paint(java.awt.Graphics, java.awt.Shape)
public Shape modelToView(int pos, Shape a, Position.Bias b) throws BadLocationException
modelToView
in class View
pos
- the position to convert >= 0a
- the allocated region to render intob
- the bias toward the previous character or the
next character represented by the offset, in case the
position is a boundary of two views.BadLocationException
- if the given position does
not represent a valid location in the associated documentIllegalArgumentException
- for an invalid bias argumentView.viewToModel(float, float, java.awt.Shape, javax.swing.text.Position.Bias[])
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 ViewLayoutState object to avoid interaction with the layout thread.
viewToModel
in class View
x
- the X coordinate >= 0y
- the Y coordinate >= 0a
- the allocated region to render intopublic int getNextVisualPositionFrom(int pos, Position.Bias b, Shape a, int direction, Position.Bias[] biasRet) throws BadLocationException
getNextVisualPositionFrom
in class View
pos
- the position to convert >= 0a
- the allocated region to render intodirection
- 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:
biasRet
- an array contain the bias that was checkedBadLocationException
IllegalArgumentException
- if direction
is invalidprotected final ViewLayoutState getChild(int index)
index
- the child index.
This must be a value >= 0 and < getViewCount().IndexOutOfBoundsException
- in case the index was invalid.protected final int getChildIndex(ViewLayoutState child)
child
- layout state which index in this view should be found.protected final int getChildIndexNoCheck(ViewLayoutState child)
child
- layout state which index in this view should be found.protected boolean useCustomReloadChildren()
public void insertUpdate(DocumentEvent evt, Shape a, ViewFactory f)
insertUpdate
in class View
protected void customInsertUpdate(DocumentEvent evt, Shape a, ViewFactory f)
protected int[] getInsertUpdateRebuildOffsetRange(DocumentEvent evt)
evt
- document event for the document modification.null
in case
no views should be rebuilt.public void removeUpdate(DocumentEvent evt, Shape a, ViewFactory f)
removeUpdate
in class View
protected void customRemoveUpdate(DocumentEvent evt, Shape a, ViewFactory f)
protected int[] getRemoveUpdateRebuildOffsetRange(DocumentEvent evt)
evt
- document event for the document modification.null
in case
no views should be rebuilt.public void changedUpdate(DocumentEvent e, Shape a, ViewFactory f)
changedUpdate
in class View
protected void reloadChildren(int index, int removeLength, int startOffset, int endOffset)
index
- index at which the views should be added/replaced.removeLength
- number of removed children views. It is useful
when rebuilding children for a portion of the view.startOffset
- starting offset of the loading. It can be -1
to indicate the loading from View.getStartOffset()
.endOffset
- ending offset of the loading. It can be -1
to indicate the loading till View.getEndOffset()
.protected void elementReloadChildren(int index, int removeLength, int elementCount)
index
- index at which the views should be added/replaced.removeLength
- number of removed children views. It is useful
when rebuilding children for a portion of the view.elementCount
- number of elements for which the views should be created.protected void customReloadChildren(int index, int removeLength, int startOffset, int endOffset)
index
- index at which the views should be added/replaced.removeLength
- number of removed children views. It is useful
when rebuilding children for a portion of the view.startOffset
- starting offset from which the loading starts.endOffset
- ending offset where the loading ends.protected View createCustomView(ViewFactory f, int startOffset, int maxEndOffset, int elementIndex)
startOffset
.f
- view factory to be used.startOffset
- offset at which the created view must start.maxEndOffset
- maximum ending offset to which the created view
may span.elementIndex
- index of the child element that best represents
the startOffset. The element is child of the element that this view
is responsible for. If this view is not based by element then this
parameter will be -1.protected void unloadChildren()
GapBoxView.releaseChildren()
to unallocate
the resources for children.
Once this method finishes all the children will be set null as a parent and the reference to children will be cleared.
protected ViewLayoutState createChild(View v)
protected ViewLayoutState createDefaultChild(View v)
protected final boolean isMajorAxisPreferenceChanged()
protected void markMajorAxisPreferenceChanged()
protected final boolean isMinorAxisPreferenceChanged()
protected void markMinorAxisPreferenceChanged()
protected final void resetAxesPreferenceChanged()
protected final float getInsetSpan(int axis)
axis
- the axis to determine the total insets along,
either X_AXIS or Y_AXIS.protected final float getMajorAxisInsetSpan()
protected final float getMinorAxisInsetSpan()
protected final int getStatusBits(int bits)
protected final boolean isStatusBitsNonZero(int bits)
protected final void setStatusBits(int bits)
protected final void clearStatusBits(int bits)
protected Rectangle reallocate(Shape a)
a
- shape to which to reallocate the view.public int getStartOffset(int childViewIndex)
public int getEndOffset(int childViewIndex)
public String childToString(int childIndex)
public void appendChildToStringBuffer(StringBuffer sb, int childIndex, int indent)
public String childrenToString()
public String childrenToString(int indent)