Ignore:
Timestamp:
05/01/08 12:26:53 (16 years ago)
Author:
ra33
Message:

New expeditee version

File:
1 edited

Legend:

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

    r4 r7  
    1313import org.expeditee.gui.FrameGraphics;
    1414import org.expeditee.gui.FrameIO;
     15import org.expeditee.gui.FrameKeyboardActions;
    1516import org.expeditee.gui.FrameMouseActions;
    1617import org.expeditee.gui.FrameUtils;
     
    1819import org.expeditee.items.Dot;
    1920import org.expeditee.items.Item;
     21import org.expeditee.items.ItemUtils;
    2022import org.expeditee.items.Line;
    2123import org.expeditee.items.Text;
     
    5961        };
    6062
    61         private static final String BREAK_TEXT = "exitrepeat";
    62 
    63         private static final String CONTINUE_TEXT = "nextrepeat";
     63        private static final String BREAK2_TEXT = "exitrepeat";
     64
     65        private static final String BREAK_TEXT = "break";
     66
     67        private static final String CONTINUE2_TEXT = "nextrepeat";
     68
     69        private static final String CONTINUE_TEXT = "continue";
    6470
    6571        private static final String RETURN_TEXT = "return";
     
    155161
    156162                FrameIO.SaveFrame(DisplayIO.getCurrentFrame(), false);
    157 
    158163                FrameGraphics.DisplayMessage("Starting test suite: " + frameset,
    159164                                Color.CYAN);
     
    229234
    230235        private static void FlagError(Item item) {
    231                 item.setColor(Color.CYAN);
     236                // item.setColor(Color.CYAN);
    232237                FrameUtils.DisplayFrame(item.getParent().getFrameName(), true);
     238                item.showHighlight(true, Color.CYAN);
    233239                FrameIO.SaveFrame(item.getParent());
    234240        }
     
    306312                Frame frame = i.getParent();
    307313
    308                 if (i == frame.getTitle() || i == frame.getName() || i.isAnnotation()) {
     314                if (i == frame.getTitle() || i == frame.getFrameNameItem() || i.isAnnotation()) {
    309315                        return false;
    310316                }
     
    319325         * @return
    320326         */
    321         private static String[] parseStatement(String statement) {
    322                 return statement.split(TOKEN_SEPARATOR);
     327        private static String[] parseStatement(Text code) throws Exception {
     328                String statement = code.getTextNoList();
     329                ArrayList<String> tokens = new ArrayList<String>();
     330
     331                for (int i = 0; i < statement.length(); i++) {
     332                        char c = statement.charAt(i);
     333                        // ignore spaces
     334                        if (c != ' ') {
     335                                int startOfToken = i;
     336                                if (c == '\"') {
     337                                        int endOfToken = statement.length() - 1;
     338                                        // find the end of the string literal
     339                                        while (statement.charAt(endOfToken) != '\"')
     340                                                endOfToken--;
     341                                        if (endOfToken > startOfToken) {
     342                                                tokens.add(statement.substring(startOfToken,
     343                                                                endOfToken + 1));
     344                                        } else {
     345                                                throw new Exception("Expected matching \" "
     346                                                                + code.toString());
     347                                        }
     348                                        break;
     349                                } else if (c == '#' || c == '/') {
     350                                        break;
     351                                } else {
     352                                        // read in a normal token
     353                                        while (++i < statement.length()
     354                                                        && statement.charAt(i) != ' ')
     355                                                ;
     356                                        tokens.add(statement.substring(startOfToken, i)
     357                                                        .toLowerCase());
     358                                }
     359                        }
     360                }
     361
     362                String[] a = new String[tokens.size()];
     363                a = tokens.toArray(a);
     364                code.setProcessedCode(a);
     365                return a;
    323366        }
    324367
     
    464507        private static Status RunItem(Text code, Context context,
    465508                        Status lastItemStatus) throws Exception {
    466                 String codeText = code.getTextNoList();
     509
     510                String[] tokens = code.getProcessedCode();
     511
     512                if (tokens == null) {
     513                        tokens = parseStatement(code);
     514                }
     515
    467516                // Comments without links are a no-op
    468                 if (codeText.startsWith("#") || codeText.startsWith("//")) {
     517                if (tokens.length == 0) {
    469518                        if (code.getLink() == null)
    470519                                return Status.OK;
     
    473522                }
    474523
    475                 // Now check for code statements
    476                 codeText = codeText.trim();
    477                 String[] tokens = parseStatement(codeText.toLowerCase());
    478524                // At present only set statements can have literals so they
    479525                // are the only statements that we have to worry about string
    480526                // literals
    481                 assert (tokens.length > 0);
    482527                if (tokens[0].equals("call") && tokens.length >= 2) {
    483528                        return Call(tokens, code, context);
     
    497542                                                // check for strings enclosed in quotes
    498543                                                if (tokens[2].startsWith("\"")) {
    499                                                         if (tokens[tokens.length - 1].endsWith("\"")) {
    500                                                                 context.getPrimitives().setValue(
    501                                                                                 tokens[1],
    502                                                                                 new SString(codeText.substring(codeText
    503                                                                                                 .indexOf("\"") + 1, codeText
    504                                                                                                 .length() - 1)));
    505                                                                 return Status.OK;
    506                                                         } else
    507                                                                 throw new Exception("Expected matching \" "
    508                                                                                 + code.toString());
     544                                                        context.getPrimitives().setValue(
     545                                                                        tokens[1],
     546                                                                        new SString(tokens[2].substring(1,
     547                                                                                        tokens[2].length() - 1)));
     548                                                        return Status.OK;
     549
    509550                                                        // set a literal
    510551                                                } else if (tokens.length == 3) {
     
    517558                                        throw new RuntimeException(e.getMessage());
    518559                                }
     560                        } else if (tokens[0].equals("setframevalue")) {
     561                                assertMinParametreCount(tokens, 4);
     562                                assertVariableType(tokens[1], 1, SPointer.framePrefix);
     563
     564                                // Get the attribute to be searched for on the target frame
     565                                Frame targetFrame = (Frame) context.getPointers().getVariable(
     566                                                tokens[1]).getValue();
     567                                String targetAttribute = context.getPrimitives()
     568                                                .getStringValue(tokens[2]).toLowerCase()
     569                                                + ":";
     570                                String value = context.getPrimitives()
     571                                                .getStringValue(tokens[3]);
     572                                Boolean found = false;
     573                                Text attributeItem = null;
     574                                Text valueItem = null;
     575                                // Begin the search
     576                                for (Text text : targetFrame.getBodyTextItems()) {
     577                                        String s = text.getTextNoList().toLowerCase();
     578                                        if (s.startsWith(targetAttribute)) {
     579                                                attributeItem = text;
     580                                                AttributeUtils.setSingleValue(attributeItem, value);
     581                                                found = true;
     582                                                break;
     583                                        }
     584                                }
     585                                // Keep looking for a matching value nearby if we found an
     586                                // attribute without the value in the same item
     587                                if (!found && attributeItem != null) {
     588                                        Point endPoint = attributeItem.getEndParagraphPosition();
     589
     590                                        for (Text text : targetFrame.getBodyTextItems()) {
     591                                                Point startPoint = text.getPosition();
     592                                                if (Math.abs(startPoint.y - endPoint.y) < 10
     593                                                                && Math.abs(startPoint.x - endPoint.x) < 20) {
     594                                                        found = true;
     595                                                        valueItem = text;
     596                                                        text.setText(value);
     597                                                        break;
     598                                                }
     599                                        }
     600                                }
     601
     602                                // Set the values of the output parametres
     603                                context.getPrimitives()
     604                                                .setValue(tokens[4], new SBoolean(found));
     605                                if (tokens.length > 5) {
     606                                        context.getPointers().setObject(tokens[5], attributeItem);
     607                                        if (tokens.length > 6) {
     608                                                context.getPointers().setObject(tokens[6], valueItem);
     609                                        }
     610                                }
     611
     612                                return Status.OK;
    519613                        } else if (tokens[0].startsWith("setitem")) {
    520614                                if (tokens[0].equals("setitemposition")) {
     
    651745                                        throw new UnitTestFailedException("null", value.toString());
    652746                                return Status.OK;
     747                        } else if (tokens[0].equals("assertnotnull")) {
     748                                assertExactParametreCount(tokens, 1);
     749                                Object value = context.getPrimitives().getVariable(tokens[1])
     750                                                .getValue();
     751                                if (value == null)
     752                                        throw new UnitTestFailedException("not null", "null");
     753                                return Status.OK;
     754                        } else if (tokens[0].equals("assertdefined")) {
     755                                assertExactParametreCount(tokens, 1);
     756                                if (!context.isDefined(tokens[1]))
     757                                        throw new UnitTestFailedException("defined", "not defined");
     758                                return Status.OK;
     759                        } else if (tokens[0].equals("assertnotdefined")) {
     760                                assertExactParametreCount(tokens, 1);
     761                                if (context.isDefined(tokens[1]))
     762                                        throw new UnitTestFailedException("defined", "not defined");
     763                                return Status.OK;
    653764                        } else if (tokens[0].equals("assertequals")) {
    654765                                assertExactParametreCount(tokens, 2);
     
    751862                                        context.getPrimitives().setValue(frameNameVar,
    752863                                                        frame.getFrameName());
     864                                        return Status.OK;
     865                                } else if (tokens[0].startsWith("getframefilepath")) {
     866                                        assertExactParametreCount(tokens, 2);
     867                                        String frameName = context.getPrimitives().getStringValue(
     868                                                        tokens[1]);
     869                                        String path = FrameIO.LoadFrame(frameName).path;
     870                                        String filePath = FrameIO.getFrameFullPathName(path,
     871                                                        frameName);
     872                                        context.getPrimitives().setValue(tokens[2], filePath);
    753873                                        return Status.OK;
    754874                                }
     
    862982                                                new SInteger(AgentStats.getMilliSecondsElapsed()));
    863983                                return Status.OK;
     984                        } else if (tokens[0].equals("getlastnumberinframeset")) {
     985                                String framesetNameVar = DEFAULT_STRING;
     986                                String countVar = DEFAULT_INTEGER;
     987                                if (tokens.length > 1) {
     988                                        assertMinParametreCount(tokens, 2);
     989                                        framesetNameVar = tokens[1];
     990                                        countVar = tokens[2];
     991                                }
     992                                String frameset = context.getPrimitives().getStringValue(
     993                                                framesetNameVar);
     994                                long count = FrameIO.getLastNumber(frameset);
     995                                context.getPrimitives().setValue(countVar, new SInteger(count));
     996                                return Status.OK;
     997                        } else if (tokens[0].equals("getlistofframesets")) {
     998                                String stringVar = DEFAULT_ITEM;
     999                                if (tokens.length > 1) {
     1000                                        assertMinParametreCount(tokens, 1);
     1001                                        stringVar = tokens[1];
     1002                                }
     1003                                context.getPrimitives().setValue(stringVar,
     1004                                                FrameIO.getFramesetList());
     1005                                return Status.OK;
    8641006                        }
    8651007                } else if (tokens[0].equals("or")) {
     
    9031045                                FrameGraphics.DisplayMessage(((Text) message).copy());
    9041046                        } catch (NullPointerException e) {
    905                                 // Just ignore not text items!
    9061047                                FrameGraphics.DisplayMessage("null");
    9071048                        } catch (ClassCastException e) {
     
    9141055                } else if (tokens[0].equals("messageln")
    9151056                                || tokens[0].equals("messageline")
     1057                                || tokens[0].equals("messagelnnospaces")
     1058                                || tokens[0].equals("messagelinenospaces")
    9161059                                || tokens[0].equals("errorln") || tokens[0].equals("errorline")) {
    917                         StringBuilder message = new StringBuilder();
    918                         if (tokens.length == 1) {
    919                                 message.append(context.getPrimitives().getVariable(
    920                                                 DEFAULT_STRING).stringValue()
    921                                                 + " ");
    922                         } else {
    923                                 for (int i = 1; i < tokens.length; i++) {
    924                                         if (Primitives.isPrimitive(tokens[i])) {
    925                                                 message.append(context.getPrimitives().getVariable(
    926                                                                 tokens[i]).stringValue()
    927                                                                 + " ");
    928                                         } else
    929                                                 throw new Exception("Illegal parametre: [" + tokens[i]
    930                                                                 + "] in line " + code.toString());
    931                                 }
    932                         }
     1060                        String message = getMessage(tokens, context, code.toString(),
     1061                                        tokens[0].endsWith("nospaces") ? "" : " ");
    9331062
    9341063                        if (tokens[0].equals("errorln") || tokens[0].equals("errorline"))
    935                                 FrameGraphics.ErrorMessage(message.toString());
     1064                                FrameGraphics.ErrorMessage(message);
    9361065                        else
    937                                 FrameGraphics.DisplayMessageAlways(message.toString());
     1066                                FrameGraphics.DisplayMessageAlways(message);
     1067                        return Status.OK;
     1068                } else if (tokens[0].equals("typein")
     1069                                || tokens[0].equals("typeinnospaces")) {
     1070
     1071                        String s = getMessage(tokens, context, code.toString(), tokens[0]
     1072                                        .equals("typein") ? " " : "");
     1073                        for (int i = 0; i < s.length(); i++) {
     1074                                FrameKeyboardActions.processChar(s.charAt(i));
     1075                                Thread.sleep(25);
     1076                        }
    9381077                        return Status.OK;
    9391078                } else if (tokens[0].startsWith("else")) {
     
    10151154                                                tokens[2]) <= 0;
    10161155                                parametres = 2;
     1156                        } else if (tokens[0].equals("ifexistingframe")) {
     1157                                result = FrameIO.DoesFrameExist(context.getPrimitives()
     1158                                                .getStringValue(tokens[1]));
     1159                        } else if (tokens[0].equals("ifexistingframeset")) {
     1160                                String framesetName = context.getPrimitives().getStringValue(
     1161                                                tokens[1]);
     1162                                result = FrameIO.DoesFramesetExist(framesetName);
    10171163                        } else {
    10181164                                // assertVariableType(variable, 1, SPointer.itemPrefix);
     
    11641310
    11651311                        return Status.OK;
     1312                } else if (tokens[0].equals("deleteitem")) {
     1313                        assertMinParametreCount(tokens, 1);
     1314                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     1315                        Item item = (Item) context.getPointers().getVariable(tokens[1])
     1316                                        .getValue();
     1317                        item.delete();
     1318                        return Status.OK;
     1319                } else if (tokens[0].equals("deleteframe")) {
     1320                        assertMinParametreCount(tokens, 1);
     1321                        assertVariableType(tokens[1], 1, SPointer.framePrefix);
     1322                        Frame frame = (Frame) context.getPointers().getVariable(tokens[1])
     1323                                        .getValue();
     1324                        boolean success = FrameIO.DeleteFrame(frame);
     1325
     1326                        if (tokens.length > 2) {
     1327                                context.getPrimitives().setValue(tokens[2],
     1328                                                new SBoolean(success));
     1329                        }
     1330
     1331                        return Status.OK;
     1332                } else if (tokens[0].equals("deleteframeset")) {
     1333                        assertMinParametreCount(tokens, 1);
     1334                        String framesetName = context.getPrimitives().getStringValue(
     1335                                        tokens[1]);
     1336                        boolean success = FrameIO.DeleteFrameset(framesetName);
     1337
     1338                        if (tokens.length > 2) {
     1339                                context.getPrimitives().setValue(tokens[2],
     1340                                                new SBoolean(success));
     1341                        }
     1342
     1343                        return Status.OK;
     1344                } else if (tokens[0].equals("copyitem")) {
     1345                        assertMinParametreCount(tokens, 2);
     1346                        assertVariableType(tokens[1],1,SPointer.itemPrefix);
     1347                        assertVariableType(tokens[2],2,SPointer.itemPrefix);
     1348                        Item item = (Item)context.getPointers().getVariable(tokens[1]).getValue();
     1349                        Item copy = item.copy();
     1350                        context.getPointers().setObject(tokens[2], copy);
     1351
     1352                        return Status.OK;
     1353                }else if (tokens[0].equals("copyframeset")) {
     1354                        assertMinParametreCount(tokens, 2);
     1355                        String framesetToCopy = context.getPrimitives().getStringValue(
     1356                                        tokens[1]);
     1357                        String copiedFrameset = context.getPrimitives().getStringValue(
     1358                                        tokens[2]);
     1359                        boolean success = FrameIO.CopyFrameset(framesetToCopy,
     1360                                        copiedFrameset);
     1361
     1362                        if (tokens.length > 3) {
     1363                                context.getPrimitives().setValue(tokens[3],
     1364                                                new SBoolean(success));
     1365                        }
     1366
     1367                        return Status.OK;
     1368                } else if (tokens[0].equals("copyframe")) {
     1369                        assertMinParametreCount(tokens, 2);
     1370                        assertVariableType(tokens[1],1,SPointer.framePrefix);
     1371                        assertVariableType(tokens[2],2,SPointer.framePrefix);
     1372                        Frame frameToCopy = (Frame) context.getPointers().getVariable(
     1373                                        tokens[1]).getValue();
     1374                        FrameIO.SuspendCache();
     1375                        Frame freshCopy = FrameIO.LoadFrame(frameToCopy.getFrameName());
     1376                        // Change the frameset if one was provided
     1377                        if (tokens.length > 3) {
     1378                                String destinationFrameset = context.getPrimitives()
     1379                                                .getStringValue(tokens[3]);
     1380                                freshCopy.setFrameset(destinationFrameset);
     1381                        }// Otherwise add it to the end of this frameset
     1382                        freshCopy.setFrameNumber(FrameIO.getLastNumber(freshCopy
     1383                                        .getFramesetName()) + 1);
     1384                        context.getPointers().setObject(tokens[2], freshCopy);
     1385                        String fileContents = FrameIO.ForceSaveFrame(freshCopy);
     1386                        boolean success = fileContents != null;
     1387                        FrameIO.ResumeCache();
     1388                        if (tokens.length > 4) {
     1389                                context.getPrimitives().setValue(tokens[4],
     1390                                                new SBoolean(success));
     1391                        }
     1392                        return Status.OK;
    11661393                } else if (tokens[0].equals("createframe")) {
    11671394
     
    12371464                                context.getPrimitives().setValue(nextCharVarName,
    12381465                                                new SCharacter(nextChar));
     1466
     1467                        return Status.OK;
     1468                } else if (tokens[0].equals("openreadfile")) {
     1469                        assertVariableType(tokens[1], 1, SString.prefix);
     1470                        assertVariableType(tokens[2], 2, SPointer.filePrefix);
     1471
     1472                        if (tokens.length > 3) {
     1473                                assertVariableType(tokens[3], 3, SBoolean.prefix);
     1474                                context.openReadFile(tokens[1], tokens[2], tokens[3]);
     1475                        } else
     1476                                context.openReadFile(tokens[1], tokens[2]);
     1477
     1478                        return Status.OK;
     1479                } else if (tokens[0].equals("readlinefile")
     1480                                || tokens[0].equals("readlnfile")) {
     1481                        assertVariableType(tokens[1], 1, SPointer.filePrefix);
     1482
     1483                        if (tokens.length > 3) {
     1484                                assertVariableType(tokens[3], 3, SBoolean.prefix);
     1485                                context.readLineFile(tokens[1], tokens[2], tokens[3]);
     1486                        } else
     1487                                context.readLineFile(tokens[1], tokens[2]);
     1488
     1489                        return Status.OK;
     1490                } else if (tokens[0].equals("readitemfile")) {
     1491                        assertVariableType(tokens[1], 1, SPointer.filePrefix);
     1492                        assertVariableType(tokens[2], 1, SPointer.itemPrefix);
     1493
     1494                        if (tokens.length > 3) {
     1495                                assertVariableType(tokens[3], 3, SBoolean.prefix);
     1496                                context.readItemFile(tokens[1], tokens[2], tokens[3]);
     1497                        } else
     1498                                context.readItemFile(tokens[1], tokens[2]);
    12391499
    12401500                        return Status.OK;
     
    12761536
    12771537                        return Status.OK;
     1538                } else if (tokens[0].equals("displayframeset")) {
     1539                        assertMinParametreCount(tokens, 1);
     1540                        String framesetName = context.getPrimitives().getStringValue(
     1541                                        tokens[1]);
     1542                        int lastFrameNo = FrameIO.getLastNumber(framesetName);
     1543                        int firstFrameNo = 0;
     1544                        double pause = 0.0;
     1545                        // get the first and last frames to display if they were proided
     1546                        if (tokens.length > 2) {
     1547                                firstFrameNo = (int) context.getPrimitives().getIntegerValue(
     1548                                                tokens[2]);
     1549                                if (tokens.length > 3) {
     1550                                        lastFrameNo = (int) context.getPrimitives()
     1551                                                        .getIntegerValue(tokens[3]);
     1552                                        if (tokens.length > 4) {
     1553                                                pause = context.getPrimitives().getDoubleValue(
     1554                                                                tokens[4]);
     1555                                        }
     1556                                }
     1557                        }
     1558                        // Display the frames
     1559                        String adjustedFramesetName = FrameUtils
     1560                                        .GetFramesetNameAdjusted(framesetName);
     1561                        for (int i = firstFrameNo; i <= lastFrameNo; i++) {
     1562                                Frame frame = FrameIO.LoadFrame(adjustedFramesetName + i);
     1563                                if (frame != null) {
     1564                                        double thisFramesPause = pause;
     1565                                        // check for change in delay for this frame only
     1566                                        Item pauseItem = ItemUtils.FindTag(frame.getItems(),
     1567                                                        "@DisplayFramePause:");
     1568                                        if (pauseItem != null) {
     1569                                                try {
     1570                                                        // attempt to read in the delay value
     1571                                                        thisFramesPause = Double.parseDouble(ItemUtils
     1572                                                                        .StripTag(
     1573                                                                                        ((Text) pauseItem).getFirstLine(),
     1574                                                                                        "@DisplayFramePause:"));
     1575                                                } catch (NumberFormatException nfe) {
     1576                                                }
     1577                                        }
     1578                                        DisplayIO.setCurrentFrame(frame);
     1579                                        pause(thisFramesPause);
     1580                                }
     1581                        }
     1582                        return Status.OK;
     1583                } else if (tokens[0].equals("createframeset")) {
     1584                        String framesetName = DEFAULT_STRING;
     1585                        String successVar = null;
     1586                        if (tokens.length > 1) {
     1587                                framesetName = tokens[1];
     1588                                if (tokens.length > 2)
     1589                                        successVar = tokens[2];
     1590                        }
     1591                        context.createFrameset(framesetName, successVar);
     1592                        return Status.OK;
    12781593                } else if (tokens[0].equals("concatstr")) {
    12791594                        assertMinParametreCount(tokens, 3);
     
    14361751                        }
    14371752
    1438                         double time = context.getPrimitives().getDoubleValue(lengthVar);
    1439                         for (int i = 0; i < time * 10; i++) {
    1440                                 Thread.yield();
    1441                                 Thread.sleep(100);
    1442                         }
     1753                        pause(context.getPrimitives().getDoubleValue(lengthVar));
    14431754                        return Status.OK;
    14441755                } else if (tokens[0].equals("glidecursorto")) {
     
    14731784                        Thread.sleep(milliseconds % timeInterval);
    14741785                        DisplayIO.setCursorPosition(finalX, finalY);
     1786                        return Status.OK;
     1787                } else if (tokens[0].equals("glideitemto")) {
     1788                        assertMinParametreCount(tokens, 3);
     1789                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     1790                        Item item = (Item) context.getPointers().getVariable(tokens[1])
     1791                                        .getValue();
     1792                        int finalX = (int) context.getPrimitives().getIntegerValue(
     1793                                        tokens[2]);
     1794                        int finalY = (int) context.getPrimitives().getIntegerValue(
     1795                                        tokens[3]);
     1796
     1797                        // DisplayIO.setCursorPosition(item.getX(), item.getY());
     1798                        // FrameMouseActions.pickup(item);
     1799
     1800                        int milliseconds = 1000;
     1801                        if (tokens.length > 4)
     1802                                milliseconds = (int) (context.getPrimitives().getDoubleValue(
     1803                                                tokens[4]) * 1000);
     1804
     1805                        int initialX = item.getX();
     1806                        int initialY = item.getY();
     1807                        // int initialX = DisplayIO.getMouseX();
     1808                        // int initialY = DisplayIO.getMouseY();
     1809
     1810                        final int timeInterval = 40;
     1811
     1812                        int deltaX = (int) (finalX - initialX);
     1813                        int deltaY = (int) (finalY - initialY);
     1814
     1815                        int intervals = milliseconds / timeInterval;
     1816                        for (double i = 0; i < intervals; i++) {
     1817                                int newX = initialX + (int) (deltaX * i / intervals);
     1818                                int newY = initialY + (int) (deltaY * i / intervals);
     1819                                Thread.yield();
     1820                                Thread.sleep(timeInterval);
     1821                                // DisplayIO.setCursorPosition(newX, newY);
     1822
     1823                                item.setPosition(newX, newY);
     1824                                DisplayIO.repaint();
     1825                        }
     1826                        // Thread.yield();
     1827                        Thread.sleep(milliseconds % timeInterval);
     1828                        item.setPosition(finalX, finalY);
     1829                        // DisplayIO.setCursorPosition(finalX, finalY);
     1830                        FrameMouseActions.anchor(item);
     1831                        Frame.FreeItems.clear();
     1832                        FrameGraphics.Repaint();
     1833                        // FrameMouseActions.updateCursor();
    14751834                        return Status.OK;
    14761835                }
     
    14871846                                        status = Status.OK;
    14881847                                return status;
    1489                         } else if (tokens[0].equals(CONTINUE_TEXT)) {
     1848                        } else if (tokens[0].equals(CONTINUE_TEXT)
     1849                                        || tokens[0].equals(CONTINUE2_TEXT)) {
    14901850                                return Status.Continue;
    1491                         } else if (tokens[0].equals(BREAK_TEXT)) {
     1851                        } else if (tokens[0].equals(BREAK_TEXT)
     1852                                        || tokens[0].equals(BREAK2_TEXT)) {
    14921853                                return Status.Break;
    14931854                        } else if (tokens[0].equals(RETURN_TEXT)) {
     
    15361897                                assertVariableType(tokens[1], 1, SPointer.filePrefix);
    15371898                                context.closeWriteFile(tokens[1]);
     1899
     1900                                return Status.OK;
     1901                        } else if (tokens[0].equals("closereadfile")) {
     1902                                assertVariableType(tokens[1], 1, SPointer.filePrefix);
     1903                                context.closeReadFile(tokens[1]);
    15381904
    15391905                                return Status.OK;
     
    15501916                        }
    15511917                } else if (tokens.length == 3) {
    1552                         if (tokens[0].equals("foreach")) {
     1918                        if (tokens[0].startsWith("foreach")) {
     1919                                Class itemType = Object.class;
     1920                                String type = tokens[0].substring("foreach".length());
     1921                                // Check the type of foreach loop
     1922                                // and set the item type to iterate over
     1923                                if (type.equals("dot")) {
     1924                                        itemType = Dot.class;
     1925                                } else if (type.equals("text")) {
     1926                                        itemType = Text.class;
     1927                                } else if (type.equals("line")) {
     1928                                        itemType = Line.class;
     1929                                }
     1930
    15531931                                assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    15541932                                assertVariableType(tokens[2], 2, SPointer.framePrefix);
     
    15561934                                                tokens[2]).getValue();
    15571935                                // Create the ip variable
     1936                                Item frameName = currFrame.getFrameNameItem();
     1937                                Item frameTitle = currFrame.getTitle();
     1938
    15581939                                for (Item i : currFrame.getItems()) {
     1940                                        if (i == frameName || i == frameTitle)
     1941                                                continue;
     1942                                        if (!(itemType.isInstance(i)))
     1943                                                continue;
     1944
    15591945                                        context.getPointers().setObject(tokens[1], i);
    15601946                                        Status status = RunFrameAndReportError(code, context);
    15611947                                        // check if we need to exit this loop because of
    1562                                         // statements in
    1563                                         // the code that was run
     1948                                        // statements in the code that was run
    15641949                                        if (status == Status.Exit || status == Status.Return)
    15651950                                                return status;
     
    16332018        }
    16342019
     2020        private static void pause(double time) throws Exception {
     2021                for (int i = 0; i < time * 10; i++) {
     2022                        Thread.yield();
     2023                        Thread.sleep(100);
     2024                }
     2025        }
     2026
    16352027        public static int countCharsInString(String s, String pattern) {
    16362028                String newString = s;
     
    16682060                        throw new IncorrectParametreCountException(parametreCount);
    16692061        }
     2062
     2063        private static String getMessage(String[] tokens, Context context,
     2064                        String code, String separator) throws Exception {
     2065                StringBuilder message = new StringBuilder();
     2066                if (tokens.length == 1) {
     2067                        message.append(context.getPrimitives().getVariable(DEFAULT_STRING)
     2068                                        .stringValue());
     2069                } else {
     2070                        for (int i = 1; i < tokens.length; i++) {
     2071                                if (Primitives.isPrimitive(tokens[i])) {
     2072                                        message.append(context.getPrimitives().getVariable(
     2073                                                        tokens[i]).stringValue()
     2074                                                        + separator);
     2075                                } else
     2076                                        throw new Exception("Illegal parametre: [" + tokens[i]
     2077                                                        + "] in line " + code);
     2078                        }
     2079                }
     2080                return message.toString();
     2081        }
    16702082}
Note: See TracChangeset for help on using the changeset viewer.