加入 Gitee
与超过 1200万 开发者一起发现、参与优秀开源项目,私有仓库也完全免费 :)
免费加入
文件
该仓库未声明开源许可证文件(LICENSE),使用请关注具体项目描述及其代码上游依赖。
克隆/下载
MainDailog.java 4.82 KB
一键复制 编辑 原始数据 按行查看 历史
xavier 提交于 2020-02-25 14:49 . init
package com.ui;
import java.awt.BorderLayout;
import java.awt.FlowLayout;
import javax.swing.JButton;
import javax.swing.JDialog;
import javax.swing.JFileChooser;
import javax.swing.JLabel;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.filechooser.FileNameExtensionFilter;
import com.utils.FileOperation;
import javax.swing.JTextField;
import java.awt.event.ActionListener;
import java.io.File;
import java.io.IOException;
import java.awt.event.ActionEvent;
public class MainDailog extends JDialog {
private final JPanel contentPanel = new JPanel();
private JTextField filePath_text;
/**
* Launch the application.
*/
public static void main(String[] args) {
try {
MainDailog dialog = new MainDailog();
dialog.setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE);
dialog.setVisible(true);
dialog.setTitle("格式转换");
dialog.setResizable(false);
} catch (Exception e) {
e.printStackTrace();
}
}
private String getSelectFilePath() {
// TODO Auto-generated method stub
JFileChooser jfc=new JFileChooser();
FileNameExtensionFilter filter =
new FileNameExtensionFilter(
"xmind", "xmind");
jfc.setFileFilter(filter);
jfc.showDialog(new JLabel(), "选择");
File file=jfc.getSelectedFile();
if(file != null){
return jfc.getSelectedFile().getAbsolutePath();
}else{
return null;
}
}
private String getSaveFilePath(){
JFileChooser jf = new JFileChooser();
jf.setFileSelectionMode(JFileChooser.SAVE_DIALOG | JFileChooser.DIRECTORIES_ONLY);
jf.showDialog(new JLabel(), "保存");
File fi = jf.getSelectedFile();
String f = fi.getAbsolutePath() + ".xlsx";
if(fi != null && fi.getName() != null && !fi.getName().equals("") && fi.getAbsolutePath() != null &&
!fi.getAbsolutePath().equals("")){
return f;
}else{
return null;
}
}
/**
* Create the dialog.
*/
public MainDailog() {
setBounds(100, 100, 610, 236);
getContentPane().setLayout(new BorderLayout());
contentPanel.setBorder(new EmptyBorder(5, 5, 5, 5));
getContentPane().add(contentPanel, BorderLayout.CENTER);
contentPanel.setLayout(null);
{
JButton okButton = new JButton("\u8F6C\u6362");
okButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if(filePath_text.getText().equals("") || filePath_text.getText()==null){
JOptionPane.showConfirmDialog (null, "目录不得为空", "提示", JOptionPane.YES_OPTION);
}else{
File file = new File(filePath_text.getText());
if(!file.exists()){
JOptionPane.showConfirmDialog (null, "该文件不存在", "提示", JOptionPane.YES_OPTION);
}else{
FileOperation fo = new FileOperation();
String outPath = getSaveFilePath();
if(outPath == null){
JOptionPane.showConfirmDialog (null, "保存文件的路径不对", "提示", JOptionPane.YES_OPTION);
}else{
fo.unZipFiles(filePath_text.getText());
if(fo.analysisXML(new File(filePath_text.getText()).getParent()+ "\\tm\\content.xml")){
if(fo.writeExcel(outPath)){
JOptionPane.showConfirmDialog (null, "转换成功!", "提示", JOptionPane.YES_OPTION);
try {
Runtime.getRuntime().exec("explorer.exe " + new File(outPath).getParent());
} catch (IOException e1) {
// TODO Auto-generated catch block
e1.printStackTrace();
}
}else{
JOptionPane.showConfirmDialog (null, "转换失败!", "提示", JOptionPane.YES_OPTION);
}
fo.cleanTemp(new File(new File(filePath_text.getText()).getParent() + "\\tm"));
}else{
JOptionPane.showConfirmDialog (null, "非法的xmind文件!没有得到解压的xml文件", "转换失败!", JOptionPane.YES_OPTION);
}
}
}
}
}
});
okButton.setBounds(230, 126, 141, 36);
contentPanel.add(okButton);
okButton.setActionCommand("OK");
getRootPane().setDefaultButton(okButton);
}
filePath_text = new JTextField();
filePath_text.setBounds(54, 66, 390, 28);
contentPanel.add(filePath_text);
filePath_text.setColumns(10);
JButton select_btn = new JButton("\u9009\u62e9\u6587\u4ef6");
select_btn.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
String path = getSelectFilePath();
filePath_text.setText(path);
}
});
select_btn.setBounds(454, 61, 115, 36);
contentPanel.add(select_btn);
{
JPanel buttonPane = new JPanel();
buttonPane.setLayout(new FlowLayout(FlowLayout.RIGHT));
getContentPane().add(buttonPane, BorderLayout.SOUTH);
}
}
}
马建仓 AI 助手
尝试更多
代码解读
代码找茬
代码优化