Search in sources :

Example 31 with BasicStroke

use of java.awt.BasicStroke in project JMRI by JMRI.

the class LayoutSlip method drawSlipState.

private void drawSlipState(Graphics2D g2, int state) {
    int ctrX = 20;
    int ctrY = 20;
    Point2D ldispA = new Point2D.Double(-20.0, 0.0);
    Point2D ldispB = new Point2D.Double(-14.0, 14.0);
    g2.setColor(Color.black);
    Point2D A = new Point2D.Double(ctrX + ldispA.getX(), ctrY + ldispA.getY());
    Point2D B = new Point2D.Double(ctrX + ldispB.getX(), ctrY + ldispB.getY());
    Point2D C = new Point2D.Double(ctrX - ldispA.getX(), ctrY - ldispA.getY());
    Point2D D = new Point2D.Double(ctrX - ldispB.getX(), ctrY - ldispB.getY());
    g2.setStroke(new BasicStroke(2, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND));
    g2.draw(new Line2D.Double(A, MathUtil.oneThirdPoint(A, C)));
    g2.draw(new Line2D.Double(C, MathUtil.oneThirdPoint(C, A)));
    if (state == STATE_AC || state == STATE_BD || state == UNKNOWN) {
        g2.draw(new Line2D.Double(A, MathUtil.oneThirdPoint(A, D)));
        g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, A)));
        if (getSlipType() == DOUBLE_SLIP) {
            g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, C)));
            g2.draw(new Line2D.Double(C, MathUtil.oneThirdPoint(C, B)));
        }
    } else {
        g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
        g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
    }
    if (getSlipType() == DOUBLE_SLIP) {
        if (state == STATE_AC) {
            g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
            g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(A, C));
        } else if (state == STATE_BD) {
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(B, D));
        } else if (state == STATE_AD) {
            g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, C)));
            g2.draw(new Line2D.Double(C, MathUtil.oneThirdPoint(C, B)));
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(A, D));
        } else if (state == STATE_BC) {
            g2.draw(new Line2D.Double(A, MathUtil.oneThirdPoint(A, D)));
            g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, A)));
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(B, C));
        } else {
            g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
            g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
        }
    } else {
        g2.draw(new Line2D.Double(A, MathUtil.oneThirdPoint(A, D)));
        g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, A)));
        if (state == STATE_AD) {
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(A, D));
        } else if (state == STATE_AC) {
            g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
            g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(A, C));
        } else if (state == STATE_BD) {
            g2.setColor(Color.red);
            g2.draw(new Line2D.Double(B, D));
        } else {
            g2.draw(new Line2D.Double(B, MathUtil.oneThirdPoint(B, D)));
            g2.draw(new Line2D.Double(D, MathUtil.oneThirdPoint(D, B)));
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Point2D(java.awt.geom.Point2D) Line2D(java.awt.geom.Line2D)

Example 32 with BasicStroke

use of java.awt.BasicStroke in project JMRI by JMRI.

the class TrackSegment method drawDashed.

// drawHidden(Graphics2D g2)
public void drawDashed(Graphics2D g2, boolean mainline) {
    if ((!isHidden()) && getDashed() && (mainline == getMainline())) {
        setColorForTrackBlock(g2, getLayoutBlock());
        float trackWidth = layoutEditor.setTrackStrokeWidth(g2, mainline);
        if (getArc()) {
            calculateTrackSegmentAngle();
            Stroke originalStroke = g2.getStroke();
            Stroke drawingStroke = new BasicStroke(trackWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 9 }, 0);
            g2.setStroke(drawingStroke);
            g2.draw(new Arc2D.Double(getCX(), getCY(), getCW(), getCH(), getStartadj(), getTmpAngle(), Arc2D.OPEN));
            g2.setStroke(originalStroke);
        } else if (getBezier()) {
            Stroke originalStroke = g2.getStroke();
            Stroke drawingStroke = new BasicStroke(trackWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0, new float[] { 9 }, 0);
            g2.setStroke(drawingStroke);
            Point2D pt1 = layoutEditor.getCoords(getConnect1(), getType1());
            Point2D pt2 = layoutEditor.getCoords(getConnect2(), getType2());
            int cnt = bezierControlPoints.size();
            Point2D[] points = new Point2D[cnt + 2];
            points[0] = pt1;
            for (int idx = 0; idx < cnt; idx++) {
                points[idx + 1] = bezierControlPoints.get(idx);
            }
            points[cnt + 1] = pt2;
            MathUtil.drawBezier(g2, points);
            g2.setStroke(originalStroke);
        } else {
            Point2D end1 = layoutEditor.getCoords(getConnect1(), getType1());
            Point2D end2 = layoutEditor.getCoords(getConnect2(), getType2());
            double delX = end1.getX() - end2.getX();
            double delY = end1.getY() - end2.getY();
            double cLength = Math.hypot(delX, delY);
            // note: The preferred dimension of a dash (solid + blank space) is
            //         5 * the track width - about 60% solid and 40% blank.
            int nDashes = (int) (cLength / ((trackWidth) * 5.0));
            if (nDashes < 3) {
                nDashes = 3;
            }
            double delXDash = -delX / ((nDashes) - 0.5);
            double delYDash = -delY / ((nDashes) - 0.5);
            double begX = end1.getX();
            double begY = end1.getY();
            for (int k = 0; k < nDashes; k++) {
                g2.draw(new Line2D.Double(new Point2D.Double(begX, begY), new Point2D.Double(begX + (delXDash * 0.5), begY + (delYDash * 0.5))));
                begX += delXDash;
                begY += delYDash;
            }
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Point2D(java.awt.geom.Point2D) Arc2D(java.awt.geom.Arc2D)

Example 33 with BasicStroke

use of java.awt.BasicStroke in project jdk8u_jdk by JetBrains.

the class Test7019861 method main.

public static void main(String[] argv) throws Exception {
    BufferedImage im = getWhiteImage(30, 30);
    Graphics2D g2 = (Graphics2D) im.getGraphics();
    g2.setRenderingHint(KEY_ANTIALIASING, VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(KEY_STROKE_CONTROL, VALUE_STROKE_PURE);
    g2.setStroke(new BasicStroke(10, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL));
    g2.setBackground(Color.white);
    g2.setColor(Color.black);
    Path2D p = getPath(0, 0, 20);
    g2.draw(p);
    if (!(new Color(im.getRGB(20, 19))).equals(Color.black)) {
        throw new Exception("This pixel should be black");
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Path2D(java.awt.geom.Path2D) Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage) Graphics2D(java.awt.Graphics2D)

Example 34 with BasicStroke

use of java.awt.BasicStroke in project jdk8u_jdk by JetBrains.

the class DrawXORModeTest method paint.

@Override
public void paint(Graphics g) {
    if (g == null || !(g instanceof Graphics2D)) {
        return;
    }
    g.setColor(Color.white);
    g.setXORMode(Color.black);
    Graphics2D dg = (Graphics2D) g;
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 10.0f, new float[] { 1.0f, 1.0f }, 0.0f);
    dg.setStroke(stroke);
    try {
        dg.draw(new Line2D.Float(10, 10, 20, 20));
    } catch (Throwable e) {
        synchronized (this) {
            theError = e;
        }
    } finally {
        didDraw.countDown();
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Line2D(java.awt.geom.Line2D) Graphics2D(java.awt.Graphics2D)

Example 35 with BasicStroke

use of java.awt.BasicStroke in project processdash by dtuma.

the class FloppyDiskIcon method paintIcon.

@Override
protected void paintIcon(Graphics2D g2, Shape clip, float scale) {
    // fill the background
    g2.setColor(highlight);
    g2.fill(area);
    // paint the shutter
    g2.setColor(gray);
    g2.fill(new Rectangle2D.Float(5, 1, 6, 5 + 1 / scale));
    g2.setColor(white);
    g2.fill(new Rectangle2D.Float(8, 2 + 1 / scale, 2, 3));
    // paint the label
    g2.clip(area);
    g2.setColor(white);
    g2.fill(label);
    g2.setStroke(new BasicStroke(1 / scale));
    g2.setColor(gray);
    g2.draw(label);
    // draw text on the label
    g2.setColor(highlight);
    int t = 1;
    for (float f = 10; f < 13; f += 2 / scale) {
        g2.draw(new Line2D.Float(5, f, 10 - t, f));
        t = (t + 2) % 3;
    }
    // paint the outer edge
    g2.setClip(clip);
    g2.setColor(edge);
    g2.draw(area);
}
Also used : BasicStroke(java.awt.BasicStroke) Rectangle2D(java.awt.geom.Rectangle2D) RoundRectangle2D(java.awt.geom.RoundRectangle2D) Line2D(java.awt.geom.Line2D)

Aggregations

BasicStroke (java.awt.BasicStroke)563 Graphics2D (java.awt.Graphics2D)179 Color (java.awt.Color)160 Stroke (java.awt.Stroke)137 GradientPaint (java.awt.GradientPaint)95 Test (org.junit.Test)93 Rectangle2D (java.awt.geom.Rectangle2D)67 Paint (java.awt.Paint)64 Font (java.awt.Font)61 Line2D (java.awt.geom.Line2D)46 Point (java.awt.Point)45 BufferedImage (java.awt.image.BufferedImage)43 Shape (java.awt.Shape)38 Point2D (java.awt.geom.Point2D)38 JFreeChart (org.jfree.chart.JFreeChart)34 AffineTransform (java.awt.geom.AffineTransform)33 Rectangle (java.awt.Rectangle)27 RectangleInsets (org.jfree.ui.RectangleInsets)27 Ellipse2D (java.awt.geom.Ellipse2D)25 NumberAxis (org.jfree.chart.axis.NumberAxis)25