KickJava   Java API By Example, From Geeks To Geeks.

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


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  * SWTPlotEditor.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.awt.Stroke JavaDoc;
44 import java.util.ResourceBundle JavaDoc;
45
46 import org.eclipse.swt.SWT;
47 import org.eclipse.swt.graphics.Color;
48 import org.eclipse.swt.layout.FillLayout;
49 import org.eclipse.swt.widgets.Composite;
50 import org.eclipse.swt.widgets.Group;
51 import org.eclipse.swt.widgets.TabFolder;
52 import org.eclipse.swt.widgets.TabItem;
53 import org.jfree.chart.axis.Axis;
54 import org.jfree.chart.plot.CategoryPlot;
55 import org.jfree.chart.plot.Plot;
56 import org.jfree.chart.plot.XYPlot;
57 import org.jfree.experimental.swt.SWTUtils;
58
59 /**
60  * An editor for plot properties.
61  */

62 class SWTPlotEditor extends Composite {
63     
64     /**
65      * A panel used to display/edit the properties of the domain axis (if any).
66      */

67     private SWTAxisEditor domainAxisPropertyPanel;
68
69     /**
70      * A panel used to display/edit the properties of the range axis (if any).
71      */

72     private SWTAxisEditor rangeAxisPropertyPanel;
73
74     private SWTPlotAppearanceEditor plotAppearance;
75     
76     /** The resourceBundle for the localization. */
77     protected static ResourceBundle JavaDoc localizationResources
78         = ResourceBundle.getBundle("org.jfree.chart.editor.LocalizationBundle");
79
80     /**
81      * Creates a new editor for the specified plot.
82      *
83      * @param parent the parent.
84      * @param style the style.
85      * @param plot the plot.
86      */

87     public SWTPlotEditor(Composite parent, int style, Plot plot) {
88         super(parent, style);
89         FillLayout layout = new FillLayout();
90         layout.marginHeight = layout.marginWidth = 4;
91         this.setLayout(layout);
92
93         Group plotType = new Group(this, SWT.NONE);
94         FillLayout plotTypeLayout = new FillLayout();
95         plotTypeLayout.marginHeight = plotTypeLayout.marginWidth = 4;
96         plotType.setLayout(plotTypeLayout);
97         plotType.setText(plot.getPlotType() + localizationResources.getString(
98                 ":"));
99         
100         TabFolder tabs = new TabFolder(plotType, SWT.NONE);
101         
102         //deal with domain axis
103
TabItem item1 = new TabItem(tabs, SWT.NONE);
104         item1.setText(localizationResources.getString("Domain_Axis"));
105         Axis domainAxis = null;
106         if (plot instanceof CategoryPlot) {
107             domainAxis = ((CategoryPlot) plot).getDomainAxis();
108         }
109         else if (plot instanceof XYPlot) {
110             domainAxis = ((XYPlot) plot).getDomainAxis();
111         }
112         this.domainAxisPropertyPanel = SWTAxisEditor.getInstance(tabs,
113                 SWT.NONE, domainAxis);
114         item1.setControl(this.domainAxisPropertyPanel);
115         
116         //deal with range axis
117
TabItem item2 = new TabItem(tabs, SWT.NONE);
118         item2.setText(localizationResources.getString("Range_Axis"));
119         Axis rangeAxis = null;
120         if (plot instanceof CategoryPlot) {
121             rangeAxis = ((CategoryPlot) plot).getRangeAxis();
122         }
123         else if (plot instanceof XYPlot) {
124             rangeAxis = ((XYPlot) plot).getRangeAxis();
125         }
126         this.rangeAxisPropertyPanel = SWTAxisEditor.getInstance(tabs, SWT.NONE,
127                 rangeAxis);
128         item2.setControl(this.rangeAxisPropertyPanel);
129         
130         //deal with plot appearance
131
TabItem item3 = new TabItem(tabs, SWT.NONE);
132         item3.setText(localizationResources.getString("Appearance"));
133         plotAppearance = new SWTPlotAppearanceEditor(tabs, SWT.NONE, plot);
134         item3.setControl(plotAppearance);
135     }
136
137     /**
138      * Returns the current outline stroke.
139      *
140      * @return The current outline stroke.
141      */

142     public Color getBackgroundPaint() {
143         return this.plotAppearance.getBackGroundPaint();
144     }
145
146     /**
147      * Returns the current outline stroke.
148      *
149      * @return The current outline stroke.
150      */

151     public Color getOutlinePaint() {
152         return this.plotAppearance.getOutlinePaint();
153     }
154
155     /**
156      * Returns the current outline stroke.
157      *
158      * @return The current outline stroke.
159      */

160     public Stroke JavaDoc getOutlineStroke() {
161         return this.plotAppearance.getStroke();
162     }
163
164
165     /**
166      * Updates the plot properties to match the properties
167      * defined on the panel.
168      *
169      * @param plot The plot.
170      */

171     public void updatePlotProperties(Plot plot) {
172         // set the plot properties...
173
plot.setBackgroundPaint(SWTUtils.toAwtColor(getBackgroundPaint()));
174         plot.setOutlinePaint(SWTUtils.toAwtColor(getOutlinePaint()));
175         plot.setOutlineStroke(getOutlineStroke());
176         
177         // set the axis properties
178
if (this.domainAxisPropertyPanel != null) {
179             Axis domainAxis = null;
180             if (plot instanceof CategoryPlot) {
181                 CategoryPlot p = (CategoryPlot) plot;
182                 domainAxis = p.getDomainAxis();
183             }
184             else if (plot instanceof XYPlot) {
185                 XYPlot p = (XYPlot) plot;
186                 domainAxis = p.getDomainAxis();
187             }
188             if (domainAxis != null)
189                 this.domainAxisPropertyPanel.setAxisProperties(domainAxis);
190         }
191         if (this.rangeAxisPropertyPanel != null) {
192             Axis rangeAxis = null;
193             if (plot instanceof CategoryPlot) {
194                 CategoryPlot p = (CategoryPlot) plot;
195                 rangeAxis = p.getRangeAxis();
196             }
197             else if (plot instanceof XYPlot) {
198                 XYPlot p = ( XYPlot ) plot;
199                 rangeAxis = p.getRangeAxis();
200             }
201             if (rangeAxis != null)
202                 this.rangeAxisPropertyPanel.setAxisProperties(rangeAxis);
203         }
204         if (this.plotAppearance.getPlotOrientation() != null) {
205             if (plot instanceof CategoryPlot) {
206                 CategoryPlot p = (CategoryPlot) plot;
207                 p.setOrientation(this.plotAppearance.getPlotOrientation() );
208             }
209             else if (plot instanceof XYPlot) {
210                 XYPlot p = (XYPlot) plot;
211                 p.setOrientation(this.plotAppearance.getPlotOrientation());
212             }
213         }
214     }
215 }
216
Popular Tags