From ad1ffbe2154b4171ca223c4400552def22c7606d Mon Sep 17 00:00:00 2001 From: jprocter Date: Sat, 1 Sep 2012 17:46:15 +0100 Subject: [PATCH] JAL-1075 sort nodes alphabetically --- src/jalview/gui/JDatabaseTree.java | 37 ++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) 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 { -- 1.7.10.2