001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2007, 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: * SWTPlotEditor.java
029: * ------------------
030: * (C) Copyright 2006, 2007, by Henry Proudhon and Contributors.
031: *
032: * Original Author: Henry Proudhon (henry.proudhon AT insa-lyon.fr);
033: * Contributor(s): David Gilbert (for Object Refinery Limited);
034: *
035: * Changes
036: * -------
037: * 01-Aug-2006 : New class (HP);
038: *
039: */
040:
041: package org.jfree.experimental.chart.swt.editor;
042:
043: import java.awt.Stroke;
044: import java.util.ResourceBundle;
045:
046: import org.eclipse.swt.SWT;
047: import org.eclipse.swt.graphics.Color;
048: import org.eclipse.swt.layout.FillLayout;
049: import org.eclipse.swt.widgets.Composite;
050: import org.eclipse.swt.widgets.Group;
051: import org.eclipse.swt.widgets.TabFolder;
052: import org.eclipse.swt.widgets.TabItem;
053: import org.jfree.chart.axis.Axis;
054: import org.jfree.chart.plot.CategoryPlot;
055: import org.jfree.chart.plot.Plot;
056: import org.jfree.chart.plot.XYPlot;
057: import org.jfree.experimental.swt.SWTUtils;
058:
059: /**
060: * An editor for plot properties.
061: */
062: class SWTPlotEditor extends Composite {
063:
064: /**
065: * A panel used to display/edit the properties of the domain axis (if any).
066: */
067: private SWTAxisEditor domainAxisPropertyPanel;
068:
069: /**
070: * A panel used to display/edit the properties of the range axis (if any).
071: */
072: private SWTAxisEditor rangeAxisPropertyPanel;
073:
074: private SWTPlotAppearanceEditor plotAppearance;
075:
076: /** The resourceBundle for the localization. */
077: protected static ResourceBundle localizationResources = ResourceBundle
078: .getBundle("org.jfree.chart.editor.LocalizationBundle");
079:
080: /**
081: * Creates a new editor for the specified plot.
082: *
083: * @param parent the parent.
084: * @param style the style.
085: * @param plot the plot.
086: */
087: public SWTPlotEditor(Composite parent, int style, Plot plot) {
088: super (parent, style);
089: FillLayout layout = new FillLayout();
090: layout.marginHeight = layout.marginWidth = 4;
091: this .setLayout(layout);
092:
093: Group plotType = new Group(this , SWT.NONE);
094: FillLayout plotTypeLayout = new FillLayout();
095: plotTypeLayout.marginHeight = plotTypeLayout.marginWidth = 4;
096: plotType.setLayout(plotTypeLayout);
097: plotType.setText(plot.getPlotType()
098: + localizationResources.getString(":"));
099:
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: } else if (plot instanceof XYPlot) {
109: domainAxis = ((XYPlot) plot).getDomainAxis();
110: }
111: this .domainAxisPropertyPanel = SWTAxisEditor.getInstance(tabs,
112: SWT.NONE, domainAxis);
113: item1.setControl(this .domainAxisPropertyPanel);
114:
115: //deal with range axis
116: TabItem item2 = new TabItem(tabs, SWT.NONE);
117: item2.setText(localizationResources.getString("Range_Axis"));
118: Axis rangeAxis = null;
119: if (plot instanceof CategoryPlot) {
120: rangeAxis = ((CategoryPlot) plot).getRangeAxis();
121: } else if (plot instanceof XYPlot) {
122: rangeAxis = ((XYPlot) plot).getRangeAxis();
123: }
124: this .rangeAxisPropertyPanel = SWTAxisEditor.getInstance(tabs,
125: SWT.NONE, rangeAxis);
126: item2.setControl(this .rangeAxisPropertyPanel);
127:
128: //deal with plot appearance
129: TabItem item3 = new TabItem(tabs, SWT.NONE);
130: item3.setText(localizationResources.getString("Appearance"));
131: this .plotAppearance = new SWTPlotAppearanceEditor(tabs,
132: SWT.NONE, plot);
133: item3.setControl(this .plotAppearance);
134: }
135:
136: /**
137: * Returns the current outline stroke.
138: *
139: * @return The current outline stroke.
140: */
141: public Color getBackgroundPaint() {
142: return this .plotAppearance.getBackGroundPaint();
143: }
144:
145: /**
146: * Returns the current outline stroke.
147: *
148: * @return The current outline stroke.
149: */
150: public Color getOutlinePaint() {
151: return this .plotAppearance.getOutlinePaint();
152: }
153:
154: /**
155: * Returns the current outline stroke.
156: *
157: * @return The current outline stroke.
158: */
159: public Stroke getOutlineStroke() {
160: return this .plotAppearance.getStroke();
161: }
162:
163: /**
164: * Updates the plot properties to match the properties
165: * defined on the panel.
166: *
167: * @param plot The plot.
168: */
169: public void updatePlotProperties(Plot plot) {
170: // set the plot properties...
171: plot.setBackgroundPaint(SWTUtils
172: .toAwtColor(getBackgroundPaint()));
173: plot.setOutlinePaint(SWTUtils.toAwtColor(getOutlinePaint()));
174: plot.setOutlineStroke(getOutlineStroke());
175:
176: // set the axis properties
177: if (this .domainAxisPropertyPanel != null) {
178: Axis domainAxis = null;
179: if (plot instanceof CategoryPlot) {
180: CategoryPlot p = (CategoryPlot) plot;
181: domainAxis = p.getDomainAxis();
182: } else if (plot instanceof XYPlot) {
183: XYPlot p = (XYPlot) plot;
184: domainAxis = p.getDomainAxis();
185: }
186: if (domainAxis != null)
187: this .domainAxisPropertyPanel
188: .setAxisProperties(domainAxis);
189: }
190: if (this .rangeAxisPropertyPanel != null) {
191: Axis rangeAxis = null;
192: if (plot instanceof CategoryPlot) {
193: CategoryPlot p = (CategoryPlot) plot;
194: rangeAxis = p.getRangeAxis();
195: } else if (plot instanceof XYPlot) {
196: XYPlot p = (XYPlot) plot;
197: rangeAxis = p.getRangeAxis();
198: }
199: if (rangeAxis != null)
200: this .rangeAxisPropertyPanel
201: .setAxisProperties(rangeAxis);
202: }
203: if (this .plotAppearance.getPlotOrientation() != null) {
204: if (plot instanceof CategoryPlot) {
205: CategoryPlot p = (CategoryPlot) plot;
206: p.setOrientation(this .plotAppearance
207: .getPlotOrientation());
208: } else if (plot instanceof XYPlot) {
209: XYPlot p = (XYPlot) plot;
210: p.setOrientation(this.plotAppearance
211: .getPlotOrientation());
212: }
213: }
214: }
215: }
|