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: * SWTChartEditor.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.layout.FillLayout;
049: import org.eclipse.swt.layout.GridData;
050: import org.eclipse.swt.layout.GridLayout;
051: import org.eclipse.swt.widgets.Button;
052: import org.eclipse.swt.widgets.Composite;
053: import org.eclipse.swt.widgets.Display;
054: import org.eclipse.swt.widgets.Shell;
055: import org.eclipse.swt.widgets.TabFolder;
056: import org.eclipse.swt.widgets.TabItem;
057: import org.jfree.chart.JFreeChart;
058: import org.jfree.chart.editor.ChartEditor;
059:
060: /**
061: * An editor for chart properties.
062: */
063: public class SWTChartEditor implements ChartEditor {
064:
065: /** The shell */
066: private Shell shell;
067:
068: /** The chart which the properties have to be edited */
069: private JFreeChart chart;
070:
071: /** A composite for displaying/editing the properties of the title. */
072: private SWTTitleEditor titleEditor;
073:
074: /** A composite for displaying/editing the properties of the plot. */
075: private SWTPlotEditor plotEditor;
076:
077: /** A composite for displaying/editing the other properties of the chart. */
078: private SWTOtherEditor otherEditor;
079:
080: /** The resourceBundle for the localization. */
081: protected static ResourceBundle localizationResources = ResourceBundle
082: .getBundle("org.jfree.chart.editor.LocalizationBundle");
083:
084: /**
085: * Creates a new editor.
086: *
087: * @param display the display.
088: * @param chart2edit the chart to edit.
089: */
090: public SWTChartEditor(Display display, JFreeChart chart2edit) {
091: shell = new Shell(display, SWT.DIALOG_TRIM);
092: shell.setSize(400, 500);
093: this .chart = chart2edit;
094: shell.setText(ResourceBundle.getBundle(
095: "org.jfree.chart.LocalizationBundle").getString(
096: "Chart_Properties"));
097: GridLayout layout = new GridLayout(2, true);
098: layout.marginLeft = layout.marginTop = layout.marginRight = layout.marginBottom = 5;
099: shell.setLayout(layout);
100: Composite main = new Composite(shell, SWT.NONE);
101: main.setLayout(new FillLayout());
102: main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true,
103: 2, 1));
104:
105: TabFolder tab = new TabFolder(main, SWT.BORDER);
106: // build first tab
107: TabItem item1 = new TabItem(tab, SWT.NONE);
108: item1.setText(" " + localizationResources.getString("Title")
109: + " ");
110: titleEditor = new SWTTitleEditor(tab, SWT.NONE, chart
111: .getTitle());
112: item1.setControl(titleEditor);
113: // build second tab
114: TabItem item2 = new TabItem(tab, SWT.NONE);
115: item2.setText(" " + localizationResources.getString("Plot")
116: + " ");
117: plotEditor = new SWTPlotEditor(tab, SWT.NONE, chart.getPlot());
118: item2.setControl(plotEditor);
119: // build the third tab
120: TabItem item3 = new TabItem(tab, SWT.NONE);
121: item3.setText(" " + localizationResources.getString("Other")
122: + " ");
123: otherEditor = new SWTOtherEditor(tab, SWT.NONE, chart);
124: item3.setControl(otherEditor);
125:
126: // ok and cancel buttons
127: Button ok = new Button(shell, SWT.PUSH | SWT.OK);
128: ok.setText(" Ok ");
129: ok
130: .setLayoutData(new GridData(SWT.FILL, SWT.FILL, false,
131: false));
132: ok.addSelectionListener(new SelectionAdapter() {
133: public void widgetSelected(SelectionEvent e) {
134: updateChart(chart);
135: shell.dispose();
136: }
137: });
138: Button cancel = new Button(shell, SWT.PUSH);
139: cancel.setText(" Cancel ");
140: cancel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false,
141: false));
142: cancel.addSelectionListener(new SelectionAdapter() {
143: public void widgetSelected(SelectionEvent e) {
144: shell.dispose();
145: }
146: });
147: }
148:
149: /**
150: * Opens the editor.
151: */
152: public void open() {
153: shell.open();
154: shell.layout();
155: while (!shell.isDisposed()) {
156: if (!shell.getDisplay().readAndDispatch()) {
157: shell.getDisplay().sleep();
158: }
159: }
160: }
161:
162: /**
163: * Updates the chart properties.
164: *
165: * @param chart the chart.
166: */
167: public void updateChart(JFreeChart chart) {
168: this.titleEditor.setTitleProperties(chart);
169: this.plotEditor.updatePlotProperties(chart.getPlot());
170: this.otherEditor.updateChartProperties(chart);
171: }
172:
173: }
|