Skip to content

Commit e896736

Browse files
committed
1.调整老界面
1 parent ad6638c commit e896736

7 files changed

Lines changed: 122 additions & 50 deletions

File tree

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

Lines changed: 104 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -2,9 +2,15 @@
22

33
import com.xwintop.xJavaFxTool.XJavaFxToolApplication;
44
import com.xwintop.xJavaFxTool.controller.index.PluginManageController;
5+
import com.xwintop.xJavaFxTool.event.AppEvents;
6+
import com.xwintop.xJavaFxTool.event.PluginEvent;
7+
import com.xwintop.xJavaFxTool.model.PluginJarInfo;
58
import com.xwintop.xJavaFxTool.model.ToolFxmlLoaderConfiguration;
9+
import com.xwintop.xJavaFxTool.newui.NewLauncherService;
610
import com.xwintop.xJavaFxTool.newui.PluginCategoryController;
711
import com.xwintop.xJavaFxTool.newui.PluginItemController;
12+
import com.xwintop.xJavaFxTool.plugin.PluginManager;
13+
import com.xwintop.xJavaFxTool.plugin.PluginParser;
814
import com.xwintop.xJavaFxTool.services.IndexService;
915
import com.xwintop.xJavaFxTool.services.index.PluginManageService;
1016
import com.xwintop.xJavaFxTool.services.index.SystemSettingService;
@@ -20,6 +26,7 @@
2026
import javafx.fxml.FXML;
2127
import javafx.fxml.FXMLLoader;
2228
import javafx.scene.Parent;
29+
import javafx.scene.control.CheckMenuItem;
2330
import javafx.scene.control.ContextMenu;
2431
import javafx.scene.control.Menu;
2532
import javafx.scene.control.MenuItem;
@@ -30,6 +37,7 @@
3037
import lombok.extern.slf4j.Slf4j;
3138
import org.apache.commons.beanutils.BeanUtils;
3239
import org.apache.commons.lang.StringUtils;
40+
import org.apache.commons.lang3.BooleanUtils;
3341
import org.apache.commons.lang3.time.DateFormatUtils;
3442
import org.dom4j.Attribute;
3543
import org.dom4j.Document;
@@ -53,18 +61,20 @@
5361
@Getter
5462
@Setter
5563
public class IndexController extends IndexView {
56-
5764
public static final String QQ_URL = "https://support.qq.com/product/127577";
5865

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

68+
public static final String FAVORITE_CATEGORY_NAME = "置顶";
69+
6170
private Map<String, Menu> menuMap = new HashMap<>();
6271

6372
private Map<String, MenuItem> menuItemMap = new HashMap<>();
6473

6574
private IndexService indexService = new IndexService(this);
6675

6776
private ContextMenu contextMenu = new ContextMenu();
77+
private ContextMenu itemContextMenu;
6878

6979
// 实现搜索用
7080
private List<PluginItemController> pluginItemControllers = new ArrayList<>();
@@ -86,6 +96,7 @@ public void initialize(URL location, ResourceBundle resources) {
8696

8797
this.indexService.addWebView(XJavaFxToolApplication.RESOURCE_BUNDLE.getString("feedback"), QQ_URL, null);
8898
this.tongjiWebView.getEngine().load(STATISTICS_URL);
99+
this.tabPaneMain.getSelectionModel().select(0);
89100
}
90101

91102
private void initNotepad() {
@@ -95,6 +106,7 @@ private void initNotepad() {
95106
}
96107

97108
private void initView() {
109+
initContextMenu();
98110
menuMap.put("moreToolsMenu", moreToolsMenu);
99111
File libPath = new File("libs/");
100112
// 获取所有的.jar和.zip文件
@@ -116,12 +128,91 @@ private void initView() {
116128
private void initEvent() {
117129
mainMenuBar.setUseSystemMenuBar(true);
118130
myTextField.textProperty().addListener((observable, oldValue, newValue) -> selectAction(newValue));
119-
myButton.setOnAction(arg0 -> {
120-
selectAction(myTextField.getText());
121-
});
122131
}
123132

124133
private void initService() {
134+
NewLauncherService.getInstance().setTabPane(tabPaneMain);
135+
loadPlugins(); // 加载插件列表到界面上
136+
AppEvents.addEventHandler(PluginEvent.PLUGIN_DOWNLOADED, pluginEvent -> {
137+
loadPlugins();
138+
});
139+
}
140+
141+
private void initContextMenu() {
142+
CheckMenuItem chkFavorite = new CheckMenuItem("置顶");
143+
chkFavorite.setStyle("-fx-padding: 0 35 0 0");
144+
this.itemContextMenu = new ContextMenu(chkFavorite);
145+
chkFavorite.setOnAction(event -> {
146+
CheckMenuItem _this = (CheckMenuItem) event.getSource();
147+
PluginItemController pluginItemController = NewLauncherService.getInstance().getCurrentPluginItem();
148+
setFavorite(pluginItemController, _this.isSelected());
149+
});
150+
}
151+
private void setFavorite(PluginItemController itemController, boolean isFavorite) {
152+
if (itemController == null) {
153+
return;
154+
}
155+
itemController.getPluginJarInfo().setIsFavorite(isFavorite);
156+
PluginManager.getInstance().saveToFileQuietly();
157+
loadPlugins();
158+
}
159+
160+
/**
161+
* 加载/刷新插件列表
162+
*/
163+
private void loadPlugins() {
164+
this.pluginCategories.getChildren().clear();
165+
this.pluginItemControllers.clear();
166+
this.categoryControllers.clear();
167+
168+
PluginManager pluginManager = PluginManager.getInstance();
169+
pluginManager.loadLocalPlugins();
170+
pluginManager.getEnabledPluginList().forEach(this::loadPlugin);
171+
}
172+
173+
/**
174+
* 加载单个插件到界面,要求插件已经经过 {@link PluginParser#parse(File, PluginJarInfo)} 解析
175+
*
176+
* @param jarInfo 插件信息
177+
*/
178+
private void loadPlugin(PluginJarInfo jarInfo) {
179+
if (!jarInfo.getFile().exists()) {
180+
log.info("跳过插件 {}: 文件不存在", jarInfo.getName());
181+
return;
182+
}
183+
if (BooleanUtils.isFalse(jarInfo.getIsEnable())) {
184+
log.info("跳过插件 {}: 插件未启用", jarInfo.getName());
185+
return;
186+
}
187+
String menuParentTitle = jarInfo.getMenuParentTitle();
188+
if (menuParentTitle == null) {
189+
log.info("跳过插件 {}: menuParentTitle 为空", jarInfo.getName());
190+
return;
191+
}
192+
String categoryName = jarInfo.getIsFavorite() ? FAVORITE_CATEGORY_NAME : XJavaFxToolApplication.RESOURCE_BUNDLE.getString(menuParentTitle);
193+
PluginCategoryController category = categoryControllers.computeIfAbsent(
194+
categoryName, __ -> {
195+
PluginCategoryController _category = PluginCategoryController.newInstance(categoryName);
196+
addCategory(_category);
197+
return _category;
198+
}
199+
);
200+
201+
PluginItemController item = PluginItemController.newInstance(jarInfo);
202+
item.setContextMenu(itemContextMenu);
203+
category.addItem(item);
204+
205+
if (!pluginItemControllers.contains(item)) {
206+
pluginItemControllers.add(item);
207+
}
208+
}
209+
210+
private void addCategory(PluginCategoryController category) {
211+
if (category.lblCategoryName.getText().equals(FAVORITE_CATEGORY_NAME)) {
212+
this.pluginCategories.getChildren().add(0, category.root);
213+
} else {
214+
this.pluginCategories.getChildren().add(category.root);
215+
}
125216
}
126217

127218
public void addToolMenu(File file) throws Exception {
@@ -230,11 +321,15 @@ private void addMenu(List<ToolFxmlLoaderConfiguration> toolList) {
230321
}
231322

232323
public void selectAction(String selectText) {
233-
if (contextMenu.isShowing()) {
234-
contextMenu.hide();
235-
}
236-
contextMenu = indexService.getSelectContextMenu(selectText);
237-
contextMenu.show(myTextField, null, 0, myTextField.getHeight());
324+
// if (contextMenu.isShowing()) {
325+
// contextMenu.hide();
326+
// }
327+
// contextMenu = indexService.getSelectContextMenu(selectText);
328+
// contextMenu.show(myTextField, null, 0, myTextField.getHeight());
329+
boolean notSearching = StringUtils.isBlank(selectText);
330+
pluginItemControllers.forEach(itemController -> {
331+
itemController.setVisible(notSearching || itemController.matchKeyword(selectText));
332+
});
238333
}
239334

240335
@FXML

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ public class NewLauncherController {
5151
private final Map<String, PluginCategoryController> categoryControllers = new HashMap<>();
5252

5353
public void initialize() {
54-
NewLauncherService.getInstance().setController(this);
54+
NewLauncherService.getInstance().setTabPane(tabPane);
5555
txtSearch.textProperty().addListener(this::onSearchKeywordChanged);
5656

5757
initContextMenu();

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

Lines changed: 3 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -18,10 +18,9 @@
1818
@Slf4j
1919
@Data
2020
public class NewLauncherService {
21-
2221
private static final NewLauncherService instance = new NewLauncherService();
2322

24-
private NewLauncherController newLauncherController;
23+
private TabPane tabPane;
2524

2625
private Map<Tab, PluginJarInfo> jarInfoMap = new HashMap<>();
2726

@@ -35,14 +34,11 @@ private NewLauncherService() {
3534

3635
}
3736

38-
public void setController(NewLauncherController newLauncherController) {
39-
this.newLauncherController = newLauncherController;
37+
public void setTabPane(TabPane tabPane) {
38+
this.tabPane = tabPane;
4039
}
4140

4241
public void loadPlugin(PluginJarInfo pluginJarInfo) {
43-
44-
TabPane tabPane = this.newLauncherController.getTabPane();
45-
4642
for (Entry<Tab, PluginJarInfo> entry : jarInfoMap.entrySet()) {
4743
if (entry.getValue() == pluginJarInfo) {
4844
tabPane.getSelectionModel().select(entry.getKey());
@@ -67,6 +63,4 @@ public void loadPlugin(PluginJarInfo pluginJarInfo) {
6763
jarInfoMap.put(tab, pluginJarInfo);
6864
}
6965
}
70-
71-
7266
}

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

Lines changed: 1 addition & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -17,18 +17,14 @@
1717

1818
@Slf4j
1919
public class PluginItemController {
20-
2120
public static final String FXML_PATH = "/com/xwintop/xJavaFxTool/fxmlView/newui/plugin-item.fxml";
22-
2321
public static PluginItemController newInstance(PluginJarInfo pluginJarInfo) {
2422
FXMLLoader fxmlLoader = FxmlHelper.loadFromResource(FXML_PATH);
2523
PluginItemController controller = fxmlLoader.getController();
2624
controller.setPluginInfo(pluginJarInfo);
2725
return controller;
2826
}
2927

30-
///////////////////////////////////////////////////////////////
31-
3228
private PluginJarInfo pluginJarInfo;
3329

3430
private ContextMenu contextMenu;
@@ -42,7 +38,6 @@ public static PluginItemController newInstance(PluginJarInfo pluginJarInfo) {
4238
public void initialize() {
4339
// 当元素不可见时也从布局流中去掉
4440
this.root.managedProperty().bind(this.root.visibleProperty());
45-
4641
this.root.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
4742
if (event.getButton() == MouseButton.PRIMARY) {
4843
onMouseLeftClicked(event);
@@ -64,12 +59,7 @@ private void onMouseLeftClicked(MouseEvent event) {
6459
}
6560

6661
private void updateIcon() {
67-
URL iconUrl = ResourceUtils.getResource(
68-
this.pluginJarInfo.getIconPath(),
69-
this.pluginJarInfo.getDefaultIconPath(),
70-
"/logo/plugin.png"
71-
);
72-
62+
URL iconUrl = ResourceUtils.getResource(this.pluginJarInfo.getIconPath(), this.pluginJarInfo.getDefaultIconPath(), "/logo/plugin.png");
7363
if (iconUrl != null) {
7464
String url = iconUrl.toExternalForm();
7565
if (url.endsWith("plugin.png")) {

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

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -101,13 +101,11 @@ public void addLogConsoleAction(ActionEvent event) {
101101
* 添加Content内容
102102
*/
103103
public void addContent(String title, String fxmlPath, String resourceBundleName, String iconPath) {
104-
105104
PluginJarInfo pluginJarInfo = PluginManager.getInstance().getPluginByFxmlPath(fxmlPath);
106105
if (pluginJarInfo == null) {
107106
FxAlerts.error("打开失败", "没有找到指定的插件");
108107
return;
109108
}
110-
111109
if (indexController.getSingleWindowBootCheckMenuItem().isSelected()) {
112110
PluginLoader.loadPluginAsWindow(pluginJarInfo);
113111
} else {

src/main/java/com/xwintop/xJavaFxTool/view/IndexView.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
package com.xwintop.xJavaFxTool.view;
22

33
import java.util.ResourceBundle;
4+
5+
import com.jfoenix.controls.JFXTextField;
46
import javafx.fxml.FXML;
57
import javafx.fxml.Initializable;
68
import javafx.scene.control.*;
@@ -16,9 +18,7 @@ public abstract class IndexView implements Initializable {
1618
protected ResourceBundle bundle;
1719

1820
@FXML
19-
protected Button myButton;
20-
21-
@FXML
21+
// protected JFXTextField myTextField;
2222
protected TextField myTextField;
2323

2424
@FXML

src/main/resources/com/xwintop/xJavaFxTool/fxmlView/Index.fxml

Lines changed: 10 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
<?xml version="1.0" encoding="UTF-8"?>
22

33
<?import javafx.geometry.Insets?>
4-
<?import javafx.scene.control.Button?>
54
<?import javafx.scene.control.CheckMenuItem?>
65
<?import javafx.scene.control.Hyperlink?>
6+
<?import javafx.scene.control.Label?>
77
<?import javafx.scene.control.Menu?>
88
<?import javafx.scene.control.MenuBar?>
99
<?import javafx.scene.control.MenuItem?>
@@ -17,13 +17,13 @@
1717
<?import javafx.scene.layout.VBox?>
1818
<?import javafx.scene.web.WebView?>
1919

20-
<AnchorPane prefHeight="654.0" prefWidth="1044.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.xwintop.xJavaFxTool.controller.IndexController">
20+
<AnchorPane prefHeight="654.0" prefWidth="1044.0" stylesheets="/com/xwintop/xJavaFxTool/fxmlView/newui/main.css" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.xwintop.xJavaFxTool.controller.IndexController">
2121
<children>
2222
<TabPane fx:id="tabPaneMain" tabClosingPolicy="ALL_TABS" tabMinWidth="45.0" AnchorPane.bottomAnchor="0.0" AnchorPane.leftAnchor="0.0" AnchorPane.rightAnchor="0.0" AnchorPane.topAnchor="0.0">
2323
<tabs>
2424
<Tab closable="false" text="%start">
2525
<content>
26-
<ScrollPane>
26+
<ScrollPane fitToWidth="true" style="-fx-border-width: 0 1 1 1;-fx-border-color: #CCCCCC;-fx-background:#2a2a2a">
2727
<content>
2828
<VBox>
2929
<children>
@@ -65,24 +65,19 @@
6565
</Menu>
6666
</menus>
6767
</MenuBar>
68-
<TextField fx:id="myTextField" focusTraversable="false" promptText="%selectTextField">
69-
<HBox.margin>
70-
<Insets left="10.0" right="10.0" />
71-
</HBox.margin>
72-
</TextField>
73-
<Button fx:id="myButton" mnemonicParsing="false" text="%selectButton">
74-
<HBox.margin>
75-
<Insets />
76-
</HBox.margin>
77-
</Button>
68+
<Label text="%search">
69+
<padding>
70+
<Insets left="10.0" />
71+
</padding></Label>
72+
<TextField fx:id="myTextField" promptText="%selectTextField" styleClass="search-text" />
7873
<WebView fx:id="tongjiWebView" prefHeight="1.0" prefWidth="1.0" visible="false" />
79-
<Hyperlink onAction="#xwintopLinkOnAction" text="http://gitee.com/xwintop/xJavaFxTool" textFill="RED" />
74+
<Hyperlink onAction="#xwintopLinkOnAction" text="http://gitee.com/xwintop/xJavaFxTool" textFill="#868686" />
8075
</children>
8176
<VBox.margin>
8277
<Insets top="5.0" />
8378
</VBox.margin>
8479
</HBox>
85-
<VBox fx:id="pluginCategories" alignment="TOP_CENTER"/>
80+
<VBox fx:id="pluginCategories" alignment="TOP_CENTER" />
8681
</children>
8782
</VBox>
8883
</content>

0 commit comments

Comments
 (0)