KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > experimental > chart > swt > editor > SWTChartEditor


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2006, by Object Refinery Limited and Contributors.
6  *
7  * Project Info: http://www.jfree.org/jfreechart/index.html
8  *
9  * This library is free software; you can redistribute it and/or modify it
10  * under the terms of the GNU Lesser General Public License as published by
11  * the Free Software Foundation; either version 2.1 of the License, or
12  * (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but
15  * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
16  * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
17  * License for more details.
18  *
19  * You should have received a copy of the GNU Lesser General Public
20  * License along with this library; if not, write to the Free Software
21  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
22  * USA.
23  *
24  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
25  * in the United States and other countries.]
26  *
27  * -------------------
28  * SWTChartEditor.java
29  * -------------------
30  * (C) Copyright 2006, by Henry Proudhon and Contributors.
31  *
32  * Original Author: Henry Proudhon (henry.proudhon AT insa-lyon.fr);
33  * Contributor(s): David Gilbert (for Object Refinery Limited);
34  *
35  * Changes
36  * -------
37  * 01-Aug-2006 : New class (HP);
38  *
39  */

40
41 package org.jfree.experimental.chart.swt.editor;
42
43 import java.util.ResourceBundle JavaDoc;
44
45 import org.eclipse.swt.SWT;
46 import org.eclipse.swt.events.SelectionAdapter;
47 import org.eclipse.swt.events.SelectionEvent;
48 import org.eclipse.swt.layout.FillLayout;
49 import org.eclipse.swt.layout.GridData;
50 import org.eclipse.swt.layout.GridLayout;
51 import org.eclipse.swt.widgets.Button;
52 import org.eclipse.swt.widgets.Composite;
53 import org.eclipse.swt.widgets.Display;
54 import org.eclipse.swt.widgets.Shell;
55 import org.eclipse.swt.widgets.TabFolder;
56 import org.eclipse.swt.widgets.TabItem;
57 import org.jfree.chart.JFreeChart;
58 import org.jfree.chart.editor.ChartEditor;
59
60 /**
61  * An editor for chart properties.
62  */

63 public class SWTChartEditor implements ChartEditor {
64     
65     /** The shell */
66     private Shell shell;
67     
68     /** The chart which the properties have to be edited */
69     private JFreeChart chart;
70     
71     /** A composite for displaying/editing the properties of the title. */
72     private SWTTitleEditor titleEditor;
73
74     /** A composite for displaying/editing the properties of the plot. */
75     private SWTPlotEditor plotEditor;
76     
77     /** A composite for displaying/editing the other properties of the chart. */
78     private SWTOtherEditor otherEditor;
79
80     /** The resourceBundle for the localization. */
81     protected static ResourceBundle JavaDoc localizationResources
82         = ResourceBundle.getBundle("org.jfree.chart.editor.LocalizationBundle");
83     
84     /**
85      * Creates a new editor.
86      *
87      * @param display the display.
88      * @param chart2edit the chart to edit.
89      */

90     public SWTChartEditor(Display display, JFreeChart chart2edit) {
91         shell = new Shell(display, SWT.DIALOG_TRIM);
92         shell.setSize(400, 500);
93         this.chart = chart2edit;
94         shell.setText(ResourceBundle.getBundle(
95                 "org.jfree.chart.LocalizationBundle").getString(
96                         "Chart_Properties"));
97         GridLayout layout = new GridLayout(2, true);
98         layout.marginLeft = layout.marginTop = layout.marginRight
99                 = layout.marginBottom = 5;
100         shell.setLayout(layout);
101         Composite main = new Composite(shell, SWT.NONE);
102         main.setLayout(new FillLayout());
103         main.setLayoutData(new GridData(SWT.FILL, SWT.FILL, true, true, 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         titleEditor = new SWTTitleEditor(tab, SWT.NONE, chart.getTitle());
110         item1.setControl(titleEditor);
111         // build second tab
112
TabItem item2 = new TabItem(tab, SWT.NONE);
113         item2.setText(" " + localizationResources.getString( "Plot" ) + " ");
114         plotEditor = new SWTPlotEditor(tab, SWT.NONE, chart.getPlot());
115         item2.setControl(plotEditor);
116         // build the third tab
117
TabItem item3 = new TabItem(tab, SWT.NONE);
118         item3.setText(" " + localizationResources.getString("Other") + " ");
119         otherEditor = new SWTOtherEditor(tab, SWT.NONE, chart);
120         item3.setControl(otherEditor);
121         
122         // ok and cancel buttons
123
Button ok = new Button(shell, SWT.PUSH | SWT.OK);
124         ok.setText(" Ok ");
125         ok.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
126         ok.addSelectionListener(new SelectionAdapter() {
127             public void widgetSelected(SelectionEvent e) {
128                 updateChart(chart);
129                 shell.dispose();
130             }
131         });
132         Button cancel = new Button(shell, SWT.PUSH);
133         cancel.setText(" Cancel ");
134         cancel.setLayoutData(new GridData(SWT.FILL, SWT.FILL, false, false));
135         cancel.addSelectionListener(new SelectionAdapter() {
136             public void widgetSelected(SelectionEvent e) {
137                 shell.dispose();
138             }
139         } );
140     }
141     
142     /**
143      * Opens the editor.
144      */

145     public void open() {
146         shell.open();
147         shell.layout();
148         while (!shell.isDisposed()) {
149             if (!shell.getDisplay().readAndDispatch()) {
150                 shell.getDisplay().sleep();
151             }
152         }
153     }
154
155     /**
156      * Updates the chart properties.
157      *
158      * @param chart the chart.
159      */

160     public void updateChart(JFreeChart chart)
161     {
162         this.titleEditor.setTitleProperties(chart);
163         this.plotEditor.updatePlotProperties(chart.getPlot());
164         this.otherEditor.updateChartProperties(chart );
165     }
166
167 }
168
Popular Tags