Source Code Cross Referenced for Legend.java in  » Chart » charting-0.94 » de » progra » charting » 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 
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:            Legend.java
021:            Created on 26. Juni 2001, 22:49
022:         */
023:
024:        package de.progra.charting;
025:
026:        import java.awt.*;
027:        import java.awt.geom.*;
028:        import java.awt.font.*;
029:        import java.awt.image.*;
030:        import de.progra.charting.render.*;
031:
032:        /** This class implements a Chart's Legend. The Strings and the colors 
033:         * can be set manually or eventually through some kind of data model.
034:         */
035:        public class Legend extends AbstractRenderer {
036:
037:            protected int inner_margin = 5;
038:            protected int color_text_spacing = 10;
039:            protected Font font = new Font("Helvetica", Font.PLAIN, 14);
040:            protected Rectangle colorbox = new Rectangle(25, 15);
041:
042:            protected RowColorModel rcm;
043:
044:            /** Creates a default Legend. */
045:            public Legend() {
046:            }
047:
048:            /** Creates a Legend with the given Strings and Colors.
049:             * @param rcm the RowColorModel containing the row titles and their colors.
050:             */
051:            public Legend(RowColorModel rcm) {
052:                setRowColorModel(rcm);
053:            }
054:
055:            /** Defines the RowColorModel of the DataModel.
056:             * @param rcm the RowColorModel
057:             */
058:            public void setRowColorModel(RowColorModel rcm) {
059:                this .rcm = rcm;
060:            }
061:
062:            /** Returns the RowColorModel of the DataModel.
063:             * @return the RowColorModel
064:             */
065:            public RowColorModel getRowColorModel() {
066:                return rcm;
067:            }
068:
069:            /** Sets the size of the color boxes.
070:             * @param r the Rectangle defining the colored box rendered left to every Legend entry.
071:             */
072:            public void setColorBox(Rectangle r) {
073:                colorbox = r;
074:            }
075:
076:            /** Returns the size of the color boxes.
077:             * @return the Rectangle defining the colored box left to every Legend entry
078:             */
079:            public Rectangle getColorBox() {
080:                return colorbox;
081:            }
082:
083:            /** Sets the Font that is used to render the Legend.
084:             * @param f the font object
085:             */
086:            public void setFont(Font f) {
087:                font = f;
088:            }
089:
090:            /** Returns this Legend's Font.
091:             * @return the font currently in use
092:             */
093:            public Font getFont() {
094:                return font;
095:            }
096:
097:            /** Returns the preferred size needed for the renderer.
098:             * @return a non-null Dimension object
099:             */
100:            public Dimension getPreferredSize() {
101:                RowColorModel rcm = getRowColorModel();
102:
103:                int maxTitleWidth = Integer.MIN_VALUE;
104:                int titleHeight = Integer.MIN_VALUE;
105:
106:                titleHeight = (int) getFont().getMaxCharBounds(
107:                        new FontRenderContext(null, true, false)).getHeight();
108:
109:                for (int i = 0; i < rcm.getRowCount(); i++) {
110:                    TextLayout layout = new TextLayout(rcm.getRow(i),
111:                            getFont(), new FontRenderContext(null, true, false));
112:
113:                    maxTitleWidth = (int) Math.max((double) maxTitleWidth,
114:                            layout.getBounds().getWidth());
115:                }
116:
117:                return new Dimension(
118:                        (int) (2 * inner_margin + color_text_spacing
119:                                + getColorBox().getWidth() + maxTitleWidth),
120:                        Math.max(titleHeight, (int) getColorBox().getHeight())
121:                                * rcm.getRowCount() + (rcm.getRowCount() + 1)
122:                                * inner_margin);
123:            }
124:
125:            /** This method is called by the paint method to do the actual painting.
126:             * The painting is supposed to start at point (0,0) and the size is
127:             * always the same as the preferred size. The paint method performs
128:             * the possible scaling.
129:             * @param g the <CODE>Graphics2D</CODE> object to paint in
130:             */
131:            public void paintDefault(Graphics2D g) {
132:                RowColorModel rcm = getRowColorModel();
133:
134:                int height = Integer.MIN_VALUE;
135:
136:                int fontheight = (int) getFont().getMaxCharBounds(
137:                        g.getFontRenderContext()).getHeight();
138:                height = (int) Math.max(fontheight, getColorBox().getHeight());
139:
140:                int startx = inner_margin;
141:                int starty = inner_margin;
142:
143:                Rectangle colorBox = getColorBox();
144:
145:                /* Rendering the Text and the ColorBoxes. */
146:                for (int i = 0; i < rcm.getRowCount(); i++) {
147:                    colorBox.setLocation(startx, starty);
148:                    g.setColor(rcm.getColor(i));
149:
150:                    g.fill(colorBox);
151:
152:                    g.setColor(Color.black);
153:
154:                    TextLayout layout = new TextLayout(rcm.getRow(i),
155:                            getFont(), new FontRenderContext(null, true, false));
156:
157:                    layout.draw(g, startx + (int) colorBox.getWidth()
158:                            + color_text_spacing, starty
159:                            + (int) colorBox.getHeight());
160:
161:                    starty = starty + height + inner_margin;
162:                }
163:            }
164:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.