in progress
authorcmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Mon, 13 Feb 2012 01:19:31 +0000 (01:19 +0000)
committercmzmasek <cmzmasek@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Mon, 13 Feb 2012 01:19:31 +0000 (01:19 +0000)
forester/java/src/org/forester/archaeopteryx/Configuration.java
forester/java/src/org/forester/archaeopteryx/ControlPanel.java
forester/java/src/org/forester/archaeopteryx/TreePanel.java
forester/java/src/org/forester/phylogeny/PhylogenyMethods.java

index c715858..064fc7d 100644 (file)
@@ -129,7 +129,7 @@ public final class Configuration {
     final static int                        collapse_uncollapse                                    = 1;
     final static int                        reroot                                                 = 2;
     final static int                        subtree                                                = 3;
-    final static int                        swap                                                   = 4;
+    final static int                        swap               = 4;
     final static int                        color_subtree                                          = 5;
     final static int                        open_seq_web                                           = 6;
     final static int                        open_tax_web                                           = 7;
@@ -140,6 +140,9 @@ public final class Configuration {
     final static int                        add_new_node                                           = 12;
     final static int                        edit_node_data                                         = 13;
     final static int                        blast                                                  = 14;
+    final static int                        sort_descendents                                        = 15;
+    
+    
     // ---------------------------
     // Display options for trees
     // ---------------------------
@@ -167,7 +170,7 @@ public final class Configuration {
             { "Sub/Super Tree", "display" }, { "Swap Descendants", "display" }, { "Colorize Subtree", "display" },
             { "Open Sequence Web", "display" }, { "Open Taxonomy Web", "display" }, { "Cut Subtree", "display" },
             { "Copy Subtree", "display" }, { "Paste Subtree", "display" }, { "Delete Subtree/Node", "display" },
-            { "Add New Node", "display" }, { "Edit Node Data", "display" }, { "Blast", "nodisplay" } };
+            { "Add New Node", "display" }, { "Edit Node Data", "display" }, { "Blast", "nodisplay" }, { "Sort Descendants", "display" } };
     // This option is selected in the dropdown
     int                                     default_clickto                                        = Configuration.display_node_data;
     // --------------
@@ -363,6 +366,9 @@ public final class Configuration {
         else if ( name.equals( "swap" ) ) {
             index = Configuration.swap;
         }
+        else if ( name.equals( "sort_descendants" ) ) {
+            index = Configuration.sort_descendents;
+        }
         else if ( name.equals( "display_sequences" ) ) {
             ForesterUtil
                     .printWarningMessage( Constants.PRG_NAME, "configuration key [display_sequences] is deprecated" );
index 27930ec..2a2ffd7 100644 (file)
@@ -125,6 +125,7 @@ final class ControlPanel extends JPanel implements ActionListener {
     private int                  _subtree_cb_item;
     private int                  _color_subtree_cb_item;
     private int                  _open_seq_web_item;
+    private int                  _sort_descendents_item;
     private int                  _open_tax_web_item;
     private int                  _cut_subtree_item;
     private int                  _copy_subtree_item;
@@ -1141,6 +1142,9 @@ final class ControlPanel extends JPanel implements ActionListener {
         else if ( action == _open_seq_web_item ) {
             setActionWhenNodeClicked( NodeClickAction.OPEN_SEQ_WEB );
         }
+        else if ( action == _sort_descendents_item ) {
+            setActionWhenNodeClicked( NodeClickAction.SORT_DESCENDENTS );
+        }
         else if ( action == _blast_item ) {
             if ( !Constants.__RELEASE && !Constants.__SNAPSHOT_RELEASE ) {
                 setActionWhenNodeClicked( NodeClickAction.BLAST );
@@ -1315,6 +1319,14 @@ final class ControlPanel extends JPanel implements ActionListener {
             }
             cb_index++;
         }
+        if ( _configuration.doDisplayClickToOption( Configuration.sort_descendents ) ) {
+            _sort_descendents_item = cb_index;
+            addClickToOption( Configuration.sort_descendents, _configuration.getClickToTitle( Configuration.sort_descendents ) );
+            if ( default_option == Configuration.sort_descendents ) {
+                selected_index = cb_index;
+            }
+            cb_index++;
+        }
         if ( _configuration.doDisplayClickToOption( Configuration.color_subtree ) ) {
             _color_subtree_cb_item = cb_index;
             addClickToOption( Configuration.color_subtree, _configuration.getClickToTitle( Configuration.color_subtree ) );
@@ -1929,6 +1941,7 @@ final class ControlPanel extends JPanel implements ActionListener {
         PASTE_SUBTREE,
         ADD_NEW_NODE,
         EDIT_NODE_DATA,
+        SORT_DESCENDENTS,
         BLAST;
     }
 }
index 79dfca7..b561ac2 100644 (file)
@@ -1317,6 +1317,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             case EDIT_NODE_DATA:
                 showNodeEditFrame( node );
                 break;
+            case SORT_DESCENDENTS:
+                sortDescendants( node );
+                break;
             default:
                 throw new IllegalArgumentException( "unknown action: " + action );
         }
@@ -4914,7 +4917,17 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
         repaint();
     }
-
+    
+    
+    final void  sortDescendants( final PhylogenyNode node ) {
+        if ( !node.isExternal() ) {
+            PhylogenyMethods.sortNodeDescendents( node );
+            setNodeInPreorderToNull();
+        }
+        repaint();
+    }
+    
+    
     final private void switchDisplaygetPhylogenyGraphicsType() {
         switch ( getPhylogenyGraphicsType() ) {
             case RECTANGULAR:
index 9ca9086..7835d62 100644 (file)
@@ -30,6 +30,7 @@ import java.io.File;
 import java.io.IOException;
 import java.util.ArrayList;
 import java.util.Arrays;
+import java.util.Collections;
 import java.util.HashSet;
 import java.util.Iterator;
 import java.util.List;
@@ -231,6 +232,21 @@ public class PhylogenyMethods {
             }
         }
     }
+    
+    
+    
+    final static public void sortNodeDescendents( PhylogenyNode node ) {
+        final List<PhylogenyNode> descs = node.getDescendants();
+       // Collections.sort( arg0, comparator );
+        Collections.sort( descs );
+        
+        int i = 0;
+        for( PhylogenyNode desc : descs ) {
+            node.setChildNode( i++, desc );
+        }
+        
+    }
+    
 
     final static public void transferNodeNameToField( final Phylogeny phy,
                                                       final PhylogenyMethods.PhylogenyNodeField field ) {