Thread: [Jarspy-commits] CVS: JarSpy/src/com/ociweb/jarspy/gui ClassesViewer.java,NONE,1.1 JarSpyGUI.java,1.
Status: Beta
Brought to you by:
brown_j
|
From: Jeff B. <br...@us...> - 2003-01-25 01:28:16
|
Update of /cvsroot/jarspy/JarSpy/src/com/ociweb/jarspy/gui
In directory sc8-pr-cvs1:/tmp/cvs-serv31272
Modified Files:
JarSpyGUI.java
Added Files:
ClassesViewer.java
Removed Files:
JarSpyClassList.java JarSpyListCellRenderer.java
Log Message:
significant refactoring of viewer code from JarSpyGUI into ClassesViewer
--- NEW FILE: ClassesViewer.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 com.ociweb.jarspy.JarInspector;
import com.ociweb.jarspy.gui.classdetails.ClassDetailsPanel;
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;
import java.awt.BorderLayout;
import java.awt.Component;
import java.awt.Container;
import java.awt.Cursor;
import java.awt.Font;
import java.io.File;
import java.io.IOException;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import javax.swing.BorderFactory;
import javax.swing.JComponent;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JSplitPane;
import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.JOptionPane;
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;
/**
* @author Jeff Brown
* @version $Id: ClassesViewer.java,v 1.1 2003/01/25 01:28:10 brown_j Exp $
*/
public class ClassesViewer extends JPanel
implements/* ListSelectionListener,*/ TreeSelectionListener {
// private JarInspector jarInspector = null;
private ClassDetailsPanel classDetailPanel;
// private JarSpyClassList classList;
private JarSpyClassTree classTree;
// private List jarFileSelectionListeners = new ArrayList();
private List classSelectionListeners = new ArrayList();
private JarSpyPreferences jarSpyPreferences = null;
private JSplitPane splitter = null;
public ClassesViewer(JarInspector jarInspector) {
super(new BorderLayout());
// this.jarInspector = jarInspector;
classDetailPanel = new ClassDetailsPanel(this);
classTree = new JarSpyClassTree(jarInspector);
// classList = new JarSpyClassList(jarInspector);
// classList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
Container cont = this;
splitter = new JSplitPane();
cont.add(BorderLayout.CENTER, splitter);
splitter.setRightComponent(classDetailPanel);
setJarViewComponent(classTree);
// classList.addListSelectionListener(this);
classTree.addTreeSelectionListener(this);
jarSpyPreferences = JarSpyPreferencesFactory.getPreferences();
int dividerLocation = jarSpyPreferences.getMainDividerLocation();
splitter.setDividerLocation(dividerLocation);
// if (initialFileToOpen == null) {
// if a file path was not passed on the command line...
// initialFileToOpen = jarSpyPreferences.getMostRecentJarFile();
// }
// if (initialFileToOpen != null) {
// try {
// File jarFile = new File(initialFileToOpen);
// if (jarFile.exists()) {
// setFile(jarFile);
// }
// } catch (IOException e) {
// e.printStackTrace();
// }
// }
}
public void setFile(File file) throws IOException {
classDetailPanel.jarFileSelectionChanged(file);
classTree.jarFileSelectionChanged(file);
// classList.jarFileSelectionChanged(file);
// jarInspector.setFile(file);
}
// public void addJarFileSelectionListener(JarFileSelectionListener l) {
// jarFileSelectionListeners.add(l);
// }
//
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 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);
}
public void savePreferences() {
jarSpyPreferences.saveMainDividerLocation(splitter.getDividerLocation());
}
private JComponent createClassViewPanel(Component viewComponent) {
JPanel classListPanel = new JPanel(new BorderLayout(0, 1));
JLabel classesLabel = new JLabel(" Classes:");
classesLabel.setBorder
(BorderFactory.createRaisedBevelBorder());
// classList.setFont(new Font("Courier", Font.PLAIN, 14));
classListPanel.add(BorderLayout.NORTH, classesLabel);
classListPanel.add(BorderLayout.CENTER, new JScrollPane(viewComponent));
classListPanel.setBorder
(BorderFactory.createRaisedBevelBorder());
return classListPanel;
}
/**
* Called whenever the value of the selection changes.
* @param tse 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();
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;
// notifyClassSelectionListeners(classInfo);
// } else if (o == null) {
// notifyClassSelectionListeners(null);
// }
// }
// setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
// }
}
Index: JarSpyGUI.java
===================================================================
RCS file: /cvsroot/jarspy/JarSpy/src/com/ociweb/jarspy/gui/JarSpyGUI.java,v
retrieving revision 1.46
retrieving revision 1.47
diff -C2 -d -r1.46 -r1.47
*** JarSpyGUI.java 3 Jan 2003 00:09:29 -0000 1.46
--- JarSpyGUI.java 25 Jan 2003 01:28:10 -0000 1.47
***************
*** 21,29 ****
import com.ociweb.gui.ChangeLookAndFeelAction;
import com.ociweb.gui.util.Splasher;
- import com.ociweb.jarspy.ClassInfo;
import com.ociweb.jarspy.JarInspector;
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;
--- 21,27 ----
***************
*** 32,46 ****
import com.ociweb.jarspy.gui.actions.ViewJarContentsAction;
import com.ociweb.jarspy.gui.actions.ViewManifestAction;
- import com.ociweb.jarspy.gui.classdetails.ClassDetailsPanel;
- 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;
import java.awt.BorderLayout;
- import java.awt.Component;
import java.awt.Container;
- import java.awt.Cursor;
import java.awt.Dimension;
- import java.awt.Font;
import java.awt.Point;
import java.awt.event.WindowListener;
--- 30,38 ----
***************
*** 54,80 ****
import java.util.jar.JarFile;
import javax.swing.Action;
- import javax.swing.BorderFactory;
import javax.swing.ImageIcon;
- import javax.swing.JComponent;
import javax.swing.JFrame;
- import javax.swing.JLabel;
- import javax.swing.JList;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
- import javax.swing.JPanel;
- import javax.swing.JScrollPane;
- import javax.swing.JSplitPane;
import javax.swing.JToolBar;
- import javax.swing.JTree;
- import javax.swing.ListSelectionModel;
import javax.swing.SwingUtilities;
import javax.swing.UIManager;
- 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;
/**
--- 46,58 ----
***************
*** 82,104 ****
* @version $Id$
*/
! public class JarSpyGUI extends JFrame
! implements ListSelectionListener, TreeSelectionListener {
private JarInspector jarInspector = new JarInspector();
- private ClassDetailsPanel 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;
public JarSpyGUI(String initialFileToOpen) {
super("JarSpy");
- classDetailPanel = new ClassDetailsPanel(this);
- classTree = new JarSpyClassTree(this, jarInspector);
- classList = new JarSpyClassList(this, jarInspector);
- classList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
try {
ImageIcon imageIcon =
--- 60,73 ----
* @version $Id$
*/
! public class JarSpyGUI extends JFrame {
private JarInspector jarInspector = new JarInspector();
private Map actions = new HashMap();
private List jarFileSelectionListeners = new ArrayList();
private JarSpyPreferences jarSpyPreferences = null;
! private ClassesViewer classesViewer = null;
public JarSpyGUI(String initialFileToOpen) {
super("JarSpy");
try {
ImageIcon imageIcon =
***************
*** 108,128 ****
// not a big deal...
}
createActions();
Container cont = getContentPane();
- splitter = new JSplitPane();
cont.add(BorderLayout.NORTH, createToolBar());
StatusBar sb = new StatusBar();
! addClassSelectionListener(sb);
addJarFileSelectionListener(sb);
cont.add(BorderLayout.SOUTH, sb);
! 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());
--- 77,93 ----
// not a big deal...
}
+ classesViewer = new ClassesViewer(jarInspector);
createActions();
Container cont = getContentPane();
cont.add(BorderLayout.NORTH, createToolBar());
StatusBar sb = new StatusBar();
! classesViewer.addClassSelectionListener(sb);
addJarFileSelectionListener(sb);
cont.add(BorderLayout.SOUTH, sb);
! cont.add(BorderLayout.CENTER, classesViewer);
addWindowListener((WindowListener)
actions.get(ActionNames.EXIT_ACTION));
setJMenuBar(createJMenuBar());
***************
*** 157,164 ****
setSize(size);
! int dividerLocation = jarSpyPreferences.getMainDividerLocation();
! splitter.setDividerLocation(dividerLocation);
!
! if(initialFileToOpen == null) {
// if a file path was not passed on the command line...
initialFileToOpen = jarSpyPreferences.getMostRecentJarFile();
--- 122,126 ----
setSize(size);
! if (initialFileToOpen == null) {
// if a file path was not passed on the command line...
initialFileToOpen = jarSpyPreferences.getMostRecentJarFile();
***************
*** 194,207 ****
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"));
}
--- 156,159 ----
***************
*** 229,239 ****
((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");
--- 181,184 ----
***************
*** 267,283 ****
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);
setTitle("JarSpy");
--- 212,221 ----
public void addClassSelectionListener(ClassSelectionListener l) {
! classesViewer.addClassSelectionListener(l);
}
public void setFile(File file) throws IOException {
notifyFileSelectionListeners(null);
+ classesViewer.setFile(null);
setTitle("JarSpy");
***************
*** 317,335 ****
}
- 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);
- }
-
private JToolBar createToolBar() {
JToolBar toolBar = new JToolBar();
--- 255,258 ----
***************
*** 358,369 ****
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)));
--- 281,284 ----
***************
*** 372,378 ****
private void savePreferences() {
jarSpyPreferences.saveMainWindowPosition(getLocation());
jarSpyPreferences.saveMainWindowSize(getSize());
- jarSpyPreferences.saveMainDividerLocation(splitter.getDividerLocation());
jarSpyPreferences.savePreferredLookAndFeel(UIManager.getLookAndFeel().getClass().getName());
JarFile jarFile = jarInspector.getJarFile();
--- 287,293 ----
private void savePreferences() {
+ classesViewer.savePreferences();
jarSpyPreferences.saveMainWindowPosition(getLocation());
jarSpyPreferences.saveMainWindowSize(getSize());
jarSpyPreferences.savePreferredLookAndFeel(UIManager.getLookAndFeel().getClass().getName());
JarFile jarFile = jarInspector.getJarFile();
***************
*** 384,437 ****
}
jarSpyPreferences.flush();
- }
-
- private JComponent createClassViewPanel(Component viewComponent) {
- JPanel classListPanel = new JPanel(new BorderLayout(0, 1));
-
- JLabel classesLabel = new JLabel(" Classes:");
- classesLabel.setBorder
- (BorderFactory.createRaisedBevelBorder());
- classList.setFont(new Font("Courier", Font.PLAIN, 14));
- classListPanel.add(BorderLayout.NORTH, classesLabel);
- classListPanel.add(BorderLayout.CENTER, new JScrollPane(viewComponent));
- classListPanel.setBorder
- (BorderFactory.createRaisedBevelBorder());
- return classListPanel;
- }
-
- /**
- * Called whenever the value of the selection changes.
- * @param tse 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();
- 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;
- notifyClassSelectionListeners(classInfo);
- } else if (o == null) {
- notifyClassSelectionListeners(null);
- }
- }
- setCursor(Cursor.getPredefinedCursor(Cursor.DEFAULT_CURSOR));
}
--- 299,302 ----
--- JarSpyClassList.java DELETED ---
--- JarSpyListCellRenderer.java DELETED ---
|