boxview.java
来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 974 行 · 第 1/3 页
JAVA
974 行
layoutMinorAxis(span[minorAxis], minorAxis, offsets[minorAxis], spans[minorAxis]); // Update the child view's sizes. for (int i = 0; i < count; ++i) { getView(i).setSize(spans[X_AXIS][i], spans[Y_AXIS][i]); } layoutValid[minorAxis] = true; } // Update major axis as appropriate. if ((! isLayoutValid(myAxis)) || newSpan[myAxis] != span[myAxis]) { layoutValid[myAxis] = false; span[myAxis] = newSpan[myAxis]; layoutMajorAxis(span[myAxis], myAxis, offsets[myAxis], spans[myAxis]); // Update the child view's sizes. for (int i = 0; i < count; ++i) { getView(i).setSize(spans[X_AXIS][i], spans[Y_AXIS][i]); } layoutValid[myAxis] = true; } if (layoutValid[myAxis] == false) System.err.println("WARNING: Major axis layout must be valid after layout"); if (layoutValid[minorAxis] == false) System.err.println("Minor axis layout must be valid after layout"); } /** * Performs the layout along the major axis of a <code>BoxView</code>. * * @param targetSpan the (inner) span of the <code>BoxView</code> in which * to layout the children * @param axis the axis along which the layout is performed * @param offsets the array that holds the offsets of the children on exit * @param spans the array that holds the spans of the children on exit */ protected void layoutMajorAxis(int targetSpan, int axis, int[] offsets, int[] spans) { updateChildRequirements(axis); updateRequirements(axis); // Calculate the spans and offsets using the SizeRequirements uility // methods. SizeRequirements.calculateTiledPositions(targetSpan, requirements[axis], childReqs[axis], offsets, spans); } /** * Performs the layout along the minor axis of a <code>BoxView</code>. * * @param targetSpan the (inner) span of the <code>BoxView</code> in which * to layout the children * @param axis the axis along which the layout is performed * @param offsets the array that holds the offsets of the children on exit * @param spans the array that holds the spans of the children on exit */ protected void layoutMinorAxis(int targetSpan, int axis, int[] offsets, int[] spans) { updateChildRequirements(axis); updateRequirements(axis); // Calculate the spans and offsets using the SizeRequirements uility // methods. SizeRequirements.calculateAlignedPositions(targetSpan, requirements[axis], childReqs[axis], offsets, spans); } /** * Returns <code>true</code> if the cached allocations for the children * are still valid, <code>false</code> otherwise. * * @return <code>true</code> if the cached allocations for the children * are still valid, <code>false</code> otherwise */ protected boolean isAllocationValid() { return isLayoutValid(X_AXIS) && isLayoutValid(Y_AXIS); } /** * Return the current width of the box. This is the last allocated width. * * @return the current width of the box */ public int getWidth() { return span[X_AXIS]; } /** * Return the current height of the box. This is the last allocated height. * * @return the current height of the box */ public int getHeight() { return span[Y_AXIS]; } /** * Sets the size of the view. If the actual size has changed, the layout * is updated accordingly. * * @param width the new width * @param height the new height */ public void setSize(float width, float height) { layout((int) width, (int) height); } /** * Returns the span for the child view with the given index for the specified * axis. * * @param axis the axis to examine, either <code>X_AXIS</code> or * <code>Y_AXIS</code> * @param childIndex the index of the child for for which to return the span * * @return the span for the child view with the given index for the specified * axis */ protected int getSpan(int axis, int childIndex) { if (axis != X_AXIS && axis != Y_AXIS) throw new IllegalArgumentException("Illegal axis argument"); return spans[axis][childIndex]; } /** * Returns the offset for the child view with the given index for the * specified axis. * * @param axis the axis to examine, either <code>X_AXIS</code> or * <code>Y_AXIS</code> * @param childIndex the index of the child for for which to return the span * * @return the offset for the child view with the given index for the * specified axis */ protected int getOffset(int axis, int childIndex) { if (axis != X_AXIS && axis != Y_AXIS) throw new IllegalArgumentException("Illegal axis argument"); return offsets[axis][childIndex]; } /** * 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. * * @param axis the axis which is examined * * @return the alignment for this box view for the specified axis */ public float getAlignment(int axis) { float align; if (axis == myAxis) align = 0.5F; else { updateRequirements(axis); align = requirements[axis].alignment; } return align; } /** * Called by a child View when its preferred span has changed. * * @param width indicates that the preferred width of the child changed. * @param height indicates that the preferred height of the child changed. * @param child the child View. */ public void preferenceChanged(View child, boolean width, boolean height) { if (width) layoutValid[X_AXIS] = false; if (height) layoutValid[Y_AXIS] = false; super.preferenceChanged(child, width, height); } /** * Maps the document model position <code>pos</code> 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. */ public Shape modelToView(int pos, Shape a, Position.Bias bias) throws BadLocationException { // Make sure everything is allocated properly and then call super if (! isAllocationValid()) { Rectangle bounds = a.getBounds(); layout(bounds.width, bounds.height); } return super.modelToView(pos, a, bias); } /** * Returns the resize weight of this view. A value of <code>0</code> or less * means this view is not resizeable. Positive values make the view * resizeable. This implementation returns <code>0</code> for the major * axis and <code>1</code> for the minor axis of this box view. * * @param axis the axis * * @return the resizability of this view along the specified axis * * @throws IllegalArgumentException if <code>axis</code> is invalid */ public int getResizeWeight(int axis) { if (axis != X_AXIS && axis != Y_AXIS) throw new IllegalArgumentException("Illegal axis argument"); int weight = 1; if (axis == myAxis) weight = 0; return weight; } /** * Returns the child allocation for the child view with the specified * <code>index</code>. If the layout is invalid, this returns * <code>null</code>. * * @param index the child view index * @param a the allocation to this view * * @return the child allocation for the child view with the specified * <code>index</code> or <code>null</code> if the layout is invalid * or <code>a</code> is null */ public Shape getChildAllocation(int index, Shape a) { Shape ret = null; if (isAllocationValid() && a != null) ret = super.getChildAllocation(index, a); return ret; } protected void forwardUpdate(DocumentEvent.ElementChange ec, DocumentEvent e, Shape a, ViewFactory vf) { // FIXME: What to do here? super.forwardUpdate(ec, e, a, vf); } public int viewToModel(float x, float y, Shape a, Position.Bias[] bias) { // FIXME: What to do here? return super.viewToModel(x, y, a, bias); } protected boolean flipEastAndWestEnds(int position, Position.Bias bias) { // FIXME: What to do here? return super.flipEastAndWestAtEnds(position, bias); } /** * Updates the child requirements along the specified axis. The requirements * are only updated if the layout for the specified axis is marked as * invalid. * * @param axis the axis to be updated */ private void updateChildRequirements(int axis) { if (! isLayoutValid(axis)) { int numChildren = getViewCount(); if (childReqs[axis] == null || childReqs[axis].length != numChildren) childReqs[axis] = new SizeRequirements[numChildren]; for (int i = 0; i < numChildren; ++i) { View child = getView(i); childReqs[axis][i] = new SizeRequirements((int) child.getMinimumSpan(axis), (int) child.getPreferredSpan(axis), (int) child.getMaximumSpan(axis), child.getAlignment(axis)); } } } /** * Updates the view's cached requirements along the specified axis if * necessary. The requirements are only updated if the layout for the * specified axis is marked as invalid. * * @param axis the axis */ private void updateRequirements(int axis) { if (! layoutValid[axis]) { if (axis == myAxis) requirements[axis] = calculateMajorAxisRequirements(axis, requirements[axis]); else requirements[axis] = calculateMinorAxisRequirements(axis, requirements[axis]); } }}
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?