Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialog.java
r18576 r18586 895 895 if (newLayer != null) { 896 896 newLayer.addPropertyChangeListener(this); 897 if (newLayer.isVisible() ) {897 if (newLayer.isVisible() && Boolean.TRUE.equals(PROP_PREVIEW_ON_HOVER.get())) { 898 898 MainApplication.getMap().mapView.addPrimitiveHoverListener(this); 899 899 } else { … … 909 909 910 910 // Disable hover preview when primitives are invisible 911 if (isVisible ) {911 if (isVisible && Boolean.TRUE.equals(PROP_PREVIEW_ON_HOVER.get())) { 912 912 MainApplication.getMap().mapView.addPrimitiveHoverListener(this); 913 913 } else { -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/properties/PropertiesDialogTest.java
r18037 r18586 3 3 4 4 import static org.junit.jupiter.api.Assertions.assertEquals; 5 import static org.junit.jupiter.api.Assertions.assertFalse; 6 import static org.junit.jupiter.api.Assertions.assertTrue; 5 7 8 import java.lang.reflect.Field; 6 9 import java.util.ArrayList; 7 10 import java.util.List; 11 import java.util.concurrent.CopyOnWriteArrayList; 12 import java.util.stream.Stream; 8 13 14 import org.junit.jupiter.api.Test; 15 import org.junit.jupiter.api.extension.RegisterExtension; 16 import org.junit.jupiter.params.ParameterizedTest; 17 import org.junit.jupiter.params.provider.Arguments; 18 import org.junit.jupiter.params.provider.MethodSource; 9 19 import org.openstreetmap.josm.data.coor.LatLon; 20 import org.openstreetmap.josm.data.osm.DataSet; 10 21 import org.openstreetmap.josm.data.osm.Node; 11 22 import org.openstreetmap.josm.data.osm.OsmPrimitive; 12 23 import org.openstreetmap.josm.data.osm.Way; 24 import org.openstreetmap.josm.gui.MainApplication; 25 import org.openstreetmap.josm.gui.NavigatableComponent; 26 import org.openstreetmap.josm.gui.PrimitiveHoverListener; 27 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 28 import org.openstreetmap.josm.testutils.JOSMTestRules; 13 29 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 14 15 import org.junit.jupiter.api.Test; 30 import org.openstreetmap.josm.tools.ReflectionUtils; 16 31 17 32 /** … … 20 35 @BasicPreferences 21 36 class PropertiesDialogTest { 37 @RegisterExtension 38 static JOSMTestRules rules = new JOSMTestRules().main().projection(); 39 22 40 private static String createSearchSetting(List<OsmPrimitive> sel, boolean sameType) { 23 41 return PropertiesDialog.createSearchSetting("foo", sel, sameType).text; … … 54 72 assertEquals("(type:way \"foo\"=\"bar\") OR (type:node \"foo\"=\"bar\")", createSearchSetting(sel, true)); 55 73 } 74 75 static Stream<Arguments> testTicket22487() { 76 return Stream.of( 77 Arguments.of("Layer add", (Runnable) () -> 78 MainApplication.getLayerManager().addLayer(new OsmDataLayer(new DataSet(), "testTicket22487-layerAdd", null))), 79 Arguments.of("Layer hide", (Runnable) () -> { 80 // We need to toggle the layer visibility to hit the bug. 81 MainApplication.getLayerManager().getLayers().forEach(layer -> layer.setVisible(false)); 82 MainApplication.getLayerManager().getLayers().forEach(layer -> layer.setVisible(true)); 83 }) 84 ); 85 } 86 87 @ParameterizedTest 88 @MethodSource 89 void testTicket22487(String ignored_title, Runnable action) throws ReflectiveOperationException { 90 Field primitiveHoverListenersField = NavigatableComponent.class.getDeclaredField("primitiveHoverListeners"); 91 ReflectionUtils.setObjectsAccessible(primitiveHoverListenersField); 92 93 DataSet ds = new DataSet(); 94 OsmDataLayer layer = new OsmDataLayer(ds, "testTicket22487", null); 95 // Ensure that the navigatable component is set up 96 MainApplication.getLayerManager().addLayer(layer); 97 PropertiesDialog propertiesDialog = MainApplication.getMap().propertiesDialog; 98 @SuppressWarnings("unchecked") 99 CopyOnWriteArrayList<PrimitiveHoverListener> listeners = 100 (CopyOnWriteArrayList<PrimitiveHoverListener>) primitiveHoverListenersField.get(MainApplication.getMap().mapView); 101 assertTrue(listeners.contains(propertiesDialog)); 102 103 // Set the properties to false 104 PropertiesDialog.PROP_PREVIEW_ON_HOVER.put(false); 105 assertFalse(listeners.contains(propertiesDialog)); 106 107 action.run(); 108 assertFalse(listeners.contains(propertiesDialog)); 109 } 56 110 }
Note:
See TracChangeset
for help on using the changeset viewer.