JAL-3026 srcjar files for VARNA and log4j
[jalview.git] / srcjar / fr / orsay / lri / varna / views / VueAboutPanel.java
1 /*
2  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.
3  Copyright (C) 2008  Kevin Darty, Alain Denise and Yann Ponty.
4  electronic mail : Yann.Ponty@lri.fr
5  paper mail : LRI, bat 490 Université Paris-Sud 91405 Orsay Cedex France
6
7  This file is part of VARNA version 3.1.
8  VARNA version 3.1 is free software: you can redistribute it and/or 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  VARNA version 3.1 is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
12  without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
13  See the GNU General Public License for more details.
14
15  You should have received a copy of the GNU General Public License along with VARNA version 3.1.
16  If not, see http://www.gnu.org/licenses.
17  */
18 package fr.orsay.lri.varna.views;
19
20 import java.awt.BorderLayout;
21 import java.awt.Color;
22 import java.awt.Dimension;
23 import java.awt.event.ActionEvent;
24 import java.awt.event.ActionListener;
25 import java.util.ArrayList;
26
27 import javax.swing.BorderFactory;
28 import javax.swing.JPanel;
29 import javax.swing.JTextArea;
30 import javax.swing.Timer;
31
32 import fr.orsay.lri.varna.VARNAPanel;
33 import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength;
34 import fr.orsay.lri.varna.models.VARNAConfig;
35
36 /**
37  * BH j2s SwingJS replaces thread with simple javax.swing.Timer
38  * 
39  */
40 public class VueAboutPanel extends JPanel {
41
42         /**
43          * 
44          */
45         private static final long serialVersionUID = 4525998278180950602L;
46
47         private AboutAnimator _anim;
48         private JPanel _textPanel;
49         private JTextArea _textArea;
50
51         public VueAboutPanel() {
52                 init();
53         }
54
55         private void init() {
56                 try {
57                         setBorder(BorderFactory.createEtchedBorder());
58                         setLayout(new BorderLayout());
59                         setBackground(Color.WHITE);
60
61                         String message = "VARNA "
62                                         + VARNAConfig.MAJOR_VERSION
63                                         + "."
64                                         + VARNAConfig.MINOR_VERSION
65                                         + "\n"
66                                         + "\n"
67                                         + "Created by: Kevin Darty, Alain Denise and Yann Ponty\n"
68                                         + "Contact: ponty@lri.fr\n"
69                                         + "\n"
70                                         + "VARNA is freely distributed under the terms of the GNU GPL 3.0 license.\n"
71                                         + "\n"
72                                         + "Supported by the BRASERO project (ANR-06-BLAN-0045)\n";
73
74                         _textArea = new JTextArea();
75                         _textArea.setText(message);
76                         _textArea.setEditable(false);
77
78                         _textPanel = new JPanel();
79                         _textPanel.setBackground(Color.WHITE);
80                         _textPanel.setLayout(new BorderLayout());
81                         _textPanel.setBorder(BorderFactory.createMatteBorder(0, 15, 0, 15,
82                                         getBackground()));
83                         _textPanel.add(_textArea);
84
85                         VARNAPanel vp = new VARNAPanel("GGGGAAAACCCC", "((((....))))");
86                         vp.setModifiable(false);
87                         vp.setPreferredSize(new Dimension(100, 100));
88                         // vp.setBorder(BorderFactory.createLineBorder(Color.gray));
89
90                         _anim = new AboutAnimator(vp);
91                         _anim
92                                         .addRNA("GGGGAAGGGGAAAACCCCAACCCC",
93                                                         "((((..((((....))))..))))");
94                         _anim.addRNA("GGGGAAGGGGAAGGGGAAAACCCCAACCCCAACCCC",
95                                         "((((..((((..((((....))))..))))..))))");
96                         _anim
97                                         .addRNA(
98                                                         "GGGGAGGGGAAAACCCCAGGGGAGGGGAAAACCCCAGGGGAAAACCCCAGGGGAAAACCCCACCCCAGGGGAAAACCCCACCCC",
99                                                         "((((.((((....)))).((((.((((....)))).((((....)))).((((....)))).)))).((((....)))).))))");
100                         _anim
101                                         .addRNA(
102                                                         "GGGGGGGGAAAACCCCAGGGGAAAACCCCAGGGGGGGGAAAACCCCAGGGGAAAACCCCAGGGGAAAACCCCAGGGGAAAACCCCGGGGAAAACCCCACCCCAGGGGAAAACCCCAGGGGAAAACCCCCCCC",
103                                                         "((((((((....)))).((((....)))).((((((((....)))).((((....)))).((((....)))).((((....))))((((....)))).)))).((((....)))).((((....))))))))");
104                         _anim.addRNA("GGGGAAAACCCC", "((((....))))");
105                         _anim.addRNA("GGGGAAGGGGAAAACCCCAGGGGAAAACCCCACCCC",
106                                         "((((..((((....)))).((((....)))).))))");
107                         _anim.addRNA("GGGGAGGGGAAAACCCCAGGGGAAAACCCCAGGGGAAAACCCCACCCC",
108                                         "((((.((((....)))).((((....)))).((((....)))).))))");
109                         _anim
110                                         .addRNA(
111                                                         "GGGGAGGGGAAAAAAACCCCAGGGGAAAAAAACCCCAGGGGAAAAAAACCCCACCCC",
112                                                         "((((.((((.......)))).((((.......)))).((((.......)))).))))");
113                         _anim.start();
114
115                         add(vp, BorderLayout.WEST);
116                         add(_textPanel, BorderLayout.CENTER);
117                 } catch (ExceptionNonEqualLength e) {
118                 }
119         }
120
121         public void gracefulStop() {
122                 _anim.gracefulStop();
123         }
124
125         private class AboutAnimator implements ActionListener {
126                 VARNAPanel _vp;
127                 ArrayList<String> _structures = new ArrayList<String>();
128                 ArrayList<String> _sequences = new ArrayList<String>();
129                 int _period = 2000;
130                 boolean _over = false;
131
132                 public AboutAnimator(VARNAPanel vp) {
133                         super();
134                         _vp = vp;
135                 }
136
137                 /**
138                  * mode pointer for timer cycle -- DELAY1, TASK, DELAY2, STOP
139                  */
140                 int mode = 0;
141                 
142                 /**
143                  * modes for run()
144                  * 
145                  */
146                 final int DELAY1 = 0, TASK = 1, DELAY2 = 2, STOP = 3;
147                 int i = 0;
148
149                 @Override
150                 public void actionPerformed(ActionEvent e) {
151                         run();
152                 }
153
154                 public void start() {
155                         int mode = DELAY1;
156                         run();
157                 }
158
159                 public void addRNA(String seq, String str) {
160                         _sequences.add(seq);
161                         _structures.add(str);
162                 }
163
164                 public void gracefulStop() {
165                         _over = true;
166                 }
167
168                 public void run() {
169                         int initialDelay;
170                         if (_over)
171                                 mode = STOP;
172                         switch (mode) {
173                         case DELAY1:
174                                 mode = TASK;
175                                 initialDelay = _period;
176                                 break;
177                         case TASK:
178                                 String seq = _sequences.get(i);
179                                 String str = _structures.get(i);
180                                 try {
181                                         _vp.drawRNAInterpolated(seq, str);
182                                         mode = DELAY2;
183                                         initialDelay = 500;
184                                 } catch (ExceptionNonEqualLength e) {
185                                         initialDelay = -1;
186                                 }
187                                 break;
188                         case DELAY2:
189                                 i = (i + 1) % _sequences.size();
190                                 mode = DELAY1;
191                                 initialDelay = 0;
192                                 break;
193                         case STOP:
194                         default:
195                                 initialDelay = -1;
196                                 break;
197                         }
198                         if (initialDelay >= 0) {
199                                 Timer t = new Timer(initialDelay, this);
200                                 t.setDelay(0);
201                                 t.setRepeats(false);
202                                 t.start();
203                         } else {
204                                 System.out.println("VueAbout done");
205                         }
206
207                 }
208         }
209
210 }