33import com .xwintop .xJavaFxTool .services .littleTools .FileRenameToolService ;
44import com .xwintop .xJavaFxTool .utils .JavaFxViewUtil ;
55import com .xwintop .xJavaFxTool .view .littleTools .FileRenameToolView ;
6- import com .xwintop .xcore .util .javafx .AlertUtil ;
76import com .xwintop .xcore .util .javafx .FileChooserUtil ;
7+ import com .xwintop .xcore .util .javafx .TooltipUtil ;
88import javafx .collections .FXCollections ;
99import javafx .collections .ObservableList ;
1010import javafx .event .ActionEvent ;
1919import java .util .HashMap ;
2020import java .util .Map ;
2121import java .util .ResourceBundle ;
22+
2223/**
2324 * @ClassName: FileRenameToolController
2425 * @Description: 文件重命名工具
@@ -36,14 +37,13 @@ public class FileRenameToolController extends FileRenameToolView {
3637
3738 @ Override
3839 public void initialize (URL location , ResourceBundle resources ) {
39- AlertUtil .showInfoAlert ("该工具未完善,谢谢!!!" );
4040 initView ();
4141 initEvent ();
4242 initService ();
4343 }
4444
4545 private void initView () {
46- JavaFxViewUtil .setTableColumnMapValueFactory (orderTableColumn , "order" ,false );
46+ JavaFxViewUtil .setTableColumnMapValueFactory (orderTableColumn , "order" , false );
4747 JavaFxViewUtil .setTableColumnMapValueFactory (ruleTableColumn , "rule" );
4848 JavaFxViewUtil .setTableColumnMapValueFactory (explainTableColumn , "explain" );
4949 ruleTableView .setItems (ruleTableData );
@@ -53,6 +53,8 @@ private void initView() {
5353 JavaFxViewUtil .setTableColumnMapValueFactory (errorInfoTableColumn , "errorInfo" );
5454 JavaFxViewUtil .setTableColumnMapValueFactory (filesPathTableColumn , "filesPath" );
5555 fileInfoTableView .setItems (fileInfoTableData );
56+
57+ JavaFxViewUtil .setSpinnerValueFactory (startNumberOfRenameTab , 0 , Integer .MAX_VALUE , 0 );
5658 }
5759
5860 private void initEvent () {
@@ -67,11 +69,11 @@ private void addFileAction(ActionEvent event) {
6769 File file = FileChooserUtil .chooseFile ();
6870 if (file != null ) {
6971 Map <String , String > dataRow = new HashMap <String , String >();
70- dataRow .put ("status" ,"true" );
71- dataRow .put ("fileName" ,file .getName ());
72- dataRow .put ("newFileName" ,"" );
73- dataRow .put ("errorInfo" ,"" );
74- dataRow .put ("filesPath" ,file .getPath ());
72+ dataRow .put ("status" , "true" );
73+ dataRow .put ("fileName" , file .getName ());
74+ dataRow .put ("newFileName" , "" );
75+ dataRow .put ("errorInfo" , "" );
76+ dataRow .put ("filesPath" , file .getPath ());
7577 fileInfoTableData .add (dataRow );
7678 }
7779 }
@@ -82,11 +84,11 @@ private void addFolderAction(ActionEvent event) {
8284 if (folderFile != null ) {
8385 for (File file : FileUtils .listFiles (folderFile , null , false )) {
8486 Map <String , String > dataRow = new HashMap <String , String >();
85- dataRow .put ("status" ,"true" );
86- dataRow .put ("fileName" ,file .getName ());
87- dataRow .put ("newFileName" ,"" );
88- dataRow .put ("errorInfo" ,"" );
89- dataRow .put ("filesPath" ,file .getPath ());
87+ dataRow .put ("status" , "true" );
88+ dataRow .put ("fileName" , file .getName ());
89+ dataRow .put ("newFileName" , "" );
90+ dataRow .put ("errorInfo" , "" );
91+ dataRow .put ("filesPath" , file .getPath ());
9092 fileInfoTableData .add (dataRow );
9193 }
9294 }
@@ -98,14 +100,25 @@ private void previewAction(ActionEvent event) {
98100
99101 @ FXML
100102 private void renameAction (ActionEvent event ) {
103+ for (Map <String , String > fileInfoTableDatum : fileInfoTableData ) {
104+ if ("true" .equals (fileInfoTableDatum .get ("status" ))) {
105+ File file = new File (fileInfoTableDatum .get ("filesPath" ));
106+ File newFile = new File (file .getParent (), fileInfoTableDatum .get ("newFileName" ));
107+ file .renameTo (newFile );
108+ fileInfoTableDatum .put ("fileName" , newFile .getName ());
109+ fileInfoTableDatum .put ("filesPath" , newFile .getPath ());
110+ }
111+ }
112+ fileInfoTableView .refresh ();
113+ TooltipUtil .showToast ("重命名成功!" );
101114 }
102115
103116 @ FXML
104117 private void addRoleTableAction (ActionEvent event ) {
105118 Map <String , String > dataRow = new HashMap <String , String >();
106- dataRow .put ("order" ,"true" );
107- dataRow .put ("rule" ,"true" );
108- dataRow .put ("explain" ,"true" );
119+ dataRow .put ("order" , "true" );
120+ dataRow .put ("rule" , "true" );
121+ dataRow .put ("explain" , "true" );
109122 ruleTableData .add (dataRow );
110123 }
111124
@@ -121,4 +134,33 @@ private void upRuleTableAction(ActionEvent event) {
121134 @ FXML
122135 private void downRuleTableAction (ActionEvent event ) {
123136 }
137+
138+ public void generateRenameDestFilesOfFormat () {
139+ if (!fileInfoTableData .isEmpty ()) {
140+ int startNumber = startNumberOfRenameTab .getValue ();
141+ String filePrefixString = filePrefixTextField .getText ().trim ();
142+ String filePostfixString = filePostfixTextField .getText ().trim ();
143+ for (Map <String , String > fileInfoTableDatum : fileInfoTableData ) {
144+ String fileName = fileInfoTableDatum .get ("fileName" );
145+ fileInfoTableDatum .put ("newFileName" , filePrefixString + fileName + (startNumber ++) + filePostfixString );
146+ }
147+ fileInfoTableView .refresh ();
148+ }
149+ }
150+
151+ public void generateRenameDestFilesOfReplace () {
152+ for (Map <String , String > fileInfoTableDatum : fileInfoTableData ) {
153+ String fileName = fileInfoTableDatum .get ("fileName" );
154+ fileInfoTableDatum .put ("newFileName" , fileName .replaceAll (fileQueryStringOfRenameTab .getText ().trim (), fileReplaceStringOfRenameTab .getText ().trim ()));
155+ }
156+ fileInfoTableView .refresh ();
157+ }
158+
159+ public void generateRenameDestFilesOfAddable () {
160+ for (Map <String , String > fileInfoTableDatum : fileInfoTableData ) {
161+ String fileName = fileInfoTableDatum .get ("fileName" );
162+ fileInfoTableDatum .put ("newFileName" , filePrefixAddableText .getText ().trim () + fileName + filePostfixAddableText .getText ().trim ());
163+ }
164+ fileInfoTableView .refresh ();
165+ }
124166}
0 commit comments