Source Code Cross Referenced for TestbedUI.java in  » IDE-Netbeans » uml » org » netbeans » modules » uml » core » reverseengineering » parsers » parsertestbed » 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 » IDE Netbeans » uml » org.netbeans.modules.uml.core.reverseengineering.parsers.parsertestbed 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003:         *
004:         * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005:         *
006:         * The contents of this file are subject to the terms of either the GNU
007:         * General Public License Version 2 only ("GPL") or the Common
008:         * Development and Distribution License("CDDL") (collectively, the
009:         * "License"). You may not use this file except in compliance with the
010:         * License. You can obtain a copy of the License at
011:         * http://www.netbeans.org/cddl-gplv2.html
012:         * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013:         * specific language governing permissions and limitations under the
014:         * License.  When distributing the software, include this License Header
015:         * Notice in each file and include the License file at
016:         * nbbuild/licenses/CDDL-GPL-2-CP.  Sun designates this
017:         * particular file as subject to the "Classpath" exception as provided
018:         * by Sun in the GPL Version 2 section of the License file that
019:         * accompanied this code. If applicable, add the following below the
020:         * License Header, with the fields enclosed by brackets [] replaced by
021:         * your own identifying information:
022:         * "Portions Copyrighted [year] [name of copyright owner]"
023:         *
024:         * Contributor(s):
025:         *
026:         * The Original Software is NetBeans. The Initial Developer of the Original
027:         * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028:         * Microsystems, Inc. All Rights Reserved.
029:         *
030:         * If you wish your version of this file to be governed by only the CDDL
031:         * or only the GPL Version 2, indicate your decision by adding
032:         * "[Contributor] elects to include this software in this distribution
033:         * under the [CDDL or GPL Version 2] license." If you do not indicate a
034:         * single choice of license, a recipient has the option to distribute
035:         * your version of this file under either the CDDL, the GPL Version 2 or
036:         * to extend the choice of license to its licensees as provided above.
037:         * However, if you add GPL Version 2 code and therefore, elected the GPL
038:         * Version 2 license, then the option applies only if the new code is
039:         * made subject to such option by the copyright holder.
040:         */
041:
042:        package org.netbeans.modules.uml.core.reverseengineering.parsers.parsertestbed;
043:
044:        import javax.swing.*;
045:        import javax.swing.event.TreeSelectionEvent;
046:        import javax.swing.event.TreeSelectionListener;
047:        import javax.swing.tree.DefaultMutableTreeNode;
048:        import javax.swing.tree.DefaultTreeCellRenderer;
049:        import javax.swing.tree.DefaultTreeModel;
050:        import javax.swing.tree.MutableTreeNode;
051:        import javax.swing.tree.TreeNode;
052:        import javax.swing.tree.TreePath;
053:
054:        import org.netbeans.modules.uml.common.ETSystem;
055:        import org.netbeans.modules.uml.common.generics.ETPairT;
056:        import org.netbeans.modules.uml.core.coreapplication.CoreProduct;
057:        import org.netbeans.modules.uml.core.coreapplication.CoreProductManager;
058:        import org.netbeans.modules.uml.core.coreapplication.ICoreProduct;
059:        import org.netbeans.modules.uml.core.reverseengineering.reframework.parsingframework.ILanguage;
060:        import org.netbeans.modules.uml.core.reverseengineering.reframework.parsingframework.ILanguageParser;
061:        import org.netbeans.modules.uml.core.reverseengineering.reframework.parsingframework.ITokenDescriptor;
062:        import org.netbeans.modules.uml.core.support.umlsupport.ProductRetriever;
063:
064:        import java.awt.*;
065:        import java.awt.event.ActionEvent;
066:        import java.awt.event.ActionListener;
067:        import java.awt.event.KeyAdapter;
068:        import java.awt.event.KeyEvent;
069:        import java.awt.event.KeyListener;
070:        import java.awt.event.MouseAdapter;
071:        import java.awt.event.MouseEvent;
072:        import java.awt.event.MouseListener;
073:        import java.awt.image.RenderedImage;
074:        import java.io.File;
075:        import java.net.URL;
076:        import java.util.ArrayList;
077:        import java.util.Enumeration;
078:        import java.util.HashMap;
079:        import java.util.List;
080:        import java.util.Map;
081:
082:        /**
083:         * <p>Title: </p>
084:         * <p>Description: </p>
085:         * <p>Copyright: Copyright (c) 2003</p>
086:         * <p>Company: </p>
087:         * @author not attributable
088:         * @version 1.0
089:         */
090:
091:        public class TestbedUI extends JDialog {
092:            void parseFile() {
093:                tokenMap.clear();
094:                ((DefaultTreeModel) trParserEvents.getModel()).setRoot(null);
095:
096:                String filename = txtFilename.getText();
097:                if (filename == null
098:                        || (filename = filename.trim()).length() == 0)
099:                    return;
100:
101:                File f = new File(filename);
102:                if (!f.exists())
103:                    return;
104:
105:                ILanguage lang = ProductRetriever.retrieveProduct()
106:                        .getLanguageManager().getLanguageForFile(filename);
107:                if (lang != null) {
108:                    final ILanguageParser parser = lang.getParser("Default");
109:                    if (parser != null) {
110:                        Filter stateFilter = new Filter();
111:                        StateListener listener = new StateListener(this );
112:                        final ErrorListener errListener = new ErrorListener(
113:                                this );
114:
115:                        ListModel model = lstFilteredStates.getModel();
116:                        for (int i = 0, count = model.getSize(); i < count; ++i)
117:                            stateFilter.addState(model.getElementAt(i)
118:                                    .toString());
119:
120:                        model = lstFilteredTokens.getModel();
121:                        for (int i = 0, count = model.getSize(); i < count; ++i)
122:                            stateFilter.addToken(model.getElementAt(i)
123:                                    .toString());
124:
125:                        parser.setStateListener(listener);
126:                        parser.setStateFilter(stateFilter);
127:                        parser.setTokenProcessor(listener);
128:                        parser.setTokenFilter(stateFilter);
129:                        parser.setErrorListener(errListener);
130:
131:                        lastNode = null;
132:
133:                        final String fileToParse = filename;
134:                        Thread t = new Thread() {
135:                            public void run() {
136:                                parser.parseFile(fileToParse);
137:                                setRenderer();
138:                                ETSystem.out.println("Found "
139:                                        + errListener.getErrorCount()
140:                                        + " errors");
141:                                DefaultTreeModel model = (DefaultTreeModel) trParserEvents
142:                                        .getModel();
143:                                TreeNode root = (TreeNode) model.getRoot();
144:                                expandTreeNode(root);
145:
146:                            }
147:                        };
148:                        t.start();
149:                    }
150:                }
151:            }
152:
153:            public void setLastNode(TreeNode node) {
154:                lastNode = node;
155:            }
156:
157:            public TreeNode getLastNode() {
158:                return lastNode;
159:            }
160:
161:            /**
162:             * @param node
163:             * @param curName
164:             * @param string
165:             */
166:            public TreeNode addErrorNode(TreeNode parent, String curName,
167:                    String text) {
168:                return addNode(parent, new ErrorNode(text));
169:            }
170:
171:            /**
172:             * @param curName
173:             * @param string
174:             */
175:            public TreeNode addNode(TreeNode parent, MutableTreeNode newNode) {
176:                if (parent == null) {
177:                    DefaultTreeModel model = (DefaultTreeModel) trParserEvents
178:                            .getModel();
179:                    parent = (TreeNode) model.getRoot();
180:                    if (parent == null) {
181:                        TreeNode node = new DefaultMutableTreeNode(
182:                                "Compilation Unit");
183:                        model.setRoot(node);
184:                        parent = node;
185:                    }
186:                }
187:
188:                ((DefaultMutableTreeNode) parent).add(newNode);
189:
190:                return newNode;
191:            }
192:
193:            /**
194:             * @param curName
195:             * @param string
196:             */
197:            public TreeNode addNode(TreeNode parent, String nodeKey,
198:                    String nodeText) {
199:                return addNode(parent, new DefaultMutableTreeNode(nodeText));
200:            }
201:
202:            public TreeNode getSelectedTreeNode() {
203:                TreePath path = trParserEvents.getSelectionPath();
204:                return path != null && path.getPathCount() > 0 ? (TreeNode) path
205:                        .getPathComponent(path.getPathCount() - 1)
206:                        : null;
207:            }
208:
209:            public void treeSelectionChanged(TreeSelectionEvent e) {
210:                clearFields();
211:                TreePath path = e.getNewLeadSelectionPath();
212:                if (path != null && path.getPathCount() > 0) {
213:                    TreeNode node = (TreeNode) path.getPathComponent(path
214:                            .getPathCount() - 1);
215:                    ETPairT<ITokenDescriptor, String> tokd = tokenMap.get(node);
216:
217:                    if (tokd == null)
218:                        return;
219:                    ITokenDescriptor tok = tokd.getParamOne();
220:                    String language = tokd.getParamTwo();
221:
222:                    txtValue.setText(tok.getValue());
223:                    txtLength.setText(String.valueOf(tok.getLength()));
224:                    txtLine.setText(String.valueOf(tok.getLine()));
225:                    txtColumn.setText(String.valueOf(tok.getColumn()));
226:                    txtPosition.setText(String.valueOf(tok.getPosition()));
227:                    txtLanguage.setText(language);
228:                    txtDescription.setText(tok.getProperty("Comment"));
229:                    txtLine1.setText(tok.getProperty("CommentStartLine"));
230:                    txtColumn1.setText(tok.getProperty("CommentStartColumn"));
231:                    txtPosition1.setText(tok.getProperty("CommentStartPos"));
232:                    txtLength1.setText(tok.getProperty("CommentLength"));
233:                }
234:            }
235:
236:            private void clearFields() {
237:                txtValue.setText("");
238:                txtLength.setText("");
239:                txtLine.setText("");
240:                txtColumn.setText("");
241:                txtPosition.setText("");
242:                txtLanguage.setText("");
243:                txtDescription.setText("");
244:                txtLine1.setText("");
245:                txtColumn1.setText("");
246:                txtPosition1.setText("");
247:                txtLength1.setText("");
248:            }
249:
250:            private void jbInit() throws Exception {
251:                //lblFilename.setRequestFocusEnabled(true);
252:                lblFilename.setText("Filename");
253:                lblFilename.setBounds(new Rectangle(20, 19, 59, 15));
254:                this .getContentPane().setLayout(null);
255:                txtFilename.setText("d:\\temp\\TestbedUI.java");
256:                txtFilename.setBounds(new Rectangle(82, 14, 385, 24));
257:                cmdChooseFile.setBounds(new Rectangle(481, 14, 42, 24));
258:                cmdChooseFile.setText("...");
259:                cmdChooseFile.setRequestFocusEnabled(true);
260:                cmdChooseFile.addActionListener(new ActionListener() {
261:                    public void actionPerformed(ActionEvent e) {
262:                        JFileChooser chooser = new JFileChooser();
263:                        chooser.setAcceptAllFileFilterUsed(false);
264:
265:                        chooser
266:                                .setFileFilter(new javax.swing.filechooser.FileFilter() {
267:                                    public boolean accept(File file) {
268:                                        return file.isDirectory()
269:                                                || file.toString()
270:                                                        .toLowerCase()
271:                                                        .endsWith(".java");
272:                                    }
273:
274:                                    public String getDescription() {
275:                                        return "Java source files";
276:                                    }
277:                                });
278:                        int returnVal = chooser.showOpenDialog(TestbedUI.this );
279:                        if (returnVal == JFileChooser.APPROVE_OPTION)
280:                            txtFilename.setText(chooser.getSelectedFile()
281:                                    .toString());
282:
283:                    }
284:                });
285:                trParserEvents.setBorder(BorderFactory.createEtchedBorder());
286:                trParserEvents.setBounds(new Rectangle(20, 80, 255, 397));
287:                trParserEvents.setScrollsOnExpand(true);
288:                lblEventsReceived.setRequestFocusEnabled(true);
289:                lblEventsReceived.setText("Events Received");
290:                jPanel1.setBounds(new Rectangle(286, 80, 234, 185));
291:                jPanel1.setLayout(null);
292:                jPanel1.setBorder(BorderFactory
293:                        .createTitledBorder("Token Details"));
294:                lblValue.setText("Value");
295:                lblValue.setBounds(new Rectangle(14, 20, 82, 15));
296:                txtValue.setText("");
297:                txtValue.setBounds(new Rectangle(108, 17, 115, 20));
298:                jLabel2.setText("Length");
299:                jLabel2.setBounds(new Rectangle(14, 47, 82, 15));
300:                txtLength.setText("");
301:                txtLength.setBounds(new Rectangle(108, 44, 115, 20));
302:                jLabel3.setText("Line");
303:                jLabel3.setBounds(new Rectangle(14, 75, 82, 15));
304:                txtLine.setText("");
305:                txtLine.setBounds(new Rectangle(108, 72, 115, 20));
306:                jLabel4.setText("Column");
307:                jLabel4.setBounds(new Rectangle(14, 102, 82, 15));
308:                txtColumn.setText("");
309:                txtColumn.setBounds(new Rectangle(108, 99, 115, 20));
310:                jLabel5.setText("Position");
311:                jLabel5.setBounds(new Rectangle(14, 130, 82, 15));
312:                txtPosition.setText("");
313:                txtPosition.setBounds(new Rectangle(108, 127, 115, 20));
314:                jLabel6.setText("Language");
315:                jLabel6.setBounds(new Rectangle(14, 157, 82, 15));
316:                txtLanguage.setText("");
317:                txtLanguage.setBounds(new Rectangle(108, 154, 115, 20));
318:                jLabel13.setText("Length");
319:                jLabel13.setBounds(new Rectangle(13, 102, 82, 15));
320:                jPanel3.setLayout(null);
321:                jPanel3.setBounds(new Rectangle(286, 268, 234, 282));
322:                jPanel3.setBorder(BorderFactory.createCompoundBorder(
323:                        BorderFactory.createTitledBorder("Comment Details"),
324:                        BorderFactory.createEmptyBorder(5, 5, 5, 5)));
325:                txtLength1.setText("");
326:                txtLength1.setBounds(new Rectangle(106, 99, 116, 20));
327:                jLabel15.setRequestFocusEnabled(true);
328:                jLabel15.setText("Description");
329:                jLabel15.setBounds(new Rectangle(13, 125, 85, 15));
330:                txtDescription.setText("");
331:                txtDescription.setTabSize(8);
332:                txtDescription.setBounds(new Rectangle(10, 145, 213, 44));
333:
334:                commentDesc = new JScrollPane(txtDescription);
335:                commentDesc.setBounds(new Rectangle(10, 145, 213, 126));
336:                commentDesc.setPreferredSize(new Dimension(400, 500));
337:                commentDesc.setVisible(true);
338:
339:                lstFilteredStates.setBorder(BorderFactory.createEtchedBorder());
340:                lstFilteredStates.setBounds(new Rectangle(19, 574, 256, 95));
341:                lstFilteredTokens.setBorder(BorderFactory.createEtchedBorder());
342:                lstFilteredTokens.setBounds(new Rectangle(284, 574, 235, 95));
343:                cmdParse.setBounds(new Rectangle(204, 675, 150, 25));
344:                cmdParse.setText("Parse");
345:                cmdClose.setBounds(new Rectangle(369, 675, 150, 25));
346:                cmdClose.setText("Close");
347:                cmdClose.setDefaultCapable(true);
348:                jLabel18.setRequestFocusEnabled(true);
349:                jLabel18.setText("Filtered States");
350:                jLabel18.setBounds(new Rectangle(19, 555, 116, 15));
351:                jLabel19.setBounds(new Rectangle(284, 555, 123, 15));
352:                jLabel19.setText("Filtered Tokens");
353:                jLabel14.setText("Column");
354:                jLabel14.setBounds(new Rectangle(13, 47, 82, 15));
355:                txtPosition1.setText("");
356:                txtPosition1.setBounds(new Rectangle(106, 72, 116, 20));
357:                txtLine1.setText("");
358:                txtLine1.setBounds(new Rectangle(106, 17, 116, 20));
359:                txtColumn1.setText("");
360:                txtColumn1.setBounds(new Rectangle(106, 44, 116, 20));
361:                jLabel16.setText("Line");
362:                jLabel16.setBounds(new Rectangle(13, 20, 82, 15));
363:                jLabel17.setText("Position");
364:                jLabel17.setBounds(new Rectangle(13, 75, 82, 15));
365:
366:                treeView = new JScrollPane(trParserEvents);
367:                treeView.setBounds(new Rectangle(20, 80, 255, 470));
368:                treeView.setPreferredSize(new Dimension(400, 500));
369:                treeView.setVisible(true);
370:
371:                this .getContentPane().add(lblFilename, null);
372:                this .getContentPane().add(txtFilename, null);
373:                this .getContentPane().add(cmdChooseFile, null);
374:                this .getContentPane().add(treeView);
375:                this .getContentPane().add(lblEventsReceived, null);
376:
377:                txtValue.setEditable(false);
378:                txtLength.setEditable(false);
379:                txtLine.setEditable(false);
380:                txtColumn.setEditable(false);
381:                txtPosition.setEditable(false);
382:                txtLanguage.setEditable(false);
383:                txtDescription.setEditable(false);
384:                txtLine1.setEditable(false);
385:                txtColumn1.setEditable(false);
386:                txtPosition1.setEditable(false);
387:                txtLength1.setEditable(false);
388:
389:                txtValue.setHorizontalAlignment(JTextField.CENTER);
390:                txtLength.setHorizontalAlignment(JTextField.CENTER);
391:                txtLine.setHorizontalAlignment(JTextField.CENTER);
392:                txtColumn.setHorizontalAlignment(JTextField.CENTER);
393:                txtPosition.setHorizontalAlignment(JTextField.CENTER);
394:                txtLanguage.setHorizontalAlignment(JTextField.CENTER);
395:                txtLine1.setHorizontalAlignment(JTextField.CENTER);
396:                txtColumn1.setHorizontalAlignment(JTextField.CENTER);
397:                txtPosition1.setHorizontalAlignment(JTextField.CENTER);
398:                txtLength1.setHorizontalAlignment(JTextField.CENTER);
399:
400:                txtValue.setFont(new Font("Verdana", Font.BOLD, 11));
401:                txtLength.setFont(new Font("Verdana", Font.BOLD, 11));
402:                txtLine.setFont(new Font("Verdana", Font.BOLD, 11));
403:                txtColumn.setFont(new Font("Verdana", Font.BOLD, 11));
404:                txtPosition.setFont(new Font("Verdana", Font.BOLD, 11));
405:                txtLanguage.setFont(new Font("Verdana", Font.BOLD, 11));
406:                txtLine1.setFont(new Font("Verdana", Font.BOLD, 11));
407:                txtColumn1.setFont(new Font("Verdana", Font.BOLD, 11));
408:                txtPosition1.setFont(new Font("Verdana", Font.BOLD, 11));
409:                txtLength1.setFont(new Font("Verdana", Font.BOLD, 11));
410:
411:                jPanel1.add(jLabel3, null);
412:                jPanel1.add(txtLine, null);
413:                jPanel1.add(jLabel4, null);
414:                jPanel1.add(txtColumn, null);
415:                jPanel1.add(jLabel5, null);
416:                jPanel1.add(txtPosition, null);
417:                jPanel1.add(jLabel6, null);
418:                jPanel1.add(txtLanguage, null);
419:                jPanel1.add(lblValue, null);
420:                jPanel1.add(txtLength, null);
421:                jPanel1.add(jLabel2, null);
422:                jPanel1.add(txtValue, null);
423:                this .getContentPane().add(cmdParse, null);
424:                this .getContentPane().add(cmdClose, null);
425:                this .getContentPane().add(lstFilteredStates, null);
426:                this .getContentPane().add(jLabel18, null);
427:                this .getContentPane().add(jLabel19, null);
428:                this .getContentPane().add(lstFilteredTokens, null);
429:                this .getContentPane().add(jPanel3, null);
430:                jPanel3.add(commentDesc, null);
431:                this .getContentPane().add(jPanel1, null);
432:                jPanel3.add(txtLength1, null);
433:                jPanel3.add(txtPosition1, null);
434:                jPanel3.add(txtColumn1, null);
435:                jPanel3.add(txtLine1, null);
436:                jPanel3.add(jLabel14, null);
437:                jPanel3.add(jLabel17, null);
438:                jPanel3.add(jLabel13, null);
439:                jPanel3.add(jLabel16, null);
440:                jPanel3.add(jLabel15, null);
441:
442:                setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
443:                setModal(true);
444:                setResizable(false);
445:
446:                ((DefaultTreeModel) trParserEvents.getModel()).setRoot(null);
447:
448:                cmdParse.addActionListener(new ActionListener() {
449:                    public void actionPerformed(ActionEvent e) {
450:                        parseFile();
451:                    }
452:                });
453:
454:                cmdClose.addActionListener(new ActionListener() {
455:                    public void actionPerformed(ActionEvent arg0) {
456:                        dispose();
457:                    }
458:                });
459:
460:                trParserEvents
461:                        .addTreeSelectionListener(new TreeSelectionListener() {
462:                            public void valueChanged(TreeSelectionEvent e) {
463:                                treeSelectionChanged(e);
464:                            }
465:                        });
466:
467:                constructPopups();
468:                getRootPane().setDefaultButton(cmdChooseFile);
469:
470:                setTitle("Parsing Framework Testbed");
471:                pack();
472:            }
473:
474:            protected void filterState() {
475:                TreeNode sel = getSelectedTreeNode();
476:                if (sel != null) {
477:                    ((DefaultListModel) lstFilteredStates.getModel())
478:                            .addElement(sel.toString());
479:                }
480:            }
481:
482:            protected void filterToken() {
483:                TreeNode sel = getSelectedTreeNode();
484:                if (sel != null) {
485:                    ((DefaultListModel) lstFilteredTokens.getModel())
486:                            .addElement(sel.toString());
487:                }
488:            }
489:
490:            // If expand is true, expands all nodes in the tree.
491:            // Otherwise, collapses all nodes in the tree.
492:            protected void expandAll(JTree tree, boolean expand) {
493:                TreeNode root = (TreeNode) tree.getModel().getRoot();
494:
495:                // Traverse tree from root
496:                expandAll(tree, new TreePath(root), expand);
497:            }
498:
499:            private void expandAll(JTree tree, TreePath parent, boolean expand) {
500:                // Traverse children
501:                TreeNode node = (TreeNode) parent.getLastPathComponent();
502:                if (node.getChildCount() >= 0) {
503:                    for (Enumeration e = node.children(); e.hasMoreElements();) {
504:                        TreeNode n = (TreeNode) e.nextElement();
505:                        TreePath path = parent.pathByAddingChild(n);
506:                        expandAll(tree, path, expand);
507:                    }
508:                }
509:
510:                // Expansion or collapse must be done bottom-up
511:                if (expand) {
512:                    tree.expandPath(parent);
513:                } else {
514:                    tree.collapsePath(parent);
515:                }
516:            }
517:
518:            protected void expandAll() {
519:                expandAll(trParserEvents, true);
520:            }
521:
522:            protected void collapseAll() {
523:                expandAll(trParserEvents, false);
524:            }
525:
526:            protected void expandTreeNode(TreeNode node) {
527:                TreePath sel = trParserEvents.getSelectionPath();
528:                if (node != null)
529:                    sel = new TreePath(node);
530:
531:                if (sel != null)
532:                    trParserEvents.expandPath(sel);
533:            }
534:
535:            protected void collapseTreeNode() {
536:                TreePath sel = trParserEvents.getSelectionPath();
537:                if (sel != null)
538:                    trParserEvents.collapsePath(sel);
539:            }
540:
541:            protected void showNextError() {
542:
543:            }
544:
545:            protected void showAllErrors() {
546:
547:            }
548:
549:            private void constructPopups() {
550:                stateMenu = new JPopupMenu();
551:                JMenuItem menuItem = new JMenuItem("Filter State");
552:                menuItem.addActionListener(new ActionListener() {
553:                    public void actionPerformed(ActionEvent e) {
554:                        filterState();
555:                    }
556:                });
557:                stateMenu.add(menuItem);
558:
559:                stateMenu.add(new JSeparator());
560:
561:                menuItem = new JMenuItem("Expand All");
562:                menuItem.addActionListener(new ActionListener() {
563:                    public void actionPerformed(ActionEvent e) {
564:                        expandAll();
565:                    }
566:                });
567:                stateMenu.add(menuItem);
568:
569:                menuItem = new JMenuItem("Collapse All");
570:                menuItem.addActionListener(new ActionListener() {
571:                    public void actionPerformed(ActionEvent e) {
572:                        collapseAll();
573:                    }
574:                });
575:                stateMenu.add(menuItem);
576:
577:                stateMenu.add(new JSeparator());
578:
579:                menuItem = new JMenuItem("Expand");
580:                menuItem.addActionListener(new ActionListener() {
581:                    public void actionPerformed(ActionEvent e) {
582:                        expandTreeNode(null);
583:                    }
584:                });
585:                stateMenu.add(menuItem);
586:
587:                menuItem = new JMenuItem("Collapse");
588:                menuItem.addActionListener(new ActionListener() {
589:                    public void actionPerformed(ActionEvent e) {
590:                        collapseTreeNode();
591:                    }
592:                });
593:                stateMenu.add(menuItem);
594:
595:                //        stateMenu.add(new JSeparator());
596:                //        
597:                //
598:                //        menuItem = new JMenuItem("Show Next Error");
599:                //        menuItem.addActionListener(new ActionListener()
600:                //        {
601:                //            public void actionPerformed(ActionEvent e)
602:                //            {
603:                //                showNextError();
604:                //            }
605:                //        });
606:                //        stateMenu.add(menuItem);
607:                //        
608:                //        menuItem = new JMenuItem("Show All Errors");
609:                //        menuItem.addActionListener(new ActionListener()
610:                //                {
611:                //            public void actionPerformed(ActionEvent e)
612:                //            {
613:                //                showAllErrors();
614:                //            }
615:                //        });
616:                //        stateMenu.add(menuItem);
617:
618:                tokenMenu = new JPopupMenu();
619:                menuItem = new JMenuItem("Filter Token");
620:                menuItem.addActionListener(new ActionListener() {
621:                    public void actionPerformed(ActionEvent e) {
622:                        filterToken();
623:                    }
624:                });
625:                tokenMenu.add(menuItem);
626:
627:                //        tokenMenu.add(new JSeparator());
628:                //
629:                //        menuItem = new JMenuItem("Show Next Error");
630:                //        menuItem.addActionListener(new ActionListener()
631:                //        {
632:                //            public void actionPerformed(ActionEvent e)
633:                //            {
634:                //                showNextError();
635:                //            }
636:                //        });
637:                //        tokenMenu.add(menuItem);
638:                //        
639:                //        menuItem = new JMenuItem("Show All Errors");
640:                //        menuItem.addActionListener(new ActionListener()
641:                //        {
642:                //            public void actionPerformed(ActionEvent e)
643:                //            {
644:                //                showAllErrors();
645:                //            }
646:                //        });
647:                //        tokenMenu.add(menuItem);
648:
649:                // Add listener to components that can bring up popup menus.
650:                MouseListener popupListener = new MouseAdapter() {
651:
652:                    public void mousePressed(MouseEvent e) {
653:                        maybeShowPopup(e);
654:                    }
655:
656:                    public void mouseReleased(MouseEvent e) {
657:                        maybeShowPopup(e);
658:                    }
659:
660:                    private void maybeShowPopup(MouseEvent e) {
661:                        if (e.isPopupTrigger()) {
662:                            TreeNode node = getSelectedTreeNode();
663:                            if (node != null
664:                                    && !(node instanceof  ErrorNode)
665:                                    && !"Compilation Unit".equals(node
666:                                            .toString()))
667:                                if (tokenMap.containsKey(node))
668:                                    tokenMenu.show(e.getComponent(), e.getX(),
669:                                            e.getY());
670:                                else
671:                                    stateMenu.show(e.getComponent(), e.getX(),
672:                                            e.getY());
673:                            else if (node != null
674:                                    && "Compilation Unit".equals(node
675:                                            .toString())) {
676:                                if (compUnitMenu == null) {
677:                                    compUnitMenu = new JPopupMenu();
678:                                    JMenuItem menuItem = new JMenuItem(
679:                                            "Expand All");
680:                                    menuItem
681:                                            .addActionListener(new ActionListener() {
682:                                                public void actionPerformed(
683:                                                        ActionEvent e) {
684:                                                    expandAll();
685:                                                }
686:                                            });
687:                                    compUnitMenu.add(menuItem);
688:
689:                                    menuItem = new JMenuItem("Collapse All");
690:                                    menuItem
691:                                            .addActionListener(new ActionListener() {
692:                                                public void actionPerformed(
693:                                                        ActionEvent e) {
694:                                                    collapseAll();
695:                                                }
696:                                            });
697:                                    compUnitMenu.add(menuItem);
698:
699:                                    compUnitMenu.add(new JSeparator());
700:
701:                                    menuItem = new JMenuItem("Expand");
702:                                    menuItem
703:                                            .addActionListener(new ActionListener() {
704:                                                public void actionPerformed(
705:                                                        ActionEvent e) {
706:                                                    expandTreeNode(null);
707:                                                }
708:                                            });
709:                                    compUnitMenu.add(menuItem);
710:
711:                                    menuItem = new JMenuItem("Collapse");
712:                                    menuItem
713:                                            .addActionListener(new ActionListener() {
714:                                                public void actionPerformed(
715:                                                        ActionEvent e) {
716:                                                    collapseTreeNode();
717:                                                }
718:                                            });
719:                                    compUnitMenu.add(menuItem);
720:                                }
721:                                compUnitMenu.show(e.getComponent(), e.getX(), e
722:                                        .getY());
723:                            }
724:                        }
725:                    }
726:                };
727:                trParserEvents.addMouseListener(popupListener);
728:
729:                KeyListener kl = new KeyAdapter() {
730:                    public void keyReleased(KeyEvent e) {
731:                        if (e.getKeyCode() == KeyEvent.VK_DELETE) {
732:                            JList list = (JList) e.getSource();
733:                            int sel = list.getSelectedIndex();
734:                            if (sel != -1)
735:                                ((DefaultListModel) list.getModel())
736:                                        .remove(sel);
737:                        }
738:                    }
739:                };
740:
741:                lstFilteredStates.addKeyListener(kl);
742:                lstFilteredTokens.addKeyListener(kl);
743:
744:            }
745:
746:            private void setRenderer() {
747:                URL tokenURL = getClass().getResource("token.gif");
748:                URL stateURL = getClass().getResource("state.gif");
749:                URL errorURL = getClass().getResource("error.gif");
750:                ImageIcon tokenIcon = new ImageIcon(tokenURL);
751:                ImageIcon stateIcon = new ImageIcon(stateURL);
752:                ImageIcon errorIcon = new ImageIcon(errorURL);
753:                if ((tokenIcon != null && stateIcon != null)
754:                        || errorIcon != null) {
755:                    DefaultTreeCellRenderer renderer = new DefaultTreeCellRenderer();
756:                    renderer.setLeafIcon(errorsExist ? errorIcon : tokenIcon);
757:                    renderer.setFont(new Font("Arial", Font.BOLD, 11));
758:                    renderer.setOpenIcon(errorsExist ? errorIcon : stateIcon);
759:                    renderer.setClosedIcon(errorsExist ? errorIcon : stateIcon);
760:                    trParserEvents.setCellRenderer(renderer);
761:                }
762:            }
763:
764:            /* (non-Javadoc)
765:             * @see java.awt.Dialog#dispose()
766:             */
767:            public void dispose() {
768:                super .dispose();
769:                System.exit(0);
770:            }
771:
772:            public void addToken(TreeNode node, ITokenDescriptor token,
773:                    String language) {
774:                tokenMap.put(node, new ETPairT<ITokenDescriptor, String>(token,
775:                        language));
776:            }
777:
778:            public static void main(String[] args) {
779:                CoreProduct product = new CoreProduct();
780:                CoreProductManager.instance().setCoreProduct(product);
781:                ICoreProduct prod = CoreProductManager.instance()
782:                        .getCoreProduct();
783:                prod.initialize();
784:
785:                try {
786:                    UIManager
787:                            .setLookAndFeel("com.sun.java.swing.plaf.windows.WindowsLookAndFeel");
788:                } catch (Exception e) {
789:                }
790:
791:                new TestbedUI().setVisible(true);
792:            }
793:
794:            public TestbedUI() throws HeadlessException {
795:                try {
796:                    jbInit();
797:                    this .setSize(550, 730);
798:                } catch (Exception e) {
799:                    e.printStackTrace();
800:                }
801:            }
802:
803:            public void errorsFound(boolean err) {
804:                errorsExist = err;
805:            }
806:
807:            private static class ErrorNode extends DefaultMutableTreeNode {
808:                public ErrorNode(String text) {
809:                    super (text);
810:                }
811:            }
812:
813:            private Map<TreeNode, ETPairT<ITokenDescriptor, String>> tokenMap = new HashMap<TreeNode, ETPairT<ITokenDescriptor, String>>();
814:
815:            private TreeNode lastNode;
816:
817:            /**
818:             * This is the filename JLabel
819:             */
820:            private JLabel lblFilename = new JLabel();
821:
822:            private JTextField txtFilename = new JTextField();
823:            private JButton cmdChooseFile = new JButton();
824:            private JTree trParserEvents = new JTree();
825:            private JLabel lblEventsReceived = new JLabel();
826:            private JPanel jPanel1 = new JPanel();
827:            private JLabel lblValue = new JLabel();
828:            private JTextField txtValue = new JTextField();
829:            private JLabel jLabel2 = new JLabel();
830:            private JTextField txtLength = new JTextField();
831:            private JLabel jLabel3 = new JLabel();
832:            private JTextField txtLine = new JTextField();
833:            private JLabel jLabel4 = new JLabel();
834:            private JTextField txtColumn = new JTextField();
835:            private JLabel jLabel5 = new JLabel();
836:            private JTextField txtPosition = new JTextField();
837:            private JLabel jLabel6 = new JLabel();
838:            private JTextField txtLanguage = new JTextField();
839:            private JTextField jTextField7 = new JTextField();
840:            private JLabel jLabel7 = new JLabel();
841:            private JLabel jLabel8 = new JLabel();
842:            private JTextField jTextField8 = new JTextField();
843:            private JLabel jLabel9 = new JLabel();
844:            private JLabel jLabel10 = new JLabel();
845:            private JLabel jLabel11 = new JLabel();
846:            private JTextField jTextField9 = new JTextField();
847:            private JTextField jTextField10 = new JTextField();
848:            private JTextField jTextField11 = new JTextField();
849:            private JTextField jTextField12 = new JTextField();
850:            private JLabel jLabel12 = new JLabel();
851:            private JLabel jLabel13 = new JLabel();
852:            private JPanel jPanel3 = new JPanel();
853:            private JTextField txtLength1 = new JTextField();
854:            private JLabel jLabel15 = new JLabel();
855:            private JTextArea txtDescription = new JTextArea();
856:            private JList lstFilteredStates = new JList(new DefaultListModel());
857:            private JList lstFilteredTokens = new JList(new DefaultListModel());
858:            private JButton cmdParse = new JButton();
859:            private JButton cmdClose = new JButton();
860:            private JLabel jLabel18 = new JLabel();
861:            private JLabel jLabel19 = new JLabel();
862:            private JLabel jLabel14 = new JLabel();
863:            private JTextField txtPosition1 = new JTextField();
864:            private JTextField txtLine1 = new JTextField();
865:            private JTextField txtColumn1 = new JTextField();
866:            private JLabel jLabel16 = new JLabel();
867:            private JLabel jLabel17 = new JLabel();
868:
869:            private boolean errorsExist = false;
870:
871:            private JPopupMenu stateMenu, tokenMenu, compUnitMenu;
872:
873:            JScrollPane treeView;
874:            JScrollPane commentDesc;
875:        }
w___w_w_._java2__s._c_o_m_ | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.