From 4bd4b4372c75fcf1fa20e2537d425c40ce729d46 Mon Sep 17 00:00:00 2001
From: Robert Scott <code@humanleg.org.uk>
Date: Sat, 25 Nov 2017 23:28:57 +0000
Subject: [PATCH v3 1/3] NavigatableComponent: tweak behaviour to allow
updateLocationState to run in headless mode
if we detect we're in headless mode we presume we're executing unit tests
and present sensible (yet imaginary) results in cases where awt will
fail to behave properly in headless mode.
---
src/org/openstreetmap/josm/gui/MapViewState.java | 15 +++++++++++----
src/org/openstreetmap/josm/gui/NavigatableComponent.java | 5 ++++-
2 files changed, 15 insertions(+), 5 deletions(-)
diff --git a/src/org/openstreetmap/josm/gui/MapViewState.java b/src/org/openstreetmap/josm/gui/MapViewState.java
index 6fbe14d5d..820fd4f0a 100644
|
a
|
b
|
|
| 2 | 2 | package org.openstreetmap.josm.gui; |
| 3 | 3 | |
| 4 | 4 | import java.awt.Container; |
| | 5 | import java.awt.GraphicsEnvironment; |
| 5 | 6 | import java.awt.Point; |
| 6 | 7 | import java.awt.geom.AffineTransform; |
| 7 | 8 | import java.awt.geom.Area; |
| … |
… |
public final class MapViewState implements Serializable {
|
| 144 | 145 | } |
| 145 | 146 | |
| 146 | 147 | private static Point findTopLeftOnScreen(JComponent position) { |
| 147 | | try { |
| 148 | | return position.getLocationOnScreen(); |
| 149 | | } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) { |
| 150 | | throw BugReport.intercept(e).put("position", position).put("parent", position::getParent); |
| | 148 | if (GraphicsEnvironment.isHeadless()) { |
| | 149 | // in our imaginary universe the window is always (10, 10) from the top left of the screen |
| | 150 | Point topLeftInWindow = findTopLeftInWindow(position); |
| | 151 | return new Point(topLeftInWindow.x + 10, topLeftInWindow.y + 10); |
| | 152 | } else { |
| | 153 | try { |
| | 154 | return position.getLocationOnScreen(); |
| | 155 | } catch (JosmRuntimeException | IllegalArgumentException | IllegalStateException e) { |
| | 156 | throw BugReport.intercept(e).put("position", position).put("parent", position::getParent); |
| | 157 | } |
| 151 | 158 | } |
| 152 | 159 | } |
| 153 | 160 | |
diff --git a/src/org/openstreetmap/josm/gui/NavigatableComponent.java b/src/org/openstreetmap/josm/gui/NavigatableComponent.java
index e8da39e87..ca02f0c2b 100644
|
a
|
b
|
|
| 2 | 2 | package org.openstreetmap.josm.gui; |
| 3 | 3 | |
| 4 | 4 | import java.awt.Cursor; |
| | 5 | import java.awt.GraphicsEnvironment; |
| 5 | 6 | import java.awt.Point; |
| 6 | 7 | import java.awt.Rectangle; |
| 7 | 8 | import java.awt.event.ComponentAdapter; |
| … |
… |
public class NavigatableComponent extends JComponent implements Helpful {
|
| 319 | 320 | } |
| 320 | 321 | |
| 321 | 322 | protected boolean isVisibleOnScreen() { |
| 322 | | return SwingUtilities.getWindowAncestor(this) != null && isShowing(); |
| | 323 | return GraphicsEnvironment.isHeadless() || ( |
| | 324 | SwingUtilities.getWindowAncestor(this) != null && isShowing() |
| | 325 | ); |
| 323 | 326 | } |
| 324 | 327 | |
| 325 | 328 | /** |