package com.landray.kmss.plugin.dialog;
import com.intellij.openapi.fileChooser.FileChooserDescriptor;
import com.intellij.openapi.fileChooser.FileChooserDescriptorFactory;
import com.intellij.openapi.project.Project;
import com.intellij.openapi.ui.Messages;
import com.intellij.openapi.ui.TextBrowseFolderListener;
import com.intellij.openapi.ui.TextFieldWithBrowseButton;
import com.intellij.uiDesigner.core.GridConstraints;
import com.intellij.uiDesigner.core.GridLayoutManager;
import com.landray.kmss.plugin.util.PluginCheckVersion;
import java.awt.Color;
import java.awt.Dimension;
import java.awt.Font;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.io.File;
import javax.swing.BorderFactory;
import javax.swing.JButton;
import javax.swing.JComponent;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JPanel;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.Logger;
public class DownloadPluginDialog extends JDialog {
private static final Logger LOGGER = LogManager.getLogger(DownloadPluginDialog.class);
private JPanel contentPane;
TextFieldWithBrowseButton textFieldWithBrowseButton;
private JButton buttonOK;
private JButton buttonCancel;
private TextFieldWithBrowseButton imageFolder;
private String newVersingName = "";
private Project project;
public DownloadPluginDialog(final String newVersingName) {
try {
this.initDraw();
this.setContentPane(this.contentPane);
this.setModal(true);
this.getRootPane().setDefaultButton(this.buttonOK);
this.newVersingName = newVersingName;
this.imageFolder.setText(System.getProperty("user.home") + File.separator + newVersingName + ".zip");
this.buttonOK.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
try {
DownloadPluginDialog.this.onOK();
} catch (Exception var3) {
var3.printStackTrace();
}
}
});
this.buttonCancel.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
DownloadPluginDialog.this.onCancel();
}
});
final FileChooserDescriptor e = FileChooserDescriptorFactory.createSingleFolderDescriptor();
this.imageFolder.addBrowseFolderListener(new TextBrowseFolderListener(e) {
public void actionPerformed(ActionEvent e) {
JFileChooser fc = new JFileChooser();
String current = DownloadPluginDialog.this.imageFolder.getText();
if(!current.isEmpty()) {
fc.setCurrentDirectory(new File(current));
}
fc.setFileSelectionMode(1);
fc.showOpenDialog(DownloadPluginDialog.this.getRootPane());
File file = fc.getSelectedFile();
String path = file == null?"":file.getAbsolutePath() + File.separator;
if(path.endsWith("/") || path.endsWith("\\")) {
path = path + newVersingName + ".zip";
}
if(path.endsWith(".zip")) {
DownloadPluginDialog.this.imageFolder.setText(path);
}
}
});
} catch (Exception var3) {
var3.printStackTrace();
}
}
public void setProject(Project project) {
this.project = project;
}
private void onOK() throws Exception {
if(this.imageFolder.getText() != null && this.imageFolder.getText().trim().length() != 0) {
this.buttonOK.setEnabled(false);
this.buttonCancel.setEnabled(false);
boolean rtn = PluginCheckVersion.downloadPlugin(this.imageFolder.getText());
if(rtn) {
Messages.showErrorDialog(this.project, "下载成功,请通过idea菜单
\"File\\Settings...\\Plugins\"更新插件。", "提示");
} else {
Messages.showErrorDialog(this.project, "下载失败,请检查连接SCM服务器的网络", "提示");
}
this.dispose();
} else {
Messages.showErrorDialog(this.project, "保存位置不能为空", "提示");
}
}
private void onCancel() {
this.dispose();
}
private void initDraw() {
JPanel jPanel;
this.contentPane = jPanel = new JPanel();
jPanel.setLayout(new GridLayoutManager(3, 1, new Insets(10, 10, 10, 10), -1, -1, false, false));
JPanel jPanelTip = new JPanel();
jPanelTip.setLayout(new GridLayoutManager(1, 2, new Insets(2, 8, 2, 8), -1, -1, false, false));
Font font2 = this.$$$getFont$$$("Microsoft YaHei UI", -1, 12, jPanelTip.getFont());
if(font2 != null) {
jPanelTip.setFont(font2);
}
jPanel.add(jPanelTip, new GridConstraints(0, 0, 1, 1, 0, 3, 3, 3, (Dimension)null, (Dimension)null, (Dimension)null));
jPanelTip.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), (String)null, 0, 0, (Font)null, (Color)null));
JLabel jLabelTip = new JLabel();
jLabelTip.setText("插件有新版本,请下载更新。下载成功后,请通过idea菜单
\"File\\Settings...\\Plugins\\Installed\\Install Plugin from Disk...\"进行插件更新操作。");
jPanelTip.add(jLabelTip, new GridConstraints(0, 0, 1, 1, 8, 0, 0, 0, (Dimension)null, (Dimension)null, (Dimension)null));
JPanel jPanelOut = new JPanel();
jPanelOut.setLayout(new GridLayoutManager(1, 2, new Insets(2, 8, 2, 8), -1, -1, false, false));
Font font3 = this.$$$getFont$$$("Microsoft YaHei UI", -1, 12, jPanelOut.getFont());
if(font3 != null) {
jPanelOut.setFont(font3);
}
jPanel.add(jPanelOut, new GridConstraints(1, 0, 1, 1, 0, 3, 3, 3, (Dimension)null, (Dimension)null, (Dimension)null));
jPanelOut.setBorder(BorderFactory.createTitledBorder(BorderFactory.createEtchedBorder(), (String)null, 0, 0, (Font)null, (Color)null));
JLabel jLabelOut = new JLabel();
jLabelOut.setText("保存位置:");
jPanelOut.add(jLabelOut, new GridConstraints(0, 0, 1, 1, 8, 0, 0, 0, (Dimension)null, (Dimension)null, (Dimension)null));
this.imageFolder = this.textFieldWithBrowseButton = new TextFieldWithBrowseButton();
jPanelOut.add(this.textFieldWithBrowseButton, new GridConstraints(0, 1, 1, 1, 0, 1, 7, 3, (Dimension)null, (Dimension)null, (Dimension)null));
JPanel jPanel3 = new JPanel();
jPanel3.setLayout(new GridLayoutManager(1, 2, new Insets(0, 0, 0, 0), -1, -1, false, false));
jPanel.add(jPanel3, new GridConstraints(2, 0, 1, 1, 0, 3, 3, 1, (Dimension)null, (Dimension)null, (Dimension)null));
JPanel jPanel4 = new JPanel();
jPanel4.setLayout(new GridLayoutManager(1, 1, new Insets(0, 0, 0, 0), -1, -1, false, false));
jPanel3.add(jPanel4, new GridConstraints(0, 1, 1, 1, 0, 3, 3, 3, (Dimension)null, (Dimension)null, (Dimension)null));
JButton jButton2;
this.buttonCancel = jButton2 = new JButton();
jButton2.setText("取消");
jPanel4.add(jButton2, new GridConstraints(0, 0, 1, 1, 0, 1, 3, 0, (Dimension)null, (Dimension)null, (Dimension)null));
JButton jButton;
this.buttonOK = jButton = new JButton();
jButton.setText("下载");
jPanel3.add(jButton, new GridConstraints(0, 0, 1, 1, 0, 1, 3, 0, (Dimension)null, (Dimension)null, (Dimension)null));
}
private Font $$$getFont$$$(String string, int n, int n2, Font font) {
if(font == null) {
return null;
} else {
Font font2;
String string2 = string == null?font.getName():((font2 = new Font(string, 0, 10)).canDisplay('a') && font2.canDisplay('1')?string:font.getName());
return new Font(string2, n >= 0?n:font.getStyle(), n2 >= 0?n2:font.getSize());
}
}
public JComponent $$$getRootComponent$$$() {
return this.contentPane;
}
}