1 | // License: GPL. See LICENSE file for details.
|
---|
2 |
|
---|
3 | package org.openstreetmap.josm.gui;
|
---|
4 |
|
---|
5 | import static org.openstreetmap.josm.tools.I18n.tr;
|
---|
6 |
|
---|
7 | import java.awt.event.ActionEvent;
|
---|
8 | import java.awt.event.ActionListener;
|
---|
9 |
|
---|
10 | import javax.swing.JCheckBoxMenuItem;
|
---|
11 | import javax.swing.JMenu;
|
---|
12 | import javax.swing.JMenuBar;
|
---|
13 | import javax.swing.JMenuItem;
|
---|
14 | import javax.swing.KeyStroke;
|
---|
15 |
|
---|
16 | import org.openstreetmap.josm.Main;
|
---|
17 | import org.openstreetmap.josm.actions.AlignInRectangleAction;
|
---|
18 | import org.openstreetmap.josm.actions.JosmAction;
|
---|
19 | import org.openstreetmap.josm.actions.AboutAction;
|
---|
20 | import org.openstreetmap.josm.actions.AlignInCircleAction;
|
---|
21 | import org.openstreetmap.josm.actions.AlignInLineAction;
|
---|
22 | import org.openstreetmap.josm.actions.AutoScaleAction;
|
---|
23 | import org.openstreetmap.josm.actions.CombineWayAction;
|
---|
24 | import org.openstreetmap.josm.actions.CopyAction;
|
---|
25 | import org.openstreetmap.josm.actions.DownloadAction;
|
---|
26 | import org.openstreetmap.josm.actions.DuplicateAction;
|
---|
27 | import org.openstreetmap.josm.actions.ExitAction;
|
---|
28 | import org.openstreetmap.josm.actions.GpxExportAction;
|
---|
29 | import org.openstreetmap.josm.actions.HelpAction;
|
---|
30 | import org.openstreetmap.josm.actions.JoinNodeWayAction;
|
---|
31 | import org.openstreetmap.josm.actions.MergeNodesAction;
|
---|
32 | import org.openstreetmap.josm.actions.NewAction;
|
---|
33 | import org.openstreetmap.josm.actions.OpenAction;
|
---|
34 | import org.openstreetmap.josm.actions.PasteAction;
|
---|
35 | import org.openstreetmap.josm.actions.PasteTagsAction;
|
---|
36 | import org.openstreetmap.josm.actions.PreferencesAction;
|
---|
37 | import org.openstreetmap.josm.actions.RedoAction;
|
---|
38 | import org.openstreetmap.josm.actions.ReverseWayAction;
|
---|
39 | import org.openstreetmap.josm.actions.SaveAction;
|
---|
40 | import org.openstreetmap.josm.actions.SaveAsAction;
|
---|
41 | import org.openstreetmap.josm.actions.SelectAllAction;
|
---|
42 | import org.openstreetmap.josm.actions.SplitWayAction;
|
---|
43 | import org.openstreetmap.josm.actions.UndoAction;
|
---|
44 | import org.openstreetmap.josm.actions.UnselectAllAction;
|
---|
45 | import org.openstreetmap.josm.actions.UploadAction;
|
---|
46 | import org.openstreetmap.josm.actions.audio.AudioBackAction;
|
---|
47 | import org.openstreetmap.josm.actions.audio.AudioFwdAction;
|
---|
48 | import org.openstreetmap.josm.actions.audio.AudioNextAction;
|
---|
49 | import org.openstreetmap.josm.actions.audio.AudioPlayPauseAction;
|
---|
50 | import org.openstreetmap.josm.actions.audio.AudioPrevAction;
|
---|
51 | import org.openstreetmap.josm.actions.audio.AudioFasterAction;
|
---|
52 | import org.openstreetmap.josm.actions.audio.AudioSlowerAction;
|
---|
53 | import org.openstreetmap.josm.actions.search.SearchAction;
|
---|
54 | import org.openstreetmap.josm.data.DataSetChecker;
|
---|
55 |
|
---|
56 | /**
|
---|
57 | * This is the JOSM main menu bar. It is overwritten to initialize itself and provide
|
---|
58 | * all menu entries as member variables (sort of collect them).
|
---|
59 | *
|
---|
60 | * It also provides possibilities to attach new menu entries (used by plugins).
|
---|
61 | *
|
---|
62 | * @author Immanuel.Scholz
|
---|
63 | */
|
---|
64 | public class MainMenu extends JMenuBar {
|
---|
65 |
|
---|
66 | /* File menu */
|
---|
67 | public final NewAction newAction = new NewAction();
|
---|
68 | public final OpenAction open = new OpenAction();
|
---|
69 | public final JosmAction save = new SaveAction(null);
|
---|
70 | public final JosmAction saveAs = new SaveAsAction(null);
|
---|
71 | public final JosmAction gpxExport = new GpxExportAction(null);
|
---|
72 | public final DownloadAction download = new DownloadAction();
|
---|
73 | public final JosmAction upload = new UploadAction();
|
---|
74 | public final JosmAction exit = new ExitAction();
|
---|
75 |
|
---|
76 | /* Edit menu */
|
---|
77 | public final UndoAction undo = new UndoAction();
|
---|
78 | public final RedoAction redo = new RedoAction();
|
---|
79 | public final JosmAction copy = new CopyAction();
|
---|
80 | public final JosmAction paste = new PasteAction();
|
---|
81 | public final JosmAction pasteTags = new PasteTagsAction(copy);
|
---|
82 | public final JosmAction duplicate = new DuplicateAction();
|
---|
83 | public final JosmAction selectAll = new SelectAllAction();
|
---|
84 | public final JosmAction unselectAll = new UnselectAllAction();
|
---|
85 | /* crashes when loading data, if using JosmAction for search */
|
---|
86 | public final JosmAction search = new SearchAction();
|
---|
87 | public final JosmAction preferences = new PreferencesAction();
|
---|
88 |
|
---|
89 | /* View menu */
|
---|
90 |
|
---|
91 | /* Tools menu */
|
---|
92 | public final JosmAction splitWay = new SplitWayAction();
|
---|
93 | public final JosmAction combineWay = new CombineWayAction();
|
---|
94 | public final JosmAction reverseWay = new ReverseWayAction();
|
---|
95 | public final JosmAction alignInCircle = new AlignInCircleAction();
|
---|
96 | public final JosmAction alignInLine = new AlignInLineAction();
|
---|
97 | public final JosmAction alignInRect = new AlignInRectangleAction();
|
---|
98 | public final JosmAction mergeNodes = new MergeNodesAction();
|
---|
99 | public final JosmAction joinNodeWay = new JoinNodeWayAction();
|
---|
100 |
|
---|
101 | /* Audio menu */
|
---|
102 | public final JosmAction audioPlayPause = new AudioPlayPauseAction();
|
---|
103 | public final JosmAction audioNext = new AudioNextAction();
|
---|
104 | public final JosmAction audioPrev = new AudioPrevAction();
|
---|
105 | public final JosmAction audioFwd = new AudioFwdAction();
|
---|
106 | public final JosmAction audioBack = new AudioBackAction();
|
---|
107 | public final JosmAction audioFaster = new AudioFasterAction();
|
---|
108 | public final JosmAction audioSlower = new AudioSlowerAction();
|
---|
109 |
|
---|
110 | /* Help menu */
|
---|
111 | public final HelpAction help = new HelpAction();
|
---|
112 | public final JosmAction about = new AboutAction();
|
---|
113 |
|
---|
114 | public final JMenu fileMenu = new JMenu(tr("File"));
|
---|
115 | public final JMenu editMenu = new JMenu(tr("Edit"));
|
---|
116 | public final JMenu viewMenu = new JMenu(tr("View"));
|
---|
117 | public final JMenu toolsMenu = new JMenu(tr("Tools"));
|
---|
118 | public final JMenu audioMenu = new JMenu(tr("Audio"));
|
---|
119 | public final JMenu presetsMenu = new JMenu(tr("Presets"));
|
---|
120 | public final JMenu helpMenu = new JMenu(tr("Help"));
|
---|
121 |
|
---|
122 |
|
---|
123 | public MainMenu() {
|
---|
124 | JMenuItem current;
|
---|
125 |
|
---|
126 | fileMenu.setMnemonic('F');
|
---|
127 | current = fileMenu.add(newAction);
|
---|
128 | current.setAccelerator(newAction.shortCut);
|
---|
129 | current = fileMenu.add(open);
|
---|
130 | current.setAccelerator(open.shortCut);
|
---|
131 | fileMenu.addSeparator();
|
---|
132 | current = fileMenu.add(save);
|
---|
133 | current.setAccelerator(save.shortCut);
|
---|
134 | current = fileMenu.add(saveAs);
|
---|
135 | current.setAccelerator(saveAs.shortCut);
|
---|
136 | current = fileMenu.add(gpxExport);
|
---|
137 | current.setAccelerator(gpxExport.shortCut);
|
---|
138 | fileMenu.addSeparator();
|
---|
139 | current = fileMenu.add(download);
|
---|
140 | current.setAccelerator(download.shortCut);
|
---|
141 | current = fileMenu.add(upload);
|
---|
142 | current.setAccelerator(upload.shortCut);
|
---|
143 | fileMenu.addSeparator();
|
---|
144 | current = fileMenu.add(exit);
|
---|
145 | current.setAccelerator(exit.shortCut);
|
---|
146 | add(fileMenu);
|
---|
147 |
|
---|
148 | editMenu.setMnemonic('E');
|
---|
149 | current = editMenu.add(undo);
|
---|
150 | current.setAccelerator(undo.shortCut);
|
---|
151 | current = editMenu.add(redo);
|
---|
152 | current.setAccelerator(redo.shortCut);
|
---|
153 | editMenu.addSeparator();
|
---|
154 | current = editMenu.add(copy);
|
---|
155 | current.setAccelerator(copy.shortCut);
|
---|
156 | current = editMenu.add(paste);
|
---|
157 | current.setAccelerator(paste.shortCut);
|
---|
158 | current = editMenu.add(pasteTags);
|
---|
159 | current.setAccelerator(pasteTags.shortCut);
|
---|
160 | current = editMenu.add(duplicate);
|
---|
161 | current.setAccelerator(duplicate.shortCut);
|
---|
162 | editMenu.addSeparator();
|
---|
163 | current = editMenu.add(selectAll);
|
---|
164 | current.setAccelerator(selectAll.shortCut);
|
---|
165 | current = editMenu.add(unselectAll);
|
---|
166 | current.setAccelerator(unselectAll.shortCut);
|
---|
167 | editMenu.addSeparator();
|
---|
168 | current = editMenu.add(search);
|
---|
169 | current.setAccelerator(search.shortCut);
|
---|
170 | editMenu.addSeparator();
|
---|
171 | current = editMenu.add(preferences);
|
---|
172 | current.setAccelerator(preferences.shortCut);
|
---|
173 | add(editMenu);
|
---|
174 |
|
---|
175 | viewMenu.setMnemonic('V');
|
---|
176 | for (String mode : AutoScaleAction.modes) {
|
---|
177 | JosmAction autoScaleAction = new AutoScaleAction(mode);
|
---|
178 | current = viewMenu.add(autoScaleAction);
|
---|
179 | current.setAccelerator(autoScaleAction.shortCut);
|
---|
180 | }
|
---|
181 | viewMenu.addSeparator();
|
---|
182 |
|
---|
183 | // TODO move code to an "action" like the others?
|
---|
184 | final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(tr("Wireframe view"));
|
---|
185 | wireframe.setSelected(Main.pref.getBoolean("draw.wireframe", true));
|
---|
186 | wireframe.setAccelerator(KeyStroke.getKeyStroke("ctrl W"));
|
---|
187 | wireframe.addActionListener(new ActionListener() {
|
---|
188 | public void actionPerformed(ActionEvent ev) {
|
---|
189 | Main.pref.put("draw.wireframe", wireframe.isSelected());
|
---|
190 | if (Main.map != null) {
|
---|
191 | Main.map.mapView.repaint();
|
---|
192 | }
|
---|
193 | }
|
---|
194 | });
|
---|
195 | viewMenu.add(wireframe);
|
---|
196 |
|
---|
197 | add(viewMenu);
|
---|
198 |
|
---|
199 | toolsMenu.setMnemonic('T');
|
---|
200 | current = toolsMenu.add(splitWay);
|
---|
201 | current.setAccelerator(splitWay.shortCut);
|
---|
202 | current = toolsMenu.add(combineWay);
|
---|
203 | current.setAccelerator(combineWay.shortCut);
|
---|
204 | toolsMenu.addSeparator();
|
---|
205 | current = toolsMenu.add(reverseWay);
|
---|
206 | current.setAccelerator(reverseWay.shortCut);
|
---|
207 | toolsMenu.addSeparator();
|
---|
208 | current = toolsMenu.add(alignInCircle);
|
---|
209 | current.setAccelerator(alignInCircle.shortCut);
|
---|
210 | current = toolsMenu.add(alignInLine);
|
---|
211 | current.setAccelerator(alignInLine.shortCut);
|
---|
212 | current = toolsMenu.add(alignInRect);
|
---|
213 | current.setAccelerator(alignInRect.shortCut);
|
---|
214 | toolsMenu.addSeparator();
|
---|
215 | current = toolsMenu.add(mergeNodes);
|
---|
216 | current.setAccelerator(mergeNodes.shortCut);
|
---|
217 | current = toolsMenu.add(joinNodeWay);
|
---|
218 | current.setAccelerator(joinNodeWay.shortCut);
|
---|
219 | add(toolsMenu);
|
---|
220 |
|
---|
221 | if (! Main.pref.getBoolean("audio.menuinvisible")) {
|
---|
222 | audioMenu.setMnemonic('A');
|
---|
223 | current = audioMenu.add(audioPlayPause);
|
---|
224 | current.setAccelerator(audioPlayPause.shortCut);
|
---|
225 | current = audioMenu.add(audioNext);
|
---|
226 | current.setAccelerator(audioNext.shortCut);
|
---|
227 | current = audioMenu.add(audioPrev);
|
---|
228 | current.setAccelerator(audioPrev.shortCut);
|
---|
229 | current = audioMenu.add(audioFwd);
|
---|
230 | current.setAccelerator(audioFwd.shortCut);
|
---|
231 | current = audioMenu.add(audioBack);
|
---|
232 | current.setAccelerator(audioBack.shortCut);
|
---|
233 | current = audioMenu.add(audioSlower);
|
---|
234 | current.setAccelerator(audioSlower.shortCut);
|
---|
235 | current = audioMenu.add(audioFaster);
|
---|
236 | current.setAccelerator(audioFaster.shortCut);
|
---|
237 | add(audioMenu);
|
---|
238 | }
|
---|
239 |
|
---|
240 | add(presetsMenu);
|
---|
241 | presetsMenu.setMnemonic('P');
|
---|
242 |
|
---|
243 | helpMenu.setMnemonic('H');
|
---|
244 | JMenuItem check = new JMenuItem("DEBUG: Check Dataset");
|
---|
245 | check.addActionListener(new ActionListener(){
|
---|
246 | public void actionPerformed(ActionEvent e) {
|
---|
247 | DataSetChecker.check();
|
---|
248 | }
|
---|
249 | });
|
---|
250 | current = helpMenu.add(check);
|
---|
251 | current = helpMenu.add(help);
|
---|
252 | //current.setAccelerator(help.shortCut);
|
---|
253 | current = helpMenu.add(about);
|
---|
254 | current.setAccelerator(about.shortCut);
|
---|
255 | add(helpMenu);
|
---|
256 | }
|
---|
257 | }
|
---|