source: trunk/src/org/expeditee/actions/IDE.java@ 80

Last change on this file since 80 was 80, checked in by ra33, 16 years ago

Added some more unit tests
Did a bunch of refactoring
AND added a few new features... @b @v were the most significant

File size: 2.0 KB
Line 
1package org.expeditee.actions;
2
3import java.awt.Color;
4import java.io.BufferedReader;
5import java.io.InputStreamReader;
6
7import org.expeditee.agents.WriteTree;
8import org.expeditee.gui.DisplayIO;
9import org.expeditee.gui.Frame;
10import org.expeditee.gui.FrameGraphics;
11
12public class IDE {
13 public static void CompileClass() {
14 Frame source = DisplayIO.getCurrentFrame();
15 String title = source.getTitleItem().getText();
16 String[] tokens = title.split(" ");
17 String className = tokens[tokens.length - 1];
18 String fileName = "expeditee/src/" + className + ".java";
19 WriteTree wt = new WriteTree("java", fileName);
20 if (wt.initialise(source)) {
21 wt.setStartFrame(source);
22 wt.run();
23 try {
24 Runtime.getRuntime().exec("javac -d expeditee/bin " + fileName);
25 FrameGraphics.DisplayMessage("Compiled " + fileName, Color.darkGray);
26 } catch (Exception e) {
27 FrameGraphics.ErrorMessage("Could not compile class!");
28 }
29 } else {
30 FrameGraphics.ErrorMessage("Could not initialise agent!");
31 }
32 }
33
34 public static String getClassName(Frame source) {
35 return source.getTitleItem().getText().trim();
36 //String title = source.getTitle().getTextNoList();
37 //String[] tokens = title.split(" ");
38 //return tokens[tokens.length - 1];
39 }
40
41 public static void RunClass() {
42 Frame source = DisplayIO.getCurrentFrame();
43 String className = getClassName(source);
44 try {
45 Process p = Runtime.getRuntime().exec("java -cp expeditee/bin " + className);
46 BufferedReader stdInput = new BufferedReader(new InputStreamReader(
47 p.getInputStream()));
48 BufferedReader stdError = new BufferedReader(new InputStreamReader(
49 p.getErrorStream()));
50 String message = "";
51 while ((message = stdInput.readLine()) != null) {
52 FrameGraphics.DisplayMessage(message);
53 }
54 while ((message = stdError.readLine()) != null) {
55 FrameGraphics.ErrorMessage(message);
56 }
57 } catch (Exception e) {
58 FrameGraphics.ErrorMessage("Could not run class!");
59 }
60 }
61
62 public static void CompileAndRunClass() {
63 CompileClass();
64 RunClass();
65 }
66}
Note: See TracBrowser for help on using the repository browser.