JAL-3490 revised layout and search algorithm (more tests to be added)
[jalview.git] / src / jalview / gui / Finder.java
index a4d7ad0..217a390 100755 (executable)
@@ -28,9 +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;
@@ -65,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;
 
@@ -82,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);
@@ -122,6 +106,7 @@ public class Finder extends GFinder
               }
             });
     addEscapeHandler();
+
     Desktop.addInternalFrame(frame, MessageManager.getString("label.find"),
             MY_WIDTH, MY_HEIGHT);
     frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
@@ -172,13 +157,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)
       {
@@ -198,6 +184,7 @@ public class Finder extends GFinder
       {
         av = ((AlignFrame) alignFrame).viewport;
         ap = ((AlignFrame) alignFrame).alignPanel;
+        ignoreHidden.setEnabled(av.hasHiddenColumns());
         return true;
       }
     }
@@ -274,13 +261,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();
@@ -388,4 +378,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);
+  }
 }