KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > ui > ChartPropertyEditPanel


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 License
20  * along with this library; if not, write to the Free Software Foundation,
21  * Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA.
22  *
23  * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
24  * in the United States and other countries.]
25  *
26  * ---------------------------
27  * ChartPropertyEditPanel.java
28  * ---------------------------
29  * (C) Copyright 2000-2004, by Object Refinery Limited.
30  *
31  * Original Author: David Gilbert (for Object Refinery Limited);
32  * Contributor(s): Arnaud Lelievre;
33  * Daniel Gredler;
34  *
35  * $Id: ChartPropertyEditPanel.java,v 1.4 2005/03/29 12:56:52 mungady Exp $
36  *
37  * Changes (from 22-Jun-2001)
38  * --------------------------
39  * 22-Jun-2001 : Disabled title panel, as it doesn't support the new title
40  * code (DG);
41  * 24-Aug-2001 : Fixed DOS encoding problem (DG);
42  * 07-Nov-2001 : Separated the JCommon Class Library classes, JFreeChart now
43  * requires jcommon.jar (DG);
44  * 21-Nov-2001 : Allowed for null legend (DG);
45  * 17-Jan-2003 : Moved plot classes into separate package (DG);
46  * 20-May-2003 : Removed titlePanel until it is implemented. (TM);
47  * 08-Sep-2003 : Added internationalization via use of properties
48  * resourceBundle (RFE 690236) (AL);
49  * 24-Aug-2004 : Applied patch 1014378 (DG);
50  *
51  */

52
53 package org.jfree.chart.ui;
54
55 import java.awt.BorderLayout JavaDoc;
56 import java.awt.Color JavaDoc;
57 import java.awt.Paint JavaDoc;
58 import java.awt.event.ActionEvent JavaDoc;
59 import java.awt.event.ActionListener JavaDoc;
60 import java.util.ResourceBundle JavaDoc;
61
62 import javax.swing.BorderFactory JavaDoc;
63 import javax.swing.JButton JavaDoc;
64 import javax.swing.JCheckBox JavaDoc;
65 import javax.swing.JColorChooser JavaDoc;
66 import javax.swing.JLabel JavaDoc;
67 import javax.swing.JPanel JavaDoc;
68 import javax.swing.JTabbedPane JavaDoc;
69 import javax.swing.JTextField JavaDoc;
70
71 import org.jfree.chart.JFreeChart;
72 import org.jfree.chart.OldLegend;
73 import org.jfree.chart.plot.Plot;
74 import org.jfree.chart.title.Title;
75 import org.jfree.layout.LCBLayout;
76 import org.jfree.ui.PaintSample;
77
78 /**
79  * A panel for editing chart properties (includes subpanels for the title,
80  * legend and plot).
81  */

82 public class ChartPropertyEditPanel extends JPanel JavaDoc implements ActionListener JavaDoc {
83
84     /** A panel for displaying/editing the properties of the title. */
85     private TitlePropertyEditPanel titlePropertiesPanel;
86
87     /** A panel for displaying/editing the properties of the legend. */
88     private LegendPropertyEditPanel legendPropertiesPanel;
89
90     /** A panel for displaying/editing the properties of the plot. */
91     private PlotPropertyEditPanel plotPropertiesPanel;
92
93     /** A checkbox indicating whether or not the chart is drawn with
94      * anti-aliasing.
95      */

96     private JCheckBox JavaDoc antialias;
97
98     /** The chart background color. */
99     private PaintSample background;
100
101     /** The resourceBundle for the localization. */
102     protected static ResourceBundle JavaDoc localizationResources
103         = ResourceBundle.getBundle("org.jfree.chart.ui.LocalizationBundle");
104
105     /**
106      * Standard constructor - the property panel is made up of a number of
107      * sub-panels that are displayed in the tabbed pane.
108      *
109      * @param chart the chart, whichs properties should be changed.
110      */

111     public ChartPropertyEditPanel(JFreeChart chart) {
112         setLayout(new BorderLayout JavaDoc());
113
114         JPanel JavaDoc other = new JPanel JavaDoc(new BorderLayout JavaDoc());
115         other.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
116
117         JPanel JavaDoc general = new JPanel JavaDoc(new BorderLayout JavaDoc());
118         general.setBorder(
119             BorderFactory.createTitledBorder(
120                 BorderFactory.createEtchedBorder(),
121                 localizationResources.getString("General")
122             )
123         );
124
125         JPanel JavaDoc interior = new JPanel JavaDoc(new LCBLayout(6));
126         interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
127
128         this.antialias = new JCheckBox JavaDoc(
129             localizationResources.getString("Draw_anti-aliased")
130         );
131         this.antialias.setSelected(chart.getAntiAlias());
132         interior.add(this.antialias);
133         interior.add(new JLabel JavaDoc(""));
134         interior.add(new JLabel JavaDoc(""));
135         interior.add(
136             new JLabel JavaDoc(localizationResources.getString("Background_paint"))
137         );
138         this.background = new PaintSample(chart.getBackgroundPaint());
139         interior.add(this.background);
140         JButton JavaDoc button = new JButton JavaDoc(
141             localizationResources.getString("Select...")
142         );
143         button.setActionCommand("BackgroundPaint");
144         button.addActionListener(this);
145         interior.add(button);
146
147         interior.add(
148             new JLabel JavaDoc(localizationResources.getString("Series_Paint"))
149         );
150         JTextField JavaDoc info = new JTextField JavaDoc(
151             localizationResources.getString("No_editor_implemented")
152         );
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(
160             new JLabel JavaDoc(localizationResources.getString("Series_Stroke"))
161         );
162         info = new JTextField JavaDoc(
163             localizationResources.getString("No_editor_implemented")
164         );
165         info.setEnabled(false);
166         interior.add(info);
167         button = new JButton JavaDoc(localizationResources.getString("Edit..."));
168         button.setEnabled(false);
169         interior.add(button);
170
171         interior.add(
172             new JLabel JavaDoc(localizationResources.getString("Series_Outline_Paint"))
173         );
174         info = new JTextField JavaDoc(
175             localizationResources.getString("No_editor_implemented")
176         );
177         info.setEnabled(false);
178         interior.add(info);
179         button = new JButton JavaDoc(localizationResources.getString("Edit..."));
180         button.setEnabled(false);
181         interior.add(button);
182
183         interior.add(
184             new JLabel JavaDoc(localizationResources.getString("Series_Outline_Stroke"))
185         );
186         info = new JTextField JavaDoc(
187             localizationResources.getString("No_editor_implemented")
188         );
189         info.setEnabled(false);
190         interior.add(info);
191         button = new JButton JavaDoc(localizationResources.getString("Edit..."));
192         button.setEnabled(false);
193         interior.add(button);
194
195         general.add(interior, BorderLayout.NORTH);
196         other.add(general, BorderLayout.NORTH);
197
198         JPanel JavaDoc parts = new JPanel JavaDoc(new BorderLayout JavaDoc());
199
200         Title title = chart.getTitle();
201         OldLegend legend = chart.getOldLegend();
202         Plot plot = chart.getPlot();
203
204         JTabbedPane JavaDoc tabs = new JTabbedPane JavaDoc();
205
206         this.titlePropertiesPanel = new TitlePropertyEditPanel(title);
207         this.titlePropertiesPanel.setBorder(
208             BorderFactory.createEmptyBorder(2, 2, 2, 2)
209         );
210         tabs.addTab(
211             localizationResources.getString("Title"), this.titlePropertiesPanel
212         );
213
214         this.legendPropertiesPanel = new LegendPropertyEditPanel(legend);
215         this.legendPropertiesPanel.setBorder(
216             BorderFactory.createEmptyBorder(2, 2, 2, 2)
217         );
218         tabs.addTab(
219             localizationResources.getString("Legend"),
220             this.legendPropertiesPanel
221         );
222
223         this.plotPropertiesPanel = new PlotPropertyEditPanel(plot);
224         this.plotPropertiesPanel.setBorder(
225             BorderFactory.createEmptyBorder(2, 2, 2, 2)
226         );
227         tabs.addTab(
228             localizationResources.getString("Plot"), this.plotPropertiesPanel
229         );
230
231         tabs.add(localizationResources.getString("Other"), other);
232         parts.add(tabs, BorderLayout.NORTH);
233         add(parts);
234     }
235
236     /**
237      * Returns a reference to the title property sub-panel.
238      *
239      * @return A panel for editing the title.
240      */

241     public TitlePropertyEditPanel getTitlePropertyEditPanel() {
242       return this.titlePropertiesPanel;
243     }
244
245     /**
246      * Returns a reference to the legend property sub-panel.
247      *
248      * @return A panel for editing the legend.
249      */

250     public LegendPropertyEditPanel getLegendPropertyEditPanel() {
251         return this.legendPropertiesPanel;
252     }
253
254     /**
255      * Returns a reference to the plot property sub-panel.
256      *
257      * @return A panel for editing the plot properties.
258      */

259     public PlotPropertyEditPanel getPlotPropertyEditPanel() {
260         return this.plotPropertiesPanel;
261     }
262
263     /**
264      * Returns the current setting of the anti-alias flag.
265      *
266      * @return <code>true</code> if anti-aliasing is enabled.
267      */

268     public boolean getAntiAlias() {
269         return this.antialias.isSelected();
270     }
271
272     /**
273      * Returns the current background paint.
274      *
275      * @return The current background paint.
276      */

277     public Paint JavaDoc getBackgroundPaint() {
278         return this.background.getPaint();
279     }
280
281     /**
282      * Handles user interactions with the panel.
283      *
284      * @param event a BackgroundPaint action.
285      */

286     public void actionPerformed(ActionEvent JavaDoc event) {
287         String JavaDoc command = event.getActionCommand();
288         if (command.equals("BackgroundPaint")) {
289             attemptModifyBackgroundPaint();
290         }
291     }
292
293     /**
294      * Allows the user the opportunity to select a new background paint. Uses
295      * JColorChooser, so we are only allowing a subset of all Paint objects to
296      * be selected (fix later).
297      */

298     private void attemptModifyBackgroundPaint() {
299         Color JavaDoc c;
300         c = JColorChooser.showDialog(
301             this, localizationResources.getString("Background_Color"),
302             Color.blue
303         );
304         if (c != null) {
305             this.background.setPaint(c);
306         }
307     }
308
309     /**
310      * Updates the properties of a chart to match the properties defined on the
311      * panel.
312      *
313      * @param chart the chart.
314      */

315     public void updateChartProperties(JFreeChart chart) {
316
317         this.titlePropertiesPanel.setTitleProperties(chart);
318         this.legendPropertiesPanel.setLegendProperties(chart);
319         this.plotPropertiesPanel.updatePlotProperties(chart.getPlot());
320
321         chart.setAntiAlias(getAntiAlias());
322         chart.setBackgroundPaint(getBackgroundPaint());
323     }
324
325 }
326
Popular Tags