• Home
  • Line#
  • Scopes#
  • Navigate#
  • Raw
  • Download
1 /*
2  * Copyright (c) 2022 Shenzhen Kaihong Digital Industry Development Co., Ltd.
3  * Licensed under the Apache License, Version 2.0 (the "License");
4  * you may not use this file except in compliance with the License.
5  * You may obtain a copy of the License at
6  *
7  * http://www.apache.org/licenses/LICENSE-2.0
8  *
9  * Unless required by applicable law or agreed to in writing, software
10  * distributed under the License is distributed on an "AS IS" BASIS,
11  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12  * See the License for the specific language governing permissions and
13  * limitations under the License.
14  */
15 package com.sk.action;
16 
17 import javax.swing.JButton;
18 import javax.swing.JFileChooser;
19 import javax.swing.JTextField;
20 import java.awt.event.ActionEvent;
21 import java.awt.event.ActionListener;
22 
23 /**
24  * 编译文件夹选择框
25  *
26  * @author: xudong
27  * @see: select generator file path
28  * @version: v1.0.0
29  * @since 2022-02-21
30  */
31 public class SelectOutPathAction implements ActionListener {
32     private final JButton button;
33     private final JTextField textField;
34 
SelectOutPathAction(JButton button, JTextField textField)35     public SelectOutPathAction(JButton button, JTextField textField) {
36         this.button = button;
37         this.textField = textField;
38     }
39 
40     @Override
actionPerformed(ActionEvent actionEvent)41     public void actionPerformed(ActionEvent actionEvent) {
42         if (actionEvent.getSource().equals(button)) {
43             JFileChooser fcDlg = new JFileChooser(textField.getText());
44             fcDlg.setDialogTitle("请选择输出目录路径...");
45             fcDlg.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
46             int returnVal = fcDlg.showOpenDialog(null);
47             if (returnVal == JFileChooser.APPROVE_OPTION) {
48                 String filepath = fcDlg.getSelectedFile().getPath();
49                 textField.setText(filepath);
50             }
51         }
52     }
53 }
54