JAL-4190 - escape clears selected nodes
authorJames Procter <j.procter@dundee.ac.uk>
Mon, 29 May 2023 17:05:51 +0000 (18:05 +0100)
committerJames Procter <j.procter@dundee.ac.uk>
Mon, 29 May 2023 17:05:51 +0000 (18:05 +0100)
src/jalview/gui/TreeCanvas.java
src/jalview/gui/TreePanel.java

index 425f710..c1a6b0a 100755 (executable)
@@ -143,9 +143,43 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
     scrollPane = scroller;
     addMouseListener(this);
     addMouseMotionListener(this);
+    
     ToolTipManager.sharedInstance().registerComponent(this);
   }
 
+  public void clearSelectedLeaves()
+  {
+    Vector<BinaryNode> leaves = tp.getTree()
+            .findLeaves(tp.getTree().getTopNode());
+    if (tp.isColumnWise())
+    {
+      markColumnsFor(getAssociatedPanels(), leaves, Color.white, true);
+    }
+    else
+    {
+      for (AlignmentPanel ap : getAssociatedPanels())
+      {
+        SequenceGroup selected = ap.av.getSelectionGroup();
+        if (selected != null)
+        {
+          {
+            for (int i = 0; i < leaves.size(); i++)
+            {
+              SequenceI seq = (SequenceI) leaves.elementAt(i).element();
+              if (selected.contains(seq))
+              {
+                selected.addOrRemove(seq, false);
+              }
+            }
+            selected.recalcConservation();
+          }
+        }
+        ap.av.sendSelection();
+      }
+    }
+    PaintRefresher.Refresh(tp, av.getSequenceSetId());
+    repaint();
+  }
   /**
    * DOCUMENT ME!
    * 
@@ -830,7 +864,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
       Vector<BinaryNode> leaves = tree.findLeaves(highlightNode);
       if (tp.isColumnWise())
       {
-        markColumnsFor(getAssociatedPanels(), leaves, Color.red);
+        markColumnsFor(getAssociatedPanels(), leaves, Color.red,false);
       }
       else
       {
@@ -1172,7 +1206,7 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
   }
 
   private void markColumnsFor(AlignmentPanel[] aps, Vector<BinaryNode> l,
-          Color col)
+          Color col, boolean clearSelected)
   {
     SequenceI rseq = tp.assocAnnotation.sequenceRef;
     if (av == null || av.getAlignment() == null)
@@ -1219,15 +1253,15 @@ public class TreeCanvas extends JPanel implements MouseListener, Runnable,
         offp = (rseq != null) ? rseq.findIndex(rseq.getStart() + colm)
                 : colm;
       }
-      if (!av.hasHiddenColumns() || hc.isVisible(offp - 1))
+      if (!av.hasHiddenColumns() || hc.isVisible(offp))
       {
-        if (cs.contains(offp - 1))
+        if (clearSelected || cs.contains(offp))
         {
-          cs.removeElement(offp - 1);
+          cs.removeElement(offp);
         }
         else
         {
-          cs.addElement(offp - 1);
+          cs.addElement(offp);
         }
       }
     }
index 0e1fd42..4737235 100755 (executable)
@@ -24,6 +24,8 @@ import java.awt.Font;
 import java.awt.Graphics;
 import java.awt.event.ActionEvent;
 import java.awt.event.ActionListener;
+import java.awt.event.KeyAdapter;
+import java.awt.event.KeyEvent;
 import java.beans.PropertyChangeEvent;
 import java.beans.PropertyChangeListener;
 import java.io.File;
@@ -188,6 +190,22 @@ public class TreePanel extends GTreePanel
     treeCanvas = new TreeCanvas(this, ap, scrollPane);
     scrollPane.setViewportView(treeCanvas);
 
+    addKeyListener(new KeyAdapter()
+    {
+      @Override
+      public void keyPressed(KeyEvent e)
+      {
+        switch (e.getKeyCode())
+        { 
+        case 27: // escape
+          treeCanvas.clearSelectedLeaves();
+          e.consume();
+          break;
+          
+        }
+        
+      }
+    });
     PaintRefresher.Register(this, ap.av.getSequenceSetId());
 
     buildAssociatedViewMenu();