in progress
[jalview.git] / forester / java / src / org / forester / phylogeny / data / NodeVisualization.java
1 // $Id:
2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
4 //
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
7 // All rights reserved
8 //
9 // This library is free software; you can redistribute it and/or
10 // modify it under the terms of the GNU Lesser General Public
11 // License as published by the Free Software Foundation; either
12 // version 2.1 of the License, or (at your option) any later version.
13 //
14 // This library is distributed in the hope that it will be useful,
15 // but WITHOUT ANY WARRANTY; without even the implied warranty of
16 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17 // Lesser General Public License for more details.
18 //
19 // You should have received a copy of the GNU Lesser General Public
20 // License along with this library; if not, write to the Free Software
21 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA
22 //
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org
25
26 package org.forester.phylogeny.data;
27
28 import java.awt.Color;
29 import java.io.IOException;
30 import java.io.Writer;
31 import java.util.ArrayList;
32 import java.util.List;
33
34 import org.forester.phylogeny.data.Property.AppliesTo;
35
36 public class NodeVisualization implements PhylogenyData {
37
38     private NodeShape _shape;
39     private NodeFill  _fill_type;
40     private Color     _border_color;
41     private Color     _fill_color;
42     private double    _size;
43     private double    _transparancy;
44
45     public NodeVisualization() {
46         init();
47     }
48
49     public NodeVisualization( final NodeShape shape,
50                               final NodeFill fill_type,
51                               final Color border_color,
52                               final Color fill_color,
53                               final double size,
54                               final double transparancy ) {
55         setShape( shape );
56         setFillType( fill_type );
57         setBorderColor( border_color );
58         setFillColor( fill_color );
59         setSize( size );
60         setTransparancy( transparancy );
61     }
62
63     @Override
64     public StringBuffer asSimpleText() {
65         return asText();
66     }
67
68     @Override
69     public StringBuffer asText() {
70         final StringBuffer sb = new StringBuffer();
71         return sb;
72     }
73
74     @Override
75     public PhylogenyData copy() {
76         return new NodeVisualization( getShape(),
77                                       getFillType(),
78                                       getBorderColor() != null ? new Color( getBorderColor().getRed(), getBorderColor()
79                                               .getGreen(), getBorderColor().getBlue() ) : null,
80                                       getFillColor() != null ? new Color( getFillColor().getRed(), getFillColor()
81                                               .getGreen(), getFillColor().getBlue() ) : null,
82                                       getSize(),
83                                       getTransparancy() );
84     }
85
86     public Color getBorderColor() {
87         return _border_color;
88     }
89
90     public Color getFillColor() {
91         return _fill_color;
92     }
93
94     public NodeFill getFillType() {
95         return _fill_type;
96     }
97
98     public NodeShape getShape() {
99         return _shape;
100     }
101
102     public double getSize() {
103         return _size;
104     }
105
106     public double getTransparancy() {
107         return _transparancy;
108     }
109
110     private void init() {
111         setShape( NodeShape.CIRCLE );
112         setFillType( NodeFill.SOLID );
113         setBorderColor( null );
114         setFillColor( null );
115         setSize( 0 );
116         setTransparancy( 1 );
117     }
118
119     @Override
120     public boolean isEqual( final PhylogenyData data ) {
121         throw new UnsupportedOperationException();
122     }
123
124     public void setBorderColor( final Color border_color ) {
125         _border_color = border_color;
126     }
127
128     public void setFillColor( final Color fill_color ) {
129         _fill_color = fill_color;
130     }
131
132     public void setFillType( final NodeFill fill_type ) {
133         _fill_type = fill_type;
134     }
135
136     public void setShape( final NodeShape shape ) {
137         _shape = shape;
138     }
139
140     public void setSize( final double size ) {
141         _size = size;
142     }
143
144     public void setTransparancy( final double transparancy ) {
145         _transparancy = transparancy;
146     }
147
148     @Override
149     public StringBuffer toNHX() {
150         throw new UnsupportedOperationException();
151     }
152
153     @Override
154     public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
155         throw new UnsupportedOperationException();
156     }
157
158     @Override
159     public String toString() {
160         return asText().toString();
161     }
162
163     public enum NodeFill {
164         NONE, GRADIENT, SOLID
165     }
166
167     public enum NodeShape {
168         CIRCLE, RECTANGLE
169     }
170
171     private List<Property> toProperties() {
172         final List<Property> properties = new ArrayList<Property>();
173         properties.add( new Property( SIZE_REF, String.valueOf( getSize() ), "", SIZE_TYPE, AppliesTo.NODE ) );
174         properties.add( new Property( SIZE_REF, String.valueOf( getShape() ), "", SIZE_TYPE, AppliesTo.NODE ) );
175         properties.add( new Property( SIZE_REF, String.valueOf( getFillType() ), "", SIZE_TYPE, AppliesTo.NODE ) );
176         properties.add( new Property( SIZE_REF, String.valueOf( getTransparancy() ), "", SIZE_TYPE, AppliesTo.NODE ) );
177         properties.add( new Property( SIZE_REF, String.valueOf( getFillColor() ), "", SIZE_TYPE, AppliesTo.NODE ) );
178         properties.add( new Property( SIZE_REF, String.valueOf( getBorderColor() ), "", SIZE_TYPE, AppliesTo.NODE ) );
179         return properties;
180     }
181     public static final String SIZE_REF  = "aptx_visualiation:node_sise";
182     public static final String SIZE_TYPE = "xsd:decimal";
183 }