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