refactored
[jalview.git] / forester / java / src / org / forester / archaeopteryx / TreePanel.java
index a82f574..00620cc 100644 (file)
@@ -95,6 +95,8 @@ import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
 import org.forester.archaeopteryx.phylogeny.data.RenderableDomainArchitecture;
 import org.forester.archaeopteryx.phylogeny.data.RenderableVector;
+import org.forester.archaeopteryx.tools.Blast;
+import org.forester.archaeopteryx.tools.ImageLoader;
 import org.forester.io.parsers.phyloxml.PhyloXmlUtil;
 import org.forester.phylogeny.Phylogeny;
 import org.forester.phylogeny.PhylogenyMethods;
@@ -228,6 +230,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                                                                                                        false );
     // expression values menu:
     private DescriptiveStatistics           _statistics_for_vector_data;
+    private PhylogenyNode[]                 _nodes_in_preorder                = null;
     //  private Image                           offscreenImage;
     //  private Graphics                        offscreenGraphics;
     //  private Dimension                       offscreenDimension;
@@ -403,6 +406,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         else {
             phy.addAsChild( node );
         }
+        _nodes_in_preorder = null;
         _phylogeny.externalNodesHaveChanged();
         _phylogeny.hashIDs();
         _phylogeny.recalculateNumberOfExternalDescendants( true );
@@ -688,6 +692,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             _phylogeny.recalculateNumberOfExternalDescendants( true );
             resetNodeIdToDistToLeafMap();
             calculateLongestExtNodeInfo();
+            _nodes_in_preorder = null;
             resetPreferredSize();
             updateOvSizes();
             _main_panel.adjustJScrollPane();
@@ -704,6 +709,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         _phylogeny.recalculateNumberOfExternalDescendants( true );
         resetNodeIdToDistToLeafMap();
         calculateLongestExtNodeInfo();
+        _nodes_in_preorder = null;
         resetPreferredSize();
         _main_panel.adjustJScrollPane();
         setArrowCursor();
@@ -768,6 +774,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             errorMessageNoCutCopyPasteInUnrootedDisplay();
             return;
         }
+        _nodes_in_preorder = null;
         setCutOrCopiedTree( _phylogeny.copy( node ) );
         final List<PhylogenyNode> nodes = PhylogenyMethods.getAllDescendants( node );
         final Set<Integer> node_ids = new HashSet<Integer>( nodes.size() );
@@ -799,6 +806,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         if ( r != JOptionPane.OK_OPTION ) {
             return;
         }
+        _nodes_in_preorder = null;
         setCopiedAndPastedNodes( null );
         setCutOrCopiedTree( _phylogeny.copy( node ) );
         _phylogeny.deleteSubtree( node, true );
@@ -853,6 +861,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                                                     null,
                                                     options,
                                                     options[ 2 ] );
+        _nodes_in_preorder = null;
         boolean node_only = true;
         if ( r == 1 ) {
             node_only = false;
@@ -1090,7 +1099,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
      * 
      * @return a pointer to the phylogeny
      */
-    final Phylogeny getPhylogeny() {
+    public final Phylogeny getPhylogeny() {
         return _phylogeny;
     }
 
@@ -1695,6 +1704,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                                            JOptionPane.WARNING_MESSAGE );
             return;
         }
+        _nodes_in_preorder = null;
         setWaitCursor();
         PhylogenyMethods.midpointRoot( _phylogeny );
         resetNodeIdToDistToLeafMap();
@@ -3336,6 +3346,17 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 if ( getControlPanel().isShowTaxonomyCode() && ( PhylogenyMethods.getSpecies( node ).length() > 0 ) ) {
                     x += getTreeFontSet()._fm_large_italic.stringWidth( PhylogenyMethods.getSpecies( node ) + " " );
                 }
+                if ( getControlPanel().isShowGeneNames() ) {
+                    x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getName() + " " );
+                }
+                if ( getControlPanel().isShowGeneSymbols() ) {
+                    x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getSymbol() + " " );
+                }
+                if ( getControlPanel().isShowSequenceAcc() ) {
+                    x += getTreeFontSet()._fm_large.stringWidth( node.getNodeData().getSequence().getAccession()
+                            .toString()
+                            + " " );
+                }
                 if ( getControlPanel().isShowNodeNames() && ( node.getName().length() > 0 ) ) {
                     x += getTreeFontSet()._fm_large.stringWidth( node.getName() + " " );
                 }
@@ -3468,9 +3489,20 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                     getControlPanel().setDynamicHidingIsOn( false );
                 }
             }
-            final PhylogenyNodeIterator it;
-            for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
-                paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData()
+            if ( _nodes_in_preorder == null ) {
+                _nodes_in_preorder = new PhylogenyNode[ _phylogeny.getNodeCount() ];
+                int i = 0;
+                for( final PhylogenyNodeIterator it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
+                    _nodes_in_preorder[ i++ ] = it.next();
+                }
+            }
+            //final PhylogenyNodeIterator it;
+            //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
+            //    paintNodeRectangular( g, it.next(), to_pdf, getControlPanel().isDynamicallyHideData()
+            //            && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
+            //}
+            for( int i = 0; i < _nodes_in_preorder.length; ++i ) {
+                paintNodeRectangular( g, _nodes_in_preorder[ i ], to_pdf, getControlPanel().isDynamicallyHideData()
                         && ( dynamic_hiding_factor > 1 ), dynamic_hiding_factor, to_graphics_file );
             }
             if ( getOptions().isShowScale() && getControlPanel().isDrawPhylogram() && ( getScaleDistance() > 0.0 ) ) {
@@ -3591,9 +3623,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 .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() );
+        //final PhylogenyNodeIterator it;
+        //for( it = _phylogeny.iteratorPreorder(); it.hasNext(); ) {
+        //    paintNodeLite( g, it.next() );
+        //}
+        for( int i = 0; i < _nodes_in_preorder.length; ++i ) {
+            paintNodeLite( g, _nodes_in_preorder[ i ] );
         }
         paintOvRectangle( g );
     }
@@ -3955,6 +3990,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
         node_ids.add( node.getId() );
         getCopiedAndPastedNodes().addAll( node_ids );
+        _nodes_in_preorder = null;
         _phylogeny.externalNodesHaveChanged();
         _phylogeny.hashIDs();
         _phylogeny.recalculateNumberOfExternalDescendants( true );
@@ -4030,6 +4066,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         getPhylogeny().reRoot( node );
         getPhylogeny().recalculateNumberOfExternalDescendants( true );
         resetNodeIdToDistToLeafMap();
+        _nodes_in_preorder = null;
         resetPreferredSize();
         getMainPanel().adjustJScrollPane();
         repaint();
@@ -4073,7 +4110,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         setPreferredSize( new Dimension( x, y ) );
     }
 
-    final void setArrowCursor() {
+    public final void setArrowCursor() {
         setCursor( ARROW_CURSOR );
         repaint();
     }
@@ -4090,7 +4127,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         getMainPanel().setCutOrCopiedTree( cut_or_copied_tree );
     }
 
-    final void setEdited( final boolean edited ) {
+    public final void setEdited( final boolean edited ) {
         _edited = edited;
     }
 
@@ -4288,7 +4325,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
      * @param t
      *            an instance of a Phylogeny
      */
-    final void setTree( final Phylogeny t ) {
+    public final void setTree( final Phylogeny t ) {
+        _nodes_in_preorder = null;
         _phylogeny = t;
     }
 
@@ -4322,7 +4360,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         _urt_factor_ov = urt_factor_ov;
     }
 
-    final void setWaitCursor() {
+    public final void setWaitCursor() {
         setCursor( WAIT_CURSOR );
         repaint();
     }
@@ -4627,6 +4665,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
     final void swap( final PhylogenyNode node ) {
         if ( !node.isExternal() ) {
             _phylogeny.swapChildren( node );
+            _nodes_in_preorder = null;
         }
         repaint();
     }
@@ -4840,11 +4879,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
     }
 
-    synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
+    public synchronized void setImageMap( final Hashtable<String, BufferedImage> image_map ) {
         getMainPanel().setImageMap( image_map );
     }
 
-    synchronized Hashtable<String, BufferedImage> getImageMap() {
+    public synchronized Hashtable<String, BufferedImage> getImageMap() {
         return getMainPanel().getImageMap();
     }
 }