1 package fr.orsay.lri.varna;
3 VARNA is a tool for the automated drawing, visualization and annotation of the secondary structure of RNA, designed as a companion software for web servers and databases.
4 Copyright (C) 2008 Kevin Darty, Alain Denise and Yann Ponty.
5 electronic mail : Yann.Ponty@lri.fr
6 paper mail : LRI, bat 490 Université Paris-Sud 91405 Orsay Cedex France
8 This file is part of VARNA version 3.1.
9 VARNA version 3.1 is free software: you can redistribute it and/or modify it under the terms of the GNU General Public License
10 as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
12 VARNA version 3.1 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
13 without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
14 See the GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License along with VARNA version 3.1.
17 If not, see http://www.gnu.org/licenses.
19 import java.awt.Component;
20 import java.awt.GridLayout;
21 import java.awt.datatransfer.DataFlavor;
22 import java.awt.datatransfer.Transferable;
23 import java.awt.dnd.DnDConstants;
24 import java.awt.dnd.DropTarget;
25 import java.awt.dnd.DropTargetDragEvent;
26 import java.awt.dnd.DropTargetDropEvent;
27 import java.awt.dnd.DropTargetEvent;
28 import java.awt.dnd.DropTargetListener;
30 import java.io.FileReader;
31 import java.io.IOException;
32 import java.util.ArrayList;
33 import java.util.List;
35 import javax.swing.JApplet;
36 import javax.swing.JOptionPane;
38 import fr.orsay.lri.varna.controlers.ControleurScriptParser;
39 import fr.orsay.lri.varna.exceptions.ExceptionFileFormatOrSyntax;
40 import fr.orsay.lri.varna.exceptions.ExceptionLoadingFailed;
41 import fr.orsay.lri.varna.exceptions.ExceptionModeleStyleBaseSyntaxError;
42 import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength;
43 import fr.orsay.lri.varna.exceptions.ExceptionParameterError;
44 import fr.orsay.lri.varna.interfaces.InterfaceParameterLoader;
45 import fr.orsay.lri.varna.models.VARNAConfigLoader;
46 import fr.orsay.lri.varna.models.rna.RNA;
49 // @j2s issues -- see README_SWINGJS.txt
51 public class VARNA extends JApplet implements InterfaceParameterLoader,DropTargetListener {
52 ArrayList<VARNAPanel> _vpl = null;
59 * if (!thisApplet.__Info.sequenceDBN) {
60 * thisApplet.__Info.sequenceDBN = "GGGGCCAAUAUGGCCAUCC";
61 * thisApplet.__Info.structureDBN = "((((((.....))))..))";
62 * thisApplet.__Info.title = "Hello RNA world, from SwingJS!";//prompt("Title?","Hello RNA world!");
71 // private static final_long serialVersionUID = -2598221520127067670L;
79 VARNAConfigLoader VARNAcfg = new VARNAConfigLoader(this);
82 _vpl = VARNAcfg.createVARNAPanels();
83 for (int i=0;i<_vpl.size();i++)
85 new DropTarget(_vpl.get(i), this);
87 } catch (IOException e) {
88 JOptionPane.showMessageDialog(this, e.getMessage(),
89 "VARNA Error", JOptionPane.ERROR_MESSAGE);
90 } catch (ExceptionFileFormatOrSyntax e) {
91 JOptionPane.showMessageDialog(this, e.getMessage(),
92 "VARNA Error", JOptionPane.ERROR_MESSAGE);
93 } catch (ExceptionLoadingFailed e) {
94 JOptionPane.showMessageDialog(this, e.getMessage(),
95 "VARNA Error", JOptionPane.ERROR_MESSAGE);
97 setLayout(new GridLayout(VARNAcfg.getNbColumns(), VARNAcfg
99 for (int i = 0; i < _vpl.size(); i++) {
100 getContentPane().add(_vpl.get(i));
102 } catch (ExceptionParameterError e) {
103 VARNAPanel.errorDialogStatic(e, this);
104 } catch (ExceptionModeleStyleBaseSyntaxError e) {
105 VARNAPanel.errorDialogStatic(e, this);
106 } catch (ExceptionNonEqualLength e) {
107 VARNAPanel.errorDialogStatic(e, this);
112 public void start() {
115 //getContentPane().setVisible(true);
116 //getContentPane().repaint();
119 public void update() {
120 System.out.println("update");
123 public String getParameterValue(String key, String def) {
124 if (getParameter(key) == null) {
127 return getParameter(key);
131 public String[][] getParameterInfo() {
132 return VARNAConfigLoader.getParameterInfo();
135 public ArrayList<VARNAPanel> getPanels()
140 public String getSelection()
142 return getSelection(0);
145 public String getSelection(int panel)
148 VARNAPanel v = _vpl.get(panel);
149 List<Integer> l = v.getSelectionIndices();
150 for(int i=0;i<l.size();i++)
162 public void runScript(String script)
166 VARNAPanel _vp = _vpl.get(0);
168 ControleurScriptParser.executeScript(_vp, script);
169 } catch (Exception e) {
176 public void setRNA(String seq, String str)
181 _vpl.get(0).drawRNA(seq, str);
182 } catch (ExceptionNonEqualLength e) {
188 public void setSmoothedRNA(String seq, String str)
194 _vpl.get(0).drawRNAInterpolated(seq, str);
195 _vpl.get(0).repaint();
196 } catch (ExceptionNonEqualLength e) {
197 // TODO Auto-generated catch block
203 public void dragEnter(DropTargetDragEvent arg0) {
206 public void dragExit(DropTargetEvent arg0) {
209 public void dragOver(DropTargetDragEvent arg0) {
212 public void drop(DropTargetDropEvent dtde)
216 Transferable tr = dtde.getTransferable();
217 DataFlavor[] flavors = tr.getTransferDataFlavors();
218 for (int i = 0; i < flavors.length; i++)
220 if (flavors[i].isFlavorJavaFileListType())
222 dtde.acceptDrop(DnDConstants.ACTION_COPY_OR_MOVE);
223 List list = (List) tr.getTransferData(flavors[i]);
224 for (int j = 0; j < list.size(); j++)
226 Object o = list.get(j);
227 if (dtde.getSource() instanceof DropTarget)
229 DropTarget dt = (DropTarget) dtde.getSource();
230 Component c = dt.getComponent();
231 if (c instanceof VARNAPanel)
233 VARNAPanel vp = (VARNAPanel) c;
234 // BH -- in JavaScript, the File object has a .bytes
235 // property that we need to maintain.
236 //String path = o.toString();
237 vp.loadFile((File) o,true);
238 //vp.repaint(); BH unnecessary
242 dtde.dropComplete(true);
255 public void dropActionChanged(DropTargetDragEvent arg0) {