001: /*
002: * Copyright (c) 2001-2007, Jean Tessier
003: * All rights reserved.
004: *
005: * Redistribution and use in source and binary forms, with or without
006: * modification, are permitted provided that the following conditions
007: * are met:
008: *
009: * * Redistributions of source code must retain the above copyright
010: * notice, this list of conditions and the following disclaimer.
011: *
012: * * Redistributions in binary form must reproduce the above copyright
013: * notice, this list of conditions and the following disclaimer in the
014: * documentation and/or other materials provided with the distribution.
015: *
016: * * Neither the name of Jean Tessier nor the names of his contributors
017: * may be used to endorse or promote products derived from this software
018: * without specific prior written permission.
019: *
020: * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
021: * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
022: * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR
023: * A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR
024: * CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
025: * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO,
026: * PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR
027: * PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF
028: * LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
029: * NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS
030: * SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
031: */
032:
033: package com.jeantessier.dependencyfinder.gui;
034:
035: import java.awt.event.*;
036: import java.io.*;
037: import java.util.*;
038:
039: import javax.swing.*;
040:
041: import com.jeantessier.classreader.*;
042: import com.jeantessier.dependency.*;
043:
044: public class DependencyExtractAction extends AbstractAction implements
045: Runnable {
046: private DependencyFinder model;
047:
048: public DependencyExtractAction(DependencyFinder model) {
049: this .model = model;
050:
051: putValue(Action.LONG_DESCRIPTION,
052: "Extract dependencies from compiled classes");
053: putValue(Action.NAME, "Extract");
054: putValue(Action.SMALL_ICON, new ImageIcon(getClass()
055: .getResource("icons/extract.gif")));
056: }
057:
058: public void actionPerformed(ActionEvent e) {
059: JFileChooser chooser;
060: if (model.getInputFiles().isEmpty()) {
061: chooser = new JFileChooser(new File("."));
062: } else {
063: chooser = new JFileChooser(model.getInputFiles().iterator()
064: .next());
065: }
066: chooser.addChoosableFileFilter(new JavaBytecodeFileFilter());
067: chooser
068: .setFileSelectionMode(JFileChooser.FILES_AND_DIRECTORIES);
069: chooser.setMultiSelectionEnabled(true);
070: int returnValue = chooser.showDialog(model, "Extract");
071: if (returnValue == JFileChooser.APPROVE_OPTION) {
072: for (File file : chooser.getSelectedFiles()) {
073: model.addInputFile(file);
074: }
075: new Thread(this ).start();
076: }
077: }
078:
079: public void run() {
080: Date start = new Date();
081:
082: model.getStatusLine().showInfo("Scanning ...");
083: ClassfileScanner scanner = new ClassfileScanner();
084: scanner.load(model.getInputFiles());
085:
086: model.getProgressBar().setMaximum(scanner.getNbFiles());
087:
088: model.getMonitor().setClosedSession(false);
089:
090: ClassfileLoader loader = new TransientClassfileLoader(model
091: .getClassfileLoaderDispatcher());
092: loader.addLoadListener(new VerboseListener(model
093: .getStatusLine(), model.getProgressBar()));
094: loader.addLoadListener(model.getMonitor());
095: loader.load(model.getInputFiles());
096:
097: if (model.getMaximize()) {
098: model.getStatusLine().showInfo("Maximizing ...");
099: new LinkMaximizer().traverseNodes(model.getPackages());
100: } else if (model.getMinimize()) {
101: model.getStatusLine().showInfo("Minimizing ...");
102: new LinkMinimizer().traverseNodes(model.getPackages());
103: }
104:
105: Date stop = new Date();
106:
107: model
108: .getStatusLine()
109: .showInfo(
110: "Done ("
111: + ((stop.getTime() - start.getTime()) / (double) 1000)
112: + " secs).");
113: model.setTitle("Dependency Finder - Extractor");
114: }
115: }
|