3 // FORESTER -- software libraries and applications
4 // for evolutionary biology research and applications.
6 // Copyright (C) 2008-2009 Christian M. Zmasek
7 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
10 // This library is free software; you can redistribute it and/or
11 // modify it under the terms of the GNU Lesser General Public
12 // License as published by the Free Software Foundation; either
13 // version 2.1 of the License, or (at your option) any later version.
15 // This library is distributed in the hope that it will be useful,
16 // but WITHOUT ANY WARRANTY; without even the implied warranty of
17 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
18 // Lesser General Public License for more details.
20 // You should have received a copy of the GNU Lesser General Public
21 // License along with this library; if not, write to the Free Software
22 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
24 // Contact: phylosoft @ gmail . com
25 // WWW: https://sites.google.com/site/cmzmasek/home/software/forester
27 package org.forester.archaeopteryx.phylogeny.data;
29 import java.awt.Color;
30 import java.awt.Dimension;
31 import java.awt.Graphics2D;
32 import java.awt.geom.Rectangle2D;
33 import java.io.IOException;
34 import java.io.Writer;
35 import java.util.List;
37 import org.forester.archaeopteryx.AptxUtil;
38 import org.forester.archaeopteryx.Configuration;
39 import org.forester.archaeopteryx.TreePanel;
40 import org.forester.phylogeny.data.PhylogenyData;
41 import org.forester.util.DescriptiveStatistics;
42 import org.forester.util.ForesterUtil;
44 public final class RenderableVector implements RenderablePhylogenyData {
46 final static public int DEFAULT_HEIGHT = 12;
47 final static public int DEFAULT_WIDTH = 120;
48 private double _rendering_factor_width = 1.0;
49 private List<Double> _values;
50 private final Rectangle2D _rectangle = new Rectangle2D.Float();
51 private Configuration _configuration;
52 private double _height;
56 private static RenderableVector _instance = null;
58 private RenderableVector() {
60 _configuration = null;
64 public StringBuffer asSimpleText() {
65 return new StringBuffer( _values.toString() );
69 public StringBuffer asText() {
70 return asSimpleText();
74 public Object clone() {
75 throw new NoSuchMethodError();
79 public PhylogenyData copy() {
80 throw new NoSuchMethodError();
84 public Dimension getOriginalSize() {
85 return new Dimension( getTotalLength(), ( int ) getRenderingHeight() );
89 public Object getParameter() {
93 public double getRenderingFactorWidth() {
94 return _rendering_factor_width;
98 public Dimension getRenderingSize() {
99 return getOriginalSize();
102 public int getTotalLength() {
103 return ( int ) ( _values.size() * getRenderingHeight() );
107 public boolean isEqual( final PhylogenyData data ) {
108 throw new NoSuchMethodError();
112 public void render( final double x1,
115 final TreePanel tree_panel,
116 final boolean to_pdf ) {
118 final double start = x1 + 20.0;
119 final double width = ( double ) DEFAULT_WIDTH / _values.size();
120 for( int i = 0; i < _values.size(); ++i ) {
121 g.setColor( calculateColor( _values.get( i ) ) );
122 _rectangle.setFrame( start + ( i * width ), y - 0.5, width, getRenderingHeight() );
123 g.fill( _rectangle );
128 public void setParameter( final double parameter ) {
129 throw new NoSuchMethodError();
132 public void setRenderingFactorWidth( final double rendering_factor_width ) {
133 _rendering_factor_width = rendering_factor_width;
137 public void setRenderingHeight( final double height ) {
142 public StringBuffer toNHX() {
143 throw new NoSuchMethodError();
147 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
148 throw new NoSuchMethodError();
151 private Color calculateColor( final double v ) {
152 return ForesterUtil.calcColor( v, _min, _max, _mean, Color.MAGENTA, Color.GREEN, Color.WHITE );
155 private double getRenderingHeight() {
159 public static RenderableVector createInstance( final List<Double> values,
160 final DescriptiveStatistics stats,
161 final Configuration configuration ) {
162 if ( _instance == null ) {
163 _instance = new RenderableVector();
165 _instance.setRenderingHeight( DEFAULT_HEIGHT );
166 _instance._values = values;
167 _instance._configuration = configuration;
168 if ( stats.getN() > 0 ) {
169 _instance._min = stats.getMin();
170 _instance._max = stats.getMax();
171 _instance._mean = stats.arithmeticMean();
177 AptxUtil.printWarningMessage( "Archaeopteryx", "creating renderable vector with empty statistics" );