!164 尝试修复文件图标渲染问题

Merge pull request !164 from 格物方能致知/develop
This commit is contained in:
格物方能致知 2023-10-11 14:11:24 +00:00 committed by Gitee
commit 5fef22d0db
No known key found for this signature in database
GPG Key ID: 173E9B9CA92EEF8F

View File

@ -1,6 +1,7 @@
package org.jcnc.jnotepad.app.utils;
import javafx.scene.Node;
import javafx.scene.image.ImageView;
import org.jcnc.jnotepad.controller.event.handler.menuitem.OpenFile;
import org.jcnc.jnotepad.controller.exception.AppException;
import org.jcnc.jnotepad.model.entity.DirFileModel;
@ -165,7 +166,7 @@ public class FileUtil {
dirFileModel.getChildFile().add(new DirFileModel(
f.getAbsolutePath(), f.getName(), null,
getIconCorrespondingToFileName(f.getName()),
getIconCorrespondingToFileName(f.getName())));
null));
}
}
}
@ -306,7 +307,14 @@ public class FileUtil {
public static Node getIconCorrespondingToFileName(String fileName) {
// todo 在此根据文件缀名获取对应的图标
String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1);
return UiUtil.getIconMap().getOrDefault(fileExtension, FontIcon.of(FILE_UNKNOWN));
Node orDefault = UiUtil.getIconMap().getOrDefault(fileExtension, FontIcon.of(FILE_UNKNOWN));
if (orDefault instanceof FontIcon fontIcon) {
return new FontIcon(fontIcon.getIconLiteral());
}
if (orDefault instanceof ImageView imageView) {
return new ImageView(imageView.getImage());
}
return orDefault;
}
}