KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > editor > DefaultChartEditor


1 /* ===========================================================
2  * JFreeChart : a free chart library for the Java(tm) platform
3  * ===========================================================
4  *
5  * (C) Copyright 2000-2005, 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  * DefaultChartEditor.java
29  * -----------------------
30  * (C) Copyright 2000-2005, by Object Refinery Limited.
31  *
32  * Original Author: David Gilbert (for Object Refinery Limited);
33  * Contributor(s): Arnaud Lelievre;
34  * Daniel Gredler;
35  *
36  * $Id: DefaultChartEditor.java,v 1.1.2.1 2005/11/24 16:11:48 mungady Exp $
37  *
38  * Changes
39  * -------
40  * 24-Nov-2005 : New class, based on ChartPropertyEditPanel.java (DG);
41  *
42  */

43
44 package org.jfree.chart.editor;
45
46 import java.awt.BorderLayout JavaDoc;
47 import java.awt.Color JavaDoc;
48 import java.awt.Paint JavaDoc;
49 import java.awt.event.ActionEvent JavaDoc;
50 import java.awt.event.ActionListener JavaDoc;
51 import java.util.ResourceBundle JavaDoc;
52
53 import javax.swing.BorderFactory JavaDoc;
54 import javax.swing.JButton JavaDoc;
55 import javax.swing.JCheckBox JavaDoc;
56 import javax.swing.JColorChooser JavaDoc;
57 import javax.swing.JLabel JavaDoc;
58 import javax.swing.JPanel JavaDoc;
59 import javax.swing.JTabbedPane JavaDoc;
60 import javax.swing.JTextField JavaDoc;
61
62 import org.jfree.chart.JFreeChart;
63 import org.jfree.chart.plot.Plot;
64 import org.jfree.chart.title.Title;
65 import org.jfree.layout.LCBLayout;
66 import org.jfree.ui.PaintSample;
67
68 /**
69  * A panel for editing chart properties (includes subpanels for the title,
70  * legend and plot).
71  */

72 class DefaultChartEditor extends JPanel JavaDoc implements ActionListener JavaDoc, ChartEditor {
73
74     /** A panel for displaying/editing the properties of the title. */
75     private DefaultTitleEditor titleEditor;
76
77     /** A panel for displaying/editing the properties of the plot. */
78     private DefaultPlotEditor plotEditor;
79
80     /**
81      * A checkbox indicating whether or not the chart is drawn with
82      * anti-aliasing.
83      */

84     private JCheckBox JavaDoc antialias;
85
86     /** The chart background color. */
87     private PaintSample background;
88
89     /** The resourceBundle for the localization. */
90     protected static ResourceBundle JavaDoc localizationResources
91         = ResourceBundle.getBundle("org.jfree.chart.editor.LocalizationBundle");
92
93     /**
94      * Standard constructor - the property panel is made up of a number of
95      * sub-panels that are displayed in the tabbed pane.
96      *
97      * @param chart the chart, whichs properties should be changed.
98      */

99     public DefaultChartEditor(JFreeChart chart) {
100         setLayout(new BorderLayout JavaDoc());
101
102         JPanel JavaDoc other = new JPanel JavaDoc(new BorderLayout JavaDoc());
103         other.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
104
105         JPanel JavaDoc general = new JPanel JavaDoc(new BorderLayout JavaDoc());
106         general.setBorder(BorderFactory.createTitledBorder(
107             BorderFactory.createEtchedBorder(),
108             localizationResources.getString("General")));
109
110         JPanel JavaDoc interior = new JPanel JavaDoc(new LCBLayout(6));
111         interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
112
113         this.antialias = new JCheckBox JavaDoc(localizationResources.getString(
114                 "Draw_anti-aliased"));
115         this.antialias.setSelected(chart.getAntiAlias());
116         interior.add(this.antialias);
117         interior.add(new JLabel JavaDoc(""));
118         interior.add(new JLabel JavaDoc(""));
119         interior.add(new JLabel JavaDoc(localizationResources.getString(
120                 "Background_paint")));
121         this.background = new PaintSample(chart.getBackgroundPaint());
122         interior.add(this.background);
123         JButton JavaDoc button = new JButton JavaDoc(localizationResources.getString(
124                 "Select..."));
125         button.setActionCommand("BackgroundPaint");
126         button.addActionListener(this);
127         interior.add(button);
128
129         interior.add(new JLabel JavaDoc(localizationResources.getString(
130                 "Series_Paint")));
131         JTextField JavaDoc info = new JTextField JavaDoc(localizationResources.getString(
132                 "No_editor_implemented"));
133         info.setEnabled(false);
134         interior.add(info);
135         button = new JButton JavaDoc(localizationResources.getString("Edit..."));
136         button.setEnabled(false);
137         interior.add(button);
138
139         interior.add(new JLabel JavaDoc(localizationResources.getString(
140                 "Series_Stroke")));
141         info = new JTextField JavaDoc(localizationResources.getString(
142                 "No_editor_implemented"));
143         info.setEnabled(false);
144         interior.add(info);
145         button = new JButton JavaDoc(localizationResources.getString("Edit..."));
146         button.setEnabled(false);
147         interior.add(button);
148
149         interior.add(new JLabel JavaDoc(localizationResources.getString(
150                 "Series_Outline_Paint")));
151         info = new JTextField JavaDoc(localizationResources.getString(
152                 "No_editor_implemented"));
153         info.setEnabled(false);
154         interior.add(info);
155         button = new JButton JavaDoc(localizationResources.getString("Edit..."));
156         button.setEnabled(false);
157         interior.add(button);
158
159         interior.add(new JLabel JavaDoc(localizationResources.getString(
160                 "Series_Outline_Stroke")));
161         info = new JTextField JavaDoc(localizationResources.getString(
162                 "No_editor_implemented"));
163         info.setEnabled(false);
164         interior.add(info);
165         button = new JButton JavaDoc(localizationResources.getString("Edit..."));
166         button.setEnabled(false);
167         interior.add(button);
168
169         general.add(interior, BorderLayout.NORTH);
170         other.add(general, BorderLayout.NORTH);
171
172         JPanel JavaDoc parts = new JPanel JavaDoc(new BorderLayout JavaDoc());
173
174         Title title = chart.getTitle();
175         Plot plot = chart.getPlot();
176
177         JTabbedPane JavaDoc tabs = new JTabbedPane JavaDoc();
178
179         this.titleEditor = new DefaultTitleEditor(title);
180         this.titleEditor.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
181         tabs.addTab(localizationResources.getString("Title"), this.titleEditor);
182
183         this.plotEditor = new DefaultPlotEditor(plot);
184         this.plotEditor.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
185         tabs.addTab(localizationResources.getString("Plot"), this.plotEditor);
186
187         tabs.add(localizationResources.getString("Other"), other);
188         parts.add(tabs, BorderLayout.NORTH);
189         add(parts);
190     }
191
192     /**
193      * Returns a reference to the title editor.
194      *
195      * @return A panel for editing the title.
196      */

197     public DefaultTitleEditor getTitleEditor() {
198       return this.titleEditor;
199     }
200
201     /**
202      * Returns a reference to the plot property sub-panel.
203      *
204      * @return A panel for editing the plot properties.
205      */

206     public DefaultPlotEditor getPlotEditor() {
207         return this.plotEditor;
208     }
209
210     /**
211      * Returns the current setting of the anti-alias flag.
212      *
213      * @return <code>true</code> if anti-aliasing is enabled.
214      */

215     public boolean getAntiAlias() {
216         return this.antialias.isSelected();
217     }
218
219     /**
220      * Returns the current background paint.
221      *
222      * @return The current background paint.
223      */

224     public Paint JavaDoc getBackgroundPaint() {
225         return this.background.getPaint();
226     }
227
228     /**
229      * Handles user interactions with the panel.
230      *
231      * @param event a BackgroundPaint action.
232      */

233     public void actionPerformed(ActionEvent JavaDoc event) {
234         String JavaDoc command = event.getActionCommand();
235         if (command.equals("BackgroundPaint")) {
236             attemptModifyBackgroundPaint();
237         }
238     }
239
240     /**
241      * Allows the user the opportunity to select a new background paint. Uses
242      * JColorChooser, so we are only allowing a subset of all Paint objects to
243      * be selected (fix later).
244      */

245     private void attemptModifyBackgroundPaint() {
246         Color JavaDoc c;
247         c = JColorChooser.showDialog(this, localizationResources.getString(
248                 "Background_Color"), Color.blue);
249         if (c != null) {
250             this.background.setPaint(c);
251         }
252     }
253
254     /**
255      * Updates the properties of a chart to match the properties defined on the
256      * panel.
257      *
258      * @param chart the chart.
259      */

260     public void updateChart(JFreeChart chart) {
261
262         this.titleEditor.setTitleProperties(chart);
263         this.plotEditor.updatePlotProperties(chart.getPlot());
264
265         chart.setAntiAlias(getAntiAlias());
266         chart.setBackgroundPaint(getBackgroundPaint());
267     }
268
269 }
270
Popular Tags