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(float x1, float y1, Color color1, float x2, float y2, Color color2, boolean cyclic) 

Source Link

Document

Constructs either a cyclic or acyclic GradientPaint object depending on the boolean parameter.

Usage

From source file:org.openfaces.component.chart.impl.renderers.LineFillRenderer.java

private Paint getAreaFillPaint(CategoryPlot plot, Double plotWidth, Double plotHeight, Color mainColor,
        Color secondaryColor) {/*from   w  w  w.  j av a2 s.  co m*/
    return (plot.getOrientation() == PlotOrientation.VERTICAL)
            ? new GradientPaint(0.0f, 0.0f, mainColor, 0.0f, plotHeight.floatValue(), secondaryColor, true)
            : new GradientPaint(plotWidth.floatValue(), 0.0f, mainColor, 0.0f, 0.0f, secondaryColor, true);
}

From source file:be.vds.jtbdive.client.view.core.dive.profile.DiveProfileGraphicDetailPanel.java

private Component createGraphicPanel() {
    depthSerie = new XYSeries(DiveProfileChartFactory.SERIE_DEPTH);
    XYSeriesCollection depthCollection = new XYSeriesCollection();
    depthCollection.addSeries(depthSerie);

    chart = ChartFactory.createXYAreaChart(null, getDomainLegend(), getRangeLegend(), depthCollection,
            PlotOrientation.VERTICAL, false, true, false);
    xyp = chart.getXYPlot();//from w  ww .  ja  v a  2  s. c  o  m

    Paint p = new GradientPaint(0f, 0f, UIAgent.getInstance().getColorWaterBottom(), 200f, 200f,
            UIAgent.getInstance().getColorWaterSurface(), false);
    xyp.setBackgroundPaint(p);
    xyp.setDomainGridlinePaint(UIAgent.getInstance().getColorWaterGrid());
    xyp.setRangeGridlinePaint(UIAgent.getInstance().getColorWaterGrid());

    xyp.setDomainCrosshairVisible(true);
    xyp.setRangeCrosshairVisible(true);
    xyp.setRangeCrosshairPaint(UIAgent.getInstance().getColorWaterCrossHair());
    xyp.setDomainCrosshairPaint(UIAgent.getInstance().getColorWaterCrossHair());
    xyp.setRangeCrosshairLockedOnData(true);
    xyp.setDomainCrosshairLockedOnData(true);
    ((NumberAxis) xyp.getDomainAxis()).setNumberFormatOverride(new MinutesNumberFormat());

    XYAreaRenderer renderer0 = new XYAreaRenderer();
    renderer0.setOutline(true);
    renderer0.setBaseOutlinePaint(UIAgent.getInstance().getColorWaterBottom());

    Color baseColor = UIAgent.getInstance().getColorBaseBackground();
    renderer0.setSeriesPaint(0, new Color(baseColor.getRed(), baseColor.getGreen(), baseColor.getBlue(), 50));
    xyp.setRenderer(0, renderer0);

    createDecoWarningCollection();
    createAscentTooFastCollection();
    createRemainBottomTimeCollection();
    createDecoEntriesCollection();

    createGazMixCollection();

    chartPanel = new ChartPanel(chart);
    chart.setBackgroundPaint(null);
    chartPanel.setOpaque(false);

    chartPanel.addChartMouseListener(new ChartMouseListener() {

        @Override
        public void chartMouseMoved(ChartMouseEvent arg0) {
        }

        @Override
        public void chartMouseClicked(ChartMouseEvent evt) {

            SwingUtilities.invokeLater(new Runnable() {

                @Override
                public void run() {
                    double x = xyp.getDomainCrosshairValue();
                    double y = xyp.getRangeCrosshairValue();
                    Calendar cal = new GregorianCalendar(0, 0, 0, 0, 0, (int) x);
                    instantTimeTf.setText(new SimpleDateFormat("HH:mm:ss").format(cal.getTime()));
                    instantDepthTf.setText(StringManipulator.formatFixedDecimalNumber(y,
                            UIAgent.PRECISION_DEPTH, UIAgent.NUMBER_DECIMAL_CHAR));
                }
            });
        }
    });
    return chartPanel;
}

From source file:lcmc.common.ui.ResourceGraph.java

protected final void drawInsideVertex(final Graphics2D g2d, final Vertex v, final Color[] colors,
        final double x, final double y, final float height, final float width) {
    final int number = colors.length;
    if (number > 1) {
        for (int i = 1; i < number; i++) {
            final Paint p = new GradientPaint((float) x + width / number, (float) y,
                    getVertexFillSecondaryColor(v), (float) x + width / number, (float) y + height, colors[i],
                    false);/*from   ww  w.  ja v a  2s .  c  o  m*/
            g2d.setPaint(p);
            final Shape s = new Rectangle2D.Double(x + width / 2 + (width / number / 2) * i, y,
                    width / number / 2, height - 2);
            g2d.fill(s);
        }
    }
}

From source file:lcmc.gui.ResourceGraph.java

/** This method draws in the host vertex. */
protected final void drawInsideVertex(final Graphics2D g2d, final Vertex v, final Color[] colors,
        final double x, final double y, final float height, final float width) {
    final int number = colors.length;
    if (number > 1) {
        for (int i = 1; i < number; i++) {
            final Paint p = new GradientPaint((float) x + width / number, (float) y,
                    getVertexFillSecondaryColor(v), (float) x + width / number, (float) y + height, colors[i],
                    false);//from  www.j a v a  2  s . com
            g2d.setPaint(p);
            final Rectangle2D s = new Rectangle2D.Double(x + width / 2 + (width / number / 2) * i, y,
                    width / number / 2, height - 2);
            g2d.fill(s);
        }
    }
}

From source file:org.pentaho.platform.uifoundation.chart.JFreeChartEngine.java

/**
 * @param gradientNode//from w w  w  .  j  a  v  a2  s.c  om
 *          root node that hold gradient information
 * @return a gradientPaint implementation of Paint
 */
public static Paint getGradientPaint(final Node gradientNode, final int width, final int height) {

    if (gradientNode == null) {
        return null;
    }
    float x1 = 0;
    float y1 = 0;
    float x2 = width;
    float y2 = height;

    if (gradientNode.selectSingleNode(JFreeChartEngine.X1_NODE_NAME) != null) {
        x1 = Float.parseFloat(gradientNode.selectSingleNode(JFreeChartEngine.X1_NODE_NAME).getText());
    }
    if (gradientNode.selectSingleNode(JFreeChartEngine.Y1_NODE_NAME) != null) {
        y1 = Float.parseFloat(gradientNode.selectSingleNode(JFreeChartEngine.Y1_NODE_NAME).getText());
    }
    if (gradientNode.selectSingleNode(JFreeChartEngine.X2_NODE_NAME) != null) {
        x2 = Float.parseFloat(gradientNode.selectSingleNode(JFreeChartEngine.X2_NODE_NAME).getText());
    }
    if (gradientNode.selectSingleNode(JFreeChartEngine.Y2_NODE_NAME) != null) {
        y2 = Float.parseFloat(gradientNode.selectSingleNode(JFreeChartEngine.Y2_NODE_NAME).getText());
    }
    Color color1 = JFreeChartEngine
            .getColor(gradientNode.selectSingleNode(JFreeChartEngine.COLOR1_NODE_NAME).getText());
    Color color2 = JFreeChartEngine
            .getColor(gradientNode.selectSingleNode(JFreeChartEngine.COLOR2_NODE_NAME).getText());
    boolean cyclic = false;
    if (gradientNode.selectSingleNode(JFreeChartEngine.CYCLIC_NODE_NAME) != null) {
        cyclic = Boolean.valueOf(gradientNode.selectSingleNode(JFreeChartEngine.CYCLIC_NODE_NAME).getText())
                .booleanValue();
    }

    Paint paint = new GradientPaint(x1, y1, color1, x2, y2, color2, cyclic);
    return paint;
}

From source file:net.sf.fspdfs.chartthemes.simple.SimpleChartTheme.java

protected void setChartBackground(JFreeChart jfreeChart) {
    Paint backgroundPaint = getChartSettings().getBackgroundPaint() == null ? null
            : getChartSettings().getBackgroundPaint().getPaint();

    if (getChart().getOwnModeValue() != null) {
        if (getChart().getOwnModeValue() == ModeEnum.OPAQUE) {
            if (getChart().getOwnBackcolor() != null || backgroundPaint == null) {
                backgroundPaint = getChart().getBackcolor();
            }/*  www  .j av  a 2 s .  com*/
        } else {
            backgroundPaint = ChartThemesConstants.TRANSPARENT_PAINT;
        }
    }

    if (backgroundPaint != null) {
        GradientPaint gp = backgroundPaint instanceof GradientPaint ? (GradientPaint) backgroundPaint : null;
        if (gp != null) {
            backgroundPaint = new GradientPaint(0f, 0f, gp.getColor1(), 0f, getChart().getHeight() * 0.7f,
                    gp.getColor2(), false);
        }
        jfreeChart.setBackgroundPaint(backgroundPaint);
    }

    setChartBackgroundImage(jfreeChart);
}