Source Code Cross Referenced for StandardXYZToolTipGenerator.java in  » Chart » jfreechart » org » jfree » chart » labels » 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.labels 
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:         * StandardXYZToolTipGenerator.java
029:         * --------------------------------
030:         * (C) Copyright 2004, 2005, by Object Refinery Limited.
031:         *
032:         * Original Author:  David Gilbert (for Object Refinery Limited);
033:         * Contributor(s):   -;
034:         *
035:         * $Id: StandardXYZToolTipGenerator.java,v 1.5.2.1 2005/10/25 20:49:02 mungady Exp $
036:         *
037:         * Changes
038:         * -------
039:         * 11-May-2003 : Version 1, split from StandardXYZItemLabelGenerator (DG);
040:         * 15-Jul-2004 : Switched getZ() and getZValue() methods (DG);
041:         *
042:         */
043:
044:        package org.jfree.chart.labels;
045:
046:        import java.io.Serializable;
047:        import java.text.DateFormat;
048:        import java.text.MessageFormat;
049:        import java.text.NumberFormat;
050:
051:        import org.jfree.data.xy.XYDataset;
052:        import org.jfree.data.xy.XYZDataset;
053:        import org.jfree.util.ObjectUtilities;
054:
055:        /**
056:         * A standard item label generator for use with {@link XYZDataset} data.  Each 
057:         * value can be formatted as a number or as a date.
058:         */
059:        public class StandardXYZToolTipGenerator extends
060:                StandardXYToolTipGenerator implements  XYZToolTipGenerator,
061:                Serializable {
062:
063:            /** For serialization. */
064:            private static final long serialVersionUID = -2961577421889473503L;
065:
066:            /** The default tooltip format. */
067:            public static final String DEFAULT_TOOL_TIP_FORMAT = "{0}: ({1}, {2}, {3})";
068:
069:            /** 
070:             * A number formatter for the z value - if this is null, then zDateFormat 
071:             * must be non-null. 
072:             */
073:            private NumberFormat zFormat;
074:
075:            /** 
076:             * A date formatter for the z-value - if this is null, then zFormat must be 
077:             * non-null. 
078:             */
079:            private DateFormat zDateFormat;
080:
081:            /**
082:             * Creates a new tool tip generator using default number formatters for the
083:             * x, y and z-values.
084:             */
085:            public StandardXYZToolTipGenerator() {
086:                this (DEFAULT_TOOL_TIP_FORMAT, NumberFormat.getNumberInstance(),
087:                        NumberFormat.getNumberInstance(), NumberFormat
088:                                .getNumberInstance());
089:            }
090:
091:            /**
092:             * Constructs a new tool tip generator using the specified number 
093:             * formatters.
094:             *
095:             * @param formatString  the format string.
096:             * @param xFormat  the format object for the x values (<code>null</code> 
097:             *                 not permitted).
098:             * @param yFormat  the format object for the y values (<code>null</code> 
099:             *                 not permitted).
100:             * @param zFormat  the format object for the z values (<code>null</code> 
101:             *                 not permitted).
102:             */
103:            public StandardXYZToolTipGenerator(String formatString,
104:                    NumberFormat xFormat, NumberFormat yFormat,
105:                    NumberFormat zFormat) {
106:                super (formatString, xFormat, yFormat);
107:                if (zFormat == null) {
108:                    throw new IllegalArgumentException(
109:                            "Null 'zFormat' argument.");
110:                }
111:                this .zFormat = zFormat;
112:            }
113:
114:            /**
115:             * Constructs a new tool tip generator using the specified date formatters.
116:             *
117:             * @param formatString  the format string.
118:             * @param xFormat  the format object for the x values (<code>null</code> 
119:             *                 not permitted).
120:             * @param yFormat  the format object for the y values (<code>null</code> 
121:             *                 not permitted).
122:             * @param zFormat  the format object for the z values (<code>null</code> 
123:             *                 not permitted).
124:             */
125:            public StandardXYZToolTipGenerator(String formatString,
126:                    DateFormat xFormat, DateFormat yFormat, DateFormat zFormat) {
127:                super (formatString, xFormat, yFormat);
128:                if (zFormat == null) {
129:                    throw new IllegalArgumentException(
130:                            "Null 'zFormat' argument.");
131:                }
132:                this .zDateFormat = zFormat;
133:            }
134:
135:            // TODO:  add constructors for combinations of number and date formatters.
136:
137:            /**
138:             * Returns the number formatter for the z-values.
139:             *
140:             * @return The number formatter (possibly <code>null</code>).
141:             */
142:            public NumberFormat getZFormat() {
143:                return this .zFormat;
144:            }
145:
146:            /**
147:             * Returns the date formatter for the z-values.
148:             *
149:             * @return The date formatter (possibly <code>null</code>).
150:             */
151:            public DateFormat getZDateFormat() {
152:                return this .zDateFormat;
153:            }
154:
155:            /**
156:             * Generates a tool tip text item for a particular item within a series.
157:             *
158:             * @param dataset  the dataset (<code>null</code> not permitted).
159:             * @param series  the series index (zero-based).
160:             * @param item  the item index (zero-based).
161:             *
162:             * @return The tooltip text (possibly <code>null</code>).
163:             */
164:            public String generateToolTip(XYZDataset dataset, int series,
165:                    int item) {
166:                return generateLabelString(dataset, series, item);
167:            }
168:
169:            /**
170:             * Generates a label string for an item in the dataset.
171:             *
172:             * @param dataset  the dataset (<code>null</code> not permitted).
173:             * @param series  the series (zero-based index).
174:             * @param item  the item (zero-based index).
175:             *
176:             * @return The label (possibly <code>null</code>).
177:             */
178:            public String generateLabelString(XYDataset dataset, int series,
179:                    int item) {
180:                String result = null;
181:                Object[] items = createItemArray((XYZDataset) dataset, series,
182:                        item);
183:                result = MessageFormat.format(getFormatString(), items);
184:                return result;
185:            }
186:
187:            /**
188:             * Creates the array of items that can be passed to the 
189:             * {@link MessageFormat} class for creating labels.
190:             *
191:             * @param dataset  the dataset (<code>null</code> not permitted).
192:             * @param series  the series (zero-based index).
193:             * @param item  the item (zero-based index).
194:             *
195:             * @return The items (never <code>null</code>).
196:             */
197:            protected Object[] createItemArray(XYZDataset dataset, int series,
198:                    int item) {
199:
200:                Object[] result = new Object[4];
201:                result[0] = dataset.getSeriesKey(series).toString();
202:
203:                Number x = dataset.getX(series, item);
204:                DateFormat xf = getXDateFormat();
205:                if (xf != null) {
206:                    result[1] = xf.format(x);
207:                } else {
208:                    result[1] = getXFormat().format(x);
209:                }
210:
211:                Number y = dataset.getY(series, item);
212:                DateFormat yf = getYDateFormat();
213:                if (yf != null) {
214:                    result[2] = yf.format(y);
215:                } else {
216:                    result[2] = getYFormat().format(y);
217:                }
218:
219:                Number z = dataset.getZ(series, item);
220:                if (this .zDateFormat != null) {
221:                    result[3] = this .zDateFormat.format(z);
222:                } else {
223:                    result[3] = this .zFormat.format(z);
224:                }
225:
226:                return result;
227:
228:            }
229:
230:            /**
231:             * Tests this object for equality with an arbitrary object.
232:             *
233:             * @param obj  the other object (<code>null</code> permitted).
234:             *
235:             * @return A boolean.
236:             */
237:            public boolean equals(Object obj) {
238:                if (obj == this ) {
239:                    return true;
240:                }
241:                if (!(obj instanceof  StandardXYZToolTipGenerator)) {
242:                    return false;
243:                }
244:                if (!super .equals(obj)) {
245:                    return false;
246:                }
247:                StandardXYZToolTipGenerator that = (StandardXYZToolTipGenerator) obj;
248:                if (!ObjectUtilities.equal(this .zFormat, that.zFormat)) {
249:                    return false;
250:                }
251:                if (!ObjectUtilities.equal(this .zDateFormat, that.zDateFormat)) {
252:                    return false;
253:                }
254:                return true;
255:
256:            }
257:
258:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.