From 78e55030215fa1d1ddd0f7659d37e66421041b97 Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Fri, 25 Oct 2013 00:45:07 +0000 Subject: [PATCH] in progress --- .../surfacing/PrintableDomainSimilarity.java | 84 ++++++++------------ 1 file changed, 32 insertions(+), 52 deletions(-) diff --git a/forester/java/src/org/forester/surfacing/PrintableDomainSimilarity.java b/forester/java/src/org/forester/surfacing/PrintableDomainSimilarity.java index c8c30d6..e585f5a 100644 --- a/forester/java/src/org/forester/surfacing/PrintableDomainSimilarity.java +++ b/forester/java/src/org/forester/surfacing/PrintableDomainSimilarity.java @@ -26,8 +26,7 @@ package org.forester.surfacing; -import java.awt.Color; -import java.util.HashMap; + import java.util.List; import java.util.Map; import java.util.SortedMap; @@ -36,7 +35,6 @@ import java.util.TreeMap; import java.util.TreeSet; import org.forester.phylogeny.Phylogeny; -import org.forester.phylogeny.PhylogenyNode; import org.forester.species.Species; import org.forester.surfacing.DomainSimilarityCalculator.Detailedness; import org.forester.util.ForesterUtil; @@ -58,8 +56,7 @@ public class PrintableDomainSimilarity implements DomainSimilarity { private List _species_order; private DomainSimilarityCalculator.Detailedness _detailedness; private final boolean _treat_as_binary_comparison; - private final static Map _TAXCODE_HEXCOLORSTRING_MAP = new HashMap(); - + public PrintableDomainSimilarity( final CombinableDomains combinable_domains, final double min, final double max, @@ -189,20 +186,29 @@ public class PrintableDomainSimilarity implements DomainSimilarity { final Map tax_code_to_id_map, final Phylogeny phy ) { String hex = null; - if ( ( phy != null ) && !phy.isEmpty() ) { - hex = obtainHexColorStringDependingOnTaxonomyGroup( tax_code, phy ); + if ( phy != null && !phy.isEmpty() ) { + hex = SurfacingUtil.obtainHexColorStringDependingOnTaxonomyGroup( tax_code, phy ); } sb.append( "" ); if ( !ForesterUtil.isEmpty( tax_code ) && ( ( tax_code_to_id_map != null ) && tax_code_to_id_map.containsKey( tax_code ) ) ) { if ( !ForesterUtil.isEmpty( hex ) ) { - sb.append( "" - + tax_code + "" ); + sb.append( "" ); + sb.append( tax_code ); + sb.append( "" ); } else { - sb.append( "" + tax_code + "" ); + sb.append( "" ); + sb.append( tax_code ); + sb.append( "" ); } } else { @@ -211,39 +217,7 @@ public class PrintableDomainSimilarity implements DomainSimilarity { sb.append( "" ); } - private String obtainHexColorStringDependingOnTaxonomyGroup( final String tax_code, final Phylogeny phy ) { - if ( ( phy != null ) && !_TAXCODE_HEXCOLORSTRING_MAP.containsKey( tax_code ) ) { - final List nodes = phy.getNodesViaTaxonomyCode( tax_code ); - Color c = null; - if ( ( nodes == null ) || nodes.isEmpty() ) { - throw new RuntimeException( tax_code + " is not found" ); - } - if ( nodes.size() != 1 ) { - throw new RuntimeException( tax_code + " is not unique" ); - } - PhylogenyNode n = nodes.get( 0 ); - while ( n != null ) { - if ( n.getNodeData().isHasTaxonomy() - && !ForesterUtil.isEmpty( n.getNodeData().getTaxonomy().getScientificName() ) ) { - c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getNodeData().getTaxonomy() - .getScientificName() ); - } - if ( ( c == null ) && !ForesterUtil.isEmpty( n.getName() ) ) { - c = ForesterUtil.obtainColorDependingOnTaxonomyGroup( n.getName() ); - } - if ( c != null ) { - break; - } - n = n.getParent(); - } - if ( c == null ) { - throw new RuntimeException( "no color found for taxonomy code \"" + tax_code + "\"" ); - } - final String hex = String.format( "#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue() ); - _TAXCODE_HEXCOLORSTRING_MAP.put( tax_code, hex ); - } - return _TAXCODE_HEXCOLORSTRING_MAP.get( tax_code ); - } + private int compareByDomainId( final DomainSimilarity other ) { return getDomainId().compareToIgnoreCase( other.getDomainId() ); @@ -361,17 +335,23 @@ public class PrintableDomainSimilarity implements DomainSimilarity { for( final Map.Entry> e : m.entrySet() ) { sb.append( "" + e.getKey() + "" ); sb.append( ": " ); - for( final String s : e.getValue() ) { - final String hex = obtainHexColorStringDependingOnTaxonomyGroup( s, null ); + sb.append( "" ); + for( final String tax : e.getValue() ) { + final String hex = SurfacingUtil.obtainHexColorStringDependingOnTaxonomyGroup( tax, null ); if ( !ForesterUtil.isEmpty( hex ) ) { - sb.append( "" + s + "" ); + sb.append( "" ); + sb.append( tax ); + sb.append( "" ); } else { - sb.append( s ); + sb.append( tax ); } sb.append( " " ); } - sb.append( "
" ); + sb.append( "
" ); + sb.append( "
\n" ); } return sb; } @@ -419,7 +399,7 @@ public class PrintableDomainSimilarity implements DomainSimilarity { @Override public StringBuffer toStringBuffer( final PrintableDomainSimilarity.PRINT_OPTION print_option, final Map tax_code_to_id_map, - final Phylogeny phy ) { + Phylogeny phy ) { switch ( print_option ) { case SIMPLE_TAB_DELIMITED: return toStringBufferSimpleTabDelimited(); @@ -430,7 +410,7 @@ public class PrintableDomainSimilarity implements DomainSimilarity { } } - private StringBuffer toStringBufferDetailedHTML( final Map tax_code_to_id_map, final Phylogeny phy ) { + private StringBuffer toStringBufferDetailedHTML( final Map tax_code_to_id_map, Phylogeny phy ) { final StringBuffer sb = new StringBuffer(); sb.append( "" ); sb.append( "" ); -- 1.7.10.2