From: cmzmasek@gmail.com Date: Wed, 2 Apr 2014 23:37:55 +0000 (+0000) Subject: inprogress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=639e47e620cf7e78465d79d4f51a633e301d78ae;p=jalview.git inprogress --- diff --git a/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java b/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java index 79faa7f..a2018a2 100644 --- a/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java +++ b/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java @@ -13,20 +13,39 @@ import org.forester.util.ForesterUtil; public final class NodeVisualData implements PhylogenyData { - public static final String APTX_VISUALIZATION_REF = "aptx_visualization:"; - public static final String FONT_REF = APTX_VISUALIZATION_REF + "node_font"; - public static final String FONT_SIZE_REF = APTX_VISUALIZATION_REF + "node_font_size"; + public static final String APTX_VISUALIZATION_REF = "style:"; + public static final String FONT_COLOR_REF = APTX_VISUALIZATION_REF + "font_color"; + public static final String FONT_COLOR_TYPE = "xsd:token"; + public static final String FONT_REF = APTX_VISUALIZATION_REF + "font"; + public static final String FONT_SIZE_REF = APTX_VISUALIZATION_REF + "font_size"; public static final String FONT_SIZE_TYPE = "xsd:unsignedByte"; public static final String FONT_STYLE_BOLD = "bold"; public static final String FONT_STYLE_BOLD_ITALIC = "bold_italic"; public static final String FONT_STYLE_ITALIC = "italic"; public static final String FONT_STYLE_PLAIN = "plain"; - public static final String FONT_STYLE_REF = APTX_VISUALIZATION_REF + "node_font_style"; + public static final String FONT_STYLE_REF = APTX_VISUALIZATION_REF + "font_style"; public static final String FONT_STYLE_TYPE = "xsd:token"; public static final String FONT_TYPE = "xsd:token"; + public static final String NODE_BORDER_COLOR_REF = APTX_VISUALIZATION_REF + "border_color"; + public static final String NODE_BORDER_COLOR_TYPE = "xsd:token"; + public static final String NODE_FILL_COLOR_REF = APTX_VISUALIZATION_REF + "fill_color"; + public static final String NODE_FILL_COLOR_TYPE = "xsd:token"; + public static final String NODE_FILL_GRADIENT = "gradient"; + public static final String NODE_FILL_NONE = "none"; + public static final String NODE_FILL_SOLID = "solid"; + public static final String NODE_FILL_TYPE_REF = APTX_VISUALIZATION_REF + "fill_type"; + public static final String NODE_FILL_TYPE_TYPE = "xsd:token"; + public static final String NODE_SHAPE_CIRCLE = "cicle"; + public static final String NODE_SHAPE_RECTANGLE = "rectangle"; + public static final String NODE_SHAPE_REF = APTX_VISUALIZATION_REF + "shape"; + public static final String NODE_SHAPE_TYPE = "xsd:token"; + public static final String NODE_SIZE_REF = APTX_VISUALIZATION_REF + "size"; + public static final String NODE_SIZE_TYPE = "xsd:float"; + public static final String NODE_TRANSPARENCY_REF = APTX_VISUALIZATION_REF + "transparency"; + public static final String NODE_TRANSPARENCY_TYPE = "xsd:float"; private static final byte DEFAULT_FONT_SIZE = -1; private static final int DEFAULT_SIZE = -1; - private static final int DEFAULT_TRANSPARANCY = -1; + private static final int DEFAULT_TRANSPARENCY = -1; private Color _border_color; private Color _fill_color; private NodeFill _fill_type; @@ -37,7 +56,7 @@ public final class NodeVisualData implements PhylogenyData { private FontType _font_style; private NodeShape _shape; private float _size; - private float _transparancy; + private float _transparency; public NodeVisualData() { init(); @@ -52,7 +71,7 @@ public final class NodeVisualData implements PhylogenyData { final Color border_color, final Color fill_color, final float size, - final float transparancy ) { + final float transparency ) { setFontName( font_name ); setFontStyle( font_style ); setFontSize( font_size ); @@ -62,7 +81,7 @@ public final class NodeVisualData implements PhylogenyData { setBorderColor( border_color ); setFillColor( fill_color ); setSize( size ); - setTransparancy( transparancy ); + setTransparency( transparency ); } @Override @@ -90,7 +109,7 @@ public final class NodeVisualData implements PhylogenyData { getFillColor() != null ? new Color( getFillColor().getRed(), getFillColor() .getGreen(), getFillColor().getBlue() ) : null, getSize(), - getTransparancy() ); + getTransparency() ); } public final Color getBorderColor() { @@ -153,15 +172,15 @@ public final class NodeVisualData implements PhylogenyData { return _size; } - public final float getTransparancy() { - return _transparancy; + public final float getTransparency() { + return _transparency; } public final boolean isEmpty() { return ( ForesterUtil.isEmpty( getFontName() ) && ( getFontStyle() == FontType.PLAIN ) && ( getFontSize() == DEFAULT_FONT_SIZE ) && ( getFontColor() == null ) && ( getShape() == NodeShape.DEFAULT ) && ( getFillType() == NodeFill.DEFAULT ) - && ( getBorderColor() == null ) && ( getFillColor() == null ) && ( getSize() == DEFAULT_SIZE ) && ( getTransparancy() == DEFAULT_TRANSPARANCY ) ); + && ( getBorderColor() == null ) && ( getFillColor() == null ) && ( getSize() == DEFAULT_SIZE ) && ( getTransparency() == DEFAULT_TRANSPARENCY ) ); } @Override @@ -188,6 +207,14 @@ public final class NodeVisualData implements PhylogenyData { else if ( prop.getRef().equals( FONT_STYLE_REF ) ) { setFontStyle( prop.getValue() ); } + else if ( prop.getRef().equals( FONT_COLOR_REF ) ) { + try { + setFontColor( Color.decode( prop.getValue() ) ); + } + catch ( final NumberFormatException e ) { + return; + } + } } public final void setBorderColor( final Color border_color ) { @@ -270,8 +297,8 @@ public final class NodeVisualData implements PhylogenyData { _size = size; } - public final void setTransparancy( final float transparancy ) { - _transparancy = transparancy; + public final void setTransparency( final float transparency ) { + _transparency = transparency; } @Override @@ -291,6 +318,10 @@ public final class NodeVisualData implements PhylogenyData { return asText().toString(); } + private String colorToHex( final Color c ) { + return String.format( "#%02x%02x%02x", c.getRed(), c.getGreen(), c.getBlue() ); + } + private final void init() { setFontName( null ); setFontStyle( FontType.PLAIN ); @@ -301,7 +332,7 @@ public final class NodeVisualData implements PhylogenyData { setBorderColor( null ); setFillColor( null ); setSize( DEFAULT_SIZE ); - setTransparancy( DEFAULT_TRANSPARANCY ); + setTransparency( DEFAULT_TRANSPARENCY ); _font = null; } @@ -318,7 +349,7 @@ public final class NodeVisualData implements PhylogenyData { AppliesTo.NODE ) ); } if ( getFontStyle() != FontType.PLAIN ) { - String font_style = FONT_STYLE_PLAIN; + String font_style = ""; if ( getFontStyle() == FontType.ITALIC ) { font_style = FONT_STYLE_ITALIC; } @@ -328,8 +359,76 @@ public final class NodeVisualData implements PhylogenyData { else if ( getFontStyle() == FontType.BOLD_ITALIC ) { font_style = FONT_STYLE_BOLD_ITALIC; } + else { + throw new RuntimeException( "unknown font style" + getShape() ); + } properties.add( new Property( FONT_STYLE_REF, font_style, "", FONT_STYLE_TYPE, AppliesTo.NODE ) ); } + if ( getFontColor() != null ) { + properties.add( new Property( FONT_COLOR_REF, + colorToHex( getFontColor() ), + "", + FONT_COLOR_TYPE, + AppliesTo.NODE ) ); + } + // + if ( getShape() != NodeShape.DEFAULT ) { + String shape = null; + if ( getShape() == NodeShape.RECTANGLE ) { + shape = NODE_SHAPE_RECTANGLE; + } + else if ( getShape() == NodeShape.CIRCLE ) { + shape = NODE_SHAPE_CIRCLE; + } + else { + throw new RuntimeException( "unknown node shape" + getShape() ); + } + properties.add( new Property( NODE_SHAPE_REF, shape, "", NODE_SHAPE_TYPE, AppliesTo.NODE ) ); + } + if ( getSize() != DEFAULT_SIZE ) { + properties.add( new Property( NODE_SIZE_REF, + String.valueOf( getSize() ), + "", + NODE_SIZE_TYPE, + AppliesTo.NODE ) ); + } + if ( getFillColor() != null ) { + properties.add( new Property( NODE_FILL_COLOR_REF, + colorToHex( getFillColor() ), + "", + NODE_FILL_COLOR_TYPE, + AppliesTo.NODE ) ); + } + if ( getBorderColor() != null ) { + properties.add( new Property( NODE_BORDER_COLOR_REF, + colorToHex( getBorderColor() ), + "", + NODE_BORDER_COLOR_TYPE, + AppliesTo.NODE ) ); + } + if ( getFillType() != NodeFill.DEFAULT ) { + String fill = null; + if ( getFillType() == NodeFill.GRADIENT ) { + fill = NODE_FILL_GRADIENT; + } + else if ( getFillType() == NodeFill.NONE ) { + fill = NODE_FILL_NONE; + } + else if ( getFillType() == NodeFill.SOLID ) { + fill = NODE_FILL_SOLID; + } + else { + throw new RuntimeException( "unknown fill type " + getFillType() ); + } + properties.add( new Property( NODE_FILL_TYPE_REF, fill, "", NODE_FILL_TYPE_TYPE, AppliesTo.NODE ) ); + } + if ( getTransparency() != DEFAULT_TRANSPARENCY ) { + properties.add( new Property( NODE_TRANSPARENCY_REF, + String.valueOf( getTransparency() ), + "", + NODE_TRANSPARENCY_TYPE, + AppliesTo.NODE ) ); + } return properties; }