|
|
@ -31,12 +31,31 @@ import javax.swing.event.TreeModelEvent; |
|
|
|
///import com.sun.java.swing.event.TreeModelListener;
|
|
|
|
///import com.sun.java.swing.event.TreeModelListener;
|
|
|
|
///import com.sun.java.swing.event.TreeModelEvent;
|
|
|
|
///import com.sun.java.swing.event.TreeModelEvent;
|
|
|
|
///#endif
|
|
|
|
///#endif
|
|
|
|
import java.util.*; |
|
|
|
|
|
|
|
|
|
|
|
///#ifdef JDK12
|
|
|
|
|
|
|
|
///import java.util.Arrays;
|
|
|
|
|
|
|
|
///import java.util.TreeSet;
|
|
|
|
|
|
|
|
///import java.util.HashSet;
|
|
|
|
|
|
|
|
///import java.util.Set;
|
|
|
|
|
|
|
|
///import java.util.HashMap;
|
|
|
|
|
|
|
|
///import java.util.Map;
|
|
|
|
|
|
|
|
///#else
|
|
|
|
|
|
|
|
import jode.util.Comparable; |
|
|
|
|
|
|
|
import jode.util.Arrays; |
|
|
|
|
|
|
|
import jode.util.TreeSet; |
|
|
|
|
|
|
|
import jode.util.HashSet; |
|
|
|
|
|
|
|
import jode.util.Set; |
|
|
|
|
|
|
|
import jode.util.HashMap; |
|
|
|
|
|
|
|
import jode.util.Map; |
|
|
|
|
|
|
|
///#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.Enumeration; |
|
|
|
|
|
|
|
import java.util.NoSuchElementException; |
|
|
|
|
|
|
|
|
|
|
|
public class PackagesTreeModel implements TreeModel { |
|
|
|
public class PackagesTreeModel implements TreeModel { |
|
|
|
Hashtable cachedChildrens = new Hashtable(); |
|
|
|
Map cachedChildrens = new HashMap(); |
|
|
|
|
|
|
|
|
|
|
|
class TreeElement { |
|
|
|
class TreeElement implements Comparable { |
|
|
|
String fullName; |
|
|
|
String fullName; |
|
|
|
String name; |
|
|
|
String name; |
|
|
|
boolean leaf; |
|
|
|
boolean leaf; |
|
|
@ -73,7 +92,7 @@ public class PackagesTreeModel implements TreeModel { |
|
|
|
|
|
|
|
|
|
|
|
public boolean equals(Object o) { |
|
|
|
public boolean equals(Object o) { |
|
|
|
return (o instanceof TreeElement) |
|
|
|
return (o instanceof TreeElement) |
|
|
|
&& fullName == ((TreeElement)o).fullName; |
|
|
|
&& fullName.equals(((TreeElement)o).fullName); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public int hashCode() { |
|
|
|
public int hashCode() { |
|
|
@ -82,14 +101,14 @@ public class PackagesTreeModel implements TreeModel { |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
TreeElement root = new TreeElement("", "", false); |
|
|
|
TreeElement root = new TreeElement("", "", false); |
|
|
|
Vector listeners = new Vector(); |
|
|
|
Set listeners = new HashSet(); |
|
|
|
|
|
|
|
|
|
|
|
public void rebuild() { |
|
|
|
public void rebuild() { |
|
|
|
cachedChildrens.clear(); |
|
|
|
cachedChildrens.clear(); |
|
|
|
TreeModelListener[] ls; |
|
|
|
TreeModelListener[] ls; |
|
|
|
synchronized (listeners) { |
|
|
|
synchronized (listeners) { |
|
|
|
ls = new TreeModelListener[listeners.size()]; |
|
|
|
ls = (TreeModelListener[]) |
|
|
|
listeners.copyInto(ls); |
|
|
|
listeners.toArray(new TreeModelListener[listeners.size()]); |
|
|
|
} |
|
|
|
} |
|
|
|
TreeModelEvent ev = new TreeModelEvent(this, new Object[] { root }); |
|
|
|
TreeModelEvent ev = new TreeModelEvent(this, new Object[] { root }); |
|
|
|
for (int i=0; i< ls.length; i++) |
|
|
|
for (int i=0; i< ls.length; i++) |
|
|
@ -100,45 +119,32 @@ public class PackagesTreeModel implements TreeModel { |
|
|
|
TreeElement[] result = |
|
|
|
TreeElement[] result = |
|
|
|
(TreeElement[]) cachedChildrens.get(parent); |
|
|
|
(TreeElement[]) cachedChildrens.get(parent); |
|
|
|
if (result == null) { |
|
|
|
if (result == null) { |
|
|
|
Vector v = new Vector(); |
|
|
|
TreeSet v = new TreeSet(); |
|
|
|
String prefix = parent == root ? "" : parent.getFullName() + "."; |
|
|
|
String prefix = parent == root ? "" : parent.getFullName() + "."; |
|
|
|
Enumeration enum = |
|
|
|
Enumeration enum = |
|
|
|
ClassInfo.getClassesAndPackages(parent.getFullName()); |
|
|
|
ClassInfo.getClassesAndPackages(parent.getFullName()); |
|
|
|
while (enum.hasMoreElements()) { |
|
|
|
while (enum.hasMoreElements()) { |
|
|
|
//insert sorted and remove double elements;
|
|
|
|
//insert sorted and remove double elements;
|
|
|
|
String name = (String)enum.nextElement(); |
|
|
|
String name = (String)enum.nextElement(); |
|
|
|
String fqn = prefix+name; |
|
|
|
String fqn = prefix + name; |
|
|
|
boolean isClass = !ClassInfo.isPackage(fqn); |
|
|
|
boolean isClass = !ClassInfo.isPackage(fqn); |
|
|
|
|
|
|
|
|
|
|
|
if (isClass && Decompiler.skipClass(ClassInfo.forName(fqn))) |
|
|
|
if (isClass && Decompiler.skipClass(ClassInfo.forName(fqn))) |
|
|
|
continue; |
|
|
|
continue; |
|
|
|
|
|
|
|
|
|
|
|
TreeElement newElem = new TreeElement(prefix, name, isClass); |
|
|
|
TreeElement newElem = new TreeElement(prefix, name, isClass); |
|
|
|
for (int i=0; ; i++) { |
|
|
|
v.add(newElem); |
|
|
|
if (i == v.size()) { |
|
|
|
|
|
|
|
v.addElement(newElem); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
int compare = newElem.compareTo(v.elementAt(i)); |
|
|
|
|
|
|
|
if (compare < 0) { |
|
|
|
|
|
|
|
v.insertElementAt(newElem, i); |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} else if (compare == 0) |
|
|
|
|
|
|
|
break; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
result = new TreeElement[v.size()]; |
|
|
|
result = (TreeElement[]) v.toArray(new TreeElement[v.size()]); |
|
|
|
v.copyInto(result); |
|
|
|
|
|
|
|
cachedChildrens.put(parent, result); |
|
|
|
cachedChildrens.put(parent, result); |
|
|
|
} |
|
|
|
} |
|
|
|
return result; |
|
|
|
return result; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
public void addTreeModelListener(TreeModelListener l) { |
|
|
|
public void addTreeModelListener(TreeModelListener l) { |
|
|
|
listeners.addElement(l); |
|
|
|
listeners.add(l); |
|
|
|
} |
|
|
|
} |
|
|
|
public void removeTreeModelListener(TreeModelListener l) { |
|
|
|
public void removeTreeModelListener(TreeModelListener l) { |
|
|
|
listeners.removeElement(l); |
|
|
|
listeners.remove(l); |
|
|
|
} |
|
|
|
} |
|
|
|
public void valueForPathChanged(TreePath path, Object newValue) { |
|
|
|
public void valueForPathChanged(TreePath path, Object newValue) { |
|
|
|
// we don't allow values
|
|
|
|
// we don't allow values
|
|
|
@ -154,10 +160,9 @@ public class PackagesTreeModel implements TreeModel { |
|
|
|
|
|
|
|
|
|
|
|
public int getIndexOfChild(Object parent, Object child) { |
|
|
|
public int getIndexOfChild(Object parent, Object child) { |
|
|
|
TreeElement[] childrens = getChildrens((TreeElement) parent); |
|
|
|
TreeElement[] childrens = getChildrens((TreeElement) parent); |
|
|
|
for (int i=0; i< childrens.length; i++) { |
|
|
|
int i = Arrays.binarySearch(childrens, child); |
|
|
|
if (childrens[i] == child) |
|
|
|
if (i >= 0) |
|
|
|
return i; |
|
|
|
return i; |
|
|
|
} |
|
|
|
|
|
|
|
throw new NoSuchElementException |
|
|
|
throw new NoSuchElementException |
|
|
|
(((TreeElement)parent).getFullName() + "." + child); |
|
|
|
(((TreeElement)parent).getFullName() + "." + child); |
|
|
|
} |
|
|
|
} |
|
|
|