Move MapWithAI Menu to the "data" menu

Signed-off-by: Taylor Smock <tsmock@fb.com>
pull/1/head
Taylor Smock 2020-11-30 08:49:35 -07:00
rodzic 793af99bf8
commit a9b06f09de
3 zmienionych plików z 17 dodań i 9 usunięć

Wyświetl plik

@ -1,10 +1,8 @@
// License: GPL. For details, see LICENSE file.
package org.openstreetmap.josm.plugins.mapwithai;
import static org.openstreetmap.josm.gui.help.HelpUtil.ht;
import static org.openstreetmap.josm.tools.I18n.tr;
import java.awt.event.KeyEvent;
import java.lang.reflect.InvocationTargetException;
import java.util.ArrayList;
import java.util.Arrays;
@ -13,6 +11,7 @@ import java.util.List;
import java.util.Map;
import java.util.Optional;
import javax.swing.JMenu;
import javax.swing.JMenuItem;
import org.openstreetmap.josm.actions.JosmAction;
@ -82,9 +81,10 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable {
preferenceSetting = new MapWithAIPreferences();
// Add MapWithAI specific menu
JMenu dataMenu = MainApplication.getMenu().dataMenu;
mapwithaiMenu = new MapWithAIMenu();
MainApplication.getMenu().addMenu(mapwithaiMenu, "mapwithai:menu", KeyEvent.VK_M, 9, ht("/Plugin/MapWithAI"));
dataMenu.add(mapwithaiMenu);
for (final Map.Entry<Class<? extends JosmAction>, Boolean> entry : MENU_ENTRIES.entrySet()) {
if (Arrays.asList(mapwithaiMenu.getMenuComponents()).parallelStream().filter(JMenuItem.class::isInstance)
.map(JMenuItem.class::cast)
@ -172,7 +172,7 @@ public final class MapWithAIPlugin extends Plugin implements Destroyable {
*/
@Override
public void destroy() {
MainApplication.getMenu().remove(this.mapwithaiMenu);
MainApplication.getMenu().dataMenu.remove(this.mapwithaiMenu);
MainApplication.getLayerManager().getLayersOfType(MapWithAILayer.class).stream()
.forEach(layer -> MainApplication.getLayerManager().removeLayer(layer));

Wyświetl plik

@ -40,7 +40,9 @@ import org.openstreetmap.josm.plugins.mapwithai.backend.MapWithAILayer;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAICategory;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAIInfo;
import org.openstreetmap.josm.plugins.mapwithai.data.mapwithai.MapWithAILayerInfo;
import org.openstreetmap.josm.tools.ImageProvider;
import org.openstreetmap.josm.tools.ImageProvider.ImageSizes;
import org.openstreetmap.josm.tools.ImageResource;
import org.openstreetmap.josm.tools.Logging;
/**
@ -65,6 +67,12 @@ public class MapWithAIMenu extends JMenu {
public MapWithAIMenu() {
/* I18N: mnemonic: I */
super(trc("menu", "MapWithAI"));
ImageProvider mapwithai = new ImageProvider("MapWithAI").setOptional(true)
.setMaxSize(ImageProvider.ImageSizes.MENU);
ImageResource resource = mapwithai.getResource();
if (resource != null) {
super.setIcon(resource.getImageIconBounded(ImageProvider.ImageSizes.MENU.getImageDimension()));
}
setupMenuScroller();
// build dynamically
addMenuListener(new MenuListener() {

Wyświetl plik

@ -88,12 +88,11 @@ class MapWithAIPluginTest {
Field menuEntries = MapWithAIPlugin.class.getDeclaredField("MENU_ENTRIES");
menuEntries.setAccessible(true);
// + 1 comes from the preferences panel
final JMenu dataMenu = MainApplication.getMenu().dataMenu;
final int dataMenuSize = dataMenu.getMenuComponentCount();
final int addedMenuItems = ((Map<?, ?>) menuEntries.get(plugin)).size() + 1;
plugin = new MapWithAIPlugin(info);
// Currently adding the menu at the 9th index
final JMenu dataMenu = MainApplication.getMenu().getMenu(9);
final int dataMenuSize = dataMenu.getMenuComponentCount();
assertEquals(addedMenuItems, dataMenu.getMenuComponentCount(), "Menu items were not added");
assertEquals(dataMenuSize + 1, dataMenu.getMenuComponentCount(), "Menu items were not added");
assertEquals(1,
MapPaintStyles.getStyles().getStyleSources().parallelStream()
.filter(source -> source.url != null && source.name.contains("MapWithAI")).count(),
@ -116,7 +115,8 @@ class MapWithAIPluginTest {
for (int i = 0; i < 3; i++) {
plugin = new MapWithAIPlugin(info);
assertEquals(addedMenuItems, dataMenu.getMenuComponentCount(), "The menu items were added multiple times");
assertEquals(dataMenuSize + 1, dataMenu.getMenuComponentCount(),
"The menu items were added multiple times");
assertEquals(1,
MapPaintStyles.getStyles().getStyleSources().parallelStream()
.filter(source -> source.url != null && source.name.contains("MapWithAI")).count(),