2 * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3 * Copyright (C) $$Year-Rel$$ The Jalview Authors
5 * This file is part of Jalview.
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.
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.
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.
21 package jalview.jbgui;
23 import java.awt.FlowLayout;
24 import java.awt.event.ActionEvent;
25 import java.awt.event.ActionListener;
27 import javax.swing.JCheckBoxMenuItem;
28 import javax.swing.JFrame;
29 import javax.swing.JMenu;
30 import javax.swing.JMenuBar;
31 import javax.swing.JMenuItem;
33 import jalview.api.AlignmentViewPanel;
34 import jalview.bin.Cache;
35 import jalview.gui.APQHandlers;
36 import jalview.gui.Desktop;
37 import jalview.io.FileFormatException;
38 import jalview.util.MessageManager;
39 import jalview.util.Platform;
47 @SuppressWarnings("serial")
48 public class GDesktop extends JFrame
51 protected static JMenu windowMenu = new JMenu();
53 JMenuBar desktopMenubar = new JMenuBar();
55 JMenu FileMenu = new JMenu();
57 JMenu HelpMenu = new JMenu();
59 JMenuItem inputLocalFileMenuItem = new JMenuItem();
61 JMenuItem inputURLMenuItem = new JMenuItem();
63 JMenuItem inputTextboxMenuItem = new JMenuItem();
65 JMenuItem quit = new JMenuItem();
67 JMenuItem aboutMenuItem = new JMenuItem();
69 JMenuItem documentationMenuItem = new JMenuItem();
71 FlowLayout flowLayout1 = new FlowLayout();
73 protected JMenu toolsMenu = new JMenu();
75 JMenuItem preferences = new JMenuItem();
77 JMenuItem saveState = new JMenuItem();
79 JMenuItem saveAsState = new JMenuItem();
81 JMenuItem loadState = new JMenuItem();
83 JMenu inputMenu = new JMenu();
85 JMenuItem inputSequence = new JMenuItem();
87 JMenuItem closeAll = new JMenuItem();
89 JMenuItem raiseRelated = new JMenuItem();
91 JMenuItem minimizeAssociated = new JMenuItem();
93 protected JCheckBoxMenuItem showMemusage = new JCheckBoxMenuItem();
95 JMenuItem garbageCollect = new JMenuItem();
97 protected JMenuItem groovyShell;
99 protected JCheckBoxMenuItem experimentalFeatures;
101 protected JCheckBoxMenuItem showConsole = new JCheckBoxMenuItem();
103 protected JCheckBoxMenuItem showNews = new JCheckBoxMenuItem();
105 protected JMenuItem snapShotWindow = new JMenuItem();
108 * Creates a new GDesktop object.
116 this.setJMenuBar(desktopMenubar);
117 } catch (Exception e)
122 if (Platform.allowMnemonics())
124 // BH was !Platform.isAMacAndNotJS()) i.e. "JS or not Mac"
125 // but here we want just not a Mac, period, right?
126 FileMenu.setMnemonic('F');
127 inputLocalFileMenuItem.setMnemonic('L');
128 inputURLMenuItem.setMnemonic('U');
129 inputTextboxMenuItem.setMnemonic('C');
130 quit.setMnemonic('Q');
131 saveState.setMnemonic('S');
132 loadState.setMnemonic('L');
133 inputMenu.setMnemonic('I');
143 private void jbInit() throws Exception
146 * APQHandlers sets handlers for About, Preferences and Quit actions
147 * peculiar to macOS's application menu. APQHandlers will check to see if a
148 * handler is supported before setting it.
152 APQHandlers.setAPQHandlers((Desktop) this);
153 } catch (Exception e)
155 jalview.bin.Console.outPrintln("Cannot set APQHandlers");
156 // e.printStackTrace();
157 } catch (Throwable t)
160 .warn("Error setting APQHandlers: " + t.toString());
161 jalview.bin.Console.trace(Cache.getStackTraceString(t));
164 setName("jalview-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
171 javax.swing.KeyStroke
172 .getKeyStroke(java.awt.event.KeyEvent.VK_O,
173 jalview.util.ShortcutKeyMaskExWrapper
174 .getMenuShortcutKeyMaskEx(),
176 inputLocalFileMenuItem
177 .addActionListener(new java.awt.event.ActionListener()
180 public void actionPerformed(ActionEvent e)
182 inputLocalFileMenuItem_actionPerformed(null);
185 inputURLMenuItem.setText(MessageManager.getString("label.from_url"));
186 inputURLMenuItem.addActionListener(new java.awt.event.ActionListener()
189 public void actionPerformed(ActionEvent e)
193 inputURLMenuItem_actionPerformed(null);
194 } catch (FileFormatException e1)
197 .errPrintln("Error loading from URL: " + e1.getMessage());
202 .setText(MessageManager.getString("label.from_textbox"));
204 .addActionListener(new java.awt.event.ActionListener()
207 public void actionPerformed(ActionEvent e)
209 inputTextboxMenuItem_actionPerformed(null);
212 quit.setText(MessageManager.getString("action.quit"));
213 quit.addActionListener(new java.awt.event.ActionListener()
216 public void actionPerformed(ActionEvent e)
218 if (Desktop.instance != null)
219 Desktop.instance.desktopQuit();
222 aboutMenuItem.setText(MessageManager.getString("label.about"));
223 aboutMenuItem.addActionListener(new java.awt.event.ActionListener()
226 public void actionPerformed(ActionEvent e)
228 aboutMenuItem_actionPerformed(e);
231 documentationMenuItem
232 .setText(MessageManager.getString("label.documentation"));
233 documentationMenuItem.setAccelerator(javax.swing.KeyStroke
234 .getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0, false));
235 documentationMenuItem
236 .addActionListener(new java.awt.event.ActionListener()
239 public void actionPerformed(ActionEvent e)
241 documentationMenuItem_actionPerformed();
244 this.getContentPane().setLayout(flowLayout1);
245 windowMenu.setText(MessageManager.getString("label.window"));
246 preferences.setText(MessageManager.getString("label.preferences"));
247 preferences.addActionListener(new ActionListener()
250 public void actionPerformed(ActionEvent e)
252 preferences_actionPerformed(e);
255 toolsMenu.setText(MessageManager.getString("label.tools"));
256 saveState.setText(MessageManager.getString("action.save_project"));
257 saveState.addActionListener(new ActionListener()
260 public void actionPerformed(ActionEvent e)
262 saveState_actionPerformed();
265 saveAsState.setText(MessageManager.getString("action.save_project_as"));
266 saveAsState.addActionListener(new ActionListener()
269 public void actionPerformed(ActionEvent e)
271 saveAsState_actionPerformed(e);
274 loadState.setText(MessageManager.getString("action.load_project"));
275 loadState.addActionListener(new ActionListener()
278 public void actionPerformed(ActionEvent e)
280 loadState_actionPerformed();
283 inputMenu.setText(MessageManager.getString("label.input_alignment"));
285 .setText(MessageManager.getString("action.fetch_sequences"));
286 inputSequence.addActionListener(new ActionListener()
289 public void actionPerformed(ActionEvent e)
291 inputSequence_actionPerformed(e);
294 closeAll.setText(MessageManager.getString("action.close_all"));
295 closeAll.addActionListener(new ActionListener()
298 public void actionPerformed(ActionEvent e)
300 closeAll_actionPerformed(e);
303 raiseRelated.setText(
304 MessageManager.getString("action.raise_associated_windows"));
305 raiseRelated.addActionListener(new ActionListener()
308 public void actionPerformed(ActionEvent e)
310 raiseRelated_actionPerformed(e);
313 minimizeAssociated.setText(
314 MessageManager.getString("action.minimize_associated_windows"));
315 minimizeAssociated.addActionListener(new ActionListener()
318 public void actionPerformed(ActionEvent e)
320 minimizeAssociated_actionPerformed(e);
324 .setText(MessageManager.getString("label.collect_garbage"));
325 garbageCollect.addActionListener(new ActionListener()
328 public void actionPerformed(ActionEvent e)
330 garbageCollect_actionPerformed(e);
334 .setText(MessageManager.getString("label.show_memory_usage"));
335 showMemusage.addActionListener(new ActionListener()
338 public void actionPerformed(ActionEvent e)
340 showMemusage_actionPerformed(e);
344 .setText(MessageManager.getString("label.show_java_console"));
345 showConsole.addActionListener(new ActionListener()
348 public void actionPerformed(ActionEvent e)
350 showConsole_actionPerformed(e);
353 showNews.setText(MessageManager.getString("label.show_jalview_news"));
354 showNews.addActionListener(new ActionListener()
357 public void actionPerformed(ActionEvent e)
359 showNews_actionPerformed(e);
362 groovyShell = new JMenuItem();
363 groovyShell.setText(MessageManager.getString("label.groovy_console"));
364 groovyShell.addActionListener(new ActionListener()
367 public void actionPerformed(ActionEvent e)
369 groovyShell_actionPerformed();
372 experimentalFeatures = new JCheckBoxMenuItem();
374 .setText(MessageManager.getString("label.show_experimental"));
375 experimentalFeatures.setToolTipText(
376 MessageManager.getString("label.show_experimental_tip"));
377 experimentalFeatures.addActionListener(new ActionListener()
380 public void actionPerformed(ActionEvent e)
382 showExperimental_actionPerformed(experimentalFeatures.isSelected());
386 snapShotWindow.setText(MessageManager.getString("label.take_snapshot"));
387 snapShotWindow.addActionListener(new ActionListener()
390 public void actionPerformed(ActionEvent e)
392 snapShotWindow_actionPerformed(e);
396 desktopMenubar.add(FileMenu);
397 desktopMenubar.add(toolsMenu);
398 desktopMenubar.add(HelpMenu);
399 desktopMenubar.add(windowMenu);
400 FileMenu.add(inputMenu);
401 FileMenu.add(inputSequence);
402 FileMenu.addSeparator();
403 // FileMenu.add(saveState);
404 FileMenu.add(saveAsState);
405 FileMenu.add(loadState);
406 FileMenu.addSeparator();
407 if (!APQHandlers.setQuit)
411 if (!APQHandlers.setAbout)
413 HelpMenu.add(aboutMenuItem);
415 HelpMenu.add(documentationMenuItem);
416 if (!APQHandlers.setPreferences)
418 toolsMenu.add(preferences);
420 if (!Platform.isJS())
422 toolsMenu.add(showMemusage);
423 toolsMenu.add(showConsole);
424 toolsMenu.add(showNews);
425 toolsMenu.add(garbageCollect);
426 toolsMenu.add(groovyShell);
428 toolsMenu.add(experimentalFeatures);
429 // toolsMenu.add(snapShotWindow);
430 inputMenu.add(inputLocalFileMenuItem);
431 inputMenu.add(inputURLMenuItem);
432 inputMenu.add(inputTextboxMenuItem);
433 windowMenu.add(closeAll);
434 windowMenu.add(raiseRelated);
435 windowMenu.add(minimizeAssociated);
436 windowMenu.addSeparator();
437 // inputMenu.add(vamsasLoad);
440 protected void showExperimental_actionPerformed(boolean selected)
444 protected void groovyShell_actionPerformed()
448 protected void snapShotWindow_actionPerformed(ActionEvent e)
450 // TODO Auto-generated method stub
454 protected void showConsole_actionPerformed(ActionEvent e)
456 // TODO Auto-generated method stub
460 protected void showNews_actionPerformed(ActionEvent e)
462 // TODO Auto-generated method stub
466 protected void showMemusage_actionPerformed(ActionEvent e)
468 // TODO Auto-generated method stub
472 protected void garbageCollect_actionPerformed(ActionEvent e)
474 // TODO Auto-generated method stub
478 protected void vamsasStMenu_actionPerformed()
482 public void vamsasSave_actionPerformed(ActionEvent e)
492 protected void inputLocalFileMenuItem_actionPerformed(
493 jalview.gui.AlignViewport av)
502 * @throws FileFormatException
504 protected void inputURLMenuItem_actionPerformed(
505 jalview.gui.AlignViewport av) throws FileFormatException
515 protected void inputTextboxMenuItem_actionPerformed(
516 AlignmentViewPanel avp)
523 protected void quit()
525 // jalview.bin.Console.outPrintln("********** GDesktop.quit()");
534 protected void aboutMenuItem_actionPerformed(ActionEvent e)
538 protected void documentationMenuItem_actionPerformed()
548 protected void preferences_actionPerformed(ActionEvent e)
558 public void saveState_actionPerformed()
562 public void saveAsState_actionPerformed(ActionEvent e)
572 public void loadState_actionPerformed()
582 public void loadJalviewAlign_actionPerformed(ActionEvent e)
586 public void vamsasStart_actionPerformed(ActionEvent e)
591 public void inputSequence_actionPerformed(ActionEvent e)
596 public void vamsasStop_actionPerformed(ActionEvent e)
601 public void closeAll_actionPerformed(ActionEvent e)
606 public void raiseRelated_actionPerformed(ActionEvent e)
611 public void minimizeAssociated_actionPerformed(ActionEvent e)
616 public void vamsasImport_actionPerformed(ActionEvent e)