Search in sources :

Example 31 with Stroke

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

the class WPathGraphics method draw.

/**
     * Strokes the outline of a Shape using the settings of the current
     * graphics state.  The rendering attributes applied include the
     * clip, transform, paint or color, composite and stroke attributes.
     * @param s The shape to be drawn.
     * @see #setStroke
     * @see #setPaint
     * @see java.awt.Graphics#setColor
     * @see #transform
     * @see #setTransform
     * @see #clip
     * @see #setClip
     * @see #setComposite
     */
@Override
public void draw(Shape s) {
    Stroke stroke = getStroke();
    /* If the line being drawn is thinner than can be
         * rendered, then change the line width, stroke
         * the shape, and then set the line width back.
         * We can only do this for BasicStroke's.
         */
    if (stroke instanceof BasicStroke) {
        BasicStroke lineStroke;
        BasicStroke minLineStroke = null;
        float deviceLineWidth;
        float lineWidth;
        AffineTransform deviceTransform;
        Point2D.Float penSize;
        /* Get the requested line width in user space.
             */
        lineStroke = (BasicStroke) stroke;
        lineWidth = lineStroke.getLineWidth();
        penSize = new Point2D.Float(lineWidth, lineWidth);
        /* Compute the line width in device coordinates.
             * Work on a point in case there is asymetric scaling
             * between user and device space.
             * Take the absolute value in case there is negative
             * scaling in effect.
             */
        deviceTransform = getTransform();
        deviceTransform.deltaTransform(penSize, penSize);
        deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y));
        /* If the requested line is too thin then map our
             * minimum line width back to user space and set
             * a new BasicStroke.
             */
        if (deviceLineWidth < MIN_DEVICE_LINEWIDTH) {
            Point2D.Float minPenSize = new Point2D.Float(MIN_DEVICE_LINEWIDTH, MIN_DEVICE_LINEWIDTH);
            try {
                AffineTransform inverse;
                float minLineWidth;
                /* Convert the minimum line width from device
                     * space to user space.
                     */
                inverse = deviceTransform.createInverse();
                inverse.deltaTransform(minPenSize, minPenSize);
                minLineWidth = Math.max(Math.abs(minPenSize.x), Math.abs(minPenSize.y));
                /* Use all of the parameters from the current
                     * stroke but change the line width to our
                     * calculated minimum.
                     */
                minLineStroke = new BasicStroke(minLineWidth, lineStroke.getEndCap(), lineStroke.getLineJoin(), lineStroke.getMiterLimit(), lineStroke.getDashArray(), lineStroke.getDashPhase());
                setStroke(minLineStroke);
            } catch (NoninvertibleTransformException e) {
            /* If we can't invert the matrix there is something
                     * very wrong so don't worry about the minor matter
                     * of a minimum line width.
                     */
            }
        }
        super.draw(s);
        /* If we changed the stroke, put back the old
             * stroke in order to maintain a minimum line
             * width.
             */
        if (minLineStroke != null) {
            setStroke(lineStroke);
        }
    /* The stroke in effect was not a BasicStroke so we
         * will not try to enforce a minimum line width.
         */
    } else {
        super.draw(s);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) NoninvertibleTransformException(java.awt.geom.NoninvertibleTransformException) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Point2D(java.awt.geom.Point2D) AffineTransform(java.awt.geom.AffineTransform)

Example 32 with Stroke

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

the class WPathGraphics method deviceFrameRect.

/**
     * Draw the bounding rectangle using transformed coordinates.
     */
@Override
protected void deviceFrameRect(int x, int y, int width, int height, Color color) {
    AffineTransform deviceTransform = getTransform();
    /* check if rotated or sheared */
    int transformType = deviceTransform.getType();
    boolean usePath = ((transformType & (AffineTransform.TYPE_GENERAL_ROTATION | AffineTransform.TYPE_GENERAL_TRANSFORM)) != 0);
    if (usePath) {
        draw(new Rectangle2D.Float(x, y, width, height));
        return;
    }
    Stroke stroke = getStroke();
    if (stroke instanceof BasicStroke) {
        BasicStroke lineStroke = (BasicStroke) stroke;
        int endCap = lineStroke.getEndCap();
        int lineJoin = lineStroke.getLineJoin();
        /* check for default style and try to optimize it by
             * calling the frameRect native function instead of using paths.
             */
        if ((endCap == BasicStroke.CAP_SQUARE) && (lineJoin == BasicStroke.JOIN_MITER) && (lineStroke.getMiterLimit() == 10.0f)) {
            float lineWidth = lineStroke.getLineWidth();
            Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth);
            deviceTransform.deltaTransform(penSize, penSize);
            float deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y));
            /* transform upper left coordinate */
            Point2D.Float ul_pos = new Point2D.Float(x, y);
            deviceTransform.transform(ul_pos, ul_pos);
            /* transform lower right coordinate */
            Point2D.Float lr_pos = new Point2D.Float(x + width, y + height);
            deviceTransform.transform(lr_pos, lr_pos);
            float w = (float) (lr_pos.getX() - ul_pos.getX());
            float h = (float) (lr_pos.getY() - ul_pos.getY());
            WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();
            /* use selectStylePen, if supported */
            if (wPrinterJob.selectStylePen(endCap, lineJoin, deviceLineWidth, color) == true) {
                wPrinterJob.frameRect((float) ul_pos.getX(), (float) ul_pos.getY(), w, h);
            } else /* not supported, must be a Win 9x */
            {
                double lowerRes = Math.min(wPrinterJob.getXRes(), wPrinterJob.getYRes());
                if ((deviceLineWidth / lowerRes) < MAX_THINLINE_INCHES) {
                    /* use the default pen styles for thin pens. */
                    wPrinterJob.selectPen(deviceLineWidth, color);
                    wPrinterJob.frameRect((float) ul_pos.getX(), (float) ul_pos.getY(), w, h);
                } else {
                    draw(new Rectangle2D.Float(x, y, width, height));
                }
            }
        } else {
            draw(new Rectangle2D.Float(x, y, width, height));
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Rectangle2D(java.awt.geom.Rectangle2D) Point2D(java.awt.geom.Point2D) AffineTransform(java.awt.geom.AffineTransform)

Example 33 with Stroke

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

the class WPathGraphics method deviceDrawLine.

/**
     * Draw a line using a pen created using the specified color
     * and current stroke properties.
     */
@Override
protected void deviceDrawLine(int xBegin, int yBegin, int xEnd, int yEnd, Color color) {
    Stroke stroke = getStroke();
    if (stroke instanceof BasicStroke) {
        BasicStroke lineStroke = (BasicStroke) stroke;
        if (lineStroke.getDashArray() != null) {
            draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd));
            return;
        }
        float lineWidth = lineStroke.getLineWidth();
        Point2D.Float penSize = new Point2D.Float(lineWidth, lineWidth);
        AffineTransform deviceTransform = getTransform();
        deviceTransform.deltaTransform(penSize, penSize);
        float deviceLineWidth = Math.min(Math.abs(penSize.x), Math.abs(penSize.y));
        Point2D.Float begin_pos = new Point2D.Float(xBegin, yBegin);
        deviceTransform.transform(begin_pos, begin_pos);
        Point2D.Float end_pos = new Point2D.Float(xEnd, yEnd);
        deviceTransform.transform(end_pos, end_pos);
        int endCap = lineStroke.getEndCap();
        int lineJoin = lineStroke.getLineJoin();
        /* check if it's a one-pixel line */
        if ((end_pos.getX() == begin_pos.getX()) && (end_pos.getY() == begin_pos.getY())) {
            /* endCap other than Round will not print!
                 * due to Windows GDI limitation, force it to CAP_ROUND
                 */
            endCap = BasicStroke.CAP_ROUND;
        }
        WPrinterJob wPrinterJob = (WPrinterJob) getPrinterJob();
        /* call native function that creates pen with style */
        if (wPrinterJob.selectStylePen(endCap, lineJoin, deviceLineWidth, color)) {
            wPrinterJob.moveTo((float) begin_pos.getX(), (float) begin_pos.getY());
            wPrinterJob.lineTo((float) end_pos.getX(), (float) end_pos.getY());
        } else /* selectStylePen is not supported, must be Win 9X */
        {
            /* let's see if we can use a a default pen
                 *  if it's round end (Windows' default style)
                 *  or it's vertical/horizontal
                 *  or stroke is too thin.
                 */
            double lowerRes = Math.min(wPrinterJob.getXRes(), wPrinterJob.getYRes());
            if ((endCap == BasicStroke.CAP_ROUND) || (((xBegin == xEnd) || (yBegin == yEnd)) && (deviceLineWidth / lowerRes < MAX_THINLINE_INCHES))) {
                wPrinterJob.selectPen(deviceLineWidth, color);
                wPrinterJob.moveTo((float) begin_pos.getX(), (float) begin_pos.getY());
                wPrinterJob.lineTo((float) end_pos.getX(), (float) end_pos.getY());
            } else {
                draw(new Line2D.Float(xBegin, yBegin, xEnd, yEnd));
            }
        }
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Point2D(java.awt.geom.Point2D) AffineTransform(java.awt.geom.AffineTransform) Line2D(java.awt.geom.Line2D)

Example 34 with Stroke

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

the class DrawFrame method setDrawParams.

protected void setDrawParams() {
    TargetPane targetPane = (TargetPane) _parent.getEditor().getTargetPanel();
    Stroke stroke = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 10f);
    targetPane.setSelectRectStroke(stroke);
    targetPane.setSelectRectColor(Color.green);
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) TargetPane(jmri.jmrit.display.Editor.TargetPane)

Example 35 with Stroke

use of java.awt.Stroke in project ChatGameFontificator by GlitchCog.

the class ColorSwatch method paint.

@Override
public void paint(Graphics g) {
    super.paint(g);
    if (isSelected()) {
        Graphics2D g2d = (Graphics2D) g;
        g2d.setPaint(Color.BLACK);
        Stroke stroke = new BasicStroke(BORDER_THICKNESS, BasicStroke.CAP_BUTT, BasicStroke.JOIN_BEVEL, 0.0f, new float[] { 3, 3, 3, 3 }, dashTimer.getOffset());
        g2d.setStroke(stroke);
        final int halfThickness = Math.max(1, BORDER_THICKNESS / 2);
        g2d.drawRect(halfThickness, halfThickness, getWidth() - BORDER_THICKNESS, getHeight() - BORDER_THICKNESS);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Graphics2D(java.awt.Graphics2D)

Aggregations

Stroke (java.awt.Stroke)43 BasicStroke (java.awt.BasicStroke)41 Paint (java.awt.Paint)18 Point (java.awt.Point)11 Shape (java.awt.Shape)11 Color (java.awt.Color)7 Line2D (java.awt.geom.Line2D)7 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)6 Graphics2D (java.awt.Graphics2D)6 AffineTransform (java.awt.geom.AffineTransform)5 Ellipse2D (java.awt.geom.Ellipse2D)4 Point2D (java.awt.geom.Point2D)4 Font (java.awt.Font)3 GradientPaint (java.awt.GradientPaint)3 Rectangle (java.awt.Rectangle)3 RoundRectangle2D (java.awt.geom.RoundRectangle2D)3 Dimension (java.awt.Dimension)2 AxisChart (org.jCharts.axisChart.AxisChart)2 AxisChartDataSet (org.jCharts.chartData.AxisChartDataSet)2 DataSeries (org.jCharts.chartData.DataSeries)2