Source Code Cross Referenced for JavaSourceCanvas.java in  » Code-Analyzer » Java2Html » de » java2html » 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 » Code Analyzer » Java2Html » de.java2html 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package de.java2html;
002:
003:        import java.awt.BorderLayout;
004:        import java.awt.Color;
005:        import java.awt.Dimension;
006:        import java.awt.Frame;
007:        import java.awt.Graphics;
008:        import java.awt.event.WindowAdapter;
009:        import java.awt.event.WindowEvent;
010:        import java.util.StringTokenizer;
011:
012:        import javax.swing.JComponent;
013:
014:        import de.java2html.javasource.JavaSource;
015:        import de.java2html.javasource.JavaSourceParser;
016:        import de.java2html.javasource.JavaSourceType;
017:        import de.java2html.options.JavaSourceStyleTable;
018:        import de.java2html.util.RGB;
019:
020:        /**
021:         * Experimental: A <code>java.awt.Canvas</code> for displaying parsed java source code as one pixel
022:         * per character. The code will be displayed in colored pixels with one square block of pixels for
023:         * each character in the code. At the moment there is not really any use for this class yet, however
024:         * it could be cool to write a plugin for IDEs to be able to navigate in a source code by clicking in
025:         * this overview component... Just an idea ;-)
026:         *
027:         * For questions, suggestions, bug-reports, enhancement-requests etc.
028:         * I may be contacted at:
029:         *   <a href="mailto:markus@jave.de">markus@jave.de</a>
030:         *
031:         * The Java2html home page is located at:
032:         *   <a href="http://www.java2html.de">http://www.java2html.de</a>
033:         *
034:         * @author  <a href="mailto:markus@jave.de">Markus Gebhard</a>
035:         * @version 2.0, 05/07/02
036:         *
037:         * Copyright (C) Markus Gebhard 2000-2002
038:         *
039:         * This program is free software; you can redistribute it and/or
040:         * modify it under the terms of the GNU General Public License
041:         * as published by the Free Software Foundation; either version 2
042:         * of the License, or (at your option) any later version.
043:         *
044:         * This program is distributed in the hope that it will be useful,
045:         * but WITHOUT ANY WARRANTY; without even the implied warranty of
046:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
047:         * GNU General Public License for more details.
048:         * 
049:         * You should have received a copy of the GNU General Public License
050:         * along with this program; if not, write to the Free Software
051:         * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
052:         */
053:        public class JavaSourceCanvas extends JComponent {
054:            protected JavaSource source;
055:            protected int scale = 1; //number of pixels per character
056:            private JavaSourceStyleTable colorTable = JavaSourceStyleTable
057:                    .getDefault();
058:
059:            public JavaSourceCanvas(JavaSource source) {
060:                this .source = source;
061:            }
062:
063:            /**
064:             * This method was once used for drawing the source code
065:             * (a pixel for each character)
066:             * I will leave it here - maybe someone will use it some day 
067:             */
068:            public Dimension getPreferredSize() {
069:                return new Dimension(scale * source.getMaxLineLength(), scale
070:                        * source.getLineCount());
071:            }
072:
073:            /**
074:             * This method was once used for drawing the source code
075:             * (a pixel for each character).
076:             * I will leave it here - maybe someone will use it some day 
077:             */
078:            public void paint(Graphics g) {
079:                //White background where source code
080:                g.setColor(Color.white);
081:                Dimension d = getPreferredSize();
082:                g.fillRect(0, 0, d.width, d.height);
083:
084:                int y = 0;
085:
086:                int index = 0;
087:                StringTokenizer st = new StringTokenizer(source.getCode(),
088:                        "\n\r", true);
089:                while (st.hasMoreTokens()) {
090:                    String line = st.nextToken();
091:
092:                    if (line.charAt(0) == '\n' || line.charAt(0) == '\r') {
093:                        ++index;
094:                        ++y;
095:                    } else {
096:                        paint(g, y, index, index + line.length() - 1);
097:                        index += line.length();
098:                    }
099:                }
100:            }
101:
102:            /**
103:             *
104:             */
105:            protected void paint(Graphics g, int y, int start, int end) {
106:                int x = 0;
107:                int index1 = start;
108:                int index2 = start;
109:
110:                JavaSourceType[] sourceTypes = source.getClassification();
111:
112:                while (index2 <= end) {
113:                    while (index2 < end
114:                            && sourceTypes[index2 + 1] == sourceTypes[index1]) {
115:                        ++index2;
116:                    }
117:
118:                    if (sourceTypes[index1] != JavaSourceType.BACKGROUND) {
119:                        g.setColor(getAwtColor(colorTable.get(
120:                                sourceTypes[index1]).getColor()));
121:
122:                        if (scale == 1)
123:                            g.drawLine(x, y, (x + index2 - index1), y);
124:                        else if (scale == 2) {
125:                            g.drawLine(2 * x, 2 * y,
126:                                    2 * (x + index2 - index1) + 1, 2 * y);
127:                            g.drawLine(2 * x, 2 * y + 1,
128:                                    2 * (x + index2 - index1) + 1, 2 * y + 1);
129:                        } else
130:                            System.err.println("scale>2 not implemented yet!");
131:                    }
132:
133:                    x += index2 - index1 + 1;
134:
135:                    index1 = index2 + 1;
136:                    index2 = index1;
137:                }
138:            }
139:
140:            private Color getAwtColor(RGB rgb) {
141:                return new Color(rgb.getRed(), rgb.getGreen(), rgb.getBlue());
142:            }
143:
144:            public static void main(String args[]) throws Exception {
145:                JavaSourceParser parser = new JavaSourceParser();
146:                JavaSource j = parser
147:                        .parse(new java.io.File(
148:                                "f:\\eclipse\\de\\java2html\\JavaSource2TeXConverter.java"));
149:                JavaSourceCanvas canny = new JavaSourceCanvas(j);
150:                Frame f = new Frame();
151:                f.addWindowListener(new WindowAdapter() {
152:                    public void windowClosing(WindowEvent e) {
153:                        System.exit(0);
154:                    }
155:                });
156:
157:                f.setLayout(new BorderLayout());
158:                f.add(canny, BorderLayout.CENTER);
159:                f.pack();
160:                f.setVisible(true);
161:            }
162:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.