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
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.
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.
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.
18 package fr.orsay.lri.varna.controlers;
20 import java.awt.Point;
21 import java.awt.event.FocusEvent;
22 import java.awt.event.FocusListener;
23 import java.awt.event.KeyEvent;
24 import java.awt.event.KeyListener;
25 import java.awt.event.MouseEvent;
26 import java.awt.event.MouseListener;
27 import java.awt.geom.Point2D;
29 import fr.orsay.lri.varna.VARNAPanel;
30 import fr.orsay.lri.varna.views.VueUI;
34 * VARNAPanel Shortcuts Controller
39 public class ControleurVARNAPanelKeys implements KeyListener, FocusListener {
41 private VARNAPanel _vp;
44 public ControleurVARNAPanelKeys(VARNAPanel vp) {
48 public void mouseClicked(MouseEvent e) {
51 public void mouseEntered(MouseEvent e) {
57 public void mouseExited(MouseEvent e) {
60 public void mousePressed(MouseEvent e) {
63 public void mouseReleased(MouseEvent e) {
66 public void keyPressed(KeyEvent e) {
67 boolean controlDown = (e.getModifiersEx() & (KeyEvent.CTRL_DOWN_MASK)) == KeyEvent.CTRL_DOWN_MASK;
68 boolean shiftDown = (e.getModifiersEx() & (KeyEvent.SHIFT_DOWN_MASK)) == KeyEvent.SHIFT_DOWN_MASK;
69 boolean altDown = (e.getModifiersEx() & (KeyEvent.ALT_DOWN_MASK)) == KeyEvent.ALT_DOWN_MASK;
70 VueUI ui = _vp.getVARNAUI();
72 switch (e.getKeyCode()) {
84 ui.UIToggleDrawBackbone();
88 if (shiftDown && controlDown) {
89 ui.UISetColorMapCaption();
95 ui.UIPickGapsBasesColor();
97 ui.UIToggleColorGapsBases();
101 case (KeyEvent.VK_E):
103 ui.UIToggleShowNonPlanar();
106 case (KeyEvent.VK_F):
108 ui.UIToggleFlatExteriorLoop();
111 case (KeyEvent.VK_G):
113 ui.UISetBackground();
115 else if (!shiftDown && altDown) {
116 ui.UIToggleGaspinMode();
119 case (KeyEvent.VK_H):
120 if (controlDown && !shiftDown) {
121 ui.UISetBPHeightIncrement();
123 else if (controlDown && shiftDown)
125 Point2D.Double p = _vp.getLastSelectedPosition();
126 ui.UIAnnotationsAddPosition((int)p.x,(int)p.y);
129 case (KeyEvent.VK_J):
132 ui.UIPickSpecialBasesColor();
134 ui.UIToggleColorSpecialBases();
138 case (KeyEvent.VK_K):
139 if (controlDown && shiftDown) {
140 ui.UILoadColorMapValues();
142 else if (controlDown) {
143 ui.UISetBackboneColor();
146 case (KeyEvent.VK_L):
147 if (shiftDown && controlDown) {
148 ui.UIToggleColorMap();
149 } else if (controlDown)
151 ui.UISetColorMapStyle();
152 } else if (shiftDown)
154 ui.UISetColorMapValues();
157 case (KeyEvent.VK_M):
160 } else if (shiftDown && altDown) {
161 ui.UIToggleModifiable();
164 case (KeyEvent.VK_N):
169 case (KeyEvent.VK_O):
174 case (KeyEvent.VK_P):
175 if (controlDown && shiftDown) {
178 else if (controlDown && !shiftDown) {
182 case (KeyEvent.VK_Q):
183 if (controlDown && !shiftDown && !altDown) {
184 _vp.getVARNAUI().UIAutoAnnotateHelices();
186 else if (controlDown && shiftDown && !altDown) {
187 _vp.getVARNAUI().UIAutoAnnotateTerminalLoops();
189 else if (!controlDown && shiftDown && altDown) {
190 _vp.getVARNAUI().UIAutoAnnotateInteriorLoops();
192 else if (controlDown && !shiftDown && altDown) {
193 _vp.getVARNAUI().UIAutoAnnotateStrandEnds();
196 case (KeyEvent.VK_R):
201 ui.UIGlobalRotation();
205 case (KeyEvent.VK_S):
208 ui.UISetSpaceBetweenBases();
214 case (KeyEvent.VK_T):
218 } else if (altDown) {
219 ui.UISetTitleColor();
225 case (KeyEvent.VK_U):
226 if (controlDown && !shiftDown && !altDown) {
227 _vp.getVARNAUI().UIBaseTypeColor();
228 } else if (!controlDown && shiftDown && !altDown) {
229 _vp.getVARNAUI().UIBasePairTypeColor();
230 } else if (!controlDown && !shiftDown && altDown) {
231 _vp.getVARNAUI().UIBaseAllColor();
234 case (KeyEvent.VK_W):
236 ui.UIToggleShowNCBP();
239 case (KeyEvent.VK_X):
244 case (KeyEvent.VK_Y):
250 case (KeyEvent.VK_Z):
251 if (controlDown && !shiftDown) {
254 else if (controlDown && shiftDown) {
257 else if (!controlDown && !shiftDown) {
261 case (KeyEvent.VK_1):
266 case (KeyEvent.VK_2):
271 case (KeyEvent.VK_3):
276 case (KeyEvent.VK_4):
281 case (KeyEvent.VK_5):
286 case (KeyEvent.VK_6):
292 // Navigation control keys (Zoom in/out, arrow keys ...)
293 case (KeyEvent.VK_DOWN):
294 if (_vp.getZoom() > 1) {
295 _vp.setTranslation(new Point(_vp.getTranslation().x,_vp.getTranslation().y-5));
296 _vp.checkTranslation();
299 case (KeyEvent.VK_UP):
300 if (_vp.getZoom() > 1) {
301 _vp.setTranslation(new Point(_vp.getTranslation().x,_vp.getTranslation().y+5));
302 _vp.checkTranslation();
305 case (KeyEvent.VK_LEFT):
306 if (_vp.getZoom() > 1) {
307 _vp.setTranslation(new Point(_vp.getTranslation().x+5,_vp.getTranslation().y));
308 _vp.checkTranslation();
311 case (KeyEvent.VK_RIGHT):
312 if (_vp.getZoom() > 1) {
313 _vp.setTranslation(new Point(_vp.getTranslation().x-5,_vp.getTranslation().y));
314 _vp.checkTranslation();
317 case (KeyEvent.VK_EQUALS):
318 case (KeyEvent.VK_PLUS):
321 case (KeyEvent.VK_MINUS):
325 } catch (Exception e1) {
332 * if ((e.getKeyCode() == KeyEvent.VK_PLUS)||(e.getKeyChar() == '+')) {
333 * _vp.getVARNAUI().UIZoomIn(); } else if (e.getKeyCode() ==
334 * KeyEvent.VK_MINUS) { _vp.getVARNAUI().UIZoomOut(); } // 1 pour Redraw
335 * Radiate else if (e.getKeyChar() == KeyEvent.VK_1) {
336 * _vp.getVARNAUI().UIRadiate(); } // 2 pour Redraw Circular else if
337 * (e.getKeyChar() == KeyEvent.VK_2) { _vp.getVARNAUI().UICircular(); } // 3
338 * pour Redraw NAView else if (e.getKeyChar() == KeyEvent.VK_3) {
339 * _vp.getVARNAUI().UINAView(); }
341 * // 4 for RNA on a line else if (e.getKeyChar() == KeyEvent.VK_4) {
342 * _vp.getVARNAUI().UILine(); } // 5 fun arn random coord else if
343 * (e.isControlDown() && e.getKeyChar() == KeyEvent.VK_9) { for (int i = 0;
344 * i < _vp.getRNA().get_listeBases().size(); i++) {
345 * _vp.getRNA().get_listeBases().get(i).set_coords( new
346 * Point2D.Double(_vp.getWidth() * Math.random(), _vp.getHeight() *
347 * Math.random())); _vp.getRNA().get_listeBases().get(i).set_center( new
348 * Point2D.Double(_vp.getWidth() / 2 Math.random(), _vp.getHeight() / 2
349 * Math.random())); } } // 6 fun random arn structure else if
350 * (e.isControlDown() & e.getKeyChar() == KeyEvent.VK_8) { try {
351 * _vp.drawRNA(_vp.getRNA().getListeBasesToString(), getRandomRNA(), _vp
352 * .getRNA().get_drawMode()); } catch (ExceptionNonEqualLength e1) {
353 * _vp.errorDialog(e1); } } _vp.repaint(); }
356 public String getRandomRNA() {
357 int pile = 0, j, i = 0;
361 if (Math.random() > 0.5) {
363 l = Math.random() * 10;
370 if (Math.random() > 0.5 && pile > 0) {
372 l = Math.random() * 5;
373 while (j < l && pile > 0) {
381 l = Math.random() * 5;
399 public void keyReleased(KeyEvent e) {
402 public void keyTyped(KeyEvent e) {
405 public void focusGained(FocusEvent arg0) {
409 public void focusLost(FocusEvent arg0) {