Search in sources :

Example 81 with Shape

use of java.awt.Shape in project processdash by dtuma.

the class RadarPlot method drawRadar.

protected void drawRadar(Graphics2D g2, Rectangle2D plotArea, PlotRenderingInfo info, int pieIndex, PieDataset data) {
    // 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;
    // 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);
    }
}
Also used : Shape(java.awt.Shape) GeneralPath(java.awt.geom.GeneralPath) Color(java.awt.Color) Rectangle2D(java.awt.geom.Rectangle2D) Paint(java.awt.Paint) Line2D(java.awt.geom.Line2D) Paint(java.awt.Paint) Iterator(java.util.Iterator) List(java.util.List)

Example 82 with Shape

use of java.awt.Shape in project processdash by dtuma.

the class HierarchyNoteIcon method paintIcon.

@Override
protected void paintIcon(Graphics2D g2, int width, int height, float scale) {
    // fill the background area and trace its outline
    Shape shape = new RoundRectangle2D.Float(0, 0, width - 1, height - 1, 5 * scale, 5 * scale);
    g2.setPaint(new GradientPaint(0, 0, fill, width, height, Color.white));
    g2.fill(shape);
    g2.setStroke(new BasicStroke(1));
    g2.setColor(edge);
    g2.draw(shape);
    // draw text in the center
    int x = (int) (2 * Math.min(scale, 2));
    int y = (int) (3 * scale);
    int lineSpacing = (int) (2.3 * scale);
    g2.setClip(new RoundRectangle2D.Float(x, x, width - 2 * x, height - 2 * x, 2 * scale, 2 * scale));
    g2.setFont(new Font("Dialog", Font.BOLD, 10).deriveFont(1.9f * scale));
    g2.setColor(text);
    String s = TEXT;
    while (y <= height - 2) {
        g2.drawString(s, x, y);
        s = s.substring(10);
        y += lineSpacing;
    }
}
Also used : BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape) RoundRectangle2D(java.awt.geom.RoundRectangle2D) GradientPaint(java.awt.GradientPaint) GradientPaint(java.awt.GradientPaint) Font(java.awt.Font)

Example 83 with Shape

use of java.awt.Shape in project processdash by dtuma.

the class RangeXYItemRenderer method drawItem.

/** Draws the visual representation of a single data item.
     */
@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);
    }
}
Also used : Stroke(java.awt.Stroke) BasicStroke(java.awt.BasicStroke) PlotOrientation(org.jfree.chart.plot.PlotOrientation) Shape(java.awt.Shape) EntityCollection(org.jfree.chart.entity.EntityCollection) Paint(java.awt.Paint) GradientPaint(java.awt.GradientPaint) RangeInfo(org.jfree.data.RangeInfo) RectangleEdge(org.jfree.ui.RectangleEdge)

Example 84 with Shape

use of java.awt.Shape in project processdash by dtuma.

the class PlayIcon method paintIcon.

@Override
protected void paintIcon(Graphics2D g2, int width, int height, float scale) {
    int pad = (int) (this.pad * width / (double) this.width);
    int left = pad;
    int right = width - pad - 1;
    int top = pad;
    int bottom = height - pad - 1;
    int mid = height / 2;
    // fill the background area
    Shape triangle = shape(left, top, left, bottom, right, mid);
    g2.setColor(fill);
    g2.setClip(triangle);
    g2.fill(triangle);
    // paint the glow, if applicable
    if (innerGlow != null) {
        g2.setColor(innerGlow);
        int cX = (left * 2 + right) / 3;
        for (int i = 8; i-- > 0; ) {
            int r = (int) (i * mid / 10f);
            g2.fillOval(cX - r, mid - r, r * 2 + 1, r * 2 + 1);
        }
    }
    // prepare to draw the beveled inset edges on the triangle
    float bevelWidth = 2 + (float) Math.pow(width - 17, 0.8) / 3f;
    g2.setStroke(new BasicStroke(bevelWidth));
    int bevX = (left + left + right) / 3;
    // draw the shadow for the top and left edges
    g2.setColor(shadow);
    g2.draw(triangle);
    // draw the highlight on the bottom edge
    g2.setColor(highlight);
    g2.setClip(shape(left - 1, bottom + 1, bevX, mid, right + 1, mid));
    g2.draw(triangle);
}
Also used : BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape)

Example 85 with Shape

use of java.awt.Shape in project processdash by dtuma.

the class ExpandAllIcon method paintIcon.

@Override
protected void paintIcon(Graphics2D g2, int width, int height, float scale) {
    g2.setStroke(new BasicStroke(1));
    // calculate the size of the icon and various features
    int plusSize = width / 2;
    int leg = (int) (0.7 + plusSize / 3f);
    int body = plusSize - 2 * leg;
    // calculate the shape of a single plus sign
    int a = 0, b = leg, c = leg + body, d = plusSize;
    Shape shape = shape(//
    b, //
    a, //
    c, //
    a, //
    c, //
    b, //
    d, //
    b, //
    d, //
    c, //
    c, //
    c, //
    c, //
    d, //
    b, //
    d, b, c, a, c, a, b, b, b);
    // draw the top-left plus sign
    g2.setColor(fill);
    g2.fill(shape);
    g2.setColor(edge);
    g2.draw(shape);
    // draw the bottom-right plus sign
    g2.translate(plusSize - 1, c);
    g2.setColor(fill);
    g2.fill(shape);
    g2.setColor(edge);
    g2.draw(shape);
}
Also used : BasicStroke(java.awt.BasicStroke) Shape(java.awt.Shape)

Aggregations

Shape (java.awt.Shape)85 AffineTransform (java.awt.geom.AffineTransform)21 BasicStroke (java.awt.BasicStroke)20 Graphics2D (java.awt.Graphics2D)19 Rectangle (java.awt.Rectangle)13 Stroke (java.awt.Stroke)11 Color (java.awt.Color)10 Rectangle2D (java.awt.geom.Rectangle2D)10 BufferedImage (java.awt.image.BufferedImage)9 Paint (android.graphics.Paint)6 LayoutlibDelegate (com.android.tools.layoutlib.annotations.LayoutlibDelegate)6 Composite (java.awt.Composite)6 TextLayout (java.awt.font.TextLayout)6 Area (java.awt.geom.Area)6 Point2D (java.awt.geom.Point2D)6 Font (java.awt.Font)5 FontMetrics (java.awt.FontMetrics)5 Paint (java.awt.Paint)5 Point (java.awt.Point)5 Test (org.junit.Test)5