KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > jeantessier > dependencyfinder > gui > DependencyFinder


1 /*
2  * Copyright (c) 2001-2005, Jean Tessier
3  * All rights reserved.
4  *
5  * Redistribution and use in source and binary forms, with or without
6  * modification, are permitted provided that the following conditions
7  * are met:
8  *
9  * * Redistributions of source code must retain the above copyright
10  * notice, this list of conditions and the following disclaimer.
11  *
12  * * Redistributions in binary form must reproduce the above copyright
13  * notice, this list of conditions and the following disclaimer in the
14  * documentation and/or other materials provided with the distribution.
15  *
16  * * Neither the name of Jean Tessier nor the names of his contributors
17  * may be used to endorse or promote products derived from this software
18  * without specific prior written permission.
19  *
20  * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
21  * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
22  * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
23  * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
24  * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
25  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
26  * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
27  * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
28  * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
29  * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
30  * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
31  */

32
33 package com.jeantessier.dependencyfinder.gui;
34
35 import java.awt.*;
36 import java.awt.event.*;
37 import java.io.*;
38 import java.util.*;
39
40 import javax.swing.*;
41 import javax.swing.border.*;
42
43 import org.apache.log4j.*;
44
45 import org.xml.sax.*;
46
47 import com.jeantessier.classreader.*;
48 import com.jeantessier.commandline.*;
49 import com.jeantessier.dependency.*;
50
51 public class DependencyFinder extends JFrame {
52     private boolean minimize;
53     private boolean maximize;
54
55     private boolean advancedMode;
56     private JPanel queryPanel = new JPanel();
57     
58     private JMenuBar menuBar = new JMenuBar();
59     private JMenu fileMenu = new JMenu();
60     private JMenu viewMenu = new JMenu();
61     private JMenu helpMenu = new JMenu();
62     private JToolBar toolbar = new JToolBar();
63     private JTextArea dependenciesResultArea = new JTextArea();
64     private JTextArea closureResultArea = new JTextArea();
65     private JTextArea metricsResultArea = new JTextArea();
66     private MetricsTableModel metricsChartModel = new MetricsTableModel();
67     private StatusLine statusLine = new StatusLine(420);
68     private JProgressBar progressBar = new JProgressBar();
69
70     private Collection inputFiles = null;
71     private ClassfileLoaderDispatcher dispatcher = null;
72     private NodeFactory nodeFactory = null;
73     private Monitor monitor = null;
74
75     private JCheckBox packageScope = new JCheckBox("packages");
76     private JCheckBox classScope = new JCheckBox("classes");
77     private JCheckBox featureScope = new JCheckBox("features");
78     private JTextField scopeIncludes = new JTextField();
79     private JTextField packageScopeIncludes = new JTextField();
80     private JTextField classScopeIncludes = new JTextField();
81     private JTextField featureScopeIncludes = new JTextField();
82     private JTextField scopeExcludes = new JTextField();
83     private JTextField packageScopeExcludes = new JTextField();
84     private JTextField classScopeExcludes = new JTextField();
85     private JTextField featureScopeExcludes = new JTextField();
86     
87     private JCheckBox packageFilter = new JCheckBox("packages");
88     private JCheckBox classFilter = new JCheckBox("classes");
89     private JCheckBox featureFilter = new JCheckBox("features");
90     private JTextField filterIncludes = new JTextField();
91     private JTextField packageFilterIncludes = new JTextField();
92     private JTextField classFilterIncludes = new JTextField();
93     private JTextField featureFilterIncludes = new JTextField();
94     private JTextField filterExcludes = new JTextField();
95     private JTextField packageFilterExcludes = new JTextField();
96     private JTextField classFilterExcludes = new JTextField();
97     private JTextField featureFilterExcludes = new JTextField();
98
99     private JCheckBox showInbounds = new JCheckBox("<--");
100     private JCheckBox showOutbounds = new JCheckBox("-->");
101     private JCheckBox showEmptyNodes = new JCheckBox("empty elements");
102     private JCheckBox copyOnly = new JCheckBox("copy only");
103     
104     private JTextField maximumInboundDepth = new JTextField("0", 2);
105     private JTextField maximumOutboundDepth = new JTextField(2);
106
107     private GraphCopier dependenciesQuery = null;
108     
109     public DependencyFinder(CommandLine commandLine) {
110         this.setSize(new Dimension(800, 600));
111         this.setTitle("Dependency Finder");
112         this.setIconImage(new ImageIcon(getClass().getResource("icons/logoicon.gif")).getImage());
113         this.setDefaultCloseOperation(JFrame.DISPOSE_ON_CLOSE);
114         this.addWindowListener(new WindowKiller());
115
116         setNewDependencyGraph();
117         
118         packageScope.setToolTipText("Select packages");
119         classScope.setToolTipText("Select classes (with their package)");
120         featureScope.setToolTipText("Select methods and fields (with their class and package)");
121         scopeIncludes.setToolTipText("Package, class, method, or field must match any these expressions. E.g., /^com.mycompany/, /\\.get\\w+\\(/");
122         packageScopeIncludes.setToolTipText("Package must match any these expressions. E.g., /^com.mycompany/, /\\.get\\w+\\(/");
123         classScopeIncludes.setToolTipText("Class must match any these expressions. E.g., /^com.mycompany/, /\\.get\\w+\\(/");
124         featureScopeIncludes.setToolTipText("Method or field must match any these expressions. E.g., /^com.mycompany/, /\\.get\\w+\\(/");
125         scopeExcludes.setToolTipText("Package, class, method, or field must NOT match any of these expressions. E.g., /Test/");
126         packageScopeExcludes.setToolTipText("Package must NOT match any of these expressions. E.g., /Test/");
127         classScopeExcludes.setToolTipText("Class must NOT match any of these expressions. E.g., /Test/");
128         featureScopeExcludes.setToolTipText("Method or field must NOT match any of these expressions. E.g., /Test/");
129         
130         packageFilter.setToolTipText("Show dependencies to/from packages");
131         classFilter.setToolTipText("Show dependencies to/from classes");
132         featureFilter.setToolTipText("Show dependencies to/from methods and fields");
133         filterIncludes.setToolTipText("Package, class, method, or field at the other end of the dependency must match any these expressions. E.g., /^com.mycompany/, /\\.get\\w+\\(/");
134         packageFilterIncludes.setToolTipText("Package at the other end of the dependency must match any these expressions. E.g., /^com.mycompany/, /\\.get\\w+\\(/");
135         classFilterIncludes.setToolTipText("Class at the other end of the dependency must match any these expressions. E.g., /^com.mycompany/, /\\.get\\w+\\(/");
136         featureFilterIncludes.setToolTipText("Method or field at the other end of the dependency must match any these expressions. E.g., /^com.mycompany/, /\\.get\\w+\\(/");
137         filterExcludes.setToolTipText("Package, class, method, or field at the other end of the dependency must NOT match any of these expressions. E.g., /Test/");
138         packageFilterExcludes.setToolTipText("Package at the other end of the dependency must NOT match any of these expressions. E.g., /Test/");
139         classFilterExcludes.setToolTipText("Class at the other end of the dependency must NOT match any of these expressions. E.g., /Test/");
140         featureFilterExcludes.setToolTipText("Method or field at the other end of the dependency must NOT match any of these expressions. E.g., /Test/");
141         
142         showInbounds.setToolTipText("Show dependencies that point to the selected packages, classes, methods, or fields");
143         showOutbounds.setToolTipText("Show dependencies that originate from the selected packages, classes, methods, or fields");
144         showEmptyNodes.setToolTipText("Show selected packages, classes, methods, and fields even if they do not have dependencies");
145         copyOnly.setToolTipText("<html>Only copy explicit dependencies to the result graph.<br>Do not introduce implicit dependencies<br>where explicit dependencies match the regular expressions<br>but are otherwise out of scope</html>");
146
147         showInbounds.setFont(getCodeFont(Font.BOLD, 14));
148         showOutbounds.setFont(getCodeFont(Font.BOLD, 14));
149         
150         maximumInboundDepth.setToolTipText("Maximum hops against the direction dependencies. Empty field means no limit.");
151         maximumOutboundDepth.setToolTipText("Maximum hops in the direction of dependencies. Empty field means no limit.");
152
153         setAdvancedMode(false);
154         
155         buildMenus(commandLine);
156         buildUI();
157
158         try {
159             UIManager.setLookAndFeel("javax.swing.plaf.metal.MetalLookAndFeel");
160             SwingUtilities.updateComponentTreeUI(this);
161         } catch (Exception JavaDoc ex) {
162             Logger.getLogger(DependencyFinder.class).error("Unable to set look and feel", ex);
163         }
164         
165         statusLine.showInfo("Ready.");
166     }
167
168     private Font getCodeFont(int style, int size) {
169         String JavaDoc fontName = "Monospaced";
170         
171         String JavaDoc[] fontNames = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames();
172         for (int i=0; i<fontNames.length; i++) {
173             if (fontNames[i].indexOf("Courier") != -1) {
174                 fontName = fontNames[i];
175             }
176         }
177
178         return new Font(fontName, style, size);
179     }
180
181     private boolean isAdvancedMode() {
182         return advancedMode;
183     }
184
185     void setAdvancedMode(boolean advancedMode) {
186         this.advancedMode = advancedMode;
187
188         copyOnly.setVisible(advancedMode);
189     }
190     
191     public boolean getMaximize() {
192         return maximize;
193     }
194
195     private void setMaximize(boolean maximize) {
196         this.maximize = maximize;
197     }
198
199     public boolean getMinimize() {
200         return minimize;
201     }
202
203     private void setMinimize(boolean minimize) {
204         this.minimize = minimize;
205     }
206     
207     public ClassfileLoaderDispatcher getClassfileLoaderDispatcher() {
208         return dispatcher;
209     }
210
211     private void setClassfileLoaderDispatcher(ClassfileLoaderDispatcher dispatcher) {
212         this.dispatcher = dispatcher;
213     }
214
215     public Monitor getMonitor() {
216         return monitor;
217     }
218
219     private void setMonitor(Monitor monitor) {
220         this.monitor = monitor;
221     }
222     
223     public Collection getInputFiles() {
224         return inputFiles;
225     }
226
227     private void setInputFiles(Collection inputFiles) {
228         this.inputFiles = inputFiles;
229     }
230     
231     public void addInputFiles(Collection files) {
232         inputFiles.addAll(files);
233     }
234
235     public Collection getPackages() {
236         return getNodeFactory().getPackages().values();
237     }
238
239     public NodeFactory getNodeFactory() {
240         return nodeFactory;
241     }
242
243     private void setNodeFactory(NodeFactory nodeFactory) {
244         this.nodeFactory = nodeFactory;
245     }
246     
247     StatusLine getStatusLine() {
248         return statusLine;
249     }
250         
251     JProgressBar getProgressBar() {
252         return progressBar;
253     }
254
255     private void buildMenus(CommandLine commandLine) {
256         buildFileMenu(commandLine);
257         buildViewMenu(commandLine);
258         buildHelpMenu(commandLine);
259
260         this.setJMenuBar(menuBar);
261     }
262     
263     private void buildFileMenu(CommandLine commandLine) {
264         menuBar.add(fileMenu);
265
266         fileMenu.setText("File");
267
268         Action action;
269         JMenuItem menuItem;
270         JButton button;
271
272         action = new DependencyExtractAction(this);
273         menuItem = fileMenu.add(action);
274         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, Event.CTRL_MASK));
275         menuItem.setMnemonic('e');
276         button = toolbar.add(action);
277         button.setToolTipText((String JavaDoc) action.getValue(Action.LONG_DESCRIPTION));
278
279         action = new RefreshDependencyGraphAction(this);
280         menuItem = fileMenu.add(action);
281         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_R, Event.CTRL_MASK));
282         menuItem.setMnemonic('r');
283         button = toolbar.add(action);
284         button.setToolTipText((String JavaDoc) action.getValue(Action.LONG_DESCRIPTION));
285
286         toolbar.addSeparator();
287         fileMenu.addSeparator();
288         
289         action = new OpenFileAction(this);
290         menuItem = fileMenu.add(action);
291         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, Event.CTRL_MASK));
292         menuItem.setMnemonic('o');
293         button = toolbar.add(action);
294         button.setToolTipText((String JavaDoc) action.getValue(Action.LONG_DESCRIPTION));
295         
296         action = new SaveFileAction(this, commandLine.getSingleSwitch("encoding"), commandLine.getSingleSwitch("dtd-prefix"));
297         menuItem = fileMenu.add(action);
298         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, Event.CTRL_MASK));
299         menuItem.setMnemonic('s');
300         button = toolbar.add(action);
301         button.setToolTipText((String JavaDoc) action.getValue(Action.LONG_DESCRIPTION));
302
303         if (commandLine.isPresent("indent-text")) {
304             ((SaveFileAction) action).setIndentText(commandLine.getSingleSwitch("indent-text"));
305         }
306         
307         toolbar.addSeparator();
308         fileMenu.addSeparator();
309         
310         action = new NewDependencyGraphAction(this);
311         menuItem = fileMenu.add(action);
312         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, Event.CTRL_MASK));
313         menuItem.setMnemonic('n');
314         button = toolbar.add(action);
315         button.setToolTipText((String JavaDoc) action.getValue(Action.LONG_DESCRIPTION));
316
317         toolbar.addSeparator();
318         fileMenu.addSeparator();
319         
320         action = new DependencyQueryAction(this);
321         menuItem = fileMenu.add(action);
322         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_D, Event.CTRL_MASK));
323         menuItem.setMnemonic('d');
324         button = toolbar.add(action);
325         button.setToolTipText((String JavaDoc) action.getValue(Action.LONG_DESCRIPTION));
326
327         action = new ClosureQueryAction(this);
328         menuItem = fileMenu.add(action);
329         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_C, Event.CTRL_MASK));
330         menuItem.setMnemonic('c');
331         button = toolbar.add(action);
332         button.setToolTipText((String JavaDoc) action.getValue(Action.LONG_DESCRIPTION));
333
334         action = new MetricsQueryAction(this);
335         menuItem = fileMenu.add(action);
336         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_M, Event.CTRL_MASK));
337         menuItem.setMnemonic('m');
338         button = toolbar.add(action);
339         button.setToolTipText((String JavaDoc) action.getValue(Action.LONG_DESCRIPTION));
340
341         action = new AllQueriesAction(this);
342         menuItem = fileMenu.add(action);
343         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_A, Event.CTRL_MASK));
344         menuItem.setMnemonic('a');
345         button = toolbar.add(action);
346         button.setToolTipText((String JavaDoc) action.getValue(Action.LONG_DESCRIPTION));
347
348         toolbar.addSeparator();
349         fileMenu.addSeparator();
350
351         action = new ExitAction(this);
352         menuItem = fileMenu.add(action);
353         menuItem.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_X, Event.CTRL_MASK));
354         menuItem.setMnemonic('x');
355     }
356     
357     private void buildViewMenu(CommandLine commandLine) {
358         menuBar.add(viewMenu);
359
360         viewMenu.setText("View");
361
362         ButtonGroup group = new ButtonGroup();
363         JMenuItem menuItem;
364         
365         menuItem = new JRadioButtonMenuItem(new SimpleQueryPanelAction(this));
366         menuItem.setSelected(true);
367         group.add(menuItem);
368         viewMenu.add(menuItem);
369         
370         menuItem = new JRadioButtonMenuItem(new AdvancedQueryPanelAction(this));
371         group.add(menuItem);
372         viewMenu.add(menuItem);
373     }
374
375     private void buildHelpMenu(CommandLine commandLine) {
376         menuBar.add(helpMenu);
377
378         helpMenu.setText("Help");
379
380         Action action;
381         JMenuItem menuItem;
382
383         action = new AboutAction(this);
384         menuItem = helpMenu.add(action);
385         menuItem.setMnemonic('a');
386     }
387
388     private void buildUI() {
389         this.getContentPane().setLayout(new BorderLayout());
390         this.getContentPane().add(buildControlPanel(), BorderLayout.NORTH);
391         this.getContentPane().add(buildResultPanel(), BorderLayout.CENTER);
392         this.getContentPane().add(buildStatusPanel(), BorderLayout.SOUTH);
393     }
394
395     private JComponent buildControlPanel() {
396         JPanel result = new JPanel();
397
398         result.setLayout(new BorderLayout());
399         result.add(toolbar, BorderLayout.NORTH);
400         result.add(buildQueryPanel(), BorderLayout.CENTER);
401         
402         return result;
403     }
404     
405     JComponent buildQueryPanel() {
406         if (isAdvancedMode()) {
407             buildAdvancedQueryPanel();
408         } else {
409             buildSimpleQueryPanel();
410         }
411         
412         return queryPanel;
413     }
414     
415     private void buildSimpleQueryPanel() {
416         queryPanel.removeAll();
417         queryPanel.setLayout(new GridLayout(1, 2));
418         queryPanel.add(buildSimpleScopePanel());
419         queryPanel.add(buildSimpleFilterPanel());
420         queryPanel.revalidate();
421     }
422     
423     private void buildAdvancedQueryPanel() {
424         queryPanel.removeAll();
425         queryPanel.setLayout(new GridLayout(1, 2));
426         queryPanel.add(buildAdvancedScopePanel());
427         queryPanel.add(buildAdvancedFilterPanel());
428         queryPanel.revalidate();
429     }
430
431     private JComponent buildSimpleScopePanel() {
432         JPanel result = new JPanel();
433
434         result.setBorder(BorderFactory.createTitledBorder("Select programming elements"));
435
436         result.setLayout(new BorderLayout());
437
438         result.add(buildSimpleScopePanelCheckboxes(), BorderLayout.NORTH);
439         result.add(buildSimpleScopePanelTextFields(), BorderLayout.SOUTH);
440
441         return result;
442     }
443     
444     private JComponent buildSimpleScopePanelTextFields() {
445         JPanel result = new JPanel();
446
447         GridBagLayout gbl = new GridBagLayout();
448         GridBagConstraints c = new GridBagConstraints();
449         c.insets = new Insets(0, 2, 0, 2);
450         
451         result.setLayout(gbl);
452
453         JLabel scopeIncludesLabel = new JLabel("including:");
454         c.anchor = GridBagConstraints.WEST;
455         c.fill = GridBagConstraints.NONE;
456         c.gridx = 0;
457         c.gridy = 0;
458         c.weightx = 0;
459         c.weighty = 0;
460         result.add(scopeIncludesLabel);
461         gbl.setConstraints(scopeIncludesLabel, c);
462
463         JLabel scopeExcludesLabel = new JLabel("excluding:");
464         c.anchor = GridBagConstraints.WEST;
465         c.fill = GridBagConstraints.NONE;
466         c.gridx = 1;
467         c.gridy = 0;
468         c.weightx = 0;
469         c.weighty = 0;
470         result.add(scopeExcludesLabel);
471         gbl.setConstraints(scopeExcludesLabel, c);
472
473         // -scope-includes
474
c.anchor = GridBagConstraints.WEST;
475         c.fill = GridBagConstraints.HORIZONTAL;
476         c.gridx = 0;
477         c.gridy = 1;
478         c.weightx = 1;
479         c.weighty = 0;
480         result.add(scopeIncludes);
481         gbl.setConstraints(scopeIncludes, c);
482         
483         // -scope-excludes
484
c.anchor = GridBagConstraints.WEST;
485         c.fill = GridBagConstraints.HORIZONTAL;
486         c.gridx = 1;
487         c.gridy = 1;
488         c.weightx = 1;
489         c.weighty = 0;
490         result.add(scopeExcludes);
491         gbl.setConstraints(scopeExcludes, c);
492
493         return result;
494     }
495
496     private JComponent buildSimpleScopePanelCheckboxes() {
497         JPanel result = new JPanel();
498
499         GridBagLayout gbl = new GridBagLayout();
500         GridBagConstraints c = new GridBagConstraints();
501         c.insets = new Insets(0, 2, 0, 2);
502         
503         result.setLayout(gbl);
504
505         // -package-scope
506
c.anchor = GridBagConstraints.EAST;
507         c.fill = GridBagConstraints.NONE;
508         c.gridx = 0;
509         c.gridy = 0;
510         c.weightx = 1;
511         c.weighty = 0;
512         result.add(packageScope);
513         gbl.setConstraints(packageScope, c);
514
515         // -class-scope
516
c.anchor = GridBagConstraints.CENTER;
517         c.fill = GridBagConstraints.NONE;
518         c.gridx = 1;
519         c.gridy = 0;
520         c.weightx = 0;
521         c.weighty = 0;
522         result.add(classScope);
523         gbl.setConstraints(classScope, c);
524
525         // -feature-scope
526
c.anchor = GridBagConstraints.WEST;
527         c.fill = GridBagConstraints.NONE;
528         c.gridx = 2;
529         c.gridy = 0;
530         c.weightx = 1;
531         c.weighty = 0;
532         result.add(featureScope);
533         gbl.setConstraints(featureScope, c);
534
535         return result;
536     }
537     
538     private JComponent buildSimpleFilterPanel() {
539         JPanel result = new JPanel();
540
541         result.setBorder(BorderFactory.createTitledBorder("Show dependencies (stop for closure)"));
542
543         result.setLayout(new BorderLayout());
544
545         result.add(buildSimpleFilterPanelCheckboxes(), BorderLayout.NORTH);
546         result.add(buildSimpleFilterPanelTextFields(), BorderLayout.SOUTH);
547
548         return result;
549     }
550     
551     private JComponent buildSimpleFilterPanelTextFields() {
552         JPanel result = new JPanel();
553
554         GridBagLayout gbl = new GridBagLayout();
555         GridBagConstraints c = new GridBagConstraints();
556         c.insets = new Insets(0, 2, 0, 2);
557         
558         result.setLayout(gbl);
559
560         JLabel filterIncludesLabel = new JLabel("including:");
561         c.anchor = GridBagConstraints.WEST;
562         c.fill = GridBagConstraints.NONE;
563         c.gridx = 0;
564         c.gridy = 0;
565         c.weightx = 0;
566         c.weighty = 0;
567         result.add(filterIncludesLabel);
568         gbl.setConstraints(filterIncludesLabel, c);
569
570         JLabel filterExcludesLabel = new JLabel("excluding:");
571         c.anchor = GridBagConstraints.WEST;
572         c.fill = GridBagConstraints.NONE;
573         c.gridx = 1;
574         c.gridy = 0;
575         c.weightx = 0;
576         c.weighty = 0;
577         result.add(filterExcludesLabel);
578         gbl.setConstraints(filterExcludesLabel, c);
579
580         // -filter-includes
581
c.anchor = GridBagConstraints.WEST;
582         c.fill = GridBagConstraints.HORIZONTAL;
583         c.gridx = 0;
584         c.gridy = 1;
585         c.weightx = 1;
586         c.weighty = 0;
587         result.add(filterIncludes);
588         gbl.setConstraints(filterIncludes, c);
589
590         // -filter-excludes
591
c.anchor = GridBagConstraints.WEST;
592         c.fill = GridBagConstraints.HORIZONTAL;
593         c.gridx = 1;
594         c.gridy = 1;
595         c.weightx = 1;
596         c.weighty = 0;
597         result.add(filterExcludes);
598         gbl.setConstraints(filterExcludes, c);
599
600         return result;
601     }
602     
603     private JComponent buildSimpleFilterPanelCheckboxes() {
604         JPanel result = new JPanel();
605
606         GridBagLayout gbl = new GridBagLayout();
607         GridBagConstraints c = new GridBagConstraints();
608         c.insets = new Insets(0, 2, 0, 2);
609         
610         result.setLayout(gbl);
611
612         // -package-filter
613
c.anchor = GridBagConstraints.EAST;
614         c.fill = GridBagConstraints.NONE;
615         c.gridx = 0;
616         c.gridy = 0;
617         c.weightx = 1;
618         c.weighty = 0;
619         result.add(packageFilter);
620         gbl.setConstraints(packageFilter, c);
621
622         // -class-filter
623
c.anchor = GridBagConstraints.CENTER;
624         c.fill = GridBagConstraints.NONE;
625         c.gridx = 1;
626         c.gridy = 0;
627         c.weightx = 0;
628         c.weighty = 0;
629         result.add(classFilter);
630         gbl.setConstraints(classFilter, c);
631
632         // -feature-filter
633
c.anchor = GridBagConstraints.WEST;
634         c.fill = GridBagConstraints.NONE;
635         c.gridx = 2;
636         c.gridy = 0;
637         c.weightx = 1;
638         c.weighty = 0;
639         result.add(featureFilter);
640         gbl.setConstraints(featureFilter, c);
641
642         return result;
643     }
644
645     private JComponent buildAdvancedScopePanel() {
646         JPanel result = new JPanel();
647
648         result.setBorder(BorderFactory.createTitledBorder("Select programming elements"));
649
650         GridBagLayout gbl = new GridBagLayout();
651         GridBagConstraints c = new GridBagConstraints();
652         c.insets = new Insets(2, 0, 2, 5);
653         
654         result.setLayout(gbl);
655
656         // -package-scope
657
c.anchor = GridBagConstraints.WEST;
658         c.fill = GridBagConstraints.NONE;
659         c.gridx = 0;
660         c.gridy = 2;
661         c.weightx = 0;
662         c.weighty = 0;
663         result.add(packageScope);
664         gbl.setConstraints(packageScope, c);
665
666         // -class-scope
667
c.anchor = GridBagConstraints.WEST;
668         c.fill = GridBagConstraints.NONE;
669         c.gridx = 0;
670         c.gridy = 3;
671         c.weightx = 0;
672         c.weighty = 0;
673         result.add(classScope);
674         gbl.setConstraints(classScope, c);
675
676         // -feature-scope
677
c.anchor = GridBagConstraints.WEST;
678         c.fill = GridBagConstraints.NONE;
679         c.gridx = 0;
680         c.gridy = 4;
681         c.weightx = 0;
682         c.weighty = 0;
683         result.add(featureScope);
684         gbl.setConstraints(featureScope, c);
685
686         JLabel scopeIncludesLabel = new JLabel("including:");
687         c.anchor = GridBagConstraints.WEST;
688         c.fill = GridBagConstraints.NONE;
689         c.gridx = 1;
690         c.gridy = 0;
691         c.weightx = 0;
692         c.weighty = 0;
693         result.add(scopeIncludesLabel);
694         gbl.setConstraints(scopeIncludesLabel, c);
695
696         // -scope-includes
697
c.anchor = GridBagConstraints.WEST;
698         c.fill = GridBagConstraints.HORIZONTAL;
699         c.gridx = 1;
700         c.gridy = 1;
701         c.weightx = 1;
702         c.weighty = 0;
703         result.add(scopeIncludes);
704         gbl.setConstraints(scopeIncludes, c);
705
706         // -package-scope-includes
707
c.anchor = GridBagConstraints.WEST;
708         c.fill = GridBagConstraints.HORIZONTAL;
709         c.gridx = 1;
710         c.gridy = 2;
711         c.weightx = 1;
712         c.weighty = 0;
713         result.add(packageScopeIncludes);
714         gbl.setConstraints(packageScopeIncludes, c);
715
716         // -class-scope-includes
717
c.anchor = GridBagConstraints.WEST;
718         c.fill = GridBagConstraints.HORIZONTAL;
719         c.gridx = 1;
720         c.gridy = 3;
721         c.weightx = 1;
722         c.weighty = 0;
723         result.add(classScopeIncludes);
724         gbl.setConstraints(classScopeIncludes, c);
725
726         // -feature-scope-includes
727
c.anchor = GridBagConstraints.WEST;
728         c.fill = GridBagConstraints.HORIZONTAL;
729         c.gridx = 1;
730         c.gridy = 4;
731         c.weightx = 1;
732         c.weighty = 0;
733         result.add(featureScopeIncludes);
734         gbl.setConstraints(featureScopeIncludes, c);
735
736         JLabel scopeExcludesLabel = new JLabel("excluding:");
737         c.anchor = GridBagConstraints.WEST;
738         c.fill = GridBagConstraints.NONE;
739         c.gridx = 2;
740         c.gridy = 0;
741         c.weightx = 0;
742         c.weighty = 0;
743         result.add(scopeExcludesLabel);
744         gbl.setConstraints(scopeExcludesLabel, c);
745
746         // -scope-excludes
747
c.anchor = GridBagConstraints.WEST;
748         c.fill = GridBagConstraints.HORIZONTAL;
749         c.gridx = 2;
750         c.gridy = 1;
751         c.weightx = 1;
752         c.weighty = 0;
753         result.add(scopeExcludes);
754         gbl.setConstraints(scopeExcludes, c);
755
756         // -package-scope-excludes
757
c.anchor = GridBagConstraints.WEST;
758         c.fill = GridBagConstraints.HORIZONTAL;
759         c.gridx = 2;
760         c.gridy = 2;
761         c.weightx = 1;
762         c.weighty = 0;
763         result.add(packageScopeExcludes);
764         gbl.setConstraints(packageScopeExcludes, c);
765
766         // -class-scope-excludes
767
c.anchor = GridBagConstraints.WEST;
768         c.fill = GridBagConstraints.HORIZONTAL;
769         c.gridx = 2;
770         c.gridy = 3;
771         c.weightx = 1;
772         c.weighty = 0;
773         result.add(classScopeExcludes);
774         gbl.setConstraints(classScopeExcludes, c);
775
776         // -feature-scope-excludes
777
c.anchor = GridBagConstraints.WEST;
778         c.fill = GridBagConstraints.HORIZONTAL;
779         c.gridx = 2;
780         c.gridy = 4;
781         c.weightx = 1;
782         c.weighty = 0;
783         result.add(featureScopeExcludes);
784         gbl.setConstraints(featureScopeExcludes, c);
785
786         return result;
787     }
788     
789     private JComponent buildAdvancedFilterPanel() {
790         JPanel result = new JPanel();
791
792         result.setBorder(BorderFactory.createTitledBorder("Show dependencies (stop for closure)"));
793
794         GridBagLayout gbl = new GridBagLayout();
795         GridBagConstraints c = new GridBagConstraints();
796         c.insets = new Insets(2, 0, 2, 5);
797         
798         result.setLayout(gbl);
799
800         // -package-filter
801
c.anchor = GridBagConstraints.WEST;
802         c.fill = GridBagConstraints.NONE;
803         c.gridx = 0;
804         c.gridy = 2;
805         c.weightx = 0;
806         c.weighty = 0;
807         result.add(packageFilter);
808         gbl.setConstraints(packageFilter, c);
809
810         // -class-filter
811
c.anchor = GridBagConstraints.WEST;
812         c.fill = GridBagConstraints.NONE;
813         c.gridx = 0;
814         c.gridy = 3;
815         c.weightx = 0;
816         c.weighty = 0;
817         result.add(classFilter);
818         gbl.setConstraints(classFilter, c);
819
820         // -feature-filter
821
c.anchor = GridBagConstraints.WEST;
822         c.fill = GridBagConstraints.NONE;
823         c.gridx = 0;
824         c.gridy = 4;
825         c.weightx = 0;
826         c.weighty = 0;
827         result.add(featureFilter);
828         gbl.setConstraints(featureFilter, c);
829
830         JLabel filterIncludesLabel = new JLabel("including:");
831         c.anchor = GridBagConstraints.WEST;
832         c.fill = GridBagConstraints.NONE;
833         c.gridx = 1;
834         c.gridy = 0;
835         c.weightx = 0;
836         c.weighty = 0;
837         result.add(filterIncludesLabel);
838         gbl.setConstraints(filterIncludesLabel, c);
839
840         // -filter-includes
841
c.anchor = GridBagConstraints.WEST;
842         c.fill = GridBagConstraints.HORIZONTAL;
843         c.gridx = 1;
844         c.gridy = 1;
845         c.weightx = 1;
846         c.weighty = 0;
847         result.add(filterIncludes);
848         gbl.setConstraints(filterIncludes, c);
849
850         // -package-filter-includes
851
c.anchor = GridBagConstraints.WEST;
852         c.fill = GridBagConstraints.HORIZONTAL;
853         c.gridx = 1;
854         c.gridy = 2;
855         c.weightx = 1;
856         c.weighty = 0;
857         result.add(packageFilterIncludes);
858         gbl.setConstraints(packageFilterIncludes, c);
859
860         // -class-filter-includes
861
c.anchor = GridBagConstraints.WEST;
862         c.fill = GridBagConstraints.HORIZONTAL;
863         c.gridx = 1;
864         c.gridy = 3;
865         c.weightx = 1;
866         c.weighty = 0;
867         result.add(classFilterIncludes);
868         gbl.setConstraints(classFilterIncludes, c);
869
870         // -feature-filter-includes
871
c.anchor = GridBagConstraints.WEST;
872         c.fill = GridBagConstraints.HORIZONTAL;
873         c.gridx = 1;
874         c.gridy = 4;
875         c.weightx = 1;
876         c.weighty = 0;
877         result.add(featureFilterIncludes);
878         gbl.setConstraints(featureFilterIncludes, c);
879
880         JLabel filterExcludesLabel = new JLabel("excluding:");
881         c.anchor = GridBagConstraints.WEST;
882         c.fill = GridBagConstraints.NONE;
883         c.gridx = 2;
884         c.gridy = 0;
885         c.weightx = 0;
886         c.weighty = 0;
887         result.add(filterExcludesLabel);
888         gbl.setConstraints(filterExcludesLabel, c);
889
890         // -filter-excludes
891
c.anchor = GridBagConstraints.WEST;
892         c.fill = GridBagConstraints.HORIZONTAL;
893         c.gridx = 2;
894         c.gridy = 1;
895         c.weightx = 1;
896         c.weighty = 0;
897         result.add(filterExcludes);
898         gbl.setConstraints(filterExcludes, c);
899
900         // -package-filter-excludes
901
c.anchor = GridBagConstraints.WEST;
902         c.fill = GridBagConstraints.HORIZONTAL;
903         c.gridx = 2;
904         c.gridy = 2;
905         c.weightx = 1;
906         c.weighty = 0;
907         result.add(packageFilterExcludes);
908         gbl.setConstraints(packageFilterExcludes, c);
909
910         // -class-filter-excludes
911
c.anchor = GridBagConstraints.WEST;
912         c.fill = GridBagConstraints.HORIZONTAL;
913         c.gridx = 2;
914         c.gridy = 3;
915         c.weightx = 1;
916         c.weighty = 0;
917         result.add(classFilterExcludes);
918         gbl.setConstraints(classFilterExcludes, c);
919
920         // -feature-filter-excludes
921
c.anchor = GridBagConstraints.WEST;
922         c.fill = GridBagConstraints.HORIZONTAL;
923         c.gridx = 2;
924         c.gridy = 4;
925         c.weightx = 1;
926         c.weighty = 0;
927         result.add(featureFilterExcludes);
928         gbl.setConstraints(featureFilterExcludes, c);
929
930         return result;
931     }
932     
933     private JComponent buildResultPanel() {
934         JTabbedPane result = new JTabbedPane();
935
936         result.setBorder(BorderFactory.createTitledBorder("Results"));
937         result.addTab("Dependencies", buildDependenciesPanel());
938         result.addTab("Closure", buildClosurePanel());
939         result.addTab("Metrics", buildMetricsPanel());
940         
941         return result;
942     }
943
944     private JComponent buildDependenciesPanel() {
945         JPanel result = new JPanel();
946
947         result.setLayout(new BorderLayout());
948         result.add(buildPrinterControlPanel(), BorderLayout.NORTH);
949         result.add(buildDependenciesResultPanel(), BorderLayout.CENTER);
950         
951         return result;
952     }
953     
954     private JComponent buildPrinterControlPanel() {
955         JPanel result = new JPanel();
956
957         result.add(new JLabel("Show "));
958         result.add(showInbounds);
959         result.add(showOutbounds);
960         result.add(showEmptyNodes);
961         result.add(copyOnly);
962
963         PrinterControlAction action = new PrinterControlAction(this);
964         showInbounds.addActionListener(action);
965         showOutbounds.addActionListener(action);
966         showEmptyNodes.addActionListener(action);
967
968         return result;
969     }
970     
971     private JComponent buildDependenciesResultPanel() {
972         JComponent result = new JScrollPane(dependenciesResultArea);
973         
974         dependenciesResultArea.setEditable(false);
975         dependenciesResultArea.setFont(getCodeFont(Font.PLAIN, 12));
976         
977         return result;
978     }
979     
980     private JComponent buildClosurePanel() {
981         JPanel result = new JPanel();
982         
983         result.setLayout(new BorderLayout());
984         result.add(buildClosureControlPanel(), BorderLayout.NORTH);
985         result.add(buildClosureResultPanel(), BorderLayout.CENTER);
986         
987         return result;
988     }
989     
990     private JComponent buildClosureControlPanel() {
991         JPanel result = new JPanel();
992         
993         result.add(new JLabel("Follow inbounds: "));
994         result.add(maximumInboundDepth);
995         result.add(new JLabel("Follow outbounds: "));
996         result.add(maximumOutboundDepth);
997         
998         return result;
999     }
1000
1001    private JComponent buildClosureResultPanel() {
1002        JComponent result = new JScrollPane(closureResultArea);
1003        
1004        closureResultArea.setEditable(false);
1005        closureResultArea.setFont(getCodeFont(Font.PLAIN, 12));
1006        
1007        return result;
1008    }
1009    
1010    private JComponent buildMetricsPanel() {
1011        return new JSplitPane(JSplitPane.VERTICAL_SPLIT, buildMetricsResultPanel(), buildMetricsChartPanel());
1012    }
1013
1014    private JComponent buildMetricsResultPanel() {
1015        JComponent result = new JScrollPane(metricsResultArea);
1016
1017        metricsResultArea.setEditable(false);
1018        
1019        return result;
1020    }
1021
1022    private JComponent buildMetricsChartPanel() {
1023        JComponent result;
1024
1025        JTable table = new JTable(metricsChartModel);
1026
1027        table.setCellSelectionEnabled(true);
1028        table.setColumnSelectionAllowed(true);
1029        
1030        result = new JScrollPane(table);
1031
1032        return result;
1033    }
1034    
1035    private JComponent buildStatusPanel() {
1036        JPanel result = new JPanel();
1037
1038        Dimension size = getProgressBar().getPreferredSize();
1039        size.width = 100;
1040        getProgressBar().setPreferredSize(size);
1041        getProgressBar().setBorder(BorderFactory.createBevelBorder(BevelBorder.LOWERED));
1042        
1043        result.setLayout(new BorderLayout());
1044        result.add(getStatusLine(), BorderLayout.CENTER);
1045        result.add(getProgressBar(), BorderLayout.EAST);
1046        
1047        return result;
1048    }
1049    
1050    public void resetQuery() {
1051        packageScope.setSelected(true);
1052        classScope.setSelected(false);
1053        featureScope.setSelected(false);
1054        scopeIncludes.setText("//");
1055        packageScopeIncludes.setText("");
1056        classScopeIncludes.setText("");
1057        featureScopeIncludes.setText("");
1058        scopeExcludes.setText("");
1059        packageScopeExcludes.setText("");
1060        classScopeExcludes.setText("");
1061        featureScopeExcludes.setText("");
1062    
1063        packageFilter.setSelected(true);
1064        classFilter.setSelected(false);
1065        featureFilter.setSelected(false);
1066        filterIncludes.setText("//");
1067        packageFilterIncludes.setText("");
1068        classFilterIncludes.setText("");
1069        featureFilterIncludes.setText("");
1070        filterExcludes.setText("");
1071        packageFilterExcludes.setText("");
1072        classFilterExcludes.setText("");
1073        featureFilterExcludes.setText("");
1074
1075        showInbounds.setSelected(true);
1076        showOutbounds.setSelected(true);
1077        showEmptyNodes.setSelected(true);
1078        copyOnly.setSelected(false);
1079    }
1080    
1081    void clearDependencyResult() {
1082        dependenciesQuery = null;
1083        dependenciesResultArea.setText("");
1084    }
1085    
1086    void doDependencyQuery() {
1087        RegularExpressionSelectionCriteria scopeCriteria = new RegularExpressionSelectionCriteria();
1088        
1089        scopeCriteria.setMatchingPackages(packageScope.isSelected());
1090        scopeCriteria.setMatchingClasses(classScope.isSelected());
1091        scopeCriteria.setMatchingFeatures(featureScope.isSelected());
1092        scopeCriteria.setGlobalIncludes(scopeIncludes.getText());
1093        scopeCriteria.setGlobalExcludes(scopeExcludes.getText());
1094
1095        if (isAdvancedMode()) {
1096            scopeCriteria.setPackageIncludes(packageScopeIncludes.getText());
1097            scopeCriteria.setClassIncludes(classScopeIncludes.getText());
1098            scopeCriteria.setFeatureIncludes(featureScopeIncludes.getText());
1099            scopeCriteria.setPackageExcludes(packageScopeExcludes.getText());
1100            scopeCriteria.setClassExcludes(classScopeExcludes.getText());
1101            scopeCriteria.setFeatureExcludes(featureScopeExcludes.getText());
1102        }
1103    
1104        RegularExpressionSelectionCriteria filterCriteria = new RegularExpressionSelectionCriteria();
1105        
1106        filterCriteria.setMatchingPackages(packageFilter.isSelected());
1107        filterCriteria.setMatchingClasses(classFilter.isSelected());
1108        filterCriteria.setMatchingFeatures(featureFilter.isSelected());
1109        filterCriteria.setGlobalIncludes(filterIncludes.getText());
1110        filterCriteria.setGlobalExcludes(filterExcludes.getText());
1111
1112        if (isAdvancedMode()) {
1113            filterCriteria.setPackageIncludes(packageFilterIncludes.getText());
1114            filterCriteria.setClassIncludes(classFilterIncludes.getText());
1115            filterCriteria.setFeatureIncludes(featureFilterIncludes.getText());
1116            filterCriteria.setPackageExcludes(packageFilterExcludes.getText());
1117            filterCriteria.setClassExcludes(classFilterExcludes.getText());
1118            filterCriteria.setFeatureExcludes(featureFilterExcludes.getText());
1119        }
1120
1121        if ((isAdvancedMode() && copyOnly.isSelected()) || getMaximize()) {
1122            TraversalStrategy strategy = new SelectiveTraversalStrategy(scopeCriteria, filterCriteria);
1123            dependenciesQuery = new GraphCopier(strategy);
1124        } else {
1125            dependenciesQuery = new GraphSummarizer(scopeCriteria, filterCriteria);
1126        }
1127        
1128        dependenciesQuery.traverseNodes(getPackages());
1129
1130        refreshDependenciesDisplay();
1131    }
1132
1133    void refreshDependenciesDisplay() {
1134        if (dependenciesQuery != null) {
1135            StringWriter out = new StringWriter();
1136            com.jeantessier.dependency.TextPrinter printer = new com.jeantessier.dependency.TextPrinter(new PrintWriter(out));
1137
1138            printer.setShowInbounds(showInbounds.isSelected());
1139            printer.setShowOutbounds(showOutbounds.isSelected());
1140            printer.setShowEmptyNodes(showEmptyNodes.isSelected());
1141            
1142            printer.traverseNodes(dependenciesQuery.getScopeFactory().getPackages().values());
1143            
1144            dependenciesResultArea.setText(out.toString());
1145        }
1146    }
1147    
1148    void clearClosureResult() {
1149        closureResultArea.setText("");
1150    }
1151    
1152    void doClosureQuery() {
1153        RegularExpressionSelectionCriteria startCriteria = new RegularExpressionSelectionCriteria();
1154        
1155        startCriteria.setGlobalIncludes(scopeIncludes.getText());
1156        startCriteria.setGlobalExcludes(scopeExcludes.getText());
1157
1158        if (isAdvancedMode()) {
1159            startCriteria.setPackageIncludes(packageScopeIncludes.getText());
1160            startCriteria.setClassIncludes(classScopeIncludes.getText());
1161            startCriteria.setFeatureIncludes(featureScopeIncludes.getText());
1162            startCriteria.setPackageExcludes(packageScopeExcludes.getText());
1163            startCriteria.setClassExcludes(classScopeExcludes.getText());
1164            startCriteria.setFeatureExcludes(featureScopeExcludes.getText());
1165        }
1166    
1167        RegularExpressionSelectionCriteria stopCriteria = new RegularExpressionSelectionCriteria();
1168        
1169        stopCriteria.setGlobalIncludes(filterIncludes.getText());
1170        stopCriteria.setGlobalExcludes(filterExcludes.getText());
1171
1172        if (isAdvancedMode()) {
1173            stopCriteria.setPackageIncludes(packageFilterIncludes.getText());
1174            stopCriteria.setClassIncludes(classFilterIncludes.getText());
1175            stopCriteria.setFeatureIncludes(featureFilterIncludes.getText());
1176            stopCriteria.setPackageExcludes(packageFilterExcludes.getText());
1177            stopCriteria.setClassExcludes(classFilterExcludes.getText());
1178            stopCriteria.setFeatureExcludes(featureFilterExcludes.getText());
1179        }
1180
1181        TransitiveClosure selector = new TransitiveClosure(startCriteria, stopCriteria);
1182
1183        try {
1184            selector.setMaximumInboundDepth(Long.parseLong(maximumInboundDepth.getText()));
1185        } catch (NumberFormatException JavaDoc ex) {
1186            selector.setMaximumInboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
1187        }
1188
1189        try {
1190            selector.setMaximumOutboundDepth(Long.parseLong(maximumOutboundDepth.getText()));
1191        } catch (NumberFormatException JavaDoc ex) {
1192            selector.setMaximumOutboundDepth(TransitiveClosure.UNBOUNDED_DEPTH);
1193        }
1194        
1195        selector.traverseNodes(getPackages());
1196
1197        RegularExpressionSelectionCriteria scopeCriteria = new RegularExpressionSelectionCriteria();
1198        
1199        scopeCriteria.setMatchingPackages(packageScope.isSelected());
1200        scopeCriteria.setMatchingClasses(classScope.isSelected());
1201        scopeCriteria.setMatchingFeatures(featureScope.isSelected());
1202        
1203        RegularExpressionSelectionCriteria filterCriteria = new RegularExpressionSelectionCriteria();
1204        
1205        filterCriteria.setMatchingPackages(packageFilter.isSelected());
1206        filterCriteria.setMatchingClasses(classFilter.isSelected());
1207        filterCriteria.setMatchingFeatures(featureFilter.isSelected());
1208
1209        GraphSummarizer summarizer = new GraphSummarizer(scopeCriteria, filterCriteria);
1210        summarizer.traverseNodes(selector.getFactory().getPackages().values());
1211        
1212        StringWriter out = new StringWriter();
1213        com.jeantessier.dependency.Printer printer = new com.jeantessier.dependency.TextPrinter(new PrintWriter(out));
1214        printer.traverseNodes(summarizer.getScopeFactory().getPackages().values());
1215        closureResultArea.setText(out.toString());
1216    }
1217    
1218    void clearMetricsResult() {
1219        metricsResultArea.setText("");
1220    }
1221    
1222    void doMetricsQuery() {
1223        RegularExpressionSelectionCriteria scopeCriteria = new RegularExpressionSelectionCriteria();
1224        
1225        scopeCriteria.setMatchingPackages(packageScope.isSelected());
1226        scopeCriteria.setMatchingClasses(classScope.isSelected());
1227        scopeCriteria.setMatchingFeatures(featureScope.isSelected());
1228        scopeCriteria.setGlobalIncludes(scopeIncludes.getText());
1229        scopeCriteria.setGlobalExcludes(scopeExcludes.getText());
1230
1231        if (isAdvancedMode()) {
1232            scopeCriteria.setPackageIncludes(packageScopeIncludes.getText());
1233            scopeCriteria.setClassIncludes(classScopeIncludes.getText());
1234            scopeCriteria.setFeatureIncludes(featureScopeIncludes.getText());
1235            scopeCriteria.setPackageExcludes(packageScopeExcludes.getText());
1236            scopeCriteria.setClassExcludes(classScopeExcludes.getText());
1237            scopeCriteria.setFeatureExcludes(featureScopeExcludes.getText());
1238        }
1239    
1240        RegularExpressionSelectionCriteria filterCriteria = new RegularExpressionSelectionCriteria();
1241        
1242        filterCriteria.setMatchingPackages(packageFilter.isSelected());
1243        filterCriteria.setMatchingClasses(classFilter.isSelected());
1244        filterCriteria.setMatchingFeatures(featureFilter.isSelected());
1245        filterCriteria.setGlobalIncludes(filterIncludes.getText());
1246        filterCriteria.setGlobalExcludes(filterExcludes.getText());
1247
1248        if (isAdvancedMode()) {
1249            filterCriteria.setPackageIncludes(packageFilterIncludes.getText());
1250            filterCriteria.setClassIncludes(classFilterIncludes.getText());
1251            filterCriteria.setFeatureIncludes(featureFilterIncludes.getText());
1252            filterCriteria.setPackageExcludes(packageFilterExcludes.getText());
1253            filterCriteria.setClassExcludes(classFilterExcludes.getText());
1254            filterCriteria.setFeatureExcludes(featureFilterExcludes.getText());
1255        }
1256
1257        TraversalStrategy strategy = new SelectiveTraversalStrategy(scopeCriteria, filterCriteria);
1258        com.jeantessier.dependency.MetricsGatherer metrics = new com.jeantessier.dependency.MetricsGatherer(strategy);
1259        
1260        metrics.traverseNodes(getPackages());
1261
1262        StringWriter out = new StringWriter();
1263        MetricsReport report = new MetricsReport(new PrintWriter(out));
1264        report.process(metrics);
1265        
1266        metricsResultArea.setText(out.toString());
1267        metricsChartModel.setMetrics(metrics);
1268    }
1269
1270    void setNewDependencyGraph() {
1271        setInputFiles(new LinkedList());
1272        setClassfileLoaderDispatcher(new ModifiedOnlyDispatcher(ClassfileLoaderEventSource.DEFAULT_DISPATCHER));
1273
1274        NodeFactory factory = new NodeFactory();
1275        setNodeFactory(factory);
1276
1277        CodeDependencyCollector collector = new CodeDependencyCollector(factory);
1278        DeletingVisitor deletingVisitor = new DeletingVisitor(factory);
1279        setMonitor(new Monitor(collector, deletingVisitor));
1280
1281        resetQuery();
1282    }
1283
1284    public static void showError(CommandLineUsage clu, String JavaDoc msg) {
1285        System.err.println(msg);
1286        showError(clu);
1287    }
1288
1289    public static void showError(CommandLineUsage clu) {
1290        System.err.println(clu);
1291    }
1292
1293    public static void main(String JavaDoc[] args) throws Exception JavaDoc {
1294        // Parsing the command line
1295
CommandLine commandLine = new CommandLine(new NullParameterStrategy());
1296        commandLine.addToggleSwitch("minimize");
1297        commandLine.addToggleSwitch("maximize");
1298        commandLine.addSingleValueSwitch("encoding", com.jeantessier.dependency.XMLPrinter.DEFAULT_ENCODING);
1299        commandLine.addSingleValueSwitch("dtd-prefix", com.jeantessier.dependency.XMLPrinter.DEFAULT_DTD_PREFIX);
1300        commandLine.addSingleValueSwitch("indent-text");
1301        commandLine.addToggleSwitch("help");
1302
1303        CommandLineUsage usage = new CommandLineUsage("DependencyFinder");
1304        commandLine.accept(usage);
1305
1306        try {
1307            commandLine.parse(args);
1308        } catch (IllegalArgumentException JavaDoc ex) {
1309            showError(usage, ex.toString());
1310            System.exit(1);
1311        } catch (CommandLineException ex) {
1312            showError(usage, ex.toString());
1313            System.exit(1);
1314        }
1315
1316        if (commandLine.getToggleSwitch("help")) {
1317            showError(usage);
1318            System.exit(1);
1319        }
1320
1321        if (commandLine.getToggleSwitch("maximize") && commandLine.getToggleSwitch("minimize")) {
1322            showError(usage, "Only one of -maximize or -minimize allowed");
1323        }
1324
1325        /*
1326         * Beginning of main processing
1327         */

1328
1329        try {
1330            UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
1331        } catch (Exception JavaDoc ex) {
1332            // Ignore
1333
}
1334
1335        DependencyFinder model = new DependencyFinder(commandLine);
1336        model.setMaximize(commandLine.getToggleSwitch("maximize"));
1337        model.setMinimize(commandLine.getToggleSwitch("minimize"));
1338        model.setVisible(true);
1339    }
1340}
1341
Popular Tags