From ca87cef11606dd9b1ba66222cea87e000e556817 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 12 Mar 2018 15:06:34 +0000 Subject: [PATCH] JAL-2933 remember Find position per viewport --- src/jalview/appletgui/Finder.java | 106 ++++++++++++++++++++++--------------- src/jalview/gui/Finder.java | 46 +++++++++++++--- 2 files changed, 102 insertions(+), 50 deletions(-) diff --git a/src/jalview/appletgui/Finder.java b/src/jalview/appletgui/Finder.java index ee0d4a0..f44387f 100644 --- a/src/jalview/appletgui/Finder.java +++ b/src/jalview/appletgui/Finder.java @@ -20,12 +20,12 @@ */ package jalview.appletgui; +import jalview.api.AlignViewportI; import jalview.datamodel.SearchResultMatchI; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceI; import jalview.util.MessageManager; -import jalview.viewmodel.AlignmentViewport; import java.awt.Button; import java.awt.Checkbox; @@ -42,25 +42,48 @@ import java.awt.event.KeyEvent; import java.awt.event.WindowAdapter; import java.awt.event.WindowEvent; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Vector; public class Finder extends Panel implements ActionListener { - AlignmentViewport av; + private AlignViewportI av; - AlignmentPanel ap; + private AlignmentPanel ap; - Frame frame; + private TextField textfield = new TextField(); - SearchResultsI searchResults; + private Button findAll = new Button(); - int seqIndex = 0; + private Button findNext = new Button(); - int resIndex = -1; + private Button createFeatures = new Button(); + + private Checkbox caseSensitive = new Checkbox(); + + private Checkbox searchDescription = new Checkbox(); + + private SearchResultsI searchResults; + + /* + * sequence index and residue position of last match, + * for current search and per viewport + */ + private int seqIndex = 0; + + private int resIndex = -1; + + Map seqIndices; + + Map resIndices; public Finder(final AlignmentPanel ap) { + seqIndices = new HashMap<>(); + resIndices = new HashMap<>(); + try { jbInit(); @@ -72,7 +95,7 @@ public class Finder extends Panel implements ActionListener this.av = ap.av; this.ap = ap; - frame = new Frame(); + Frame frame = new Frame(); frame.add(this); jalview.bin.JalviewLite.addFrame(frame, MessageManager.getString("action.find"), 340, 120); @@ -107,13 +130,13 @@ public class Finder extends Panel implements ActionListener seqIndex = 0; doSearch(true); } - else if (evt.getSource() == createNewGroup) + else if (evt.getSource() == createFeatures) { - createNewGroup_actionPerformed(); + createFeatures_actionPerformed(); } } - public void createNewGroup_actionPerformed() + public void createFeatures_actionPerformed() { List seqs = new ArrayList<>(); List features = new ArrayList<>(); @@ -135,26 +158,40 @@ public class Finder extends Panel implements ActionListener } } - void doSearch(boolean findAll) + void doSearch(boolean doFindAll) { if (ap.av.applet.currentAlignFrame != null) { ap = ap.av.applet.currentAlignFrame.alignPanel; av = ap.av; + seqIndex = 0; + resIndex = -1; + if (seqIndices.containsKey(av)) + { + seqIndex = seqIndices.get(av).intValue(); + } + if (resIndices.containsKey(av)) + { + resIndex = resIndices.get(av).intValue(); + } } - createNewGroup.setEnabled(false); + createFeatures.setEnabled(false); jalview.analysis.Finder finder = new jalview.analysis.Finder( av.getAlignment(), av.getSelectionGroup(), seqIndex, resIndex); finder.setCaseSensitive(caseSensitive.getState()); finder.setIncludeDescription(searchDescription.getState()); - finder.setFindAll(findAll); + finder.setFindAll(doFindAll); String searchString = textfield.getText(); finder.find(searchString); + seqIndex = finder.getSeqIndex(); resIndex = finder.getResIndex(); + seqIndices.put(av, seqIndex); + resIndices.put(av, resIndex); searchResults = finder.getSearchResults(); + Vector idMatch = finder.getIdMatch(); ap.idPanel.highlightSearchResults(idMatch); @@ -164,7 +201,7 @@ public class Finder extends Panel implements ActionListener } else { - createNewGroup.setEnabled(true); + createFeatures.setEnabled(true); } // if allResults is null, this effectively switches displaySearch flag in @@ -181,7 +218,7 @@ public class Finder extends Panel implements ActionListener } else { - if (findAll) + if (doFindAll) { String message = (idMatch.size() > 0) ? "" + idMatch.size() + " IDs" : ""; @@ -209,28 +246,10 @@ public class Finder extends Panel implements ActionListener } } - Label jLabel1 = new Label(); - - protected TextField textfield = new TextField(); - - protected Button findAll = new Button(); - - protected Button findNext = new Button(); - - Panel actionsPanel = new Panel(); - - GridLayout gridLayout1 = new GridLayout(); - - protected Button createNewGroup = new Button(); - - Checkbox caseSensitive = new Checkbox(); - - Checkbox searchDescription = new Checkbox(); - private void jbInit() throws Exception { + Label jLabel1 = new Label(MessageManager.getString("action.find")); jLabel1.setFont(new java.awt.Font("Verdana", 0, 12)); - jLabel1.setText(MessageManager.getString("action.find")); jLabel1.setBounds(new Rectangle(3, 30, 34, 15)); this.setLayout(null); textfield.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); @@ -241,7 +260,7 @@ public class Finder extends Panel implements ActionListener @Override public void keyTyped(KeyEvent e) { - textfield_keyTyped(e); + textfield_keyTyped(); } }); textfield.addActionListener(this); @@ -252,15 +271,18 @@ public class Finder extends Panel implements ActionListener findNext.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); findNext.setLabel(MessageManager.getString("action.find_next")); findNext.addActionListener(this); + + Panel actionsPanel = new Panel(); actionsPanel.setBounds(new Rectangle(195, 5, 141, 64)); + GridLayout gridLayout1 = new GridLayout(); actionsPanel.setLayout(gridLayout1); gridLayout1.setHgap(0); gridLayout1.setRows(3); gridLayout1.setVgap(2); - createNewGroup.setEnabled(false); - createNewGroup.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); - createNewGroup.setLabel(MessageManager.getString("label.new_feature")); - createNewGroup.addActionListener(this); + createFeatures.setEnabled(false); + createFeatures.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10)); + createFeatures.setLabel(MessageManager.getString("label.new_feature")); + createFeatures.addActionListener(this); caseSensitive.setLabel(MessageManager.getString("label.match_case")); caseSensitive.setBounds(new Rectangle(30, 39, 126, 23)); @@ -269,7 +291,7 @@ public class Finder extends Panel implements ActionListener searchDescription.setBounds(new Rectangle(30, 59, 170, 23)); actionsPanel.add(findNext, null); actionsPanel.add(findAll, null); - actionsPanel.add(createNewGroup, null); + actionsPanel.add(createFeatures, null); this.add(caseSensitive); this.add(textfield, null); this.add(jLabel1, null); @@ -277,7 +299,7 @@ public class Finder extends Panel implements ActionListener this.add(searchDescription); } - void textfield_keyTyped(KeyEvent e) + void textfield_keyTyped() { findNext.setEnabled(true); } diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index e5093d4..1cbe6ab 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -20,6 +20,7 @@ */ package jalview.gui; +import jalview.api.AlignViewportI; import jalview.datamodel.SearchResultMatchI; import jalview.datamodel.SearchResultsI; import jalview.datamodel.SequenceFeature; @@ -32,7 +33,9 @@ import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.util.ArrayList; +import java.util.HashMap; import java.util.List; +import java.util.Map; import java.util.Vector; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -57,25 +60,33 @@ import javax.swing.event.InternalFrameEvent; */ public class Finder extends GFinder { + private static final int MIN_WIDTH = 350; + + private static final int MIN_HEIGHT = 120; + private static final int MY_HEIGHT = 120; private static final int MY_WIDTH = 400; - AlignmentViewport av; + private AlignViewportI av; - AlignmentPanel ap; + private AlignmentPanel ap; - private static final int MIN_WIDTH = 350; + private JInternalFrame frame; - private static final int MIN_HEIGHT = 120; + /* + * sequence and column position of the last match, + * as currently used, and saved for each viewport + */ + private int seqIndex = 0; - JInternalFrame frame; + private int resIndex = -1; - int seqIndex = 0; + Map seqIndices; - int resIndex = -1; + Map resIndices; - SearchResultsI searchResults; + private SearchResultsI searchResults; /** * Creates a new Finder object with no associated viewport or panel. @@ -97,6 +108,8 @@ public class Finder extends GFinder { av = viewport; ap = alignPanel; + seqIndices = new HashMap<>(); + resIndices = new HashMap<>(); focusfixed = true; frame = new JInternalFrame(); frame.setContentPane(this); @@ -198,6 +211,21 @@ public class Finder extends GFinder { av = ((AlignFrame) alignFrame).viewport; ap = ((AlignFrame) alignFrame).alignPanel; + + /* + * restore search position if switching to a + * panel where we have previously searched + */ + seqIndex = 0; + resIndex = -1; + if (seqIndices.containsKey(av)) + { + seqIndex = seqIndices.get(av).intValue(); + } + if (resIndices.containsKey(av)) + { + resIndex = resIndices.get(av).intValue(); + } return true; } } @@ -273,6 +301,8 @@ public class Finder extends GFinder seqIndex = finder.getSeqIndex(); resIndex = finder.getResIndex(); + seqIndices.put(av, seqIndex); + resIndices.put(av, resIndex); searchResults = finder.getSearchResults(); Vector idMatch = finder.getIdMatch(); -- 1.7.10.2