Source Code Cross Referenced for SWTTitleEditor.java in  » Chart » jfreechart » org » jfree » experimental » chart » swt » editor » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » Chart » jfreechart » org.jfree.experimental.chart.swt.editor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /* ===========================================================
002:         * JFreeChart : a free chart library for the Java(tm) platform
003:         * ===========================================================
004:         *
005:         * (C) Copyright 2000-2006, 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:         * SWTTitleEditor.java
029:         * -------------------
030:         * (C) Copyright 2006, 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.util.ResourceBundle;
044:
045:        import org.eclipse.swt.SWT;
046:        import org.eclipse.swt.events.SelectionAdapter;
047:        import org.eclipse.swt.events.SelectionEvent;
048:        import org.eclipse.swt.graphics.Color;
049:        import org.eclipse.swt.graphics.Font;
050:        import org.eclipse.swt.graphics.FontData;
051:        import org.eclipse.swt.graphics.RGB;
052:        import org.eclipse.swt.layout.FillLayout;
053:        import org.eclipse.swt.layout.GridData;
054:        import org.eclipse.swt.layout.GridLayout;
055:        import org.eclipse.swt.widgets.Button;
056:        import org.eclipse.swt.widgets.ColorDialog;
057:        import org.eclipse.swt.widgets.Composite;
058:        import org.eclipse.swt.widgets.FontDialog;
059:        import org.eclipse.swt.widgets.Group;
060:        import org.eclipse.swt.widgets.Label;
061:        import org.eclipse.swt.widgets.Text;
062:        import org.jfree.chart.JFreeChart;
063:        import org.jfree.chart.title.TextTitle;
064:        import org.jfree.chart.title.Title;
065:        import org.jfree.experimental.swt.SWTPaintCanvas;
066:        import org.jfree.experimental.swt.SWTUtils;
067:
068:        /**
069:         * An editor for chart title properties.
070:         */
071:        class SWTTitleEditor extends Composite {
072:
073:            /** Whether or not to display the title on the chart. */
074:            private boolean showTitle;
075:
076:            /** The checkbox to indicate whether or not to display the title. */
077:            private Button showTitleCheckBox;
078:
079:            /** A field for displaying/editing the title text. */
080:            private Text titleField;
081:
082:            /** The font used to draw the title. */
083:            private FontData titleFont;
084:
085:            /** A field for displaying a description of the title font. */
086:            private Text fontField;
087:
088:            /** The button to use to select a new title font. */
089:            private Button selectFontButton;
090:
091:            /** The paint (color) used to draw the title. */
092:            private Color titleColor;
093:
094:            /** The button to use to select a new paint (color) to draw the title. */
095:            private Button selectColorButton;
096:
097:            /** The resourceBundle for the localization. */
098:            protected static ResourceBundle localizationResources = ResourceBundle
099:                    .getBundle("org.jfree.chart.editor.LocalizationBundle");
100:
101:            /** Font object used to handle a change of font. */
102:            private Font font;
103:
104:            /**
105:             * Standard constructor: builds a panel for displaying/editing the
106:             * properties of the specified title.
107:             *
108:             * @param title  the title, which should be changed.
109:             */
110:            SWTTitleEditor(Composite parent, int style, Title title) {
111:                super (parent, style);
112:                FillLayout layout = new FillLayout();
113:                layout.marginHeight = layout.marginWidth = 4;
114:                setLayout(layout);
115:
116:                TextTitle t = (title != null ? (TextTitle) title
117:                        : new TextTitle(localizationResources
118:                                .getString("Title")));
119:                this .showTitle = (title != null);
120:                this .titleFont = SWTUtils.toSwtFontData(getDisplay(), t
121:                        .getFont(), true);
122:                this .titleColor = SWTUtils.toSwtColor(getDisplay(), t
123:                        .getPaint());
124:
125:                Group general = new Group(this , SWT.NONE);
126:                general.setLayout(new GridLayout(3, false));
127:                general.setText(localizationResources.getString("General"));
128:                // row 1
129:                Label label = new Label(general, SWT.NONE);
130:                label.setText(localizationResources.getString("Show_Title"));
131:                GridData gridData = new GridData();
132:                gridData.horizontalSpan = 2;
133:                label.setLayoutData(gridData);
134:                showTitleCheckBox = new Button(general, SWT.CHECK);
135:                showTitleCheckBox.setSelection(this .showTitle);
136:                showTitleCheckBox.setLayoutData(new GridData(SWT.CENTER,
137:                        SWT.CENTER, false, false));
138:                showTitleCheckBox.addSelectionListener(new SelectionAdapter() {
139:                    public void widgetSelected(SelectionEvent event) {
140:                        showTitle = showTitleCheckBox.getSelection();
141:                    }
142:                });
143:                // row 2
144:                new Label(general, SWT.NONE).setText(localizationResources
145:                        .getString("Text"));
146:                titleField = new Text(general, SWT.BORDER);
147:                titleField.setText(t.getText());
148:                titleField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
149:                        true, false));
150:                new Label(general, SWT.NONE).setText("");
151:                // row 3
152:                new Label(general, SWT.NONE).setText(localizationResources
153:                        .getString("Font"));
154:                fontField = new Text(general, SWT.BORDER);
155:                fontField.setText(titleFont.toString());
156:                fontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
157:                        true, false));
158:                selectFontButton = new Button(general, SWT.PUSH);
159:                selectFontButton.setText(localizationResources
160:                        .getString("Select..."));
161:                selectFontButton.addSelectionListener(new SelectionAdapter() {
162:                    public void widgetSelected(SelectionEvent event) {
163:                        // Create the font-change dialog
164:                        FontDialog dlg = new FontDialog(getShell());
165:                        dlg.setText(localizationResources
166:                                .getString("Font_Selection"));
167:                        dlg.setFontList(new FontData[] { titleFont });
168:                        if (dlg.open() != null) {
169:                            // Dispose of any fonts we have created
170:                            if (font != null)
171:                                font.dispose();
172:                            // Create the new font and set it into the title 
173:                            // label
174:                            font = new Font(getShell().getDisplay(), dlg
175:                                    .getFontList());
176:                            //titleField.setFont(font);
177:                            fontField.setText(font.getFontData()[0].toString());
178:                            titleFont = font.getFontData()[0];
179:                        }
180:                    }
181:                });
182:                // row 4
183:                new Label(general, SWT.NONE).setText(localizationResources
184:                        .getString("Color"));
185:                // Use a SwtPaintCanvas to show the color, note that we must set the 
186:                // heightHint.
187:                final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general,
188:                        SWT.NONE, this .titleColor);
189:                GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER,
190:                        true, false);
191:                canvasGridData.heightHint = 20;
192:                colorCanvas.setLayoutData(canvasGridData);
193:                selectColorButton = new Button(general, SWT.PUSH);
194:                selectColorButton.setText(localizationResources
195:                        .getString("Select..."));
196:                selectColorButton.addSelectionListener(new SelectionAdapter() {
197:                    public void widgetSelected(SelectionEvent event) {
198:                        // Create the color-change dialog
199:                        ColorDialog dlg = new ColorDialog(getShell());
200:                        dlg.setText(localizationResources
201:                                .getString("Title_Color"));
202:                        dlg.setRGB(titleColor.getRGB());
203:                        RGB rgb = dlg.open();
204:                        if (rgb != null) {
205:                            // create the new color and set it to the 
206:                            // SwtPaintCanvas
207:                            titleColor = new Color(getDisplay(), rgb);
208:                            colorCanvas.setColor(titleColor);
209:                        }
210:                    }
211:                });
212:            }
213:
214:            /**
215:             * Returns the title text entered in the panel.
216:             *
217:             * @return The title text entered in the panel.
218:             */
219:            public String getTitleText() {
220:                return this .titleField.getText();
221:            }
222:
223:            /**
224:             * Returns the font selected in the panel.
225:             *
226:             * @return The font selected in the panel.
227:             */
228:            public FontData getTitleFont() {
229:                return this .titleFont;
230:            }
231:
232:            /**
233:             * Returns the font selected in the panel.
234:             *
235:             * @return The font selected in the panel.
236:             */
237:            public Color getTitleColor() {
238:                return this .titleColor;
239:            }
240:
241:            /**
242:             * Sets the properties of the specified title to match the properties
243:             * defined on this panel.
244:             *
245:             * @param chart  the chart whose title is to be modified.
246:             */
247:            public void setTitleProperties(JFreeChart chart) {
248:                if (this .showTitle) {
249:                    TextTitle title = chart.getTitle();
250:                    if (title == null) {
251:                        title = new TextTitle();
252:                        chart.setTitle(title);
253:                    }
254:                    title.setText(getTitleText());
255:                    title.setFont(SWTUtils.toAwtFont(getDisplay(),
256:                            getTitleFont(), true));
257:                    title.setPaint(SWTUtils.toAwtColor(getTitleColor()));
258:                } else {
259:                    chart.setTitle((TextTitle) null);
260:                }
261:            }
262:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.