1 Clazz.declarePackage ("jalview.appletgui");
2 Clazz.load (["awt2swing.Panel", "java.awt.event.ActionListener", "$.MouseListener", "awt2swing.Button", "$.TextArea", "java.awt.BorderLayout"], "jalview.appletgui.CutAndPasteTransfer", ["awt2swing.Frame", "$.Label", "jalview.analysis.AlignmentUtils", "jalview.api.ComplexAlignFile", "jalview.appletgui.AlignFrame", "$.AppletJmol", "$.JVDialog", "$.SplitFrame", "jalview.datamodel.PDBEntry", "jalview.io.AnnotationFile", "$.AppletFormatAdapter", "$.IdentifyFile", "$.NewickFile", "jalview.jsdev.GenericFileAdapter", "jalview.schemes.TCoffeeColourScheme", "jalview.util.MessageManager", "java.awt.Font"], function () {
3 c$ = Clazz.decorateAsClass (function () {
4 this.pdbImport = false;
5 this.treeImport = false;
6 this.annotationImport = false;
8 this.alignFrame = null;
12 this.addSequences = null;
14 this.buttonPanel = null;
15 this.borderLayout1 = null;
16 Clazz.instantialize (this, arguments);
17 }, jalview.appletgui, "CutAndPasteTransfer", awt2swing.Panel, [java.awt.event.ActionListener, java.awt.event.MouseListener]);
18 Clazz.prepareFields (c$, function () {
19 this.textarea = new awt2swing.TextArea ();
20 this.accept = new awt2swing.Button ("New Window");
21 this.addSequences = new awt2swing.Button ("Add to Current Alignment");
22 this.$cancel = new awt2swing.Button ("Close");
23 this.buttonPanel = new awt2swing.Panel ();
24 this.borderLayout1 = new java.awt.BorderLayout ();
26 Clazz.makeConstructor (c$,
27 function (forImport, alignFrame) {
28 Clazz.superConstructor (this, jalview.appletgui.CutAndPasteTransfer, []);
32 if (Clazz.exceptionOf (e, Exception)) {
38 this.alignFrame = alignFrame;
40 this.buttonPanel.setVisible (false);
41 }}, "~B,jalview.appletgui.AlignFrame");
42 Clazz.defineMethod (c$, "getText",
44 return this.textarea.getText ();
46 Clazz.defineMethod (c$, "setText",
48 this.textarea.setText (text);
50 Clazz.defineMethod (c$, "setPDBImport",
53 this.accept.setLabel (jalview.util.MessageManager.getString ("action.accept"));
54 this.addSequences.setVisible (false);
55 this.pdbImport = true;
56 }, "jalview.datamodel.SequenceI");
57 Clazz.defineMethod (c$, "setTreeImport",
59 this.treeImport = true;
60 this.accept.setLabel (jalview.util.MessageManager.getString ("action.accept"));
61 this.addSequences.setVisible (false);
63 Clazz.defineMethod (c$, "setAnnotationImport",
65 this.annotationImport = true;
66 this.accept.setLabel (jalview.util.MessageManager.getString ("action.accept"));
67 this.addSequences.setVisible (false);
69 Clazz.overrideMethod (c$, "actionPerformed",
71 if (evt.getSource () === this.accept) {
73 } else if (evt.getSource () === this.addSequences) {
75 } else if (evt.getSource () === this.$cancel) {
77 }}, "java.awt.event.ActionEvent");
78 Clazz.defineMethod (c$, "ok",
79 function (newWindow) {
80 var text = this.getText ();
81 var length = text.length;
82 this.textarea.append ("\n");
83 if (this.textarea.getText ().length == length) {
84 var warning = "\n\n#################################################\nWARNING!! THIS IS THE MAXIMUM SIZE OF TEXTAREA!!\n\nCAN\'T INPUT FULL ALIGNMENT\n\nYOU MUST DELETE THIS WARNING TO CONTINUE\n\nMAKE SURE LAST SEQUENCE PASTED IS COMPLETE\n#################################################\n";
85 this.textarea.setText (text.substring (0, text.length - warning.length) + warning);
86 this.textarea.setCaretPosition (text.length);
87 }if (this.pdbImport) {
88 this.openPdbViewer (text);
89 } else if (this.treeImport) {
90 if (!this.loadTree ()) {
92 }} else if (this.annotationImport) {
93 this.loadAnnotations ();
94 } else if (this.alignFrame != null) {
95 this.loadAlignment (text, newWindow, this.alignFrame.getAlignViewport ());
96 }if (Clazz.instanceOf (this.getParent (), awt2swing.Frame)) {
97 (this.getParent ()).setVisible (false);
99 (this.getParent ()).setVisible (false);
101 Clazz.defineMethod (c$, "loadTree",
104 var fin = new jalview.io.NewickFile (this.textarea.getText (), "Paste");
106 if (fin.getTree () != null) {
107 this.alignFrame.loadTree (fin, "Pasted tree file");
110 if (Clazz.exceptionOf (ex, Exception)) {
111 this.textarea.setText (jalview.util.MessageManager.formatMessage ("label.could_not_parse_newick_file", Clazz.newArray (-1, [ex.getMessage ()])));
119 Clazz.defineMethod (c$, "loadAlignment",
120 function (text, newWindow, viewport) {
122 var format = new jalview.io.IdentifyFile ().Identify (text, jalview.io.AppletFormatAdapter.PASTE);
123 var afa = new jalview.io.AppletFormatAdapter (this.alignFrame.alignPanel);
125 al = afa.readFile (text, jalview.io.AppletFormatAdapter.PASTE, format);
126 this.source = afa.getAlignFile ();
128 if (Clazz.exceptionOf (ex, java.io.IOException)) {
129 ex.printStackTrace ();
135 al.setDataset (null);
136 var allowSplitFrame = this.alignFrame.viewport.applet.getDefaultParameter ("enableSplitFrame", false);
137 if (allowSplitFrame && this.openSplitFrame (al, format)) {
141 if (Clazz.instanceOf (this.source, jalview.api.ComplexAlignFile)) {
142 var colSel = (this.source).getColumnSelection ();
143 var hiddenSeqs = (this.source).getHiddenSequences ();
144 var showSeqFeatures = (this.source).isShowSeqFeatures ();
145 var cs = (this.source).getColourScheme ();
146 af = new jalview.appletgui.AlignFrame (al, hiddenSeqs, colSel, this.alignFrame.viewport.applet, "Cut & Paste input - " + format, false);
147 af.getAlignViewport ().setShowSequenceFeatures (showSeqFeatures);
148 af.changeColour (cs);
150 af = new jalview.appletgui.AlignFrame (al, this.alignFrame.viewport.applet, "Cut & Paste input - " + format, false);
151 }af.setStatus (jalview.util.MessageManager.getString ("label.successfully_pasted_annotation_to_alignment"));
153 this.alignFrame.addSequences (al.getSequencesArray ());
154 this.alignFrame.setStatus (jalview.util.MessageManager.getString ("label.successfully_pasted_alignment_file"));
155 }}}, "~S,~B,jalview.appletgui.AlignViewport");
156 Clazz.defineMethod (c$, "openSplitFrame",
157 function (al, format) {
158 var thisAlignment = this.alignFrame.getAlignViewport ().getAlignment ();
159 if (thisAlignment.isNucleotide () == al.isNucleotide ()) {
161 }var protein = thisAlignment.isNucleotide () ? al : thisAlignment;
162 var dna = thisAlignment.isNucleotide () ? thisAlignment : al;
163 var mapped = jalview.analysis.AlignmentUtils.mapProteinToCdna (protein, dna);
166 }var title = jalview.util.MessageManager.getString ("label.open_split_window");
167 var dialog = new jalview.appletgui.JVDialog (this.getParent (), title, true, 100, 400);
168 dialog.ok.setLabel (jalview.util.MessageManager.getString ("action.yes"));
169 dialog.cancel.setLabel (jalview.util.MessageManager.getString ("action.no"));
170 var question = new awt2swing.Panel ( new java.awt.BorderLayout ());
171 var text = jalview.util.MessageManager.getString ("label.open_split_window?");
172 question.add ( new awt2swing.Label (text, 0), "Center");
173 dialog.setMainPanel (question);
174 dialog.setVisible (true);
176 if (!dialog.accept) {
178 }var applet = this.alignFrame.viewport.applet;
179 var copyFrame = new jalview.appletgui.AlignFrame (this.alignFrame.viewport.getAlignment (), applet, this.alignFrame.getTitle (), false, false);
180 var newFrame = new jalview.appletgui.AlignFrame (al, this.alignFrame.viewport.applet, "Cut & Paste input - " + format, false, false);
181 var dnaFrame = al.isNucleotide () ? newFrame : copyFrame;
182 var proteinFrame = al.isNucleotide () ? copyFrame : newFrame;
183 var sf = new jalview.appletgui.SplitFrame (dnaFrame, proteinFrame);
184 sf.addToDisplay (false, applet);
186 }, "jalview.datamodel.AlignmentI,~S");
187 Clazz.defineMethod (c$, "loadAnnotations",
191 tcf = jalview.jsdev.GenericFileAdapter.getFile ("TCoffeeScoreFile", [this.textarea.getText (), jalview.io.AppletFormatAdapter.PASTE]);
192 if (tcf.isValid ()) {
193 if (tcf.annotateAlignment (this.alignFrame.viewport.getAlignment (), true)) {
194 this.alignFrame.tcoffeeColour.setEnabled (true);
195 this.alignFrame.alignPanel.fontChanged ();
196 this.alignFrame.changeColour ( new jalview.schemes.TCoffeeColourScheme (this.alignFrame.viewport.getAlignment ()));
197 this.alignFrame.setStatus (jalview.util.MessageManager.getString ("label.successfully_pasted_tcoffee_scores_to_alignment"));
199 this.alignFrame.setStatus (jalview.util.MessageManager.formatMessage ("label.failed_add_tcoffee_scores", Clazz.newArray (-1, [(tcf.getWarningMessage () != null ? tcf.getWarningMessage () : "")])));
203 if (Clazz.exceptionOf (x, Exception)) {
210 if ( new jalview.io.AnnotationFile ().annotateAlignmentView (this.alignFrame.viewport, this.textarea.getText (), jalview.io.AppletFormatAdapter.PASTE)) {
211 this.alignFrame.alignPanel.fontChanged ();
212 this.alignFrame.alignPanel.setScrollValues (0, 0);
213 this.alignFrame.setStatus (jalview.util.MessageManager.getString ("label.successfully_pasted_annotation_to_alignment"));
215 if (!this.alignFrame.parseFeaturesFile (this.textarea.getText (), jalview.io.AppletFormatAdapter.PASTE)) {
216 this.alignFrame.setStatus (jalview.util.MessageManager.getString ("label.couldnt_parse_pasted_text_as_valid_annotation_feature_GFF_tcoffee_file"));
218 Clazz.defineMethod (c$, "openPdbViewer",
220 var pdb = new jalview.datamodel.PDBEntry ();
222 new jalview.appletgui.AppletJmol (pdb, Clazz.newArray (-1, [this.seq]), null, this.alignFrame.alignPanel, jalview.io.AppletFormatAdapter.PASTE);
224 Clazz.defineMethod (c$, "cancel",
226 this.textarea.setText ("");
227 if (Clazz.instanceOf (this.getParent (), awt2swing.Frame)) {
228 (this.getParent ()).setVisible (false);
230 (this.getParent ()).setVisible (false);
232 Clazz.defineMethod (c$, "jbInit",
234 this.textarea.setFont ( new java.awt.Font ("Monospaced", 0, 10));
235 this.textarea.setText (jalview.util.MessageManager.getString ("label.paste_your_alignment_file"));
236 this.textarea.addMouseListener (this);
237 this.setLayout (this.borderLayout1);
238 this.accept.addActionListener (this);
239 this.addSequences.addActionListener (this);
240 this.$cancel.addActionListener (this);
241 this.add (this.buttonPanel, "South");
242 this.buttonPanel.add (this.accept, null);
243 this.buttonPanel.add (this.addSequences);
244 this.buttonPanel.add (this.$cancel, null);
245 this.add (this.textarea, "Center");
247 Clazz.overrideMethod (c$, "mousePressed",
249 if (this.textarea.getText ().startsWith (jalview.util.MessageManager.getString ("label.paste_your"))) {
250 this.textarea.setText ("");
251 }}, "java.awt.event.MouseEvent");
252 Clazz.overrideMethod (c$, "mouseReleased",
254 }, "java.awt.event.MouseEvent");
255 Clazz.overrideMethod (c$, "mouseClicked",
257 }, "java.awt.event.MouseEvent");
258 Clazz.overrideMethod (c$, "mouseEntered",
260 }, "java.awt.event.MouseEvent");
261 Clazz.overrideMethod (c$, "mouseExited",
263 }, "java.awt.event.MouseEvent");