/*
* Created on 2004/08/11
* Author aki@www.xucker.jpn.org
* License Apache2.0 or Common Public License
*/
package org.jpn.xucker.returncode;
import java.io.BufferedInputStream;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import org.eclipse.swt.SWT;
import org.eclipse.swt.graphics.Image;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TableItem;
import org.jpn.xucker.commons.io.LineSeparatorCountInputStream;
import org.jpn.xucker.commons.swt.series.ResultData;
import org.jpn.xucker.commons.swt.series.fls.FileListStandard;
/**
*
*
*/;
public class ReturnCodeChecker extends FileListStandard{
/**
* @param shell
*/
Image macImage;
Image unixImage;
Image winImage;
Image unknownImage;
public ReturnCodeChecker(Shell shell) {
super(shell);
//don't write here
//use before and after
}
public static void main(String[] args) {
Display display=new Display();
Shell shell=new Shell(display,SWT.CLOSE|SWT.MIN);
ReturnCodeChecker main=new ReturnCodeChecker(shell);
shell.open();
while(!shell.isDisposed()){
if (!display.readAndDispatch ()){
display.sleep ();
}
}
display.dispose();
}
/* (non-Javadoc)
* @see org.jpn.xucker.commons.series.FileListStandard#afterConstract()
*/
protected void afterConstract() {
}
/* (non-Javadoc)
* @see org.jpn.xucker.commons.series.FileListStandard#beforeConstract()
*/
protected void beforeConstract() {
macImage= new Image(shell.getDisplay(), ReturnCodeChecker.class.getClassLoader()
.getResourceAsStream(
"org/jpn/xucker/returncode/resource/mac.png"));
unixImage= new Image(shell.getDisplay(), ReturnCodeChecker.class.getClassLoader()
.getResourceAsStream(
"org/jpn/xucker/returncode/resource/unix.png"));
winImage= new Image(shell.getDisplay(), ReturnCodeChecker.class.getClassLoader()
.getResourceAsStream(
"org/jpn/xucker/returncode/resource/win.png"));
unknownImage= new Image(shell.getDisplay(), ReturnCodeChecker.class.getClassLoader()
.getResourceAsStream(
"org/jpn/xucker/returncode/resource/unknown.png"));
ICON_RESOURCE="org/jpn/xucker/returncode/resource/icon.png";
APP_NAME="ReturnCode Checker";
EXEC_LABEL="調べる";
resultColumnText=new String[]{"名前","Win改行","Unix改行","Mac改行","byte数","ディレクトリー"};
resultColumnWidth=new int[]{115,60,60,60,55,125};
}
/* (non-Javadoc)
* @see org.jpn.xucker.commons.series.FileListStandard#execFile(java.io.File)
*/
public void execFile(File file) {
if(file.isFile()){
// TODO Auto-generated method stub
LineSeparatorCountInputStream counter=null;
try {
counter = new LineSeparatorCountInputStream(new FileInputStream(file));
BufferedInputStream binput=new BufferedInputStream(counter,10240);
int c;
long count=0;
while((c=binput.read())!=-1){
count++;
}
} catch (FileNotFoundException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
int mac=counter.getR();
int win=counter.getRn();
int unix=counter.getN();
ResultData data=new ResultData();
data.setValue(resultColumnText[0],file.getName());
data.setValue(resultColumnText[1],""+win);
data.setValue(resultColumnText[2],""+unix);
data.setValue(resultColumnText[3],""+mac);
data.setValue(resultColumnText[4],""+file.length());
data.setValue(resultColumnText[5],file.getParent());
addResult(data);
}else{
String list[]=file.list();
for (int i = 0; i < list.length; i++) {
execFile(new File(file,list[i]));
}
}
}
/* (non-Javadoc)
* @see org.jpn.xucker.commons.series.FileListStandard#parseValues(java.lang.String[])
*/
public void parseValues(TableItem item,String[] values) {
// TODO Auto-generated method stub
item.setText(values);
int win=Integer.parseInt(values[1]);
int unix=Integer.parseInt(values[2]);
int mac=Integer.parseInt(values[3]);
// System.out.println(""+win+","+unix+","+mac);
if(mac==0 && unix==0 && win>0){
item.setImage(0,winImage);
}
else if(mac==0 && unix>0 && win==0){
item.setImage(unixImage);
}
else if(mac>0 && unix==0 && win>0){
item.setImage(macImage);
}else{
item.setImage(unknownImage);
}
}
/* (non-Javadoc)
* @see org.jpn.xucker.commons.swt.series.fls.FileListStandard#createOptionUI(org.eclipse.swt.widgets.Group)
*/
protected void createOptionUI(Group optionGroup2) {
// TODO Auto-generated method stub
}
}
|