Source Code Cross Referenced for ASTFrame.java in  » J2EE » hgcommons » biz » hammurapi » antlr » 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 » J2EE » hgcommons » biz.hammurapi.antlr 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /**
002:         * Borrowed from Terence Parr
003:         */package biz.hammurapi.antlr;
004:
005:        /* ANTLR Translator Generator
006:         * Project led by Terence Parr at http://www.jGuru.com
007:         * Software rights: http://www.antlr.org/license.html
008:         *
009:         * $Id: //depot/code/org.antlr/release/antlr-2.7.5/antlr/debug/misc/ASTFrame.java#1 $
010:         */
011:
012:        import java.awt.BorderLayout;
013:        import java.awt.Container;
014:        import java.awt.Frame;
015:        import java.awt.event.WindowAdapter;
016:        import java.awt.event.WindowEvent;
017:
018:        import javax.swing.JFrame;
019:        import javax.swing.JPanel;
020:        import javax.swing.JScrollPane;
021:        import javax.swing.JTree;
022:        import javax.swing.event.TreeModelListener;
023:        import javax.swing.event.TreeSelectionListener;
024:        import javax.swing.tree.TreeModel;
025:        import javax.swing.tree.TreePath;
026:
027:        import antlr.collections.AST;
028:
029:        public class ASTFrame extends JFrame {
030:
031:            public static class JTreeASTPanel extends JPanel {
032:                JTree tree;
033:
034:                public JTreeASTPanel(TreeModel tm,
035:                        TreeSelectionListener listener) {
036:                    // use a layout that will stretch tree to panel size
037:                    setLayout(new BorderLayout());
038:
039:                    // Create tree
040:                    tree = new JTree(tm);
041:
042:                    // Change line style
043:                    tree.putClientProperty("JTree.lineStyle", "Angled");
044:
045:                    // Add TreeSelectionListener
046:                    if (listener != null)
047:                        tree.addTreeSelectionListener(listener);
048:
049:                    // Put tree in a scrollable pane's viewport
050:                    JScrollPane sp = new JScrollPane();
051:                    sp.getViewport().add(tree);
052:
053:                    add(sp, BorderLayout.CENTER);
054:                }
055:            }
056:
057:            public static class JTreeASTModel implements  TreeModel {
058:
059:                private class Node {
060:                    AST master;
061:
062:                    /**
063:                     * @param master
064:                     */
065:                    public Node(AST master) {
066:                        super ();
067:                        // TODO Auto-generated constructor stub
068:                        this .master = master;
069:                    }
070:
071:                    public String toString() {
072:                        return "[" + tokenNames[master.getType()] + " "
073:                                + master.getLine() + ":" + master.getColumn()
074:                                + "] " + master.getText();
075:                    }
076:
077:                    public int hashCode() {
078:                        return master.hashCode();
079:                    }
080:
081:                    public boolean equals(Object obj) {
082:                        return obj instanceof  Node
083:                                && master.equals(((Node) obj).master);
084:                    }
085:                }
086:
087:                AST root = null;
088:                private String[] tokenNames;
089:
090:                public JTreeASTModel(AST t, String[] tokenNames) {
091:                    if (t == null) {
092:                        throw new IllegalArgumentException("root is null");
093:                    }
094:                    root = t;
095:                    this .tokenNames = tokenNames;
096:                }
097:
098:                public void addTreeModelListener(TreeModelListener l) {
099:                }
100:
101:                public Object getChild(Object parent, int index) {
102:                    if (parent == null) {
103:                        return null;
104:                    }
105:                    AST p = ((Node) parent).master;
106:                    AST c = p.getFirstChild();
107:                    if (c == null) {
108:                        throw new ArrayIndexOutOfBoundsException(
109:                                "node has no children");
110:                    }
111:                    int i = 0;
112:                    while (c != null && i < index) {
113:                        c = c.getNextSibling();
114:                        i++;
115:                    }
116:
117:                    return new Node(c);
118:                }
119:
120:                public int getChildCount(Object parent) {
121:                    if (parent == null) {
122:                        throw new IllegalArgumentException("root is null");
123:                    }
124:                    AST p = ((Node) parent).master;
125:                    AST c = p.getFirstChild();
126:                    int i = 0;
127:                    while (c != null) {
128:                        c = c.getNextSibling();
129:                        i++;
130:                    }
131:                    return i;
132:                }
133:
134:                public int getIndexOfChild(Object parent, Object child) {
135:                    if (parent == null || child == null) {
136:                        throw new IllegalArgumentException(
137:                                "root or child is null");
138:                    }
139:                    AST p = ((Node) parent).master;
140:                    AST c = p.getFirstChild();
141:                    if (c == null) {
142:                        throw new ArrayIndexOutOfBoundsException(
143:                                "node has no children");
144:                    }
145:                    int i = 0;
146:                    while (c != null && c != ((Node) child).master) {
147:                        c = c.getNextSibling();
148:                        i++;
149:                    }
150:                    if (c == ((Node) child).master) {
151:                        return i;
152:                    }
153:                    throw new java.util.NoSuchElementException(
154:                            "node is not a child");
155:                }
156:
157:                public Object getRoot() {
158:                    return new Node(root);
159:                }
160:
161:                public boolean isLeaf(Object node) {
162:                    if (node == null) {
163:                        throw new IllegalArgumentException("node is null");
164:                    }
165:                    AST t = ((Node) node).master;
166:                    return t.getFirstChild() == null;
167:                }
168:
169:                public void removeTreeModelListener(TreeModelListener l) {
170:                }
171:
172:                public void valueForPathChanged(TreePath path, Object newValue) {
173:                    System.out
174:                            .println("heh, who is calling this mystery method?");
175:                }
176:            }
177:
178:            // The initial width and height of the frame
179:            static final int FRAME_WIDTH = 400;
180:            static final int FRAME_HEIGHT = 600;
181:
182:            public ASTFrame(String lab, AST r, String[] tokenNames) {
183:                super (lab);
184:
185:                JTreeASTPanel tp = new JTreeASTPanel(new JTreeASTModel(r,
186:                        tokenNames), null);
187:                Container content = getContentPane();
188:                content.add(tp, BorderLayout.CENTER);
189:                addWindowListener(new WindowAdapter() {
190:                    public void windowClosing(WindowEvent e) {
191:                        Frame f = (Frame) e.getSource();
192:                        f.setVisible(false);
193:                        f.dispose();
194:                        // System.exit(0);
195:                    }
196:                });
197:                setSize(FRAME_WIDTH, FRAME_HEIGHT);
198:            }
199:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.