Search in sources :

Example 1 with StrokeStyle

use of org.apache.poi.sl.usermodel.StrokeStyle in project poi by apache.

the class DrawTableShape method draw.

public void draw(Graphics2D graphics) {
    Drawable d = getGroupShape(graphics);
    if (d != null) {
        d.draw(graphics);
        return;
    }
    TableShape<?, ?> ts = getShape();
    DrawPaint drawPaint = DrawFactory.getInstance(graphics).getPaint(ts);
    final int rows = ts.getNumberOfRows();
    final int cols = ts.getNumberOfColumns();
    // draw background boxes
    for (int row = 0; row < rows; row++) {
        for (int col = 0; col < cols; col++) {
            TableCell<?, ?> tc = ts.getCell(row, col);
            if (tc == null || tc.isMerged()) {
                continue;
            }
            Paint fillPaint = drawPaint.getPaint(graphics, tc.getFillStyle().getPaint());
            graphics.setPaint(fillPaint);
            Rectangle2D cellAnc = tc.getAnchor();
            graphics.fill(cellAnc);
            for (BorderEdge edge : BorderEdge.values()) {
                StrokeStyle stroke = tc.getBorderStyle(edge);
                if (stroke == null) {
                    continue;
                }
                graphics.setStroke(getStroke(stroke));
                Paint linePaint = drawPaint.getPaint(graphics, stroke.getPaint());
                graphics.setPaint(linePaint);
                double x = cellAnc.getX(), y = cellAnc.getY(), w = cellAnc.getWidth(), h = cellAnc.getHeight();
                Line2D line;
                switch(edge) {
                    default:
                    case bottom:
                        line = new Line2D.Double(x - borderSize, y + h, x + w + borderSize, y + h);
                        break;
                    case left:
                        line = new Line2D.Double(x, y, x, y + h + borderSize);
                        break;
                    case right:
                        line = new Line2D.Double(x + w, y, x + w, y + h + borderSize);
                        break;
                    case top:
                        line = new Line2D.Double(x - borderSize, y, x + w + borderSize, y);
                        break;
                }
                graphics.draw(line);
            }
        }
    }
    // draw text
    drawContent(graphics);
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) BorderEdge(org.apache.poi.sl.usermodel.TableCell.BorderEdge) Paint(java.awt.Paint) StrokeStyle(org.apache.poi.sl.usermodel.StrokeStyle) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint)

Example 2 with StrokeStyle

use of org.apache.poi.sl.usermodel.StrokeStyle in project poi by apache.

the class DrawFreeformShape method computeOutlines.

protected Collection<Outline> computeOutlines(Graphics2D graphics) {
    List<Outline> lst = new ArrayList<Outline>();
    FreeformShape<?, ?> fsh = getShape();
    Path2D sh = fsh.getPath();
    AffineTransform tx = (AffineTransform) graphics.getRenderingHint(Drawable.GROUP_TRANSFORM);
    if (tx == null) {
        tx = new AffineTransform();
    }
    java.awt.Shape canvasShape = tx.createTransformedShape(sh);
    FillStyle fs = fsh.getFillStyle();
    StrokeStyle ss = fsh.getStrokeStyle();
    Path path = new Path(fs != null, ss != null);
    lst.add(new Outline(canvasShape, path));
    return lst;
}
Also used : Path(org.apache.poi.sl.draw.geom.Path) Path2D(java.awt.geom.Path2D) ArrayList(java.util.ArrayList) FillStyle(org.apache.poi.sl.usermodel.FillStyle) AffineTransform(java.awt.geom.AffineTransform) Outline(org.apache.poi.sl.draw.geom.Outline) StrokeStyle(org.apache.poi.sl.usermodel.StrokeStyle)

Aggregations

StrokeStyle (org.apache.poi.sl.usermodel.StrokeStyle)2 Paint (java.awt.Paint)1 AffineTransform (java.awt.geom.AffineTransform)1 Line2D (java.awt.geom.Line2D)1 Path2D (java.awt.geom.Path2D)1 Rectangle2D (java.awt.geom.Rectangle2D)1 ArrayList (java.util.ArrayList)1 Outline (org.apache.poi.sl.draw.geom.Outline)1 Path (org.apache.poi.sl.draw.geom.Path)1 FillStyle (org.apache.poi.sl.usermodel.FillStyle)1 BorderEdge (org.apache.poi.sl.usermodel.TableCell.BorderEdge)1