Changeset 439


Ignore:
Timestamp:
02/10/12 11:30:49 (12 years ago)
Author:
davidb
Message:

Hooks to link Simple to the additional actions added:

getItemAtPosition and getItemContainingData

File:
1 edited

Legend:

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

    r429 r439  
    1515import java.util.Random;
    1616import java.util.regex.Pattern;
     17
     18import junit.framework.Assert;
     19
     20import org.expeditee.actions.Misc;
    1721
    1822import org.expeditee.agents.Agent;
     
    321325                                throw new RuntimeException(frameset + " failed");
    322326                        }
     327                       
    323328                }
    324329
    325330        }
    326331
    327         private static void RunFrame(Frame frame, Text current,
     332        //Have changed parameters, so it takes an Item, not just a Text item.
     333        private static void RunFrame(Frame frame, Item current,
    328334                        boolean acceptKeyboardInput, boolean step, int pause, Color color) {
    329335                try {
     
    370376                RunFrame(frame, current, acceptKeyboardInput, false, 0, null);
    371377        }
     378       
     379        /**
     380         * Same as RunFrame method above, except that it takes in
     381         * any Item, not just a Text item. -kgas1
     382         * @param frame - frame to run
     383         * @param current - item selected
     384         * @param acceptKeyboardInput
     385         */
     386        public static void RunFrame(Frame frame, Item current,
     387                        boolean acceptKeyboardInput){
     388                RunFrame(frame, current, acceptKeyboardInput, false, 0, null);
     389               
     390        }
    372391
    373392        public static void RunFrame(Frame frame, Text current) {
     393                RunFrame(frame, current, false);
     394        }
     395       
     396        /**
     397         * Same as runframe method above, except it takes
     398         * any Item as a parameter; not just Text Items. -kgas1
     399         * @param frame
     400         * @param current
     401         */
     402        public static void RunFrame(Frame frame, Item current){
    374403                RunFrame(frame, current, false);
    375404        }
     
    658687                // This makes the call and signature tokens counts match
    659688                String procedureTitle = procedure.getTitleItem().getFirstLine();
     689               
    660690                if (!procedureTitle.toLowerCase().startsWith("call "))
    661691                        procedureTitle = "call " + procedureTitle;
     
    802832                        // Check if the user wants to display a message
    803833                        // Check for set statements
    804                 } else if (tokens[0].startsWith("calculatestring")) {
     834                }
     835                else if (tokens[0].startsWith("calculatestring")) {
    805836                        assertMinParametreCount(tokens, 1);
    806837                        String toCalculate = context.getPrimitives().getStringValue(
     
    814845                                Node equation = myParser.parse(toCalculate);
    815846                                String value = myParser.evaluate(equation, false);
     847                               
    816848                                // Add a new variable if its an assignment statement
    817849                                String newVar = SReal.prefix + myParser.getNewVariable();
     
    11411173                                                        .stringValue());
    11421174                                } else if (tokens[0].equals("setitemdata")) {
     1175                                       
    11431176                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    11441177                                        // assertPrimitiveType(tokens[2], 2);
    11451178                                        Item item = (Item) context.getPointers().getVariable(
    11461179                                                        tokens[1]).getValue();
    1147                                         item.setData(context.getPrimitives().getVariable(tokens[2])
    1148                                                         .stringValue());
     1180                                       
     1181                                        item.setData(context.getPrimitives().getVariable(tokens[2]).stringValue());
     1182                                        //TODO: should there be a difference between setting and appending??
     1183                                        //item.addToData(context.getPrimitives().getVariable(tokens[2]).stringValue());
     1184                                       
    11491185                                } else if (tokens[0].equals("setitemaction")) {
    11501186                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     
    11721208                                        item.setColor((Color) Conversion.Convert(Color.class,
    11731209                                                        stringColor, item.getColor()));
     1210                                       
    11741211                                } else if (tokens[0].equals("setitemtext")) {
    11751212                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     
    11801217                                                        tokens[1]).getValue();
    11811218                                        textItem.setText(newText, true);
    1182                                 } else
     1219                                }
     1220                                else
    11831221                                        throw new Exception("Unsupported setItem command: "
    11841222                                                        + code.toString());
     
    12891327                        Navigation.Goto(frameName);
    12901328                } else if (tokens[0].startsWith("get")) {
    1291                         if (tokens[0].startsWith("getframe")) {
     1329                                else if (tokens[0].startsWith("getframe")) {
    12921330                                if (tokens[0].equals("getframevalue")) {
    12931331                                        assertMinParametreCount(tokens, 3);
     
    14601498                                }
    14611499                        } else if (tokens[0].startsWith("getitem")) {
    1462                                 if (tokens[0].equals("getitemposition")) {
     1500                               
     1501                                //used to return an item containing a particular piece of data.
     1502                        if(tokens[0].equals("getitemcontainingdata")) {
     1503                               
     1504                                assertVariableType(tokens[1],1,SPointer.itemPrefix);
     1505               
     1506                String data;
     1507                Item getItem;
     1508                String getFrameName;
     1509               
     1510                if(tokens.length == 3) {
     1511                    data = context.getPrimitives().getVariable(tokens[2]).stringValue();
     1512                   
     1513                    //no frame specified by user so use current frame.
     1514                    getFrameName = DisplayIO.getCurrentFrame().getName();
     1515                    getItem = Misc.getItemContainingData(data, FrameUtils.getFrame(getFrameName));
     1516                }
     1517                else if(tokens.length == 4) {
     1518                   
     1519                        getFrameName = context.getPrimitives().getStringValue(tokens[2]);
     1520                    data = context.getPrimitives().getVariable(tokens[3]).stringValue();
     1521                    getItem = Misc.getItemContainingData(data, FrameUtils.getFrame(getFrameName));
     1522                }
     1523                else {
     1524                    getItem = null;
     1525                }
     1526               
     1527                context.getPointers().setObject(tokens[1], getItem);
     1528               
     1529                // System.out.println(getItem.getText());
     1530                               
     1531                        }       //used to get an item at a specified position,
     1532                        //will lessen the amount of looping and if statements
     1533                        //I have to do when writing SIMPLE code - kgas1 23/01/2012
     1534                        else if(tokens[0].equals("getitematposition")) {
    14631535                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    1464                                         // assertPrimitiveType(tokens[2], 2);
    1465                                         // assertPrimitiveType(tokens[3], 3);
    1466                                         Point pos = ((Item) context.getPointers().getVariable(
    1467                                                         tokens[1]).getValue()).getPosition();
    1468                                         Integer x = pos.x;
    1469                                         Integer y = pos.y;
    1470                                         context.getPrimitives()
    1471                                                         .setValue(tokens[2], new SInteger(x));
    1472                                         context.getPrimitives()
    1473                                                         .setValue(tokens[3], new SInteger(y));
     1536                                       
     1537                                        Integer x;
     1538                                        Integer y;
     1539                                        Item getItem;
     1540                                        String getFrameName;
     1541       
     1542                                        //use 3 parameter version.
     1543                                        if(tokens.length == 4)
     1544                                        {
     1545                                                x = context.getPrimitives()
     1546                                                                .getVariable(tokens[2]).integerValue().intValue();
     1547                                                y = context.getPrimitives()
     1548                                                                .getVariable(tokens[3]).integerValue().intValue();
     1549                                               
     1550                                                //no frame specified by user so use current frame.
     1551                                                getFrameName = DisplayIO.getCurrentFrame().getName();
     1552                                                getItem = Misc.getItemAtPosition(x, y, FrameUtils.getFrame(getFrameName));
     1553                                        }
     1554                                        else if(tokens.length == 5)     //use 4 parameter version.
     1555                                        {
     1556                                                getFrameName = context.getPrimitives()
     1557                                                                .getStringValue(tokens[2]);
     1558                                                x = context.getPrimitives()
     1559                                                                .getVariable(tokens[3]).integerValue().intValue();
     1560                                                y = context.getPrimitives()
     1561                                                                .getVariable(tokens[4]).integerValue().intValue();
     1562                                               
     1563                                                getItem = Misc.getItemAtPosition(x, y, FrameUtils.getFrame(getFrameName));
     1564                                        }
     1565                                        else {
     1566                                                getItem = null;
     1567                                        }
     1568                                       
     1569                                        context.getPointers().setObject(tokens[1], getItem);
     1570                                }                               
     1571                                else if (tokens[0].equals("getitemposition")) {
     1572                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     1573
     1574                                                Point pos = ((Item) context.getPointers().getVariable(
     1575                                                                tokens[1]).getValue()).getPosition();
     1576                                                Integer x = pos.x;
     1577                                                Integer y = pos.y;
     1578                                                context.getPrimitives()
     1579                                                                .setValue(tokens[2], new SInteger(x));
     1580                                                context.getPrimitives()
     1581                                                                .setValue(tokens[3], new SInteger(y));
     1582                                                               
     1583                                       
    14741584                                } else if (tokens[0].equals("getitemthickness")) {
    14751585                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     
    14861596                                        context.getPrimitives().setValue(tokens[2],
    14871597                                                        new SInteger(width));
    1488                                 } else if (tokens[0].equals("getitemsize")) {
     1598                                } else if(tokens[0].equals("getitemheight")) {
     1599                                        //added in by kgas1
     1600                                       
     1601                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     1602                                       
     1603                                        Integer height = ((Item) context.getPointers().getVariable(
     1604                                                        tokens[1]).getValue()).getHeight();
     1605                                        context.getPrimitives().setValue(tokens[2],
     1606                                                        new SInteger(height));
     1607                                }                               
     1608                                else if (tokens[0].equals("getitemsize")) {
    14891609                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    14901610                                        // assertPrimitiveType(tokens[2], 2);
     
    15181638                                        context.getPrimitives().setValue(tokens[2],
    15191639                                                        new SString(action));
    1520                                 } else if (tokens[0].equals("getitemfillcolor")) {
     1640                                }
     1641                                else if (tokens[0].equals("getitemfillcolor")) {
    15211642                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
    15221643                                        // assertPrimitiveType(tokens[2], 2);
     
    15431664                                        context.getPrimitives().setValue(tokens[2],
    15441665                                                        new SString(item.getText()));
     1666                                } else if(tokens[0].equals("getitemid")) {
     1667                                        assertVariableType(tokens[1], 1, SPointer.itemPrefix);
     1668                                        Item item = ((Item) context.getPointers().getVariable(
     1669                                                        tokens[1]).getValue());
     1670                                        context.getPrimitives().setValue(tokens[2], new SInteger(item.getID()));                                                       
     1671                                       
    15451672                                } else
    15461673                                        throw new Exception("Unsupported getItem command: "
     
    27162843                        assertVariableType(tokens[1], 1, SPointer.filePrefix);
    27172844                        context.closeReadFile(tokens[1]);
    2718                 } else if (tokens[0].startsWith("foreach")) {
     2845                }
     2846
     2847                else if (tokens[0].startsWith("foreach")) {
    27192848                        if (tokens[0].equals("foreachassociation")) {
    27202849                                assertExactParametreCount(tokens, 3);
     
    27362865                                                break;
    27372866                                }
    2738                         } else {
     2867                        }
     2868                        else {
    27392869                                Class itemType = Object.class;
    27402870                                String type = tokens[0].substring("foreach".length());
     
    27822912                        int y = (int) context.getPrimitives().getIntegerValue(tokens[2]);
    27832913                        DisplayIO.setCursorPosition(x, y);
     2914                       
     2915                       
    27842916                } else {
    27852917                        // Check the available actions
Note: See TracChangeset for help on using the changeset viewer.