X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Farchaeopteryx%2Fphylogeny%2Fdata%2FRenderableVector.java;h=c39cf8d768d1082b207955ce02cf2727a7954d71;hb=1702b9bd1e87048151c4b40c9c8598291d6fcfed;hp=df16b7549ef378c390055bf6802d2e2e130a1b48;hpb=656be28debec520e0e35a8b311114398a40ea366;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 df16b75..c39cf8d 100644 --- a/forester/java/src/org/forester/archaeopteryx/phylogeny/data/RenderableVector.java +++ b/forester/java/src/org/forester/archaeopteryx/phylogeny/data/RenderableVector.java @@ -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; + final static public 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,7 +121,7 @@ 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() ); @@ -118,8 +129,9 @@ public final class RenderableVector implements RenderablePhylogenyData { } } - 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.setRenderingHeight( VECTOR_DEFAULT_HEIGHT ); + _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; + } }