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