public class SimpleViewLayoutState extends Object implements ViewLayoutState
ViewLayoutState
for non-flyweight views that only caches preferred spans
along both axes.
ViewLayoutState.Parent
Modifier and Type | Field and Description |
---|---|
protected static int |
LAST_USED_BIT |
Constructor and Description |
---|
SimpleViewLayoutState(View v) |
Modifier and Type | Method and Description |
---|---|
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.
|
protected static final int LAST_USED_BIT
public SimpleViewLayoutState(View v)
public final View getView()
ViewLayoutState
getView
in interface ViewLayoutState
public boolean isFlyweight()
ViewLayoutState
isFlyweight
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.
protected final boolean isXMajorAxis()
protected final int getMajorAxis()
protected final int getMinorAxis()
protected final ViewLayoutState.Parent getLayoutStateParent()
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 doUpdateLayout(View parent)
protected boolean minorAxisUpdateLayout(int minorAxis)
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 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 layoutMajorAxisRawOffset)
ViewLayoutState
setLayoutMajorAxisRawOffset
in interface ViewLayoutState
layoutMajorAxisRawOffset
- raw offset value along the major axis.
It is not particularly useful without postprocessing by the parent.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 getLayoutMajorAxisPreferredSpanFloat()
protected void setLayoutMajorAxisPreferredSpan(float layoutMajorAxisPreferredSpan)
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
protected void setLayoutMinorAxisPreferredSpan(float layoutMinorAxisPreferredSpan)
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 void setLayoutMinorAxisAlignment(float layoutMinorAxisAlignment)
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 boolean isLayoutValid()
ViewLayoutState
isLayoutValid
in interface ViewLayoutState
true
here.protected final int getStatusBits(int bits)
protected final boolean isStatusBitsNonZero(int bits)
protected final void setStatusBits(int bits)
protected final void clearStatusBits(int bits)