Search in sources :

Example 21 with Stroke

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

the class TooltipLineXYLineAndShapeRenderer method getAreaWidth.

/**
     *  This method tries to get the line stroke's thickness to determine how big we need
     *   to draw the area. If it fails, or if the stroke thickness is not big enough, the
     *   minimum width will be used.
     */
private float getAreaWidth(int series) {
    float areaWidth = MINIMUM_TOOLTIP_AREA_WIDTH;
    Stroke seriesStroke = getSeriesStroke(series);
    if (seriesStroke instanceof BasicStroke) {
        float lineWidth = ((BasicStroke) seriesStroke).getLineWidth();
        if (lineWidth > areaWidth)
            areaWidth = lineWidth;
    }
    return areaWidth;
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke)

Example 22 with Stroke

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

the class RangeXYItemRenderer method lookupSeriesStroke.

@Override
public Stroke lookupSeriesStroke(int series) {
    Comparable key = getPlot().getDataset(0).getSeriesKey(series);
    Stroke result = strokeMap.getStroke(key);
    if (result == null)
        result = super.lookupSeriesStroke(series);
    return result;
}
Also used : Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke)

Example 23 with Stroke

use of java.awt.Stroke 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 24 with Stroke

use of java.awt.Stroke 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 25 with Stroke

use of java.awt.Stroke in project knime-core by knime.

the class ParallelCoordinateDrawingPane method drawCurve.

/**
 * Draws a quad curve between the mapped data points of one
 * {@link org.knime.base.node.viz.plotter.parcoord.LineInfo}.
 *
 * @param g graphics object
 * @param line one line / row
 */
private void drawCurve(final Graphics2D g, final LineInfo line) {
    // for each line
    GeneralPath path = null;
    Point ctrl = null;
    // Point newCtrl = null;
    if (m_fade && !line.isHilite()) {
        if (line.isSelected()) {
            g.setColor(ColorAttr.INACTIVE_SELECTED);
        } else {
            g.setColor(ColorAttr.INACTIVE);
        }
    } else if (!m_hide && !m_fade) {
        g.setColor(line.getColor().getColor(line.isSelected(), line.isHilite()));
    } else {
        // bugfix : 1278
        g.setColor(line.getColor().getColor(line.isSelected(), false));
    }
    int lineSize = getStrokeSize(line.getSize());
    Stroke selectionStroke = new BasicStroke(lineSize, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 1.0f, new float[] { DASH }, 0);
    ((Graphics2D) g).setStroke(new BasicStroke(lineSize));
    // for all points
    for (int i = 0; i < line.getPoints().size() - 1; i++) {
        Point p1 = line.getPoints().get(i);
        Point p2 = line.getPoints().get(i + 1);
        if (path == null) {
            path = new GeneralPath();
            path.moveTo(p1.x, p1.y);
            // first control Point with offset
            int x = p1.x + ((p2.x - p1.x) / 2);
            int y = p1.y + ((p2.y - p1.y) / 2) + 10;
            ctrl = new Point(x, y);
        }
        // create cubic curve
        int firstX = p1.x + ((p2.x - p1.x) / 3);
        int secondX = p1.x + ((p2.x - p1.x) / 2);
        Point firstCtrl = getNextControlPoint(ctrl, p1, firstX);
        Point secondCtrl = createAdditionalCtrlPoint(secondX, p2, firstCtrl);
        path.curveTo(firstCtrl.x, firstCtrl.y, secondCtrl.x, secondCtrl.y, p2.x, p2.y);
        ctrl = secondCtrl;
    }
    Color backupColor = g.getColor();
    if (line.isHilite() && !m_hide && !m_fade) {
        // draw additional "hilite" line
        g.setColor(ColorAttr.HILITE);
        Stroke backupStroke = g.getStroke();
        g.setStroke(new BasicStroke(2 * lineSize));
        g.draw(path);
        g.setColor(backupColor);
        g.setStroke(backupStroke);
    }
    g.draw(path);
    if (line.isSelected()) {
        // draw dotted line
        Stroke backupStroke = ((Graphics2D) g).getStroke();
        ((Graphics2D) g).setStroke(selectionStroke);
        g.setXORMode(Color.white);
        g.draw(path);
        ((Graphics2D) g).setStroke(backupStroke);
        g.setPaintMode();
    }
    if (m_showDots) {
        for (Point p : line.getPoints()) {
            int size = getStrokeSize(line.getSize());
            paintDot(g, p, line, size);
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) GeneralPath(java.awt.geom.GeneralPath) Color(java.awt.Color) Point(java.awt.Point) Point(java.awt.Point) Graphics2D(java.awt.Graphics2D)

Aggregations

Stroke (java.awt.Stroke)83 BasicStroke (java.awt.BasicStroke)74 Paint (java.awt.Paint)36 Color (java.awt.Color)34 Graphics2D (java.awt.Graphics2D)30 Point (java.awt.Point)23 GradientPaint (java.awt.GradientPaint)11 Shape (java.awt.Shape)11 Line2D (java.awt.geom.Line2D)11 Point2D (java.awt.geom.Point2D)11 Ellipse2D (java.awt.geom.Ellipse2D)9 Rectangle (java.awt.Rectangle)8 RoundRectangle2D (java.awt.geom.RoundRectangle2D)7 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)6 Font (java.awt.Font)6 RadialGradientPaint (java.awt.RadialGradientPaint)6 AffineTransform (java.awt.geom.AffineTransform)6 Arc2D (java.awt.geom.Arc2D)5 Rectangle2D (java.awt.geom.Rectangle2D)5 GeneralPath (java.awt.geom.GeneralPath)4