X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FCutAndPasteTransfer.java;h=12f9e283a1a8516f57a15cdec2590f00297414a2;hb=e25f63a72efddff9e071abdeff0ae5599431e4f8;hp=bd2eb7d5e76e2c4e15ba836b658dfa685eccfeb8;hpb=258c0056231d8a97c1d40dd665260e7814d11206;p=jalview.git diff --git a/src/jalview/gui/CutAndPasteTransfer.java b/src/jalview/gui/CutAndPasteTransfer.java index bd2eb7d..12f9e28 100755 --- a/src/jalview/gui/CutAndPasteTransfer.java +++ b/src/jalview/gui/CutAndPasteTransfer.java @@ -39,6 +39,19 @@ import javax.swing.*; */ public class CutAndPasteTransfer extends GCutAndPasteTransfer { + + public CutAndPasteTransfer() + { + SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + textarea.requestFocus(); + } + }); + + } + /** * DOCUMENT ME! */ @@ -67,6 +80,11 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer textarea.setText(text); } + public void appendText(String text) + { + textarea.append(text); + } + /** * DOCUMENT ME! * @@ -74,8 +92,9 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer */ public void copyItem_actionPerformed(ActionEvent e) { + textarea.getSelectedText(); Clipboard c = Toolkit.getDefaultToolkit().getSystemClipboard(); - c.setContents(new StringSelection(textarea.getText()), null); + c.setContents(new StringSelection(textarea.getSelectedText()), null); } /** @@ -95,7 +114,7 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer try { - textarea.setText((String) contents.getTransferData( + textarea.append((String) contents.getTransferData( DataFlavor.stringFlavor)); } catch (Exception ex) @@ -110,12 +129,20 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer */ public void ok_actionPerformed(ActionEvent e) { - String format = IdentifyFile.Identify(getText(), "Paste"); + String format = new IdentifyFile().Identify(getText(), "Paste"); SequenceI[] sequences = null; if (FormatAdapter.formats.contains(format)) { - sequences = FormatAdapter.readFile(getText(), "Paste", format); + try{ + sequences = new FormatAdapter().readFile(getText(), "Paste", format); + }catch(java.io.IOException ex) + { + JOptionPane.showInternalMessageDialog(Desktop.desktop, + "Couldn't read the pasted text.\n" +ex.toString(), + "Error parsing text", + JOptionPane.WARNING_MESSAGE); + } } if (sequences != null) @@ -142,14 +169,6 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer { } } - else - { - JOptionPane.showInternalMessageDialog(Desktop.desktop, - "Couldn't read the pasted text.\n" + - "Formats currently supported are\n" + - "Fasta, MSF, Clustal, BLC, PIR, MSP, and PFAM", - "Error parsing text", JOptionPane.WARNING_MESSAGE); - } } /** @@ -167,4 +186,31 @@ public class CutAndPasteTransfer extends GCutAndPasteTransfer { } } + + public void textarea_mousePressed(MouseEvent e) + { + if(SwingUtilities.isRightMouseButton(e)) + { + JPopupMenu popup = new JPopupMenu("Edit"); + JMenuItem item = new JMenuItem("Copy"); + item.addActionListener(new ActionListener() + {public void actionPerformed(ActionEvent e) + { + copyItem_actionPerformed(e); + } + }); + popup.add(item); + item = new JMenuItem("Paste"); + item.addActionListener(new ActionListener() + {public void actionPerformed(ActionEvent e) + { + pasteMenu_actionPerformed(e); + } + }); + popup.add(item); + popup.show(this, e.getX(), e.getY()+textarea.getY()+30); + + } + } + }