Source Code Cross Referenced for XYDotRenderer.java in  » Chart » jfreechart » org » jfree » chart » renderer » xy » 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.renderer.xy 
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:         * XYDotRenderer.java
029:         * ------------------
030:         * (C) Copyright 2002-2007, by Object Refinery Limited.
031:         *
032:         * Original Author:  David Gilbert (for Object Refinery Limited);
033:         * Contributor(s):   Christian W. Zuckschwerdt;
034:         *
035:         * $Id: XYDotRenderer.java,v 1.5.2.4 2007/02/06 16:29:11 mungady Exp $
036:         *
037:         * Changes (from 29-Oct-2002)
038:         * --------------------------
039:         * 29-Oct-2002 : Added standard header (DG);
040:         * 25-Mar-2003 : Implemented Serializable (DG);
041:         * 01-May-2003 : Modified drawItem() method signature (DG);
042:         * 30-Jul-2003 : Modified entity constructor (CZ);
043:         * 20-Aug-2003 : Implemented Cloneable and PublicCloneable (DG);
044:         * 16-Sep-2003 : Changed ChartRenderingInfo --> PlotRenderingInfo (DG);
045:         * 25-Feb-2004 : Replaced CrosshairInfo with CrosshairState (DG);
046:         * 19-Jan-2005 : Now uses only primitives from dataset (DG);
047:         * ------------- JFREECHART 1.0.x ---------------------------------------------
048:         * 10-Jul-2006 : Added dotWidth and dotHeight attributes (DG);
049:         * 06-Feb-2007 : Fixed bug 1086307, crosshairs with multiple axes (DG);
050:         *
051:         */
052:
053:        package org.jfree.chart.renderer.xy;
054:
055:        import java.awt.Graphics2D;
056:        import java.awt.geom.Rectangle2D;
057:        import java.io.Serializable;
058:
059:        import org.jfree.chart.axis.ValueAxis;
060:        import org.jfree.chart.event.RendererChangeEvent;
061:        import org.jfree.chart.plot.CrosshairState;
062:        import org.jfree.chart.plot.PlotOrientation;
063:        import org.jfree.chart.plot.PlotRenderingInfo;
064:        import org.jfree.chart.plot.XYPlot;
065:        import org.jfree.data.xy.XYDataset;
066:        import org.jfree.ui.RectangleEdge;
067:        import org.jfree.util.PublicCloneable;
068:
069:        /**
070:         * A renderer that draws a small dot at each data point for an {@link XYPlot}.
071:         */
072:        public class XYDotRenderer extends AbstractXYItemRenderer implements 
073:                XYItemRenderer, Cloneable, PublicCloneable, Serializable {
074:
075:            /** For serialization. */
076:            private static final long serialVersionUID = -2764344339073566425L;
077:
078:            /** The dot width. */
079:            private int dotWidth;
080:
081:            /** The dot height. */
082:            private int dotHeight;
083:
084:            /**
085:             * Constructs a new renderer.
086:             */
087:            public XYDotRenderer() {
088:                super ();
089:                this .dotWidth = 1;
090:                this .dotHeight = 1;
091:            }
092:
093:            /**
094:             * Returns the dot width (the default value is 1).
095:             * 
096:             * @return The dot width.
097:             * 
098:             * @since 1.0.2
099:             * @see #setDotWidth(int)
100:             */
101:            public int getDotWidth() {
102:                return this .dotWidth;
103:            }
104:
105:            /**
106:             * Sets the dot width and sends a {@link RendererChangeEvent} to all 
107:             * registered listeners.
108:             * 
109:             * @param w  the new width (must be greater than zero).
110:             * 
111:             * @throws IllegalArgumentException if <code>w</code> is less than one.
112:             * 
113:             * @since 1.0.2
114:             * @see #getDotWidth()
115:             */
116:            public void setDotWidth(int w) {
117:                if (w < 1) {
118:                    throw new IllegalArgumentException("Requires w > 0.");
119:                }
120:                this .dotWidth = w;
121:                notifyListeners(new RendererChangeEvent(this ));
122:            }
123:
124:            /**
125:             * Returns the dot height (the default value is 1).
126:             * 
127:             * @return The dot height.
128:             * 
129:             * @since 1.0.2
130:             * @see #setDotHeight(int)
131:             */
132:            public int getDotHeight() {
133:                return this .dotHeight;
134:            }
135:
136:            /**
137:             * Sets the dot height and sends a {@link RendererChangeEvent} to all 
138:             * registered listeners.
139:             * 
140:             * @param h  the new height (must be greater than zero).
141:             * 
142:             * @throws IllegalArgumentException if <code>h</code> is less than one.
143:             * 
144:             * @since 1.0.2
145:             * @see #getDotHeight()
146:             */
147:            public void setDotHeight(int h) {
148:                if (h < 1) {
149:                    throw new IllegalArgumentException("Requires h > 0.");
150:                }
151:                this .dotHeight = h;
152:                notifyListeners(new RendererChangeEvent(this ));
153:            }
154:
155:            /**
156:             * Draws the visual representation of a single data item.
157:             *
158:             * @param g2  the graphics device.
159:             * @param state  the renderer state.
160:             * @param dataArea  the area within which the data is being drawn.
161:             * @param info  collects information about the drawing.
162:             * @param plot  the plot (can be used to obtain standard color 
163:             *              information etc).
164:             * @param domainAxis  the domain (horizontal) axis.
165:             * @param rangeAxis  the range (vertical) axis.
166:             * @param dataset  the dataset.
167:             * @param series  the series index (zero-based).
168:             * @param item  the item index (zero-based).
169:             * @param crosshairState  crosshair information for the plot 
170:             *                        (<code>null</code> permitted).
171:             * @param pass  the pass index.
172:             */
173:            public void drawItem(Graphics2D g2, XYItemRendererState state,
174:                    Rectangle2D dataArea, PlotRenderingInfo info, XYPlot plot,
175:                    ValueAxis domainAxis, ValueAxis rangeAxis,
176:                    XYDataset dataset, int series, int item,
177:                    CrosshairState crosshairState, int pass) {
178:
179:                // get the data point...
180:                double x = dataset.getXValue(series, item);
181:                double y = dataset.getYValue(series, item);
182:                double adjx = (this .dotWidth - 1) / 2.0;
183:                double adjy = (this .dotHeight - 1) / 2.0;
184:                if (!Double.isNaN(y)) {
185:                    RectangleEdge xAxisLocation = plot.getDomainAxisEdge();
186:                    RectangleEdge yAxisLocation = plot.getRangeAxisEdge();
187:                    double transX = domainAxis.valueToJava2D(x, dataArea,
188:                            xAxisLocation)
189:                            - adjx;
190:                    double transY = rangeAxis.valueToJava2D(y, dataArea,
191:                            yAxisLocation)
192:                            - adjy;
193:
194:                    g2.setPaint(getItemPaint(series, item));
195:                    PlotOrientation orientation = plot.getOrientation();
196:                    if (orientation == PlotOrientation.HORIZONTAL) {
197:                        g2.fillRect((int) transY, (int) transX, this .dotHeight,
198:                                this .dotWidth);
199:                    } else if (orientation == PlotOrientation.VERTICAL) {
200:                        g2.fillRect((int) transX, (int) transY, this .dotWidth,
201:                                this .dotHeight);
202:                    }
203:
204:                    int domainAxisIndex = plot.getDomainAxisIndex(domainAxis);
205:                    int rangeAxisIndex = plot.getRangeAxisIndex(rangeAxis);
206:                    updateCrosshairValues(crosshairState, x, y,
207:                            domainAxisIndex, rangeAxisIndex, transX, transY,
208:                            orientation);
209:                }
210:
211:            }
212:
213:            /**
214:             * Tests this renderer for equality with an arbitrary object.  This method
215:             * returns <code>true</code> if and only if:
216:             * 
217:             * <ul>
218:             * <li><code>obj</code> is not <code>null</code>;</li>
219:             * <li><code>obj</code> is an instance of <code>XYDotRenderer</code>;</li>
220:             * <li>both renderers have the same attribute values.
221:             * </ul>
222:             * 
223:             * @param obj  the object (<code>null</code> permitted).
224:             * 
225:             * @return A boolean.
226:             */
227:            public boolean equals(Object obj) {
228:                if (obj == this ) {
229:                    return true;
230:                }
231:                if (!(obj instanceof  XYDotRenderer)) {
232:                    return false;
233:                }
234:                XYDotRenderer that = (XYDotRenderer) obj;
235:                if (this .dotWidth != that.dotWidth) {
236:                    return false;
237:                }
238:                if (this .dotHeight != that.dotHeight) {
239:                    return false;
240:                }
241:                return super .equals(obj);
242:            }
243:
244:            /**
245:             * Returns a clone of the renderer.
246:             * 
247:             * @return A clone.
248:             * 
249:             * @throws CloneNotSupportedException  if the renderer cannot be cloned.
250:             */
251:            public Object clone() throws CloneNotSupportedException {
252:                return super.clone();
253:            }
254:
255:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.