Source Code Cross Referenced for DefaultAxisEditor.java in  » Chart » jfreechart » org » jfree » chart » 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.chart.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-2005, 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:         * DefaultAxisEditor.java
029:         * ----------------------
030:         * (C) Copyright 2005, by Object Refinery Limited and Contributors.
031:         *
032:         * Original Author:  David Gilbert;
033:         * Contributor(s):   Andrzej Porebski;
034:         *                   Arnaud Lelievre;
035:         *
036:         * $Id: DefaultAxisEditor.java,v 1.1.2.1 2005/11/24 16:11:48 mungady Exp $
037:         *
038:         * Changes
039:         * -------
040:         * 24-Nov-2005 : Version 1, based on AxisPropertyEditPanel.java (DG); 
041:         *
042:         */
043:
044:        package org.jfree.chart.editor;
045:
046:        import java.awt.BorderLayout;
047:        import java.awt.Color;
048:        import java.awt.Font;
049:        import java.awt.Paint;
050:        import java.awt.event.ActionEvent;
051:        import java.awt.event.ActionListener;
052:        import java.util.ResourceBundle;
053:
054:        import javax.swing.BorderFactory;
055:        import javax.swing.JButton;
056:        import javax.swing.JCheckBox;
057:        import javax.swing.JColorChooser;
058:        import javax.swing.JLabel;
059:        import javax.swing.JOptionPane;
060:        import javax.swing.JPanel;
061:        import javax.swing.JTabbedPane;
062:        import javax.swing.JTextField;
063:
064:        import org.jfree.chart.axis.Axis;
065:        import org.jfree.chart.axis.NumberAxis;
066:        import org.jfree.layout.LCBLayout;
067:        import org.jfree.ui.FontChooserPanel;
068:        import org.jfree.ui.FontDisplayField;
069:        import org.jfree.ui.PaintSample;
070:        import org.jfree.ui.RectangleInsets;
071:
072:        /**
073:         * A panel for editing the properties of an axis.
074:         */
075:        class DefaultAxisEditor extends JPanel implements  ActionListener {
076:
077:            /** The axis label. */
078:            private JTextField label;
079:
080:            /** The label font. */
081:            private Font labelFont;
082:
083:            /** The label paint. */
084:            private PaintSample labelPaintSample;
085:
086:            /** A field showing a description of the label font. */
087:            private JTextField labelFontField;
088:
089:            /** The font for displaying tick labels on the axis. */
090:            private Font tickLabelFont;
091:
092:            /** 
093:             * A field containing a description of the font for displaying tick labels 
094:             * on the axis. 
095:             */
096:            private JTextField tickLabelFontField;
097:
098:            /** The paint (color) for the tick labels. */
099:            private PaintSample tickLabelPaintSample;
100:
101:            /**
102:             * An empty sub-panel for extending the user interface to handle more 
103:             * complex axes. 
104:             */
105:            private JPanel slot1;
106:
107:            /** 
108:             * An empty sub-panel for extending the user interface to handle more 
109:             * complex axes. 
110:             */
111:            private JPanel slot2;
112:
113:            /** A flag that indicates whether or not the tick labels are visible. */
114:            private JCheckBox showTickLabelsCheckBox;
115:
116:            /** A flag that indicates whether or not the tick marks are visible. */
117:            private JCheckBox showTickMarksCheckBox;
118:
119:            //    /** Insets text field. */
120:            //    private InsetsTextField tickLabelInsetsTextField;
121:            //
122:            //    /** Label insets text field. */
123:            //    private InsetsTextField labelInsetsTextField;
124:
125:            /** The tick label insets. */
126:            private RectangleInsets tickLabelInsets;
127:
128:            /** The label insets. */
129:            private RectangleInsets labelInsets;
130:
131:            /** A tabbed pane for... */
132:            private JTabbedPane otherTabs;
133:
134:            /** The resourceBundle for the localization. */
135:            protected static ResourceBundle localizationResources = ResourceBundle
136:                    .getBundle("org.jfree.chart.editor.LocalizationBundle");
137:
138:            /**
139:             * A static method that returns a panel that is appropriate for the axis
140:             * type.
141:             *
142:             * @param axis  the axis whose properties are to be displayed/edited in 
143:             *              the panel.
144:             *
145:             * @return A panel or <code>null</code< if axis is <code>null</code>.
146:             */
147:            public static DefaultAxisEditor getInstance(Axis axis) {
148:
149:                if (axis != null) {
150:                    // figure out what type of axis we have and instantiate the
151:                    // appropriate panel
152:                    if (axis instanceof  NumberAxis) {
153:                        return new DefaultNumberAxisEditor((NumberAxis) axis);
154:                    } else {
155:                        return new DefaultAxisEditor(axis);
156:                    }
157:                } else {
158:                    return null;
159:                }
160:
161:            }
162:
163:            /**
164:             * Standard constructor: builds a panel for displaying/editing the
165:             * properties of the specified axis.
166:             *
167:             * @param axis  the axis whose properties are to be displayed/edited in 
168:             *              the panel.
169:             */
170:            public DefaultAxisEditor(Axis axis) {
171:
172:                this .labelFont = axis.getLabelFont();
173:                this .labelPaintSample = new PaintSample(axis.getLabelPaint());
174:                this .tickLabelFont = axis.getTickLabelFont();
175:                this .tickLabelPaintSample = new PaintSample(axis
176:                        .getTickLabelPaint());
177:
178:                // Insets values
179:                this .tickLabelInsets = axis.getTickLabelInsets();
180:                this .labelInsets = axis.getLabelInsets();
181:
182:                setLayout(new BorderLayout());
183:
184:                JPanel general = new JPanel(new BorderLayout());
185:                general.setBorder(BorderFactory.createTitledBorder(
186:                        BorderFactory.createEtchedBorder(),
187:                        localizationResources.getString("General")));
188:
189:                JPanel interior = new JPanel(new LCBLayout(5));
190:                interior.setBorder(BorderFactory.createEmptyBorder(0, 5, 0, 5));
191:                interior.add(new JLabel(localizationResources
192:                        .getString("Label")));
193:                this .label = new JTextField(axis.getLabel());
194:                interior.add(this .label);
195:                interior.add(new JPanel());
196:
197:                interior
198:                        .add(new JLabel(localizationResources.getString("Font")));
199:                this .labelFontField = new FontDisplayField(this .labelFont);
200:                interior.add(this .labelFontField);
201:                JButton b = new JButton(localizationResources
202:                        .getString("Select..."));
203:                b.setActionCommand("SelectLabelFont");
204:                b.addActionListener(this );
205:                interior.add(b);
206:
207:                interior.add(new JLabel(localizationResources
208:                        .getString("Paint")));
209:                interior.add(this .labelPaintSample);
210:                b = new JButton(localizationResources.getString("Select..."));
211:                b.setActionCommand("SelectLabelPaint");
212:                b.addActionListener(this );
213:                interior.add(b);
214:
215:                //        interior.add(
216:                //            new JLabel(localizationResources.getString("Label_Insets"))
217:                //        );
218:                //        b = new JButton(localizationResources.getString("Edit..."));
219:                //        b.setActionCommand("LabelInsets");
220:                //        b.addActionListener(this);
221:                //        this.labelInsetsTextField = new InsetsTextField(this.labelInsets);
222:                //        interior.add(this.labelInsetsTextField);
223:                //        interior.add(b);
224:                //
225:                //        interior.add(
226:                //            new JLabel(localizationResources.getString("Tick_Label_Insets"))
227:                //        );
228:                //        b = new JButton(localizationResources.getString("Edit..."));
229:                //        b.setActionCommand("TickLabelInsets");
230:                //        b.addActionListener(this);
231:                //        this.tickLabelInsetsTextField 
232:                //            = new InsetsTextField(this.tickLabelInsets);
233:                //        interior.add(this.tickLabelInsetsTextField);
234:                //        interior.add(b);
235:
236:                general.add(interior);
237:
238:                add(general, BorderLayout.NORTH);
239:
240:                this .slot1 = new JPanel(new BorderLayout());
241:
242:                JPanel other = new JPanel(new BorderLayout());
243:                other.setBorder(BorderFactory.createTitledBorder(BorderFactory
244:                        .createEtchedBorder(), localizationResources
245:                        .getString("Other")));
246:
247:                this .otherTabs = new JTabbedPane();
248:                this .otherTabs.setBorder(BorderFactory.createEmptyBorder(0, 5,
249:                        0, 5));
250:
251:                JPanel ticks = new JPanel(new LCBLayout(3));
252:                ticks.setBorder(BorderFactory.createEmptyBorder(4, 4, 4, 4));
253:
254:                this .showTickLabelsCheckBox = new JCheckBox(
255:                        localizationResources.getString("Show_tick_labels"),
256:                        axis.isTickLabelsVisible());
257:                ticks.add(this .showTickLabelsCheckBox);
258:                ticks.add(new JPanel());
259:                ticks.add(new JPanel());
260:
261:                ticks.add(new JLabel(localizationResources
262:                        .getString("Tick_label_font")));
263:                this .tickLabelFontField = new FontDisplayField(
264:                        this .tickLabelFont);
265:                ticks.add(this .tickLabelFontField);
266:                b = new JButton(localizationResources.getString("Select..."));
267:                b.setActionCommand("SelectTickLabelFont");
268:                b.addActionListener(this );
269:                ticks.add(b);
270:
271:                this .showTickMarksCheckBox = new JCheckBox(
272:                        localizationResources.getString("Show_tick_marks"),
273:                        axis.isTickMarksVisible());
274:                ticks.add(this .showTickMarksCheckBox);
275:                ticks.add(new JPanel());
276:                ticks.add(new JPanel());
277:
278:                this .otherTabs.add(localizationResources.getString("Ticks"),
279:                        ticks);
280:
281:                other.add(this .otherTabs);
282:
283:                this .slot1.add(other);
284:
285:                this .slot2 = new JPanel(new BorderLayout());
286:                this .slot2.add(this .slot1, BorderLayout.NORTH);
287:                add(this .slot2);
288:
289:            }
290:
291:            /**
292:             * Returns the current axis label.
293:             *
294:             * @return The current axis label.
295:             */
296:            public String getLabel() {
297:                return this .label.getText();
298:            }
299:
300:            /**
301:             * Returns the current label font.
302:             *
303:             * @return The current label font.
304:             */
305:            public Font getLabelFont() {
306:                return this .labelFont;
307:            }
308:
309:            /**
310:             * Returns the current label paint.
311:             *
312:             * @return The current label paint.
313:             */
314:            public Paint getLabelPaint() {
315:                return this .labelPaintSample.getPaint();
316:            }
317:
318:            /**
319:             * Returns a flag that indicates whether or not the tick labels are visible.
320:             *
321:             * @return <code>true</code> if ick mark labels are visible.
322:             */
323:            public boolean isTickLabelsVisible() {
324:                return this .showTickLabelsCheckBox.isSelected();
325:            }
326:
327:            /**
328:             * Returns the font used to draw the tick labels (if they are showing).
329:             *
330:             * @return The font used to draw the tick labels.
331:             */
332:            public Font getTickLabelFont() {
333:                return this .tickLabelFont;
334:            }
335:
336:            /**
337:             * Returns the current tick label paint.
338:             *
339:             * @return The current tick label paint.
340:             */
341:            public Paint getTickLabelPaint() {
342:                return this .tickLabelPaintSample.getPaint();
343:            }
344:
345:            /**
346:             * Returns the current value of the flag that determines whether or not
347:             * tick marks are visible.
348:             *
349:             * @return <code>true</code> if tick marks are visible.
350:             */
351:            public boolean isTickMarksVisible() {
352:                return this .showTickMarksCheckBox.isSelected();
353:            }
354:
355:            /**
356:             * Returns the current tick label insets value
357:             *
358:             * @return The current tick label insets value.
359:             */
360:            public RectangleInsets getTickLabelInsets() {
361:                return (this .tickLabelInsets == null) ? new RectangleInsets(0,
362:                        0, 0, 0) : this .tickLabelInsets;
363:            }
364:
365:            /**
366:             * Returns the current label insets value
367:             *
368:             * @return The current label insets value.
369:             */
370:            public RectangleInsets getLabelInsets() {
371:                return (this .labelInsets == null) ? new RectangleInsets(0, 0,
372:                        0, 0) : this .labelInsets;
373:            }
374:
375:            /**
376:             * Returns a reference to the tabbed pane.
377:             *
378:             * @return A reference to the tabbed pane.
379:             */
380:            public JTabbedPane getOtherTabs() {
381:                return this .otherTabs;
382:            }
383:
384:            /**
385:             * Handles user interaction with the property panel.
386:             * 
387:             * @param event  information about the event that triggered the call to
388:             *      this method.
389:             */
390:            public void actionPerformed(ActionEvent event) {
391:                String command = event.getActionCommand();
392:                if (command.equals("SelectLabelFont")) {
393:                    attemptLabelFontSelection();
394:                } else if (command.equals("SelectLabelPaint")) {
395:                    attemptModifyLabelPaint();
396:                } else if (command.equals("SelectTickLabelFont")) {
397:                    attemptTickLabelFontSelection();
398:                }
399:                //        else if (command.equals("LabelInsets")) {
400:                //            editLabelInsets();
401:                //        }
402:                //        else if (command.equals("TickLabelInsets")) {
403:                //            editTickLabelInsets();
404:                //        }
405:            }
406:
407:            /**
408:             * Presents a font selection dialog to the user.
409:             */
410:            private void attemptLabelFontSelection() {
411:
412:                FontChooserPanel panel = new FontChooserPanel(this .labelFont);
413:                int result = JOptionPane
414:                        .showConfirmDialog(this , panel, localizationResources
415:                                .getString("Font_Selection"),
416:                                JOptionPane.OK_CANCEL_OPTION,
417:                                JOptionPane.PLAIN_MESSAGE);
418:
419:                if (result == JOptionPane.OK_OPTION) {
420:                    this .labelFont = panel.getSelectedFont();
421:                    this .labelFontField.setText(this .labelFont.getFontName()
422:                            + " " + this .labelFont.getSize());
423:                }
424:
425:            }
426:
427:            /**
428:             * Allows the user the opportunity to change the outline paint.
429:             */
430:            private void attemptModifyLabelPaint() {
431:                Color c;
432:                c = JColorChooser.showDialog(this , localizationResources
433:                        .getString("Label_Color"), Color.blue);
434:                if (c != null) {
435:                    this .labelPaintSample.setPaint(c);
436:                }
437:            }
438:
439:            /**
440:             * Presents a tick label font selection dialog to the user.
441:             */
442:            public void attemptTickLabelFontSelection() {
443:
444:                FontChooserPanel panel = new FontChooserPanel(
445:                        this .tickLabelFont);
446:                int result = JOptionPane
447:                        .showConfirmDialog(this , panel, localizationResources
448:                                .getString("Font_Selection"),
449:                                JOptionPane.OK_CANCEL_OPTION,
450:                                JOptionPane.PLAIN_MESSAGE);
451:
452:                if (result == JOptionPane.OK_OPTION) {
453:                    this .tickLabelFont = panel.getSelectedFont();
454:                    this .tickLabelFontField.setText(this .tickLabelFont
455:                            .getFontName()
456:                            + " " + this .tickLabelFont.getSize());
457:                }
458:
459:            }
460:
461:            //    /**
462:            //     * Presents insets chooser panel allowing user to modify tick label's
463:            //     * individual insets values. Updates the current insets text field if edit
464:            //     * is accepted.
465:            //     */
466:            //    private void editTickLabelInsets() {
467:            //        InsetsChooserPanel panel = new InsetsChooserPanel(this.tickLabelInsets);
468:            //        int result =  JOptionPane.showConfirmDialog(
469:            //            this, panel, localizationResources.getString("Edit_Insets"),
470:            //            JOptionPane.PLAIN_MESSAGE
471:            //        );
472:            //
473:            //        if (result == JOptionPane.OK_OPTION) {
474:            //            this.tickLabelInsets = panel.getInsets();
475:            //            this.tickLabelInsetsTextField.setInsets(this.tickLabelInsets);
476:            //        }
477:            //    }
478:            //
479:            //    /**
480:            //     * Presents insets chooser panel allowing user to modify label's
481:            //     * individual insets values. Updates the current insets text field if edit
482:            //     * is accepted.
483:            //     */
484:            //    private void editLabelInsets() {
485:            //        InsetsChooserPanel panel = new InsetsChooserPanel(this.labelInsets);
486:            //        int result = JOptionPane.showConfirmDialog(
487:            //            this, panel, localizationResources.getString("Edit_Insets"),
488:            //            JOptionPane.PLAIN_MESSAGE
489:            //        );
490:            //
491:            //        if (result == JOptionPane.OK_OPTION) {
492:            //            this.labelInsets = panel.getInsets();
493:            //            this.labelInsetsTextField.setInsets(this.labelInsets);
494:            //        }
495:            //    }
496:
497:            /**
498:             * Sets the properties of the specified axis to match the properties
499:             * defined on this panel.
500:             *
501:             * @param axis  the axis.
502:             */
503:            public void setAxisProperties(Axis axis) {
504:                axis.setLabel(getLabel());
505:                axis.setLabelFont(getLabelFont());
506:                axis.setLabelPaint(getLabelPaint());
507:                axis.setTickMarksVisible(isTickMarksVisible());
508:                // axis.setTickMarkStroke(getTickMarkStroke());
509:                axis.setTickLabelsVisible(isTickLabelsVisible());
510:                axis.setTickLabelFont(getTickLabelFont());
511:                axis.setTickLabelPaint(getTickLabelPaint());
512:                axis.setTickLabelInsets(getTickLabelInsets());
513:                axis.setLabelInsets(getLabelInsets());
514:            }
515:
516:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.