Source Code Cross Referenced for PatternMechanismUI.java in  » Testing » KeY » de » uka » ilkd » key » casetool » patternimplementor » 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 » Testing » KeY » de.uka.ilkd.key.casetool.patternimplementor 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        // This file is part of KeY - Integrated Deductive Software Design
002:        // Copyright (C) 2001-2007 Universitaet Karlsruhe, Germany
003:        //                         Universitaet Koblenz-Landau, Germany
004:        //                         Chalmers University of Technology, Sweden
005:        //
006:        // The KeY system is protected by the GNU General Public License. 
007:        // See LICENSE.TXT for details.
008:        //
009:        //
010:
011:        package de.uka.ilkd.key.casetool.patternimplementor;
012:
013:        import java.awt.BorderLayout;
014:        import java.awt.Dimension;
015:        import java.awt.FlowLayout;
016:        import java.awt.event.ActionEvent;
017:        import java.awt.event.ActionListener;
018:        import java.util.Enumeration;
019:        import java.util.Observable;
020:        import java.util.Observer;
021:
022:        import javax.swing.*;
023:        import javax.swing.tree.DefaultMutableTreeNode;
024:        import javax.swing.tree.TreePath;
025:
026:        public class PatternMechanismUI implements  ActionListener, Observer {
027:
028:            private static final String OK = "Ok";
029:
030:            private static final String PREVIEW = "Preview";
031:
032:            private static final String CANCEL = "Cancel";
033:
034:            PatternMechanism pm;
035:
036:            // the main window, all parts except buttonPanel should be in scrollpanes
037:            JDialog mainDialog;
038:
039:            // the ui of the pattern
040:            JPanel patternPanel;
041:
042:            // a tree where it's possible to select which pattern to use
043:            JTree patternSelectorTree;
044:
045:            // apply, cancel, preview
046:            JPanel buttonPanel;
047:
048:            // the buttons in the buttonPanel
049:            JButton okButton;
050:
051:            JButton previewButton;
052:
053:            JButton cancelButton;
054:
055:            // shows information about the pattern
056:            JComponent infoPanel;
057:
058:            public PatternMechanismUI(PatternMechanism pm) {
059:                setPatternMechanism(pm);
060:                buildUI();
061:            }
062:
063:            public void setPatternMechanism(PatternMechanism pm) {
064:                this .pm = pm;
065:                pm.addObserver(this );
066:            }
067:
068:            private void buildUI() {
069:                //System.out.println("buildUI");
070:                if (mainDialog == null) {
071:                    patternSelectorTree = buildTree();
072:
073:                    buttonPanel = new JPanel();
074:                    buttonPanel.setLayout(new FlowLayout());
075:
076:                    okButton = new JButton(OK);
077:                    previewButton = new JButton(PREVIEW);
078:                    cancelButton = new JButton(CANCEL);
079:                    okButton.addActionListener(this );
080:                    previewButton.addActionListener(this );
081:                    cancelButton.addActionListener(this );
082:
083:                    buttonPanel.add(previewButton);
084:                    buttonPanel.add(okButton);
085:                    buttonPanel.add(cancelButton);
086:
087:                    mainDialog = new JDialog(new JFrame(),
088:                            "KeY Pattern Mechanism", true);
089:
090:                    mainDialog.setSize(new Dimension(700, 500));
091:
092:                    /*
093:                     * mainWindowDialog = new JDialog(new JFrame(), true);
094:                     * mainWindowDialog.getContentPane().add(mainFrame);
095:                     * mainWindowDialog.setVisible(true);
096:                     */
097:                }
098:
099:                mainDialog.getContentPane().removeAll();
100:                mainDialog.getContentPane().setLayout(new BorderLayout());
101:                mainDialog.getContentPane()
102:                        .add(new JScrollPane(patternSelectorTree),
103:                                BorderLayout.WEST);
104:                mainDialog.getContentPane()
105:                        .add(buttonPanel, BorderLayout.SOUTH);
106:
107:                mainDialog.getContentPane().add(new JScrollPane(centerPanel()),
108:                        BorderLayout.CENTER);
109:
110:                //mainFrame.pack();
111:                mainDialog.setVisible(true);
112:            }
113:
114:            public void update(Observable o, Object arg) {
115:                //System.out.println("PMUI.update");
116:                buildUI();
117:            }
118:
119:            private JPanel centerPanel() {
120:                JPanel center = new JPanel();
121:
122:                try {
123:                    patternPanel = new PIParameterGUIGroup(pm.getParameters());
124:                    center.setLayout(new BorderLayout());
125:                    center.add(patternPanel, BorderLayout.WEST);
126:                    infoPanel = new JTextArea(pm.getImplementation().toString());
127:                    ((JTextArea) infoPanel).setEditable(false);
128:                    center.add(infoPanel, BorderLayout.SOUTH);
129:                } catch (Exception e) {
130:                    e.printStackTrace();
131:
132:                    JLabel label = new JLabel("No Patterns found");
133:                    center.add(label);
134:                }
135:
136:                return center;
137:            }
138:
139:            /**
140:             * /-------------------------\ | pS-tree | patternPanel | | | | | | | |
141:             * +---------------| | | infoPanel | | | | |-------------------------| |
142:             * buttonPanel | | [Preview][Ok][Cancel] | \-------------------------/
143:             */
144:            public void actionPerformed(ActionEvent e) {
145:                if (OK.equals(e.getActionCommand())) {
146:                    //System.out.println("Button pressed: " + OK);
147:                    //System.out.println(pm.getImplementation());
148:                    PIParameterGroup pg = pm.getParameters();
149:                    String[] constraint = new String[pg.size()];
150:                    for (int i = 0; i < constraint.length; i++) {
151:                        constraint[i] = pg.getValue(i);
152:                        //System.out.println("constraint[" + i + "] = " + constraint[i]);
153:                    }
154:                    mainDialog.dispose();
155:
156:                    //pm.setPattern(pm.getPatterns()[1]);
157:                } else if (PREVIEW.equals(e.getActionCommand())) {
158:                    //System.out.println("Button pressed: " + PREVIEW);
159:
160:                    //infoPanel.setVisible(false);
161:                    ((JTextArea) infoPanel).setText(pm.getImplementation()
162:                            .toString());
163:
164:                    //((JTextArea)infoPanel).setEditable(false);
165:                    //infoPanel.setVisible(true);
166:                } else if (CANCEL.equals(e.getActionCommand())) {
167:                    //System.out.println("Button pressed: " + CANCEL);
168:                    //System.out.println("Remove this exit feature");
169:                    //System.exit(0);
170:                    this .pm.cancel();
171:                    mainDialog.dispose();
172:                }
173:            }
174:
175:            private JTree buildTree() {
176:                //pm.getPatterns();
177:                DefaultMutableTreeNode root = new DefaultMutableTreeNode(
178:                        "Design patterns");
179:
180:                //DefaultMutableTreeNode selected;
181:                TreePath actualPath = new TreePath(root);
182:
183:                for (int i = 0; i < pm.getPatterns().length; i++) {
184:                    PMTreeNode node = new PMTreeNode(pm.getPatterns()[i]);
185:
186:                    //node.addTreeSelectionListener(pm);
187:                    String path = node.getpmPath();
188:                    DefaultMutableTreeNode lastNode = root;
189:
190:                    while (path.indexOf(':') != -1) {
191:                        //System.out.println("path " + path);
192:                        DefaultMutableTreeNode tmpnode = new DefaultMutableTreeNode(
193:                                path.substring(0, path.indexOf(':')));
194:                        path = path.substring(path.indexOf(':') + 1, path
195:                                .length());
196:
197:                        /*
198:                         * System.err.println("lastNode.getIndex(tmpnode) = " +
199:                         * lastNode.getIndex(tmpnode));
200:                         */
201:                        for (Enumeration e = lastNode.children(); e
202:                                .hasMoreElements();) {
203:                            DefaultMutableTreeNode child = (DefaultMutableTreeNode) e
204:                                    .nextElement();
205:
206:                            if (child.toString().equals(tmpnode.toString())) {
207:                                tmpnode = child;
208:                            }
209:                        }
210:
211:                        lastNode.add(tmpnode);
212:                        lastNode = tmpnode;
213:
214:                        if (i == 0) {
215:                            actualPath = actualPath.pathByAddingChild(lastNode);
216:                        }
217:                    }
218:
219:                    lastNode.add(node);
220:
221:                    if (i == 0) {
222:                        actualPath = actualPath.pathByAddingChild(node);
223:                    }
224:                }
225:
226:                JTree tree = new JTree(root);
227:                tree.setVisible(false);
228:
229:                //System.out.println(actualPath);
230:                //System.out.println("trying to set the path");
231:                //System.out.println("old : " + tree.getSelectionPath());
232:                tree.setSelectionPath(actualPath);
233:
234:                //System.out.println("new : " + tree.getSelectionPath());
235:                tree.setExpandsSelectedPaths(true);
236:
237:                tree.setRootVisible(true);
238:                tree.setVisible(true);
239:
240:                tree.addTreeSelectionListener(pm);
241:
242:                return tree;
243:            }
244:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.