Debian Codegraph @

src/dr/app/beauti/BeautiMacFileMenuFactory.java

raw symbols SCIP
1 /*
2 * BeautiMacFileMenuFactory.java
3 *
4 * Copyright (c) 2002-2015 Alexei Drummond, Andrew Rambaut and Marc Suchard
5 *
6 * This file is part of BEAST.
7 * See the NOTICE file distributed with this work for additional
8 * information regarding copyright ownership and licensing.
9 *
10 * BEAST is free software; you can redistribute it and/or modify
11 * it under the terms of the GNU Lesser General Public License as
12 * published by the Free Software Foundation; either version 2
13 * of the License, or (at your option) any later version.
14 *
15 * BEAST is distributed in the hope that it will be useful,
16 * but WITHOUT ANY WARRANTY; without even the implied warranty of
17 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 * GNU Lesser General Public License for more details.
19 *
20 * You should have received a copy of the GNU Lesser General Public
21 * License along with BEAST; if not, write to the
22 * Free Software Foundation, Inc., 51 Franklin St, Fifth Floor,
23 * Boston, MA 02110-1301 USA
24 */
25
26 package dr.app.beauti;
27
28 import jam.framework.MenuFactory;
29 import jam.framework.AbstractFrame;
30 import jam.framework.Application;
31 import jam.framework.MenuBarFactory;
32
33 import javax.swing.*;
34 import java.awt.event.KeyEvent;
35 import java.awt.event.ActionEvent;
36
37 /**
38 * @author rambaut
39 * Date: Dec 26, 2004
40 * Time: 11:02:45 AM
41 */
42 public class BeautiMacFileMenuFactory implements MenuFactory {
43
44 public BeautiMacFileMenuFactory() {
45 }
46
47 public String getMenuName() {
48 return "File";
49 }
50
51 public void populateMenu(JMenu menu, AbstractFrame frame) {
52
53 Application application = Application.getApplication();
54 JMenuItem item;
55
56 item = new JMenuItem(application.getNewAction());
57 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_N, MenuBarFactory.MENU_MASK));
58 menu.add(item);
59
60 item = new JMenuItem(application.getOpenAction());
61 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, MenuBarFactory.MENU_MASK));
62 menu.add(item);
63
64 if (application.getRecentFileMenu() != null) {
65 JMenu subMenu = application.getRecentFileMenu();
66 menu.add(subMenu);
67 }
68
69
70 if (frame != null && frame instanceof BeautiFrame) {
71 menu.addSeparator();
72
73 item = new JMenuItem(frame.getImportAction());
74 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, MenuBarFactory.MENU_MASK));
75 menu.add(item);
76
77 item = new JMenuItem(((BeautiFrame)frame).getImportTraitsAction());
78 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, MenuBarFactory.MENU_MASK + ActionEvent.ALT_MASK));
79 menu.add(item);
80
81 menu.addSeparator();
82
83 item = new JMenuItem(frame.getExportAction());
84 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, MenuBarFactory.MENU_MASK));
85 menu.add(item);
86 } else {
87 // If the frame is not a BeautiFrame then create a dummy set of disabled menu options.
88 // At present the only situation where this may happen is in Mac OS X when no windows
89 // are open and the menubar is created by the hidden frame.
90
91 menu.addSeparator();
92
93 item = new JMenuItem("Import Data...");
94 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, MenuBarFactory.MENU_MASK));
95 item.setEnabled(false);
96 menu.add(item);
97
98 item = new JMenuItem("Import Traits...");
99 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_I, MenuBarFactory.MENU_MASK + ActionEvent.ALT_MASK));
100 item.setEnabled(false);
101 menu.add(item);
102
103 // menu.addSeparator();
104 //
105 // item = new JMenuItem("Apply Template...");
106 // item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_O, MenuBarFactory.MENU_MASK));
107 // item.setEnabled(false);
108 // menu.add(item);
109 //
110 // item = new JMenuItem("Save Template As...");
111 // item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, MenuBarFactory.MENU_MASK));
112 // item.setEnabled(false);
113 // menu.add(item);
114
115 menu.addSeparator();
116
117 item = new JMenuItem("Generate BEAST File...");
118 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_E, MenuBarFactory.MENU_MASK));
119 item.setEnabled(false);
120 menu.add(item);
121 }
122
123 menu.addSeparator();
124
125 if (frame != null) {
126 item = new JMenuItem(frame.getCloseWindowAction());
127 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, MenuBarFactory.MENU_MASK));
128 menu.add(item);
129
130 item = new JMenuItem(frame.getSaveAction());
131 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, MenuBarFactory.MENU_MASK));
132 menu.add(item);
133
134 item = new JMenuItem(frame.getSaveAsAction());
135 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, MenuBarFactory.MENU_MASK + ActionEvent.SHIFT_MASK));
136 menu.add(item);
137
138 menu.addSeparator();
139
140 item = new JMenuItem(frame.getPrintAction());
141 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, MenuBarFactory.MENU_MASK));
142 menu.add(item);
143 } else {
144 item = new JMenuItem("Close");
145 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_W, MenuBarFactory.MENU_MASK));
146 item.setEnabled(false);
147 menu.add(item);
148
149 item = new JMenuItem("Save");
150 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, MenuBarFactory.MENU_MASK));
151 item.setEnabled(false);
152 menu.add(item);
153
154 item = new JMenuItem("Save As...");
155 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_S, MenuBarFactory.MENU_MASK + ActionEvent.SHIFT_MASK));
156 item.setEnabled(false);
157 menu.add(item);
158
159 menu.addSeparator();
160
161 item = new JMenuItem("Print...");
162 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, MenuBarFactory.MENU_MASK));
163 item.setEnabled(false);
164 menu.add(item);
165
166 }
167
168 item = new JMenuItem(application.getPageSetupAction());
169 item.setAccelerator(KeyStroke.getKeyStroke(KeyEvent.VK_P, MenuBarFactory.MENU_MASK + ActionEvent.SHIFT_MASK));
170 menu.add(item);
171
172 }
173
174 public int getPreferredAlignment() {
175 return LEFT;
176 }
177 }