X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fappletgui%2FCutAndPasteTransfer.java;h=4b890bbf8e7d6ef8afbba593e39ea49b08d4ad6b;hb=c77ccc33971183dba9cb66b40886a6b61fe8eaa0;hp=f8c3756b2f3d6aff93c20663aec017846aaecfcf;hpb=8da7acff9214ddaf0e6d28e76219ab51bd38e62d;p=jalview.git diff --git a/src/jalview/appletgui/CutAndPasteTransfer.java b/src/jalview/appletgui/CutAndPasteTransfer.java index f8c3756..4b890bb 100755 --- a/src/jalview/appletgui/CutAndPasteTransfer.java +++ b/src/jalview/appletgui/CutAndPasteTransfer.java @@ -24,16 +24,23 @@ import java.awt.event.*; import jalview.datamodel.*; import jalview.io.*; -import jalview.jbappletgui.*; -public class CutAndPasteTransfer - extends GCutAndPasteTransfer +public class CutAndPasteTransfer extends Panel implements ActionListener, MouseListener { - jalview.bin.JalviewLite applet; - public CutAndPasteTransfer(boolean forImport, jalview.bin.JalviewLite mainApplet) + boolean pdbImport = false; + boolean treeImport = false; + Sequence seq; + AlignFrame alignFrame; + + public CutAndPasteTransfer(boolean forImport, AlignFrame alignFrame) { - super(); - applet = mainApplet; + try { + jbInit(); + } catch (Exception e) { + e.printStackTrace(); + } + + this.alignFrame = alignFrame; if (!forImport) { @@ -51,7 +58,22 @@ public class CutAndPasteTransfer 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(); @@ -68,31 +90,95 @@ public class CutAndPasteTransfer +warning); textarea.setCaretPosition(text.length()); - return; } - SequenceI[] sequences = null; + if(pdbImport) + { + new MCview.AppletPDBViewer(text, AppletFormatAdapter.PASTE, + seq, + alignFrame.getSeqcanvas()); + } + else if(treeImport) + { + try{ + jalview.io.NewickFile fin = new jalview.io.NewickFile(textarea.getText(), + "Paste"); - String format = IdentifyFile.Identify(text, "Paste"); - sequences = FormatAdapter.readFile(text, "Paste", format); + fin.parse(); + if(fin.getTree()!=null) + alignFrame.loadTree(fin, "Pasted tree file"); - if (sequences != null) + } + catch (Exception ex) + { + textarea.setText("Could not parse Newick file!\n" + ex); + return; + } + } + else if(alignFrame!=null) { - AlignFrame af = new AlignFrame(new Alignment(sequences), applet); - jalview.bin.JalviewLite.addFrame(af, "Cut & Paste input - " + format, - AlignFrame.NEW_WINDOW_WIDTH, - AlignFrame.NEW_WINDOW_HEIGHT); - af.statusBar.setText("Successfully pasted alignment file"); + 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), alignFrame.applet, + "Cut & Paste input - " + format, + false); + af.statusBar.setText("Successfully pasted alignment file"); + } } - Frame frame = (Frame)this.getParent(); - frame.setVisible(false); + 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 frame = (Frame)this.getParent(); - frame.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(); + Button ok = new Button(); + Button cancel = new Button(); + protected Panel buttonPanel = new Panel(); + BorderLayout borderLayout1 = new BorderLayout(); + + + private void jbInit() throws Exception { + textarea.setFont(new java.awt.Font("Monospaced", Font.PLAIN, 10)); + textarea.setText("Paste your alignment file here"); + textarea.addMouseListener(this); + this.setLayout(borderLayout1); + ok.setLabel("OK"); + ok.addActionListener(this); + cancel.setLabel("Cancel"); + cancel.addActionListener(this); + this.add(buttonPanel, BorderLayout.SOUTH); + buttonPanel.add(ok, null); + buttonPanel.add(cancel, null); + this.add(textarea, java.awt.BorderLayout.CENTER); + } + + 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){} }