big refactoring (moving of methods)
[jalview.git] / forester / java / src / org / forester / phylogeny / data / BranchColor.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/forester
25
26 package org.forester.phylogeny.data;
27
28 import java.awt.Color;
29 import java.io.IOException;
30 import java.io.Writer;
31
32 import org.forester.io.parsers.nhx.NHXtags;
33 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
34 import org.forester.util.ForesterUtil;
35
36 public class BranchColor implements PhylogenyData {
37
38     private Color _color;
39
40     public BranchColor() {
41         _color = null;
42     }
43
44     public BranchColor( final Color color ) {
45         _color = color;
46     }
47
48     @Override
49     public StringBuffer asSimpleText() {
50         return new StringBuffer( getValue().toString() );
51     }
52
53     @Override
54     public StringBuffer asText() {
55         return new StringBuffer( getValue().toString() );
56     }
57
58     @Override
59     /**
60      * Not a deep copy.
61      * 
62      */
63     public PhylogenyData copy() {
64         final BranchColor bc = new BranchColor();
65         bc.setValue( getValue() );
66         return bc;
67     }
68
69     public Color getValue() {
70         return _color;
71     }
72
73     @Override
74     public boolean isEqual( final PhylogenyData data ) {
75         return getValue().equals( ( ( BranchColor ) data ).getValue() );
76     }
77
78     public void setValue( final Color color ) {
79         _color = color;
80     }
81
82     @Override
83     public StringBuffer toNHX() {
84         final StringBuffer sb = new StringBuffer();
85         sb.append( NHXtags.COLOR );
86         sb.append( getValue().getRed() );
87         sb.append( "." );
88         sb.append( getValue().getGreen() );
89         sb.append( "." );
90         sb.append( getValue().getBlue() );
91         return sb;
92     }
93
94     @Override
95     public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
96         writer.write( ForesterUtil.LINE_SEPARATOR );
97         writer.write( indentation );
98         PhylogenyDataUtil.appendOpen( writer, PhyloXmlMapping.COLOR );
99         PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.COLOR_RED, getValue().getRed() + "", indentation );
100         PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.COLOR_GREEN, getValue().getGreen() + "", indentation );
101         PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.COLOR_BLUE, getValue().getBlue() + "", indentation );
102         writer.write( ForesterUtil.LINE_SEPARATOR );
103         writer.write( indentation );
104         PhylogenyDataUtil.appendClose( writer, PhyloXmlMapping.COLOR );
105     }
106
107     @Override
108     public String toString() {
109         return asText().toString();
110     }
111 }