2 package org.forester.phylogeny.data;
\r
4 import java.awt.Color;
\r
5 import java.awt.Font;
\r
6 import java.io.IOException;
\r
7 import java.io.Writer;
\r
8 import java.util.ArrayList;
\r
9 import java.util.List;
\r
11 import org.forester.phylogeny.data.Property.AppliesTo;
\r
12 import org.forester.util.ForesterUtil;
\r
14 public final class NodeVisualData implements PhylogenyData {
\r
16 public static final String SIZE_REF = "aptx_visualiation:node_size";
\r
17 public static final String SIZE_TYPE = "xsd:decimal";
\r
18 private static final byte DEFAULT_FONT_SIZE = -1;
\r
19 private static final int DEFAULT_SIZE = -1;
\r
20 private static final int DEFAULT_TRANSPARANCY = -1;
\r
21 private Color _border_color;
\r
22 private Color _fill_color;
\r
23 private NodeFill _fill_type;
\r
24 private String _font;
\r
25 private Color _font_color;
\r
26 private byte _font_size;
\r
27 private FontType _font_type;
\r
28 private NodeShape _shape;
\r
29 private float _size;
\r
30 private float _transparancy;
\r
32 public NodeVisualData() {
\r
36 public NodeVisualData( final String font,
\r
37 final FontType font_type,
\r
38 final byte font_size,
\r
39 final Color font_color,
\r
40 final NodeShape shape,
\r
41 final NodeFill fill_type,
\r
42 final Color border_color,
\r
43 final Color fill_color,
\r
45 final float transparancy ) {
\r
47 setFontType( font_type );
\r
48 setFontSize( font_size );
\r
49 setFontColor( font_color );
\r
51 setFillType( fill_type );
\r
52 setBorderColor( border_color );
\r
53 setFillColor( fill_color );
\r
55 setTransparancy( transparancy );
\r
59 public final StringBuffer asSimpleText() {
\r
64 public final StringBuffer asText() {
\r
65 final StringBuffer sb = new StringBuffer();
\r
70 public final PhylogenyData copy() {
\r
71 return new NodeVisualData( !ForesterUtil.isEmpty( getFont() ) ? new String( getFont() ) : null,
\r
74 getFontColor() != null ? new Color( getFontColor().getRed(), getFontColor()
\r
75 .getGreen(), getFontColor().getBlue() ) : null,
\r
78 getBorderColor() != null ? new Color( getBorderColor().getRed(), getBorderColor()
\r
79 .getGreen(), getBorderColor().getBlue() ) : null,
\r
80 getFillColor() != null ? new Color( getFillColor().getRed(), getFillColor()
\r
81 .getGreen(), getFillColor().getBlue() ) : null,
\r
83 getTransparancy() );
\r
86 public final Color getBorderColor() {
\r
87 return _border_color;
\r
90 public final Color getFillColor() {
\r
94 public final NodeFill getFillType() {
\r
98 public final String getFont() {
\r
102 public final Color getFontColor() {
\r
103 return _font_color;
\r
106 public final byte getFontSize() {
\r
110 public final FontType getFontType() {
\r
114 public final NodeShape getShape() {
\r
118 public final float getSize() {
\r
122 public final float getTransparancy() {
\r
123 return _transparancy;
\r
126 public final boolean isEmpty() {
\r
127 return ( ForesterUtil.isEmpty( getFont() ) && ( getFontType() == FontType.NORMAL )
\r
128 && ( getFontSize() == DEFAULT_FONT_SIZE ) && ( getFontColor() == null )
\r
129 && ( getShape() == NodeShape.DEFAULT ) && ( getFillType() == NodeFill.DEFAULT )
\r
130 && ( getBorderColor() == null ) && ( getFillColor() == null ) && ( getSize() == DEFAULT_SIZE ) && ( getTransparancy() == DEFAULT_TRANSPARANCY ) );
\r
134 public final boolean isEqual( final PhylogenyData data ) {
\r
135 throw new UnsupportedOperationException();
\r
138 public final void setBorderColor( final Color border_color ) {
\r
139 _border_color = border_color;
\r
142 public final void setFillColor( final Color fill_color ) {
\r
143 _fill_color = fill_color;
\r
146 public final void setFillType( final NodeFill fill_type ) {
\r
147 _fill_type = fill_type;
\r
150 public final void setFont( final String font ) {
\r
151 if ( !ForesterUtil.isEmpty( font ) ) {
\r
159 public final void setFontColor( final Color font_color ) {
\r
160 _font_color = font_color;
\r
163 public final void setFontSize( final byte font_size ) {
\r
164 _font_size = font_size;
\r
167 public final void setFontType( final FontType font_type ) {
\r
168 _font_type = font_type;
\r
171 public final void setShape( final NodeShape shape ) {
\r
175 public final void setSize( final float size ) {
\r
179 public final void setTransparancy( final float transparancy ) {
\r
180 _transparancy = transparancy;
\r
183 public final int getFontStyle() {
\r
184 if ( getFontType() == FontType.BOLD ) {
\r
187 else if ( getFontType() == FontType.ITALIC ) {
\r
188 return Font.ITALIC;
\r
190 else if ( getFontType() == FontType.BOLD_ITALIC ) {
\r
191 return Font.BOLD & Font.ITALIC;
\r
196 public final Font getFontObject() {
\r
197 if ( !ForesterUtil.isEmpty( getFont() ) ) {
\r
198 return new Font( getFont(), getFontStyle(), getFontSize() );
\r
204 public final StringBuffer toNHX() {
\r
205 throw new UnsupportedOperationException();
\r
209 public final void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {
\r
210 throw new UnsupportedOperationException();
\r
214 public final String toString() {
\r
215 return asText().toString();
\r
218 private final void init() {
\r
220 setFontType( FontType.NORMAL );
\r
221 setFontSize( DEFAULT_FONT_SIZE );
\r
222 setFontColor( null );
\r
223 setShape( NodeShape.DEFAULT );
\r
224 setFillType( NodeFill.DEFAULT );
\r
225 setBorderColor( null );
\r
226 setFillColor( null );
\r
227 setSize( DEFAULT_SIZE );
\r
228 setTransparancy( DEFAULT_TRANSPARANCY );
\r
231 private final List<Property> toProperties() {
\r
232 final List<Property> properties = new ArrayList<Property>();
\r
233 properties.add( new Property( SIZE_REF, String.valueOf( getSize() ), "", SIZE_TYPE, AppliesTo.NODE ) );
\r
234 properties.add( new Property( SIZE_REF, String.valueOf( getShape() ), "", SIZE_TYPE, AppliesTo.NODE ) );
\r
235 properties.add( new Property( SIZE_REF, String.valueOf( getFillType() ), "", SIZE_TYPE, AppliesTo.NODE ) );
\r
236 properties.add( new Property( SIZE_REF, String.valueOf( getTransparancy() ), "", SIZE_TYPE, AppliesTo.NODE ) );
\r
237 properties.add( new Property( SIZE_REF, String.valueOf( getFillColor() ), "", SIZE_TYPE, AppliesTo.NODE ) );
\r
238 properties.add( new Property( SIZE_REF, String.valueOf( getBorderColor() ), "", SIZE_TYPE, AppliesTo.NODE ) );
\r
242 public enum FontType {
\r
243 BOLD, BOLD_ITALIC, ITALIC, NORMAL
\r
246 public enum NodeFill {
\r
247 DEFAULT, GRADIENT, NONE, SOLID
\r
250 public enum NodeShape {
\r
251 CIRCLE, DEFAULT, RECTANGLE
\r