package com.taover.codegenerate.ui; import java.awt.BorderLayout; import java.awt.event.ActionEvent; import java.awt.event.ActionListener; import java.io.File; import java.io.FileInputStream; import java.io.FileNotFoundException; import java.io.IOException; import java.util.ArrayList; import java.util.List; import java.util.Properties; import javax.swing.JButton; import javax.swing.JCheckBox; import javax.swing.JComboBox; import javax.swing.JFileChooser; import javax.swing.JFrame; import javax.swing.JLabel; import javax.swing.JOptionPane; import javax.swing.JPanel; import javax.swing.JTextArea; import javax.swing.JTextField; import javax.swing.SwingConstants; public class EntityGenWindow extends JFrame{ private JTextField tf_outputDir; private JTextField tf_dbPackage; private JTextField tf_dbName; private JTextArea ta_tableList; private Properties prop; private boolean createAllTable; public EntityGenWindow(){ initComponents(); } /** * Initialize the contents of the frame. */ private void initComponents() { this.setBounds(100, 100, 746, 464); this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); JPanel panel = new JPanel(); this.getContentPane().add(panel, BorderLayout.CENTER); this.setTitle("生成实体文件"); panel.setLayout(null); JLabel lblNewLabel = new JLabel("表名列表"); lblNewLabel.setHorizontalAlignment(SwingConstants.LEFT); lblNewLabel.setVerticalAlignment(SwingConstants.TOP); lblNewLabel.setBounds(40, 66, 89, 15); panel.add(lblNewLabel); JLabel label = new JLabel("数据库配置文件"); label.setBounds(40, 29, 89, 15); panel.add(label); JComboBox comboBox = new JComboBox(); comboBox.setBounds(139, 26, 249, 21); this.initPropCombobox(comboBox); panel.add(comboBox); ta_tableList = new JTextArea(); ta_tableList.setTabSize(4); ta_tableList.setBounds(139, 62, 516, 157); panel.add(ta_tableList); JLabel label_1 = new JLabel("输出文件夹"); label_1.setBounds(40, 243, 89, 15); panel.add(label_1); tf_outputDir = new JTextField(); tf_outputDir.setBounds(139, 240, 413, 21); panel.add(tf_outputDir); tf_outputDir.setColumns(10); JLabel lblClass = new JLabel("CLASS包名"); lblClass.setBounds(40, 283, 89, 15); panel.add(lblClass); tf_dbPackage = new JTextField(); tf_dbPackage.setColumns(10); tf_dbPackage.setBounds(139, 280, 413, 21); panel.add(tf_dbPackage); JLabel lblClass1 = new JLabel("数据库名称"); lblClass1.setBounds(40, 320, 89, 15); panel.add(lblClass1); tf_dbName = new JTextField(); tf_dbName.setColumns(10); tf_dbName.setBounds(139, 320, 413, 21); panel.add(tf_dbName); JButton btnNewButton = new JButton("生成文件"); btnNewButton.addActionListener(e -> { List tableNameList = new ArrayList(); String tableNameStr = ta_tableList.getText(); String[] tableNameSplitBack = tableNameStr.split("\n"); for(int i=0; i { JFileChooser fileChooser = new JFileChooser(); fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY); fileChooser.setCurrentDirectory(new File(tf_outputDir.getText())); int status = fileChooser.showOpenDialog(EntityGenWindow.this); if (status == JFileChooser.APPROVE_OPTION) { File selectedFile = fileChooser.getSelectedFile(); tf_outputDir.setText(selectedFile.getPath()); } }); button.setBounds(562, 239, 93, 23); panel.add(button); JCheckBox chckbxNewCheckBox = new JCheckBox("所有表"); chckbxNewCheckBox.setBounds(408, 26, 82, 21); chckbxNewCheckBox.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { JCheckBox tempCheck = (JCheckBox)e.getSource(); if(tempCheck.isSelected()){ createAllTable = true; ta_tableList.setEnabled(false); }else{ createAllTable = false; ta_tableList.setEnabled(true); } } }); panel.add(chckbxNewCheckBox); } private void initPropCombobox(JComboBox comboBox){ String binDirPath = UiUtils.getProjectRoot(); File binDir = new File(binDirPath); File[] sonFileArr = binDir.listFiles(); for(int i=0; i