| GNU Classpath (0.95) | |
| Prev Class | Next Class | Frames | No Frames |
| Summary: Nested | Field | Method | Constr | Detail: Nested | Field | Method | Constr |
java.lang.Objectjavax.swing.text.Viewjavax.swing.text.CompositeViewjavax.swing.text.BoxViewpublic class BoxViewextends CompositeViewCompositeView 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 | |
Method Summary | |
protected void |
|
protected SizeRequirements |
|
protected SizeRequirements |
|
protected SizeRequirements |
|
protected void |
|
protected boolean |
|
protected void |
|
float |
|
int |
|
Shape |
|
int |
|
float |
|
float |
|
protected int |
|
float |
|
int |
|
protected int |
|
protected View |
|
int |
|
protected boolean | |
protected boolean |
|
protected boolean | |
protected boolean |
|
protected void |
|
void |
|
protected void |
|
protected void |
|
Shape |
|
void | |
protected void |
|
void |
|
void | |
void |
|
void |
|
int |
|
Methods inherited from class java.lang.Object | |
clone, equals, extends Object> getClass, finalize, hashCode, notify, notifyAll, toString, wait, wait, wait | |
public BoxView(Element element, int axis)
Creates a newBoxViewfor the givenElementand axis. Valid values for the axis areView.X_AXISandView.Y_AXIS.
- Parameters:
element- the element that is rendered by this BoxViewaxis- the axis along which the box is laid out
protected void baselineLayout(int span, int axis, int[] offsets, int[] spans)
Calculates the baseline layout of the children of thisBoxViewalong 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.
- Parameters:
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 baselineRequirements(int axis, SizeRequirements sr)
Calculates size requirements for a baseline layout. This is not used by the BoxView itself, but by subclasses that wish to perform a baseline layout, like the FlowView's rows.
- Parameters:
axis- the axis that is examinedsr- theSizeRequirementsobject to hold the result, ifnull, a new one is created
- Returns:
- the size requirements for this
BoxViewalong the specified axis
protected SizeRequirements calculateMajorAxisRequirements(int axis, SizeRequirements sr)
Calculates the size requirements of thisBoxViewalong its major axis, that is the axis specified in the constructor.
- Parameters:
axis- the axis that is examinedsr- theSizeRequirementsobject to hold the result, ifnull, a new one is created
- Returns:
- the size requirements for this
BoxViewalong the specified axis
protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements sr)
Calculates the size requirements of thisBoxViewalong its minor axis, that is the axis opposite to the axis specified in the constructor.
- Parameters:
axis- the axis that is examinedsr- theSizeRequirementsobject to hold the result, ifnull, a new one is created
- Returns:
- the size requirements for this
BoxViewalong the specified axis
protected void childAllocation(int index, Rectangle a)
Computes the allocation for a childView. The parameterastores the allocation of thisCompositeViewand is then adjusted to hold the allocation of the child view.
- Overrides:
- childAllocation in interface CompositeView
- Parameters:
index- the index of the childViewa- the allocation of thisCompositeViewbefore the call, the allocation of the child on exit
protected boolean flipEastAndWestAtEnds(int position, Position.Bias bias)
- Overrides:
- flipEastAndWestAtEnds in interface CompositeView
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. This callesView.forwardUpdateToView(View,DocumentEvent,Shape,ViewFactory)for each View that must be forwarded to. Ifecis notnull(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.
- Overrides:
- forwardUpdate in interface View
- Parameters:
ec- the ElementChange describing the element changes (may benullif there were no changes)vf- the ViewFactory used to create new Views
- Since:
- 1.3
public float getAlignment(int axis)
Returns the alignment for this box view for the specified axis. The axis that is tiled (the major axis) will be requested to be aligned centered (0.5F). The minor axis alignment depends on the child view's total alignment.
- Overrides:
- getAlignment in interface View
- Parameters:
axis- the axis which is examined
- Returns:
- the alignment for this box view for the specified axis
public int getAxis()
Returns the axis along which thisBoxViewis laid out.
- Returns:
- the axis along which this
BoxViewis laid out
- Since:
- 1.3
public Shape getChildAllocation(int index, Shape a)
Returns the child allocation for the child view with the specifiedindex. If the layout is invalid, this returnsnull.
- Overrides:
- getChildAllocation in interface CompositeView
- Parameters:
index- the child view indexa- the allocation to this view
- Returns:
- the child allocation for the child view with the specified
indexornullif the layout is invalid orais null
public int getHeight()
Return the current height of the box. This is the last allocated height.
- Returns:
- the current height of the box
public float getMaximumSpan(int axis)
Returns the maximum span of this view along the specified axis. This returnsInteger.MAX_VALUEfor the minor axis and the preferred span for the major axis.
- Overrides:
- getMaximumSpan in interface View
- Parameters:
axis- the axis
- Returns:
- the maximum span of this view along the specified axis
public float getMinimumSpan(int axis)
Returns the minimum span of this view along the specified axis. This calculates the minimum span usingcalculateMajorAxisRequirements(int,SizeRequirements)orcalculateMinorAxisRequirements(int,SizeRequirements)(depending on the axis) and returns the resulting minimum span.
- Overrides:
- getMinimumSpan in interface View
- Parameters:
axis- the 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.
- Parameters:
axis- the axis to examine, eitherX_AXISorY_AXISchildIndex- the index of the child for for which to return the span
- Returns:
- the offset for the child view with the given index for the specified axis
public float getPreferredSpan(int axis)
Returns the preferred span of the content managed by thisViewalong the specifiedaxis.
- Overrides:
- getPreferredSpan in interface View
- Parameters:
axis- the axis
- Returns:
- the preferred span of this
View.
public int getResizeWeight(int axis)
Returns the resize weight of this view. A value of0or less means this view is not resizeable. Positive values make the view resizeable. This implementation returns0for the major axis and1for the minor axis of this box view.
- Overrides:
- getResizeWeight in interface View
- Parameters:
axis- the axis
- Returns:
- the resizability of this view along the specified axis
- Throws:
IllegalArgumentException- ifaxisis invalid
protected int getSpan(int axis, int childIndex)
Returns the span for the child view with the given index for the specified axis.
- Parameters:
axis- the axis to examine, eitherX_AXISorY_AXISchildIndex- the index of the child for for which to return the span
- 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 childViewat the specified location.
- Overrides:
- getViewAtPoint in interface CompositeView
- Parameters:
x- the X coordinatey- the Y coordinater- the inner allocation of thisBoxViewon entry, the allocation of the found child on exit
- Returns:
- the child
Viewat the specified location
public int getWidth()
Return the current width of the box. This is the last allocated width.
- Returns:
- the current width of the box
protected boolean isAfter(int x, int y, Rectangle r)
Returnstrueif the specified point lies after the givenRectangle,falseotherwise. "After" is typically defined as being to the right or below.
- Overrides:
- isAfter in interface CompositeView
- Parameters:
x- the X coordinate of the pointy- the Y coordinate of the pointr- the rectangle to test the point against
- Returns:
trueif the specified point lies after the givenRectangle,falseotherwise
protected boolean isAllocationValid()
Returnstrueif the cached allocations for the children are still valid,falseotherwise.
- Returns:
trueif the cached allocations for the children are still valid,falseotherwise
protected boolean isBefore(int x, int y, Rectangle r)
Returnstrueif the specified point lies before the givenRectangle,falseotherwise. "Before" is typically defined as being to the left or above.
- Overrides:
- isBefore in interface CompositeView
- Parameters:
x- the X coordinate of the pointy- the Y coordinate of the pointr- the rectangle to test the point against
- Returns:
trueif the specified point lies before the givenRectangle,falseotherwise
protected boolean isLayoutValid(int axis)
Returnstrueif the layout along the specifiedaxisis valid,falseotherwise. Valid values for the axis areView.X_AXISandView.Y_AXIS.
- Parameters:
axis- the axis
- Returns:
trueif the layout along the specifiedaxisis valid,falseotherwise
- Since:
- 1.4
protected void layout(int width, int height)
Lays out the children of thisBoxViewwith the specified bounds.
- Parameters:
width- the width of the allocated region for the children (that is the inner allocation of thisBoxViewheight- the height of the allocated region for the children (that is the inner allocation of thisBoxView
public void layoutChanged(int axis)
Marks the layout along the specified axis as invalid. This is triggered automatically when any of the child view changes its preferences viapreferenceChanged(View,boolean,boolean). The layout will be updated the next time whensetSize(float,float)is called, typically from within thepaint(Graphics,Shape)method. Valid values for the axis areView.X_AXISandView.Y_AXIS.
- Parameters:
axis- anintvalue
- Since:
- 1.3
protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans)
Performs the layout along the major axis of aBoxView.
- Parameters:
targetSpan- the (inner) span of theBoxViewin 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)
Performs the layout along the minor axis of aBoxView.
- Parameters:
targetSpan- the (inner) span of theBoxViewin 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
public Shape modelToView(int pos, Shape a, Position.Bias bias) throws BadLocationException
Maps the document model positionposto 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.
- Overrides:
- modelToView in interface CompositeView
public void paint(Graphics g, Shape a)
Renders theElementthat is associated with thisView.
- Parameters:
g- theGraphicscontext to render toa- the allocated region for theElement
protected void paintChild(Graphics g, Rectangle alloc, int index)
Paints the childViewat the specifiedindex. This method modifies the actual values inallocso make sure you have a copy of the original values if you need them.
- Parameters:
g- theGraphicscontext to paint toalloc- the allocated region for the child to paint intoindex- the index of the child to be painted
- See Also:
childAllocation(int,Rectangle)
public void preferenceChanged(View child, boolean width, boolean height)
Called by a child View when its preferred span has changed.
- Overrides:
- preferenceChanged in interface View
- Parameters:
child- the child View.width- indicates that the preferred width of the child changed.height- indicates that the preferred height of the child changed.
public void replace(int offset, int length, View[] views)
Replaces child views by some other child views. If there are no views to remove (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.
- Overrides:
- replace in interface CompositeView
- Parameters:
offset- the start offset from where to remove childrenlength- the number of children to removeviews- the views that replace the removed children
public void setAxis(int axis)
Sets the axis along which thisBoxViewis laid out. Valid values for the axis areView.X_AXISandView.Y_AXIS.
- Parameters:
axis- the axis along which thisBoxViewis laid out
- Since:
- 1.3
public void setSize(float width, float height)
Sets the size of the view. If the actual size has changed, the layout is updated accordingly.
- Parameters:
width- the new widthheight- the new height
public int viewToModel(float x, float y, Shape a, Position.Bias[] bias)
Maps coordinates from theView's space into a position in the document model.
- Overrides:
- viewToModel in interface CompositeView
- Parameters:
x- the x coordinate in the view spacey- the y coordinate in the view spacea- the allocation of thisView
- Returns:
- the position in the document that corresponds to the screen coordinates
x, y
| GNU Classpath (0.95) |