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