Search in sources :

Example 71 with BasicStroke

use of java.awt.BasicStroke in project pentaho-kettle by pentaho.

the class SwingGC method drawImage.

private void drawImage(SwingUniversalImage image, int centerX, int centerY, double angle, int imageSize) {
    if (isDrawingPixelatedImages() && image.isBitmap()) {
        BufferedImage img = image.getAsBitmapForSize(imageSize, imageSize, angle);
        ColorModel cm = img.getColorModel();
        Raster raster = img.getRaster();
        int offx = centerX + xOffset - img.getWidth() / 2;
        int offy = centerY + yOffset - img.getHeight() / 2;
        for (int x = 0; x < img.getWidth(observer); x++) {
            for (int y = 0; y < img.getHeight(observer); y++) {
                Object pix = raster.getDataElements(x, y, null);
                gc.setColor(new Color(cm.getRed(pix), cm.getGreen(pix), cm.getBlue(pix), cm.getAlpha(pix)));
                gc.setStroke(new BasicStroke(1.0f));
                gc.drawLine(offx + x, offy + y, offx + x + 1, offy + y + 1);
            }
        }
    } else {
        image.drawToGraphics(gc, centerX, centerY, imageSize, imageSize, angle);
    }
}
Also used : BasicStroke(java.awt.BasicStroke) ColorModel(java.awt.image.ColorModel) Raster(java.awt.image.Raster) Color(java.awt.Color) BufferedImage(java.awt.image.BufferedImage)

Example 72 with BasicStroke

use of java.awt.BasicStroke in project pentaho-kettle by pentaho.

the class TransPerfDelegate method updateCanvas.

private void updateCanvas() {
    Rectangle bounds = canvas.getBounds();
    if (bounds.width <= 0 || bounds.height <= 0) {
        return;
    }
    // The list of snapshots : convert to JFreeChart dataset
    // 
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String[] selectedSteps = stepsList.getSelection();
    if (selectedSteps == null || selectedSteps.length == 0) {
        // first step
        selectedSteps = new String[] { steps[0] };
        stepsList.select(0);
    }
    int[] dataIndices = dataList.getSelectionIndices();
    if (dataIndices == null || dataIndices.length == 0) {
        dataIndices = new int[] { DATA_CHOICE_WRITTEN };
        dataList.select(0);
    }
    boolean multiStep = stepsList.getSelectionCount() > 1;
    boolean multiData = dataList.getSelectionCount() > 1;
    // A single metric shown for a single step
    boolean calcMoving = !multiStep && !multiData;
    List<Double> movingList = new ArrayList<Double>();
    int movingSize = 10;
    double movingTotal = 0;
    int totalTimeInSeconds = 0;
    for (int t = 0; t < selectedSteps.length; t++) {
        String stepNameCopy = selectedSteps[t];
        List<StepPerformanceSnapShot> snapShotList = stepPerformanceSnapShots.get(stepNameCopy);
        if (snapShotList != null && snapShotList.size() > 1) {
            totalTimeInSeconds = (int) Math.round(((double) (snapShotList.get(snapShotList.size() - 1).getDate().getTime() - snapShotList.get(0).getDate().getTime())) / 1000);
            for (int i = 0; i < snapShotList.size(); i++) {
                StepPerformanceSnapShot snapShot = snapShotList.get(i);
                if (snapShot.getTimeDifference() != 0) {
                    double factor = (double) 1000 / (double) snapShot.getTimeDifference();
                    for (int d = 0; d < dataIndices.length; d++) {
                        String dataType;
                        if (multiStep) {
                            dataType = stepNameCopy;
                        } else {
                            dataType = dataChoices[dataIndices[d]];
                        }
                        String xLabel = Integer.toString(Math.round(i * timeDifference / 1000));
                        Double metric = null;
                        switch(dataIndices[d]) {
                            case DATA_CHOICE_INPUT:
                                metric = snapShot.getLinesInput() * factor;
                                break;
                            case DATA_CHOICE_OUTPUT:
                                metric = snapShot.getLinesOutput() * factor;
                                break;
                            case DATA_CHOICE_READ:
                                metric = snapShot.getLinesRead() * factor;
                                break;
                            case DATA_CHOICE_WRITTEN:
                                metric = snapShot.getLinesWritten() * factor;
                                break;
                            case DATA_CHOICE_UPDATED:
                                metric = snapShot.getLinesUpdated() * factor;
                                break;
                            case DATA_CHOICE_REJECTED:
                                metric = snapShot.getLinesRejected() * factor;
                                break;
                            case DATA_CHOICE_INPUT_BUFFER_SIZE:
                                metric = (double) snapShot.getInputBufferSize();
                                break;
                            case DATA_CHOICE_OUTPUT_BUFFER_SIZE:
                                metric = (double) snapShot.getOutputBufferSize();
                                break;
                            default:
                                break;
                        }
                        if (metric != null) {
                            dataset.addValue(metric, dataType, xLabel);
                            if (calcMoving) {
                                movingTotal += metric;
                                movingList.add(metric);
                                if (movingList.size() > movingSize) {
                                    movingTotal -= movingList.get(0);
                                    movingList.remove(0);
                                }
                                double movingAverage = movingTotal / movingList.size();
                                dataset.addValue(movingAverage, dataType + "(Avg)", xLabel);
                            // System.out.println("moving average = "+movingAverage+", movingTotal="+movingTotal+", m");
                            }
                        }
                    }
                }
            }
        }
    }
    String chartTitle = title;
    if (multiStep) {
        chartTitle += " (" + dataChoices[dataIndices[0]] + ")";
    } else {
        chartTitle += " (" + selectedSteps[0] + ")";
    }
    final JFreeChart chart = // chart title
    ChartFactory.createLineChart(// chart title
    chartTitle, BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.TimeInSeconds.Label", Integer.toString(totalTimeInSeconds), // domain axis label
    Long.toString(timeDifference)), // range axis label
    BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.RowsPerSecond.Label"), // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips
    true, // urls
    false);
    chart.setBackgroundPaint(Color.white);
    TextTitle title = new TextTitle(chartTitle);
    // title.setExpandToFitSpace(true);
    // org.eclipse.swt.graphics.Color pentahoColor = GUIResource.getInstance().getColorPentaho();
    // java.awt.Color color = new java.awt.Color(pentahoColor.getRed(), pentahoColor.getGreen(),pentahoColor.getBlue());
    // title.setBackgroundPaint(color);
    title.setFont(new java.awt.Font("SansSerif", java.awt.Font.BOLD, 12));
    chart.setTitle(title);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setForegroundAlpha(0.5f);
    plot.setRangeGridlinesVisible(true);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelsVisible(false);
    // Customize the renderer...
    // 
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(Color.white);
    renderer.setSeriesStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesOutlineStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesStroke(1, new BasicStroke(2.5f));
    renderer.setSeriesOutlineStroke(1, new BasicStroke(2.5f));
    renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));
    BufferedImage bufferedImage = chart.createBufferedImage(bounds.width, bounds.height);
    ImageData imageData = ImageUtil.convertToSWT(bufferedImage);
    // 
    if (image != null) {
        image.dispose();
    }
    image = new Image(transGraph.getDisplay(), imageData);
    // Draw the image on the canvas...
    // 
    canvas.redraw();
}
Also used : BasicStroke(java.awt.BasicStroke) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) BufferedImage(java.awt.image.BufferedImage) Image(org.eclipse.swt.graphics.Image) Ellipse2D(java.awt.geom.Ellipse2D) BufferedImage(java.awt.image.BufferedImage) ImageData(org.eclipse.swt.graphics.ImageData) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) TextTitle(org.jfree.chart.title.TextTitle) CategoryAxis(org.jfree.chart.axis.CategoryAxis) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) StepPerformanceSnapShot(org.pentaho.di.trans.performance.StepPerformanceSnapShot)

Example 73 with BasicStroke

use of java.awt.BasicStroke in project pentaho-kettle by pentaho.

the class StepPerformanceSnapShotDialog method updateCanvas.

private void updateCanvas() {
    Rectangle bounds = canvas.getBounds();
    if (bounds.width <= 0 || bounds.height <= 0) {
        return;
    }
    // The list of snapshots : convert to JFreeChart dataset
    // 
    DefaultCategoryDataset dataset = new DefaultCategoryDataset();
    String[] selectedSteps = stepsList.getSelection();
    if (selectedSteps == null || selectedSteps.length == 0) {
        // first step
        selectedSteps = new String[] { steps[0] };
        stepsList.select(0);
    }
    int[] dataIndices = dataList.getSelectionIndices();
    if (dataIndices == null || dataIndices.length == 0) {
        dataIndices = new int[] { DATA_CHOICE_WRITTEN };
        dataList.select(0);
    }
    boolean multiStep = stepsList.getSelectionCount() > 1;
    boolean multiData = dataList.getSelectionCount() > 1;
    // A single metric shown for a single step
    boolean calcMoving = !multiStep && !multiData;
    List<Double> movingList = new ArrayList<Double>();
    int movingSize = 10;
    double movingTotal = 0;
    int totalTimeInSeconds = 0;
    for (int t = 0; t < selectedSteps.length; t++) {
        String stepNameCopy = selectedSteps[t];
        List<StepPerformanceSnapShot> snapShotList = stepPerformanceSnapShots.get(stepNameCopy);
        if (snapShotList != null && snapShotList.size() > 1) {
            totalTimeInSeconds = (int) Math.round(((double) (snapShotList.get(snapShotList.size() - 1).getDate().getTime() - snapShotList.get(0).getDate().getTime())) / 1000);
            for (int i = 0; i < snapShotList.size(); i++) {
                StepPerformanceSnapShot snapShot = snapShotList.get(i);
                if (snapShot.getTimeDifference() != 0) {
                    double factor = (double) 1000 / (double) snapShot.getTimeDifference();
                    for (int d = 0; d < dataIndices.length; d++) {
                        String dataType;
                        if (multiStep) {
                            dataType = stepNameCopy;
                        } else {
                            dataType = dataChoices[dataIndices[d]];
                        }
                        String xLabel = Integer.toString(Math.round(i * timeDifference / 1000));
                        Double metric = null;
                        switch(dataIndices[d]) {
                            case DATA_CHOICE_INPUT:
                                metric = snapShot.getLinesInput() * factor;
                                break;
                            case DATA_CHOICE_OUTPUT:
                                metric = snapShot.getLinesOutput() * factor;
                                break;
                            case DATA_CHOICE_READ:
                                metric = snapShot.getLinesRead() * factor;
                                break;
                            case DATA_CHOICE_WRITTEN:
                                metric = snapShot.getLinesWritten() * factor;
                                break;
                            case DATA_CHOICE_UPDATED:
                                metric = snapShot.getLinesUpdated() * factor;
                                break;
                            case DATA_CHOICE_REJECTED:
                                metric = snapShot.getLinesRejected() * factor;
                                break;
                            case DATA_CHOICE_INPUT_BUFFER_SIZE:
                                metric = (double) snapShot.getInputBufferSize();
                                break;
                            case DATA_CHOICE_OUTPUT_BUFFER_SIZE:
                                metric = (double) snapShot.getOutputBufferSize();
                                break;
                            default:
                                break;
                        }
                        if (metric != null) {
                            dataset.addValue(metric, dataType, xLabel);
                            if (calcMoving) {
                                movingTotal += metric;
                                movingList.add(metric);
                                if (movingList.size() > movingSize) {
                                    movingTotal -= movingList.get(0);
                                    movingList.remove(0);
                                }
                                double movingAverage = movingTotal / movingList.size();
                                dataset.addValue(movingAverage, dataType + "(Avg)", xLabel);
                            // System.out.println("moving average = "+movingAverage+", movingTotal="+movingTotal+", m");
                            }
                        }
                    }
                }
            }
        }
    }
    String chartTitle = title;
    if (multiStep) {
        chartTitle += " (" + dataChoices[dataIndices[0]] + ")";
    } else {
        chartTitle += " (" + selectedSteps[0] + ")";
    }
    final JFreeChart chart = // chart title
    ChartFactory.createLineChart(// chart title
    chartTitle, BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.TimeInSeconds.Label", Integer.toString(totalTimeInSeconds), // domain axis label
    Long.toString(timeDifference)), // range axis label
    BaseMessages.getString(PKG, "StepPerformanceSnapShotDialog.RowsPerSecond.Label"), // data
    dataset, // orientation
    PlotOrientation.VERTICAL, // include legend
    true, // tooltips
    true, // urls
    false);
    chart.setBackgroundPaint(Color.white);
    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.white);
    plot.setForegroundAlpha(0.5f);
    plot.setRangeGridlinesVisible(true);
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
    CategoryAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickLabelsVisible(false);
    // Customize the renderer...
    // 
    LineAndShapeRenderer renderer = (LineAndShapeRenderer) plot.getRenderer();
    renderer.setBaseShapesVisible(true);
    renderer.setDrawOutlines(true);
    renderer.setUseFillPaint(true);
    renderer.setBaseFillPaint(Color.white);
    renderer.setSeriesStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesOutlineStroke(0, new BasicStroke(1.5f));
    renderer.setSeriesStroke(1, new BasicStroke(2.5f));
    renderer.setSeriesOutlineStroke(1, new BasicStroke(2.5f));
    renderer.setSeriesShape(0, new Ellipse2D.Double(-3.0, -3.0, 6.0, 6.0));
    BufferedImage bufferedImage = chart.createBufferedImage(bounds.width, bounds.height);
    ImageData imageData = ImageUtil.convertToSWT(bufferedImage);
    // 
    if (image != null) {
        image.dispose();
    }
    image = new Image(display, imageData);
    // Draw the image on the canvas...
    // 
    canvas.redraw();
}
Also used : BasicStroke(java.awt.BasicStroke) LineAndShapeRenderer(org.jfree.chart.renderer.category.LineAndShapeRenderer) NumberAxis(org.jfree.chart.axis.NumberAxis) Rectangle(org.eclipse.swt.graphics.Rectangle) ArrayList(java.util.ArrayList) Image(org.eclipse.swt.graphics.Image) BufferedImage(java.awt.image.BufferedImage) JFreeChart(org.jfree.chart.JFreeChart) CategoryPlot(org.jfree.chart.plot.CategoryPlot) Ellipse2D(java.awt.geom.Ellipse2D) BufferedImage(java.awt.image.BufferedImage) CategoryAxis(org.jfree.chart.axis.CategoryAxis) ImageData(org.eclipse.swt.graphics.ImageData) DefaultCategoryDataset(org.jfree.data.category.DefaultCategoryDataset) StepPerformanceSnapShot(org.pentaho.di.trans.performance.StepPerformanceSnapShot)

Example 74 with BasicStroke

use of java.awt.BasicStroke in project archi by archimatetool.

the class GraphicsToGraphics2DAdaptor method initSVGGraphics.

/**
 * Create the SVG graphics object and initializes it with the current line
 * stlye and width
 */
private void initSVGGraphics(Graphics2D graphics) {
    this.graphics2D = graphics;
    relativeClipRegion = new Rectangle(viewBox.x, viewBox.y, viewBox.width, viewBox.height);
    // Initialize the line style and width
    stroke = new BasicStroke(swtGraphics.getLineWidth(), BasicStroke.CAP_SQUARE, BasicStroke.JOIN_ROUND, 0, null, 0);
    LineAttributes lineAttributes = new LineAttributes(1);
    swtGraphics.getLineAttributes(lineAttributes);
    setLineAttributes(lineAttributes);
    setFillRule(swtGraphics.getFillRule());
    setAdvanced(swtGraphics.getAdvanced());
    getGraphics2D().setStroke(stroke);
}
Also used : BasicStroke(java.awt.BasicStroke) Rectangle(org.eclipse.draw2d.geometry.Rectangle) LineAttributes(org.eclipse.swt.graphics.LineAttributes)

Example 75 with BasicStroke

use of java.awt.BasicStroke in project archi by archimatetool.

the class GraphicsToGraphics2DAdaptor method createStroke.

/**
 * Sets and retirns AWT Stroke based on the value of
 * <code>LineAttributes</code> within the current state object
 *
 * @return the new AWT stroke
 */
protected Stroke createStroke() {
    float factor = currentState.lineAttributes.width > 0 ? currentState.lineAttributes.width : 3;
    float[] awt_dash;
    int awt_cap;
    int awt_join;
    switch(currentState.lineAttributes.style) {
        case Graphics.LINE_DASH:
            awt_dash = new float[] { factor * 6, factor * 3 };
            break;
        case Graphics.LINE_DASHDOT:
            awt_dash = new float[] { factor * 3, factor, factor, factor };
            break;
        case Graphics.LINE_DASHDOTDOT:
            awt_dash = new float[] { factor * 3, factor, factor, factor, factor, factor };
            break;
        case Graphics.LINE_DOT:
            awt_dash = new float[] { factor, factor };
            break;
        case Graphics.LINE_CUSTOM:
            awt_dash = currentState.lineAttributes.dash;
            break;
        default:
            awt_dash = null;
    }
    switch(currentState.lineAttributes.cap) {
        case SWT.CAP_FLAT:
            awt_cap = BasicStroke.CAP_BUTT;
            break;
        case SWT.CAP_ROUND:
            awt_cap = BasicStroke.CAP_ROUND;
            break;
        case SWT.CAP_SQUARE:
            awt_cap = BasicStroke.CAP_SQUARE;
            break;
        default:
            awt_cap = BasicStroke.CAP_BUTT;
    }
    switch(currentState.lineAttributes.join) {
        case SWT.JOIN_BEVEL:
            awt_join = BasicStroke.JOIN_BEVEL;
            break;
        case SWT.JOIN_MITER:
            awt_join = BasicStroke.JOIN_MITER;
            break;
        case SWT.JOIN_ROUND:
            awt_join = BasicStroke.JOIN_ROUND;
            break;
        default:
            awt_join = BasicStroke.JOIN_MITER;
    }
    /*
         * SWT paints line width == 0 as if it is == 1, so AWT is synced up with
         * that below.
         */
    stroke = new BasicStroke(currentState.lineAttributes.width != 0 ? currentState.lineAttributes.width : 1, awt_cap, awt_join, currentState.lineAttributes.miterLimit, awt_dash, currentState.lineAttributes.dashOffset);
    return stroke;
}
Also used : BasicStroke(java.awt.BasicStroke) Point(org.eclipse.draw2d.geometry.Point) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint)

Aggregations

BasicStroke (java.awt.BasicStroke)571 Graphics2D (java.awt.Graphics2D)179 Color (java.awt.Color)164 Stroke (java.awt.Stroke)141 GradientPaint (java.awt.GradientPaint)96 Test (org.junit.Test)93 Rectangle2D (java.awt.geom.Rectangle2D)71 Paint (java.awt.Paint)64 Font (java.awt.Font)61 Point (java.awt.Point)47 Line2D (java.awt.geom.Line2D)47 BufferedImage (java.awt.image.BufferedImage)43 Shape (java.awt.Shape)39 Point2D (java.awt.geom.Point2D)38 AffineTransform (java.awt.geom.AffineTransform)34 JFreeChart (org.jfree.chart.JFreeChart)34 Rectangle (java.awt.Rectangle)27 Ellipse2D (java.awt.geom.Ellipse2D)27 RectangleInsets (org.jfree.ui.RectangleInsets)27 NumberAxis (org.jfree.chart.axis.NumberAxis)25