Skip to content

Commit cb34cea

Browse files
committed
1、优化文件图标处理;2、添加文件大小搜索条件
1 parent 2480b5f commit cb34cea

3 files changed

Lines changed: 51 additions & 4 deletions

File tree

src/main/java/com/xwintop/xJavaFxTool/controller/littleTools/FileSearchToolController.java

Lines changed: 16 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -62,6 +62,8 @@ public void initialize(URL location, ResourceBundle resources) {
6262
}
6363

6464
private void initView() {
65+
JavaFxViewUtil.setSpinnerValueFactory(fileSizeFromSpinner, 0, Integer.MAX_VALUE, 0);
66+
JavaFxViewUtil.setSpinnerValueFactory(fileSizeToSpinner, 0, Integer.MAX_VALUE, 0);
6567
JavaFxViewUtil.setTableColumnMapValueFactory(fileNameTableColumn, "fileName", false);
6668
fileNameTableColumn.setCellFactory(new Callback<TableColumn<Map<String, String>, String>, TableCell<Map<String, String>, String>>() {
6769
@Override
@@ -84,8 +86,16 @@ protected void updateItem(String item, boolean empty) {
8486
});
8587
return;
8688
}
87-
ImageIcon icon = (ImageIcon) FileSystemView.getFileSystemView().getSystemIcon(file);
88-
Image fxImage = SwingFXUtils.toFXImage((BufferedImage) icon.getImage(), null);
89+
// ImageIcon icon = (ImageIcon) FileSystemView.getFileSystemView().getSystemIcon(file);
90+
// Image fxImage = SwingFXUtils.toFXImage((BufferedImage) icon.getImage(), null);
91+
Icon icon = FileSystemView.getFileSystemView().getSystemIcon(file);
92+
BufferedImage bufferedImage = new BufferedImage(
93+
icon.getIconWidth(),
94+
icon.getIconHeight(),
95+
BufferedImage.TYPE_INT_ARGB
96+
);
97+
icon.paintIcon(null, bufferedImage.getGraphics(), 0, 0);
98+
Image fxImage = SwingFXUtils.toFXImage(bufferedImage, null);
8999
if (file.isHidden()) {
90100
this.setTextFill(Color.GREY);
91101
fxImage = ImgToolUtil.pixWithImage(8, fxImage);
@@ -119,6 +129,10 @@ private void initEvent() {
119129
FileChooserUtil.setOnDrag(searchDirectoryTextField, FileChooserUtil.FileType.FOLDER);
120130

121131
searchResultTableVIew.setOnMouseClicked(event -> {
132+
if (event.getClickCount() == 2) {
133+
String absolutePath = searchResultTableVIew.getSelectionModel().getSelectedItem().get("absolutePath");
134+
XJavaFxSystemUtil.openDirectory(absolutePath);
135+
}
122136
if (event.getButton() == MouseButton.SECONDARY) {
123137
MenuItem menuOpen = new MenuItem("打开");
124138
menuOpen.setOnAction(event1 -> {

src/main/java/com/xwintop/xJavaFxTool/view/littleTools/FileSearchToolView.java

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -35,6 +35,14 @@ public abstract class FileSearchToolView implements Initializable {
3535
@FXML
3636
protected ChoiceBox fileTypeChoiceBox;
3737
@FXML
38+
protected Spinner<Integer> fileSizeFromSpinner;
39+
@FXML
40+
protected ChoiceBox fileSizeFromChoiceBox;
41+
@FXML
42+
protected Spinner<Integer> fileSizeToSpinner;
43+
@FXML
44+
protected ChoiceBox fileSizeToChoiceBox;
45+
@FXML
3846
protected TextField searchDirectoryTextField;
3947
@FXML
4048
protected Button searchDirectoryButton;

src/main/resources/com/xwintop/xJavaFxTool/fxmlView/littleTools/FileSearchTool.fxml

Lines changed: 27 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
<?import javafx.scene.control.CheckBox?>
88
<?import javafx.scene.control.ChoiceBox?>
99
<?import javafx.scene.control.Label?>
10+
<?import javafx.scene.control.Spinner?>
1011
<?import javafx.scene.control.TableColumn?>
1112
<?import javafx.scene.control.TableView?>
1213
<?import javafx.scene.control.TextField?>
@@ -15,7 +16,7 @@
1516
<?import javafx.scene.layout.HBox?>
1617
<?import javafx.scene.layout.VBox?>
1718

18-
<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">
19+
<AnchorPane prefHeight="630.0" prefWidth="935.0" xmlns="http://javafx.com/javafx/8.0.171" xmlns:fx="http://javafx.com/fxml/1" fx:controller="com.xwintop.xJavaFxTool.controller.littleTools.FileSearchToolController">
1920
<children>
2021
<BorderPane AnchorPane.bottomAnchor="10.0" AnchorPane.leftAnchor="10.0" AnchorPane.rightAnchor="10.0" AnchorPane.topAnchor="10.0">
2122
<top>
@@ -24,7 +25,7 @@
2425
<HBox alignment="CENTER_LEFT" spacing="5.0">
2526
<children>
2627
<TextField fx:id="searchContentTextField" onKeyReleased="#searchContentAction" promptText="请输入搜索内容" HBox.hgrow="ALWAYS" />
27-
<CheckBox fx:id="autoRefreshIndexCheckBox" mnemonicParsing="false" selected="false" onAction="#autoRefreshIndexAction" text="自动刷新索引" />
28+
<CheckBox fx:id="autoRefreshIndexCheckBox" mnemonicParsing="false" onAction="#autoRefreshIndexAction" selected="false" text="自动刷新索引" />
2829
<Button fx:id="refreshIndexButton" mnemonicParsing="false" onAction="#refreshIndexAction" text="刷新索引" />
2930
</children>
3031
</HBox>
@@ -51,6 +52,30 @@
5152
</FXCollections>
5253
</items>
5354
</ChoiceBox>
55+
<Label text="大小" />
56+
<Spinner fx:id="fileSizeFromSpinner" prefWidth="80.0" />
57+
<ChoiceBox fx:id="fileSizeFromChoiceBox" onAction="#searchContentAction" value="MB">
58+
<items>
59+
<FXCollections fx:factory="observableArrayList">
60+
<String fx:value="Bytes" />
61+
<String fx:value="KB" />
62+
<String fx:value="MB" />
63+
<String fx:value="GB" />
64+
</FXCollections>
65+
</items>
66+
</ChoiceBox>
67+
<Label text="" />
68+
<Spinner fx:id="fileSizeToSpinner" prefWidth="80.0" />
69+
<ChoiceBox fx:id="fileSizeToChoiceBox" onAction="#searchContentAction" value="MB">
70+
<items>
71+
<FXCollections fx:factory="observableArrayList">
72+
<String fx:value="Bytes" />
73+
<String fx:value="KB" />
74+
<String fx:value="MB" />
75+
<String fx:value="GB" />
76+
</FXCollections>
77+
</items>
78+
</ChoiceBox>
5479
<TextField fx:id="searchDirectoryTextField" onKeyReleased="#searchContentAction" promptText="搜索文件夹" HBox.hgrow="ALWAYS" />
5580
<Button fx:id="searchDirectoryButton" mnemonicParsing="false" onAction="#searchDirectoryAction" text="浏览" />
5681
</children>

0 commit comments

Comments
 (0)