Source Code Cross Referenced for SourceCodeControl.java in  » 6.0-JDK-Modules » java-3d » org » jdesktop » j3dedit » scenegrapheditor » sourcecontrol » 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 » 6.0 JDK Modules » java 3d » org.jdesktop.j3dedit.scenegrapheditor.sourcecontrol 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *  $Header: /cvs/j3dfly/J3dEditor/src/org/jdesktop/j3dedit/scenegrapheditor/sourcecontrol/SourceCodeControl.java,v 1.1 2005/04/20 22:21:21 paulby Exp $
003:         *
004:         *                         Sun Public License Notice
005:         *
006:         *  The contents of this file are subject to the Sun Public License Version
007:         *  1.0 (the "License"). You may not use this file except in compliance with
008:         *  the License. A copy of the License is available at http://www.sun.com/
009:         *  
010:         *  The Original Code is the Java 3D(tm) Scene Graph Editor.
011:         *  The Initial Developer of the Original Code is Paul Byrne.
012:         *  Portions created by Paul Byrne are Copyright (C) 2002.
013:         *  All Rights Reserved.
014:         *  
015:         *  Contributor(s): Paul Byrne.
016:         *  
017:         **/
018:        package org.jdesktop.j3dedit.scenegrapheditor.sourcecontrol;
019:
020:        import java.io.*;
021:        import java.util.*;
022:
023:        /**
024:         * Controls the generation of source code for the  Java3D applications
025:         *
026:         * This initial version is very limited in terms of it's formating
027:         * capabilities. Futher work is required and probably some extension to the
028:         * interface.
029:         *
030:         * @Author Paul Byrne
031:         *  @(#)SourceCodeControl.java 1.4 99/04/07 23:04:56
032:         */
033:        public class SourceCodeControl {
034:
035:            private String className = new String("className");
036:
037:            private Stack methodStack;
038:            private Stack tmpVarStack;
039:
040:            private ArrayList globalVar;
041:            private ArrayList methods;
042:            private TreeSet imports; // All the required imports
043:
044:            private int tmpVar = 0; // Count of temporary variables
045:
046:            public SourceCodeControl() {
047:                methods = new ArrayList();
048:                methodStack = new Stack();
049:                tmpVarStack = new Stack();
050:                imports = new TreeSet();
051:                globalVar = new ArrayList();
052:
053:                imports.add("java.applet.Applet");
054:                imports.add("javax.media.j3d.*");
055:                imports.add("com.sun.j3d.utils.applet.MainFrame");
056:            }
057:
058:            /**
059:             * Returns the name of this class
060:             */
061:            public String getClassName() {
062:                return className;
063:            }
064:
065:            /**
066:             * Set the name of the current class
067:             */
068:            public void setClassName(String className) {
069:                this .className = className;
070:            }
071:
072:            /**
073:             * Add a method to the package and make it the current method
074:             */
075:            public void newCurrentMethod(CodeMethod method) {
076:                if (methods.contains(method))
077:                    throw new RuntimeException(
078:                            "Duplicate Method Name in SourceCodeControl "
079:                                    + method);
080:                methods.add(method);
081:                methodStack.push(method);
082:
083:                tmpVarStack.push(new Integer(tmpVar));
084:                tmpVar = 0;
085:            }
086:
087:            /**
088:             * Finish the current method
089:             * The new current method will be the previous current method ie
090:             * the current method stack will be popped
091:             */
092:            public void completeCurrentMethod() {
093:                methodStack.pop();
094:                tmpVar = ((Integer) tmpVarStack.pop()).intValue();
095:            }
096:
097:            /**
098:             * Returns a temporary variable name.
099:             * Takes into account the current scope so variable names are
100:             * reused
101:             *
102:             * Needs improving so that variable names represent types
103:             */
104:            public String getTmpVariableName() {
105:                if (tmpVar > 0)
106:                    return "tmp" + tmpVar++;
107:                else {
108:                    tmpVar++;
109:                    return "tmp";
110:                }
111:            }
112:
113:            /**
114:             * Add the line to the current method
115:             */
116:            public void addLine(int indent, String line) {
117:                ((CodeMethod) methodStack.peek()).addLine(indent, line);
118:            }
119:
120:            /**
121:             * Add an import statement
122:             *
123:             * Duplicates will be removed
124:             */
125:            public void addImport(String name) {
126:                imports.add(name);
127:            }
128:
129:            /**
130:             * Add a global variable
131:             */
132:            public void addGlobalVariable(String code) {
133:                globalVar.add(code);
134:            }
135:
136:            /**  
137:             * Produce the require indent in the code
138:             * output stream
139:             */
140:            void doIndent(PrintStream out, int indent) {
141:                for (int i = 0; i < indent; i++)
142:                    out.print("    ");
143:            }
144:
145:            /**
146:             * Output a formated line of code
147:             */
148:            void outputLine(PrintStream out, int indent, String line) {
149:                doIndent(out, indent);
150:                out.println(line);
151:            }
152:
153:            void outputLine(PrintStream out) {
154:                out.println();
155:            }
156:
157:            private void writeHeader(PrintStream out) {
158:                out.println("// Java3D generated by Java3D world builder");
159:                out.println("// World builder by Paul Byrne");
160:                out.println("//     Paul.Byrne@uk.sun.com");
161:                out.println();
162:            }
163:
164:            private void writeImports(PrintStream out) {
165:
166:                Iterator it = imports.iterator();
167:
168:                while (it.hasNext()) {
169:                    out.println("import " + it.next() + ";");
170:                }
171:
172:            }
173:
174:            private void writeGlobalVariables(PrintStream out) {
175:                Iterator it = globalVar.iterator();
176:
177:                while (it.hasNext()) {
178:                    out.println("    " + it.next() + ";");
179:                }
180:            }
181:
182:            private void writeMethods(PrintStream out) {
183:
184:                Iterator it = methods.iterator();
185:                CodeMethod method;
186:
187:                while (it.hasNext()) {
188:                    method = (CodeMethod) it.next();
189:                    method.writeMethod(out);
190:                }
191:            }
192:
193:            public void generateCode() {
194:                generateCode(System.out);
195:            }
196:
197:            public void generateCode(OutputStream outStream) {
198:                PrintStream out = new PrintStream(outStream);
199:
200:                writeHeader(out);
201:                writeImports(out);
202:                outputLine(out, 0, "public class " + className
203:                        + " extends Applet {");
204:
205:                writeGlobalVariables(out);
206:
207:                outputLine(out, 1, "public " + className + "() {");
208:                outputLine(out, 2, "buildUniverse();");
209:                outputLine(out, 1, "}");
210:
211:                writeMethods(out);
212:
213:                outputLine(out, 1, "public static void main( String[] args ) {");
214:                outputLine(out, 2, "new MainFrame( new " + className
215:                        + "(), 256, 256 );");
216:                outputLine(out, 1, "}");
217:
218:                outputLine(out, 0, "}");
219:            }
220:
221:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.