Ignore:
Timestamp:
05/16/08 10:25:28 (16 years ago)
Author:
ra33
Message:

A whole day of big changes.
Adding the ability to have Text at the end of Lines.
Also a lot of refactoring to improve the quality of code relating to constraints and lines

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/actions/Simple.java

    r42 r50  
    99import java.util.LinkedList;
    1010import java.util.List;
     11import java.util.Random;
    1112
    1213import org.expeditee.agents.DisplayTree;
     
    2627import org.expeditee.items.Line;
    2728import org.expeditee.items.Text;
     29import org.expeditee.items.Item.SelectedMode;
    2830import org.expeditee.simple.BelowMinParametreCountException;
    2931import org.expeditee.simple.Context;
     
    206208                        }
    207209                }
    208 
     210                // The statement below assumes there are no other programs running at
     211                // the same time
     212                assert (_programsRunning == 0);
    209213                // Report the number of test passed and failed
    210214                FrameGraphics.DisplayMessage("Total tests: "
     
    239243
    240244        private static void FlagError(Item item) {
    241                 // item.setColor(Color.CYAN);
    242245                FrameUtils.DisplayFrame(item.getParent().getFrameName(), true);
     246                item.setSelectedMode(SelectedMode.Normal);
    243247                item.setSelectionColor(Color.CYAN);
    244248                FrameIO.SaveFrame(item.getParent());
     
    349353                                                                endOfToken + 1));
    350354                                        } else {
    351                                                 throw new Exception("Expected matching \" "
    352                                                                 + code.toString());
     355                                                throw new RuntimeException("Expected matching \" ");
    353356                                        }
    354357                                        break;
     
    745748                                        throw new UnitTestFailedException("false", "true");
    746749                                return Status.OK;
     750                        }
     751                        if (tokens[0].equals("assertfail")) {
     752                                assertExactParametreCount(tokens, 0);
     753                                throw new UnitTestFailedException("pass", "fail");
    747754                        } else if (tokens[0].equals("assertnull")) {
    748755                                assertExactParametreCount(tokens, 1);
     
    10421049
    10431050                                return Status.OK;
     1051                        } else if (tokens[0].equals("getrandominteger")) {
     1052                                assertExactParametreCount(tokens, 3);
     1053                                int lowerBound = (int) context.getPrimitives().getIntegerValue(
     1054                                                tokens[1]);
     1055                                int upperBound = (int) context.getPrimitives().getIntegerValue(
     1056                                                tokens[2]);
     1057                                Random random = new Random();
     1058                                long result = Math.abs(random.nextInt())
     1059                                                % (upperBound - lowerBound) + lowerBound;
     1060                                context.getPrimitives().setValue(tokens[3],
     1061                                                new SInteger(result));
     1062                                return Status.OK;
     1063                        } else if (tokens[0].equals("getrandomreal")) {
     1064                                assertExactParametreCount(tokens, 3);
     1065                                double lowerBound = context.getPrimitives().getDoubleValue(
     1066                                                tokens[1]);
     1067                                double upperBound = context.getPrimitives().getDoubleValue(
     1068                                                tokens[2]);
     1069                                Random random = new Random();
     1070                                double result = random.nextDouble() * (upperBound - lowerBound)
     1071                                                + lowerBound;
     1072                                context.getPrimitives().setValue(tokens[3], new SReal(result));
     1073                                return Status.OK;
     1074                        } else if (tokens[0].equals("getrandomtextitem")) {
     1075                                assertExactParametreCount(tokens, 2);
     1076                                assertVariableType(tokens[1], 1, SPointer.framePrefix);
     1077                                assertVariableType(tokens[2], 2, SPointer.itemPrefix);
     1078                                List<Text> items = ((Frame) context.getPointers().getVariable(
     1079                                                tokens[1]).getValue()).getBodyTextItems(false);
     1080                                Random random = new Random();
     1081                                int itemIndex = random.nextInt(items.size());
     1082                                context.getPointers()
     1083                                                .setObject(tokens[2], items.get(itemIndex));
     1084                                return Status.OK;
    10441085                        }
    10451086                } else if (tokens[0].equals("or")) {
     
    11361177                        String command = getMessage(tokens, context, code.toString(), " ",
    11371178                                        1);
    1138                         Process p = Runtime.getRuntime().exec(command);
    1139                         FrameGraphics.DisplayMessage(command, Color.darkGray);
    1140                        
    1141                         BufferedReader stdInput = new BufferedReader(new InputStreamReader(
    1142                                         p.getInputStream()));
    1143                         BufferedReader stdError = new BufferedReader(new InputStreamReader(
    1144                                         p.getErrorStream()));
    1145                         String message = "";
    1146                         while ((message = stdInput.readLine()) != null) {
    1147                                 FrameGraphics.DisplayMessage(message);
    1148                         }
    1149                         while ((message = stdError.readLine()) != null) {
    1150                                 FrameGraphics.ErrorMessage(message);
     1179                        try {
     1180                                Process p = Runtime.getRuntime().exec(command);
     1181                                FrameGraphics.DisplayMessage(command, Color.darkGray);
     1182
     1183                                BufferedReader stdInput = new BufferedReader(
     1184                                                new InputStreamReader(p.getInputStream()));
     1185                                BufferedReader stdError = new BufferedReader(
     1186                                                new InputStreamReader(p.getErrorStream()));
     1187                                String message = "";
     1188                                while ((message = stdInput.readLine()) != null) {
     1189                                        FrameGraphics.DisplayMessage(message);
     1190                                }
     1191                                while ((message = stdError.readLine()) != null) {
     1192                                        FrameGraphics.ErrorMessage(message);
     1193                                }
     1194                        } catch (Exception e) {
     1195                                throw new RuntimeException(e.getMessage());
    11511196                        }
    11521197                        return Status.OK;
     
    16661711                                        DisplayIO.setCurrentFrame(frame);
    16671712                                        pause(thisFramesPause);
    1668                                        
     1713
    16691714                                        long freeMemory = runtime.freeMemory();
    1670                                         if(freeMemory < DisplayTree.GARBAGE_COLLECTION_THRESHOLD){
     1715                                        if (freeMemory < DisplayTree.GARBAGE_COLLECTION_THRESHOLD) {
    16711716                                                runtime.gc();
    1672                                                 FrameGraphics.DisplayMessage("Force Garbage Collection!");
     1717                                                FrameGraphics
     1718                                                                .DisplayMessage("Force Garbage Collection!");
    16731719                                        }
    16741720                                }
     
    16931739                        String fileName = context.getPrimitives().getStringValue(tokens[3]);
    16941740                        WriteTree wt = new WriteTree(format, fileName);
    1695                         if (wt.initialise(source)){
     1741                        if (wt.initialise(source)) {
    16961742                                wt.setStartFrame(source);
    16971743                                wt.run();
Note: See TracChangeset for help on using the changeset viewer.