Search in sources :

Example 6 with Line2D

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

the class PPGraphics2D 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.Float(x1, y1, x2, y2);
    draw(line);
}
Also used : Line2D(java.awt.geom.Line2D)

Example 7 with Line2D

use of java.awt.geom.Line2D in project beast-mcmc by beast-dev.

the class JChart method paintComponent.

public void paintComponent(Graphics g) {
    if (!hasContents())
        return;
    Graphics2D g2 = (Graphics2D) g;
    Dimension size = getSize();
    //        g2.setRenderingHint(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    try {
        if (!calibrated) {
            calibrate(g2, size);
            calibrated = true;
        }
        g2.setFont(labelFont);
        double tickLabelHeight = g2.getFontMetrics().getHeight();
        xTickLabelOffset = g2.getFontMetrics().getAscent();
        yTickLabelOffset = g2.getFontMetrics().getAscent() / 2;
        double maxXTickLabelWidth = getMaxTickLabelWidth(g2, xAxis);
        double maxYTickLabelWidth = getMaxTickLabelWidth(g2, yAxis);
        double w = size.width - (majorTickSize * 1.25) - maxYTickLabelWidth - (maxXTickLabelWidth / 2);
        double h = size.height - yTickLabelOffset - (majorTickSize * 1.25) - tickLabelHeight;
        plotBounds = new Rectangle2D.Double((majorTickSize * 1.25) + maxYTickLabelWidth, yTickLabelOffset, w, h);
        xOffset = plotBounds.getX();
        yOffset = plotBounds.getMaxY();
        xScale = w / (xAxis.transform(xAxis.getMaxAxis()) - xAxis.transform(xAxis.getMinAxis()));
        yScale = -h / (yAxis.transform(yAxis.getMaxAxis()) - yAxis.transform(yAxis.getMinAxis()));
        g2.setPaint(plotBackgroundPaint);
        g2.fill(plotBounds);
        g2.setClip(plotBounds);
        Stroke oldStroke = g2.getStroke();
        if (originStroke != null && originPaint != null) {
            double minX = xAxis.getMinAxis();
            double maxX = xAxis.getMaxAxis();
            double minY = yAxis.getMinAxis();
            double maxY = yAxis.getMaxAxis();
            g2.setPaint(originPaint);
            g2.setStroke(originStroke);
            if (minX < 0.0 && maxX > 0.0) {
                Line2D line = new Line2D.Double(transformX(0.0), transformY(minY), transformX(0.0), transformY(maxY));
                g2.draw(line);
            }
            if (minY < 0.0 && maxY > 0.0) {
                Line2D line = new Line2D.Double(transformX(minX), transformY(0.0), transformX(maxX), transformY(0.0));
                g2.draw(line);
            }
        }
        g2.setStroke(oldStroke);
        paintContents(g2);
        if (showLegend) {
            paintLegend(g2);
        }
        if (dragRectangle != null) {
            g2.setPaint(new Color(128, 128, 128, 128));
            g2.fill(dragRectangle);
        }
        g2.setClip(null);
        paintFrame(g2);
        paintAxis(g2, xAxis, true);
        paintAxis(g2, yAxis, false);
    } catch (ChartRuntimeException cre) {
    // ignore (just won't paint chart)
    }
}
Also used : Rectangle2D(java.awt.geom.Rectangle2D) Line2D(java.awt.geom.Line2D)

Example 8 with Line2D

use of java.awt.geom.Line2D in project beast-mcmc by beast-dev.

the class SquareTreePainter method paintNode.

/**
	 * Paint a node.
     * @param x0 the height of the parent node
     * @param x1 the height of the node
	 */
private double paintNode(Graphics2D g2, Tree tree, NodeRef node, double x0, double x1, boolean hilight) {
    double y;
    double ix0 = convertX(x0);
    double ix1 = convertX(x1);
    double iy;
    if (tree.getNodeAttribute(node, "selected") != null) {
        hilight = true;
    }
    if (tree.isExternal(node)) {
        if (rememberYPositions) {
            // remember the y positions of taxa that you have seen before... AD
            String taxonId = tree.getNodeTaxon(node).getId();
            Double pos = yPositionMap.get(taxonId);
            if (pos != null) {
                y = pos;
            } else {
                y = currentY;
                currentY += 1.0;
                yPositionMap.put(taxonId, y);
            }
        } else {
            y = currentY;
            currentY += 1.0;
        }
        if (hilight) {
            g2.setPaint(hilightLabelPaint);
            g2.setFont(hilightLabelFont);
        } else {
            g2.setPaint(labelPaint);
            g2.setFont(labelFont);
        }
        String label = tree.getTaxonId(node.getNumber());
        double labelWidth = g2.getFontMetrics().stringWidth(label);
        double labelHeight = g2.getFontMetrics().getAscent();
        double labelOffset = labelHeight / 2;
        iy = convertY(y);
        if (label != null && label.length() > 0 && drawLabels) {
            g2.drawString(label, (float) (ix1 + 4), (float) (iy + labelOffset));
        }
        nodeRectVert[node.getNumber()] = new Rectangle.Double(ix1 + 4, iy, labelWidth, labelHeight);
        if (hilight) {
            g2.setPaint(hilightPaint);
            g2.setStroke(hilightStroke);
        } else {
            // use tree color attribute if set
            if (colorAttribute != null) {
                Paint c = (Color) tree.getNodeAttribute(node, colorAttribute);
                if (c == null)
                    c = linePaint;
                g2.setPaint(c);
            } else {
                g2.setPaint(linePaint);
            }
            if (lineAttribute != null) {
                Stroke stroke = (Stroke) tree.getNodeAttribute(node, lineAttribute);
                if (stroke == null)
                    stroke = lineStroke;
                g2.setStroke(stroke);
            } else
                g2.setStroke(lineStroke);
        }
    } else {
        double y0, y1;
        NodeRef child = tree.getChild(node, 0);
        double length = tree.getNodeHeight(node) - tree.getNodeHeight(child);
        y0 = paintNode(g2, tree, child, x1, x1 - length, hilight);
        y1 = y0;
        for (int i = 1; i < tree.getChildCount(node); i++) {
            child = tree.getChild(node, i);
            length = tree.getNodeHeight(node) - tree.getNodeHeight(child);
            y1 = paintNode(g2, tree, child, x1, x1 - length, hilight);
        }
        double iy0 = convertY(y0);
        double iy1 = convertY(y1);
        if (hilight) {
            g2.setPaint(hilightPaint);
            g2.setStroke(hilightStroke);
        } else {
            // use tree color attribute if set
            if (colorAttribute != null) {
                Paint c = (Color) tree.getNodeAttribute(node, colorAttribute);
                if (c == null)
                    c = linePaint;
                g2.setPaint(c);
            } else {
                g2.setPaint(linePaint);
            }
            if (lineAttribute != null) {
                Stroke stroke = (Stroke) tree.getNodeAttribute(node, lineAttribute);
                if (stroke == null)
                    stroke = lineStroke;
                g2.setStroke(stroke);
            } else
                g2.setStroke(lineStroke);
        }
        if (drawHorizontals) {
            Line2D line = new Line2D.Double(ix1, iy0, ix1, iy1);
            g2.draw(line);
        }
        nodeRectVert[node.getNumber()] = new Rectangle.Double(ix1 - 2, iy0 - 2, 5, (iy1 - iy0) + 4);
        y = (y1 + y0) / 2;
        iy = convertY(y);
    }
    if (drawVerticals) {
        Line2D line = new Line2D.Double(ix0, iy, ix1, iy);
        g2.draw(line);
    }
    nodeRectHoriz[node.getNumber()] = new Rectangle.Double(ix0 - 2, iy - 2, (ix1 - ix0) + 4, 5);
    if (shapeAttribute != null) {
        Shape shape = (Shape) tree.getNodeAttribute(node, shapeAttribute);
        if (shape != null) {
            Rectangle bounds = shape.getBounds();
            double tx = ix1 - bounds.getWidth() / 2.0;
            double ty = iy - bounds.getHeight() / 2.0;
            g2.translate(tx, ty);
            g2.fill(shape);
            g2.translate(-tx, -ty);
        }
    }
    if (labelAttribute != null) {
        Object label = tree.getNodeAttribute(node, labelAttribute);
        if (label != null) {
            Color c = g2.getColor();
            Font f = g2.getFont();
            Font fsmall = f.deriveFont(f.getSize() - 1.0f);
            g2.setFont(fsmall);
            String labelString = label.toString();
            int width = g2.getFontMetrics().stringWidth(labelString);
            g2.setColor(textColor);
            g2.drawString(labelString, (float) (ix1 - width - 1.0), (float) (iy - 2.0));
            // recover color and font
            g2.setColor(c);
            g2.setFont(f);
        }
    }
    return y;
}
Also used : Line2D(java.awt.geom.Line2D) NodeRef(dr.evolution.tree.NodeRef)

Example 9 with Line2D

use of java.awt.geom.Line2D in project beast-mcmc by beast-dev.

the class KMLViewer method drawGrid.

private void drawGrid(int dLat, int dLong, Graphics2D g2d, AffineTransform transform) {
    for (double longitude = -180; longitude < 180; longitude += dLong) {
        Line2D line = new Line2D.Double(longitude, -90, longitude, 90);
        g2d.draw(transform.createTransformedShape(line));
    }
    for (double lat = -90; lat < 90; lat += dLat) {
        Line2D line = new Line2D.Double(-180, lat, 180, lat);
        g2d.draw(transform.createTransformedShape(line));
    }
}
Also used : Line2D(java.awt.geom.Line2D)

Example 10 with Line2D

use of java.awt.geom.Line2D in project processdash by dtuma.

the class RangeXYItemRenderer method gradientStart.

private Point2D gradientStart(double x0, double y0, double x1, double y1, double x2, double y2, double x3, double y3) {
    double dy = x0 - x1;
    double dx = y1 - y0;
    double startLen = Math.sqrt(dy * dy + dx * dx);
    if (startLen == 0)
        throw new IllegalArgumentException();
    Line2D line = new Line2D.Double(x0, y0, x1, y1);
    double len2 = line.ptLineDist(x2, y2);
    double len3 = line.ptLineDist(x3, y3);
    double len = 10;
    len = Math.max(len, len2);
    len = Math.max(len, len3);
    double fraction = len / startLen;
    return new Point2D.Double(x1 + dx * fraction, y1 + dy * fraction);
}
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