001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, 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: * DefaultChartEditor.java
029: * -----------------------
030: * (C) Copyright 2000-2005, by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): Arnaud Lelievre;
034: * Daniel Gredler;
035: *
036: * $Id: DefaultChartEditor.java,v 1.1.2.1 2005/11/24 16:11:48 mungady Exp $
037: *
038: * Changes
039: * -------
040: * 24-Nov-2005 : New class, based on ChartPropertyEditPanel.java (DG);
041: *
042: */
043:
044: package org.jfree.chart.editor;
045:
046: import java.awt.BorderLayout;
047: import java.awt.Color;
048: import java.awt.Paint;
049: import java.awt.event.ActionEvent;
050: import java.awt.event.ActionListener;
051: import java.util.ResourceBundle;
052:
053: import javax.swing.BorderFactory;
054: import javax.swing.JButton;
055: import javax.swing.JCheckBox;
056: import javax.swing.JColorChooser;
057: import javax.swing.JLabel;
058: import javax.swing.JPanel;
059: import javax.swing.JTabbedPane;
060: import javax.swing.JTextField;
061:
062: import org.jfree.chart.JFreeChart;
063: import org.jfree.chart.plot.Plot;
064: import org.jfree.chart.title.Title;
065: import org.jfree.layout.LCBLayout;
066: import org.jfree.ui.PaintSample;
067:
068: /**
069: * A panel for editing chart properties (includes subpanels for the title,
070: * legend and plot).
071: */
072: class DefaultChartEditor extends JPanel implements ActionListener,
073: ChartEditor {
074:
075: /** A panel for displaying/editing the properties of the title. */
076: private DefaultTitleEditor titleEditor;
077:
078: /** A panel for displaying/editing the properties of the plot. */
079: private DefaultPlotEditor plotEditor;
080:
081: /**
082: * A checkbox indicating whether or not the chart is drawn with
083: * anti-aliasing.
084: */
085: private JCheckBox antialias;
086:
087: /** The chart background color. */
088: private PaintSample background;
089:
090: /** The resourceBundle for the localization. */
091: protected static ResourceBundle localizationResources = ResourceBundle
092: .getBundle("org.jfree.chart.editor.LocalizationBundle");
093:
094: /**
095: * Standard constructor - the property panel is made up of a number of
096: * sub-panels that are displayed in the tabbed pane.
097: *
098: * @param chart the chart, whichs properties should be changed.
099: */
100: public DefaultChartEditor(JFreeChart chart) {
101: setLayout(new BorderLayout());
102:
103: JPanel other = new JPanel(new BorderLayout());
104: other.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
105:
106: JPanel general = new JPanel(new BorderLayout());
107: general.setBorder(BorderFactory.createTitledBorder(
108: BorderFactory.createEtchedBorder(),
109: localizationResources.getString("General")));
110:
111: JPanel interior = new JPanel(new LCBLayout(6));
112: interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
113:
114: this .antialias = new JCheckBox(localizationResources
115: .getString("Draw_anti-aliased"));
116: this .antialias.setSelected(chart.getAntiAlias());
117: interior.add(this .antialias);
118: interior.add(new JLabel(""));
119: interior.add(new JLabel(""));
120: interior.add(new JLabel(localizationResources
121: .getString("Background_paint")));
122: this .background = new PaintSample(chart.getBackgroundPaint());
123: interior.add(this .background);
124: JButton button = new JButton(localizationResources
125: .getString("Select..."));
126: button.setActionCommand("BackgroundPaint");
127: button.addActionListener(this );
128: interior.add(button);
129:
130: interior.add(new JLabel(localizationResources
131: .getString("Series_Paint")));
132: JTextField info = new JTextField(localizationResources
133: .getString("No_editor_implemented"));
134: info.setEnabled(false);
135: interior.add(info);
136: button = new JButton(localizationResources.getString("Edit..."));
137: button.setEnabled(false);
138: interior.add(button);
139:
140: interior.add(new JLabel(localizationResources
141: .getString("Series_Stroke")));
142: info = new JTextField(localizationResources
143: .getString("No_editor_implemented"));
144: info.setEnabled(false);
145: interior.add(info);
146: button = new JButton(localizationResources.getString("Edit..."));
147: button.setEnabled(false);
148: interior.add(button);
149:
150: interior.add(new JLabel(localizationResources
151: .getString("Series_Outline_Paint")));
152: info = new JTextField(localizationResources
153: .getString("No_editor_implemented"));
154: info.setEnabled(false);
155: interior.add(info);
156: button = new JButton(localizationResources.getString("Edit..."));
157: button.setEnabled(false);
158: interior.add(button);
159:
160: interior.add(new JLabel(localizationResources
161: .getString("Series_Outline_Stroke")));
162: info = new JTextField(localizationResources
163: .getString("No_editor_implemented"));
164: info.setEnabled(false);
165: interior.add(info);
166: button = new JButton(localizationResources.getString("Edit..."));
167: button.setEnabled(false);
168: interior.add(button);
169:
170: general.add(interior, BorderLayout.NORTH);
171: other.add(general, BorderLayout.NORTH);
172:
173: JPanel parts = new JPanel(new BorderLayout());
174:
175: Title title = chart.getTitle();
176: Plot plot = chart.getPlot();
177:
178: JTabbedPane tabs = new JTabbedPane();
179:
180: this .titleEditor = new DefaultTitleEditor(title);
181: this .titleEditor.setBorder(BorderFactory.createEmptyBorder(2,
182: 2, 2, 2));
183: tabs.addTab(localizationResources.getString("Title"),
184: this .titleEditor);
185:
186: this .plotEditor = new DefaultPlotEditor(plot);
187: this .plotEditor.setBorder(BorderFactory.createEmptyBorder(2, 2,
188: 2, 2));
189: tabs.addTab(localizationResources.getString("Plot"),
190: this .plotEditor);
191:
192: tabs.add(localizationResources.getString("Other"), other);
193: parts.add(tabs, BorderLayout.NORTH);
194: add(parts);
195: }
196:
197: /**
198: * Returns a reference to the title editor.
199: *
200: * @return A panel for editing the title.
201: */
202: public DefaultTitleEditor getTitleEditor() {
203: return this .titleEditor;
204: }
205:
206: /**
207: * Returns a reference to the plot property sub-panel.
208: *
209: * @return A panel for editing the plot properties.
210: */
211: public DefaultPlotEditor getPlotEditor() {
212: return this .plotEditor;
213: }
214:
215: /**
216: * Returns the current setting of the anti-alias flag.
217: *
218: * @return <code>true</code> if anti-aliasing is enabled.
219: */
220: public boolean getAntiAlias() {
221: return this .antialias.isSelected();
222: }
223:
224: /**
225: * Returns the current background paint.
226: *
227: * @return The current background paint.
228: */
229: public Paint getBackgroundPaint() {
230: return this .background.getPaint();
231: }
232:
233: /**
234: * Handles user interactions with the panel.
235: *
236: * @param event a BackgroundPaint action.
237: */
238: public void actionPerformed(ActionEvent event) {
239: String command = event.getActionCommand();
240: if (command.equals("BackgroundPaint")) {
241: attemptModifyBackgroundPaint();
242: }
243: }
244:
245: /**
246: * Allows the user the opportunity to select a new background paint. Uses
247: * JColorChooser, so we are only allowing a subset of all Paint objects to
248: * be selected (fix later).
249: */
250: private void attemptModifyBackgroundPaint() {
251: Color c;
252: c = JColorChooser.showDialog(this , localizationResources
253: .getString("Background_Color"), Color.blue);
254: if (c != null) {
255: this .background.setPaint(c);
256: }
257: }
258:
259: /**
260: * Updates the properties of a chart to match the properties defined on the
261: * panel.
262: *
263: * @param chart the chart.
264: */
265: public void updateChart(JFreeChart chart) {
266:
267: this.titleEditor.setTitleProperties(chart);
268: this.plotEditor.updatePlotProperties(chart.getPlot());
269:
270: chart.setAntiAlias(getAntiAlias());
271: chart.setBackgroundPaint(getBackgroundPaint());
272: }
273:
274: }
|