001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * -------------------
028: * SWTOtherEditor.java
029: * -------------------
030: * (C) Copyright 2006, by Henry Proudhon and Contributors.
031: *
032: * Original Author: Henry Proudhon (henry.proudhon AT insa-lyon.fr);
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: *
035: * Changes
036: * -------
037: * 01-Aug-2006 : New class (HP);
038: *
039: */
040:
041: package org.jfree.experimental.chart.swt.editor;
042:
043: import java.util.ResourceBundle;
044:
045: import org.eclipse.swt.SWT;
046: import org.eclipse.swt.events.SelectionAdapter;
047: import org.eclipse.swt.events.SelectionEvent;
048: import org.eclipse.swt.graphics.Color;
049: import org.eclipse.swt.graphics.RGB;
050: import org.eclipse.swt.layout.FillLayout;
051: import org.eclipse.swt.layout.GridData;
052: import org.eclipse.swt.layout.GridLayout;
053: import org.eclipse.swt.widgets.Button;
054: import org.eclipse.swt.widgets.ColorDialog;
055: import org.eclipse.swt.widgets.Composite;
056: import org.eclipse.swt.widgets.Group;
057: import org.eclipse.swt.widgets.Label;
058: import org.jfree.chart.JFreeChart;
059: import org.jfree.experimental.swt.SWTPaintCanvas;
060: import org.jfree.experimental.swt.SWTUtils;
061:
062: /**
063: * An editor for miscellaneous chart properties.
064: */
065: class SWTOtherEditor extends Composite {
066:
067: /** A checkbox indicating whether or not
068: * the chart is drawn with anti-aliasing. */
069: private Button antialias;
070:
071: /** The chart background color. */
072: private SWTPaintCanvas backgroundPaintCanvas;
073:
074: /** The resourceBundle for the localization. */
075: protected static ResourceBundle localizationResources = ResourceBundle
076: .getBundle("org.jfree.chart.editor.LocalizationBundle");
077:
078: /**
079: * Creates a new instance.
080: *
081: * @param parent the parent.
082: * @param style the style.
083: * @param chart the chart.
084: */
085: public SWTOtherEditor(Composite parent, int style, JFreeChart chart) {
086: super (parent, style);
087: FillLayout layout = new FillLayout();
088: layout.marginHeight = layout.marginWidth = 4;
089: setLayout(layout);
090:
091: Group general = new Group(this , SWT.NONE);
092: general.setLayout(new GridLayout(3, false));
093: general.setText(localizationResources.getString("General"));
094:
095: // row 1: antialiasing
096: antialias = new Button(general, SWT.CHECK);
097: antialias.setText(localizationResources
098: .getString("Draw_anti-aliased"));
099: antialias.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER,
100: true, false, 3, 1));
101: antialias.setSelection(chart.getAntiAlias());
102:
103: //row 2: background paint for the chart
104: new Label(general, SWT.NONE).setText(localizationResources
105: .getString("Background_paint"));
106: backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
107: SWTUtils.toSwtColor(getDisplay(), chart
108: .getBackgroundPaint()));
109: GridData bgGridData = new GridData(SWT.FILL, SWT.CENTER, true,
110: false);
111: bgGridData.heightHint = 20;
112: backgroundPaintCanvas.setLayoutData(bgGridData);
113: Button selectBgPaint = new Button(general, SWT.PUSH);
114: selectBgPaint.setText(localizationResources
115: .getString("Select..."));
116: selectBgPaint.setLayoutData(new GridData(SWT.CENTER,
117: SWT.CENTER, false, false));
118: selectBgPaint.addSelectionListener(new SelectionAdapter() {
119: public void widgetSelected(SelectionEvent event) {
120: ColorDialog dlg = new ColorDialog(getShell());
121: dlg.setText(localizationResources
122: .getString("Background_paint"));
123: dlg.setRGB(backgroundPaintCanvas.getColor().getRGB());
124: RGB rgb = dlg.open();
125: if (rgb != null) {
126: backgroundPaintCanvas.setColor(new Color(
127: getDisplay(), rgb));
128: }
129: }
130: });
131: }
132:
133: /**
134: * Updates the chart.
135: *
136: * @param chart the chart.
137: */
138: public void updateChartProperties(JFreeChart chart) {
139: chart.setAntiAlias(this.antialias.getSelection());
140: chart.setBackgroundPaint(SWTUtils
141: .toAwtColor(this.backgroundPaintCanvas.getColor()));
142: }
143:
144: }
|