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: www.phylosoft.org/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.Configuration;
38 import org.forester.archaeopteryx.TreePanel;
39 import org.forester.phylogeny.data.PhylogenyData;
40 import org.forester.util.DescriptiveStatistics;
41 import org.forester.util.ForesterUtil;
43 public final class RenderableVector implements RenderablePhylogenyData {
45 final static public int DEFAULT_HEIGHT = 12;
46 final static public int DEFAULT_WIDTH = 120;
47 private double _rendering_factor_width = 1.0;
48 private List<Double> _values;
49 private final Rectangle2D _rectangle = new Rectangle2D.Float();
50 private Configuration _configuration;
51 private double _height;
55 private static RenderableVector _instance = null;
57 public static RenderableVector createInstance( final List<Double> values,
58 final DescriptiveStatistics stats,
59 final Configuration configuration ) {
60 if ( _instance == null ) {
61 _instance = new RenderableVector();
63 _instance.setRenderingHeight( DEFAULT_HEIGHT );
64 _instance._values = values;
65 _instance._configuration = configuration;
66 _instance._min = stats.getMin();
67 _instance._max = stats.getMax();
68 _instance._mean = stats.arithmeticMean();
73 public Object clone() {
74 throw new NoSuchMethodError();
77 private RenderableVector() {
79 _configuration = null;
83 public StringBuffer asSimpleText() {
84 return new StringBuffer( _values.toString() );
88 public StringBuffer asText() {
89 return asSimpleText();
92 public double getRenderingFactorWidth() {
93 return _rendering_factor_width;
96 public int getTotalLength() {
97 return ( int ) ( _values.size() * getRenderingHeight() );
101 public boolean isEqual( final PhylogenyData data ) {
102 throw new NoSuchMethodError();
106 public void render( final double x1,
109 final TreePanel tree_panel,
110 final boolean to_pdf ) {
112 final double start = x1 + 20.0;
113 final double width = ( double ) DEFAULT_WIDTH / _values.size();
114 for( int i = 0; i < _values.size(); ++i ) {
115 g.setColor( calculateColor( _values.get( i ) ) );
116 _rectangle.setFrame( start + i * width, y - 0.5, width, getRenderingHeight() );
117 g.fill( _rectangle );
121 private Color calculateColor( final double v ) {
122 return ForesterUtil.calcColor( v, _min, _max, _mean, Color.MAGENTA, Color.GREEN, Color.WHITE );
125 public void setRenderingFactorWidth( final double rendering_factor_width ) {
126 _rendering_factor_width = rendering_factor_width;
130 public StringBuffer toNHX() {
131 throw new NoSuchMethodError();
135 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
136 throw new NoSuchMethodError();
140 public PhylogenyData copy() {
141 throw new NoSuchMethodError();
145 public Dimension getOriginalSize() {
146 return new Dimension( getTotalLength(), ( int ) getRenderingHeight() );
150 public Object getParameter() {
155 public Dimension getRenderingSize() {
156 return getOriginalSize();
160 public void setParameter( final double parameter ) {
161 throw new NoSuchMethodError();
165 public void setRenderingHeight( final double height ) {
169 private double getRenderingHeight() {