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

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

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

org.netbeans.lib.editor.view
Class SimpleViewLayoutState

java.lang.Object
  extended by org.netbeans.lib.editor.view.SimpleViewLayoutState
All Implemented Interfaces:
ViewLayoutState
Direct Known Subclasses:
DefaultViewLayoutState

public class SimpleViewLayoutState
extends Object
implements ViewLayoutState

Implementation of ViewLayoutState for non-flyweight views that only caches preferred spans along both axes.
Preferred span is returned for maximum and minimum spans along both axes.


Nested Class Summary
 
Nested classes/interfaces inherited from interface org.netbeans.editor.view.spi.ViewLayoutState
ViewLayoutState.Parent
 
Field Summary
protected static int LAST_USED_BIT
           
 
Constructor Summary
SimpleViewLayoutState(View v)
           
 
Method Summary
protected  void clearStatusBits(int bits)
           
protected  void doUpdateLayout(View parent)
           
 double getLayoutMajorAxisPreferredSpan()
          Get the preferred span along major axis.
 float getLayoutMajorAxisPreferredSpanFloat()
           
 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  ViewLayoutState.Parent getLayoutStateParent()
           
protected  int getMajorAxis()
           
protected  int getMinorAxis()
           
protected  int getStatusBits(int bits)
           
 View getView()
          Get the view that this layout state is wrapping.
 int getViewRawIndex()
          Get the raw index of the view (wrapped by this layout state) in its parent view.
 boolean isFlyweight()
          Check whether this layout state and its associated view is flyweight (there is just one immutable shared instance of it).
 boolean isLayoutValid()
          Check whether there are any layout duties present.
protected  boolean isStatusBitsNonZero(int bits)
           
protected  boolean isXMajorAxis()
           
 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.
protected  boolean minorAxisUpdateLayout(int minorAxis)
           
 ViewLayoutState selectLayoutMajorAxis(int axis)
          Select which axis will be used as major axis by this layout state.
protected  void setLayoutMajorAxisPreferredSpan(float layoutMajorAxisPreferredSpan)
           
 void setLayoutMajorAxisRawOffset(double layoutMajorAxisRawOffset)
          Parent can set the view's raw offset along the parent view's major axis using this method.
 void setLayoutMinorAxisAlignment(float layoutMinorAxisAlignment)
           
protected  void setLayoutMinorAxisPreferredSpan(float layoutMinorAxisPreferredSpan)
           
protected  void setStatusBits(int bits)
           
 void setViewRawIndex(int viewRawIndex)
          Parent can set the index of the view (wrapped by this layout state) in itself.
 void updateLayout()
          Do actual layout updating.
 void viewPreferenceChanged(boolean width, boolean height)
          Notify this layout state that the preferences has changed for the view that it wraps.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

LAST_USED_BIT

protected static final int LAST_USED_BIT
See Also:
Constant Field Values
Constructor Detail

SimpleViewLayoutState

public SimpleViewLayoutState(View v)
Method Detail

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.

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.

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.


isXMajorAxis

protected final boolean isXMajorAxis()

getMajorAxis

protected final int getMajorAxis()

getMinorAxis

protected final int getMinorAxis()

getLayoutStateParent

protected final ViewLayoutState.Parent getLayoutStateParent()

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

doUpdateLayout

protected void doUpdateLayout(View parent)

minorAxisUpdateLayout

protected boolean minorAxisUpdateLayout(int minorAxis)

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.

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 layoutMajorAxisRawOffset)
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:
layoutMajorAxisRawOffset - raw offset value along the major axis. It is not particularly useful without postprocessing by the parent.

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

getLayoutMajorAxisPreferredSpanFloat

public float getLayoutMajorAxisPreferredSpanFloat()

setLayoutMajorAxisPreferredSpan

protected void setLayoutMajorAxisPreferredSpan(float layoutMajorAxisPreferredSpan)

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

setLayoutMinorAxisPreferredSpan

protected void setLayoutMinorAxisPreferredSpan(float layoutMinorAxisPreferredSpan)

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

setLayoutMinorAxisAlignment

public void setLayoutMinorAxisAlignment(float layoutMinorAxisAlignment)

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

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.

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)

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.