Browse Source

update

master
Fangjie Hu 8 years ago
parent
commit
b5502d16c1
  1. 33
      designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java

33
designer_base/src/com/fr/design/extra/plugindependence/DownLoadDependenceUI.java

@ -65,7 +65,7 @@ public class DownLoadDependenceUI implements ActionListener {
init(); init();
} }
private void init(){ private void init() {
// 创建标签,并在标签上放置一张图片 // 创建标签,并在标签上放置一张图片
BufferedImage image = IOUtils.readImage("/com/fr/design/extra/plugindependence/image/background.png"); BufferedImage image = IOUtils.readImage("/com/fr/design/extra/plugindependence/image/background.png");
ImageIcon imageIcon = new ImageIcon(image); ImageIcon imageIcon = new ImageIcon(image);
@ -92,10 +92,10 @@ public class DownLoadDependenceUI implements ActionListener {
frame.setTitle(Inter.getLocText("FR-Designer-Dependence_Install_Online") + dependenceID); frame.setTitle(Inter.getLocText("FR-Designer-Dependence_Install_Online") + dependenceID);
frame.setSize(LOAD_WIDTH, LOAD_HEIGHT); frame.setSize(LOAD_WIDTH, LOAD_HEIGHT);
Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize(); Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation(screenSize.width/2-LOAD_WIDTH/2,screenSize.height/2-LOAD_HEIGHT/2); frame.setLocation(screenSize.width / 2 - LOAD_WIDTH / 2, screenSize.height / 2 - LOAD_HEIGHT / 2);
frame.setResizable(false); frame.setResizable(false);
// 设置布局为空 // 设置布局为空
frame.setLayout(new BorderLayout(0,0)); frame.setLayout(new BorderLayout(0, 0));
frame.getContentPane().add(label, BorderLayout.CENTER); frame.getContentPane().add(label, BorderLayout.CENTER);
frame.getContentPane().add(progressbar, BorderLayout.SOUTH); frame.getContentPane().add(progressbar, BorderLayout.SOUTH);
@ -111,13 +111,13 @@ public class DownLoadDependenceUI implements ActionListener {
//是否可以连接服务器 //是否可以连接服务器
private boolean connectToServer(){ private boolean connectToServer() {
httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceID)); httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceID));
return httpClient.getResponseCode() == HttpURLConnection.HTTP_OK; return httpClient.getResponseCode() == HttpURLConnection.HTTP_OK;
} }
//获取依赖文件大小 //获取依赖文件大小
private int getFileLength(){ private int getFileLength() {
HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceID)); HttpClient httpClient = new HttpClient(SiteCenter.getInstance().acquireUrlByKind(dependenceID));
if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) { if (httpClient.getResponseCode() == HttpURLConnection.HTTP_OK) {
return httpClient.getContentLength(); return httpClient.getContentLength();
@ -172,7 +172,7 @@ public class DownLoadDependenceUI implements ActionListener {
writer.close(); writer.close();
//下载被取消 //下载被取消
if (flag == false){ if (flag == false) {
result = false; result = false;
return StringUtils.EMPTY; return StringUtils.EMPTY;
} }
@ -184,10 +184,10 @@ public class DownLoadDependenceUI implements ActionListener {
} }
} }
public void installDependenceOnline(){ public void installDependenceOnline() {
try { try {
String filePath = downloadPluginDependenceFile(); String filePath = downloadPluginDependenceFile();
if (!StringUtils.EMPTY.equals(filePath)){ if (!StringUtils.EMPTY.equals(filePath)) {
//安装文件 //安装文件
installPluginDependenceFile(filePath); installPluginDependenceFile(filePath);
result = true; result = true;
@ -198,7 +198,7 @@ public class DownLoadDependenceUI implements ActionListener {
} }
//安装已经下载好的文件 //安装已经下载好的文件
private void installPluginDependenceFile(String filePath){ private void installPluginDependenceFile(String filePath) {
IOUtils.unzip(new File(filePath), dependenceDir); IOUtils.unzip(new File(filePath), dependenceDir);
} }
@ -207,8 +207,7 @@ public class DownLoadDependenceUI implements ActionListener {
int value = progressbar.getValue(); int value = progressbar.getValue();
if (value < totalSize) { if (value < totalSize) {
progressbar.setValue(totalBytesRead); progressbar.setValue(totalBytesRead);
} } else {
else {
timer.stop(); timer.stop();
frame.dispose(); frame.dispose();
} }
@ -217,25 +216,25 @@ public class DownLoadDependenceUI implements ActionListener {
public boolean installOnline() { public boolean installOnline() {
int choose = JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Designer-Plugin_Plugin") + currentID + Inter.getLocText("Need") + dependenceID + Inter.getLocText("Support") + "," + Inter.getLocText("Need_Install") + dependenceID + "(" + showFileLength() + " m)?", "install tooltip", JOptionPane.YES_NO_OPTION); int choose = JOptionPane.showConfirmDialog(null, Inter.getLocText("FR-Designer-Plugin_Plugin") + currentID + Inter.getLocText("Need") + dependenceID + Inter.getLocText("Support") + "," + Inter.getLocText("Need_Install") + dependenceID + "(" + showFileLength() + " m)?", "install tooltip", JOptionPane.YES_NO_OPTION);
if (choose == 0){//下载安装 if (choose == 0) {//下载安装
if (!connectToServer()){ if (!connectToServer()) {
JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Dependence_Connect_Server_Error"), "alert", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, Inter.getLocText("FR-Designer-Dependence_Connect_Server_Error"), "alert", JOptionPane.ERROR_MESSAGE);
return false; return false;
} }
//安装依赖环境 //安装依赖环境
if (install()){ if (install()) {
JOptionPane.showMessageDialog(null, dependenceID + Inter.getLocText("FR-Designer-Dependence_Install_Succeed") + "!!"); JOptionPane.showMessageDialog(null, dependenceID + Inter.getLocText("FR-Designer-Dependence_Install_Succeed") + "!!");
return true; return true;
}else { } else {
JOptionPane.showMessageDialog(null, dependenceID + Inter.getLocText("FR-Designer-Dependence_Install_Failed") + "!!", "alert", JOptionPane.ERROR_MESSAGE); JOptionPane.showMessageDialog(null, dependenceID + Inter.getLocText("FR-Designer-Dependence_Install_Failed") + "!!", "alert", JOptionPane.ERROR_MESSAGE);
return false; return false;
} }
}else {//不安装。无需为用户准备环境 } else {//不安装。无需为用户准备环境
return true; return true;
} }
} }
private String showFileLength() { private String showFileLength() {
return totalSize == -1 ? "NAN" : totalSize/Math.pow(10, 6) + ""; return totalSize == -1 ? "NAN" : totalSize / Math.pow(10, 6) + "";
} }
} }

Loading…
Cancel
Save