- All Implemented Interfaces:
-
SwingConstants
- Direct Known Subclasses:
-
BlockView
,FlowView
,TableView
,TableView.TableCell
,TableView.TableRow
,WrappedPlainView
,ZoneView
Layout for each axis is handled separately by the methods layoutMajorAxis
and layoutMinorAxis
. Subclasses can change the layout algorithm by reimplementing these methods. These methods will be called as necessary depending upon whether or not there is cached layout information and the cache is considered valid. These methods are typically called if the given size along the axis changes, or if layoutChanged
is called to force an updated layout. The layoutChanged
method invalidates cached layout information, if there is any. The requirements published to the parent view are calculated by the methods calculateMajorAxisRequirements
and calculateMinorAxisRequirements
. If the layout algorithm is changed, these methods will likely need to be reimplemented.
-
Field Summary
Fields declared in class javax.swing.text.View
BadBreakWeight, ExcellentBreakWeight, ForcedBreakWeight, GoodBreakWeight, X_AXIS, Y_AXIS
Fields declared in 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
Modifier and TypeMethodDescriptionprotected void
baselineLayout
(int targetSpan, int axis, int[] offsets, int[] spans) Computes the location and extent of each child view in thisBoxView
given thetargetSpan
, which is the width (or height) of the region we have to work with.protected SizeRequirements
baselineRequirements
(int axis, SizeRequirements r) Calculates the size requirements for thisBoxView
by examining the size of each child view.protected SizeRequirements
calculateMajorAxisRequirements
(int axis, SizeRequirements r) Calculates the size requirements for the major axisaxis
.protected SizeRequirements
calculateMinorAxisRequirements
(int axis, SizeRequirements r) Calculates the size requirements for the minor axisaxis
.protected void
childAllocation
(int index, Rectangle alloc) Allocates a region for a child view.protected boolean
flipEastAndWestAtEnds
(int position, Position.Bias bias) Determines in which direction the next view lays.protected void
Forwards the givenDocumentEvent
to the child views that need to be notified of the change to the model.float
getAlignment
(int axis) Determines the desired alignment for this view along an axis.int
getAxis()
Fetches the tile axis property.getChildAllocation
(int index, Shape a) Fetches the allocation for the given child view.int
Returns the current height of the box.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.protected int
getOffset
(int axis, int childIndex) Fetches the offset of a particular child's current layout.float
getPreferredSpan
(int axis) Determines the preferred span for this view along an axis.int
getResizeWeight
(int axis) Gets the resize weight.protected int
getSpan
(int axis, int childIndex) Fetches the span of a particular child's current layout.protected View
getViewAtPoint
(int x, int y, Rectangle alloc) Fetches the child view at the given coordinates.int
getWidth()
Returns the current width of the box.protected boolean
Determines if a point falls after an allocated region.protected boolean
Are the allocations for the children still valid?protected boolean
Determines if a point falls before an allocated region.protected boolean
isLayoutValid
(int axis) Determines if the layout is valid along the given axis.protected void
layout
(int width, int height) Perform layout on the boxvoid
layoutChanged
(int axis) Invalidates the layout along an axis.protected void
layoutMajorAxis
(int targetSpan, int axis, int[] offsets, int[] spans) Performs layout for the major axis of the box (i.e. the axis that it represents).protected void
layoutMinorAxis
(int targetSpan, int axis, int[] offsets, int[] spans) Performs layout for the minor axis of the box (i.e. the axis orthogonal to the axis that it represents).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
Renders theBoxView
using the given rendering surface and area on that surface.protected void
paintChild
(Graphics g, Rectangle alloc, int index) Paints a child.void
preferenceChanged
(View child, boolean width, boolean height) This is called by a child to indicate its preferred span has changed.void
Invalidates the layout and resizes the cache of requests/allocations.void
setAxis
(int axis) Sets the tile axis property.void
setSize
(float width, float height) Sets the size of the view.int
viewToModel
(float x, float y, Shape a, Position.Bias[] bias) Provides a mapping from the view coordinate space to the logical coordinate space of the model.Methods declared in class javax.swing.text.CompositeView
getBottomInset, getInsideAllocation, getLeftInset, getNextEastWestVisualPositionFrom, getNextNorthSouthVisualPositionFrom, getNextVisualPositionFrom, getRightInset, getTopInset, getView, getViewAtPosition, getViewCount, getViewIndex, getViewIndexAtPosition, loadChildren, modelToView, setInsets, setParagraphInsets, setParent
Methods declared in class javax.swing.text.View
append, breakView, changedUpdate, createFragment, forwardUpdateToView, getAttributes, getBreakWeight, getContainer, getDocument, getElement, getEndOffset, getGraphics, getParent, getStartOffset, getToolTipText, getViewFactory, getViewIndex, insert, insertUpdate, isVisible, modelToView, remove, removeAll, removeUpdate, updateChildren, updateLayout, viewToModel
-
Constructor Details
-
BoxView
Constructs aBoxView
.- Parameters:
-
elem
- the element this view is responsible for -
axis
- eitherView.X_AXIS
orView.Y_AXIS
-
-
Method Details
-
getAxis
public int getAxis()Fetches the tile axis property. This is the axis along which the child views are tiled.- Returns:
-
the major axis of the box, either
View.X_AXIS
orView.Y_AXIS
- Since:
- 1.3
-
setAxis
public void setAxis(int axis) Sets the tile axis property. This is the axis along which the child views are tiled.- Parameters:
-
axis
- eitherView.X_AXIS
orView.Y_AXIS
- Since:
- 1.3
-
layoutChanged
public void layoutChanged(int axis) Invalidates the layout along an axis. This happens automatically if the preferences have changed for any of the child views. In some cases the layout may need to be recalculated when the preferences have not changed. The layout can be marked as invalid by calling this method. The layout will be updated the next time thesetSize
method is called on this view (typically in paint).- Parameters:
-
axis
- eitherView.X_AXIS
orView.Y_AXIS
- Since:
- 1.3
-
isLayoutValid
protected boolean isLayoutValid(int axis) Determines if the layout is valid along the given axis.- Parameters:
-
axis
- eitherView.X_AXIS
orView.Y_AXIS
- Returns:
- if the layout is valid along the given axis
- Since:
- 1.4
-
paintChild
Paints a child. By default that is all it does, but a subclass can use this to paint things relative to the child.- Parameters:
-
g
- the graphics context -
alloc
- the allocated region to paint into -
index
- the child index, >= 0 && < getViewCount()
-
replace
Invalidates the layout and resizes the cache of requests/allocations. The child allocations can still be accessed for the old layout, but the new children will have an offset and span of 0.- Overrides:
-
replace
in classCompositeView
- Parameters:
-
index
- the starting index into the child views to insert the new views; this should be a value >= 0 and <= getViewCount -
length
- the number of existing child views to remove; This should be a value >= 0 and <= (getViewCount() - offset) -
elems
- the child views to add; this value can benull
to indicate no children are being added (useful to remove)
-
forwardUpdate
protected void forwardUpdate(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a, ViewFactory f) Forwards the givenDocumentEvent
to the child views that need to be notified of the change to the model. If a child changed its requirements and the allocation was valid prior to forwarding the portion of the box from the starting child to the end of the box will be repainted.- Overrides:
-
forwardUpdate
in classView
- Parameters:
-
ec
- changes to the element this view is responsible for (may benull
if there were no changes) -
e
- the change information from the associated document -
a
- the current allocation of the view -
f
- the factory to use to rebuild if the view has children - Since:
- 1.3
- See Also:
-
preferenceChanged
This is called by a child to indicate its preferred span has changed. This is implemented to throw away cached layout information so that new calculations will be done the next time the children need an allocation.- Overrides:
-
preferenceChanged
in classView
- Parameters:
-
child
- the child view -
width
- true if the width preference should change -
height
- true if the height preference should change - See Also:
-
getResizeWeight
public int getResizeWeight(int axis) Gets the resize weight. A value of 0 or less is not resizable.- 覆盖:
-
getResizeWeight
在类View
中 - 参数:
-
axis
- 可以是View.X_AXIS
或View.Y_AXIS
- 返回:
- 权重
- 抛出:
-
IllegalArgumentException
- 对于无效的轴
-
setSize
public void setSize(float width, float height) 设置视图的大小。如果视图缓存任何布局信息,则应导致视图的布局。实现为使用插入内部的大小调用布局方法。 -
paint
使用给定的渲染表面和该表面上的区域呈现BoxView
。只会呈现与给定Graphics
的剪切边界相交的子项。 -
getChildAllocation
获取给定子视图的分配。这使得可以找出各个视图的位置。如果布局无效,则实现为返回null
,否则执行超类行为。- 覆盖:
-
getChildAllocation
在类CompositeView
中 - 参数:
-
index
- 子项的索引,>= 0 && > getViewCount() -
a
- 分配给此视图的分配 - 返回:
-
子项的分配;如果
a
为null
,则返回null
;如果布局无效,则返回null
-
modelToView
提供从文档模型坐标空间到其映射视图的坐标空间的映射。在调用超类之前,确保分配有效。- 覆盖:
-
modelToView
在类CompositeView
中 - 参数:
-
pos
- 要转换的位置 >= 0 -
a
- 要呈现的分配区域 -
b
-Position.Bias.Forward
或Position.Bias.Backward
的偏移值 - 返回:
- 给定位置的边界框
- 抛出:
-
BadLocationException
- 如果给定位置不表示关联文档中的有效位置 - 参见:
-
viewToModel
提供从视图坐标空间到模型的逻辑坐标空间的映射。- 覆盖:
-
viewToModel
在类CompositeView
中 - 参数:
-
x
- 要转换的视图位置的x坐标 >= 0 -
y
- 要转换的视图位置的y坐标 >= 0 -
a
- 要呈现的分配区域 -
bias
-Position.Bias.Forward
或Position.Bias.Backward
- 返回:
- 最能代表视图中给定点的模型内位置 >= 0
- 参见:
-
getAlignment
public float getAlignment(int axis) 确定沿轴线的此视图的所需对齐方式。实现为提供所需的总对齐,以使具有对齐点沿被平铺的轴的垂直轴对齐的子项定位所需的总对齐。被平铺的轴将请求居中对齐(即0.5f)。- 覆盖:
-
getAlignment
在类View
中 - 参数:
-
axis
- 可以是View.X_AXIS
或View.Y_AXIS
- 返回:
- 所需的对齐方式 >= 0.0f && <= 1.0f;这应该是一个值介于0.0和1.0之间,其中0表示在原点对齐,1.0表示远离原点的完整跨度对齐;对齐值为0.5将是视图的中心
- 抛出:
-
IllegalArgumentException
- 对于无效的轴
-
getPreferredSpan
public float getPreferredSpan(int axis) 确定此视图沿轴线的首选跨度。- 指定者:
-
getPreferredSpan
在类View
中 - 参数:
-
axis
- 可以是View.X_AXIS
或View.Y_AXIS
- 返回:
- 视图希望呈现的跨度 >= 0;通常告诉视图呈现返回的跨度,尽管不能保证;父级可能选择调整或分割视图
- 抛出:
-
IllegalArgumentException
- 对于无效的轴类型
-
getMinimumSpan
public float getMinimumSpan(int axis) 确定此视图沿轴线的最小跨度。- 覆盖:
-
getMinimumSpan
在类View
中 - 参数:
-
axis
- 可以是View.X_AXIS
或View.Y_AXIS
- 返回:
- 视图希望呈现的跨度 >= 0;通常告诉视图呈现返回的跨度,尽管不能保证;父级可能选择调整或分割视图
- 抛出:
-
IllegalArgumentException
- 对于无效的轴类型 - 参见:
-
getMaximumSpan
public float getMaximumSpan(int axis) 确定此视图沿轴线的最大跨度。- 覆盖:
-
getMaximumSpan
在类View
中 - 参数:
-
axis
- 可以是View.X_AXIS
或View.Y_AXIS
- 返回:
- 视图希望呈现的跨度 >= 0;通常告诉视图呈现返回的跨度,尽管不能保证;父级可能选择调整或分割视图
- 抛出:
-
IllegalArgumentException
- 对于无效的轴类型 - 参见:
-
isAllocationValid
protected boolean isAllocationValid()子项的分配是否仍然有效?- 返回:
- 如果分配仍然有效,则为true
-
isBefore
确定点是否落在分配区域之前。- 指定者:
-
isBefore
在类CompositeView
中 - 参数:
-
x
- X坐标 >= 0 -
y
- Y坐标 >= 0 -
innerAlloc
- 分配的区域;这是插入内部的区域 - 返回:
- 如果点位于区域之前,则为true,否则为false
-
isAfter
确定点是否落在分配区域之后。- 指定者:
-
isAfter
在类CompositeView
中 - 参数:
-
x
- X坐标 >= 0 -
y
- Y坐标 >= 0 -
innerAlloc
- 分配的区域;这是插入内部的区域 - 返回:
- 如果点位于区域之后,则为true,否则为false
-
getViewAtPoint
获取给定坐标处的子视图。- 指定者:
-
getViewAtPoint
在类CompositeView
中 - 参数:
-
x
- X坐标 >= 0 -
y
- Y坐标 >= 0 -
alloc
- 父级在进入时的内部分配,应在退出时更改为子级的分配 - 返回:
- 视图
-
childAllocation
为子视图分配区域。- 指定者:
-
childAllocation
在类CompositeView
中 - 参数:
-
index
- 要分配的子视图的索引,>= 0 && < getViewCount() -
alloc
- 分配的区域
-
layout
protected void layout(int width, int height) 在盒子上执行布局- 参数:
-
width
- 宽度(内部填充)>= 0 -
height
- 高度(内部填充)>= 0
-
getWidth
public int getWidth()返回盒子的当前宽度。这是上次分配的宽度。- 返回:
- 盒子的当前宽度
-
getHeight
public int getHeight()返回盒子的当前高度。这是上次分配的高度。- 返回:
- 盒子的当前高度
-
layoutMajorAxis
protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans) 为盒子的主轴(即它代表的轴)执行布局。布局的结果(每个子视图的偏移和跨度)被放置在给定的数组中,这些数组表示沿主轴对子视图的分配。- 参数:
-
targetSpan
- 给定给视图的总跨度,将用于布局子视图 -
axis
- 正在布局的轴 -
offsets
- 每个子视图相对于视图原点的偏移量;这是一个返回值,由此方法的实现填充 -
spans
- 每个子视图的跨度;这是一个返回值,由此方法的实现填充
-
layoutMinorAxis
protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) 为盒子的次轴(即它代表的与主轴正交的轴)执行布局。布局的结果(每个子视图的偏移和跨度)被放置在给定的数组中,这些数组表示沿次轴对子视图的分配。- 参数:
-
targetSpan
- 给定给视图的总跨度,将用于布局子视图 -
axis
- 正在布局的轴 -
offsets
- 每个子视图相对于视图原点的偏移量;这是一个返回值,由此方法的实现填充 -
spans
- 每个子视图的跨度;这是一个返回值,由此方法的实现填充
-
calculateMajorAxisRequirements
计算主轴axis
的大小需求。- 参数:
-
axis
- 正在研究的轴 -
r
-SizeRequirements
对象;如果为null
,将创建一个 - 返回:
-
新初始化的
SizeRequirements
对象 - 参见:
-
calculateMinorAxisRequirements
计算次轴axis
的大小需求。- 参数:
-
axis
- 正在研究的轴 -
r
-SizeRequirements
对象;如果为null
,将创建一个 - 返回:
-
新初始化的
SizeRequirements
对象 - 参见:
-
baselineLayout
protected void baselineLayout(int targetSpan, int axis, int[] offsets, int[] spans) 计算此BoxView
中每个子视图的位置和范围,给定targetSpan
,即我们要处理的区域的宽度(或高度)。- 参数:
-
targetSpan
- 给定给视图的总跨度,将用于布局子视图 -
axis
- 正在研究的轴,要么是View.X_AXIS
,要么是View.Y_AXIS
-
offsets
- 由此方法填充的空数组,其中包含指定每个子视图位置的值 -
spans
- 由此方法填充的空数组,其中包含指定每个子视图范围的值
-
baselineRequirements
通过检查每个子视图的大小来计算此BoxView
的大小需求。- 参数:
-
axis
- 正在研究的轴 -
r
-SizeRequirements
对象;如果为null
,将创建一个 - 返回:
-
新初始化的
SizeRequirements
对象
-
getOffset
protected int getOffset(int axis, int childIndex) 获取特定子视图当前布局的偏移量。- 参数:
-
axis
- 正在研究的轴 -
childIndex
- 请求的子视图的索引 - 返回:
- 指定子视图的偏移量(位置)
-
getSpan
protected int getSpan(int axis, int childIndex) 获取特定子视图当前布局的跨度。- 参数:
-
axis
- 正在研究的轴 -
childIndex
- 请求的子视图的索引 - 返回:
- 指定子视图的跨度(宽度或高度)
-
flipEastAndWestAtEnds
确定下一个视图的布局方向。考虑索引为n的视图。通常,View
从左到右布局,因此东侧的View
将在索引n + 1处,西侧的View
将在索引n - 1处。在某些情况下,例如双向文本,可能东侧的View
不在索引n + 1处,而在索引n - 1处,或者西侧的View
不在索引n - 1处,而在索引n + 1处。在这种情况下,此方法将返回true,表示View
按降序布局。否则,该方法将返回false,表示View
按升序布局。如果接收器沿
Y_AXIS
布置其View
,则将返回从负责渲染position
和bias
的View
上调用相同方法的值。否则,将返回false。- 覆盖:
-
flipEastAndWestAtEnds
在类CompositeView
中 - 参数:
-
position
- 模型中的位置 -
bias
-Position.Bias.Forward
或Position.Bias.Backward
- 返回:
-
如果围绕渲染
position
和bias
的View
周围的View
按降序布局,则为true;否则为false
-