work on data buffer for aLeaves MAFFT suite + clean up
[jalview.git] / forester / java / src / org / forester / archaeopteryx / TreePanel.java
index 907a20f..870f1c8 100644 (file)
@@ -129,111 +129,113 @@ import org.forester.util.SequenceIdParser;
 
 public final class TreePanel extends JPanel implements ActionListener, MouseWheelListener, Printable {
 
-    private static final float              PI                                = ( float ) ( Math.PI );
-    private static final double             TWO_PI                            = 2 * Math.PI;
-    private static final float              ONEHALF_PI                        = ( float ) ( 1.5 * Math.PI );
-    private static final float              HALF_PI                           = ( float ) ( Math.PI / 2.0 );
-    private static final float              ANGLE_ROTATION_UNIT               = ( float ) ( Math.PI / 32 );
-    private static final short              OV_BORDER                         = 10;
-    final static Cursor                     CUT_CURSOR                        = Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
-    final static Cursor                     MOVE_CURSOR                       = Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR );
-    final static Cursor                     ARROW_CURSOR                      = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR );
-    final static Cursor                     HAND_CURSOR                       = Cursor.getPredefinedCursor( Cursor.HAND_CURSOR );
-    final static Cursor                     WAIT_CURSOR                       = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
-    private final static long               serialVersionUID                  = -978349745916505029L;
-    private final static int                EURO_D                            = 10;
-    private final static String             NODE_POPMENU_NODE_CLIENT_PROPERTY = "node";
-    private final static int                MIN_ROOT_LENGTH                   = 3;
-    private final static int                MAX_SUBTREES                      = 100;
-    private final static int                MAX_NODE_FRAMES                   = 10;
-    private final static int                MOVE                              = 20;
+    private static final float              PI                                                 = ( float ) ( Math.PI );
+    private static final double             TWO_PI                                             = 2 * Math.PI;
+    private static final float              ONEHALF_PI                                         = ( float ) ( 1.5 * Math.PI );
+    private static final float              HALF_PI                                            = ( float ) ( Math.PI / 2.0 );
+    private static final float              ANGLE_ROTATION_UNIT                                = ( float ) ( Math.PI / 32 );
+    private static final short              OV_BORDER                                          = 10;
+    final static Cursor                     CUT_CURSOR                                         = Cursor.getPredefinedCursor( Cursor.CROSSHAIR_CURSOR );
+    final static Cursor                     MOVE_CURSOR                                        = Cursor.getPredefinedCursor( Cursor.MOVE_CURSOR );
+    final static Cursor                     ARROW_CURSOR                                       = Cursor.getPredefinedCursor( Cursor.DEFAULT_CURSOR );
+    final static Cursor                     HAND_CURSOR                                        = Cursor.getPredefinedCursor( Cursor.HAND_CURSOR );
+    final static Cursor                     WAIT_CURSOR                                        = Cursor.getPredefinedCursor( Cursor.WAIT_CURSOR );
+    private final static long               serialVersionUID                                   = -978349745916505029L;
+    private final static int                EURO_D                                             = 10;
+    private final static String             NODE_POPMENU_NODE_CLIENT_PROPERTY                  = "node";
+    private final static int                MIN_ROOT_LENGTH                                    = 3;
+    private final static int                MAX_SUBTREES                                       = 100;
+    private final static int                MAX_NODE_FRAMES                                    = 10;
+    private final static int                MOVE                                               = 20;
     private final static NumberFormat       FORMATTER_CONFIDENCE;
     private final static NumberFormat       FORMATTER_BRANCH_LENGTH;
-    private final static int                WIGGLE                            = 2;
-    private final static int                LIMIT_FOR_HQ_RENDERING            = 1000;
-    private final static int                CONFIDENCE_LEFT_MARGIN            = 4;
-    // TODO "rendering_hints" was static before. Need to make sure everything is OK with it not
-    // being static anymore (02/20/2009).
-    private final RenderingHints            _rendering_hints                  = new RenderingHints( RenderingHints.KEY_RENDERING,
-                                                                                                    RenderingHints.VALUE_RENDER_DEFAULT );
-    private File                            _treefile                         = null;
-    private Configuration                   _configuration                    = null;
-    private final NodeFrame[]               _node_frames                      = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
-    private int                             _node_frame_index                 = 0;
-    private Phylogeny                       _phylogeny                        = null;
-    private final Phylogeny[]               _sub_phylogenies                  = new Phylogeny[ TreePanel.MAX_SUBTREES ];
-    private final PhylogenyNode[]           _sub_phylogenies_temp_roots       = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
-    private int                             _subtree_index                    = 0;
-    private MainPanel                       _main_panel                       = null;
-    private Set<Integer>                    _found_nodes                      = null;
-    private PhylogenyNode                   _highlight_node                   = null;
-    private JPopupMenu                      _node_popup_menu                  = null;
-    private JMenuItem                       _node_popup_menu_items[]          = null;
-    private int                             _longest_ext_node_info            = 0;
-    private float                           _x_correction_factor              = 0.0f;
-    private float                           _ov_x_correction_factor           = 0.0f;
-    private float                           _x_distance                       = 0.0f;
-    private float                           _y_distance                       = 0.0f;
-    private PHYLOGENY_GRAPHICS_TYPE         _graphics_type                    = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
-    private double                          _domain_structure_width           = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
-    private int                             _domain_structure_e_value_thr_exp = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
-    private float                           _last_drag_point_x                = 0;
-    private float                           _last_drag_point_y                = 0;
-    private ControlPanel                    _control_panel                    = null;
-    private int                             _external_node_index              = 0;
-    private final Polygon                   _polygon                          = new Polygon();
-    private final StringBuilder             _sb                               = new StringBuilder();
-    private JColorChooser                   _color_chooser                    = null;
-    private double                          _scale_distance                   = 0.0;
-    private String                          _scale_label                      = null;
-    private final CubicCurve2D              _cubic_curve                      = new CubicCurve2D.Float();
-    private final QuadCurve2D               _quad_curve                       = new QuadCurve2D.Float();
-    private final Line2D                    _line                             = new Line2D.Float();
-    private final Ellipse2D                 _ellipse                          = new Ellipse2D.Float();
-    private final Rectangle2D               _rectangle                        = new Rectangle2D.Float();
-    private Options                         _options                          = null;
-    private float                           _ov_max_width                     = 0;
-    private float                           _ov_max_height                    = 0;
-    private int                             _ov_x_position                    = 0;
-    private int                             _ov_y_position                    = 0;
-    private int                             _ov_y_start                       = 0;
-    private float                           _ov_y_distance                    = 0;
-    private float                           _ov_x_distance                    = 0;
-    private boolean                         _ov_on                            = false;
-    private double                          _urt_starting_angle               = ( float ) ( Math.PI / 2 );
-    private float                           _urt_factor                       = 1;
-    private float                           _urt_factor_ov                    = 1;
+    private final static int                WIGGLE                                             = 2;
+    private final static int                LIMIT_FOR_HQ_RENDERING                             = 1000;
+    private final static int                CONFIDENCE_LEFT_MARGIN                             = 4;
+    private final RenderingHints            _rendering_hints                                   = new RenderingHints( RenderingHints.KEY_RENDERING,
+                                                                                                                     RenderingHints.VALUE_RENDER_DEFAULT );
+    private File                            _treefile                                          = null;
+    private Configuration                   _configuration                                     = null;
+    private final NodeFrame[]               _node_frames                                       = new NodeFrame[ TreePanel.MAX_NODE_FRAMES ];
+    private int                             _node_frame_index                                  = 0;
+    private Phylogeny                       _phylogeny                                         = null;
+    private final Phylogeny[]               _sub_phylogenies                                   = new Phylogeny[ TreePanel.MAX_SUBTREES ];
+    private final PhylogenyNode[]           _sub_phylogenies_temp_roots                        = new PhylogenyNode[ TreePanel.MAX_SUBTREES ];
+    private int                             _subtree_index                                     = 0;
+    private MainPanel                       _main_panel                                        = null;
+    private Set<Integer>                    _found_nodes                                       = null;
+    private PhylogenyNode                   _highlight_node                                    = null;
+    private JPopupMenu                      _node_popup_menu                                   = null;
+    private JMenuItem                       _node_popup_menu_items[]                           = null;
+    private int                             _longest_ext_node_info                             = 0;
+    private float                           _x_correction_factor                               = 0.0f;
+    private float                           _ov_x_correction_factor                            = 0.0f;
+    private float                           _x_distance                                        = 0.0f;
+    private float                           _y_distance                                        = 0.0f;
+    private PHYLOGENY_GRAPHICS_TYPE         _graphics_type                                     = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
+    private double                          _domain_structure_width                            = Constants.DOMAIN_STRUCTURE_DEFAULT_WIDTH;
+    private int                             _domain_structure_e_value_thr_exp                  = Constants.DOMAIN_STRUCTURE_E_VALUE_THR_DEFAULT_EXP;
+    private float                           _last_drag_point_x                                 = 0;
+    private float                           _last_drag_point_y                                 = 0;
+    private ControlPanel                    _control_panel                                     = null;
+    private int                             _external_node_index                               = 0;
+    private final Polygon                   _polygon                                           = new Polygon();
+    private final StringBuilder             _sb                                                = new StringBuilder();
+    private JColorChooser                   _color_chooser                                     = null;
+    private double                          _scale_distance                                    = 0.0;
+    private String                          _scale_label                                       = null;
+    private final CubicCurve2D              _cubic_curve                                       = new CubicCurve2D.Float();
+    private final QuadCurve2D               _quad_curve                                        = new QuadCurve2D.Float();
+    private final Line2D                    _line                                              = new Line2D.Float();
+    private final Ellipse2D                 _ellipse                                           = new Ellipse2D.Float();
+    private final Rectangle2D               _rectangle                                         = new Rectangle2D.Float();
+    private Options                         _options                                           = null;
+    private float                           _ov_max_width                                      = 0;
+    private float                           _ov_max_height                                     = 0;
+    private int                             _ov_x_position                                     = 0;
+    private int                             _ov_y_position                                     = 0;
+    private int                             _ov_y_start                                        = 0;
+    private float                           _ov_y_distance                                     = 0;
+    private float                           _ov_x_distance                                     = 0;
+    private boolean                         _ov_on                                             = false;
+    private double                          _urt_starting_angle                                = ( float ) ( Math.PI / 2 );
+    private float                           _urt_factor                                        = 1;
+    private float                           _urt_factor_ov                                     = 1;
     private final boolean                   _phy_has_branch_lengths;
-    private final Rectangle2D               _ov_rectangle                     = new Rectangle2D.Float();
-    private boolean                         _in_ov_rect                       = false;
-    private boolean                         _in_ov                            = false;
-    private final Rectangle                 _ov_virtual_rectangle             = new Rectangle();
-    final private static double             _180_OVER_PI                      = 180.0 / Math.PI;
-    private static final float              ROUNDED_D                         = 8;
+    private final Rectangle2D               _ov_rectangle                                      = new Rectangle2D.Float();
+    private boolean                         _in_ov_rect                                        = false;
+    private boolean                         _in_ov                                             = false;
+    private final Rectangle                 _ov_virtual_rectangle                              = new Rectangle();
+    final private static double             _180_OVER_PI                                       = 180.0 / Math.PI;
+    private static final float              ROUNDED_D                                          = 8;
     private int                             _circ_max_depth;
     private PhylogenyNode                   _root;
-    final private Arc2D                     _arc                              = new Arc2D.Double();
-    final private HashMap<Integer, Double>  _urt_nodeid_angle_map             = new HashMap<Integer, Double>();
-    final private HashMap<Integer, Integer> _urt_nodeid_index_map             = new HashMap<Integer, Integer>();
-    final private Set<Integer>              _collapsed_external_nodeid_set    = new HashSet<Integer>();
-    HashMap<Integer, Short>                 _nodeid_dist_to_leaf              = new HashMap<Integer, Short>();
+    final private Arc2D                     _arc                                               = new Arc2D.Double();
+    final private HashMap<Integer, Double>  _urt_nodeid_angle_map                              = new HashMap<Integer, Double>();
+    final private HashMap<Integer, Integer> _urt_nodeid_index_map                              = new HashMap<Integer, Integer>();
+    final private Set<Integer>              _collapsed_external_nodeid_set                     = new HashSet<Integer>();
+    HashMap<Integer, Short>                 _nodeid_dist_to_leaf                               = new HashMap<Integer, Short>();
     private AffineTransform                 _at;
-    private double                          _max_distance_to_root             = -1;
-    private int                             _dynamic_hiding_factor            = 0;
-    private boolean                         _edited                           = false;
+    private double                          _max_distance_to_root                              = -1;
+    private int                             _dynamic_hiding_factor                             = 0;
+    private boolean                         _edited                                            = false;
     private Popup                           _node_desc_popup;
     private JTextArea                       _rollover_popup;
-    private final StringBuffer              _popup_buffer                     = new StringBuffer();
-    final private static Font               POPUP_FONT                        = new Font( Configuration.getDefaultFontFamilyName(),
-                                                                                          Font.PLAIN,
-                                                                                          12 );
-    private Sequence                        _query_sequence                   = null;
-    private final FontRenderContext         _frc                              = new FontRenderContext( null,
-                                                                                                       false,
-                                                                                                       false );
+    private final StringBuffer              _popup_buffer                                      = new StringBuffer();
+    final private static Font               POPUP_FONT                                         = new Font( Configuration
+                                                                                                                   .getDefaultFontFamilyName(),
+                                                                                                           Font.PLAIN,
+                                                                                                           12 );
+    private Sequence                        _query_sequence                                    = null;
+    private final FontRenderContext         _frc                                               = new FontRenderContext( null,
+                                                                                                                        false,
+                                                                                                                        false );
     // expression values menu:
     private DescriptiveStatistics           _statistics_for_vector_data;
-    private PhylogenyNode[]                 _nodes_in_preorder                = null;
+    private PhylogenyNode[]                 _nodes_in_preorder                                 = null;
+    private StringBuilder                   _current_external_nodes_data_buffer                = new StringBuilder();
+    private int                             _current_external_nodes_data_buffer_change_counter = 0;
+    private Set<Integer>                    _current_external_nodes                            = null;
     //  private Image                           offscreenImage;
     //  private Graphics                        offscreenGraphics;
     //  private Dimension                       offscreenDimension;
@@ -731,6 +733,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         return c;
     }
 
+    void clearCurrentExternalNodesDataBuffer() {
+        setCurrentExternalNodesDataBuffer( new StringBuilder() );
+    }
+
     /**
      * Collapse the tree from the given node
      * 
@@ -877,6 +883,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         return _control_panel;
     }
 
+    String getCurrentExternalNodesDataBufferAsString() {
+        return _current_external_nodes_data_buffer.toString();
+    }
+
+    int getCurrentExternalNodesDataBufferChangeCounter() {
+        return _current_external_nodes_data_buffer_change_counter;
+    }
+
     final int getDomainStructureEvalueThreshold() {
         return _domain_structure_e_value_thr_exp;
     }
@@ -1238,6 +1252,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
 
     final void mouseMoved( final MouseEvent e ) {
         requestFocusInWindow();
+        if ( _current_external_nodes != null ) {
+            _current_external_nodes = null;
+            repaint();
+        }
         if ( getControlPanel().isNodeDescPopup() ) {
             if ( _node_desc_popup != null ) {
                 _node_desc_popup.hide();
@@ -1269,8 +1287,14 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             }
             final PhylogenyNode node = findNode( e.getX(), e.getY() );
             if ( ( node != null ) && ( node.isRoot() || !node.getParent().isCollapse() ) ) {
-                // cursor is over a tree node
-                if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
+                if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.GET_EXT_DESC_DATA ) ) {
+                    for( final PhylogenyNode n : node.getAllExternalDescendants() ) {
+                        addToCurrentExternalNodes( n.getId() );
+                    }
+                    setCursor( HAND_CURSOR );
+                    repaint();
+                }
+                else if ( ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.CUT_SUBTREE )
                         || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.COPY_SUBTREE )
                         || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.PASTE_SUBTREE )
                         || ( getControlPanel().getActionWhenNodeClicked() == NodeClickAction.DELETE_NODE_OR_SUBTREE )
@@ -1327,9 +1351,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                   root_x + ( Math.cos( angle ) * parent_radius ),
                   root_y + ( Math.sin( angle ) * parent_radius ),
                   g );
-        paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file, isInFoundNodes( c ) );
+        paintNodeBox( c.getXcoord(), c.getYcoord(), c, g, to_pdf, to_graphics_file, isInFoundNodes( c )
+                || isInCurrentExternalNodes( c ) );
         if ( c.isExternal() ) {
-            final boolean is_in_found_nodes = isInFoundNodes( c );
+            final boolean is_in_found_nodes = isInFoundNodes( c ) || isInCurrentExternalNodes( c );
             if ( ( _dynamic_hiding_factor > 1 ) && !is_in_found_nodes
                     && ( ( _urt_nodeid_index_map.get( c.getId() ) % _dynamic_hiding_factor ) != 1 ) ) {
                 return;
@@ -1356,7 +1381,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                   root_x + ( Math.cos( angle ) * parent_radius ),
                   root_y + ( Math.sin( angle ) * parent_radius ),
                   g );
-        if ( isInFoundNodes( c ) ) {
+        if ( isInFoundNodes( c ) || isInCurrentExternalNodes( c ) ) {
             g.setColor( getTreeColorSet().getFoundColor() );
             drawRectFilled( c.getXSecondary() - 1, c.getYSecondary() - 1, 3, 3, g );
         }
@@ -1736,6 +1761,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         _control_panel = atv_control;
     }
 
+    void setCurrentExternalNodesDataBuffer( final StringBuilder sb ) {
+        increaseCurrentExternalNodesDataBufferChangeCounter();
+        _current_external_nodes_data_buffer = sb;
+    }
+
     final void setFoundNodes( final Set<Integer> found_nodes ) {
         _found_nodes = found_nodes;
     }
@@ -2123,6 +2153,13 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         repaint();
     }
 
+    final private void addToCurrentExternalNodes( final int i ) {
+        if ( _current_external_nodes == null ) {
+            _current_external_nodes = new HashSet<Integer>();
+        }
+        _current_external_nodes.add( i );
+    }
+
     final private void assignGraphicsForBranchWithColorForParentBranch( final PhylogenyNode node,
                                                                         final boolean is_vertical,
                                                                         final Graphics g,
@@ -2339,6 +2376,22 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         repaint();
     }
 
+    private String createAnnotationString( final SortedSet<Annotation> ann ) {
+        final StringBuilder sb = new StringBuilder();
+        boolean first = true;
+        for( final Annotation a : ann ) {
+            if ( !first ) {
+                sb.append( "|" );
+            }
+            else {
+                first = false;
+            }
+            sb.append( a.asSimpleText() );
+        }
+        final String ann_str = sb.toString();
+        return ann_str;
+    }
+
     final private String createASimpleTextRepresentationOfANode( final PhylogenyNode node ) {
         final String tax = PhylogenyMethods.getSpecies( node );
         String label = node.getName();
@@ -2611,6 +2664,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         return getMainPanel().getCopiedAndPastedNodes();
     }
 
+    final private Set<Integer> getCurrentExternalNodes() {
+        return _current_external_nodes;
+    }
+
     final private Phylogeny getCutOrCopiedTree() {
         return getMainPanel().getCutOrCopiedTree();
     }
@@ -2754,6 +2811,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
     }
 
+    final private void increaseCurrentExternalNodesDataBufferChangeCounter() {
+        _current_external_nodes_data_buffer_change_counter++;
+    }
+
     final private void increaseOvSize() {
         if ( ( getOvMaxWidth() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect().getWidth() / 2 ) )
                 && ( getOvMaxHeight() < ( getMainPanel().getCurrentScrollPane().getViewport().getVisibleRect()
@@ -2833,6 +2894,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
     }
 
+    final private boolean isInCurrentExternalNodes( final PhylogenyNode node ) {
+        return ( ( getCurrentExternalNodes() != null ) && getCurrentExternalNodes().contains( node.getId() ) );
+    }
+
     final private boolean isInFoundNodes( final PhylogenyNode node ) {
         return ( ( getFoundNodes() != null ) && getFoundNodes().contains( node.getId() ) );
     }
@@ -3446,7 +3511,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             }
         }
         if ( node.isExternal() ) {
-            paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) );
+            paintNodeBox( x2, y2, node, g, to_pdf, to_graphics_file, isInFoundNodes( node )
+                    || isInCurrentExternalNodes( node ) );
         }
     }
 
@@ -4035,22 +4101,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
     }
 
-    private String createAnnotationString( final SortedSet<Annotation> ann ) {
-        final StringBuilder sb = new StringBuilder();
-        boolean first = true;
-        for( final Annotation a : ann ) {
-            if ( !first ) {
-                sb.append( "|" );
-            }
-            else {
-                first = false;
-            }
-            sb.append( a.asSimpleText() );
-        }
-        final String ann_str = sb.toString();
-        return ann_str;
-    }
-
     final private void paintNodeDataUnrootedCirc( final Graphics2D g,
                                                   final PhylogenyNode node,
                                                   final boolean to_pdf,
@@ -4196,7 +4246,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             }
             return;
         }
-        if ( isInFoundNodes( node ) ) {
+        if ( isInFoundNodes( node ) || isInCurrentExternalNodes( node ) ) {
             g.setColor( getTreeColorSet().getFoundColor() );
             drawRectFilled( node.getXSecondary() - 1, node.getYSecondary() - 1, 3, 3, g );
         }
@@ -4243,7 +4293,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                                              final boolean dynamically_hide,
                                              final int dynamic_hiding_factor,
                                              final boolean to_graphics_file ) {
-        final boolean is_in_found_nodes = isInFoundNodes( node );
+        final boolean is_in_found_nodes = isInFoundNodes( node ) || isInCurrentExternalNodes( node );
         if ( node.isCollapse() ) {
             if ( ( !node.isRoot() && !node.getParent().isCollapse() ) || node.isRoot() ) {
                 paintCollapsedNode( g, node, to_graphics_file, to_pdf, is_in_found_nodes );
@@ -4325,7 +4375,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 child_node.setYcoord( y2 );
                 y2 += _y_distance * child_node.getNumberOfExternalNodes();
             }
-            paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file, isInFoundNodes( node ) );
+            paintNodeBox( node.getXcoord(), node.getYcoord(), node, g, to_pdf, to_graphics_file, isInFoundNodes( node )
+                    || isInCurrentExternalNodes( node ) );
         }
         if ( dynamically_hide
                 && !is_in_found_nodes
@@ -4463,16 +4514,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
     }
 
     final private void paintPhylogenyLite( final Graphics2D g ) {
-        //System.out.println( getVisibleRect().x + " " + getVisibleRect().y );
         _phylogeny
                 .getRoot()
                 .setXSecondary( ( float ) ( getVisibleRect().x + getOvXPosition() + ( MOVE / ( getVisibleRect().width / getOvRectangle()
                         .getWidth() ) ) ) );
         _phylogeny.getRoot().setYSecondary( ( getVisibleRect().y + getOvYStart() ) );
-        //final PhylogenyNodeIterator it;
-        //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
-        //    paintNodeLite( g, it.next() );
-        //}
         for( final PhylogenyNode element : _nodes_in_preorder ) {
             paintNodeLite( g, element );
         }
@@ -4658,7 +4704,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                                        to_graphics_file,
                                        radial_labels,
                                        ( high_angle + low_angle ) / 2,
-                                       isInFoundNodes( n ) );
+                                       isInFoundNodes( n ) || isInCurrentExternalNodes( n ) );
             return;
         }
         final float num_enclosed = n.getNumberOfExternalNodes();
@@ -4706,7 +4752,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             current_angle += arc_size;
             assignGraphicsForBranchWithColorForParentBranch( desc, false, g, to_pdf, to_graphics_file );
             drawLine( x, y, new_x, new_y, g );
-            paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file, isInFoundNodes( desc ) );
+            paintNodeBox( new_x, new_y, desc, g, to_pdf, to_graphics_file, isInFoundNodes( desc )
+                    || isInCurrentExternalNodes( desc ) );
         }
         if ( n.isRoot() ) {
             paintNodeBox( n.getXcoord(), n.getYcoord(), n, g, to_pdf, to_graphics_file, isInFoundNodes( n ) );
@@ -4752,7 +4799,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             final float new_y = ( float ) ( y + ( Math.sin( mid_angle ) * length ) );
             desc.setXSecondary( new_x );
             desc.setYSecondary( new_y );
-            if ( isInFoundNodes( desc ) ) {
+            if ( isInFoundNodes( desc ) || isInCurrentExternalNodes( desc ) ) {
                 g.setColor( getTreeColorSet().getFoundColor() );
                 drawRectFilled( desc.getXSecondary() - 1, desc.getYSecondary() - 1, 3, 3, g );
                 g.setColor( getTreeColorSet().getOvColor() );
@@ -4991,40 +5038,53 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                             + getOptions().getExtDescNodeDataToReturn() );
             }
         } // for loop
-        if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) {
+        if ( ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE )
+                || ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.BUFFER_ONLY ) ) {
+            final StringBuilder sb = new StringBuilder();
             for( final String d : data ) {
                 if ( !ForesterUtil.isEmpty( d ) ) {
-                    System.out.println( d );
+                    if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.CONSOLE ) {
+                        System.out.println( d );
+                    }
+                    sb.append( d );
+                    sb.append( ForesterUtil.LINE_SEPARATOR );
                 }
             }
+            if ( sb.length() < 1 ) {
+                clearCurrentExternalNodesDataBuffer();
+            }
+            else {
+                setCurrentExternalNodesDataBuffer( sb );
+            }
         }
         else if ( getConfiguration().getExtNodeDataReturnOn() == EXT_NODE_DATA_RETURN_ON.WINODW ) {
             final StringBuilder sb = new StringBuilder();
             for( final String d : data ) {
                 if ( !ForesterUtil.isEmpty( d ) ) {
                     sb.append( d );
-                    sb.append( "\n" );
+                    sb.append( ForesterUtil.LINE_SEPARATOR );
                 }
             }
             if ( sb.length() < 1 ) {
                 AptxUtil.showInformationMessage( this,
                                                  "No Appropriate Data (" + obtainTitleForExtDescNodeData() + ")",
                                                  "Descendants of selected node do not contain selected data" );
+                clearCurrentExternalNodesDataBuffer();
             }
             else {
+                setCurrentExternalNodesDataBuffer( sb );
                 final String title = "External Descendants "
                         + ( getOptions().getExtDescNodeDataToReturn() == NODE_DATA.UNKNOWN ? "Data"
                                 : obtainTitleForExtDescNodeData() ) + " (" + data.size() + "/"
                         + node.getNumberOfExternalNodes() + ") For Node " + node;
+                final String s = sb.toString().trim();
                 if ( getMainPanel().getMainFrame() == null ) {
                     // Must be "E" applet version.
                     final ArchaeopteryxE ae = ( ArchaeopteryxE ) ( ( MainPanelApplets ) getMainPanel() ).getApplet();
-                    final String s = sb.toString().trim();
                     ae.showTextFrame( s, title );
-                    ae.setCurrentExternalNodesDataBuffer( s );
                 }
                 else {
-                    getMainPanel().getMainFrame().showTextFrame( sb.toString(), title );
+                    getMainPanel().getMainFrame().showTextFrame( s, title );
                 }
             }
         }