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: https://sites.google.com/site/cmzmasek/home/software/forester
26 package org.forester.phylogeny.data;
28 import java.awt.Color;
29 import java.io.IOException;
30 import java.io.Writer;
32 import org.forester.io.parsers.nhx.NHXtags;
33 import org.forester.io.parsers.phyloxml.PhyloXmlMapping;
34 import org.forester.util.ForesterUtil;
36 public class BranchColor implements PhylogenyData {
40 public BranchColor() {
44 public BranchColor( final Color color ) {
49 public StringBuffer asSimpleText() {
50 return new StringBuffer( getValue().toString() );
54 public StringBuffer asText() {
55 return new StringBuffer( getValue().toString() );
63 public PhylogenyData copy() {
64 final BranchColor bc = new BranchColor();
65 bc.setValue( getValue() );
69 public Color getValue() {
74 public boolean isEqual( final PhylogenyData data ) {
75 return getValue().equals( ( ( BranchColor ) data ).getValue() );
78 public void setValue( final Color color ) {
83 public StringBuffer toNHX() {
84 final StringBuffer sb = new StringBuffer();
85 sb.append( NHXtags.COLOR );
86 sb.append( getValue().getRed() );
88 sb.append( getValue().getGreen() );
90 sb.append( getValue().getBlue() );
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 );
108 public String toString() {
109 return asText().toString();