Example usage for java.awt.geom Arc2D PIE

List of usage examples for java.awt.geom Arc2D PIE

Introduction

In this page you can find the example usage for java.awt.geom Arc2D PIE.

Prototype

int PIE

To view the source code for java.awt.geom Arc2D PIE.

Click Source Link

Document

The closure type for an arc closed by drawing straight line segments from the start of the arc segment to the center of the full ellipse and from that point to the end of the arc segment.

Usage

From source file:Main.java

public void paint(Graphics g) {
    Graphics2D g2 = (Graphics2D) g;
    int w = getSize().width;
    int h = getSize().height;

    Arc2D arc = new Arc2D.Double(0.0, 0.5, w, h, 0.0, 60.0, Arc2D.CHORD);
    System.out.println(arc.getPathIterator(AffineTransform.getQuadrantRotateInstance(5)));
    g2.draw(arc);/*from w  w  w  .jav a 2s  . co m*/

    arc = new Arc2D.Float(0.0f, 0.0f, w, h, 80.0f, 110.0f, Arc2D.PIE);

    g2.fill(arc);

    arc = new Arc2D.Float(0.0f, 0.0f, w, h, 210.0f, 130.0f, Arc2D.OPEN);

    g2.draw(arc);
}

From source file:DrawingApplet.java

public Shape createWedge(double x, double y, double w, double h, double start, double extent) {
    return new Arc2D.Double(x, y, w, h, start, extent, Arc2D.PIE);
}

From source file:ClipImage.java

public void drawDemo(Graphics2D g2) {
    if (newBufferedImage) {
        x = Math.random() * w;/*  w w w .  j  a va  2s .c o  m*/
        y = Math.random() * h;
        ew = (Math.random() * w) / 2;
        eh = (Math.random() * h) / 2;
    }
    x += ix;
    y += iy;
    ew += iw;
    eh += ih;
    if (ew > w / 2) {
        ew = w / 2;
        iw = Math.random() * -w / 16 - 1;
    }
    if (ew < w / 8) {
        ew = w / 8;
        iw = Math.random() * w / 16 + 1;
    }
    if (eh > h / 2) {
        eh = h / 2;
        ih = Math.random() * -h / 16 - 1;
    }
    if (eh < h / 8) {
        eh = h / 8;
        ih = Math.random() * h / 16 + 1;
    }
    if ((x + ew) > w) {
        x = (w - ew) - 1;
        ix = Math.random() * -w / 32 - 1;
    }
    if (x < 0) {
        x = 2;
        ix = Math.random() * w / 32 + 1;
    }
    if ((y + eh) > h) {
        y = (h - eh) - 2;
        iy = Math.random() * -h / 32 - 1;
    }
    if (y < 0) {
        y = 2;
        iy = Math.random() * h / 32 + 1;
    }

    ellipse.setFrame(x, y, ew, eh);
    g2.setClip(ellipse);

    rect.setRect(x + 5, y + 5, ew - 10, eh - 10);
    g2.clip(rect);

    g2.drawImage(img, 0, 0, w, h, this);

    p.reset();
    p.moveTo(-w / 2.0f, -h / 8.0f);
    p.lineTo(+w / 2.0f, -h / 8.0f);
    p.lineTo(-w / 4.0f, +h / 2.0f);
    p.lineTo(+0.0f, -h / 2.0f);
    p.lineTo(+w / 4.0f, +h / 2.0f);
    p.closePath();

    at.setToIdentity();
    at.translate(w * .5f, h * .5f);
    g2.transform(at);
    g2.setStroke(bs);
    g2.setPaint(redBlend);
    g2.draw(p);

    at.setToIdentity();
    g2.setTransform(at);

    g2.setPaint(greenBlend);

    for (int yy = 0; yy < h; yy += 50) {
        for (int xx = 0, i = 0; xx < w; i++, xx += 50) {
            switch (i) {
            case 0:
                arc.setArc(xx, yy, 25, 25, 45, 270, Arc2D.PIE);
                g2.fill(arc);
                break;
            case 1:
                ellipse.setFrame(xx, yy, 25, 25);
                g2.fill(ellipse);
                break;
            case 2:
                roundRect.setRoundRect(xx, yy, 25, 25, 4, 4);
                g2.fill(roundRect);
                break;
            case 3:
                rect.setRect(xx, yy, 25, 25);
                g2.fill(rect);
                i = -1;
            }

        }
    }
}

From source file:ClipImage.java

public void drawDemo(Graphics2D g2) {

    if (newBufferedImage) {
        x = Math.random() * w;/*from  w  w  w  . j a va  2s .  c  om*/
        y = Math.random() * h;
        ew = (Math.random() * w) / 2;
        eh = (Math.random() * h) / 2;
    }
    x += ix;
    y += iy;
    ew += iw;
    eh += ih;
    if (ew > w / 2) {
        ew = w / 2;
        iw = Math.random() * -w / 16 - 1;
    }
    if (ew < w / 8) {
        ew = w / 8;
        iw = Math.random() * w / 16 + 1;
    }
    if (eh > h / 2) {
        eh = h / 2;
        ih = Math.random() * -h / 16 - 1;
    }
    if (eh < h / 8) {
        eh = h / 8;
        ih = Math.random() * h / 16 + 1;
    }
    if ((x + ew) > w) {
        x = (w - ew) - 1;
        ix = Math.random() * -w / 32 - 1;
    }
    if (x < 0) {
        x = 2;
        ix = Math.random() * w / 32 + 1;
    }
    if ((y + eh) > h) {
        y = (h - eh) - 2;
        iy = Math.random() * -h / 32 - 1;
    }
    if (y < 0) {
        y = 2;
        iy = Math.random() * h / 32 + 1;
    }

    ellipse.setFrame(x, y, ew, eh);
    g2.setClip(ellipse);

    rect.setRect(x + 5, y + 5, ew - 10, eh - 10);
    g2.clip(rect);

    g2.drawImage(img, 0, 0, w, h, this);

    p.reset();
    p.moveTo(-w / 2.0f, -h / 8.0f);
    p.lineTo(+w / 2.0f, -h / 8.0f);
    p.lineTo(-w / 4.0f, +h / 2.0f);
    p.lineTo(+0.0f, -h / 2.0f);
    p.lineTo(+w / 4.0f, +h / 2.0f);
    p.closePath();

    at.setToIdentity();
    at.translate(w * .5f, h * .5f);
    g2.transform(at);
    g2.setStroke(bs);
    g2.setPaint(redBlend);
    g2.draw(p);

    at.setToIdentity();
    g2.setTransform(at);

    g2.setPaint(greenBlend);

    for (int yy = 0; yy < h; yy += 50) {
        for (int xx = 0, i = 0; xx < w; i++, xx += 50) {
            switch (i) {
            case 0:
                arc.setArc(xx, yy, 25, 25, 45, 270, Arc2D.PIE);
                g2.fill(arc);
                break;
            case 1:
                ellipse.setFrame(xx, yy, 25, 25);
                g2.fill(ellipse);
                break;
            case 2:
                roundRect.setRoundRect(xx, yy, 25, 25, 4, 4);
                g2.fill(roundRect);
                break;
            case 3:
                rect.setRect(xx, yy, 25, 25);
                g2.fill(rect);
                i = -1;
            }

        }
    }
}

From source file:com.piketec.jenkins.plugins.tpt.publisher.PieChart.java

private Arc2D paintPieSegment(Graphics2D g2, double startRatio, double endRatio, double radius,
        Color fillColor) {/*from w w  w.j a  v  a  2  s.  c o m*/
    Arc2D pie = new Arc2D.Double(Arc2D.PIE);
    double startAngle = 90 - 360 * startRatio; // top (= north)
    double endAngle = -360 * endRatio; // mit dem Uhrzeigersinn
    pie.setArcByCenter(centerX, centerY, radius, startAngle, endAngle, Arc2D.PIE);
    g2.setColor(fillColor);
    g2.fill(pie);
    return pie;
}

From source file:DefaultGraphics2D.java

/**
 * Fills a circular or elliptical arc covering the specified rectangle.
 * <p>/*from  ww w.  j  a  v a 2s  .  com*/
 * The resulting arc begins at <code>startAngle</code> and extends for
 * <code>arcAngle</code> degrees. Angles are interpreted such that
 * 0&nbsp;degrees is at the 3&nbsp;o'clock position. A positive value
 * indicates a counter-clockwise rotation while a negative value indicates a
 * clockwise rotation.
 * <p>
 * The center of the arc is the center of the rectangle whose origin is (<i>x</i>,&nbsp;<i>y</i>)
 * and whose size is specified by the <code>width</code> and
 * <code>height</code> arguments.
 * <p>
 * The resulting arc covers an area <code>width&nbsp;+&nbsp;1</code> pixels
 * wide by <code>height&nbsp;+&nbsp;1</code> pixels tall.
 * <p>
 * The angles are specified relative to the non-square extents of the bounding
 * rectangle such that 45 degrees always falls on the line from the center of
 * the ellipse to the upper right corner of the bounding rectangle. As a
 * result, if the bounding rectangle is noticeably longer in one axis than the
 * other, the angles to the start and end of the arc segment will be skewed
 * farther along the longer axis of the bounds.
 * 
 * @param x
 *          the <i>x</i> coordinate of the upper-left corner of the arc to be
 *          filled.
 * @param y
 *          the <i>y</i> coordinate of the upper-left corner of the arc to be
 *          filled.
 * @param width
 *          the width of the arc to be filled.
 * @param height
 *          the height of the arc to be filled.
 * @param startAngle
 *          the beginning angle.
 * @param arcAngle
 *          the angular extent of the arc, relative to the start angle.
 * @see java.awt.Graphics#drawArc
 */
public void fillArc(int x, int y, int width, int height, int startAngle, int arcAngle) {
    Arc2D arc = new Arc2D.Float(x, y, width, height, startAngle, arcAngle, Arc2D.PIE);
    fill(arc);
}

From source file:org.deeplearning4j.examples.multigpu.video.VideoGenerator.java

private static int[] generateVideo(String path, int nFrames, int width, int height, int numShapes, Random r,
        boolean backgroundNoise, int numDistractorsPerFrame) throws Exception {

    //First: decide where transitions between one shape and another are
    double[] rns = new double[numShapes];
    double sum = 0;
    for (int i = 0; i < numShapes; i++) {
        rns[i] = r.nextDouble();//  w  ww  .  j a v  a 2  s .c  o  m
        sum += rns[i];
    }
    for (int i = 0; i < numShapes; i++)
        rns[i] /= sum;

    int[] startFrames = new int[numShapes];
    startFrames[0] = 0;
    for (int i = 1; i < numShapes; i++) {
        startFrames[i] = (int) (startFrames[i - 1] + MIN_FRAMES + rns[i] * (nFrames - numShapes * MIN_FRAMES));
    }

    //Randomly generate shape positions, velocities, colors, and type
    int[] shapeTypes = new int[numShapes];
    int[] initialX = new int[numShapes];
    int[] initialY = new int[numShapes];
    double[] velocityX = new double[numShapes];
    double[] velocityY = new double[numShapes];
    Color[] color = new Color[numShapes];
    for (int i = 0; i < numShapes; i++) {
        shapeTypes[i] = r.nextInt(NUM_SHAPES);
        initialX[i] = SHAPE_MIN_DIST_FROM_EDGE + r.nextInt(width - SHAPE_SIZE - 2 * SHAPE_MIN_DIST_FROM_EDGE);
        initialY[i] = SHAPE_MIN_DIST_FROM_EDGE + r.nextInt(height - SHAPE_SIZE - 2 * SHAPE_MIN_DIST_FROM_EDGE);
        velocityX[i] = -1 + 2 * r.nextDouble();
        velocityY[i] = -1 + 2 * r.nextDouble();
        color[i] = new Color(r.nextFloat(), r.nextFloat(), r.nextFloat());
    }

    //Generate a sequence of BufferedImages with the given shapes, and write them to the video
    SequenceEncoder enc = new SequenceEncoder(new File(path));
    int currShape = 0;
    int[] labels = new int[nFrames];
    for (int i = 0; i < nFrames; i++) {
        if (currShape < numShapes - 1 && i >= startFrames[currShape + 1])
            currShape++;

        BufferedImage bi = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
        Graphics2D g2d = bi.createGraphics();
        g2d.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        g2d.setBackground(Color.BLACK);

        if (backgroundNoise) {
            for (int x = 0; x < width; x++) {
                for (int y = 0; y < height; y++) {
                    bi.setRGB(x, y, new Color(r.nextFloat() * MAX_NOISE_VALUE, r.nextFloat() * MAX_NOISE_VALUE,
                            r.nextFloat() * MAX_NOISE_VALUE).getRGB());
                }
            }
        }

        g2d.setColor(color[currShape]);

        //Position of shape this frame
        int currX = (int) (initialX[currShape]
                + (i - startFrames[currShape]) * velocityX[currShape] * MAX_VELOCITY);
        int currY = (int) (initialY[currShape]
                + (i - startFrames[currShape]) * velocityY[currShape] * MAX_VELOCITY);

        //Render the shape
        switch (shapeTypes[currShape]) {
        case 0:
            //Circle
            g2d.fill(new Ellipse2D.Double(currX, currY, SHAPE_SIZE, SHAPE_SIZE));
            break;
        case 1:
            //Square
            g2d.fill(new Rectangle2D.Double(currX, currY, SHAPE_SIZE, SHAPE_SIZE));
            break;
        case 2:
            //Arc
            g2d.fill(new Arc2D.Double(currX, currY, SHAPE_SIZE, SHAPE_SIZE, 315, 225, Arc2D.PIE));
            break;
        case 3:
            //Line
            g2d.setStroke(lineStroke);
            g2d.draw(new Line2D.Double(currX, currY, currX + SHAPE_SIZE, currY + SHAPE_SIZE));
            break;
        default:
            throw new RuntimeException();
        }

        //Add some distractor shapes, which are present for one frame only
        for (int j = 0; j < numDistractorsPerFrame; j++) {
            int distractorShapeIdx = r.nextInt(NUM_SHAPES);

            int distractorX = DISTRACTOR_MIN_DIST_FROM_EDGE + r.nextInt(width - SHAPE_SIZE);
            int distractorY = DISTRACTOR_MIN_DIST_FROM_EDGE + r.nextInt(height - SHAPE_SIZE);

            g2d.setColor(new Color(r.nextFloat(), r.nextFloat(), r.nextFloat()));

            switch (distractorShapeIdx) {
            case 0:
                g2d.fill(new Ellipse2D.Double(distractorX, distractorY, SHAPE_SIZE, SHAPE_SIZE));
                break;
            case 1:
                g2d.fill(new Rectangle2D.Double(distractorX, distractorY, SHAPE_SIZE, SHAPE_SIZE));
                break;
            case 2:
                g2d.fill(new Arc2D.Double(distractorX, distractorY, SHAPE_SIZE, SHAPE_SIZE, 315, 225,
                        Arc2D.PIE));
                break;
            case 3:
                g2d.setStroke(lineStroke);
                g2d.draw(new Line2D.Double(distractorX, distractorY, distractorX + SHAPE_SIZE,
                        distractorY + SHAPE_SIZE));
                break;
            default:
                throw new RuntimeException();
            }
        }

        enc.encodeImage(bi);
        g2d.dispose();
        labels[i] = shapeTypes[currShape];
    }
    enc.finish(); //write .mp4

    return labels;
}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

/**
 * /*from   w w w.j av  a  2s . co  m*/
 * @param iArcStyle
 * @return
 */
protected static final int toG2dArcType(int iArcStyle) {
    switch (iArcStyle) {
    case ArcRenderEvent.OPEN:
        return Arc2D.OPEN;
    case ArcRenderEvent.CLOSED:
        return Arc2D.CHORD;
    case ArcRenderEvent.SECTOR:
        return Arc2D.PIE;
    }
    return -1;
}

From source file:org.eclipse.birt.chart.device.g2d.G2dRendererBase.java

@Override
public void fillArc(ArcRenderEvent are) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(are);//from  www .  ja va2s . co m
    }

    final Fill flBackground = validateMultipleFill(are.getBackground());

    if (isFullTransparent(flBackground)) {
        return;
    }

    if (flBackground instanceof ColorDefinition) {
        final ColorDefinition cl = (ColorDefinition) flBackground;
        final Color clrPrevious = _g2d.getColor();
        final Color currentColor = (Color) _ids.getColor(cl);
        _g2d.setColor(currentColor);

        if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0
                && are.getInnerRadius() < are.getOuterRadius())
                || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) {
            Bounds rctOuter = getOuterRectangle(are);
            Bounds rctInner = getInnerRectangle(are);

            Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(),
                    rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE);

            Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(),
                    rctInner.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE);

            Area fArea = new Area(outerArc);
            fArea.exclusiveOr(new Area(innerArc));

            Shape prevClip = _g2d.getClip();
            Area ar2 = new Area(fArea);
            if (prevClip != null) {
                Area ar1 = new Area(prevClip);
                ar2.intersect(ar1);
            }
            _g2d.setClip(ar2);
            _g2d.fill(fArea);
            _g2d.setClip(prevClip);
        } else {
            _g2d.fill(new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(),
                    are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle())));
        }

        _g2d.setColor(clrPrevious); // RESTORE
    } else if (flBackground instanceof Gradient) {
        final Gradient g = (Gradient) flBackground;
        final ColorDefinition cdStart = g.getStartColor();
        final ColorDefinition cdEnd = g.getEndColor();
        double dAngleInDegrees = g.getDirection();
        final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0);
        Bounds bo = are.getBounds();

        if (dAngleInDegrees < -90 || dAngleInDegrees > 90) {
            throw new ChartException(ChartDeviceExtensionPlugin.ID, ChartException.RENDERING,
                    "SwingRendererImpl.exception.gradient.angle", //$NON-NLS-1$
                    new Object[] { new Double(dAngleInDegrees) }, Messages.getResourceBundle(getULocale()));
        }

        Point2D.Double p2dStart, p2dEnd;
        if (dAngleInDegrees == 90) {
            p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight());
            p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop());
        } else if (dAngleInDegrees == -90) {
            p2dEnd = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight());
            p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop());
        } else if (dAngleInDegrees > 0) {
            p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop() + bo.getHeight());
            p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(),
                    bo.getTop() + bo.getHeight() - bo.getWidth() * Math.abs(Math.tan(dAngleInRadians)));
        } else if (dAngleInDegrees < 0) {
            p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop());
            p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(),
                    bo.getTop() + bo.getWidth() * Math.abs(Math.tan(dAngleInRadians)));
        } else {
            p2dStart = new Point2D.Double(bo.getLeft(), bo.getTop());
            p2dEnd = new Point2D.Double(bo.getLeft() + bo.getWidth(), bo.getTop());
        }

        final Paint pPrevious = _g2d.getPaint();
        _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd,
                (Color) _ids.getColor(cdEnd)));

        if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0
                && are.getInnerRadius() < are.getOuterRadius())
                || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) {
            Bounds rctOuter = getOuterRectangle(are);
            Bounds rctInner = getInnerRectangle(are);

            Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(),
                    rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE);

            Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(),
                    rctInner.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE);

            Area fArea = new Area(outerArc);
            fArea.exclusiveOr(new Area(innerArc));

            Shape prevClip = _g2d.getClip();
            Area ar2 = new Area(fArea);
            if (prevClip != null) {
                Area ar1 = new Area(prevClip);
                ar2.intersect(ar1);
            }
            _g2d.setClip(ar2);
            _g2d.fill(fArea);
            _g2d.setClip(prevClip);
        } else {
            _g2d.fill(new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(), are.getWidth(),
                    are.getHeight(), are.getStartAngle(), are.getAngleExtent(), toG2dArcType(are.getStyle())));
        }

        _g2d.setPaint(pPrevious); // RESTORE
    } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) {
        final Bounds bo = are.getBounds();
        final Rectangle2D.Double r2d = new Rectangle2D.Double(bo.getLeft(), bo.getTop(), bo.getWidth(),
                bo.getHeight());

        Shape shPreviousClip = _g2d.getClip();
        Area ar = null;

        if ((are.getInnerRadius() >= 0 && are.getOuterRadius() > 0
                && are.getInnerRadius() < are.getOuterRadius())
                || (are.getInnerRadius() > 0 && are.getOuterRadius() <= 0)) {
            Bounds rctOuter = getOuterRectangle(are);
            Bounds rctInner = getInnerRectangle(are);

            Shape outerArc = new Arc2D.Double(rctOuter.getLeft(), rctOuter.getTop(), rctOuter.getWidth(),
                    rctOuter.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE);

            Shape innerArc = new Arc2D.Double(rctInner.getLeft(), rctInner.getTop(), rctInner.getWidth(),
                    rctInner.getHeight(), are.getStartAngle(), are.getAngleExtent(), Arc2D.PIE);

            Area fArea = new Area(outerArc);
            fArea.exclusiveOr(new Area(innerArc));

            if (shPreviousClip != null) {
                Area ar1 = new Area(shPreviousClip);
                fArea.intersect(ar1);
            }
            // _g2d.setClip( fArea );
            ar = fArea;
        } else {
            // SETUP THE CLIPPING AREA
            final Shape shArc = new Arc2D.Double(are.getTopLeft().getX(), are.getTopLeft().getY(),
                    are.getWidth(), are.getHeight(), are.getStartAngle(), are.getAngleExtent(),
                    toG2dArcType(are.getStyle()));

            Area ar2 = new Area(shArc);
            if (shPreviousClip != null) {
                Area ar1 = new Area(shPreviousClip);
                ar2.intersect(ar1);
            }
            // _g2d.setClip( ar2 );
            ar = ar2;
        }

        if (flBackground instanceof PatternImage) {
            fillWithPatternImage(new Area(ar), flBackground);
            return;
        }

        _g2d.setClip(ar);

        // LOAD THE IMAGE
        java.awt.Image img = createImageFromModel(flBackground);
        if (img != null) {
            // REPLICATE THE IMAGE AS NEEDED
            final Size szImage = _ids.getSize(img);
            int iXRepeat = (int) (Math.ceil(r2d.width / szImage.getWidth()));
            int iYRepeat = (int) (Math.ceil(r2d.height / szImage.getHeight()));
            ImageObserver io = (ImageObserver) _ids.getObserver();
            for (int i = 0; i < iXRepeat; i++) {
                for (int j = 0; j < iYRepeat; j++) {
                    _g2d.drawImage(img, (int) (r2d.x + i * szImage.getWidth()),
                            (int) (r2d.y + j * szImage.getHeight()), io);
                }
            }
        }

        _g2d.setClip(shPreviousClip); // RESTORE
    }
}

From source file:org.jcurl.demo.tactics.sg.BroomPromptScenario.java

public BroomPromptScenario() {
    // create the scene
    final boolean stickUp = false;
    final boolean bothSides = true;
    final int pieAngle = 150;
    final Color sp = Color.BLACK;
    final Color bgc = new Color(1, 1, 1, 0.5f);
    final Stroke fine = new BasicStroke(0.01f, BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER);
    final Stroke bold = new BasicStroke(0.03f, BasicStroke.CAP_ROUND, BasicStroke.JOIN_MITER);
    // final Font fo = new Font("SansSerif", Font.BOLD, 1);
    final float halo = RockProps.DEFAULT.getRadius();
    final float outer = 0.8f * RockProps.DEFAULT.getRadius();
    stickLength = (stickUp ? 1 : -1) * 5 * outer;
    final float inner = 0.5F * outer;

    final SGGroup me = new SGGroup();
    // the transparent background
    {/*from   w  w  w. j  ava2 s .co m*/
        final SGShape bg = node(new Arc2D.Float(-halo, -halo, 2 * halo, 2 * halo, 0, 360, Arc2D.OPEN), null,
                null, scale0);
        bg.setFillPaint(bgc);
        bg.addMouseListener(new MoveHandler());
        bg.setMouseBlocker(true);
        bg.setCursor(moveC);
        me.add(bg);
    }
    // the cross-hair and stick
    {
        final int off = 90;
        final int pieOff = 180;
        final int arrowLengthDegrees = 7;
        // colored pie:
        pie = node(new Arc2D.Float(-outer, -outer, 2 * outer, 2 * outer, off - pieOff, pieAngle, Arc2D.PIE),
                null, null, scale0);
        me.add(pie);
        // inner circle:
        me.add(node(new Arc2D.Float(-inner, -inner, 2 * inner, 2 * inner, off, pieOff + pieAngle, Arc2D.OPEN),
                fine, sp, scale50));
        // outer circle:
        me.add(node(new Arc2D.Float(-outer, -outer, 2 * outer, 2 * outer, off,
                pieOff + pieAngle - (14 + arrowLengthDegrees), Arc2D.OPEN), fine, sp, scale50));
        // Semantic zooming: me.add(node(new Arc2D.Float(-outer, -outer, 2 *
        // outer, 2 * outer,
        // off, pieOff + pieAngle, Arc2D.OPEN), fine, sp, -scale50));
        final double ar = Math.PI * (off + pieAngle) / 180.0;
        // radius
        // if (pieAngle % 90 != 0)
        me.add(node(new Line2D.Double(0, 0, -outer * Math.cos(ar), outer * Math.sin(ar)), bold, sp, scale0));

        // arrow:
        final float f = outer / 10;
        final SGShape s = node(IceShapes.createArrowHead(f, 3 * f, 0.5f * f), null, null, scale50);
        s.setFillPaint(sp);
        final double a = Math.PI * (off + pieAngle - arrowLengthDegrees) / 180.0;
        final AffineTransform a_ = new AffineTransform();
        a_.translate(-outer * Math.cos(a), outer * Math.sin(a));
        a_.rotate(Math.PI * (90 - (off + pieAngle) + 8 + arrowLengthDegrees) / 180.0);
        final Affine s_ = SGTransform.createAffine(a_, s);
        me.add(s_);
    }
    { // y-axis:
        me.add(node(new Line2D.Float(0, -Math.signum(stickLength) * halo, 0, stickLength), fine, sp, scale0));
        // x-axis:
        me.add(node(new Line2D.Float(-halo, 0, halo, 0), fine, sp, scale0));
    }
    { // slider
        sli = new SGShape();
        sli.setShape(IceShapes.createSlider(0.4f * outer, bothSides));
        // sli.setFillPaint(sp);
        sli.setDrawStroke(fine);
        sli.setDrawPaint(sp);
        sli.setMode(Mode.STROKE_FILL);
        sli.setAntialiasingHint(RenderingHints.VALUE_ANTIALIAS_ON);
        me.add(slider = SGTransform.createAffine(new AffineTransform(), sli));
        slider.setCursor(moveC);
        slider.addMouseListener(new SpeedHandler());
        slider.setMouseBlocker(true);
    }
    handle = SGTransform.createAffine(new AffineTransform(), me);
    scene = SGTransform.createAffine(new AffineTransform(), handle);
    scene.setVisible(false);
}