JAL-3210 Merge branch 'develop' into trialMerge
[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 @SuppressWarnings("serial")
45 public class GDesktop extends JFrame
46 {
47
48   protected static JMenu windowMenu = new JMenu();
49
50   JMenuBar desktopMenubar = new JMenuBar();
51
52   JMenu FileMenu = new JMenu();
53
54   JMenu HelpMenu = new JMenu();
55
56   JMenuItem inputLocalFileMenuItem = new JMenuItem();
57
58   JMenuItem inputURLMenuItem = new JMenuItem();
59
60   JMenuItem inputTextboxMenuItem = new JMenuItem();
61
62   JMenuItem quit = new JMenuItem();
63
64   JMenuItem aboutMenuItem = new JMenuItem();
65
66   JMenuItem documentationMenuItem = new JMenuItem();
67
68   FlowLayout flowLayout1 = new FlowLayout();
69
70   protected JMenu toolsMenu = new JMenu();
71
72   JMenuItem preferences = new JMenuItem();
73
74   JMenuItem saveState = new JMenuItem();
75
76   JMenuItem saveAsState = new JMenuItem();
77
78   JMenuItem loadState = new JMenuItem();
79
80   JMenu inputMenu = new JMenu();
81
82   JMenuItem inputSequence = new JMenuItem();
83
84   JMenuItem closeAll = new JMenuItem();
85
86   JMenuItem raiseRelated = new JMenuItem();
87
88   JMenuItem minimizeAssociated = new JMenuItem();
89
90   protected JCheckBoxMenuItem showMemusage = new JCheckBoxMenuItem();
91
92   JMenuItem garbageCollect = new JMenuItem();
93
94   protected JMenuItem groovyShell;
95
96   protected JCheckBoxMenuItem experimentalFeatures;
97
98   protected JCheckBoxMenuItem showConsole = new JCheckBoxMenuItem();
99
100   protected JCheckBoxMenuItem showNews = new JCheckBoxMenuItem();
101
102   protected JMenuItem snapShotWindow = new JMenuItem();
103
104   /**
105    * Creates a new GDesktop object.
106    */
107   public GDesktop()
108   {
109     super();
110     try
111     {
112       jbInit();
113       this.setJMenuBar(desktopMenubar);
114     } catch (Exception e)
115     {
116       e.printStackTrace();
117     }
118
119     if (Platform.allowMnemonics()) 
120     {
121         //BH was !Platform.isAMacAndNotJS()) i.e. "JS or not Mac"
122         // but here we want just not a Mac, period, right?
123       FileMenu.setMnemonic('F');
124       inputLocalFileMenuItem.setMnemonic('L');
125       inputURLMenuItem.setMnemonic('U');
126       inputTextboxMenuItem.setMnemonic('C');
127       quit.setMnemonic('Q');
128       saveState.setMnemonic('S');
129       loadState.setMnemonic('L');
130       inputMenu.setMnemonic('I');
131     }
132   }
133
134   /**
135    * DOCUMENT ME!
136    * 
137    * @throws Exception
138    *           DOCUMENT ME!
139    */
140   private void jbInit() throws Exception
141   {
142     setName("jalview-desktop");
143     FileMenu.setText(MessageManager.getString("action.file"));
144     HelpMenu.setText(MessageManager.getString("action.help"));
145     inputLocalFileMenuItem
146             .setText(MessageManager.getString("label.load_tree_from_file"));
147     inputLocalFileMenuItem.setAccelerator(
148             javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O,
149                     jalview.util.ShortcutKeyMaskExWrapper.getMenuShortcutKeyMaskEx(),
150                     false));
151     inputLocalFileMenuItem
152             .addActionListener(new java.awt.event.ActionListener()
153             {
154               @Override
155               public void actionPerformed(ActionEvent e)
156               {
157                 inputLocalFileMenuItem_actionPerformed(null);
158               }
159             });
160     inputURLMenuItem.setText(MessageManager.getString("label.from_url"));
161     inputURLMenuItem.addActionListener(new java.awt.event.ActionListener()
162     {
163       @Override
164       public void actionPerformed(ActionEvent e)
165       {
166         try
167         {
168           inputURLMenuItem_actionPerformed(null);
169         } catch (FileFormatException e1)
170         {
171           System.err.println("Error loading from URL: " + e1.getMessage());
172         }
173       }
174     });
175     inputTextboxMenuItem
176             .setText(MessageManager.getString("label.from_textbox"));
177     inputTextboxMenuItem
178             .addActionListener(new java.awt.event.ActionListener()
179             {
180               @Override
181               public void actionPerformed(ActionEvent e)
182               {
183                 inputTextboxMenuItem_actionPerformed(null);
184               }
185             });
186     quit.setText(MessageManager.getString("action.quit"));
187     quit.addActionListener(new java.awt.event.ActionListener()
188     {
189       @Override
190       public void actionPerformed(ActionEvent e)
191       {
192         quit();
193       }
194     });
195     aboutMenuItem.setText(MessageManager.getString("label.about"));
196     aboutMenuItem.addActionListener(new java.awt.event.ActionListener()
197     {
198       @Override
199       public void actionPerformed(ActionEvent e)
200       {
201         aboutMenuItem_actionPerformed(e);
202       }
203     });
204     documentationMenuItem
205             .setText(MessageManager.getString("label.documentation"));
206     documentationMenuItem.setAccelerator(javax.swing.KeyStroke
207             .getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0, false));
208     documentationMenuItem
209             .addActionListener(new java.awt.event.ActionListener()
210             {
211               @Override
212               public void actionPerformed(ActionEvent e)
213               {
214                 documentationMenuItem_actionPerformed();
215               }
216             });
217     this.getContentPane().setLayout(flowLayout1);
218     windowMenu.setText(MessageManager.getString("label.window"));
219     preferences.setText(MessageManager.getString("label.preferences"));
220     preferences.addActionListener(new ActionListener()
221     {
222       @Override
223       public void actionPerformed(ActionEvent e)
224       {
225         preferences_actionPerformed(e);
226       }
227     });
228     toolsMenu.setText(MessageManager.getString("label.tools"));
229     saveState.setText(MessageManager.getString("action.save_project"));
230     saveState.addActionListener(new ActionListener()
231     {
232       @Override
233       public void actionPerformed(ActionEvent e)
234       {
235         saveState_actionPerformed();
236       }
237     });
238     saveAsState.setText(MessageManager.getString("action.save_project_as"));
239     saveAsState.addActionListener(new ActionListener()
240     {
241       @Override
242       public void actionPerformed(ActionEvent e)
243       {
244         saveAsState_actionPerformed(e);
245       }
246     });
247     loadState.setText(MessageManager.getString("action.load_project"));
248     loadState.addActionListener(new ActionListener()
249     {
250       @Override
251       public void actionPerformed(ActionEvent e)
252       {
253         loadState_actionPerformed();
254       }
255     });
256     inputMenu.setText(MessageManager.getString("label.input_alignment"));
257     inputSequence
258             .setText(MessageManager.getString("action.fetch_sequences"));
259     inputSequence.addActionListener(new ActionListener()
260     {
261       @Override
262       public void actionPerformed(ActionEvent e)
263       {
264         inputSequence_actionPerformed(e);
265       }
266     });
267     closeAll.setText(MessageManager.getString("action.close_all"));
268     closeAll.addActionListener(new ActionListener()
269     {
270       @Override
271       public void actionPerformed(ActionEvent e)
272       {
273         closeAll_actionPerformed(e);
274       }
275     });
276     raiseRelated.setText(
277             MessageManager.getString("action.raise_associated_windows"));
278     raiseRelated.addActionListener(new ActionListener()
279     {
280       @Override
281       public void actionPerformed(ActionEvent e)
282       {
283         raiseRelated_actionPerformed(e);
284       }
285     });
286     minimizeAssociated.setText(
287             MessageManager.getString("action.minimize_associated_windows"));
288     minimizeAssociated.addActionListener(new ActionListener()
289     {
290       @Override
291       public void actionPerformed(ActionEvent e)
292       {
293         minimizeAssociated_actionPerformed(e);
294       }
295     });
296     garbageCollect
297             .setText(MessageManager.getString("label.collect_garbage"));
298     garbageCollect.addActionListener(new ActionListener()
299     {
300       @Override
301       public void actionPerformed(ActionEvent e)
302       {
303         garbageCollect_actionPerformed(e);
304       }
305     });
306     showMemusage
307             .setText(MessageManager.getString("label.show_memory_usage"));
308     showMemusage.addActionListener(new ActionListener()
309     {
310       @Override
311       public void actionPerformed(ActionEvent e)
312       {
313         showMemusage_actionPerformed(e);
314       }
315     });
316     showConsole
317             .setText(MessageManager.getString("label.show_java_console"));
318     showConsole.addActionListener(new ActionListener()
319     {
320       @Override
321       public void actionPerformed(ActionEvent e)
322       {
323         showConsole_actionPerformed(e);
324       }
325     });
326     showNews.setText(MessageManager.getString("label.show_jalview_news"));
327     showNews.addActionListener(new ActionListener()
328     {
329       @Override
330       public void actionPerformed(ActionEvent e)
331       {
332         showNews_actionPerformed(e);
333       }
334     });
335     groovyShell = new JMenuItem();
336     groovyShell.setText(MessageManager.getString("label.groovy_console"));
337     groovyShell.addActionListener(new ActionListener()
338     {
339       @Override
340       public void actionPerformed(ActionEvent e)
341       {
342         groovyShell_actionPerformed();
343       }
344     });
345     experimentalFeatures = new JCheckBoxMenuItem();
346     experimentalFeatures
347             .setText(MessageManager.getString("label.show_experimental"));
348     experimentalFeatures.setToolTipText(
349             MessageManager.getString("label.show_experimental_tip"));
350     experimentalFeatures.addActionListener(new ActionListener()
351     {
352       @Override
353       public void actionPerformed(ActionEvent e)
354       {
355         showExperimental_actionPerformed(experimentalFeatures.isSelected());
356       }
357     });
358
359     snapShotWindow.setText(MessageManager.getString("label.take_snapshot"));
360     snapShotWindow.addActionListener(new ActionListener()
361     {
362       @Override
363       public void actionPerformed(ActionEvent e)
364       {
365         snapShotWindow_actionPerformed(e);
366       }
367     });
368
369     Float specversion = Float.parseFloat(System.getProperty("java.specification.version"));
370     
371     desktopMenubar.add(FileMenu);
372     desktopMenubar.add(toolsMenu);
373     desktopMenubar.add(HelpMenu);
374     desktopMenubar.add(windowMenu);
375     FileMenu.add(inputMenu);
376     FileMenu.add(inputSequence);
377     FileMenu.addSeparator();
378     //FileMenu.add(saveState);
379     FileMenu.add(saveAsState);
380     FileMenu.add(loadState);
381     FileMenu.addSeparator();
382     FileMenu.add(quit);
383     HelpMenu.add(aboutMenuItem);
384     HelpMenu.add(documentationMenuItem);
385     if (!Platform.isAMacAndNotJS() || specversion < 11)
386     {
387       toolsMenu.add(preferences);
388     }
389     if (!Platform.isJS())
390     {
391       toolsMenu.add(showMemusage);
392       toolsMenu.add(showConsole);
393       toolsMenu.add(showNews);
394       toolsMenu.add(garbageCollect);
395       toolsMenu.add(groovyShell);
396     }
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   protected void documentationMenuItem_actionPerformed()
508   {
509   }
510
511   /**
512    * DOCUMENT ME!
513    * 
514    * @param e
515    *          DOCUMENT ME!
516    */
517   protected void preferences_actionPerformed(ActionEvent e)
518   {
519   }
520
521   /**
522    * DOCUMENT ME!
523    * 
524    * @param e
525    *          DOCUMENT ME!
526    */
527   public void saveState_actionPerformed()
528   {
529   }
530
531   public void saveAsState_actionPerformed(ActionEvent e)
532   {
533   }
534
535   /**
536    * DOCUMENT ME!
537    * 
538    * @param e
539    *          DOCUMENT ME!
540    */
541   public void loadState_actionPerformed()
542   {
543   }
544
545   /**
546    * DOCUMENT ME!
547    * 
548    * @param e
549    *          DOCUMENT ME!
550    */
551   public void loadJalviewAlign_actionPerformed(ActionEvent e)
552   {
553   }
554
555   public void vamsasStart_actionPerformed(ActionEvent e)
556   {
557
558   }
559
560   public void inputSequence_actionPerformed(ActionEvent e)
561   {
562
563   }
564
565   public void vamsasStop_actionPerformed(ActionEvent e)
566   {
567
568   }
569
570   public void closeAll_actionPerformed(ActionEvent e)
571   {
572
573   }
574
575   public void raiseRelated_actionPerformed(ActionEvent e)
576   {
577
578   }
579
580   public void minimizeAssociated_actionPerformed(ActionEvent e)
581   {
582
583   }
584
585   public void vamsasImport_actionPerformed(ActionEvent e)
586   {
587   }
588 }