import javax.swing.tree.DefaultTreeCellRenderer;
import javax.swing.tree.DefaultTreeModel;
import javax.swing.tree.TreeCellRenderer;
+import javax.swing.tree.TreeNode;
import javax.swing.tree.TreePath;
import javax.swing.tree.TreeSelectionModel;
}
root.add(tn);
}
+ // and sort the tree
+ sortTreeNodes(root);
svp = new JScrollPane();
// svp.setAutoscrolls(true);
dbviews = new JTree(new DefaultTreeModel(root, false));
validate();
}
+ private void sortTreeNodes(DefaultMutableTreeNode root)
+ {
+ if (root.getChildCount()==0)
+ {
+ return;
+ }
+ int count=root.getChildCount();
+ String[] names=new String[count];
+ DefaultMutableTreeNode[] nodes=new DefaultMutableTreeNode[count];
+ for (int i=0;i<count;i++)
+ {
+ TreeNode node = root.getChildAt(i);
+ if (node instanceof DefaultMutableTreeNode)
+ {
+ DefaultMutableTreeNode child=(DefaultMutableTreeNode) node;
+ nodes[i]=child;
+ if (child.getUserObject() instanceof DbSourceProxy) {
+ names[i]=((DbSourceProxy)child.getUserObject()).getDbName().toLowerCase();
+ } else {
+ names[i] = ((String) child.getUserObject()).toLowerCase();
+ sortTreeNodes(child);
+ }
+ } else {
+ throw new Error("Implementation Error: Can't reorder this tree. Not DefaultMutableTreeNode.");
+ }
+ }
+ jalview.util.QuickSort.sort(names, nodes);
+ root.removeAllChildren();
+ for (int i=count-1;i>=0;i--)
+ {
+ root.add(nodes[i]);
+ }
+ }
+
private class DbTreeRenderer extends DefaultTreeCellRenderer implements
TreeCellRenderer
{