Source Code Cross Referenced for GSDSettingsDialog.java in  » IDE » tIDE » tide » exttools » gsd » 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 » tIDE » tide.exttools.gsd 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        package tide.exttools.gsd;
002:
003:        import java.awt.EventQueue;
004:        import java.util.*;
005:        import snow.utils.*;
006:        import java.awt.Insets;
007:        import java.awt.event.*;
008:        import snow.utils.SysUtils;
009:        import tide.project.ProjectSettings;
010:        import java.io.File;
011:        import tide.editor.MainEditorFrame;
012:        import snow.utils.gui.*;
013:        import java.awt.BorderLayout;
014:        import javax.swing.*;
015:
016:        /** Google Singleton Detector.
017:         */
018:        public final class GSDSettingsDialog extends JDialog {
019:            private final FileField gsdPath = new FileField("", false,
020:                    "Give the gsd jar path", JFileChooser.FILES_ONLY);
021:            private final FileField yedPath = new FileField("", false,
022:                    "Give the yED jar path", JFileChooser.FILES_ONLY);
023:
024:            // private final JCheckBox applyJadToClassFilesCB = new JCheckBox("Apply jad on lib classes per default (instead of viewing bytecode)", false);
025:            public boolean dialogWasAccepted = false;
026:
027:            public final static String defaultGSDLocation = "c:/java/tools/gsd/gsd.jar";
028:            public final static String defaultYEDLocation = "C:/java/tools/yed-2.4.2.2/yed.jar";
029:            public final static String gsdHomepage = "http://code.google.com/p/google-singleton-detector/";
030:            public final static String yedHomepage = "http://www.yworks.com/en/index.html";
031:
032:            public GSDSettingsDialog(final JFrame parent,
033:                    final ProjectSettings settings) {
034:                super (parent, "Google Singleton Detector", true);
035:
036:                JComponent ta = GUIUtils
037:                        .createReadOnlyDescriptionArea("GSD is an external tool used to analyse the project singletons in a graph."
038:                                + "\nIt is available for free on "
039:                                + gsdHomepage
040:                                + "\nGSD analyses the current classes, so compile the project first (F9 or Shift+F9)."
041:                                + "\nThe resulting graphs are stored in the folder <project-home>.tide/gsd/ "
042:                                + "\nand can be viewed with the free yEd Graph Editor tool. Hint: Use the layout organic/smart."
043:                                + "\nyEd home is "
044:                                + yedHomepage
045:
046:                                + "\n\nRed: singletons, Orange: hingletons, Yellow: mingletons, Green: fingletons.");
047:                add(ta, BorderLayout.NORTH);
048:
049:                JPanel inputPanel = new JPanel();
050:                add(inputPanel, BorderLayout.CENTER);
051:                GridLayout3 gl3 = new GridLayout3(2, inputPanel);
052:
053:                JButton help = new JButton("GSD Homepage", Icons
054:                        .createHelpIcon(16, true));
055:                help.setMargin(new Insets(0, 2, 0, 2));
056:                help.setFocusPainted(false);
057:                gl3.addSeparator();
058:                gl3.add(help);
059:                gl3.addSeparator();
060:                help.addActionListener(new ActionListener() {
061:                    public void actionPerformed(ActionEvent ae) {
062:                        try {
063:                            SysUtils.openBrowser(gsdHomepage);
064:                        } catch (Exception e) {
065:                            JOptionPane.showMessageDialog(null,
066:                                    "Can't open browser for " + gsdHomepage
067:                                            + "\nerr:" + e.getMessage(),
068:                                    "Error", JOptionPane.ERROR_MESSAGE);
069:                        }
070:                    }
071:                });
072:
073:                gl3.add("GSD application");
074:                gl3.add(gsdPath);
075:                gsdPath.setPath(settings.getProperty("GSD_path",
076:                        defaultGSDLocation));
077:                gsdPath.offerRememberedGlobalCompletion(
078:                        MainEditorFrame.instance.globalProperties, "knownGSDs");
079:                gsdPath.setComponentWidth(300);
080:                gsdPath.setAutoColorized();
081:                gsdPath.allowedExtensions.add("jar");
082:                gsdPath.fileTypeDescription = "Java executables";
083:
084:                JButton helpY = new JButton("yED Homepage", Icons
085:                        .createHelpIcon(16, true));
086:                helpY.setMargin(new Insets(0, 2, 0, 2));
087:                helpY.setFocusPainted(false);
088:                gl3.addSeparator();
089:                gl3.addSeparator();
090:                gl3.add(helpY);
091:                gl3.addSeparator();
092:                helpY.addActionListener(new ActionListener() {
093:                    public void actionPerformed(ActionEvent ae) {
094:                        try {
095:                            SysUtils.openBrowser(yedHomepage);
096:                        } catch (Exception e) {
097:
098:                        }
099:                    }
100:                });
101:
102:                gl3.add("yED application");
103:                gl3.add(yedPath);
104:                yedPath.setPath(settings.getProperty("yed_path",
105:                        defaultYEDLocation));
106:                yedPath.offerRememberedGlobalCompletion(
107:                        MainEditorFrame.instance.globalProperties, "knownYEDs");
108:                yedPath.setComponentWidth(300);
109:                yedPath.setAutoColorized();
110:                yedPath.allowedExtensions.add("jar");
111:                yedPath.fileTypeDescription = "Java executables";
112:
113:                /*    gl3.addTitleSeparator("Options");
114:                 gl3.add("");
115:                 gl3.add(applyJadToClassFilesCB);
116:                 applyJadToClassFilesCB.setSelected( settings.getBooleanProperty("JAD_applyJadToClassFilesCB", false) );
117:                 */
118:
119:                gl3.addTitleSeparator("Analysis");
120:                //gl3.addExplanationArea("");
121:                JButton analyse = new JButton("Analyse current project classes");
122:                analyse.setMargin(new Insets(0, 2, 0, 2));
123:                analyse.setFocusPainted(false);
124:                gl3.add(analyse);
125:                analyse.addActionListener(new ActionListener() {
126:                    public void actionPerformed(ActionEvent ae) {
127:                        settings.setProperty("GSD_path", gsdPath.getPath()
128:                                .getAbsolutePath());
129:                        settings.setProperty("yed_path", yedPath.getPath()
130:                                .getAbsolutePath());
131:                        analyseAction();
132:                    }
133:                });
134:
135:                // todo: analyse some other jar
136:
137:                CloseControlPanel ccp = new CloseControlPanel(this , true, true,
138:                        "Ok");
139:                add(ccp, BorderLayout.SOUTH);
140:
141:                pack();
142:                this .setLocationRelativeTo(parent);
143:                this .setVisible(true); // MODAL => waits
144:
145:                if (ccp.getWasCancelled())
146:                    return;
147:                dialogWasAccepted = true;
148:
149:                // save settings
150:                settings.setProperty("GSD_path", gsdPath.getPath()
151:                        .getAbsolutePath());
152:                settings.setProperty("yed_path", yedPath.getPath()
153:                        .getAbsolutePath());
154:                //settings.setBooleanProperty("JAD_applyJadToClassFilesCB", applyJadToClassFilesCB.isSelected() );
155:
156:                gsdPath.rememberPathForGlobalCompletion(
157:                        MainEditorFrame.instance.globalProperties, "knownGSDs");
158:                yedPath.rememberPathForGlobalCompletion(
159:                        MainEditorFrame.instance.globalProperties, "knownYEDs");
160:
161:            }
162:
163:            public static void analyseAction() {
164:                if (!isConfigured()) {
165:                    JOptionPane
166:                            .showMessageDialog(
167:                                    null,
168:                                    "Please give the correct path of GSD in the settings.",
169:                                    "GSD not configured",
170:                                    JOptionPane.ERROR_MESSAGE);
171:                    return;
172:                }
173:
174:                final ProgressModalDialog pmd = ProgressModalDialog
175:                        .createStandaloneProgress("GSD Analysis");
176:                Thread t = new Thread() {
177:                    public void run() {
178:                        try {
179:                            pmd.start();
180:                            analysisT(pmd);
181:                        } finally {
182:                            pmd.closeDialog();
183:                        }
184:                    }
185:                };
186:                t.start();
187:            }
188:
189:            private static void analysisT(final ProgressModalDialog pmd) {
190:
191:                ProjectSettings actualProject = MainEditorFrame.instance
192:                        .getActualProject();
193:                try {
194:                    File gsdf = new File(actualProject.getProperty("GSD_path",
195:                            defaultGSDLocation));
196:                    final List<String> execCommand = new ArrayList<String>();
197:                    execCommand.add(actualProject.getJDK_Tool("java")
198:                            .getAbsolutePath());
199:                    execCommand.add("-Xmx1024m"); // ?? make optional ?
200:                    execCommand.add("-jar");
201:                    execCommand.add(gsdf.getAbsolutePath());
202:                    execCommand.add(actualProject.getClasses_Home()
203:                            .getAbsolutePath());
204:                    final File destFile = new File(actualProject
205:                            .getProjectSettingsFolder(), "gsd/"
206:                            + actualProject.getProjectName() + ".graphml");
207:                    execCommand.add(destFile.getAbsolutePath());
208:
209:                    ProcessBuilder pb = new ProcessBuilder(execCommand);
210:                    //pb.directory(  jarFile.getParentFile() );
211:                    Process proc = pb.start();
212:                    pmd.setProcessToOptionalKill(proc);
213:
214:                    MainEditorFrame.instance.outputPanels.processesManager
215:                            .addProcess("GSD analysis", proc, true);
216:
217:                    StreamGobbler sg = new StreamGobbler(proc.getInputStream());
218:                    // MainEditorFrame.instance.outputPanels.toolsOutputPanel.doc.createWriterForThisDocument(false),
219:                    // "ProGuard");
220:                    sg.start();
221:                    sg.setLineListener(new StringGobblerLineListener() {
222:                        public String lineToMatch() {
223:                            return null;
224:                        }
225:
226:                        public void lineMatch(String line) {
227:                        }
228:
229:                        public void lineRead(String line) {
230:                            String linet = line.trim(); // some have indent?
231:                            /*if(linet.startsWith("Reading")
232:                            || linet.startsWith("Preparing")
233:                            || linet.startsWith("Copying"))
234:                            {
235:                              pmd.setProgressComment(linet);
236:                            }
237:                            else
238:                            {*/
239:                            MainEditorFrame.instance.outputPanels.toolsOutputPanel.doc
240:                                    .appendLine("GSD> " + line);
241:                            //}
242:                        }
243:                    });
244:
245:                    // errors
246:                    StreamGobbler sge = new StreamGobbler(
247:                            proc.getErrorStream(),
248:                            MainEditorFrame.instance.outputPanels.toolsOutputPanel.doc
249:                                    .createWriterForThisDocument(true), "GSD");
250:                    sge.start();
251:
252:                    MainEditorFrame.instance.outputPanels.selectToolsTab(true);
253:
254:                    // wait until proc completed...
255:                    proc.waitFor();
256:                    sg.join();
257:                    sge.join();
258:
259:                    // launch !
260:
261:                    File yedf = new File(actualProject.getProperty("yed_path",
262:                            defaultYEDLocation));
263:                    if (yedf.exists()) {
264:                        execCommand.clear();
265:                        execCommand.add(actualProject.getJDK_Tool("java")
266:                                .getAbsolutePath());
267:                        execCommand.add("-Xmx1024m"); // ?? make optional ?
268:                        execCommand.add("-jar");
269:                        execCommand.add(yedf.getAbsolutePath());
270:                        execCommand.add(destFile.getAbsolutePath());
271:                        pb = new ProcessBuilder(execCommand);
272:                        //pb.directory(  jarFile.getParentFile() );
273:                        proc = pb.start();
274:                        pmd.setProcessToOptionalKill(proc);
275:
276:                        MainEditorFrame.instance.outputPanels.processesManager
277:                                .addProcess("yED viewer", proc, true);
278:                        ProcessUtils.drainProcess(proc, false);
279:                    } else {
280:                        EventQueue.invokeLater(new Runnable() {
281:                            public void run() {
282:                                JOptionPane
283:                                        .showMessageDialog(
284:                                                MainEditorFrame.instance,
285:                                                "You don't specified a valid yED path."
286:                                                        + "\nPlease download and install yED or browse the result"
287:                                                        + "\nin another way:\n   "
288:                                                        + destFile, "No yED",
289:                                                JOptionPane.WARNING_MESSAGE);
290:                            }
291:                        });
292:
293:                    }
294:
295:                } catch (Exception e) {
296:                    e.printStackTrace();
297:                    MainEditorFrame.instance.outputPanels.toolsOutputPanel.doc
298:                            .appendErrorLine("\nGSD Launch Error: "
299:                                    + e.getMessage());
300:
301:                }
302:            }
303:
304:            /** @return true if Lint4j path is present.
305:              Used to detect if a setup dialog should be shown when starting the tool (if not found).
306:             */
307:            public static boolean isConfigured() {
308:                ProjectSettings actualProject = MainEditorFrame.instance
309:                        .getActualProject();
310:                return new File(actualProject.getProperty("GSD_path",
311:                        defaultGSDLocation)).exists();
312:            }
313:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.