JAL-3949 fixed failing commandlinetests due to more output and line count limit
[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 = Platform.isJS() ? Float.valueOf(8)
370             : Float.parseFloat(
371                     System.getProperty("java.specification.version"));
372     
373     desktopMenubar.add(FileMenu);
374     desktopMenubar.add(toolsMenu);
375     desktopMenubar.add(HelpMenu);
376     desktopMenubar.add(windowMenu);
377     FileMenu.add(inputMenu);
378     FileMenu.add(inputSequence);
379     FileMenu.addSeparator();
380     //FileMenu.add(saveState);
381     FileMenu.add(saveAsState);
382     FileMenu.add(loadState);
383     FileMenu.addSeparator();
384     FileMenu.add(quit);
385     HelpMenu.add(aboutMenuItem);
386     HelpMenu.add(documentationMenuItem);
387     if (!Platform.isAMacAndNotJS() || specversion < 11)
388     {
389       toolsMenu.add(preferences);
390     }
391     if (!Platform.isJS())
392     {
393       toolsMenu.add(showMemusage);
394       toolsMenu.add(showConsole);
395       toolsMenu.add(showNews);
396       toolsMenu.add(garbageCollect);
397       toolsMenu.add(groovyShell);
398     }
399     toolsMenu.add(experimentalFeatures);
400     // toolsMenu.add(snapShotWindow);
401     inputMenu.add(inputLocalFileMenuItem);
402     inputMenu.add(inputURLMenuItem);
403     inputMenu.add(inputTextboxMenuItem);
404     windowMenu.add(closeAll);
405     windowMenu.add(raiseRelated);
406     windowMenu.add(minimizeAssociated);
407     windowMenu.addSeparator();
408     // inputMenu.add(vamsasLoad);
409   }
410
411   protected void showExperimental_actionPerformed(boolean selected)
412   {
413   }
414
415   protected void groovyShell_actionPerformed()
416   {
417   }
418
419   protected void snapShotWindow_actionPerformed(ActionEvent e)
420   {
421     // TODO Auto-generated method stub
422
423   }
424
425   protected void showConsole_actionPerformed(ActionEvent e)
426   {
427     // TODO Auto-generated method stub
428
429   }
430
431   protected void showNews_actionPerformed(ActionEvent e)
432   {
433     // TODO Auto-generated method stub
434
435   }
436
437   protected void showMemusage_actionPerformed(ActionEvent e)
438   {
439     // TODO Auto-generated method stub
440
441   }
442
443   protected void garbageCollect_actionPerformed(ActionEvent e)
444   {
445     // TODO Auto-generated method stub
446
447   }
448
449   protected void vamsasStMenu_actionPerformed()
450   {
451   }
452
453   public void vamsasSave_actionPerformed(ActionEvent e)
454   {
455   }
456
457   /**
458    * DOCUMENT ME!
459    * 
460    * @param e
461    *          DOCUMENT ME!
462    */
463   protected void inputLocalFileMenuItem_actionPerformed(
464           jalview.gui.AlignViewport av)
465   {
466   }
467
468   /**
469    * DOCUMENT ME!
470    * 
471    * @param e
472    *          DOCUMENT ME!
473    * @throws FileFormatException
474    */
475   protected void inputURLMenuItem_actionPerformed(
476           jalview.gui.AlignViewport av) throws FileFormatException
477   {
478   }
479
480   /**
481    * DOCUMENT ME!
482    * 
483    * @param e
484    *          DOCUMENT ME!
485    */
486   protected void inputTextboxMenuItem_actionPerformed(
487           AlignmentViewPanel avp)
488   {
489   }
490
491   /**
492    * DOCUMENT ME!
493    */
494   protected void quit()
495   {
496     //System.out.println("********** GDesktop.quit()");
497   }
498
499   /**
500    * DOCUMENT ME!
501    * 
502    * @param e
503    *          DOCUMENT ME!
504    */
505   protected void aboutMenuItem_actionPerformed(ActionEvent e)
506   {
507   }
508
509   protected void documentationMenuItem_actionPerformed()
510   {
511   }
512
513   /**
514    * DOCUMENT ME!
515    * 
516    * @param e
517    *          DOCUMENT ME!
518    */
519   protected void preferences_actionPerformed(ActionEvent e)
520   {
521   }
522
523   /**
524    * DOCUMENT ME!
525    * 
526    * @param e
527    *          DOCUMENT ME!
528    */
529   public void saveState_actionPerformed()
530   {
531   }
532
533   public void saveAsState_actionPerformed(ActionEvent e)
534   {
535   }
536
537   /**
538    * DOCUMENT ME!
539    * 
540    * @param e
541    *          DOCUMENT ME!
542    */
543   public void loadState_actionPerformed()
544   {
545   }
546
547   /**
548    * DOCUMENT ME!
549    * 
550    * @param e
551    *          DOCUMENT ME!
552    */
553   public void loadJalviewAlign_actionPerformed(ActionEvent e)
554   {
555   }
556
557   public void vamsasStart_actionPerformed(ActionEvent e)
558   {
559
560   }
561
562   public void inputSequence_actionPerformed(ActionEvent e)
563   {
564
565   }
566
567   public void vamsasStop_actionPerformed(ActionEvent e)
568   {
569
570   }
571
572   public void closeAll_actionPerformed(ActionEvent e)
573   {
574
575   }
576
577   public void raiseRelated_actionPerformed(ActionEvent e)
578   {
579
580   }
581
582   public void minimizeAssociated_actionPerformed(ActionEvent e)
583   {
584
585   }
586
587   public void vamsasImport_actionPerformed(ActionEvent e)
588   {
589   }
590 }