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;
24 import java.awt.FlowLayout;
25 import java.awt.event.ActionEvent;
26 import java.awt.event.ActionListener;
28 import javax.swing.JCheckBoxMenuItem;
29 import javax.swing.JFrame;
30 import javax.swing.JMenu;
31 import javax.swing.JMenuBar;
32 import javax.swing.JMenuItem;
34 import jalview.api.AlignmentViewPanel;
35 import jalview.bin.Cache;
36 import jalview.io.FileFormatException;
37 import jalview.util.MessageManager;
38 import jalview.util.Platform;
45 @SuppressWarnings("serial")
46 public class GDesktop extends JFrame
49 protected 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 // TODO: if (!Platform.isJS()
152 apqHandlersSet = APQHandlers.setAPQHandlers(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(Platform.getAppID("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.setAccelerator(
170 javax.swing.KeyStroke.getKeyStroke(java.awt.event.KeyEvent.VK_O,
171 Platform.SHORTCUT_KEY_MASK,
173 inputLocalFileMenuItem
174 .addActionListener(new java.awt.event.ActionListener()
177 public void actionPerformed(ActionEvent e)
179 inputLocalFileMenuItem_actionPerformed(null);
182 inputURLMenuItem.setText(MessageManager.getString("label.from_url"));
183 inputURLMenuItem.addActionListener(new java.awt.event.ActionListener()
186 public void actionPerformed(ActionEvent e)
190 inputURLMenuItem_actionPerformed(null);
191 } catch (FileFormatException e1)
193 System.err.println("Error loading from URL: " + e1.getMessage());
198 .setText(MessageManager.getString("label.from_textbox"));
200 .addActionListener(new java.awt.event.ActionListener()
203 public void actionPerformed(ActionEvent e)
205 inputTextboxMenuItem_actionPerformed(null);
208 quit.setText(MessageManager.getString("action.quit"));
209 quit.addActionListener(new java.awt.event.ActionListener()
212 public void actionPerformed(ActionEvent e)
217 aboutMenuItem.setText(MessageManager.getString("label.about"));
218 aboutMenuItem.addActionListener(new java.awt.event.ActionListener()
221 public void actionPerformed(ActionEvent e)
223 aboutMenuItem_actionPerformed(e);
226 documentationMenuItem
227 .setText(MessageManager.getString("label.documentation"));
228 documentationMenuItem.setAccelerator(javax.swing.KeyStroke
229 .getKeyStroke(java.awt.event.KeyEvent.VK_F1, 0, false));
230 documentationMenuItem
231 .addActionListener(new java.awt.event.ActionListener()
234 public void actionPerformed(ActionEvent e)
236 documentationMenuItem_actionPerformed();
239 this.getContentPane().setLayout(flowLayout1);
240 windowMenu.setText(MessageManager.getString("label.window"));
241 preferences.setText(MessageManager.getString("label.preferences"));
242 preferences.addActionListener(new ActionListener()
245 public void actionPerformed(ActionEvent e)
247 preferences_actionPerformed(e);
250 toolsMenu.setText(MessageManager.getString("label.tools"));
251 saveState.setText(MessageManager.getString("action.save_project"));
252 saveState.addActionListener(new ActionListener()
255 public void actionPerformed(ActionEvent e)
257 saveState_actionPerformed();
260 saveAsState.setText(MessageManager.getString("action.save_project_as"));
261 saveAsState.addActionListener(new ActionListener()
264 public void actionPerformed(ActionEvent e)
266 saveAsState_actionPerformed(e);
269 loadState.setText(MessageManager.getString("action.load_project"));
270 loadState.addActionListener(new ActionListener()
273 public void actionPerformed(ActionEvent e)
275 loadState_actionPerformed();
278 inputMenu.setText(MessageManager.getString("label.input_alignment"));
280 .setText(MessageManager.getString("action.fetch_sequences"));
281 inputSequence.addActionListener(new ActionListener()
284 public void actionPerformed(ActionEvent e)
286 inputSequence_actionPerformed(e);
289 closeAll.setText(MessageManager.getString("action.close_all"));
290 closeAll.addActionListener(new ActionListener()
293 public void actionPerformed(ActionEvent e)
295 closeAll_actionPerformed(e);
298 raiseRelated.setText(
299 MessageManager.getString("action.raise_associated_windows"));
300 raiseRelated.addActionListener(new ActionListener()
303 public void actionPerformed(ActionEvent e)
305 raiseRelated_actionPerformed(e);
308 minimizeAssociated.setText(
309 MessageManager.getString("action.minimize_associated_windows"));
310 minimizeAssociated.addActionListener(new ActionListener()
313 public void actionPerformed(ActionEvent e)
315 minimizeAssociated_actionPerformed(e);
319 .setText(MessageManager.getString("label.collect_garbage"));
320 garbageCollect.addActionListener(new ActionListener()
323 public void actionPerformed(ActionEvent e)
325 garbageCollect_actionPerformed(e);
329 .setText(MessageManager.getString("label.show_memory_usage"));
330 showMemusage.addActionListener(new ActionListener()
333 public void actionPerformed(ActionEvent e)
335 showMemusage_actionPerformed(e);
339 .setText(MessageManager.getString("label.show_java_console"));
340 showConsole.addActionListener(new ActionListener()
343 public void actionPerformed(ActionEvent e)
345 showConsole_actionPerformed(e);
348 showNews.setText(MessageManager.getString("label.show_jalview_news"));
349 showNews.addActionListener(new ActionListener()
352 public void actionPerformed(ActionEvent e)
354 showNews_actionPerformed(e);
357 groovyShell = new JMenuItem();
358 groovyShell.setText(MessageManager.getString("label.groovy_console"));
359 groovyShell.addActionListener(new ActionListener()
362 public void actionPerformed(ActionEvent e)
364 groovyShell_actionPerformed();
367 experimentalFeatures = new JCheckBoxMenuItem();
369 .setText(MessageManager.getString("label.show_experimental"));
370 experimentalFeatures.setToolTipText(
371 MessageManager.getString("label.show_experimental_tip"));
372 experimentalFeatures.addActionListener(new ActionListener()
375 public void actionPerformed(ActionEvent e)
377 showExperimental_actionPerformed(experimentalFeatures.isSelected());
381 snapShotWindow.setText(MessageManager.getString("label.take_snapshot"));
382 snapShotWindow.addActionListener(new ActionListener()
385 public void actionPerformed(ActionEvent e)
387 snapShotWindow_actionPerformed(e);
391 Float specversion = Platform.isJS() ? Float.valueOf(8)
393 System.getProperty("java.specification.version"));
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)