2 // FORESTER -- software libraries and applications
3 // for evolutionary biology research and applications.
5 // Copyright (C) 2008-2009 Christian M. Zmasek
6 // Copyright (C) 2008-2009 Burnham Institute for Medical Research
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.
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.
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
23 // Contact: phylosoft @ gmail . com
24 // WWW: www.phylosoft.org
26 package org.forester.phylogeny.data;
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;
34 import org.forester.phylogeny.data.Property.AppliesTo;
36 public class NodeVisualization implements PhylogenyData {
38 private NodeShape _shape;
39 private NodeFill _fill_type;
40 private Color _border_color;
41 private Color _fill_color;
43 private double _transparancy;
45 public NodeVisualization() {
49 public NodeVisualization( final NodeShape shape,
50 final NodeFill fill_type,
51 final Color border_color,
52 final Color fill_color,
54 final double transparancy ) {
56 setFillType( fill_type );
57 setBorderColor( border_color );
58 setFillColor( fill_color );
60 setTransparancy( transparancy );
64 public StringBuffer asSimpleText() {
69 public StringBuffer asText() {
70 final StringBuffer sb = new StringBuffer();
75 public PhylogenyData copy() {
76 return new NodeVisualization( getShape(),
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,
86 public Color getBorderColor() {
90 public Color getFillColor() {
94 public NodeFill getFillType() {
98 public NodeShape getShape() {
102 public double getSize() {
106 public double getTransparancy() {
107 return _transparancy;
110 private void init() {
111 setShape( NodeShape.CIRCLE );
112 setFillType( NodeFill.SOLID );
113 setBorderColor( null );
114 setFillColor( null );
116 setTransparancy( 1 );
120 public boolean isEqual( final PhylogenyData data ) {
121 throw new UnsupportedOperationException();
124 public void setBorderColor( final Color border_color ) {
125 _border_color = border_color;
128 public void setFillColor( final Color fill_color ) {
129 _fill_color = fill_color;
132 public void setFillType( final NodeFill fill_type ) {
133 _fill_type = fill_type;
136 public void setShape( final NodeShape shape ) {
140 public void setSize( final double size ) {
144 public void setTransparancy( final double transparancy ) {
145 _transparancy = transparancy;
149 public StringBuffer toNHX() {
150 throw new UnsupportedOperationException();
154 public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
155 throw new UnsupportedOperationException();
159 public String toString() {
160 return asText().toString();
163 public enum NodeFill {
164 NONE, GRADIENT, SOLID
167 public enum NodeShape {
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 ) );
181 public static final String SIZE_REF = "aptx_visualiation:node_sise";
182 public static final String SIZE_TYPE = "xsd:decimal";