• 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 javax.swing.filechooser.FileNameExtensionFilter;
21 import java.awt.event.ActionEvent;
22 import java.awt.event.ActionListener;
23 
24 /**
25  * 编译文件夹选择框
26  *
27  * @author: xudong
28  * @see: select generator file path
29  * @version: v1.0.0
30  * @since 2022-02-21
31  */
32 public class SelectHAction implements ActionListener {
33     private final JButton button;
34     private final JTextField textField;
35 
SelectHAction(JButton button, JTextField textField)36     public SelectHAction(JButton button, JTextField textField) {
37         this.button = button;
38         this.textField = textField;
39     }
40 
41     @Override
actionPerformed(ActionEvent actionEvent)42     public void actionPerformed(ActionEvent actionEvent) {
43         if (actionEvent.getSource().equals(button)) {
44             JFileChooser fcDlg = new JFileChooser(textField.getText());
45             fcDlg.setDialogTitle("请选择.h文件路径...");
46             fcDlg.setFileSelectionMode(JFileChooser.FILES_ONLY);
47             FileNameExtensionFilter filter = new FileNameExtensionFilter("文本文件(*.h)", "h");
48             fcDlg.setMultiSelectionEnabled(true);
49             fcDlg.setFileFilter(filter);
50             int returnVal = fcDlg.showOpenDialog(null);
51             if (returnVal == JFileChooser.APPROVE_OPTION) {
52                 String filepath = fcDlg.getSelectedFile().getPath();
53                 textField.setText(filepath);
54             }
55         }
56     }
57 }
58