Example usage for java.awt GradientPaint GradientPaint

List of usage examples for java.awt GradientPaint GradientPaint

Introduction

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

Prototype

public GradientPaint(Point2D pt1, Color color1, Point2D pt2, Color color2) 

Source Link

Document

Constructs a simple acyclic GradientPaint object.

Usage

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

@Override
public void fillPolygon(PolygonRenderEvent pre) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(pre);/*  ww  w . j  a va2  s.c om*/
    }
    final Fill flBackground = validateMultipleFill(pre.getBackground());

    if (isFullTransparent(flBackground)) {
        return;
    }

    final Location[] loa = pre.getPoints();
    final int[][] i2a = getCoordinatesAsInts(loa);

    if (flBackground instanceof ColorDefinition) {
        final ColorDefinition cd = (ColorDefinition) flBackground;
        _g2d.setColor((Color) _ids.getColor(cd));
        _g2d.fill(getPolygon(loa));
    } else if (flBackground instanceof Gradient) {
        final Gradient g = (Gradient) flBackground;
        final ColorDefinition cdStart = g.getStartColor();
        final ColorDefinition cdEnd = g.getEndColor();
        // final boolean bRadial = g.isCyclic();
        final double dAngleInDegrees = g.getDirection();
        final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0);
        // final int iAlpha = g.getTransparency();

        final double dMinX = BaseRenderer.getX(loa, IConstants.MIN);
        final double dMaxX = BaseRenderer.getX(loa, IConstants.MAX);
        final double dMinY = BaseRenderer.getY(loa, IConstants.MIN);
        final double dMaxY = BaseRenderer.getY(loa, IConstants.MAX);

        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(dMinX, dMaxY);
            p2dEnd = new Point2D.Double(dMinX, dMinY);
        } else if (dAngleInDegrees == -90) {
            p2dStart = new Point2D.Double(dMinX, dMinY);
            p2dEnd = new Point2D.Double(dMinX, dMaxY);
        } else if (dAngleInDegrees > 0) {
            p2dStart = new Point2D.Double(dMinX, dMaxY);
            p2dEnd = new Point2D.Double(dMaxX, dMaxY - (dMaxX - dMinX) * Math.abs(Math.tan(dAngleInRadians)));
        } else if (dAngleInDegrees < 0) {
            p2dStart = new Point2D.Double(dMinX, dMinY);
            p2dEnd = new Point2D.Double(dMaxX, dMinY + (dMaxX - dMinX) * Math.abs(Math.tan(dAngleInRadians)));
        } else {
            p2dStart = new Point2D.Double(dMinX, dMinY);
            p2dEnd = new Point2D.Double(dMaxX, dMinY);
        }
        _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd,
                (Color) _ids.getColor(cdEnd)));
        _g2d.fill(getPolygon(loa));
    } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) {
        Area ar2 = new Area(new Polygon(i2a[0], i2a[1], loa.length));
        if (flBackground instanceof PatternImage) {
            fillWithPatternImage(ar2, flBackground);
            return;
        }
        java.awt.Image img = createImageFromModel(flBackground);

        if (img != null) {
            final Shape shClip = _g2d.getClip();
            if (shClip != null) {
                Area ar1 = new Area(shClip);
                ar2.intersect(ar1);
            }
            _g2d.setClip(ar2);

            final double dMinX = BaseRenderer.getX(loa, IConstants.MIN);
            final double dMaxX = BaseRenderer.getX(loa, IConstants.MAX);
            final double dMinY = BaseRenderer.getY(loa, IConstants.MIN);
            final double dMaxY = BaseRenderer.getY(loa, IConstants.MAX);
            final Size szImage = _ids.getSize(img);

            final int iXRepeat = (int) (Math.ceil((dMaxX - dMinX) / szImage.getWidth()));
            final int iYRepeat = (int) (Math.ceil((dMaxY - dMinY) / szImage.getHeight()));
            final ImageObserver io = (ImageObserver) _ids.getObserver();
            for (int i = 0; i < iXRepeat; i++) {
                for (int j = 0; j < iYRepeat; j++) {
                    _g2d.drawImage(img, (int) (dMinX + i * szImage.getWidth()),
                            (int) (dMinY + j * szImage.getHeight()), io);
                }
            }

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

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);/*w  w w  .  jav a 2 s  .c o 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:se.technipelago.weather.chart.Generator.java

private void createTemperatureDial(float temperature, int humidity, final String filename) throws IOException {
    ValueDataset dataset1 = new DefaultValueDataset(temperature);
    ValueDataset dataset2 = new DefaultValueDataset(humidity);

    // get data for diagrams
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);//from   w w  w. j a va  2s  . co m
    plot.setDataset(0, dataset1);
    plot.setDataset(1, dataset2);
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialFrame.setBackgroundPaint(Color.lightGray);
    dialFrame.setForegroundPaint(Color.darkGray);
    plot.setDialFrame(dialFrame);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));
    DialBackground db = new DialBackground(gp);
    db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    plot.setBackground(db);

    // Temperature
    DialTextAnnotation annotation1 = new DialTextAnnotation("\u00B0C");
    annotation1.setFont(new Font("Dialog", Font.BOLD, 10));
    annotation1.setRadius(0.76);

    plot.addLayer(annotation1);

    // Humidity
    DialTextAnnotation annotation2 = new DialTextAnnotation("%");
    annotation2.setFont(new Font("Dialog", Font.BOLD, 10));
    annotation2.setPaint(Color.blue);
    annotation2.setRadius(0.4);

    plot.addLayer(annotation2);

    // Temperature
    DialValueIndicator dvi = new DialValueIndicator(0);
    dvi.setFont(new Font("Dialog", Font.PLAIN, 9));
    dvi.setOutlinePaint(Color.darkGray);
    //dvi.setBackgroundPaint(new Color(0xee, 0xee, 0xf6));
    NumberFormat fmt = new DecimalFormat("#");
    fmt.setMaximumFractionDigits(1);
    fmt.setMinimumIntegerDigits(1);
    dvi.setNumberFormat(fmt);
    dvi.setRadius(0.71);
    dvi.setAngle(-88.0); // -103
    dvi.setInsets(new RectangleInsets(0.0, 8.0, 0.0, 2.0)); // top, left, bottom, right
    plot.addLayer(dvi);

    StandardDialScale scale = new StandardDialScale(-30, 30, -120, -300, 5, 4);
    scale.setTickRadius(0.88);
    scale.setTickLabelOffset(0.15);
    scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    NumberFormat fmt3 = new DecimalFormat("#");
    fmt3.setMaximumFractionDigits(0);
    scale.setTickLabelFormatter(fmt3);
    plot.addScale(0, scale);

    // Humidity
    DialValueIndicator dvi2 = new DialValueIndicator(1);
    dvi2.setFont(new Font("Dialog", Font.PLAIN, 9));
    dvi2.setOutlinePaint(Color.blue);
    //dvi2.setBackgroundPaint(new Color(0xee, 0xee, 0xf6));
    NumberFormat fmt2 = new DecimalFormat("#");
    fmt2.setMaximumFractionDigits(0);
    dvi2.setNumberFormat(fmt2);

    dvi2.setRadius(0.59);
    dvi2.setAngle(-90.0); // -77
    dvi2.setInsets(new RectangleInsets(0.0, 1.0, 0.0, 1.0));
    plot.addLayer(dvi2);

    StandardDialScale scale2 = new StandardDialScale(0, 100, -120, -300, 10, 4);
    scale2.setTickRadius(0.50);
    scale2.setTickLabelOffset(0.15);
    scale2.setTickLabelFont(new Font("Dialog", Font.PLAIN, 9));
    scale2.setTickLabelFormatter(fmt3);
    scale2.setMajorTickPaint(Color.blue);
    plot.addScale(1, scale2);
    plot.mapDatasetToScale(1, 1);

    // Add needles.
    // To make the temperature needle the front-most needle,
    // it must be added after humidity needle.
    // Humidity needle.
    DialPointer needle2 = new DialPointer.Pin(1);
    needle2.setRadius(0.50);
    plot.addLayer(needle2);

    // Temperature needle.
    DialPointer needle = new DialPointer.Pointer(0);
    Color darkGreen = new Color(0x15, 0x49, 0x1f);
    ((DialPointer.Pointer) needle).setFillPaint(darkGreen);
    plot.addLayer(needle);

    // Add a cap at the dial center.
    DialCap cap = new DialCap();
    cap.setRadius(0.10);
    plot.setCap(cap);

    JFreeChart chart = new JFreeChart(plot);
    //TextTitle title = new TextTitle("Temperatur/luftfuktighet", new Font("Dialog", Font.BOLD, 12));
    //title.setPaint(Color.DARK_GRAY);
    //chart.setTitle(title);
    chart.setBackgroundPaint(VERY_LIGHT_GRAY);

    OutputStream out = null;
    try {
        out = new FileOutputStream(outputDir != null ? outputDir + "/" + filename : filename);
        ChartUtilities.writeChartAsPNG(out, chart, DIAL_WIDTH, DIAL_HEIGHT);
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

From source file:se.technipelago.weather.chart.Generator.java

private void createWindDial(float speed, float high, final String filename) throws IOException {
    ValueDataset dataset1 = new DefaultValueDataset(speed);
    ValueDataset dataset2 = new DefaultValueDataset(high);

    // get data for diagrams
    DialPlot plot = new DialPlot();
    plot.setView(0.0, 0.0, 1.0, 1.0);/*from w  ww.j  av  a 2 s. c  o  m*/
    plot.setDataset(0, dataset1);
    plot.setDataset(1, dataset2);
    StandardDialFrame dialFrame = new StandardDialFrame();
    dialFrame.setBackgroundPaint(Color.lightGray);
    dialFrame.setForegroundPaint(Color.darkGray);
    plot.setDialFrame(dialFrame);

    GradientPaint gp = new GradientPaint(new Point(), new Color(255, 255, 255), new Point(),
            new Color(170, 170, 220));
    DialBackground db = new DialBackground(gp);
    db.setGradientPaintTransformer(new StandardGradientPaintTransformer(GradientPaintTransformType.VERTICAL));
    plot.setBackground(db);

    // Wind Speed
    DialTextAnnotation annotation1 = new DialTextAnnotation("m/s");
    annotation1.setFont(new Font("Dialog", Font.BOLD, 10));
    annotation1.setRadius(0.76);

    plot.addLayer(annotation1);

    DialValueIndicator dvi = new DialValueIndicator(0);
    dvi.setFont(new Font("Dialog", Font.PLAIN, 9));
    dvi.setOutlinePaint(Color.darkGray);
    //dvi.setBackgroundPaint(new Color(0xee, 0xee, 0xf6));
    NumberFormat fmt = new DecimalFormat("#");
    fmt.setMaximumFractionDigits(1);
    fmt.setMinimumIntegerDigits(1);
    dvi.setNumberFormat(fmt);
    dvi.setRadius(0.71);
    dvi.setAngle(-89.0); // -103
    dvi.setInsets(new RectangleInsets(0.0, 2.0, 0.0, 2.0)); // top, left, bottom, right
    plot.addLayer(dvi);

    StandardDialScale scale = new StandardDialScale(0, 20, -120, -300, 1, 0);
    scale.setTickRadius(0.88);
    scale.setTickLabelOffset(0.15);
    scale.setTickLabelFont(new Font("Dialog", Font.PLAIN, 10));
    NumberFormat fmt3 = new DecimalFormat("#");
    fmt3.setMaximumFractionDigits(0);
    scale.setTickLabelFormatter(fmt3);
    plot.addScale(0, scale);

    // Add needles.
    // To make the average speed needle the front-most needle,
    // it must be added after high speed needle.
    // High speed needle.
    DialPointer needle2 = new DialPointer.Pin(1);
    needle2.setRadius(0.62);
    plot.addLayer(needle2);

    // Average speed needle.
    DialPointer needle = new DialPointer.Pointer(0);
    Color darkGreen = new Color(0x15, 0x49, 0x1f);
    ((DialPointer.Pointer) needle).setFillPaint(darkGreen);
    plot.addLayer(needle);

    // Add a cap at the dial center.
    DialCap cap = new DialCap();
    cap.setRadius(0.10);
    plot.setCap(cap);

    JFreeChart chart = new JFreeChart(plot);
    //TextTitle title = new TextTitle("Vindhastighet", new Font("Dialog", Font.BOLD, 12));
    //title.setPaint(Color.DARK_GRAY);
    //chart.setTitle(title);
    chart.setBackgroundPaint(VERY_LIGHT_GRAY);

    OutputStream out = null;
    try {
        out = new FileOutputStream(outputDir != null ? outputDir + "/" + filename : filename);
        ChartUtilities.writeChartAsPNG(out, chart, DIAL_WIDTH, DIAL_HEIGHT);
    } finally {
        if (out != null) {
            out.close();
        }
    }
}

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

@Override
public void fillArea(AreaRenderEvent are) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(are);//from   ww w  . jav  a  2s . c  o m
    }

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

    if (isFullTransparent(flBackground)) {
        return;
    }

    // SETUP SWING DATA STRUCTURES
    final GeneralPath gp = new GeneralPath();
    PrimitiveRenderEvent pre;
    for (int i = 0; i < are.getElementCount(); i++) {
        pre = are.getElement(i);
        if (pre instanceof ArcRenderEvent) {
            final ArcRenderEvent acre = (ArcRenderEvent) pre;
            final Arc2D.Double a2d = new Arc2D.Double(acre.getTopLeft().getX(), acre.getTopLeft().getY(),
                    acre.getWidth(), acre.getHeight(), acre.getStartAngle(), acre.getAngleExtent(),
                    toG2dArcType(acre.getStyle()));
            gp.append(a2d, true);
        } else if (pre instanceof LineRenderEvent) {
            final LineRenderEvent lre = (LineRenderEvent) pre;
            final Line2D.Double l2d = new Line2D.Double(lre.getStart().getX(), lre.getStart().getY(),
                    lre.getEnd().getX(), lre.getEnd().getY());
            gp.append(l2d, true);
        }
    }

    // BEGIN FILLING
    if (flBackground instanceof ColorDefinition) {
        _g2d.setColor((Color) _ids.getColor((ColorDefinition) flBackground));
    } else if (flBackground instanceof Gradient) {
        final Gradient g = (Gradient) flBackground;
        final ColorDefinition cdStart = g.getStartColor();
        final ColorDefinition cdEnd = g.getEndColor();
        // boolean bCyclic = g.isCyclic();
        double dAngleInDegrees = g.getDirection();
        final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0);
        // int iAlpha = g.getTransparency();
        Bounds bo = are.getBounds();

        /*
         * if (bCyclic) { }
         */

        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());
        }
        _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd,
                (Color) _ids.getColor(cdEnd)));
    } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) {
        // TODO TBD
    }
    _g2d.fill(gp);
}

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

@Override
public void fillOval(OvalRenderEvent ore) throws ChartException {
    if (iv != null) {
        iv.modifyEvent(ore);/*from   w  w w .  j a  v a 2  s  . com*/
    }

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

    if (isFullTransparent(flBackground)) {
        return;
    }

    final Bounds bo = ore.getBounds();
    final Ellipse2D.Double e2d = new Ellipse2D.Double(bo.getLeft(), bo.getTop(), bo.getWidth(), bo.getHeight());
    if (flBackground instanceof ColorDefinition) {
        final ColorDefinition cd = (ColorDefinition) flBackground;
        _g2d.setColor((Color) _ids.getColor(cd));
        _g2d.fill(e2d);
    } else if (flBackground instanceof Gradient) {
        final Gradient g = (Gradient) flBackground;
        final ColorDefinition cdStart = g.getStartColor();
        final ColorDefinition cdEnd = g.getEndColor();
        // boolean bCyclic = g.isCyclic();
        double dAngleInDegrees = g.getDirection();
        final double dAngleInRadians = ((-dAngleInDegrees * Math.PI) / 180.0);

        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());
        }
        _g2d.setPaint(new GradientPaint(p2dStart, (Color) _ids.getColor(cdStart), p2dEnd,
                (Color) _ids.getColor(cdEnd)));
        _g2d.fill(e2d);
    } else if (flBackground instanceof org.eclipse.birt.chart.model.attribute.Image) {
        Area ar2 = new Area(e2d);
        if (flBackground instanceof PatternImage) {
            fillWithPatternImage(ar2, flBackground);
            return;
        }
        java.awt.Image img = createImageFromModel(flBackground);

        if (img != null) {

            final Shape shClip = _g2d.getClip();
            if (shClip != null) {
                Area ar1 = new Area(shClip);
                ar2.intersect(ar1);
            }
            _g2d.setClip(ar2);

            final Size szImage = _ids.getSize(img);

            int iXRepeat = (int) (Math.ceil(e2d.width / szImage.getWidth()));
            int iYRepeat = (int) (Math.ceil(e2d.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) (e2d.x + i * szImage.getWidth()),
                            (int) (e2d.y + j * szImage.getHeight()), io);
                }
            }

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

From source file:semaforo.Semaforo.java

public static void SemaforoGrafico(JFreeChart chart) {

    // set a custom background for the chart
    chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.BLACK, new Point(400, 200), Color.BLACK));

    // customise the title position and font
    TextTitle t = chart.getTitle();/* w  ww  .j  av a  2  s .  c  o m*/
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 0));
    PiePlot plot = null;
    plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.00);
    plot.setOutlineVisible(true);

    // use gradients and white borders for the section colours

    plot.setBaseSectionOutlinePaint(Color.BLACK);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 0));
    plot.setLabelLinkPaint(Color.BLACK);
    plot.setLabelLinkStroke(new BasicStroke(0.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.BLACK);
    plot.setLabelBackgroundPaint(null);
    plot.setLabelBackgroundPaint(Color.BLACK);
    plot.setLabelShadowPaint(Color.BLACK);

    // add a subtitle giving the data source       

    // Mostramos la grafica dentro del jPanel1
    panel = new ChartPanel(chart);
    panel.setBackground(Color.BLACK);
    panel.repaint();

    jPanel3.setLayout(null);
    jPanel3.setLayout(new java.awt.BorderLayout());
    jPanel3.remove(panel);
    jPanel3.add(panel);

    jPanel3.repaint();
    Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
    jTabbedPane1.setPreferredSize(new Dimension(screenSize.width, screenSize.height));
}

From source file:semaforo.Semaforo.java

public static void editGrafico() {
    DecimalFormat df = new DecimalFormat();
    df.setMaximumFractionDigits(2);/*  w  w w.  ja  va  2  s.c  o  m*/
    double cfd = 0.0;
    double bull = 0.0;
    double bear = 0.0;
    if (countCfd != 0)
        cfd = (countCfd * 100) / (countBear + countBull + countCfd);
    if (countBull != 0)
        bull = ((countBull * 100) / (countBear + countBull + countCfd));
    if (countBear != 0)
        bear = ((countBear * 100) / (countBear + countBull + countCfd));
    Semaforo.l1.setText("CFD (" + String.format("%.2f", cfd) + "%)");
    Semaforo.l2.setText("BULL (" + String.format("%.2f", bull) + "%)");
    Semaforo.l3.setText("BEAR (" + String.format("%.2f", bear) + "%)");
    DefaultPieDataset pieDataset = new DefaultPieDataset();
    pieDataset.setValue("CFD (" + cfd + "%)", new Integer((int) countCfd));
    pieDataset.setValue("BULL (" + bull + "%)", new Integer((int) countBull));
    pieDataset.setValue("BEAR (" + bear + "%)", new Integer((int) countBear));
    JFreeChart chart = null;
    chart = ChartFactory.createPieChart("", // chart title
            pieDataset, // data
            false, // no legend
            false, // tooltips
            false // no URL generation
    );

    // set a custom background for the chart
    chart.setBackgroundPaint(new GradientPaint(new Point(0, 0), Color.BLACK, new Point(400, 200), Color.BLACK));

    // customise the title position and font
    TextTitle t = chart.getTitle();
    t.setHorizontalAlignment(HorizontalAlignment.LEFT);
    t.setPaint(new Color(240, 240, 240));
    t.setFont(new Font("Arial", Font.BOLD, 0));
    PiePlot plot = null;
    plot = (PiePlot) chart.getPlot();
    plot.setBackgroundPaint(null);
    plot.setInteriorGap(0.00);
    plot.setOutlineVisible(true);

    // use gradients and white borders for the section colours

    plot.setBaseSectionOutlinePaint(Color.BLACK);
    plot.setSectionOutlinesVisible(true);
    plot.setBaseSectionOutlineStroke(new BasicStroke(0.0f));

    // customise the section label appearance
    plot.setLabelFont(new Font("Courier New", Font.BOLD, 0));
    plot.setLabelLinkPaint(Color.BLACK);
    plot.setLabelLinkStroke(new BasicStroke(0.0f));
    plot.setLabelOutlineStroke(null);
    plot.setLabelPaint(Color.BLACK);
    plot.setLabelBackgroundPaint(null);
    plot.setLabelBackgroundPaint(Color.BLACK);
    plot.setLabelShadowPaint(Color.BLACK);

    // add a subtitle giving the data source       

    // Mostramos la grafica dentro del jPanel1
    Semaforo.panel.setChart(chart);
}