Source Code Cross Referenced for SWTAxisEditor.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-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:         * SWTAxisEditor.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:         * 07-Feb-2007 : Fixed bug 1647749, handle null axis labels (DG);
039:         * 
040:         */
041:
042:        package org.jfree.experimental.chart.swt.editor;
043:
044:        import java.awt.Paint;
045:        import java.util.ResourceBundle;
046:
047:        import org.eclipse.swt.SWT;
048:        import org.eclipse.swt.events.SelectionAdapter;
049:        import org.eclipse.swt.events.SelectionEvent;
050:        import org.eclipse.swt.graphics.Color;
051:        import org.eclipse.swt.graphics.Font;
052:        import org.eclipse.swt.graphics.FontData;
053:        import org.eclipse.swt.graphics.RGB;
054:        import org.eclipse.swt.layout.FillLayout;
055:        import org.eclipse.swt.layout.GridData;
056:        import org.eclipse.swt.layout.GridLayout;
057:        import org.eclipse.swt.widgets.Button;
058:        import org.eclipse.swt.widgets.ColorDialog;
059:        import org.eclipse.swt.widgets.Composite;
060:        import org.eclipse.swt.widgets.FontDialog;
061:        import org.eclipse.swt.widgets.Group;
062:        import org.eclipse.swt.widgets.Label;
063:        import org.eclipse.swt.widgets.TabFolder;
064:        import org.eclipse.swt.widgets.TabItem;
065:        import org.eclipse.swt.widgets.Text;
066:        import org.jfree.chart.axis.Axis;
067:        import org.jfree.chart.axis.NumberAxis;
068:        import org.jfree.experimental.swt.SWTPaintCanvas;
069:        import org.jfree.experimental.swt.SWTUtils;
070:
071:        /**
072:         * An editor for axis properties.
073:         */
074:        class SWTAxisEditor extends Composite {
075:
076:            /** The axis label. */
077:            private Text label;
078:
079:            /** The font used to draw the axis labels. */
080:            private FontData labelFont;
081:
082:            /** The paint (color) used to draw the axis labels. */
083:            private Color labelPaintColor;
084:
085:            /** The font used to draw the axis tick labels. */
086:            private FontData tickLabelFont;
087:
088:            /** The paint (color) used to draw the axis tick labels. */
089:            private Color tickLabelPaintColor;
090:
091:            /** A field showing a description of the label font. */
092:            private Text labelFontField;
093:
094:            /** 
095:             * A field containing a description of the font 
096:             * for displaying tick labels on the axis. 
097:             */
098:            private Text tickLabelFontField;
099:
100:            /** The resourceBundle for the localization. */
101:            protected static ResourceBundle localizationResources = ResourceBundle
102:                    .getBundle("org.jfree.chart.editor.LocalizationBundle");
103:
104:            /** Font object used to handle a change of font. */
105:            private Font font;
106:
107:            /** A flag that indicates whether or not the tick labels are visible. */
108:            private Button showTickLabelsCheckBox;
109:
110:            /** A flag that indicates whether or not the tick marks are visible. */
111:            private Button showTickMarksCheckBox;
112:
113:            /** A tabbed pane for... */
114:            private TabFolder otherTabs;
115:
116:            /**
117:             * Standard constructor: builds a composite for displaying/editing 
118:             * the properties of the specified axis.
119:             *
120:             * @param parent The parent composite.
121:             * @param style The SWT style of the SwtAxisEditor.
122:             * @param axis  the axis whose properties are to be displayed/edited  
123:             *              in the composite.
124:             */
125:            public SWTAxisEditor(Composite parent, int style, Axis axis) {
126:                super (parent, style);
127:                this .labelFont = SWTUtils.toSwtFontData(getDisplay(), axis
128:                        .getLabelFont(), true);
129:                this .labelPaintColor = SWTUtils.toSwtColor(getDisplay(), axis
130:                        .getLabelPaint());
131:                this .tickLabelFont = SWTUtils.toSwtFontData(getDisplay(), axis
132:                        .getTickLabelFont(), true);
133:                this .tickLabelPaintColor = SWTUtils.toSwtColor(getDisplay(),
134:                        axis.getTickLabelPaint());
135:
136:                FillLayout layout = new FillLayout(SWT.VERTICAL);
137:                layout.marginHeight = layout.marginWidth = 4;
138:                this .setLayout(layout);
139:                Group general = new Group(this , SWT.NONE);
140:                general.setLayout(new GridLayout(3, false));
141:                general.setText(localizationResources.getString("General"));
142:                // row 1
143:                new Label(general, SWT.NONE).setText(localizationResources
144:                        .getString("Label"));
145:                label = new Text(general, SWT.BORDER);
146:                if (axis.getLabel() != null) {
147:                    label.setText(axis.getLabel());
148:                }
149:                label.setLayoutData(new GridData(SWT.FILL, SWT.CENTER, true,
150:                        false));
151:                new Label(general, SWT.NONE).setText(""); //empty cell
152:                // row 2
153:                new Label(general, SWT.NONE).setText(localizationResources
154:                        .getString("Font"));
155:                labelFontField = new Text(general, SWT.BORDER);
156:                labelFontField.setText(this .labelFont.toString());
157:                labelFontField.setLayoutData(new GridData(SWT.FILL, SWT.CENTER,
158:                        true, false));
159:                Button selectFontButton = new Button(general, SWT.PUSH);
160:                selectFontButton.setText(localizationResources
161:                        .getString("Select..."));
162:                selectFontButton.addSelectionListener(new SelectionAdapter() {
163:                    public void widgetSelected(SelectionEvent event) {
164:                        // Create the color-change dialog
165:                        FontDialog dlg = new FontDialog(getShell());
166:                        dlg.setText(localizationResources
167:                                .getString("Font_Selection"));
168:                        dlg.setFontList(new FontData[] { labelFont });
169:                        if (dlg.open() != null) {
170:                            // Dispose of any fonts we have created
171:                            if (font != null) {
172:                                font.dispose();
173:                            }
174:                            // Create the new font and set it into the title 
175:                            // label
176:                            font = new Font(getShell().getDisplay(), dlg
177:                                    .getFontList());
178:                            //label.setFont( font );
179:                            labelFontField.setText(font.getFontData()[0]
180:                                    .toString());
181:                            labelFont = font.getFontData()[0];
182:                        }
183:                    }
184:                });
185:                // row 3
186:                new Label(general, SWT.NONE).setText(localizationResources
187:                        .getString("Paint"));
188:                // Use a colored text field to show the color
189:                final SWTPaintCanvas colorCanvas = new SWTPaintCanvas(general,
190:                        SWT.NONE, this .labelPaintColor);
191:                GridData canvasGridData = new GridData(SWT.FILL, SWT.CENTER,
192:                        true, false);
193:                canvasGridData.heightHint = 20;
194:                colorCanvas.setLayoutData(canvasGridData);
195:                Button selectColorButton = new Button(general, SWT.PUSH);
196:                selectColorButton.setText(localizationResources
197:                        .getString("Select..."));
198:                selectColorButton.addSelectionListener(new SelectionAdapter() {
199:                    public void widgetSelected(SelectionEvent event) {
200:                        // Create the color-change dialog
201:                        ColorDialog dlg = new ColorDialog(getShell());
202:                        dlg.setText(localizationResources
203:                                .getString("Title_Color"));
204:                        dlg.setRGB(labelPaintColor.getRGB());
205:                        RGB rgb = dlg.open();
206:                        if (rgb != null) {
207:                            // create the new color and set it to the 
208:                            // SwtPaintCanvas
209:                            labelPaintColor = new Color(getDisplay(), rgb);
210:                            colorCanvas.setColor(labelPaintColor);
211:                        }
212:                    }
213:                });
214:                Group other = new Group(this , SWT.NONE);
215:                FillLayout tabLayout = new FillLayout();
216:                tabLayout.marginHeight = tabLayout.marginWidth = 4;
217:                other.setLayout(tabLayout);
218:                other.setText(localizationResources.getString("Other"));
219:
220:                otherTabs = new TabFolder(other, SWT.NONE);
221:                TabItem item1 = new TabItem(otherTabs, SWT.NONE);
222:                item1.setText(" " + localizationResources.getString("Ticks")
223:                        + " ");
224:                Composite ticks = new Composite(otherTabs, SWT.NONE);
225:                ticks.setLayout(new GridLayout(3, false));
226:                showTickLabelsCheckBox = new Button(ticks, SWT.CHECK);
227:                showTickLabelsCheckBox.setText(localizationResources
228:                        .getString("Show_tick_labels"));
229:                showTickLabelsCheckBox.setSelection(axis.isTickLabelsVisible());
230:                showTickLabelsCheckBox.setLayoutData(new GridData(SWT.FILL,
231:                        SWT.CENTER, true, false, 3, 1));
232:                new Label(ticks, SWT.NONE).setText(localizationResources
233:                        .getString("Tick_label_font"));
234:                tickLabelFontField = new Text(ticks, SWT.BORDER);
235:                tickLabelFontField.setText(this .tickLabelFont.toString());
236:                //tickLabelFontField.setFont(SwtUtils.toSwtFontData(getDisplay(), 
237:                // axis.getTickLabelFont()));
238:                tickLabelFontField.setLayoutData(new GridData(SWT.FILL,
239:                        SWT.CENTER, true, false));
240:                Button selectTickLabelFontButton = new Button(ticks, SWT.PUSH);
241:                selectTickLabelFontButton.setText(localizationResources
242:                        .getString("Select..."));
243:                selectTickLabelFontButton
244:                        .addSelectionListener(new SelectionAdapter() {
245:                            public void widgetSelected(SelectionEvent event) {
246:                                // Create the font-change dialog
247:                                FontDialog dlg = new FontDialog(getShell());
248:                                dlg.setText(localizationResources
249:                                        .getString("Font_Selection"));
250:                                dlg
251:                                        .setFontList(new FontData[] { tickLabelFont });
252:                                if (dlg.open() != null) {
253:                                    // Dispose of any fonts we have created
254:                                    if (font != null)
255:                                        font.dispose();
256:                                    // Create the new font and set it into the title label
257:                                    font = new Font(getShell().getDisplay(),
258:                                            dlg.getFontList());
259:                                    //tickLabelFontField.setFont(font);
260:                                    tickLabelFontField.setText(font
261:                                            .getFontData()[0].toString());
262:                                    tickLabelFont = font.getFontData()[0];
263:                                }
264:                            }
265:                        });
266:                showTickMarksCheckBox = new Button(ticks, SWT.CHECK);
267:                showTickMarksCheckBox.setText(localizationResources
268:                        .getString("Show_tick_marks"));
269:                showTickMarksCheckBox.setSelection(axis.isTickMarksVisible());
270:                showTickMarksCheckBox.setLayoutData(new GridData(SWT.FILL,
271:                        SWT.CENTER, true, false, 3, 1));
272:                item1.setControl(ticks);
273:            }
274:
275:            /**
276:             * A static method that returns a panel that is appropriate 
277:             * for the axis type.
278:             *
279:             * @param parent  the parent.
280:             * @param style  the style.
281:             * @param axis  the axis whose properties are to be displayed/edited  
282:             *              in the composite.
283:             * @return A composite or <code>null</code< if axis is <code>null</code>.
284:             */
285:            public static SWTAxisEditor getInstance(Composite parent,
286:                    int style, Axis axis) {
287:
288:                if (axis != null) {
289:                    // return the appropriate axis editor
290:                    if (axis instanceof  NumberAxis)
291:                        return new SWTNumberAxisEditor(parent, style,
292:                                (NumberAxis) axis);
293:                    else
294:                        return new SWTAxisEditor(parent, style, axis);
295:                } else
296:                    return null;
297:            }
298:
299:            /**
300:             * Returns a reference to the tabbed composite.
301:             *
302:             * @return A reference to the tabbed composite.
303:             */
304:            public TabFolder getOtherTabs() {
305:                return this .otherTabs;
306:            }
307:
308:            /**
309:             * Returns the current axis label.
310:             *
311:             * @return The current axis label.
312:             */
313:            public String getLabel() {
314:                return this .label.getText();
315:            }
316:
317:            /**
318:             * Returns the current label font.
319:             *
320:             * @return The current label font.
321:             */
322:            public java.awt.Font getLabelFont() {
323:                return SWTUtils.toAwtFont(getDisplay(), this .labelFont, true);
324:            }
325:
326:            /**
327:             * Returns the current label paint.
328:             *
329:             * @return The current label paint.
330:             */
331:            public Paint getTickLabelPaint() {
332:                return SWTUtils.toAwtColor(this .tickLabelPaintColor);
333:            }
334:
335:            /**
336:             * Returns the current label font.
337:             *
338:             * @return The current label font.
339:             */
340:            public java.awt.Font getTickLabelFont() {
341:                return SWTUtils.toAwtFont(getDisplay(), tickLabelFont, true);
342:            }
343:
344:            /**
345:             * Returns the current label paint.
346:             *
347:             * @return The current label paint.
348:             */
349:            public Paint getLabelPaint() {
350:                return SWTUtils.toAwtColor(this .labelPaintColor);
351:            }
352:
353:            /**
354:             * Sets the properties of the specified axis to match 
355:             * the properties defined on this panel.
356:             *
357:             * @param axis  the axis.
358:             */
359:            public void setAxisProperties(Axis axis) {
360:                axis.setLabel(getLabel());
361:                axis.setLabelFont(getLabelFont());
362:                axis.setLabelPaint(getLabelPaint());
363:                axis.setTickMarksVisible(showTickMarksCheckBox.getSelection());
364:                axis
365:                        .setTickLabelsVisible(showTickLabelsCheckBox
366:                                .getSelection());
367:                axis.setTickLabelFont(getTickLabelFont());
368:                axis.setTickLabelPaint(getTickLabelPaint());
369:            }
370:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.