JAL-3490 merged with 2.11.2 develop
[jalview.git] / src / jalview / gui / Finder.java
index a1693f7..d328452 100755 (executable)
@@ -28,8 +28,9 @@ import jalview.datamodel.SequenceFeature;
 import jalview.datamodel.SequenceI;
 import jalview.jbgui.GFinder;
 import jalview.util.MessageManager;
-import jalview.viewmodel.AlignmentViewport;
 
+import java.awt.Dimension;
+import java.awt.Graphics;
 import java.awt.event.ActionEvent;
 import java.awt.event.KeyEvent;
 import java.util.ArrayList;
@@ -64,7 +65,7 @@ public class Finder extends GFinder
 
   private static final int MIN_HEIGHT = 120;
 
-  private static final int MY_HEIGHT = 120;
+  private static final int MY_HEIGHT = 150;
 
   private static final int MY_WIDTH = 400;
 
@@ -81,33 +82,17 @@ public class Finder extends GFinder
 
   private SearchResultsI searchResults;
 
-  /*
-   * true if we only search a given alignment view
-   */
-  private boolean focusfixed;
-
-  /**
-   * Creates a new Finder object with no associated viewport or panel. Each Find
-   * or Find Next action will act on whichever viewport has focus at the time.
-   */
-  public Finder()
-  {
-    this(null, null);
-  }
-
   /**
-   * Constructor given an associated viewport and alignment panel. Constructs
-   * and displays an internal frame where the user can enter a search string.
+   * Constructor given an associated alignment panel. Constructs and displays an
+   * internal frame where the user can enter a search string.
    * 
-   * @param viewport
    * @param alignPanel
    */
-  public Finder(AlignmentViewport viewport, AlignmentPanel alignPanel)
+  public Finder(AlignmentPanel alignPanel)
   {
-    av = viewport;
+    av = alignPanel.getAlignViewport();
     ap = alignPanel;
     finders = new HashMap<>();
-    focusfixed = viewport != null;
     frame = new JInternalFrame();
     frame.setContentPane(this);
     frame.setLayer(JLayeredPane.PALETTE_LAYER);
@@ -121,6 +106,7 @@ public class Finder extends GFinder
               }
             });
     addEscapeHandler();
+
     Desktop.addInternalFrame(frame, MessageManager.getString("label.find"),
             true, MY_WIDTH, MY_HEIGHT, true, true);
     searchBox.getComponent().requestFocus();
@@ -170,13 +156,14 @@ public class Finder extends GFinder
   /**
    * if !focusfixed and not in a desktop environment, checks that av and ap are
    * valid. Otherwise, gets the topmost alignment window and sets av and ap
-   * accordingly
+   * accordingly. Also sets the 'ignore hidden' checkbox disabled if the viewport
+   * has no hidden columns.
    * 
    * @return false if no alignment window was found
    */
   boolean getFocusedViewport()
   {
-    if (focusfixed || Desktop.desktop == null)
+    if (Desktop.desktop == null)
     {
       if (ap != null && av != null)
       {
@@ -196,6 +183,7 @@ public class Finder extends GFinder
       {
         av = ((AlignFrame) alignFrame).viewport;
         ap = ((AlignFrame) alignFrame).alignPanel;
+        ignoreHidden.setEnabled(av.hasHiddenColumns());
         return true;
       }
     }
@@ -265,13 +253,16 @@ public class Finder extends GFinder
 
     boolean isCaseSensitive = caseSensitive.isSelected();
     boolean doSearchDescription = searchDescription.isSelected();
+    boolean skipHidden = ignoreHidden.isSelected();
     if (doFindAll)
     {
-      finder.findAll(searchString, isCaseSensitive, doSearchDescription);
+      finder.findAll(searchString, isCaseSensitive, doSearchDescription,
+              skipHidden);
     }
     else
     {
-      finder.findNext(searchString, isCaseSensitive, doSearchDescription);
+      finder.findNext(searchString, isCaseSensitive, doSearchDescription,
+              skipHidden);
     }
 
     searchResults = finder.getSearchResults();
@@ -307,11 +298,11 @@ public class Finder extends GFinder
                 : "";
         if (searchResults != null)
         {
-          if (idMatch.size() > 0 && searchResults.getSize() > 0)
+          if (idMatch.size() > 0 && searchResults.getCount() > 0)
           {
             message += " and ";
           }
-          message += searchResults.getSize()
+          message += searchResults.getCount()
                   + " subsequence matches found.";
         }
         JvOptionPane.showInternalMessageDialog(this, message, null,
@@ -380,4 +371,15 @@ public class Finder extends GFinder
       ap.alignFrame.requestFocus();
     }
   }
+
+  @Override
+  protected void paintComponent(Graphics g)
+  {
+    /*
+     * enable 'hidden regions' option only if
+     * 'top' viewport has hidden columns
+     */
+    getFocusedViewport();
+    super.paintComponent(g);
+  }
 }