Example usage for org.jfree.chart.plot XYPlot getBackgroundPaint

List of usage examples for org.jfree.chart.plot XYPlot getBackgroundPaint

Introduction

In this page you can find the example usage for org.jfree.chart.plot XYPlot getBackgroundPaint.

Prototype

public Paint getBackgroundPaint() 

Source Link

Document

Returns the background color of the plot area.

Usage

From source file:tdunnick.jphineas.console.queue.Charts.java

private JFreeChart createLineChart(String title, String constraint, XYDataset dataset) {
    // create the chart...
    JFreeChart chart = ChartFactory.createXYLineChart(title, "Date/Time", // x axis label
            null, // y axis label
            dataset, // data
            PlotOrientation.VERTICAL, true, // include legend
            true, // tooltips
            false // urls
    );/*from ww  w  .j  a  va 2s. co m*/
    XYPlot plot = chart.getXYPlot();
    // X axis shows dates
    plot.setDomainAxis(new DateAxis());
    // if data has a constraint, hide every thing else
    if (constraint != null) {
        chart.removeLegend();
        XYDataset data = plot.getDataset();
        Paint bg = plot.getBackgroundPaint();
        for (int i = 0; i < data.getSeriesCount(); i++) {
            if (!constraint.equals(data.getSeriesKey(i)))
                plot.getRenderer().setSeriesPaint(i, bg);
            else {
                // get a color match...
                plot.getRenderer().setSeriesPaint(i, DefaultDrawingSupplier.DEFAULT_PAINT_SEQUENCE[i]);
                // reset plot range for this maximum
                double d = 0;
                for (int j = 0; j < data.getItemCount(i); j++) {
                    if (d < data.getYValue(i, j))
                        d = data.getYValue(i, j);
                }
                // add a bit for top margin
                d += d * 0.04;
                plot.getRangeAxis().setUpperBound(d);
            }
        }
    }
    return chart;
}

From source file:org.cds06.speleograph.graph.GraphEditor.java

/**
 * Creates a modal dialog by specifying the attached {@link GraphPanel}.
 * <p>Please look at {@link javax.swing.JDialog#JDialog()} to see defaults params applied to this Dialog.</p>
 *///from w  ww.j a  v a  2  s  .c  o  m
public GraphEditor(GraphPanel panel) {
    super((Frame) SwingUtilities.windowForComponent(panel), true);
    Validate.notNull(panel);
    this.graphPanel = panel;

    KeyStroke stroke = KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0);
    mainPanel.registerKeyboardAction(new ActionListener() {
        @Override
        public void actionPerformed(ActionEvent e) {
            setVisible(false);
        }
    }, stroke, JComponent.WHEN_IN_FOCUSED_WINDOW);

    setContentPane(mainPanel);
    mainPanel.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    this.setTitle(I18nSupport.translate("menus.graph.graphEditor"));

    {
        // This section use FormLayout which is an external layout for Java, consult the doc before edit the
        // following lines !
        final FormLayout layout = new FormLayout(
                "right:max(40dlu;p), 4dlu, p:grow, 4dlu, p, 4dlu, p:grow, 4dlu, p", //NON-NLS
                "p,4dlu,p,4dlu,p,4dlu,p,4dlu,p" //NON-NLS
        );

        PanelBuilder builder = new PanelBuilder(layout);

        final JLabel colorLabel = new JLabel();
        final JTextField titleForGraph = new JTextField(
                graphPanel.getChart().getTitle() != null ? graphPanel.getChart().getTitle().getText() : "");
        final JLabel colorXYPlotLabel = new JLabel();
        final JLabel colorGridLabel = new JLabel();
        final JCheckBox showLegendCheckBox = new JCheckBox("Afficher la lgende",
                graphPanel.getChart().getLegend().isVisible());

        {
            builder.addLabel("Titre :", "1,1");
            builder.add(titleForGraph, "3,1,7,1");
        }

        {
            builder.addLabel(I18nSupport.translate("menus.graph.graphEditor.backgroundColor"), "1,3");
            colorLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
            colorLabel.setText(" ");
            colorLabel.setBackground((Color) graphPanel.getChart().getBackgroundPaint());
            colorLabel.setOpaque(true);
            colorLabel.setEnabled(false);
            final JButton edit = new JButton(I18nSupport.translate("menus.graph.graphEditor.edit"));
            edit.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    Color c = JColorChooser.showDialog(GraphEditor.this,
                            I18nSupport.translate("menus.graph.graphEditor.selectColor"),
                            colorLabel.getBackground());
                    if (c != null) {
                        colorLabel.setBackground(c);
                    }
                }
            });
            builder.add(colorLabel, "3,3,5,1");
            builder.add(edit, "9,3");
        }

        final XYPlot xyPlot = graphPanel.getChart().getXYPlot();
        {
            builder.addLabel(I18nSupport.translate("menus.graph.graphEditor.graphColor"), "1,5");
            colorXYPlotLabel.setText(" ");
            colorXYPlotLabel.setOpaque(true);
            colorXYPlotLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
            colorXYPlotLabel.setBackground((Color) xyPlot.getBackgroundPaint());
            colorXYPlotLabel.setEnabled(false);
            final JButton edit = new JButton(I18nSupport.translate("menus.graph.graphEditor.edit"));
            edit.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    Color c = JColorChooser.showDialog(GraphEditor.this,
                            I18nSupport.translate("menus.graph.graphEditor.selectColor"),
                            colorXYPlotLabel.getBackground());
                    if (c != null) {
                        colorXYPlotLabel.setBackground(c);
                    }
                }
            });
            builder.add(colorXYPlotLabel, "3,5,5,1");
            builder.add(edit, "9,5");
        }

        {
            builder.addLabel(I18nSupport.translate("menus.graph.graphEditor.gridColor"), "1,7");
            colorGridLabel.setOpaque(true);
            colorGridLabel.setText(" ");
            colorGridLabel.setBorder(BorderFactory.createLineBorder(Color.BLACK));
            colorGridLabel.setBackground((Color) xyPlot.getRangeGridlinePaint());
            colorGridLabel.setEnabled(false);
            final JButton edit = new JButton(I18nSupport.translate("menus.graph.graphEditor.edit"));
            edit.addActionListener(new ActionListener() {
                @Override
                public void actionPerformed(ActionEvent e) {
                    Color c = JColorChooser.showDialog(GraphEditor.this,
                            I18nSupport.translate("menus.graph.graphEditor.selectColor"),
                            colorGridLabel.getBackground());
                    if (c != null) {
                        colorGridLabel.setBackground(c);
                    }
                }
            });
            builder.add(colorGridLabel, "3,7,5,1");
            builder.add(edit, "9,7");
        }

        {
            builder.add(showLegendCheckBox, "1,9,9,1");
        }

        mainPanel.add(builder.build(), BorderLayout.CENTER);

        ButtonBarBuilder buttonBarBuilder = new ButtonBarBuilder();

        buttonBarBuilder.addGlue();

        buttonBarBuilder.addButton(new AbstractAction() {
            {
                putValue(NAME, I18nSupport.translate("cancel"));
            }

            @Override
            public void actionPerformed(ActionEvent e) {
                GraphEditor.this.setVisible(false);
            }
        });

        buttonBarBuilder.addButton(new AbstractAction() {

            {
                putValue(NAME, I18nSupport.translate("ok"));
            }

            @Override
            public void actionPerformed(ActionEvent e) {
                if (titleForGraph.getText().isEmpty())
                    graphPanel.getChart().setTitle((String) null);
                else
                    graphPanel.getChart().setTitle(titleForGraph.getText());
                {
                    Color c = colorGridLabel.getBackground();
                    xyPlot.setRangeGridlinePaint(c);
                    xyPlot.setRangeMinorGridlinePaint(c);
                    xyPlot.setDomainGridlinePaint(c);
                    xyPlot.setDomainMinorGridlinePaint(c);
                }
                graphPanel.getChart().setBackgroundPaint(colorLabel.getBackground());
                xyPlot.setBackgroundPaint(colorXYPlotLabel.getBackground());
                graphPanel.getChart().getLegend().setVisible(showLegendCheckBox.isSelected());
                GraphEditor.this.setVisible(false);
            }
        });

        mainPanel.add(buttonBarBuilder.build(), BorderLayout.SOUTH);
    }

    pack();
    Dimension d = this.getPreferredSize();
    this.setSize(new Dimension(d.width + 20, d.height));
    setResizable(false);
}

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

private void configureGradientAreaFill(Graphics2D g2, XYPlot plot, PlotRenderingInfo info, Paint itemPaint,
        GradientLineAreaFill gradientLineAreaFill) {
    final Rectangle2D plotArea = info.getPlotArea();
    double plotWidth = plotArea.getWidth();
    double plotHeight = plotArea.getHeight();
    Double mainColorTransparency = gradientLineAreaFill.getMaxValueTransparency();
    Double bgColorTransparency = gradientLineAreaFill.getMinValueTransparency();

    if (itemPaint instanceof Color) {
        Color itemColor = (Color) itemPaint;
        int red = itemColor.getRed();
        int green = itemColor.getGreen();
        int blue = itemColor.getBlue();
        int mainColorAlpha = (mainColorTransparency >= 0.0 && mainColorTransparency <= 1.0)
                ? Math.round(255 * mainColorTransparency.floatValue())
                : 150;/*from  www .jav  a 2  s  . c om*/
        int bgColorAlpha = (bgColorTransparency >= 0.0 && bgColorTransparency <= 1.0)
                ? Math.round(255 * bgColorTransparency.floatValue())
                : 128;

        Color mainColor = new Color(red, green, blue, mainColorAlpha);
        Paint bgColor = getBackgroundPaint();
        if (bgColor == null) {
            bgColor = plot.getBackgroundPaint();
        }
        Color secondaryColor = getSecondaryColor(bgColorAlpha, bgColor);

        Paint areaPaint = getAreaFillPaint(plot, plotWidth, plotHeight, mainColor, secondaryColor);
        g2.setPaint(areaPaint);
    } else {
        g2.setPaint(itemPaint);
    }
}