|
等 级:版主 |
经 验 值:37213 |
魅 力 值:4262 |
龙 币:26833 |
积 分:25066.1 |
注册日期:2005-08-20 |
|
|
|
working
import java.awt.BorderLayout;
import java.awt.GridLayout;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
import java.awt.event.WindowAdapter;
import java.awt.event.WindowEvent;
import javax.swing.JButton;
import javax.swing.JFileChooser;
import javax.swing.JFrame;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.JTextArea;
import javax.swing.JTextField;
import java.io.File;
import java.util.Vector;
import org.w3c.dom.Document;
public class AppWindow extends JFrame {
/**
*
*/
private static final long serialVersionUID = 1L;
// public final static HtmlReport bug = new HtmlReport("index.html");
public final static StringBuffer sb = new StringBuffer();
JLabel inputLabel;
JTextField tfPath;
JButton openButton;
JButton runButton;
JTextArea tfOutPut;
public AppWindow parent;
public AppWindow(String title) {
super(title);
parent = this;
setResizable(false);
setSize(450, 400);
setLocation(300, 200);
// this.setLayout(new GridLayout(4, 0)); // new java.awt.FlowLayout()
JPanel panel1 = new JPanel(new GridLayout(3, 0));
JPanel panel2 = new JPanel();
JPanel panel3 = new JPanel();
addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
System.exit(0); // 退出应用程序
}
});
inputLabel = new JLabel("Input Directory:");
tfPath = new JTextField();
tfOutPut = new JTextArea("Output:");
openButton = new JButton("Browser");
runButton = new JButton("Run");
openButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
JFileChooser chooser = new JFileChooser();
chooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
chooser.setDialogType(JFileChooser.OPEN_DIALOG);
int returnVal = chooser.showOpenDialog(parent);
if (returnVal == JFileChooser.APPROVE_OPTION) {
tfPath.setText(chooser.getSelectedFile().getPath());
}
}
});
runButton.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
// TODO Auto-generated method stub
runButton.setEnabled(false);
sb.delete(0, sb.length());
sb
.append("<H2 align="center">Running Log</H2><BR><table width="669" border="1" align="center" cellspacing="0" bordercolor="#000000"><tr><td width="426"><strong>script Name</strong></td><td width="101"><strong>Error Number</strong></td><td width="64"><strong>Language</strong></td><td width="64"><strong>Link</strong></td></tr>");
ExecuteReport er = new ExecuteReport(parent);
Thread t = new Thread(er);
t.start();
}
});
panel3.add(openButton);
panel1.add(inputLabel, BorderLayout.NORTH);
panel1.add(tfPath, BorderLayout.CENTER);
panel1.add(panel3, BorderLayout.SOUTH);
panel2.add(runButton);
add(panel1, BorderLayout.NORTH);
add(tfOutPut, BorderLayout.CENTER);
add(panel2, BorderLayout.SOUTH);
}
}
class ExecuteReport implements Runnable {
AppWindow parent;
long startTime;
long endTime;
ExecuteReport(AppWindow parent) {
this.parent = parent;
startTime = System.currentTimeMillis();
}
public void run() {
// TODO Auto-generated method stub
String filePath = "";
if (parent.tfPath != null && !(parent.tfPath.getText().equals("")))
filePath = parent.tfPath.getText();
else {
parent.tfOutPut.setText("Please Select a directory!");
parent.runButton.setEnabled(true);
return;
}
File file = new File(filePath);
String scriptStr[] = file.list();
for (int i = 0; i < scriptStr.length; i++) {
an(filePath + File.separator + scriptStr[i]);
}
endTime = System.currentTimeMillis();
parent.runButton.setEnabled(true);
parent.tfOutPut.setText("Complete!nRunning time:"
+ (endTime - startTime) / 1000 + "s");
AppWindow.sb.append("</table>");
String reportFile = filePath + File.separator + "index.html";
HtmlReport bug = new HtmlReport(reportFile);
bug.addContent(AppWindow.sb.toString());
bug.savePage();
try {
// Thread.sleep(3000);
Runtime.getRuntime().exec(
new String[] { "cmd.exe", "/c", reportFile });
} catch (Exception e) {
System.out.println(e.toString());
}
}
public void an(String filePath) {
String info = "";
FileList fl = new FileList(filePath);// filePath);
File[] listLanguage = fl.getSubFolder();
if (listLanguage == null) {
return;
}
File[] xmlFile = null;
parent.tfOutPut.setText("Running...");
int languageNumber = listLanguage.length;
Vector languageVector = new Vector();
int enFiles = 0;
ExtensionFileFilter fileFilter = new ExtensionFileFilter("xml");
int indexEn = -1;
for (int i = 0; i < languageNumber; i++) {
if (listLanguage[i].isDirectory()) {
String namel = listLanguage[i].getName();
if (namel.equalsIgnoreCase("EN"))
indexEn = i;
languageVector.add(namel);
}
}
String filelist[];
Vector enList = new Vector();
if (indexEn != -1) {
xmlFile = listLanguage[indexEn].listFiles(fileFilter);
enFiles = xmlFile.length;
filelist = new String[enFiles];
for (int j = 0; j < enFiles; j++) {
filelist[j] = xmlFile[j].getName();
info = "n" + info;
info = "Reading " + filelist[j] + "..." + info;
parent.tfOutPut.setText(info);
Document doc = fl.getDocFromFile(xmlFile[j]);
enList.add(doc);
}
} else {
parent.tfOutPut.setText("Error!nNo English xml file");
parent.runButton.setEnabled(true);
return;
}
// for(int i = 0 ; i < )
Vector byFileList[] = new Vector[enFiles];
for (int i = 0; i < enFiles; i++) {
byFileList[i] = new Vector();
for (int j = 0; j < languageNumber; j++) {
// byFileList
if (j == indexEn)
byFileList[i].add(enList.get(i));
else {
String s = "" + (languageVector.get(j));
String Path = filePath + File.separator + s
+ File.separator + filelist[i];
File f = new File(Path);
Document doc = fl.getDocFromFile(f);
byFileList[i].add(doc);
}
}
}
// 加入每种语言的相应文件,没有加空;
// constractor index.html
final HtmlReport hr = new HtmlReport(filePath + "\index.html");
hr.setTitle("Test Report Summary");
hr
.addContent("<P><table width="600" border="1" cellspacing="0" bordercolor="#666666">");
hr.startRow();
hr.startTD();
hr.addContent("Page");
hr.endTD();
hr.startTD();
hr.addContent("Report");
hr.endTD();
hr.endRow();
if (xmlFile != null) {
final Thread[] runThread = new Thread[enFiles];
final ExecuteLanguage[] el = new ExecuteLanguage[enFiles];
for (int i = 0; i < enFiles; i++) {
info = "n" + info;
info = "Analyse " + xmlFile[i].getName() + "......" + info;
parent.tfOutPut.setText(info);
hr.startRow();
hr.startTD();
hr.addContent(xmlFile[i].getName());
hr.endTD();
hr.startTD();
hr.addContent("<a href=.\" + xmlFile[i].getName()
+ ".html>View</a>");
hr.endTD();
hr.endRow();
el[i] = new ExecuteLanguage(byFileList[i], filePath,
languageVector, xmlFile[i].getName());
runThread[i] = new Thread(el[i]);
runThread[i].start();
}
for (int i = 0; i < runThread.length; i++) {
try {
runThread[i].join(); // 等待所有线程运行结束
} catch (InterruptedException e) {
// ignore
}
}
int countErro = 0;
for (int i = 0; i < enFiles; i++) {
countErro += el[i].getErrorNum();
}
hr.endTable();
String tmps = filePath.substring(filePath.lastIndexOf('\') + 1);
AppWindow.sb.append("<tr><td>" + tmps + "</td><td>" + countErro
+ "</td><td>" + languageNumber + "</td><td><a href=""
+ tmps + "\index.html">View</a></td></tr>");
// hr.addContent("<input type="hidden" value="" + countErro
// + "" name="ErrorNum" />");
hr.savePage();
}
}
}
class ExecuteLanguage implements Runnable {
Vector list;
String filePath;
String name;
Vector languageVector;
int ErrorNum;
ExecuteLanguage(Vector list, String filePath, Vector languageVector,
String name) {
this.list = list;
this.filePath = filePath;
this.languageVector = languageVector;
this.name = name;
}
public void run() {
// TODO Auto-generated method stub
parseDoc pdoc = new parseDoc(list);
pdoc.saveReportPage(filePath, name, languageVector);
ErrorNum = pdoc.getErrorNum();
}
public int getErrorNum() {
return ErrorNum;
}
} (此文由winchi在2007-02-08 17:26:34编辑过)
『声明:以上内容为本站网友《winchi》原创,转载需征得原作者同意并注明转载自www.hlgnet.com』 |
|
-- 世界上最遥远的距离是冷漠的心
|
|
|