1+ package com .xwintop .xJavaFxTool .controller .littleTools ;
2+
3+ import com .xwintop .xJavaFxTool .services .littleTools .FileCompressToolService ;
4+ import com .xwintop .xJavaFxTool .view .littleTools .FileCompressToolView ;
5+ import com .xwintop .xcore .util .javafx .FileChooserUtil ;
6+ import javafx .event .ActionEvent ;
7+ import javafx .fxml .FXML ;
8+ import javafx .stage .FileChooser ;
9+ import lombok .Getter ;
10+ import lombok .Setter ;
11+ import lombok .extern .slf4j .Slf4j ;
12+
13+ import javax .swing .filechooser .FileSystemView ;
14+ import java .io .File ;
15+ import java .net .URL ;
16+ import java .util .ArrayList ;
17+ import java .util .List ;
18+ import java .util .ResourceBundle ;
19+
20+ import static org .apache .commons .compress .archivers .ArchiveStreamFactory .*;
21+ import static org .apache .commons .compress .compressors .CompressorStreamFactory .*;
22+
23+ /**
24+ * @ClassName: FileCompressToolController
25+ * @Description: 文件解压缩工具
26+ * @author: xufeng
27+ * @date: 2019/10/26 0026 19:17
28+ */
29+
30+ @ Getter
31+ @ Setter
32+ @ Slf4j
33+ public class FileCompressToolController extends FileCompressToolView {
34+ private FileCompressToolService fileCompressToolService = new FileCompressToolService (this );
35+ private String [] fileTypeChoiceBoxStrings = new String []{"AUTO" , AR , ZIP , TAR , JAR , CPIO , SEVEN_Z , GZIP , BZIP2 , XZ , LZMA , PACK200 , DEFLATE , SNAPPY_FRAMED , LZ4_BLOCK , LZ4_FRAMED , ZSTANDARD };
36+
37+ @ Override
38+ public void initialize (URL location , ResourceBundle resources ) {
39+ initView ();
40+ initEvent ();
41+ initService ();
42+ }
43+
44+ private void initView () {
45+ fileTypeChoiceBox .getItems ().addAll (fileTypeChoiceBoxStrings );
46+ fileTypeChoiceBox .getSelectionModel ().select (2 );
47+ }
48+
49+ private void initEvent () {
50+ FileChooserUtil .setOnDrag (selectFileTextField , FileChooserUtil .FileType .FOLDER );
51+ FileChooserUtil .setOnDrag (saveFilePathTextField , FileChooserUtil .FileType .FOLDER );
52+ }
53+
54+ private void initService () {
55+ }
56+
57+ @ FXML
58+ private void selectFileAction (ActionEvent event ) {
59+ List <File > files = null ;
60+ try {
61+ FileChooser fileChooser = new FileChooser ();
62+ fileChooser .setTitle ("请选择文件" );
63+ fileChooser .setInitialDirectory (FileSystemView .getFileSystemView ().getHomeDirectory ());
64+ files = fileChooser .showOpenMultipleDialog (null );
65+ } catch (NullPointerException e ) {
66+ log .error ("选择文件错误" , e );
67+ }
68+ if (files != null ) {
69+ List <String > strings = new ArrayList <>();
70+ for (File file : files ) {
71+ strings .add (file .getPath ());
72+ }
73+ selectFileTextField .setText (String .join ("|" , strings ));
74+ }
75+ }
76+
77+ @ FXML
78+ private void selectFolderAction (ActionEvent event ) {
79+ File file = FileChooserUtil .chooseDirectory ();
80+ if (file != null ) {
81+ selectFileTextField .setText (file .getPath ());
82+ }
83+ }
84+
85+ @ FXML
86+ private void saveFilePathAction (ActionEvent event ) {
87+ File file = FileChooserUtil .chooseDirectory ();
88+ if (file != null ) {
89+ saveFilePathTextField .setText (file .getPath ());
90+ }
91+ }
92+
93+ @ FXML
94+ private void compressAction (ActionEvent event ) {
95+ fileCompressToolService .compressAction ();
96+ }
97+
98+ }
0 commit comments