Skip to content

Commit 6ecd371

Browse files
committed
添加文件搜索工具。
1 parent 7c48603 commit 6ecd371

9 files changed

Lines changed: 263 additions & 3 deletions

File tree

README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -141,6 +141,8 @@ Mac OS X x64 [xJavaFxTool-0.1.7-macosx-x64.pkg](https://dev.tencent.com/s/bb44f6
141141

142142
49、ClipboardHistoryTool:剪贴板历史工具;
143143

144+
50、FileSearchTool:文件搜索工具;
145+
144146
传输工具目前支持功能如下:
145147

146148
Receiver接收器:

pom.xml

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -248,6 +248,12 @@
248248
<version>9.1.1.0</version>
249249
</dependency>
250250

251+
<dependency>
252+
<groupId>org.apache.lucene</groupId>
253+
<artifactId>lucene-core</artifactId>
254+
<version>7.1.0</version>
255+
</dependency>
256+
251257
</dependencies>
252258
<build>
253259
<plugins>
Lines changed: 71 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,71 @@
1+
package com.xwintop.xJavaFxTool.controller.littleTools;
2+
3+
import com.xwintop.xJavaFxTool.services.littleTools.FileSearchToolService;
4+
import com.xwintop.xJavaFxTool.utils.JavaFxViewUtil;
5+
import com.xwintop.xJavaFxTool.view.littleTools.FileSearchToolView;
6+
import com.xwintop.xcore.util.javafx.FileChooserUtil;
7+
import javafx.collections.FXCollections;
8+
import javafx.collections.ObservableList;
9+
import javafx.event.ActionEvent;
10+
import javafx.fxml.FXML;
11+
import lombok.Getter;
12+
import lombok.Setter;
13+
import lombok.extern.slf4j.Slf4j;
14+
15+
import java.io.File;
16+
import java.net.URL;
17+
import java.util.Map;
18+
import java.util.ResourceBundle;
19+
20+
/**
21+
* @ClassName: FileSearchToolController
22+
* @Description: 文件搜索工具
23+
* @author: xufeng
24+
* @date: 2019/7/18 10:21
25+
*/
26+
27+
@Getter
28+
@Setter
29+
@Slf4j
30+
public class FileSearchToolController extends FileSearchToolView {
31+
private FileSearchToolService fileSearchToolService = new FileSearchToolService(this);
32+
private ObservableList<Map<String, String>> searchResultTableData = FXCollections.observableArrayList();
33+
34+
@Override
35+
public void initialize(URL location, ResourceBundle resources) {
36+
initView();
37+
initEvent();
38+
initService();
39+
}
40+
41+
private void initView() {
42+
JavaFxViewUtil.setTableColumnMapValueFactory(fileNameTableColumn, "fileName", false);
43+
JavaFxViewUtil.setTableColumnMapValueFactory(absolutePathTableColumn, "absolutePath", false);
44+
JavaFxViewUtil.setTableColumnMapValueFactory(fileSizeTableColumn, "fileSize", false);
45+
JavaFxViewUtil.setTableColumnMapValueFactory(lastModifiedTableColumn, "lastModified", false);
46+
searchResultTableVIew.setItems(searchResultTableData);
47+
}
48+
49+
private void initEvent() {
50+
FileChooserUtil.setOnDrag(searchDirectoryTextField, FileChooserUtil.FileType.FOLDER);
51+
}
52+
53+
private void initService() {
54+
}
55+
56+
public void searchContentAction() {
57+
58+
}
59+
60+
@FXML
61+
private void refreshIndexAction(ActionEvent event) {
62+
}
63+
64+
@FXML
65+
private void searchDirectoryAction(ActionEvent event) {
66+
File file = FileChooserUtil.chooseDirectory();
67+
if (file != null) {
68+
searchDirectoryTextField.setText(file.getPath());
69+
}
70+
}
71+
}
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
package com.xwintop.xJavaFxTool.services.littleTools;
2+
3+
import com.xwintop.xJavaFxTool.controller.littleTools.FileSearchToolController;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
import lombok.extern.slf4j.Slf4j;
7+
import org.apache.lucene.document.*;
8+
9+
import java.io.File;
10+
import java.nio.file.DirectoryStream;
11+
import java.nio.file.Files;
12+
import java.nio.file.Path;
13+
import java.nio.file.Paths;
14+
import java.util.Iterator;
15+
16+
/**
17+
* @ClassName: FileSearchToolService
18+
* @Description: 文件搜索工具
19+
* @author: xufeng
20+
* @date: 2019/7/18 10:21
21+
*/
22+
23+
@Getter
24+
@Setter
25+
@Slf4j
26+
public class FileSearchToolService {
27+
private FileSearchToolController fileSearchToolController;
28+
29+
public FileSearchToolService(FileSearchToolController fileSearchToolController) {
30+
this.fileSearchToolController = fileSearchToolController;
31+
}
32+
33+
public void searchContentAction() {
34+
35+
}
36+
37+
private void refreshIndexAction() {
38+
39+
}
40+
41+
private void searchDirectoryAction() {
42+
43+
}
44+
45+
public void addSearchIndexFile(String path) throws Exception {
46+
DirectoryStream<Path> stream = Files.newDirectoryStream(Paths.get(path));
47+
Iterator<Path> pathIterator = stream.iterator();
48+
while (pathIterator.hasNext()) {
49+
Path curPath = pathIterator.next();
50+
// System.out.println(curPath.toString());
51+
if (Files.isDirectory(curPath)) {
52+
addSearchIndexFile(curPath.toString());
53+
} else {
54+
// System.out.println(curPath.toString());
55+
}
56+
}
57+
}
58+
59+
public void addIndexDocument(File file) throws Exception {
60+
Document doc = new Document();
61+
doc.add(new TextField("fileName", file.getName(), Field.Store.YES));
62+
doc.add(new TextField("absolutePath", file.getAbsolutePath(), Field.Store.YES));
63+
doc.add(new LongPoint("fileSize", file.length()));
64+
doc.add(new TextField("lastModified", DateTools.timeToString(file.lastModified(), DateTools.Resolution.MILLISECOND), Field.Store.YES));
65+
}
66+
}
Lines changed: 50 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,50 @@
1+
package com.xwintop.xJavaFxTool.view.littleTools;
2+
3+
import javafx.fxml.FXML;
4+
import javafx.fxml.Initializable;
5+
import javafx.scene.control.*;
6+
import lombok.Getter;
7+
import lombok.Setter;
8+
9+
import java.util.Map;
10+
11+
/**
12+
* @ClassName: FileSearchToolView
13+
* @Description: 文件搜索工具
14+
* @author: xufeng
15+
* @date: 2019/7/18 10:21
16+
*/
17+
18+
@Getter
19+
@Setter
20+
public abstract class FileSearchToolView implements Initializable {
21+
@FXML
22+
protected TextField searchContentTextField;
23+
@FXML
24+
protected CheckBox autoRefreshIndexCheckBox;
25+
@FXML
26+
protected Button refreshIndexButton;
27+
@FXML
28+
protected CheckBox regularCheckBox;
29+
@FXML
30+
protected CheckBox matchCaseCheckBox;
31+
@FXML
32+
protected CheckBox fullTextMatchingCheckBox;
33+
@FXML
34+
protected CheckBox showHideFileCheckBox;
35+
@FXML
36+
protected TextField searchDirectoryTextField;
37+
@FXML
38+
protected Button searchDirectoryButton;
39+
@FXML
40+
protected TableView<Map<String, String>> searchResultTableVIew;
41+
@FXML
42+
protected TableColumn<Map<String, String>, String> fileNameTableColumn;
43+
@FXML
44+
protected TableColumn<Map<String, String>, String> absolutePathTableColumn;
45+
@FXML
46+
protected TableColumn<Map<String, String>, String> fileSizeTableColumn;
47+
@FXML
48+
protected TableColumn<Map<String, String>, String> lastModifiedTableColumn;
49+
50+
}
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
3+
<?import javafx.geometry.Insets?>
4+
<?import javafx.scene.control.Button?>
5+
<?import javafx.scene.control.CheckBox?>
6+
<?import javafx.scene.control.TableColumn?>
7+
<?import javafx.scene.control.TableView?>
8+
<?import javafx.scene.control.TextField?>
9+
<?import javafx.scene.layout.AnchorPane?>
10+
<?import javafx.scene.layout.BorderPane?>
11+
<?import javafx.scene.layout.HBox?>
12+
<?import javafx.scene.layout.VBox?>
13+
14+
<AnchorPane prefHeight="400.0" prefWidth="600.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.xwintop.xJavaFxTool.controller.littleTools.FileSearchToolController">
15+
<children>
16+
<BorderPane AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0">
17+
<top>
18+
<VBox spacing="5.0" BorderPane.alignment="CENTER">
19+
<children>
20+
<HBox alignment="CENTER_LEFT" spacing="5.0">
21+
<children>
22+
<TextField fx:id="searchContentTextField" promptText="请输入搜索内容" onKeyReleased="#searchContentAction" HBox.hgrow="ALWAYS" />
23+
<CheckBox fx:id="autoRefreshIndexCheckBox" mnemonicParsing="false" selected="true" text="自动刷新索引" />
24+
<Button fx:id="refreshIndexButton" mnemonicParsing="false" onAction="#refreshIndexAction" text="刷新索引" />
25+
</children>
26+
</HBox>
27+
<HBox alignment="CENTER_LEFT" spacing="5.0">
28+
<children>
29+
<CheckBox fx:id="regularCheckBox" mnemonicParsing="false" text="正则表达式" />
30+
<CheckBox fx:id="matchCaseCheckBox" mnemonicParsing="false" text="区分大小写" />
31+
<CheckBox fx:id="fullTextMatchingCheckBox" mnemonicParsing="false" text="全字匹配" />
32+
<CheckBox fx:id="showHideFileCheckBox" mnemonicParsing="false" selected="true" text="隐藏文件" />
33+
<TextField fx:id="searchDirectoryTextField" promptText="搜索文件夹" HBox.hgrow="ALWAYS" />
34+
<Button fx:id="searchDirectoryButton" mnemonicParsing="false" onAction="#searchDirectoryAction" text="浏览" />
35+
</children>
36+
</HBox>
37+
</children>
38+
</VBox>
39+
</top>
40+
<center>
41+
<TableView fx:id="searchResultTableVIew" BorderPane.alignment="CENTER">
42+
<columns>
43+
<TableColumn fx:id="fileNameTableColumn" minWidth="60.0" prefWidth="120.0" text="名称" />
44+
<TableColumn fx:id="absolutePathTableColumn" minWidth="120.0" prefWidth="240.0" text="路径" />
45+
<TableColumn fx:id="fileSizeTableColumn" maxWidth="120.0" minWidth="40.0" prefWidth="60.0" text="大小" />
46+
<TableColumn fx:id="lastModifiedTableColumn" maxWidth="200.0" minWidth="60.0" prefWidth="120.0" text="修改时间" />
47+
</columns>
48+
<BorderPane.margin>
49+
<Insets top="10.0" />
50+
</BorderPane.margin>
51+
<columnResizePolicy>
52+
<TableView fx:constant="CONSTRAINED_RESIZE_POLICY" />
53+
</columnResizePolicy>
54+
</TableView>
55+
</center>
56+
</BorderPane>
57+
</children>
58+
</AnchorPane>

src/main/resources/config/toolFxmlLoaderConfiguration.xml

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,7 +284,12 @@
284284
<url>/com/xwintop/xJavaFxTool/fxmlView/developTools/ClipboardHistoryTool.fxml</url>
285285
<title>ClipboardHistoryTool</title>
286286
<menuParentId>developTools</menuParentId>
287-
<isDefaultShow></isDefaultShow>
287+
</ToolFxmlLoaderConfiguration>
288+
<ToolFxmlLoaderConfiguration>
289+
<url>/com/xwintop/xJavaFxTool/fxmlView/littleTools/FileSearchTool.fxml</url>
290+
<title>FileSearchTool</title>
291+
<menuParentId>littleTools</menuParentId>
292+
<isDefaultShow>true</isDefaultShow>
288293
</ToolFxmlLoaderConfiguration>
289294

290295
<ToolFxmlLoaderConfiguration url="/web/littleTools/cron/index.htm"

src/main/resources/locale/Menu.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,5 @@ ScanPortTool=\u7AEF\u53E3\u626B\u63CF\u5DE5\u5177
8787
FileMergeTool=\u6587\u4EF6\u5408\u5E76\u5DE5\u5177
8888
SedentaryReminderTool=\u4E45\u5750\u63D0\u9192\u5DE5\u5177
8989
RandomGeneratorTool=\u968F\u673A\u6570\u751F\u6210\u5DE5\u5177
90-
ClipboardHistoryTool=\u526A\u8D34\u677F\u5386\u53F2\u5DE5\u5177
90+
ClipboardHistoryTool=\u526A\u8D34\u677F\u5386\u53F2\u5DE5\u5177
91+
FileSearchTool=\u6587\u4EF6\u641C\u7D22\u5DE5\u5177

src/main/resources/locale/Menu_en_US.properties

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,5 @@ ScanPortTool=ScanPortTool
8787
FileMergeTool=FileMergeTool
8888
SedentaryReminderTool=SedentaryReminderTool
8989
RandomGeneratorTool=RandomGeneratorTool
90-
ClipboardHistoryTool=ClipboardHistoryTool
90+
ClipboardHistoryTool=ClipboardHistoryTool
91+
FileSearchTool=FileSearchTool

0 commit comments

Comments
 (0)