Example usage for java.awt Graphics2D setStroke

List of usage examples for java.awt Graphics2D setStroke

Introduction

In this page you can find the example usage for java.awt Graphics2D setStroke.

Prototype

public abstract void setStroke(Stroke s);

Source Link

Document

Sets the Stroke for the Graphics2D context.

Usage

From source file:net.sourceforge.processdash.ev.ui.chart.RangeXYItemRenderer.java

/** Draws the visual representation of a single data item.
 */// w w  w. j  av  a  2  s .  c  o m
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int item,
        CrosshairState crosshairInfo, int pass) {

    // setup for collecting optional entity info...
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }
    Shape entityArea = null;

    Paint paint = getItemPaint(series, item);
    Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    // get the data point...
    Number x1n = dataset.getX(series, item);
    Number y1n = dataset.getY(series, item);
    if (y1n == null || x1n == null) {
        return;
    }

    double x1 = x1n.doubleValue();
    double y1 = y1n.doubleValue();
    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);
    PlotOrientation orientation = plot.getOrientation();

    if (item > 0) {
        // get the previous data point...
        Number x0n = dataset.getX(series, item - 1);
        Number y0n = dataset.getY(series, item - 1);
        if (y0n != null && x0n != null) {
            double x0 = x0n.doubleValue();
            double y0 = y0n.doubleValue();

            double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
            double transY0 = rangeAxis.valueToJava2D(y0, dataArea, yAxisLocation);

            // only draw if we have good values
            if (Double.isNaN(transX0) || Double.isNaN(transY0) || Double.isNaN(transX1)
                    || Double.isNaN(transY1)) {
                return;
            }

            if (orientation == PlotOrientation.HORIZONTAL) {
                line.setLine(transY0, transX0, transY1, transX1);
            } else if (orientation == PlotOrientation.VERTICAL) {
                line.setLine(transX0, transY0, transX1, transY1);
            }

            if (y1n instanceof RangeInfo) {
                RangeInfo y1r = (RangeInfo) y1n;
                double transY1low = rangeAxis.valueToJava2D(y1r.getRangeLowerBound(false), dataArea,
                        yAxisLocation);
                double transY1high = rangeAxis.valueToJava2D(y1r.getRangeUpperBound(false), dataArea,
                        yAxisLocation);
                drawItemRangeGradient(g2, line, paint, seriesStroke, transX1, transY1low, transX1, transY1high);

            } else if (x1n instanceof RangeInfo) {
                RangeInfo x1r = (RangeInfo) x1n;
                double transX1low = domainAxis.valueToJava2D(x1r.getRangeLowerBound(false), dataArea,
                        xAxisLocation);
                double transX1high = domainAxis.valueToJava2D(x1r.getRangeUpperBound(false), dataArea,
                        xAxisLocation);
                drawItemRangeGradient(g2, line, paint, seriesStroke, transX1low, transY1, transX1high, transY1);

            } else if (line.intersects(dataArea)) {
                g2.draw(line);
            }
        }
    } else if (dataset.getItemCount(series) == 1) {
        Shape shape = getItemShape(series, item);
        if (orientation == PlotOrientation.HORIZONTAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transY1, transX1);
        } else if (orientation == PlotOrientation.VERTICAL) {
            shape = ShapeUtilities.createTranslatedShape(shape, transX1, transY1);
        }
        if (shape.intersects(dataArea)) {
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;
    }

    if (entities != null && (dataArea.contains(transX1, transY1) || entityArea != null)) {
        addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
    }

}

From source file:net.sf.fspdfs.chartthemes.spring.ScaledDialRange.java

/**
 * Draws the range.//from  w  w  w .  j  a v a 2 s  .c o m
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame (in Java2D space).
 * @param view  the dial's view rectangle (in Java2D space).
 */
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, this.getInnerRadius(), this.getInnerRadius());
    Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, this.getOuterRadius(), this.getOuterRadius());

    DialScale scale = plot.getScale(this.getScaleIndex());
    if (scale == null) {
        throw new RuntimeException("No scale for scaleIndex = " + this.getScaleIndex());
    }
    double angleMin = scale.valueToAngle(this.getLowerBound());
    double angleMax = scale.valueToAngle(this.getUpperBound());

    Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, angleMax - angleMin, Arc2D.OPEN);
    Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, angleMin - angleMax, Arc2D.OPEN);

    g2.setPaint(this.getPaint());
    g2.setStroke(new BasicStroke(this.lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    g2.draw(arcInner);
    g2.draw(arcOuter);
}

From source file:net.sf.jasperreports.chartthemes.spring.ScaledDialRange.java

/**
 * Draws the range./*w  w  w  .ja  va 2  s.  c  om*/
 * 
 * @param g2  the graphics target.
 * @param plot  the plot.
 * @param frame  the dial's reference frame (in Java2D space).
 * @param view  the dial's view rectangle (in Java2D space).
 */
@Override
public void draw(Graphics2D g2, DialPlot plot, Rectangle2D frame, Rectangle2D view) {

    Rectangle2D arcRectInner = DialPlot.rectangleByRadius(frame, this.getInnerRadius(), this.getInnerRadius());
    Rectangle2D arcRectOuter = DialPlot.rectangleByRadius(frame, this.getOuterRadius(), this.getOuterRadius());

    DialScale scale = plot.getScale(this.getScaleIndex());
    if (scale == null) {
        throw new RuntimeException("No scale for scaleIndex = " + this.getScaleIndex());
    }
    double angleMin = scale.valueToAngle(this.getLowerBound());
    double angleMax = scale.valueToAngle(this.getUpperBound());

    Arc2D arcInner = new Arc2D.Double(arcRectInner, angleMin, angleMax - angleMin, Arc2D.OPEN);
    Arc2D arcOuter = new Arc2D.Double(arcRectOuter, angleMax, angleMin - angleMax, Arc2D.OPEN);

    g2.setPaint(this.getPaint());
    g2.setStroke(new BasicStroke(this.lineWidth, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER));
    g2.draw(arcInner);
    g2.draw(arcOuter);
}

From source file:gda.plots.TurboXYItemRenderer.java

/**
 * Draws the visual representation of a single data item. This mostly reproduces the code of StandardXYItemRenderer
 * but using the line by line information stored in the SimpleXYSeries instead of the series indexed information
 * stored in the Renderer itself./* w ww . j a  v  a  2s.c o  m*/
 * 
 * @param g2
 *            the graphics device.
 * @param state
 *            the renderer state.
 * @param dataArea
 *            the area within which the data is being drawn.
 * @param info
 *            collects information about the drawing.
 * @param plot
 *            the plot (can be used to obtain standard color information etc).
 * @param domainAxis
 *            the domain axis.
 * @param rangeAxis
 *            the range axis.
 * @param dataset
 *            the dataset.
 * @param series
 *            the series index (zero-based).
 * @param crosshairState
 *            crosshair information for the plot ( <code>null</code> permitted).
 * @param pass
 *            the pass index.
 */
@Override
public void drawItem(Graphics2D g2, XYItemRendererState state, Rectangle2D dataArea, PlotRenderingInfo info,
        XYPlot plot, ValueAxis domainAxis, ValueAxis rangeAxis, XYDataset dataset, int series, int _item,
        CrosshairState crosshairState, int pass) {

    if (_item > 0)
        return;
    SimpleXYSeries sxys = (SimpleXYSeries) ((SimpleXYSeriesCollection) dataset).getSeries(series);
    if (!sxys.isVisible()) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    g2.setPaint(sxys.getPaint());
    g2.setStroke(sxys.getStroke());

    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();

    try {
        int x0 = -1; // the x position in pixels of the previous point
        int y0 = -1; // the y position in pixels of the previous point
        int x1 = -1; // the x position in pixels of the current point
        int y1 = -1; // the y position in pixels of the current point
        int xmin = (int) dataArea.getMinX();
        int xmax = (int) dataArea.getMaxX();
        int ymin = (int) dataArea.getMinY();
        int ymax = (int) dataArea.getMaxY();
        GeneralPath path = null;

        /*
         * To remove the time spent repeatedly calling domainAxis.valueToJava2D for linear axes use simple linear
         * maths
         */
        double xl = 0., mx = Double.NaN, cx = 0.;
        if (domainAxis instanceof SimpleNumberAxis) {
            xl = domainAxis.getRange().getLowerBound();
            mx = dataArea.getWidth() / (domainAxis.getRange().getUpperBound() - xl);
            cx = xmin;
        }
        double yl = 0., my = Double.NaN, cy = 0.;
        if (rangeAxis instanceof SimpleNumberAxis) {
            yl = rangeAxis.getRange().getLowerBound();
            my = -dataArea.getHeight() / (rangeAxis.getRange().getUpperBound() - yl);
            cy = ymax;
        }
        List<XYDataItem> list = sxys.getData();

        boolean MX_MY_NaN = Double.isNaN(mx) || Double.isNaN(my);
        Paint paint = sxys.getPaint();
        Stroke stroke = sxys.getStroke();
        Paint paint_symbol = sxys.getSymbolPaint();
        Stroke stroke_symbol = new BasicStroke();
        drawLines = sxys.isDrawLines();
        boolean filled = sxys.getFilled();
        Shape shape = sxys.getSymbol();
        boolean drawMarkers = sxys.isDrawMarkers() & shape != null;
        int tooltipThresholdCounts = -1; /* number of points to be shown below which markers are also to be drawn */
        if (drawLines && drawMarkers && shape != null && tooltipThreshold != 0) {
            Rectangle shapeBoundingBox = shape.getBounds();
            tooltipThresholdCounts = (int) dataArea.getWidth()
                    / (Math.max(1, shapeBoundingBox.width) * tooltipThreshold);
        }

        java.util.Vector<ddouble> markerPositions = null;
        Shape entityArea = null;
        EntityCollection entities = null;
        if (info != null) {
            entities = info.getOwner().getEntityCollection();
        }
        boolean prevLineAdded = false;
        // In case the iterator does not work then use the TODO comment iterator use and why not always
        // comment variables
        synchronized (list) {
            Iterator<XYDataItem> iter = list.iterator();
            /*
             * loop over all points calculating X1 and Y1. Store previous points positions into X0 and Y0 The
             * variable addThis determines if the current point is to be added to the path If previous line was
             * added that the current must be even if off the screen - but in this case the flag prevLineAdded is
             * set false so that the next does not have to be added.
             */
            for (int item = 0; iter.hasNext(); item++, x0 = x1, y0 = y1, x1 = -1, y1 = -1) {
                XYDataItem dataitem = iter.next();
                double x = dataitem.getX().doubleValue();
                double y = dataitem.getY().doubleValue();
                x = xValueTransformer.transformValue(x);

                x1 = MX_MY_NaN ? (int) domainAxis.valueToJava2D(x, dataArea, xAxisLocation)
                        : (int) ((x - xl) * mx + cx);
                y1 = MX_MY_NaN ? (int) rangeAxis.valueToJava2D(y, dataArea, yAxisLocation)
                        : (int) ((y - yl) * my + cy);

                boolean addThis = true;
                if (item == 0) {
                    x0 = x1;
                    y0 = y1;
                    if ((x1 < xmin) || (x1 > xmax) || (y1 < ymin) || (y1 > ymax)) {
                        addThis = false;
                    }
                } else {
                    if (x1 == x0 && y1 == y0) {
                        addThis = false;
                    }
                    if ((x1 < xmin && x0 < xmin) || (x1 > xmax && x0 > xmax) || (y1 < ymin && y0 < ymin)
                            || (y1 > ymax && y0 > ymax)) {
                        if (prevLineAdded) {
                            path = addPointToLine(path, orientation, x1, y1);
                        }
                        addThis = false;
                    }
                }
                if (addThis) {
                    /*
                     * If the current point is to be added then ensure previous one is as well to prevent lines
                     * not crossing the edge of the screen
                     */
                    if (!prevLineAdded) {
                        path = addPointToLine(path, orientation, x0, y0);
                    }
                    path = addPointToLine(path, orientation, x1, y1);
                    prevLineAdded = true;
                }
                prevLineAdded = addThis;
                if (addThis && drawMarkers) {
                    if (markerPositions == null) {
                        markerPositions = new java.util.Vector<ddouble>();
                    }
                    markerPositions.add(new ddouble(item, x1, y1));
                    if (tooltipThresholdCounts != -1 && markerPositions.size() > tooltipThresholdCounts) {
                        drawMarkers = false;
                        markerPositions = null;
                    }
                }
            }
            if (path != null) {
                g2.setStroke(stroke);
                g2.setPaint(paint);
                g2.draw(path);
            }
            if (markerPositions != null) {
                if (drawMarkers) {
                    g2.setPaint(paint_symbol);
                    g2.setStroke(stroke_symbol);
                    for (ddouble dd : markerPositions) {
                        Shape shape_item = ShapeUtilities.createTranslatedShape(shape, dd.x, dd.y);
                        if (filled) {
                            g2.fill(shape_item);
                        } else {
                            g2.draw(shape_item);
                        }
                        entityArea = shape_item;
                        // add an entity for the item...
                        if (entities != null) {
                            addEntity(entities, entityArea, dataset, series, dd.item, dd.x, dd.y);
                        }
                    }
                    g2.setPaint(paint);
                    g2.setStroke(stroke);
                }
            }
        }

    } catch (Exception e) {
        e.printStackTrace();
    }

}

From source file:org.tellervo.desktop.graph.SkeletonPlot.java

public void draw(GraphSettings gInfo, Graphics2D g2, int bottom, Graph g, int thickness, int xscroll) {
    // cache yearsize, we use this a lot
    int yearWidth = gInfo.getYearWidth(); // the size of a year, in pixels
    float unitScale = gInfo.getHundredUnitHeight() / 100.0f; // the size of 1 "unit" in pixels.

    // set pen//  w  w  w .ja  v a  2  s .co  m
    boolean dotted = (gInfo.isDottedIndexes() && (g.graph instanceof Index));
    g2.setStroke(makeStroke(thickness, dotted));

    // If it's a chronology, point bones down
    /*if(g.graph instanceof Sample)
    {
       if (((Sample) g.graph).getSeries() instanceof TridasDerivedSeries)
       {
    this.areBonesBelowLine = true;
       }
    }*/

    // left/right
    int l = g2.getClipBounds().x;
    int r = l + g2.getClipBounds().width;

    // no data?  stop.
    if (g.graph.getRingWidthData().isEmpty())
        return;

    // compare g.getClipBounds() to [x,0]..[x+yearSize*data.size(),bottom]
    tempRect.x = yearWidth * (g.graph.getStart().diff(gInfo.getDrawBounds().getStart()) + g.xoffset); // REDUNDANT! see x later
    tempRect.y = 0; // - g.yoffset, IF you're sure there are no negative values (but there are)
    tempRect.width = yearWidth * (g.graph.getRingWidthData().size() - 1);
    tempRect.height = bottom;
    // TODO: compute top/bottom as min/max?
    // REFACTOR: will this be obsolete with the start/end stuff below?
    if (!tempRect.intersects(g2.getClipBounds())) {
        // skip this graph, it's off the screen
        return;
    }

    // Draw standard line
    int x = yearWidth * (g.graph.getStart().diff(gInfo.getDrawBounds().getStart()) + g.xoffset);
    //int value1 = yTransform((float) getMeanValue(g));
    int value1 = yTransform((float) baselineY);
    int baseYVal = bottom - (int) (value1 * unitScale) - (int) (g.yoffset * unitScale);

    try {
        // x-position
        int x1 = x;
        int x2 = yearWidth * (g.graph.getStart().diff(gInfo.getDrawBounds().getStart()) + g.xoffset
                + g.graph.getRingWidthData().size());

        // if we're past the end, draw only as far as we need
        if (x2 > r + yearWidth) {
            x2 = r + yearWidth;
        }

        //log.debug("Drawing mean line: "+x1+", "+meanYVal+", "+x2+", "+meanYVal);
        g2.drawLine(x1, baseYVal, x2, baseYVal);

        // Calcs for start/end triangles
        int YLineHeight = 50;
        int YTriangleHeight = 25;
        int XTriangleWidth = 15;
        if (areBonesBelowLine) {
            YLineHeight = -50;
            YTriangleHeight = -25;
        }

        // Draw start triangle
        g2.drawLine(x1, baseYVal, x1, baseYVal - YTriangleHeight);
        g2.drawLine(x1, baseYVal, x1 - XTriangleWidth, baseYVal - YTriangleHeight);
        g2.drawLine(x1 - XTriangleWidth, baseYVal - YTriangleHeight, x1, baseYVal - YTriangleHeight);
        g2.drawLine(x1, baseYVal, x1, baseYVal - YLineHeight);

        // Draw end triangle
        g2.drawLine(x2, baseYVal, x2, baseYVal - YTriangleHeight);
        g2.drawLine(x2, baseYVal, x2 + XTriangleWidth, baseYVal - YTriangleHeight);
        g2.drawLine(x2 + XTriangleWidth, baseYVal - YTriangleHeight, x2, baseYVal - YTriangleHeight);
        g2.drawLine(x2, baseYVal, x2, baseYVal - YLineHeight);

    } catch (ClassCastException cce) {

    }

    int value;
    try {
        value = ((Number) g.graph.getRingWidthData().get(0)).intValue();
        value = yTransform(value * g.scale);
    } catch (ClassCastException cce) {
        value = yTransform(0);
    }

    int n = g.graph.getRingWidthData().size();

    for (int i = 1; i < n; i++) {
        // new x-position for this point
        x += yearWidth;

        // if we're past the end, draw what we've got, and say goodbye
        // (go +_yearsize so the line going off the screen is visible)
        if (x > r + yearWidth) {
            break;
        }

        // Extract the window of interest
        int ringsEitherSideOfFocus = (App.prefs.getIntPref(PrefKey.STATS_SKELETON_PLOT_WINDOW_SIZE, 7) - 1) / 2;

        // Convert to ArrayList first as its easier to handle
        ArrayList<Double> ringWidths = new ArrayList<Double>();
        for (int z = 0; z < n; z++) {
            ringWidths.add((double) g.graph.getRingWidthData().get(z).intValue());
        }

        int firstind = i - 1 - ringsEitherSideOfFocus;
        int lastind = i + ringsEitherSideOfFocus;
        if (firstind < 0)
            firstind = 0;
        if (lastind > n)
            lastind = n;
        int size = lastind - firstind;

        double[] window = new double[size];

        int t = 0;
        for (int w = firstind; w < lastind; w++) {
            window[t] = ringWidths.get(w);
            t++;
        }

        DescriptiveStatistics windowStats = new DescriptiveStatistics(window);
        /*if(i<7 ) 
        {
           log.debug("Stats for ring: "+i);
           try{
              log.debug("  Window 0: "+window[0]);
              log.debug("  Window 1: "+window[1]);
              log.debug("  Window 2: "+window[2]);
              log.debug("  Window 3: "+window[3]);
              log.debug("  Window 4: "+window[4]);
              log.debug("  Window 5: "+window[5]);
              log.debug("  Window 6: "+window[6]);
           } catch (ArrayIndexOutOfBoundsException e){}
           log.debug("  Mean  is "+i+" - "+(int) windowStats.getMean());
           log.debug("  Min   is "+i+" - "+(int) windowStats.getMin());
           log.debug("  Std   is "+i+" - "+(int) windowStats.getStandardDeviation());
           log.debug("  Std/2 is "+i+" - "+(int) windowStats.getStandardDeviation()/2);
        }*/

        // y-position for this point
        try {
            value = yTransform(((Number) g.graph.getRingWidthData().get(i)).intValue() * g.scale);
        } catch (ClassCastException cce) {
            value = yTransform(0); // e.g., if it's being edited, it's still a string
            // BAD!  instead: (1) draw what i've got so far, and (2) NEXT point is a move-to.
            // -- try to parse String as an integer?
        }
        int y = bottom - (int) (value * unitScale) - (int) (g.yoffset * unitScale);

        // Calculate skeleton category
        Integer skeletonCateogory = null;

        String prefAlg = App.prefs.getPref(PrefKey.STATS_SKELETON_PLOT_ALGORITHM,
                SkeletonPlotAlgorithm.PERCENTILES.toString());

        if (prefAlg.equals(SkeletonPlotAlgorithm.PERCENTILES.toString())) {
            skeletonCateogory = getSkeletonCategoryFromPercentiles(value, windowStats);
        } else if (prefAlg.equals(SkeletonPlotAlgorithm.CROPPER1979_0POINT5.toString())) {
            skeletonCateogory = getSkeletonCategoryFromCropper1979(value, windowStats, 0.5);
        } else if (prefAlg.equals(SkeletonPlotAlgorithm.CROPPER1979_0POINT75.toString())) {
            skeletonCateogory = getSkeletonCategoryFromCropper1979(value, windowStats, 0.75);
        }

        // Draw the skeleton line
        if (areBonesBelowLine) {
            g2.drawLine(x, baseYVal, x, baseYVal + (skeletonCateogory * 5));
        } else {
            g2.drawLine(x, baseYVal, x, baseYVal - (skeletonCateogory * 5));
        }

        // Try and paint remark icons
        try {
            List<TridasRemark> remarks = g.graph.getTridasValues().get(i).getRemarks();

            if (areBonesBelowLine) {
                Graph.drawRemarkIcons(g2, gInfo, remarks, g.graph.getTridasValues().get(i), x, baseYVal, false);
            } else {
                Graph.drawRemarkIcons(g2, gInfo, remarks, g.graph.getTridasValues().get(i), x, baseYVal, true);
            }

        } catch (Exception e) {
            log.error("Exception drawing icons to graph: " + e.getClass());
        }

    }
}

From source file:edu.csun.ecs.cs.multitouchj.application.whiteboard.ui.InteractiveCanvas.java

protected void drawPoints() {
    synchronized (previousPoints) {
        synchronized (resizableBufferedImage) {
            // clear points for pen if it's been long since last changed
            long currentTime = new Date().getTime();
            for (int id : pens.keySet()) {
                if (previousTimes.containsKey(id)) {
                    long time = previousTimes.get(id);
                    if ((currentTime - time) > POINT_CLEAR_DURATION) {
                        previousPoints.remove(id);
                        previousTimes.remove(id);
                    }/* w  w  w  .  j ava 2  s  .co  m*/
                }
            }

            DisplayMode displayMode = getWindowManager().getDisplayManager().getCurrentDisplayMode();
            BufferedImage bufferedImage = resizableBufferedImage.getBufferedImage();

            Graphics2D graphics = bufferedImage.createGraphics();
            for (int id : pens.keySet()) {
                Pen pen = pens.get(id);
                LinkedList<Point> points = previousPoints.get(id);
                if ((pen != null) && (points != null) && (points.size() > 1)) {
                    log.debug("id: " + id + ", points: " + points.size());

                    Point previousPoint = points.removeFirst();
                    Iterator<Point> iterator = points.iterator();
                    while (iterator.hasNext()) {
                        Point point = iterator.next();
                        if (iterator.hasNext()) {
                            iterator.remove();
                        }

                        graphics.setStroke(pen.getStroke());
                        graphics.setPaint(pen.getPaint());
                        graphics.drawLine((int) Math.floor(previousPoint.getX()),
                                (displayMode.getHeight() - (int) Math.floor(previousPoint.getY())),
                                (int) Math.floor(point.getX()),
                                (displayMode.getHeight() - (int) Math.floor(point.getY())));

                        previousPoint = point;
                    }

                    setDirty(true);
                }
            }
            graphics.dispose();
        }
    }
}

From source file:org.openfaces.component.chart.impl.renderers.XYLineFillRenderer.java

private void drawItemShape(Graphics2D g2, int series, int item, Shape entityShape) {
    if (getItemShapeFilled(series, item)) {
        g2.setPaint(getUseFillPaint() ? getItemFillPaint(series, item) : getItemPaint(series, item));
        g2.fill(entityShape);/* ww  w . j  a  va 2  s  . com*/
    }

    if (getDrawOutlines()) {
        g2.setPaint(getUseOutlinePaint() ? getItemOutlinePaint(series, item) : getItemPaint(series, item));
        g2.setStroke(getItemOutlineStroke(series, item));
    }

    g2.draw(entityShape);
}

From source file:TextLayoutWithCarets.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    g2.setRenderingHint(RenderingHints.KEY_FRACTIONALMETRICS, RenderingHints.VALUE_FRACTIONALMETRICS_ON);

    if (mInitialized == false)
        initialize(g2);/*  w  w w  . j  av  a 2 s .c  om*/

    float x = 20, y = 80;
    mLayout.draw(g2, x, y);

    // Create a plain stroke and a dashed stroke.
    Stroke[] caretStrokes = new Stroke[2];
    caretStrokes[0] = new BasicStroke();
    caretStrokes[1] = new BasicStroke(1, BasicStroke.CAP_BUTT, BasicStroke.JOIN_ROUND, 0, new float[] { 4, 4 },
            0);

    // Now draw the carets
    Shape[] carets = mLayout.getCaretShapes(mHit.getInsertionIndex());
    for (int i = 0; i < carets.length; i++) {
        if (carets[i] != null) {
            AffineTransform at = AffineTransform.getTranslateInstance(x, y);
            Shape shape = at.createTransformedShape(carets[i]);
            g2.setStroke(caretStrokes[i]);
            g2.draw(shape);
        }
    }
}

From source file:com.rapidminer.gui.plotter.charts.RapidXYBarPainter.java

@Override
public void paintBar(Graphics2D g2, XYBarRenderer renderer, int row, int column, RectangularShape bar,
        RectangleEdge base) {//from ww w. ja  va  2s .c o m
    Paint itemPaint = renderer.getItemPaint(row, column);

    Color c0 = null;

    if (itemPaint instanceof Color) {
        c0 = (Color) itemPaint;
    } else {
        c0 = SwingTools.DARK_BLUE;
    }

    // as a special case, if the bar color has alpha == 0, we draw
    // nothing.
    if (c0.getAlpha() == 0) {
        return;
    }

    g2.setPaint(c0);
    g2.fill(new Rectangle2D.Double(bar.getMinX(), bar.getMinY(), bar.getWidth(), bar.getHeight()));

    // draw the outline...
    if (renderer.isDrawBarOutline()) {
        Stroke stroke = renderer.getItemOutlineStroke(row, column);
        Paint paint = renderer.getItemOutlinePaint(row, column);
        if (stroke != null && paint != null) {
            g2.setStroke(stroke);
            g2.setPaint(paint);
            g2.draw(bar);
        }
    }
}

From source file:org.pentaho.reporting.engine.classic.core.layout.output.RenderUtility.java

public static DefaultImageReference createImageFromDrawable(final DrawableWrapper drawable,
        final StrictBounds rect, final StyleSheet box, final OutputProcessorMetaData metaData) {
    final int imageWidth = (int) StrictGeomUtility.toExternalValue(rect.getWidth());
    final int imageHeight = (int) StrictGeomUtility.toExternalValue(rect.getHeight());

    if (imageWidth == 0 || imageHeight == 0) {
        return null;
    }//w w  w. j a  va 2s . co  m

    final double scale = RenderUtility.getNormalizationScale(metaData);
    final Image image = ImageUtils.createTransparentImage((int) (imageWidth * scale),
            (int) (imageHeight * scale));
    final Graphics2D g2 = (Graphics2D) image.getGraphics();

    final Object attribute = box.getStyleProperty(ElementStyleKeys.ANTI_ALIASING);
    if (attribute != null) {
        if (Boolean.TRUE.equals(attribute)) {
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        } else if (Boolean.FALSE.equals(attribute)) {
            g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_OFF);
        }

    }
    if (RenderUtility.isFontSmooth(box, metaData)) {
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    } else {
        g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_OFF);
    }

    g2.scale(scale, scale);
    // the clipping bounds are a sub-area of the whole drawable
    // we only want to print a certain area ...

    final String fontName = (String) box.getStyleProperty(TextStyleKeys.FONT);
    final int fontSize = box.getIntStyleProperty(TextStyleKeys.FONTSIZE, 8);
    final boolean bold = box.getBooleanStyleProperty(TextStyleKeys.BOLD);
    final boolean italics = box.getBooleanStyleProperty(TextStyleKeys.ITALIC);
    if (bold && italics) {
        g2.setFont(new Font(fontName, Font.BOLD | Font.ITALIC, fontSize));
    } else if (bold) {
        g2.setFont(new Font(fontName, Font.BOLD, fontSize));
    } else if (italics) {
        g2.setFont(new Font(fontName, Font.ITALIC, fontSize));
    } else {
        g2.setFont(new Font(fontName, Font.PLAIN, fontSize));
    }

    g2.setStroke((Stroke) box.getStyleProperty(ElementStyleKeys.STROKE));
    g2.setPaint((Paint) box.getStyleProperty(ElementStyleKeys.PAINT));

    drawable.draw(g2, new Rectangle2D.Double(0, 0, imageWidth, imageHeight));
    g2.dispose();

    try {
        return new DefaultImageReference(image);
    } catch (final IOException e1) {
        logger.warn("Unable to fully load a given image. (It should not happen here.)", e1);
        return null;
    }
}