Changeset 439
- Timestamp:
- 02/10/12 11:30:49 (12 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Simple.java
r429 r439 15 15 import java.util.Random; 16 16 import java.util.regex.Pattern; 17 18 import junit.framework.Assert; 19 20 import org.expeditee.actions.Misc; 17 21 18 22 import org.expeditee.agents.Agent; … … 321 325 throw new RuntimeException(frameset + " failed"); 322 326 } 327 323 328 } 324 329 325 330 } 326 331 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, 328 334 boolean acceptKeyboardInput, boolean step, int pause, Color color) { 329 335 try { … … 370 376 RunFrame(frame, current, acceptKeyboardInput, false, 0, null); 371 377 } 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 } 372 391 373 392 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){ 374 403 RunFrame(frame, current, false); 375 404 } … … 658 687 // This makes the call and signature tokens counts match 659 688 String procedureTitle = procedure.getTitleItem().getFirstLine(); 689 660 690 if (!procedureTitle.toLowerCase().startsWith("call ")) 661 691 procedureTitle = "call " + procedureTitle; … … 802 832 // Check if the user wants to display a message 803 833 // Check for set statements 804 } else if (tokens[0].startsWith("calculatestring")) { 834 } 835 else if (tokens[0].startsWith("calculatestring")) { 805 836 assertMinParametreCount(tokens, 1); 806 837 String toCalculate = context.getPrimitives().getStringValue( … … 814 845 Node equation = myParser.parse(toCalculate); 815 846 String value = myParser.evaluate(equation, false); 847 816 848 // Add a new variable if its an assignment statement 817 849 String newVar = SReal.prefix + myParser.getNewVariable(); … … 1141 1173 .stringValue()); 1142 1174 } else if (tokens[0].equals("setitemdata")) { 1175 1143 1176 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 1144 1177 // assertPrimitiveType(tokens[2], 2); 1145 1178 Item item = (Item) context.getPointers().getVariable( 1146 1179 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 1149 1185 } else if (tokens[0].equals("setitemaction")) { 1150 1186 assertVariableType(tokens[1], 1, SPointer.itemPrefix); … … 1172 1208 item.setColor((Color) Conversion.Convert(Color.class, 1173 1209 stringColor, item.getColor())); 1210 1174 1211 } else if (tokens[0].equals("setitemtext")) { 1175 1212 assertVariableType(tokens[1], 1, SPointer.itemPrefix); … … 1180 1217 tokens[1]).getValue(); 1181 1218 textItem.setText(newText, true); 1182 } else 1219 } 1220 else 1183 1221 throw new Exception("Unsupported setItem command: " 1184 1222 + code.toString()); … … 1289 1327 Navigation.Goto(frameName); 1290 1328 } else if (tokens[0].startsWith("get")) { 1291 if (tokens[0].startsWith("getframe")) {1329 else if (tokens[0].startsWith("getframe")) { 1292 1330 if (tokens[0].equals("getframevalue")) { 1293 1331 assertMinParametreCount(tokens, 3); … … 1460 1498 } 1461 1499 } 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")) { 1463 1535 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 1474 1584 } else if (tokens[0].equals("getitemthickness")) { 1475 1585 assertVariableType(tokens[1], 1, SPointer.itemPrefix); … … 1486 1596 context.getPrimitives().setValue(tokens[2], 1487 1597 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")) { 1489 1609 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 1490 1610 // assertPrimitiveType(tokens[2], 2); … … 1518 1638 context.getPrimitives().setValue(tokens[2], 1519 1639 new SString(action)); 1520 } else if (tokens[0].equals("getitemfillcolor")) { 1640 } 1641 else if (tokens[0].equals("getitemfillcolor")) { 1521 1642 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 1522 1643 // assertPrimitiveType(tokens[2], 2); … … 1543 1664 context.getPrimitives().setValue(tokens[2], 1544 1665 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 1545 1672 } else 1546 1673 throw new Exception("Unsupported getItem command: " … … 2716 2843 assertVariableType(tokens[1], 1, SPointer.filePrefix); 2717 2844 context.closeReadFile(tokens[1]); 2718 } else if (tokens[0].startsWith("foreach")) { 2845 } 2846 2847 else if (tokens[0].startsWith("foreach")) { 2719 2848 if (tokens[0].equals("foreachassociation")) { 2720 2849 assertExactParametreCount(tokens, 3); … … 2736 2865 break; 2737 2866 } 2738 } else { 2867 } 2868 else { 2739 2869 Class itemType = Object.class; 2740 2870 String type = tokens[0].substring("foreach".length()); … … 2782 2912 int y = (int) context.getPrimitives().getIntegerValue(tokens[2]); 2783 2913 DisplayIO.setCursorPosition(x, y); 2914 2915 2784 2916 } else { 2785 2917 // Check the available actions
Note:
See TracChangeset
for help on using the changeset viewer.