Ticket #15599: v3-0001-NavigatableComponent-tweak-behaviour-to-allow-upd.patch

File v3-0001-NavigatableComponent-tweak-behaviour-to-allow-upd.patch, 3.0 KB (added by ris, 8 years ago)
  • src/org/openstreetmap/josm/gui/MapViewState.java

    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  
    22package org.openstreetmap.josm.gui;
    33
    44import java.awt.Container;
     5import java.awt.GraphicsEnvironment;
    56import java.awt.Point;
    67import java.awt.geom.AffineTransform;
    78import java.awt.geom.Area;
    public final class MapViewState implements Serializable {  
    144145    }
    145146
    146147    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            }
    151158        }
    152159    }
    153160
  • src/org/openstreetmap/josm/gui/NavigatableComponent.java

    diff --git a/src/org/openstreetmap/josm/gui/NavigatableComponent.java b/src/org/openstreetmap/josm/gui/NavigatableComponent.java
    index e8da39e87..ca02f0c2b 100644
    a b  
    22package org.openstreetmap.josm.gui;
    33
    44import java.awt.Cursor;
     5import java.awt.GraphicsEnvironment;
    56import java.awt.Point;
    67import java.awt.Rectangle;
    78import java.awt.event.ComponentAdapter;
    public class NavigatableComponent extends JComponent implements Helpful {  
    319320    }
    320321
    321322    protected boolean isVisibleOnScreen() {
    322         return SwingUtilities.getWindowAncestor(this) != null && isShowing();
     323        return GraphicsEnvironment.isHeadless() || (
     324            SwingUtilities.getWindowAncestor(this) != null && isShowing()
     325        );
    323326    }
    324327
    325328    /**