Example usage for java.awt Graphics2D setPaint

List of usage examples for java.awt Graphics2D setPaint

Introduction

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

Prototype

public abstract void setPaint(Paint paint);

Source Link

Document

Sets the Paint attribute for the Graphics2D context.

Usage

From source file:msi.gama.outputs.layers.charts.FastXYItemRenderer.java

/** {@inheritDoc} */
@Override/*w w w.  j  a va 2s.  c o m*/
public void drawItem(final Graphics2D g2, final XYItemRendererState state, final Rectangle2D dataArea,
        final PlotRenderingInfo info, final XYPlot plot, final ValueAxis domainAxis, final ValueAxis rangeAxis,
        final XYDataset dataset, final int series, final int item, final CrosshairState crosshairState,
        final int pass) {

    if (!getItemVisible(series, item)) {
        return;
    }
    // setup for collecting optional entity info...
    boolean bAddEntity = false;
    Shape entityArea = null;
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }

    final PlotOrientation orientation = plot.getOrientation();
    final Paint paint = getItemPaint(series, item);
    final Stroke seriesStroke = getItemStroke(series, item);
    g2.setPaint(paint);
    g2.setStroke(seriesStroke);

    // get the data point...
    final double x1 = dataset.getXValue(series, item);
    final double y1 = dataset.getYValue(series, item);
    if (Double.isNaN(x1) || Double.isNaN(y1)) {
        return;
    }

    final RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    final RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    final double transX1 = domainAxis.valueToJava2D(x1, dataArea, xAxisLocation);
    final double transY1 = rangeAxis.valueToJava2D(y1, dataArea, yAxisLocation);

    if (getPlotLines()) {
        if (item == 0) {
            if (this.drawSeriesLineAsPath) {
                final State s = (State) state;
                s.seriesPath.reset();
                s.lastPointGood = false;
            }
            previousDrawnItem = 0;
        }

        if (this.drawSeriesLineAsPath) {
            final State s = (State) state;
            // update path to reflect latest point
            if (!Double.isNaN(transX1) && !Double.isNaN(transY1)) {
                float x = (float) transX1;
                float y = (float) transY1;
                if (orientation == PlotOrientation.HORIZONTAL) {
                    x = (float) transY1;
                    y = (float) transX1;
                }
                if (s.isLastPointGood()) {
                    // TODO: check threshold
                    s.seriesPath.lineTo(x, y);
                } else {
                    s.seriesPath.moveTo(x, y);
                }
                s.setLastPointGood(true);
            } else {
                s.setLastPointGood(false);
            }
            if (item == dataset.getItemCount(series) - 1) {
                // draw path
                g2.setStroke(getSeriesStroke(series));
                g2.setPaint(getSeriesPaint(series));
                g2.draw(s.seriesPath);
            }
        }

        else if (item != 0) {
            // get the previous data point...
            final double x0 = dataset.getXValue(series, item - previousDrawnItem);
            final double y0 = dataset.getYValue(series, item - previousDrawnItem);
            if (!Double.isNaN(x0) && !Double.isNaN(y0)) {
                boolean drawLine = true;
                if (getPlotDiscontinuous()) {
                    // only draw a line if the gap between the current and
                    // previous data point is within the threshold
                    final int numX = dataset.getItemCount(series);
                    final double minX = dataset.getXValue(series, 0);
                    final double maxX = dataset.getXValue(series, numX - 1);
                    if (this.gapThresholdType == UnitType.ABSOLUTE) {
                        drawLine = Math.abs(x1 - x0) <= this.gapThreshold;
                    } else {
                        drawLine = Math.abs(x1 - x0) <= (maxX - minX) / numX * getGapThreshold();
                    }
                }
                if (drawLine) {
                    final double transX0 = domainAxis.valueToJava2D(x0, dataArea, xAxisLocation);
                    final 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;
                    }

                    // Only draw line if it is more than a pixel away from the previous one
                    if (transX1 - transX0 > 2 || transX1 - transX0 < -2 || transY1 - transY0 > 2
                            || transY1 - transY0 < -2 || 0 == previousDrawnItem) {
                        previousDrawnItem = 1;

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

                        if (state.workingLine.intersects(dataArea)) {
                            g2.draw(state.workingLine);
                        }
                    } else {
                        // Increase counter for the previous drawn item.
                        previousDrawnItem++;
                        bAddEntity = false;
                    }
                }
            }
        }
    }

    if (getBaseShapesVisible()) {

        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)) {
            bAddEntity = true;
            if (getItemShapeFilled(series, item)) {
                g2.fill(shape);
            } else {
                g2.draw(shape);
            }
        }
        entityArea = shape;

    }

    if (getPlotImages()) {
        final Image image = getImage(plot, series, item, transX1, transY1);
        if (image != null) {
            final Point hotspot = getImageHotspot(plot, series, item, transX1, transY1, image);
            g2.drawImage(image, (int) (transX1 - hotspot.getX()), (int) (transY1 - hotspot.getY()), null);
            entityArea = new Rectangle2D.Double(transX1 - hotspot.getX(), transY1 - hotspot.getY(),
                    image.getWidth(null), image.getHeight(null));
        }

    }

    // draw the item label if there is one...
    if (isItemLabelVisible(series, item)) {
        double xx = transX1;
        double yy = transY1;
        if (orientation == PlotOrientation.HORIZONTAL) {
            xx = transY1;
            yy = transX1;
        }
        drawItemLabel(g2, orientation, dataset, series, item, xx, yy, y1 < 0.0);
    }

    updateCrosshairValues(crosshairState, x1, y1, transX1, transY1, orientation);

    // add an entity for the item...
    if (entities != null && bAddEntity) {
        addEntity(entities, entityArea, dataset, series, item, transX1, transY1);
    }
}

From source file:at.tuwien.ifs.somtoolbox.visualization.ClusterConnectionsVisualizer.java

@Override
public BufferedImage createVisualization(int variantIndex, GrowingSOM gsom, int width, int height)
        throws SOMToolboxException {
    GrowingLayer layer = gsom.getLayer();
    BufferedImage image = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
    Graphics2D g = image.createGraphics();

    g.setBackground(Color.WHITE);
    g.clearRect(0, 0, width, height);/*from  w w w .  ja  v a  2s.  c  om*/

    // need to calculate some params relative to the unit width/height, which is relative to the desired output size
    // a unitWidth/Height of 10, as used previously, works by default only fine in the SOMViewer
    int somWidth = layer.getXSize();
    int somHeight = layer.getYSize();
    double unitWidth = width / somWidth;
    double unitHeight = height / somHeight;

    DoubleMatrix2D unitDistanceMatrix = gsom.getLayer().getUnitDistanceMatrix();

    for (int col = 0; col < somWidth; col++) {
        for (int row = 0; row < somHeight; row++) {

            if (col < somWidth - 1) {
                // draw horizontal connection
                double distanceRight = unitDistanceMatrix.get(layer.getUnitIndex(col, row),
                        layer.getUnitIndex(col + 1, row));
                g.setPaint(getColor(distanceRight));
                int xPos = (int) (col * unitHeight + unitHeight * 0.7);
                int yPos = (int) (row * unitWidth + unitWidth * 0.4);
                g.fillRect(xPos, yPos, (int) (unitWidth * 0.6), (int) (unitHeight * 0.2));
            }

            if (row < somHeight - 1) {
                // draw vertical connection
                double distanceLower = unitDistanceMatrix.get(layer.getUnitIndex(col, row),
                        layer.getUnitIndex(col, row + 1));
                g.setPaint(getColor(distanceLower));

                int xPos = (int) (col * unitHeight + unitHeight * 0.4);
                int yPos = (int) (row * unitWidth + unitWidth * 0.7);
                g.fillRect(xPos, yPos, (int) (unitWidth * 0.2), (int) (unitHeight * 0.6));
            }
        }
    }

    return image;
}

From source file:org.apache.fop.svg.AbstractFOPTextPainter.java

/**
 * Paint a single text run on the Graphics2D at a given location.
 * @param run the text run to paint// w  w w.  j  a v  a  2 s . c om
 * @param g2d the Graphics2D to paint to
 * @param loc the current location of the "cursor"
 * @return the new location of the "cursor" after painting the text run
 */
protected Point2D paintTextRun(StrokingTextPainter.TextRun run, Graphics2D g2d, Point2D loc) {
    AttributedCharacterIterator aci = run.getACI();
    aci.first();

    updateLocationFromACI(aci, loc);
    AffineTransform at = g2d.getTransform();
    loc = at.transform(loc, null);

    // font
    Font font = getFont(aci);
    if (font != null) {
        nativeTextHandler.setOverrideFont(font);
    }

    // color
    TextPaintInfo tpi = (TextPaintInfo) aci
            .getAttribute(GVTAttributedCharacterIterator.TextAttribute.PAINT_INFO);
    if (tpi == null) {
        return loc;
    }
    Paint foreground = tpi.fillPaint;
    if (foreground instanceof Color) {
        Color col = (Color) foreground;
        g2d.setColor(col);
    }
    g2d.setPaint(foreground);

    // text anchor
    TextNode.Anchor anchor = (TextNode.Anchor) aci
            .getAttribute(GVTAttributedCharacterIterator.TextAttribute.ANCHOR_TYPE);

    // text
    String txt = getText(aci);
    float advance = getStringWidth(txt, font);
    float tx = 0;
    if (anchor != null) {
        switch (anchor.getType()) {
        case TextNode.Anchor.ANCHOR_MIDDLE:
            tx = -advance / 2;
            break;
        case TextNode.Anchor.ANCHOR_END:
            tx = -advance;
            break;
        default: //nop
        }
    }

    // draw string
    double x = loc.getX();
    double y = loc.getY();
    try {
        try {
            nativeTextHandler.drawString(g2d, txt, (float) x + tx, (float) y);
        } catch (IOException ioe) {
            if (g2d instanceof AFPGraphics2D) {
                ((AFPGraphics2D) g2d).handleIOException(ioe);
            }
        }
    } finally {
        nativeTextHandler.setOverrideFont(null);
    }
    loc.setLocation(loc.getX() + advance, loc.getY());
    return loc;
}

From source file:com.lfx.web.WebChartXYPlot.java

/**
 * Draws the gridlines for the plot's primary range axis, if they are
 * visible./*w ww  . j a va2  s . com*/
 *
 * @param g2  the graphics device.
 * @param area  the data area.
 * @param ticks  the ticks.
 *
 * @see #drawDomainGridlines(Graphics2D, Rectangle2D, List)
 */
protected void drawDomainGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {
    Composite oldcomp = g2.getComposite();
    Paint bandPaint = getBackgroundPaint();
    if (bandPaint != null && bandPaint instanceof java.awt.Color) {
        g2.setComposite(AlphaComposite.SrcIn);
        java.awt.Color bandcolor = (java.awt.Color) (bandPaint);
        boolean fillBand = true;
        ValueAxis axis = getDomainAxis();
        double previous = axis.getLowerBound();
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            ValueTick tick = (ValueTick) iterator.next();
            if (!tick.getTickType().equals(TickType.MAJOR))
                continue;
            double current = tick.getValue();
            double y1 = axis.valueToJava2D(previous, dataArea, getDomainAxisEdge());
            double y2 = axis.valueToJava2D(current, dataArea, getDomainAxisEdge());
            Rectangle2D band = new Rectangle2D.Double(y1, dataArea.getMinY(), y2 - y1, dataArea.getWidth());
            if (fillBand)
                g2.setPaint(bandcolor);
            else
                g2.setPaint(bandcolor.darker());
            g2.fill(band);
            previous = current;
            fillBand = !fillBand;
        }
        double end = axis.getUpperBound();
        double y1 = axis.valueToJava2D(previous, dataArea, getDomainAxisEdge());
        double y2 = axis.valueToJava2D(end, dataArea, getDomainAxisEdge());
        Rectangle2D band = new Rectangle2D.Double(y1, dataArea.getMinY(), y2 - y1, dataArea.getWidth());
        if (fillBand)
            g2.setPaint(bandcolor);
        else
            g2.setPaint(bandcolor.darker());
        g2.fill(band);
    } else {
        super.drawDomainGridlines(g2, dataArea, ticks);
    }
    g2.setComposite(oldcomp);
}

From source file:com.lfx.web.WebChartXYPlot.java

/**
  * Draws the gridlines for the plot, if they are visible.
  */*from   www.  ja v a  2  s.c o m*/
  * @param g2  the graphics device.
  * @param dataArea  the data area.
  * @param ticks  the ticks.
  *
  * @see #drawRangeGridlines(Graphics2D, Rectangle2D, List)
  */

protected void drawRangeGridlines(Graphics2D g2, Rectangle2D dataArea, List ticks) {
    Composite oldcomp = g2.getComposite();
    Paint bandPaint = getBackgroundPaint();
    if (bandPaint != null && bandPaint instanceof java.awt.Color) {
        // g2.setComposite(AlphaComposite.SrcO);
        java.awt.Color bandcolor = (java.awt.Color) (bandPaint);
        boolean fillBand = false;
        ValueAxis axis = getRangeAxis();
        double previous = axis.getLowerBound();
        Iterator iterator = ticks.iterator();
        while (iterator.hasNext()) {
            ValueTick tick = (ValueTick) iterator.next();
            if (!tick.getTickType().equals(TickType.MAJOR))
                continue;
            double current = tick.getValue();
            double y1 = axis.valueToJava2D(previous, dataArea, getRangeAxisEdge());
            double y2 = axis.valueToJava2D(current, dataArea, getRangeAxisEdge());
            Rectangle2D band = new Rectangle2D.Double(dataArea.getMinX(), y2, dataArea.getWidth(), y1 - y2);
            if (fillBand)
                g2.setPaint(bandcolor);
            else
                g2.setPaint(bandcolor.darker());
            g2.fill(band);
            previous = current;
            fillBand = !fillBand;
        }
        double end = axis.getUpperBound();
        double y1 = axis.valueToJava2D(previous, dataArea, getRangeAxisEdge());
        double y2 = axis.valueToJava2D(end, dataArea, getRangeAxisEdge());
        Rectangle2D band = new Rectangle2D.Double(dataArea.getMinX(), y2, dataArea.getWidth(), y1 - y2);
        if (fillBand)
            g2.setPaint(bandcolor);
        else
            g2.setPaint(bandcolor.darker());
        g2.fill(band);
    } else {
        super.drawRangeGridlines(g2, dataArea, ticks);
    }
    g2.setComposite(oldcomp);
}

From source file:edu.jhuapl.graphs.jfreechart.utils.SparselyLabeledCategoryAxis.java

@SuppressWarnings("unchecked")
@Override//from ww w.ja  v a2 s .co m
public void drawTickMarks(Graphics2D g2, double cursor, Rectangle2D dataArea, RectangleEdge edge,
        AxisState state) {
    Plot p = getPlot();

    if (p == null) {
        return;
    }

    CategoryPlot plot = (CategoryPlot) p;
    double il = getTickMarkInsideLength();
    double ol = getTickMarkOutsideLength();
    Line2D line = new Line2D.Double();
    List categories = plot.getCategoriesForAxis(this);
    int tickEvery = categories.size() / (maxLabeledTicks == 0 ? 1 : maxLabeledTicks);

    if (tickEvery < 1) {
        tickEvery = 1;
    }

    if (edge.equals(RectangleEdge.TOP)) {
        Iterator iterator = categories.iterator();
        int i = 0;

        while (iterator.hasNext()) {
            Comparable key = (Comparable) iterator.next();

            if (i % tickEvery == 0) {
                double x = getCategoryMiddle(key, categories, dataArea, edge);
                g2.setPaint(getTickMarkPaint());
                g2.setStroke(getTickMarkStroke());
                line.setLine(x, cursor, x, cursor + il);
                g2.draw(line);
                line.setLine(x, cursor, x, cursor - ol);
                g2.draw(line);

                if (domainGridlinePaint != null) {
                    drawDomainGridline(g2, plot, dataArea, x);
                }
            }

            i++;
        }

        state.cursorUp(ol);
    } else if (edge.equals(RectangleEdge.BOTTOM)) {
        Iterator iterator = categories.iterator();
        int i = 0;

        while (iterator.hasNext()) {
            Comparable key = (Comparable) iterator.next();

            if (i % tickEvery == 0) {
                double x = getCategoryMiddle(key, categories, dataArea, edge);
                g2.setPaint(getTickMarkPaint());
                g2.setStroke(getTickMarkStroke());
                line.setLine(x, cursor, x, cursor - il);
                g2.draw(line);
                line.setLine(x, cursor, x, cursor + ol);
                g2.draw(line);

                if (domainGridlinePaint != null) {
                    drawDomainGridline(g2, plot, dataArea, x);
                }
            }

            i++;
        }

        state.cursorDown(ol);
    } else if (edge.equals(RectangleEdge.LEFT)) {
        Iterator iterator = categories.iterator();
        int i = 0;

        while (iterator.hasNext()) {
            Comparable key = (Comparable) iterator.next();

            if (i % tickEvery == 0) {
                double y = getCategoryMiddle(key, categories, dataArea, edge);
                g2.setPaint(getTickMarkPaint());
                g2.setStroke(getTickMarkStroke());
                line.setLine(cursor, y, cursor + il, y);
                g2.draw(line);
                line.setLine(cursor, y, cursor - ol, y);
                g2.draw(line);

                if (domainGridlinePaint != null) {
                    drawDomainGridline(g2, plot, dataArea, y);
                }
            }

            i++;
        }

        state.cursorLeft(ol);
    } else if (edge.equals(RectangleEdge.RIGHT)) {
        Iterator iterator = categories.iterator();
        int i = 0;

        while (iterator.hasNext()) {
            Comparable key = (Comparable) iterator.next();

            if (i % tickEvery == 0) {
                double y = getCategoryMiddle(key, categories, dataArea, edge);
                g2.setPaint(getTickMarkPaint());
                g2.setStroke(getTickMarkStroke());
                line.setLine(cursor, y, cursor - il, y);
                g2.draw(line);
                line.setLine(cursor, y, cursor + ol, y);
                g2.draw(line);

                if (domainGridlinePaint != null) {
                    drawDomainGridline(g2, plot, dataArea, y);
                }
            }

            i++;
        }

        state.cursorRight(ol);
    }
}

From source file:business.ImageManager.java

public ImageIcon getArrow(double angle) {
    BufferedImage img = new BufferedImage(40, 40, BufferedImage.TRANSLUCENT);
    Graphics2D big = img.createGraphics();
    //setup para os rastros
    big.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    big.setStroke(//from w  ww .ja v  a  2 s. c o  m
            new BasicStroke(2f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_ROUND, 1f, new float[] { 5f }, 0f));
    big.setColor(Color.red);

    int cx = this.getYellowBall().getIconWidth() / 2;
    int cy = this.getYellowBall().getIconHeight() / 2;
    AffineTransform at = AffineTransform.getTranslateInstance(cx, cy);
    at.rotate(Math.toRadians(angle));
    //        at.scale(2.0, 2.0);
    Shape shape = at.createTransformedShape(createArrow());
    big.setPaint(Color.red);
    big.draw(shape);
    ImageIcon ret = new ImageIcon(img);
    return (ret);
    //        tenta com o icone...angle.
}

From source file:ste.travian.world.TileRenderer.java

/**
 * Draws the visual representation of a single data item.
 *
 * @param g2  the graphics device.// w w  w. jav  a2 s.  co m
 * @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 (horizontal) axis.
 * @param rangeAxis  the range (vertical) axis.
 * @param dataset  the dataset.
 * @param series  the series index (zero-based).
 * @param item  the item index (zero-based).
 * @param crosshairState  crosshair information for the plot 
 *                        (<code>null</code> permitted).
 * @param pass  the pass index.
 */
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) {

    // get the data point...
    double x = dataset.getXValue(series, item);
    double y = dataset.getYValue(series, item);
    double adjx = (this.dotWidth - 1) / 2.0;
    double adjy = (this.dotHeight - 1) / 2.0;
    if (Double.isNaN(y)) {
        return;
    }

    PlotOrientation orientation = plot.getOrientation();
    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
    double transX = domainAxis.valueToJava2D(x, dataArea, xAxisLocation) - adjx;
    double transY = rangeAxis.valueToJava2D(y, dataArea, yAxisLocation) - adjy;

    g2.setPaint(getItemPaint(series, item));
    if (orientation == PlotOrientation.HORIZONTAL) {
        g2.fillRect((int) transY, (int) transX, this.dotHeight, this.dotWidth);
    } else if (orientation == PlotOrientation.VERTICAL) {
        g2.fillRect((int) transX, (int) transY, this.dotWidth, this.dotHeight);
    }

    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
    updateCrosshairValues(crosshairState, x, y, domainAxisIndex, rangeAxisIndex, transX, transY, orientation);

    // add an entity for the item, but only if it falls within the data
    // area...
    EntityCollection entities = null;
    if (info != null) {
        entities = info.getOwner().getEntityCollection();
    }
    int xx = (int) transX;
    int yy = (int) transY;
    if (orientation == PlotOrientation.HORIZONTAL) {
        xx = (int) transY;
        yy = (int) transX;
    }
    if (entities != null && dataArea.contains(xx, yy)) {
        addEntity(entities, null, dataset, series, item, (int) xx, (int) yy);
    }

}

From source file:ucar.unidata.idv.control.chart.MyTimeSeriesPlot.java

/**
 * draw/*  ww w  . ja  v  a  2  s.  c o m*/
 *
 * @param g2 the graphics
 * @param dataArea where the data area is
 * @param index which data set
 * @param info info
 * @param crosshairState crosshairState
 *
 * @return any drawn
 */
public boolean render(Graphics2D g2, Rectangle2D dataArea, int index, PlotRenderingInfo info,
        CrosshairState crosshairState) {

    XYDataset dataset = getDataset(index);
    if (DatasetUtilities.isEmptyOrNull(dataset)) {
        return false;
    }

    ValueAxis rangeAxis = getRangeAxisForDataset(index);
    ValueAxis domainAxis = getDomainAxisForDataset(index);
    AxisLocation rangeAxisLocation = getRangeAxisLocation(index);
    AxisLocation domainAxisLocation = getDomainAxisLocation(index);
    RectangleEdge rangeEdge = getRangeAxisEdge();
    RectangleEdge domainEdge = getDomainAxisEdge();
    int seriesCount = dataset.getSeriesCount();
    //        System.out.println ("********************************");
    for (int series = seriesCount - 1; series >= 0; series--) {
        int itemCount = dataset.getItemCount(series);
        int[] xs = new int[itemCount];
        int[] ys = new int[itemCount];
        g2.setStroke(getRendererForDataset(dataset).getSeriesStroke(series));
        g2.setPaint(getRendererForDataset(dataset).getSeriesPaint(series));
        int pointCnt = 0;
        for (int item = 0; item < itemCount; item++) {
            double x1 = dataset.getXValue(series, item);
            double y1 = dataset.getYValue(series, item);
            if (!timeseries.valuesOk(index, x1, y1)) {
                if (pointCnt > 0) {
                    g2.drawPolyline(xs, ys, pointCnt);
                    pointCnt = 0;
                }
                continue;
            }
            double transX = domainAxis.valueToJava2D(x1, dataArea, domainEdge);
            double transY = rangeAxis.valueToJava2D(y1, dataArea, rangeEdge);
            if (!dataArea.contains(transX, transY)) {
                continue;
            }

            xs[pointCnt] = (int) (transX + 0.5);
            ys[pointCnt] = (int) (transY + 0.5);
            pointCnt++;
            if (pointCnt > 10) {
                g2.drawPolyline(xs, ys, pointCnt);
                xs[0] = xs[pointCnt - 1];
                ys[0] = ys[pointCnt - 1];
                pointCnt = 1;
            }

        }
        if (pointCnt > 1) {
            g2.drawPolyline(xs, ys, pointCnt);
        }
        long t2 = System.currentTimeMillis();
        //            System.err.println("time:" + (t2 - t1) + "ms #" + itemCount);
    }
    return true;
}

From source file:net.sourceforge.processdash.ui.web.reports.RadarPlot.java

/**
 * Draws the label for one radar axis./*from  w w w  .  j a  v  a  2s.  c om*/
 *
 * @param g2 The graphics device.
 * @param chartArea The area for the radar chart.
 * @param data The data for the plot.
 * @param axis The axis (zero-based index).
 * @param startAngle The starting angle.
 */
protected void drawLabel(Graphics2D g2, Rectangle2D chartArea, String label, int axis, double labelX,
        double labelY) {

    // handle label drawing...
    FontRenderContext frc = g2.getFontRenderContext();
    Rectangle2D labelBounds = this.axisLabelFont.getStringBounds(label, frc);
    LineMetrics lm = this.axisLabelFont.getLineMetrics(label, frc);
    double ascent = lm.getAscent();

    if (labelX == chartArea.getCenterX())
        labelX -= labelBounds.getWidth() / 2;
    else if (labelX < chartArea.getCenterX())
        labelX -= labelBounds.getWidth();
    if (labelY > chartArea.getCenterY())
        labelY += ascent;

    g2.setPaint(this.axisLabelPaint);
    g2.setFont(this.axisLabelFont);
    g2.drawString(label, (float) labelX, (float) labelY);
}