import org.forester.phylogeny.data.Event;
import org.forester.phylogeny.data.NodeData.NODE_DATA;
import org.forester.phylogeny.data.NodeVisualData;
-import org.forester.phylogeny.data.NodeVisualData.FontType;
import org.forester.phylogeny.data.NodeVisualData.NodeFill;
import org.forester.phylogeny.data.NodeVisualData.NodeShape;
import org.forester.phylogeny.data.PhylogenyDataUtil;
private void changeNodeFont( final PhylogenyNode node ) {
final FontChooser fc = new FontChooser();
Font f = null;
- if ( node.getNodeData().getNodeVisualData() != null && !node.getNodeData().getNodeVisualData().isEmpty() ) {
- f = node.getNodeData().getNodeVisualData().getFontObject();
+ if ( ( node.getNodeData().getNodeVisualData() != null ) && !node.getNodeData().getNodeVisualData().isEmpty() ) {
+ f = node.getNodeData().getNodeVisualData().getFont();
}
if ( f != null ) {
fc.setFont( f );
fc.setFont( getMainPanel().getTreeFontSet().getLargeFont() );
}
fc.showDialog( this, "Select Font" );
- if ( fc.getFont() != null ) {
- NodeVisualData v = node.getNodeData().getNodeVisualData();
- Font ff = fc.getFont();
- v.setFont( ff.getFamily() );
- v.setFontSize( ( byte ) ( ff.getSize() ) );
- if ( ff.getStyle() == Font.BOLD && ff.getStyle() == Font.ITALIC ) {
- v.setFontType( FontType.BOLD_ITALIC );
+ if ( ( fc.getFont() != null ) && !ForesterUtil.isEmpty( fc.getFont().getFamily().trim() ) ) {
+ if ( node.getNodeData().getNodeVisualData() == null ) {
+ node.getNodeData().setNodeVisualData( new NodeVisualData() );
}
- else if ( ff.getStyle() == Font.ITALIC ) {
- v.setFontType( FontType.ITALIC );
+ final NodeVisualData vd = node.getNodeData().getNodeVisualData();
+ final Font ff = fc.getFont();
+ vd.setFontName( ff.getFamily().trim() );
+ int s = ff.getSize();
+ if ( s < 0 ) {
+ s = 0;
}
- else if ( ff.getStyle() == Font.BOLD ) {
- v.setFontType( FontType.BOLD );
- }
- else {
- v.setFontType( FontType.NORMAL );
+ if ( s > Byte.MAX_VALUE ) {
+ s = Byte.MAX_VALUE;
}
+ vd.setFontSize( s );
+ vd.setFontStyle( ff.getStyle() );
}
}
}
_sb.append( propertiesToString( node ) );
}
- g.setFont( getTreeFontSet().getLargeFont() );
+ if ( getControlPanel().isColorBranches() && ( node.getNodeData().getNodeVisualData() != null ) ) {
+ final Font f = node.getNodeData().getNodeVisualData().getFont();
+ g.setFont( f != null ? f : getTreeFontSet().getLargeFont() );
+ }
+ else {
+ g.setFont( getTreeFontSet().getLargeFont() );
+ }
if ( is_in_found_nodes ) {
g.setFont( getTreeFontSet().getLargeFont().deriveFont( Font.BOLD ) );
}
private Color _border_color;\r
private Color _fill_color;\r
private NodeFill _fill_type;\r
- private String _font;\r
+ private String _font_name;\r
private Color _font_color;\r
private byte _font_size;\r
- private FontType _font_type;\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
}\r
\r
- public NodeVisualData( final String font,\r
- final FontType font_type,\r
+ public NodeVisualData( final String font_name,\r
+ final FontType font_style,\r
final byte font_size,\r
final Color font_color,\r
final NodeShape shape,\r
final Color fill_color,\r
final float size,\r
final float transparancy ) {\r
- setFont( font );\r
- setFontType( font_type );\r
+ setFontName( font_name );\r
+ setFontStyle( font_style );\r
setFontSize( font_size );\r
setFontColor( font_color );\r
setShape( shape );\r
\r
@Override\r
public final PhylogenyData copy() {\r
- return new NodeVisualData( !ForesterUtil.isEmpty( getFont() ) ? new String( getFont() ) : null,\r
- getFontType(),\r
+ return new NodeVisualData( !ForesterUtil.isEmpty( getFontName() ) ? new String( getFontName() ) : null,\r
+ getFontStyle(),\r
getFontSize(),\r
getFontColor() != null ? new Color( getFontColor().getRed(), getFontColor()\r
.getGreen(), getFontColor().getBlue() ) : null,\r
return _fill_type;\r
}\r
\r
- public final String getFont() {\r
- return _font;\r
+ public final String getFontName() {\r
+ return _font_name;\r
}\r
\r
public final Color getFontColor() {\r
return _font_size;\r
}\r
\r
- public final FontType getFontType() {\r
- return _font_type;\r
+ public final FontType getFontStyle() {\r
+ return _font_style;\r
}\r
\r
public final NodeShape getShape() {\r
}\r
\r
public final boolean isEmpty() {\r
- return ( ForesterUtil.isEmpty( getFont() ) && ( getFontType() == FontType.NORMAL )\r
+ return ( ForesterUtil.isEmpty( getFontName() ) && ( getFontStyle() == FontType.PLAIN )\r
&& ( getFontSize() == DEFAULT_FONT_SIZE ) && ( getFontColor() == null )\r
&& ( getShape() == NodeShape.DEFAULT ) && ( getFillType() == NodeFill.DEFAULT )\r
&& ( getBorderColor() == null ) && ( getFillColor() == null ) && ( getSize() == DEFAULT_SIZE ) && ( getTransparancy() == DEFAULT_TRANSPARANCY ) );\r
_fill_type = fill_type;\r
}\r
\r
- public final void setFont( final String font ) {\r
- if ( !ForesterUtil.isEmpty( font ) ) {\r
- _font = font;\r
+ public final void setFontName( final String font_name ) {\r
+ if ( !ForesterUtil.isEmpty( font_name ) ) {\r
+ _font_name = font_name;\r
}\r
else {\r
- _font = null;\r
+ _font_name = null;\r
}\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 byte font_size ) {\r
- _font_size = font_size;\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
+ else if ( font_size > Byte.MAX_VALUE ) {\r
+ throw new IllegalArgumentException( "font size is too large: " + font_size );\r
+ }\r
+ _font_size = ( byte ) font_size;\r
+ _font = null;\r
}\r
\r
- public final void setFontType( final FontType font_type ) {\r
- _font_type = font_type;\r
+ public final void setFontStyle( final FontType font_style ) {\r
+ _font_style = font_style;\r
+ _font = null;\r
+ }\r
+\r
+ public final void setFontStyle( final int font_style ) {\r
+ if ( ( font_style == ( Font.BOLD + Font.ITALIC ) ) ) {\r
+ setFontStyle( FontType.BOLD_ITALIC );\r
+ }\r
+ else if ( font_style == Font.ITALIC ) {\r
+ setFontStyle( FontType.ITALIC );\r
+ }\r
+ else if ( font_style == Font.BOLD ) {\r
+ setFontStyle( FontType.BOLD );\r
+ }\r
+ else {\r
+ setFontStyle( FontType.PLAIN );\r
+ }\r
}\r
\r
public final void setShape( final NodeShape shape ) {\r
_transparancy = transparancy;\r
}\r
\r
- public final int getFontStyle() {\r
- if ( getFontType() == FontType.BOLD ) {\r
+ public final int getFontStyleInt() {\r
+ if ( getFontStyle() == FontType.BOLD ) {\r
return Font.BOLD;\r
}\r
- else if ( getFontType() == FontType.ITALIC ) {\r
+ else if ( getFontStyle() == FontType.ITALIC ) {\r
return Font.ITALIC;\r
}\r
- else if ( getFontType() == FontType.BOLD_ITALIC ) {\r
- return Font.BOLD & Font.ITALIC;\r
+ else if ( getFontStyle() == FontType.BOLD_ITALIC ) {\r
+ return Font.BOLD + Font.ITALIC;\r
}\r
return Font.PLAIN;\r
}\r
\r
- public final Font getFontObject() {\r
- if ( !ForesterUtil.isEmpty( getFont() ) ) {\r
- return new Font( getFont(), getFontStyle(), getFontSize() );\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
\r
private final void init() {\r
- setFont( null );\r
- setFontType( FontType.NORMAL );\r
+ setFontName( null );\r
+ setFontStyle( FontType.PLAIN );\r
setFontSize( DEFAULT_FONT_SIZE );\r
setFontColor( null );\r
setShape( NodeShape.DEFAULT );\r
setFillColor( null );\r
setSize( DEFAULT_SIZE );\r
setTransparancy( DEFAULT_TRANSPARANCY );\r
+ _font = null;\r
}\r
\r
private final List<Property> toProperties() {\r
}\r
\r
public enum FontType {\r
- BOLD, BOLD_ITALIC, ITALIC, NORMAL\r
+ BOLD, BOLD_ITALIC, ITALIC, PLAIN\r
}\r
\r
public enum NodeFill {\r