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 System.out.println("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)
196 System.err.println("Error loading from URL: " + e1.getMessage());
201 .setText(MessageManager.getString("label.from_textbox"));
203 .addActionListener(new java.awt.event.ActionListener()
206 public void actionPerformed(ActionEvent e)
208 inputTextboxMenuItem_actionPerformed(null);
211 quit.setText(MessageManager.getString("action.quit"));
212 quit.addActionListener(new java.awt.event.ActionListener()
215 public void actionPerformed(ActionEvent e)
217 if (Desktop.instance != null)
218 Desktop.instance.desktopQuit();
221 aboutMenuItem.setText(MessageManager.getString("label.about"));
222 aboutMenuItem.addActionListener(new java.awt.event.ActionListener()
225 public void actionPerformed(ActionEvent e)
227 aboutMenuItem_actionPerformed(e);
230 documentationMenuItem
231 .setText(MessageManager.getString("label.documentation"));
232 documentationMenuItem.setAccelerator(javax.swing.KeyStroke
233 .getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0, false));
234 documentationMenuItem
235 .addActionListener(new java.awt.event.ActionListener()
238 public void actionPerformed(ActionEvent e)
240 documentationMenuItem_actionPerformed();
243 this.getContentPane().setLayout(flowLayout1);
244 windowMenu.setText(MessageManager.getString("label.window"));
245 preferences.setText(MessageManager.getString("label.preferences"));
246 preferences.addActionListener(new ActionListener()
249 public void actionPerformed(ActionEvent e)
251 preferences_actionPerformed(e);
254 toolsMenu.setText(MessageManager.getString("label.tools"));
255 saveState.setText(MessageManager.getString("action.save_project"));
256 saveState.addActionListener(new ActionListener()
259 public void actionPerformed(ActionEvent e)
261 saveState_actionPerformed();
264 saveAsState.setText(MessageManager.getString("action.save_project_as"));
265 saveAsState.addActionListener(new ActionListener()
268 public void actionPerformed(ActionEvent e)
270 saveAsState_actionPerformed(e);
273 loadState.setText(MessageManager.getString("action.load_project"));
274 loadState.addActionListener(new ActionListener()
277 public void actionPerformed(ActionEvent e)
279 loadState_actionPerformed();
282 inputMenu.setText(MessageManager.getString("label.input_alignment"));
284 .setText(MessageManager.getString("action.fetch_sequences"));
285 inputSequence.addActionListener(new ActionListener()
288 public void actionPerformed(ActionEvent e)
290 inputSequence_actionPerformed(e);
293 closeAll.setText(MessageManager.getString("action.close_all"));
294 closeAll.addActionListener(new ActionListener()
297 public void actionPerformed(ActionEvent e)
299 closeAll_actionPerformed(e);
302 raiseRelated.setText(
303 MessageManager.getString("action.raise_associated_windows"));
304 raiseRelated.addActionListener(new ActionListener()
307 public void actionPerformed(ActionEvent e)
309 raiseRelated_actionPerformed(e);
312 minimizeAssociated.setText(
313 MessageManager.getString("action.minimize_associated_windows"));
314 minimizeAssociated.addActionListener(new ActionListener()
317 public void actionPerformed(ActionEvent e)
319 minimizeAssociated_actionPerformed(e);
323 .setText(MessageManager.getString("label.collect_garbage"));
324 garbageCollect.addActionListener(new ActionListener()
327 public void actionPerformed(ActionEvent e)
329 garbageCollect_actionPerformed(e);
333 .setText(MessageManager.getString("label.show_memory_usage"));
334 showMemusage.addActionListener(new ActionListener()
337 public void actionPerformed(ActionEvent e)
339 showMemusage_actionPerformed(e);
343 .setText(MessageManager.getString("label.show_java_console"));
344 showConsole.addActionListener(new ActionListener()
347 public void actionPerformed(ActionEvent e)
349 showConsole_actionPerformed(e);
352 showNews.setText(MessageManager.getString("label.show_jalview_news"));
353 showNews.addActionListener(new ActionListener()
356 public void actionPerformed(ActionEvent e)
358 showNews_actionPerformed(e);
361 groovyShell = new JMenuItem();
362 groovyShell.setText(MessageManager.getString("label.groovy_console"));
363 groovyShell.addActionListener(new ActionListener()
366 public void actionPerformed(ActionEvent e)
368 groovyShell_actionPerformed();
371 experimentalFeatures = new JCheckBoxMenuItem();
373 .setText(MessageManager.getString("label.show_experimental"));
374 experimentalFeatures.setToolTipText(
375 MessageManager.getString("label.show_experimental_tip"));
376 experimentalFeatures.addActionListener(new ActionListener()
379 public void actionPerformed(ActionEvent e)
381 showExperimental_actionPerformed(experimentalFeatures.isSelected());
385 snapShotWindow.setText(MessageManager.getString("label.take_snapshot"));
386 snapShotWindow.addActionListener(new ActionListener()
389 public void actionPerformed(ActionEvent e)
391 snapShotWindow_actionPerformed(e);
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)
410 if (!APQHandlers.setAbout)
412 HelpMenu.add(aboutMenuItem);
414 HelpMenu.add(documentationMenuItem);
415 if (!APQHandlers.setPreferences)
417 toolsMenu.add(preferences);
419 if (!Platform.isJS())
421 toolsMenu.add(showMemusage);
422 toolsMenu.add(showConsole);
423 toolsMenu.add(showNews);
424 toolsMenu.add(garbageCollect);
425 toolsMenu.add(groovyShell);
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);
439 protected void showExperimental_actionPerformed(boolean selected)
443 protected void groovyShell_actionPerformed()
447 protected void snapShotWindow_actionPerformed(ActionEvent e)
449 // TODO Auto-generated method stub
453 protected void showConsole_actionPerformed(ActionEvent e)
455 // TODO Auto-generated method stub
459 protected void showNews_actionPerformed(ActionEvent e)
461 // TODO Auto-generated method stub
465 protected void showMemusage_actionPerformed(ActionEvent e)
467 // TODO Auto-generated method stub
471 protected void garbageCollect_actionPerformed(ActionEvent e)
473 // TODO Auto-generated method stub
477 protected void vamsasStMenu_actionPerformed()
481 public void vamsasSave_actionPerformed(ActionEvent e)
491 protected void inputLocalFileMenuItem_actionPerformed(
492 jalview.gui.AlignViewport av)
501 * @throws FileFormatException
503 protected void inputURLMenuItem_actionPerformed(
504 jalview.gui.AlignViewport av) throws FileFormatException
514 protected void inputTextboxMenuItem_actionPerformed(
515 AlignmentViewPanel avp)
522 protected void quit()
524 // System.out.println("********** GDesktop.quit()");
533 protected void aboutMenuItem_actionPerformed(ActionEvent e)
537 protected void documentationMenuItem_actionPerformed()
547 protected void preferences_actionPerformed(ActionEvent e)
557 public void saveState_actionPerformed()
561 public void saveAsState_actionPerformed(ActionEvent e)
571 public void loadState_actionPerformed()
581 public void loadJalviewAlign_actionPerformed(ActionEvent e)
585 public void vamsasStart_actionPerformed(ActionEvent e)
590 public void inputSequence_actionPerformed(ActionEvent e)
595 public void vamsasStop_actionPerformed(ActionEvent e)
600 public void closeAll_actionPerformed(ActionEvent e)
605 public void raiseRelated_actionPerformed(ActionEvent e)
610 public void minimizeAssociated_actionPerformed(ActionEvent e)
615 public void vamsasImport_actionPerformed(ActionEvent e)