flowview.java
来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 606 行 · 第 1/2 页
JAVA
606 行
View toBeBroken = row.getView(breakIndex); View brokenView = toBeBroken.breakView(axis, toBeBroken.getStartOffset(), breakX, breakSpan); row.replace(breakIndex, count - breakIndex, new View[]{brokenView}); } } } /** * This special subclass of <code>View</code> is used to represent * the logical representation of this view. It does not support any * visual representation, this is handled by the physical view implemented * in the <code>FlowView</code>. */ class LogicalView extends BoxView { /** * Creates a new LogicalView instance. */ LogicalView(Element el, int axis) { super(el, axis); } } /** * The shared instance of FlowStrategy. */ static final FlowStrategy sharedStrategy = new FlowStrategy(); /** * The span of the <code>FlowView</code> that should be flowed. */ protected int layoutSpan; /** * Represents the logical child elements of this view, encapsulated within * one parent view (an instance of a package private <code>LogicalView</code> * class). These will be translated to a set of real views that are then * displayed on screen. This translation is performed by the inner class * {@link FlowStrategy}. */ protected View layoutPool; /** * The <code>FlowStrategy</code> to use for translating between the * logical and physical view. */ protected FlowStrategy strategy; /** * Indicates if the flow should be rebuild during the next layout. */ private boolean layoutDirty; /** * Creates a new <code>FlowView</code> for the given * <code>Element</code> and <code>axis</code>. * * @param element the element that is rendered by this FlowView * @param axis the axis along which the view is tiled, either * <code>View.X_AXIS</code> or <code>View.Y_AXIS</code>, the flow * axis is orthogonal to this one */ public FlowView(Element element, int axis) { super(element, axis); strategy = sharedStrategy; layoutDirty = true; } /** * Returns the axis along which the view should be flowed. This is * orthogonal to the axis along which the boxes are tiled. * * @return the axis along which the view should be flowed */ public int getFlowAxis() { int axis = getAxis(); int flowAxis; if (axis == X_AXIS) flowAxis = Y_AXIS; else flowAxis = X_AXIS; return flowAxis; } /** * Returns the span of the flow for the specified child view. A flow * layout can be shaped by providing different span values for different * child indices. The default implementation returns the entire available * span inside the view. * * @param index the index of the child for which to return the span * * @return the span of the flow for the specified child view */ public int getFlowSpan(int index) { return layoutSpan; } /** * Returns the location along the flow axis where the flow span starts * given a child view index. The flow can be shaped by providing * different values here. * * @param index the index of the child for which to return the flow location * * @return the location along the flow axis where the flow span starts */ public int getFlowStart(int index) { return getLeftInset(); // TODO: Is this correct? } /** * Creates a new view that represents a row within a flow. * * @return a view for a new row */ protected abstract View createRow(); /** * Loads the children of this view. The <code>FlowView</code> does not * directly load its children. Instead it creates a logical view * (@{link #layoutPool}) which is filled by the logical child views. * The real children are created at layout time and each represent one * row. * * This method is called by {@link View#setParent} in order to initialize * the view. * * @param vf the view factory to use for creating the child views */ protected void loadChildren(ViewFactory vf) { if (layoutPool == null) { layoutPool = new LogicalView(getElement(), getAxis()); layoutPool.setParent(this); } } /** * Performs the layout of this view. If the span along the flow axis changed, * this first calls {@link FlowStrategy#layout} in order to rebuild the * rows of this view. Then the superclass's behaviour is called to arrange * the rows within the box. * * @param width the width of the view * @param height the height of the view */ protected void layout(int width, int height) { int flowAxis = getFlowAxis(); if (flowAxis == X_AXIS) { if (layoutSpan != width) { layoutChanged(Y_AXIS); layoutSpan = width; } } else { if (layoutSpan != height) { layoutChanged(X_AXIS); layoutSpan = height; } } if (layoutDirty) { strategy.layout(this); layoutDirty = false; } if (getPreferredSpan(getAxis()) != height) preferenceChanged(this, false, true); super.layout(width, height); } /** * Receice notification that some content has been inserted in the region * that this view is responsible for. This calls * {@link FlowStrategy#insertUpdate}. * * @param changes the document event describing the changes * @param a the current allocation of the view * @param vf the view factory that is used for creating new child views */ public void insertUpdate(DocumentEvent changes, Shape a, ViewFactory vf) { // First we must send the insertUpdate to the logical view so it can // be updated accordingly. layoutPool.insertUpdate(changes, a, vf); strategy.insertUpdate(this, changes, getInsideAllocation(a)); layoutDirty = true; } /** * Receice notification that some content has been removed from the region * that this view is responsible for. This calls * {@link FlowStrategy#removeUpdate}. * * @param changes the document event describing the changes * @param a the current allocation of the view * @param vf the view factory that is used for creating new child views */ public void removeUpdate(DocumentEvent changes, Shape a, ViewFactory vf) { strategy.removeUpdate(this, changes, getInsideAllocation(a)); layoutDirty = true; } /** * Receice notification that some attributes changed in the region * that this view is responsible for. This calls * {@link FlowStrategy#changedUpdate}. * * @param changes the document event describing the changes * @param a the current allocation of the view * @param vf the view factory that is used for creating new child views */ public void changedUpdate(DocumentEvent changes, Shape a, ViewFactory vf) { strategy.changedUpdate(this, changes, getInsideAllocation(a)); layoutDirty = true; } /** * Returns the index of the child <code>View</code> for the given model * position. * * This is implemented to iterate over the children of this * view (the rows) and return the index of the first view that contains * the given position. * * @param pos the model position for whicht the child <code>View</code> is * queried * * @return the index of the child <code>View</code> for the given model * position */ protected int getViewIndexAtPosition(int pos) { // First make sure we have a valid layout. if (!isAllocationValid()) layout(getWidth(), getHeight()); int count = getViewCount(); int result = -1; for (int i = 0; i < count; ++i) { View child = getView(i); int start = child.getStartOffset(); int end = child.getEndOffset(); if (start <= pos && end > pos) { result = i; break; } } return result; } /** * Calculates the size requirements of this <code>BoxView</code> along * its minor axis, that is the axis opposite to the axis specified in the * constructor. * * This is overridden and forwards the request to the logical view. * * @param axis the axis that is examined * @param r the <code>SizeRequirements</code> object to hold the result, * if <code>null</code>, a new one is created * * @return the size requirements for this <code>BoxView</code> along * the specified axis */ protected SizeRequirements calculateMinorAxisRequirements(int axis, SizeRequirements r) { // We need to call super here so that the alignment is properly // calculated. SizeRequirements res = super.calculateMinorAxisRequirements(axis, r); res.minimum = (int) layoutPool.getMinimumSpan(axis); res.preferred = (int) layoutPool.getPreferredSpan(axis); res.maximum = (int) layoutPool.getMaximumSpan(axis); return res; }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?