📄 itemfactory.java
字号:
}
/**
* Creates a new ImageElement.
*
* @param name the name of the new element
* @param bounds the bounds of the new element
* @param paint the color of this element (currently not used)
* @param field the name of the column/function/expression that returns the URL for the image.
*
* @return a report element for displaying an image.
*
* @throws NullPointerException if bounds, name or source are null
* @throws IllegalArgumentException if the given alignment is invalid
*
* @deprecated use createImageDataRowElement instead
*/
public static ImageElement createImageFieldElement(final String name,
final Rectangle2D bounds,
final Paint paint,
final String field)
{
return createImageDataRowElement(name, bounds, paint, field);
}
/**
* Creates a new ImageElement.
*
* @param name the name of the new element
* @param bounds the bounds of the new element
* @param paint the color of this element (currently not used)
* @param field the name of the column/function/expression that returns the URL for the image.
*
* @return a report element for displaying an image.
*
* @throws NullPointerException if bounds, name or source are null
* @throws IllegalArgumentException if the given alignment is invalid
*/
public static ImageElement createImageDataRowElement(final String name,
final Rectangle2D bounds,
final Paint paint,
final String field
)
{
return createImageDataRowElement(name, bounds, paint, field, true);
}
/**
* Creates a new ImageElement.
*
* @param name the name of the new element.
* @param bounds the bounds of the new element.
* @param paint the color of this element (currently not used).
* @param field the name of the column/function/expression that returns the URL for the image.
* @param scale scale the image?
*
* @return a report element for displaying an image.
*
* @throws NullPointerException if bounds, name or source are null
* @throws IllegalArgumentException if the given alignment is invalid
*/
public static ImageElement createImageDataRowElement(final String name,
final Rectangle2D bounds,
final Paint paint,
final String field,
final boolean scale)
{
return createImageDataRowElement(name, bounds, paint, field, scale, false);
}
/**
* Creates a new ImageElement.
*
* @param name the name of the new element.
* @param bounds the bounds of the new element.
* @param paint the color of this element (currently not used).
* @param field the name of the column/function/expression that returns the URL for the image.
* @param scale scale the image?
* @param keepAspectRatio preserve the aspect ratio?
*
* @return a report element for displaying an image.
*
* @throws NullPointerException if bounds, name or source are null
* @throws IllegalArgumentException if the given alignment is invalid
*/
public static ImageElement createImageDataRowElement(final String name,
final Rectangle2D bounds,
final Paint paint,
final String field,
final boolean scale,
final boolean keepAspectRatio)
{
final ImageFieldTemplate template = new ImageFieldTemplate();
template.setField(field);
final ImageElement element = new ImageElement();
if (name != null)
{
element.setName(name);
}
if (paint != null)
{
element.getStyle().setStyleProperty(ElementStyleSheet.PAINT, paint);
}
setElementBounds(element, bounds);
element.setDataSource(template);
element.setScale(scale);
element.setKeepAspectRatio(keepAspectRatio);
return element;
}
/**
* Creates a new ImageElement.
*
* @param name the name of the new element
* @param bounds the bounds of the new element
* @param paint the color of this element (currently not used)
* @param function the name of the function that returns the URL for the image.
*
* @return a report element for displaying an image.
*
* @throws NullPointerException if bounds, name or source are null
* @throws IllegalArgumentException if the given alignment is invalid
*
* @deprecated use createImageDataRowElement instead
*/
public static ImageElement createImageFunctionElement(final String name,
final Rectangle2D bounds,
final Paint paint,
final String function)
{
return createImageDataRowElement(name, bounds, paint, function);
}
/**
* Creates a new TextElement containing a label.
*
* @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 labeltext the text to display
*
* @return a report element for displaying a label (static text).
*
* @throws NullPointerException if bounds, name, format or field are null
* @throws IllegalArgumentException if the given alignment is invalid
*/
public static TextElement createLabelElement(final String name,
final Rectangle2D bounds,
final Paint paint,
final int alignment,
final Font font,
final String labeltext)
{
return createLabelElement(name, bounds, paint, alignment,
ElementAlignment.TOP.getOldAlignment(),
font, labeltext);
}
/**
* Creates a new {@link TextElement} containing a label.
*
* @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 alignment.
* @param valign the vertical alignment.
* @param font the font for this element.
* @param labeltext the text to display.
*
* @return a report element for displaying a label (static text).
*
* @throws NullPointerException if bounds, name, format or field are <code>null</code>.
* @throws IllegalArgumentException if the given alignment is invalid.
*/
public static TextElement createLabelElement(final String name,
final Rectangle2D bounds,
final Paint paint,
final int alignment,
final int valign,
final Font font,
final String labeltext)
{
final LabelTemplate template = new LabelTemplate();
template.setContent(labeltext);
final TextElement label = new TextElement();
if (name != null)
{
label.setName(name);
}
setElementBounds(label, bounds);
if (paint != null)
{
label.getStyle().setStyleProperty(ElementStyleSheet.PAINT, paint);
}
if (font != null)
{
label.getStyle().setFontDefinitionProperty(new FontDefinition(font));
}
label.getStyle().setStyleProperty(
ElementStyleSheet.ALIGNMENT,
ElementAlignment.translateHorizontalAlignment(alignment));
label.getStyle().setStyleProperty(
ElementStyleSheet.VALIGNMENT,
ElementAlignment.translateVerticalAlignment(valign));
label.setDataSource(template);
return label;
}
/**
* Creates a new LineShapeElement. The line must not contain negative coordinates,
* or an IllegalArgumentException will be thrown. If you want to define scaling
* lines, you will have use one of the createShape methods.
*
* @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 Line2D 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 createLineShapeElement(final String name,
final Paint paint,
final Stroke stroke,
final Line2D shape)
{
if (shape.getX1() == shape.getX2() && shape.getY1() == shape.getY2())
{
// scale the line, is horizontal,the line is on pos 0,0 within the element
final Rectangle2D bounds = new Rectangle2D.Float(0, (float) shape.getY1(), -100, 0);
return createShapeElement(name, bounds, paint, stroke, new Line2D.Float(0, 0, 100, 0),
true, false, true);
}
else
{
final Rectangle2D bounds = shape.getBounds2D();
if (bounds.getX() < 0)
{
throw new IllegalArgumentException("Line coordinates must not be negative.");
}
if (bounds.getY() < 0)
{
throw new IllegalArgumentException("Line coordinates must not be negative.");
}
shape.setLine(shape.getX1() - bounds.getX(),
shape.getY1() - bounds.getY(),
shape.getX2() - bounds.getX(),
shape.getY2() - bounds.getY());
return createShapeElement(name, bounds, paint, stroke, shape, true, false, true);
}
}
/**
* Creates a new LineShapeElement.
*
* @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 BasicStrokes.
* @param shape the shape.
* @param shouldDraw draw the shape?
* @param shouldFill fill 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
* @deprecated this methods has to extract the bounds from the shape and correct
* the shape by using an AffineTransform. Use one of the createShape methods, that
* allow you to supply separate bounds and shapes.
*/
public static ShapeElement createShapeElement(final String name,
final Paint paint,
final Stroke stroke,
final Shape shape,
final boolean shouldDraw,
final boolean shouldFill)
{
// we have two choices here: let the element be big enough to take up
// the complete shape and let the element start at 0,0, and the shape
// therefore starts at x,y
//
// or
//
// translate the shape to start at 0,0 and let the element start at
// the shapes origin (x,y).
// we have to translate the shape, as anything else would mess up the table layout
final Rectangle2D shapeBounds = shape.getBounds2D();
if (shapeBounds.getX() == 0 && shapeBounds.getY() == 0)
{
// no need to translate ...
return createShapeElement(name, shapeBounds, paint, stroke, shape,
shouldDraw, shouldFill, true);
}
final AffineTransform af = AffineTransform.getTranslateInstance(-shapeBounds.getX(),
-shapeBounds.getY());
return createShapeElement(name, shapeBounds, paint, stroke, af.createTransformedShape(shape),
shouldDraw, shouldFill, true);
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -