⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 auto.java

📁 使用Java Swing开发的一个自动生成POJO的软件,能够生成Appfuse框架需要的带有XDoclet代码的POJO.
💻 JAVA
📖 第 1 页 / 共 3 页
字号:
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.setBounds(180, 5, 40, 30);
		tomcatButton.setText("tomcat");
		tomcatButton.setIcon(imgTomcat);
		tomcatButton.addActionListener(this);

		// 加入状态栏
		statusPanel.add(companyField, BorderLayout.CENTER);
		companyField.setText("西安用友软件工程公司");
		companyField.setBorder(unSelected);
		companyField.setEditable(false);
		companyField.setForeground(Color.white);
		companyField.setBackground(DarkColor);
		
		statusPanel.add(timeField, BorderLayout.EAST);
		timeField.setText(getNowDate().toString());
		timeField.setBorder(unSelected);
		timeField.setEditable(false);
		timeField.setForeground(Color.white);
		timeField.setBackground(DarkColor);

		jlName.setBounds(100, 50, 80, 30);
		jlName.setText("对象名");
		jlName.setFont(new java.awt.Font("宋体", java.awt.Font.BOLD, 18));
		jlName.setForeground(java.awt.Color.white);

		jlSeted.setBounds(40, 150, 120, 20);
		jlSeted.setText("已设置的属性");
		jlSeted.setFont(new java.awt.Font("宋体", java.awt.Font.BOLD, 18));
		jlSeted.setForeground(java.awt.Color.white);

		jlParent.setBounds(320, 150, 120, 20);
		jlParent.setText("Parent");
		jlParent.setFont(new java.awt.Font("宋体", java.awt.Font.BOLD, 18));
		jlParent.setForeground(java.awt.Color.white);

		jlRun.setBounds(380, 345, 120, 20);
		jlRun.setText("通用");
		jlRun.setFont(new java.awt.Font("宋体", java.awt.Font.BOLD, 18));
		jlRun.setForeground(java.awt.Color.white);

		checkParent.setBounds(340, 180, 20, 15);
		checkParent.setBackground(new java.awt.Color(76, 146, 196));
		checkParent.addItemListener(this);

		checkInstall.setBounds(420, 347, 20, 15);
		checkInstall.setBackground(new java.awt.Color(76, 146, 196));
		checkInstall.addItemListener(this);

		listParent.setBounds(390, 150, 100, 60);
		listParent.setVisible(false);

		listProperty.setBounds(200, 150, 100, 80);

		jtCode.setBounds(200, 50, 100, 30);
		jtCode.setFont(new Font("Dialog",Font.PLAIN,18));

		jbSure = new JButton("确定", sure);
		jbSure.setBounds(new java.awt.Rectangle(140, 340, 60, 30));
		jbSure.addActionListener(this);
		jbSure.setBorder(unSelected);
		jbSure.setRolloverIcon(sureBack);

		jbExit = new JButton("退出", exit);
		jbExit.setBounds(new java.awt.Rectangle(220, 340, 60, 30));
		jbExit.addActionListener(this);
		jbExit.setBorder(unSelected);
		jbExit.setRolloverIcon(exitBack);

		jbRun = new JButton("运行ant", run);
		jbRun.setBounds(new java.awt.Rectangle(300, 340, 60, 30));
		jbRun.addActionListener(this);
		jbRun.setBorder(unSelected);
		jbRun.setRolloverIcon(runBack);

		jbAdd = new JButton("设置", add);
		jbAdd.setBounds(new java.awt.Rectangle(140, 250, 60, 25));
		jbAdd.addActionListener(this);
		jbAdd.setBorder(unSelected);
		jbAdd.setRolloverIcon(addBack);

		jbEdit = new JButton("编辑", edit);
		jbEdit.setBounds(new java.awt.Rectangle(220, 250, 60, 25));
		jbEdit.addActionListener(this);
		jbEdit.setBorder(unSelected);
		jbEdit.setRolloverIcon(editBack);

		jbDel = new JButton("删除", del);
		jbDel.setBounds(new java.awt.Rectangle(300, 250, 60, 25));
		jbDel.addActionListener(this);
		jbDel.setBorder(unSelected);
		jbDel.setRolloverIcon(delBack);

		contentPanel.add(jlName);
		contentPanel.add(jlSeted);
		contentPanel.add(jlParent);
		contentPanel.add(jlRun);
		contentPanel.add(jtCode);
		contentPanel.add(listProperty);
		contentPanel.add(checkParent);
		contentPanel.add(listParent);
		contentPanel.add(checkInstall);
		contentPanel.add(jbSure);
		contentPanel.add(jbExit);
		contentPanel.add(jbEdit);
		contentPanel.add(jbRun);
		contentPanel.add(jbAdd);
		contentPanel.add(jbDel);

		jfchooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
		jfchooser.setDialogTitle("选择model所在文件夹");
	}

	/**
	 * 设定按钮被选择之后的图案
	 */
	void setButton(JButton jb) {
		jbSure.setBorder(unSelected);
		jbDel.setBorder(unSelected);
		jbAdd.setBorder(unSelected);
		jbExit.setBorder(unSelected);
		jbRun.setBorder(unSelected);
		jbEdit.setBorder(unSelected);
		jb.setBorder(emptyBorder);
	}

	/**
	 * 设定按钮的图案
	 */
	void setButton() {
		jbSure.setBorder(unSelected);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -