Changeset 18684 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplay.java
r18605 r18684 365 365 currentVisibleRect.width = (int) (currentVisibleRect.width * ZOOM_STEP.get()); 366 366 currentVisibleRect.height = (int) (currentVisibleRect.height * ZOOM_STEP.get()); 367 } else {367 } else if (rotation < 0) { 368 368 currentVisibleRect.width = (int) (currentVisibleRect.width / ZOOM_STEP.get()); 369 369 currentVisibleRect.height = (int) (currentVisibleRect.height / ZOOM_STEP.get()); 370 } 370 } // else rotation == 0, which can happen with some modern trackpads (see #22770) 371 371 372 372 // Check that the zoom doesn't exceed MAX_ZOOM:1 -
trunk/test/unit/org/openstreetmap/josm/gui/layer/geoimage/ImageDisplayTest.java
r18037 r18684 2 2 package org.openstreetmap.josm.gui.layer.geoimage; 3 3 4 import static org.junit.jupiter.api.Assertions.assertAll; 5 import static org.junit.jupiter.api.Assertions.assertDoesNotThrow; 4 6 import static org.junit.jupiter.api.Assertions.assertEquals; 7 import static org.junit.jupiter.api.Assertions.assertNotEquals; 5 8 6 9 import java.awt.Dimension; 7 10 import java.awt.Graphics2D; 8 11 import java.awt.Rectangle; 12 import java.awt.event.MouseWheelEvent; 13 import java.awt.event.MouseWheelListener; 9 14 import java.awt.image.BufferedImage; 15 import java.io.IOException; 16 import java.lang.reflect.Field; 10 17 import java.nio.file.DirectoryStream; 11 18 import java.nio.file.Files; 12 19 import java.nio.file.Path; 13 20 import java.nio.file.Paths; 21 import java.util.function.IntFunction; 22 import java.util.function.Supplier; 23 24 import javax.swing.JPanel; 14 25 15 26 import org.junit.jupiter.api.Disabled; … … 18 29 import org.openstreetmap.josm.gui.layer.imagery.ImageryFilterSettings; 19 30 import org.openstreetmap.josm.testutils.annotations.BasicPreferences; 31 import org.openstreetmap.josm.tools.ReflectionUtils; 20 32 21 33 /** … … 61 73 } 62 74 } 75 76 /** 77 * Non-regression test for #22770 which occurs when a high resolution trackpad does not have a full mouse wheel event 78 */ 79 @Test 80 void testNonRegression22770() { 81 final ImageDisplay imageDisplay = new ImageDisplay(new ImageryFilterSettings()); 82 final Field visRectField = assertDoesNotThrow(() -> ImageDisplay.class.getDeclaredField("visibleRect")); 83 final Field wheelListenerField = assertDoesNotThrow(() -> ImageDisplay.class.getDeclaredField("imgMouseListener")); 84 ReflectionUtils.setObjectsAccessible(wheelListenerField, visRectField); 85 final Supplier<VisRect> visRectSupplier = () -> new VisRect((VisRect) assertDoesNotThrow(() -> visRectField.get(imageDisplay))); 86 final MouseWheelListener listener = (MouseWheelListener) assertDoesNotThrow(() -> wheelListenerField.get(imageDisplay)); 87 final IntFunction<MouseWheelEvent> mouseEventProvider = wheelRotation -> new MouseWheelEvent(new JPanel(), 0, 0, 0, 88 320, 240, 320, 240, 0, false, 89 MouseWheelEvent.WHEEL_UNIT_SCROLL, wheelRotation, wheelRotation, wheelRotation); 90 imageDisplay.setSize(640, 480); 91 imageDisplay.setImage0(new TestImageEntry(640, 480)).run(); 92 final VisRect initialVisibleRect = visRectSupplier.get(); 93 assertEquals(640, initialVisibleRect.width); 94 assertEquals(480, initialVisibleRect.height); 95 // First, check that zoom in works 96 listener.mouseWheelMoved(mouseEventProvider.apply(-1)); 97 assertNotEquals(initialVisibleRect, imageDisplay.getVisibleRect()); 98 final VisRect zoomedInVisRect = visRectSupplier.get(); 99 // If this fails, check to make certain that geoimage.zoom-step-factor defaults haven't changed 100 assertAll(() -> assertEquals(426, zoomedInVisRect.width), 101 () -> assertEquals(320, zoomedInVisRect.height)); 102 // Now check that a zoom event with no wheel rotation does not cause movement 103 listener.mouseWheelMoved(mouseEventProvider.apply(0)); 104 final VisRect noZoomVisRect = visRectSupplier.get(); 105 assertAll(() -> assertEquals(426, noZoomVisRect.width), 106 () -> assertEquals(320, noZoomVisRect.height)); 107 108 // Finally zoom out 109 listener.mouseWheelMoved(mouseEventProvider.apply(1)); 110 final VisRect zoomOutVisRect = visRectSupplier.get(); 111 assertAll(() -> assertEquals(640, zoomOutVisRect.width), 112 () -> assertEquals(480, zoomOutVisRect.height)); 113 } 114 115 private static class TestImageEntry extends ImageEntry { 116 private final int width; 117 private final int height; 118 TestImageEntry(int width, int height) { 119 this.width = width; 120 this.height = height; 121 } 122 123 @Override 124 public int getWidth() { 125 return this.width; 126 } 127 128 @Override 129 public int getHeight() { 130 return this.height; 131 } 132 133 @Override 134 public BufferedImage read(Dimension target) throws IOException { 135 return new BufferedImage(this.width, this.height, BufferedImage.TYPE_INT_RGB); 136 } 137 } 63 138 }
Note:
See TracChangeset
for help on using the changeset viewer.