X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FCutAndPasteTransfer.java;h=e885c6541df7da7d6ae9a9a0e8bb27ce5435aaba;hb=61505ac1511435b067e647f5c7c9050e5c1eef41;hp=ea9a8aa04d9b8bc01006d0eb5802c204163b2ee2;hpb=55e2e9b22b133db8b9ff0979b0338a33081fc8fd;p=jalview.git diff --git a/src/jalview/appletgui/CutAndPasteTransfer.java b/src/jalview/appletgui/CutAndPasteTransfer.java index ea9a8aa..e885c65 100755 --- a/src/jalview/appletgui/CutAndPasteTransfer.java +++ b/src/jalview/appletgui/CutAndPasteTransfer.java @@ -25,15 +25,14 @@ import java.awt.event.*; import jalview.datamodel.*; import jalview.io.*; -public class CutAndPasteTransfer extends Panel +public class CutAndPasteTransfer extends Panel implements ActionListener, MouseListener { - jalview.bin.JalviewLite applet; - boolean pdbImport = false; + boolean treeImport = false; Sequence seq; - SeqCanvas seqcanvas; + AlignFrame alignFrame; - public CutAndPasteTransfer(boolean forImport, jalview.bin.JalviewLite mainApplet) + public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame) { try { jbInit(); @@ -41,7 +40,7 @@ public class CutAndPasteTransfer extends Panel e.printStackTrace(); } - applet = mainApplet; + this.alignFrame = alignFrame; if (!forImport) { @@ -49,14 +48,6 @@ public class CutAndPasteTransfer extends Panel } } - public void setPDBImport(Sequence seq, SeqCanvas seqcanvas) - { - this.seq = seq; - this.seqcanvas = seqcanvas; - pdbImport = true; - } - - public String getText() { return textarea.getText(); @@ -67,7 +58,22 @@ public class CutAndPasteTransfer extends Panel textarea.setText(text); } - protected void ok_actionPerformed(ActionEvent e) + public void setPDBImport(Sequence seq) + { + this.seq = seq; + pdbImport = true; + } + + + public void actionPerformed(ActionEvent evt) + { + if(evt.getSource()==ok) + ok_actionPerformed(); + else if(evt.getSource()==cancel) + cancel_actionPerformed(); + } + + protected void ok_actionPerformed() { String text = getText(); int length = text.length(); @@ -88,29 +94,60 @@ public class CutAndPasteTransfer extends Panel if(pdbImport) { - new MCview.AppletPDBViewer(text, "Paste", seq, seqcanvas); + new MCview.AppletPDBViewer(text, AppletFormatAdapter.PASTE, + seq, + alignFrame.getSeqcanvas()); } - else + else if(treeImport) { - SequenceI[] sequences = null; + try{ + jalview.io.NewickFile fin = new jalview.io.NewickFile(textarea.getText(), + "Paste"); - String format = IdentifyFile.Identify(text, "Paste"); - sequences = new AppletFormatAdapter().readFile(text, "Paste", format); + fin.parse(); + if(fin.getTree()!=null) + alignFrame.loadTree(fin, "Pasted tree file"); + } + catch (Exception ex) + { + textarea.setText("Could not parse Newick file!\n" + ex); + return; + } + } + else if(alignFrame!=null) + { + SequenceI[] sequences = null; + + String format = new IdentifyFile().Identify(text, AppletFormatAdapter.PASTE); + try{ + sequences = new AppletFormatAdapter().readFile(text, AppletFormatAdapter.PASTE, format); + }catch(java.io.IOException ex) + { + ex.printStackTrace(); + } if (sequences != null) { - AlignFrame af = new AlignFrame(new Alignment(sequences), applet, - "Cut & Paste input - " + format); + AlignFrame af = new AlignFrame(new Alignment(sequences), alignFrame.viewport.applet, + "Cut & Paste input - " + format, + false); af.statusBar.setText("Successfully pasted alignment file"); } } + if(this.getParent() instanceof Frame) ((Frame)this.getParent()).setVisible(false); + else + ((Dialog)this.getParent()).setVisible(false); } - protected void cancel_actionPerformed(ActionEvent e) + protected void cancel_actionPerformed() { - ((Frame)this.getParent()).setVisible(false); + textarea.setText(""); + if(this.getParent() instanceof Frame) + ((Frame)this.getParent()).setVisible(false); + else + ((Dialog)this.getParent()).setVisible(false); } protected TextArea textarea = new TextArea(); @@ -123,33 +160,25 @@ public class CutAndPasteTransfer extends Panel private void jbInit() throws Exception { textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10)); textarea.setText("Paste your alignment file here"); - textarea.addMouseListener(new java.awt.event.MouseAdapter() { - public void mousePressed(MouseEvent e) { - textarea_mousePressed(e); - } - }); + textarea.addMouseListener(this); this.setLayout(borderLayout1); ok.setLabel("OK"); - ok.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - ok_actionPerformed(e); - } - }); + ok.addActionListener(this); cancel.setLabel("Cancel"); - cancel.addActionListener(new java.awt.event.ActionListener() { - public void actionPerformed(ActionEvent e) { - cancel_actionPerformed(e); - } - }); + cancel.addActionListener(this); this.add(buttonPanel, BorderLayout.SOUTH); buttonPanel.add(ok, null); buttonPanel.add(cancel, null); this.add(textarea, java.awt.BorderLayout.CENTER); } - void textarea_mousePressed(MouseEvent e) { + public void mousePressed(MouseEvent evt) { if (textarea.getText().startsWith("Paste your")) { textarea.setText(""); - } + } } + public void mouseReleased(MouseEvent evt){} + public void mouseClicked(MouseEvent evt){} + public void mouseEntered(MouseEvent evt){} + public void mouseExited(MouseEvent evt){} }