JAL-2844 work started on moving the graphical partitioning code to Aptx
[jalview.git] / forester / java / src / org / forester / archaeopteryx / TreePanel.java
index 048c9a3..3b3977d 100644 (file)
@@ -258,11 +258,12 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                                                                                                                         2.0f },
                                                                                                                 0f );
     private static final double           TWO_PI                                             = 2 * Math.PI;
-    private final static int              WIGGLE                                             = 2;
+    private final static int              WIGGLE                                             = 3;
     private static final String           SHOW_ONLY_THIS_CONF_TYPE                           = null;                                                     //TODO remove me
     HashMap<Long, Short>                  _nodeid_dist_to_leaf                               = new HashMap<Long, Short>();
     final private Arc2D                   _arc                                               = new Arc2D.Double();
     private AffineTransform               _at;
+    private int                             _clicked_x;
     private int                           _circ_max_depth;
     final private Set<Long>               _collapsed_external_nodeid_set                     = new HashSet<Long>();
     private JColorChooser                 _color_chooser                                     = null;
@@ -283,6 +284,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
     private final FontRenderContext       _frc                                               = new FontRenderContext( null,
                                                                                                                       false,
                                                                                                                       false );
+    private float                           _furthest_node_x;
     private PHYLOGENY_GRAPHICS_TYPE       _graphics_type                                     = PHYLOGENY_GRAPHICS_TYPE.RECTANGULAR;
     private PhylogenyNode                 _highlight_node                                    = null;
     private boolean                       _in_ov                                             = false;
@@ -312,6 +314,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
     private float                         _ov_y_distance                                     = 0;
     private int                           _ov_y_position                                     = 0;
     private int                           _ov_y_start                                        = 0;
+    private boolean                     _partition_tree                                     = false;
     private final boolean                 _phy_has_branch_lengths;
     private Phylogeny                     _phylogeny                                         = null;
     private final Path2D.Float            _polygon                                           = new Path2D.Float();
@@ -323,6 +326,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                                                                                                                    RenderingHints.VALUE_RENDER_DEFAULT );
     private JTextArea                     _rollover_popup;
     private PhylogenyNode                 _root;
+    private float                           _root_x;
     private final StringBuilder           _sb                                                = new StringBuilder();
     private double                        _scale_distance                                    = 0.0;
     private String                        _scale_label                                       = null;
@@ -345,6 +349,9 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
     private Map<String, AttributedString> _attributed_string_map                             = null;
     private int                           _depth_collapse_level                              = -1;
     private int                           _rank_collapse_level                               = -1;
+
+
+
     static {
         final DecimalFormatSymbols dfs = new DecimalFormatSymbols();
         dfs.setDecimalSeparator( '.' );
@@ -4720,7 +4727,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
             }
             boolean use_vis = false;
             final Graphics2D g = ( Graphics2D ) getGraphics();
-            if ( getControlPanel().isUseVisualStyles() ) {
+            if ( g != null && getControlPanel().isUseVisualStyles() ) {
                 use_vis = setFont( g, node, false );
             }
             if ( !use_vis ) {
@@ -5025,7 +5032,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
      * @param y
      * @return pointer to the node at x,y, null if not found
      */
-    final PhylogenyNode findNode( final int x, final int y ) {
+    public final PhylogenyNode findNode( final int x, final int y ) {
         if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
             return null;
         }
@@ -5063,15 +5070,15 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         return _domain_structure_e_value_thr_exp;
     }
 
-    final Set<Long> getFoundNodes0() {
+    public final Set<Long> getFoundNodes0() {
         return _found_nodes_0;
     }
 
-    final Set<Long> getFoundNodes1() {
+    public final Set<Long> getFoundNodes1() {
         return _found_nodes_1;
     }
 
-    List<PhylogenyNode> getFoundNodesAsListOfPhylogenyNodes() {
+    public List<PhylogenyNode> getFoundNodesAsListOfPhylogenyNodes() {
         final List<PhylogenyNode> additional_nodes = new ArrayList<PhylogenyNode>();
         if ( getFoundNodes0() != null ) {
             for( final Long id : getFoundNodes0() ) {
@@ -5150,7 +5157,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         return getTreeColorSet().getTaxonomyColor();
     }
 
-    final File getTreeFile() {
+    public final File getTreeFile() {
         return _treefile;
     }
 
@@ -5383,10 +5390,28 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                 }
             }
             else {
-                // no node was clicked
+                // no node was clicked so partition tree instead
                 _highlight_node = null;
-            }
+                
+                _clicked_x = e.getX();
+                if (!getPhylogeny().isEmpty()) {
+                // should be calculated on each partition as the tree can theoretically
+                // change in the meantime
+                PhylogenyNode furthestNode = PhylogenyMethods.calculateNodeWithMaxDistanceToRoot( _phylogeny );
+                _furthest_node_x = furthestNode.getXcoord();
+                _root_x = _phylogeny.getRoot().getXcoord();
+                
+                // don't bother if 0 distance tree or clicked x lies outside of tree
+                if (_furthest_node_x != _root_x && !(_clicked_x < _root_x || _clicked_x > _furthest_node_x)) 
+                {
+                    _partition_tree = true;
+
+                }
+
+
         }
+                }
+            }
         repaint();
     }
 
@@ -5659,6 +5684,13 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
                                final int graphics_file_height,
                                final int graphics_file_x,
                                final int graphics_file_y ) {
+        if (_partition_tree) {
+//            float threshold = (_clicked_x - _root_x) / (_furthest_node_x - _root_x);
+//            drawLine( _clicked_x, 0, _clicked_x, getHeight(),g);
+            
+            _partition_tree = false;
+        }
+        
         if ( ( _phylogeny == null ) || _phylogeny.isEmpty() ) {
             return;
         }
@@ -5989,11 +6021,11 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         _current_external_nodes_data_buffer = sb;
     }
 
-    final void setFoundNodes0( final Set<Long> found_nodes ) {
+    public final void setFoundNodes0( final Set<Long> found_nodes ) {
         _found_nodes_0 = found_nodes;
     }
 
-    final void setFoundNodes1( final Set<Long> found_nodes ) {
+    public final void setFoundNodes1( final Set<Long> found_nodes ) {
         _found_nodes_1 = found_nodes;
     }
 
@@ -6074,7 +6106,7 @@ public final class TreePanel extends JPanel implements ActionListener, MouseWhee
         getTreeFontSet().tinyFonts();
     }
 
-    final void setTreeFile( final File treefile ) {
+    public final void setTreeFile( final File treefile ) {
         _treefile = treefile;
     }