JAL-3032 adds Java 8 functionality (2/2)
[jalview.git] / src2 / fr / orsay / lri / varna / controlers / ControleurMenu.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.controlers;
19
20
21 import java.awt.Color;
22 import java.awt.event.ActionEvent;
23 import java.awt.event.ActionListener;
24 import java.io.File;
25 import java.text.ParseException;
26 import java.util.ArrayList;
27
28 import javax.swing.JCheckBoxMenuItem;
29 import javax.swing.JColorChooser;
30 import javax.swing.JOptionPane;
31
32 import fr.orsay.lri.varna.VARNAPanel;
33 import fr.orsay.lri.varna.exceptions.ExceptionExportFailed;
34 import fr.orsay.lri.varna.exceptions.ExceptionJPEGEncoding;
35 import fr.orsay.lri.varna.exceptions.ExceptionNonEqualLength;
36 import fr.orsay.lri.varna.exceptions.ExceptionPermissionDenied;
37 import fr.orsay.lri.varna.exceptions.ExceptionWritingForbidden;
38 import fr.orsay.lri.varna.interfaces.InterfaceVARNAListener;
39 import fr.orsay.lri.varna.models.VARNAConfig;
40 import fr.orsay.lri.varna.models.annotations.TextAnnotation;
41 import fr.orsay.lri.varna.models.rna.ModeleBase;
42 import fr.orsay.lri.varna.models.rna.ModeleBP;
43 import fr.orsay.lri.varna.models.rna.RNA;
44 import fr.orsay.lri.varna.views.VueBPThickness;
45 import fr.orsay.lri.varna.views.VueMenu;
46
47 /**
48  * This listener controls menu items
49  * 
50  * @author darty
51  * 
52  */
53 public class ControleurMenu implements InterfaceVARNAListener,
54                 ActionListener {
55
56         private VARNAPanel _vp;
57         @SuppressWarnings("unused")
58         private VueMenu _vm;
59         private String _type;
60         private String _color;
61         private Object _source;
62
63         /**
64          * Creates the menu listener
65          * 
66          * @param _varnaPanel
67          *            The VARNAPanel
68          */
69         public ControleurMenu(VARNAPanel _varnaPanel, VueMenu _vueMenu) {
70                 _vp = _varnaPanel;
71                 _vm = _vueMenu;
72                 _vp.getRNA().addVARNAListener(this);
73         }
74
75         public void actionPerformed(ActionEvent e) {
76                 String[] temp = e.getActionCommand().split(",");
77                 _source = e.getSource();
78                 _type = temp[0];
79                 if (temp.length > 1)
80                         _color = temp[1];
81                 else
82                         _color = "";
83                 // selon l'option choisie dans le menu:
84                 if (!optionRedraw())
85                         if (!optionExport())
86                                 if (!optionImport())
87                                         if (!optionRNADisplay())
88                                                 if (!optionTitle())
89                                                         if (!optionColorMap())
90                                                                 if (!optionView())
91                                                                         if (!optionBase())
92                                                                                 if (!optionBasePair())
93                                                                                         if (!optionLoop())
94                                                                                                 if (!option3prime())
95                                                                                                         if (!option5prime())
96                                                                                                                 if (!optionHelix())
97                                                                                                                         if (!optionStem())
98                                                                                                                                 if (!optionBulge())
99                                                                                                                                         if (!optionAnnotation())
100                                                                                                                                                 if (!optionEditRNA())
101                                                                                                                                                         _vp.errorDialog(new Exception("Uknown action command '"+_type+"'"));
102         }
103         
104         private boolean optionEditRNA()
105         {
106                 if (_type.equals("editallbps")) {
107                         _vp.getVARNAUI().UIEditAllBasePairs();
108                 }
109                 else if (_type.equals("editallbases")) {
110                         _vp.getVARNAUI().UIEditAllBases();
111                 }
112                 else return false;
113                 return true;
114         }
115
116         private boolean optionAnnotation() {
117                 if (!_type.contains("annotation"))
118                         return false;
119                 // a partir du menu principale (gestion des annotations)
120                 if (_type.equals("annotationsaddPosition")) {
121                         _vp.getVARNAUI().UIAnnotationsAddPosition(_vp.getPopup().getSpawnPoint().x,_vp.getPopup().getSpawnPoint().y);
122                 } else if (_type.equals("annotationsaddBase")) {
123                         _vp.getVARNAUI().UIAnnotationsAddBase(_vp.getPopup().getSpawnPoint().x,_vp.getPopup().getSpawnPoint().y);
124                 } else if (_type.equals("annotationsaddLoop")) {
125                         _vp.getVARNAUI().UIAnnotationsAddLoop(_vp.getPopup().getSpawnPoint().x,_vp.getPopup().getSpawnPoint().y);
126                 } else if (_type.equals("annotationsaddChemProb")) {
127                         _vp.getVARNAUI().UIAnnotationsAddChemProb(_vp.getPopup().getSpawnPoint().x,_vp.getPopup().getSpawnPoint().y);
128                 } else if (_type.equals("annotationsaddRegion")) {
129                         _vp.getVARNAUI().UIAnnotationsAddRegion(_vp.getPopup().getSpawnPoint().x,_vp.getPopup().getSpawnPoint().y);
130                 } else if (_type.equals("annotationsaddHelix")) {
131                         _vp.getVARNAUI().UIAnnotationsAddHelix(_vp.getPopup().getSpawnPoint().x,_vp.getPopup().getSpawnPoint().y);
132                 } else if (_type.equals("annotationsautohelices")) {
133                         _vp.getVARNAUI().UIAutoAnnotateHelices();
134                 } else if (_type.equals("annotationsautointerior")) {
135                         _vp.getVARNAUI().UIAutoAnnotateInteriorLoops();
136                 } else if (_type.equals("annotationsautoterminal")) {
137                         _vp.getVARNAUI().UIAutoAnnotateTerminalLoops();
138                 } else if (_type.equals("annotationsautohelices")) {
139                         _vp.getVARNAUI().UIAutoAnnotateHelices();
140                 } else if (_type.equals("annotationsremove")) {
141                         _vp.getVARNAUI().UIAnnotationsRemove();
142                 } else if (_type.equals("annotationsautoextremites")) {
143                         _vp.getVARNAUI().UIAutoAnnotateStrandEnds();
144                 } else if (_type.equals("annotationsedit")) {
145                         _vp.getVARNAUI().UIAnnotationsEdit();
146                         // a partir du menu selection (annotation la plus proche)
147                 } else if (_type.equals("Selectionannotationremove")) {
148                         _vp.getVARNAUI().UIAnnotationRemoveFromAnnotation(_vp.get_selectedAnnotation());
149                 } else if (_type.equals("Selectionannotationedit")) {
150                         _vp.getVARNAUI().UIAnnotationEditFromAnnotation(_vp.get_selectedAnnotation());
151
152                         // a partir d'une structure(base, loop, helix) dans l'arn
153                         // (annotation li� a la structure)
154                 } else if (_type.endsWith("annotationadd")||_type.contains("annotationremove")||_type.contains("annotationedit")) 
155                 {
156                         try {
157                                 TextAnnotation.AnchorType type = trouverAncrage();
158                                  ArrayList<Integer> listeIndex = new ArrayList<Integer>();
159                                 switch(type)
160                                 {
161                                         case BASE:
162                                                 listeIndex.add(_vp.getNearestBase());
163                                         case LOOP:
164                                                 if (_type.startsWith("loop1"))
165                                                         listeIndex = _vp.getRNA().findLoopForward(_vp.getNearestBase());
166                                                 else if (_type.startsWith("loop2"))
167                                                         listeIndex = _vp.getRNA().findLoopBackward(_vp.getNearestBase());
168                                                 else
169                                                         listeIndex = _vp.getRNA().findLoop(_vp.getNearestBase());
170                                         break;
171                                         case HELIX:
172                                                 listeIndex = _vp.getRNA().findHelix(_vp.getNearestBase());
173                                         break;                          
174                                 }
175                                 if (_type.endsWith("annotationadd"))
176                                 { _vp.getVARNAUI().UIAnnotationAddFromStructure(type,listeIndex); }
177                                 else if (_type.contains("annotationremove")) 
178                                 { _vp.getVARNAUI().UIAnnotationRemoveFromStructure(trouverAncrage(),listeIndex); }
179                                 else if (_type.contains("annotationedit")) 
180                                 { _vp.getVARNAUI().UIAnnotationEditFromStructure(trouverAncrage(),listeIndex); }
181                                         
182                         } catch (Exception e2) {
183                                 e2.printStackTrace();
184                         }
185                         } else
186                         return false;
187                 return true;
188         }
189
190         private TextAnnotation.AnchorType trouverAncrage() {
191                 if (_type.contains("loop"))
192                         return TextAnnotation.AnchorType.LOOP;
193                 if (_type.contains("helix"))
194                         return TextAnnotation.AnchorType.HELIX;
195                 if (_type.contains("base"))
196                         return TextAnnotation.AnchorType.BASE;
197                 errorDialog(new Exception("probleme d'identification de l'ancrage"));
198                 return TextAnnotation.AnchorType.POSITION;
199         }
200
201         private boolean option5prime() {
202                 return colorBases();
203         }
204
205         private boolean option3prime() {
206                 return colorBases();
207         }
208
209         private boolean optionBulge() {
210                 return colorBases();
211         }
212
213         private boolean optionStem() {
214                 return colorBases();
215         }
216
217         private boolean optionHelix() {
218                 return colorBases();
219         }
220
221         private boolean colorBases() {
222                 // System.out.println(_type);
223                 ArrayList<Integer> listBase = new ArrayList<Integer>();
224                 String phrase = "Choose new " + _type;
225                 if (_color.equals("InnerColor")) {
226                         phrase += " inner color";
227                         Color c = JColorChooser.showDialog(_vp, phrase,
228                                         VARNAConfig.BASE_INNER_COLOR_DEFAULT);
229                         if (c != null) {
230                                 listBase = listSwitchType(_type);
231                                 for (int i = 0; i < listBase.size(); i++) {
232                                         _vp.getRNA().get_listeBases().get(listBase.get(i))
233                                                         .getStyleBase().setBaseInnerColor(c);
234                                 }
235                                 _vp.repaint();
236                         }
237                 } else if (_color.equals("OutlineColor")) {
238                         phrase += " outline color";
239                         Color c = JColorChooser.showDialog(_vp, phrase,
240                                         VARNAConfig.BASE_OUTLINE_COLOR_DEFAULT);
241                         if (c != null) {
242                                 listBase = listSwitchType(_type);
243                                 for (int i = 0; i < listBase.size(); i++) {
244                                         _vp.getRNA().get_listeBases().get(listBase.get(i))
245                                                         .getStyleBase().setBaseOutlineColor(c);
246                                 }
247                                 _vp.repaint();
248                         }
249                 } else if (_color.equals("NameColor")) {
250                         phrase += " name color";
251                         Color c = JColorChooser.showDialog(_vp, phrase,
252                                         VARNAConfig.BASE_NAME_COLOR_DEFAULT);
253                         if (c != null) {
254                                 listBase = listSwitchType(_type);
255                                 for (int i = 0; i < listBase.size(); i++) {
256                                         _vp.getRNA().get_listeBases().get(listBase.get(i))
257                                                         .getStyleBase().setBaseNameColor(c);
258                                 }
259                                 _vp.repaint();
260                         }
261                 } else if (_color.equals("NumberColor")) {
262                         phrase += " number color";
263                         Color c = JColorChooser.showDialog(_vp, phrase,
264                                         VARNAConfig.BASE_NUMBER_COLOR_DEFAULT);
265                         if (c != null) {
266                                 listBase = listSwitchType(_type);
267                                 for (int i = 0; i < listBase.size(); i++) {
268                                         _vp.getRNA().get_listeBases().get(listBase.get(i))
269                                                         .getStyleBase().setBaseNumberColor(c);
270                                 }
271                                 _vp.repaint();
272                         }
273                 } else if (_color.equals("BPColor")) {
274                         phrase += " base-pair color";
275                         Color c = JColorChooser.showDialog(_vp, phrase,
276                                         VARNAConfig.BASE_NUMBER_COLOR_DEFAULT);
277                         if (c != null) {
278                                 listBase = listSwitchType(_type);
279                                 for (int i = 0; i < listBase.size(); i++) 
280                                 {
281                                         for (ModeleBP msbp:_vp.getRNA().getBPsAt(listBase.get(i)))
282                                         {
283                                                 if (msbp!=null) {
284                                                         msbp.getStyle().setCustomColor(c);
285                                                 }       
286                                         }
287                                 }
288                                 _vp.repaint();
289                         }
290                 } else if (_color.equals("BPColor")) {
291                         phrase += " base-pair color";
292                         Color c = JColorChooser.showDialog(_vp, phrase,
293                                         VARNAConfig.BASE_NUMBER_COLOR_DEFAULT);
294                         if (c != null) {
295                                 listBase = listSwitchType(_type);
296                                 for (int i = 0; i < listBase.size(); i++) {
297                                         ModeleBase mb = _vp.getRNA().get_listeBases().get(
298                                                         listBase.get(i));
299                                         if (mb.getElementStructure() != -1) {
300                                                 mb.getStyleBP().getStyle().setCustomColor(c);
301                                         }
302                                 }
303                                 _vp.repaint();
304                         }
305                 } else if (_color.equals("BPThickness")) {
306                         listBase = listSwitchType(_type);
307                         // System.out.println(listBase.size());
308                         ArrayList<ModeleBP> styleBPs = new ArrayList<ModeleBP>();
309                         for (int i = 0; i < listBase.size(); i++) {
310                                 ModeleBase mb = _vp.getRNA().get_listeBases().get(
311                                                 listBase.get(i));
312                                 if (mb.getElementStructure() != -1) {
313                                         styleBPs.add(mb.getStyleBP());
314                                 }
315                         }
316                         VueBPThickness vbpt = new VueBPThickness(_vp, styleBPs);
317                         if (JOptionPane.showConfirmDialog(_vp, vbpt.getPanel(),
318                                         "Set base pair(s) thickness", JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION) {
319                                 vbpt.restoreThicknesses();
320                                 _vp.repaint();
321                         }
322                 } else
323                         return false;
324                 return true;
325         }
326
327         private ArrayList<Integer> listSwitchType(String _type) {
328                 if (_type.equals("helix"))
329                         return _vp.getRNA().findHelix(_vp.getNearestBase());
330                 if (_type.equals("current")) {
331                         return _vp.getSelectionIndices();
332                 }
333                 if (_type.equals("allBases")) {
334                         return _vp.getRNA().findAll();
335                 }
336                 if (_type.equals("loop1")) {
337                         return _vp.getRNA().findLoopForward(_vp.getNearestBase());
338                 }
339                 if (_type.equals("loop2")) {
340                         return _vp.getRNA().findLoopBackward(_vp.getNearestBase());
341                 }
342                 if (_type.equals("stem"))
343                         return _vp.getRNA().findStem(_vp.getNearestBase());
344                 if (_type.equals("base")) {
345                         ArrayList<Integer> list = new ArrayList<Integer>();
346                         list.add(_vp.getNearestBase());
347                         return list;
348                 }
349                 if (_type.equals("basepair") || _type.equals("bpcolor")
350                                 || _type.equals("bp")) {
351                         ArrayList<Integer> list = new ArrayList<Integer>();
352                         int i = _vp.getNearestBase();
353                         list.add(i);
354                         ModeleBase mb = _vp.getRNA().get_listeBases().get(i);
355                         int j = mb.getElementStructure();
356                         if (mb.getElementStructure() != -1) {
357                                 list.add(i);
358                                 list.add(j);
359                         }
360                         return list;
361                 }
362                 if (_type.equals("5'"))
363                         return _vp.getRNA().findNonPairedBaseGroup(_vp.getNearestBase());
364                 if (_type.equals("3'"))
365                         return _vp.getRNA().findNonPairedBaseGroup(_vp.getNearestBase());
366                 if (_type.equals("bulge"))
367                         return _vp.getRNA().findNonPairedBaseGroup(_vp.getNearestBase());
368                 if (_type.equals("all"))
369                         return _vp.getRNA().findAll();
370                 return new ArrayList<Integer>();
371         }
372
373         private boolean optionLoop() {
374                 return colorBases();
375         }
376
377         private boolean optionBase() {
378                 if (_type.equals("baseChar")) {
379                         _vp.getVARNAUI().UISetBaseCharacter();
380                         return true;
381                 } else {
382                         return colorBases();
383                 }
384         }
385
386         private boolean optionBasePair() {
387                 if (_type.equals("basepair")) {
388                         _vp.getVARNAUI().UIEditBasePair();
389                         return true;
390                 } else if (_type.equals("bpcolor")) {
391                         _vp.getVARNAUI().UIColorBasePair();
392                         return true;
393                 } else if (_type.equals("thickness")) {
394                         _vp.getVARNAUI().UIThicknessBasePair();
395                         return true;
396                 }
397                 return false;
398         }
399
400         
401         
402         private boolean optionView() {
403                 if (_type.equals("background")) {
404                         _vp.getVARNAUI().UISetBackground();
405                 } else if (_type.equals("shownc")) {
406                         _vp.getVARNAUI().UIToggleShowNCBP();
407                 } else if (_type.equals("showbackbone")) {
408                         _vp.getVARNAUI().UIToggleDrawBackbone();
409                 } else if (_type.equals("shownp")) {
410                         _vp.getVARNAUI().UIToggleShowNonPlanar();
411                 } else if (_type.equals("spaceBetweenBases")) {
412                         _vp.getVARNAUI().UISetSpaceBetweenBases();
413                 } else if (_type.equals("bpheightincrement")) {
414                         _vp.getVARNAUI().UISetBPHeightIncrement();
415                 } else if (_type.equals("borderSize")) {
416                         _vp.getVARNAUI().UISetBorder();
417                 } else if (_type.startsWith("zoom")) {
418                         if (_type.equals("zoom")) {
419                                 _vp.getVARNAUI().UICustomZoom();
420                         } else {
421                                 String factor = _type.substring("zoom".length());
422                                 double pc = Integer.parseInt(factor);
423                                 pc /= 100.0;
424                                 _vp.setZoom(new Double(pc));
425                                 _vp.repaint();
426                         }
427                 } else if (_type.equals("rotation")) {
428                         _vp.getVARNAUI().UIGlobalRotation();
429                 } else if (_type.equals("rescale")) {
430                         _vp.getVARNAUI().UIGlobalRescale();
431                 } else
432                         return false;
433                 return true;
434         }
435
436         
437         private boolean optionTitle() {
438                 if (_type.equals("titleDisplay")) {
439                         _vp.getVARNAUI().UISetTitleFont();
440                 } else if (_type.equals("setTitle")) {
441                         _vp.getVARNAUI().UISetTitle();
442                 } else if (_type.equals("titleColor")) {
443                         _vp.getVARNAUI().UISetTitleColor();
444                 } else
445                         return false;
446                 return true;
447         }
448
449                 
450         private boolean optionColorMap() {
451                 if (_type.equals("toggleshowcolormap")) {
452                         _vp.getVARNAUI().UIToggleColorMap();
453                 } else  if (_type.equals("colormapcaption")) {
454                         _vp.getVARNAUI().UISetColorMapCaption();
455                 } else  if (_type.equals("colormapstyle")) {
456                         _vp.getVARNAUI().UISetColorMapStyle();
457                 } else  if (_type.equals("colormaploadvalues")) {
458                         _vp.getVARNAUI().UILoadColorMapValues();
459                 } else  if (_type.equals("colormapvalues")) {
460                         _vp.getVARNAUI().UISetColorMapValues();
461                 } else
462                         return false;
463                 return true;
464         }
465
466         private boolean optionRNADisplay() {
467                 // les options d'affichages generales
468                 if (_type.equals("gaspin")) {
469                         _vp.getVARNAUI().UIToggleGaspinMode();
470                 } else if (_type.equals("backbone")) {
471                         _vp.getVARNAUI().UISetBackboneColor();
472                 } else if (_type.equals("bonds")) {
473                         Color c = JColorChooser.showDialog(_vp, "Choose new bonds color",
474                                         _vp.getBackground());
475                         if (c != null) {
476                                 _vp.setDefaultBPColor(c);
477                                 _vp.repaint();
478                         }
479                 } else if (_type.equals("basecolorforBP")) {
480                         if (_source != null) {
481                                 if (_source instanceof JCheckBoxMenuItem) {
482                                         JCheckBoxMenuItem check = (JCheckBoxMenuItem) _source;
483                                         _vp.setUseBaseColorsForBPs(check.getState());
484                                         _vp.repaint();
485                                 }
486                         }
487                 } else if (_type.equals("bpstyle")) {
488                         _vp.getVARNAUI().UISetBPStyle();
489                 } else if (_type.equals("specialbasecolored")) {
490                         _vp.getVARNAUI().UIToggleColorSpecialBases();
491                 } else if (_type.equals("showwarnings")) {
492                         _vp.getVARNAUI().UIToggleShowWarnings();
493                 } else if (_type.equals("dashbasecolored")) {
494                         _vp.getVARNAUI().UIToggleColorGapsBases();
495                 } else if (_type.equals("numPeriod")) {
496                         _vp.getVARNAUI().UISetNumPeriod();
497                 } else if (_type.equals("eachKind")) {
498                         if (_vp.getRNA().get_listeBases() != null) {
499                                 _vp.getVARNAUI().UIBaseTypeColor();
500                         } else {
501                                 _vp.emitWarning("No base");
502                         }
503                 } else if (_type.equals("eachCouple")) {
504                         if (_vp.getRNA().get_listeBases() != null
505                                         && _vp.getRNA().get_listeBases().size() != 0) {
506                                 _vp.getVARNAUI().UIBasePairTypeColor();
507                         } else {
508                                 _vp.emitWarning("No base");
509                         }
510                 } else if (_type.equals("eachBase")) {
511                         if (_vp.getRNA().get_listeBases() != null
512                                         && _vp.getRNA().get_listeBases().size() != 0) {
513                                 _vp.getVARNAUI().UIBaseAllColor();
514                         } else {
515                                 _vp.emitWarning("No base");
516                         }
517                 } else if (_type.equals("specialBasesColor")) {
518                         _vp.getVARNAUI().UIPickSpecialBasesColor();
519                 } else if (_type.equals("dashBasesColor")) {
520                         _vp.getVARNAUI().UIPickGapsBasesColor();
521                 } else
522                         return colorBases();
523                 return true;
524         }
525
526         private boolean optionImport() {
527                 if (_type.equals("userInput")) {
528                         try {
529                                 _vp.getVARNAUI().UIManualInput();
530                         } catch (ParseException e1) {
531                                 errorDialog(e1);
532                         } catch (ExceptionNonEqualLength e2) {
533                                 errorDialog(e2);
534                         }
535                 } else if (_type.equals("file")) {
536                         try {
537                                 _vp.getVARNAUI().UIFile();
538                         } catch (ExceptionNonEqualLength e1) {
539                                 errorDialog(e1);
540                         }
541                 } else if (_type.equals("print")) {
542                         _vp.getVARNAUI().UIPrint();
543                 } else if (_type.equals("about")) {
544                         _vp.getVARNAUI().UIAbout();
545                 } else
546                         return false;
547                 return true;
548         }
549
550         private boolean optionRedraw() {
551                 if (_type.equals("reset")) {
552                         _vp.getVARNAUI().UIReset();
553                 } else if (_type.equals("circular")) {
554                         _vp.getVARNAUI().UICircular();
555                 } else if (_type.equals("radiate")) {
556                         _vp.getVARNAUI().UIRadiate();
557                 } else if (_type.equals("naview")) {
558                         _vp.getVARNAUI().UINAView();
559                 } else if (_type.equals("varnaview")) {
560                         _vp.getVARNAUI().UIVARNAView();
561                 } else if (_type.equals("motifview")) {
562                         _vp.getVARNAUI().UIMOTIFView();
563                 } else if (_type.equals("line")) {
564                         _vp.getVARNAUI().UILine();
565                 } else if (_type.equals("flat")) {
566                         _vp.getVARNAUI().UIToggleFlatExteriorLoop();
567                 } else
568                         return false;
569                 return true;
570         }
571
572         private boolean optionExport() {
573                 if (_type.equals("saveas")) {
574                         try {
575                                 _vp.getVARNAUI().UISaveAs();
576                         } catch (ExceptionExportFailed e1) {
577                                 errorDialog(e1);
578                         } catch (ExceptionPermissionDenied e1) {
579                                 errorDialog(e1);
580                         }
581                 } else if (_type.equals("dbn")) {
582                         try {
583                                 _vp.getVARNAUI().UISaveAsDBN();
584                         } catch (ExceptionExportFailed e) {
585                                 errorDialog(e);
586                         } catch (ExceptionPermissionDenied e) {
587                                 errorDialog(e);
588                         }
589                 } else if (_type.equals("bpseq")) {
590                         try {
591                                 _vp.getVARNAUI().UISaveAsBPSEQ();
592                         } catch (ExceptionExportFailed e) {
593                                 errorDialog(e);
594                         } catch (ExceptionPermissionDenied e) {
595                                 errorDialog(e);
596                         }
597                 } else if (_type.equals("ct")) {
598                         try {
599                                 _vp.getVARNAUI().UISaveAsCT();
600                         } catch (ExceptionExportFailed e) {
601                                 errorDialog(e);
602                         } catch (ExceptionPermissionDenied e) {
603                                 errorDialog(e);
604                         }
605                 } else if (_type.equals("eps")) {
606                         try {
607                                 _vp.getVARNAUI().UIExportEPS();
608                         } catch (ExceptionWritingForbidden e1) {
609                                 errorDialog(e1);
610                         } catch (ExceptionExportFailed e) {
611                                 errorDialog(e);
612                         }
613                 } else if (_type.equals("tikz")) {
614                         try {
615                                 _vp.getVARNAUI().UIExportTIKZ();
616                         } catch (ExceptionWritingForbidden e1) {
617                                 errorDialog(e1);
618                         } catch (ExceptionExportFailed e) {
619                                 errorDialog(e);
620                         }
621                 } else if (_type.equals("xfig")) {
622                         try {
623                                 _vp.getVARNAUI().UIExportXFIG();
624                         } catch (ExceptionWritingForbidden e1) {
625                                 errorDialog(e1);
626                         } catch (ExceptionExportFailed e) {
627                                 errorDialog(e);
628                         }
629                 } else if (_type.equals("svg")) {
630                         try {
631                                 _vp.getVARNAUI().UIExportSVG();
632                         } catch (ExceptionWritingForbidden e1) {
633                                 errorDialog(e1);
634                         } catch (ExceptionExportFailed e) {
635                                 errorDialog(e);
636                         }
637                 } else if (_type.equals("jpeg")) {
638                         try {
639                                 _vp.getVARNAUI().UIExportJPEG();
640                         } catch (ExceptionJPEGEncoding e1) {
641                                 errorDialog(e1);
642                         } catch (ExceptionExportFailed e1) {
643                                 errorDialog(e1);
644                         }
645                 } else if (_type.equals("png")) {
646                         try {
647                                 _vp.getVARNAUI().UIExportPNG();
648                         } catch (ExceptionExportFailed e1) {
649                                 errorDialog(e1);
650                         }
651                 } else
652                         return false;
653                 return true;
654         }
655
656         /**
657          * Return the extension of a file, it means the string after the last dot of
658          * the file name
659          * 
660          * @param f
661          *            The file
662          * @return <code>null</code> if the file name have no dot<br>
663          *         <code>ext</code> if the file name contains a dot
664          */
665         public String getExtension(File f) {
666                 String s = f.getName();
667                 return getExtension(s);
668         }
669
670         /**
671          * Return the extension of a string, it means the string after the last dot
672          * of the path
673          * 
674          * @param s
675          *            The strnig o the path
676          * @return <code>null</code> if the path have no dot<br>
677          *         <code>ext</code> if the path contains a dot
678          */
679         public String getExtension(String s) {
680                 String ext = null;
681                 int i = s.lastIndexOf('.');
682
683                 if (i > 0 && i < s.length() - 1) {
684                         ext = s.substring(i + 1).toLowerCase();
685                 }
686                 return ext;
687         }
688
689         /**
690          * Open an error message dialog with the exception message
691          * 
692          * @param e1
693          *            The <code>Exception</code>
694          */
695         public void errorDialog(Exception e1) {
696                 if (_vp.isErrorsOn())
697                         JOptionPane.showMessageDialog(_vp, e1.getMessage(), "VARNA Error",
698                                         JOptionPane.ERROR_MESSAGE);
699         }
700
701         public void onStructureRedrawn() {
702                 // TODO Auto-generated method stub
703                 
704         }
705
706         public void onWarningEmitted(String s) {
707                 if (_vp.isErrorsOn())
708                         JOptionPane.showMessageDialog(_vp,s, "VARNA Warning",
709                                         JOptionPane.ERROR_MESSAGE);
710         }
711
712         public void onLoad(String path) {
713                 // TODO Auto-generated method stub
714                 
715         }
716
717         public void onLoaded() {
718                 // TODO Auto-generated method stub
719                 
720         }
721
722         public void onUINewStructure(VARNAConfig v, RNA r) {
723                 // TODO Auto-generated method stub
724                 
725         }
726
727         public void onZoomLevelChanged() {
728                 // TODO Auto-generated method stub
729                 
730         }
731
732         public void onTranslationChanged() {
733                 // TODO Auto-generated method stub
734                 
735         }
736
737
738 }