|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Objectjavax.swing.text.View
javax.swing.text.CompositeView
javax.swing.text.BoxView
public class BoxView
An implementation of CompositeView that arranges its children in
a box along one axis. This is comparable to how the BoxLayout
works, but for View children.
| Field Summary |
|---|
| 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 | |
|---|---|
BoxView(Element element,
int axis)
Creates a new BoxView for the given
Element and axis. |
|
| Method Summary | |
|---|---|
protected void |
baselineLayout(int span,
int axis,
int[] offsets,
int[] spans)
Calculates the baseline layout of the children of this BoxView along the specified axis. |
protected SizeRequirements |
baselineRequirements(int axis,
SizeRequirements sr)
Calculates size requirements for a baseline layout. |
protected SizeRequirements |
calculateMajorAxisRequirements(int axis,
SizeRequirements sr)
Calculates the size requirements of this BoxView along
its major axis, that is the axis specified in the constructor. |
protected SizeRequirements |
calculateMinorAxisRequirements(int axis,
SizeRequirements sr)
Calculates the size requirements of this BoxView along
its minor axis, that is the axis opposite to the axis specified in the
constructor. |
protected void |
childAllocation(int index,
Rectangle a)
Computes the allocation for a child View. |
protected boolean |
flipEastAndWestAtEnds(int position,
Position.Bias bias)
Determines if the next view in horinzontal direction is located to the east or west of the view at position pos. |
protected void |
forwardUpdate(DocumentEvent.ElementChange ec,
DocumentEvent e,
Shape a,
ViewFactory vf)
Forwards the DocumentEvent to child views that need to get notified of the change to the model. |
float |
getAlignment(int axis)
Returns the alignment for this box view for the specified axis. |
int |
getAxis()
Returns the axis along which this BoxView is laid out. |
Shape |
getChildAllocation(int index,
Shape a)
Returns the child allocation for the child view with the specified index. |
int |
getHeight()
Return the current height of the box. |
float |
getMaximumSpan(int axis)
Returns the maximum span of this view along the specified axis. |
float |
getMinimumSpan(int axis)
Returns the minimum span of this view along the specified axis. |
protected int |
getOffset(int axis,
int childIndex)
Returns the offset for the child view with the given index for the specified axis. |
float |
getPreferredSpan(int axis)
Returns the preferred span of the content managed by this View along the specified axis. |
int |
getResizeWeight(int axis)
Returns the resize weight of this view. |
protected int |
getSpan(int axis,
int childIndex)
Returns the span for the child view with the given index for the specified axis. |
protected View |
getViewAtPoint(int x,
int y,
Rectangle r)
Returns the child View at the specified location. |
int |
getWidth()
Return the current width of the box. |
protected boolean |
isAfter(int x,
int y,
Rectangle r)
Returns true if the specified point lies after the
given Rectangle, false otherwise. |
protected boolean |
isAllocationValid()
Returns true if the cached allocations for the children
are still valid, false otherwise. |
protected boolean |
isBefore(int x,
int y,
Rectangle r)
Returns true if the specified point lies before the
given Rectangle, false otherwise. |
protected boolean |
isLayoutValid(int axis)
Returns true if the layout along the specified
axis is valid, false otherwise. |
protected void |
layout(int width,
int height)
Lays out the children of this BoxView with the specified
bounds. |
void |
layoutChanged(int axis)
Marks the layout along the specified axis as invalid. |
protected void |
layoutMajorAxis(int targetSpan,
int axis,
int[] offsets,
int[] spans)
Performs the layout along the major axis of a BoxView. |
protected void |
layoutMinorAxis(int targetSpan,
int axis,
int[] offsets,
int[] spans)
Performs the layout along the minor axis of a BoxView. |
Shape |
modelToView(int pos,
Shape a,
Position.Bias bias)
Maps the document model position pos to a Shape
in the view coordinate space. |
void |
paint(Graphics g,
Shape a)
Renders the Element that is associated with this
View. |
protected void |
paintChild(Graphics g,
Rectangle alloc,
int index)
Paints the child View at the specified index. |
void |
preferenceChanged(View child,
boolean width,
boolean height)
Called by a child View when its preferred span has changed. |
void |
replace(int offset,
int length,
View[] views)
Replaces child views by some other child views. |
void |
setAxis(int axis)
Sets the axis along which this BoxView is laid out. |
void |
setSize(float width,
float height)
Sets the size of the view. |
int |
viewToModel(float x,
float y,
Shape a,
Position.Bias[] bias)
Maps coordinates from the View's space into a position
in the document model. |
| Methods inherited from class javax.swing.text.CompositeView |
|---|
getBottomInset, getInsideAllocation, getLeftInset, getNextEastWestVisualPositionFrom, getNextNorthSouthVisualPositionFrom, getNextVisualPositionFrom, getRightInset, getTopInset, getView, getViewAtPosition, getViewCount, getViewIndex, getViewIndexAtPosition, loadChildren, modelToView, setInsets, setParagraphInsets, setParent |
| Methods inherited from class javax.swing.text.View |
|---|
append, breakView, changedUpdate, createFragment, dump, forwardUpdateToView, getAttributes, getBreakWeight, getContainer, getDocument, getElement, getEndOffset, getGraphics, getParent, getStartOffset, getToolTipText, getViewFactory, getViewIndex, insert, insertUpdate, isVisible, modelToView, remove, removeAll, removeUpdate, updateChildren, updateLayout, viewToModel |
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Constructor Detail |
|---|
public BoxView(Element element,
int axis)
BoxView for the given
Element and axis. Valid values for the axis are
View.X_AXIS and View.Y_AXIS.
element - the element that is rendered by this BoxViewaxis - the axis along which the box is laid out| Method Detail |
|---|
public int getAxis()
BoxView is laid out.
BoxView is laid outpublic void setAxis(int axis)
BoxView is laid out.
Valid values for the axis are View.X_AXIS and
View.Y_AXIS.
axis - the axis along which this BoxView is laid outpublic void layoutChanged(int axis)
preferenceChanged(View, boolean, boolean).
The layout will be updated the next time when
setSize(float, float) is called, typically from within the
paint(Graphics, Shape) method.
Valid values for the axis are View.X_AXIS and
View.Y_AXIS.
axis - an int valueprotected boolean isLayoutValid(int axis)
true if the layout along the specified
axis is valid, false otherwise.
Valid values for the axis are View.X_AXIS and
View.Y_AXIS.
axis - the axis
true if the layout along the specified
axis is valid, false otherwise
protected void paintChild(Graphics g,
Rectangle alloc,
int index)
View at the specified index.
This method modifies the actual values in alloc so make
sure you have a copy of the original values if you need them.
g - the Graphics context to paint toalloc - the allocated region for the child to paint intoindex - the index of the child to be paintedchildAllocation(int, Rectangle)
public void replace(int offset,
int length,
View[] views)
length == 0), the result is a simple insert, if
there are no children to add (view == null) the result
is a simple removal.
In addition this invalidates the layout and resizes the internal cache
for the child allocations. The old children's cached allocations can
still be accessed (although they are not guaranteed to be valid), and
the new children will have an initial offset and span of 0.
replace in class CompositeViewoffset - the start offset from where to remove childrenlength - the number of children to removeviews - the views that replace the removed children
public void paint(Graphics g,
Shape a)
Element that is associated with this
View.
paint in class Viewg - the Graphics context to render toa - the allocated region for the Elementpublic float getPreferredSpan(int axis)
View along the specified axis.
getPreferredSpan in class Viewaxis - the axis
View.public float getMaximumSpan(int axis)
Integer.MAX_VALUE for the minor axis
and the preferred span for the major axis.
getMaximumSpan in class Viewaxis - the axis
public float getMinimumSpan(int axis)
calculateMajorAxisRequirements(int, javax.swing.SizeRequirements) or
calculateMinorAxisRequirements(int, javax.swing.SizeRequirements) (depending on the axis) and
returns the resulting minimum span.
getMinimumSpan in class Viewaxis - the axis
protected SizeRequirements baselineRequirements(int axis,
SizeRequirements sr)
axis - the axis that is examinedsr - the SizeRequirements object to hold the result,
if null, a new one is created
BoxView along
the specified axis
protected void baselineLayout(int span,
int axis,
int[] offsets,
int[] spans)
BoxView along the specified axis.
This is not used by the BoxView itself, but by subclasses that wish to
perform a baseline layout, like the FlowView's rows.
span - the target spanaxis - the axis that is examinedoffsets - an empty array, filled with the offsets of the childrenspans - an empty array, filled with the spans of the children
protected SizeRequirements calculateMajorAxisRequirements(int axis,
SizeRequirements sr)
BoxView along
its major axis, that is the axis specified in the constructor.
axis - the axis that is examinedsr - the SizeRequirements object to hold the result,
if null, a new one is created
BoxView along
the specified axis
protected SizeRequirements calculateMinorAxisRequirements(int axis,
SizeRequirements sr)
BoxView along
its minor axis, that is the axis opposite to the axis specified in the
constructor.
axis - the axis that is examinedsr - the SizeRequirements object to hold the result,
if null, a new one is created
BoxView along
the specified axis
protected boolean isBefore(int x,
int y,
Rectangle r)
true if the specified point lies before the
given Rectangle, false otherwise.
"Before" is typically defined as being to the left or above.
isBefore in class CompositeViewx - the X coordinate of the pointy - the Y coordinate of the pointr - the rectangle to test the point against
true if the specified point lies before the
given Rectangle, false otherwise
protected boolean isAfter(int x,
int y,
Rectangle r)
true if the specified point lies after the
given Rectangle, false otherwise.
"After" is typically defined as being to the right or below.
isAfter in class CompositeViewx - the X coordinate of the pointy - the Y coordinate of the pointr - the rectangle to test the point against
true if the specified point lies after the
given Rectangle, false otherwise
protected View getViewAtPoint(int x,
int y,
Rectangle r)
View at the specified location.
getViewAtPoint in class CompositeViewx - the X coordinatey - the Y coordinater - the inner allocation of this BoxView on entry,
the allocation of the found child on exit
View at the specified location
protected void childAllocation(int index,
Rectangle a)
View. The parameter
a stores the allocation of this CompositeView
and is then adjusted to hold the allocation of the child view.
childAllocation in class CompositeViewindex - the index of the child Viewa - the allocation of this CompositeView before the
call, the allocation of the child on exit
protected void layout(int width,
int height)
BoxView with the specified
bounds.
width - the width of the allocated region for the children (that
is the inner allocation of this BoxViewheight - the height of the allocated region for the children (that
is the inner allocation of this BoxView
protected void layoutMajorAxis(int targetSpan,
int axis,
int[] offsets,
int[] spans)
BoxView.
targetSpan - the (inner) span of the BoxView in which
to layout the childrenaxis - the axis along which the layout is performedoffsets - the array that holds the offsets of the children on exitspans - the array that holds the spans of the children on exit
protected void layoutMinorAxis(int targetSpan,
int axis,
int[] offsets,
int[] spans)
BoxView.
targetSpan - the (inner) span of the BoxView in which
to layout the childrenaxis - the axis along which the layout is performedoffsets - the array that holds the offsets of the children on exitspans - the array that holds the spans of the children on exitprotected boolean isAllocationValid()
true if the cached allocations for the children
are still valid, false otherwise.
true if the cached allocations for the children
are still valid, false otherwisepublic int getWidth()
public int getHeight()
public void setSize(float width,
float height)
setSize in class Viewwidth - the new widthheight - the new height
protected int getSpan(int axis,
int childIndex)
axis - the axis to examine, either X_AXIS or
Y_AXISchildIndex - the index of the child for for which to return the span
protected int getOffset(int axis,
int childIndex)
axis - the axis to examine, either X_AXIS or
Y_AXISchildIndex - the index of the child for for which to return the span
public float getAlignment(int axis)
getAlignment in class Viewaxis - the axis which is examined
public void preferenceChanged(View child,
boolean width,
boolean height)
preferenceChanged in class Viewwidth - indicates that the preferred width of the child changed.height - indicates that the preferred height of the child changed.child - the child View.
public Shape modelToView(int pos,
Shape a,
Position.Bias bias)
throws BadLocationException
pos to a Shape
in the view coordinate space. This method overrides CompositeView's
method to make sure the children are allocated properly before
calling the super's behaviour.
modelToView in class CompositeViewpos - the position of the character in the modela - the area that is occupied by the viewbias - either Position.Bias.Forward or
Position.Bias.Backward depending on the preferred
direction bias. If null this defaults to
Position.Bias.Forward
BadLocationException - if pos is invalidpublic int getResizeWeight(int axis)
0 or less
means this view is not resizeable. Positive values make the view
resizeable. This implementation returns 0 for the major
axis and 1 for the minor axis of this box view.
getResizeWeight in class Viewaxis - the axis
IllegalArgumentException - if axis is invalid
public Shape getChildAllocation(int index,
Shape a)
index. If the layout is invalid, this returns
null.
getChildAllocation in class CompositeViewindex - the child view indexa - the allocation to this view
index or null if the layout is invalid
or a is null
protected void forwardUpdate(DocumentEvent.ElementChange ec,
DocumentEvent e,
Shape a,
ViewFactory vf)
ViewView.forwardUpdateToView(javax.swing.text.View, javax.swing.event.DocumentEvent, java.awt.Shape, javax.swing.text.ViewFactory)
for each View that must be forwarded to.
If ec is not null (this means there have been
structural changes to the element that this view is responsible for) this
method should recognize this and don't notify newly added child views.
forwardUpdate in class Viewec - the ElementChange describing the element changes (may be
null if there were no changes)e - the DocumentEvent describing the changes to the modela - the current allocation of the viewvf - the ViewFactory used to create new Views
public int viewToModel(float x,
float y,
Shape a,
Position.Bias[] bias)
CompositeViewView's space into a position
in the document model.
viewToModel in class CompositeViewx - the x coordinate in the view space, x >= 0y - the y coordinate in the view space, y >= 0a - the allocation of this Viewbias - the bias to use
x, y >= 0
protected boolean flipEastAndWestAtEnds(int position,
Position.Bias bias)
CompositeViewpos. Usually
the Views are laid out from the east to the west, so
we unconditionally return false here. Subclasses that
support bidirectional text may wish to override this method.
flipEastAndWestAtEnds in class CompositeViewposition - the position in the documentbias - the bias to be applied to pos
true if the next View is located
to the EAST, false otherwise
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||