Changeset 18116 in josm


Ignore:
Timestamp:
2021-08-02T19:18:47+02:00 (3 years ago)
Author:
Don-vip
Message:

fix #17915 - HTML in imagery menu tooltips does not work with Aqua L&F

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/imagery/ImageryInfo.java

    r17862 r18116  
    3636import org.openstreetmap.josm.tools.Logging;
    3737import org.openstreetmap.josm.tools.MultiMap;
     38import org.openstreetmap.josm.tools.PlatformManager;
    3839import org.openstreetmap.josm.tools.StreamUtils;
    3940import org.openstreetmap.josm.tools.Utils;
     
    705706    }
    706707
    707 
    708708    /**
    709709     * Returns a tool tip text for display.
     
    713713    @Override
    714714    public String getToolTipText() {
     715        boolean htmlSupported = PlatformManager.getPlatform().isHtmlSupportedInMenuTooltips();
    715716        StringBuilder res = new StringBuilder(getName());
    716717        boolean html = false;
    717718        String dateStr = getDate();
    718719        if (dateStr != null && !dateStr.isEmpty()) {
    719             res.append("<br>").append(tr("Date of imagery: {0}", dateStr));
    720             html = true;
     720            html = addNewLineInTooltip(res, tr("Date of imagery: {0}", dateStr), htmlSupported);
    721721        }
    722722        if (category != null && category.getDescription() != null) {
    723             res.append("<br>").append(tr("Imagery category: {0}", category.getDescription()));
    724             html = true;
     723            html = addNewLineInTooltip(res, tr("Imagery category: {0}", category.getDescription()), htmlSupported);
    725724        }
    726725        if (bestMarked) {
    727             res.append("<br>").append(tr("This imagery is marked as best in this region in other editors."));
    728             html = true;
     726            html = addNewLineInTooltip(res, tr("This imagery is marked as best in this region in other editors."), htmlSupported);
    729727        }
    730728        if (overlay) {
    731             res.append("<br>").append(tr("This imagery is an overlay."));
    732             html = true;
     729            html = addNewLineInTooltip(res, tr("This imagery is an overlay."), htmlSupported);
    733730        }
    734731        String desc = getDescription();
    735732        if (desc != null && !desc.isEmpty()) {
    736             res.append("<br>").append(Utils.escapeReservedCharactersHTML(desc));
    737             html = true;
     733            html = addNewLineInTooltip(res, desc, htmlSupported);
    738734        }
    739735        if (html) {
     
    741737        }
    742738        return res.toString();
     739    }
     740
     741    private static boolean addNewLineInTooltip(StringBuilder res, String line, boolean htmlSupported) {
     742        if (htmlSupported) {
     743            res.append("<br>").append(Utils.escapeReservedCharactersHTML(line));
     744        } else {
     745            res.append('\n').append(line);
     746        }
     747        return htmlSupported;
    743748    }
    744749
  • trunk/src/org/openstreetmap/josm/tools/PlatformHook.java

    r17779 r18116  
    234234
    235235    /**
     236     * Determines if HTML rendering is supported in menu tooltips.
     237     * @return {@code true} if HTML rendering is supported in menu tooltips
     238     * @since 18116
     239     */
     240    default boolean isHtmlSupportedInMenuTooltips() {
     241        return true;
     242    }
     243
     244    /**
    236245     * Returns extended modifier key used as the appropriate accelerator key for menu shortcuts.
    237246     * It is advised everywhere to use {@link Toolkit#getMenuShortcutKeyMask()} to get the cross-platform modifier, but:
  • trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java

    r17826 r18116  
    2727import java.util.Objects;
    2828import java.util.concurrent.ExecutionException;
     29
     30import javax.swing.UIManager;
    2931
    3032import org.openstreetmap.josm.data.Preferences;
     
    9597        checkExpiredJava(javaCallback);
    9698        checkWebStartMigration(webStartCallback);
     99    }
     100
     101    @Override
     102    public boolean isHtmlSupportedInMenuTooltips() {
     103        // See #17915 - JDK-8164935
     104        // "Mac" is the native LAF, "Aqua" is Quaqua. Both use native menus with native tooltips.
     105        String laf = UIManager.getLookAndFeel().getID();
     106        return !("true".equals(Utils.getSystemProperty("apple.laf.useScreenMenuBar"))
     107                && ("Aqua".equals(laf) || laf.contains("Mac")));
    97108    }
    98109
  • trunk/src/org/openstreetmap/josm/tools/Shortcut.java

    r17676 r18116  
    2121import javax.swing.JMenu;
    2222import javax.swing.KeyStroke;
    23 import javax.swing.UIManager;
    2423import javax.swing.text.JTextComponent;
    2524
     
    640639                .filter(text -> !text.isEmpty());
    641640
    642         final String laf = UIManager.getLookAndFeel().getID();
    643         // "Mac" is the native LAF, "Aqua" is Quaqua. Both use native menus with native tooltips.
    644         final boolean canHtml = !(PlatformManager.isPlatformOsx() && (laf.contains("Mac") || laf.contains("Aqua")));
     641        final boolean canHtml = PlatformManager.getPlatform().isHtmlSupportedInMenuTooltips();
    645642
    646643        StringBuilder result = new StringBuilder(48);
     
    664661        return result.toString();
    665662    }
    666 
    667663}
Note: See TracChangeset for help on using the changeset viewer.