package com.lx.product.seal.frame;
|
|
import java.awt.BorderLayout;
|
import java.awt.Dimension;
|
import java.awt.Font;
|
import java.awt.Image;
|
import java.awt.event.ActionEvent;
|
import java.awt.event.ActionListener;
|
import java.io.File;
|
import java.util.concurrent.ExecutorService;
|
import java.util.concurrent.Executors;
|
|
import javax.swing.ImageIcon;
|
import javax.swing.JComponent;
|
import javax.swing.JLabel;
|
import javax.swing.JPanel;
|
|
import com.product.common.io.FileUtils;
|
import com.lx.product.seal.config.Config;
|
import com.lx.product.seal.log.Logger;
|
import com.lx.product.seal.utils.CommonUtil;
|
|
public class MasterPanel extends JPanel {
|
public static Logger log = Logger.getInstance();
|
private JLabel stepl = new JLabel();
|
private int step = 1;
|
JComponent center = null;
|
public ButtonNextLabel next = new ButtonNextLabel();
|
private ButtonPreLabel pre = new ButtonPreLabel();
|
private MasterFrame mainf = null;
|
private ButtonOKLabel ok = new ButtonOKLabel();
|
public Boolean access = true;
|
public Config config=new Config();
|
private ExecutorService executorService;
|
public MasterPanel(MasterFrame f) {
|
mainf = f;
|
this.setLayout(new BorderLayout());
|
updateStep();
|
this.add(stepl, BorderLayout.NORTH);
|
updateCenter();
|
this.add(initButton(), BorderLayout.SOUTH);
|
}
|
|
public void updateStep() {
|
ImageIcon colorIcon = new ImageIcon("./images/step" + step + ".png");
|
|
colorIcon.setImage(colorIcon.getImage().getScaledInstance(690, 81, Image.SCALE_DEFAULT));//宽高根据需要设定
|
stepl.setIcon(colorIcon);
|
}
|
|
//-------------------------------
|
public void updateCenter() {
|
if (center != null) {
|
this.remove(center);
|
}
|
if (step == 1) {
|
log.writeInfo("准备产品版本", Logger.INFO_TYPE);
|
center = imageCenter();
|
} else if (step == 2) {
|
log.writeInfo("相关路径设置", Logger.INFO_TYPE);
|
center = pathCenter();
|
} else if (step == 3) {
|
log.writeInfo("编译Web程序", Logger.INFO_TYPE);
|
JComponent o= compileCenter();
|
if(o !=null) {
|
center=o;//说明发生错误
|
}
|
} else if (step == 4) {
|
log.writeInfo("复制Install代码", Logger.INFO_TYPE);
|
center = copyInstallCode();
|
} else if (step == 5) {
|
log.writeInfo("复制Java代码", Logger.INFO_TYPE);
|
center = copyJavaCode();
|
} else if (step == 6) {
|
log.writeInfo("复制Web代码", Logger.INFO_TYPE);
|
center = copyWebCode();
|
}else {
|
System.out.println("结束");
|
System.exit(0);
|
}
|
this.add(center, BorderLayout.CENTER);
|
this.updateUI();
|
this.repaint();
|
mainf.repaint();
|
}
|
|
private JComponent imageCenter() {
|
JLabel welcome = new JLabel();
|
ImageIcon colorIcon = new ImageIcon("./images/welcome.png");
|
colorIcon.setImage(colorIcon.getImage().getScaledInstance(697, 392, Image.SCALE_DEFAULT));//宽高根据需要设定
|
welcome.setIcon(colorIcon);
|
return welcome;
|
}
|
private JComponent pathCenter() {
|
PathPanel cp = new PathPanel(this);
|
mainf.setPanel(cp.name, cp);
|
return cp;
|
}
|
|
/**
|
* 编译Web
|
* @return
|
*/
|
private JComponent compileCenter() {
|
JLabel web=new JLabel(" 正在编译Web程序,请勿关闭窗口");
|
next.setEnabled(false);
|
executorService = Executors.newSingleThreadExecutor();
|
executorService.submit(new Runnable() {
|
@Override
|
public void run() {
|
String path=((PathPanel)mainf.getPanel("path_panel")).product_web_root.getText()+File.separator+"packed.bat";
|
String dist=((PathPanel)mainf.getPanel("path_panel")).product_web_root.getText()+File.separator+"dist";
|
File distd=new File(dist);
|
if(distd.exists()) {
|
FileUtils.delFile(dist);
|
}
|
try {
|
System.out.println(path);
|
CommonUtil.run("start "+path,web);
|
while(!distd.exists()) {
|
Thread.sleep(1000);
|
web.setText(web.getText()+"..");
|
}
|
|
web.setText(" 编译Web程序完成。");
|
next.setEnabled(true);
|
}catch(Exception e) {
|
e.printStackTrace();
|
web.setText(" 编译Web程序发生错误:"+e.getMessage());
|
}
|
// mainf.mpanel.add(center, BorderLayout.CENTER);
|
// mainf.mpanel.updateUI();
|
// mainf.mpanel.repaint();
|
// mainf.repaint();
|
executorService.shutdown();
|
}
|
});
|
return web;
|
}
|
private JComponent copyInstallCode() {
|
JLabel welcome = new JLabel(" 开始复制安装程序........");
|
next.setEnabled(false);
|
executorService = Executors.newSingleThreadExecutor();
|
executorService.submit(new Runnable() {
|
@Override
|
public void run() {
|
String install_path=((PathPanel)mainf.getPanel("path_panel")).install_project_root.getText()+File.separator+"bin";
|
String version_path=((PathPanel)mainf.getPanel("path_panel")).product_version_root.getText()+File.separator+((PathPanel)mainf.getPanel("path_panel")).product_version.getText();
|
File vf=new File(version_path);
|
if(vf.exists()) {
|
welcome.setText("【"+version_path+"】目录已存在,请返回上一步重新指定新版本号或手动删除该目录。");
|
//不显示下一步按钮,只能点上一步
|
|
}else {
|
vf.mkdirs();
|
String install=version_path+File.separator+"install";
|
File inf=new File(install);
|
if(inf.exists()) {
|
FileUtils.deleteDirectory(install);
|
}
|
inf.mkdirs();
|
File src=new File(install_path);
|
try {
|
for(int i=0;i<src.listFiles().length;i++) {
|
welcome.setText("正在复制文件:"+src.listFiles()[i].getAbsolutePath());
|
System.out.println("正在复制文件:"+src.listFiles()[i].getAbsolutePath());
|
if(src.listFiles()[i].isDirectory()) {
|
FileUtils.copyDirectory(src.listFiles()[i], new File(install+File.separator+src.listFiles()[i].getName()));
|
}else {
|
FileUtils.copyFile(src.listFiles()[i], new File(install+File.separator+src.listFiles()[i].getName()));
|
}
|
}
|
welcome.setText(" 复制安装程序完成,共复制"+src.listFiles().length+"个文件!");
|
next.setEnabled(true);
|
}catch(Exception e) {
|
e.printStackTrace();
|
welcome.setText(" 复制安装文件错误:"+e.getMessage()+",请处理后返回上一步重新操作。");
|
//不显示下一步按钮,只能点上一步
|
|
}
|
}
|
executorService.shutdown();
|
}
|
});
|
return welcome;
|
}
|
private JComponent copyWebCode() {
|
JLabel welcome = new JLabel(" 正在复制Web程序........");
|
next.setEnabled(false);
|
executorService = Executors.newSingleThreadExecutor();
|
executorService.submit(new Runnable() {
|
@Override
|
public void run() {
|
String web_path=((PathPanel)mainf.getPanel("path_panel")).product_web_root.getText()+File.separator+"dist";
|
File src=new File(web_path);
|
if(!src.exists()) {
|
welcome.setText(" 前端代码没有编译:"+web_path);
|
return ;
|
}
|
String version_path=((PathPanel)mainf.getPanel("path_panel")).product_version_root.getText()+File.separator+((PathPanel)mainf.getPanel("path_panel")).product_version.getText();
|
String web=version_path+File.separator+"install"+File.separator+"product-server"+File.separator+"web";
|
File w=new File(web);
|
if(w.exists()) {
|
FileUtils.deleteDirectory(web);
|
}
|
w.mkdirs();
|
try {
|
for(int i=0;i<src.listFiles().length;i++) {
|
welcome.setText("正在复制文件:"+src.listFiles()[i].getAbsolutePath());
|
System.out.println("正在复制文件:"+src.listFiles()[i].getAbsolutePath());
|
if(src.listFiles()[i].isDirectory()) {
|
FileUtils.copyDirectory(src.listFiles()[i], new File(web+File.separator+src.listFiles()[i].getName()));
|
}else {
|
FileUtils.copyFile(src.listFiles()[i], new File(web+File.separator+src.listFiles()[i].getName()));
|
}
|
|
}
|
welcome.setText(" 复制Web程序完成,共复制"+src.listFiles().length+"个文件!");
|
|
next.setEnabled(true);
|
}catch(Exception e) {
|
welcome.setText("复制Web文件错误:"+e.getMessage()+",请处理后返回上一步重新操作。");
|
//不显示下一步按钮,只能点上一步
|
}
|
executorService.shutdown();
|
}
|
});
|
return welcome;
|
}
|
private JComponent copyJavaCode() {
|
JLabel welcome = new JLabel(" 正在复制Java程序........");
|
next.setEnabled(false);
|
executorService = Executors.newSingleThreadExecutor();
|
executorService.submit(new Runnable() {
|
@Override
|
public void run() {
|
String lib_path=((PathPanel)mainf.getPanel("path_panel")).product_java_root.getText()+File.separator+"target"+File.separator+"lib";
|
String resources_path=((PathPanel)mainf.getPanel("path_panel")).product_java_root.getText()+File.separator+"target"+File.separator+"resources";
|
String version_path=((PathPanel)mainf.getPanel("path_panel")).product_version_root.getText()+File.separator+((PathPanel)mainf.getPanel("path_panel")).product_version.getText();
|
String att_path=((PathPanel)mainf.getPanel("path_panel")).product_java_root.getText()+File.separator+"attachment";
|
String resources=version_path+File.separator+"install"+File.separator+"product-server"+File.separator+"resources";
|
String lib=version_path+File.separator+"install"+File.separator+"product-server"+File.separator+"lib";
|
String att=version_path+File.separator+"install"+File.separator+"product-server"+File.separator+"attachment";
|
|
|
File resourcesf=new File(resources);
|
if(resourcesf.exists()) {
|
FileUtils.deleteDirectory(resources);
|
}
|
resourcesf.mkdirs();
|
File libf=new File(lib);
|
if(libf.exists()) {
|
FileUtils.deleteDirectory(lib);
|
}
|
libf.mkdirs();
|
try {
|
//resources
|
File src=new File(resources_path);
|
for(int i=0;i<src.listFiles().length;i++) {
|
welcome.setText("正在复制文件:"+src.listFiles()[i].getAbsolutePath());
|
System.out.println("正在复制文件:"+src.listFiles()[i].getAbsolutePath());
|
if(src.listFiles()[i].isDirectory()) {
|
FileUtils.copyDirectory(src.listFiles()[i], new File(resources+File.separator+src.listFiles()[i].getName()));
|
}else {
|
FileUtils.copyFile(src.listFiles()[i], new File(resources+File.separator+src.listFiles()[i].getName()));
|
}
|
|
}
|
//lib/*.jar
|
int fs=src.listFiles().length;
|
src=new File(lib_path);
|
for(int i=0;i<src.listFiles().length;i++) {
|
if(src.listFiles()[i].getName().indexOf("spring-server-master-1.2.6.0")>=0
|
||src.listFiles()[i].getName().indexOf("product-server-core-1.0.0-SNAPSHOT")>=0) {
|
continue;
|
}
|
if(src.listFiles()[i].isDirectory()) {
|
FileUtils.copyDirectory(src.listFiles()[i], new File(lib+File.separator+src.listFiles()[i].getName()));
|
}else {
|
FileUtils.copyFile(src.listFiles()[i], new File(lib+File.separator+src.listFiles()[i].getName()));
|
}
|
welcome.setText("正在复制文件:"+src.listFiles()[i].getAbsolutePath());
|
}
|
String src1=((PathPanel)mainf.getPanel("path_panel")).product_java_root.getText()+File.separator+"target"+File.separator+"product-server-web-1.0.0-SNAPSHOT.jar";
|
String aims7=version_path+File.separator+"install"+File.separator+"product-server"+File.separator+"product-server-web-1.0.0-SNAPSHOT.jar";
|
if(new File(aims7).exists()) {
|
FileUtils.deleteFile(aims7);
|
}
|
//web.jar
|
FileUtils.copyFile(src1, aims7);
|
//复制附件
|
FileUtils.copyDir(att_path, att);
|
fs+=1;
|
welcome.setText(" 复制Java程序完成,共复制"+(src.listFiles().length+fs)+"个文件!");
|
next.setEnabled(true);
|
}catch(Exception e) {
|
e.printStackTrace();
|
welcome.setText(" 复制Java文件错误:"+e.getMessage()+",请处理后返回上一步重新操作。");
|
//不显示下一步按钮,只能点上一步
|
}
|
executorService.shutdown();
|
}
|
});
|
return welcome;
|
}
|
//-------------------------
|
public JComponent initButton() {
|
JPanel b = new JPanel();
|
b.setPreferredSize(new Dimension(690, 48));
|
next.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
if (access) {
|
step += 1;
|
updateStep();
|
updateSouth();
|
updateCenter();
|
}
|
}
|
});
|
pre.addActionListener(new ActionListener() {
|
public void actionPerformed(ActionEvent e) {
|
step -= 1;
|
updateStep();
|
updateSouth();
|
updateCenter();
|
|
}
|
});
|
b.add(pre);
|
b.add(next);
|
b.add(ok);
|
updateSouth();
|
return b;
|
}
|
|
public void updateSouth() {
|
ok.setEnabled(false);
|
if (step == 1) {
|
firstButton();
|
}else if (step == 6) {
|
preButton();
|
}else {
|
nextButton();
|
}
|
}
|
|
/**
|
* 进入安装系统页面初始化按钮为空
|
*/
|
public void startInstallStepButton() {
|
pre.setEnabled(false);
|
next.setOperate(false);
|
ok.setEnabled(false);
|
}
|
|
/**
|
* 安装系统完成后显示按钮 下一步
|
*/
|
public void finalInstallStepButton() {
|
pre.setEnabled(false);
|
next.setOperate(true);
|
ok.setEnabled(false);
|
}
|
|
|
private void firstButton() {
|
pre.setEnabled(false);
|
next.setEnabled(true);
|
next.setOperate(true);
|
access = true;
|
|
}
|
private void nextButton() {
|
pre.setEnabled(true);
|
next.setEnabled(true);
|
next.setOperate(true);
|
access = true;
|
|
}
|
|
private void preButton() {
|
pre.setEnabled(true);
|
next.setEnabled(false);
|
access = true;
|
}
|
|
}
|