Changeset 35324 in osm for applications/editors/josm/plugins/terracer/src
- Timestamp:
- 2020-02-15T18:05:24+01:00 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
applications/editors/josm/plugins/terracer/src/org/openstreetmap/josm/plugins/terracer/TerracerPlugin.java
r34584 r35324 2 2 package org.openstreetmap.josm.plugins.terracer; 3 3 4 import java.awt.Component; 5 import java.util.Arrays; 6 import java.util.List; 7 import java.util.Map; 8 import java.util.Map.Entry; 9 import java.util.stream.Collectors; 10 11 import javax.swing.Action; 12 import javax.swing.JMenu; 13 import javax.swing.JMenuItem; 14 15 import org.openstreetmap.josm.actions.JosmAction; 4 16 import org.openstreetmap.josm.gui.MainApplication; 5 17 import org.openstreetmap.josm.gui.MainMenu; 6 18 import org.openstreetmap.josm.plugins.Plugin; 7 19 import org.openstreetmap.josm.plugins.PluginInformation; 20 import org.openstreetmap.josm.tools.Destroyable; 8 21 9 22 /** … … 12 25 * @author zere - Copyright 2009 CloudMade Ltd 13 26 */ 14 public class TerracerPlugin extends Plugin { 27 public class TerracerPlugin extends Plugin implements Destroyable { 28 private List<JosmAction> actions = Arrays.asList(new TerracerAction(), new ReverseTerraceAction()); 29 15 30 public TerracerPlugin(PluginInformation info) { 16 31 super(info); 32 for (JosmAction action : actions) { 33 MainMenu.add(MainApplication.getMenu().moreToolsMenu, action); 34 } 35 } 17 36 18 MainMenu.add(MainApplication.getMenu().moreToolsMenu, new TerracerAction()); 19 MainMenu.add(MainApplication.getMenu().moreToolsMenu, new ReverseTerraceAction()); 20 } 37 @Override 38 public void destroy() { 39 final JMenu moreToolsMenu = MainApplication.getMenu().moreToolsMenu; 40 final Map<Action, Component> actionsMap = Arrays.asList(moreToolsMenu.getMenuComponents()).stream() 41 .filter(JMenuItem.class::isInstance).map(JMenuItem.class::cast) 42 .collect(Collectors.toMap(JMenuItem::getAction, component -> component)); 43 44 for (final Entry<Action, Component> action : actionsMap.entrySet()) { 45 if (actionsMap.containsKey(action.getKey())) { 46 moreToolsMenu.remove(action.getValue()); 47 } 48 } 49 actions.forEach(JosmAction::destroy); 50 } 21 51 }
Note:
See TracChangeset
for help on using the changeset viewer.