JAL-3384 catch non-float version number of java
[jalview.git] / src / jalview / jbgui / GDesktop.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.jbgui;
22
23 import jalview.api.AlignmentViewPanel;
24 import jalview.io.FileFormatException;
25 import jalview.util.MessageManager;
26 import jalview.util.Platform;
27
28 import java.awt.FlowLayout;
29 import java.awt.event.ActionEvent;
30 import java.awt.event.ActionListener;
31
32 import javax.swing.JCheckBoxMenuItem;
33 import javax.swing.JFrame;
34 import javax.swing.JMenu;
35 import javax.swing.JMenuBar;
36 import javax.swing.JMenuItem;
37
38 /**
39  * DOCUMENT ME!
40  * 
41  * @author $author$
42  * @version $Revision$
43  */
44 public class GDesktop extends JFrame
45 {
46   protected static JMenu windowMenu = new JMenu();
47
48   JMenuBar desktopMenubar = new JMenuBar();
49
50   JMenu FileMenu = new JMenu();
51
52   JMenu HelpMenu = new JMenu();
53
54   JMenuItem inputLocalFileMenuItem = new JMenuItem();
55
56   JMenuItem inputURLMenuItem = new JMenuItem();
57
58   JMenuItem inputTextboxMenuItem = new JMenuItem();
59
60   JMenuItem quit = new JMenuItem();
61
62   JMenuItem aboutMenuItem = new JMenuItem();
63
64   JMenuItem documentationMenuItem = new JMenuItem();
65
66   FlowLayout flowLayout1 = new FlowLayout();
67
68   protected JMenu toolsMenu = new JMenu();
69
70   JMenuItem preferences = new JMenuItem();
71
72   JMenuItem saveState = new JMenuItem();
73
74   JMenuItem saveAsState = new JMenuItem();
75
76   JMenuItem loadState = new JMenuItem();
77
78   JMenu inputMenu = new JMenu();
79
80   JMenuItem inputSequence = new JMenuItem();
81
82   JMenuItem closeAll = new JMenuItem();
83
84   JMenuItem raiseRelated = new JMenuItem();
85
86   JMenuItem minimizeAssociated = new JMenuItem();
87
88   protected JCheckBoxMenuItem showMemusage = new JCheckBoxMenuItem();
89
90   JMenuItem garbageCollect = new JMenuItem();
91
92   protected JMenuItem groovyShell;
93
94   protected JCheckBoxMenuItem experimentalFeatures;
95
96   protected JCheckBoxMenuItem showConsole = new JCheckBoxMenuItem();
97
98   protected JCheckBoxMenuItem showNews = new JCheckBoxMenuItem();
99
100   protected JMenuItem snapShotWindow = new JMenuItem();
101
102   /**
103    * Creates a new GDesktop object.
104    */
105   public GDesktop()
106   {
107     try
108     {
109       jbInit();
110       this.setJMenuBar(desktopMenubar);
111     } catch (Exception e)
112     {
113       e.printStackTrace();
114     }
115
116     if (!Platform.isAMac())
117     {
118       FileMenu.setMnemonic('F');
119       inputLocalFileMenuItem.setMnemonic('L');
120       inputURLMenuItem.setMnemonic('U');
121       inputTextboxMenuItem.setMnemonic('C');
122       quit.setMnemonic('Q');
123       saveState.setMnemonic('S');
124       loadState.setMnemonic('L');
125       inputMenu.setMnemonic('I');
126     }
127   }
128
129   /**
130    * DOCUMENT ME!
131    * 
132    * @throws Exception
133    *           DOCUMENT ME!
134    */
135   private void jbInit() throws Exception
136   {
137
138     FileMenu.setText(MessageManager.getString("action.file"));
139     HelpMenu.setText(MessageManager.getString("action.help"));
140     inputLocalFileMenuItem
141             .setText(MessageManager.getString("label.load_tree_from_file"));
142     inputLocalFileMenuItem.setAccelerator(
143             javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O,
144                     jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(),
145                     false));
146     inputLocalFileMenuItem
147             .addActionListener(new java.awt.event.ActionListener()
148             {
149               @Override
150               public void actionPerformed(ActionEvent e)
151               {
152                 inputLocalFileMenuItem_actionPerformed(null);
153               }
154             });
155     inputURLMenuItem.setText(MessageManager.getString("label.from_url"));
156     inputURLMenuItem.addActionListener(new java.awt.event.ActionListener()
157     {
158       @Override
159       public void actionPerformed(ActionEvent e)
160       {
161         try
162         {
163           inputURLMenuItem_actionPerformed(null);
164         } catch (FileFormatException e1)
165         {
166           System.err.println("Error loading from URL: " + e1.getMessage());
167         }
168       }
169     });
170     inputTextboxMenuItem
171             .setText(MessageManager.getString("label.from_textbox"));
172     inputTextboxMenuItem
173             .addActionListener(new java.awt.event.ActionListener()
174             {
175               @Override
176               public void actionPerformed(ActionEvent e)
177               {
178                 inputTextboxMenuItem_actionPerformed(null);
179               }
180             });
181     quit.setText(MessageManager.getString("action.quit"));
182     quit.addActionListener(new java.awt.event.ActionListener()
183     {
184       @Override
185       public void actionPerformed(ActionEvent e)
186       {
187         quit();
188       }
189     });
190     aboutMenuItem.setText(MessageManager.getString("label.about"));
191     aboutMenuItem.addActionListener(new java.awt.event.ActionListener()
192     {
193       @Override
194       public void actionPerformed(ActionEvent e)
195       {
196         aboutMenuItem_actionPerformed(e);
197       }
198     });
199     documentationMenuItem
200             .setText(MessageManager.getString("label.documentation"));
201     documentationMenuItem.setAccelerator(javax.swing.KeyStroke
202             .getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0, false));
203     documentationMenuItem
204             .addActionListener(new java.awt.event.ActionListener()
205             {
206               @Override
207               public void actionPerformed(ActionEvent e)
208               {
209                 documentationMenuItem_actionPerformed(e);
210               }
211             });
212     this.getContentPane().setLayout(flowLayout1);
213     windowMenu.setText(MessageManager.getString("label.window"));
214     preferences.setText(MessageManager.getString("label.preferences"));
215     preferences.addActionListener(new ActionListener()
216     {
217       @Override
218       public void actionPerformed(ActionEvent e)
219       {
220         preferences_actionPerformed(e);
221       }
222     });
223     toolsMenu.setText(MessageManager.getString("label.tools"));
224     saveState.setText(MessageManager.getString("action.save_project"));
225     saveState.addActionListener(new ActionListener()
226     {
227       @Override
228       public void actionPerformed(ActionEvent e)
229       {
230         saveState_actionPerformed();
231       }
232     });
233     saveAsState.setText(MessageManager.getString("action.save_project_as"));
234     saveAsState.addActionListener(new ActionListener()
235     {
236       @Override
237       public void actionPerformed(ActionEvent e)
238       {
239         saveAsState_actionPerformed(e);
240       }
241     });
242     loadState.setText(MessageManager.getString("action.load_project"));
243     loadState.addActionListener(new ActionListener()
244     {
245       @Override
246       public void actionPerformed(ActionEvent e)
247       {
248         loadState_actionPerformed();
249       }
250     });
251     inputMenu.setText(MessageManager.getString("label.input_alignment"));
252     inputSequence
253             .setText(MessageManager.getString("action.fetch_sequences"));
254     inputSequence.addActionListener(new ActionListener()
255     {
256       @Override
257       public void actionPerformed(ActionEvent e)
258       {
259         inputSequence_actionPerformed(e);
260       }
261     });
262     closeAll.setText(MessageManager.getString("action.close_all"));
263     closeAll.addActionListener(new ActionListener()
264     {
265       @Override
266       public void actionPerformed(ActionEvent e)
267       {
268         closeAll_actionPerformed(e);
269       }
270     });
271     raiseRelated.setText(
272             MessageManager.getString("action.raise_associated_windows"));
273     raiseRelated.addActionListener(new ActionListener()
274     {
275       @Override
276       public void actionPerformed(ActionEvent e)
277       {
278         raiseRelated_actionPerformed(e);
279       }
280     });
281     minimizeAssociated.setText(
282             MessageManager.getString("action.minimize_associated_windows"));
283     minimizeAssociated.addActionListener(new ActionListener()
284     {
285       @Override
286       public void actionPerformed(ActionEvent e)
287       {
288         minimizeAssociated_actionPerformed(e);
289       }
290     });
291     garbageCollect
292             .setText(MessageManager.getString("label.collect_garbage"));
293     garbageCollect.addActionListener(new ActionListener()
294     {
295       @Override
296       public void actionPerformed(ActionEvent e)
297       {
298         garbageCollect_actionPerformed(e);
299       }
300     });
301     showMemusage
302             .setText(MessageManager.getString("label.show_memory_usage"));
303     showMemusage.addActionListener(new ActionListener()
304     {
305       @Override
306       public void actionPerformed(ActionEvent e)
307       {
308         showMemusage_actionPerformed(e);
309       }
310     });
311     showConsole
312             .setText(MessageManager.getString("label.show_java_console"));
313     showConsole.addActionListener(new ActionListener()
314     {
315       @Override
316       public void actionPerformed(ActionEvent e)
317       {
318         showConsole_actionPerformed(e);
319       }
320     });
321     showNews.setText(MessageManager.getString("label.show_jalview_news"));
322     showNews.addActionListener(new ActionListener()
323     {
324       @Override
325       public void actionPerformed(ActionEvent e)
326       {
327         showNews_actionPerformed(e);
328       }
329     });
330     groovyShell = new JMenuItem();
331     groovyShell.setText(MessageManager.getString("label.groovy_console"));
332     groovyShell.addActionListener(new ActionListener()
333     {
334       @Override
335       public void actionPerformed(ActionEvent e)
336       {
337         groovyShell_actionPerformed();
338       }
339     });
340     experimentalFeatures = new JCheckBoxMenuItem();
341     experimentalFeatures
342             .setText(MessageManager.getString("label.show_experimental"));
343     experimentalFeatures.setToolTipText(
344             MessageManager.getString("label.show_experimental_tip"));
345     experimentalFeatures.addActionListener(new ActionListener()
346     {
347       @Override
348       public void actionPerformed(ActionEvent e)
349       {
350         showExperimental_actionPerformed(experimentalFeatures.isSelected());
351       }
352     });
353
354     snapShotWindow.setText(MessageManager.getString("label.take_snapshot"));
355     snapShotWindow.addActionListener(new ActionListener()
356     {
357       @Override
358       public void actionPerformed(ActionEvent e)
359       {
360         snapShotWindow_actionPerformed(e);
361       }
362     });
363
364     float specversion;
365     try
366     {
367       specversion = Float
368               .parseFloat(System.getProperty("java.specification.version"));
369     } catch (Exception e)
370     {
371       specversion = 8;
372     }
373     
374     desktopMenubar.add(FileMenu);
375     desktopMenubar.add(toolsMenu);
376     desktopMenubar.add(HelpMenu);
377     desktopMenubar.add(windowMenu);
378     FileMenu.add(inputMenu);
379     FileMenu.add(inputSequence);
380     FileMenu.addSeparator();
381     //FileMenu.add(saveState);
382     FileMenu.add(saveAsState);
383     FileMenu.add(loadState);
384     FileMenu.addSeparator();
385     FileMenu.add(quit);
386     HelpMenu.add(aboutMenuItem);
387     HelpMenu.add(documentationMenuItem);
388     if (!Platform.isAMac() || specversion < 11)
389     {
390       toolsMenu.add(preferences);
391     }
392     toolsMenu.add(showMemusage);
393     toolsMenu.add(showConsole);
394     toolsMenu.add(showNews);
395     toolsMenu.add(garbageCollect);
396     toolsMenu.add(groovyShell);
397     toolsMenu.add(experimentalFeatures);
398     // toolsMenu.add(snapShotWindow);
399     inputMenu.add(inputLocalFileMenuItem);
400     inputMenu.add(inputURLMenuItem);
401     inputMenu.add(inputTextboxMenuItem);
402     windowMenu.add(closeAll);
403     windowMenu.add(raiseRelated);
404     windowMenu.add(minimizeAssociated);
405     windowMenu.addSeparator();
406     // inputMenu.add(vamsasLoad);
407   }
408
409   protected void showExperimental_actionPerformed(boolean selected)
410   {
411   }
412
413   protected void groovyShell_actionPerformed()
414   {
415   }
416
417   protected void snapShotWindow_actionPerformed(ActionEvent e)
418   {
419     // TODO Auto-generated method stub
420
421   }
422
423   protected void showConsole_actionPerformed(ActionEvent e)
424   {
425     // TODO Auto-generated method stub
426
427   }
428
429   protected void showNews_actionPerformed(ActionEvent e)
430   {
431     // TODO Auto-generated method stub
432
433   }
434
435   protected void showMemusage_actionPerformed(ActionEvent e)
436   {
437     // TODO Auto-generated method stub
438
439   }
440
441   protected void garbageCollect_actionPerformed(ActionEvent e)
442   {
443     // TODO Auto-generated method stub
444
445   }
446
447   protected void vamsasStMenu_actionPerformed()
448   {
449   }
450
451   public void vamsasSave_actionPerformed(ActionEvent e)
452   {
453   }
454
455   /**
456    * DOCUMENT ME!
457    * 
458    * @param e
459    *          DOCUMENT ME!
460    */
461   protected void inputLocalFileMenuItem_actionPerformed(
462           jalview.gui.AlignViewport av)
463   {
464   }
465
466   /**
467    * DOCUMENT ME!
468    * 
469    * @param e
470    *          DOCUMENT ME!
471    * @throws FileFormatException
472    */
473   protected void inputURLMenuItem_actionPerformed(
474           jalview.gui.AlignViewport av) throws FileFormatException
475   {
476   }
477
478   /**
479    * DOCUMENT ME!
480    * 
481    * @param e
482    *          DOCUMENT ME!
483    */
484   protected void inputTextboxMenuItem_actionPerformed(
485           AlignmentViewPanel avp)
486   {
487   }
488
489   /**
490    * DOCUMENT ME!
491    */
492   protected void quit()
493   {
494     //System.out.println("********** GDesktop.quit()");
495   }
496
497   /**
498    * DOCUMENT ME!
499    * 
500    * @param e
501    *          DOCUMENT ME!
502    */
503   protected void aboutMenuItem_actionPerformed(ActionEvent e)
504   {
505   }
506
507   /**
508    * DOCUMENT ME!
509    * 
510    * @param e
511    *          DOCUMENT ME!
512    */
513   protected void documentationMenuItem_actionPerformed(ActionEvent e)
514   {
515   }
516
517   /**
518    * DOCUMENT ME!
519    * 
520    * @param e
521    *          DOCUMENT ME!
522    */
523   protected void preferences_actionPerformed(ActionEvent e)
524   {
525   }
526
527   /**
528    * DOCUMENT ME!
529    * 
530    * @param e
531    *          DOCUMENT ME!
532    */
533   public void saveState_actionPerformed()
534   {
535   }
536
537   public void saveAsState_actionPerformed(ActionEvent e)
538   {
539   }
540
541   /**
542    * DOCUMENT ME!
543    * 
544    * @param e
545    *          DOCUMENT ME!
546    */
547   public void loadState_actionPerformed()
548   {
549   }
550
551   /**
552    * DOCUMENT ME!
553    * 
554    * @param e
555    *          DOCUMENT ME!
556    */
557   public void loadJalviewAlign_actionPerformed(ActionEvent e)
558   {
559   }
560
561   public void vamsasStart_actionPerformed(ActionEvent e)
562   {
563
564   }
565
566   public void inputSequence_actionPerformed(ActionEvent e)
567   {
568
569   }
570
571   public void vamsasStop_actionPerformed(ActionEvent e)
572   {
573
574   }
575
576   public void closeAll_actionPerformed(ActionEvent e)
577   {
578
579   }
580
581   public void raiseRelated_actionPerformed(ActionEvent e)
582   {
583
584   }
585
586   public void minimizeAssociated_actionPerformed(ActionEvent e)
587   {
588
589   }
590
591   public void vamsasImport_actionPerformed(ActionEvent e)
592   {
593   }
594 }