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