Citation :
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.eclipse.swt.SWT;
import org.eclipse.swt.layout.GridData;
import org.eclipse.swt.layout.GridLayout;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.Text;
public class RunStarGeneGUI {
private Shell shell;
private GridLayout gridLayout;
private GridData gridData;
private Display display;
private String cmd;
private Text allStarGene, term;
/**
* Constructeur
* @param display Le display de la fenetre
* @param cmd La commande a executer
*/
public RunStarGeneGUI(Display display, final String cmd){
this.display = display;
this.cmd = cmd;
this.initLayout();
this.initShell();
this.initRunStarGeneGUI();
this.run();
this.ear();
}
private void initShell(){
// create the shell
this.shell = new Shell(SWT.TITLE | SWT.CLOSE | SWT.RESIZE);
this.shell.setText("Run of STARGene" );
this.shell.setSize(517, 486);
shell.setLayout(gridLayout);
}
private void initLayout(){
this.gridLayout = new GridLayout();
gridLayout.numColumns = 1;
this.gridData = new GridData(SWT.FILL, SWT.FILL, true, true);
}
private void initRunStarGeneGUI(){
this.allStarGene = new Text(this.shell, SWT.H_SCROLL | SWT.V_SCROLL);
allStarGene.setLayoutData(gridData);
this.term = new Text(this.shell, SWT.H_SCROLL | SWT.V_SCROLL);
term.setLayoutData(gridData);
}
public void run(){
display.asyncExec (new Runnable () {
public void run () {
try{
Runtime r = Runtime.getRuntime();
Process p = r.exec(cmd);
// Consommation de la sortie standard de l'application externe dans un Thread separe
try {
BufferedReader reader = new BufferedReader(new InputStreamReader(p.getInputStream()));
String line = "";
try {
while((line = reader.readLine()) != null) {
System.out.println(line);
/*
* Ici j'aimerai faire un :
* term.setText(line);
* mais ça ne marche pas
*/
}
} finally {
reader.close();
}
} catch(IOException ioe) {
ioe.printStackTrace();
}
} catch (Exception e){
System.err.println("Probleme"+e+": dans le lancement de StarGene avec la commande :"+cmd);
}
}
});
}
// Affiche la fenetre
private void ear(){ shell.open();
while (!shell.isDisposed())
if (!display.readAndDispatch())
display.sleep();
}
}
|