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