Source Code Cross Referenced for DialWidgetDefinition.java in  » Report » pentaho-report » org » pentaho » plugin » jfreechart » 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 » Report » pentaho report » org.pentaho.plugin.jfreechart 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * Copyright 2006 Pentaho Corporation.  All rights reserved.
003:         * This software was developed by Pentaho Corporation and is provided under the terms
004:         * of the Mozilla Public License, Version 1.1, or any later version. You may not use
005:         * this file except in compliance with the license. If you need a copy of the license,
006:         * please go to http://www.mozilla.org/MPL/MPL-1.1.txt. The Original Code is the Pentaho
007:         * BI Platform.  The Initial Developer is Pentaho Corporation.
008:         *
009:         * Software distributed under the Mozilla Public License is distributed on an "AS IS"
010:         * basis, WITHOUT WARRANTY OF ANY KIND, either express or  implied. Please refer to
011:         * the license for the specific language governing your rights and limitations.
012:         *
013:         * @created Aug 15, 2005
014:         * @author James Dixon
015:         *
016:         */
017:
018:        package org.pentaho.plugin.jfreechart;
019:
020:        import java.awt.BasicStroke;
021:        import java.awt.Color;
022:        import java.awt.Font;
023:        import java.awt.Image;
024:        import java.awt.Paint;
025:        import java.awt.Stroke;
026:        import java.util.ArrayList;
027:        import java.util.Iterator;
028:        import java.util.List;
029:
030:        import org.apache.commons.logging.Log;
031:        import org.apache.commons.logging.LogFactory;
032:        import org.dom4j.Document;
033:        import org.dom4j.Element;
034:        import org.dom4j.Node;
035:        import org.jfree.chart.plot.DialShape;
036:        import org.jfree.chart.plot.MeterInterval;
037:        import org.jfree.data.Range;
038:        import org.jfree.ui.RectangleEdge;
039:        import org.pentaho.commons.connection.IPentahoResultSet;
040:        import org.pentaho.commons.connection.PentahoDataTransmuter;
041:        import org.pentaho.core.session.IPentahoSession;
042:        import org.pentaho.messages.Messages;
043:
044:        /**
045:         * This class represents the definition of a dashboard dial. It holds:
046:         * <ul>
047:         * <li>The value to be displayed on the dial</li>
048:         * <li>Minimum value of the dial</li>
049:         * <li>Maximum value of the dial</li>
050:         * <li>A list of intervals with the dial. Each interval specifies a minimum,
051:         * maximum and information about how the interval should be painted.</li>
052:         * <li>Painting information
053:         * <ul>
054:         * <li>Background paint</li>
055:         * <li>Dial paint</li>
056:         * <li>Needle paint</li>
057:         * </ul>
058:         * </ul>
059:         *
060:         * <p/> This class does not generate an image of the dial, it just defines the
061:         * properties of the dial. <p/> Dial definitions are stored in xml documents in
062:         * the solution folders with *.dial.xml extensions. These definition files store
063:         * XML representations of all the settings here. Typically the value to be
064:         * displayed is provided at runtime by a query or business rule, but the value
065:         * can also read from the definition file. <p/> The definitions are read by
066:         * org.pentaho.core.ui.component.DashboardWidgetComponent objects, which create
067:         * instances of this object and set the properties defined here. <p/> The
068:         * DashboardWidgetComponent objects pass this, now populated, object to
069:         *
070:         * The dial image is generated by
071:         * {@link org.pentaho.core.ui.component.JFreeChartEngine} <p/>
072:         *
073:         * Example Dial <br/> <img src="doc-files/DialWidgetDefinition-1.png">
074:         */
075:        public class DialWidgetDefinition extends WidgetDefinition implements 
076:                ChartDefinition {
077:
078:            private static final long serialVersionUID = 2232742163326878608L;
079:
080:            private ArrayList intervals = new ArrayList();
081:
082:            private RectangleEdge titlePosition = RectangleEdge.TOP;
083:
084:            private Paint chartBackgroundPaint = Color.WHITE;
085:
086:            private Paint plotBackgroundPaint = Color.GRAY;
087:
088:            private Paint needlePaint = Color.blue;
089:
090:            private DialShape dialShape = DialShape.CHORD;
091:
092:            private Font titleFont;
093:
094:            private List subTitles = new ArrayList();
095:
096:            private boolean rangeLimited;
097:
098:            private int tickSize = 5;
099:
100:            private Paint tickPaint = Color.blue;
101:
102:            private Paint valuePaint = Color.BLUE;
103:
104:            private Font valueFont;
105:
106:            private String units;
107:
108:            private Font legendFont = null;
109:
110:            private boolean legendBorderVisible = true;
111:
112:            private Node attributes = null;
113:
114:            //    private IPentahoSession session;
115:
116:            public DialWidgetDefinition(double value, double minimum,
117:                    double maximum, boolean rangeLimited) {
118:                super (value, minimum, maximum);
119:                this .rangeLimited = rangeLimited;
120:            }
121:
122:            /**
123:             * TODO PROBLEM HERE! If you use this constructor, the XML schema for the chart attributes is different than if you use the constructor with the arguments 
124:             * public DialWidgetDefinition( Document document, double value, int width, int height, IPentahoSession session). This constructor expects the 
125:             * chart attribute nodes to be children of the <chart-attributes> node, whereas the latter constructor expects the attributes to be children of a <dial> node. 
126:             * This does not help us with our parity situation, and should be deprecated and reconciled. 
127:             *  
128:             * @param data
129:             * @param byRow
130:             * @param chartAttributes
131:             * @param width
132:             * @param height
133:             * @param session
134:             */
135:            public DialWidgetDefinition(IPentahoResultSet data, boolean byRow,
136:                    Node chartAttributes, int width, int height,
137:                    IPentahoSession session) {
138:                this (0.0, Double.MIN_VALUE, Double.MAX_VALUE, false);
139:
140:                attributes = chartAttributes;
141:
142:                if (data != null) {
143:                    if (byRow) {
144:                        setDataByRow(data);
145:                    } else {
146:                        setDataByColumn(data);
147:                    }
148:                }
149:
150:                //set legend font
151:                setLegendFont(chartAttributes
152:                        .selectSingleNode(LEGEND_FONT_NODE_NAME));
153:
154:                // set legend border visible
155:                setLegendBorderVisible(chartAttributes
156:                        .selectSingleNode(DISPLAY_LEGEND_BORDER_NODE_NAME));
157:
158:                createDial(this , chartAttributes, width, height, session);
159:            }
160:
161:            /**
162:             * TODO: PROBLEM HERE! See the note on the constructor above. 
163:             * 
164:             * @param document
165:             * @param value
166:             * @param width
167:             * @param height
168:             * @param session
169:             */
170:            public DialWidgetDefinition(Document document, double value,
171:                    int width, int height, IPentahoSession session) {
172:                this (value, Double.MIN_VALUE, Double.MAX_VALUE, false);
173:
174:                // get the dial node from the document
175:                attributes = document.selectSingleNode("//dial"); //$NON-NLS-1$
176:
177:                deriveMinMax(value);
178:
179:                // create the dial definition object
180:                createDial(this , attributes, width, height, session);
181:            }
182:
183:            public static Log getLogger() {
184:                return LogFactory.getLog(DialWidgetDefinition.class);
185:            }
186:
187:            /*
188:             * public ThermometerWidgetDefinition createThermometer( Document doc ) { //
189:             * TODO implement this to return a ThermometerWidgetDefinition object return
190:             * null; }
191:             */
192:            /**
193:             * Create a dial definition object from an XML document
194:             *
195:             * @param doc
196:             *            definition XML document
197:             * @return Dial definition object
198:             */
199:            public static void createDial(
200:                    DialWidgetDefinition widgetDefinition, Node dialNode,
201:                    int width, int height, IPentahoSession session) {
202:
203:                Node node = dialNode.selectSingleNode("units"); //$NON-NLS-1$
204:                if (node != null) {
205:                    String units = node.getText();
206:                    widgetDefinition.setUnits(units);
207:                }
208:
209:                // set the background Paint
210:                Paint paint = JFreeChartEngine.getPaint(dialNode
211:                        .selectSingleNode("background-color")); //$NON-NLS-1$
212:                if (paint == null) {
213:                    Element backgroundNode = (Element) dialNode
214:                            .selectSingleNode("chart-background"); //$NON-NLS-1$
215:                    if (backgroundNode != null) {
216:                        String backgroundType = backgroundNode
217:                                .attributeValue("type"); //$NON-NLS-1$
218:                        if ("texture".equals(backgroundType)) { //$NON-NLS-1$
219:                            paint = JFreeChartEngine.getTexturePaint(
220:                                    backgroundNode, width, height, session);
221:                        } else if ("gradient".equals(backgroundType)) { //$NON-NLS-1$
222:                            paint = JFreeChartEngine.getGradientPaint(
223:                                    backgroundNode, width, height);
224:                        }
225:                    }
226:                } else {
227:                    // log a deprecation warning for background-color ...
228:                    getLogger()
229:                            .warn(
230:                                    Messages
231:                                            .getString(
232:                                                    "CHART.WARN_DEPRECATED_PROPERTY", "background-color", "chart-background"));//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$    
233:                    getLogger()
234:                            .warn(
235:                                    Messages
236:                                            .getString(
237:                                                    "CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", "background-color"));//$NON-NLS-1$ //$NON-NLS-2$     
238:                }
239:
240:                if (paint != null) {
241:                    widgetDefinition.setChartBackgroundPaint(paint);
242:                }
243:
244:                // set the dial background Paint
245:                paint = JFreeChartEngine.getPaint(dialNode
246:                        .selectSingleNode("plot-background-color")); //$NON-NLS-1$
247:                if (paint == null) {
248:                    Element backgroundNode = (Element) dialNode
249:                            .selectSingleNode("plot-background"); //$NON-NLS-1$
250:                    if (backgroundNode != null) {
251:                        String backgroundType = backgroundNode
252:                                .attributeValue("type"); //$NON-NLS-1$
253:                        if ("texture".equals(backgroundType)) { //$NON-NLS-1$
254:                            paint = JFreeChartEngine.getTexturePaint(
255:                                    backgroundNode, width, height, session);
256:                        } else if ("gradient".equals(backgroundType)) { //$NON-NLS-1$
257:                            paint = JFreeChartEngine.getGradientPaint(
258:                                    backgroundNode, width, height);
259:                        }
260:                    }
261:                } else {
262:                    // log a deprecation warning for plot-background-color ...
263:                    getLogger()
264:                            .warn(
265:                                    Messages
266:                                            .getString(
267:                                                    "CHART.WARN_DEPRECATED_PROPERTY", "plot-background-color", "plot-background"));//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$    
268:                    getLogger()
269:                            .warn(
270:                                    Messages
271:                                            .getString(
272:                                                    "CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", "plot-background-color"));//$NON-NLS-1$ //$NON-NLS-2$     
273:                }
274:
275:                if (paint != null) {
276:                    widgetDefinition.setPlotBackgroundPaint(paint);
277:                }
278:
279:                // set the needle Paint
280:                paint = JFreeChartEngine.getPaint(dialNode
281:                        .selectSingleNode("needle-color")); //$NON-NLS-1$
282:                if (paint != null) {
283:                    widgetDefinition.setNeedlePaint(paint);
284:                }
285:
286:                // set the tick Paint
287:                paint = JFreeChartEngine.getPaint(dialNode
288:                        .selectSingleNode("tick-color")); //$NON-NLS-1$
289:                if (paint != null) {
290:                    widgetDefinition.setTickPaint(paint);
291:                }
292:
293:                Node tmpNode = dialNode.selectSingleNode("tick-interval"); //$NON-NLS-1$
294:                if (tmpNode != null) {
295:                    widgetDefinition.setTickSize(Integer.parseInt(dialNode
296:                            .selectSingleNode("tick-interval").getText())); //$NON-NLS-1$
297:                }
298:
299:                // set the value Paint
300:                paint = JFreeChartEngine.getPaint(dialNode
301:                        .selectSingleNode("value-color")); //$NON-NLS-1$
302:                if (paint != null) {
303:                    widgetDefinition.setValuePaint(paint);
304:                }
305:
306:                // TODO get this from the XML document
307:                widgetDefinition.setDialShape(DialShape.CHORD);
308:
309:                Node titleFontNode = dialNode.selectSingleNode("title-font"); //$NON-NLS-1$
310:                if (titleFontNode != null) {
311:                    String titleFontStr = titleFontNode.getText().trim();
312:                    if (!"".equals(titleFontStr)) { //$NON-NLS-1$
313:                        widgetDefinition.setTitleFont(new Font(titleFontStr,
314:                                Font.ITALIC, 24));
315:                    }
316:                }
317:
318:                Node valueFontNode = dialNode.selectSingleNode("title-font"); //$NON-NLS-1$
319:                if (valueFontNode != null) {
320:                    String fontStr = valueFontNode.getText().trim();
321:                    if (!"".equals(fontStr)) { //$NON-NLS-1$
322:                        widgetDefinition.setValueFont(new Font(fontStr,
323:                                Font.ITALIC, 24));
324:                    }
325:                }
326:
327:                // set any intervals that are defined in the document
328:
329:                // A list of interval nodes should not be allowed to exist as a child of the main XML element (for XML schema to 
330:                // be well constructed and validate the XML . 
331:                // We have deprecated <interval> as a child of the main node , and now require an <intervals> parent node 
332:                // under which <intervals> can exist. 
333:
334:                List intervals = dialNode.selectNodes("interval"); //$NON-NLS-1$
335:
336:                if ((intervals == null) || (intervals.isEmpty())) {
337:                    Node intervalsNode = dialNode.selectSingleNode("intervals"); //$NON-NLS-1$
338:                    if (intervalsNode != null) {
339:                        intervals = intervalsNode.selectNodes("interval"); //$NON-NLS-1$
340:                    }
341:                } else {
342:                    // log a deprecation warning for this property...
343:                    getLogger()
344:                            .warn(
345:                                    Messages
346:                                            .getString(
347:                                                    "CHART.WARN_DEPRECATED_CHILD", "interval", "intervals"));//$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$    
348:                    getLogger()
349:                            .warn(
350:                                    Messages
351:                                            .getString(
352:                                                    "CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", "interval"));//$NON-NLS-1$ //$NON-NLS-2$     
353:                }
354:
355:                if (intervals != null) {
356:
357:                    Iterator intervalIterator = intervals.iterator();
358:                    while (intervalIterator.hasNext()) {
359:                        // get the interval node
360:                        Node intervalNode = (Node) intervalIterator.next();
361:
362:                        // get the interval name
363:                        String label = intervalNode
364:                                .selectSingleNode("label").getText(); //$NON-NLS-1$
365:
366:                        // get the range of the interval
367:                        double minimum = Double.parseDouble(intervalNode
368:                                .selectSingleNode("minimum").getText()); //$NON-NLS-1$
369:                        double maximum = Double.parseDouble(intervalNode
370:                                .selectSingleNode("maximum").getText()); //$NON-NLS-1$
371:                        Range range = new Range(minimum, maximum);
372:
373:                        Paint backgroundPaint = JFreeChartEngine
374:                                .getPaint(intervalNode
375:                                        .selectSingleNode("color")); //$NON-NLS-1$
376:                        if (backgroundPaint == null) {
377:                            Element backgroundNode = (Element) intervalNode
378:                                    .selectSingleNode("interval-background"); //$NON-NLS-1$
379:                            if (backgroundNode != null) {
380:                                String backgroundType = backgroundNode
381:                                        .attributeValue("type"); //$NON-NLS-1$
382:                                if ("texture".equals(backgroundType)) { //$NON-NLS-1$
383:                                    backgroundPaint = JFreeChartEngine
384:                                            .getTexturePaint(backgroundNode,
385:                                                    width, height, session);
386:                                } else if ("gradient".equals(backgroundType)) { //$NON-NLS-1$
387:                                    backgroundPaint = JFreeChartEngine
388:                                            .getGradientPaint(backgroundNode,
389:                                                    width, height);
390:                                }
391:                            }
392:                        }
393:
394:                        // get the text color of the interval
395:                        String textColor = intervalNode.selectSingleNode(
396:                                "text-color").getText(); //$NON-NLS-1$
397:                        Stroke outlineStroke;
398:                        if (intervalNode.selectSingleNode("stroke-width") != null) { //$NON-NLS-1$
399:                            outlineStroke = new BasicStroke(Float
400:                                    .parseFloat(intervalNode.selectSingleNode(
401:                                            "stroke-width").getText())); //$NON-NLS-1$
402:                        } else {
403:                            outlineStroke = new BasicStroke();
404:                        }
405:                        Paint outlinePaint = JFreeChartEngine
406:                                .getPaint(textColor);
407:
408:                        // create the interval object
409:                        MeterInterval interval = new MeterInterval(label,
410:                                range, outlinePaint, outlineStroke,
411:                                backgroundPaint);
412:
413:                        // add the interval to the widget
414:                        widgetDefinition.addInterval(interval);
415:                    }
416:                }
417:
418:                // get the chart subtitles
419:
420:                // A list of <subtitle> nodes should not be allowed to exist as a child of the main XML element (for XML schema to 
421:                // be well constructed and validate the XML . 
422:                // We have deprecated <subtitle> as a child of the main node , and now require a <subtitles> parent node 
423:                // under which <subtitle> can exist. 
424:
425:                List subtitles = dialNode.selectNodes(SUBTITLE_NODE_NAME);
426:
427:                if ((subtitles == null) || (subtitles.isEmpty())) {
428:                    Node subTitlesNode = dialNode
429:                            .selectSingleNode(SUBTITLES_NODE_NAME);
430:                    if (subTitlesNode != null) {
431:                        subtitles = subTitlesNode
432:                                .selectNodes(SUBTITLE_NODE_NAME);
433:                    }
434:                } else {
435:                    // log a deprecation warning for this property...
436:                    getLogger()
437:                            .warn(
438:                                    Messages
439:                                            .getString(
440:                                                    "CHART.WARN_DEPRECATED_CHILD", SUBTITLE_NODE_NAME, SUBTITLES_NODE_NAME));//$NON-NLS-1$ 
441:                    getLogger()
442:                            .warn(
443:                                    Messages
444:                                            .getString(
445:                                                    "CHART.WARN_PROPERTY_WILL_NOT_VALIDATE", SUBTITLE_NODE_NAME));//$NON-NLS-1$  
446:                }
447:
448:                if (subtitles != null) {
449:                    widgetDefinition.addSubTitles(subtitles);
450:                }
451:
452:            }
453:
454:            public void setUnits(String units) {
455:                this .units = units;
456:            }
457:
458:            public String getUnits() {
459:                return units;
460:            }
461:
462:            private void setDataByColumn(IPentahoResultSet data) {
463:                setDataByRow(PentahoDataTransmuter.pivot(data));
464:            }
465:
466:            private void setDataByRow(IPentahoResultSet data) {
467:
468:                if (data == null) {
469:                    noDataMessage = Messages
470:                            .getString("CHART.USER_NO_DATA_AVAILABLE"); //$NON-NLS-1$
471:                    return;
472:                }
473:
474:                Object[] rowData = data.next();
475:
476:                double newValue = ((Number) rowData[0]).doubleValue();
477:
478:                // Do we have a value, minimum and maximum? 
479:                if (rowData.length >= 3) {
480:
481:                    double newMinimum = ((Number) rowData[1]).doubleValue();
482:                    double newMaximum = ((Number) rowData[2]).doubleValue();
483:                    this .setMinimum(newMinimum);
484:                    this .setMaximum(newMaximum);
485:
486:                } else {
487:
488:                    deriveMinMax(newValue);
489:
490:                }
491:
492:                this .setValue(newValue);
493:
494:            }
495:
496:            public void deriveMinMax(double value) {
497:
498:                double min = 0;
499:                double max = 100;
500:                Node node = attributes.selectSingleNode("range-limited"); //$NON-NLS-1$
501:                rangeLimited = (node == null)
502:                        || ("true".equalsIgnoreCase(node.getText())); //$NON-NLS-1$
503:
504:                if (!rangeLimited) {
505:                } else {
506:                    max = 0.1;
507:                    double absValue = Math.abs(value);
508:                    // based on the current value, to to select some sensible min and
509:                    // max values
510:                    while (max < absValue) {
511:                        max *= 2;
512:                        if (max < absValue) {
513:                            min *= 2.5;
514:                            max *= 2.5;
515:                        }
516:                        if (max < absValue) {
517:                            min *= 2;
518:                            max *= 2;
519:                        }
520:                    }
521:                    if (value > 0) {
522:                        min = 0;
523:                    } else {
524:                        min = -max;
525:                    }
526:                    setMaximum(max);
527:                    setMinimum(min);
528:                }
529:            }
530:
531:            /**
532:             * Add an interval (MeterInterval) to the dial definition. The interval
533:             * defines a range and how it should be painted. <p/> The dial images here
534:             * have three intervals. The lowest interval has a minimum of 0 and a
535:             * maximum of 30. <p/> Intervals have a color. In this image the lowest
536:             * interval color is set to red. <br/> <img
537:             * src="doc-files/DialWidgetDefinition-5.png"> <p/> Intervals have a text
538:             * color. In this image the lowest interval text color is set to red. This
539:             * affects the outer rim, the interval value text <br/> <img
540:             * src="doc-files/DialWidgetDefinition-6.png">
541:             *
542:             * @param interval
543:             *            A MeterInterval that defines an interval (range) on the dial
544:             */
545:            public void addInterval(MeterInterval interval) {
546:                intervals.add(interval);
547:                Range range = interval.getRange();
548:                double min = range.getLowerBound();
549:                double max = range.getUpperBound();
550:                if (rangeLimited && intervals.size() == 1) {
551:                    setMinimum(min);
552:                    setMaximum(max);
553:                } else {
554:                    if (min < getMinimum()) {
555:                        setMinimum(min);
556:                    }
557:                    if (max > getMaximum()) {
558:                        setMaximum(max);
559:                    }
560:                }
561:            }
562:
563:            /**
564:             * Sets the value to be displayed on the dial image
565:             *
566:             * @param value
567:             *            The value to be displayed
568:             */
569:
570:            public void setValue(double value) {
571:                setValue(new Double(value));
572:                if (rangeLimited) {
573:                    if (value < getMinimum()) {
574:                        setValue(getMinimum());
575:                    } else if (value > getMaximum()) {
576:                        setValue(getMaximum());
577:                    }
578:                } else {
579:                    if (value < getMinimum()) {
580:                        setMinimum(value);
581:                    } else if (value > getMaximum()) {
582:                        setMaximum(value);
583:                    }
584:                }
585:            }
586:
587:            /**
588:             * Return the java.awt.Paint object to be used to paint the backound of the
589:             * dial.
590:             *
591:             * @return The Paint to be used
592:             */
593:            public Paint getPlotBackgroundPaint() {
594:                return plotBackgroundPaint;
595:            }
596:
597:            /**
598:             * Return the java.awt.Paint object to be used to paint the backound of the
599:             * dial. <p/> In this image the background paint has been set to red <br/>
600:             * <img src="doc-files/DialWidgetDefinition-2.png">
601:             *
602:             * @return The Paint to used for the background of the image
603:             */
604:            public void setPlotBackgroundPaint(Paint plotBackgroundPaint) {
605:                this .plotBackgroundPaint = plotBackgroundPaint;
606:            }
607:
608:            /**
609:             * Return the java.awt.Paint used to paint the needle of the dial image
610:             *
611:             * @return The Paint to use for the needle of this dial
612:             */
613:            public Paint getNeedlePaint() {
614:                return needlePaint;
615:            }
616:
617:            /**
618:             * Sets the java.awt.Paint object to be used to paint the needle of the dial
619:             * image. <p/> In this image the needle paint has been set to red. <br/>
620:             * <img src="doc-files/DialWidgetDefinition-4.png">
621:             *
622:             * @param needlePaint
623:             *            The Paint to use for ths needle of this dial
624:             */
625:            public void setNeedlePaint(Paint needlePaint) {
626:                this .needlePaint = needlePaint;
627:            }
628:
629:            /**
630:             * Return the shape to be used for the dial.
631:             *
632:             * @return DialShape The DialShape for this dial
633:             */
634:            public DialShape getDialShape() {
635:                return dialShape;
636:            }
637:
638:            /**
639:             * Return the java.awt.Font to be used to display the dial title
640:             *
641:             * @return Font The Font for the title of this dial
642:             */
643:            public Font getTitleFont() {
644:                if (titleFont != null) {
645:                    return titleFont;
646:                } else {
647:                    return new Font("sans-serif", Font.PLAIN, 14); //$NON-NLS-1$
648:                }
649:            }
650:
651:            public void setTitleFont(Font tFont) {
652:                titleFont = tFont;
653:
654:            }
655:
656:            /**
657:             * Sets the shape to be used for the dial. This affects the area of dial
658:             * outside the range that the needle covers. <table>
659:             * <tr>
660:             * <td><center>CIRCLE</center></td>
661:             * <td><center>CHORD</center></td>
662:             * <td><center>PIE</center></td>
663:             * </tr>
664:             * <tr>
665:             * <td><img src="doc-files/DialWidgetDefinition-3.png"></td>
666:             * <td><img src="doc-files/DialWidgetDefinition-8.png"></td>
667:             * <td><img src="doc-files/DialWidgetDefinition-9.png"></td>
668:             * </tr>
669:             * </table>
670:             *
671:             * @param dialShape
672:             *            The shape for this dial
673:             */
674:            public void setDialShape(DialShape dialShape) {
675:                this .dialShape = dialShape;
676:            }
677:
678:            /**
679:             * Return a list of the intervals for the dial. Each object in the list is a
680:             * MeterInterval object.
681:             *
682:             * @return List The list of MeterInterval objects for this dial
683:             */
684:
685:            public List getIntervals() {
686:                return intervals;
687:            }
688:
689:            public Paint[] getPaintSequence() {
690:                return null;
691:            }
692:
693:            public Image getPlotBackgroundImage() {
694:                return null;
695:            }
696:
697:            public List getSubtitles() {
698:                return subTitles;
699:            }
700:
701:            public void addSubTitles(List subTitleNodes) {
702:                if (subTitleNodes != null) {
703:                    Iterator iter = subTitleNodes.iterator();
704:                    while (iter.hasNext()) {
705:                        addSubTitle(((Node) iter.next()).getText());
706:                    }
707:                }
708:            }
709:
710:            public void addSubTitle(String subTitle) {
711:                subTitles.add(subTitle);
712:            }
713:
714:            public Paint getChartBackgroundPaint() {
715:                // TODO Auto-generated method stub
716:                return chartBackgroundPaint;
717:            }
718:
719:            public Image getChartBackgroundImage() {
720:                // TODO Auto-generated method stub
721:                return null;
722:            }
723:
724:            public boolean isBorderVisible() {
725:                // TODO Auto-generated method stub
726:                return false;
727:            }
728:
729:            public Paint getBorderPaint() {
730:                // TODO Auto-generated method stub
731:                return null;
732:            }
733:
734:            public RectangleEdge getTitlePosition() {
735:                return titlePosition;
736:            }
737:
738:            /**
739:             * @param chartBackgroundPaint
740:             *            The chartBackgroundPaint to set.
741:             */
742:            public void setChartBackgroundPaint(Paint chartBackgroundPaint) {
743:                this .chartBackgroundPaint = chartBackgroundPaint;
744:            }
745:
746:            public int getHeight() {
747:                // TODO Auto-generated method stub
748:                return 200;
749:            }
750:
751:            public int getWidth() {
752:                // TODO Auto-generated method stub
753:                return 200;
754:            }
755:
756:            public String getTitle() {
757:                return null;
758:            }
759:
760:            public boolean isLegendIncluded() {
761:                // TODO Auto-generated method stub
762:                return false;
763:            }
764:
765:            public boolean isThreeD() {
766:                // TODO Auto-generated method stub
767:                return false;
768:            }
769:
770:            public Paint getValuePaint() {
771:                return valuePaint;
772:            }
773:
774:            public Paint getTickPaint() {
775:                return tickPaint;
776:            }
777:
778:            public int getTickSize() {
779:                return tickSize;
780:            }
781:
782:            public void setValuePaint(Paint valuePaint) {
783:                this .valuePaint = valuePaint;
784:            }
785:
786:            public void setTickPaint(Paint tickPaint) {
787:                this .tickPaint = tickPaint;
788:            }
789:
790:            public void setTickSize(int tickSize) {
791:                this .tickSize = tickSize;
792:            }
793:
794:            public Font getValueFont() {
795:                return valueFont;
796:            }
797:
798:            public void setValueFont(Font valueFont) {
799:                this .valueFont = valueFont;
800:            }
801:
802:            public boolean isDisplayLabels() {
803:                // TODO Auto-generated method stub
804:                return false;
805:            }
806:
807:            /**
808:             * Return the java.awt.Font to be used to display the legend items
809:             *
810:             * @return Font The font for the legend items
811:             */
812:            public Font getLegendFont() {
813:                // TODO Auto-generated method stub
814:                return legendFont;
815:            }
816:
817:            /**
818:             * Set java.awt.Font to be used to display the legend items
819:             *
820:             * @param Font The java.awt.Font for the legend items
821:             */
822:            public void setLegendFont(Font legendFont) {
823:                this .legendFont = legendFont;
824:            }
825:
826:            public void setLegendFont(Node legendFontNode) {
827:                Font font = JFreeChartEngine.getFont(legendFontNode);
828:                if (font != null) {
829:                    setLegendFont(font);
830:                }
831:            }
832:
833:            public void setLegendBorderVisible(Node legendBorderVisibleNode) {
834:                if (legendBorderVisibleNode != null) {
835:                    boolean legBorderVisible = (new Boolean(
836:                            legendBorderVisibleNode.getText())).booleanValue();
837:                    setLegendBorderVisible(legBorderVisible);
838:                }
839:            }
840:
841:            /**
842:             * @param boolean legendBorderVisible
843:             *        Set the visibility of the legend border.
844:             */
845:            public void setLegendBorderVisible(boolean legendBorderVisible) {
846:                this .legendBorderVisible = legendBorderVisible;
847:            }
848:
849:            /**
850:             * Return the boolen that states if the legend border is visible
851:             *
852:             * @return boolean Is the legend border visible
853:             */
854:            public boolean isLegendBorderVisible() {
855:                return legendBorderVisible;
856:            }
857:
858:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.