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

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

Introduction

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

Prototype

public Paint getBackgroundPaint() 

Source Link

Document

Returns the background color of the plot area.

Usage

From source file:daylightchart.options.chart.PlotOptions.java

/**
 * {@inheritDoc}/*ww w  . j a  v  a  2s  .c o  m*/
 *
 * @see BaseChartOptions#copyFromChart(org.jfree.chart.JFreeChart)
 */
@Override
public void copyFromChart(final JFreeChart chart) {
    final Plot plot = chart.getPlot();

    backgroundPaint = plot.getBackgroundPaint();
    outlinePaint = plot.getOutlinePaint();
    outlineStroke = plot.getOutlineStroke();
    insets = plot.getInsets();
    //
    // Update axes
    Axis domainAxis = null;
    if (plot instanceof CategoryPlot) {
        final CategoryPlot p = (CategoryPlot) plot;
        domainAxis = p.getDomainAxis();
    } else if (plot instanceof XYPlot) {
        final XYPlot p = (XYPlot) plot;
        domainAxis = p.getDomainAxis();
    }
    if (domainAxis != null) {
        domainAxisOptions.getAxisProperties(domainAxis);
    }

    Axis rangeAxis = null;
    if (plot instanceof CategoryPlot) {
        final CategoryPlot p = (CategoryPlot) plot;
        rangeAxis = p.getRangeAxis();
    } else if (plot instanceof XYPlot) {
        final XYPlot p = (XYPlot) plot;
        rangeAxis = p.getRangeAxis();
    }
    if (rangeAxis != null) {
        rangeAxisOptions.getAxisProperties(rangeAxis);
    }
}

From source file:ch.zhaw.simulation.diagram.charteditor.DefaultPlotEditor.java

/**
 * Standard constructor - constructs a panel for editing the properties of
 * the specified plot.//from w w w  . j av a2 s. c om
 * <P>
 * In designing the panel, we need to be aware that subclasses of Plot will
 * need to implement subclasses of PlotPropertyEditPanel - so we need to
 * leave one or two 'slots' where the subclasses can extend the user
 * interface.
 * 
 * @param plot
 *            the plot, which should be changed.
 */
public DefaultPlotEditor(Plot plot) {
    this.plotInsets = plot.getInsets();
    this.backgroundPaintSample = new PaintSample(plot.getBackgroundPaint());
    this.outlineStrokeSample = new StrokeSample(plot.getOutlineStroke());
    this.outlinePaintSample = new PaintSample(plot.getOutlinePaint());
    // Disabled because makes no sense for us
    // if (plot instanceof CategoryPlot) {
    // this.plotOrientation = ((CategoryPlot) plot).getOrientation();
    // } else if (plot instanceof XYPlot) {
    // this.plotOrientation = ((XYPlot) plot).getOrientation();
    // }
    if (plot instanceof CategoryPlot) {
        CategoryItemRenderer renderer = ((CategoryPlot) plot).getRenderer();
        if (renderer instanceof LineAndShapeRenderer) {
            LineAndShapeRenderer r = (LineAndShapeRenderer) renderer;
            this.drawLines = BooleanUtilities.valueOf(r.getBaseLinesVisible());
            this.drawShapes = BooleanUtilities.valueOf(r.getBaseShapesVisible());
        }
    } else if (plot instanceof XYPlot) {
        XYItemRenderer renderer = ((XYPlot) plot).getRenderer();
        if (renderer instanceof StandardXYItemRenderer) {
            StandardXYItemRenderer r = (StandardXYItemRenderer) renderer;
            this.drawLines = BooleanUtilities.valueOf(r.getPlotLines());
            this.drawShapes = BooleanUtilities.valueOf(r.getBaseShapesVisible());
        }
    }

    setLayout(new BorderLayout());

    this.availableStrokeSamples = new StrokeSample[4];
    this.availableStrokeSamples[0] = new StrokeSample(null);
    this.availableStrokeSamples[1] = new StrokeSample(new BasicStroke(1.0f));
    this.availableStrokeSamples[2] = new StrokeSample(new BasicStroke(2.0f));
    this.availableStrokeSamples[3] = new StrokeSample(new BasicStroke(3.0f));

    // create a panel for the settings...
    JPanel panel = new JPanel(new BorderLayout());
    panel.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(),
            plot.getPlotType() + localizationResources.getString(":")));

    JPanel general = new JPanel(new BorderLayout());
    general.setBorder(BorderFactory.createTitledBorder(localizationResources.getString("General")));

    JPanel interior = new JPanel(new LCBLayout(7));
    interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));

    interior.add(new JLabel(localizationResources.getString("Outline_stroke")));

    DefaultComboBoxModel model = new DefaultComboBoxModel();
    for (StrokeSample s : this.availableStrokeSamples) {
        model.addElement(s.getStroke());
    }
    this.cbOutlineStroke = new JComboBox(model);
    this.cbOutlineStroke.setSelectedItem(this.outlineStrokeSample.getStroke());
    this.cbOutlineStroke.setRenderer(new StrokeComboboxRenderer());

    interior.add(this.cbOutlineStroke);
    interior.add(new JLabel());

    interior.add(new JLabel(localizationResources.getString("Outline_Paint")));
    JButton button = new JButton(localizationResources.getString("Select..."));
    button.setActionCommand("OutlinePaint");
    button.addActionListener(this);
    interior.add(this.outlinePaintSample);
    interior.add(button);

    interior.add(new JLabel(localizationResources.getString("Background_paint")));
    button = new JButton(localizationResources.getString("Select..."));
    button.setActionCommand("BackgroundPaint");
    button.addActionListener(this);
    interior.add(this.backgroundPaintSample);
    interior.add(button);

    // Disabled because makes no sense for us
    // if (this.plotOrientation != null) {
    // boolean isVertical =
    // this.plotOrientation.equals(PlotOrientation.VERTICAL);
    // int index = isVertical ? ORIENTATION_VERTICAL :
    // ORIENTATION_HORIZONTAL;
    // interior.add(new
    // JLabel(localizationResources.getString("Orientation")));
    // this.orientationCombo = new JComboBox(orientationNames);
    // this.orientationCombo.setSelectedIndex(index);
    // this.orientationCombo.setActionCommand("Orientation");
    // this.orientationCombo.addActionListener(this);
    // interior.add(this.orientationCombo);
    // interior.add(new JPanel());
    // }

    if (this.drawLines != null) {
        interior.add(new JLabel(localizationResources.getString("Draw_lines")));
        this.drawLinesCheckBox = new JCheckBox();
        this.drawLinesCheckBox.setSelected(this.drawLines.booleanValue());
        this.drawLinesCheckBox.setActionCommand("DrawLines");
        this.drawLinesCheckBox.addActionListener(this);
        interior.add(new JPanel());
        interior.add(this.drawLinesCheckBox);
    }

    if (this.drawShapes != null) {
        interior.add(new JLabel(localizationResources.getString("Draw_shapes")));
        this.drawShapesCheckBox = new JCheckBox();
        this.drawShapesCheckBox.setSelected(this.drawShapes.booleanValue());
        this.drawShapesCheckBox.setActionCommand("DrawShapes");
        this.drawShapesCheckBox.addActionListener(this);
        interior.add(new JPanel());
        interior.add(this.drawShapesCheckBox);
    }

    general.add(interior, BorderLayout.NORTH);

    JPanel appearance = new JPanel(new BorderLayout());
    appearance.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
    appearance.add(general, BorderLayout.NORTH);

    JTabbedPane tabs = new JTabbedPane();
    tabs.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));

    Axis domainAxis = null;
    if (plot instanceof CategoryPlot) {
        domainAxis = ((CategoryPlot) plot).getDomainAxis();
    } else if (plot instanceof XYPlot) {
        domainAxis = ((XYPlot) plot).getDomainAxis();
    }
    this.domainAxisPropertyPanel = DefaultAxisEditor.getInstance(domainAxis);
    if (this.domainAxisPropertyPanel != null) {
        this.domainAxisPropertyPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        tabs.add(localizationResources.getString("Domain_Axis"), this.domainAxisPropertyPanel);
    }

    Axis rangeAxis = null;
    if (plot instanceof CategoryPlot) {
        rangeAxis = ((CategoryPlot) plot).getRangeAxis();
    } else if (plot instanceof XYPlot) {
        rangeAxis = ((XYPlot) plot).getRangeAxis();
    }

    this.rangeAxisPropertyPanel = DefaultAxisEditor.getInstance(rangeAxis);
    if (this.rangeAxisPropertyPanel != null) {
        this.rangeAxisPropertyPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
        tabs.add(localizationResources.getString("Range_Axis"), this.rangeAxisPropertyPanel);
    }

    tabs.add(localizationResources.getString("Appearance"), appearance);
    panel.add(tabs);

    add(panel);
}

From source file:com.bdaum.zoom.report.internal.wizards.ReportComponent.java

public void saveChartProperties(Report report) {
    JFreeChart chart = chartComposite.getChart();
    if (chart != null) {
        Map<String, Object> properties = new HashMap<>();
        TextTitle title = chart.getTitle();
        if (title != null) {
            properties.put(TITLE, title.getText());
            properties.put(TITLEFONT, title.getFont());
            properties.put(TITLECOLOR, title.getPaint());
        }/*  ww w .jav a 2  s .c o  m*/
        Plot plot = chart.getPlot();
        properties.put(BGCOLOR, plot.getBackgroundPaint());
        properties.put(OUTLINEPAINT, plot.getOutlinePaint());
        properties.put(OUTLINESTROKE, plot.getOutlineStroke());
        Axis domainAxis = null;
        Axis rangeAxis = null;
        if (plot instanceof CategoryPlot) {
            CategoryPlot p = (CategoryPlot) plot;
            domainAxis = p.getDomainAxis();
            rangeAxis = p.getRangeAxis();
            properties.put(ORIENTATION, p.getOrientation());
        } else if (plot instanceof XYPlot) {
            XYPlot p = (XYPlot) plot;
            domainAxis = p.getDomainAxis();
            rangeAxis = p.getRangeAxis();
            properties.put(ORIENTATION, p.getOrientation());
        }
        if (domainAxis != null)
            saveAxisProperties(domainAxis, "x", properties); //$NON-NLS-1$
        if (rangeAxis != null)
            saveAxisProperties(rangeAxis, "y", properties); //$NON-NLS-1$
        properties.put(ANTIALIAS, chart.getAntiAlias());
        properties.put(CANVASPAINT, chart.getBackgroundPaint());
        report.setProperties(properties);
    }
}

From source file:com.rcp.wbw.demo.editor.SWTPlotAppearanceEditor.java

SWTPlotAppearanceEditor(Composite parent, int style, Plot plot) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    setLayout(layout);//ww w . j  a v  a2  s.  c  o  m

    Group general = new Group(this, SWT.NONE);
    GridLayout groupLayout = new GridLayout(3, false);
    groupLayout.marginHeight = groupLayout.marginWidth = 4;
    general.setLayout(groupLayout);
    general.setText(localizationResources.getString("General"));

    // row 1: stroke
    new Label(general, SWT.NONE).setText(localizationResources.getString("Outline_stroke"));
    this.strokeCanvas = new SWTStrokeCanvas(general, SWT.NONE);
    this.strokeCanvas.setStroke(plot.getOutlineStroke());
    GridData strokeGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    strokeGridData.heightHint = 20;
    this.strokeCanvas.setLayoutData(strokeGridData);
    this.selectStroke = new Spinner(general, SWT.BORDER);
    this.selectStroke.setMinimum(1);
    this.selectStroke.setMaximum(3);
    this.selectStroke.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    this.selectStroke.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int w = SWTPlotAppearanceEditor.this.selectStroke.getSelection();
            if (w > 0) {
                SWTPlotAppearanceEditor.this.strokeCanvas.setStroke(new BasicStroke(w));
                SWTPlotAppearanceEditor.this.strokeCanvas.redraw();
            }
        }
    });
    // row 2: outline color
    new Label(general, SWT.NONE).setText(localizationResources.getString("Outline_Paint"));
    this.outlinePaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), plot.getOutlinePaint()));
    GridData outlineGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    outlineGridData.heightHint = 20;
    this.outlinePaintCanvas.setLayoutData(outlineGridData);
    Button selectOutlineColor = new Button(general, SWT.PUSH);
    selectOutlineColor.setText(localizationResources.getString("Select..."));
    selectOutlineColor.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectOutlineColor.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Outline_Paint"));
            dlg.setRGB(SWTPlotAppearanceEditor.this.outlinePaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTPlotAppearanceEditor.this.outlinePaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
    // row 3: background paint
    new Label(general, SWT.NONE).setText(localizationResources.getString("Background_paint"));
    this.backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), plot.getBackgroundPaint()));
    GridData bgGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    bgGridData.heightHint = 20;
    this.backgroundPaintCanvas.setLayoutData(bgGridData);
    Button selectBgPaint = new Button(general, SWT.PUSH);
    selectBgPaint.setText(localizationResources.getString("Select..."));
    selectBgPaint.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectBgPaint.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Background_paint"));
            dlg.setRGB(SWTPlotAppearanceEditor.this.backgroundPaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTPlotAppearanceEditor.this.backgroundPaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
    // row 4: orientation
    if (plot instanceof CategoryPlot) {
        this.plotOrientation = ((CategoryPlot) plot).getOrientation();
    } else if (plot instanceof XYPlot) {
        this.plotOrientation = ((XYPlot) plot).getOrientation();
    }
    if (this.plotOrientation != null) {
        boolean isVertical = this.plotOrientation.equals(PlotOrientation.VERTICAL);
        int index = isVertical ? ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL;
        new Label(general, SWT.NONE).setText(localizationResources.getString("Orientation"));
        this.orientation = new Combo(general, SWT.DROP_DOWN);
        this.orientation.setItems(orientationNames);
        this.orientation.select(index);
        this.orientation.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 2, 1));
        this.orientation.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                switch (SWTPlotAppearanceEditor.this.orientation.getSelectionIndex()) {
                case ORIENTATION_VERTICAL:
                    SWTPlotAppearanceEditor.this.plotOrientation = PlotOrientation.VERTICAL;
                    break;
                case ORIENTATION_HORIZONTAL:
                    SWTPlotAppearanceEditor.this.plotOrientation = PlotOrientation.HORIZONTAL;
                    break;
                default:
                    SWTPlotAppearanceEditor.this.plotOrientation = PlotOrientation.VERTICAL;
                }
            }
        });
    }
}

From source file:org.jfree.experimental.chart.swt.editor.SWTPlotAppearanceEditor.java

SWTPlotAppearanceEditor(Composite parent, int style, Plot plot) {
    super(parent, style);
    FillLayout layout = new FillLayout();
    layout.marginHeight = layout.marginWidth = 4;
    this.setLayout(layout);

    Group general = new Group(this, SWT.NONE);
    GridLayout groupLayout = new GridLayout(3, false);
    groupLayout.marginHeight = groupLayout.marginWidth = 4;
    general.setLayout(groupLayout);/*from   www. j  a v a 2s .co m*/
    general.setText(localizationResources.getString("General"));

    // row 1: stroke
    new Label(general, SWT.NONE).setText(localizationResources.getString("Outline_stroke"));
    this.strokeCanvas = new SWTStrokeCanvas(general, SWT.NONE);
    this.strokeCanvas.setStroke(plot.getOutlineStroke());
    GridData strokeGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    strokeGridData.heightHint = 20;
    this.strokeCanvas.setLayoutData(strokeGridData);
    this.selectStroke = new Spinner(general, SWT.BORDER);
    this.selectStroke.setMinimum(1);
    this.selectStroke.setMaximum(3);
    this.selectStroke.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, false, false));
    this.selectStroke.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            int w = SWTPlotAppearanceEditor.this.selectStroke.getSelection();
            if (w > 0) {
                SWTPlotAppearanceEditor.this.strokeCanvas.setStroke(new BasicStroke(w));
                SWTPlotAppearanceEditor.this.strokeCanvas.redraw();
            }
        }
    });
    // row 2: outline color
    new Label(general, SWT.NONE).setText(localizationResources.getString("Outline_Paint"));
    this.outlinePaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), plot.getOutlinePaint()));
    GridData outlineGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    outlineGridData.heightHint = 20;
    this.outlinePaintCanvas.setLayoutData(outlineGridData);
    Button selectOutlineColor = new Button(general, SWT.PUSH);
    selectOutlineColor.setText(localizationResources.getString("Select..."));
    selectOutlineColor.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectOutlineColor.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Outline_Paint"));
            dlg.setRGB(SWTPlotAppearanceEditor.this.outlinePaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTPlotAppearanceEditor.this.outlinePaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
    // row 3: background paint
    new Label(general, SWT.NONE).setText(localizationResources.getString("Background_paint"));
    this.backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
            SWTUtils.toSwtColor(getDisplay(), plot.getBackgroundPaint()));
    GridData bgGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
    bgGridData.heightHint = 20;
    this.backgroundPaintCanvas.setLayoutData(bgGridData);
    Button selectBgPaint = new Button(general, SWT.PUSH);
    selectBgPaint.setText(localizationResources.getString("Select..."));
    selectBgPaint.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false, false));
    selectBgPaint.addSelectionListener(new SelectionAdapter() {
        public void widgetSelected(SelectionEvent event) {
            ColorDialog dlg = new ColorDialog(getShell());
            dlg.setText(localizationResources.getString("Background_paint"));
            dlg.setRGB(SWTPlotAppearanceEditor.this.backgroundPaintCanvas.getColor().getRGB());
            RGB rgb = dlg.open();
            if (rgb != null) {
                SWTPlotAppearanceEditor.this.backgroundPaintCanvas.setColor(new Color(getDisplay(), rgb));
            }
        }
    });
    // row 4: orientation
    if (plot instanceof CategoryPlot) {
        this.plotOrientation = ((CategoryPlot) plot).getOrientation();
    } else if (plot instanceof XYPlot) {
        this.plotOrientation = ((XYPlot) plot).getOrientation();
    }
    if (this.plotOrientation != null) {
        boolean isVertical = this.plotOrientation.equals(PlotOrientation.VERTICAL);
        int index = isVertical ? ORIENTATION_VERTICAL : ORIENTATION_HORIZONTAL;
        new Label(general, SWT.NONE).setText(localizationResources.getString("Orientation"));
        this.orientation = new Combo(general, SWT.DROP_DOWN);
        this.orientation.setItems(orientationNames);
        this.orientation.select(index);
        this.orientation.setLayoutData(new GridData(SWT.RIGHT, SWT.CENTER, true, false, 2, 1));
        this.orientation.addSelectionListener(new SelectionAdapter() {
            public void widgetSelected(SelectionEvent event) {
                switch (SWTPlotAppearanceEditor.this.orientation.getSelectionIndex()) {
                case ORIENTATION_VERTICAL:
                    SWTPlotAppearanceEditor.this.plotOrientation = PlotOrientation.VERTICAL;
                    break;
                case ORIENTATION_HORIZONTAL:
                    SWTPlotAppearanceEditor.this.plotOrientation = PlotOrientation.HORIZONTAL;
                    break;
                default:
                    SWTPlotAppearanceEditor.this.plotOrientation = PlotOrientation.VERTICAL;
                }
            }
        });
    }
}