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