Changeset 16984 in josm for trunk/src


Ignore:
Timestamp:
2020-08-30T21:27:14+02:00 (4 years ago)
Author:
simon04
Message:

see #18694 - Migrate ImageProviderTest to JUnit 5, mock bestCursorSize, compare cursors with reference images

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/tools/ImageProvider.java

    r16946 r16984  
    4848import java.util.concurrent.Executors;
    4949import java.util.function.Consumer;
     50import java.util.function.UnaryOperator;
    5051import java.util.regex.Matcher;
    5152import java.util.regex.Pattern;
     
    13311332
    13321333        Point hotSpot = new Point();
    1333         Image image = getCursorImage(name, overlay, hotSpot);
     1334        Image image = getCursorImage(name, overlay, dim -> Toolkit.getDefaultToolkit().getBestCursorSize(dim.width, dim.height), hotSpot);
    13341335
    13351336        return Toolkit.getDefaultToolkit().createCustomCursor(image, hotSpot, name);
     
    13481349     * @param name the cursor image filename in "cursor" directory
    13491350     * @param overlay optional overlay image
     1351     * @param bestCursorSizeFunction computes the best cursor size, see {@link Toolkit#getBestCursorSize(int, int)}
    13501352     * @param hotSpot will be set to the properly scaled hotspot of the cursor
    13511353     * @return cursor with a given file name, optionally decorated with an overlay image
    13521354     */
    1353     static Image getCursorImage(String name, String overlay, /* out */ Point hotSpot) {
     1355    static Image getCursorImage(String name, String overlay, UnaryOperator<Dimension> bestCursorSizeFunction, /* out */ Point hotSpot) {
    13541356        ImageProvider imageProvider = new ImageProvider("cursor", name);
    13551357        if (overlay != null) {
     
    13661368        // AWT will resize the cursor to bestCursorSize internally anyway, but miss to scale the hotspot as well
    13671369        // (bug JDK-8238734).  So let's do this ourselves, and also scale the hotspot accordingly.
    1368         Dimension bestCursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(width, height);
     1370        Dimension bestCursorSize = bestCursorSizeFunction.apply(new Dimension(width, height));
    13691371        if (bestCursorSize.width != 0 && bestCursorSize.height != 0) {
    13701372            // In principle, we could pass the MultiResolutionImage itself to AWT, but due to bug JDK-8240568,
Note: See TracChangeset for help on using the changeset viewer.