JAL-4061 JAL-4062 button in Find dialog to copy highlighted regions to clipboard
authorJim Procter <j.procter@dundee.ac.uk>
Wed, 14 Sep 2022 10:05:32 +0000 (11:05 +0100)
committerJim Procter <j.procter@dundee.ac.uk>
Wed, 14 Sep 2022 10:05:32 +0000 (11:05 +0100)
src/jalview/appletgui/Finder.java
src/jalview/gui/Finder.java
src/jalview/jbgui/GFinder.java

index 43a12ae..167d899 100644 (file)
  */
 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;
index 2de06ec..6dacbd8 100755 (executable)
@@ -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<SequenceI> 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();
index aa79671..9ed2127 100755 (executable)
  */
 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<String> 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)