package org.eclipse.ve.model;
import javax.swing.*;
import java.awt.*;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStream;
import java.net.*;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.awt.event.*;
import javax.swing.border.*;
/**
* <p>
* Title: Model设置
* </p>
* <p>
* Description: 设置表名及其属性
* </p>
* <p>
* Copyright: Copyright (c) 2006
* </p>
* <p>
* Company: www.use.com
* </p>
*
* @author jiangyujie
* @version 1.0
*/
public class Auto extends JFrame implements ActionListener, ItemListener {
/**
*
*/
private static final long serialVersionUID = -4487298726165465177L;
static Color DarkColor = new Color(55, 77, 118); // 暗色
static Color LightColor = new Color(111, 146, 212); // 亮色
static Border unSelected = BorderFactory.createLineBorder(DarkColor, 1); // 未选中时的边框
static Border emptyBorder = BorderFactory.createEmptyBorder();// 选中之后的按钮边框
static Dimension faceSize = new Dimension(780, 500);
static Image icon, contentPanelBack, setupDialogBack, warningDialogBack;// 主程序图标,主界面背景,设置对话框和警告对话框背景
static ImageIcon imgSetup, imgRefresh, imgAbout, imgTomcat, imgPath, sure,
del, logo, exit, run, add, edit, addBack, delBack, exitBack,
runBack, sureBack, editBack;// 主界面按钮的图标
static JFileChooser jfchooser = new JFileChooser(); // 目录选择器
static JPanel toolBar; // 工具栏
static JPanel contentPanel; // 容器
static JPanel statusPanel; // 状态栏
static JTextPane actionPanel = new JTextPane(); // 代码显示栏
static JLabel jlName = new JLabel();// 对象名
static JLabel jlSeted = new JLabel();// 已选择的属性
static JLabel jlParent = new JLabel();// parent
static JLabel jlRun = new JLabel();// run
static Checkbox checkParent = new Checkbox();// parent选择框
static Checkbox checkInstall = new Checkbox();// run选择框
static List listParent = new List();// parent外键设置列表
static List listProperty = new List();// 已设置的参数
static TextField jtCode = new TextField();// code输入框
static JTextField companyField = new JTextField();// 状态栏文字
static JTextField timeField= new JTextField(9);// 时间信息
static SetupDialog setupDialog;// 设置对话框
static AboutDialog aboutDialog; // 关于对话框
static WarnDialog warnDialog;// 警告对话框
static JButton jbSure;// 确定
static JButton jbDel;// 删除
static JButton jbAdd;// 添加
static JButton jbEdit;// 添加
static JButton jbExit;// 退出
static JButton jbRun;// 运行
static JButton setupButton = new JButton(); // 设置
static JButton aboutButton = new JButton(); // 关于
static JButton pathButton = new JButton(); // 目录设置
static JButton tomcatButton = new JButton();// tomcat
static String parentModel = null;// parent选择的Model
static String fileName = null;// 生成文件名
static String path = new String(Constants.modelDir);// Model输出目录,默认为C:\\Model
static String pathProject = new String(Constants.modelDir);// 选定的工程目录,其下必须有build.xml文件才能运行ant
static int flagForeignKey = 0;// flagForeignKey为设置parent与否的标志
static int modelFlag = 0;// 在文件夹中查找model的标志键,用于测试是否有文件夹名为model
static ArrayList proList = new ArrayList();// 传递的参数列表
static ArrayList modelDireList = new ArrayList();// 传递可用的model文件夹列表
static ArrayList modelList = new ArrayList();// 设置了的model列表
final char ch = '\"';// 引号
final char nl = '\n';// 换行
// 构造函数
public Auto() {
initResource();
initUI();
this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
this.pack();
this.setSize(faceSize);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
this.setLocation((int) (screenSize.width - faceSize.getWidth()) / 2,
(int) (screenSize.height - faceSize.getHeight()) / 2);
this.setResizable(false);
this.setTitle("appfrm自动设置"); // 设置标题
this.setIconImage(icon); // 设置程序图标
setMouse(this);
}
/**
* 初始化系统所需要的资源
*/
public void initResource() {
// 程序图标
icon = getImage("images/about.gif");
contentPanelBack = getImage("images/back1.gif");
setupDialogBack = getImage("images/back3.gif");
warningDialogBack = getImage("images/back4.gif");
imgSetup = new ImageIcon(getImage("images/setup.jpg"));
imgAbout = new ImageIcon(getImage("images/about.jpg"));
imgTomcat = new ImageIcon(getImage("images/tomcat.jpg"));
imgPath = new ImageIcon(getImage("images/path.jpg"));
sure = new ImageIcon(getImage("images/sure.jpg"));
del = new ImageIcon(getImage("images/del.jpg"));
logo = new ImageIcon(getImage("images/logo.gif"));
exit = new ImageIcon(getImage("images/exit.jpg"));
run = new ImageIcon(getImage("images/run.jpg"));
add = new ImageIcon(getImage("images/add.jpg"));
edit = new ImageIcon(getImage("images/edit.jpg"));
addBack = new ImageIcon(getImage("images/addback.jpg"));
delBack = new ImageIcon(getImage("images/delback.jpg"));
runBack = new ImageIcon(getImage("images/runback.jpg"));
exitBack = new ImageIcon(getImage("images/exitback.jpg"));
sureBack = new ImageIcon(getImage("images/sureback.jpg"));
editBack = new ImageIcon(getImage("images/editback.jpg"));
// 初始化对话框
setupDialog = new SetupDialog(this);
aboutDialog = new AboutDialog(this);
warnDialog = new WarnDialog(this);
}
/**
* 初始化用户界面
*/
public void initUI() {
// 界面整体布局
Border border = BorderFactory.createBevelBorder(BevelBorder.LOWERED,
new Color(45, 92, 162), new Color(43, 66, 97), new Color(45,
92, 162), new Color(84, 123, 200));
BorderLayout borderLayout = new BorderLayout();
toolBar = new JPanel();
toolBar.setBackground(new Color(228, 226, 204));
toolBar.setBorder(border);
toolBar.setPreferredSize(new Dimension(780, 40));
toolBar.setMinimumSize(new Dimension(780, 40));
toolBar.setLayout(null);
actionPanel.setBackground(new Color(228, 226, 204));
actionPanel.setBorder(border);
actionPanel.setForeground(Color.red);
actionPanel.setFont(new java.awt.Font("宋体", java.awt.Font.PLAIN, 14));
actionPanel.setPreferredSize(new Dimension(260, 380));
actionPanel.setText("欢迎使用POJO自动设置程序");
actionPanel.setMinimumSize(new Dimension(160, 380));
contentPanel = new Content(contentPanelBack);
contentPanel.setBorder(border);
contentPanel.setPreferredSize(new Dimension(520, 380));
contentPanel.setMinimumSize(new Dimension(620, 380));
contentPanel.setLayout(null);
statusPanel = new JPanel();
statusPanel.setBackground(DarkColor);
statusPanel.setBorder(border);
statusPanel.setPreferredSize(new Dimension(620, 24));
statusPanel.setMinimumSize(new Dimension(620, 24));
statusPanel.setLayout(new BorderLayout());
this.getContentPane().setLayout(borderLayout);
this.getContentPane().add(toolBar, BorderLayout.NORTH);
this.getContentPane().add(actionPanel, BorderLayout.EAST);
this.getContentPane().add(contentPanel, BorderLayout.CENTER);
this.getContentPane().add(statusPanel, BorderLayout.SOUTH);
// 加入设置
toolBar.add(setupButton);
setupButton.setBounds(20, 5, 40, 30);
setupButton.setText("属性");
setupButton.setIcon(imgSetup);
setupButton.addActionListener(this);
setupButton.setRolloverIcon(imgSetup);
// 加入路径
toolBar.add(pathButton);
pathButton.setBounds(100, 5, 40, 30);
pathButton.setText("路径");
pathButton.setIcon(imgPath);
pathButton.addActionListener(this);
// 加入关于
toolBar.add(aboutButton);
aboutButton.setBounds(260, 5, 40, 30);
aboutButton.setText("关于");
aboutButton.setIcon(imgAbout);
aboutButton.addActionListener(this);
// 加入tomcat
toolBar.add(tomcatButton);
tomcatButton.setBound