colors
authorcmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Mon, 19 Sep 2011 22:24:29 +0000 (22:24 +0000)
committercmzmasek@gmail.com <cmzmasek@gmail.com@ca865154-3058-d1c3-3e42-d8f55a55bdbd>
Mon, 19 Sep 2011 22:24:29 +0000 (22:24 +0000)
forester/java/src/org/forester/archaeopteryx/MainFrame.java
forester/java/src/org/forester/archaeopteryx/Util.java

index 0e8f328..1c67316 100644 (file)
@@ -649,7 +649,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
             if ( ranks.length < 1 ) {
                 JOptionPane.showMessageDialog( this,
                                                "No rank information was found",
-                                               "No Rank Inoformation",
+                                               "No Rank Information",
                                                JOptionPane.WARNING_MESSAGE );
                 return;
             }
@@ -657,7 +657,7 @@ public abstract class MainFrame extends JFrame implements ActionListener {
                     .showInputDialog( this,
                                       "What rank should the colorization be based on",
                                       "Rank Selection",
-                                      JOptionPane.PLAIN_MESSAGE,
+                                      JOptionPane.QUESTION_MESSAGE,
                                       null,
                                       ranks,
                                       null );
index 05823d0..daceb3e 100644 (file)
@@ -41,9 +41,11 @@ import java.net.URI;
 import java.net.URL;
 import java.text.ParseException;
 import java.util.Arrays;
+import java.util.HashMap;
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Set;
 import java.util.SortedSet;
 import java.util.TreeSet;
@@ -293,20 +295,43 @@ public final class Util {
     final static void colorPhylogenyAccordingToRanks( final Phylogeny tree,
                                                       final String rank,
                                                       final TreePanel tree_panel ) {
+        final Map<String, Color> m = new HashMap<String, Color>();
         for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) {
             final PhylogenyNode n = it.next();
             if ( n.getNodeData().isHasTaxonomy()
-                    && ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getRank() ) && n.getNodeData()
-                            .getTaxonomy().getRank().equalsIgnoreCase( rank ) )
                     && ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() )
                             || !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getCommonName() ) || !ForesterUtil
                             .isEmpty( n.getNodeData().getTaxonomy().getTaxonomyCode() ) ) ) {
-                final BranchColor c = new BranchColor( tree_panel.calculateTaxonomyBasedColor( n.getNodeData()
-                        .getTaxonomy() ) );
-                n.getBranchData().setBranchColor( c );
-                final List<PhylogenyNode> descs = PhylogenyMethods.getAllDescendants( n );
-                for( final PhylogenyNode desc : descs ) {
-                    desc.getBranchData().setBranchColor( c );
+                if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getRank() )
+                        && n.getNodeData().getTaxonomy().getRank().equalsIgnoreCase( rank ) ) {
+                    final BranchColor c = new BranchColor( tree_panel.calculateTaxonomyBasedColor( n.getNodeData()
+                            .getTaxonomy() ) );
+                    n.getBranchData().setBranchColor( c );
+                    final List<PhylogenyNode> descs = PhylogenyMethods.getAllDescendants( n );
+                    for( final PhylogenyNode desc : descs ) {
+                        desc.getBranchData().setBranchColor( c );
+                    }
+                    if ( !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) {
+                        m.put( n.getNodeData().getTaxonomy().getScientificName(), c.getValue() );
+                    }
+                }
+            }
+        }
+        if ( !m.isEmpty() ) {
+            for( final PhylogenyNodeIterator it = tree.iteratorPostorder(); it.hasNext(); ) {
+                final PhylogenyNode n = it.next();
+                if ( ( n.getBranchData().getBranchColor() == null ) && n.getNodeData().isHasTaxonomy()
+                        && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getLineage() ) ) {
+                    for( final String lin : n.getNodeData().getTaxonomy().getLineage() ) {
+                        if ( m.containsKey( lin ) ) {
+                            final BranchColor c = new BranchColor( m.get( lin ) );
+                            n.getBranchData().setBranchColor( c );
+                            final List<PhylogenyNode> descs = PhylogenyMethods.getAllDescendants( n );
+                            for( final PhylogenyNode desc : descs ) {
+                                desc.getBranchData().setBranchColor( c );
+                            }
+                        }
+                    }
                 }
             }
         }