in progress...
[jalview.git] / forester / java / src / org / forester / archaeopteryx / TreePanel.java
index ccd3652..75ef09b 100644 (file)
@@ -96,7 +96,6 @@ import javax.swing.PopupFactory;
 
 import org.forester.archaeopteryx.Configuration.EXT_NODE_DATA_RETURN_ON;
 import org.forester.archaeopteryx.ControlPanel.NodeClickAction;
-import org.forester.archaeopteryx.ControlPanel.TreeDisplayType;
 import org.forester.archaeopteryx.Options.CLADOGRAM_TYPE;
 import org.forester.archaeopteryx.Options.NODE_LABEL_DIRECTION;
 import org.forester.archaeopteryx.Options.PHYLOGENY_GRAPHICS_TYPE;
@@ -122,8 +121,6 @@ import org.forester.phylogeny.data.NodeVisualData;
 import org.forester.phylogeny.data.NodeVisualData.NodeFill;
 import org.forester.phylogeny.data.NodeVisualData.NodeShape;
 import org.forester.phylogeny.data.PhylogenyDataUtil;
-import org.forester.phylogeny.data.PropertiesMap;
-import org.forester.phylogeny.data.Property;
 import org.forester.phylogeny.data.ProteinDomain;
 import org.forester.phylogeny.data.Sequence;
 import org.forester.phylogeny.data.SequenceRelation;
@@ -131,7 +128,6 @@ import org.forester.phylogeny.data.Taxonomy;
 import org.forester.phylogeny.data.Uri;
 import org.forester.phylogeny.iterators.PhylogenyNodeIterator;
 import org.forester.phylogeny.iterators.PreorderTreeIterator;
-import org.forester.util.BasicDescriptiveStatistics;
 import org.forester.util.DescriptiveStatistics;
 import org.forester.util.ForesterConstants;
 import org.forester.util.ForesterUtil;
@@ -383,7 +379,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         init();
         // if ( !_phylogeny.isEmpty() ) {
         _phylogeny.recalculateNumberOfExternalDescendants( true );
-        checkForVectorProperties( _phylogeny );
         // }
         setBackground( getTreeColorSet().getBackgroundColor() );
         final MouseListener mouse_listener = new MouseListener( this );
@@ -740,8 +735,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                         type = 'n';
                     }
                 }
-               
-               
                 try {
                     Blast.openNcbiBlastWeb( query, type == 'n', this );
                 }
@@ -1304,16 +1297,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         return _last_drag_point_y;
     }
 
-    final private short getMaxBranchesToLeaf( final PhylogenyNode node ) {
-        if ( !_nodeid_dist_to_leaf.containsKey( node.getId() ) ) {
-            final short m = PhylogenyMethods.calculateMaxBranchesToLeaf( node );
-            _nodeid_dist_to_leaf.put( node.getId(), m );
-            return m;
-        }
-        else {
-            return _nodeid_dist_to_leaf.get( node.getId() );
-        }
-    }
 
     final private double getMaxDistanceToRoot() {
         if ( _max_distance_to_root < 0 ) {
@@ -1741,7 +1724,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 decreaseOvSize();
             }
         }
-        if ( e.getKeyCode() == KeyEvent.VK_HOME ) {
+        if ( e.getKeyCode() == KeyEvent.VK_HOME || e.getKeyCode() == KeyEvent.VK_ESCAPE ) {
             getControlPanel().showWhole();
         }
         else if ( e.getKeyCode() == KeyEvent.VK_PAGE_UP ) {
@@ -2001,8 +1984,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         if ( !ForesterUtil.isEmpty( uri_strs ) ) {
             for( final String uri_str : uri_strs ) {
                 try {
-                    AptxUtil.launchWebBrowser( new URI( uri_str ),
-                                               "_aptx_seq" );
+                    AptxUtil.launchWebBrowser( new URI( uri_str ), "_aptx_seq" );
                 }
                 catch ( final IOException e ) {
                     AptxUtil.showErrorMessage( this, e.toString() );
@@ -2027,9 +2009,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         final String uri_str = TreePanelUtil.createUriForSeqWeb( node, getConfiguration(), this );
         if ( !ForesterUtil.isEmpty( uri_str ) ) {
             try {
-                AptxUtil.launchWebBrowser( new URI( uri_str ),
-                                          
-                                           "_aptx_seq" );
+                AptxUtil.launchWebBrowser( new URI( uri_str ), "_aptx_seq" );
             }
             catch ( final IOException e ) {
                 AptxUtil.showErrorMessage( this, e.toString() );
@@ -2108,8 +2088,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
         if ( !ForesterUtil.isEmpty( uri_str ) ) {
             try {
-                AptxUtil.launchWebBrowser( new URI( uri_str ),
-                                           "_aptx_tax" );
+                AptxUtil.launchWebBrowser( new URI( uri_str ), "_aptx_tax" );
             }
             catch ( final IOException e ) {
                 AptxUtil.showErrorMessage( this, e.toString() );
@@ -2587,11 +2566,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                                   ( node.getYcoord() - getFontMetricsForLargeDefaultFont().getMaxDescent() ),
                                   g );
             g.setColor( getTreeColorSet().getLostCharactersColor() );
-            TreePanel.drawString( lost,
-                                  parent_x + ( ( x - parent_x
-                                          - getFontMetricsForLargeDefaultFont().stringWidth( lost ) ) / 2 ),
-                                  ( node.getYcoord() + getFontMetricsForLargeDefaultFont().getMaxAscent() ),
-                                  g );
+            TreePanel
+                    .drawString( lost,
+                                 parent_x + ( ( x - parent_x - getFontMetricsForLargeDefaultFont().stringWidth( lost ) )
+                                         / 2 ),
+                                 ( node.getYcoord() + getFontMetricsForLargeDefaultFont().getMaxAscent() ),
+                                 g );
         }
     }
 
@@ -2652,14 +2632,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 || ( getOptions().isShowDefaultNodeShapesForMarkedNodes()
                         && ( node.getNodeData().getNodeVisualData() != null )
                         && ( !node.getNodeData().getNodeVisualData().isEmpty() ) )
-                || ( 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().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()
@@ -2843,6 +2820,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         if ( !getControlPanel().isShowInternalData() && !node.isExternal() && !node.isCollapse() ) {
             return 0;
         }
+        if ( !getControlPanel().isShowExternalData() && ( node.isExternal() || node.isCollapse() ) ) {
+            return 0;
+        }
         _sb.setLength( 0 );
         int x = 0;
         if ( add > 0 ) {
@@ -2904,9 +2884,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             }
             else if ( ( _sb.length() > 0 ) || saw_species ) {
                 //  _sb.setLength( 0 );
-                _sb.append( " (" );
+                _sb.append( " [" );
                 _sb.append( node.getAllExternalDescendants().size() );
-                _sb.append( ")" );
+                _sb.append( "]" );
             }
         }
         else {
@@ -2919,7 +2899,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             down_shift_factor = 1;
         }
         float pos_x;
-        if ( getControlPanel().getTreeDisplayType() == TreeDisplayType.ALIGNED_PHYLOGRAM
+        if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
                 && ( node.isExternal() || node.isCollapse() ) ) {
             pos_x = ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
                     + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x + ( 2 * TreePanel.MOVE ) + getXdistance()
@@ -2935,7 +2915,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         else {
             pos_y = ( node.getYcoord() + ( getFontMetrics( g.getFont() ).getAscent() / down_shift_factor ) );
         }
-        if ( getControlPanel().getTreeDisplayType() == TreeDisplayType.ALIGNED_PHYLOGRAM
+        if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
                 && ( node.isExternal() || node.isCollapse() ) ) {
             drawConnection( node.getXcoord(), pos_x - x, node.getYcoord(), 5, 20, g, to_pdf );
             if ( node.isCollapse() ) {
@@ -3307,7 +3287,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         if ( !node.isExternal() && !node.isCollapse() ) {
             boolean first_child = true;
             float y2 = 0.0f;
-            final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
+            //final int parent_max_branch_to_leaf = getMaxBranchesToLeaf( node );
             for( int i = 0; i < node.getNumberOfDescendants(); ++i ) {
                 final PhylogenyNode child_node = node.getChildNode( i );
                 final int factor_x = node.getNumberOfExternalNodes() - child_node.getNumberOfExternalNodes();
@@ -3419,8 +3399,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 && ( !ForesterUtil.isEmpty( node.getNodeData().getSequence().getMolecularSequence() ) ) ) {
             paintMolecularSequences( g, node, to_pdf );
         }
-        if ( dynamically_hide && !is_in_found_nodes && ( ( node.isExternal()
-                && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) )
+        if ( dynamically_hide && ( ( node.isExternal() && ( ( _external_node_index % dynamic_hiding_factor ) != 1 ) )
                 || ( !node.isExternal() && ( ( new_x_min < 20 )
                         || ( ( _y_distance * node.getNumberOfExternalNodes() ) < getFontMetricsForLargeDefaultFont()
                                 .getHeight() ) ) ) ) ) {
@@ -3441,6 +3420,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         if ( ( !getControlPanel().isShowInternalData() && !node.isExternal() ) ) {
             return;
         }
+        if ( ( !getControlPanel().isShowExternalData() && node.isExternal() ) ) {
+            return;
+        }
         if ( getControlPanel().isShowDomainArchitectures() && node.getNodeData().isHasSequence()
                 && ( node.getNodeData().getSequence().getDomainArchitecture() != null ) && ( node.getNodeData()
                         .getSequence().getDomainArchitecture() instanceof RenderableDomainArchitecture ) ) {
@@ -3642,7 +3624,8 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         final boolean using_visual_font = setFont( g, node, is_in_found_nodes );
         setColor( g, node, to_graphics_file, to_pdf, is_in_found_nodes, getTreeColorSet().getTaxonomyColor() );
         float start_x = node.getXcoord() + 3 + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift;
-        if ( getControlPanel().getTreeDisplayType() == TreeDisplayType.ALIGNED_PHYLOGRAM && node.isExternal() ) {
+        if ( getControlPanel().getTreeDisplayType() == Options.PHYLOGENY_DISPLAY_TYPE.ALIGNED_PHYLOGRAM
+                && node.isExternal() ) {
             start_x = ( float ) ( ( getMaxDistanceToRoot() * getXcorrectionFactor() )
                     + ( getOptions().getDefaultNodeShapeSize() / 2 ) + x_shift + ( 2 * TreePanel.MOVE ) + getXdistance()
                     + 3 );
@@ -3882,25 +3865,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
     }
 
     private final StringBuffer propertiesToString( final PhylogenyNode node ) {
-        final PropertiesMap properties = node.getNodeData().getProperties();
-        final StringBuffer sb = new StringBuffer();
-        boolean first = true;
-        for( final String ref : properties.getPropertyRefs() ) {
-            if ( first ) {
-                first = false;
-            }
-            else {
-                sb.append( " " );
-            }
-            final Property p = properties.getProperty( ref );
-            sb.append( TreePanelUtil.getPartAfterColon( p.getRef() ) );
-            sb.append( "=" );
-            sb.append( p.getValue() );
-            if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
-                sb.append( TreePanelUtil.getPartAfterColon( p.getUnit() ) );
-            }
-        }
-        return sb;
+        return node.getNodeData().getProperties().asText();
     }
 
     private void setColor( final Graphics2D g,
@@ -4260,9 +4225,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                             + ", unique entries: " + size;
                 }
                 final String s = sb.toString().trim();
-               
-                    getMainPanel().getMainFrame().showTextFrame( s, title );
-                
+                getMainPanel().getMainFrame().showTextFrame( s, title );
             }
         }
     }
@@ -4453,17 +4416,10 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                     }
                 }
                 if ( node.getNodeData().isHasProperties() ) {
-                    final PropertiesMap properties = node.getNodeData().getProperties();
-                    for( final String ref : properties.getPropertyRefs() ) {
+                    if ( _popup_buffer.length() > 0 ) {
                         _popup_buffer.append( "\n" );
-                        final Property p = properties.getProperty( ref );
-                        _popup_buffer.append( TreePanelUtil.getPartAfterColon( p.getRef() ) );
-                        _popup_buffer.append( "=" );
-                        _popup_buffer.append( p.getValue() );
-                        if ( !ForesterUtil.isEmpty( p.getUnit() ) ) {
-                            _popup_buffer.append( TreePanelUtil.getPartAfterColon( p.getUnit() ) );
-                        }
                     }
+                    _popup_buffer.append( node.getNodeData().getProperties().asText() );
                 }
                 if ( _popup_buffer.length() > 0 ) {
                     if ( !getConfiguration().isUseNativeUI() ) {
@@ -4574,9 +4530,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         else {
             getControlPanel().setDrawPhylogramEnabled( false );
         }
-       
-            getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
-        
+        getMainPanel().getMainFrame().setSelectedTypeInTypeMenu( getPhylogenyGraphicsType() );
     }
 
     final void calcMaxDepth() {
@@ -4859,67 +4813,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         }
     }
 
-    void checkForVectorProperties( final Phylogeny phy ) {
-        final DescriptiveStatistics stats = new BasicDescriptiveStatistics();
-        for( final PhylogenyNodeIterator iter = phy.iteratorPreorder(); iter.hasNext(); ) {
-            final PhylogenyNode node = iter.next();
-            if ( node.getNodeData().getProperties() != null ) {
-                final PropertiesMap pm = node.getNodeData().getProperties();
-                final double[] vector = new double[ pm.getProperties().size() ];
-                int counter = 0;
-                for( final String ref : pm.getProperties().keySet() ) {
-                    if ( ref.startsWith( PhyloXmlUtil.VECTOR_PROPERTY_REF ) ) {
-                        final Property p = pm.getProperty( ref );
-                        final String value_str = p.getValue();
-                        final String index_str = ref.substring( PhyloXmlUtil.VECTOR_PROPERTY_REF.length(),
-                                                                ref.length() );
-                        double d = -100;
-                        try {
-                            d = Double.parseDouble( value_str );
-                        }
-                        catch ( final NumberFormatException e ) {
-                            JOptionPane.showMessageDialog( this,
-                                                           "Could not parse \"" + value_str + "\" into a decimal value",
-                                                           "Problem with Vector Data",
-                                                           JOptionPane.ERROR_MESSAGE );
-                            return;
-                        }
-                        int i = -1;
-                        try {
-                            i = Integer.parseInt( index_str );
-                        }
-                        catch ( final NumberFormatException e ) {
-                            JOptionPane.showMessageDialog( this,
-                                                           "Could not parse \"" + index_str
-                                                                   + "\" into index for vector data",
-                                                           "Problem with Vector Data",
-                                                           JOptionPane.ERROR_MESSAGE );
-                            return;
-                        }
-                        if ( i < 0 ) {
-                            JOptionPane.showMessageDialog( this,
-                                                           "Attempt to use negative index for vector data",
-                                                           "Problem with Vector Data",
-                                                           JOptionPane.ERROR_MESSAGE );
-                            return;
-                        }
-                        vector[ i ] = d;
-                        ++counter;
-                        stats.addValue( d );
-                    }
-                }
-                final List<Double> vector_l = new ArrayList<Double>( counter );
-                for( int i = 0; i < counter; ++i ) {
-                    vector_l.add( vector[ i ] );
-                }
-                node.getNodeData().setVector( vector_l );
-            }
-        }
-        if ( stats.getN() > 0 ) {
-            _statistics_for_vector_data = stats;
-        }
-    }
-
     void clearCurrentExternalNodesDataBuffer() {
         setCurrentExternalNodesDataBuffer( new StringBuilder() );
     }
@@ -5283,8 +5176,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 && ( e.getY() <= ( getOvRectangle().getY() + getOvRectangle().getHeight() + 1 ) ) );
     }
 
-    
-
     final boolean isCanCollapse() {
         return ( getPhylogenyGraphicsType() != PHYLOGENY_GRAPHICS_TYPE.UNROOTED );
     }
@@ -5586,8 +5477,6 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         _urt_factor *= f;
     }
 
-  
-
     final void paintBranchCircular( final PhylogenyNode p,
                                     final PhylogenyNode c,
                                     final Graphics2D g,
@@ -5794,10 +5683,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 }
             }
             final boolean disallow_shortcutting = ( dynamic_hiding_factor < 40 )
-                    || getControlPanel().isUseVisualStyles() || getOptions().isShowDefaultNodeShapesForMarkedNodes()
-                    || ( ( getFoundNodes0() != null ) && !getFoundNodes0().isEmpty() )
-                    || ( ( getFoundNodes1() != null ) && !getFoundNodes1().isEmpty() )
-                    || ( ( getCurrentExternalNodes() != null ) && !getCurrentExternalNodes().isEmpty() )
+                    /* || getControlPanel().isUseVisualStyles() || getOptions().isShowDefaultNodeShapesForMarkedNodes()*/ //TODO check if this is really not needed.
                     || to_graphics_file || to_pdf;
             for( final PhylogenyNode element : _nodes_in_preorder ) {
                 paintNodeRectangular( g,