KickJava   Java API By Example, From Geeks To Geeks.

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


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  * SWTOtherEditor.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.util.ResourceBundle JavaDoc;
44
45 import org.eclipse.swt.SWT;
46 import org.eclipse.swt.events.SelectionAdapter;
47 import org.eclipse.swt.events.SelectionEvent;
48 import org.eclipse.swt.graphics.Color;
49 import org.eclipse.swt.graphics.RGB;
50 import org.eclipse.swt.layout.FillLayout;
51 import org.eclipse.swt.layout.GridData;
52 import org.eclipse.swt.layout.GridLayout;
53 import org.eclipse.swt.widgets.Button;
54 import org.eclipse.swt.widgets.ColorDialog;
55 import org.eclipse.swt.widgets.Composite;
56 import org.eclipse.swt.widgets.Group;
57 import org.eclipse.swt.widgets.Label;
58 import org.jfree.chart.JFreeChart;
59 import org.jfree.experimental.swt.SWTPaintCanvas;
60 import org.jfree.experimental.swt.SWTUtils;
61
62 /**
63  * An editor for miscellaneous chart properties.
64  */

65 class SWTOtherEditor extends Composite {
66     
67     /** A checkbox indicating whether or not
68      * the chart is drawn with anti-aliasing. */

69     private Button antialias;
70
71     /** The chart background color. */
72     private SWTPaintCanvas backgroundPaintCanvas;
73
74     /** The resourceBundle for the localization. */
75     protected static ResourceBundle JavaDoc localizationResources
76         = ResourceBundle.getBundle("org.jfree.chart.editor.LocalizationBundle");
77
78     /**
79      * Creates a new instance.
80      *
81      * @param parent the parent.
82      * @param style the style.
83      * @param chart the chart.
84      */

85     public SWTOtherEditor(Composite parent, int style, JFreeChart chart)
86     {
87         super(parent, style);
88         FillLayout layout = new FillLayout();
89         layout.marginHeight = layout.marginWidth = 4;
90         setLayout(layout);
91
92         Group general = new Group(this, SWT.NONE);
93         general.setLayout(new GridLayout(3, false));
94         general.setText(localizationResources.getString("General"));
95         
96         // row 1: antialiasing
97
antialias = new Button(general, SWT.CHECK);
98         antialias.setText(localizationResources.getString("Draw_anti-aliased"));
99         antialias.setLayoutData(new GridData(SWT.LEFT, SWT.CENTER, true, false,
100                 3, 1));
101         antialias.setSelection(chart.getAntiAlias());
102         
103         //row 2: background paint for the chart
104
new Label(general, SWT.NONE).setText(localizationResources.getString(
105                 "Background_paint"));
106         backgroundPaintCanvas = new SWTPaintCanvas(general, SWT.NONE,
107                 SWTUtils.toSwtColor(getDisplay(), chart.getBackgroundPaint()));
108         GridData bgGridData = new GridData(SWT.FILL, SWT.CENTER, true, false);
109         bgGridData.heightHint = 20;
110         backgroundPaintCanvas.setLayoutData(bgGridData);
111         Button selectBgPaint = new Button(general, SWT.PUSH);
112         selectBgPaint.setText(localizationResources.getString("Select..."));
113         selectBgPaint.setLayoutData(new GridData(SWT.CENTER, SWT.CENTER, false,
114                 false));
115         selectBgPaint.addSelectionListener(
116                 new SelectionAdapter() {
117                     public void widgetSelected(SelectionEvent event) {
118                         ColorDialog dlg = new ColorDialog(getShell());
119                         dlg.setText(localizationResources.getString(
120                                 "Background_paint"));
121                         dlg.setRGB(backgroundPaintCanvas.getColor().getRGB());
122                         RGB rgb = dlg.open();
123                         if (rgb != null) {
124                             backgroundPaintCanvas.setColor(
125                                     new Color(getDisplay(), rgb));
126                         }
127                     }
128                 }
129         );
130     }
131     
132     /**
133      * Updates the chart.
134      *
135      * @param chart the chart.
136      */

137     public void updateChartProperties(JFreeChart chart) {
138         chart.setAntiAlias(this.antialias.getSelection());
139         chart.setBackgroundPaint(SWTUtils.toAwtColor(
140                 this.backgroundPaintCanvas.getColor()));
141     }
142
143 }
144
Popular Tags