1. /* ===========================================================
  2. * JFreeChart : a free chart library for the Java(tm) platform
  3. * ===========================================================
  4. *
  5. * (C) Copyright 2000-2004, 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 under the terms
  10. * of the GNU Lesser General Public License as published by the Free Software Foundation;
  11. * either version 2.1 of the License, or (at your option) any later version.
  12. *
  13. * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
  14. * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
  15. * See the GNU Lesser General Public License for more details.
  16. *
  17. * You should have received a copy of the GNU Lesser General Public License along with this
  18. * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
  19. * Boston, MA 02111-1307, USA.
  20. *
  21. * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
  22. * in the United States and other countries.]
  23. *
  24. * ---------------------------
  25. * ChartPropertyEditPanel.java
  26. * ---------------------------
  27. * (C) Copyright 2000-2004, by Object Refinery Limited.
  28. *
  29. * Original Author: David Gilbert (for Object Refinery Limited);
  30. * Contributor(s): Arnaud Lelievre;
  31. * Daniel Gredler;
  32. *
  33. * $Id: ChartPropertyEditPanel.java,v 1.2 2004/11/19 11:38:54 mungady Exp $
  34. *
  35. * Changes (from 22-Jun-2001)
  36. * --------------------------
  37. * 22-Jun-2001 : Disabled title panel, as it doesn't support the new title code (DG);
  38. * 24-Aug-2001 : Fixed DOS encoding problem (DG);
  39. * 07-Nov-2001 : Separated the JCommon Class Library classes, JFreeChart now requires
  40. * jcommon.jar (DG);
  41. * 21-Nov-2001 : Allowed for null legend (DG);
  42. * 17-Jan-2003 : Moved plot classes into separate package (DG);
  43. * 20-May-2003 : Removed titlePanel until it is implemented. (TM);
  44. * 08-Sep-2003 : Added internationalization via use of properties resourceBundle (RFE 690236) (AL);
  45. * 24-Aug-2004 : Applied patch 1014378 (DG);
  46. *
  47. */
  48. package org.jfree.chart.ui;
  49. import java.awt.BorderLayout;
  50. import java.awt.Color;
  51. import java.awt.Paint;
  52. import java.awt.event.ActionEvent;
  53. import java.awt.event.ActionListener;
  54. import java.util.ResourceBundle;
  55. import javax.swing.BorderFactory;
  56. import javax.swing.JButton;
  57. import javax.swing.JCheckBox;
  58. import javax.swing.JColorChooser;
  59. import javax.swing.JLabel;
  60. import javax.swing.JPanel;
  61. import javax.swing.JTabbedPane;
  62. import javax.swing.JTextField;
  63. import org.jfree.chart.JFreeChart;
  64. import org.jfree.chart.Legend;
  65. import org.jfree.chart.plot.Plot;
  66. import org.jfree.chart.title.Title;
  67. import org.jfree.layout.LCBLayout;
  68. import org.jfree.ui.PaintSample;
  69. /**
  70. * A panel for editing chart properties (includes subpanels for the title,
  71. * legend and plot).
  72. */
  73. public class ChartPropertyEditPanel extends JPanel implements ActionListener {
  74. /** A panel for displaying/editing the properties of the title. */
  75. private TitlePropertyEditPanel titlePropertiesPanel;
  76. /** A panel for displaying/editing the properties of the legend. */
  77. private LegendPropertyEditPanel legendPropertiesPanel;
  78. /** A panel for displaying/editing the properties of the plot. */
  79. private PlotPropertyEditPanel plotPropertiesPanel;
  80. /** A checkbox indicating whether or not the chart is drawn with
  81. * anti-aliasing.
  82. */
  83. private JCheckBox antialias;
  84. /** The chart background color. */
  85. private PaintSample background;
  86. /** The resourceBundle for the localization. */
  87. protected static ResourceBundle localizationResources
  88. = ResourceBundle.getBundle("org.jfree.chart.ui.LocalizationBundle");
  89. /**
  90. * Standard constructor - the property panel is made up of a number of
  91. * sub-panels that are displayed in the tabbed pane.
  92. *
  93. * @param chart the chart, whichs properties should be changed.
  94. */
  95. public ChartPropertyEditPanel(JFreeChart chart) {
  96. setLayout(new BorderLayout());
  97. JPanel other = new JPanel(new BorderLayout());
  98. other.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
  99. JPanel general = new JPanel(new BorderLayout());
  100. general.setBorder(
  101. BorderFactory.createTitledBorder(
  102. BorderFactory.createEtchedBorder(),
  103. localizationResources.getString("General")
  104. )
  105. );
  106. JPanel interior = new JPanel(new LCBLayout(6));
  107. interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
  108. this.antialias = new JCheckBox(localizationResources.getString("Draw_anti-aliased"));
  109. this.antialias.setSelected(chart.getAntiAlias());
  110. interior.add(this.antialias);
  111. interior.add(new JLabel(""));
  112. interior.add(new JLabel(""));
  113. interior.add(new JLabel(localizationResources.getString("Background_paint")));
  114. this.background = new PaintSample(chart.getBackgroundPaint());
  115. interior.add(this.background);
  116. JButton button = new JButton(localizationResources.getString("Select..."));
  117. button.setActionCommand("BackgroundPaint");
  118. button.addActionListener(this);
  119. interior.add(button);
  120. interior.add(new JLabel(localizationResources.getString("Series_Paint")));
  121. JTextField info = new JTextField(localizationResources.getString("No_editor_implemented"));
  122. info.setEnabled(false);
  123. interior.add(info);
  124. button = new JButton(localizationResources.getString("Edit..."));
  125. button.setEnabled(false);
  126. interior.add(button);
  127. interior.add(new JLabel(localizationResources.getString("Series_Stroke")));
  128. info = new JTextField(localizationResources.getString("No_editor_implemented"));
  129. info.setEnabled(false);
  130. interior.add(info);
  131. button = new JButton(localizationResources.getString("Edit..."));
  132. button.setEnabled(false);
  133. interior.add(button);
  134. interior.add(new JLabel(localizationResources.getString("Series_Outline_Paint")));
  135. info = new JTextField(localizationResources.getString("No_editor_implemented"));
  136. info.setEnabled(false);
  137. interior.add(info);
  138. button = new JButton(localizationResources.getString("Edit..."));
  139. button.setEnabled(false);
  140. interior.add(button);
  141. interior.add(new JLabel(localizationResources.getString("Series_Outline_Stroke")));
  142. info = new JTextField(localizationResources.getString("No_editor_implemented"));
  143. info.setEnabled(false);
  144. interior.add(info);
  145. button = new JButton(localizationResources.getString("Edit..."));
  146. button.setEnabled(false);
  147. interior.add(button);
  148. general.add(interior, BorderLayout.NORTH);
  149. other.add(general, BorderLayout.NORTH);
  150. JPanel parts = new JPanel(new BorderLayout());
  151. Title title = chart.getTitle();
  152. Legend legend = chart.getLegend();
  153. Plot plot = chart.getPlot();
  154. JTabbedPane tabs = new JTabbedPane();
  155. this.titlePropertiesPanel = new TitlePropertyEditPanel(title);
  156. this.titlePropertiesPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
  157. tabs.addTab(localizationResources.getString("Title"), this.titlePropertiesPanel);
  158. this.legendPropertiesPanel = new LegendPropertyEditPanel(legend);
  159. this.legendPropertiesPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
  160. tabs.addTab(localizationResources.getString("Legend"), this.legendPropertiesPanel);
  161. this.plotPropertiesPanel = new PlotPropertyEditPanel(plot);
  162. this.plotPropertiesPanel.setBorder(BorderFactory.createEmptyBorder(2, 2, 2, 2));
  163. tabs.addTab(localizationResources.getString("Plot"), this.plotPropertiesPanel);
  164. tabs.add(localizationResources.getString("Other"), other);
  165. parts.add(tabs, BorderLayout.NORTH);
  166. add(parts);
  167. }
  168. /**
  169. * Returns a reference to the title property sub-panel.
  170. *
  171. * @return A panel for editing the title.
  172. */
  173. public TitlePropertyEditPanel getTitlePropertyEditPanel() {
  174. return this.titlePropertiesPanel;
  175. }
  176. /**
  177. * Returns a reference to the legend property sub-panel.
  178. *
  179. * @return A panel for editing the legend.
  180. */
  181. public LegendPropertyEditPanel getLegendPropertyEditPanel() {
  182. return this.legendPropertiesPanel;
  183. }
  184. /**
  185. * Returns a reference to the plot property sub-panel.
  186. *
  187. * @return A panel for editing the plot properties.
  188. */
  189. public PlotPropertyEditPanel getPlotPropertyEditPanel() {
  190. return this.plotPropertiesPanel;
  191. }
  192. /**
  193. * Returns the current setting of the anti-alias flag.
  194. *
  195. * @return <code>true</code> if anti-aliasing is enabled.
  196. */
  197. public boolean getAntiAlias() {
  198. return this.antialias.isSelected();
  199. }
  200. /**
  201. * Returns the current background paint.
  202. *
  203. * @return The current background paint.
  204. */
  205. public Paint getBackgroundPaint() {
  206. return this.background.getPaint();
  207. }
  208. /**
  209. * Handles user interactions with the panel.
  210. *
  211. * @param event a BackgroundPaint action.
  212. */
  213. public void actionPerformed(ActionEvent event) {
  214. String command = event.getActionCommand();
  215. if (command.equals("BackgroundPaint")) {
  216. attemptModifyBackgroundPaint();
  217. }
  218. }
  219. /**
  220. * Allows the user the opportunity to select a new background paint. Uses
  221. * JColorChooser, so we are only allowing a subset of all Paint objects to
  222. * be selected (fix later).
  223. */
  224. private void attemptModifyBackgroundPaint() {
  225. Color c;
  226. c = JColorChooser.showDialog(
  227. this, localizationResources.getString("Background_Color"), Color.blue
  228. );
  229. if (c != null) {
  230. this.background.setPaint(c);
  231. }
  232. }
  233. /**
  234. * Updates the properties of a chart to match the properties defined on the
  235. * panel.
  236. *
  237. * @param chart the chart.
  238. */
  239. public void updateChartProperties(JFreeChart chart) {
  240. this.titlePropertiesPanel.setTitleProperties(chart);
  241. this.legendPropertiesPanel.setLegendProperties(chart);
  242. this.plotPropertiesPanel.updatePlotProperties(chart.getPlot());
  243. chart.setAntiAlias(getAntiAlias());
  244. chart.setBackgroundPaint(getBackgroundPaint());
  245. }
  246. }