X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=forester%2Fjava%2Fsrc%2Forg%2Fforester%2Fphylogeny%2Fdata%2FNodeVisualData.java;h=b3f4b5c0f1ceb521e7a99db898b1668ab85e73b7;hb=bdf2d2a11d720d6457f52866af7ff909afe98db4;hp=79faa7feb43cfa2eda7c9e43ccc82e3ff1242d1f;hpb=8bc6209a13673b7df5cee13c3f70467f2ea58303;p=jalview.git diff --git a/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java b/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java index 79faa7f..b3f4b5c 100644 --- a/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java +++ b/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java @@ -13,31 +13,47 @@ 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 int DEFAULT_SIZE = -1; + 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_COLOR_REF = APTX_VISUALIZATION_REF + "node_color"; + public static final String NODE_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 + "node_fill_type"; + public static final String NODE_FILL_TYPE_TYPE = "xsd:token"; + public static final String NODE_SHAPE_CIRCLE = "circle"; + public static final String NODE_SHAPE_RECTANGLE = "rectangle"; + public static final String NODE_SHAPE_REF = APTX_VISUALIZATION_REF + "node_shape"; + public static final String NODE_SHAPE_TYPE = "xsd:token"; + public static final String NODE_SIZE_REF = APTX_VISUALIZATION_REF + "node_size"; + public static final String NODE_SIZE_TYPE = "xsd:float"; + public static final String NODE_TRANSPARENCY_REF = APTX_VISUALIZATION_REF + "node_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 Color _border_color; - private Color _fill_color; + private static final int DEFAULT_TRANSPARENCY = -1; private NodeFill _fill_type; private Font _font; private Color _font_color; private String _font_name; private byte _font_size; private FontType _font_style; + private Color _node_color; private NodeShape _shape; private float _size; - private float _transparancy; + private float _transparency; public NodeVisualData() { init(); @@ -49,20 +65,18 @@ public final class NodeVisualData implements PhylogenyData { final Color font_color, final NodeShape shape, final NodeFill fill_type, - final Color border_color, - final Color fill_color, + final Color node_color, final float size, - final float transparancy ) { + final float transparency ) { setFontName( font_name ); setFontStyle( font_style ); setFontSize( font_size ); setFontColor( font_color ); setShape( shape ); setFillType( fill_type ); - setBorderColor( border_color ); - setFillColor( fill_color ); + setNodeColor( node_color ); setSize( size ); - setTransparancy( transparancy ); + setTransparency( transparency ); } @Override @@ -85,20 +99,10 @@ public final class NodeVisualData implements PhylogenyData { .getGreen(), getFontColor().getBlue() ) : null, getShape(), getFillType(), - getBorderColor() != null ? new Color( getBorderColor().getRed(), getBorderColor() - .getGreen(), getBorderColor().getBlue() ) : null, - getFillColor() != null ? new Color( getFillColor().getRed(), getFillColor() - .getGreen(), getFillColor().getBlue() ) : null, + getNodeColor() != null ? new Color( getNodeColor().getRed(), getNodeColor() + .getGreen(), getNodeColor().getBlue() ) : null, getSize(), - getTransparancy() ); - } - - public final Color getBorderColor() { - return _border_color; - } - - public final Color getFillColor() { - return _fill_color; + getTransparency() ); } public final NodeFill getFillType() { @@ -145,6 +149,10 @@ public final class NodeVisualData implements PhylogenyData { return Font.PLAIN; } + public final Color getNodeColor() { + return _node_color; + } + public final NodeShape getShape() { return _shape; } @@ -153,15 +161,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 ) ); + && ( getNodeColor() == null ) && ( getSize() == DEFAULT_SIZE ) && ( getTransparency() == DEFAULT_TRANSPARENCY ) ); } @Override @@ -188,20 +196,61 @@ public final class NodeVisualData implements PhylogenyData { else if ( prop.getRef().equals( FONT_STYLE_REF ) ) { setFontStyle( prop.getValue() ); } - } - - public final void setBorderColor( final Color border_color ) { - _border_color = border_color; - } - - public final void setFillColor( final Color fill_color ) { - _fill_color = fill_color; + else if ( prop.getRef().equals( FONT_COLOR_REF ) ) { + try { + setFontColor( Color.decode( prop.getValue() ) ); + } + catch ( final NumberFormatException e ) { + return; + } + } + else if ( prop.getRef().equals( NODE_SIZE_REF ) ) { + float s = -1.0f; + try { + s = Float.parseFloat( prop.getValue() ); + } + catch ( final NumberFormatException e ) { + return; + } + if ( s >= 0 ) { + setSize( s ); + } + } + else if ( prop.getRef().equals( NODE_COLOR_REF ) ) { + try { + setNodeColor( Color.decode( prop.getValue() ) ); + } + catch ( final NumberFormatException e ) { + return; + } + } + else if ( prop.getRef().equals( NODE_SHAPE_REF ) ) { + setShape( prop.getValue() ); + } + else if ( prop.getRef().equals( NODE_FILL_TYPE_REF ) ) { + setFillType( prop.getValue() ); + } } public final void setFillType( final NodeFill fill_type ) { _fill_type = fill_type; } + public final void setFillType( final String fill ) { + if ( fill.equalsIgnoreCase( NODE_FILL_NONE ) ) { + setFillType( NodeFill.NONE ); + } + else if ( fill.equalsIgnoreCase( NODE_FILL_SOLID ) ) { + setFillType( NodeFill.SOLID ); + } + else if ( fill.equalsIgnoreCase( NODE_FILL_GRADIENT ) ) { + setFillType( NodeFill.GRADIENT ); + } + else { + setFillType( NodeFill.DEFAULT ); + } + } + public final void setFontColor( final Color font_color ) { _font_color = font_color; } @@ -262,16 +311,35 @@ public final class NodeVisualData implements PhylogenyData { } } + public final void setNodeColor( final Color node_color ) { + _node_color = node_color; + } + public final void setShape( final NodeShape shape ) { _shape = shape; } + public final void setShape( final String shape ) { + if ( shape.equalsIgnoreCase( NODE_SHAPE_CIRCLE ) ) { + setShape( NodeShape.CIRCLE ); + } + else if ( shape.equalsIgnoreCase( NODE_SHAPE_RECTANGLE ) ) { + setShape( NodeShape.RECTANGLE ); + } + else { + setShape( NodeShape.DEFAULT ); + } + } + public final void setSize( final float size ) { + if ( ( size != DEFAULT_SIZE ) && ( size < 0 ) ) { + throw new IllegalArgumentException( "negative size: " + size ); + } _size = size; } - public final void setTransparancy( final float transparancy ) { - _transparancy = transparancy; + public final void setTransparency( final float transparency ) { + _transparency = transparency; } @Override @@ -291,6 +359,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 ); @@ -298,10 +370,9 @@ public final class NodeVisualData implements PhylogenyData { setFontColor( null ); setShape( NodeShape.DEFAULT ); setFillType( NodeFill.DEFAULT ); - setBorderColor( null ); - setFillColor( null ); + setNodeColor( null ); setSize( DEFAULT_SIZE ); - setTransparancy( DEFAULT_TRANSPARANCY ); + setTransparency( DEFAULT_TRANSPARENCY ); _font = null; } @@ -318,7 +389,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 +399,68 @@ 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 ( getNodeColor() != null ) { + properties.add( new Property( NODE_COLOR_REF, + colorToHex( getNodeColor() ), + "", + NODE_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; }