⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 staticlayoutmanager.java

📁 Java的Web报表库
💻 JAVA
📖 第 1 页 / 共 2 页
字号:

    // now apply the maximum limit defined for that band in case the calculated height
    // is higher than the given max height.
    height = (float) Math.min(height, maxSize.getHeight());
    width = (float) Math.min(width, maxSize.getWidth());

    //Log.debug ("Dimension after static correction [PREF]: " + width + " -> " + height);
    final FloatDimension base = new FloatDimension(width, height);
    Point2D absPos = null;
    Dimension2D absDim = null;

    // calculate relative widths
    for (int i = 0; i < elements.length; i++)
    {
      final Element e = elements[i];

      if (e.isVisible() == false)
      {
        continue;
      }
      final boolean staticWidth = isElementStaticWidth(e);
      final boolean staticHeight = isElementStaticHeight(e);
      if (staticWidth == false || staticHeight == false)
      {
        absPos = correctPoint((Point2D) e.getStyle().getStyleProperty(ABSOLUTE_POS),
            base, absPos);
        // check whether the element would be visible .. if not visible, then
        // dont do anything ...
        if (absPos.getX() > base.getWidth() || absPos.getY() > base.getHeight())
        {
          // dont display, as this element is larger than the container ...
          continue;
        }

        absDim = correctDimension(getPreferredSize(e, base), base, absDim);

        if (staticWidth == false)
        {
          width = Math.max((float) (absDim.getWidth() + absPos.getX()), width);
        }
        if (staticHeight == false)
        {
          height = Math.max((float) (absDim.getHeight() + absPos.getY()), height);
        }
      }
    }

    // now apply the minimum limit defined for that band in case the calculated height
    // is lower than the given minimum height.
    height = (float) Math.max(height, minSize.getHeight());
    width = (float) Math.max(width, minSize.getWidth());

    // now take the maximum limit defined for that band into account for a last time.
    // or specifying -140 would be a nice way to kill the layout ...
    height = (float) Math.min(height, maxSize.getHeight());
    width = (float) Math.min(width, maxSize.getWidth());

    // now align the calculated data ...
    base.setSize(align(width, getLayoutSupport().getHorizontalAlignmentBorder()),
        align(height, getLayoutSupport().getVerticalAlignmentBorder()));
    return base;
  }

  /**
   * Calculates the minimum layout size for a band. The width for the child elements
   * are not calculated, as we assume that the width's are defined fixed within the
   * parent.
   *
   * @param b  the band.
   * @param containerBounds the bounds of the bands parents.
   *
   * @return the minimum size.
   */
  public synchronized Dimension2D minimumLayoutSize(final Band b, final Dimension2D containerBounds)
  {
    final ElementLayoutInformation eli = createLayoutInformationForMinimumSize(b, containerBounds);
    final Dimension2D maxSize = eli.getMaximumSize();
    final Dimension2D minSize = eli.getMinimumSize();

    // we use the max width, as the width is bound to the outside container,
    // either an other band or the page; the width is required to compute dynamic
    // elements or elements with an 100% width ...
    float height = (float) minSize.getHeight();
    float width = (float) maxSize.getWidth();

    // Check the position of the elements inside and calculate the minimum width
    // needed to display all elements
    final Element[] elements = b.getElementArray();

    // calculate absolute width
    for (int i = 0; i < elements.length; i++)
    {
      final Element e = elements[i];

      if (e.isVisible() == false)
      {
        continue;
      }
      final boolean staticWidth = isElementStaticWidth(e);
      final boolean staticHeight = isElementStaticHeight(e);
      if (staticWidth || staticHeight)
      {
        // absPos is readonly ...
        final Point2D absPos = (Point2D) e.getStyle().getStyleProperty(ABSOLUTE_POS);
        // check whether the element would be visible .. if not visible, then
        // dont do anything ...
        if (absPos.getX() > maxSize.getWidth() || absPos.getY() > maxSize.getHeight())
        {
          // dont display, as this element is larger than the container ...
          continue;
        }
        final Dimension2D size = getMinimumSize(e, maxSize);

        if (staticWidth)
        {
          width = (float) Math.max(size.getWidth() + absPos.getX(), width);
        }
        if (staticHeight)
        {
          height = (float) Math.max(size.getHeight() + absPos.getY(), height);
        }
      }
    }

    //Log.debug ("Dimension after static part: " + width + " -> " + height);
    // now apply the minimum limit defined for that band in case the calculated height
    // is lower than the given minimum height.
    height = (float) Math.max(height, minSize.getHeight());
    width = (float) Math.max(width, minSize.getWidth());

    // now apply the maximum limit defined for that band in case the calculated height
    // is higher than the given max height.
    height = (float) Math.min(height, maxSize.getHeight());
    width = (float) Math.min(width, maxSize.getWidth());

    //Log.debug ("Dimension after static correction [MIN]: " + width + " -> " + height);
    final FloatDimension base = new FloatDimension(width, height);
    Point2D absPos = null;
    Dimension2D absDim = null;

    // calculate relative widths
    for (int i = 0; i < elements.length; i++)
    {
      final Element e = elements[i];

      if (e.isVisible() == false)
      {
        continue;
      }
      final boolean staticWidth = isElementStaticWidth(e);
      final boolean staticHeight = isElementStaticHeight(e);
      if (staticWidth == false || staticHeight == false)
      {
        absPos = correctPoint((Point2D) e.getStyle().getStyleProperty(ABSOLUTE_POS), base, absPos);
        // check whether the element would be visible .. if not visible, then
        // dont do anything ...
        if (absPos.getX() > base.getWidth() || absPos.getY() > base.getHeight())
        {
          // dont display, as this element is larger than the container ...
          continue;
        }
        absDim = correctDimension(getMinimumSize(e, base), base, absDim);

        if (staticWidth == false)
        {
          width = (float) Math.max(absDim.getWidth() + absPos.getX(), width);
        }
        if (staticHeight == false)
        {
          height = (float) Math.max(absDim.getHeight() + absPos.getY(), height);
        }
        //Log.debug ("Element " + e + " -> " + size);
      }
    }

    //Log.debug ("Dimension after dynamic part: " + width + " -> " + height);
    // now apply the minimum limit defined for that band in case the calculated height
    // is lower than the given minimum height.
    height = (float) Math.max(height, minSize.getHeight());
    width = (float) Math.max(width, minSize.getWidth());

    // now take the maximum limit defined for that band into account for a last time.
    height = (float) Math.min(height, maxSize.getHeight());
    width = (float) Math.min(width, maxSize.getWidth());

    //Log.debug ("Dimension after dynamic correction: " + maxSize);
    //Log.debug ("Dimension after dynamic correction: " + width + " -> " + height);
    // now align the calculated data ...
    final FloatDimension fdim = new FloatDimension(
        align(width, getLayoutSupport().getHorizontalAlignmentBorder()),
        align(height, getLayoutSupport().getVerticalAlignmentBorder()));
    return fdim;
  }

  /**
   * Layout a single band with all elements contained within the band.
   * <p>
   * The band has its <code>BOUNDS</code> already set and all elements are laid out
   * within these bounds. The band's properties will not be changed during the layouting.
   * <p>
   * This layout manager requires that all direct child elements have the <code>ABSOLUTE_POS</code>
   * and <code>MINIMUM_SIZE</code> properties set to valid values.
   *
   * @param b the band to lay out.
   * @throws IllegalStateException if the bands has no bounds set.
   */
  public synchronized void doLayout(final Band b)
  {
    final Element[] elements = b.getElementArray();
    final Rectangle2D parentBounds = BandLayoutManagerUtil.getBounds(b, null);
    if (parentBounds == null)
    {
      throw new IllegalStateException("Need the parent's bound set");
    }

    final Dimension2D parentDim = new FloatDimension((float) parentBounds.getWidth(),
        (float) parentBounds.getHeight());

    //Log.debug ("My LayoutSize: " + b.getName() + " " + parentDim);

    Dimension2D absDim = null;
    Point2D absPos = null;
    final LayoutSupport layoutSupport = getLayoutSupport();
    for (int i = 0; i < elements.length; i++)
    {
      final Element e = elements[i];

      if (e.isVisible() == false)
      {
        continue;
      }
      absPos = correctPoint((Point2D) e.getStyle().getStyleProperty(ABSOLUTE_POS), parentDim,
          absPos);
      // check whether the element would be visible .. if not visible, then
      // dont do anything ...
      if (absPos.getX() > parentDim.getWidth() || absPos.getY() > parentDim.getHeight())
      {
        // dont display, as this element is larger than the container ...
        // Log.debug ("Element Out of Bounds: " + e);
        BandLayoutManagerUtil.setBounds(e, new Rectangle2D.Float(0, 0, 0, 0));
        continue;
      }

      final Dimension2D uncorrectedSize = getPreferredSize(e, parentDim);
      //Log.debug ("UBounds: Element: " + e.getName() + " Bounds: " + uncorrectedSize);
      absDim = correctDimension(uncorrectedSize, parentDim, absDim);
      // Log.debug ("CBounds: Element: " + e.getName() + " Bounds: " + absDim);

      // here apply the maximum bounds ...
      final Rectangle2D bounds = new Rectangle2D.Float(
          align((float) absPos.getX(), layoutSupport.getHorizontalAlignmentBorder()),
          align((float) absPos.getY(), layoutSupport.getVerticalAlignmentBorder()),
          align((float) absDim.getWidth(), layoutSupport.getHorizontalAlignmentBorder()),
          align((float) absDim.getHeight(), layoutSupport.getVerticalAlignmentBorder()));
      BandLayoutManagerUtil.setBounds(e, bounds);
      //Log.debug ("Bounds: Element: " + e.getName() + " Bounds: " + bounds);
      if (e instanceof Band)
      {
        final BandLayoutManager lm = BandLayoutManagerUtil.getLayoutManager(e, getLayoutSupport());
        lm.doLayout((Band) e);
      }
    }
  }

  /**
   * Returns <code>true</code> if the element has a static width, and <code>false</code> otherwise.
   *
   * @param e  the element.
   *
   * @return <code>true</code> or </code>false</code>.
   */
  protected boolean isElementStaticWidth(final Element e)
  {
    final Point2D absPos = (Point2D) e.getStyle().getStyleProperty(ABSOLUTE_POS);
    if (absPos == null)
    {
      throw new IllegalArgumentException("Element " + e
          + " has no valid constraints. ABSOLUTE_POS is missing");
    }
    if (absPos.getX() < 0)
    {
      return false;
    }
    return super.isElementStaticWidth(e);
  }

  /**
   * Returns true if the element has a static height, and false otherwise.
   *
   * @param e  the element.
   *
   * @return true or false.
   */
  protected boolean isElementStaticHeight(final Element e)
  {
    final Point2D absPos = (Point2D) e.getStyle().getStyleProperty(ABSOLUTE_POS);
    if (absPos == null)
    {
      throw new IllegalArgumentException("Element " + e
          + " has no valid constraints. ABSOLUTE_POS is missing");
    }
    if (absPos.getY() < 0)
    {
      return false;
    }
    return super.isElementStaticHeight(e);
  }

  /**
   * Clears any cached items used by the layout manager.
   *
   * @param container  the container band.
   */
  public synchronized void invalidateLayout(final Band container)
  {
    cache.flush();
  }
}

⌨️ 快捷键说明

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