Search in sources :

Example 51 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 52 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 53 with Stroke

use of java.awt.Stroke in project jmeter by apache.

the class RespTimeGraphChart method drawSample.

private void drawSample(String _title, String[] _xAxisLabels, String _yAxisTitle, String[] _legendLabels, double[][] _data, int _width, int _height, int _incrScaleYAxis, Color[] _color, Font legendFont, Graphics g) {
    // define max scale y axis
    double max = maxYAxisScale > 0 ? maxYAxisScale : getTopValue(findMax(_data), BigDecimal.ROUND_UP);
    try {
        // if the title graph is empty, we can assume some default
        if (_title.length() == 0) {
            //$NON-NLS-1$
            _title = JMeterUtils.getResString("graph_resp_time_title");
        }
        this.setPreferredSize(new Dimension(_width, _height));
        // replace _xAxisTitle to null (don't display x axis title)
        DataSeries dataSeries = new DataSeries(_xAxisLabels, null, _yAxisTitle, _title);
        // Stroke and shape line settings
        Stroke[] strokes = new Stroke[_legendLabels.length];
        for (int i = 0; i < _legendLabels.length; i++) {
            strokes[i] = new BasicStroke(strokeWidth, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 5f);
        }
        Shape[] shapes = new Shape[_legendLabels.length];
        for (int i = 0; i < _legendLabels.length; i++) {
            shapes[i] = pointShape;
        }
        LineChartProperties lineChartProperties = new LineChartProperties(strokes, shapes);
        // Lines colors
        Paint[] paints = new Paint[_color.length];
        System.arraycopy(_color, 0, paints, 0, _color.length);
        // Define chart type (line)
        AxisChartDataSet axisChartDataSet = new AxisChartDataSet(_data, _legendLabels, paints, ChartType.LINE, lineChartProperties);
        dataSeries.addIAxisPlotDataSet(axisChartDataSet);
        ChartProperties chartProperties = new ChartProperties();
        LabelAxisProperties xaxis = new LabelAxisProperties();
        DataAxisProperties yaxis = new DataAxisProperties();
        yaxis.setUseCommas(showGrouping);
        if (legendFont != null) {
            yaxis.setAxisTitleChartFont(new ChartFont(legendFont, new Color(20)));
            yaxis.setScaleChartFont(new ChartFont(legendFont, new Color(20)));
            xaxis.setAxisTitleChartFont(new ChartFont(legendFont, new Color(20)));
            xaxis.setScaleChartFont(new ChartFont(legendFont, new Color(20)));
        }
        if (titleFont != null) {
            chartProperties.setTitleFont(new ChartFont(titleFont, new Color(0)));
        }
        // Y Axis ruler
        try {
            // ~a tic every 50 px
            double numInterval = _height / 50d;
            double incrYAxis = max / numInterval;
            double incrTopValue = _incrScaleYAxis;
            if (_incrScaleYAxis == 0) {
                incrTopValue = getTopValue(incrYAxis, BigDecimal.ROUND_HALF_UP);
            }
            if (incrTopValue < 1) {
                // Increment cannot be < 1
                incrTopValue = 1.0d;
            }
            yaxis.setUserDefinedScale(0, incrTopValue);
            yaxis.setNumItems((int) (max / incrTopValue) + 1);
            yaxis.setShowGridLines(1);
        } catch (PropertyException e) {
            log.warn("Exception while setting Y axis properties.", e);
        }
        AxisProperties axisProperties = new AxisProperties(xaxis, yaxis);
        axisProperties.setXAxisLabelsAreVertical(true);
        LegendProperties legendProperties = new LegendProperties();
        legendProperties.setBorderStroke(null);
        legendProperties.setPlacement(legendPlacement);
        legendProperties.setIconBorderPaint(Color.WHITE);
        legendProperties.setIconBorderStroke(new BasicStroke(0f, BasicStroke.CAP_SQUARE, BasicStroke.CAP_SQUARE));
        // Manage legend placement
        legendProperties.setNumColumns(LegendAreaProperties.COLUMNS_FIT_TO_IMAGE);
        if (legendPlacement == LegendAreaProperties.RIGHT || legendPlacement == LegendAreaProperties.LEFT) {
            legendProperties.setNumColumns(1);
        }
        if (legendFont != null) {
            legendProperties.setFont(legendFont);
        }
        AxisChart axisChart = new AxisChart(dataSeries, chartProperties, axisProperties, legendProperties, _width, _height);
        axisChart.setGraphics2D((Graphics2D) g);
        axisChart.render();
    } catch (ChartDataException | PropertyException e) {
        log.warn("Exception while rendering axis chart.", e);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) LineChartProperties(org.jCharts.properties.LineChartProperties) ChartFont(org.jCharts.properties.util.ChartFont) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) AxisChart(org.jCharts.axisChart.AxisChart) PropertyException(org.jCharts.properties.PropertyException) Color(java.awt.Color) AxisProperties(org.jCharts.properties.AxisProperties) DataAxisProperties(org.jCharts.properties.DataAxisProperties) LabelAxisProperties(org.jCharts.properties.LabelAxisProperties) AxisChartDataSet(org.jCharts.chartData.AxisChartDataSet) Dimension(java.awt.Dimension) Paint(java.awt.Paint) Paint(java.awt.Paint) DataAxisProperties(org.jCharts.properties.DataAxisProperties) LegendProperties(org.jCharts.properties.LegendProperties) ChartProperties(org.jCharts.properties.ChartProperties) PointChartProperties(org.jCharts.properties.PointChartProperties) LineChartProperties(org.jCharts.properties.LineChartProperties) ChartDataException(org.jCharts.chartData.ChartDataException) DataSeries(org.jCharts.chartData.DataSeries) LabelAxisProperties(org.jCharts.properties.LabelAxisProperties)

Example 54 with Stroke

use of java.awt.Stroke in project jmeter by apache.

the class LineGraph method drawSample.

private void drawSample(String _title, String[] _xAxisLabels, String _xAxisTitle, String _yAxisTitle, double[][] _data, int _width, int _height, Graphics g) {
    try {
        if (_width == 0) {
            _width = 450;
        }
        if (_height == 0) {
            _height = 250;
        }
        this.setPreferredSize(new Dimension(_width, _height));
        DataSeries dataSeries = new DataSeries(_xAxisLabels, _xAxisTitle, _yAxisTitle, _title);
        String[] legendLabels = yAxisLabel;
        Paint[] paints = this.createPaint(_data.length);
        Shape[] shapes = createShapes(_data.length);
        Stroke[] lstrokes = createStrokes(_data.length);
        LineChartProperties lineChartProperties = new LineChartProperties(lstrokes, shapes);
        AxisChartDataSet axisChartDataSet = new AxisChartDataSet(_data, legendLabels, paints, ChartType.LINE, lineChartProperties);
        dataSeries.addIAxisPlotDataSet(axisChartDataSet);
        ChartProperties chartProperties = new ChartProperties();
        AxisProperties axisProperties = new AxisProperties();
        // show the grid lines, to turn it off, set it to zero
        axisProperties.getYAxisProperties().setShowGridLines(1);
        axisProperties.setXAxisLabelsAreVertical(true);
        // set the Y Axis to round
        DataAxisProperties daxp = (DataAxisProperties) axisProperties.getYAxisProperties();
        daxp.setRoundToNearest(1);
        LegendProperties legendProperties = new LegendProperties();
        AxisChart axisChart = new AxisChart(dataSeries, chartProperties, axisProperties, legendProperties, _width, _height);
        axisChart.setGraphics2D((Graphics2D) g);
        axisChart.render();
    } catch (Exception e) {
        log.error("Error while rendering axis chart. {}", e.getMessage());
    }
}
Also used : LineChartProperties(org.jCharts.properties.LineChartProperties) Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) AxisChart(org.jCharts.axisChart.AxisChart) AxisProperties(org.jCharts.properties.AxisProperties) DataAxisProperties(org.jCharts.properties.DataAxisProperties) AxisChartDataSet(org.jCharts.chartData.AxisChartDataSet) Dimension(java.awt.Dimension) Paint(java.awt.Paint) DataAxisProperties(org.jCharts.properties.DataAxisProperties) LegendProperties(org.jCharts.properties.LegendProperties) PointChartProperties(org.jCharts.properties.PointChartProperties) LineChartProperties(org.jCharts.properties.LineChartProperties) ChartProperties(org.jCharts.properties.ChartProperties) DataSeries(org.jCharts.chartData.DataSeries)

Example 55 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)

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