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) 

Source Link

Document

Constructs a simple acyclic GradientPaint object.

Usage

From source file:org.hxzon.demo.jfreechart.CategoryDatasetDemo.java

private static JFreeChart createBarChart3D(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createBarChart3D("Bar Chart 3D Demo 1", // chart title
            "Category", // domain axis label
            "Value", // range axis label
            dataset, // data
            PlotOrientation.HORIZONTAL, // orientation
            true, // include legend
            true, // tooltips?
            false // URLs?
    );// ww  w . j av a  2  s .  c om

    chart.setBackgroundPaint(Color.white);

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setForegroundAlpha(0.5f);

    // set the range axis to display integers only...
    NumberAxis rangeAxis = (NumberAxis) plot.getRangeAxis();
    rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());

    BarRenderer3D renderer = (BarRenderer3D) plot.getRenderer();

    // set up gradient paints for series...
    GradientPaint gp0 = new GradientPaint(0.0f, 0.0f, Color.blue, 0.0f, 0.0f, new Color(0, 0, 64));
    GradientPaint gp1 = new GradientPaint(0.0f, 0.0f, Color.green, 0.0f, 0.0f, new Color(0, 64, 0));
    GradientPaint gp2 = new GradientPaint(0.0f, 0.0f, Color.red, 0.0f, 0.0f, new Color(64, 0, 0));
    renderer.setSeriesPaint(0, gp0);
    renderer.setSeriesPaint(1, gp1);
    renderer.setSeriesPaint(2, gp2);

    return chart;

}

From source file:com.sdk.connector.chart.CoherenceDomainRenderer.java

public CoherenceDomainRenderer(final String title, JPanel panel, String side) {
    sdf = Protocol.getInstance().getTimestampFormat();

    serieFFT.setKey(side + " FFT Based");
    serieLomb.setKey(side + " Lomb Based");
    serieMemse.setKey(side + " AR Based");

    dataset.addSeries(serieFFT);//from  w w  w. j a  va2 s. co  m
    dataset.addSeries(serieLomb);
    dataset.addSeries(serieMemse);

    chart = ChartFactory.createTimeSeriesChart(title,
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("coherence.xlabel"),
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("coherence.ylabel"),
            dataset, true, true, false);

    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    chart.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);

    chart.getRenderingHints().put(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    chart.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    chart.getRenderingHints().put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    chart.getRenderingHints().put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    chart.getRenderingHints().put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100);
    //chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.GREEN));
    // chart.setBackgroundPaint(new Color(220,255,220,0));
    //chart.setBackgroundImage(new javax.swing.ImageIcon(getClass().getResource("/com/sdk/connector/resources/background.png")).getImage());
    chart.addSubtitle(rangeAnnotation);
    plot = (XYPlot) chart.getPlot();

    XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer.setSeriesLinesVisible(0, true);
    renderer.setSeriesShapesVisible(0, true);
    renderer.setBaseToolTipGenerator(new StandardXYToolTipGenerator(
            StandardXYToolTipGenerator.DEFAULT_TOOL_TIP_FORMAT, sdf, new DecimalFormat("0.00")));
    renderer.setSeriesOutlinePaint(0, Color.BLACK);

    if (side.startsWith(
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("side.left"))) {
        renderer.setSeriesPaint(0, Color.BLUE);
        leftSide = true;
    } else {
        renderer.setSeriesPaint(0, Color.RED);
        leftSide = false;
    }
    renderer.setSeriesShape(0, new Ellipse2D.Double(-1.0, -1.0, 3.0, 3.0));

    DateTickUnit dtUnit = new DateTickUnit(DateTickUnitType.MINUTE, 1, tickSDF);
    final DateAxis domainAxis = (DateAxis) plot.getDomainAxis();
    domainAxis.setTickUnit(dtUnit);

    //        ValueAxis axis = plot.getDomainAxis();
    //        axis = plot.getRangeAxis();
    //        ((NumberAxis) axis).setTickUnit(new NumberTickUnit(100));

    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.BLACK);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(1.0f));
    // plot.getRenderer().setSeriesStroke(1, new BasicStroke(1.0f));
    plot.setForegroundAlpha(0.5f);
    plot.setNoDataMessage(
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("message.wait"));
    plot.setRangePannable(true);
    plot.setDomainPannable(true);
    Color color1 = new Color(0, 0, 0, 24);
    Color color2 = new Color(255, 255, 255, 24);

    GradientPaint gp = new GradientPaint(0, 0, color1, 0, 0, color2);
    plot.setBackgroundPaint(gp);

    chartPanel = new ChartPanel(chart);

    panel.setLayout(new GridLayout(0, 1));

    panel.add(chartPanel);
    panel.repaint();
    panel.revalidate();

}

From source file:forge.toolbox.FSkin.java

public static void setGraphicsGradientPaint(final Graphics2D g2d, final float x1, final float y1,
        final Color color1, final float x2, final float y2, final SkinColor skinColor2) {
    g2d.setPaint(new GradientPaint(x1, y1, color1, x2, y2, skinColor2.color));
}

From source file:com.cburch.logisim.gui.start.AboutCredits.java

@Override
protected void paintComponent(Graphics g) {
    FontMetrics[] fms = new FontMetrics[font.length];
    for (int i = 0; i < fms.length; i++) {
        fms[i] = g.getFontMetrics(font[i]);
    }/*from w  w w. j a  va2 s.c  om*/
    if (linesHeight == 0) {
        int y = 0;
        int index = -1;
        for (CreditsLine line : lines) {
            index++;
            if (index == initialLines)
                initialHeight = y;
            if (line.type == 0)
                y += 10;
            FontMetrics fm = fms[line.type];
            line.y = y + fm.getAscent();
            y += fm.getHeight();
        }
        linesHeight = y;
    }

    Paint[] paint = paintSteady;
    int yPos = 0;
    int height = getHeight();
    int initY = Math.min(0, initialHeight - height + About.IMAGE_BORDER);
    int maxY = linesHeight - height - initY;
    int totalMillis = 2 * MILLIS_FREEZE + (linesHeight + height) * MILLIS_PER_PIXEL;
    int offs = scroll % totalMillis;
    if (offs >= 0 && offs < MILLIS_FREEZE) {
        // frozen before starting the credits scroll
        int a = 255 * (MILLIS_FREEZE - offs) / MILLIS_FREEZE;
        if (a > 245) {
            paint = null;
        } else if (a < 15) {
            paint = paintSteady;
        } else {
            paint = new Paint[colorBase.length];
            for (int i = 0; i < paint.length; i++) {
                Color hue = colorBase[i];
                paint[i] = new GradientPaint(0.0f, 0.0f, derive(hue, a), 0.0f, fadeStop, hue);
            }
        }
        yPos = initY;
    } else if (offs < MILLIS_FREEZE + maxY * MILLIS_PER_PIXEL) {
        // scrolling through credits
        yPos = initY + (offs - MILLIS_FREEZE) / MILLIS_PER_PIXEL;
    } else if (offs < 2 * MILLIS_FREEZE + maxY * MILLIS_PER_PIXEL) {
        // freezing at bottom of scroll
        yPos = initY + maxY;
    } else if (offs < 2 * MILLIS_FREEZE + (linesHeight - initY) * MILLIS_PER_PIXEL) {
        // scrolling bottom off screen
        yPos = initY + (offs - 2 * MILLIS_FREEZE) / MILLIS_PER_PIXEL;
    } else {
        // scrolling next credits onto screen
        int millis = offs - 2 * MILLIS_FREEZE - (linesHeight - initY) * MILLIS_PER_PIXEL;
        paint = null;
        yPos = -height + millis / MILLIS_PER_PIXEL;
    }

    int width = getWidth();
    int centerX = width / 2;
    maxY = getHeight();
    for (CreditsLine line : lines) {
        int y = line.y - yPos;
        if (y < -100 || y > maxY + 50)
            continue;

        int type = line.type;
        if (paint == null) {
            g.setColor(colorBase[type]);
        } else {
            ((Graphics2D) g).setPaint(paint[type]);
        }
        g.setFont(font[type]);
        int textWidth = fms[type].stringWidth(line.text);
        g.drawString(line.text, centerX - textWidth / 2, line.y - yPos);

        Image img = line.img;
        if (img != null) {
            int x = width - line.imgWidth - About.IMAGE_BORDER;
            int top = y - fms[type].getAscent();
            g.drawImage(img, x, top, this);
        }
    }
}

From source file:org.fhaes.jsea.JSEABarChart.java

/**
 * Returns an array of paint objects that will be used for the bar colors. this method sets the colors for each bar.
 * /*from  w w  w.j a v a 2  s .co  m*/
 * @return An array of paint objects.
 */
private static Paint[] createPaint(int lengthOfWindow, Color color) {

    Paint[] colors = new Paint[lengthOfWindow];
    for (int i = 0; i <= lengthOfWindow - 1; i++) {
        colors[i] = new GradientPaint(0f, 0f, color, 0f, 0f, color);
        // colors[i] = new GradientPaint(0f, 0f, Color.pink, 0f, 0f, Color.yellow);
    }
    for (int i = 0; i <= lengthOfWindow - 1; i++) {
        if (meanByWindow[i] > leftEndPointSim[i][alphaLevel]
                && meanByWindow[i] < rightEndPointSim[i][alphaLevel]) {
            colors[i] = new GradientPaint(0f, 0f, Color.darkGray, 0f, 0f, Color.darkGray);
            // colors[i] = new GradientPaint(0f, 0f, Color.CYAN, 0f, 0f,
            // Color.ORANGE);
        }
    }
    return colors;
}

From source file:edu.ucla.stat.SOCR.chart.demo.StackedBarChartDemo4.java

/**
 * Creates a sample chart./* w  ww  .j  ava2 s . c  om*/
 * 
 * @param dataset  the dataset for the chart.
 * 
 * @return A sample chart.
 */
protected JFreeChart createChart(CategoryDataset dataset) {

    JFreeChart chart = ChartFactory.createStackedBarChart(chartTitle, // chart title
            domainLabel, // domain axis label
            rangeLabel, // range axis label
            dataset, // data
            PlotOrientation.VERTICAL, // the plot orientation
            !legendPanelOn, // legend
            true, // tooltips
            false // urls
    );

    GroupedStackedBarRenderer renderer = new GroupedStackedBarRenderer();
    KeyToGroupMap map = new KeyToGroupMap("G1");
    map.mapKeyToGroup("Product 1 (US)", "G1");
    map.mapKeyToGroup("Product 1 (Europe)", "G1");
    map.mapKeyToGroup("Product 1 (Asia)", "G1");
    map.mapKeyToGroup("Product 1 (Middle East)", "G1");
    map.mapKeyToGroup("Product 2 (US)", "G2");
    map.mapKeyToGroup("Product 2 (Europe)", "G2");
    map.mapKeyToGroup("Product 2 (Asia)", "G2");
    map.mapKeyToGroup("Product 2 (Middle East)", "G2");
    map.mapKeyToGroup("Product 3 (US)", "G3");
    map.mapKeyToGroup("Product 3 (Europe)", "G3");
    map.mapKeyToGroup("Product 3 (Asia)", "G3");
    map.mapKeyToGroup("Product 3 (Middle East)", "G3");
    renderer.setSeriesToGroupMap(map);

    renderer.setItemMargin(0.10);
    renderer.setDrawBarOutline(false);
    Paint p1 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0x22, 0xFF), 0.0f, 0.0f,
            new Color(0x88, 0x88, 0xFF));
    renderer.setSeriesPaint(0, p1);
    renderer.setSeriesPaint(4, p1);
    renderer.setSeriesPaint(8, p1);

    Paint p2 = new GradientPaint(0.0f, 0.0f, new Color(0x22, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0x88, 0xFF, 0x88));
    renderer.setSeriesPaint(1, p2);
    renderer.setSeriesPaint(5, p2);
    renderer.setSeriesPaint(9, p2);

    Paint p3 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0x22, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0x88, 0x88));
    renderer.setSeriesPaint(2, p3);
    renderer.setSeriesPaint(6, p3);
    renderer.setSeriesPaint(10, p3);

    Paint p4 = new GradientPaint(0.0f, 0.0f, new Color(0xFF, 0xFF, 0x22), 0.0f, 0.0f,
            new Color(0xFF, 0xFF, 0x88));
    renderer.setSeriesPaint(3, p4);
    renderer.setSeriesPaint(7, p4);
    renderer.setSeriesPaint(11, p4);
    renderer.setGradientPaintTransformer(
            new StandardGradientPaintTransformer(GradientPaintTransformType.HORIZONTAL));

    renderer.setLegendItemLabelGenerator(new SOCRCategorySeriesLabelGenerator());

    SubCategoryAxis domainAxis = new SubCategoryAxis("Product / Month");
    domainAxis.setCategoryMargin(0.05);
    domainAxis.addSubCategory("Product 1");
    domainAxis.addSubCategory("Product 2");
    domainAxis.addSubCategory("Product 3");

    CategoryPlot plot = (CategoryPlot) chart.getPlot();
    plot.setDomainAxis(domainAxis);
    //plot.setDomainAxisLocation(AxisLocation.TOP_OR_RIGHT);
    plot.setRenderer(renderer);
    //   plot.setFixedLegendItems(createLegendItems());

    setCategorySummary(dataset);
    return chart;

}

From source file:forge.toolbox.FSkin.java

public static void setGraphicsGradientPaint(final Graphics2D g2d, final float x1, final float y1,
        final SkinColor skinColor1, final float x2, final float y2, final Color color2) {
    g2d.setPaint(new GradientPaint(x1, y1, skinColor1.color, x2, y2, color2));
}

From source file:com.polivoto.vistas.acciones.Datos.java

private JFreeChart createChartBar(CategoryDataset dataset) {
    JFreeChart chart = ChartFactory.createBarChart("Votacion", "Opciones", "Total de votos", dataset,
            PlotOrientation.VERTICAL, true, true, true);
    try {/*from ww  w.  j  a  v  a  2s . c  o m*/

        chart.addSubtitle(new TextTitle(ac.getPreguntas().getJSONObject(pox).getString("pregunta")));
        chart.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, Color.white));
        CategoryPlot plot = chart.getCategoryPlot();
        org.jfree.chart.axis.CategoryAxis axis = plot.getDomainAxis();
        axis.setCategoryLabelPositions(
                CategoryLabelPositions.createUpRotationLabelPositions(0.39269908169872414D));
        //            final CategoryItemRenderer itemRenderer = new CustomRenderer(
        //                    new Paint[] {Color.green, Color.red, Color.blue, Color.yellow, Color.magenta, Color.cyan, Color.pink, Color.lightGray}
        //            );
        ////        itemRenderer.setBaseItemLabelsVisible(true);
        ////        BarRenderer barRenderer = (BarRenderer)itemRenderer;
        ////        barRenderer.setItemMargin(0.2D);
        ////        plot.setBackgroundPaint(new GradientPaint(0, 0, Color.white, 0, 1000, new java.awt.Color(147, 60, 45)));
        ////        //        StandardCategoryToolTipGenerator toolTipGenerator = new StandardCategoryToolTipGenerator("{0}: {2} %", new DecimalFormat("0"));
        //            //
        //            plot.setNoDataMessage("SIN DATOS!");
        //            
        //            
        ////        renderer.setLabelGenerator(new StandardCategoryLabelGenerator());
        //            itemRenderer.setItemLabelsVisible(true);
        //            final ItemLabelPosition p = new ItemLabelPosition(
        //                    ItemLabelAnchor.CENTER, TextAnchor.CENTER, TextAnchor.CENTER, 45.0
        //            );
        //            itemRenderer.setPositiveItemLabelPosition(p);
        //            plot.setRenderer(itemRenderer);

        // change the margin at the top of the range axis...
        final ValueAxis rangeAxis = plot.getRangeAxis();
        rangeAxis.setStandardTickUnits(NumberAxis.createIntegerTickUnits());
        rangeAxis.setLowerMargin(0.15);
        rangeAxis.setUpperMargin(0.15);

    } catch (JSONException ex) {
        Logger.getLogger(Datos.class.getName()).log(Level.SEVERE, null, ex);
    }
    return chart;
}

From source file:savant.view.swing.GraphPane.java

public boolean render(Graphics2D g2, Range xRange, Range yRange) {
    LOG.trace("GraphPane.render(g2, " + xRange + ", " + yRange + ")");
    double oldUnitHeight = unitHeight;
    int oldYMax = yMax;

    // Paint a gradient from top to bottom
    GradientPaint gp0 = new GradientPaint(0, 0, ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_TOP), 0,
            getHeight(), ColourSettings.getColor(ColourKey.GRAPH_PANE_BACKGROUND_BOTTOM));
    g2.setPaint(gp0);//  w w  w . j ava 2s .co m
    g2.fillRect(0, 0, getWidth(), getHeight());

    GraphPaneController gpc = GraphPaneController.getInstance();
    LocationController lc = LocationController.getInstance();
    JScrollBar scroller = getVerticalScrollBar();

    if (gpc.isPanning() && !isLocked()) {

        double fromX = transformXPos(gpc.getMouseClickPosition());
        double toX = transformXPos(gpc.getMouseReleasePosition());
        g2.translate(toX - fromX, 0);
    }

    // Deal with the progress-bar.
    if (tracks == null) {
        parentFrame.updateProgress();
        return false;
    } else {
        for (Track t : tracks) {
            if (t.getRenderer().isWaitingForData()) {
                String progressMsg = (String) t.getRenderer().getInstruction(DrawingInstruction.PROGRESS);
                setPreferredSize(new Dimension(getWidth(), 0));
                showProgress(progressMsg, -1.0);
                return false;
            }
        }
    }
    if (progressPanel != null) {
        remove(progressPanel);
        progressPanel = null;
    }

    int minYRange = Integer.MAX_VALUE;
    int maxYRange = Integer.MIN_VALUE;
    AxisType bestYAxis = AxisType.NONE;
    for (Track t : tracks) {

        // ask renderers for extra info on range; consolidate to maximum Y range
        AxisRange axisRange = (AxisRange) t.getRenderer().getInstruction(DrawingInstruction.AXIS_RANGE);

        if (axisRange != null) {
            int axisYMin = axisRange.getYMin();
            int axisYMax = axisRange.getYMax();
            if (axisYMin < minYRange) {
                minYRange = axisYMin;
            }
            if (axisYMax > maxYRange) {
                maxYRange = axisYMax;
            }
        }

        // Ask renderers if they want horizontal grid-lines; if any say yes, draw them.
        switch (t.getYAxisType(t.getResolution(xRange))) {
        case INTEGER_GRIDLESS:
            if (bestYAxis == AxisType.NONE) {
                bestYAxis = AxisType.INTEGER_GRIDLESS;
            }
            break;
        case INTEGER:
            if (bestYAxis != AxisType.REAL) {
                bestYAxis = AxisType.INTEGER;
            }
            break;
        case REAL:
            bestYAxis = AxisType.REAL;
            break;
        }
    }

    setXAxisType(tracks[0].getXAxisType(tracks[0].getResolution(xRange)));
    setXRange(xRange);
    setYAxisType(bestYAxis);
    Range consolidatedYRange = new Range(minYRange, maxYRange);

    setYRange(consolidatedYRange);
    consolidatedYRange = new Range(yMin, yMax);

    DrawingMode currentMode = tracks[0].getDrawingMode();

    boolean sameRange = (prevRange != null && xRange.equals(prevRange));
    if (!sameRange) {
        PopupPanel.hidePopup();
    }
    boolean sameMode = currentMode == prevMode;
    boolean sameSize = prevSize != null && getSize().equals(prevSize)
            && parentFrame.getFrameLandscape().getWidth() == oldWidth
            && parentFrame.getFrameLandscape().getHeight() == oldHeight;
    boolean sameRef = prevRef != null && lc.getReferenceName().equals(prevRef);
    boolean withinScrollBounds = bufferedImage != null && scroller.getValue() >= getOffset()
            && scroller.getValue() < getOffset() + getViewportHeight() * 2;

    //bufferedImage stores the current graphic for future use. If nothing
    //has changed in the track since the last render, bufferedImage will
    //be used to redraw the current view. This method allows for fast repaints
    //on tracks where nothing has changed (panning, selection, plumbline,...)

    //if nothing has changed draw buffered image
    if (sameRange && sameMode && sameSize && sameRef && !renderRequired && withinScrollBounds) {
        g2.drawImage(bufferedImage, 0, getOffset(), this);
        renderCurrentSelected(g2);

        //force unitHeight from last render
        unitHeight = oldUnitHeight;
        yMax = oldYMax;

    } else {
        // Otherwise prepare for new render.
        renderRequired = false;

        int h = getHeight();
        if (!forcedHeight) {
            h = Math.min(h, getViewportHeight() * 3);
        }
        LOG.debug("Requesting " + getWidth() + "\u00D7" + h + " bufferedImage.");
        bufferedImage = new BufferedImage(getWidth(), h, BufferedImage.TYPE_INT_RGB);
        if (bufferedImage.getHeight() == getHeight()) {
            setOffset(0);
        } else {
            setOffset(scroller.getValue() - getViewportHeight());
        }
        LOG.debug("Rendering fresh " + bufferedImage.getWidth() + "\u00D7" + bufferedImage.getHeight()
                + " bufferedImage at (0, " + getOffset() + ")");

        Graphics2D g3 = bufferedImage.createGraphics();
        g3.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
        prevRange = xRange;
        prevSize = getSize();
        prevMode = tracks[0].getDrawingMode();
        prevRef = lc.getReferenceName();

        renderBackground(g3, xAxisType == AxisType.INTEGER || xAxisType == AxisType.REAL,
                yAxisType == AxisType.INTEGER || yAxisType == AxisType.REAL);

        // Call the actual render() methods.
        boolean nothingRendered = true;
        String message = null;
        int priority = -1;

        for (Track t : tracks) {
            // Change renderers' drawing instructions to reflect consolidated YRange
            AxisRange axes = (AxisRange) t.getRenderer().getInstruction(DrawingInstruction.AXIS_RANGE);

            if (axes == null) {
                axes = new AxisRange(xRange, consolidatedYRange);
            } else {
                axes = new AxisRange(axes.getXRange(), consolidatedYRange);
            }

            //System.out.println("Consolidated y range for " + t.getName() + " is " + consolidatedYRange);
            t.getRenderer().addInstruction(DrawingInstruction.AXIS_RANGE, axes);

            try {
                t.getRenderer().render(g3, this);
                nothingRendered = false;
            } catch (RenderingException rx) {
                if (rx.getPriority() > priority) {
                    // If we have more than one message with the same priority, the first one will end up being drawn.
                    message = rx.getMessage();
                    priority = rx.getPriority();
                }
            } catch (Throwable x) {
                // Renderer itself threw an exception.
                LOG.error("Error rendering " + t, x);
                message = MiscUtils.getMessage(x);
                priority = RenderingException.ERROR_PRIORITY;
            }
        }
        if (nothingRendered && message != null) {
            setPreferredSize(new Dimension(getWidth(), 0));
            revalidate();
            drawMessage(g3, message);
        }

        updateYMax();

        // If a change has occured that affects scrollbar...
        if (paneResize) {
            paneResize = false;

            // Change size of current frame
            if (getHeight() != newHeight) {
                Dimension newSize = new Dimension(getWidth(), newHeight);
                setPreferredSize(newSize);
                setSize(newSize);
                parentFrame.validate(); // Ensures that scroller.getMaximum() is up to date.

                // If pane is resized, scrolling always starts at the bottom.  The only place
                // where looks wrong is when we have a continuous track with negative values.
                scroller.setValue(scroller.getMaximum());
                repaint();
                return false;
            }
        } else if (oldViewHeight != -1 && oldViewHeight != getViewportHeight()) {
            int newViewHeight = getViewportHeight();
            int oldScroll = scroller.getValue();
            scroller.setValue(oldScroll + (oldViewHeight - newViewHeight));
            oldViewHeight = newViewHeight;
        }
        oldWidth = parentFrame.getFrameLandscape().getWidth();
        oldHeight = parentFrame.getFrameLandscape().getHeight();

        g2.drawImage(bufferedImage, 0, getOffset(), this);
        fireExportEvent(xRange, bufferedImage);

        renderCurrentSelected(g2);
    }
    return true;
}

From source file:com.sdk.connector.chart.FrequencyDomainRenderer.java

/**
 * Creates a new demo application.//from ww w .  jav  a  2 s  .co m
 *
 * @param title  the frame title.
 */
public FrequencyDomainRenderer(String title, JPanel panel, String side, String type) {

    this.side = side;
    this.type = type;
    serie.setKey(side);

    dataset.addSeries(serie);
    JFreeChart chart = ChartFactory.createXYAreaChart(title,
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("frequency.xlabel"),
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("frequency.ylabel2"),
            dataset, PlotOrientation.VERTICAL, true, true, false);

    //        TextTitle t1 = new TextTitle( "Espectro de Frequncia Estimado (PSD)", new Font("SansSerif", Font.BOLD, 14)  );
    //        //TextTitle t2 = new TextTitle( "valores atualizados a cada potncia de 2", new Font("SansSerif", Font.PLAIN, 11)      );
    //        chart.addSubtitle(t1);
    chart.getRenderingHints().put(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON);
    chart.getRenderingHints().put(RenderingHints.KEY_RENDERING, RenderingHints.VALUE_RENDER_QUALITY);
    chart.getRenderingHints().put(RenderingHints.KEY_ALPHA_INTERPOLATION,
            RenderingHints.VALUE_ALPHA_INTERPOLATION_QUALITY);
    chart.getRenderingHints().put(RenderingHints.KEY_FRACTIONALMETRICS,
            RenderingHints.VALUE_FRACTIONALMETRICS_ON);
    chart.getRenderingHints().put(RenderingHints.KEY_INTERPOLATION, RenderingHints.VALUE_INTERPOLATION_BICUBIC);
    chart.getRenderingHints().put(RenderingHints.KEY_STROKE_CONTROL, RenderingHints.VALUE_STROKE_NORMALIZE);
    chart.getRenderingHints().put(RenderingHints.KEY_TEXT_ANTIALIASING, RenderingHints.VALUE_TEXT_ANTIALIAS_ON);
    chart.getRenderingHints().put(RenderingHints.KEY_TEXT_LCD_CONTRAST, 100);
    //chart.addSubtitle(t2);
    plot = (XYPlot) chart.getPlot();
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.BLUE);
    plot.setRangeGridlinePaint(Color.CYAN);
    plot.getRenderer().setSeriesStroke(0, new BasicStroke(2.0f));
    plot.getRenderer().setSeriesStroke(1, new BasicStroke(2.0f));

    //plot.setRangePannable(true);
    plot.setForegroundAlpha(0.65f);

    //XYLineAndShapeRenderer renderer = new XYLineAndShapeRenderer();
    renderer = plot.getRenderer();
    renderer.setSeriesOutlinePaint(0, Color.BLACK);
    if (side.startsWith(
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("side.left"))) {
        renderer.setSeriesPaint(0, Color.BLUE);
    } else {
        renderer.setSeriesPaint(0, Color.RED);
    }
    //        renderer.setSeriesLinesVisible(0, true);
    //        renderer.setSeriesShapesVisible(0, false);
    //        renderer.setSeriesLinesVisible(1, true);
    //        renderer.setSeriesShapesVisible(1, false);
    plot.setRenderer(renderer);
    plot.setBackgroundPaint(Color.WHITE);
    plot.setDomainGridlinePaint(Color.BLACK);
    plot.setRangeGridlinePaint(Color.BLACK);
    plot.setForegroundAlpha(0.5f);

    Color color1 = new Color(0, 0, 0, 24);
    Color color2 = new Color(255, 255, 255, 24);

    GradientPaint gp = new GradientPaint(0, 0, color1, 0, 0, color2);
    plot.setBackgroundPaint(gp);

    final ValueAxis domainAxis = plot.getDomainAxis();
    domainAxis.setTickMarkPaint(Color.black);
    domainAxis.setLowerMargin(0.0);
    domainAxis.setUpperMargin(0.0);
    NumberAxis numDomainAxis = (NumberAxis) plot.getDomainAxis();
    numDomainAxis.setAutoRangeIncludesZero(true);
    //
    //        final NumberAxis rangeAxis = new LogarithmicAxis("Log(y)");
    //
    //        plot.setRangeAxis(rangeAxis);
    final ValueAxis rangeAxis = plot.getRangeAxis();
    rangeAxis.setTickMarkPaint(Color.black);

    numRangeAxis = (NumberAxis) plot.getRangeAxis();
    numRangeAxis.setAutoRangeIncludesZero(true);

    vlfTarget.setLabel("VLF");
    vlfTarget.setLabelFont(new Font("SansSerif", Font.ITALIC, 9));
    vlfTarget.setLabelAnchor(RectangleAnchor.CENTER);
    vlfTarget.setLabelTextAnchor(TextAnchor.CENTER);
    vlfTarget.setPaint(new Color(0, 100, 255, 128));
    // plot.addRangeMarker(target, Layer.BACKGROUND);
    plot.addDomainMarker(vlfTarget, Layer.BACKGROUND);

    lfTarget.setLabel("LF");
    lfTarget.setLabelFont(new Font("SansSerif", Font.ITALIC, 9));
    lfTarget.setLabelAnchor(RectangleAnchor.CENTER);
    lfTarget.setLabelTextAnchor(TextAnchor.CENTER);
    lfTarget.setPaint(new Color(255, 255, 0, 128));
    // plot.addRangeMarker(target, Layer.BACKGROUND);
    plot.addDomainMarker(lfTarget, Layer.BACKGROUND);

    hfTarget.setLabel("HF");
    hfTarget.setLabelFont(new Font("SansSerif", Font.ITALIC, 9));
    hfTarget.setLabelAnchor(RectangleAnchor.CENTER);
    hfTarget.setLabelTextAnchor(TextAnchor.CENTER);
    hfTarget.setPaint(new Color(255, 0, 255, 128));
    // plot.addRangeMarker(target, Layer.BACKGROUND);
    plot.addDomainMarker(hfTarget, Layer.BACKGROUND);
    plot.setNoDataMessage(
            java.util.ResourceBundle.getBundle("com/sdk/connector/chart/Bundle").getString("message.wait"));

    chartPanel = new ChartPanel(chart);

    panel.setLayout(new GridLayout(0, 1));
    panel.add(chartPanel);
    panel.repaint();
    panel.revalidate();

}