X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FFinder.java;h=2bad00626ed1e0c10fea28ed95c8f77eeea3a8f4;hb=7fb89dadbc3eac97602fc84e519014582abe4649;hp=81de48fb2fe956d16ccd7d0e7801776defb3cdf9;hpb=b9d3d1f71c6a8aee09cd23e1303b062cbe43a239;p=jalview.git diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index 81de48f..2bad006 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -28,7 +28,6 @@ import jalview.jbgui.GFinder; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; -import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.KeyEvent; import java.util.ArrayList; @@ -42,6 +41,7 @@ import javax.swing.JComponent; import javax.swing.JInternalFrame; import javax.swing.JLayeredPane; import javax.swing.KeyStroke; +import javax.swing.event.InternalFrameEvent; /** * Performs the menu option for searching the alignment, for the next or all @@ -100,11 +100,19 @@ public class Finder extends GFinder frame = new JInternalFrame(); frame.setContentPane(this); frame.setLayer(JLayeredPane.PALETTE_LAYER); + frame.addInternalFrameListener( + new javax.swing.event.InternalFrameAdapter() + { + @Override + public void internalFrameClosing(InternalFrameEvent e) + { + closeAction(); + } + }); addEscapeHandler(); Desktop.addInternalFrame(frame, MessageManager.getString("label.find"), - MY_WIDTH, MY_HEIGHT); - frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT)); - textfield.requestFocus(); + true, MY_WIDTH, MY_HEIGHT, true, true); + searchBox.getComponent().requestFocus(); } /** @@ -112,28 +120,19 @@ public class Finder extends GFinder */ private void addEscapeHandler() { - getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put( - KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Cancel"); + getRootPane().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW) + .put(KeyStroke.getKeyStroke(KeyEvent.VK_ESCAPE, 0), "Cancel"); getRootPane().getActionMap().put("Cancel", new AbstractAction() { @Override public void actionPerformed(ActionEvent e) { - escapeActionPerformed(); + closeAction(); } }); } /** - * Close the panel on Escape key press - */ - protected void escapeActionPerformed() - { - setVisible(false); - frame.dispose(); - } - - /** * Performs the 'Find Next' action. * * @param e @@ -204,15 +203,19 @@ public class Finder extends GFinder /** * Opens a dialog that allows the user to create sequence features for the - * find match results. + * find match results */ @Override public void createFeatures_actionPerformed() { + if (searchResults.isEmpty()) + { + return; // shouldn't happen + } List seqs = new ArrayList(); List features = new ArrayList(); - String searchString = textfield.getText().trim(); + String searchString = searchBox.getUserInput(); String desc = "Search Results"; /* @@ -222,22 +225,11 @@ public class Finder extends GFinder for (SearchResultMatchI match : searchResults.getResults()) { seqs.add(match.getSequence().getDatasetSequence()); - features.add(new SequenceFeature(searchString, desc, - match - .getStart(), match.getEnd(), desc)); + features.add(new SequenceFeature(searchString, desc, match.getStart(), + match.getEnd(), desc)); } - if (ap.getSeqPanel().seqCanvas.getFeatureRenderer().amendFeatures(seqs, - features, true, ap)) - { - /* - * ensure feature display is turned on to show the new features, - * and remove them as highlighted regions - */ - ap.alignFrame.showSeqFeatures.setSelected(true); - av.setShowSequenceFeatures(true); - ap.highlightSearchResults(null); - } + new FeatureEditor(ap, seqs, features, true).showDialog(); } /** @@ -250,7 +242,7 @@ public class Finder extends GFinder { createFeatures.setEnabled(false); - String searchString = textfield.getText().trim(); + String searchString = searchBox.getUserInput(); if (isInvalidSearchString(searchString)) { @@ -297,6 +289,8 @@ public class Finder extends GFinder searchResults = null; } + searchBox.updateCache(); + // if allResults is null, this effectively switches displaySearch flag in // seqCanvas ap.highlightSearchResults(searchResults); @@ -304,19 +298,19 @@ public class Finder extends GFinder // 'SelectRegion' selection if (!haveResults) { - JvOptionPane.showInternalMessageDialog(this, - MessageManager.getString("label.finished_searching"), null, - JvOptionPane.INFORMATION_MESSAGE); resIndex = -1; seqIndex = 0; + JvOptionPane.showInternalMessageDialog(this, + MessageManager.getString("label.finished_searching"), null, + JvOptionPane.PLAIN_MESSAGE); } else { if (doFindAll) { // then we report the matches that were found - String message = (idMatch.size() > 0) ? "" + idMatch.size() - + " IDs" : ""; + String message = (idMatch.size() > 0) ? "" + idMatch.size() + " IDs" + : ""; if (searchResults != null) { if (idMatch.size() > 0 && searchResults.getSize() > 0) @@ -326,13 +320,12 @@ public class Finder extends GFinder message += searchResults.getSize() + " subsequence matches found."; } - JvOptionPane.showInternalMessageDialog(this, message, null, - JvOptionPane.INFORMATION_MESSAGE); resIndex = -1; seqIndex = 0; + JvOptionPane.showInternalMessageDialog(this, message, null, + JvOptionPane.PLAIN_MESSAGE); } } - } /** @@ -384,4 +377,15 @@ public class Finder extends GFinder } return error; } + + protected void closeAction() + { + frame.setVisible(false); + frame.dispose(); + searchBox.persistCache(); + if (getFocusedViewport()) + { + ap.alignFrame.requestFocus(); + } + } }