From daca035ea0a7379b3f5332aceb19bcb41f7038b3 Mon Sep 17 00:00:00 2001 From: Jim Procter Date: Wed, 14 Sep 2022 11:05:32 +0100 Subject: [PATCH] JAL-4061 JAL-4062 button in Find dialog to copy highlighted regions to clipboard --- src/jalview/appletgui/Finder.java | 16 ++++++++-------- src/jalview/gui/Finder.java | 36 ++++++++++++++++++++++++++++++++++-- src/jalview/jbgui/GFinder.java | 33 ++++++++++++++++++++++++++------- 3 files changed, 68 insertions(+), 17 deletions(-) diff --git a/src/jalview/appletgui/Finder.java b/src/jalview/appletgui/Finder.java index 43a12ae..167d899 100644 --- a/src/jalview/appletgui/Finder.java +++ b/src/jalview/appletgui/Finder.java @@ -20,14 +20,6 @@ */ package jalview.appletgui; -import jalview.api.AlignViewportI; -import jalview.api.FinderI; -import jalview.datamodel.SearchResultMatchI; -import jalview.datamodel.SearchResultsI; -import jalview.datamodel.SequenceFeature; -import jalview.datamodel.SequenceI; -import jalview.util.MessageManager; - import java.awt.Button; import java.awt.Checkbox; import java.awt.Font; @@ -47,6 +39,14 @@ import java.util.HashMap; import java.util.List; import java.util.Map; +import jalview.api.AlignViewportI; +import jalview.api.FinderI; +import jalview.datamodel.SearchResultMatchI; +import jalview.datamodel.SearchResultsI; +import jalview.datamodel.SequenceFeature; +import jalview.datamodel.SequenceI; +import jalview.util.MessageManager; + public class Finder extends Panel implements ActionListener { private AlignViewportI av; diff --git a/src/jalview/gui/Finder.java b/src/jalview/gui/Finder.java index 2de06ec..6dacbd8 100755 --- a/src/jalview/gui/Finder.java +++ b/src/jalview/gui/Finder.java @@ -20,8 +20,6 @@ */ package jalview.gui; -import java.util.Locale; - import java.awt.Dimension; import java.awt.event.ActionEvent; import java.awt.event.FocusAdapter; @@ -30,6 +28,7 @@ import java.awt.event.KeyEvent; import java.util.ArrayList; import java.util.HashMap; import java.util.List; +import java.util.Locale; import java.util.Map; import java.util.regex.Pattern; import java.util.regex.PatternSyntaxException; @@ -254,6 +253,37 @@ public class Finder extends GFinder new FeatureEditor(ap, seqs, features, true).showDialog(); } + @Override + protected void copyToClipboard_actionPerformed() + { + if (searchResults.isEmpty()) + { + return; // shouldn't happen + } + List seqs = new ArrayList<>(); + + String searchString = searchBox.getUserInput(); + String desc = "Search Results"; + + /* + * assemble dataset sequences, and template new sequence features, + * for the amend features dialog + */ + for (SearchResultMatchI match : searchResults.getResults()) + { + SequenceI seq = match.getSequence(); + while (seq.getDatasetSequence() != null) + { + seq = seq.getDatasetSequence(); + } + seqs.add(seq.getSubSequence(seq.findIndex(match.getStart()), + seq.findIndex(match.getEnd()) + 1)); + } + Desktop.jalviewClipboard = new Object[] { + seqs.toArray(new SequenceI[0]), ap.av.getAlignment().getDataset(), + ap.av.getAlignment().getHiddenColumns() }; + } + /** * Search the alignment for the next or all matches. If 'all matches', a * dialog is shown with the number of sequence ids and subsequences matched. @@ -263,6 +293,7 @@ public class Finder extends GFinder void doSearch(boolean doFindAll) { createFeatures.setEnabled(false); + copyToClipboard.setEnabled(false); String searchString = searchBox.getUserInput(); @@ -310,6 +341,7 @@ public class Finder extends GFinder else { createFeatures.setEnabled(true); + copyToClipboard.setEnabled(true); } searchBox.updateCache(); diff --git a/src/jalview/jbgui/GFinder.java b/src/jalview/jbgui/GFinder.java index aa79671..9ed2127 100755 --- a/src/jalview/jbgui/GFinder.java +++ b/src/jalview/jbgui/GFinder.java @@ -20,13 +20,6 @@ */ package jalview.jbgui; -import jalview.datamodel.AlignmentI; -import jalview.io.DataSourceType; -import jalview.io.FileFormat; -import jalview.io.FormatAdapter; -import jalview.io.cache.JvCacheableInputBox; -import jalview.util.MessageManager; - import java.awt.BorderLayout; import java.awt.Font; import java.awt.GridLayout; @@ -44,6 +37,13 @@ import javax.swing.SwingUtilities; import javax.swing.event.CaretEvent; import javax.swing.event.CaretListener; +import jalview.datamodel.AlignmentI; +import jalview.io.DataSourceType; +import jalview.io.FileFormat; +import jalview.io.FormatAdapter; +import jalview.io.cache.JvCacheableInputBox; +import jalview.util.MessageManager; + public class GFinder extends JPanel { private static final java.awt.Font VERDANA_12 = new Font("Verdana", @@ -59,6 +59,8 @@ public class GFinder extends JPanel protected JButton createFeatures; + protected JButton copyToClipboard; + protected JvCacheableInputBox searchBox; protected JCheckBox caseSensitive; @@ -205,9 +207,26 @@ public class GFinder extends JPanel createFeatures_actionPerformed(); } }); + copyToClipboard = new JButton(); + copyToClipboard.setEnabled(false); + copyToClipboard.setFont(VERDANA_12); + copyToClipboard.setText(MessageManager.getString("label.copy")); + copyToClipboard.addActionListener(new ActionListener() + { + @Override + public void actionPerformed(ActionEvent e) + { + copyToClipboard_actionPerformed(); + } + }); eastPanel.add(findNext); eastPanel.add(findAll); eastPanel.add(createFeatures); + eastPanel.add(copyToClipboard); + } + + protected void copyToClipboard_actionPerformed() + { } protected void textfield_keyPressed(KeyEvent e) -- 1.7.10.2