1 | package org.expeditee.actions;
|
---|
2 |
|
---|
3 | import java.awt.Color;
|
---|
4 | import java.io.BufferedReader;
|
---|
5 | import java.io.InputStreamReader;
|
---|
6 |
|
---|
7 | import org.expeditee.agents.WriteTree;
|
---|
8 | import org.expeditee.gui.DisplayIO;
|
---|
9 | import org.expeditee.gui.Frame;
|
---|
10 | import org.expeditee.gui.FrameGraphics;
|
---|
11 |
|
---|
12 | public 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 | }
|
---|