Search in sources :

Example 1 with Line2D

use of java.awt.geom.Line2D in project tomcat by apache.

the class DrawMessage method draw.

/**
     * Draws this DrawMessage onto the given Graphics2D.
     *
     * @param g The target for the DrawMessage
     */
public void draw(Graphics2D g) {
    g.setStroke(new BasicStroke((float) thickness, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER));
    g.setColor(new Color(colorR & 0xFF, colorG & 0xFF, colorB & 0xFF, colorA & 0xFF));
    if (x1 == x2 && y1 == y2) {
        // Always draw as arc to meet the behavior in the HTML5 Canvas.
        Arc2D arc = new Arc2D.Double(x1, y1, 0, 0, 0d, 360d, Arc2D.OPEN);
        g.draw(arc);
    } else if (type == 1 || type == 2) {
        // Draw a line.
        Line2D line = new Line2D.Double(x1, y1, x2, y2);
        g.draw(line);
    } else if (type == 3 || type == 4) {
        double x1 = this.x1, x2 = this.x2, y1 = this.y1, y2 = this.y2;
        if (x1 > x2) {
            x1 = this.x2;
            x2 = this.x1;
        }
        if (y1 > y2) {
            y1 = this.y2;
            y2 = this.y1;
        }
        if (type == 3) {
            // Draw a rectangle.
            Rectangle2D rect = new Rectangle2D.Double(x1, y1, x2 - x1, y2 - y1);
            g.draw(rect);
        } else if (type == 4) {
            // Draw an ellipse.
            Arc2D arc = new Arc2D.Double(x1, y1, x2 - x1, y2 - y1, 0d, 360d, Arc2D.OPEN);
            g.draw(arc);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) Arc2D(java.awt.geom.Arc2D) Line2D(java.awt.geom.Line2D)

Example 2 with Line2D

use of java.awt.geom.Line2D in project limelight by slagyr.

the class BorderPainterTest method checkLine.

private void checkLine(MockGraphics.DrawnShape shape, int width, Color color, int x1, int y1, int x2, int y2) {
    assertEquals(width, (int) shape.stroke.getLineWidth());
    assertEquals(color, shape.color);
    assertEquals(false, shape.antialiasing);
    Line2D line = (Line2D) shape.shape;
    assertEquals(x1, (int) line.getX1());
    assertEquals(y1, (int) line.getY1());
    assertEquals(x2, (int) line.getX2());
    assertEquals(y2, (int) line.getY2());
}
Also used : Line2D(java.awt.geom.Line2D)

Example 3 with Line2D

use of java.awt.geom.Line2D in project poi by apache.

the class EscherGraphics2d method draw.

public void draw(Shape shape) {
    if (shape instanceof Line2D) {
        Line2D shape2d = (Line2D) shape;
        int width = 0;
        if (_stroke != null && _stroke instanceof BasicStroke) {
            width = (int) ((BasicStroke) _stroke).getLineWidth() * 12700;
        }
        drawLine((int) shape2d.getX1(), (int) shape2d.getY1(), (int) shape2d.getX2(), (int) shape2d.getY2(), width);
    } else {
        if (logger.check(POILogger.WARN))
            logger.log(POILogger.WARN, "draw not fully supported");
    }
}
Also used : Line2D(java.awt.geom.Line2D)

Example 4 with Line2D

use of java.awt.geom.Line2D 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 5 with Line2D

use of java.awt.geom.Line2D in project poi by apache.

the class SLGraphics method drawLine.

/**
     * Draws a line, using the current color, between the points
     * <code>(x1,&nbsp;y1)</code> and <code>(x2,&nbsp;y2)</code>
     * in this graphics context's coordinate system.
     * @param   x1  the first point's <i>x</i> coordinate.
     * @param   y1  the first point's <i>y</i> coordinate.
     * @param   x2  the second point's <i>x</i> coordinate.
     * @param   y2  the second point's <i>y</i> coordinate.
     */
public void drawLine(int x1, int y1, int x2, int y2) {
    Line2D line = new Line2D.Double(x1, y1, x2, y2);
    draw(line);
}
Also used : Line2D(java.awt.geom.Line2D)

Aggregations

Line2D (java.awt.geom.Line2D)19 Rectangle2D (java.awt.geom.Rectangle2D)6 BasicStroke (java.awt.BasicStroke)3 Color (java.awt.Color)3 Paint (java.awt.Paint)3 Density (com.android.resources.Density)1 ScreenRatio (com.android.resources.ScreenRatio)1 ScreenSize (com.android.resources.ScreenSize)1 NodeRef (dr.evolution.tree.NodeRef)1 GradientPaint (java.awt.GradientPaint)1 Polygon (java.awt.Polygon)1 Shape (java.awt.Shape)1 Stroke (java.awt.Stroke)1 Arc2D (java.awt.geom.Arc2D)1 Ellipse2D (java.awt.geom.Ellipse2D)1 GeneralPath (java.awt.geom.GeneralPath)1 RoundRectangle2D (java.awt.geom.RoundRectangle2D)1 Iterator (java.util.Iterator)1 List (java.util.List)1 StrokeStyle (org.apache.poi.sl.usermodel.StrokeStyle)1