From: cmzmasek@gmail.com Date: Fri, 11 Apr 2014 23:30:48 +0000 (+0000) Subject: inprogress X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=87d8c4dedc7e2418f12242986cea67307dd62a7f;p=jalview.git inprogress --- diff --git a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java index 0e217c4..09effc3 100644 --- a/forester/java/src/org/forester/archaeopteryx/AptxUtil.java +++ b/forester/java/src/org/forester/archaeopteryx/AptxUtil.java @@ -702,6 +702,12 @@ public final class AptxUtil { } } + final static void removeVisualStyles( final Phylogeny phy ) { + for( final PhylogenyNodeIterator it = phy.iteratorPreorder(); it.hasNext(); ) { + it.next().getNodeData().setNodeVisualData( null ); + } + } + final static void unexpectedError( final Error e ) { System.err.println(); e.printStackTrace( System.err ); diff --git a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java index e5bb03f..9e48b82 100644 --- a/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java +++ b/forester/java/src/org/forester/archaeopteryx/ArchaeopteryxE.java @@ -96,6 +96,7 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { private JMenuItem _phyloxml_ref_item; private JMenuItem _aptx_ref_item; private JMenuItem _remove_branch_color_item; + private JMenuItem _remove_visual_styles_item; private JCheckBoxMenuItem _show_domain_labels; private JCheckBoxMenuItem _show_annotation_ref_source; private JCheckBoxMenuItem _color_labels_same_as_parent_branch; @@ -164,6 +165,9 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { else if ( o == _remove_branch_color_item ) { removeBranchColors(); } + else if ( o == _remove_visual_styles_item ) { + removeVisualStyles(); + } else if ( o == _switch_colors_mi ) { switchColors(); } @@ -805,8 +809,13 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { customizeJMenuItem( _confcolor_item ); _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) ); customizeJMenuItem( _taxcolor_item ); - _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) ); - _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." ); + _tools_menu.addSeparator(); + _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) ); + _remove_visual_styles_item + .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." ); + customizeJMenuItem( _remove_visual_styles_item ); + _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) ); + _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." ); customizeJMenuItem( _remove_branch_color_item ); _tools_menu.addSeparator(); _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) ); @@ -1486,6 +1495,12 @@ public class ArchaeopteryxE extends JApplet implements ActionListener { } } + private void removeVisualStyles() { + if ( getMainPanel().getCurrentPhylogeny() != null ) { + AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() ); + } + } + private void setMainPanel( final MainPanelApplets main_panel ) { _mainpanel = main_panel; } diff --git a/forester/java/src/org/forester/archaeopteryx/Configuration.java b/forester/java/src/org/forester/archaeopteryx/Configuration.java index 5223e7e..2766ec0 100644 --- a/forester/java/src/org/forester/archaeopteryx/Configuration.java +++ b/forester/java/src/org/forester/archaeopteryx/Configuration.java @@ -57,20 +57,21 @@ public final class Configuration { final static String clickto_options[][] = { { "Display Node Data", "display" }, { "Collapse/Uncollapse", "display" }, { "Root/Reroot", "display" }, - { "Sub/Super Tree", "display" }, { "Swap Descendants", "display" }, { "Colorize Subtree(s)", "display" }, - { "Colorize Node(s)", "display" }, { "Change Node Font", "display" }, { "Open Sequence DB", "display" }, - { "Go to PDB", "display" }, { "Open Taxonomy DB", "display" }, { "Blast", "display" }, - { "Cut Subtree", "display" }, { "Copy Subtree", "display" }, { "Paste Subtree", "display" }, - { "Delete Subtree/Node", "display" }, { "Add New Node", "display" }, { "Edit Node Data", "display" }, - { "Sort Descendants", "display" }, { "Return", "display" }, { "Select Node(s)", "display" } }; + { "Go to Sub-/Super-Tree", "display" }, { "Swap Descendants", "display" }, + { "Colorize Node(s)", "display" }, { "Change Node Font(s)", "display" }, + { "Colorize Subtree(s)", "display" }, { "Open Sequence DB", "display" }, { "Open PDB", "display" }, + { "Open Taxonomy DB", "display" }, { "Launch BLAST", "display" }, { "Cut Subtree", "display" }, + { "Copy Subtree", "display" }, { "Paste Subtree", "display" }, { "Delete Subtree/Node", "display" }, + { "Add New Node", "display" }, { "Edit Node Data", "display" }, { "Sort Descendants", "display" }, + { "Return", "display" }, { "Select Node(s)", "display" } }; final static int display_node_data = 0; final static int collapse_uncollapse = 1; final static int reroot = 2; final static int subtree = 3; final static int swap = 4; - final static int color_subtree = 5; - final static int color_node_font = 6; - final static int change_node_font = 7; + final static int color_node_font = 5; + final static int change_node_font = 6; + final static int color_subtree = 7; final static int open_seq_web = 8; final static int open_pdb_web = 9; final static int open_tax_web = 10; @@ -91,7 +92,7 @@ public final class Configuration { { "Phylogram", "display", "?" }, { "Node Name", "display", "yes" }, { "Taxonomy Code", "display", "yes" }, { "Seq Annotations", "nodisplay", "no" }, { "Confidence Values", "display", "?" }, { "Node Events", "display", "?" }, { "Colorize by Taxonomy", "display", "no" }, - { "Use Visual Styles", "display", "no" }, { "Use Branch Widths", "display", "no" }, + { "Visual Styles/Branch Colors", "display", "no" }, { "Branch Widths", "display", "no" }, { "Show Custom Nodes", "display", "yes" }, { "Protein Domains", "nodisplay", "no" }, { "Binary Characters", "nodisplay", "no" }, { "Binary Char Counts", "nodisplay", "no" }, { "Seq Name", "display", "yes" }, { "Seq Accession", "display", "no" }, diff --git a/forester/java/src/org/forester/archaeopteryx/ControlPanel.java b/forester/java/src/org/forester/archaeopteryx/ControlPanel.java index a3712df..a398560 100644 --- a/forester/java/src/org/forester/archaeopteryx/ControlPanel.java +++ b/forester/java/src/org/forester/archaeopteryx/ControlPanel.java @@ -595,7 +595,8 @@ final class ControlPanel extends JPanel implements ActionListener { break; case Configuration.use_style: _use_visual_styles_cb = new JCheckBox( title ); - getUseVisualStylesCb().setToolTipText( "To use visual styles (colors, fonts), if present" ); + getUseVisualStylesCb() + .setToolTipText( "To use visual styles (node colors, fonts) and branch colors, if present" ); addJCheckBox( getUseVisualStylesCb(), ch_panel ); add( ch_panel ); break; @@ -1894,14 +1895,6 @@ final class ControlPanel extends JPanel implements ActionListener { } cb_index++; } - if ( _configuration.doDisplayClickToOption( Configuration.color_subtree ) ) { - _color_subtree_cb_item = cb_index; - addClickToOption( Configuration.color_subtree, _configuration.getClickToTitle( Configuration.color_subtree ) ); - if ( default_option == Configuration.color_subtree ) { - selected_index = cb_index; - } - cb_index++; - } if ( _configuration.doDisplayClickToOption( Configuration.color_node_font ) ) { _color_node_font_item = cb_index; addClickToOption( Configuration.color_node_font, @@ -1920,6 +1913,14 @@ final class ControlPanel extends JPanel implements ActionListener { } cb_index++; } + if ( _configuration.doDisplayClickToOption( Configuration.color_subtree ) ) { + _color_subtree_cb_item = cb_index; + addClickToOption( Configuration.color_subtree, _configuration.getClickToTitle( Configuration.color_subtree ) ); + if ( default_option == Configuration.color_subtree ) { + selected_index = cb_index; + } + cb_index++; + } if ( _configuration.doDisplayClickToOption( Configuration.open_seq_web ) ) { _open_seq_web_item = cb_index; addClickToOption( Configuration.open_seq_web, _configuration.getClickToTitle( Configuration.open_seq_web ) ); diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrame.java b/forester/java/src/org/forester/archaeopteryx/MainFrame.java index 0866f1c..b7dc624 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrame.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrame.java @@ -159,6 +159,8 @@ public abstract class MainFrame extends JFrame implements ActionListener { JMenuItem _move_node_names_to_seq_names_jmi; JMenuItem _extract_tax_code_from_node_names_jmi; JMenuItem _annotate_item; + JMenuItem _remove_branch_color_item; + JMenuItem _remove_visual_styles_item; // font size menu: JMenuItem _super_tiny_fonts_item; JMenuItem _tiny_fonts_item; @@ -243,7 +245,6 @@ public abstract class MainFrame extends JFrame implements ActionListener { Container _contentpane; final LinkedList _textframes = new LinkedList(); ; Configuration _configuration; - JMenuItem _remove_branch_color_item; Options _options; private Phylogeny _species_tree; InferenceManager _inference_manager; @@ -306,6 +307,12 @@ public abstract class MainFrame extends JFrame implements ActionListener { } removeBranchColors(); } + else if ( o == _remove_visual_styles_item ) { + if ( isSubtreeDisplayed() ) { + return; + } + removeVisualStyles(); + } else if ( o == _midpoint_root_item ) { if ( isSubtreeDisplayed() ) { return; @@ -1558,6 +1565,12 @@ public abstract class MainFrame extends JFrame implements ActionListener { } } + private void removeVisualStyles() { + if ( getMainPanel().getCurrentPhylogeny() != null ) { + AptxUtil.removeVisualStyles( getMainPanel().getCurrentPhylogeny() ); + } + } + private void setPreviousNodeAnnotationReference( final String previous_node_annotation_ref ) { _previous_node_annotation_ref = previous_node_annotation_ref; } @@ -1737,15 +1750,16 @@ public abstract class MainFrame extends JFrame implements ActionListener { static void setTextColorChooseMenuItem( final JMenuItem mi, final TreePanel tree_panel ) { if ( ( tree_panel != null ) && ( tree_panel.getTreeColorSet() != null ) ) { - mi.setText( "Select Colors... (current: " + tree_panel.getTreeColorSet().getCurrentColorSchemeName() + ")" ); + mi.setText( "Select Color Scheme... (current: " + tree_panel.getTreeColorSet().getCurrentColorSchemeName() + + ")" ); } else { - mi.setText( "Select Colors..." ); + mi.setText( "Select Color Scheme..." ); } } static void setTextForFontChooserMenuItem( final JMenuItem mi, final String font_desc ) { - mi.setText( "Select Font... (current: " + font_desc + ")" ); + mi.setText( "Select Default Font... (current: " + font_desc + ")" ); } static void setTextMinSupportMenuItem( final JMenuItem mi, final Options options, final TreePanel current_tree_panel ) { diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java index b03b1f6..baec909 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplet.java @@ -289,8 +289,13 @@ public final class MainFrameApplet extends MainFrame { customizeJMenuItem( _confcolor_item ); _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) ); customizeJMenuItem( _taxcolor_item ); - _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) ); - _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny." ); + _tools_menu.addSeparator(); + _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) ); + _remove_visual_styles_item + .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." ); + customizeJMenuItem( _remove_visual_styles_item ); + _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) ); + _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." ); customizeJMenuItem( _remove_branch_color_item ); _tools_menu.addSeparator(); _tools_menu.add( _midpoint_root_item = new JMenuItem( "Midpoint-Root" ) ); diff --git a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java index 0744fdd..d0484a4 100644 --- a/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java +++ b/forester/java/src/org/forester/archaeopteryx/MainFrameApplication.java @@ -1053,8 +1053,13 @@ public final class MainFrameApplication extends MainFrame { _color_rank_jmi.setToolTipText( "for example, at \"Class\" level, colorize mammal specific subtree red" ); _tools_menu.add( _taxcolor_item = new JMenuItem( "Taxonomy Colorize Branches" ) ); customizeJMenuItem( _taxcolor_item ); - _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete Branch Colors" ) ); - _remove_branch_color_item.setToolTipText( "To delete branch color values from the current phylogeny" ); + _tools_menu.addSeparator(); + _tools_menu.add( _remove_visual_styles_item = new JMenuItem( "Delete All Visual Styles From Nodes" ) ); + _remove_visual_styles_item + .setToolTipText( "To remove all node visual styles (fonts, colors) from the current phylogeny." ); + customizeJMenuItem( _remove_visual_styles_item ); + _tools_menu.add( _remove_branch_color_item = new JMenuItem( "Delete All Colors From Branches" ) ); + _remove_branch_color_item.setToolTipText( "To remove all branch color values from the current phylogeny." ); customizeJMenuItem( _remove_branch_color_item ); _tools_menu.addSeparator(); _tools_menu.add( _annotate_item = new JMenuItem( "Annotate Sequences of Selected Nodes" ) ); diff --git a/forester/java/src/org/forester/archaeopteryx/TreePanel.java b/forester/java/src/org/forester/archaeopteryx/TreePanel.java index aa85956..b8905f2 100644 --- a/forester/java/src/org/forester/archaeopteryx/TreePanel.java +++ b/forester/java/src/org/forester/archaeopteryx/TreePanel.java @@ -603,60 +603,21 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( node.isCollapse() ) { continue; } - if ( getControlPanel().isShowNodeNames() ) { - sum += getFontMetricsForLargeDefaultFont().stringWidth( node.getName() + " " ); - } - if ( node.getNodeData().isHasSequence() ) { - if ( getControlPanel().isShowSequenceAcc() - && ( node.getNodeData().getSequence().getAccession() != null ) ) { - sum += getFontMetricsForLargeDefaultFont().stringWidth( node.getNodeData().getSequence() - .getAccession().getValue() - + " " ); - } - if ( getControlPanel().isShowSeqNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) { - sum += getFontMetricsForLargeDefaultFont().stringWidth( node.getNodeData().getSequence().getName() - + " " ); - } - if ( getControlPanel().isShowSeqSymbols() - && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) { - sum += getFontMetricsForLargeDefaultFont().stringWidth( node.getNodeData().getSequence() - .getSymbol() - + " " ); - } - if ( getControlPanel().isShowGeneNames() - && ( node.getNodeData().getSequence().getGeneName().length() > 0 ) ) { - sum += getFontMetricsForLargeDefaultFont().stringWidth( node.getNodeData().getSequence() - .getGeneName() - + " " ); - } - if ( getControlPanel().isShowAnnotation() - && ( node.getNodeData().getSequence().getAnnotations() != null ) - && !node.getNodeData().getSequence().getAnnotations().isEmpty() ) { - sum += getFontMetricsForLargeDefaultFont().stringWidth( TreePanelUtil.createAnnotationString( node - .getNodeData().getSequence().getAnnotations(), getOptions().isShowAnnotationRefSource() ) - + " " ); - } - if ( getControlPanel().isShowDomainArchitectures() - && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) ) { - sum += ( ( RenderableDomainArchitecture ) node.getNodeData().getSequence().getDomainArchitecture() ) - .getRenderingSize().getWidth(); - } - } + final StringBuilder sb = new StringBuilder(); + nodeDataAsSB( node, sb ); if ( node.getNodeData().isHasTaxonomy() ) { - final Taxonomy tax = node.getNodeData().getTaxonomy(); - if ( getControlPanel().isShowTaxonomyCode() && !ForesterUtil.isEmpty( tax.getTaxonomyCode() ) ) { - sum += getFontMetricsForLargeDefaultFont().stringWidth( tax.getTaxonomyCode() + " " ); - } - if ( getControlPanel().isShowTaxonomyScientificNames() - && !ForesterUtil.isEmpty( tax.getScientificName() ) ) { - sum += getFontMetricsForLargeDefaultFont().stringWidth( tax.getScientificName() + " " ); - } - if ( getControlPanel().isShowTaxonomyCommonNames() && !ForesterUtil.isEmpty( tax.getCommonName() ) ) { - sum += getFontMetricsForLargeDefaultFont().stringWidth( tax.getCommonName() + " ()" ); - } + nodeTaxonomyDataAsSB( node.getNodeData().getTaxonomy(), sb ); + } + boolean use_vis = false; + final Graphics2D g = ( Graphics2D ) getGraphics(); + if ( getControlPanel().isUseVisualStyles() ) { + use_vis = setFont( g, node, false ); + } + if ( !use_vis ) { + sum = getFontMetricsForLargeDefaultFont().stringWidth( sb.toString() ); } - if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) { - sum += getFontMetricsForLargeDefaultFont().stringWidth( propertiesToString( node ).toString() ); + else { + sum = getFontMetrics( g.getFont() ).stringWidth( sb.toString() ); } if ( getControlPanel().isShowBinaryCharacters() && node.getNodeData().isHasBinaryCharacters() ) { sum += getFontMetricsForLargeDefaultFont().stringWidth( node.getNodeData().getBinaryCharacters() @@ -2178,14 +2139,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } - private void abbreviateScientificName( final String sn ) { + private void abbreviateScientificName( final String sn, final StringBuilder sb ) { final String[] a = sn.split( "\\s+" ); - _sb.append( a[ 0 ].substring( 0, 1 ) ); - _sb.append( a[ 1 ].substring( 0, 2 ) ); + sb.append( a[ 0 ].substring( 0, 1 ) ); + sb.append( a[ 1 ].substring( 0, 2 ) ); if ( a.length > 2 ) { for( int i = 2; i < a.length; i++ ) { - _sb.append( " " ); - _sb.append( a[ i ] ); + sb.append( " " ); + sb.append( a[ i ] ); } } } @@ -2701,22 +2662,16 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee g.fill( _ellipse ); } - final private void drawOvalGradient( final double x, - final double y, - final double width, - final double heigth, + final private void drawOvalGradient( final float x, + final float y, + final float width, + final float heigth, final Graphics2D g, final Color color_1, final Color color_2, final Color color_border ) { _ellipse.setFrame( x, y, width, heigth ); - g.setPaint( new GradientPaint( ( float ) x, - ( float ) y, - color_1, - ( float ) ( x + width ), - ( float ) ( y + heigth ), - color_2, - false ) ); + g.setPaint( new GradientPaint( x, y, color_1, ( x + width ), ( y + heigth ), color_2, false ) ); g.fill( _ellipse ); if ( color_border != null ) { g.setPaint( color_border ); @@ -2738,22 +2693,16 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee g.fill( _rectangle ); } - final private void drawRectGradient( final double x, - final double y, - final double width, - final double heigth, + final private void drawRectGradient( final float x, + final float y, + final float width, + final float heigth, final Graphics2D g, final Color color_1, final Color color_2, final Color color_border ) { _rectangle.setFrame( x, y, width, heigth ); - g.setPaint( new GradientPaint( ( float ) x, - ( float ) y, - color_1, - ( float ) ( x + width ), - ( float ) ( y + heigth ), - color_2, - false ) ); + g.setPaint( new GradientPaint( x, y, color_1, ( x + width ), ( y + heigth ), color_2, false ) ); g.fill( _rectangle ); if ( color_border != null ) { g.setPaint( color_border ); @@ -3430,6 +3379,105 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee } } + private final void nodeDataAsSB( final PhylogenyNode node, final StringBuilder sb ) { + if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) { + if ( sb.length() > 0 ) { + sb.append( " " ); + } + sb.append( node.getName() ); + } + if ( node.getNodeData().isHasSequence() ) { + if ( getControlPanel().isShowSeqSymbols() && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) { + if ( sb.length() > 0 ) { + sb.append( " " ); + } + sb.append( node.getNodeData().getSequence().getSymbol() ); + } + if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getGeneName().length() > 0 ) ) { + if ( sb.length() > 0 ) { + sb.append( " " ); + } + sb.append( node.getNodeData().getSequence().getGeneName() ); + } + if ( getControlPanel().isShowSeqNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) { + if ( sb.length() > 0 ) { + sb.append( " " ); + } + sb.append( node.getNodeData().getSequence().getName() ); + } + if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) { + if ( sb.length() > 0 ) { + sb.append( " " ); + } + if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) { + sb.append( node.getNodeData().getSequence().getAccession().getSource() ); + sb.append( ":" ); + } + sb.append( node.getNodeData().getSequence().getAccession().getValue() ); + } + } + if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) { + if ( sb.length() > 0 ) { + sb.append( " " ); + } + sb.append( propertiesToString( node ) ); + } + } + + private final void nodeTaxonomyDataAsSB( final Taxonomy taxonomy, final StringBuilder sb ) { + if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) { + sb.append( taxonomy.getTaxonomyCode() ); + sb.append( " " ); + } + if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) { + if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) + && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) { + if ( getOptions().isAbbreviateScientificTaxonNames() + && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) { + abbreviateScientificName( taxonomy.getScientificName(), sb ); + } + else { + sb.append( taxonomy.getScientificName() ); + } + sb.append( " (" ); + sb.append( taxonomy.getCommonName() ); + sb.append( ") " ); + } + else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) { + if ( getOptions().isAbbreviateScientificTaxonNames() + && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) { + abbreviateScientificName( taxonomy.getScientificName(), sb ); + } + else { + sb.append( taxonomy.getScientificName() ); + } + sb.append( " " ); + } + else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) { + sb.append( taxonomy.getCommonName() ); + sb.append( " " ); + } + } + else if ( _control_panel.isShowTaxonomyScientificNames() ) { + if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) { + if ( getOptions().isAbbreviateScientificTaxonNames() + && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) { + abbreviateScientificName( taxonomy.getScientificName(), sb ); + } + else { + sb.append( taxonomy.getScientificName() ); + } + sb.append( " " ); + } + } + else if ( _control_panel.isShowTaxonomyCommonNames() ) { + if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) { + sb.append( taxonomy.getCommonName() ); + sb.append( " " ); + } + } + } + private final String obtainTitleForExtDescNodeData() { switch ( getOptions().getExtDescNodeDataToReturn() ) { case NODE_NAME: @@ -4019,8 +4067,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee * @param node * @param g */ - final private void paintNodeBox( final double x, - final double y, + final private void paintNodeBox( final float x, + final float y, final PhylogenyNode node, final Graphics2D g, final boolean to_pdf, @@ -4038,12 +4086,25 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee if ( ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) || ( getOptions().isShowDefaultNodeShapesExternal() && node.isExternal() ) || ( getOptions().isShowDefaultNodeShapesInternal() && node.isInternal() ) + || ( getControlPanel().isUseVisualStyles() && ( ( node.getNodeData().getNodeVisualData() != null ) && ( ( node + .getNodeData().getNodeVisualData().getNodeColor() != null ) + || ( node.getNodeData().getNodeVisualData().getSize() != NodeVisualData.DEFAULT_SIZE ) + || ( node.getNodeData().getNodeVisualData().getFillType() != NodeFill.DEFAULT ) || ( node + .getNodeData().getNodeVisualData().getShape() != NodeShape.DEFAULT ) ) ) ) || ( getControlPanel().isEvents() && node.isHasAssignedEvent() && ( node.getNodeData().getEvent() .isDuplication() || node.getNodeData().getEvent().isSpeciation() || node.getNodeData().getEvent() .isSpeciationOrDuplication() ) ) ) { - final double box_size = getOptions().getDefaultNodeShapeSize(); - final double half_box_size = box_size / 2.0; + NodeVisualData vis = null; + if ( getControlPanel().isUseVisualStyles() && ( node.getNodeData().getNodeVisualData() != null ) + && ( !node.getNodeData().getNodeVisualData().isEmpty() ) ) { + vis = node.getNodeData().getNodeVisualData(); + } + float box_size = getOptions().getDefaultNodeShapeSize(); + if ( ( vis != null ) && ( vis.getSize() != NodeVisualData.DEFAULT_SIZE ) ) { + box_size = vis.getSize(); + } + final float half_box_size = box_size / 2.0f; Color outline_color = null; if ( ( to_pdf || to_graphics_file ) && getOptions().isPrintBlackAndWhite() ) { outline_color = Color.BLACK; @@ -4051,6 +4112,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) { outline_color = getColorForFoundNode( node ); } + else if ( vis != null ) { + if ( vis.getNodeColor() != null ) { + outline_color = vis.getNodeColor(); + } + else if ( vis.getFontColor() != null ) { + outline_color = vis.getFontColor(); + } + } else if ( getControlPanel().isEvents() && TreePanelUtil.isHasAssignedEvent( node ) ) { final Event event = node.getNodeData().getEvent(); if ( event.isDuplication() ) { @@ -4063,18 +4132,62 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee outline_color = getTreeColorSet().getDuplicationOrSpeciationColor(); } } - else { + if ( outline_color == null ) { outline_color = getGraphicsForNodeBoxWithColorForParentBranch( node ); if ( to_pdf && ( outline_color == getTreeColorSet().getBranchColor() ) ) { outline_color = getTreeColorSet().getBranchColorForPdf(); } } - if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) { - if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) { + NodeShape shape = null; + if ( vis != null ) { + if ( vis.getShape() == NodeShape.CIRCLE ) { + shape = NodeShape.CIRCLE; + } + else if ( vis.getShape() == NodeShape.RECTANGLE ) { + shape = NodeShape.RECTANGLE; + } + } + if ( shape == null ) { + if ( getOptions().getDefaultNodeShape() == NodeShape.CIRCLE ) { + shape = NodeShape.CIRCLE; + } + else if ( getOptions().getDefaultNodeShape() == NodeShape.RECTANGLE ) { + shape = NodeShape.RECTANGLE; + } + } + NodeFill fill = null; + if ( vis != null ) { + if ( vis.getFillType() == NodeFill.SOLID ) { + fill = NodeFill.SOLID; + } + else if ( vis.getFillType() == NodeFill.NONE ) { + fill = NodeFill.NONE; + } + else if ( vis.getFillType() == NodeFill.GRADIENT ) { + fill = NodeFill.GRADIENT; + } + } + if ( fill == null ) { + if ( getOptions().getDefaultNodeFill() == NodeFill.SOLID ) { + fill = NodeFill.SOLID; + } + else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) { + fill = NodeFill.NONE; + } + else if ( getOptions().getDefaultNodeFill() == NodeFill.GRADIENT ) { + fill = NodeFill.GRADIENT; + } + } + Color vis_fill_color = null; + if ( ( vis != null ) && ( vis.getNodeColor() != null ) ) { + vis_fill_color = vis.getNodeColor(); + } + if ( shape == NodeShape.CIRCLE ) { + if ( fill == NodeFill.GRADIENT ) { drawOvalGradient( x - half_box_size, y - half_box_size, box_size, box_size, g, to_pdf ? Color.WHITE : outline_color, to_pdf ? outline_color : getBackground(), outline_color ); } - else if ( getOptions().getDefaultNodeFill() == NodeFill.NONE ) { + else if ( fill == NodeFill.NONE ) { Color background = getBackground(); if ( to_pdf ) { background = Color.WHITE; @@ -4088,17 +4201,22 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee background, outline_color ); } - else if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.SOLID ) { - g.setColor( outline_color ); + else if ( fill == NodeVisualData.NodeFill.SOLID ) { + if ( vis_fill_color != null ) { + g.setColor( vis_fill_color ); + } + else { + g.setColor( outline_color ); + } drawOvalFilled( x - half_box_size, y - half_box_size, box_size, box_size, g ); } } - else if ( getOptions().getDefaultNodeShape() == NodeVisualData.NodeShape.RECTANGLE ) { - if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.GRADIENT ) { + else if ( shape == NodeVisualData.NodeShape.RECTANGLE ) { + if ( fill == NodeVisualData.NodeFill.GRADIENT ) { drawRectGradient( x - half_box_size, y - half_box_size, box_size, box_size, g, to_pdf ? Color.WHITE : outline_color, to_pdf ? outline_color : getBackground(), outline_color ); } - else if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.NONE ) { + else if ( fill == NodeVisualData.NodeFill.NONE ) { Color background = getBackground(); if ( to_pdf ) { background = Color.WHITE; @@ -4112,8 +4230,13 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee background, outline_color ); } - else if ( getOptions().getDefaultNodeFill() == NodeVisualData.NodeFill.SOLID ) { - g.setColor( outline_color ); + else if ( fill == NodeVisualData.NodeFill.SOLID ) { + if ( vis_fill_color != null ) { + g.setColor( vis_fill_color ); + } + else { + g.setColor( outline_color ); + } drawRectFilled( x - half_box_size, y - half_box_size, box_size, box_size, g ); } } @@ -4164,48 +4287,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee else { _sb.setLength( 0 ); } - if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) { - if ( _sb.length() > 0 ) { - _sb.append( " " ); - } - _sb.append( node.getName() ); - } - if ( node.getNodeData().isHasSequence() ) { - if ( getControlPanel().isShowSeqSymbols() && ( node.getNodeData().getSequence().getSymbol().length() > 0 ) ) { - if ( _sb.length() > 0 ) { - _sb.append( " " ); - } - _sb.append( node.getNodeData().getSequence().getSymbol() ); - } - if ( getControlPanel().isShowGeneNames() && ( node.getNodeData().getSequence().getGeneName().length() > 0 ) ) { - if ( _sb.length() > 0 ) { - _sb.append( " " ); - } - _sb.append( node.getNodeData().getSequence().getGeneName() ); - } - if ( getControlPanel().isShowSeqNames() && ( node.getNodeData().getSequence().getName().length() > 0 ) ) { - if ( _sb.length() > 0 ) { - _sb.append( " " ); - } - _sb.append( node.getNodeData().getSequence().getName() ); - } - if ( getControlPanel().isShowSequenceAcc() && ( node.getNodeData().getSequence().getAccession() != null ) ) { - if ( _sb.length() > 0 ) { - _sb.append( " " ); - } - if ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getAccession().getSource() ) ) { - _sb.append( node.getNodeData().getSequence().getAccession().getSource() ); - _sb.append( ":" ); - } - _sb.append( node.getNodeData().getSequence().getAccession().getValue() ); - } - } - if ( getControlPanel().isShowProperties() && node.getNodeData().isHasProperties() ) { - if ( _sb.length() > 0 ) { - _sb.append( " " ); - } - _sb.append( propertiesToString( node ) ); - } + nodeDataAsSB( node, _sb ); final boolean using_visual_font = setFont( g, node, is_in_found_nodes ); float down_shift_factor = 3.0f; if ( !node.isExternal() && ( node.getNumberOfDescendants() == 1 ) ) { @@ -4818,57 +4900,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee + ( getFontMetrics( g.getFont() ).getAscent() / ( node.getNumberOfDescendants() == 1 ? 1 : 3.0f ) ); } _sb.setLength( 0 ); - if ( _control_panel.isShowTaxonomyCode() && !ForesterUtil.isEmpty( taxonomy.getTaxonomyCode() ) ) { - _sb.append( taxonomy.getTaxonomyCode() ); - _sb.append( " " ); - } - if ( _control_panel.isShowTaxonomyScientificNames() && _control_panel.isShowTaxonomyCommonNames() ) { - if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) - && !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) { - if ( getOptions().isAbbreviateScientificTaxonNames() - && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) { - abbreviateScientificName( taxonomy.getScientificName() ); - } - else { - _sb.append( taxonomy.getScientificName() ); - } - _sb.append( " (" ); - _sb.append( taxonomy.getCommonName() ); - _sb.append( ") " ); - } - else if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) { - if ( getOptions().isAbbreviateScientificTaxonNames() - && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) { - abbreviateScientificName( taxonomy.getScientificName() ); - } - else { - _sb.append( taxonomy.getScientificName() ); - } - _sb.append( " " ); - } - else if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) { - _sb.append( taxonomy.getCommonName() ); - _sb.append( " " ); - } - } - else if ( _control_panel.isShowTaxonomyScientificNames() ) { - if ( !ForesterUtil.isEmpty( taxonomy.getScientificName() ) ) { - if ( getOptions().isAbbreviateScientificTaxonNames() - && ( taxonomy.getScientificName().indexOf( ' ' ) > 0 ) ) { - abbreviateScientificName( taxonomy.getScientificName() ); - } - else { - _sb.append( taxonomy.getScientificName() ); - } - _sb.append( " " ); - } - } - else if ( _control_panel.isShowTaxonomyCommonNames() ) { - if ( !ForesterUtil.isEmpty( taxonomy.getCommonName() ) ) { - _sb.append( taxonomy.getCommonName() ); - _sb.append( " " ); - } - } + nodeTaxonomyDataAsSB( taxonomy, _sb ); final String label = _sb.toString(); /* GUILHEM_BEG */ if ( _control_panel.isShowSequenceRelations() && ( label.length() > 0 ) diff --git a/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java b/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java index da0dc24..b3f4b5c 100644 --- a/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java +++ b/forester/java/src/org/forester/phylogeny/data/NodeVisualData.java @@ -14,6 +14,7 @@ import org.forester.util.ForesterUtil; public final class NodeVisualData implements PhylogenyData { 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"; @@ -26,16 +27,14 @@ public final class NodeVisualData implements PhylogenyData { 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 + "node_border_color"; - public static final String NODE_BORDER_COLOR_TYPE = "xsd:token"; - public static final String NODE_FILL_COLOR_REF = APTX_VISUALIZATION_REF + "node_fill_color"; - public static final String NODE_FILL_COLOR_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 = "cicle"; + 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"; @@ -44,16 +43,14 @@ public final class NodeVisualData implements PhylogenyData { 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_TRANSPARENCY = -1; - private Color _border_color; - private Color _fill_color; 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 _transparency; @@ -68,8 +65,7 @@ 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 transparency ) { setFontName( font_name ); @@ -78,8 +74,7 @@ public final class NodeVisualData implements PhylogenyData { setFontColor( font_color ); setShape( shape ); setFillType( fill_type ); - setBorderColor( border_color ); - setFillColor( fill_color ); + setNodeColor( node_color ); setSize( size ); setTransparency( transparency ); } @@ -104,22 +99,12 @@ 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(), getTransparency() ); } - public final Color getBorderColor() { - return _border_color; - } - - public final Color getFillColor() { - return _fill_color; - } - public final NodeFill getFillType() { return _fill_type; } @@ -164,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; } @@ -180,7 +169,7 @@ public final class NodeVisualData implements PhylogenyData { 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 ) && ( getTransparency() == DEFAULT_TRANSPARENCY ) ); + && ( getNodeColor() == null ) && ( getSize() == DEFAULT_SIZE ) && ( getTransparency() == DEFAULT_TRANSPARENCY ) ); } @Override @@ -215,11 +204,10 @@ public final class NodeVisualData implements PhylogenyData { return; } } - // else if ( prop.getRef().equals( NODE_SIZE_REF ) ) { - int s = -1; + float s = -1.0f; try { - s = Integer.parseInt( prop.getValue() ); + s = Float.parseFloat( prop.getValue() ); } catch ( final NumberFormatException e ) { return; @@ -228,44 +216,41 @@ public final class NodeVisualData implements PhylogenyData { setSize( s ); } } - else if ( prop.getRef().equals( NODE_FILL_COLOR_REF ) ) { - try { - setFillColor( Color.decode( prop.getValue() ) ); - } - catch ( final NumberFormatException e ) { - return; - } - } - else if ( prop.getRef().equals( NODE_BORDER_COLOR_REF ) ) { + else if ( prop.getRef().equals( NODE_COLOR_REF ) ) { try { - setBorderColor( Color.decode( prop.getValue() ) ); + setNodeColor( Color.decode( prop.getValue() ) ); } catch ( final NumberFormatException e ) { return; } } else if ( prop.getRef().equals( NODE_SHAPE_REF ) ) { - try { - setShape( prop.getValue() ); - } - catch ( final NumberFormatException e ) { - return; - } + setShape( prop.getValue() ); + } + else if ( prop.getRef().equals( NODE_FILL_TYPE_REF ) ) { + setFillType( 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; } 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; } @@ -326,6 +311,10 @@ 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; } @@ -381,8 +370,7 @@ public final class NodeVisualData implements PhylogenyData { setFontColor( null ); setShape( NodeShape.DEFAULT ); setFillType( NodeFill.DEFAULT ); - setBorderColor( null ); - setFillColor( null ); + setNodeColor( null ); setSize( DEFAULT_SIZE ); setTransparency( DEFAULT_TRANSPARENCY ); _font = null; @@ -443,18 +431,11 @@ public final class NodeVisualData implements PhylogenyData { 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() ), + if ( getNodeColor() != null ) { + properties.add( new Property( NODE_COLOR_REF, + colorToHex( getNodeColor() ), "", - NODE_BORDER_COLOR_TYPE, + NODE_COLOR_TYPE, AppliesTo.NODE ) ); } if ( getFillType() != NodeFill.DEFAULT ) {