JAL-1988 JAL-3416 avoid unnecessary static flag
[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     FileMenu.add(quit);
405     if (!apqHandlersSet)
406     {
407       HelpMenu.add(aboutMenuItem);
408     }
409     HelpMenu.add(documentationMenuItem);
410     if (!apqHandlersSet)
411     {
412       toolsMenu.add(preferences);
413     }
414     if (!Platform.isJS())
415     {
416       toolsMenu.add(showMemusage);
417       toolsMenu.add(showConsole);
418       toolsMenu.add(showNews);
419       toolsMenu.add(garbageCollect);
420       toolsMenu.add(groovyShell);
421     }
422     toolsMenu.add(experimentalFeatures);
423     // toolsMenu.add(snapShotWindow);
424     inputMenu.add(inputLocalFileMenuItem);
425     inputMenu.add(inputURLMenuItem);
426     inputMenu.add(inputTextboxMenuItem);
427     windowMenu.add(closeAll);
428     windowMenu.add(raiseRelated);
429     windowMenu.add(minimizeAssociated);
430     windowMenu.addSeparator();
431     // inputMenu.add(vamsasLoad);
432   }
433
434   protected void showExperimental_actionPerformed(boolean selected)
435   {
436   }
437
438   protected void groovyShell_actionPerformed()
439   {
440   }
441
442   protected void snapShotWindow_actionPerformed(ActionEvent e)
443   {
444     // TODO Auto-generated method stub
445
446   }
447
448   protected void showConsole_actionPerformed(ActionEvent e)
449   {
450     // TODO Auto-generated method stub
451
452   }
453
454   protected void showNews_actionPerformed(ActionEvent e)
455   {
456     // TODO Auto-generated method stub
457
458   }
459
460   protected void showMemusage_actionPerformed(ActionEvent e)
461   {
462     // TODO Auto-generated method stub
463
464   }
465
466   protected void garbageCollect_actionPerformed(ActionEvent e)
467   {
468     // TODO Auto-generated method stub
469
470   }
471
472   protected void vamsasStMenu_actionPerformed()
473   {
474   }
475
476   public void vamsasSave_actionPerformed(ActionEvent e)
477   {
478   }
479
480   /**
481    * DOCUMENT ME!
482    * 
483    * @param e
484    *          DOCUMENT ME!
485    */
486   protected void inputLocalFileMenuItem_actionPerformed(
487           jalview.gui.AlignViewport av)
488   {
489   }
490
491   /**
492    * DOCUMENT ME!
493    * 
494    * @param e
495    *          DOCUMENT ME!
496    * @throws FileFormatException
497    */
498   protected void inputURLMenuItem_actionPerformed(
499           jalview.gui.AlignViewport av) throws FileFormatException
500   {
501   }
502
503   /**
504    * DOCUMENT ME!
505    * 
506    * @param e
507    *          DOCUMENT ME!
508    */
509   protected void inputTextboxMenuItem_actionPerformed(
510           AlignmentViewPanel avp)
511   {
512   }
513
514   /**
515    * DOCUMENT ME!
516    */
517   protected void quit()
518   {
519     // System.out.println("********** GDesktop.quit()");
520   }
521
522   /**
523    * DOCUMENT ME!
524    * 
525    * @param e
526    *          DOCUMENT ME!
527    */
528   protected void aboutMenuItem_actionPerformed(ActionEvent e)
529   {
530   }
531
532   protected void documentationMenuItem_actionPerformed()
533   {
534   }
535
536   /**
537    * DOCUMENT ME!
538    * 
539    * @param e
540    *          DOCUMENT ME!
541    */
542   protected void preferences_actionPerformed(ActionEvent e)
543   {
544   }
545
546   /**
547    * DOCUMENT ME!
548    * 
549    * @param e
550    *          DOCUMENT ME!
551    */
552   public void saveState_actionPerformed()
553   {
554   }
555
556   public void saveAsState_actionPerformed(ActionEvent e)
557   {
558   }
559
560   /**
561    * DOCUMENT ME!
562    * 
563    * @param e
564    *          DOCUMENT ME!
565    */
566   public void loadState_actionPerformed()
567   {
568   }
569
570   /**
571    * DOCUMENT ME!
572    * 
573    * @param e
574    *          DOCUMENT ME!
575    */
576   public void loadJalviewAlign_actionPerformed(ActionEvent e)
577   {
578   }
579
580   public void vamsasStart_actionPerformed(ActionEvent e)
581   {
582
583   }
584
585   public void inputSequence_actionPerformed(ActionEvent e)
586   {
587
588   }
589
590   public void vamsasStop_actionPerformed(ActionEvent e)
591   {
592
593   }
594
595   public void closeAll_actionPerformed(ActionEvent e)
596   {
597
598   }
599
600   public void raiseRelated_actionPerformed(ActionEvent e)
601   {
602
603   }
604
605   public void minimizeAssociated_actionPerformed(ActionEvent e)
606   {
607
608   }
609
610   public void vamsasImport_actionPerformed(ActionEvent e)
611   {
612   }
613 }