Skip to content

Commit add8e98

Browse files
committed
1.修改插件图标读取方法
1 parent bf1e52f commit add8e98

5 files changed

Lines changed: 51 additions & 19 deletions

File tree

src/main/java/com/xwintop/xJavaFxTool/controller/IndexController.java

Lines changed: 12 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,12 @@ public void initialize(URL location, ResourceBundle resources) {
7676
initView();
7777
initEvent();
7878
initService();
79-
initNotepad();
80-
}
81-
82-
private void initNotepad() {
83-
// if (Config.getBoolean(Config.Keys.NotepadEnabled, true)) {
84-
// addNodepadAction(null);
85-
// }
8679
}
8780

8881
private void initView() {
82+
if (Config.getBoolean(Config.Keys.NotepadEnabled, true)) {
83+
addNodepadAction(null);
84+
}
8985
this.indexService.addWebView(XJavaFxToolApplication.RESOURCE_BUNDLE.getString("feedback"), QQ_URL, null);
9086
this.tongjiWebView.getEngine().load(STATISTICS_URL);
9187
this.tabPaneMain.getSelectionModel().select(0);
@@ -173,8 +169,15 @@ private void addMenu(PluginJarInfo jarInfo) {
173169
moreToolsMenu.getItems().add(menu);
174170
}
175171
MenuItem menuItem = new MenuItem(jarInfo.getTitle());
176-
if (StringUtils.isNotEmpty(jarInfo.getIconPath())) {
177-
ImageView imageView = new ImageView(new Image(jarInfo.getIconPath()));
172+
if (jarInfo.getIconImage() == null) {
173+
if (StringUtils.isNotEmpty(jarInfo.getIconPath())) {
174+
ImageView imageView = new ImageView(new Image(jarInfo.getIconPath()));
175+
imageView.setFitHeight(18);
176+
imageView.setFitWidth(18);
177+
menuItem.setGraphic(imageView);
178+
}
179+
} else {
180+
ImageView imageView = new ImageView(jarInfo.getIconImage());
178181
imageView.setFitHeight(18);
179182
imageView.setFitWidth(18);
180183
menuItem.setGraphic(imageView);

src/main/java/com/xwintop/xJavaFxTool/model/PluginJarInfo.java

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.xwintop.xJavaFxTool.model;
22

33
import com.alibaba.fastjson.annotation.JSONField;
4+
import javafx.scene.image.Image;
45
import lombok.Data;
56
import lombok.NoArgsConstructor;
67

@@ -83,4 +84,7 @@ public File getFile() {
8384
public String getDefaultIconPath() {
8485
return bundleName == null ? "" : (bundleName.replace("locale.", "/logo/") + ".png");
8586
}
87+
88+
@JSONField(serialize = false)
89+
private Image iconImage;
8690
}

src/main/java/com/xwintop/xJavaFxTool/newui/PluginItemController.java

Lines changed: 11 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@
2323
@Slf4j
2424
public class PluginItemController {
2525
public static final String FXML_PATH = "/com/xwintop/xJavaFxTool/fxmlView/newui/plugin-item.fxml";
26+
2627
public static PluginItemController newInstance(PluginJarInfo pluginJarInfo) {
2728
FXMLLoader fxmlLoader = FxmlHelper.loadFromResource(FXML_PATH);
2829
PluginItemController controller = fxmlLoader.getController();
@@ -73,13 +74,17 @@ private void onMouseLeftClicked(MouseEvent event) {
7374
}
7475

7576
private void updateIcon() {
76-
URL iconUrl = ResourceUtils.getResource(this.pluginJarInfo.getIconPath(), this.pluginJarInfo.getDefaultIconPath(), "/logo/plugin.png");
77-
if (iconUrl != null) {
78-
String url = iconUrl.toExternalForm();
79-
if (url.endsWith("plugin.png")) {
80-
log.info("please add logo to " + this.pluginJarInfo.getDefaultIconPath());
77+
if (this.pluginJarInfo.getIconImage() != null) {
78+
imgLogo.setImage(this.pluginJarInfo.getIconImage());
79+
} else {
80+
URL iconUrl = ResourceUtils.getResource(this.pluginJarInfo.getIconPath(), this.pluginJarInfo.getDefaultIconPath(), "/logo/plugin.png");
81+
if (iconUrl != null) {
82+
String url = iconUrl.toExternalForm();
83+
if (url.endsWith("plugin.png")) {
84+
log.info("please add logo to " + this.pluginJarInfo.getDefaultIconPath());
85+
}
86+
imgLogo.setImage(new Image(url));
8187
}
82-
imgLogo.setImage(new Image(url));
8388
}
8489
}
8590

src/main/java/com/xwintop/xJavaFxTool/plugin/PluginParser.java

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
import com.xwintop.xJavaFxTool.AppException;
44
import com.xwintop.xJavaFxTool.model.PluginJarInfo;
55
import com.xwintop.xJavaFxTool.utils.Config;
6+
import javafx.scene.image.Image;
67
import lombok.extern.slf4j.Slf4j;
78
import org.apache.commons.lang3.StringUtils;
89
import org.dom4j.Document;
@@ -71,6 +72,11 @@ public static void parse(File pluginFile, PluginJarInfo pluginJarInfo, ClassLoad
7172
pluginJarInfo.setBundleName(resourceBundleName);
7273
pluginJarInfo.setControllerType(controllerType);
7374
pluginJarInfo.setTitle(title);
75+
pluginJarInfo.setIconPath(pluginElement.elementTextTrim("iconPath"));
76+
if (StringUtils.isNotBlank(pluginJarInfo.getIconPath())) {
77+
Image iconImage = new Image(jarFile.getInputStream(jarFile.getJarEntry(StringUtils.removeStart(pluginJarInfo.getIconPath(),"/"))));
78+
pluginJarInfo.setIconImage(iconImage);
79+
}
7480

7581
if (controllerType.equals("Node")) {
7682
pluginJarInfo.setFxmlPath(url);

src/main/java/com/xwintop/xJavaFxTool/services/IndexService.java

Lines changed: 18 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -153,8 +153,15 @@ public static Tab loadIsolatedPluginAsTab(PluginJarInfo plugin, TabPane tabPane,
153153
}
154154

155155
Tab tab = new Tab(plugin.getTitle());
156-
if (StringUtils.isNotEmpty(plugin.getIconPath())) {
157-
ImageView imageView = new ImageView(new Image(plugin.getIconPath()));
156+
if (plugin.getIconImage() == null) {
157+
if (StringUtils.isNotEmpty(plugin.getIconPath())) {
158+
ImageView imageView = new ImageView(new Image(plugin.getIconPath()));
159+
imageView.setFitHeight(18);
160+
imageView.setFitWidth(18);
161+
tab.setGraphic(imageView);
162+
}
163+
} else {
164+
ImageView imageView = new ImageView(plugin.getIconImage());
158165
imageView.setFitHeight(18);
159166
imageView.setFitWidth(18);
160167
tab.setGraphic(imageView);
@@ -203,8 +210,15 @@ public static Tab loadWebViewAsTab(PluginJarInfo plugin, TabPane tabPane, boolea
203210
return null;
204211
}
205212
Tab tab = new Tab(title);
206-
if (StringUtils.isNotEmpty(plugin.getIconPath())) {
207-
ImageView imageView = new ImageView(new Image(plugin.getIconPath()));
213+
if (plugin.getIconImage() == null) {
214+
if (StringUtils.isNotEmpty(plugin.getIconPath())) {
215+
ImageView imageView = new ImageView(new Image(plugin.getIconPath()));
216+
imageView.setFitHeight(18);
217+
imageView.setFitWidth(18);
218+
tab.setGraphic(imageView);
219+
}
220+
} else {
221+
ImageView imageView = new ImageView(plugin.getIconImage());
208222
imageView.setFitHeight(18);
209223
imageView.setFitWidth(18);
210224
tab.setGraphic(imageView);

0 commit comments

Comments
 (0)