1 package fr.orsay.lri.varna.applications;
4 VARNA is a Java library for quick automated drawings RNA secondary structure
5 Copyright (C) 2007 Yann Ponty
7 This program is free software:you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 import java.awt.BorderLayout;
22 import java.awt.Color;
23 import java.awt.Dimension;
25 import java.awt.GridLayout;
26 import java.awt.event.ActionEvent;
27 import java.awt.event.ActionListener;
29 import javax.swing.JApplet;
30 import javax.swing.JButton;
31 import javax.swing.JLabel;
32 import javax.swing.JPanel;
33 import javax.swing.JTextField;
35 import fr.orsay.lri.varna.VARNAPanel;
36 import fr.orsay.lri.varna.components.VARNAConsole;
37 import fr.orsay.lri.varna.controlers.ControleurDemoTextField;
38 import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength;
39 import fr.orsay.lri.varna.models.rna.RNA;
42 * An RNA 2d Panel demo applet
44 * @author Yann Ponty & Darty Kévin
48 public class VARNAConsoleDemo extends JApplet implements ActionListener {
53 private static final long serialVersionUID = -790155708306987257L;
55 private static final String DEFAULT_SEQUENCE = "CAGCACGACACUAGCAGUCAGUGUCAGACUGCAIACAGCACGACACUAGCAGUCAGUGUCAGACUGCAIACAGCACGACACUAGCAGUCAGUGUCAGACUGCAIA";
57 private static final String DEFAULT_STRUCTURE = "..(((((...(((((...(((((...(((((.....)))))...))))).....(((((...(((((.....)))))...))))).....)))))...)))))..";
59 private VARNAPanel _vp;
61 private JPanel _tools = new JPanel();
62 private JPanel _input = new JPanel();
64 private JPanel _seqPanel = new JPanel();
65 private JPanel _structPanel = new JPanel();
66 private JLabel _info = new JLabel();
67 private JButton _go = new JButton("Go");
68 private JTextField _struct = new JTextField();
69 private JTextField _seq = new JTextField();
70 private JLabel _structLabel = new JLabel(" Str:");
71 private JLabel _seqLabel = new JLabel(" Seq:");
73 private VARNAConsole _console;
75 private static String errorOpt = "error";
76 private boolean _error;
78 private Color _backgroundColor = Color.white;
80 private int _algoCode;
82 public VARNAConsoleDemo() {
85 _vp = new VARNAPanel(_seq.getText(), _struct.getText());
86 _vp.setErrorsOn(false);
87 } catch (ExceptionNonEqualLength e) {
93 private void RNAPanelDemoInit() {
98 setBackground(_backgroundColor);
99 _vp.setBackground(_backgroundColor);
102 _vp.getRNA().setRNA(_seq.getText(), _struct.getText());
103 _vp.setErrorsOn(false);
104 } catch (Exception e1) {
108 Font textFieldsFont = Font.decode("MonoSpaced-PLAIN-12");
110 _console = new VARNAConsole(_vp);
113 _go.addActionListener(this);
115 _seqLabel.setHorizontalTextPosition(JLabel.LEFT);
116 _seqLabel.setPreferredSize(new Dimension(marginTools, 15));
117 _seq.setFont(textFieldsFont);
118 _seq.setText(_vp.getRNA().getSeq());
120 _seqPanel.setLayout(new BorderLayout());
121 _seqPanel.add(_seqLabel, BorderLayout.WEST);
122 _seqPanel.add(_seq, BorderLayout.CENTER);
124 _structLabel.setPreferredSize(new Dimension(marginTools, 15));
125 _structLabel.setHorizontalTextPosition(JLabel.LEFT);
126 _struct.setFont(textFieldsFont);
127 _struct.setText(_vp.getRNA().getStructDBN());
128 _structPanel.setLayout(new BorderLayout());
129 _structPanel.add(_structLabel, BorderLayout.WEST);
130 _structPanel.add(_struct, BorderLayout.CENTER);
133 _input.setLayout(new GridLayout(3, 0));
134 _input.add(_seqPanel);
135 _input.add(_structPanel);
137 _tools.setLayout(new BorderLayout());
138 _tools.add(_input, BorderLayout.CENTER);
139 _tools.add(_info, BorderLayout.SOUTH);
140 _tools.add(_go, BorderLayout.EAST);
142 getContentPane().setLayout(new BorderLayout());
143 getContentPane().add(_vp, BorderLayout.CENTER);
144 getContentPane().add(_tools, BorderLayout.SOUTH);
146 _vp.getVARNAUI().UIRadiate();
147 setPreferredSize(new Dimension(400,400));
151 _console.setVisible(true);
155 public String[][] getParameterInfo() {
157 // Parameter Name Kind of Value Description,
158 { "sequenceDBN", "String", "A raw RNA sequence" },
159 { "structureDBN", "String",
160 "An RNA structure in dot bracket notation (DBN)" },
161 { errorOpt, "boolean", "To show errors" }, };
166 retrieveParametersValues();
167 _vp.setBackground(_backgroundColor);
171 private Color getSafeColor(String col, Color def) {
174 result = Color.decode(col);
175 } catch (Exception e) {
177 result = Color.getColor(col, def);
178 } catch (Exception e2) {
185 private String getParameterValue(String key, String def) {
187 tmp = getParameter(key);
195 private void retrieveParametersValues() {
196 _error = Boolean.parseBoolean(getParameterValue(errorOpt, "false"));
197 _vp.setErrorsOn(_error);
198 _backgroundColor = getSafeColor(getParameterValue("background",
199 _backgroundColor.toString()), _backgroundColor);
200 _vp.setBackground(_backgroundColor);
201 _seq.setText(getParameterValue("sequenceDBN", ""));
202 _struct.setText(getParameterValue("structureDBN", ""));
203 String _algo = getParameterValue("algorithm", "radiate");
204 if (_algo.equals("circular"))
205 _algoCode = RNA.DRAW_MODE_CIRCULAR;
206 else if (_algo.equals("naview"))
207 _algoCode = RNA.DRAW_MODE_NAVIEW;
208 else if (_algo.equals("line"))
209 _algoCode = RNA.DRAW_MODE_LINEAR;
211 _algoCode = RNA.DRAW_MODE_RADIATE;
212 if (_seq.getText().equals("") && _struct.getText().equals("")) {
213 _seq.setText(DEFAULT_SEQUENCE);
214 _struct.setText(DEFAULT_STRUCTURE);
217 _vp.drawRNA(_seq.getText(), _struct.getText(), _algoCode);
218 } catch (ExceptionNonEqualLength e) {
224 public VARNAPanel get_varnaPanel() {
228 public void set_varnaPanel(VARNAPanel surface) {
232 public JTextField get_struct() {
236 public void set_struct(JTextField _struct) {
237 this._struct = _struct;
240 public JTextField get_seq() {
244 public void set_seq(JTextField _seq) {
248 public JLabel get_info() {
252 public void set_info(JLabel _info) {
256 public void actionPerformed(ActionEvent arg0) {
259 _vp.drawRNAInterpolated(_seq.getText(), _struct.getText());
260 } catch (ExceptionNonEqualLength e) {
261 // TODO Auto-generated catch block