Example usage for java.awt.geom GeneralPath createTransformedShape

List of usage examples for java.awt.geom GeneralPath createTransformedShape

Introduction

In this page you can find the example usage for java.awt.geom GeneralPath createTransformedShape.

Prototype

public final synchronized Shape createTransformedShape(AffineTransform at) 

Source Link

Document

Returns a new Shape representing a transformed version of this Path2D .

Usage

From source file:Utils.java

public static Shape generatePolygon(int sides, int outsideRadius, int insideRadius, boolean normalize) {
    Shape shape = generatePolygon(sides, outsideRadius, insideRadius);
    if (normalize) {
        Rectangle2D bounds = shape.getBounds2D();
        GeneralPath path = new GeneralPath(shape);
        shape = path
                .createTransformedShape(AffineTransform.getTranslateInstance(-bounds.getX(), -bounds.getY()));
    }//from   w w w .  java 2s .  co  m
    return shape;
}

From source file:edu.gmu.cs.sim.util.media.chart.ScatterPlotSeriesAttributes.java

static Shape[] buildShapes() {
    Shape[] s = new Shape[7];
    GeneralPath g = null;

    // Circle/*  w w w  .  ja v a 2s . c om*/
    s[0] = new Ellipse2D.Double(-3, -3, 6, 6);

    // Rectangle
    Rectangle2D.Double r = new Rectangle2D.Double(-3, -3, 6, 6);
    s[1] = r;

    // Diamond
    s[2] = AffineTransform.getRotateInstance(Math.PI / 4.0).createTransformedShape(r);

    // Cross +
    g = new GeneralPath();
    g.moveTo(-0.5f, -3);
    g.lineTo(-0.5f, -0.5f);
    g.lineTo(-3, -0.5f);
    g.lineTo(-3, 0.5f);
    g.lineTo(-0.5f, 0.5f);
    g.lineTo(-0.5f, 3);
    g.lineTo(0.5f, 3);
    g.lineTo(0.5f, 0.5f);
    g.lineTo(3, 0.5f);
    g.lineTo(3, -0.5f);
    g.lineTo(0.5f, -0.5f);
    g.lineTo(0.5f, -3);
    g.closePath();
    s[3] = g;

    // X 
    s[4] = g.createTransformedShape(AffineTransform.getRotateInstance(Math.PI / 4.0));

    // Up Triangle
    g = new GeneralPath();
    g.moveTo(0f, -3);
    g.lineTo(-3, 3);
    g.lineTo(3, 3);
    g.closePath();
    s[5] = g;

    // Down Triangle
    s[6] = g.createTransformedShape(AffineTransform.getRotateInstance(Math.PI));

    return s;
}

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

protected void drawRadar(Graphics2D g2, Rectangle2D plotArea, PlotRenderingInfo info, int pieIndex,
        PieDataset data) {//  w  w w  .  ja  va 2  s.com

    // adjust the plot area by the interior spacing value
    double gapHorizontal = plotArea.getWidth() * this.interiorGap;
    double gapVertical = plotArea.getHeight() * this.interiorGap;
    double radarX = plotArea.getX() + gapHorizontal / 2;
    double radarY = plotArea.getY() + gapVertical / 2;
    double radarW = plotArea.getWidth() - gapHorizontal;
    double radarH = plotArea.getHeight() - gapVertical;

    // make the radar area a square if the radar chart is to be circular...
    // NOTE that non-circular radar charts are not currently supported.
    if (true) { //circular) {
        double min = Math.min(radarW, radarH) / 2;
        radarX = (radarX + radarX + radarW) / 2 - min;
        radarY = (radarY + radarY + radarH) / 2 - min;
        radarW = 2 * min;
        radarH = 2 * min;
    }

    double radius = radarW / 2;
    double centerX = radarX + radarW / 2;
    double centerY = radarY + radarH / 2;

    Rectangle2D radarArea = new Rectangle2D.Double(radarX, radarY, radarW, radarH);

    // plot the data (unless the dataset is null)...
    if ((data != null) && (data.getKeys().size() > 0)) {

        // get a list of categories...
        List keys = data.getKeys();
        int numAxes = keys.size();

        // draw each of the axes on the radar chart, and register
        // the shape of the radar line.

        double multiplier = 1.0;
        GeneralPath lineShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1);
        GeneralPath gridShape = new GeneralPath(GeneralPath.WIND_NON_ZERO, numAxes + 1);

        int axisNumber = -1;
        Iterator iterator = keys.iterator();
        while (iterator.hasNext()) {
            Comparable currentKey = (Comparable) iterator.next();
            axisNumber++;
            Number dataValue = data.getValue(currentKey);

            double value = (dataValue != null ? dataValue.doubleValue() : 0);
            if (value > 1 || Double.isNaN(value) || Double.isInfinite(value))
                value = 1.0;
            if (value < 0)
                value = 0.0;
            multiplier *= value;

            double angle = 2 * Math.PI * axisNumber / numAxes;
            double deltaX = Math.sin(angle) * radius;
            double deltaY = -Math.cos(angle) * radius;

            // draw the spoke
            g2.setPaint(axisPaint);
            g2.setStroke(axisStroke);
            Line2D line = new Line2D.Double(centerX, centerY, centerX + deltaX, centerY + deltaY);
            g2.draw(line);

            // register the grid line and the shape line
            if (axisNumber == 0) {
                gridShape.moveTo((float) deltaX, (float) deltaY);
                lineShape.moveTo((float) (deltaX * value), (float) (deltaY * value));
            } else {
                gridShape.lineTo((float) deltaX, (float) deltaY);
                lineShape.lineTo((float) (deltaX * value), (float) (deltaY * value));
            }

            if (showAxisLabels) {
                // draw the label
                double labelX = centerX + deltaX * (1 + axisLabelGap);
                double labelY = centerY + deltaY * (1 + axisLabelGap);
                String label = currentKey.toString();
                drawLabel(g2, radarArea, label, axisNumber, labelX, labelY);
            }

        }
        gridShape.closePath();
        lineShape.closePath();

        // draw five gray concentric gridlines
        g2.translate(centerX, centerY);
        g2.setPaint(gridLinePaint);
        g2.setStroke(gridLineStroke);
        for (int i = 5; i > 0; i--) {
            Shape scaledGrid = gridShape
                    .createTransformedShape(AffineTransform.getScaleInstance(i / 5.0, i / 5.0));
            g2.draw(scaledGrid);
        }

        // get the color for the plot shape.
        Paint dataPaint = plotLinePaint;
        if (dataPaint == ADAPTIVE_COLORING) {
            //multiplier = Math.exp(Math.log(multiplier) * 2 / numAxes);
            dataPaint = getMultiplierColor((float) multiplier);
        }

        // compute a slightly transparent version of the plot color for
        // the fill.
        Paint dataFill = null;
        if (dataPaint instanceof Color && getForegroundAlpha() != 1.0)
            dataFill = new Color(((Color) dataPaint).getRed() / 255f, ((Color) dataPaint).getGreen() / 255f,
                    ((Color) dataPaint).getBlue() / 255f, getForegroundAlpha());
        else
            dataFill = dataPaint;

        // draw the plot shape.  First fill with a parially
        // transparent color, then stroke with the opaque color.
        g2.setPaint(dataFill);
        g2.fill(lineShape);
        g2.setPaint(dataPaint);
        g2.setStroke(plotLineStroke);
        g2.draw(lineShape);

        // cleanup the graphics context.
        g2.translate(-centerX, -centerY);
    }
}