7d47e24f568c87ee686c1995b7c1ceafd8f7f744
[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: https://sites.google.com/site/cmzmasek/home/software/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.phyloxml.PhyloXmlMapping;
33 import org.forester.util.ForesterUtil;
34
35 public class BranchColor implements PhylogenyData {
36
37     private Color _color;
38
39     public BranchColor() {
40         _color = null;
41     }
42
43     public BranchColor( final Color color ) {
44         _color = color;
45     }
46
47     @Override
48     public StringBuffer asSimpleText() {
49         return new StringBuffer( getValue().toString() );
50     }
51
52     @Override
53     public StringBuffer asText() {
54         return new StringBuffer( getValue().toString() );
55     }
56
57     @Override
58     /**
59      * Not a deep copy.
60      *
61      */
62     public PhylogenyData copy() {
63         final BranchColor bc = new BranchColor();
64         bc.setValue( getValue() );
65         return bc;
66     }
67
68     public Color getValue() {
69         return _color;
70     }
71
72     @Override
73     public boolean isEqual( final PhylogenyData data ) {
74         return getValue().equals( ( ( BranchColor ) data ).getValue() );
75     }
76
77     public void setValue( final Color color ) {
78         _color = color;
79     }
80
81     @Override
82     public StringBuffer toNHX() {
83         throw new UnsupportedOperationException();
84     }
85
86     @Override
87     public void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
88         writer.write( ForesterUtil.LINE_SEPARATOR );
89         writer.write( indentation );
90         PhylogenyDataUtil.appendOpen( writer, PhyloXmlMapping.COLOR );
91         PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.COLOR_RED, getValue().getRed() + "", indentation );
92         PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.COLOR_GREEN, getValue().getGreen() + "", indentation );
93         PhylogenyDataUtil.appendElement( writer, PhyloXmlMapping.COLOR_BLUE, getValue().getBlue() + "", indentation );
94         writer.write( ForesterUtil.LINE_SEPARATOR );
95         writer.write( indentation );
96         PhylogenyDataUtil.appendClose( writer, PhyloXmlMapping.COLOR );
97     }
98
99     @Override
100     public String toString() {
101         return asText().toString();
102     }
103 }