From 724bd2bd4cbc5b3ea5ec856d156fa37b93b3d0fb Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Tue, 7 Jun 2011 00:21:18 +0000 Subject: [PATCH] in progress --- .../org/forester/archaeopteryx/Archaeopteryx.java | 44 +------ .../org/forester/archaeopteryx/Configuration.java | 78 +++++++++++++ .../src/org/forester/archaeopteryx/Constants.java | 1 + .../src/org/forester/archaeopteryx/Options.java | 121 +++++++++++++------- .../src/org/forester/archaeopteryx/TreePanel.java | 40 +++++-- 5 files changed, 191 insertions(+), 93 deletions(-) diff --git a/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java b/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java index 3593218..8bd8df5 100644 --- a/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java +++ b/forester/java/src/org/forester/archaeopteryx/Archaeopteryx.java @@ -32,7 +32,6 @@ import org.forester.io.parsers.nexus.NexusPhylogeniesParser; import org.forester.io.parsers.nhx.NHXParser; import org.forester.io.parsers.phyloxml.PhyloXmlParser; import org.forester.phylogeny.Phylogeny; -import org.forester.phylogeny.factories.ParserBasedPhylogenyFactory; import org.forester.util.ForesterUtil; // @@ -43,8 +42,6 @@ import org.forester.util.ForesterUtil; // public final class Archaeopteryx { - private final static boolean TEST = false; //TODO remove me! - public static MainFrame createApplication( final Phylogeny phylogeny ) { final Phylogeny[] phylogenies = new Phylogeny[ 1 ]; phylogenies[ 0 ] = phylogeny; @@ -116,21 +113,6 @@ public final class Archaeopteryx { ForesterUtil.transferInternalNodeNamesToConfidence( phy ); } } - // - // Phylogeny py = phylogenies[ 0 ]; - // for( final PhylogenyNodeIterator iter = py.iteratorExternalForward(); iter.hasNext(); ) { - // final PhylogenyNode node = iter.next(); - // System.out.println( node.getNodeData().getTaxonomy().getScientificName() + "\t" - // + node.getNodeData().getBinaryCharacters().getPresentCount() ); - // } - // for( final PhylogenyNodeIterator iter = py.iteratorPreorder(); iter.hasNext(); ) { - // final PhylogenyNode node = iter.next(); - // if ( !node.isExternal() ) { - // System.out.println( node.getNodeData().getTaxonomy().getScientificName() + "\t" - // + node.getNodeData().getBinaryCharacters().getPresentCount() ); - // } - // } - // } } } @@ -142,32 +124,8 @@ public final class Archaeopteryx { title = f.getName(); } try { - String s = ""; - if ( TEST ) { - s = "/home/czmasek/888.xml"; - if ( ForesterUtil.isReadableFile( s ) != null ) { - s = "/Users/zma/888.xml"; - if ( ForesterUtil.isReadableFile( s ) != null ) { - s = "C:\\888.xml"; - if ( ForesterUtil.isReadableFile( s ) != null ) { - s = "C:\\Documents and Settings\\czmasek\\"; - } - } - } - } - if ( !TEST ) { - MainFrameApplication.createInstance( phylogenies, conf, title ); - } - else { - MainFrameApplication.createInstance( ParserBasedPhylogenyFactory.getInstance() - .create( s, new PhyloXmlParser() ), - conf, - title ); - } + MainFrameApplication.createInstance( phylogenies, conf, title ); } - // catch ( final IOException ex ) { - // ForesterUtil.fatalError( Constants.PRG_NAME, "failed to start: " + ex.getLocalizedMessage() ); - // } catch ( final Exception ex ) { Util.unexpectedException( ex ); } diff --git a/forester/java/src/org/forester/archaeopteryx/Configuration.java b/forester/java/src/org/forester/archaeopteryx/Configuration.java index 0e6b05f..342fcdb 100644 --- a/forester/java/src/org/forester/archaeopteryx/Configuration.java +++ b/forester/java/src/org/forester/archaeopteryx/Configuration.java @@ -45,6 +45,8 @@ import java.util.TreeMap; import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE; import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION; +import org.forester.archaeopteryx.Options.NodeFill; +import org.forester.archaeopteryx.Options.NodeShape; import org.forester.archaeopteryx.Options.OVERVIEW_PLACEMENT_TYPE; import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE; import org.forester.util.ForesterUtil; @@ -91,6 +93,10 @@ public final class Configuration { private boolean _abbreviate_scientific_names = false; private boolean _color_labels_same_as_parent_branch = false; private int _default_bootstrap_samples = -1; + private NodeShape _default_node_shape = NodeShape.NONE; + private NodeFill _default_node_fill = NodeFill.GRADIENT; + private short _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT; + private boolean _taxonomy_colorize_node_shapes_instead_of_labels = false; final static int display_as_phylogram = 0; final static int show_node_names = 1; final static int show_tax_code = 2; @@ -1056,6 +1062,46 @@ public final class Configuration { else if ( key.equals( "domain_structure_base_color" ) ) { _domain_structure_base_color = Color.decode( ( String ) st.nextElement() ); } + // + else if ( key.equals( "default_node_size" ) ) { + final short i = parseShort( ( ( String ) st.nextElement() ).trim() ); + setDefaultNodeShapeSize( i ); + } + else if ( key.equals( "default_node_fill" ) ) { + final String fill_str = ( ( String ) st.nextElement() ).trim(); + if ( fill_str.equalsIgnoreCase( Options.NodeFill.NONE.toString() ) ) { + setDefaultNodeFill( NodeFill.NONE ); + } + else if ( fill_str.equalsIgnoreCase( Options.NodeFill.GRADIENT.toString() ) ) { + setDefaultNodeFill( NodeFill.GRADIENT ); + } + else if ( fill_str.equalsIgnoreCase( Options.NodeFill.SOLID.toString() ) ) { + setDefaultNodeFill( NodeFill.SOLID ); + } + else { + ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + fill_str + + "] for [default_node_fill]" ); + } + } + else if ( key.equals( "default_node_shape" ) ) { + final String shape_str = ( ( String ) st.nextElement() ).trim(); + if ( shape_str.equalsIgnoreCase( Options.NodeShape.NONE.toString() ) ) { + setDefaultNodeShape( NodeShape.NONE ); + } + else if ( shape_str.equalsIgnoreCase( Options.NodeShape.CIRCLE.toString() ) ) { + setDefaultNodeShape( NodeShape.CIRCLE ); + } + else if ( shape_str.equalsIgnoreCase( Options.NodeShape.RECTANGLE.toString() ) ) { + setDefaultNodeShape( NodeShape.RECTANGLE ); + } + else { + ForesterUtil.printWarningMessage( Constants.PRG_NAME, "unknown value [" + shape_str + + "] for [default_node_shape]" ); + } + } + else if ( key.equals( "taxonomy_colorize_node_shapes" ) ) { + setTaxonomyColorizeNodeShapesInsteadOfLabels( parseBoolean( ( String ) st.nextElement() ) ); + } else if ( st.countTokens() >= 2 ) { // counts the tokens that are not // yet retrieved! int key_index = -1; @@ -1337,4 +1383,36 @@ public final class Configuration { public boolean isAbbreviateScientificTaxonNames() { return _abbreviate_scientific_names; } + + public NodeShape getDefaultNodeShape() { + return _default_node_shape; + } + + private void setDefaultNodeShape( final NodeShape default_node_shape ) { + _default_node_shape = default_node_shape; + } + + private void setDefaultNodeFill( final NodeFill default_node_fill ) { + _default_node_fill = default_node_fill; + } + + public NodeFill getDefaultNodeFill() { + return _default_node_fill; + } + + private void setDefaultNodeShapeSize( final short default_node_shape_size ) { + _default_node_shape_size = default_node_shape_size; + } + + public short getDefaultNodeShapeSize() { + return _default_node_shape_size; + } + + private void setTaxonomyColorizeNodeShapesInsteadOfLabels( final boolean taxonomy_colorize_node_shapes_instead_of_labels ) { + _taxonomy_colorize_node_shapes_instead_of_labels = taxonomy_colorize_node_shapes_instead_of_labels; + } + + public boolean isTaxonomyColorizeNodeShapesInsteadOfLabels() { + return _taxonomy_colorize_node_shapes_instead_of_labels; + } } diff --git a/forester/java/src/org/forester/archaeopteryx/Constants.java b/forester/java/src/org/forester/archaeopteryx/Constants.java index 006dadb..0715abe 100644 --- a/forester/java/src/org/forester/archaeopteryx/Constants.java +++ b/forester/java/src/org/forester/archaeopteryx/Constants.java @@ -106,4 +106,5 @@ public final class Constants { 144, 144 ); final static String NCBI_ALL_DATABASE_SEARCH = "http://www.ncbi.nlm.nih.gov/gquery/?term="; + final static short DEFAULT_NODE_SHAPE_SIZE_DEFAULT = 6; } diff --git a/forester/java/src/org/forester/archaeopteryx/Options.java b/forester/java/src/org/forester/archaeopteryx/Options.java index 7f5cabd..31c9873 100644 --- a/forester/java/src/org/forester/archaeopteryx/Options.java +++ b/forester/java/src/org/forester/archaeopteryx/Options.java @@ -68,19 +68,10 @@ final public class Options { private boolean _color_labels_same_as_parent_branch; private boolean _abbreviate_scientific_names; private NodeShape _default_node_shape; + private NodeFill _default_node_fill; private short _default_node_shape_size; private boolean _taxonomy_colorize_node_shapes_instead_of_labels; - enum NodeShape { - NONE, - CIRCLE_WITH_GRADIENT, - CIRCLE_SOLID, - CIRCLE_HOLLOW, - RECTANGLE_WITH_GRADIENT, - RECTANGLE_SOLID, - RECTANGLE_HOLLOW; - } - private Options() { init(); } @@ -93,6 +84,23 @@ final public class Options { return _cladogram_type; } + int getDefaultNodeBoxSize() { + // TODO make variable ~~ + return 8; + } + + final NodeFill getDefaultNodeFill() { + return _default_node_fill; + } + + final NodeShape getDefaultNodeShape() { + return _default_node_shape; + } + + final short getDefaultNodeShapeSize() { + return _default_node_shape_size; + } + final double getMinConfidenceValue() { return _min_confidence_value; } @@ -134,7 +142,10 @@ final public class Options { } final private void init() { - _default_node_shape = NodeShape.RECTANGLE_WITH_GRADIENT; + _default_node_shape = NodeShape.NONE; + _default_node_fill = NodeFill.GRADIENT; + _default_node_shape_size = Constants.DEFAULT_NODE_SHAPE_SIZE_DEFAULT; + _taxonomy_colorize_node_shapes_instead_of_labels = false; _show_branch_length_values = false; _internal_number_are_confidence_for_nh_parsing = false; _show_scale = false; @@ -175,6 +186,14 @@ final public class Options { _color_labels_same_as_parent_branch = false; } + final boolean isAbbreviateScientificTaxonNames() { + return _abbreviate_scientific_names; + } + + boolean isAllowMagnificationOfTaxonomyImages() { + return true; + } + final boolean isAntialiasPrint() { return _antialias_print; } @@ -187,10 +206,6 @@ final public class Options { return _background_color_gradient; } - public final boolean isShowDomainLabels() { - return _show_domain_labels; - } - final boolean isColorLabelsSameAsParentBranch() { return _color_labels_same_as_parent_branch; } @@ -243,8 +258,8 @@ final public class Options { return _show_branch_length_values; } - final NodeShape getDefaultNodeShape() { - return _default_node_shape; + public final boolean isShowDomainLabels() { + return _show_domain_labels; } final boolean isShowOverview() { @@ -255,6 +270,14 @@ final public class Options { return _show_scale; } + boolean isTaxonomyColorizeNodeShapesInsteadOfLabels() { + return _taxonomy_colorize_node_shapes_instead_of_labels; + } + + final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) { + _abbreviate_scientific_names = abbreviate_scientific_names; + } + final void setAntialiasPrint( final boolean antialias_print ) { _antialias_print = antialias_print; } @@ -267,20 +290,28 @@ final public class Options { _background_color_gradient = background_color_gradient; } - public void setShowDomainLabels( final boolean show_domain_labels ) { - _show_domain_labels = show_domain_labels; + final void setBaseFont( final Font base_font ) { + _base_font = base_font; + } + + final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) { + _cladogram_type = cladogram_type; } public void setColorLabelsSameAsParentBranch( final boolean color_labels_same_as_parent_branch ) { _color_labels_same_as_parent_branch = color_labels_same_as_parent_branch; } - final void setBaseFont( final Font base_font ) { - _base_font = base_font; + final void setDefaultNodeFill( final NodeFill default_node_fill ) { + _default_node_fill = default_node_fill; } - final void setCladogramType( final CLADOGRAM_TYPE cladogram_type ) { - _cladogram_type = cladogram_type; + final void setDefaultNodeShape( final NodeShape default_node_shape ) { + _default_node_shape = default_node_shape; + } + + final void setDefaultNodeShapeSize( final short default_node_shape_size ) { + _default_node_shape_size = default_node_shape_size; } final void setEditable( final boolean editable ) { @@ -377,8 +408,8 @@ final public class Options { _show_branch_length_values = show_branch_length_values; } - final void setDefaultNodeShape( final NodeShape default_node_shape ) { - _default_node_shape = default_node_shape; + public void setShowDomainLabels( final boolean show_domain_labels ) { + _show_domain_labels = show_domain_labels; } final void setShowOverview( final boolean show_overview ) { @@ -389,6 +420,10 @@ final public class Options { _show_scale = show_scale; } + void setTaxonomyColorizeNodeShapesInsteadOfLabels( final boolean taxonomy_colorize_node_shapes_instead_of_labels ) { + _taxonomy_colorize_node_shapes_instead_of_labels = taxonomy_colorize_node_shapes_instead_of_labels; + } + final static Options createDefaultInstance() { return new Options(); } @@ -440,18 +475,21 @@ final public class Options { if ( configuration.getPhylogenyGraphicsType() != null ) { instance.setPhylogenyGraphicsType( configuration.getPhylogenyGraphicsType() ); } + if ( configuration.getDefaultNodeFill() != null ) { + instance.setDefaultNodeFill( configuration.getDefaultNodeFill() ); + } + if ( configuration.getDefaultNodeShape() != null ) { + instance.setDefaultNodeShape( configuration.getDefaultNodeShape() ); + } + if ( configuration.getDefaultNodeShapeSize() >= 0 ) { + instance.setDefaultNodeShapeSize( configuration.getDefaultNodeShapeSize() ); + } + instance.setTaxonomyColorizeNodeShapesInsteadOfLabels( configuration + .isTaxonomyColorizeNodeShapesInsteadOfLabels() ); } return instance; } - final void setAbbreviateScientificTaxonNames( final boolean abbreviate_scientific_names ) { - _abbreviate_scientific_names = abbreviate_scientific_names; - } - - final boolean isAbbreviateScientificTaxonNames() { - return _abbreviate_scientific_names; - } - static enum CLADOGRAM_TYPE { NON_LINED_UP, EXT_NODE_SUM_DEP, TOTAL_NODE_SUM_DEP; } @@ -460,6 +498,14 @@ final public class Options { HORIZONTAL, RADIAL; } + enum NodeFill { + NONE, GRADIENT, SOLID + } + + enum NodeShape { + NONE, CIRCLE, RECTANGLE + } + static enum OVERVIEW_PLACEMENT_TYPE { UPPER_LEFT( "upper left" ), UPPER_RIGHT( "upper right" ), @@ -485,13 +531,4 @@ final public class Options { static enum PHYLOGENY_GRAPHICS_TYPE { RECTANGULAR, TRIANGULAR, EURO_STYLE, ROUNDED, CONVEX, CURVED, UNROOTED, CIRCULAR; } - - boolean isAllowMagnificationOfTaxonomyImages() { - return true; - } - - int getDefaultNodeBoxSize() { - // TODO make variable ~~ - return 8; - } } diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index 6ce838e..a37c5dc 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -92,6 +92,8 @@ import javax.swing.PopupFactory; import org.forester.archaeopteryx.ControlPanel.NodeClickAction; import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE; import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION; +import org.forester.archaeopteryx.Options.NodeFill; +import org.forester.archaeopteryx.Options.NodeShape; import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE; import org.forester.archaeopteryx.phylogeny.data.RenderableDomainArchitecture; import org.forester.archaeopteryx.phylogeny.data.RenderableVector; @@ -2816,14 +2818,36 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { //TODO FIXME //drawRectFilled( x - HALF_BOX_SIZE, y - HALF_BOX_SIZE, BOX_SIZE, BOX_SIZE, g ); - drawOvalGradient( x - _half_box_size, - y - _half_box_size, - _box_size, - _box_size, - g, - Color.BLACK, - g.getColor(), - g.getColor() ); + if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) { + if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) { + drawOvalGradient( x - _half_box_size, + y - _half_box_size, + _box_size, + _box_size, + g, + Color.BLACK, + g.getColor(), + g.getColor() ); + } + else if ( getOptions().getDefaultNodeFill() == NodeFill.SOLID ) { + drawOvalFilled( x - _half_box_size, y - _half_box_size, _box_size, _box_size, g ); + } + } + else if ( getOptions().getDefaultNodeShape() == NodeShape.RECTANGLE ) { + if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) { + drawRectGradient( x - _half_box_size, + y - _half_box_size, + _box_size, + _box_size, + g, + Color.BLACK, + g.getColor(), + g.getColor() ); + } + else if ( getOptions().getDefaultNodeFill() == NodeFill.SOLID ) { + drawRectFilled( x - _half_box_size, y - _half_box_size, _box_size, _box_size, g ); + } + } } } } -- 1.7.10.2