From 7b05eefd8e0eb34d3879f59f0c8d12d785283d2d Mon Sep 17 00:00:00 2001 From: "cmzmasek@gmail.com" Date: Wed, 26 Mar 2014 23:12:11 +0000 Subject: [PATCH] in progress --- .../org/forester/archaeopteryx/Configuration.java | 16 +- .../src/org/forester/archaeopteryx/MainFrame.java | 5 +- .../src/org/forester/archaeopteryx/Options.java | 10 +- .../src/org/forester/archaeopteryx/TreePanel.java | 20 +- .../src/org/forester/phylogeny/data/NodeData.java | 29 ++- .../forester/phylogeny/data/NodeVisualData.java | 241 ++++++++++++++++++++ .../forester/phylogeny/data/NodeVisualization.java | 183 --------------- 7 files changed, 284 insertions(+), 220 deletions(-) create mode 100644 forester/java/src/org/forester/phylogeny/data/NodeVisualData.java delete mode 100644 forester/java/src/org/forester/phylogeny/data/NodeVisualization.java diff --git a/forester/java/src/org/forester/archaeopteryx/Configuration.java b/forester/java/src/org/forester/archaeopteryx/Configuration.java index 37f3b2d..7c46dff 100644 --- a/forester/java/src/org/forester/archaeopteryx/Configuration.java +++ b/forester/java/src/org/forester/archaeopteryx/Configuration.java @@ -48,9 +48,9 @@ import org.forester.archaeopteryx.Options.OVERVIEW_PLACEMENT_TYPE; import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE; import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION; import org.forester.phylogeny.data.NodeData.NODE_DATA; -import org.forester.phylogeny.data.NodeVisualization; -import org.forester.phylogeny.data.NodeVisualization.NodeFill; -import org.forester.phylogeny.data.NodeVisualization.NodeShape; +import org.forester.phylogeny.data.NodeVisualData; +import org.forester.phylogeny.data.NodeVisualData.NodeFill; +import org.forester.phylogeny.data.NodeVisualData.NodeShape; import org.forester.util.ForesterUtil; public final class Configuration { @@ -1391,13 +1391,13 @@ public final class Configuration { } else if ( key.equals( "default_node_fill" ) ) { final String fill_str = ( ( String ) st.nextElement() ).trim(); - if ( fill_str.equalsIgnoreCase( NodeVisualization.NodeFill.NONE.toString() ) ) { + if ( fill_str.equalsIgnoreCase( NodeVisualData.NodeFill.NONE.toString() ) ) { setDefaultNodeFill( NodeFill.NONE ); } - else if ( fill_str.equalsIgnoreCase( NodeVisualization.NodeFill.GRADIENT.toString() ) ) { + else if ( fill_str.equalsIgnoreCase( NodeVisualData.NodeFill.GRADIENT.toString() ) ) { setDefaultNodeFill( NodeFill.GRADIENT ); } - else if ( fill_str.equalsIgnoreCase( NodeVisualization.NodeFill.SOLID.toString() ) ) { + else if ( fill_str.equalsIgnoreCase( NodeVisualData.NodeFill.SOLID.toString() ) ) { setDefaultNodeFill( NodeFill.SOLID ); } else { @@ -1407,10 +1407,10 @@ public final class Configuration { } else if ( key.equals( "default_node_shape" ) ) { final String shape_str = ( ( String ) st.nextElement() ).trim(); - if ( shape_str.equalsIgnoreCase( NodeVisualization.NodeShape.CIRCLE.toString() ) ) { + if ( shape_str.equalsIgnoreCase( NodeVisualData.NodeShape.CIRCLE.toString() ) ) { setDefaultNodeShape( NodeShape.CIRCLE ); } - else if ( shape_str.equalsIgnoreCase( NodeVisualization.NodeShape.RECTANGLE.toString() ) ) { + else if ( shape_str.equalsIgnoreCase( NodeVisualData.NodeShape.RECTANGLE.toString() ) ) { setDefaultNodeShape( NodeShape.RECTANGLE ); } else { diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index 6248f6d..0820cbf 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -65,8 +65,9 @@ import org.forester.phylogeny.PhylogenyMethods.DESCENDANT_SORT_PRIORITY; import org.forester.phylogeny.PhylogenyNode; import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE; import org.forester.phylogeny.data.Annotation; -import org.forester.phylogeny.data.NodeVisualization.NodeFill; -import org.forester.phylogeny.data.NodeVisualization.NodeShape; + +import org.forester.phylogeny.data.NodeVisualData.NodeFill; +import org.forester.phylogeny.data.NodeVisualData.NodeShape; import org.forester.sdi.GSDI; import org.forester.sdi.GSDIR; import org.forester.sdi.SDIException; diff --git a/forester/java/src/org/forester/archaeopteryx/Options.java b/forester/java/src/org/forester/archaeopteryx/Options.java index ec63ca6..3a10245 100644 --- a/forester/java/src/org/forester/archaeopteryx/Options.java +++ b/forester/java/src/org/forester/archaeopteryx/Options.java @@ -31,9 +31,9 @@ import org.forester.io.parsers.nhx.NHXParser.TAXONOMY_EXTRACTION; import org.forester.phylogeny.PhylogenyNode.NH_CONVERSION_SUPPORT_VALUE_STYLE; import org.forester.phylogeny.data.NodeData; import org.forester.phylogeny.data.NodeData.NODE_DATA; -import org.forester.phylogeny.data.NodeVisualization; -import org.forester.phylogeny.data.NodeVisualization.NodeFill; -import org.forester.phylogeny.data.NodeVisualization.NodeShape; +import org.forester.phylogeny.data.NodeVisualData; +import org.forester.phylogeny.data.NodeVisualData.NodeFill; +import org.forester.phylogeny.data.NodeVisualData.NodeShape; import org.forester.util.ForesterUtil; /* @@ -51,8 +51,8 @@ final public class Options { private CLADOGRAM_TYPE _cladogram_type; private boolean _color_by_taxonomic_group; private boolean _color_labels_same_as_parent_branch; - private NodeVisualization.NodeFill _default_node_fill; - private NodeVisualization.NodeShape _default_node_shape; + private NodeVisualData.NodeFill _default_node_fill; + private NodeVisualData.NodeShape _default_node_shape; private short _default_node_shape_size; private boolean _editable; private NODE_DATA _ext_desc_data_to_return; diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index e5510da..d0ae1e8 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -112,9 +112,9 @@ import org.forester.phylogeny.data.BranchColor; import org.forester.phylogeny.data.Confidence; import org.forester.phylogeny.data.Event; import org.forester.phylogeny.data.NodeData.NODE_DATA; -import org.forester.phylogeny.data.NodeVisualization; -import org.forester.phylogeny.data.NodeVisualization.NodeFill; -import org.forester.phylogeny.data.NodeVisualization.NodeShape; +import org.forester.phylogeny.data.NodeVisualData; +import org.forester.phylogeny.data.NodeVisualData.NodeFill; +import org.forester.phylogeny.data.NodeVisualData.NodeShape; import org.forester.phylogeny.data.PhylogenyDataUtil; import org.forester.phylogeny.data.PropertiesMap; import org.forester.phylogeny.data.Property; @@ -3813,11 +3813,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() - d ); _polygon.lineTo( node.getXcoord() + 1, node.getYcoord() + d ); _polygon.closePath(); - if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) { + if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.SOLID ) { g.setColor( c ); g.fill( _polygon ); } - else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) { + else if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.NONE ) { g.setColor( getBackground() ); g.fill( _polygon ); g.setColor( c ); @@ -3994,17 +3994,17 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee background, outline_color ); } - else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) { + else if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.SOLID ) { g.setColor( outline_color ); drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g ); } } - else if ( getOptions().getDefaultNodeShape() == NodeVisualization.NodeShape.RECTANGLE ) { - if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.GRADIENT ) { + else if ( getOptions().getDefaultNodeShape() == NodeVisualData.NodeShape.RECTANGLE ) { + if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.GRADIENT ) { drawRectGradient( x - half_box_size, y - half_box_size, box_size, box_size, g, to_pdf ? Color.WHITE : outline_color, to_pdf ? outline_color : getBackground(), outline_color ); } - else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.NONE ) { + else if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.NONE ) { Color background = getBackground(); if ( to_pdf ) { background = Color.WHITE; @@ -4018,7 +4018,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee background, outline_color ); } - else if ( getOptions().getDefaultNodeFill() == NodeVisualization.NodeFill.SOLID ) { + else if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.SOLID ) { g.setColor( outline_color ); drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g ); } diff --git a/forester/java/src/org/forester/phylogeny/data/NodeData.java b/forester/java/src/org/forester/phylogeny/data/NodeData.java index c5c5d40..609b203 100644 --- a/forester/java/src/org/forester/phylogeny/data/NodeData.java +++ b/forester/java/src/org/forester/phylogeny/data/NodeData.java @@ -62,7 +62,7 @@ public class NodeData implements PhylogenyData { private PropertiesMap _properties; private List _references; private List _vector; - private List _node_visualizations; + private NodeVisualData _node_visual_data; public NodeData() { init(); @@ -70,6 +70,16 @@ public class NodeData implements PhylogenyData { private void init() { _node_name = ""; + _event = null; + _sequences= null; + _taxonomies= null; + _distributions= null; + _date= null; + _binary_characters= null; + _properties= null; + _references= null; + _vector= null; + _node_visual_data= null; } public void addDistribution( final Distribution distribution ) { @@ -152,13 +162,8 @@ public class NodeData implements PhylogenyData { } } } - if ( ( getNodeVisualizations() != null ) && ( getNodeVisualizations().size() > 0 ) ) { - new_data.setNodeVisualizations( new ArrayList() ); - for( final NodeVisualization v : getNodeVisualizations() ) { - if ( v != null ) { - new_data.getNodeVisualizations().add( ( NodeVisualization ) v.copy() ); - } - } + if ( getNodeVisualData() != null && !getNodeVisualData().isEmpty() ) { + new_data.setNodeVisualData( ( NodeVisualData ) getNodeVisualData().copy() ); } if ( isHasDate() ) { new_data.setDate( ( Date ) getDate().copy() ); @@ -523,11 +528,11 @@ public class NodeData implements PhylogenyData { _node_name = node_name; } - public void setNodeVisualizations( final List _node_visualizations ) { - this._node_visualizations = _node_visualizations; + public void setNodeVisualData( final NodeVisualData node_visual_data ) { + _node_visual_data = node_visual_data; } - public List getNodeVisualizations() { - return _node_visualizations; + public NodeVisualData getNodeVisualData() { + return _node_visual_data; } } diff --git a/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java b/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java new file mode 100644 index 0000000..e77016f --- /dev/null +++ b/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java @@ -0,0 +1,241 @@ +package org.forester.phylogeny.data; + +import java.awt.Color; +import java.io.IOException; +import java.io.Writer; +import java.util.ArrayList; +import java.util.List; + + +import org.forester.phylogeny.data.Property.AppliesTo; +import org.forester.util.ForesterUtil; + + +public final class NodeVisualData implements PhylogenyData { + + private static final int DEFAULT_SIZE = -1; + private static final int DEFAULT_TRANSPARANCY = -1; + private static final byte DEFAULT_FONT_SIZE = -1; + private NodeShape _shape; + private NodeFill _fill_type; + private Color _border_color; + private Color _fill_color; + + private String _font; + private FontType _font_type; + private byte _font_size; + private Color _font_color; + + private float _size; + private float _transparancy; + + public NodeVisualData() { + init(); + } + + public NodeVisualData( final String font, + final FontType font_type, + byte font_size, + Color font_color, + final NodeShape shape, + final NodeFill fill_type, + final Color border_color, + final Color fill_color, + final float size, + final float transparancy ) { + setFont( font ); + setFontType(font_type ); + setFontSize( font_size ); + setFontColor( font_color ); + setShape( shape ); + setFillType( fill_type ); + setBorderColor( border_color ); + setFillColor( fill_color ); + setSize( size ); + setTransparancy( transparancy ); + } + + @Override + public final StringBuffer asSimpleText() { + return asText(); + } + + @Override + public final StringBuffer asText() { + final StringBuffer sb = new StringBuffer(); + return sb; + } + + @Override + public final PhylogenyData copy() { + return new NodeVisualData( ForesterUtil.isEmpty( getFont() ) ? new String( getFont()) : null , + getFontType(), + getFontSize(), + getFontColor() != null ? new Color( getFontColor().getRed(), getFontColor() + .getGreen(), getFontColor().getBlue() ) : null, + getShape(), + getFillType(), + getBorderColor() != null ? new Color( getBorderColor().getRed(), getBorderColor() + .getGreen(), getBorderColor().getBlue() ) : null, + getFillColor() != null ? new Color( getFillColor().getRed(), getFillColor() + .getGreen(), getFillColor().getBlue() ) : null, + getSize(), + getTransparancy() ); + } + + public final Color getBorderColor() { + return _border_color; + } + + public final Color getFillColor() { + return _fill_color; + } + + public final NodeFill getFillType() { + return _fill_type; + } + + public final NodeShape getShape() { + return _shape; + } + + public final float getSize() { + return _size; + } + + public final float getTransparancy() { + return _transparancy; + } + + private final void init() { + setFont( null ); + setFontType( FontType.NORMAL ); + setFontSize( DEFAULT_FONT_SIZE ); + setFontColor( null ); + setShape( NodeShape.DEFAULT ); + setFillType( NodeFill.DEFAULT ); + setBorderColor( null ); + setFillColor( null ); + setSize( DEFAULT_SIZE ); + setTransparancy( DEFAULT_TRANSPARANCY ); + } + + @Override + public final boolean isEqual( final PhylogenyData data ) { + throw new UnsupportedOperationException(); + } + + public final void setBorderColor( final Color border_color ) { + _border_color = border_color; + } + + public final void setFillColor( final Color fill_color ) { + _fill_color = fill_color; + } + + public final void setFillType( final NodeFill fill_type ) { + _fill_type = fill_type; + } + + public final void setShape( final NodeShape shape ) { + _shape = shape; + } + + public final void setSize( final float size ) { + _size = size; + } + + public final void setTransparancy( final float transparancy ) { + _transparancy = transparancy; + } + + @Override + public final StringBuffer toNHX() { + throw new UnsupportedOperationException(); + } + + @Override + public final void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException { + throw new UnsupportedOperationException(); + } + + @Override + public final String toString() { + return asText().toString(); + } + + public enum NodeFill { + NONE, GRADIENT, SOLID, DEFAULT + } + + public enum NodeShape { + CIRCLE, RECTANGLE, DEFAULT + } + + public enum FontType { + NORMAL, BOLD, ITALIC, BOLD_ITALIC + } + + private final List toProperties() { + final List properties = new ArrayList(); + properties.add( new Property( SIZE_REF, String.valueOf( getSize() ), "", SIZE_TYPE, AppliesTo.NODE ) ); + properties.add( new Property( SIZE_REF, String.valueOf( getShape() ), "", SIZE_TYPE, AppliesTo.NODE ) ); + properties.add( new Property( SIZE_REF, String.valueOf( getFillType() ), "", SIZE_TYPE, AppliesTo.NODE ) ); + properties.add( new Property( SIZE_REF, String.valueOf( getTransparancy() ), "", SIZE_TYPE, AppliesTo.NODE ) ); + properties.add( new Property( SIZE_REF, String.valueOf( getFillColor() ), "", SIZE_TYPE, AppliesTo.NODE ) ); + properties.add( new Property( SIZE_REF, String.valueOf( getBorderColor() ), "", SIZE_TYPE, AppliesTo.NODE ) ); + return properties; + } + public static final String SIZE_REF = "aptx_visualiation:node_sise"; + public static final String SIZE_TYPE = "xsd:decimal"; + + public final boolean isEmpty() { + return ( ForesterUtil.isEmpty( getFont() ) && + getFontType() == FontType.NORMAL && + getFontSize() == DEFAULT_FONT_SIZE && + getFontColor() == null && + getShape() == NodeShape.DEFAULT && + getFillType() == NodeFill.DEFAULT && + getBorderColor() == null && + getFillColor() == null && + getSize() == DEFAULT_SIZE && + getTransparancy() == DEFAULT_TRANSPARANCY ); + } + + public final String getFont() { + return _font; + } + + public final void setFont( final String font ) { + if ( !ForesterUtil.isEmpty( font ) ) { + _font = font; + } + else { + _font = null; + } + } + + public final FontType getFontType() { + return _font_type; + } + + public final void setFontType( FontType font_type ) { + _font_type = font_type; + } + + public final byte getFontSize() { + return _font_size; + } + + public final void setFontSize( byte font_size ) { + _font_size = font_size; + } + + public final Color getFontColor() { + return _font_color; + } + + public final void setFontColor( Color font_color ) { + _font_color = font_color; + } +} diff --git a/forester/java/src/org/forester/phylogeny/data/NodeVisualization.java b/forester/java/src/org/forester/phylogeny/data/NodeVisualization.java deleted file mode 100644 index 5375526..0000000 --- a/forester/java/src/org/forester/phylogeny/data/NodeVisualization.java +++ /dev/null @@ -1,183 +0,0 @@ -// $Id: -// FORESTER -- software libraries and applications -// for evolutionary biology research and applications. -// -// Copyright (C) 2008-2009 Christian M. Zmasek -// Copyright (C) 2008-2009 Burnham Institute for Medical Research -// All rights reserved -// -// This library is free software; you can redistribute it and/or -// modify it under the terms of the GNU Lesser General Public -// License as published by the Free Software Foundation; either -// version 2.1 of the License, or (at your option) any later version. -// -// This library is distributed in the hope that it will be useful, -// but WITHOUT ANY WARRANTY; without even the implied warranty of -// MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU -// Lesser General Public License for more details. -// -// You should have received a copy of the GNU Lesser General Public -// License along with this library; if not, write to the Free Software -// Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA -// -// Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org - -package org.forester.phylogeny.data; - -import java.awt.Color; -import java.io.IOException; -import java.io.Writer; -import java.util.ArrayList; -import java.util.List; - -import org.forester.phylogeny.data.Property.AppliesTo; - -public class NodeVisualization implements PhylogenyData { - - private NodeShape _shape; - private NodeFill _fill_type; - private Color _border_color; - private Color _fill_color; - private double _size; - private double _transparancy; - - public NodeVisualization() { - init(); - } - - public NodeVisualization( final NodeShape shape, - final NodeFill fill_type, - final Color border_color, - final Color fill_color, - final double size, - final double transparancy ) { - setShape( shape ); - setFillType( fill_type ); - setBorderColor( border_color ); - setFillColor( fill_color ); - setSize( size ); - setTransparancy( transparancy ); - } - - @Override - public StringBuffer asSimpleText() { - return asText(); - } - - @Override - public StringBuffer asText() { - final StringBuffer sb = new StringBuffer(); - return sb; - } - - @Override - public PhylogenyData copy() { - return new NodeVisualization( getShape(), - getFillType(), - getBorderColor() != null ? new Color( getBorderColor().getRed(), getBorderColor() - .getGreen(), getBorderColor().getBlue() ) : null, - getFillColor() != null ? new Color( getFillColor().getRed(), getFillColor() - .getGreen(), getFillColor().getBlue() ) : null, - getSize(), - getTransparancy() ); - } - - public Color getBorderColor() { - return _border_color; - } - - public Color getFillColor() { - return _fill_color; - } - - public NodeFill getFillType() { - return _fill_type; - } - - public NodeShape getShape() { - return _shape; - } - - public double getSize() { - return _size; - } - - public double getTransparancy() { - return _transparancy; - } - - private void init() { - setShape( NodeShape.CIRCLE ); - setFillType( NodeFill.SOLID ); - setBorderColor( null ); - setFillColor( null ); - setSize( 0 ); - setTransparancy( 1 ); - } - - @Override - public boolean isEqual( final PhylogenyData data ) { - throw new UnsupportedOperationException(); - } - - public void setBorderColor( final Color border_color ) { - _border_color = border_color; - } - - public void setFillColor( final Color fill_color ) { - _fill_color = fill_color; - } - - public void setFillType( final NodeFill fill_type ) { - _fill_type = fill_type; - } - - public void setShape( final NodeShape shape ) { - _shape = shape; - } - - public void setSize( final double size ) { - _size = size; - } - - public void setTransparancy( final double transparancy ) { - _transparancy = transparancy; - } - - @Override - public StringBuffer toNHX() { - throw new UnsupportedOperationException(); - } - - @Override - public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException { - throw new UnsupportedOperationException(); - } - - @Override - public String toString() { - return asText().toString(); - } - - public enum NodeFill { - NONE, GRADIENT, SOLID - } - - public enum NodeShape { - CIRCLE, RECTANGLE - } - - private List toProperties() { - final List properties = new ArrayList(); - properties.add( new Property( SIZE_REF, String.valueOf( getSize() ), "", SIZE_TYPE, AppliesTo.NODE ) ); - properties.add( new Property( SIZE_REF, String.valueOf( getShape() ), "", SIZE_TYPE, AppliesTo.NODE ) ); - properties.add( new Property( SIZE_REF, String.valueOf( getFillType() ), "", SIZE_TYPE, AppliesTo.NODE ) ); - properties.add( new Property( SIZE_REF, String.valueOf( getTransparancy() ), "", SIZE_TYPE, AppliesTo.NODE ) ); - properties.add( new Property( SIZE_REF, String.valueOf( getFillColor() ), "", SIZE_TYPE, AppliesTo.NODE ) ); - properties.add( new Property( SIZE_REF, String.valueOf( getBorderColor() ), "", SIZE_TYPE, AppliesTo.NODE ) ); - return properties; - } - public static final String SIZE_REF = "aptx_visualiation:node_sise"; - public static final String SIZE_TYPE = "xsd:decimal"; -} -- 1.7.10.2