Merge branch 'improvement/JAL-1988+JAL-3416_Java8_macOS_APQHandlers_and_FlatLaF_optio...
[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     boolean apqHandlersSet = false;
144     /**
145      * APQHandlers sets handlers for About, Preferences and Quit actions
146      * peculiar to macOS's application menu. APQHandlers will check to see if a
147      * handler is supported before setting it.
148      */
149     try
150     {
151       apqHandlersSet = APQHandlers.setAPQHandlers(this);
152     } catch (Exception e)
153     {
154       System.out.println("Cannot set APQHandlers");
155       // e.printStackTrace();
156     } catch (Throwable t)
157     {
158       jalview.bin.Console
159               .warn("Error setting APQHandlers: " + t.toString());
160       jalview.bin.Console.trace(Cache.getStackTraceString(t));
161     }
162
163     setName("jalview-desktop");
164     FileMenu.setText(MessageManager.getString("action.file"));
165     HelpMenu.setText(MessageManager.getString("action.help"));
166     inputLocalFileMenuItem
167             .setText(MessageManager.getString("label.load_tree_from_file"));
168     inputLocalFileMenuItem
169             .setAccelerator(
170                     javax.swing.KeyStroke
171                             .getKeyStroke(java.awt.event.KeyEvent.VK_O,
172                                     jalview.util.ShortcutKeyMaskExWrapper
173                                             .getMenuShortcutKeyMaskEx(),
174                                     false));
175     inputLocalFileMenuItem
176             .addActionListener(new java.awt.event.ActionListener()
177             {
178               @Override
179               public void actionPerformed(ActionEvent e)
180               {
181                 inputLocalFileMenuItem_actionPerformed(null);
182               }
183             });
184     inputURLMenuItem.setText(MessageManager.getString("label.from_url"));
185     inputURLMenuItem.addActionListener(new java.awt.event.ActionListener()
186     {
187       @Override
188       public void actionPerformed(ActionEvent e)
189       {
190         try
191         {
192           inputURLMenuItem_actionPerformed(null);
193         } catch (FileFormatException e1)
194         {
195           System.err.println("Error loading from URL: " + e1.getMessage());
196         }
197       }
198     });
199     inputTextboxMenuItem
200             .setText(MessageManager.getString("label.from_textbox"));
201     inputTextboxMenuItem
202             .addActionListener(new java.awt.event.ActionListener()
203             {
204               @Override
205               public void actionPerformed(ActionEvent e)
206               {
207                 inputTextboxMenuItem_actionPerformed(null);
208               }
209             });
210     quit.setText(MessageManager.getString("action.quit"));
211     quit.addActionListener(new java.awt.event.ActionListener()
212     {
213       @Override
214       public void actionPerformed(ActionEvent e)
215       {
216         quit();
217       }
218     });
219     aboutMenuItem.setText(MessageManager.getString("label.about"));
220     aboutMenuItem.addActionListener(new java.awt.event.ActionListener()
221     {
222       @Override
223       public void actionPerformed(ActionEvent e)
224       {
225         aboutMenuItem_actionPerformed(e);
226       }
227     });
228     documentationMenuItem
229             .setText(MessageManager.getString("label.documentation"));
230     documentationMenuItem.setAccelerator(javax.swing.KeyStroke
231             .getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0, false));
232     documentationMenuItem
233             .addActionListener(new java.awt.event.ActionListener()
234             {
235               @Override
236               public void actionPerformed(ActionEvent e)
237               {
238                 documentationMenuItem_actionPerformed();
239               }
240             });
241     this.getContentPane().setLayout(flowLayout1);
242     windowMenu.setText(MessageManager.getString("label.window"));
243     preferences.setText(MessageManager.getString("label.preferences"));
244     preferences.addActionListener(new ActionListener()
245     {
246       @Override
247       public void actionPerformed(ActionEvent e)
248       {
249         preferences_actionPerformed(e);
250       }
251     });
252     toolsMenu.setText(MessageManager.getString("label.tools"));
253     saveState.setText(MessageManager.getString("action.save_project"));
254     saveState.addActionListener(new ActionListener()
255     {
256       @Override
257       public void actionPerformed(ActionEvent e)
258       {
259         saveState_actionPerformed();
260       }
261     });
262     saveAsState.setText(MessageManager.getString("action.save_project_as"));
263     saveAsState.addActionListener(new ActionListener()
264     {
265       @Override
266       public void actionPerformed(ActionEvent e)
267       {
268         saveAsState_actionPerformed(e);
269       }
270     });
271     loadState.setText(MessageManager.getString("action.load_project"));
272     loadState.addActionListener(new ActionListener()
273     {
274       @Override
275       public void actionPerformed(ActionEvent e)
276       {
277         loadState_actionPerformed();
278       }
279     });
280     inputMenu.setText(MessageManager.getString("label.input_alignment"));
281     inputSequence
282             .setText(MessageManager.getString("action.fetch_sequences"));
283     inputSequence.addActionListener(new ActionListener()
284     {
285       @Override
286       public void actionPerformed(ActionEvent e)
287       {
288         inputSequence_actionPerformed(e);
289       }
290     });
291     closeAll.setText(MessageManager.getString("action.close_all"));
292     closeAll.addActionListener(new ActionListener()
293     {
294       @Override
295       public void actionPerformed(ActionEvent e)
296       {
297         closeAll_actionPerformed(e);
298       }
299     });
300     raiseRelated.setText(
301             MessageManager.getString("action.raise_associated_windows"));
302     raiseRelated.addActionListener(new ActionListener()
303     {
304       @Override
305       public void actionPerformed(ActionEvent e)
306       {
307         raiseRelated_actionPerformed(e);
308       }
309     });
310     minimizeAssociated.setText(
311             MessageManager.getString("action.minimize_associated_windows"));
312     minimizeAssociated.addActionListener(new ActionListener()
313     {
314       @Override
315       public void actionPerformed(ActionEvent e)
316       {
317         minimizeAssociated_actionPerformed(e);
318       }
319     });
320     garbageCollect
321             .setText(MessageManager.getString("label.collect_garbage"));
322     garbageCollect.addActionListener(new ActionListener()
323     {
324       @Override
325       public void actionPerformed(ActionEvent e)
326       {
327         garbageCollect_actionPerformed(e);
328       }
329     });
330     showMemusage
331             .setText(MessageManager.getString("label.show_memory_usage"));
332     showMemusage.addActionListener(new ActionListener()
333     {
334       @Override
335       public void actionPerformed(ActionEvent e)
336       {
337         showMemusage_actionPerformed(e);
338       }
339     });
340     showConsole
341             .setText(MessageManager.getString("label.show_java_console"));
342     showConsole.addActionListener(new ActionListener()
343     {
344       @Override
345       public void actionPerformed(ActionEvent e)
346       {
347         showConsole_actionPerformed(e);
348       }
349     });
350     showNews.setText(MessageManager.getString("label.show_jalview_news"));
351     showNews.addActionListener(new ActionListener()
352     {
353       @Override
354       public void actionPerformed(ActionEvent e)
355       {
356         showNews_actionPerformed(e);
357       }
358     });
359     groovyShell = new JMenuItem();
360     groovyShell.setText(MessageManager.getString("label.groovy_console"));
361     groovyShell.addActionListener(new ActionListener()
362     {
363       @Override
364       public void actionPerformed(ActionEvent e)
365       {
366         groovyShell_actionPerformed();
367       }
368     });
369     experimentalFeatures = new JCheckBoxMenuItem();
370     experimentalFeatures
371             .setText(MessageManager.getString("label.show_experimental"));
372     experimentalFeatures.setToolTipText(
373             MessageManager.getString("label.show_experimental_tip"));
374     experimentalFeatures.addActionListener(new ActionListener()
375     {
376       @Override
377       public void actionPerformed(ActionEvent e)
378       {
379         showExperimental_actionPerformed(experimentalFeatures.isSelected());
380       }
381     });
382
383     snapShotWindow.setText(MessageManager.getString("label.take_snapshot"));
384     snapShotWindow.addActionListener(new ActionListener()
385     {
386       @Override
387       public void actionPerformed(ActionEvent e)
388       {
389         snapShotWindow_actionPerformed(e);
390       }
391     });
392
393     desktopMenubar.add(FileMenu);
394     desktopMenubar.add(toolsMenu);
395     desktopMenubar.add(HelpMenu);
396     desktopMenubar.add(windowMenu);
397     FileMenu.add(inputMenu);
398     FileMenu.add(inputSequence);
399     FileMenu.addSeparator();
400     // FileMenu.add(saveState);
401     FileMenu.add(saveAsState);
402     FileMenu.add(loadState);
403     FileMenu.addSeparator();
404     if (!APQHandlers.setQuit)
405     {
406       FileMenu.add(quit);
407     }
408     if (!APQHandlers.setAbout)
409     {
410       HelpMenu.add(aboutMenuItem);
411     }
412     HelpMenu.add(documentationMenuItem);
413     if (!APQHandlers.setPreferences)
414     {
415       toolsMenu.add(preferences);
416     }
417     if (!Platform.isJS())
418     {
419       toolsMenu.add(showMemusage);
420       toolsMenu.add(showConsole);
421       toolsMenu.add(showNews);
422       toolsMenu.add(garbageCollect);
423       toolsMenu.add(groovyShell);
424     }
425     toolsMenu.add(experimentalFeatures);
426     // toolsMenu.add(snapShotWindow);
427     inputMenu.add(inputLocalFileMenuItem);
428     inputMenu.add(inputURLMenuItem);
429     inputMenu.add(inputTextboxMenuItem);
430     windowMenu.add(closeAll);
431     windowMenu.add(raiseRelated);
432     windowMenu.add(minimizeAssociated);
433     windowMenu.addSeparator();
434     // inputMenu.add(vamsasLoad);
435   }
436
437   protected void showExperimental_actionPerformed(boolean selected)
438   {
439   }
440
441   protected void groovyShell_actionPerformed()
442   {
443   }
444
445   protected void snapShotWindow_actionPerformed(ActionEvent e)
446   {
447     // TODO Auto-generated method stub
448
449   }
450
451   protected void showConsole_actionPerformed(ActionEvent e)
452   {
453     // TODO Auto-generated method stub
454
455   }
456
457   protected void showNews_actionPerformed(ActionEvent e)
458   {
459     // TODO Auto-generated method stub
460
461   }
462
463   protected void showMemusage_actionPerformed(ActionEvent e)
464   {
465     // TODO Auto-generated method stub
466
467   }
468
469   protected void garbageCollect_actionPerformed(ActionEvent e)
470   {
471     // TODO Auto-generated method stub
472
473   }
474
475   protected void vamsasStMenu_actionPerformed()
476   {
477   }
478
479   public void vamsasSave_actionPerformed(ActionEvent e)
480   {
481   }
482
483   /**
484    * DOCUMENT ME!
485    * 
486    * @param e
487    *          DOCUMENT ME!
488    */
489   protected void inputLocalFileMenuItem_actionPerformed(
490           jalview.gui.AlignViewport av)
491   {
492   }
493
494   /**
495    * DOCUMENT ME!
496    * 
497    * @param e
498    *          DOCUMENT ME!
499    * @throws FileFormatException
500    */
501   protected void inputURLMenuItem_actionPerformed(
502           jalview.gui.AlignViewport av) throws FileFormatException
503   {
504   }
505
506   /**
507    * DOCUMENT ME!
508    * 
509    * @param e
510    *          DOCUMENT ME!
511    */
512   protected void inputTextboxMenuItem_actionPerformed(
513           AlignmentViewPanel avp)
514   {
515   }
516
517   /**
518    * DOCUMENT ME!
519    */
520   protected void quit()
521   {
522     // System.out.println("********** GDesktop.quit()");
523   }
524
525   /**
526    * DOCUMENT ME!
527    * 
528    * @param e
529    *          DOCUMENT ME!
530    */
531   protected void aboutMenuItem_actionPerformed(ActionEvent e)
532   {
533   }
534
535   protected void documentationMenuItem_actionPerformed()
536   {
537   }
538
539   /**
540    * DOCUMENT ME!
541    * 
542    * @param e
543    *          DOCUMENT ME!
544    */
545   protected void preferences_actionPerformed(ActionEvent e)
546   {
547   }
548
549   /**
550    * DOCUMENT ME!
551    * 
552    * @param e
553    *          DOCUMENT ME!
554    */
555   public void saveState_actionPerformed()
556   {
557   }
558
559   public void saveAsState_actionPerformed(ActionEvent e)
560   {
561   }
562
563   /**
564    * DOCUMENT ME!
565    * 
566    * @param e
567    *          DOCUMENT ME!
568    */
569   public void loadState_actionPerformed()
570   {
571   }
572
573   /**
574    * DOCUMENT ME!
575    * 
576    * @param e
577    *          DOCUMENT ME!
578    */
579   public void loadJalviewAlign_actionPerformed(ActionEvent e)
580   {
581   }
582
583   public void vamsasStart_actionPerformed(ActionEvent e)
584   {
585
586   }
587
588   public void inputSequence_actionPerformed(ActionEvent e)
589   {
590
591   }
592
593   public void vamsasStop_actionPerformed(ActionEvent e)
594   {
595
596   }
597
598   public void closeAll_actionPerformed(ActionEvent e)
599   {
600
601   }
602
603   public void raiseRelated_actionPerformed(ActionEvent e)
604   {
605
606   }
607
608   public void minimizeAssociated_actionPerformed(ActionEvent e)
609   {
610
611   }
612
613   public void vamsasImport_actionPerformed(ActionEvent e)
614   {
615   }
616 }