Changeset 1130 in josm
- Timestamp:
- 2008-12-14T00:52:48+01:00 (16 years ago)
- Location:
- trunk
- Files:
-
- 2 added
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/MainMenu.java
r1084 r1130 17 17 import org.openstreetmap.josm.Main; 18 18 import org.openstreetmap.josm.actions.AboutAction; 19 import org.openstreetmap.josm.actions.AddNodeAction; 19 20 import org.openstreetmap.josm.actions.AlignInCircleAction; 20 21 import org.openstreetmap.josm.actions.AlignInLineAction; … … 64 65 65 66 /** 66 * This is the JOSM main menu bar. It is overwritten to initialize itself and provide 67 * all menuentries as member variables (sort of collect them).68 * 67 * This is the JOSM main menu bar. It is overwritten to initialize itself and provide all menu 68 * entries as member variables (sort of collect them). 69 * 69 70 * It also provides possibilities to attach new menu entries (used by plugins). 70 * 71 * 71 72 * @author Immanuel.Scholz 72 73 */ 73 74 public class MainMenu extends JMenuBar { 74 75 75 /* File menu */ 76 public final NewAction newAction = new NewAction(); 77 public final OpenAction open = new OpenAction(); 78 public final JosmAction save = new SaveAction(null); 79 public final JosmAction saveAs = new SaveAsAction(null); 80 public final JosmAction gpxExport = new GpxExportAction(null); 81 public final DownloadAction download = new DownloadAction(); 82 public final JosmAction upload = new UploadAction(); 83 public final JosmAction exit = new ExitAction(); 84 85 /* Edit menu */ 86 public final UndoAction undo = new UndoAction(); 87 public final RedoAction redo = new RedoAction(); 88 public final JosmAction copy = new CopyAction(); 89 public final JosmAction paste = new PasteAction(); 90 public final JosmAction delete = new DeleteAction(); 91 public final JosmAction pasteTags = new PasteTagsAction(copy); 92 public final JosmAction duplicate = new DuplicateAction(); 93 public final JosmAction selectAll = new SelectAllAction(); 94 public final JosmAction unselectAll = new UnselectAllAction(); 76 /* File menu */ 77 public final NewAction newAction = new NewAction(); 78 public final OpenAction open = new OpenAction(); 79 public final JosmAction save = new SaveAction(null); 80 public final JosmAction saveAs = new SaveAsAction(null); 81 public final JosmAction gpxExport = new GpxExportAction(null); 82 public final DownloadAction download = new DownloadAction(); 83 public final JosmAction upload = new UploadAction(); 84 public final JosmAction exit = new ExitAction(); 85 86 /* Edit menu */ 87 public final UndoAction undo = new UndoAction(); 88 public final RedoAction redo = new RedoAction(); 89 public final AddNodeAction addnode = new AddNodeAction(); 90 public final JosmAction copy = new CopyAction(); 91 public final JosmAction paste = new PasteAction(); 92 public final JosmAction delete = new DeleteAction(); 93 public final JosmAction pasteTags = new PasteTagsAction(copy); 94 public final JosmAction duplicate = new DuplicateAction(); 95 public final JosmAction selectAll = new SelectAllAction(); 96 public final JosmAction unselectAll = new UnselectAllAction(); 95 97 /* crashes when loading data, if using JosmAction for search */ 96 97 98 99 100 101 102 103 104 105 106 107 98 public final JosmAction search = new SearchAction(); 99 public final JosmAction preferences = new PreferencesAction(); 100 101 /* View menu */ 102 public final JosmAction toggleGPXLines = new ToggleGPXLinesAction(); 103 104 /* Tools menu */ 105 public final JosmAction splitWay = new SplitWayAction(); 106 public final JosmAction combineWay = new CombineWayAction(); 107 public final JosmAction reverseWay = new ReverseWayAction(); 108 public final JosmAction alignInCircle = new AlignInCircleAction(); 109 public final JosmAction alignInLine = new AlignInLineAction(); 108 110 public final JosmAction ortho = new OrthogonalizeAction(); 109 public final JosmAction createCircle = new CreateCircleAction(); 110 public final JosmAction mergeNodes = new MergeNodesAction(); 111 public final JosmAction joinNodeWay = new JoinNodeWayAction(); 112 public final JosmAction unglueNodes = new UnGlueAction(); 113 114 /* Audio menu */ 115 public final JosmAction audioPlayPause = new AudioPlayPauseAction(); 116 public final JosmAction audioNext = new AudioNextAction(); 117 public final JosmAction audioPrev = new AudioPrevAction(); 118 public final JosmAction audioFwd = new AudioFwdAction(); 119 public final JosmAction audioBack = new AudioBackAction(); 120 public final JosmAction audioFaster = new AudioFasterAction(); 121 public final JosmAction audioSlower = new AudioSlowerAction(); 122 123 /* Help menu */ 124 public final HelpAction help = new HelpAction(); 125 public final JosmAction about = new AboutAction(); 126 public final HistoryInfoAction historyinfo = new HistoryInfoAction(); 127 128 public final JMenu fileMenu = new JMenu(tr("File")); 129 public final JMenu editMenu = new JMenu(tr("Edit")); 130 public final JMenu viewMenu = new JMenu(tr("View")); 131 public final JMenu toolsMenu = new JMenu(tr("Tools")); 132 public final JMenu audioMenu = new JMenu(tr("Audio")); 133 public final JMenu presetsMenu = new JMenu(tr("Presets")); 134 public final JMenu helpMenu = new JMenu(tr("Help")); 135 136 /** 137 * Add a JosmAction to a menu. 138 * 139 * This method handles all the shortcut handling. 140 * It also makes sure that actions that are handled by the 141 * OS are not duplicated on the menu. 142 */ 143 public static void add(JMenu menu, JosmAction action) { 144 if (!action.getShortcut().getAutomatic()) { 145 JMenuItem menuitem = menu.add(action); 146 KeyStroke ks = action.getShortcut().getKeyStroke(); 147 if (ks != null) { 148 menuitem.setAccelerator(ks); 149 } 150 } 151 } 152 153 /** 154 * Add a menu to the main menu. 155 * 156 * This method handles all the shortcut handling. 157 */ 158 public void add(JMenu menu, int mnemonicKey, String shortName) { 159 Shortcut.registerShortcut("menu:"+shortName, tr("Menu: {0}", menu.getText()), mnemonicKey, Shortcut.GROUP_MNEMONIC).setMnemonic(menu); 160 add(menu); 161 } 162 163 public MainMenu() { 164 JMenuItem current; 165 166 add(fileMenu, newAction); 167 add(fileMenu, open); 168 fileMenu.addSeparator(); 169 add(fileMenu, save); 170 add(fileMenu, saveAs); 171 add(fileMenu, gpxExport); 172 fileMenu.addSeparator(); 173 add(fileMenu, download); 174 add(fileMenu, upload); 175 add(fileMenu, exit); 176 add(fileMenu, KeyEvent.VK_F, "file"); 177 178 add(editMenu, undo); 179 add(editMenu, redo); 180 editMenu.addSeparator(); 181 add(editMenu, copy); 182 add(editMenu, delete); 183 add(editMenu, paste); 184 add(editMenu, pasteTags); 185 add(editMenu, duplicate); 186 editMenu.addSeparator(); 187 add(editMenu, selectAll); 188 add(editMenu, unselectAll); 189 editMenu.addSeparator(); 190 add(editMenu, search); 191 editMenu.addSeparator(); 192 add(editMenu, preferences); 193 add(editMenu, KeyEvent.VK_E, "edit"); 194 195 for (String mode : AutoScaleAction.modes) { 196 JosmAction autoScaleAction = new AutoScaleAction(mode); 197 add(viewMenu, autoScaleAction); 198 } 199 viewMenu.addSeparator(); 200 add(viewMenu, new ZoomOutAction()); 201 add(viewMenu, new ZoomInAction()); 202 viewMenu.addSeparator(); 203 // TODO move code to an "action" like the others? 204 final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(tr("Wireframe view")); 205 wireframe.setSelected(Main.pref.getBoolean("draw.wireframe", false)); 206 wireframe.setAccelerator(Shortcut.registerShortcut("menu:view:wireframe", "Toggle Wireframe view", KeyEvent.VK_W, Shortcut.GROUP_MENU).getKeyStroke()); 207 wireframe.addActionListener(new ActionListener() { 208 public void actionPerformed(ActionEvent ev) { 209 Main.pref.put("draw.wireframe", wireframe.isSelected()); 210 if (Main.map != null) { 211 Main.map.mapView.repaint(); 212 } 213 } 214 }); 215 viewMenu.add(wireframe); 216 add(viewMenu, KeyEvent.VK_V, "view"); 217 218 add(toolsMenu, splitWay); 219 add(toolsMenu, combineWay); 220 toolsMenu.addSeparator(); 221 add(toolsMenu, reverseWay); 222 toolsMenu.addSeparator(); 223 add(toolsMenu, alignInCircle); 224 add(toolsMenu, alignInLine); 225 add(toolsMenu, ortho); 226 toolsMenu.addSeparator(); 227 add(toolsMenu, createCircle); 228 toolsMenu.addSeparator(); 229 add(toolsMenu, mergeNodes); 230 add(toolsMenu, joinNodeWay); 231 add(toolsMenu, unglueNodes); 232 add(toolsMenu, KeyEvent.VK_T, "tools"); 233 234 if (! Main.pref.getBoolean("audio.menuinvisible")) { 235 add(audioMenu, audioPlayPause); 236 add(audioMenu, audioNext); 237 add(audioMenu, audioPrev); 238 add(audioMenu, audioFwd); 239 add(audioMenu, audioBack); 240 add(audioMenu, audioSlower); 241 add(audioMenu, audioFaster); 242 add(audioMenu, KeyEvent.VK_A, "audio"); 243 } 244 245 add(presetsMenu, KeyEvent.VK_P, "presets"); 246 247 JMenuItem check = new JMenuItem("DEBUG: Check Dataset"); 248 check.addActionListener(new ActionListener(){ 249 public void actionPerformed(ActionEvent e) { 250 DataSetChecker.check(); 251 } 252 }); 253 helpMenu.add(check); 254 current = helpMenu.add(help); // why is help not a JosmAction? 255 current.setAccelerator(Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1, Shortcut.GROUP_DIRECT).getKeyStroke()); 256 add(helpMenu, about); 257 add(helpMenu, historyinfo); 258 add(helpMenu, KeyEvent.VK_H, "help"); 111 public final JosmAction createCircle = new CreateCircleAction(); 112 public final JosmAction mergeNodes = new MergeNodesAction(); 113 public final JosmAction joinNodeWay = new JoinNodeWayAction(); 114 public final JosmAction unglueNodes = new UnGlueAction(); 115 116 /* Audio menu */ 117 public final JosmAction audioPlayPause = new AudioPlayPauseAction(); 118 public final JosmAction audioNext = new AudioNextAction(); 119 public final JosmAction audioPrev = new AudioPrevAction(); 120 public final JosmAction audioFwd = new AudioFwdAction(); 121 public final JosmAction audioBack = new AudioBackAction(); 122 public final JosmAction audioFaster = new AudioFasterAction(); 123 public final JosmAction audioSlower = new AudioSlowerAction(); 124 125 /* Help menu */ 126 public final HelpAction help = new HelpAction(); 127 public final JosmAction about = new AboutAction(); 128 public final HistoryInfoAction historyinfo = new HistoryInfoAction(); 129 130 public final JMenu fileMenu = new JMenu(tr("File")); 131 public final JMenu editMenu = new JMenu(tr("Edit")); 132 public final JMenu viewMenu = new JMenu(tr("View")); 133 public final JMenu toolsMenu = new JMenu(tr("Tools")); 134 public final JMenu audioMenu = new JMenu(tr("Audio")); 135 public final JMenu presetsMenu = new JMenu(tr("Presets")); 136 public final JMenu helpMenu = new JMenu(tr("Help")); 137 138 /** 139 * Add a JosmAction to a menu. 140 * 141 * This method handles all the shortcut handling. It also makes sure that actions that are 142 * handled by the OS are not duplicated on the menu. 143 */ 144 public static void add(JMenu menu, JosmAction action) { 145 if (!action.getShortcut().getAutomatic()) { 146 JMenuItem menuitem = menu.add(action); 147 KeyStroke ks = action.getShortcut().getKeyStroke(); 148 if (ks != null) { 149 menuitem.setAccelerator(ks); 150 } 151 } 152 } 153 154 /** 155 * Add a menu to the main menu. 156 * 157 * This method handles all the shortcut handling. 158 */ 159 public void add(JMenu menu, int mnemonicKey, String shortName) { 160 Shortcut.registerShortcut("menu:" + shortName, tr("Menu: {0}", menu.getText()), mnemonicKey, 161 Shortcut.GROUP_MNEMONIC).setMnemonic(menu); 162 add(menu); 163 } 164 165 public MainMenu() { 166 JMenuItem current; 167 168 add(fileMenu, newAction); 169 add(fileMenu, open); 170 fileMenu.addSeparator(); 171 add(fileMenu, save); 172 add(fileMenu, saveAs); 173 add(fileMenu, gpxExport); 174 fileMenu.addSeparator(); 175 add(fileMenu, download); 176 add(fileMenu, upload); 177 add(fileMenu, exit); 178 add(fileMenu, KeyEvent.VK_F, "file"); 179 180 add(editMenu, undo); 181 add(editMenu, redo); 182 editMenu.addSeparator(); 183 add(editMenu, addnode); 184 add(editMenu, copy); 185 add(editMenu, delete); 186 add(editMenu, paste); 187 add(editMenu, pasteTags); 188 add(editMenu, duplicate); 189 editMenu.addSeparator(); 190 add(editMenu, selectAll); 191 add(editMenu, unselectAll); 192 editMenu.addSeparator(); 193 add(editMenu, search); 194 editMenu.addSeparator(); 195 add(editMenu, preferences); 196 add(editMenu, KeyEvent.VK_E, "edit"); 197 198 for (String mode : AutoScaleAction.modes) { 199 JosmAction autoScaleAction = new AutoScaleAction(mode); 200 add(viewMenu, autoScaleAction); 201 } 202 viewMenu.addSeparator(); 203 add(viewMenu, new ZoomOutAction()); 204 add(viewMenu, new ZoomInAction()); 205 viewMenu.addSeparator(); 206 // TODO move code to an "action" like the others? 207 final JCheckBoxMenuItem wireframe = new JCheckBoxMenuItem(tr("Wireframe view")); 208 wireframe.setSelected(Main.pref.getBoolean("draw.wireframe", false)); 209 wireframe.setAccelerator(Shortcut.registerShortcut("menu:view:wireframe", "Toggle Wireframe view", 210 KeyEvent.VK_W, Shortcut.GROUP_MENU).getKeyStroke()); 211 wireframe.addActionListener(new ActionListener() { 212 public void actionPerformed(ActionEvent ev) { 213 Main.pref.put("draw.wireframe", wireframe.isSelected()); 214 if (Main.map != null) { 215 Main.map.mapView.repaint(); 216 } 217 } 218 }); 219 viewMenu.add(wireframe); 220 add(viewMenu, KeyEvent.VK_V, "view"); 221 222 add(toolsMenu, splitWay); 223 add(toolsMenu, combineWay); 224 toolsMenu.addSeparator(); 225 add(toolsMenu, reverseWay); 226 toolsMenu.addSeparator(); 227 add(toolsMenu, alignInCircle); 228 add(toolsMenu, alignInLine); 229 add(toolsMenu, ortho); 230 toolsMenu.addSeparator(); 231 add(toolsMenu, createCircle); 232 toolsMenu.addSeparator(); 233 add(toolsMenu, mergeNodes); 234 add(toolsMenu, joinNodeWay); 235 add(toolsMenu, unglueNodes); 236 add(toolsMenu, KeyEvent.VK_T, "tools"); 237 238 if (!Main.pref.getBoolean("audio.menuinvisible")) { 239 add(audioMenu, audioPlayPause); 240 add(audioMenu, audioNext); 241 add(audioMenu, audioPrev); 242 add(audioMenu, audioFwd); 243 add(audioMenu, audioBack); 244 add(audioMenu, audioSlower); 245 add(audioMenu, audioFaster); 246 add(audioMenu, KeyEvent.VK_A, "audio"); 247 } 248 249 add(presetsMenu, KeyEvent.VK_P, "presets"); 250 251 JMenuItem check = new JMenuItem("DEBUG: Check Dataset"); 252 check.addActionListener(new ActionListener() { 253 public void actionPerformed(ActionEvent e) { 254 DataSetChecker.check(); 255 } 256 }); 257 helpMenu.add(check); 258 current = helpMenu.add(help); // why is help not a JosmAction? 259 current.setAccelerator(Shortcut.registerShortcut("system:help", tr("Help"), KeyEvent.VK_F1, 260 Shortcut.GROUP_DIRECT).getKeyStroke()); 261 add(helpMenu, about); 262 add(helpMenu, historyinfo); 263 add(helpMenu, KeyEvent.VK_H, "help"); 259 264 } 260 265 }
Note:
See TracChangeset
for help on using the changeset viewer.