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