boxview.java

来自「linux下建立JAVA虚拟机的源码KAFFE」· Java 代码 · 共 974 行 · 第 1/3 页

JAVA
974
字号
      max = Integer.MAX_VALUE;    return max;  }  /**   * Returns the minimum span of this view along the specified axis.   * This calculates the minimum span using   * {@link #calculateMajorAxisRequirements} or   * {@link #calculateMinorAxisRequirements} (depending on the axis) and   * returns the resulting minimum span.   *   * @param axis the axis   *   * @return the minimum span of this view along the specified axis   */  public float getMinimumSpan(int axis)  {    updateRequirements(axis);    return requirements[axis].minimum;  }  /**   * This method is obsolete and no longer in use. It is replaced by   * {@link #calculateMajorAxisRequirements(int, SizeRequirements)} and   * {@link #calculateMinorAxisRequirements(int, SizeRequirements)}.   *   * @param axis the axis that is examined   * @param sr 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 baselineRequirements(int axis,                                                  SizeRequirements sr)  {    updateChildRequirements(axis);    SizeRequirements res = sr;    if (res == null)      res = new SizeRequirements();    float minLeft = 0;    float minRight = 0;    float prefLeft = 0;    float prefRight = 0;    float maxLeft = 0;    float maxRight = 0;    for (int i = 0; i < childReqs[axis].length; i++)      {        float myMinLeft = childReqs[axis][i].minimum * childReqs[axis][i].alignment;        float myMinRight = childReqs[axis][i].minimum - myMinLeft;        minLeft = Math.max(myMinLeft, minLeft);        minRight = Math.max(myMinRight, minRight);        float myPrefLeft = childReqs[axis][i].preferred * childReqs[axis][i].alignment;        float myPrefRight = childReqs[axis][i].preferred - myPrefLeft;        prefLeft = Math.max(myPrefLeft, prefLeft);        prefRight = Math.max(myPrefRight, prefRight);        float myMaxLeft = childReqs[axis][i].maximum * childReqs[axis][i].alignment;        float myMaxRight = childReqs[axis][i].maximum - myMaxLeft;        maxLeft = Math.max(myMaxLeft, maxLeft);        maxRight = Math.max(myMaxRight, maxRight);      }    int minSize = (int) (minLeft + minRight);    int prefSize = (int) (prefLeft + prefRight);    int maxSize = (int) (maxLeft + maxRight);    float align = prefLeft / (prefRight + prefLeft);    if (Float.isNaN(align))      align = 0;    res.alignment = align;    res.maximum = maxSize;    res.preferred = prefSize;    res.minimum = minSize;    return res;  }  /**   * Calculates the layout of the children of this <code>BoxView</code> along   * the specified axis.   *   * @param span the target span   * @param axis the axis that is examined   * @param offsets an empty array, filled with the offsets of the children   * @param spans an empty array, filled with the spans of the children   */  protected void baselineLayout(int span, int axis, int[] offsets,                                int[] spans)  {    updateChildRequirements(axis);    updateRequirements(axis);    // Calculate the spans and offsets using the SizeRequirements uility    // methods.    SizeRequirements.calculateAlignedPositions(span, requirements[axis],                                               childReqs[axis], offsets, spans);  }  /**   * Calculates the size requirements of this <code>BoxView</code> along   * its major axis, that is the axis specified in the constructor.   *   * @param axis the axis that is examined   * @param sr 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 calculateMajorAxisRequirements(int axis,                                                           SizeRequirements sr)  {    updateChildRequirements(axis);    SizeRequirements result = sr;    if (result == null)      result = new SizeRequirements();    long minimum = 0;    long preferred = 0;    long maximum = 0;    for (int i = 0; i < children.length; i++)      {        minimum += childReqs[axis][i].minimum;        preferred += childReqs[axis][i].preferred;        maximum += childReqs[axis][i].maximum;      }    // Overflow check.    if (minimum > Integer.MAX_VALUE)      minimum = Integer.MAX_VALUE;    if (preferred > Integer.MAX_VALUE)      preferred = Integer.MAX_VALUE;    if (maximum > Integer.MAX_VALUE)      maximum = Integer.MAX_VALUE;    result.minimum = (int) minimum;    result.preferred = (int) preferred;    result.maximum = (int) maximum;    result.alignment = 0.5F;    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.   *   * @param axis the axis that is examined   * @param sr 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 sr)  {    updateChildRequirements(axis);    SizeRequirements res = sr;    if (res == null)      res = new SizeRequirements();    float minLeft = 0;    float minRight = 0;    float prefLeft = 0;    float prefRight = 0;    float maxLeft = 0;    float maxRight = 0;    for (int i = 0; i < childReqs[axis].length; i++)      {        float myMinLeft = childReqs[axis][i].minimum * childReqs[axis][i].alignment;        float myMinRight = childReqs[axis][i].minimum - myMinLeft;        minLeft = Math.max(myMinLeft, minLeft);        minRight = Math.max(myMinRight, minRight);        float myPrefLeft = childReqs[axis][i].preferred * childReqs[axis][i].alignment;        float myPrefRight = childReqs[axis][i].preferred - myPrefLeft;        prefLeft = Math.max(myPrefLeft, prefLeft);        prefRight = Math.max(myPrefRight, prefRight);        float myMaxLeft = childReqs[axis][i].maximum * childReqs[axis][i].alignment;        float myMaxRight = childReqs[axis][i].maximum - myMaxLeft;        maxLeft = Math.max(myMaxLeft, maxLeft);        maxRight = Math.max(myMaxRight, maxRight);      }    int minSize = (int) (minLeft + minRight);    int prefSize = (int) (prefLeft + prefRight);    int maxSize = (int) (maxLeft + maxRight);    float align = prefLeft / (prefRight + prefLeft);    if (Float.isNaN(align))      align = 0;    res.alignment = align;    res.maximum = maxSize;    res.preferred = prefSize;    res.minimum = minSize;    return res;  }    /**   * Returns <code>true</code> if the specified point lies before the   * given <code>Rectangle</code>, <code>false</code> otherwise.   *   * &quot;Before&quot; is typically defined as being to the left or above.   *   * @param x the X coordinate of the point   * @param y the Y coordinate of the point   * @param r the rectangle to test the point against   *   * @return <code>true</code> if the specified point lies before the   *         given <code>Rectangle</code>, <code>false</code> otherwise   */  protected boolean isBefore(int x, int y, Rectangle r)  {    boolean result = false;    if (myAxis == X_AXIS)      result = x < r.x;    else      result = y < r.y;    return result;  }  /**   * Returns <code>true</code> if the specified point lies after the   * given <code>Rectangle</code>, <code>false</code> otherwise.   *   * &quot;After&quot; is typically defined as being to the right or below.   *   * @param x the X coordinate of the point   * @param y the Y coordinate of the point   * @param r the rectangle to test the point against   *   * @return <code>true</code> if the specified point lies after the   *         given <code>Rectangle</code>, <code>false</code> otherwise   */  protected boolean isAfter(int x, int y, Rectangle r)  {    boolean result = false;    if (myAxis == X_AXIS)      result = x > r.x;    else      result = y > r.y;    return result;  }  /**   * Returns the child <code>View</code> at the specified location.   *   * @param x the X coordinate   * @param y the Y coordinate   * @param r the inner allocation of this <code>BoxView</code> on entry,   *        the allocation of the found child on exit   *   * @return the child <code>View</code> at the specified location   */  protected View getViewAtPoint(int x, int y, Rectangle r)  {    View result = null;    int count = getViewCount();    Rectangle copy = new Rectangle(r);    for (int i = 0; i < count; ++i)      {        copy.setBounds(r);        childAllocation(i, r);        if (copy.contains(x, y))          {            result = getView(i);            break;          }      }        if (result == null && count > 0)      return getView(count - 1);    return result;  }  /**   * Computes the allocation for a child <code>View</code>. The parameter   * <code>a</code> stores the allocation of this <code>CompositeView</code>   * and is then adjusted to hold the allocation of the child view.   *    * @param index   *          the index of the child <code>View</code>   * @param a   *          the allocation of this <code>CompositeView</code> before the   *          call, the allocation of the child on exit   */  protected void childAllocation(int index, Rectangle a)  {    if (! isAllocationValid())      layout(a.width, a.height);    a.x += offsets[X_AXIS][index];    a.y += offsets[Y_AXIS][index];    a.width = spans[X_AXIS][index];    a.height = spans[Y_AXIS][index];  }  /**   * Lays out the children of this <code>BoxView</code> with the specified   * bounds.   *   * @param width the width of the allocated region for the children (that   *        is the inner allocation of this <code>BoxView</code>   * @param height the height of the allocated region for the children (that   *        is the inner allocation of this <code>BoxView</code>   */  protected void layout(int width, int height)  {    int[] newSpan = new int[]{ width, height };    int count = getViewCount();    // Update minor axis as appropriate. We need to first update the minor    // axis layout because that might affect the children's preferences along    // the major axis.    int minorAxis = myAxis == X_AXIS ? Y_AXIS : X_AXIS;    if ((! isLayoutValid(minorAxis)) || newSpan[minorAxis] != span[minorAxis])      {        layoutValid[minorAxis] = false;        span[minorAxis] = newSpan[minorAxis];

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?