[Jarspy-commits] CVS: JarSpy/src/com/ociweb/jarspy/gui ClassSelectionListener.java,NONE,1.1 JarSpyLi
Status: Beta
Brought to you by:
brown_j
Update of /cvsroot/jarspy/JarSpy/src/com/ociweb/jarspy/gui
In directory usw-pr-cvs1:/tmp/cvs-serv12138/src/com/ociweb/jarspy/gui
Modified Files:
ClassDetailPanel.java JarSpyClassList.java JarSpyGUI.java
Added Files:
ClassSelectionListener.java JarSpyListCellRenderer.java
Log Message:
added new tree view option
--- NEW FILE: ClassSelectionListener.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;
import com.ociweb.jarspy.ClassInfo;
/**
* ClassSelectionListeners are notified any time the class selection changes
* in the ui.
*
* @version $Id: ClassSelectionListener.java,v 1.1 2002/07/20 18:12:23 brown_j Exp $
*/
public interface ClassSelectionListener {
public void classSelected(ClassInfo classInfo);
}
--- NEW FILE: JarSpyListCellRenderer.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;
import com.ociweb.jarspy.ClassInfo;
import javax.swing.ListCellRenderer;
import javax.swing.ImageIcon;
import javax.swing.JList;
import javax.swing.JLabel;
import java.awt.Component;
import java.awt.Font;
/**
* This renderer delegates to another renderer. The other renderer
* is responsible for creating the render component. This wrapper
* modifies the font of the component generated by the real renderer
* to display interfaces in italic and classes in non italic.
*
* @version $Id: JarSpyListCellRenderer.java,v 1.1 2002/07/20 18:12:23 brown_j Exp $
*/
class JarSpyListCellRenderer implements ListCellRenderer {
ImageIcon classIcon =
new ImageIcon(getClass().getResource("/com/ociweb/jarspy/gui/images/class_obj.gif"));
ImageIcon interfaceIcon =
new ImageIcon(getClass().getResource("/com/ociweb/jarspy/gui/images/int_obj.gif"));
private final ListCellRenderer realRenderer;
JarSpyListCellRenderer(ListCellRenderer realRenderer) {
this.realRenderer = realRenderer;
}
public Component getListCellRendererComponent(
JList list,
Object value,
int index,
boolean isSelected,
boolean cellHasFocus) {
Component c =
realRenderer.getListCellRendererComponent(list,
value,
index,
isSelected,
cellHasFocus);
if (c instanceof JLabel) {
JLabel label = (JLabel) c;
// this should always be true...
if (value instanceof ClassInfo) {
ClassInfo classInfo = (ClassInfo) value;
if (classInfo.isAnInterface()) {
// if this is an interface, then use italics...
Font font = label.getFont();
label.setFont(font.deriveFont(Font.ITALIC));
label.setIcon(interfaceIcon);
} else {
label.setIcon(classIcon);
}
}
}
return c;
}
}
Index: ClassDetailPanel.java
===================================================================
RCS file: /cvsroot/jarspy/JarSpy/src/com/ociweb/jarspy/gui/ClassDetailPanel.java,v
retrieving revision 1.5
retrieving revision 1.6
diff -C2 -d -r1.5 -r1.6
*** ClassDetailPanel.java 19 Jun 2002 01:19:10 -0000 1.5
--- ClassDetailPanel.java 20 Jul 2002 18:12:23 -0000 1.6
***************
*** 23,26 ****
--- 23,27 ----
import javax.swing.*;
import java.awt.*;
+ import java.io.File;
/**
***************
*** 28,32 ****
* @version $Id$
*/
! class ClassDetailPanel extends JPanel {
DetailPanel fieldsPanel = new DetailPanel(" Fields:");
--- 29,34 ----
* @version $Id$
*/
! class ClassDetailPanel extends JPanel
! implements ClassSelectionListener, JarFileSelectionListener {
DetailPanel fieldsPanel = new DetailPanel(" Fields:");
***************
*** 34,42 ****
DetailPanel dependenciesPanel = new DetailPanel(" Dependencies:");
! public ClassDetailPanel() {
super(new GridLayout(0, 1, 0, 5));
add(fieldsPanel);
add(methodsPanel);
add(dependenciesPanel);
}
--- 36,47 ----
DetailPanel dependenciesPanel = new DetailPanel(" Dependencies:");
! public ClassDetailPanel(JarSpyGUI jarSpyGUI) {
super(new GridLayout(0, 1, 0, 5));
+ jarSpyGUI.addClassSelectionListener(this);
+ jarSpyGUI.addJarFileSelectionListener(this);
add(fieldsPanel);
add(methodsPanel);
add(dependenciesPanel);
+
}
***************
*** 51,54 ****
--- 56,72 ----
methodsPanel.update(classInfo.getMethods());
dependenciesPanel.update(classInfo.getDependencies());
+ }
+
+ public void classSelected(ClassInfo classInfo) {
+ clear();
+ if(classInfo != null) {
+ setClassInfo(classInfo);
+ }
+ }
+
+ public void jarFileSelectionChanged(File jarFile) {
+ if(jarFile == null) {
+ clear();
+ }
}
}
Index: JarSpyClassList.java
===================================================================
RCS file: /cvsroot/jarspy/JarSpy/src/com/ociweb/jarspy/gui/JarSpyClassList.java,v
retrieving revision 1.1
retrieving revision 1.2
diff -C2 -d -r1.1 -r1.2
*** JarSpyClassList.java 15 Jul 2002 22:22:24 -0000 1.1
--- JarSpyClassList.java 20 Jul 2002 18:12:23 -0000 1.2
***************
*** 2,10 ****
--- 2,17 ----
import com.ociweb.jarspy.ClassInfo;
+ import com.ociweb.jarspy.JarInspector;
+ import com.ociweb.jarspy.JarInspectorListener;
+ import javax.swing.DefaultListModel;
+ import javax.swing.ImageIcon;
+ import javax.swing.JLabel;
import javax.swing.JList;
import javax.swing.ListCellRenderer;
+ import javax.swing.ListModel;
import java.awt.Component;
import java.awt.Font;
+ import java.io.File;
/**
***************
*** 12,61 ****
* of classes in JarSpy
*/
! public class JarSpyClassList extends JList {
! /**
! * This renderer delegates to another renderer. The other renderer
! * is responsible for creating the render component. This wrapper
! * modifies the font of the component generated by the real renderer
! * to display interfaces in italic and classes in non italic.
! */
! private class JarSpyListCellRenderer implements ListCellRenderer {
! private final ListCellRenderer realRenderer;
! JarSpyListCellRenderer(ListCellRenderer realRenderer) {
! this.realRenderer = realRenderer;
}
- public Component getListCellRendererComponent(
- JList list,
- Object value,
- int index,
- boolean isSelected,
- boolean cellHasFocus) {
- Component c =
- realRenderer.getListCellRendererComponent(list,
- value,
- index,
- isSelected,
- cellHasFocus);
! // this should always be true...
! if (value instanceof ClassInfo) {
! ClassInfo classInfo = (ClassInfo) value;
! // if this is an interface, then use italics...
! if (classInfo.isAnInterface()) {
! Font font = c.getFont();
! c.setFont(font.deriveFont(Font.ITALIC));
! }
! }
! return c;
}
}
! public void setCellRenderer(ListCellRenderer renderer) {
! // wrap the real renderer in our renderer proxy class
! // to enforce interfaces being displayed in italics...
! super.setCellRenderer(new JarSpyListCellRenderer(renderer));
}
}
--- 19,65 ----
* of classes in JarSpy
*/
! public class JarSpyClassList extends JList
! implements JarInspectorListener, JarFileSelectionListener {
! public JarSpyClassList(JarSpyGUI jarSpyGUI, JarInspector inspector) {
! inspector.addJarInspectorListener(this);
! jarSpyGUI.addJarFileSelectionListener(this);
! }
! public void setCellRenderer(ListCellRenderer renderer) {
! // wrap the real renderer in our renderer proxy class
! // to enforce interfaces being displayed in italics...
! super.setCellRenderer(new JarSpyListCellRenderer(renderer));
! }
! /**
! * Notify listener that a JarInspector has been updated
! * @param inspector the JarInspector which has been updated
! */
! public void jarInspectorUpdated(JarInspector jarInspector) {
! DefaultListModel listModel = new DefaultListModel();
! ClassInfo[] classInfo = jarInspector.getClassInfo();
! for (int i = 0; i < classInfo.length; i++) {
! listModel.addElement(classInfo[i]);
}
+ setModel(listModel);
+ }
! public void addNotify() {
! super.addNotify();
! try {
! clearSelection();
! } catch (Exception e) {
}
}
! public void jarFileSelectionChanged(File jarFile) {
! if (jarFile == null) {
! ListModel model = getModel();
! if (model instanceof DefaultListModel) {
! ((DefaultListModel) model).removeAllElements();
! }
! }
}
}
Index: JarSpyGUI.java
===================================================================
RCS file: /cvsroot/jarspy/JarSpy/src/com/ociweb/jarspy/gui/JarSpyGUI.java,v
retrieving revision 1.32
retrieving revision 1.33
diff -C2 -d -r1.32 -r1.33
*** JarSpyGUI.java 20 Jul 2002 00:09:00 -0000 1.32
--- JarSpyGUI.java 20 Jul 2002 18:12:23 -0000 1.33
***************
*** 25,28 ****
--- 25,29 ----
import com.ociweb.jarspy.gui.actions.AboutAction;
import com.ociweb.jarspy.gui.actions.ActionNames;
+ import com.ociweb.jarspy.gui.actions.ChangeJarViewerComponentAction;
import com.ociweb.jarspy.gui.actions.DecompileAction;
import com.ociweb.jarspy.gui.actions.ExitAction;
***************
*** 31,34 ****
--- 32,37 ----
import com.ociweb.jarspy.gui.actions.ViewJarContentsAction;
import com.ociweb.jarspy.gui.actions.ViewManifestAction;
+ import com.ociweb.jarspy.gui.tree.JarSpyClassTree;
+ import com.ociweb.jarspy.gui.tree.JarSpyClassTreeNode;
import com.ociweb.jarspy.preferences.JarSpyPreferences;
import com.ociweb.jarspy.preferences.JarSpyPreferencesFactory;
***************
*** 36,40 ****
import javax.swing.Action;
import javax.swing.BorderFactory;
- import javax.swing.DefaultListModel;
import javax.swing.ImageIcon;
import javax.swing.JComponent;
--- 39,42 ----
***************
*** 50,54 ****
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
! import javax.swing.ListModel;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
--- 52,56 ----
import javax.swing.JSplitPane;
import javax.swing.JToolBar;
! import javax.swing.JTree;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
***************
*** 56,60 ****
--- 58,66 ----
import javax.swing.event.ListSelectionEvent;
import javax.swing.event.ListSelectionListener;
+ import javax.swing.event.TreeSelectionEvent;
+ import javax.swing.event.TreeSelectionListener;
+ import javax.swing.tree.TreePath;
import java.awt.BorderLayout;
+ import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
***************
*** 65,68 ****
--- 71,75 ----
import java.io.File;
import java.io.IOException;
+ import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.HashMap;
***************
*** 70,74 ****
import java.util.Map;
import java.util.jar.JarFile;
- import java.lang.reflect.InvocationTargetException;
/**
--- 77,80 ----
***************
*** 77,87 ****
*/
public class JarSpyGUI extends JFrame
! implements ListSelectionListener {
private JarInspector jarInspector = new JarInspector();
! private ClassDetailPanel classDetailPanel = new ClassDetailPanel();
private Map actions = new HashMap();
! private JList classList = new JarSpyClassList();
private List jarFileSelectionListeners = new ArrayList();
private JarSpyPreferences jarSpyPreferences = null;
private JSplitPane splitter = null;
--- 83,95 ----
*/
public class JarSpyGUI extends JFrame
! implements ListSelectionListener, TreeSelectionListener {
private JarInspector jarInspector = new JarInspector();
! private ClassDetailPanel classDetailPanel;
private Map actions = new HashMap();
! private JList classList;
! private JTree classTree;
private List jarFileSelectionListeners = new ArrayList();
+ private List classSelectionListeners = new ArrayList();
private JarSpyPreferences jarSpyPreferences = null;
private JSplitPane splitter = null;
***************
*** 89,92 ****
--- 97,103 ----
public JarSpyGUI() {
super("JarSpy");
+ classDetailPanel = new ClassDetailPanel(this);
+ classTree = new JarSpyClassTree(this, jarInspector);
+ classList = new JarSpyClassList(this, jarInspector);
classList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
try {
***************
*** 103,112 ****
cont.add(BorderLayout.NORTH, createToolBar());
cont.add(BorderLayout.CENTER, splitter);
- splitter.setLeftComponent(createClassListPanel());
splitter.setRightComponent(classDetailPanel);
!
addWindowListener((WindowListener)
actions.get(ActionNames.EXIT_ACTION));
classList.addListSelectionListener(this);
setJMenuBar(createJMenuBar());
--- 114,123 ----
cont.add(BorderLayout.NORTH, createToolBar());
cont.add(BorderLayout.CENTER, splitter);
splitter.setRightComponent(classDetailPanel);
! setJarViewComponent(classTree);
addWindowListener((WindowListener)
actions.get(ActionNames.EXIT_ACTION));
classList.addListSelectionListener(this);
+ classTree.addTreeSelectionListener(this);
setJMenuBar(createJMenuBar());
***************
*** 170,176 ****
new AboutAction(this));
actions.put(ActionNames.DECOMPILE_ACTION,
! new DecompileAction(this, classList, jarInspector));
actions.put(ActionNames.VIEW_JAR_CONTENTS_ACTION,
new ViewJarContentsAction(this));
}
--- 181,197 ----
new AboutAction(this));
actions.put(ActionNames.DECOMPILE_ACTION,
! new DecompileAction(this, classTree, jarInspector));
actions.put(ActionNames.VIEW_JAR_CONTENTS_ACTION,
new ViewJarContentsAction(this));
+ actions.put(ActionNames.SHOW_JAR_LIST_VIEW,
+ new ChangeJarViewerComponentAction(this,
+ ActionNames.SHOW_JAR_LIST_VIEW,
+ classList,
+ "/com/ociweb/jarspy/gui/images/list_mode.gif"));
+ actions.put(ActionNames.SHOW_JAR_TREE_VIEW,
+ new ChangeJarViewerComponentAction(this,
+ ActionNames.SHOW_JAR_TREE_VIEW,
+ classTree,
+ "/com/ociweb/jarspy/gui/images/tree_mode.gif"));
}
***************
*** 185,195 ****
menu.add(new JMenuItem
((Action) actions.get(ActionNames.EXTRACT_ARCHIVE_ACTION)));
- menu.add(new JMenuItem
- ((Action) actions.get(ActionNames.DECOMPILE_ACTION)));
menu.addSeparator();
menu.add(new JMenuItem
((Action) actions.get(ActionNames.EXIT_ACTION)));
! menu = new JMenu("View");
menuBar.add(menu);
menu.add(new JMenuItem
--- 206,214 ----
menu.add(new JMenuItem
((Action) actions.get(ActionNames.EXTRACT_ARCHIVE_ACTION)));
menu.addSeparator();
menu.add(new JMenuItem
((Action) actions.get(ActionNames.EXIT_ACTION)));
! menu = new JMenu("Inspect");
menuBar.add(menu);
menu.add(new JMenuItem
***************
*** 197,200 ****
--- 216,228 ----
menu.add(new JMenuItem
((Action) actions.get(ActionNames.VIEW_JAR_CONTENTS_ACTION)));
+ menu.add(new JMenuItem
+ ((Action) actions.get(ActionNames.DECOMPILE_ACTION)));
+
+ menu = new JMenu("View");
+ menuBar.add(menu);
+ menu.add(new JMenuItem
+ ((Action) actions.get(ActionNames.SHOW_JAR_LIST_VIEW)));
+ menu.add(new JMenuItem
+ ((Action) actions.get(ActionNames.SHOW_JAR_TREE_VIEW)));
menu = new JMenu("Look And Feel");
***************
*** 228,231 ****
--- 256,271 ----
}
+ public void addClassSelectionListener(ClassSelectionListener l) {
+ classSelectionListeners.add(l);
+ }
+
+ private void notifyClassSelectionListeners(ClassInfo classInfo) {
+ for (int i = 0; i < classSelectionListeners.size(); i++) {
+ ClassSelectionListener listener =
+ (ClassSelectionListener) classSelectionListeners.get(i);
+ listener.classSelected(classInfo);
+ }
+ }
+
public void setFile(File file) throws IOException {
notifyFileSelectionListeners(null);
***************
*** 235,239 ****
final StatusScreen ss = new StatusScreen(JarSpyGUI.this);
try {
- clearLists();
jarInspector.setProcessingListener(ss);
SwingUtilities.invokeAndWait(new Runnable() {
--- 275,278 ----
***************
*** 243,247 ****
});
jarInspector.setFile(file);
- refreshClassList();
notifyFileSelectionListeners(file);
setTitle("JarSpy - " + file.getName());
--- 282,285 ----
***************
*** 267,285 ****
}
! private void clearLists() {
! classDetailPanel.clear();
! ListModel model = classList.getModel();
! if (model instanceof DefaultListModel) {
! ((DefaultListModel) model).removeAllElements();
! }
! }
! private void refreshClassList() {
! DefaultListModel listModel = new DefaultListModel();
! ClassInfo[] classInfo = jarInspector.getClassInfo();
! for (int i = 0; i < classInfo.length; i++) {
! listModel.addElement(classInfo[i]);
! }
! classList.setModel(listModel);
}
--- 305,321 ----
}
! public void setJarViewComponent(Component viewComponent) {
! notifyClassSelectionListeners(null);
! int location = splitter.getDividerLocation();
! JComponent viewPanel = createClassViewPanel(viewComponent);
! // update the components UI in case the look and feel has
! // changed. if the look and feel changes while the component
! // is not in the container, the components ui will not have been
! // updated yet
! SwingUtilities.updateComponentTreeUI(viewPanel);
!
! splitter.setLeftComponent(viewPanel);
! splitter.setDividerLocation(location);
}
***************
*** 310,313 ****
--- 346,357 ----
toolBar.add(new JarSpyToolbarButton
+ ((Action)actions.get(ActionNames.SHOW_JAR_TREE_VIEW)));
+
+ toolBar.add(new JarSpyToolbarButton
+ ((Action)actions.get(ActionNames.SHOW_JAR_LIST_VIEW)));
+
+ toolBar.addSeparator();
+
+ toolBar.add(new JarSpyToolbarButton
((Action) actions.get(ActionNames.ABOUT_ACTION)));
***************
*** 328,333 ****
}
! private JComponent createClassListPanel() {
!
JPanel classListPanel = new JPanel(new BorderLayout(0, 1));
--- 372,376 ----
}
! private JComponent createClassViewPanel(Component viewComponent) {
JPanel classListPanel = new JPanel(new BorderLayout(0, 1));
***************
*** 337,341 ****
classList.setFont(new Font("Courier", Font.PLAIN, 14));
classListPanel.add(BorderLayout.NORTH, classesLabel);
! classListPanel.add(BorderLayout.CENTER, new JScrollPane(classList));
classListPanel.setBorder
(BorderFactory.createRaisedBevelBorder());
--- 380,384 ----
classList.setFont(new Font("Courier", Font.PLAIN, 14));
classListPanel.add(BorderLayout.NORTH, classesLabel);
! classListPanel.add(BorderLayout.CENTER, new JScrollPane(viewComponent));
classListPanel.setBorder
(BorderFactory.createRaisedBevelBorder());
***************
*** 343,352 ****
}
public void valueChanged(ListSelectionEvent lse) {
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
if (!lse.getValueIsAdjusting()) {
Object o = classList.getSelectedValue();
if (o instanceof ClassInfo) {
! classDetailPanel.setClassInfo((ClassInfo) o);
}
}
--- 386,422 ----
}
+ /**
+ * Called whenever the value of the selection changes.
+ * @param e the event that characterizes the change.
+ */
+ public void valueChanged(TreeSelectionEvent tse) {
+ setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+ TreePath path = tse.getNewLeadSelectionPath();
+ if (path != null) {
+ Object o = path.getLastPathComponent();
+ if (o instanceof JarSpyClassTreeNode) {
+ JarSpyClassTreeNode jctn = (JarSpyClassTreeNode) o;
+ ClassInfo classInfo = jctn.getClassInfo();
+ classDetailPanel.setClassInfo(classInfo);
+ notifyClassSelectionListeners(classInfo);
+ } else {
+ notifyClassSelectionListeners(null);
+ }
+ }
+ setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
+ }
+
public void valueChanged(ListSelectionEvent lse) {
+
setCursor(Cursor.getPredefinedCursor(Cursor.WAIT_CURSOR));
+
if (!lse.getValueIsAdjusting()) {
Object o = classList.getSelectedValue();
if (o instanceof ClassInfo) {
! ClassInfo classInfo = (ClassInfo) o;
! classDetailPanel.setClassInfo(classInfo);
! notifyClassSelectionListeners(classInfo);
! } else if (o == null) {
! notifyClassSelectionListeners(null);
}
}
***************
*** 370,372 ****
--- 440,444 ----
JarSpyGUI jvg = new JarSpyGUI();
}
+
+
}
|