[Jarspy-commits] CVS: JarSpy/src/com/ociweb/jarspy/gui/tree JarSpyClassTree.java,NONE,1.1 JarSpyClas
Status: Beta
Brought to you by:
brown_j
|
From: Jeff B. <br...@us...> - 2002-07-20 18:12:27
|
Update of /cvsroot/jarspy/JarSpy/src/com/ociweb/jarspy/gui/tree
In directory usw-pr-cvs1:/tmp/cvs-serv12138/src/com/ociweb/jarspy/gui/tree
Added Files:
JarSpyClassTree.java JarSpyClassTreeNode.java
JarSpyPackageTreeNode.java JarSpyRootTreeNode.java
JarSpyTreeCellRenderer.java JarSpyTreeModel.java
JarSpyTreeNode.java
Log Message:
added new tree view option
--- NEW FILE: JarSpyClassTree.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.tree;
import com.ociweb.jarspy.ClassInfo;
import com.ociweb.jarspy.JarInspector;
import com.ociweb.jarspy.JarInspectorListener;
import com.ociweb.jarspy.gui.JarFileSelectionListener;
import com.ociweb.jarspy.gui.JarSpyGUI;
import javax.swing.JTree;
import javax.swing.tree.TreeCellRenderer;
import java.io.File;
/**
* A tree for displaying archive contents
*
* @version $Id: JarSpyClassTree.java,v 1.1 2002/07/20 18:12:23 brown_j Exp $
*/
public class JarSpyClassTree extends JTree
implements JarInspectorListener, JarFileSelectionListener {
public JarSpyClassTree(JarSpyGUI jarSpyGUI,
JarInspector inspector) {
inspector.addJarInspectorListener(this);
jarSpyGUI.addJarFileSelectionListener(this);
setModel(new JarSpyTreeModel());
}
public void setCellRenderer(TreeCellRenderer renderer) {
// wrap the real renderer in our renderer proxy class
// to enforce interfaces being displayed in italics...
if (renderer == null) {
super.setCellRenderer(null);
} else {
super.setCellRenderer(new JarSpyTreeCellRenderer(renderer));
}
}
/**
* Notify listener that a JarInspector has been updated
* @param inspector the JarInspector which has been updated
*/
public void jarInspectorUpdated(JarInspector jarInspector) {
ClassInfo[] classInfo = jarInspector.getClassInfo();
JarSpyTreeModel treeModel = new JarSpyTreeModel(jarInspector.getJarFile().getName(), classInfo);
setModel(treeModel);
}
public void addNotify() {
super.addNotify();
try {
clearSelection();
} catch (Exception e) {
}
}
public void jarFileSelectionChanged(File jarFile) {
if (jarFile == null) {
setModel(new JarSpyTreeModel());
}
}
}
--- NEW FILE: JarSpyClassTreeNode.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.tree;
import com.ociweb.jarspy.ClassInfo;
import javax.swing.tree.DefaultMutableTreeNode;
/**
* A tree node representing a class or interface in an archive
*
* @version $Id: JarSpyClassTreeNode.java,v 1.1 2002/07/20 18:12:23 brown_j Exp $
*/
public class JarSpyClassTreeNode extends DefaultMutableTreeNode {
private String simpleClassName;
public JarSpyClassTreeNode(ClassInfo classInfo) {
super(classInfo);
simpleClassName = classInfo.getSimpleClassName();
}
public ClassInfo getClassInfo() {
return (ClassInfo) getUserObject();
}
public String toString() {
return simpleClassName;
}
}
--- NEW FILE: JarSpyPackageTreeNode.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.tree;
import javax.swing.tree.DefaultMutableTreeNode;
import java.util.HashMap;
import java.util.Map;
/**
* A tree node representing a package in an archive
*
* @version $Id: JarSpyPackageTreeNode.java,v 1.1 2002/07/20 18:12:23 brown_j Exp $
*/
public class JarSpyPackageTreeNode extends DefaultMutableTreeNode {
private static final Map nodes = new HashMap();
private static final String DEFAULT_PACKAGE = "<default>";
private JarSpyPackageTreeNode(String name) {
super(name);
}
public boolean isLeaf() {
return false;
}
public String toString() {
return super.toString() + " (" + super.getLeafCount() + ")";
}
public static final JarSpyPackageTreeNode getPackageTreeNode(String packageName) {
if ("".equals(packageName)) {
packageName = DEFAULT_PACKAGE;
}
JarSpyPackageTreeNode packageNode = null;
synchronized (nodes) {
packageNode =
(JarSpyPackageTreeNode) nodes.get(packageName);
if (packageNode == null) {
packageNode = new JarSpyPackageTreeNode(packageName);
nodes.put(packageName, packageNode);
}
}
return packageNode;
}
public static void reset() {
synchronized (nodes) {
nodes.clear();
}
}
}
--- NEW FILE: JarSpyRootTreeNode.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.tree;
import com.ociweb.jarspy.ClassInfo;
import javax.swing.tree.TreeNode;
import java.util.Enumeration;
import java.util.Vector;
/**
* A node in a tree representing an archive
*
* @version $Id: JarSpyRootTreeNode.java,v 1.1 2002/07/20 18:12:23 brown_j Exp $
*/
public class JarSpyRootTreeNode implements JarSpyTreeNode {
private Vector packageNodes = new Vector();
private String jarName;
public JarSpyRootTreeNode(String jarName, ClassInfo[] classInfo) {
this.jarName = jarName;
JarSpyPackageTreeNode.reset();
createNodes(classInfo);
}
private void createNodes(ClassInfo[] classInfo) {
for (int i = 0; i < classInfo.length; i++) {
ClassInfo info = classInfo[i];
String fullyQualifiedName = info.getClassName();
int index = fullyQualifiedName.lastIndexOf('.');
String className = fullyQualifiedName.substring(index + 1);
String packageName = "";
if (index != -1) {
packageName = fullyQualifiedName.substring(0, index);
}
JarSpyPackageTreeNode packageNode =
JarSpyPackageTreeNode.getPackageTreeNode(packageName);
if (!packageNodes.contains(packageNode)) {
packageNodes.add(packageNode);
}
packageNode.add(new JarSpyClassTreeNode(info));
}
}
/**
* Returns the child <code>TreeNode</code> at index
* <code>childIndex</code>.
*/
public TreeNode getChildAt(int childIndex) {
JarSpyPackageTreeNode node =
(JarSpyPackageTreeNode) packageNodes.elementAt(childIndex);
return node;
}
/**
* Returns the number of children <code>TreeNode</code>s the receiver
* contains.
*/
public int getChildCount() {
return packageNodes.size();
}
/**
* Returns the parent <code>TreeNode</code> of the receiver.
*/
public TreeNode getParent() {
return null;
}
/**
* Returns the index of <code>node</code> in the receivers children.
* If the receiver does not contain <code>node</code>, -1 will be
* returned.
*/
public int getIndex(TreeNode node) {
return packageNodes.indexOf(node);
}
/**
* Returns true if the receiver allows children.
*/
public boolean getAllowsChildren() {
return true;
}
/**
* Returns true if the receiver is a leaf.
*/
public boolean isLeaf() {
return false;
}
/**
* Returns the children of the receiver as an <code>Enumeration</code>.
*/
public Enumeration children() {
return packageNodes.elements();
}
public String toString() {
return jarName;
}
}
--- NEW FILE: JarSpyTreeCellRenderer.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.tree;
import com.ociweb.jarspy.ClassInfo;
import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JTree;
import javax.swing.tree.TreeCellRenderer;
import java.awt.Component;
/**
* Renders cells in a JarSpyClassTree
*
* @verson $Id: JarSpyTreeCellRenderer.java,v 1.1 2002/07/20 18:12:23 brown_j Exp $
*/
class JarSpyTreeCellRenderer implements TreeCellRenderer {
private ImageIcon classIcon =
new ImageIcon(getClass().getResource("/com/ociweb/jarspy/gui/images/class_obj.gif"));
private ImageIcon interfaceIcon =
new ImageIcon(getClass().getResource("/com/ociweb/jarspy/gui/images/int_obj.gif"));
private ImageIcon packageIcon =
new ImageIcon(getClass().getResource("/com/ociweb/jarspy/gui/images/package_obj.gif"));
private ImageIcon archiveIcon =
new ImageIcon(getClass().getResource("/com/ociweb/jarspy/gui/images/Jar16.gif"));
private TreeCellRenderer realRenderer;
JarSpyTreeCellRenderer(TreeCellRenderer renderer) {
realRenderer = renderer;
}
/**
* Sets the value of the current tree cell to <code>value</code>.
* If <code>selected</code> is true, the cell will be drawn as if
* selected. If <code>expanded</code> is true the node is currently
* expanded and if <code>leaf</code> is true the node represets a
* leaf and if <code>hasFocus</code> is true the node currently has
* focus. <code>tree</code> is the <code>JTree</code> the receiver is being
* configured for. Returns the <code>Component</code> that the renderer
* uses to draw the value.
*
* @return the <code>Component</code> that the renderer uses to draw the value
*/
public Component getTreeCellRendererComponent(JTree tree,
Object value,
boolean selected,
boolean expanded,
boolean leaf,
int row,
boolean hasFocus) {
Component c = realRenderer.getTreeCellRendererComponent(tree,
value,
selected,
expanded,
leaf,
row,
hasFocus);
if (c instanceof JLabel) {
JLabel label = (JLabel) c;
try {
if (value instanceof JarSpyClassTreeNode) {
ClassInfo classInfo = ((JarSpyClassTreeNode) value).getClassInfo();
if (classInfo.isAnInterface()) {
label.setIcon(interfaceIcon);
} else {
label.setIcon(classIcon);
}
} else if (value instanceof JarSpyPackageTreeNode) {
label.setIcon(packageIcon);
} else if (value instanceof JarSpyRootTreeNode) {
label.setIcon(archiveIcon);
}
} catch (Exception e) {
}
}
return c;
}
}
--- NEW FILE: JarSpyTreeModel.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.tree;
import com.ociweb.jarspy.ClassInfo;
import javax.swing.tree.DefaultTreeModel;
/**
* The model for a JarSpyClassTree
*
* @version $Id: JarSpyTreeModel.java,v 1.1 2002/07/20 18:12:23 brown_j Exp $
*/
public class JarSpyTreeModel extends DefaultTreeModel {
public JarSpyTreeModel() {
this("<none>", new ClassInfo[0]);
}
public JarSpyTreeModel(String jarName, ClassInfo[] classInfo) {
super(new JarSpyRootTreeNode(jarName, classInfo));
}
}
--- NEW FILE: JarSpyTreeNode.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.tree;
import javax.swing.tree.TreeNode;
/**
* A node in a JarSpyClassTree
*
* @version $Id: JarSpyTreeNode.java,v 1.1 2002/07/20 18:12:23 brown_j Exp $
*/
public interface JarSpyTreeNode extends TreeNode {
}
|