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.dialog; 16 17 import com.intellij.openapi.diagnostic.Logger; 18 19 import javax.swing.JButton; 20 import javax.swing.JDialog; 21 import javax.swing.JList; 22 import javax.swing.JPanel; 23 import java.io.File; 24 import java.util.ArrayList; 25 import java.util.List; 26 27 /** 28 * GenResultDialog结果生成框 29 * 30 * @author: xudong 31 * @see: generate success dialog 32 * @version: v1.0.0 33 * @since 2022-02-21 34 */ 35 public class GenResultDialog extends JDialog { 36 private static final Logger LOG = Logger.getInstance(GenResultDialog.class); 37 38 private JPanel contentPane; 39 private JButton buttonOK; 40 private JList resultList; 41 private String path; 42 GenResultDialog(String directoryPath)43 public GenResultDialog(String directoryPath) { 44 path = directoryPath; 45 } 46 47 /** 48 * 初始化 49 */ initResultDialog()50 public void initResultDialog() { 51 setContentPane(contentPane); 52 setModal(true); 53 getRootPane().setDefaultButton(buttonOK); 54 setTitle("执行成功"); 55 buttonOK.addActionListener(actionEvent -> onOK()); 56 List<String> fileList = getDirFileName(path); 57 resultList.setListData(fileList.toArray(new String[fileList.size()])); 58 } 59 onOK()60 private void onOK() { 61 dispose(); 62 } 63 getDirFileName(String path)64 private List<String> getDirFileName(String path) { 65 List<String> files = new ArrayList<>(); 66 File file = new File(path); 67 if (!file.exists()) { 68 LOG.info("getDirFileName f not exist"); 69 return files; 70 } 71 File[] fileArray = file.listFiles(); 72 for (int i = 0; i < fileArray.length; i++) { 73 File fs = fileArray[i]; 74 if (!fs.isDirectory()) { 75 files.add(fs.getPath()); 76 } else { 77 LOG.info("getDirFileName this file is dir"); 78 } 79 } 80 return files; 81 } 82 } 83