(JAL-893) update to VARNAv3.9-dev version
[jalview.git] / src / jalview / gui / AppVarnaBinding.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
3  * Copyright (C) 2011 J Procter, AM Waterhouse, J Engelhardt, LM Lui, G Barton, M Clamp, S Searle
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
10  * 
11  * Jalview is distributed in the hope that it will be useful, but 
12  * WITHOUT ANY WARRANTY; without even the implied warranty 
13  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
14  * PURPOSE.  See the GNU General Public License for more details.
15  * 
16  * You should have received a copy of the GNU General Public License along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
17  */
18 package jalview.gui;
19
20 import java.awt.BorderLayout;
21 import java.awt.Color;
22 import java.awt.Component;
23 import java.awt.Dimension;
24 import java.awt.Font;
25 import java.awt.GridLayout;
26 import java.awt.datatransfer.DataFlavor;
27 import java.awt.datatransfer.Transferable;
28 import java.awt.dnd.DnDConstants;
29 import java.awt.dnd.DropTarget;
30 import java.awt.dnd.DropTargetDragEvent;
31 import java.awt.dnd.DropTargetDropEvent;
32 import java.awt.dnd.DropTargetEvent;
33 import java.awt.dnd.DropTargetListener;
34 import java.awt.event.ActionEvent;
35 import java.awt.event.ActionListener;
36 import java.awt.event.ComponentEvent;
37 import java.awt.event.MouseEvent;
38 import java.awt.event.MouseListener;
39 import java.io.File;
40 import java.text.DateFormat;
41 import java.util.ArrayList;
42 import java.util.Collection;
43 import java.util.Date;
44 import java.util.List;
45
46 import javax.swing.DefaultListModel;
47 import javax.swing.DefaultListSelectionModel;
48 import javax.swing.Icon;
49 import javax.swing.JButton;
50 import javax.swing.JFrame;
51 import javax.swing.JLabel;
52 import javax.swing.JList;
53 import javax.swing.JOptionPane;
54 import javax.swing.JPanel;
55 import javax.swing.JScrollPane;
56 import javax.swing.JSplitPane;
57 import javax.swing.JTextField;
58 import javax.swing.ListModel;
59 import javax.swing.ListSelectionModel;
60 import javax.swing.UIManager;
61 import javax.swing.UnsupportedLookAndFeelException;
62 import javax.swing.event.ListSelectionEvent;
63 import javax.swing.event.ListSelectionListener;
64
65 import fr.orsay.lri.varna.VARNAPanel;
66 import fr.orsay.lri.varna.components.ReorderableJList;
67 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
68 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
69 import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength;
70 import fr.orsay.lri.varna.exceptions.ExceptionUnmatchedClosingParentheses;
71 import fr.orsay.lri.varna.interfaces.InterfaceVARNAListener;
72 import fr.orsay.lri.varna.models.FullBackup;
73 import fr.orsay.lri.varna.models.VARNAConfig;
74 import fr.orsay.lri.varna.models.rna.Mapping;
75 import fr.orsay.lri.varna.models.rna.RNA;
76
77 public class AppVarnaBinding extends jalview.ext.varna.JalviewVarnaBinding
78         implements DropTargetListener, InterfaceVARNAListener,
79         MouseListener
80 {
81
82   /**
83          * 
84          */
85   // private static final long serialVersionUID = -790155708306987257L;
86
87   private String DEFAULT_SEQUENCE = "CAGCACGACACUAGCAGUCAGUGUCAGACUGCAIACAGCACGACACUAGCAGUCAGUGUCAGACUGCAIACAGCACGACACUAGCAGUCAGUGUCAGACUGCAIA";
88
89   private String DEFAULT_STRUCTURE1 = "..(((((...(((((...(((((...(((((.....)))))...))))).....(((((...(((((.....)))))...))))).....)))))...)))))..";
90
91   private String DEFAULT_STRUCTURE2 = "..(((((...(((((...(((((........(((((...(((((.....)))))...)))))..................))))).....)))))...)))))..";
92
93   public VARNAPanel vp;
94
95   protected JPanel _tools = new JPanel();
96
97   private JPanel _input = new JPanel();
98
99   private JPanel _seqPanel = new JPanel();
100
101   private JPanel _strPanel = new JPanel();
102
103   private JLabel _info = new JLabel();
104
105   private JTextField _str = new JTextField();
106
107   private JTextField _seq = new JTextField();
108
109   private JLabel _strLabel = new JLabel(" Str:");
110
111   private JLabel _seqLabel = new JLabel(" Seq:");
112
113   private JButton _createButton = new JButton("Create");
114
115   private JButton _updateButton = new JButton("Update");
116
117   private JButton _deleteButton = new JButton("Delete");
118
119   private JButton _duplicateButton = new JButton("Snapshot");
120
121   protected JPanel _listPanel = new JPanel();
122
123   private ReorderableJList _sideList = null;
124
125   private static String errorOpt = "error";
126
127   @SuppressWarnings("unused")
128   private boolean _error;
129
130   private Color _backgroundColor = Color.white;
131
132   private static int _nextID = 1;
133
134   @SuppressWarnings("unused")
135   private int _algoCode;
136
137   private BackupHolder _rnaList;
138
139   /*
140    * public AppVarnaBinding() { //super("VARNA in Jalview");
141    * //this.set_seq("ATGC"); //this.set_str(".()."); //RNAPanelDemoInit();
142    * 
143    * //initVarna("ATGCATGATATATATATAT","....((((...))))....");
144    * initVarna(this.DEFAULT_SEQUENCE,this.DEFAULT_STRUCTURE1); }
145    */
146
147   public AppVarnaBinding(String seq, String struc)
148   {
149     // super("VARNA in Jalview");
150     initVarna(seq, struc);
151   }
152
153   public AppVarnaBinding(ArrayList<RNA> rnaList)
154   {
155     // super("VARNA in Jalview");
156     initVarnaEdit(rnaList);
157   }
158
159   private void initVarna(String seq, String str)
160   {
161     DefaultListModel dlm = new DefaultListModel();
162
163     DefaultListSelectionModel m = new DefaultListSelectionModel();
164     m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
165     m.setLeadAnchorNotificationEnabled(false);
166
167     _sideList = new ReorderableJList();
168     _sideList.setModel(dlm);
169     _sideList.addMouseListener(this);
170     _sideList.setSelectionModel(m);
171     _sideList.setPreferredSize(new Dimension(100, 0));
172     _sideList.addListSelectionListener(new ListSelectionListener()
173     {
174       public void valueChanged(ListSelectionEvent arg0)
175       {
176         if (!_sideList.isSelectionEmpty() && !arg0.getValueIsAdjusting())
177         {
178           FullBackup sel = (FullBackup) _sideList.getSelectedValue();
179           Mapping map = Mapping.DefaultOutermostMapping(vp.getRNA()
180                   .getSize(), sel.rna.getSize());
181           vp.showRNAInterpolated(sel.rna, sel.config, map);
182           _seq.setText(sel.rna.getSeq());
183           _str.setText(sel.rna.getStructDBN());
184         }
185       }
186     });
187
188     _rnaList = new BackupHolder(dlm, _sideList);
189     RNA _RNA1 = new RNA("User defined 1");
190
191     try
192     {
193       vp = new VARNAPanel("0", ".");
194       _RNA1.setRNA(seq, str);
195       _RNA1.drawRNARadiate(vp.getConfig());
196     } catch (ExceptionNonEqualLength e)
197     {
198       vp.errorDialog(e);
199     } catch (ExceptionUnmatchedClosingParentheses e2)
200     {
201       e2.printStackTrace();
202     } catch (ExceptionFileFormatOrSyntax e3)
203     {
204       e3.printStackTrace();
205     }
206     vp.setPreferredSize(new Dimension(400, 400));
207     _rnaList.add(vp.getConfig().clone(), _RNA1, generateDefaultName(), true);
208
209     // TODO setBackground(_backgroundColor);
210     vp.setBackground(_backgroundColor);
211
212     // TODO getContentPane().setLayout(new BorderLayout());
213     // TODO getContentPane().add(vp, BorderLayout.CENTER);
214
215     // setVisible(true);
216     vp.addVARNAListener(this);
217   }
218
219   private void initVarnaEdit(ArrayList<RNA> rnaInList)
220   {
221     DefaultListModel dlm = new DefaultListModel();
222
223     int marginTools = 40;
224
225     DefaultListSelectionModel m = new DefaultListSelectionModel();
226     m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
227     m.setLeadAnchorNotificationEnabled(false);
228
229     _sideList = new ReorderableJList();
230     _sideList.setModel(dlm);
231     _sideList.addMouseListener(this);
232     _sideList.setSelectionModel(m);
233     _sideList.setPreferredSize(new Dimension(100, 0));
234     _sideList.addListSelectionListener(new ListSelectionListener()
235     {
236       public void valueChanged(ListSelectionEvent arg0)
237       {
238         // System.out.println(arg0);
239         if (!_sideList.isSelectionEmpty() && !arg0.getValueIsAdjusting())
240         {
241           FullBackup sel = (FullBackup) _sideList.getSelectedValue();
242           Mapping map = Mapping.DefaultOutermostMapping(vp.getRNA()
243                   .getSize(), sel.rna.getSize());
244           vp.showRNAInterpolated(sel.rna, sel.config, map);
245           // _seq.setText(sel.rna.getSeq());
246           _str.setText(sel.rna.getStructDBN());
247         }
248       }
249     });
250     _rnaList = new BackupHolder(dlm, _sideList);
251
252     try
253     {
254       vp = new VARNAPanel("0", ".");
255       for (int i = 0; i < rnaInList.size(); i++)
256       {
257         rnaInList.get(i).drawRNARadiate(vp.getConfig());
258       }
259     } catch (ExceptionNonEqualLength e)
260     {
261       vp.errorDialog(e);
262     }
263     vp.setPreferredSize(new Dimension(400, 400));
264     for (int i = 0; i < rnaInList.size(); i++)
265     {
266       if (i < rnaInList.size() - 1)
267       {
268         _rnaList.add(vp.getConfig().clone(), rnaInList.get(i), rnaInList
269                 .get(i).getName());
270       }
271       else
272       {
273         _rnaList.add(vp.getConfig().clone(), rnaInList.get(i), rnaInList
274                 .get(i).getName(), true);
275       }
276     }
277
278     /*
279      * _rnaList.add(vp.getConfig().clone(),_RNA2,generateDefaultName());
280      * _rnaList.add(vp.getConfig().clone(),_RNA1,generateDefaultName(),true);
281      */
282
283     JScrollPane listScroller = new JScrollPane(_sideList);
284     listScroller.setPreferredSize(new Dimension(150, 0));
285
286     vp.setBackground(_backgroundColor);
287
288     Font textFieldsFont = Font.decode("MonoSpaced-PLAIN-12");
289
290     // _seqLabel.setHorizontalTextPosition(JLabel.LEFT);
291     // _seqLabel.setPreferredSize(new Dimension(marginTools, 15));
292     _seq.setFont(textFieldsFont);
293     _seq.setText(rnaInList.get(0).getSeq());
294
295     _updateButton.addActionListener(new ActionListener()
296     {
297       public void actionPerformed(ActionEvent e)
298       {
299         FullBackup sel = (FullBackup) _sideList.getSelectedValue();
300         sel.rna.setSequence("A");
301       }
302     });
303
304     // _seqPanel.setLayout(new BorderLayout());
305     // _seqPanel.add(_seqLabel, BorderLayout.WEST);
306     // _seqPanel.add(_seq, BorderLayout.CENTER);
307
308     _strLabel.setPreferredSize(new Dimension(marginTools, 15));
309     _strLabel.setHorizontalTextPosition(JLabel.LEFT);
310     _str.setFont(textFieldsFont);
311     _strPanel.setLayout(new BorderLayout());
312     _strPanel.add(_strLabel, BorderLayout.WEST);
313     _strPanel.add(_str, BorderLayout.CENTER);
314
315     _input.setLayout(new GridLayout(1, 0));
316     // _input.add(_seqPanel);
317     _input.add(_strPanel);
318
319     JPanel goPanel = new JPanel();
320     goPanel.setLayout(new BorderLayout());
321
322     _tools.setLayout(new BorderLayout());
323     _tools.add(_input, BorderLayout.CENTER);
324     // _tools.add(_info, BorderLayout.SOUTH);
325     _tools.add(goPanel, BorderLayout.EAST);
326
327     /*
328      * _deleteButton.addActionListener(new ActionListener() { public void
329      * actionPerformed(ActionEvent e) { _rnaList.removeSelected(); } });
330      * _duplicateButton.addActionListener(new ActionListener() { public void
331      * actionPerformed(ActionEvent e) {
332      * _rnaList.add((VARNAConfig)vp.getConfig().
333      * clone(),vp.getRNA().clone(),vp.getRNA
334      * ().getName()+"-"+DateFormat.getTimeInstance(DateFormat.LONG).format(new
335      * Date()),true); }});
336      */
337     goPanel.add(_updateButton, BorderLayout.CENTER);
338
339     JPanel ops = new JPanel();
340     ops.setLayout(new GridLayout(1, 2));
341     ops.add(_deleteButton);
342     ops.add(_duplicateButton);
343
344     JLabel j = new JLabel("Structures Manager", JLabel.CENTER);
345     _listPanel.setLayout(new BorderLayout());
346
347     _listPanel.add(ops, BorderLayout.SOUTH);
348     _listPanel.add(j, BorderLayout.NORTH);
349     _listPanel.add(listScroller, BorderLayout.CENTER);
350
351     // JSplitPane split = new
352     // JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,_listPanel,vp);
353     /**
354      * TODO getContentPane().setLayout(new BorderLayout());
355      * getContentPane().add(split, BorderLayout.CENTER);
356      * getContentPane().add(_tools, BorderLayout.NORTH);
357      */
358
359     // TODO setVisible(true);
360     DropTarget dt = new DropTarget(vp, this);
361
362     vp.addVARNAListener(this);
363   }
364
365   public JPanel getTools()
366   {
367     return _tools;
368   }
369
370   public JPanel getListPanel()
371   {
372     return _listPanel;
373   }
374
375   /**
376    * TODO: Is it effective to transfer the whole RNA?
377    * 
378    * @return Currently selected RNA
379    */
380   public RNA getSelectedRNA()
381   {
382     return _rnaList.getElementAt(_sideList.getSelectedIndex()).rna;
383   }
384
385   /**
386    * Substitute currently selected RNA with the edited one
387    * 
388    * @param rnaEdit
389    */
390   public void updateSelectedRNA(RNA rnaEdit)
391   {
392     vp.repaint();
393     vp.showRNA(rnaEdit);
394   }
395
396   /*
397    * private void RNAPanelDemoInit() { DefaultListModel dlm = new
398    * DefaultListModel();
399    * 
400    * 
401    * int marginTools = 40;
402    * 
403    * DefaultListSelectionModel m = new DefaultListSelectionModel();
404    * m.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
405    * m.setLeadAnchorNotificationEnabled(false);
406    * 
407    * 
408    * _sideList = new ReorderableJList(); _sideList.setModel(dlm);
409    * _sideList.addMouseListener(this); _sideList.setSelectionModel(m);
410    * _sideList.setPreferredSize(new Dimension(100, 0));
411    * _sideList.addListSelectionListener( new ListSelectionListener(){ public
412    * void valueChanged(ListSelectionEvent arg0) { //System.out.println(arg0); if
413    * (!_sideList.isSelectionEmpty() && !arg0.getValueIsAdjusting()) { FullBackup
414    * sel = (FullBackup) _sideList.getSelectedValue(); Mapping map =
415    * Mapping.DefaultOutermostMapping(vp.getRNA().getSize(), sel.rna.getSize());
416    * vp.showRNAInterpolated(sel.rna,sel.config,map);
417    * _seq.setText(sel.rna.getSeq()); _str.setText(sel.rna.getStructDBN()); } }
418    * });
419    * 
420    * _rnaList = new BackupHolder(dlm,_sideList); RNA _RNA1 = new
421    * RNA("User defined 1"); RNA _RNA2 = new RNA("User defined 2"); try { vp =
422    * new VARNAPanel("0","."); _RNA1.setRNA(DEFAULT_SEQUENCE,
423    * DEFAULT_STRUCTURE1); _RNA1.drawRNARadiate(vp.getConfig());
424    * _RNA2.setRNA(DEFAULT_SEQUENCE, DEFAULT_STRUCTURE2);
425    * _RNA2.drawRNARadiate(vp.getConfig()); } catch (ExceptionNonEqualLength e) {
426    * vp.errorDialog(e); } catch (ExceptionUnmatchedClosingParentheses e2) {
427    * e2.printStackTrace(); } catch (ExceptionFileFormatOrSyntax e3) {
428    * e3.printStackTrace(); } vp.setPreferredSize(new Dimension(400, 400));
429    * _rnaList.add(vp.getConfig().clone(),_RNA2,generateDefaultName());
430    * _rnaList.add(vp.getConfig().clone(),_RNA1,generateDefaultName(),true);
431    * 
432    * JScrollPane listScroller = new JScrollPane(_sideList);
433    * listScroller.setPreferredSize(new Dimension(150, 0));
434    * 
435    * setBackground(_backgroundColor); vp.setBackground(_backgroundColor);
436    * 
437    * 
438    * Font textFieldsFont = Font.decode("MonoSpaced-PLAIN-12");
439    * 
440    * _seqLabel.setHorizontalTextPosition(JLabel.LEFT);
441    * _seqLabel.setPreferredSize(new Dimension(marginTools, 15));
442    * _seq.setFont(textFieldsFont); _seq.setText(DEFAULT_SEQUENCE);
443    * 
444    * _createButton.addActionListener(new ActionListener() { public void
445    * actionPerformed(ActionEvent e) { try { RNA nRNA = new
446    * RNA(generateDefaultName()); nRNA.setRNA(_seq.getText(), _str.getText());
447    * nRNA.drawRNARadiate(vp.getConfig()); _rnaList.add(new
448    * VARNAConfig(),nRNA,true); } catch (ExceptionUnmatchedClosingParentheses e1)
449    * { JOptionPane.showMessageDialog(vp, e1.getMessage(),"Error",
450    * JOptionPane.ERROR_MESSAGE); } catch (ExceptionFileFormatOrSyntax e1) {
451    * JOptionPane.showMessageDialog(vp, e1.getMessage(),"Error",
452    * JOptionPane.ERROR_MESSAGE); } } });
453    * 
454    * 
455    * _seqPanel.setLayout(new BorderLayout()); _seqPanel.add(_seqLabel,
456    * BorderLayout.WEST); _seqPanel.add(_seq, BorderLayout.CENTER);
457    * 
458    * _strLabel.setPreferredSize(new Dimension(marginTools, 15));
459    * _strLabel.setHorizontalTextPosition(JLabel.LEFT);
460    * _str.setFont(textFieldsFont); _strPanel.setLayout(new BorderLayout());
461    * _strPanel.add(_strLabel, BorderLayout.WEST); _strPanel.add(_str,
462    * BorderLayout.CENTER);
463    * 
464    * _input.setLayout(new GridLayout(2, 0)); _input.add(_seqPanel);
465    * _input.add(_strPanel);
466    * 
467    * JPanel goPanel = new JPanel(); goPanel.setLayout(new BorderLayout());
468    * 
469    * _tools.setLayout(new BorderLayout()); _tools.add(_input,
470    * BorderLayout.CENTER); _tools.add(_info, BorderLayout.SOUTH);
471    * _tools.add(goPanel, BorderLayout.EAST);
472    * 
473    * _deleteButton.addActionListener(new ActionListener() { public void
474    * actionPerformed(ActionEvent e) { _rnaList.removeSelected(); } });
475    * _duplicateButton.addActionListener(new ActionListener() { public void
476    * actionPerformed(ActionEvent e) {
477    * _rnaList.add((VARNAConfig)vp.getConfig().clone
478    * (),vp.getRNA().clone(),vp.getRNA
479    * ().getName()+"-"+DateFormat.getTimeInstance(DateFormat.LONG).format(new
480    * Date()),true); }});
481    * 
482    * JPanel ops = new JPanel(); ops.setLayout(new GridLayout(1,2));
483    * ops.add(_deleteButton); ops.add(_duplicateButton);
484    * 
485    * JLabel j = new JLabel("Structures Manager",JLabel.CENTER);
486    * _listPanel.setLayout(new BorderLayout());
487    * 
488    * _listPanel.add(ops,BorderLayout.SOUTH);
489    * _listPanel.add(j,BorderLayout.NORTH);
490    * _listPanel.add(listScroller,BorderLayout.CENTER);
491    * 
492    * goPanel.add(_createButton, BorderLayout.CENTER);
493    * 
494    * JSplitPane split = new
495    * JSplitPane(JSplitPane.HORIZONTAL_SPLIT,true,_listPanel,vp);
496    * getContentPane().setLayout(new BorderLayout()); getContentPane().add(split,
497    * BorderLayout.CENTER); getContentPane().add(_tools, BorderLayout.NORTH);
498    * 
499    * setVisible(true); DropTarget dt = new DropTarget(vp, this);
500    * 
501    * vp.addVARNAListener(this); }
502    */
503   public static String generateDefaultName()
504   {
505     return "User file #" + _nextID++;
506   }
507
508   public RNA getRNA()
509   {
510     return (RNA) _sideList.getSelectedValue();
511   }
512
513   public String[][] getParameterInfo()
514   {
515     String[][] info =
516     {
517         // Parameter Name Kind of Value Description,
518         { "sequenceDBN", "String", "A raw RNA sequence" },
519         { "structureDBN", "String",
520             "An RNA structure in dot bracket notation (DBN)" },
521         { errorOpt, "boolean", "To show errors" }, };
522     return info;
523   }
524
525   public void init()
526   {
527     vp.setBackground(_backgroundColor);
528     _error = true;
529   }
530
531   @SuppressWarnings("unused")
532   private Color getSafeColor(String col, Color def)
533   {
534     Color result;
535     try
536     {
537       result = Color.decode(col);
538     } catch (Exception e)
539     {
540       try
541       {
542         result = Color.getColor(col, def);
543       } catch (Exception e2)
544       {
545         return def;
546       }
547     }
548     return result;
549   }
550
551   public VARNAPanel get_varnaPanel()
552   {
553     return vp;
554   }
555
556   public void set_varnaPanel(VARNAPanel surface)
557   {
558     vp = surface;
559   }
560
561   public String get_seq()
562   {
563     return _seq.getText();
564   }
565
566   public void set_seq(String _seq)
567   {
568     this._seq.setText(_seq);
569   }
570
571   public String get_str()
572   {
573     return _str.getText();
574   }
575
576   public void set_str(String _str)
577   {
578     this._str.setText(_str);
579   }
580
581   public JLabel get_info()
582   {
583     return _info;
584   }
585
586   public void set_info(JLabel _info)
587   {
588     this._info = _info;
589   }
590
591   /*
592    * public static void main(String[] args) { AppVarnaBinding d = new
593    * AppVarnaBinding(); d.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
594    * d.pack(); d.setVisible(true); }
595    */
596
597   public void dragEnter(DropTargetDragEvent arg0)
598   {
599     // TODO Auto-generated method stub
600
601   }
602
603   public void dragExit(DropTargetEvent arg0)
604   {
605     // TODO Auto-generated method stub
606
607   }
608
609   public void dragOver(DropTargetDragEvent arg0)
610   {
611     // TODO Auto-generated method stub
612
613   }
614
615   public void drop(DropTargetDropEvent dtde)
616   {
617     try
618     {
619       Transferable tr = dtde.getTransferable();
620       DataFlavor[] flavors = tr.getTransferDataFlavors();
621       for (int i = 0; i < flavors.length; i++)
622       {
623         if (flavors[i].isFlavorJavaFileListType())
624         {
625           dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
626           Object ob = tr.getTransferData(flavors[i]);
627           if (ob instanceof List)
628           {
629             List list = (List) ob;
630             for (int j = 0; j < list.size(); j++)
631             {
632               Object o = list.get(j);
633
634               if (dtde.getSource() instanceof DropTarget)
635               {
636                 DropTarget dt = (DropTarget) dtde.getSource();
637                 Component c = dt.getComponent();
638                 if (c instanceof VARNAPanel)
639                 {
640                   String path = o.toString();
641                   VARNAPanel vp = (VARNAPanel) c;
642                   try
643                   {
644                     FullBackup bck = VARNAPanel.importSession(path);
645                     _rnaList.add(bck.config, bck.rna, bck.name, true);
646                   } catch (ExceptionLoadingFailed e3)
647                   {
648                     int mn=1;
649                     Collection<RNA> mdls=fr.orsay.lri.varna.factories.RNAFactory.loadSecStr(path);
650                     for (RNA r:mdls)
651                     {
652                     r.drawRNA(vp.getConfig());
653                     String name = r.getName();
654                     if (name.equals(""))
655                     {
656                       name = path.substring(path
657                               .lastIndexOf(File.separatorChar) + 1);
658                     }
659                     if (mdls.size()>1)
660                     {
661                       name += " (Model "+mn+++")";
662                     }
663                     _rnaList.add(vp.getConfig().clone(), r, name, true);
664                     }
665                   }
666                 }
667               }
668             }
669           }
670           // If we made it this far, everything worked.
671           dtde.dropComplete(true);
672           return;
673         }
674       }
675       // Hmm, the user must not have dropped a file list
676       dtde.rejectDrop();
677     } catch (Exception e)
678     {
679       e.printStackTrace();
680       dtde.rejectDrop();
681     }
682
683   }
684
685   public void dropActionChanged(DropTargetDragEvent arg0)
686   {
687   }
688
689   private class BackupHolder
690   {
691     private DefaultListModel _rnaList;
692
693     private ArrayList<RNA> _rnas = new ArrayList<RNA>();
694
695     JList _l;
696
697     public BackupHolder(DefaultListModel rnaList, JList l)
698     {
699       _rnaList = rnaList;
700       _l = l;
701     }
702
703     public void add(VARNAConfig c, RNA r)
704     {
705       add(c, r, r.getName(), false);
706     }
707
708     public void add(VARNAConfig c, RNA r, boolean select)
709     {
710       add(c, r, r.getName(), select);
711     }
712
713     public void add(VARNAConfig c, RNA r, String name)
714     {
715       add(c, r, name, false);
716     }
717
718     public void add(VARNAConfig c, RNA r, String name, boolean select)
719     {
720       if (select)
721       {
722         _l.removeSelectionInterval(0, _rnaList.size());
723       }
724       if (name.equals(""))
725       {
726         name = generateDefaultName();
727       }
728       FullBackup bck = new FullBackup(c, r, name);
729       _rnas.add(0, r);
730       _rnaList.add(0, bck);
731       if (select)
732       {
733         _l.setSelectedIndex(0);
734       }
735     }
736
737     public void remove(int i)
738     {
739       _rnas.remove(i);
740       _rnaList.remove(i);
741
742     }
743
744     public DefaultListModel getModel()
745     {
746       return _rnaList;
747     }
748
749     public boolean contains(RNA r)
750     {
751       return _rnas.contains(r);
752     }
753
754     /*
755      * public int getSize() { return _rnaList.getSize(); }
756      */
757     public FullBackup getElementAt(int i)
758     {
759       return (FullBackup) _rnaList.getElementAt(i);
760     }
761
762     public void removeSelected()
763     {
764       int i = _l.getSelectedIndex();
765       if (i != -1)
766       {
767         if (_rnaList.getSize() == 1)
768         {
769           RNA r = new RNA();
770           try
771           {
772             r.setRNA(" ", ".");
773           } catch (ExceptionUnmatchedClosingParentheses e1)
774           {
775           } catch (ExceptionFileFormatOrSyntax e1)
776           {
777           }
778           vp.showRNA(r);
779           vp.repaint();
780         }
781         else
782         {
783           int newi = i + 1;
784           if (newi == _rnaList.getSize())
785           {
786             newi = _rnaList.getSize() - 2;
787           }
788           FullBackup bck = (FullBackup) _rnaList.getElementAt(newi);
789           _l.setSelectedValue(bck, true);
790         }
791         _rnaList.remove(i);
792       }
793
794     }
795   }
796
797   public void onLayoutChanged()
798   {
799     // TODO Auto-generated method stub
800
801   }
802
803   public void onUINewStructure(VARNAConfig v, RNA r)
804   {
805     _rnaList.add(v, r, "", true);
806   }
807
808   public void onWarningEmitted(String s)
809   {
810     // TODO Auto-generated method stub
811
812   }
813
814   public void mouseClicked(MouseEvent e)
815   {
816     if (e.getClickCount() == 2)
817     {
818       int index = _sideList.locationToIndex(e.getPoint());
819       ListModel dlm = _sideList.getModel();
820       FullBackup item = (FullBackup) dlm.getElementAt(index);
821       ;
822       _sideList.ensureIndexIsVisible(index);
823       /*
824        * TODO Object newName = JOptionPane.showInputDialog( this,
825        * "Specify a new name for this RNA", "Rename RNA",
826        * JOptionPane.QUESTION_MESSAGE, (Icon)null, null, item.toString()); if
827        * (newName!=null) { item.name = newName.toString();
828        * this._sideList.repaint(); }
829        */
830     }
831   }
832
833   public void mouseEntered(MouseEvent arg0)
834   {
835     // TODO Auto-generated method stub
836
837   }
838
839   public void mouseExited(MouseEvent arg0)
840   {
841     // TODO Auto-generated method stub
842
843   }
844
845   public void mousePressed(MouseEvent arg0)
846   {
847     // TODO Auto-generated method stub
848
849   }
850
851   public void mouseReleased(MouseEvent arg0)
852   {
853     // TODO Auto-generated method stub
854
855   }
856
857   @Override
858   public Color getColour(int atomIndex, int pdbResNum, String chain,
859           String pdbId)
860   {
861     // TODO Auto-generated method stub
862     return null;
863   }
864
865   @Override
866   public String[] getPdbFile()
867   {
868     // TODO Auto-generated method stub
869     return null;
870   }
871
872   @Override
873   public void highlightAtom(int atomIndex, int pdbResNum, String chain,
874           String pdbId)
875   {
876     // TODO Auto-generated method stub
877
878   }
879
880   @Override
881   public void mouseOverStructure(int atomIndex, String strInfo)
882   {
883     // TODO Auto-generated method stub
884
885   }
886
887   @Override
888   public void releaseReferences(Object svl)
889   {
890     // TODO Auto-generated method stub
891
892   }
893
894   @Override
895   public void updateColours(Object source)
896   {
897     // TODO Auto-generated method stub
898
899   }
900
901   @Override
902   public void componentHidden(ComponentEvent e)
903   {
904     // TODO Auto-generated method stub
905
906   }
907
908   @Override
909   public void componentMoved(ComponentEvent e)
910   {
911     // TODO Auto-generated method stub
912
913   }
914
915   @Override
916   public void componentResized(ComponentEvent e)
917   {
918     // TODO Auto-generated method stub
919
920   }
921
922   @Override
923   public void componentShown(ComponentEvent e)
924   {
925     // TODO Auto-generated method stub
926
927   }
928
929   @Override
930   public void onStructureRedrawn()
931   {
932     // TODO Auto-generated method stub
933
934   }
935 }
936
937 /*
938  * public static void main(String[] args) { JTextField str = new
939  * JTextField("ATGC");
940  * 
941  * AppVarnaBinding vab = new AppVarnaBinding(); vab.varnagui.set_seq(str);
942  * vab.varnagui.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
943  * vab.varnagui.pack(); vab.varnagui.setVisible(true); } }
944  */