X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2Fphylogeny%2Fdata%2FRenderableVector.java;h=02782ffb441b5d6847abe84038396a5f3e8d95b0;hb=9673231c870387fffa4516124d802ee47bbdaf45;hp=2785daf23f0d47cffa5dcbd01f6b28edf4505782;hpb=eee996a6476a1e3d84c07f8f690dcde3ff4b2ef5;p=jalview.git diff --git a/forester/java/src/org/forester/archaeopteryx/phylogeny/data/RenderableVector.java b/forester/java/src/org/forester/archaeopteryx/phylogeny/data/RenderableVector.java index 2785daf..02782ff 100644 --- a/forester/java/src/org/forester/archaeopteryx/phylogeny/data/RenderableVector.java +++ b/forester/java/src/org/forester/archaeopteryx/phylogeny/data/RenderableVector.java @@ -22,7 +22,7 @@ // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA // // Contact: phylosoft @ gmail . com -// WWW: www.phylosoft.org/forester +// WWW: https://sites.google.com/site/cmzmasek/home/software/forester package org.forester.archaeopteryx.phylogeny.data; @@ -34,6 +34,7 @@ import java.io.IOException; import java.io.Writer; import java.util.List; +import org.forester.archaeopteryx.AptxUtil; import org.forester.archaeopteryx.Configuration; import org.forester.archaeopteryx.TreePanel; import org.forester.phylogeny.data.PhylogenyData; @@ -42,31 +43,36 @@ import org.forester.util.ForesterUtil; public final class RenderableVector implements RenderablePhylogenyData { - final static public int DEFAULT_HEIGHT = 12; - final static public int DEFAULT_WIDTH = 120; + final static int VECTOR_DEFAULT_HEIGHT = 12; + public final static int VECTOR_DEFAULT_WIDTH = 120; private double _rendering_factor_width = 1.0; private List _values; private final Rectangle2D _rectangle = new Rectangle2D.Float(); - private Configuration _configuration; - private double _height; + + private double _height = VECTOR_DEFAULT_HEIGHT; private double _min; private double _max; private double _mean; + private Color _min_color = Color.BLUE; + private Color _max_color = Color.YELLOW; + private Color _mean_color = Color.WHITE; + private int _width = VECTOR_DEFAULT_WIDTH; + + private static RenderableVector _instance = null; - public static RenderableVector createInstance( final List values, - final DescriptiveStatistics stats, - final Configuration configuration ) { - if ( _instance == null ) { - _instance = new RenderableVector(); - } - _instance.setRenderingHeight( DEFAULT_HEIGHT ); - _instance._values = values; - _instance._configuration = configuration; - _instance._min = stats.getMin(); - _instance._max = stats.getMax(); - _instance._mean = stats.arithmeticMean(); - return _instance; + private RenderableVector() { + _values = null; + } + + @Override + public StringBuffer asSimpleText() { + return new StringBuffer( _values.toString() ); + } + + @Override + public StringBuffer asText() { + return asSimpleText(); } @Override @@ -74,25 +80,30 @@ public final class RenderableVector implements RenderablePhylogenyData { throw new NoSuchMethodError(); } - private RenderableVector() { - _values = null; - _configuration = null; + @Override + public PhylogenyData copy() { + throw new NoSuchMethodError(); } @Override - public StringBuffer asSimpleText() { - return new StringBuffer( _values.toString() ); + public Dimension getOriginalSize() { + return new Dimension( getTotalLength(), ( int ) getRenderingHeight() ); } @Override - public StringBuffer asText() { - return asSimpleText(); + public Object getParameter() { + return null; } public double getRenderingFactorWidth() { return _rendering_factor_width; } + @Override + public Dimension getRenderingSize() { + return getOriginalSize(); + } + public int getTotalLength() { return ( int ) ( _values.size() * getRenderingHeight() ); } @@ -110,16 +121,17 @@ public final class RenderableVector implements RenderablePhylogenyData { final boolean to_pdf ) { final double y = y1; final double start = x1 + 20.0; - final double width = ( double ) DEFAULT_WIDTH / _values.size(); + final double width = ( double ) _width / _values.size(); for( int i = 0; i < _values.size(); ++i ) { g.setColor( calculateColor( _values.get( i ) ) ); - _rectangle.setFrame( start + i * width, y - 0.5, width, getRenderingHeight() ); + _rectangle.setFrame( start + ( i * width ), y - 0.5, width, getRenderingHeight() ); g.fill( _rectangle ); } } - private Color calculateColor( final double v ) { - return ForesterUtil.calcColor( v, _min, _max, _mean, Color.MAGENTA, Color.GREEN, Color.WHITE ); + @Override + public void setParameter( final double parameter ) { + throw new NoSuchMethodError(); } public void setRenderingFactorWidth( final double rendering_factor_width ) { @@ -127,46 +139,57 @@ public final class RenderableVector implements RenderablePhylogenyData { } @Override - public StringBuffer toNHX() { - throw new NoSuchMethodError(); - } - - @Override - public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException { - throw new NoSuchMethodError(); + public void setRenderingHeight( final double height ) { + _height = height; } @Override - public PhylogenyData copy() { + public StringBuffer toNHX() { throw new NoSuchMethodError(); } @Override - public Dimension getOriginalSize() { - return new Dimension( getTotalLength(), ( int ) getRenderingHeight() ); - } - - @Override - public Object getParameter() { - return null; - } - - @Override - public Dimension getRenderingSize() { - return getOriginalSize(); - } - - @Override - public void setParameter( final double parameter ) { + public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException { throw new NoSuchMethodError(); } - @Override - public void setRenderingHeight( final double height ) { - _height = height; + private Color calculateColor( final double v ) { + return ForesterUtil.calcColor( v, _min, _max, _mean, _min_color, _max_color, _mean_color ); } private double getRenderingHeight() { return _height; } + + public static RenderableVector createInstance( final List values, + final DescriptiveStatistics stats, + final Configuration configuration ) { + if ( _instance == null ) { + _instance = new RenderableVector(); + } + + _instance._values = values; + + if ( configuration != null ) { + _instance._min_color =configuration.getVectorDataMinColor(); + _instance._max_color = configuration.getVectorDataMaxColor(); + _instance._mean_color = configuration.getVectorDataMeanColor(); + _instance._width = configuration.getVectorDataWidth(); + _instance._height = configuration.getVectorDataHeight(); + } + + + if ( stats.getN() > 0 ) { + _instance._min = stats.getMin(); + _instance._max = stats.getMax(); + _instance._mean = stats.arithmeticMean(); + } + else { + _instance._min = 0; + _instance._max = 0; + _instance._mean = 0; + AptxUtil.printWarningMessage( "Archaeopteryx", "creating renderable vector with empty statistics" ); + } + return _instance; + } }