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