[Jarspy-commits] CVS: JarSpy/src/com/ociweb/jarspy/gui/actions AboutAction.java,NONE,1.1 ActionNames
Status: Beta
Brought to you by:
brown_j
|
From: Jeff B. <br...@us...> - 2002-07-17 14:00:28
|
Update of /cvsroot/jarspy/JarSpy/src/com/ociweb/jarspy/gui/actions
In directory usw-pr-cvs1:/tmp/cvs-serv26270/com/ociweb/jarspy/gui/actions
Added Files:
AboutAction.java ActionNames.java DecompileAction.java
ExitAction.java ExtractArchiveAction.java JarSpyAction.java
OpenArchiveAction.java ViewJarContentsAction.java
ViewManifestAction.java
Log Message:
moved actions to their own package and adjusted access specifiers accordingly
--- NEW FILE: AboutAction.java ---
// JarSpy
// Copyright (c) 2001, 2002 Jeff S. Brown
// This file is part of JarSpy.
//
// JarSpy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// JarSpy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with JarSpy; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.ociweb.jarspy.gui.actions;
import com.ociweb.jarspy.gui.JarSpyGUI;
import com.ociweb.jarspy.gui.AboutJarSpy;
import java.awt.event.ActionEvent;
/**
* @author Jeff Brown
* @version $Id: AboutAction.java,v 1.1 2002/07/17 14:00:25 brown_j Exp $
*/
public class AboutAction extends JarSpyAction {
public AboutAction(JarSpyGUI gui) {
super(gui,
ActionNames.ABOUT_ACTION,
"images/question.gif",
false);
}
public void actionPerformed(ActionEvent ae) {
AboutJarSpy ajs = new AboutJarSpy(jarSpyGUI);
ajs.setVisible(true);
ajs.dispose();
}
}
--- NEW FILE: ActionNames.java ---
// JarSpy
// Copyright (c) 2001, 2002 Jeff S. Brown
// This file is part of JarSpy.
//
// JarSpy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// JarSpy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with JarSpy; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.ociweb.jarspy.gui.actions;
/**
* @author Jeff Brown
* @version $Id: ActionNames.java,v 1.1 2002/07/17 14:00:25 brown_j Exp $
*/
public interface ActionNames {
String OPEN_ARCHIVE_ACTION = "Open Archive";
String EXIT_ACTION = "Exit";
String ABOUT_ACTION = "About";
String VIEW_MANIFEST_ACTION = "View Manifest";
String EXTRACT_ARCHIVE_ACTION = "Extract Archive";
String DECOMPILE_ACTION = "Decompile Class";
String VIEW_JAR_CONTENTS_ACTION = "View Jar Contents";
}
--- NEW FILE: DecompileAction.java ---
// JarSpy
// Copyright (c) 2001, 2002 Jeff S. Brown
// This file is part of JarSpy.
//
// JarSpy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// JarSpy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with JarSpy; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.ociweb.jarspy.gui.actions;
import com.ociweb.jarspy.ClassInfo;
import com.ociweb.jarspy.JarInspector;
import com.ociweb.jarspy.gui.JarFileSelectionListener;
import com.ociweb.jarspy.gui.JarSpyGUI;
import com.ociweb.jarspy.gui.DecompileGUI;
import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
import java.awt.event.ActionEvent;
import java.io.File;
/**
* @author Jeff Brown
* @version $Id: DecompileAction.java,v 1.1 2002/07/17 14:00:25 brown_j Exp $
*/
public class DecompileAction extends JarSpyAction
implements JarFileSelectionListener, ListSelectionListener {
private String className;
private JList classList;
private String pathToJarFile;
private JarInspector jarInspector;
public DecompileAction(JarSpyGUI gui,
JList classList,
JarInspector jarInspector) {
super(gui,
ActionNames.DECOMPILE_ACTION,
"images/decompile.gif",
false);
this.jarInspector = jarInspector;
setEnabled(false);
this.classList = classList;
classList.addListSelectionListener(this);
}
public void jarFileSelectionChanged(File jarFile) {
super.jarFileSelectionChanged(jarFile);
if (jarFile != null) {
pathToJarFile = jarFile.getPath();
}
}
public void actionPerformed(ActionEvent ae) {
try {
// dec.decompile(className,
// new java.io.PrintWriter(System.out),
// null);
DecompileGUI dg = new DecompileGUI(jarSpyGUI,
className,
pathToJarFile,
jarInspector);
dg.setVisible(true);
dg.dispose();
} catch (Exception exc) {
JOptionPane.showMessageDialog(jarSpyGUI,
"ERROR: " + exc.getMessage(),
"Decompile Failed",
JOptionPane.ERROR_MESSAGE);
}
}
public void valueChanged(ListSelectionEvent lse) {
if (!lse.getValueIsAdjusting()) {
className = null;
Object o = classList.getSelectedValue();
if (o instanceof ClassInfo) {
setEnabled(true);
className = ((ClassInfo) o).getClassName();
} else {
setEnabled(false);
}
}
}
}
--- NEW FILE: ExitAction.java ---
// JarSpy
// Copyright (c) 2001, 2002 Jeff S. Brown
// This file is part of JarSpy.
//
// JarSpy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// JarSpy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with JarSpy; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.ociweb.jarspy.gui.actions;
import com.ociweb.jarspy.gui.JarSpyGUI;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
/**
* @author Jeff Brown
* @version $Id: ExitAction.java,v 1.1 2002/07/17 14:00:25 brown_j Exp $
*/
public class ExitAction extends JarSpyAction implements WindowListener {
public ExitAction(JarSpyGUI gui) {
super(gui, ActionNames.EXIT_ACTION, "images/exit.gif", false);
}
public void actionPerformed(ActionEvent ae) {
exitApplication();
}
public void windowClosing(WindowEvent we) {
exitApplication();
}
public void windowOpened(WindowEvent we) {
}
public void windowClosed(WindowEvent we) {
}
public void windowIconified(WindowEvent we) {
}
public void windowDeiconified(WindowEvent we) {
}
public void windowActivated(WindowEvent we) {
}
public void windowDeactivated(WindowEvent we) {
}
private void exitApplication() {
if (JOptionPane.showConfirmDialog(jarSpyGUI,
"Are You Sure You Want To Exit JarSpy?",
"Confirm Exit",
JOptionPane.YES_NO_OPTION) ==
JOptionPane.YES_OPTION) {
System.exit(0);
}
}
}
--- NEW FILE: ExtractArchiveAction.java ---
// JarSpy
// Copyright (c) 2001, 2002 Jeff S. Brown
// This file is part of JarSpy.
//
// JarSpy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// JarSpy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with JarSpy; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.ociweb.jarspy.gui.actions;
import com.ociweb.jarspy.JarInspector;
import com.ociweb.jarspy.gui.JarSpyGUI;
import javax.swing.*;
import java.awt.event.ActionEvent;
import java.io.File;
/**
* @author Jeff Brown
* @version $Id: ExtractArchiveAction.java,v 1.1 2002/07/17 14:00:25 brown_j Exp $
*/
public class ExtractArchiveAction extends JarSpyAction {
private final JarInspector jarInspector;
public ExtractArchiveAction(JarSpyGUI gui,
JarInspector inspector) {
super(gui,
ActionNames.EXTRACT_ARCHIVE_ACTION,
"images/extract.gif",
true);
jarInspector = inspector;
}
public void actionPerformed(ActionEvent ae) {
extractArchive();
}
private void extractArchive() {
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(chooser.DIRECTORIES_ONLY);
chooser.setDialogTitle("Extract Archive To...");
chooser.showOpenDialog(jarSpyGUI);
File file = chooser.getSelectedFile();
if (file != null) {
if (file.isDirectory()) {
try {
jarInspector.extractTo(file);
} catch (Exception exc) {
String msg = "Error occurred extracting archive!";
JOptionPane.showMessageDialog(jarSpyGUI,
msg,
"ERROR",
JOptionPane.ERROR_MESSAGE);
}
}
}
}
}
--- NEW FILE: JarSpyAction.java ---
// JarSpy
// Copyright (c) 2001, 2002 Jeff S. Brown
// This file is part of JarSpy.
//
// JarSpy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// JarSpy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with JarSpy; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.ociweb.jarspy.gui.actions;
import com.ociweb.jarspy.gui.JarFileSelectionListener;
import com.ociweb.jarspy.gui.JarSpyGUI;
import javax.swing.AbstractAction;
import javax.swing.ImageIcon;
import java.io.File;
/**
* @author Jeff Brown
* @version $Id: JarSpyAction.java,v 1.1 2002/07/17 14:00:25 brown_j Exp $
*/
public abstract class JarSpyAction extends AbstractAction
implements JarFileSelectionListener {
/**
* this flag indicates wether or not this action should be disabled
* when there is not an archive currently opened
*/
private boolean disabledWhenNoJarIsOpen = false;
/**
* the main gui
*/
protected JarSpyGUI jarSpyGUI;
/**
* @param gui the main GUI
* @param actionName the string name of this action
* @param imagePath the path to the image associated with this action
* @param disabledWhenNoJarIsOpen indicates wether or not this action
* should be disabled when there is not an archive currently open
*/
public JarSpyAction(JarSpyGUI gui,
String actionName,
String imagePath,
boolean disabledWhenNoJarIsOpen) {
super(actionName);
putValue(SMALL_ICON,
new ImageIcon(getClass().getResource(imagePath)));
putValue(SHORT_DESCRIPTION, actionName);
gui.addJarFileSelectionListener(this);
jarSpyGUI = gui;
this.disabledWhenNoJarIsOpen = disabledWhenNoJarIsOpen;
}
public void jarFileSelectionChanged(File jarFile) {
if (disabledWhenNoJarIsOpen) {
setEnabled(jarFile != null);
}
}
}
--- NEW FILE: OpenArchiveAction.java ---
// JarSpy
// Copyright (c) 2001, 2002 Jeff S. Brown
// This file is part of JarSpy.
//
// JarSpy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// JarSpy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with JarSpy; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.ociweb.jarspy.gui.actions;
import com.ociweb.jarspy.gui.JarSpyGUI;
import javax.swing.*;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.io.File;
/**
* @author Jeff Brown
* @version $Id: OpenArchiveAction.java,v 1.1 2002/07/17 14:00:25 brown_j Exp $
*/
public class OpenArchiveAction extends JarSpyAction {
private final JFileChooser fileChooser = new JFileChooser();
public OpenArchiveAction(JarSpyGUI gui) {
super(gui, ActionNames.OPEN_ARCHIVE_ACTION, "images/open.gif", false);
}
public void actionPerformed(ActionEvent ae) {
SwingUtilities.updateComponentTreeUI(fileChooser);
int returnVal = fileChooser.showOpenDialog(jarSpyGUI);
if (returnVal == fileChooser.APPROVE_OPTION) {
File file = null;
jarSpyGUI.setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
try {
file = fileChooser.getSelectedFile();
jarSpyGUI.setFile(file);
} catch (Exception exc) {
String msg = "File: " + (file != null ?
file.getName() :
"(unknown)") +
"\n" +
exc.getMessage();
JOptionPane.showMessageDialog(jarSpyGUI,
msg,
"ERROR",
JOptionPane.ERROR_MESSAGE);
} finally {
jarSpyGUI.setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
}
}
}
--- NEW FILE: ViewJarContentsAction.java ---
// JarSpy
// Copyright (c) 2001, 2002 Jeff S. Brown
// This file is part of JarSpy.
//
// JarSpy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// JarSpy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with JarSpy; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.ociweb.jarspy.gui.actions;
import com.ociweb.jarspy.gui.JarFileSelectionListener;
import com.ociweb.jarspy.gui.JarSpyGUI;
import com.ociweb.jarspy.gui.JarContentsTableModel;
import javax.swing.JDialog;
import javax.swing.JOptionPane;
import javax.swing.JScrollPane;
import javax.swing.JTable;
import javax.swing.table.TableModel;
import java.awt.Dimension;
import java.awt.Frame;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.IOException;
import java.util.jar.JarFile;
/*
* ViewJarContentsAction
*
* @version $Id: ViewJarContentsAction.java,v 1.1 2002/07/17 14:00:25 brown_j Exp $
*/
public class ViewJarContentsAction extends JarSpyAction
implements JarFileSelectionListener {
private File jarFile = null;
public ViewJarContentsAction(JarSpyGUI jarSpyGUI) {
super(jarSpyGUI,
ActionNames.VIEW_JAR_CONTENTS_ACTION,
"images/jarcontents.gif",
true);
setEnabled(false);
}
public void actionPerformed(ActionEvent e) {
if (jarFile == null) {
// should never happen because the action should
// be disabled when the file is null...
JOptionPane.showMessageDialog(null,
"Jar File Is Null!",
"Error Opening Jar File",
JOptionPane.ERROR_MESSAGE);
} else {
try {
JDialog dlg = new JDialog((Frame) null,
"Jar Contents",
true);
TableModel jarContentsModel = new JarContentsTableModel(new JarFile(jarFile));
JScrollPane scroller = new JScrollPane(new JTable(jarContentsModel));
scroller.setPreferredSize(new Dimension(400, 200));
dlg.getContentPane().add(scroller);
dlg.pack();
dlg.setVisible(true);
dlg.dispose();
} catch (IOException exc) {
JOptionPane.showMessageDialog(null,
"ERROR: " + exc.getMessage(),
"Failure",
JOptionPane.ERROR_MESSAGE);
}
}
}
public void jarFileSelectionChanged(File jarFile) {
super.jarFileSelectionChanged(jarFile);
this.jarFile = jarFile;
}
}
--- NEW FILE: ViewManifestAction.java ---
// JarSpy
// Copyright (c) 2001, 2002 Jeff S. Brown
// This file is part of JarSpy.
//
// JarSpy is free software; you can redistribute it and/or modify
// it under the terms of the GNU General Public License as published by
// the Free Software Foundation; either version 2 of the License, or
// (at your option) any later version.
//
// JarSpy is distributed in the hope that it will be useful,
// but WITHOUT ANY WARRANTY; without even the implied warranty of
// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
// GNU General Public License for more details.
//
// You should have received a copy of the GNU General Public License
// along with JarSpy; if not, write to the Free Software
// Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package com.ociweb.jarspy.gui.actions;
import com.ociweb.jarspy.JarInspector;
import com.ociweb.jarspy.gui.JarSpyGUI;
import com.ociweb.jarspy.gui.ManifestDialog;
import javax.swing.JOptionPane;
import java.awt.event.ActionEvent;
import java.io.File;
import java.util.jar.Manifest;
/**
* @author Jeff Brown
* @version $Id: ViewManifestAction.java,v 1.1 2002/07/17 14:00:25 brown_j Exp $
*/
public class ViewManifestAction extends JarSpyAction {
private JarInspector jarInspector;
public ViewManifestAction(JarSpyGUI gui,
JarInspector jarInspector) {
super(gui,
ActionNames.VIEW_MANIFEST_ACTION,
"images/manifest.gif",
true);
this.jarInspector = jarInspector;
setEnabled(false);
}
public void actionPerformed(ActionEvent ae) {
Manifest manifest = jarInspector.getManifest();
if (manifest == null) {
JOptionPane.showMessageDialog(jarSpyGUI,
"No Manifest Found.",
"Not Found",
JOptionPane.INFORMATION_MESSAGE);
} else {
ManifestDialog md = new ManifestDialog(jarSpyGUI, manifest);
md.setVisible(true);
md.dispose();
}
}
}
|