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.Desktop;
36 import jalview.io.FileFormatException;
37 import jalview.jbgui.QuitHandler.QResponse;
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
145 boolean apqHandlersSet = false;
147 * APQHandlers sets handlers for About, Preferences and Quit actions
148 * peculiar to macOS's application menu. APQHandlers will check to see if a
149 * handler is supported before setting it.
153 apqHandlersSet = APQHandlers.setAPQHandlers(this);
154 } catch (Exception e)
156 System.out.println("Cannot set APQHandlers");
157 // e.printStackTrace();
158 } catch (Throwable t)
161 .warn("Error setting APQHandlers: " + t.toString());
162 jalview.bin.Console.trace(Cache.getStackTraceString(t));
165 setName("jalview-desktop");
166 FileMenu.setText(MessageManager.getString("action.file"));
167 HelpMenu.setText(MessageManager.getString("action.help"));
168 inputLocalFileMenuItem
169 .setText(MessageManager.getString("label.load_tree_from_file"));
170 inputLocalFileMenuItem
172 javax.swing.KeyStroke
173 .getKeyStroke(java.awt.event.KeyEvent.VK_O,
174 jalview.util.ShortcutKeyMaskExWrapper
175 .getMenuShortcutKeyMaskEx(),
177 inputLocalFileMenuItem
178 .addActionListener(new java.awt.event.ActionListener()
181 public void actionPerformed(ActionEvent e)
183 inputLocalFileMenuItem_actionPerformed(null);
186 inputURLMenuItem.setText(MessageManager.getString("label.from_url"));
187 inputURLMenuItem.addActionListener(new java.awt.event.ActionListener()
190 public void actionPerformed(ActionEvent e)
194 inputURLMenuItem_actionPerformed(null);
195 } catch (FileFormatException e1)
197 System.err.println("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 QResponse qresponse = Desktop.instance != null
219 ? Desktop.instance.desktopQuit()
221 if (qresponse == QResponse.CANCEL_QUIT)
224 .debug("GDesktop: Quit action cancelled by user");
228 aboutMenuItem.setText(MessageManager.getString("label.about"));
229 aboutMenuItem.addActionListener(new java.awt.event.ActionListener()
232 public void actionPerformed(ActionEvent e)
234 aboutMenuItem_actionPerformed(e);
237 documentationMenuItem
238 .setText(MessageManager.getString("label.documentation"));
239 documentationMenuItem.setAccelerator(javax.swing.KeyStroke
240 .getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0, false));
241 documentationMenuItem
242 .addActionListener(new java.awt.event.ActionListener()
245 public void actionPerformed(ActionEvent e)
247 documentationMenuItem_actionPerformed();
250 this.getContentPane().setLayout(flowLayout1);
251 windowMenu.setText(MessageManager.getString("label.window"));
252 preferences.setText(MessageManager.getString("label.preferences"));
253 preferences.addActionListener(new ActionListener()
256 public void actionPerformed(ActionEvent e)
258 preferences_actionPerformed(e);
261 toolsMenu.setText(MessageManager.getString("label.tools"));
262 saveState.setText(MessageManager.getString("action.save_project"));
263 saveState.addActionListener(new ActionListener()
266 public void actionPerformed(ActionEvent e)
268 saveState_actionPerformed();
271 saveAsState.setText(MessageManager.getString("action.save_project_as"));
272 saveAsState.addActionListener(new ActionListener()
275 public void actionPerformed(ActionEvent e)
277 saveAsState_actionPerformed(e);
280 loadState.setText(MessageManager.getString("action.load_project"));
281 loadState.addActionListener(new ActionListener()
284 public void actionPerformed(ActionEvent e)
286 loadState_actionPerformed();
289 inputMenu.setText(MessageManager.getString("label.input_alignment"));
291 .setText(MessageManager.getString("action.fetch_sequences"));
292 inputSequence.addActionListener(new ActionListener()
295 public void actionPerformed(ActionEvent e)
297 inputSequence_actionPerformed(e);
300 closeAll.setText(MessageManager.getString("action.close_all"));
301 closeAll.addActionListener(new ActionListener()
304 public void actionPerformed(ActionEvent e)
306 closeAll_actionPerformed(e);
309 raiseRelated.setText(
310 MessageManager.getString("action.raise_associated_windows"));
311 raiseRelated.addActionListener(new ActionListener()
314 public void actionPerformed(ActionEvent e)
316 raiseRelated_actionPerformed(e);
319 minimizeAssociated.setText(
320 MessageManager.getString("action.minimize_associated_windows"));
321 minimizeAssociated.addActionListener(new ActionListener()
324 public void actionPerformed(ActionEvent e)
326 minimizeAssociated_actionPerformed(e);
330 .setText(MessageManager.getString("label.collect_garbage"));
331 garbageCollect.addActionListener(new ActionListener()
334 public void actionPerformed(ActionEvent e)
336 garbageCollect_actionPerformed(e);
340 .setText(MessageManager.getString("label.show_memory_usage"));
341 showMemusage.addActionListener(new ActionListener()
344 public void actionPerformed(ActionEvent e)
346 showMemusage_actionPerformed(e);
350 .setText(MessageManager.getString("label.show_java_console"));
351 showConsole.addActionListener(new ActionListener()
354 public void actionPerformed(ActionEvent e)
356 showConsole_actionPerformed(e);
359 showNews.setText(MessageManager.getString("label.show_jalview_news"));
360 showNews.addActionListener(new ActionListener()
363 public void actionPerformed(ActionEvent e)
365 showNews_actionPerformed(e);
368 groovyShell = new JMenuItem();
369 groovyShell.setText(MessageManager.getString("label.groovy_console"));
370 groovyShell.addActionListener(new ActionListener()
373 public void actionPerformed(ActionEvent e)
375 groovyShell_actionPerformed();
378 experimentalFeatures = new JCheckBoxMenuItem();
380 .setText(MessageManager.getString("label.show_experimental"));
381 experimentalFeatures.setToolTipText(
382 MessageManager.getString("label.show_experimental_tip"));
383 experimentalFeatures.addActionListener(new ActionListener()
386 public void actionPerformed(ActionEvent e)
388 showExperimental_actionPerformed(experimentalFeatures.isSelected());
392 snapShotWindow.setText(MessageManager.getString("label.take_snapshot"));
393 snapShotWindow.addActionListener(new ActionListener()
396 public void actionPerformed(ActionEvent e)
398 snapShotWindow_actionPerformed(e);
402 desktopMenubar.add(FileMenu);
403 desktopMenubar.add(toolsMenu);
404 desktopMenubar.add(HelpMenu);
405 desktopMenubar.add(windowMenu);
406 FileMenu.add(inputMenu);
407 FileMenu.add(inputSequence);
408 FileMenu.addSeparator();
409 // FileMenu.add(saveState);
410 FileMenu.add(saveAsState);
411 FileMenu.add(loadState);
412 FileMenu.addSeparator();
413 if (!APQHandlers.setQuit)
417 if (!APQHandlers.setAbout)
419 HelpMenu.add(aboutMenuItem);
421 HelpMenu.add(documentationMenuItem);
422 if (!APQHandlers.setPreferences)
424 toolsMenu.add(preferences);
426 if (!Platform.isJS())
428 toolsMenu.add(showMemusage);
429 toolsMenu.add(showConsole);
430 toolsMenu.add(showNews);
431 toolsMenu.add(garbageCollect);
432 toolsMenu.add(groovyShell);
434 toolsMenu.add(experimentalFeatures);
435 // toolsMenu.add(snapShotWindow);
436 inputMenu.add(inputLocalFileMenuItem);
437 inputMenu.add(inputURLMenuItem);
438 inputMenu.add(inputTextboxMenuItem);
439 windowMenu.add(closeAll);
440 windowMenu.add(raiseRelated);
441 windowMenu.add(minimizeAssociated);
442 windowMenu.addSeparator();
443 // inputMenu.add(vamsasLoad);
446 protected void showExperimental_actionPerformed(boolean selected)
450 protected void groovyShell_actionPerformed()
454 protected void snapShotWindow_actionPerformed(ActionEvent e)
456 // TODO Auto-generated method stub
460 protected void showConsole_actionPerformed(ActionEvent e)
462 // TODO Auto-generated method stub
466 protected void showNews_actionPerformed(ActionEvent e)
468 // TODO Auto-generated method stub
472 protected void showMemusage_actionPerformed(ActionEvent e)
474 // TODO Auto-generated method stub
478 protected void garbageCollect_actionPerformed(ActionEvent e)
480 // TODO Auto-generated method stub
484 protected void vamsasStMenu_actionPerformed()
488 public void vamsasSave_actionPerformed(ActionEvent e)
498 protected void inputLocalFileMenuItem_actionPerformed(
499 jalview.gui.AlignViewport av)
508 * @throws FileFormatException
510 protected void inputURLMenuItem_actionPerformed(
511 jalview.gui.AlignViewport av) throws FileFormatException
521 protected void inputTextboxMenuItem_actionPerformed(
522 AlignmentViewPanel avp)
529 protected void quit()
531 // System.out.println("********** GDesktop.quit()");
540 protected void aboutMenuItem_actionPerformed(ActionEvent e)
544 protected void documentationMenuItem_actionPerformed()
554 protected void preferences_actionPerformed(ActionEvent e)
564 public void saveState_actionPerformed()
568 public void saveAsState_actionPerformed(ActionEvent e)
578 public void loadState_actionPerformed()
588 public void loadJalviewAlign_actionPerformed(ActionEvent e)
592 public void vamsasStart_actionPerformed(ActionEvent e)
597 public void inputSequence_actionPerformed(ActionEvent e)
602 public void vamsasStop_actionPerformed(ActionEvent e)
607 public void closeAll_actionPerformed(ActionEvent e)
612 public void raiseRelated_actionPerformed(ActionEvent e)
617 public void minimizeAssociated_actionPerformed(ActionEvent e)
622 public void vamsasImport_actionPerformed(ActionEvent e)