From: jprocter Date: Sat, 1 Sep 2012 16:46:15 +0000 (+0100) Subject: JAL-1075 sort nodes alphabetically X-Git-Tag: Jalview_2_9~360 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=ad1ffbe2154b4171ca223c4400552def22c7606d;p=jalview.git JAL-1075 sort nodes alphabetically --- diff --git a/src/jalview/gui/JDatabaseTree.java b/src/jalview/gui/JDatabaseTree.java index 53fc35c..c6b16b1 100644 --- a/src/jalview/gui/JDatabaseTree.java +++ b/src/jalview/gui/JDatabaseTree.java @@ -31,6 +31,7 @@ import javax.swing.tree.DefaultMutableTreeNode; 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; @@ -117,6 +118,8 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener } root.add(tn); } + // and sort the tree + sortTreeNodes(root); svp = new JScrollPane(); // svp.setAutoscrolls(true); dbviews = new JTree(new DefaultTreeModel(root, false)); @@ -165,6 +168,40 @@ public class JDatabaseTree extends JalviewDialog implements KeyListener 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=0;i--) + { + root.add(nodes[i]); + } + } + private class DbTreeRenderer extends DefaultTreeCellRenderer implements TreeCellRenderer {