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.io.FileFormatException;
36 import jalview.util.MessageManager;
37 import jalview.util.Platform;
45 @SuppressWarnings("serial")
46 public class GDesktop extends JFrame
49 protected static JMenu windowMenu = new JMenu();
51 JMenuBar desktopMenubar = new JMenuBar();
53 JMenu FileMenu = new JMenu();
55 JMenu HelpMenu = new JMenu();
57 JMenuItem inputLocalFileMenuItem = new JMenuItem();
59 JMenuItem inputURLMenuItem = new JMenuItem();
61 JMenuItem inputTextboxMenuItem = new JMenuItem();
63 JMenuItem quit = new JMenuItem();
65 JMenuItem aboutMenuItem = new JMenuItem();
67 JMenuItem documentationMenuItem = new JMenuItem();
69 FlowLayout flowLayout1 = new FlowLayout();
71 protected JMenu toolsMenu = new JMenu();
73 JMenuItem preferences = new JMenuItem();
75 JMenuItem saveState = new JMenuItem();
77 JMenuItem saveAsState = new JMenuItem();
79 JMenuItem loadState = new JMenuItem();
81 JMenu inputMenu = new JMenu();
83 JMenuItem inputSequence = new JMenuItem();
85 JMenuItem closeAll = new JMenuItem();
87 JMenuItem raiseRelated = new JMenuItem();
89 JMenuItem minimizeAssociated = new JMenuItem();
91 protected JCheckBoxMenuItem showMemusage = new JCheckBoxMenuItem();
93 JMenuItem garbageCollect = new JMenuItem();
95 protected JMenuItem groovyShell;
97 protected JCheckBoxMenuItem experimentalFeatures;
99 protected JCheckBoxMenuItem showConsole = new JCheckBoxMenuItem();
101 protected JCheckBoxMenuItem showNews = new JCheckBoxMenuItem();
103 protected JMenuItem snapShotWindow = new JMenuItem();
106 * Creates a new GDesktop object.
114 this.setJMenuBar(desktopMenubar);
115 } catch (Exception e)
120 if (Platform.allowMnemonics())
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');
141 private void jbInit() throws Exception
143 boolean apqHandlersSet = false;
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.
151 apqHandlersSet = APQHandlers.setAPQHandlers(this);
152 } catch (Exception e)
154 System.out.println("Cannot set APQHandlers");
155 // e.printStackTrace();
156 } catch (Throwable t)
159 .warn("Error setting APQHandlers: " + t.toString());
160 jalview.bin.Console.trace(Cache.getStackTraceString(t));
163 setName("jalview-desktop");
164 FileMenu.setText(MessageManager.getString("action.file"));
165 HelpMenu.setText(MessageManager.getString("action.help"));
166 inputLocalFileMenuItem
167 .setText(MessageManager.getString("label.load_tree_from_file"));
168 inputLocalFileMenuItem
170 javax.swing.KeyStroke
171 .getKeyStroke(java.awt.event.KeyEvent.VK_O,
172 jalview.util.ShortcutKeyMaskExWrapper
173 .getMenuShortcutKeyMaskEx(),
175 inputLocalFileMenuItem
176 .addActionListener(new java.awt.event.ActionListener()
179 public void actionPerformed(ActionEvent e)
181 inputLocalFileMenuItem_actionPerformed(null);
184 inputURLMenuItem.setText(MessageManager.getString("label.from_url"));
185 inputURLMenuItem.addActionListener(new java.awt.event.ActionListener()
188 public void actionPerformed(ActionEvent e)
192 inputURLMenuItem_actionPerformed(null);
193 } catch (FileFormatException e1)
195 System.err.println("Error loading from URL: " + e1.getMessage());
200 .setText(MessageManager.getString("label.from_textbox"));
202 .addActionListener(new java.awt.event.ActionListener()
205 public void actionPerformed(ActionEvent e)
207 inputTextboxMenuItem_actionPerformed(null);
210 quit.setText(MessageManager.getString("action.quit"));
211 quit.addActionListener(new java.awt.event.ActionListener()
214 public void actionPerformed(ActionEvent e)
219 aboutMenuItem.setText(MessageManager.getString("label.about"));
220 aboutMenuItem.addActionListener(new java.awt.event.ActionListener()
223 public void actionPerformed(ActionEvent e)
225 aboutMenuItem_actionPerformed(e);
228 documentationMenuItem
229 .setText(MessageManager.getString("label.documentation"));
230 documentationMenuItem.setAccelerator(javax.swing.KeyStroke
231 .getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0, false));
232 documentationMenuItem
233 .addActionListener(new java.awt.event.ActionListener()
236 public void actionPerformed(ActionEvent e)
238 documentationMenuItem_actionPerformed();
241 this.getContentPane().setLayout(flowLayout1);
242 windowMenu.setText(MessageManager.getString("label.window"));
243 preferences.setText(MessageManager.getString("label.preferences"));
244 preferences.addActionListener(new ActionListener()
247 public void actionPerformed(ActionEvent e)
249 preferences_actionPerformed(e);
252 toolsMenu.setText(MessageManager.getString("label.tools"));
253 saveState.setText(MessageManager.getString("action.save_project"));
254 saveState.addActionListener(new ActionListener()
257 public void actionPerformed(ActionEvent e)
259 saveState_actionPerformed();
262 saveAsState.setText(MessageManager.getString("action.save_project_as"));
263 saveAsState.addActionListener(new ActionListener()
266 public void actionPerformed(ActionEvent e)
268 saveAsState_actionPerformed(e);
271 loadState.setText(MessageManager.getString("action.load_project"));
272 loadState.addActionListener(new ActionListener()
275 public void actionPerformed(ActionEvent e)
277 loadState_actionPerformed();
280 inputMenu.setText(MessageManager.getString("label.input_alignment"));
282 .setText(MessageManager.getString("action.fetch_sequences"));
283 inputSequence.addActionListener(new ActionListener()
286 public void actionPerformed(ActionEvent e)
288 inputSequence_actionPerformed(e);
291 closeAll.setText(MessageManager.getString("action.close_all"));
292 closeAll.addActionListener(new ActionListener()
295 public void actionPerformed(ActionEvent e)
297 closeAll_actionPerformed(e);
300 raiseRelated.setText(
301 MessageManager.getString("action.raise_associated_windows"));
302 raiseRelated.addActionListener(new ActionListener()
305 public void actionPerformed(ActionEvent e)
307 raiseRelated_actionPerformed(e);
310 minimizeAssociated.setText(
311 MessageManager.getString("action.minimize_associated_windows"));
312 minimizeAssociated.addActionListener(new ActionListener()
315 public void actionPerformed(ActionEvent e)
317 minimizeAssociated_actionPerformed(e);
321 .setText(MessageManager.getString("label.collect_garbage"));
322 garbageCollect.addActionListener(new ActionListener()
325 public void actionPerformed(ActionEvent e)
327 garbageCollect_actionPerformed(e);
331 .setText(MessageManager.getString("label.show_memory_usage"));
332 showMemusage.addActionListener(new ActionListener()
335 public void actionPerformed(ActionEvent e)
337 showMemusage_actionPerformed(e);
341 .setText(MessageManager.getString("label.show_java_console"));
342 showConsole.addActionListener(new ActionListener()
345 public void actionPerformed(ActionEvent e)
347 showConsole_actionPerformed(e);
350 showNews.setText(MessageManager.getString("label.show_jalview_news"));
351 showNews.addActionListener(new ActionListener()
354 public void actionPerformed(ActionEvent e)
356 showNews_actionPerformed(e);
359 groovyShell = new JMenuItem();
360 groovyShell.setText(MessageManager.getString("label.groovy_console"));
361 groovyShell.addActionListener(new ActionListener()
364 public void actionPerformed(ActionEvent e)
366 groovyShell_actionPerformed();
369 experimentalFeatures = new JCheckBoxMenuItem();
371 .setText(MessageManager.getString("label.show_experimental"));
372 experimentalFeatures.setToolTipText(
373 MessageManager.getString("label.show_experimental_tip"));
374 experimentalFeatures.addActionListener(new ActionListener()
377 public void actionPerformed(ActionEvent e)
379 showExperimental_actionPerformed(experimentalFeatures.isSelected());
383 snapShotWindow.setText(MessageManager.getString("label.take_snapshot"));
384 snapShotWindow.addActionListener(new ActionListener()
387 public void actionPerformed(ActionEvent e)
389 snapShotWindow_actionPerformed(e);
393 desktopMenubar.add(FileMenu);
394 desktopMenubar.add(toolsMenu);
395 desktopMenubar.add(HelpMenu);
396 desktopMenubar.add(windowMenu);
397 FileMenu.add(inputMenu);
398 FileMenu.add(inputSequence);
399 FileMenu.addSeparator();
400 // FileMenu.add(saveState);
401 FileMenu.add(saveAsState);
402 FileMenu.add(loadState);
403 FileMenu.addSeparator();
404 if (!APQHandlers.setQuit)
408 if (!APQHandlers.setAbout)
410 HelpMenu.add(aboutMenuItem);
412 HelpMenu.add(documentationMenuItem);
413 if (!APQHandlers.setPreferences)
415 toolsMenu.add(preferences);
417 if (!Platform.isJS())
419 toolsMenu.add(showMemusage);
420 toolsMenu.add(showConsole);
421 toolsMenu.add(showNews);
422 toolsMenu.add(garbageCollect);
423 toolsMenu.add(groovyShell);
425 toolsMenu.add(experimentalFeatures);
426 // toolsMenu.add(snapShotWindow);
427 inputMenu.add(inputLocalFileMenuItem);
428 inputMenu.add(inputURLMenuItem);
429 inputMenu.add(inputTextboxMenuItem);
430 windowMenu.add(closeAll);
431 windowMenu.add(raiseRelated);
432 windowMenu.add(minimizeAssociated);
433 windowMenu.addSeparator();
434 // inputMenu.add(vamsasLoad);
437 protected void showExperimental_actionPerformed(boolean selected)
441 protected void groovyShell_actionPerformed()
445 protected void snapShotWindow_actionPerformed(ActionEvent e)
447 // TODO Auto-generated method stub
451 protected void showConsole_actionPerformed(ActionEvent e)
453 // TODO Auto-generated method stub
457 protected void showNews_actionPerformed(ActionEvent e)
459 // TODO Auto-generated method stub
463 protected void showMemusage_actionPerformed(ActionEvent e)
465 // TODO Auto-generated method stub
469 protected void garbageCollect_actionPerformed(ActionEvent e)
471 // TODO Auto-generated method stub
475 protected void vamsasStMenu_actionPerformed()
479 public void vamsasSave_actionPerformed(ActionEvent e)
489 protected void inputLocalFileMenuItem_actionPerformed(
490 jalview.gui.AlignViewport av)
499 * @throws FileFormatException
501 protected void inputURLMenuItem_actionPerformed(
502 jalview.gui.AlignViewport av) throws FileFormatException
512 protected void inputTextboxMenuItem_actionPerformed(
513 AlignmentViewPanel avp)
520 protected void quit()
522 // System.out.println("********** GDesktop.quit()");
531 protected void aboutMenuItem_actionPerformed(ActionEvent e)
535 protected void documentationMenuItem_actionPerformed()
545 protected void preferences_actionPerformed(ActionEvent e)
555 public void saveState_actionPerformed()
559 public void saveAsState_actionPerformed(ActionEvent e)
569 public void loadState_actionPerformed()
579 public void loadJalviewAlign_actionPerformed(ActionEvent e)
583 public void vamsasStart_actionPerformed(ActionEvent e)
588 public void inputSequence_actionPerformed(ActionEvent e)
593 public void vamsasStop_actionPerformed(ActionEvent e)
598 public void closeAll_actionPerformed(ActionEvent e)
603 public void raiseRelated_actionPerformed(ActionEvent e)
608 public void minimizeAssociated_actionPerformed(ActionEvent e)
613 public void vamsasImport_actionPerformed(ActionEvent e)