Skip to content

Commit a86e37f

Browse files
committed
newui: 实现搜索
1 parent 9a06fe7 commit a86e37f

3 files changed

Lines changed: 43 additions & 13 deletions

File tree

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

Lines changed: 33 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -9,16 +9,20 @@
99
import com.xwintop.xcore.javafx.dialog.FxAlerts;
1010
import com.xwintop.xcore.util.javafx.JavaFxViewUtil;
1111
import java.io.IOException;
12+
import java.util.ArrayList;
1213
import java.util.HashMap;
1314
import java.util.List;
1415
import java.util.Map;
1516
import java.util.ResourceBundle;
17+
import javafx.beans.Observable;
1618
import javafx.fxml.FXMLLoader;
1719
import javafx.scene.Parent;
1820
import javafx.scene.control.TabPane;
21+
import javafx.scene.control.TextField;
1922
import javafx.scene.layout.VBox;
2023
import javafx.scene.web.WebView;
2124
import lombok.extern.slf4j.Slf4j;
25+
import org.apache.commons.lang3.StringUtils;
2226

2327
@Slf4j
2428
public class NewLauncherController {
@@ -29,26 +33,25 @@ public class NewLauncherController {
2933

3034
public TabPane tabPane;
3135

32-
public void openConfigDialog() {
33-
SystemSettingService.openSystemSettings("设置");
34-
}
36+
public TextField txtSearch;
3537

36-
public void openPluginManager() {
37-
try {
38-
FXMLLoader fXMLLoader = PluginManageController.getFXMLLoader();
39-
Parent root = fXMLLoader.load();
40-
JavaFxViewUtil.openNewWindow(Main.RESOURCE_BUNDLE.getString("plugin_manage"), root);
41-
} catch (IOException e) {
42-
FxAlerts.error("打开插件管理对话框失败", e);
43-
}
44-
}
38+
// 实现搜索用
39+
private List<PluginItemController> pluginItemControllers = new ArrayList<>();
4540

4641
public void initialize() {
4742
NewLauncherService.getInstance().setController(this);
43+
txtSearch.textProperty().addListener(this::onSearchKeywordChanged);
4844
loadPlugins(); // 加载插件列表到界面上
4945
startWebView.getEngine().load(IndexController.QQ_URL); // 额外再打开一个反馈页面,可关闭
5046
}
5147

48+
public void onSearchKeywordChanged(Observable ob, String _old, String keyword) {
49+
boolean notSearching = StringUtils.isBlank(keyword);
50+
pluginItemControllers.forEach(itemController -> {
51+
itemController.setVisible(notSearching || itemController.matchKeyword(keyword));
52+
});
53+
}
54+
5255
private void loadPlugins() {
5356
List<PluginJarInfo> pluginList = PluginManager.getInstance().getPluginList();
5457
ResourceBundle menuResourceBundle = Main.RESOURCE_BUNDLE;
@@ -70,6 +73,10 @@ private void loadPlugins() {
7073

7174
PluginItemController item = PluginItemController.newInstance(jarInfo);
7275
category.addItem(item);
76+
77+
if (!pluginItemControllers.contains(item)) {
78+
pluginItemControllers.add(item);
79+
}
7380
}
7481
}
7582
}
@@ -81,4 +88,18 @@ private void addCategory(PluginCategoryController category) {
8188
public TabPane getTabPane() {
8289
return tabPane;
8390
}
91+
92+
public void openConfigDialog() {
93+
SystemSettingService.openSystemSettings("设置");
94+
}
95+
96+
public void openPluginManager() {
97+
try {
98+
FXMLLoader fXMLLoader = PluginManageController.getFXMLLoader();
99+
Parent root = fXMLLoader.load();
100+
JavaFxViewUtil.openNewWindow(Main.RESOURCE_BUNDLE.getString("plugin_manage"), root);
101+
} catch (IOException e) {
102+
FxAlerts.error("打开插件管理对话框失败", e);
103+
}
104+
}
84105
}

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

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ public static PluginItemController newInstance(PluginJarInfo pluginJarInfo) {
3838
public void initialize() {
3939
// 当元素不可见时也从布局流中去掉
4040
this.root.managedProperty().bind(this.root.visibleProperty());
41+
4142
this.root.addEventHandler(MouseEvent.MOUSE_CLICKED, event -> {
4243
if (event.getButton() == MouseButton.PRIMARY) {
4344
onMouseLeftClicked(event);
@@ -76,4 +77,12 @@ private void setPluginInfo(PluginJarInfo pluginJarInfo) {
7677
this.pluginName.setText(pluginJarInfo.getName());
7778
updateIcon();
7879
}
80+
81+
public boolean matchKeyword(String keyword) {
82+
return this.pluginJarInfo.getName().toLowerCase().contains(keyword.toLowerCase());
83+
}
84+
85+
public void setVisible(boolean visible) {
86+
this.root.setVisible(visible);
87+
}
7988
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,7 @@
2929
</padding>
3030
<HBox alignment="BASELINE_LEFT" style="-fx-padding: 10">
3131
<Label text="搜索:"/>
32-
<TextField prefWidth="200" styleClass="search-text"/>
32+
<TextField prefWidth="200" styleClass="search-text" fx:id="txtSearch"/>
3333
<Pane HBox.hgrow="ALWAYS"/>
3434
<Hyperlink onAction="#openConfigDialog" text="设置"/>
3535
<Hyperlink onAction="#openPluginManager" text="插件管理"/>

0 commit comments

Comments
 (0)