prototype make groups from selection function and shift+ctrl+H to hide everything...
authorjprocter <Jim Procter>
Fri, 21 Aug 2009 11:14:44 +0000 (11:14 +0000)
committerjprocter <Jim Procter>
Fri, 21 Aug 2009 11:14:44 +0000 (11:14 +0000)
src/jalview/gui/AlignFrame.java

index 131e79e..45a0c85 100755 (executable)
@@ -408,8 +408,39 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
           boolean toggleCols = !evt.isShiftDown();
 
           boolean hide = false;
-
           SequenceGroup sg = viewport.getSelectionGroup();
+          // TODO: document ctrl-shift-h for show visible selected area and fix hack so columns for the current selected region get transferred. 
+          if (!toggleSeqs && !toggleCols)
+          {
+            // Hide everything by the current selection - this is a hack - we do the invert and then hide
+            // first check that there will be visible columns after the invert.
+            if ((viewport.colSel!=null && viewport.colSel.getSelected()!=null && viewport.colSel.getSelected().size()>0) || (sg!=null && sg.getSize()>0  && sg.getStartRes()<=sg.getEndRes())) 
+            {
+            // now invert the sequence set, if required - empty selection implies that no hiding is required.
+            if (sg!=null) {
+              invertSequenceMenuItem_actionPerformed(null);
+              sg = viewport.getSelectionGroup();
+              toggleSeqs = true;
+              
+            }
+
+            if (sg!=null && sg.getStartRes()>=0 && sg.getStartRes()<=sg.getEndRes()&& (viewport.colSel==null || viewport.colSel.getSelected()==null || viewport.colSel.getSelected().size()==0))
+            {
+              // synthesize a column selection if none exists. this happens if a single region has been selected rather than whole columns.
+              if (viewport.colSel==null)
+              {
+                viewport.colSel = new ColumnSelection();
+              }
+              for (int cspos = sg.getStartRes(); cspos<=sg.getEndRes(); cspos++) {
+                viewport.colSel.addElement(cspos);
+              }
+            }
+            // finally invert the column selection and get the new sequence selection.
+            invertColSel_actionPerformed(null);
+            toggleCols = true;
+            }
+          }
+
           if (toggleSeqs)
           {
             if (sg != null
@@ -895,9 +926,8 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     {
       if (!jalview.io.AppletFormatAdapter.isValidFormat(format, true))
       {
-        warningMessage("Cannot save file "
-                + fileName + " using format " + format,
-                "Alignment output format not supported");
+        warningMessage("Cannot save file " + fileName + " using format "
+                + format, "Alignment output format not supported");
         saveAs_actionPerformed(null);
         // JBPNote need to have a raise_gui flag here
         return false;
@@ -964,10 +994,13 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   {
     if (new jalview.util.Platform().isHeadless())
     {
-      System.err.println("Warning: "+title+"\nWarning: "+warning);
-      
-    } else {
-      JOptionPane.showInternalMessageDialog(this,warning,title,JOptionPane.WARNING_MESSAGE);
+      System.err.println("Warning: " + title + "\nWarning: " + warning);
+
+    }
+    else
+    {
+      JOptionPane.showInternalMessageDialog(this, warning, title,
+              JOptionPane.WARNING_MESSAGE);
     }
     return;
   }
@@ -4135,9 +4168,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
   }
 
   /**
-   * Attempt to load a "dropped" file or URL string: First by testing whether it's and
-   * Annotation file, then a JNet file, and finally a features file. If all are
-   * false then the user may have dropped an alignment file onto this
+   * Attempt to load a "dropped" file or URL string: First by testing whether
+   * it's and Annotation file, then a JNet file, and finally a features file. If
+   * all are false then the user may have dropped an alignment file onto this
    * AlignFrame.
    * 
    * @param file
@@ -4148,8 +4181,9 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     try
     {
       String protocol = jalview.io.FormatAdapter.FILE;
-      String f=file.toLowerCase();
-      if (f.indexOf("http:") == 0 || f.indexOf("https:")==0 || f.indexOf("file:") == 0)
+      String f = file.toLowerCase();
+      if (f.indexOf("http:") == 0 || f.indexOf("https:") == 0
+              || f.indexOf("file:") == 0)
       {
         protocol = jalview.io.FormatAdapter.URL;
       }
@@ -4427,24 +4461,70 @@ public class AlignFrame extends GAlignFrame implements DropTargetListener,
     alignPanel.paintAlignment(true);
   }
 
-  /* (non-Javadoc)
-   * @see jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event.ActionEvent)
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * jalview.jbgui.GAlignFrame#showGroupConsensus_actionPerformed(java.awt.event
+   * .ActionEvent)
    */
   protected void showGroupConsensus_actionPerformed(ActionEvent e)
   {
     viewport.setShowGroupConsensus(showGroupConsensus.getState());
     alignPanel.updateAnnotation();
-    
+
   }
 
-  /* (non-Javadoc)
-   * @see jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt.event.ActionEvent)
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * jalview.jbgui.GAlignFrame#showGroupConservation_actionPerformed(java.awt
+   * .event.ActionEvent)
    */
   protected void showGroupConservation_actionPerformed(ActionEvent e)
   {
     viewport.setShowGroupConservation(showGroupConservation.getState());
     alignPanel.updateAnnotation();
   }
+
+  /*
+   * (non-Javadoc)
+   * 
+   * @see
+   * jalview.jbgui.GAlignFrame#makeGrpsFromSelection_actionPerformed(java.awt
+   * .event.ActionEvent)
+   */
+  protected void makeGrpsFromSelection_actionPerformed(ActionEvent e)
+  {
+    if (viewport.getSelectionGroup() != null)
+    {
+      SequenceGroup[] gps = jalview.analysis.Grouping.makeGroupsFrom(
+              viewport.getSequenceSelection(), viewport.getAlignmentView(
+                      true).getSequenceStrings(viewport.getGapCharacter()),
+              viewport.alignment.getGroups());
+      viewport.alignment.deleteAllGroups();
+      viewport.sequenceColours = null;
+      viewport.setSelectionGroup(null);
+      // set view properties for each group
+      for (int g = 0; g < gps.length; g++)
+      {
+        gps[g].setShowunconserved(viewport.getShowUnconserved());
+        gps[g].setIncludeAllConsSymbols(viewport.isIncludeAllConsensusSymbols());
+        viewport.alignment.addGroup(gps[g]);
+        Color col = new Color((int) (Math.random() * 255), (int) (Math
+                .random() * 255), (int) (Math.random() * 255));
+        col = col.brighter();
+        for (Enumeration sq = gps[g].getSequences(null).elements(); sq
+                .hasMoreElements(); viewport.setSequenceColour(
+                (SequenceI) sq.nextElement(), col))
+          ;
+      }
+      PaintRefresher.Refresh(this, viewport.getSequenceSetId());
+      alignPanel.updateAnnotation();
+      alignPanel.paintAlignment(true);
+    }
+  }
 }
 
 class PrintThread extends Thread