Changeset 10586 in josm


Ignore:
Timestamp:
2016-07-22T22:30:54+02:00 (5 years ago)
Author:
Don-vip
Message:

see #11390, fix #13190 - Allow Lambda bug report parameters (patch by michael2402) - gsoc-core

Location:
trunk/src/org/openstreetmap/josm
Files:
4 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MapView.java

    r10496 r10586  
    920920        synchronized (temporaryLayers) {
    921921            for (MapViewPaintable mvp : temporaryLayers) {
    922                 mvp.paint(tempG, this, box);
     922                try {
     923                    mvp.paint(tempG, this, box);
     924                } catch (RuntimeException e) {
     925                    throw BugReport.intercept(e).put("mvp", mvp);
     926                }
    923927            }
    924928        }
    925929
    926930        // draw world borders
    927         tempG.setColor(Color.WHITE);
    928         Bounds b = getProjection().getWorldBoundsLatLon();
    929         double lat = b.getMinLat();
    930         double lon = b.getMinLon();
    931 
    932         Point p = getPoint(b.getMin());
    933 
    934         GeneralPath path = new GeneralPath();
    935 
    936         double d = 1.0;
    937         path.moveTo(p.x, p.y);
    938         double max = b.getMax().lat();
    939         for (; lat <= max; lat += d) {
    940             p = getPoint(new LatLon(lat >= max ? max : lat, lon));
    941             path.lineTo(p.x, p.y);
    942         }
    943         lat = max; max = b.getMax().lon();
    944         for (; lon <= max; lon += d) {
    945             p = getPoint(new LatLon(lat, lon >= max ? max : lon));
    946             path.lineTo(p.x, p.y);
    947         }
    948         lon = max; max = b.getMinLat();
    949         for (; lat >= max; lat -= d) {
    950             p = getPoint(new LatLon(lat <= max ? max : lat, lon));
    951             path.lineTo(p.x, p.y);
    952         }
    953         lat = max; max = b.getMinLon();
    954         for (; lon >= max; lon -= d) {
    955             p = getPoint(new LatLon(lat, lon <= max ? max : lon));
    956             path.lineTo(p.x, p.y);
    957         }
    958 
    959         int w = getWidth();
    960         int h = getHeight();
    961 
    962         // Work around OpenJDK having problems when drawing out of bounds
    963         final Area border = new Area(path);
    964         // Make the viewport 1px larger in every direction to prevent an
    965         // additional 1px border when zooming in
    966         final Area viewport = new Area(new Rectangle(-1, -1, w + 2, h + 2));
    967         border.intersect(viewport);
    968         tempG.draw(border);
     931        try {
     932            drawWorldBorders(tempG);
     933        } catch (RuntimeException e) {
     934            throw BugReport.intercept(e).put("bounds", () -> getProjection().getWorldBoundsLatLon());
     935        }
    969936
    970937        if (Main.isDisplayingMapView() && Main.map.filterDialog != null) {
     
    1007974    }
    1008975
     976    private void drawWorldBorders(Graphics2D tempG) {
     977        tempG.setColor(Color.WHITE);
     978        Bounds b = getProjection().getWorldBoundsLatLon();
     979        double lat = b.getMinLat();
     980        double lon = b.getMinLon();
     981
     982        Point p = getPoint(b.getMin());
     983
     984        GeneralPath path = new GeneralPath();
     985
     986        double d = 1.0;
     987        path.moveTo(p.x, p.y);
     988        double max = b.getMax().lat();
     989        for (; lat <= max; lat += d) {
     990            p = getPoint(new LatLon(lat >= max ? max : lat, lon));
     991            path.lineTo(p.x, p.y);
     992        }
     993        lat = max; max = b.getMax().lon();
     994        for (; lon <= max; lon += d) {
     995            p = getPoint(new LatLon(lat, lon >= max ? max : lon));
     996            path.lineTo(p.x, p.y);
     997        }
     998        lon = max; max = b.getMinLat();
     999        for (; lat >= max; lat -= d) {
     1000            p = getPoint(new LatLon(lat <= max ? max : lat, lon));
     1001            path.lineTo(p.x, p.y);
     1002        }
     1003        lat = max; max = b.getMinLon();
     1004        for (; lon >= max; lon -= d) {
     1005            p = getPoint(new LatLon(lat, lon <= max ? max : lon));
     1006            path.lineTo(p.x, p.y);
     1007        }
     1008
     1009        int w = getWidth();
     1010        int h = getHeight();
     1011
     1012        // Work around OpenJDK having problems when drawing out of bounds
     1013        final Area border = new Area(path);
     1014        // Make the viewport 1px larger in every direction to prevent an
     1015        // additional 1px border when zooming in
     1016        final Area viewport = new Area(new Rectangle(-1, -1, w + 2, h + 2));
     1017        border.intersect(viewport);
     1018        tempG.draw(border);
     1019    }
     1020
    10091021    /**
    10101022     * Sets up the viewport to prepare for drawing the view.
  • trunk/src/org/openstreetmap/josm/gui/MapViewState.java

    r10486 r10586  
    1818import org.openstreetmap.josm.data.projection.Projection;
    1919import org.openstreetmap.josm.gui.download.DownloadDialog;
     20import org.openstreetmap.josm.tools.bugreport.BugReport;
    2021
    2122/**
     
    9798            component = component.getParent();
    9899        }
    99         topLeftOnScreen = position.getLocationOnScreen();
     100        try {
     101            topLeftOnScreen = position.getLocationOnScreen();
     102        } catch (RuntimeException e) {
     103            throw BugReport.intercept(e).put("position", position).put("parent", () -> position.getParent());
     104        }
    100105    }
    101106
  • trunk/src/org/openstreetmap/josm/tools/bugreport/BugReport.java

    r10585 r10586  
    2020 * You should then add some debug information there. This can be the OSM ids that caused the error, information on the data you were working on
    2121 * or other local variables. Make sure that no excpetions may occur while computing the values. It is best to send plain local variables to
    22  * put(...). Then simply throw the throwable you got from the bug report. The global exception handler will do the rest.
     22 * put(...). If you need to do computations, put them into a lambda expression. Then simply throw the throwable you got from the bug report.
     23 * The global exception handler will do the rest.
    2324 * <pre>
    2425 * int id = ...;
     
    2728 *   ... your code ...
    2829 * } catch (RuntimeException t) {
    29  *   throw BugReport.intercept(t).put("id", id).put("tag", tag);
     30 *   throw BugReport.intercept(t).put("id", id).put("tag", () -> x.getTag());
    3031 * }
    3132 * </pre>
    3233 *
    3334 * Instead of re-throwing, you can call {@link ReportedException#warn()}. This will display a warning to the user and allow it to either report
    34  * the execption or ignore it.
     35 * the exception or ignore it.
    3536 *
    3637 * @author Michael Zangl
  • trunk/src/org/openstreetmap/josm/tools/bugreport/ReportedException.java

    r10585 r10586  
    1717import java.util.NoSuchElementException;
    1818import java.util.Set;
     19import java.util.function.Supplier;
    1920
    2021import org.openstreetmap.josm.Main;
     
    180181
    181182    /**
    182      * Adds some debug values to this exception.
     183     * Adds some debug values to this exception. The value is converted to a string. Errors during conversion are handled.
    183184     *
    184185     * @param key
     
    189190     */
    190191    public ReportedException put(String key, Object value) {
     192        return put(key, () -> value);
     193    }
     194
     195    /**
     196    * Adds some debug values to this exception. This method automatically catches errors that occur during the production of the value.
     197    *
     198    * @param key
     199    *            The key to add this for. Does not need to be unique but it would be nice.
     200    * @param valueSupplier
     201    *            A supplier that is called once to get the value.
     202    * @return This exception for easy chaining.
     203    * @since 10586
     204    */
     205    public ReportedException put(String key, Supplier<Object> valueSupplier) {
    191206        String string;
    192207        try {
     208            Object value = valueSupplier.get();
    193209            if (value == null) {
    194210                string = "null";
Note: See TracChangeset for help on using the changeset viewer.