diff --git a/src/org/openstreetmap/josm/gui/NavigatableComponent.java b/src/org/openstreetmap/josm/gui/NavigatableComponent.java
index da420a4..0da28eb 100644
|
a
|
b
|
public class NavigatableComponent extends JComponent implements Helpful {
|
| 314 | 314 | } |
| 315 | 315 | |
| 316 | 316 | protected void updateLocationState() { |
| 317 | | if (SwingUtilities.getWindowAncestor(this) != null && isShowing()) { |
| | 317 | if (isVisibleOnScreen()) { |
| 318 | 318 | state = state.usingLocation(this); |
| 319 | 319 | } |
| 320 | 320 | } |
| 321 | 321 | |
| | 322 | protected boolean isVisibleOnScreen() { |
| | 323 | return SwingUtilities.getWindowAncestor(this) != null && isShowing(); |
| | 324 | } |
| | 325 | |
| 322 | 326 | /** |
| 323 | 327 | * Gets the current view state. This includes the scale, the current view area and the position. |
| 324 | 328 | * @return The current state. |
diff --git a/test/unit/org/openstreetmap/josm/gui/NavigatableComponentTest.java b/test/unit/org/openstreetmap/josm/gui/NavigatableComponentTest.java
index 2d8bad6..865e2f4 100644
|
a
|
b
|
import java.awt.Point;
|
| 8 | 8 | import java.awt.Rectangle; |
| 9 | 9 | import java.awt.geom.Point2D; |
| 10 | 10 | |
| 11 | | import javax.swing.JFrame; |
| | 11 | import javax.swing.JPanel; |
| 12 | 12 | |
| 13 | 13 | import org.CustomMatchers; |
| 14 | 14 | import org.junit.Before; |
| … |
… |
import org.openstreetmap.josm.gui.util.GuiHelper;
|
| 29 | 29 | */ |
| 30 | 30 | public class NavigatableComponentTest { |
| 31 | 31 | |
| | 32 | private final class NavigatableComponentMock extends NavigatableComponent { |
| | 33 | @Override |
| | 34 | public Point getLocationOnScreen() { |
| | 35 | return new Point(30, 40); |
| | 36 | } |
| | 37 | |
| | 38 | @Override |
| | 39 | protected boolean isVisibleOnScreen() { |
| | 40 | return true; |
| | 41 | } |
| | 42 | } |
| | 43 | |
| 32 | 44 | private static final int HEIGHT = 200; |
| 33 | 45 | private static final int WIDTH = 300; |
| 34 | 46 | private NavigatableComponent component; |
| … |
… |
public class NavigatableComponentTest {
|
| 46 | 58 | */ |
| 47 | 59 | @Before |
| 48 | 60 | public void setUp() { |
| 49 | | component = new NavigatableComponent() { |
| 50 | | @Override |
| 51 | | public Point getLocationOnScreen() { |
| 52 | | return new Point(30, 40); |
| 53 | | } |
| 54 | | }; |
| | 61 | component = new NavigatableComponentMock(); |
| 55 | 62 | component.setBounds(new Rectangle(WIDTH, HEIGHT)); |
| 56 | 63 | // wait for the event to be propagated. |
| 57 | 64 | GuiHelper.runInEDTAndWait(new Runnable() { |
| … |
… |
public class NavigatableComponentTest {
|
| 60 | 67 | } |
| 61 | 68 | }); |
| 62 | 69 | component.setVisible(true); |
| 63 | | JFrame window = new JFrame(); |
| 64 | | window.add(component); |
| | 70 | JPanel parent = new JPanel(); |
| | 71 | parent.add(component); |
| 65 | 72 | component.updateLocationState(); |
| 66 | 73 | } |
| 67 | 74 | |