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

📄 itemfactory.java

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


  /**
   * Creates a new ShapeElement.
   *
   * @param name  the name of the new element.
   * @param bounds  the bounds.
   * @param paint  the line color of this element.
   * @param stroke  the stroke of this shape. For pdf use, restrict to BasicStrokes.
   * @param shape  the shape.
   * @param shouldDraw  draw the shape?
   * @param shouldFill  fill the shape?
   * @param shouldScale  scale the shape?
   *
   * @return a report element for drawing a line.
   *
   * @throws NullPointerException if bounds, name or shape are null
   * @throws IllegalArgumentException if the given alignment is invalid
   */
  public static ShapeElement createShapeElement(final String name,
                                                final Rectangle2D bounds,
                                                final Paint paint,
                                                final Stroke stroke,
                                                final Shape shape,
                                                final boolean shouldDraw,
                                                final boolean shouldFill,
                                                final boolean shouldScale)
  {
    return createShapeElement(name, bounds, paint, stroke, shape, shouldDraw,
        shouldFill, shouldScale, false);
  }

  /**
   * Creates a new ShapeElement.
   *
   * @param name  the name of the new element.
   * @param bounds  the bounds.
   * @param paint  the line color of this element.
   * @param stroke  the stroke of this shape. For pdf use, restrict to BasicStrokes.
   * @param shape  the shape.
   * @param shouldDraw  draw the shape?
   * @param shouldFill  fill the shape?
   * @param shouldScale  scale the shape?
   * @param keepAspectRatio  preserve the aspect ratio?
   *
   * @return a report element for drawing a line.
   *
   * @throws NullPointerException if bounds, name or shape are null
   * @throws IllegalArgumentException if the given alignment is invalid
   */
  public static ShapeElement createShapeElement(final String name,
                                                final Rectangle2D bounds,
                                                final Paint paint,
                                                final Stroke stroke,
                                                final Shape shape,
                                                final boolean shouldDraw,
                                                final boolean shouldFill,
                                                final boolean shouldScale,
                                                final boolean keepAspectRatio)
  {
    final ShapeElement shapeElement = new ShapeElement();
    if (name != null)
    {
      shapeElement.setName(name);
    }
    if (paint != null)
    {
      shapeElement.getStyle().setStyleProperty(ElementStyleSheet.PAINT, paint);
    }
    if (stroke != null)
    {
      shapeElement.setStroke(stroke);
    }
    shapeElement.setDataSource(new StaticDataSource(shape));
    shapeElement.setShouldDraw(shouldDraw);
    shapeElement.setShouldFill(shouldFill);
    shapeElement.setScale(shouldScale);
    shapeElement.setKeepAspectRatio(keepAspectRatio);
    setElementBounds(shapeElement, bounds);
    return shapeElement;
  }


  /**
   * Creates a new ShapeElement.
   *
   * @param name  the name of the new element.
   * @param bounds  the bounds.
   * @param paint  the line color of this element.
   * @param stroke  the stroke of this shape. For pdf use, restrict to BasicStrokes.
   * @param fieldname  the fieldname from where to get the shape.
   * @param shouldDraw  draw the shape?
   * @param shouldFill  fill the shape?
   * @param shouldScale  scale the shape?
   * @param keepAspectRatio  preserve the aspect ratio?
   *
   * @return a report element for drawing a line.
   *
   * @throws NullPointerException if bounds, name or shape are null
   * @throws IllegalArgumentException if the given alignment is invalid
   */
  public static ShapeElement createShapeElement(final String name,
                                                final Rectangle2D bounds,
                                                final Paint paint,
                                                final Stroke stroke,
                                                final String fieldname,
                                                final boolean shouldDraw,
                                                final boolean shouldFill,
                                                final boolean shouldScale,
                                                final boolean keepAspectRatio)
  {
    final ShapeElement shapeElement = new ShapeElement();
    if (name != null)
    {
      shapeElement.setName(name);
    }
    if (paint != null)
    {
      shapeElement.getStyle().setStyleProperty(ElementStyleSheet.PAINT, paint);
    }
    if (stroke != null)
    {
      shapeElement.setStroke(stroke);
    }
    shapeElement.setDataSource(new DataRowDataSource(fieldname));
    shapeElement.setShouldDraw(shouldDraw);
    shapeElement.setShouldFill(shouldFill);
    shapeElement.setScale(shouldScale);
    shapeElement.setKeepAspectRatio(keepAspectRatio);
    setElementBounds(shapeElement, bounds);
    return shapeElement;
  }

  /**
   * Creates a new RectangleShapeElement.
   *
   * @param name the name of the new element
   * @param paint the line color of this element
   * @param stroke the stroke of this shape. For pdf use, restrict to BasicStokes.
   * @param shape the Rectangle2D shape
   * @param shouldDraw  a flag controlling whether or not the shape outline is drawn.
   * @param shouldFill  a flag controlling whether or not the shape interior is filled.
   *
   * @return a report element for drawing a rectangle.
   *
   * @throws NullPointerException if bounds, name or shape are null
   * @throws IllegalArgumentException if the given alignment is invalid
   */
  public static ShapeElement createRectangleShapeElement(final String name,
                                                         final Paint paint,
                                                         final Stroke stroke,
                                                         final Rectangle2D shape,
                                                         final boolean shouldDraw,
                                                         final boolean shouldFill)
  {
    if (shape.getX() < 0 || shape.getY() < 0 || shape.getWidth() < 0 || shape.getHeight() < 0)
    {
      // this is a relative rectangle element, so the shape defines the bounds
      // and expects to draw a scaled rectangle within these bounds
      return createShapeElement(name, shape, paint, stroke, new Rectangle2D.Float(0, 0, 100, 100),
          shouldDraw, shouldFill, true);
    }
    final Rectangle2D rect = (Rectangle2D) shape.clone();
    rect.setRect(0, 0, rect.getWidth(), rect.getHeight());
    return createShapeElement(name, shape, paint, stroke, rect, shouldDraw, shouldFill, false);
  }

  /**
   * Creates a new TextElement. The difference between StringElements and MultilineTextElements
   * is historical and no longer relevant.
   *
   * @param name the name of the new element
   * @param bounds the bounds of the new element
   * @param paint the text color of this text element
   * @param alignment  the horizontal text alignment.
   * @param font the font for this element
   * @param nullString the text used when the value of this element is null
   * @param field the field in the datamodel to retrieve values from
   *
   * @return a report element for displaying text on multiple lines.
   *
   * @throws NullPointerException if bounds, name or function are null
   * @throws IllegalArgumentException if the given alignment is invalid
   *
   * @deprecated use createStringElement instead
   */
  public static TextElement createMultilineTextElement(final String name,
                                                       final Rectangle2D bounds,
                                                       final Paint paint,
                                                       final int alignment,
                                                       final Font font,
                                                       final String nullString,
                                                       final String field)
  {
    return createStringElement(name, bounds, paint, alignment, font, nullString, field);
  }

  /**
   * Creates a new TextElement containing a numeric filter structure.
   *
   * @param name the name of the new element
   * @param bounds the bounds of the new element
   * @param paint the text color of this text element
   * @param alignment  the horizontal text alignment.
   * @param font the font for this element
   * @param nullString the text used when the value of this element is null
   * @param field the field in the datamodel to retrieve values from
   * @param format the NumberFormat used in this number element
   *
   * @return a report element for displaying <code>Number</code> objects.
   *
   * @throws NullPointerException if bounds, name or function are null
   * @throws IllegalArgumentException if the given alignment is invalid
   */
  public static TextElement createNumberElement(final String name,
                                                final Rectangle2D bounds,
                                                final Paint paint,
                                                final int alignment,
                                                final Font font,
                                                final String nullString,
                                                final NumberFormat format,
                                                final String field)
  {
    return createNumberElement(name, bounds, paint, alignment,
        ElementAlignment.TOP.getOldAlignment(),
        font, nullString,
        format, field);
  }

  /**
   * Creates a new TextElement containing a numeric filter structure.
   *
   * @param name  the name of the new element.
   * @param bounds  the bounds of the new element.
   * @param paint  the text color of this text element.
   * @param alignment  the horizontal text alignment.
   * @param valign  the vertical alignment.
   * @param font  the font for this element.
   * @param nullString  the text used when the value of this element is null.
   * @param field  the field in the datamodel to retrieve values from.
   * @param format  the NumberFormat used in this number element.
   *
   * @return a report element for displaying <code>Number</code> objects.
   *
   * @throws NullPointerException if bounds, name or function are null
   * @throws IllegalArgumentException if the given alignment is invalid
   */
  public static TextElement createNumberElement(final String name,
                                                final Rectangle2D bounds,
                                                final Paint paint,
                                                final int alignment,
                                                final int valign,
                                                final Font font,
                                                final String nullString,
                                                final NumberFormat format,
                                                final String field)
  {
    final DataSource ds;
    if (format instanceof DecimalFormat)
    {
      final NumberFieldTemplate template = new NumberFieldTemplate();
      template.setDecimalFormat((DecimalFormat) format);
      template.setNullValue(nullString);
      template.setField(field);
      ds = template;
    }
    else
    {
      final NumberFormatFilter filter = new NumberFormatFilter();
      if (format != null)
      {
        filter.setFormatter(format);
      }
      filter.setDataSource(new DataRowDataSource(field));
      ds = filter;
    }

    final TextElement element = new TextElement();
    if (name != null)
    {
      element.setName(name);
    }
    setElementBounds(element, bounds);
    if (paint != null)
    {
      element.getStyle().setStyleProperty(ElementStyleSheet.PAINT, paint);
    }
    if (font != null)
    {
      element.getStyle().setFontDefinitionProperty(new FontDefinition(font));
    }
    element.getStyle().setStyleProperty(
        ElementStyleSheet.ALIGNMENT,
        ElementAlignment.translateHorizontalAlignment(alignment)
    );
    element.getStyle().setStyleProperty(
        ElementStyleSheet.VALIGNMENT,
        ElementAlignment.translateVerticalAlignment(valign)
    );
    element.setDataSource(ds);
    return element;
  }

  /**
   * Creates a new TextElement containing a numeric filter structure.
   *

⌨️ 快捷键说明

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