private void cacheImage(@Nullable URL url) {
if (url == null) {
return;
}
String path = url.getPath();
if (path == null) {
return;
}
Icon icon;
if (path.startsWith("/severity/")) {
String severity = url.getPath().substring(10);
icon = SonarLintIcons.severity(severity);
} else if (path.startsWith("/type/")) {
String type = url.getPath().substring(6);
icon = SonarLintIcons.type(type);
} else {
return;
}
if (JBUI.isHiDPI()) {
icon = IconUtil.scale(icon, 0.5);
}
Dictionary<URL, Image> cache = (Dictionary<URL, Image>) getDocument().getProperty("imageCache");
if (cache == null) {
cache = new Hashtable<>();
}
cache.put(url, SonarLintUtils.iconToImage(icon));
getDocument().putProperty("imageCache", cache);
}
}