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

This commit is contained in:
gewuyou 2023-10-11 22:09:19 +08:00
parent 2486b9bbb5
commit 7e745797f9

View File

@ -1,6 +1,7 @@
package org.jcnc.jnotepad.app.utils; package org.jcnc.jnotepad.app.utils;
import javafx.scene.Node; import javafx.scene.Node;
import javafx.scene.image.ImageView;
import org.jcnc.jnotepad.controller.event.handler.menuitem.OpenFile; import org.jcnc.jnotepad.controller.event.handler.menuitem.OpenFile;
import org.jcnc.jnotepad.controller.exception.AppException; import org.jcnc.jnotepad.controller.exception.AppException;
import org.jcnc.jnotepad.model.entity.DirFileModel; import org.jcnc.jnotepad.model.entity.DirFileModel;
@ -165,7 +166,7 @@ public class FileUtil {
dirFileModel.getChildFile().add(new DirFileModel( dirFileModel.getChildFile().add(new DirFileModel(
f.getAbsolutePath(), f.getName(), null, f.getAbsolutePath(), f.getName(), null,
getIconCorrespondingToFileName(f.getName()), getIconCorrespondingToFileName(f.getName()),
getIconCorrespondingToFileName(f.getName()))); null));
} }
} }
} }
@ -306,7 +307,14 @@ public class FileUtil {
public static Node getIconCorrespondingToFileName(String fileName) { public static Node getIconCorrespondingToFileName(String fileName) {
// todo 在此根据文件缀名获取对应的图标 // todo 在此根据文件缀名获取对应的图标
String fileExtension = fileName.substring(fileName.lastIndexOf(".") + 1); 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;
} }
} }