Source Code Cross Referenced for RowColorModel.java in  » Chart » charting-0.94 » de » progra » charting » render » 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 » charting 0.94 » de.progra.charting.render 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:            JOpenChart Java Charting Library and Toolkit
003:            Copyright (C) 2001  Sebastian Müller
004:            http://jopenchart.sourceforge.net
005:
006:            This library is free software; you can redistribute it and/or
007:            modify it under the terms of the GNU Lesser General Public
008:            License as published by the Free Software Foundation; either
009:            version 2.1 of the License, or (at your option) any later version.
010:
011:            This library is distributed in the hope that it will be useful,
012:            but WITHOUT ANY WARRANTY; without even the implied warranty of
013:            MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
014:            Lesser General Public License for more details.
015:
016:            You should have received a copy of the GNU Lesser General Public
017:            License along with this library; if not, write to the Free Software
018:            Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
019:
020:            RowColorModel.java
021:            Created on 28. August 2001, 20:02
022:         */
023:
024:        package de.progra.charting.render;
025:
026:        import java.awt.Color;
027:        import de.progra.charting.model.ChartDataModel;
028:        import java.util.HashMap;
029:        import java.awt.geom.RectangularShape;
030:        import java.awt.geom.Ellipse2D;
031:        import java.awt.geom.Rectangle2D;
032:        import de.progra.charting.render.shape.Diamond2D;
033:        import de.progra.charting.render.shape.Triangle2D;
034:
035:        /**
036:         * This class implements the correspondence between the DataSets and the
037:         * colors used for rendering the charts and the legend.
038:         * @author mueller
039:         * @version 1.0
040:         */
041:        public class RowColorModel {
042:
043:            private static RowColorModel instance;
044:
045:            protected ChartDataModel model;
046:
047:            protected final static Color[] predefinedColors = { Color.blue,
048:                    Color.cyan, Color.red, Color.pink, Color.yellow,
049:                    Color.green, Color.magenta, Color.orange, Color.darkGray,
050:                    Color.gray, Color.lightGray };
051:
052:            public static final Ellipse2D ELLIPSE_SHAPE = new Ellipse2D.Float(
053:                    0f, 0f, 5f, 5f);
054:            public static final Rectangle2D SQUARE_SHAPE = new Rectangle2D.Float(
055:                    0f, 0f, 5f, 5f);
056:            public static final Diamond2D DIAMOND_SHAPE = new Diamond2D(0f, 0f,
057:                    5f, 5f);
058:            public static final Triangle2D TRIANGLE_SHAPE = new Triangle2D(0f,
059:                    0f, 5f, 5f, false);
060:            public static final Triangle2D TRIANGLEDOWN_SHAPE = new Triangle2D(
061:                    0f, 0f, 5f, 5f, true);
062:
063:            protected final static RectangularShape[] predefinedShapes = {
064:                    ELLIPSE_SHAPE, SQUARE_SHAPE, DIAMOND_SHAPE, TRIANGLE_SHAPE,
065:                    TRIANGLEDOWN_SHAPE };
066:
067:            protected int predefinedColorsIdx = 0;
068:
069:            protected HashMap customColors = new HashMap();
070:
071:            protected HashMap customShapes = new HashMap();
072:
073:            /** Creates new RowColorModel.
074:             * @param model the ChartDataModel which contains the information about all the DataSets
075:             */
076:            public RowColorModel(ChartDataModel model) {
077:                this .model = model;
078:            }
079:
080:            /** Use this method to get an instance of the chart's RowColorModel. 
081:             * @param model the ChartDataModel whose data sets will be mapped to
082:             * colors.
083:             * @return a new instance of RowColorModel if there's no instance 
084:             * of if the model has changed (esp. useful if you create multiple charts
085:             * after one another).
086:             * @deprecated
087:             */
088:            public static RowColorModel getInstance(ChartDataModel model) {
089:                if (instance == null || !model.equals(instance.model))
090:                    instance = new RowColorModel(model);
091:
092:                return instance;
093:            }
094:
095:            /** Computes the amount of all Legend entries, ie. DataSets.
096:             * @return the amount of all rows, ie. DataSets.
097:             */
098:            public int getRowCount() {
099:                return model.getDataSetNumber();
100:            }
101:
102:            /** Returns the row title of a specific DataSet.
103:             * @param i the DataSet index
104:             * @return the String title
105:             */
106:            public String getRow(int i) {
107:                return model.getDataSetName(i);
108:            }
109:
110:            /** Computes the Color for a DataSet. For the first DataSets the stored Colors like <CODE>Color.red</CODE> etc are used. If there are more DataSets than stored colors, random colors are used.
111:             * @param row the row for which the Color should be returned
112:             * @return the Color stored for the given row.
113:             */
114:            public Color getColor(int row) {
115:
116:                // get the custom color
117:                Color c = (Color) customColors.get(new Integer(row));
118:
119:                // if no custom color
120:                if (c == null) {
121:                    // see if there is a predefined color for this row
122:                    if (predefinedColorsIdx < predefinedColors.length) {
123:                        c = predefinedColors[predefinedColorsIdx++];
124:                    } else {
125:                        c = new Color((float) Math.random(), (float) Math
126:                                .random(), (float) Math.random());
127:                    }
128:
129:                    // remember this 
130:                    customColors.put(new Integer(row), c);
131:                }
132:
133:                // done
134:                return c;
135:            }
136:
137:            /** Returns the Shape for a DataSet. By default, the Shapes from
138:             * the <code>predefinedShapes</code> array are cycled through unless you define
139:             * your own shape to data binding using 
140:             * <code>setShape(int row, RectangularShape shape)</code>.
141:             * @param row the row for which the Shape should be returned
142:             * @return the Shape stored for the given row.
143:             */
144:            public RectangularShape getShape(int row) {
145:
146:                // get the custom color
147:                RectangularShape c = (RectangularShape) customShapes
148:                        .get(new Integer(row));
149:
150:                // if no custom color
151:                if (c == null) {
152:                    // calculate the matching predefined shape by a modulo operation
153:                    c = predefinedShapes[row % predefinedShapes.length];
154:
155:                    // remember this 
156:                    customShapes.put(new Integer(row), c);
157:                }
158:
159:                // done
160:                return c;
161:            }
162:
163:            /** Force a certain color for a row
164:             * @param row the row for which the Color should be set
165:             * @param color the color that is associated with the row
166:             */
167:            public void setColor(int row, Color color) {
168:                customColors.put(new Integer(row), color);
169:            }
170:
171:            /** Force a certain Shape for a row
172:             * @param row the row for which the Shape should be set
173:             * @param shape the RectangularShape that is associated with the row
174:             */
175:            public void setShape(int row, RectangularShape shape) {
176:                customShapes.put(new Integer(row), shape);
177:            }
178:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.