\r
public final class NodeVisualData implements PhylogenyData {\r
\r
- public static final String SIZE_REF = "aptx_visualiation:node_size";\r
- public static final String SIZE_TYPE = "xsd:decimal";\r
- private static final byte DEFAULT_FONT_SIZE = -1;\r
- private static final int DEFAULT_SIZE = -1;\r
- private static final int DEFAULT_TRANSPARANCY = -1;\r
+ public static final String APTX_VISUALIZATION_REF = "aptx_visualization:";\r
+ public static final String FONT_REF = APTX_VISUALIZATION_REF + "node_font";\r
+ public static final String FONT_SIZE_REF = APTX_VISUALIZATION_REF + "node_font_size";\r
+ public static final String FONT_SIZE_TYPE = "xsd:unsignedByte";\r
+ public static final String FONT_STYLE_BOLD = "bold";\r
+ public static final String FONT_STYLE_BOLD_ITALIC = "bold_italic";\r
+ public static final String FONT_STYLE_ITALIC = "italic";\r
+ public static final String FONT_STYLE_PLAIN = "plain";\r
+ public static final String FONT_STYLE_REF = APTX_VISUALIZATION_REF + "node_font_style";\r
+ public static final String FONT_STYLE_TYPE = "xsd:token";\r
+ public static final String FONT_TYPE = "xsd:token";\r
+ private static final byte DEFAULT_FONT_SIZE = -1;\r
+ private static final int DEFAULT_SIZE = -1;\r
+ private static final int DEFAULT_TRANSPARANCY = -1;\r
private Color _border_color;\r
private Color _fill_color;\r
private NodeFill _fill_type;\r
- private String _font_name;\r
+ private Font _font;\r
private Color _font_color;\r
+ private String _font_name;\r
private byte _font_size;\r
private FontType _font_style;\r
private NodeShape _shape;\r
private float _size;\r
private float _transparancy;\r
- private Font _font;\r
\r
public NodeVisualData() {\r
init();\r
return _fill_type;\r
}\r
\r
- public final String getFontName() {\r
- return _font_name;\r
+ public final Font getFont() {\r
+ if ( _font != null ) {\r
+ return _font;\r
+ }\r
+ else if ( !ForesterUtil.isEmpty( getFontName() ) ) {\r
+ _font = new Font( getFontName(), getFontStyleInt(), getFontSize() );\r
+ return _font;\r
+ }\r
+ return null;\r
}\r
\r
public final Color getFontColor() {\r
return _font_color;\r
}\r
\r
+ public final String getFontName() {\r
+ return _font_name;\r
+ }\r
+\r
public final byte getFontSize() {\r
return _font_size;\r
}\r
return _font_style;\r
}\r
\r
+ public final int getFontStyleInt() {\r
+ if ( getFontStyle() == FontType.BOLD ) {\r
+ return Font.BOLD;\r
+ }\r
+ else if ( getFontStyle() == FontType.ITALIC ) {\r
+ return Font.ITALIC;\r
+ }\r
+ else if ( getFontStyle() == FontType.BOLD_ITALIC ) {\r
+ return Font.BOLD + Font.ITALIC;\r
+ }\r
+ return Font.PLAIN;\r
+ }\r
+\r
public final NodeShape getShape() {\r
return _shape;\r
}\r
throw new UnsupportedOperationException();\r
}\r
\r
+ public void parseProperty( final Property prop ) {\r
+ if ( prop.getRef().equals( FONT_REF ) ) {\r
+ setFontName( prop.getValue().trim() );\r
+ }\r
+ else if ( prop.getRef().equals( FONT_SIZE_REF ) ) {\r
+ int s = -1;\r
+ try {\r
+ s = Integer.parseInt( prop.getValue() );\r
+ }\r
+ catch ( final NumberFormatException e ) {\r
+ return;\r
+ }\r
+ if ( ( s >= 0 ) && ( s < Byte.MAX_VALUE ) ) {\r
+ setFontSize( s );\r
+ }\r
+ }\r
+ else if ( prop.getRef().equals( FONT_STYLE_REF ) ) {\r
+ setFontStyle( prop.getValue() );\r
+ }\r
+ }\r
+\r
public final void setBorderColor( final Color border_color ) {\r
_border_color = border_color;\r
}\r
_fill_type = fill_type;\r
}\r
\r
+ public final void setFontColor( final Color font_color ) {\r
+ _font_color = font_color;\r
+ }\r
+\r
public final void setFontName( final String font_name ) {\r
if ( !ForesterUtil.isEmpty( font_name ) ) {\r
_font_name = font_name;\r
_font = null;\r
}\r
\r
- public final void setFontColor( final Color font_color ) {\r
- _font_color = font_color;\r
- }\r
-\r
public final void setFontSize( final int font_size ) {\r
if ( ( font_size != DEFAULT_FONT_SIZE ) && ( font_size < 0 ) ) {\r
throw new IllegalArgumentException( "negative font size: " + font_size );\r
}\r
}\r
\r
+ public final void setFontStyle( final String font_style ) {\r
+ if ( font_style.equalsIgnoreCase( FONT_STYLE_BOLD ) ) {\r
+ setFontStyle( FontType.BOLD );\r
+ }\r
+ else if ( font_style.equalsIgnoreCase( FONT_STYLE_ITALIC ) ) {\r
+ setFontStyle( FontType.ITALIC );\r
+ }\r
+ else if ( font_style.equalsIgnoreCase( FONT_STYLE_BOLD_ITALIC ) ) {\r
+ setFontStyle( FontType.BOLD_ITALIC );\r
+ }\r
+ else {\r
+ setFontStyle( FontType.PLAIN );\r
+ }\r
+ }\r
+\r
public final void setShape( final NodeShape shape ) {\r
_shape = shape;\r
}\r
_transparancy = transparancy;\r
}\r
\r
- public final int getFontStyleInt() {\r
- if ( getFontStyle() == FontType.BOLD ) {\r
- return Font.BOLD;\r
- }\r
- else if ( getFontStyle() == FontType.ITALIC ) {\r
- return Font.ITALIC;\r
- }\r
- else if ( getFontStyle() == FontType.BOLD_ITALIC ) {\r
- return Font.BOLD + Font.ITALIC;\r
- }\r
- return Font.PLAIN;\r
- }\r
-\r
- public final Font getFont() {\r
- if ( _font != null ) {\r
- return _font;\r
- }\r
- else if ( !ForesterUtil.isEmpty( getFontName() ) ) {\r
- _font = new Font( getFontName(), getFontStyleInt(), getFontSize() );\r
- return _font;\r
- }\r
- return null;\r
- }\r
-\r
@Override\r
public final StringBuffer toNHX() {\r
throw new UnsupportedOperationException();\r
\r
@Override\r
public final void toPhyloXML( final Writer writer, final int level, final String indentation ) throws IOException {\r
- throw new UnsupportedOperationException();\r
+ for( final Property p : toProperties() ) {\r
+ p.toPhyloXML( writer, level, indentation );\r
+ }\r
}\r
\r
@Override\r
\r
private final List<Property> toProperties() {\r
final List<Property> properties = new ArrayList<Property>();\r
- properties.add( new Property( SIZE_REF, String.valueOf( getSize() ), "", SIZE_TYPE, AppliesTo.NODE ) );\r
- properties.add( new Property( SIZE_REF, String.valueOf( getShape() ), "", SIZE_TYPE, AppliesTo.NODE ) );\r
- properties.add( new Property( SIZE_REF, String.valueOf( getFillType() ), "", SIZE_TYPE, AppliesTo.NODE ) );\r
- properties.add( new Property( SIZE_REF, String.valueOf( getTransparancy() ), "", SIZE_TYPE, AppliesTo.NODE ) );\r
- properties.add( new Property( SIZE_REF, String.valueOf( getFillColor() ), "", SIZE_TYPE, AppliesTo.NODE ) );\r
- properties.add( new Property( SIZE_REF, String.valueOf( getBorderColor() ), "", SIZE_TYPE, AppliesTo.NODE ) );\r
+ if ( !ForesterUtil.isEmpty( getFontName() ) ) {\r
+ properties.add( new Property( FONT_REF, getFontName(), "", FONT_TYPE, AppliesTo.NODE ) );\r
+ }\r
+ if ( getFontSize() != DEFAULT_FONT_SIZE ) {\r
+ properties.add( new Property( FONT_SIZE_REF,\r
+ String.valueOf( getFontSize() ),\r
+ "",\r
+ FONT_SIZE_TYPE,\r
+ AppliesTo.NODE ) );\r
+ }\r
+ if ( getFontStyle() != FontType.PLAIN ) {\r
+ String font_style = FONT_STYLE_PLAIN;\r
+ if ( getFontStyle() == FontType.ITALIC ) {\r
+ font_style = FONT_STYLE_ITALIC;\r
+ }\r
+ else if ( getFontStyle() == FontType.BOLD ) {\r
+ font_style = FONT_STYLE_BOLD;\r
+ }\r
+ else if ( getFontStyle() == FontType.BOLD_ITALIC ) {\r
+ font_style = FONT_STYLE_BOLD_ITALIC;\r
+ }\r
+ properties.add( new Property( FONT_STYLE_REF, font_style, "", FONT_STYLE_TYPE, AppliesTo.NODE ) );\r
+ }\r
return properties;\r
}\r
\r