Skip to content

Commit baeb188

Browse files
committed
1.添加置顶文字多国语
1 parent 6e73b14 commit baeb188

6 files changed

Lines changed: 109 additions & 118 deletions

File tree

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -54,7 +54,7 @@ public class IndexController extends IndexView {
5454

5555
public static final String STATISTICS_URL = "https://xwintop.gitee.io/maven/tongji/xJavaFxTool.html";
5656

57-
public static final String FAVORITE_CATEGORY_NAME = "置顶";
57+
public static final String FAVORITE_CATEGORY_NAME = XJavaFxToolApplication.RESOURCE_BUNDLE.getString("favoriteCategory");
5858

5959
private Map<String, MenuItem> menuItemMap = new HashMap<>();
6060

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -52,7 +52,7 @@ public void initialize() {
5252
onMouseRightClicked(event);
5353
}
5454
});
55-
CheckMenuItem chkFavorite = new CheckMenuItem("置顶");
55+
CheckMenuItem chkFavorite = new CheckMenuItem(IndexController.FAVORITE_CATEGORY_NAME);
5656
chkFavorite.setStyle("-fx-padding: 0 35 0 0");
5757
this.contextMenu = new ContextMenu(chkFavorite);
5858
chkFavorite.setOnAction(event2 -> {

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

Lines changed: 0 additions & 108 deletions
This file was deleted.

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

Lines changed: 103 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,18 +4,30 @@
44
import com.xwintop.xJavaFxTool.common.logback.ConsoleLogAppender;
55
import com.xwintop.xJavaFxTool.controller.IndexController;
66
import com.xwintop.xJavaFxTool.model.PluginJarInfo;
7-
import com.xwintop.xJavaFxTool.plugin.PluginLoader;
7+
import com.xwintop.xJavaFxTool.plugin.PluginClassLoader;
8+
import com.xwintop.xJavaFxTool.plugin.PluginContainer;
89
import com.xwintop.xJavaFxTool.utils.Config;
910
import com.xwintop.xcore.javafx.dialog.FxAlerts;
11+
import com.xwintop.xcore.util.javafx.AlertUtil;
1012
import com.xwintop.xcore.util.javafx.JavaFxViewUtil;
1113
import javafx.event.ActionEvent;
1214
import javafx.event.Event;
15+
import javafx.fxml.FXMLLoader;
16+
import javafx.scene.Node;
1317
import javafx.scene.control.Tab;
18+
import javafx.scene.control.TabPane;
1419
import javafx.scene.control.TextArea;
20+
import javafx.scene.image.Image;
21+
import javafx.scene.image.ImageView;
22+
import javafx.scene.layout.BorderPane;
23+
import javafx.scene.web.WebEngine;
24+
import javafx.scene.web.WebView;
1525
import javafx.stage.Stage;
1626
import lombok.Data;
1727
import lombok.extern.slf4j.Slf4j;
28+
import org.apache.commons.lang3.StringUtils;
1829

30+
import java.lang.ref.WeakReference;
1931
import java.util.HashMap;
2032
import java.util.Locale;
2133
import java.util.Map;
@@ -37,7 +49,7 @@ public void setLanguageAction(String languageType) throws Exception {
3749
} else if ("English".equals(languageType)) {
3850
Config.set(Config.Keys.Locale, Locale.US);
3951
}
40-
FxAlerts.info("", indexController.getBundle().getString("SetLanguageText"));
52+
AlertUtil.showInfoAlert(indexController.getBundle().getString("SetLanguageText"));
4153
}
4254

4355
public void addNodepadAction(ActionEvent event) {
@@ -100,9 +112,9 @@ public void loadPlugin(PluginJarInfo pluginJarInfo) {
100112
String controllerType = pluginJarInfo.getControllerType();
101113

102114
if (controllerType.equals("Node")) {
103-
tab = PluginLoader.loadIsolatedPluginAsTab(pluginJarInfo, indexController.getTabPaneMain(), indexController.getSingleWindowBootCheckMenuItem().isSelected());
115+
tab = loadIsolatedPluginAsTab(pluginJarInfo, indexController.getTabPaneMain(), indexController.getSingleWindowBootCheckMenuItem().isSelected());
104116
} else if (controllerType.equals("WebView")) {
105-
tab = PluginLoader.loadWebViewAsTab(pluginJarInfo, indexController.getTabPaneMain(), indexController.getSingleWindowBootCheckMenuItem().isSelected());
117+
tab = loadWebViewAsTab(pluginJarInfo, indexController.getTabPaneMain(), indexController.getSingleWindowBootCheckMenuItem().isSelected());
106118
} else {
107119
throw new AppException("找不到 controllerType=" + controllerType + " 的加载方式");
108120
}
@@ -112,4 +124,91 @@ public void loadPlugin(PluginJarInfo pluginJarInfo) {
112124
jarInfoMap.put(pluginJarInfo, tab);
113125
}
114126
}
127+
128+
/**
129+
* 以新 Tab 方式打开插件,但使用独立的 ClassLoader
130+
*/
131+
public static Tab loadIsolatedPluginAsTab(PluginJarInfo plugin, TabPane tabPane, boolean singleWindowBoot) {
132+
try {
133+
PluginContainer pluginContainer = new PluginContainer(PluginClassLoader.class.getClassLoader(), plugin);
134+
WeakReference<PluginContainer> containerRef = new WeakReference<>(pluginContainer);
135+
FXMLLoader generatingCodeFXMLLoader = pluginContainer.createFXMLLoader();
136+
if (generatingCodeFXMLLoader == null) {
137+
return null;
138+
}
139+
140+
if (singleWindowBoot) {
141+
JavaFxViewUtil.getNewStage(plugin.getTitle(), plugin.getIconPath(), generatingCodeFXMLLoader);
142+
return null;
143+
}
144+
145+
Tab tab = new Tab(plugin.getTitle());
146+
if (StringUtils.isNotEmpty(plugin.getIconPath())) {
147+
ImageView imageView = new ImageView(new Image(plugin.getIconPath()));
148+
imageView.setFitHeight(18);
149+
imageView.setFitWidth(18);
150+
tab.setGraphic(imageView);
151+
}
152+
153+
Node root = generatingCodeFXMLLoader.load();
154+
Object controller = generatingCodeFXMLLoader.getController();
155+
WeakReference<Object> controllerRef = new WeakReference<>(controller);
156+
157+
tab.setContent(root);
158+
tabPane.getTabs().add(tab);
159+
tabPane.getSelectionModel().select(tab);
160+
161+
tab.setOnCloseRequest(
162+
event -> {
163+
Object ctrl = controllerRef.get();
164+
if (ctrl != null) {
165+
JavaFxViewUtil.setControllerOnCloseRequest(ctrl, event);
166+
}
167+
168+
PluginContainer container = containerRef.get();
169+
if (container != null) {
170+
log.info("插件关闭:" + container.getPluginJarInfo().getName());
171+
container.unload();
172+
}
173+
}
174+
);
175+
176+
return tab;
177+
} catch (Exception e) {
178+
log.error("加载插件失败", e);
179+
FxAlerts.error("插件加载失败", e);
180+
}
181+
182+
return null;
183+
}
184+
185+
public static Tab loadWebViewAsTab(PluginJarInfo plugin, TabPane tabPane, boolean singleWindowBoot) {
186+
WebView browser = new WebView();
187+
WebEngine webEngine = browser.getEngine();
188+
String url = plugin.getPagePath();
189+
String title = plugin.getTitle();
190+
191+
if (url.startsWith("http")) {
192+
webEngine.load(url);
193+
} else {
194+
PluginContainer pluginContainer = new PluginContainer(plugin);
195+
webEngine.load(pluginContainer.getResource(url).toExternalForm());
196+
}
197+
198+
if (singleWindowBoot) {
199+
JavaFxViewUtil.getNewStage(title, plugin.getIconPath(), new BorderPane(browser));
200+
return null;
201+
}
202+
Tab tab = new Tab(title);
203+
if (StringUtils.isNotEmpty(plugin.getIconPath())) {
204+
ImageView imageView = new ImageView(new Image(plugin.getIconPath()));
205+
imageView.setFitHeight(18);
206+
imageView.setFitWidth(18);
207+
tab.setGraphic(imageView);
208+
}
209+
tab.setContent(browser);
210+
tabPane.getTabs().add(tab);
211+
tabPane.getSelectionModel().select(tab);
212+
return tab;
213+
}
115214
}

src/main/resources/locale/Menu.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -27,9 +27,10 @@ SetLanguageText = \u8BED\u8A00\u9009\u62E9\u8BBE\u7F6E\u6210\u529F\uFF0C\u91CD\u
2727
feedback = \u6B22\u8FCE\u5410\u69FD
2828

2929
selectTextField = \u8BF7\u8F93\u5165\u83DC\u5355\u540D
30-
selectButton = \u641C\u7D22
3130
singleWindowBootCheckBox = \u5728\u65B0\u7A97\u53E3\u4E2D\u6253\u5F00
3231
singleInstanceBoot = \u5728\u65B0Tab\u4E2D\u6253\u5F00
32+
favoriteCategory = \u7F6E\u9876
33+
search = \u641C\u7D22
3334

3435
codeTools = Code\u5DE5\u5177
3536
debugTools = \u8C03\u8BD5\u5DE5\u5177
@@ -42,4 +43,3 @@ assistTools = \u8F85\u52A9\u5DE5\u5177
4243
games = \u6E38\u620F
4344
start = \u5F00\u59CB
4445
newPlugin = \u65B0\u5EFA
45-
search = \u641C\u7D22

src/main/resources/locale/Menu_en_US.properties

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,12 +24,12 @@ userSupport = user Support
2424

2525
aboutText = Welcome to the JavaFx tool set.\ngitUrl:https://gitee.com/xwintop/xJavaFxTool\nAuthor:xwintop\nblog:www.xwintop.com\nWelcome to make comments and improve the tool together. Thank you!!\ncurrent version:
2626
SetLanguageText = The language selection settings have been successful and will take effect after reboot.
27+
feedback = Feedback
2728

2829
selectTextField = Please enter a menu name
29-
selectButton = select
3030
singleWindowBootCheckBox = isSingleWindowBoot
3131
singleInstanceBoot = isSingleInstanceBoot
32-
feedback = Feedback
32+
favoriteCategory = favoriteCategory
3333
search = Search
3434

3535
codeTools = codeTools

0 commit comments

Comments
 (0)