站内搜索: 请输入搜索关键词
当前页面: 在线文档首页 > NetBeans API Javadoc (Current Development Version)

GapBoxView (Editor Library) - NetBeans API Javadoc (Current Development Version)

org.netbeans.modules.editor.lib/1 1.14.0 3

org.netbeans.lib.editor.view
Class GapBoxView

java.lang.Object
  extended by javax.swing.text.View
      extended by org.netbeans.lib.editor.view.GapBoxView
All Implemented Interfaces:
SwingConstants, EstimatedSpanView, ViewLayoutState, ViewLayoutState.Parent
Direct Known Subclasses:
GapDocumentView, GapLineView, GapMultiLineView

public class GapBoxView
extends View
implements ViewLayoutState.Parent, ViewLayoutState, EstimatedSpanView

Composite view implementation inspired by the AsyncBoxView holding its children in GapObjectArray and capable of posting complex layout changes into a separate layout thread.
This implementation is synchronous by default but it contains hooks where the asynchronous behavior can be installed.

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 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:

Various constraints for using of this view implementation:


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.netbeans.editor.view.spi.ViewLayoutState
ViewLayoutState.Parent
 
Field Summary
protected static int GAP_BOX_VIEW_LAST_USED_STATUS_BIT
          Last bit in statusBits used for operation of this view.
 
Fields inherited from class javax.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
 
Fields inherited from 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
GapBoxView(Element elem, int majorAxis)
          Construct a composite box view over the given element.
 
Method Summary
 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  org.netbeans.lib.editor.view.GapBoxViewChildren createChildren()
          Can be overriden by subclasses to return a different children implementation.
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.
protected  org.netbeans.lib.editor.view.GapBoxViewChildren getChildren()
           
protected  org.netbeans.lib.editor.view.GapBoxViewChildren getChildrenNull()
          Get children or null if the children were not yet initialized.
 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.
 
Methods inherited from class javax.swing.text.View
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
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

GAP_BOX_VIEW_LAST_USED_STATUS_BIT

protected static final int GAP_BOX_VIEW_LAST_USED_STATUS_BIT
Last bit in statusBits used for operation of this view. Subclasses may use higher bits if they want.

See Also:
Constant Field Values
Constructor Detail

GapBoxView

public GapBoxView(Element elem,
                  int majorAxis)
Construct a composite box view over the given element.

Parameters:
elem - the element of the model to represent.
majorAxis - the axis to tile along. This can be either X_AXIS or Y_AXIS.
Method Detail

getPreferredSpan

public float getPreferredSpan(int axis)
Determines the preferred span for this view along an axis.

Specified by:
getPreferredSpan in 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

getMinimumSpan

public float getMinimumSpan(int axis)
Determines the minimum span for this view along an axis.

Overrides:
getMinimumSpan in class View
Parameters:
axis - may be either View.X_AXIS or View.Y_AXIS
Returns:
the minimum span the view can be rendered into

getMaximumSpan

public float getMaximumSpan(int axis)
Determines the maximum span for this view along an axis.

Overrides:
getMaximumSpan in class View
Parameters:
axis - may be either View.X_AXIS or View.Y_AXIS
Returns:
the maximum span the view can be rendered into

getAlignment

public float getAlignment(int axis)
Overrides:
getAlignment in class View

getInsets

public ViewInsets getInsets()
Get the insets. The default implementation here only returns null but it can be redefined by subclasses.

Returns:
insets of this view or null for no insets.

getMajorAxis

public final 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.


getMinorAxis

public final int getMinorAxis()
Fetch the minor axis (the axis orthoginal to the tiled axis). This will have a value of either X_AXIS or Y_AXIS.


getViewCount

public int getViewCount()
Returns the number of child views of this view.

Overrides:
getViewCount in class View
Returns:
the number of views >= 0
See Also:
getView(int)

getView

public View getView(int index)
Returns the view in this container with the particular index.

Overrides:
getView in class View
Parameters:
index - index of the desired view, >= 0 and < getViewCount()
Returns:
the view at index index

replace

public void replace(int index,
                    int length,
                    View[] views)
Overrides:
replace in class View

getReplaceEstimatedThreshold

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.


isEstimatedSpan

public final boolean isEstimatedSpan()
Description copied from interface: EstimatedSpanView
Check whether this view is currently in a mode when it just estimates its span.

Specified by:
isEstimatedSpan in interface EstimatedSpanView
Returns:
true if the view estimates its preferred horizontal and vertical preferred, maximum and minimum spans. Returns false if the view measurements are exact.

setEstimatedSpan

public void setEstimatedSpan(boolean estimatedSpan)
Description copied from interface: EstimatedSpanView
Set whether this view uses estimated span computation instead of exact measurements.

Specified by:
setEstimatedSpan in interface EstimatedSpanView
Parameters:
estimatedSpan - whether view will estimate the spans or use exact measurements.

resetEstimatedSpan

protected void resetEstimatedSpan(int childIndex,
                                  int count)
Set estimated span flag to false on the given children views.
This method is called from both setEstimatedSpan() and from children.replace() if the number of added children exceeds threshold count.
Subclasses may want to do this on the background.


rebuild

public 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.

It is necessary to call updateLayout() on this view at some point later so that the possible layout changes are done.

Parameters:
index - index of the first child view to be rebuilt
count - 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.

offsetRebuild

public void offsetRebuild(int startOffset,
                          int endOffset)
Rebuild based on specification of the offset range.

Parameters:
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.

setParent

public void setParent(View parent)
Sets the parent of the view. The children are only initialized if someone has previously asked for information related to children (e.g. getViewCount()) or for preferred, minimum or maximum span of this view.

Overrides:
setParent in class View
Parameters:
parent - the parent of the view, null if none

isActiveLayoutState

public final boolean isActiveLayoutState()

getChildren

protected org.netbeans.lib.editor.view.GapBoxViewChildren getChildren()

getChildrenNull

protected final org.netbeans.lib.editor.view.GapBoxViewChildren getChildrenNull()
Get children or null if the children were not yet initialized.


releaseChildren

public void releaseChildren()
Ask for releasing of the children. The view will still remember the last allocated size and preferred, minimum and maximum spans. However various operations like painting or translations between model and visual positions will make the children to be loaded again.


getView

public final View getView()
Description copied from interface: ViewLayoutState
Get the view that this layout state is wrapping.

Specified by:
getView in interface ViewLayoutState
Returns:
view that this layout state is wrapping.

selectLayoutMajorAxis

public ViewLayoutState selectLayoutMajorAxis(int axis)
Description copied from interface: ViewLayoutState
Select which axis will be used as major axis by this layout state.

Specified by:
selectLayoutMajorAxis in interface ViewLayoutState
Parameters:
axis - major axis either View.X_AXIS or View.Y_AXIS.
Returns:
either this layout state if this state is able to work with the given major axis or another layout state if this state is only able to work over the other major 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.


isFlyweight

public boolean isFlyweight()
Description copied from interface: ViewLayoutState
Check whether this layout state and its associated view is flyweight (there is just one immutable shared instance of it).

Specified by:
isFlyweight in interface ViewLayoutState
Returns:
true if this layout state and its associated view are flyweight or false if not.

updateLayout

public void updateLayout()
Description copied from interface: ViewLayoutState
Do actual layout updating.
The first thing to do is to see if any work actually needs to be done.
Certain views such as line-wrapping views may react to 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()).
Anyway upon exit of this method the ViewLayoutState.isLayoutValid() must return true.
This method must be no-op for flyweight layout states because they should have their values up-to-date since their construction without ever calling this method.
The view is responsible for repainting itself if that's necessary. Prior to asking the component to repaint the appropriate region

Specified by:
updateLayout in interface ViewLayoutState

updateLayout

protected void updateLayout(DocumentEvent.ElementChange ec,
                            DocumentEvent e,
                            Shape a)
Update the layout in response to receiving notification of change from the model.

Overrides:
updateLayout in 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:
insertUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory), removeUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory), changedUpdate(javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)

layoutInvalid

public void layoutInvalid(ViewLayoutState child)
Called by children to mark layout of this view invalid. This only has effect if this view is active layout state.

Specified by:
layoutInvalid in interface ViewLayoutState.Parent

markLayoutInvalid

protected void markLayoutInvalid()

directUpdateLayout

protected void directUpdateLayout()
This method is called when this view is not acting as active layout state and its layout becomes invalid.
By default the layout is updated immediately but subclasses may change that but they must ensure that the layout will be updated later.


processRepaint

protected void processRepaint(ViewLayoutState.Parent lsParent)
Process pending repaint requests from children.
Children are guaranteed to be non-null once this method gets called.


markRepaint

protected boolean markRepaint(int childIndex,
                              boolean repaintTillEnd)
Mark that the child with the given index should be repainted.

Parameters:
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.
Returns:
true if lower child index was marked for repaint by this method than there was before.

isRepaintPending

public final boolean isRepaintPending()

markRepaintPending

protected final void markRepaintPending()

resetRepaintPending

protected void resetRepaintPending()

isRepaintTillEnd

public final boolean isRepaintTillEnd()

isLayoutMinorAxisPreferenceChanged

protected boolean isLayoutMinorAxisPreferenceChanged(boolean majorAxesOrthogonal)
Test whether the preference along the layout state minor axis has really changed.
The default implementation only checks preferred span but the implementation reflecting minimum and maximum spans can extend this method.

Returns:
true if it has really changed or false if not.

isLayoutValid

public boolean isLayoutValid()
Description copied from interface: ViewLayoutState
Check whether there are any layout duties present.

Specified by:
isLayoutValid in interface ViewLayoutState
Returns:
true if there are no layout duties or false if the layout needs to be udpated.
Flyweight layout states must always return true here.

getLayoutMajorAxisPreferredSpan

public double getLayoutMajorAxisPreferredSpan()
Description copied from interface: ViewLayoutState
Get the preferred span along major axis.
The value is expected to be cached for fast access.

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 #getLayoutMajorAxisOffset()) 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.

Specified by:
getLayoutMajorAxisPreferredSpan in interface ViewLayoutState

getLayoutMinorAxisPreferredSpan

public float getLayoutMinorAxisPreferredSpan()
Description copied from interface: ViewLayoutState
Get the preferred span of the view along minor axis.
The value is expected to be cached for fast access.

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.

Specified by:
getLayoutMinorAxisPreferredSpan in interface ViewLayoutState

getLayoutMinorAxisMinimumSpan

public float getLayoutMinorAxisMinimumSpan()
Description copied from interface: ViewLayoutState
Get the minimum span of the view along minor axis.
The value is expected to be cached for fast access.
By default 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.

Specified by:
getLayoutMinorAxisMinimumSpan in interface ViewLayoutState

getLayoutMinorAxisMaximumSpan

public float getLayoutMinorAxisMaximumSpan()
Description copied from interface: ViewLayoutState
Get the maximum span of the view along minor axis.
The value is expected to be cached for fast access.
As the default 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.

Specified by:
getLayoutMinorAxisMaximumSpan in interface ViewLayoutState

getLayoutMinorAxisAlignment

public float getLayoutMinorAxisAlignment()
Description copied from interface: ViewLayoutState
Get alignment along the minor axis.
The value is expected to be cached for fast access.

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 #viewPreferenceChanged().
After the value gets updated the layout state must call Parent.minorAxisPreferenceChanged() to notify the parent about the change of minor span.

Specified by:
getLayoutMinorAxisAlignment in interface ViewLayoutState

getLayoutMajorAxisRawOffset

public double getLayoutMajorAxisRawOffset()
Description copied from interface: ViewLayoutState
Get the raw visual offset of the view along the parent view's major axis.

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.

Specified by:
getLayoutMajorAxisRawOffset in interface ViewLayoutState
Returns:
raw double visual offset along major axis. It must be post-processed by parent (if it uses gap-based storage) to become a real index.
Returned valud is undefined for flyweight layout states.

setLayoutMajorAxisRawOffset

public void setLayoutMajorAxisRawOffset(double majorAxisRawOffset)
Description copied from interface: ViewLayoutState
Parent can set the view's raw offset along the parent view's major axis using this method.
This method must not be called on flyweight layout states.

Specified by:
setLayoutMajorAxisRawOffset in interface ViewLayoutState
Parameters:
majorAxisRawOffset - raw offset value along the major axis. It is not particularly useful without postprocessing by the parent.

getLayoutStateParent

protected final ViewLayoutState.Parent getLayoutStateParent()

isXLayoutStateMajorAxis

protected final boolean isXLayoutStateMajorAxis()

getLayoutStateMajorAxis

protected final int getLayoutStateMajorAxis()

getLayoutStateMinorAxis

protected final int getLayoutStateMinorAxis()

getViewRawIndex

public int getViewRawIndex()
Description copied from interface: ViewLayoutState
Get the raw index of the view (wrapped by this layout state) in its parent view.
Storing of the index is useful for the parent which can then find the child's index in a constant time.

Specified by:
getViewRawIndex in interface ViewLayoutState
Returns:
raw integer index that must be post-processed by parent (if it uses gap-based storage) to become a real index.
Returned valud is undefined for flyweight layout states.

setViewRawIndex

public void setViewRawIndex(int viewRawIndex)
Description copied from interface: ViewLayoutState
Parent can set the index of the view (wrapped by this layout state) in itself.
This method must not be called on flyweight layout states.

Specified by:
setViewRawIndex in interface ViewLayoutState
Parameters:
viewRawIndex - raw index value. It can differ from the real index because parent could preprocess it because of possible use of a gap translation.

viewPreferenceChanged

public void viewPreferenceChanged(boolean width,
                                  boolean height)
Description copied from interface: ViewLayoutState
Notify this layout state that the preferences has changed for the view that it wraps.
This gets called in response to the wrapped view calling View.preferenceChanged() in its parent.
Usually this method only makes sense when the layout state is a generic wrapper around a black-box view. If layout state and the view are one object then this method is usually no-op.
The layout state should just mark its internal state as changed but wait for layout update (that will be called by parent) to update the layout variables.
This method must be no-op for flyweight layout states.

Specified by:
viewPreferenceChanged in interface ViewLayoutState
Parameters:
width - true if the width preference has changed
height - true if the height preference has changed

markViewSizeInvalid

public void markViewSizeInvalid()
Description copied from interface: ViewLayoutState
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.
Parent is responsible for scheduling of layout update for the child after calling this method.
This method must be no-op for flyweight layout states.

Specified by:
markViewSizeInvalid in interface ViewLayoutState

majorAxisPreferenceChanged

public void majorAxisPreferenceChanged(ViewLayoutState child,
                                       double majorAxisSpanDelta)
Preference of one of the children has changed along the major axis.

Specified by:
majorAxisPreferenceChanged in interface ViewLayoutState.Parent
Parameters:
child - child layout state which preference has changed.
majorAxisSpanDelta - delta between the new span and the original span.

minorAxisPreferenceChanged

public void minorAxisPreferenceChanged(ViewLayoutState child)
Preference of one of the children has changed along the minor axis.

Specified by:
minorAxisPreferenceChanged in interface ViewLayoutState.Parent
Parameters:
child - child layout state which preference has changed.

getMinorAxisSpan

public float getMinorAxisSpan(ViewLayoutState child)
Get span of the given child along the minor axis of this view.

Specified by:
getMinorAxisSpan in interface ViewLayoutState.Parent
Parameters:
child - child layout state for which the span is being determined.

repaint

public void repaint(ViewLayoutState child,
                    double majorAxisOffset,
                    double majorAxisSpan,
                    float minorAxisOffset,
                    float minorAxisSpan)
Description copied from interface: ViewLayoutState.Parent
Inform the parent that the child layout state needs a repaint.
This method can be called anytime although usually it's called during the layout state's updateLayout().
This method can be called repetively. The lowest offsets should finally be used by the parent.

Specified by:
repaint in interface ViewLayoutState.Parent
Parameters:
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()).
This parameter is typically zero but can be used e.g. for line-wrapping views when typing on the last line.
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.

isChildrenLayoutNecessary

public final boolean isChildrenLayoutNecessary()
Test whether complete layout of the children necessary.


markChildrenLayoutNecessary

public final void markChildrenLayoutNecessary()
Mark that a complete layout of children is necessary.
This method does no scheduling of the children layout update.


preferenceChanged

public 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. This is reimplemented to queue new work on the layout thread. This method gets messaged from multiple threads via the children.

Overrides:
preferenceChanged in class View
Parameters:
childView - the child view of this view or null to signal change in this view.
width - true if the width preference has changed
height - true if the height preference has changed
See Also:
JComponent.revalidate()

setSize

public 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.

The propagation of this operation to child views can be done asynchronously if appropriate.

Overrides:
setSize in class View
Parameters:
width - the width >= 0
height - the height >= 0

setSpanOnMajorAxis

protected void setSpanOnMajorAxis(float targetMajorAxisSpan)

setSpanOnMinorAxis

protected void setSpanOnMinorAxis(float targetMinorAxisSpan)

markSizeInvalid

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.
This is made as protected method since large complex views may consider this operation lengthy with certain amount of children so they may need to do this operation in background and delegate to this implementation for small amount of children only.

Parameters:
>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.

isChildrenResizeDisabled

protected boolean isChildrenResizeDisabled()
Return true if the children should not be attempted to resize once setSize() is called on this view.
Turning this on may save considerable time but it should be only used if the views truly do not react on setSize() e.g. this should *not* be used if line-wrapping is turned on.


getChildAllocation

public Shape getChildAllocation(int index,
                                Shape a)
Fetches 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:
getChildAllocation in class View
Parameters:
index - the index of the child, >= 0 and < getViewCount()
a - the allocation to this view.
Returns:
the allocation to the child

getViewIndexAtPoint

public int getViewIndexAtPoint(float x,
                               float y,
                               Shape a)
Fetches the child view index at the given point. This is called by the various View methods that need to calculate which child to forward a message to.

Parameters:
x - the X coordinate >= 0
y - the Y coordinate >= 0
a - the allocation to thid view
Returns:
index of the view that best represents the given visual location or -1 if there are no children.
If the point is below the area of the first child view then the index of the first child view is returned.
If the point is above the area of the last child view then the index of the last child view is returned.

getViewIndex

public int getViewIndex(int offset,
                        Position.Bias b)
Returns the child view index representing the given position in the model.

Overrides:
getViewIndex in class View
Parameters:
offset - the position >= 0.
b - either forward or backward bias.
Returns:
index of the view representing the given position, or -1 if no view represents that position

getViewIndex

public int getViewIndex(int offset)
Returns the child view index representing the given position in the model.

Parameters:
offset - the position >= 0.
Returns:
index of the view representing the given position, or -1 if no view represents that position

paint

public void paint(Graphics g,
                  Shape a)
Render the view using the given allocation and rendering surface.

Specified by:
paint in class View
Parameters:
g - the rendering surface to use
a - the allocated region to render into
See Also:
View.paint(java.awt.Graphics, java.awt.Shape)

modelToView

public Shape modelToView(int pos,
                         Shape a,
                         Position.Bias b)
                  throws BadLocationException
Provides a mapping from the document model coordinate space to the coordinate space of the view mapped to it.

Specified by:
modelToView in 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[])

viewToModel

public 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. 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 ViewLayoutState object to avoid interaction with the layout thread.

Specified by:
viewToModel in class View
Parameters:
x - the X coordinate >= 0
y - the Y coordinate >= 0
a - the allocated region to render into
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
Provides 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.

Overrides:
getNextVisualPositionFrom in class View
Parameters:
pos - the position to convert >= 0
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
Returns:
the location within the model that best represents the next location visual position
Throws:
BadLocationException
IllegalArgumentException - if direction is invalid

getChild

protected final ViewLayoutState getChild(int index)
Fetch the object representing the layout state of of the child at the given index.

Parameters:
index - the child index. This must be a value >= 0 and < getViewCount().
Throws:
IndexOutOfBoundsException - in case the index was invalid.

getChildIndex

protected final int getChildIndex(ViewLayoutState child)
Get the index of the given child layout state in this view.

Parameters:
child - layout state which index in this view should be found.
Returns:
>=0 integer index of the given child in this view. Returns -1 if the given child is not present at the given index in this view.

getChildIndexNoCheck

protected final int getChildIndexNoCheck(ViewLayoutState child)
Get the index of the given child layout state in this view.

Parameters:
child - layout state which index in this view should be found.
Returns:
>=0 integer index of the given child in this view. Note: This method does no checking whether the child is really the child of this view.

createChildren

protected org.netbeans.lib.editor.view.GapBoxViewChildren createChildren()
Can be overriden by subclasses to return a different children implementation.


useCustomReloadChildren

protected boolean useCustomReloadChildren()

insertUpdate

public void insertUpdate(DocumentEvent evt,
                         Shape a,
                         ViewFactory f)
Overrides:
insertUpdate in class View

customInsertUpdate

protected void customInsertUpdate(DocumentEvent evt,
                                  Shape a,
                                  ViewFactory f)

getInsertUpdateRebuildOffsetRange

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.

Parameters:
evt - document event for the document modification.
Returns:
two-item integer array containing starting and ending offset of the area to be rebuilt or null in case no views should be rebuilt.

removeUpdate

public void removeUpdate(DocumentEvent evt,
                         Shape a,
                         ViewFactory f)
Overrides:
removeUpdate in class View

customRemoveUpdate

protected void customRemoveUpdate(DocumentEvent evt,
                                  Shape a,
                                  ViewFactory f)

getRemoveUpdateRebuildOffsetRange

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.

Parameters:
evt - document event for the document modification.
Returns:
two-item integer array containing starting and ending offset of the area to be rebuilt or null in case no views should be rebuilt.

changedUpdate

public void changedUpdate(DocumentEvent e,
                          Shape a,
                          ViewFactory f)
Overrides:
changedUpdate in class View

reloadChildren

protected void reloadChildren(int index,
                              int removeLength,
                              int startOffset,
                              int endOffset)
Load the children in the selected range of offsets.
Some implementations may reload all the present children if necessary.

Parameters:
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().

elementReloadChildren

protected void elementReloadChildren(int index,
                                     int removeLength,
                                     int elementCount)
Loads child views by tracking child elements of the element this view was created for.

Parameters:
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.
elementIndex - index of the first child element for which the view should be created
elementCount - number of elements for which the views should be created.

customReloadChildren

protected void customReloadChildren(int index,
                                    int removeLength,
                                    int startOffset,
                                    int endOffset)
Loads child views in a custom way.

Parameters:
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.

createCustomView

protected View createCustomView(ViewFactory f,
                                int startOffset,
                                int maxEndOffset,
                                int elementIndex)
Create custom child view starting at startOffset.

Parameters:
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.

unloadChildren

protected void unloadChildren()
Subclasses may override this method and deallocate resources bound to presence of children.
It's called by 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.


createChild

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


createDefaultChild

protected ViewLayoutState createDefaultChild(View v)
Return default implementation of the view layout state wrapper.


isMajorAxisPreferenceChanged

protected final boolean isMajorAxisPreferenceChanged()

markMajorAxisPreferenceChanged

protected void markMajorAxisPreferenceChanged()

isMinorAxisPreferenceChanged

protected final boolean isMinorAxisPreferenceChanged()

markMinorAxisPreferenceChanged

protected void markMinorAxisPreferenceChanged()

resetAxesPreferenceChanged

protected final void resetAxesPreferenceChanged()

getInsetSpan

protected final float getInsetSpan(int axis)
Get the span along an axis that is taken up by the view insets.

Parameters:
axis - the axis to determine the total insets along, either X_AXIS or Y_AXIS.
Returns:
span along the given axis taken up by view insets.

getMajorAxisInsetSpan

protected final float getMajorAxisInsetSpan()
Get the span along major axis that is taken up by the view insets.

Returns:
span along major axis taken up by view insets.

getMinorAxisInsetSpan

protected final float getMinorAxisInsetSpan()
Get the span along minor axis that is taken up by the view insets.

Returns:
span along minor axis taken up by view insets.

getStatusBits

protected final int getStatusBits(int bits)

isStatusBitsNonZero

protected final boolean isStatusBitsNonZero(int bits)

setStatusBits

protected final void setStatusBits(int bits)

clearStatusBits

protected final void clearStatusBits(int bits)

reallocate

protected Rectangle reallocate(Shape a)
Reallocate the view to the new size given by the passed shape.

Parameters:
a - shape to which to reallocate the view.
Returns:
rectangle bounding the shape. The returned rectangle can be mutated.

getStartOffset

public int getStartOffset(int childViewIndex)

getEndOffset

public int getEndOffset(int childViewIndex)

childToString

public String childToString(int childIndex)

appendChildToStringBuffer

public void appendChildToStringBuffer(StringBuffer sb,
                                      int childIndex,
                                      int indent)

childrenToString

public String childrenToString()

childrenToString

public String childrenToString(int indent)

toString

public String toString()
Overrides:
toString in class Object

org.netbeans.modules.editor.lib/1 1.14.0 3

Built on May 28 2007.  |  Portions Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.