Changeset 87
- Timestamp:
- 06/05/08 17:05:48 (16 years ago)
- Location:
- trunk
- Files:
-
- 1 added
- 10 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Misc.java
r86 r87 270 270 Frame current = DisplayIO.getCurrentFrame(); 271 271 Item text = current.getStatsTextItem(itemText); 272 text.setSelectedMode(Item.SelectedMode.Normal); 273 text.setSelectedMode(Item.SelectedMode.None); 272 274 FrameMouseActions.pickup(text); 273 275 FrameGraphics.Repaint(); -
trunk/src/org/expeditee/actions/Simple.java
r86 r87 32 32 import org.expeditee.items.Text; 33 33 import org.expeditee.items.Item.SelectedMode; 34 import org.expeditee.simple.AboveMaxParametreCountException; 34 35 import org.expeditee.simple.BelowMinParametreCountException; 35 36 import org.expeditee.simple.Context; … … 116 117 private static boolean _step; 117 118 118 private static int _stepPause = 0;119 private static int _stepPause = -1; 119 120 120 121 private static Color _stepColor; … … 123 124 124 125 public static void KeyStroke(char c) { 125 126 127 126 _KeyStrokes.add(c); 128 127 } … … 180 179 181 180 public static void RunSimpleTests(String frameset) { 182 RunSimpleTests(frameset, false );181 RunSimpleTests(frameset, false, true); 183 182 } 184 183 185 184 public static void RunSimpleTestsVerbose(String frameset) { 186 RunSimpleTests(frameset, true );185 RunSimpleTests(frameset, true, true); 187 186 } 188 187 … … 197 196 198 197 public void run() { 198 runSuite(); 199 } 200 201 public boolean runSuite() { 199 202 int testsPassed = 0; 200 203 int testsFailed = 0; … … 222 225 continue; 223 226 if (actions.get(0).toLowerCase().equals("runframe")) { 227 boolean passed = true; 228 String errorMessage = null; 224 229 try { 225 230 title.setLink(nextFrameName); … … 232 237 RunFrameAndReportError(title, new Context()); 233 238 _programsRunning--; 239 // if the throws exception annotation is on the frame then 240 // it passes only if an exception is thrown 241 if (title.getParentOrCurrentFrame().getThrowsException()) { 242 errorMessage = "Expected exception " + title.toString(); 243 passed = false; 244 } 245 } catch (Exception e) { 246 _programsRunning--; 247 if (!title.getParentOrCurrentFrame().getThrowsException()) { 248 errorMessage = e.getMessage(); 249 passed = false; 250 } 251 } 252 if (passed) { 234 253 if (_verbose) 235 254 FrameGraphics.DisplayMessage("Test passed: " 236 255 + title.toString(), Item.GREEN); 237 256 testsPassed++; 238 } catch (Exception e){257 } else { 239 258 testsFailed++; 240 _programsRunning--;241 259 // Print out the reason for failed tests 242 FrameGraphics.LinkedErrorMessage(e .getMessage());260 FrameGraphics.LinkedErrorMessage(errorMessage); 243 261 if (Simple._stop) { 244 262 Simple._stop = false; 245 return ;263 return false; 246 264 } 247 265 } … … 260 278 // Remove items from the cursor... 261 279 Frame.FreeItems.clear(); 262 } 263 264 public static void RunSimpleTests(String frameset, boolean verbose) { 280 281 return testsFailed == 0; 282 } 283 284 /** 285 * Runs a suite of tests stored in a given frameset. 286 * 287 * @param frameset 288 * @param verbose 289 * @param newThread 290 * false if tests should be run on the current frame 291 */ 292 public static void RunSimpleTests(String frameset, boolean verbose, 293 boolean newThread) { 265 294 _stop = false; 266 Thread t = new Thread(new Simple(frameset, verbose)); 267 t.setPriority(Thread.MIN_PRIORITY); 268 t.start(); 295 Simple testSuite = new Simple(frameset, verbose); 296 if (newThread) { 297 Thread t = new Thread(testSuite); 298 t.setPriority(Thread.MIN_PRIORITY); 299 t.start(); 300 } else { 301 assert (testSuite.runSuite()); 302 } 303 269 304 } 270 305 … … 290 325 _KeyStrokes.clear(); 291 326 292 _programsRunning++;293 327 Thread t = new Thread(current); 294 328 t.setPriority(Thread.MIN_PRIORITY); 295 329 t.start(); 296 // _programsRunning--;297 330 } catch (Exception e) { 298 // _programsRunning--;299 331 } 300 332 } … … 330 362 331 363 public static void DebugFrame(Item current) { 332 DebugFrame(current, 0.2, null);364 DebugFrame(current, -1.0, null); 333 365 } 334 366 … … 370 402 } 371 403 372 // loop through non-title, non-name, non-annotationtext items373 List<Text> body = child.getBodyTextItems( false);404 // loop through non-title, non-name, text items 405 List<Text> body = child.getBodyTextItems(true); 374 406 375 407 // if no item was found … … 383 415 Color oldColor = item.getBackgroundColor(); 384 416 if (_step) { 385 if (item.getLink() == null) { 417 if (item.getLink() != null) { 418 pause(item); 419 item.setSelectedMode(Item.SelectedMode.Normal, 420 _stepColor); 421 } else { 386 422 item.setBackgroundColor(_stepColor); 387 }else{388 item.setSelectedMode(Item.SelectedMode.Normal,_stepColor);389 423 } 390 424 FrameGraphics.Repaint(); … … 392 426 lastItemStatus = RunItem(item, context, lastItemStatus); 393 427 if (_step) { 394 if (item.getLink() != null) { 395 item.setBackgroundColor(_stepColor); 428 if (item.getLink() == null) { 429 item.setBackgroundColor(oldColor); 430 pause(item); 431 } else { 396 432 item.setSelectedMode(Item.SelectedMode.None); 397 FrameGraphics.Repaint();398 433 } 399 int timeRemaining;400 if (_stepPause < 0)401 timeRemaining = Integer.MAX_VALUE;402 else403 timeRemaining = _stepPause;404 405 while (timeRemaining > 0 && !_nextStatement) {406 if (_stop) {407 item.setBackgroundColor(oldColor);408 item.setSelectedMode(SelectedMode.Normal,_stepColor);409 throw new Exception("Program terminated");410 }411 Thread.sleep(DefaultAgent.TIMER_RESOLUTION);412 timeRemaining -= DefaultAgent.TIMER_RESOLUTION;413 }414 _nextStatement = false;415 // Turn off the highlighting416 item.setBackgroundColor(oldColor);417 434 } 418 435 … … 447 464 448 465 /** 466 * @param item 467 * @param oldColor 468 * @throws Exception 469 * @throws InterruptedException 470 */ 471 private static void pause(Text item) throws Exception, InterruptedException { 472 if (!_step) 473 return; 474 475 Color oldColor = item.getBackgroundColor(); 476 item.setBackgroundColor(_stepColor); 477 item.setSelectedMode(Item.SelectedMode.None); 478 479 // Make sure we are on the frame with this item 480 Frame parent = item.getParentOrCurrentFrame(); 481 if (!parent.equals(DisplayIO.getCurrentFrame())) { 482 DisplayIO.setCurrentFrame(parent); 483 } 484 485 FrameGraphics.Repaint(); 486 487 int timeRemaining; 488 if (_stepPause < 0) 489 timeRemaining = Integer.MAX_VALUE; 490 else 491 timeRemaining = _stepPause; 492 493 while (timeRemaining > 0 && !_nextStatement) { 494 if (_stop) { 495 item.setBackgroundColor(oldColor); 496 item.setSelectedMode(SelectedMode.Normal, _stepColor); 497 throw new Exception("Program terminated"); 498 } 499 Thread.sleep(DefaultAgent.TIMER_RESOLUTION); 500 timeRemaining -= DefaultAgent.TIMER_RESOLUTION; 501 } 502 _nextStatement = false; 503 // Turn off the highlighting 504 item.setBackgroundColor(oldColor); 505 } 506 507 private static void pause(double time) throws Exception { 508 for (int i = 0; i < time * 10; i++) { 509 if (_stop) { 510 throw new Exception("Program terminated"); 511 } 512 Thread.yield(); 513 Thread.sleep(100); 514 } 515 } 516 517 /** 449 518 * This method should be modified to parse strings correctly 450 519 * … … 453 522 */ 454 523 private static String[] parseStatement(Text code) throws Exception { 455 String statement = code.getText() ;524 String statement = code.getText().trim(); 456 525 ArrayList<String> tokens = new ArrayList<String>(); 526 527 // Check special annotation tags for programs 528 if (statement.length() > 0 && statement.charAt(0) == '@') { 529 statement = statement.toLowerCase(); 530 // Flags the next unit test as being required to throw an exception 531 if (statement.equals("@throwsexception")) { 532 code.getParentOrCurrentFrame().setThrowsException(true); 533 } 534 return null; 535 } 457 536 458 537 for (int i = 0; i < statement.length(); i++) { … … 643 722 } 644 723 645 // Comments without links are a no-op 646 if (tokens.length == 0) { 724 // Annotation items are ignored after parsing running options 725 if (tokens == null) { 726 return Status.OK; 727 // Comments without links are ignored 728 } else if (tokens.length == 0) { 647 729 if (code.getLink() == null) 648 730 return Status.OK; … … 665 747 && tokens.length == 3) { 666 748 context.getPrimitives().set(tokens[1], tokens[2]); 667 return Status.OK;668 749 } 669 750 // Otherwise we are setting a variable with a literal … … 675 756 new SString(tokens[2].substring(1, 676 757 tokens[2].length() - 1))); 677 return Status.OK;678 679 758 // set a literal 680 759 } else if (tokens.length == 3) { 681 760 context.getPrimitives().setValue(tokens[1], 682 761 tokens[2]); 683 return Status.OK;684 762 } 685 763 } … … 688 766 } 689 767 } else if (tokens[0].equals("setassociation")) { 690 assert MinParametreCount(tokens, 3);768 assertExactParametreCount(tokens, 3); 691 769 692 770 Map map = (Map) context.getPointers().getVariable(tokens[1]) … … 697 775 .getStringValue(tokens[3]); 698 776 map.put(attribute, value); 699 return Status.OK;700 777 } else if (tokens[0].equals("setframevalue")) { 701 778 assertMinParametreCount(tokens, 3); … … 754 831 } 755 832 } 756 757 return Status.OK;758 833 } else if (tokens[0].startsWith("setitem")) { 759 834 if (tokens[0].equals("setitemposition")) { … … 838 913 throw new Exception("Unsupported setItem command: " 839 914 + code.toString()); 840 return Status.OK;841 915 } else if (tokens[0].equals("setstrchar")) { 842 916 assertExactParametreCount(tokens, 3); … … 854 928 context.getPrimitives().setValue(tokens[1], 855 929 new SString(s.toString())); 856 return Status.OK;857 930 } else if (tokens[0].equals("setcharinitem")) { 858 931 assertExactParametreCount(tokens, 4); … … 883 956 itemText.set(row, sb.toString()); 884 957 item.setTextList(itemText); 885 886 return Status.OK;887 958 } 888 959 } else if (tokens[0].startsWith("assert")) { … … 891 962 if (!context.getPrimitives().getBooleanValue(tokens[1])) 892 963 throw new UnitTestFailedException("true", "false"); 893 return Status.OK;894 964 } else if (tokens[0].equals("assertfalse")) { 895 965 assertExactParametreCount(tokens, 1); 896 966 if (context.getPrimitives().getBooleanValue(tokens[1])) 897 967 throw new UnitTestFailedException("false", "true"); 898 return Status.OK; 899 } 900 if (tokens[0].equals("assertfail")) { 968 } else if (tokens[0].equals("assertfail")) { 901 969 assertExactParametreCount(tokens, 0); 902 970 throw new UnitTestFailedException("pass", "fail"); … … 907 975 if (value != null) 908 976 throw new UnitTestFailedException("null", value.toString()); 909 return Status.OK;910 977 } else if (tokens[0].equals("assertnotnull")) { 911 978 assertExactParametreCount(tokens, 1); … … 914 981 if (value == null) 915 982 throw new UnitTestFailedException("not null", "null"); 916 return Status.OK;917 983 } else if (tokens[0].equals("assertdefined")) { 918 984 assertExactParametreCount(tokens, 1); 919 985 if (!context.isDefined(tokens[1])) 920 986 throw new UnitTestFailedException("defined", "not defined"); 921 return Status.OK;922 987 } else if (tokens[0].equals("assertnotdefined")) { 923 988 assertExactParametreCount(tokens, 1); 924 989 if (context.isDefined(tokens[1])) 925 990 throw new UnitTestFailedException("defined", "not defined"); 926 return Status.OK;927 991 } else if (tokens[0].equals("assertequals")) { 928 992 assertExactParametreCount(tokens, 2); … … 931 995 .getStringValue(tokens[1]), context.getPrimitives() 932 996 .getStringValue(tokens[2])); 933 return Status.OK;934 997 } else if (tokens[0].equals("assertdefined")) { 935 998 assertExactParametreCount(tokens, 1); … … 938 1001 "not defined"); 939 1002 } 940 return Status.OK;941 1003 } 942 1004 } else if (tokens[0].startsWith("goto")) { … … 949 1011 frameNameVar); 950 1012 NavigationActions.Goto(frameName); 951 return Status.OK;952 1013 } else if (tokens[0].startsWith("get")) { 953 1014 if (tokens[0].startsWith("getframe")) { … … 1011 1072 } 1012 1073 } 1013 return Status.OK;1014 1074 } else if (tokens[0].startsWith("getframename")) { 1015 1075 String frameNameVar = DEFAULT_STRING; … … 1026 1086 context.getPrimitives().setValue(frameNameVar, 1027 1087 frame.getName()); 1028 return Status.OK;1029 1088 } else if (tokens[0].startsWith("getframefilepath")) { 1030 1089 assertExactParametreCount(tokens, 2); … … 1035 1094 frameName); 1036 1095 context.getPrimitives().setValue(tokens[2], filePath); 1037 return Status.OK;1038 1096 } else if (tokens[0].equals("getframelog")) { 1039 1097 assertExactParametreCount(tokens, 1); … … 1046 1104 .getValue(); 1047 1105 t.setText(log); 1048 1049 return Status.OK;1050 1106 } 1051 1107 } else if (tokens[0].equals("getassociation")) { … … 1057 1113 String newValue = map.get(attribute).toString(); 1058 1114 context.getPrimitives().setValue(tokens[3], newValue); 1059 return Status.OK;1060 1115 } else if (tokens[0].startsWith("getcurrent")) { 1061 1116 if (tokens[0].equals("getcurrentframe")) { … … 1071 1126 new SString(currentFrame.getName())); 1072 1127 } 1073 return Status.OK;1074 1128 } 1075 1129 } else if (tokens[0].startsWith("getitem")) { … … 1162 1216 throw new Exception("Unsupported getItem command: " 1163 1217 + code.toString()); 1164 1165 return Status.OK;1166 1218 } else if (tokens[0].equals("getstrchar")) { 1167 1219 assertExactParametreCount(tokens, 3); … … 1172 1224 context.getPrimitives().setValue(tokens[3], 1173 1225 new SCharacter(s.charAt(pos - 1))); 1174 return Status.OK;1175 1226 } else if (tokens[0].equals("getstrlength")) { 1176 1227 assertExactParametreCount(tokens, 2); … … 1179 1230 context.getPrimitives().setValue(tokens[2], 1180 1231 new SInteger(s.length())); 1181 return Status.OK;1182 1232 } else if (tokens[0].equals("getelapsedtime")) { 1183 1233 assertExactParametreCount(tokens, 1); 1184 1234 context.getPrimitives().setValue(tokens[1], 1185 1235 new SInteger(AgentStats.getMilliSecondsElapsed())); 1186 return Status.OK;1187 1236 } else if (tokens[0].equals("getlastnumberinframeset")) { 1188 1237 String framesetNameVar = DEFAULT_STRING; … … 1197 1246 long count = FrameIO.getLastNumber(frameset); 1198 1247 context.getPrimitives().setValue(countVar, new SInteger(count)); 1199 return Status.OK;1200 1248 } else if (tokens[0].equals("getlistofframesets")) { 1201 1249 String stringVar = DEFAULT_ITEM; … … 1206 1254 context.getPrimitives().setValue(stringVar, 1207 1255 FrameIO.getFramesetList()); 1208 return Status.OK;1209 1256 } else if (tokens[0].equals("getsessionstats")) { 1210 1257 assertExactParametreCount(tokens, 1); … … 1212 1259 1213 1260 String stats = SessionStats.getCurrentStats(); 1214 Text t; 1215 // try { 1216 t = (Text) context.getPointers().getVariable(tokens[1]) 1261 Text t = (Text) context.getPointers().getVariable(tokens[1]) 1217 1262 .getValue(); 1218 1263 t.setText(stats); 1219 // } catch (Exception e) {1220 // t = new Text(-1, stats);1221 // context.getPointers().setObject(tokens[1], t);1222 // }1223 1224 return Status.OK;1225 1264 } else if (tokens[0].equals("getrandominteger")) { 1226 1265 assertExactParametreCount(tokens, 3); … … 1234 1273 context.getPrimitives().setValue(tokens[3], 1235 1274 new SInteger(result)); 1236 return Status.OK;1237 1275 } else if (tokens[0].equals("getrandomreal")) { 1238 1276 assertExactParametreCount(tokens, 3); … … 1245 1283 + lowerBound; 1246 1284 context.getPrimitives().setValue(tokens[3], new SReal(result)); 1247 return Status.OK;1248 1285 } else if (tokens[0].equals("getrandomtextitem")) { 1249 1286 assertExactParametreCount(tokens, 2); … … 1256 1293 context.getPointers() 1257 1294 .setObject(tokens[2], items.get(itemIndex)); 1258 return Status.OK;1259 1295 } 1260 1296 } else if (tokens[0].equals("or")) { … … 1270 1306 context.getPrimitives().setValue(tokens[tokens.length - 1], 1271 1307 new SBoolean(false)); 1272 return Status.OK;1273 1308 } else if (tokens[0].equals("and")) { 1274 1309 for (int i = 1; i < tokens.length - 1; i++) { … … 1283 1318 context.getPrimitives().setValue(tokens[tokens.length - 1], 1284 1319 new SBoolean(true)); 1285 return Status.OK;1286 1320 } else if (tokens[0].equals("messagelnitem") 1287 1321 || tokens[0].equals("messagelineitem")) { … … 1305 1339 // Just ignore other errors 1306 1340 } 1307 return Status.OK;1308 1341 } else if (tokens[0].equals("messageln") 1309 1342 || tokens[0].equals("messageline") … … 1318 1351 else 1319 1352 FrameGraphics.DisplayMessageAlways(message); 1320 return Status.OK;1321 1353 } else if (tokens[0].equals("typeatrate")) { 1322 1354 assertMinParametreCount(tokens, 1); … … 1327 1359 Thread.sleep((int) (delay * 1000)); 1328 1360 } 1329 return Status.OK;1330 1361 } else if (tokens[0].equals("type") || tokens[0].equals("typenospaces")) { 1331 1362 … … 1336 1367 Thread.sleep(25); 1337 1368 } 1338 return Status.OK;1339 1369 } else if (tokens[0].equals("runstring")) { 1340 1370 String codeText = getMessage(tokens, context, code.toString(), " ", … … 1342 1372 Text dynamicCode = new Text(1, codeText); 1343 1373 RunItem(dynamicCode, context, Status.OK); 1344 return Status.OK;1345 1374 } else if (tokens[0].equals("runoscommand")) { 1346 1375 String command = getMessage(tokens, context, code.toString(), " ", 1347 1376 1); 1348 1377 Runtime.getRuntime().exec(command); 1349 return Status.OK;1350 1378 } else if (tokens[0].equals("executeoscommand")) { 1351 1379 String command = getMessage(tokens, context, code.toString(), " ", … … 1369 1397 throw new RuntimeException(e.getMessage()); 1370 1398 } 1371 return Status.OK;1372 1399 } else if (tokens[0].startsWith("else")) { 1373 1400 // if the if statement was false then run the else statement … … 1513 1540 } 1514 1541 return Status.FalseIf; 1515 1516 1542 } // Look for variable length methods 1517 1543 else if (tokens[0].equals("attachitemtocursor")) { … … 1529 1555 FrameMouseActions.MouseY); 1530 1556 FrameMouseActions.pickup(item); 1531 return Status.OK;1532 1557 } else if (tokens[0].equals("attachstrtocursor")) { 1533 1558 String stringVar = DEFAULT_STRING; … … 1544 1569 FrameMouseActions.MouseY); 1545 1570 FrameMouseActions.pickup(item); 1546 // DisplayIO.repaint();1547 return Status.OK;1548 1571 } else if (tokens[0].equals("additemtoframe")) { 1549 1572 String itemVar = DEFAULT_ITEM; … … 1562 1585 .getValue(); 1563 1586 frame.addItem(item); 1564 1565 return Status.OK;1566 1587 } else if (tokens[0].equals("connectdots")) { 1567 1588 assertMinParametreCount(tokens, 2); … … 1584 1605 Frame frame = dot1.getParent(); 1585 1606 frame.addItem(new Line(dot1, dot2, frame.getNextItemID())); 1586 return Status.OK;1587 1607 } else if (tokens[0].equals("createitem") 1588 1608 || tokens[0].equals("createtext")) { … … 1615 1635 } 1616 1636 context.getPointers().setObject(tokens[4], newItem); 1617 1618 return Status.OK;1619 1637 } else if (tokens[0].equals("deleteitem")) { 1620 1638 assertMinParametreCount(tokens, 1); … … 1623 1641 .getValue(); 1624 1642 item.delete(); 1625 return Status.OK;1626 1643 } else if (tokens[0].equals("deleteframe")) { 1627 1644 assertMinParametreCount(tokens, 1); … … 1635 1652 new SBoolean(success)); 1636 1653 } 1637 1638 return Status.OK;1639 1654 } else if (tokens[0].equals("deleteframeset")) { 1640 1655 assertMinParametreCount(tokens, 1); … … 1647 1662 new SBoolean(success)); 1648 1663 } 1649 1650 return Status.OK;1651 1664 } else if (tokens[0].equals("copyitem")) { 1652 1665 assertMinParametreCount(tokens, 2); … … 1657 1670 Item copy = item.copy(); 1658 1671 context.getPointers().setObject(tokens[2], copy); 1659 1660 return Status.OK;1661 1672 } else if (tokens[0].equals("copyframeset")) { 1662 1673 assertMinParametreCount(tokens, 2); … … 1672 1683 new SBoolean(success)); 1673 1684 } 1674 1675 return Status.OK;1676 1685 } else if (tokens[0].equals("copyframe")) { 1677 1686 assertMinParametreCount(tokens, 2); … … 1698 1707 new SBoolean(success)); 1699 1708 } 1700 return Status.OK;1701 1709 } else if (tokens[0].equals("createframe")) { 1702 1710 … … 1715 1723 } else 1716 1724 context.createFrame(framesetName, frameVar, null); 1717 1718 return Status.OK;1719 1725 } else if (tokens[0].equals("closeframe")) { 1720 1726 String frameVar = DEFAULT_FRAME; … … 1730 1736 } else 1731 1737 context.closeFrame(frameVar, null); 1732 1733 return Status.OK;1734 1738 } else if (tokens[0].equals("readframe") 1735 1739 || tokens[0].equals("openframe")) { … … 1751 1755 } else 1752 1756 context.readFrame(frameName, frameVar, null); 1753 1754 return Status.OK;1755 1757 } else if (tokens[0].equals("readkbdcond")) { 1756 1758 … … 1772 1774 context.getPrimitives().setValue(nextCharVarName, 1773 1775 new SCharacter(nextChar)); 1774 1775 return Status.OK;1776 1776 } else if (tokens[0].equals("createassociation")) { 1777 1777 … … 1784 1784 Map<String, String> newMap = new HashMap<String, String>(); 1785 1785 context.getPointers().setObject(associationVar, newMap); 1786 return Status.OK;1787 1786 } else if (tokens[0].equals("deleteassociation")) { 1788 1787 … … 1794 1793 } 1795 1794 context.getPointers().delete(associationVar); 1796 return Status.OK;1797 1795 } else if (tokens[0].equals("openreadfile")) { 1798 1796 assertVariableType(tokens[1], 1, SString.prefix); … … 1804 1802 } else 1805 1803 context.openReadFile(tokens[1], tokens[2]); 1806 1807 return Status.OK;1808 1804 } else if (tokens[0].equals("readlinefile") 1809 1805 || tokens[0].equals("readlnfile")) { … … 1815 1811 } else 1816 1812 context.readLineFile(tokens[1], tokens[2]); 1817 1818 return Status.OK;1819 1813 } else if (tokens[0].equals("readitemfile")) { 1820 1814 assertVariableType(tokens[1], 1, SPointer.filePrefix); … … 1826 1820 } else 1827 1821 context.readItemFile(tokens[1], tokens[2]); 1828 1829 return Status.OK;1830 1822 } else if (tokens[0].equals("openwritefile")) { 1831 1823 assertVariableType(tokens[1], 1, SString.prefix); … … 1837 1829 } else 1838 1830 context.openWriteFile(tokens[1], tokens[2]); 1839 1840 return Status.OK;1841 1831 } else if (tokens[0].equals("writefile") 1842 1832 || tokens[0].equals("writelinefile") … … 1863 1853 textToWrite.append('\n'); 1864 1854 context.writeFile(tokens[1], textToWrite.toString()); 1865 1866 return Status.OK;1867 1855 } else if (tokens[0].equals("displayframeset")) { 1868 1856 assertMinParametreCount(tokens, 1); … … 1915 1903 } 1916 1904 } 1917 return Status.OK;1918 1905 } else if (tokens[0].equals("createframeset")) { 1919 1906 String framesetName = DEFAULT_STRING; … … 1925 1912 } 1926 1913 context.createFrameset(framesetName, successVar); 1927 return Status.OK;1928 1914 } else if (tokens[0].equals("writetree")) { 1929 1915 assertMinParametreCount(tokens, 3); … … 1938 1924 wt.run(); 1939 1925 } 1940 return Status.OK;1941 1926 } else if (tokens[0].equals("concatstr")) { 1942 1927 assertMinParametreCount(tokens, 3); … … 1951 1936 context.getPrimitives().setValue(resultVar, 1952 1937 new SString(sb.toString())); 1953 return Status.OK;1954 1938 } else if (tokens[0].equals("convstrlower")) { 1955 1939 assertExactParametreCount(tokens, 1); … … 1959 1943 new SString(context.getPrimitives().getStringValue( 1960 1944 tokens[1]).toLowerCase())); 1961 return Status.OK;1962 1945 } else if (tokens[0].equals("convstrupper")) { 1963 1946 assertExactParametreCount(tokens, 1); … … 1967 1950 new SString(context.getPrimitives().getStringValue( 1968 1951 tokens[1]).toUpperCase())); 1969 return Status.OK;1970 1952 } else if (tokens[0].equals("countcharsinstr")) { 1971 1953 assertExactParametreCount(tokens, 3); … … 1974 1956 int count = countCharsInString(s, pattern); 1975 1957 context.getPrimitives().setValue(tokens[3], new SInteger(count)); 1976 return Status.OK;1977 1958 } else if (tokens[0].equals("countcharsinitem")) { 1978 1959 assertExactParametreCount(tokens, 3); … … 1985 1966 count = countCharsInString(((Text) item).getText(), pattern); 1986 1967 context.getPrimitives().setValue(tokens[3], new SInteger(count)); 1987 return Status.OK;1988 1968 } else if (tokens[0].equals("parseframename")) { 1989 1969 assertExactParametreCount(tokens, 4); … … 2007 1987 // assertPrimitiveType(tokens[4], 4); 2008 1988 context.getPrimitives().setValue(tokens[4], new SInteger(frameNo)); 2009 2010 return Status.OK;2011 1989 } else if (tokens[0].equals("parsestr")) { 2012 1990 assertMinParametreCount(tokens, 2); … … 2056 2034 } 2057 2035 } 2058 return Status.OK;2059 2036 } else if (tokens[0].equals("stripstr")) { 2060 2037 assertExactParametreCount(tokens, 2); … … 2065 2042 s = s.replaceAll(charsToStrip.substring(i, i + 1), ""); 2066 2043 context.getPrimitives().setValue(tokens[1], new SString(s)); 2067 return Status.OK;2068 2044 } else if (tokens[0].equals("subststr")) { 2069 2045 assertExactParametreCount(tokens, 3); … … 2075 2051 result = result.replaceAll(oldString, newString); 2076 2052 context.getPrimitives().setValue(tokens[1], new SString(result)); 2077 return Status.OK;2078 2053 } else if (tokens[0].equals("substr")) { 2079 2054 assertExactParametreCount(tokens, 4); … … 2089 2064 result = s.substring(startPos); 2090 2065 context.getPrimitives().setValue(tokens[4], new SString(result)); 2091 return Status.OK;2092 2066 } else if (tokens[0].equals("pause")) { 2093 2067 String lengthVar = DEFAULT_REAL; … … 2099 2073 2100 2074 pause(context.getPrimitives().getDoubleValue(lengthVar)); 2101 return Status.OK;2102 2075 } else if (tokens[0].equals("glidecursorto")) { 2103 2076 assertMinParametreCount(tokens, 2); … … 2131 2104 Thread.sleep(milliseconds % timeInterval); 2132 2105 DisplayIO.setCursorPosition(finalX, finalY); 2133 return Status.OK;2134 2106 } else if (tokens[0].equals("glideitemto")) { 2135 2107 assertMinParametreCount(tokens, 3); … … 2179 2151 FrameGraphics.Repaint(); 2180 2152 // FrameMouseActions.updateCursor(); 2181 return Status.OK;2182 2153 } 2183 2154 // Now look for fixed parametre statements 2184 else if (tokens.length == 1) { 2185 if (tokens[0].equals(EXIT_TEXT)) { 2186 return Status.Exit; 2187 } else if (tokens[0].equals(LOOP_TEXT)) { 2188 Status status = Status.OK; 2189 // Keep looping until break or exit occurs 2190 while (status == Status.OK || status == Status.Continue) 2191 status = RunFrameAndReportError(code, context); 2192 if (status == Status.Continue || status == Status.Break) 2193 status = Status.OK; 2194 return status; 2195 } else if (tokens[0].equals(CONTINUE_TEXT) 2196 || tokens[0].equals(CONTINUE2_TEXT)) { 2197 return Status.Continue; 2198 } else if (tokens[0].equals(BREAK_TEXT) 2199 || tokens[0].equals(BREAK2_TEXT)) { 2200 return Status.Break; 2201 } else if (tokens[0].equals(RETURN_TEXT)) { 2202 return Status.Return; 2203 } else if (tokens[0].equals("pressleftbutton")) { 2204 DisplayIO.pressMouse(InputEvent.BUTTON1_MASK); 2205 return Status.OK; 2206 } else if (tokens[0].equals("pressmiddlebutton")) { 2207 DisplayIO.pressMouse(InputEvent.BUTTON2_MASK); 2208 return Status.OK; 2209 } else if (tokens[0].equals("pressrightbutton")) { 2210 DisplayIO.pressMouse(InputEvent.BUTTON3_MASK); 2211 return Status.OK; 2212 } else if (tokens[0].equals("releaseleftbutton")) { 2213 DisplayIO.releaseMouse(InputEvent.BUTTON1_MASK); 2214 return Status.OK; 2215 } else if (tokens[0].equals("releasemiddlebutton")) { 2216 DisplayIO.releaseMouse(InputEvent.BUTTON2_MASK); 2217 return Status.OK; 2218 } else if (tokens[0].equals("releaserightbutton")) { 2219 DisplayIO.releaseMouse(InputEvent.BUTTON3_MASK); 2220 return Status.OK; 2221 } else if (tokens[0].equals("clickleftbutton")) { 2222 DisplayIO.clickMouse(InputEvent.BUTTON1_MASK); 2223 return Status.OK; 2224 } else if (tokens[0].equals("clickmiddlebutton")) { 2225 DisplayIO.clickMouse(InputEvent.BUTTON2_MASK); 2226 return Status.OK; 2227 } else if (tokens[0].equals("clickrightbutton")) { 2228 DisplayIO.clickMouse(InputEvent.BUTTON3_MASK); 2229 return Status.OK; 2230 } else if (tokens[0].equals("repaint")) { 2231 FrameGraphics.Repaint(); 2232 return Status.OK; 2233 } 2234 2235 if (tokens[0].equals("add")) { 2155 else if (tokens[0].equals(EXIT_TEXT)) { 2156 return Status.Exit; 2157 } else if (tokens[0].equals(LOOP_TEXT)) { 2158 Status status = Status.OK; 2159 // Keep looping until break or exit occurs 2160 while (status == Status.OK || status == Status.Continue) { 2161 status = RunFrameAndReportError(code, context); 2162 pause(code); 2163 } 2164 if (status == Status.Continue || status == Status.Break) 2165 status = Status.OK; 2166 return status; 2167 } else if (tokens[0].equals(CONTINUE_TEXT) 2168 || tokens[0].equals(CONTINUE2_TEXT)) { 2169 return Status.Continue; 2170 } else if (tokens[0].equals(BREAK_TEXT) 2171 || tokens[0].equals(BREAK2_TEXT)) { 2172 return Status.Break; 2173 } else if (tokens[0].equals(RETURN_TEXT)) { 2174 return Status.Return; 2175 } else if (tokens[0].equals("pressleftbutton")) { 2176 assertExactParametreCount(tokens, 0); 2177 DisplayIO.pressMouse(InputEvent.BUTTON1_MASK); 2178 } else if (tokens[0].equals("pressmiddlebutton")) { 2179 assertExactParametreCount(tokens, 0); 2180 DisplayIO.pressMouse(InputEvent.BUTTON2_MASK); 2181 } else if (tokens[0].equals("pressrightbutton")) { 2182 assertExactParametreCount(tokens, 0); 2183 DisplayIO.pressMouse(InputEvent.BUTTON3_MASK); 2184 } else if (tokens[0].equals("releaseleftbutton")) { 2185 assertExactParametreCount(tokens, 0); 2186 DisplayIO.releaseMouse(InputEvent.BUTTON1_MASK); 2187 } else if (tokens[0].equals("releasemiddlebutton")) { 2188 assertExactParametreCount(tokens, 0); 2189 DisplayIO.releaseMouse(InputEvent.BUTTON2_MASK); 2190 } else if (tokens[0].equals("releaserightbutton")) { 2191 assertExactParametreCount(tokens, 0); 2192 DisplayIO.releaseMouse(InputEvent.BUTTON3_MASK); 2193 } else if (tokens[0].equals("clickleftbutton")) { 2194 assertExactParametreCount(tokens, 0); 2195 DisplayIO.clickMouse(InputEvent.BUTTON1_MASK); 2196 } else if (tokens[0].equals("clickmiddlebutton")) { 2197 assertExactParametreCount(tokens, 0); 2198 DisplayIO.clickMouse(InputEvent.BUTTON2_MASK); 2199 } else if (tokens[0].equals("clickrightbutton")) { 2200 assertExactParametreCount(tokens, 0); 2201 DisplayIO.clickMouse(InputEvent.BUTTON3_MASK); 2202 } else if (tokens[0].equals("repaint")) { 2203 assertExactParametreCount(tokens, 0); 2204 FrameGraphics.Repaint(); 2205 } else if (tokens[0].equals("add")) { 2206 assertMaxParametreCount(tokens, 3); 2207 switch (tokens.length) { 2208 case 1: 2236 2209 context.getPrimitives().add(DEFAULT_INTEGER); 2237 } else if (tokens[0].equals("subtract")) { 2210 break; 2211 case 2: 2212 context.getPrimitives().add(tokens[1]); 2213 break; 2214 case 3: 2215 context.getPrimitives().add(tokens[2], tokens[1]); 2216 break; 2217 case 4: 2218 context.getPrimitives().add(tokens[1], tokens[2], tokens[3]); 2219 break; 2220 default: 2221 assert (false); 2222 } 2223 } else if (tokens[0].equals("subtract")) { 2224 assertMaxParametreCount(tokens, 3); 2225 switch (tokens.length) { 2226 case 1: 2238 2227 context.getPrimitives().subtract(DEFAULT_INTEGER); 2239 } else 2240 throw new RuntimeException("Invalid statement:"); 2241 return Status.OK; 2242 } else if (tokens.length == 2) { 2243 if (tokens[0].equals("closewritefile")) { 2244 assertVariableType(tokens[1], 1, SPointer.filePrefix); 2245 context.closeWriteFile(tokens[1]); 2246 2247 return Status.OK; 2248 } else if (tokens[0].equals("closereadfile")) { 2249 assertVariableType(tokens[1], 1, SPointer.filePrefix); 2250 context.closeReadFile(tokens[1]); 2251 2252 return Status.OK; 2253 } 2254 2255 if (Primitives.isPrimitive(tokens[1])) { 2256 if (tokens[0].equals("add")) { 2257 context.getPrimitives().add(tokens[1]); 2258 } else if (tokens[0].equals("subtract")) { 2259 context.getPrimitives().subtract(tokens[1]); 2260 } else 2261 throw new RuntimeException("Invalid statement:"); 2262 return Status.OK; 2263 } 2264 } else if (tokens.length == 3) { 2265 if (tokens[0].startsWith("foreach")) { 2266 Class itemType = Object.class; 2267 String type = tokens[0].substring("foreach".length()); 2268 // Check the type of foreach loop 2269 // and set the item type to iterate over 2270 if (type.equals("dot")) { 2271 itemType = Dot.class; 2272 } else if (type.equals("text")) { 2273 itemType = Text.class; 2274 } else if (type.equals("line")) { 2275 itemType = Line.class; 2276 } 2277 2278 assertVariableType(tokens[2], 2, SPointer.itemPrefix); 2279 assertVariableType(tokens[1], 1, SPointer.framePrefix); 2280 Frame currFrame = (Frame) context.getPointers().getVariable( 2281 tokens[1]).getValue(); 2282 // Create the ip variable 2283 Item frameTitle = currFrame.getTitleItem(); 2284 2285 for (Item i : currFrame.getItems()) { 2286 if (i == frameTitle) 2287 continue; 2288 if (!(itemType.isInstance(i))) 2289 continue; 2290 2291 context.getPointers().setObject(tokens[2], i); 2292 Status status = RunFrameAndReportError(code, context); 2293 // check if we need to exit this loop because of 2294 // statements in the code that was run 2295 if (status == Status.Exit || status == Status.Return) 2296 return status; 2297 else if (status == Status.Break) 2298 return Status.OK; 2299 } 2300 return Status.OK; 2301 } 2302 2303 if (Primitives.isPrimitive(tokens[1]) 2304 && Primitives.isPrimitive(tokens[2])) { 2305 if (tokens[0].equals("movecursorto")) { 2306 assertExactParametreCount(tokens, 2); 2307 int x = (int) context.getPrimitives().getIntegerValue( 2308 tokens[1]); 2309 int y = (int) context.getPrimitives().getIntegerValue( 2310 tokens[2]); 2311 DisplayIO.setCursorPosition(x, y); 2312 return Status.OK; 2313 } else if (tokens[0].equals("not")) { 2314 context.getPrimitives().not(tokens[1], tokens[2]); 2315 } else if (tokens[0].equals("exp")) { 2316 context.getPrimitives().exp(tokens[1], tokens[2]); 2317 } else if (tokens[0].equals("log")) { 2318 context.getPrimitives().log(tokens[2], tokens[2]); 2319 } else if (tokens[0].equals("log10")) { 2320 context.getPrimitives().log10(tokens[1], tokens[2]); 2321 } else if (tokens[0].equals("sqrt")) { 2322 context.getPrimitives().sqrt(tokens[1], tokens[2]); 2323 } else if (tokens[0].equals("add")) { 2324 context.getPrimitives().add(tokens[2], tokens[1]); 2325 } else if (tokens[0].equals("subtract")) { 2326 context.getPrimitives().subtract(tokens[2], tokens[1]); 2327 } else if (tokens[0].equals("multiply")) { 2328 context.getPrimitives().multiply(tokens[2], tokens[1]); 2329 } else if (tokens[0].equals("divide")) { 2330 context.getPrimitives().divide(tokens[2], tokens[1]); 2331 } else 2332 throw new RuntimeException("Invalid statement:"); 2333 return Status.OK; 2334 } 2335 } else if (tokens.length == 4) { 2228 break; 2229 case 2: 2230 context.getPrimitives().subtract(tokens[1]); 2231 break; 2232 case 3: 2233 context.getPrimitives().subtract(tokens[2], tokens[1]); 2234 break; 2235 case 4: 2236 context.getPrimitives().subtract(tokens[1], tokens[2], 2237 tokens[3]); 2238 break; 2239 default: 2240 assert (false); 2241 } 2242 } else if (tokens[0].equals("multiply")) { 2243 assertMinParametreCount(tokens, 2); 2244 assertMaxParametreCount(tokens, 3); 2245 switch (tokens.length) { 2246 case 3: 2247 context.getPrimitives().multiply(tokens[2], tokens[1]); 2248 break; 2249 case 4: 2250 context.getPrimitives().multiply(tokens[1], tokens[2], 2251 tokens[3]); 2252 break; 2253 default: 2254 assert (false); 2255 } 2256 } else if (tokens[0].equals("divide")) { 2257 assertMinParametreCount(tokens, 2); 2258 assertMaxParametreCount(tokens, 3); 2259 switch (tokens.length) { 2260 case 3: 2261 context.getPrimitives().divide(tokens[2], tokens[1]); 2262 break; 2263 case 4: 2264 context.getPrimitives().divide(tokens[1], tokens[2], tokens[3]); 2265 break; 2266 default: 2267 assert (false); 2268 } 2269 } else if (tokens[0].equals("modulo")) { 2270 assertExactParametreCount(tokens, 3); 2271 context.getPrimitives().modulo(tokens[1], tokens[2], tokens[3]); 2272 } else if (tokens[0].equals("power")) { 2273 assertExactParametreCount(tokens, 3); 2274 context.getPrimitives().power(tokens[1], tokens[2], tokens[3]); 2275 } else if (tokens[0].equals("not")) { 2276 assertExactParametreCount(tokens, 2); 2277 context.getPrimitives().not(tokens[1], tokens[2]); 2278 } else if (tokens[0].equals("exp")) { 2279 assertExactParametreCount(tokens, 2); 2280 context.getPrimitives().exp(tokens[1], tokens[2]); 2281 } else if (tokens[0].equals("log")) { 2282 assertExactParametreCount(tokens, 2); 2283 context.getPrimitives().log(tokens[2], tokens[2]); 2284 } else if (tokens[0].equals("log10")) { 2285 assertExactParametreCount(tokens, 2); 2286 context.getPrimitives().log10(tokens[1], tokens[2]); 2287 } else if (tokens[0].equals("sqrt")) { 2288 assertExactParametreCount(tokens, 2); 2289 context.getPrimitives().sqrt(tokens[1], tokens[2]); 2290 } else if (tokens[0].equals("closewritefile")) { 2291 assertVariableType(tokens[1], 1, SPointer.filePrefix); 2292 context.closeWriteFile(tokens[1]); 2293 } else if (tokens[0].equals("closereadfile")) { 2294 assertVariableType(tokens[1], 1, SPointer.filePrefix); 2295 context.closeReadFile(tokens[1]); 2296 } else if (tokens[0].startsWith("foreach")) { 2336 2297 if (tokens[0].equals("foreachassociation")) { 2337 2298 assertExactParametreCount(tokens, 3); … … 2345 2306 context.getPrimitives().setValue(tokens[3], value); 2346 2307 Status status = RunFrameAndReportError(code, context); 2308 pause(code); 2309 // check if we need to exit this loop because of 2310 // statements in the code that was run 2311 if (status == Status.Exit || status == Status.Return) 2312 return status; 2313 else if (status == Status.Break) 2314 break; 2315 } 2316 } else { 2317 Class itemType = Object.class; 2318 String type = tokens[0].substring("foreach".length()); 2319 // Check the type of foreach loop 2320 // and set the item type to iterate over 2321 if (type.equals("dot")) { 2322 itemType = Dot.class; 2323 } else if (type.equals("text")) { 2324 itemType = Text.class; 2325 } else if (type.equals("line")) { 2326 itemType = Line.class; 2327 } else if (type.equals("item") || type.equals("")) { 2328 itemType = Object.class; 2329 } else { 2330 throw new RuntimeException("Invalid ForEach loop type"); 2331 } 2332 2333 assertVariableType(tokens[2], 2, SPointer.itemPrefix); 2334 assertVariableType(tokens[1], 1, SPointer.framePrefix); 2335 Frame currFrame = (Frame) context.getPointers().getVariable( 2336 tokens[1]).getValue(); 2337 // Create the ip variable 2338 Item frameTitle = currFrame.getTitleItem(); 2339 2340 for (Item i : currFrame.getItems()) { 2341 if (i == frameTitle) 2342 continue; 2343 if (!(itemType.isInstance(i))) 2344 continue; 2345 2346 context.getPointers().setObject(tokens[2], i); 2347 Status status = RunFrameAndReportError(code, context); 2348 pause(code); 2347 2349 // check if we need to exit this loop because of 2348 2350 // statements in the code that was run … … 2352 2354 return Status.OK; 2353 2355 } 2354 return Status.OK; 2355 } 2356 2357 if (Primitives.isPrimitive(tokens[1]) 2358 && Primitives.isPrimitive(tokens[2]) 2359 && Primitives.isPrimitive(tokens[3])) { 2360 if (tokens[0].equals("add")) { 2361 context.getPrimitives() 2362 .add(tokens[1], tokens[2], tokens[3]); 2363 } else if (tokens[0].equals("subtract")) { 2364 context.getPrimitives().subtract(tokens[1], tokens[2], 2365 tokens[3]); 2366 } else if (tokens[0].equals("divide")) { 2367 context.getPrimitives().divide(tokens[1], tokens[2], 2368 tokens[3]); 2369 } else if (tokens[0].equals("multiply")) { 2370 context.getPrimitives().multiply(tokens[1], tokens[2], 2371 tokens[3]); 2372 } else if (tokens[0].equals("modulo")) { 2373 context.getPrimitives().modulo(tokens[1], tokens[2], 2374 tokens[3]); 2375 } else if (tokens[0].equals("power")) { 2376 context.getPrimitives().power(tokens[1], tokens[2], 2377 tokens[3]); 2378 } else 2379 throw new Exception("Statement not found: " + tokens[0] 2380 + " in " + code.toString()); 2381 return Status.OK; 2382 } 2356 } 2357 } else if (tokens[0].equals("movecursorto")) { 2358 assertExactParametreCount(tokens, 2); 2359 int x = (int) context.getPrimitives().getIntegerValue(tokens[1]); 2360 int y = (int) context.getPrimitives().getIntegerValue(tokens[2]); 2361 DisplayIO.setCursorPosition(x, y); 2362 } else { 2363 throw new RuntimeException("Unknown statement"); 2383 2364 } 2384 throw new RuntimeException("Unknown statement: "); 2385 } 2386 2387 private static void pause(double time) throws Exception { 2388 for (int i = 0; i < time * 10; i++) { 2389 Thread.yield(); 2390 Thread.sleep(100); 2391 } 2365 return Status.OK; 2392 2366 } 2393 2367 … … 2426 2400 if (tokens.length - 1 != parametreCount) 2427 2401 throw new IncorrectParametreCountException(parametreCount); 2402 } 2403 2404 public static void assertMaxParametreCount(String[] tokens, 2405 int parametreCount) throws Exception { 2406 if (tokens.length - 1 > parametreCount) 2407 throw new AboveMaxParametreCountException(parametreCount); 2428 2408 } 2429 2409 … … 2456 2436 _nextStatement = true; 2457 2437 } 2438 2439 public static void ProgramStarted() { 2440 _programsRunning++; 2441 AgentStats.reset(); 2442 FrameGraphics.DisplayMessage("Running SimpleProgram...", Color.BLUE); 2443 } 2458 2444 } -
trunk/src/org/expeditee/gui/Frame.java
r86 r87 46 46 private String _frameset = null; 47 47 48 private boolean _throwsException = false; 49 48 50 private int _number = -1; 49 51 … … 344 346 for (Item i : items) { 345 347 if (i instanceof Text && i.getX() < UserSettings.TitlePosition 346 && i.getY() < UserSettings.TitlePosition && i.getY() > 0)348 && i.getY() < UserSettings.TitlePosition /*&& i.getY() > 0*/) 347 349 return (Text) i; 348 350 } … … 1658 1660 return 1 + (backup == null ? 0 : backup.getCometLength()); 1659 1661 } 1662 1663 public void setThrowsException(boolean b) { 1664 _throwsException = b; 1665 } 1666 1667 public boolean getThrowsException() { 1668 return _throwsException; 1669 } 1660 1670 } -
trunk/src/org/expeditee/gui/FrameKeyboardActions.java
r86 r87 15 15 16 16 import org.expeditee.actions.Actions; 17 import org.expeditee.actions.Misc; 17 18 import org.expeditee.actions.NavigationActions; 18 19 import org.expeditee.actions.Simple; … … 34 35 || (e.isControlDown() && e.getKeyChar() == KeyEvent.VK_C)) { 35 36 Simple.stop(); 36 } else if (e.isControlDown() && e.getKeyChar() == KeyEvent.VK_SPACE){37 } else if (e.isControlDown() && e.getKeyChar() == KeyEvent.VK_SPACE) { 37 38 Simple.nextStatement(); 38 39 } 39 40 40 41 Simple.KeyStroke(e.getKeyChar()); 41 42 42 43 if (Simple.consumeKeyboardInput()) 43 44 return; … … 67 68 68 69 if (e.isAltDown()) { 69 if (FrameUtils.getCurrentItem() == null 70 && !Frame.itemAttachedToCursor()) { 71 Item t = DisplayIO.getCurrentFrame().createNewText(ch + ": "); 72 FrameMouseActions.pickup(t); 73 FrameGraphics.Repaint(); 74 } else { 75 // remove the link for alt+l 76 if (ch == 'l') { 77 Item current = FrameUtils.getCurrentItem(); 78 // If its not linked then link it to its self 79 if (current instanceof Text && current.getLink() == null) { 80 String text = ((Text) current).getText(); 81 if (FrameIO.isValidFrameName(text)) { 82 current.setLink(text); 83 } else if (FrameIO.isValidFramesetName(text)) { 84 current.setLink(text + '1'); 85 } 86 } else { 87 // If its linked remove the link 88 current.setLink(null); 89 } 90 FrameGraphics.Repaint(); 91 } else if (ch == 'a') { 92 Item current = FrameUtils.getCurrentItem(); 93 // If its not linked then link it to its self 94 if (current instanceof Text && current.getAction() == null) { 95 String text = ((Text) current).getText().trim(); 96 if (text.startsWith("a:")) { 97 text = text.substring(2).trim(); 98 } else if (text.startsWith("@")) { 99 text = text.substring(1).trim(); 100 } 101 current.setAction(text); 102 } else { 103 // If its linked remove the link 104 current.setActions(null); 105 } 106 FrameGraphics.Repaint(); 107 } 108 } 70 109 71 } else { 110 72 processChar(ch, e.isShiftDown()); … … 311 273 312 274 private void navigateFrame(int direction) { 313 DisplayIO.setCursor(Item.DEFAULT_CURSOR);314 275 switch (direction) { 315 276 case Text.RIGHT: … … 348 309 Actions.interruptAgent(); 349 310 return; 350 } else if (Simple. isProgramRunning()) {311 } else if (Simple.consumeKeyboardInput()) { 351 312 return; 352 313 } … … 517 478 if (ch.length() > 1) 518 479 return; 519 520 // if this is a paste command 521 if (ch.charAt(0) == KeyEvent.VK_V) { 480 Logger.Log(Logger.USER, Logger.CONTROL_CHAR, "User pressing: Ctrl+" 481 + ch); 482 // 483 // if (FrameUtils.getCurrentItem() == null 484 // && !Frame.itemAttachedToCursor()) { 485 // Item t = DisplayIO.getCurrentFrame().createNewText(ch + ": "); 486 // FrameMouseActions.pickup(t); 487 // } else { 488 // remove the link for alt+l 489 Item current = FrameUtils.getCurrentItem(); 490 Frame currentFrame = DisplayIO.getCurrentFrame(); 491 //Link or delink an item 492 if (ch.charAt(0) == KeyEvent.VK_L) { 493 // If its not linked then link it to its self 494 if (current instanceof Text && current.getLink() == null) { 495 String text = ((Text) current).getText(); 496 if (FrameIO.isValidFrameName(text)) { 497 current.setLink(text); 498 } else if (FrameIO.isValidFramesetName(text)) { 499 current.setLink(text + '1'); 500 } 501 } else { 502 // If its linked remove the link 503 current.setLink(null); 504 } 505 } else if (ch.charAt(0) == KeyEvent.VK_G) { 506 // If its not linked then link it to its self 507 if (current instanceof Text) { 508 String text = ((Text) current).getText(); 509 if (FrameIO.isValidFrameName(text)) { 510 current.setLink(text); 511 } else if (FrameIO.isValidFramesetName(text)) { 512 current.setLink(text + '1'); 513 } 514 } 515 if (current.getLink() != null){ 516 NavigationActions.Goto(current.getAbsoluteLink()); 517 return; 518 } 519 } else if (ch.charAt(0) == KeyEvent.VK_A) { 520 // If its not linked then link it to its self 521 if (current instanceof Text && current.getAction() == null) { 522 String text = ((Text) current).getText().trim(); 523 if (text.startsWith("a:")) { 524 text = text.substring(2).trim(); 525 } else if (text.startsWith("@")) { 526 text = text.substring(1).trim(); 527 } 528 current.setAction(text); 529 } else { 530 // If its linked remove the link 531 current.setActions(null); 532 } 533 } else if (ch.charAt(0) == KeyEvent.VK_V) { 522 534 try { 523 535 // read in the data from the clipboard … … 568 580 addTextItemToCurrentFrame(temp, y); 569 581 } 570 571 FrameGraphics.Repaint();572 582 } catch (Exception ex) { 573 583 } 574 return;575 576 584 // if this is a copy command 577 585 } else if (ch.charAt(0) == KeyEvent.VK_C) { … … 603 611 Toolkit.getDefaultToolkit().getSystemClipboard().setContents( 604 612 selection, null); 605 606 613 FrameGraphics.DisplayMessage("Item copied to clipboard"); 607 614 return; … … 609 616 // perform a delete operation 610 617 processChar((char) KeyEvent.VK_DELETE, e.isShiftDown()); 611 FrameGraphics.Repaint(); 618 FrameMouseActions.delete(current); 619 }else if (ch.charAt(0) == KeyEvent.VK_F) { 620 // perform a delete operation 621 Actions.PerformAction(currentFrame, null, "Format"); 622 return; 612 623 } else if (ch.charAt(0) == KeyEvent.VK_J) { 613 624 … … 621 632 622 633 text.setJustification(Item.JUSTIFICATION_LEFT); 623 624 FrameGraphics.Repaint();625 return;626 634 } else if (ch.charAt(0) == KeyEvent.VK_S) { 627 635 // split the current text item … … 641 649 y += newText.getBoundsHeight(); 642 650 newText.setY(y); 643 644 Frame current = DisplayIO.getCurrentFrame();645 651 // update the items ID to prevent conflicts with the current 646 652 // frame 647 newText.setID(current .getNextItemID());648 649 current.addItem(newText);650 653 newText.setID(currentFrame.getNextItemID()); 654 currentFrame.addItem(newText); 655 } 656 } 651 657 FrameGraphics.Repaint(); 652 653 return;654 }655 656 Logger.Log(Logger.USER, Logger.CONTROL_CHAR, "User pressing: Ctrl+"657 + ch);658 658 } 659 659 -
trunk/src/org/expeditee/gui/FrameMouseActions.java
r86 r87 1676 1676 } 1677 1677 1678 p rivatestatic void delete(Item toDelete) {1678 public static void delete(Item toDelete) { 1679 1679 FrameUtils.LastEdited = null; 1680 1680 _offX = _offY = 0; … … 2011 2011 } 2012 2012 } else { 2013 if (mergee instanceof Dot || mergee instanceof Text) {2013 if (mergee.isLineEnd()) { 2014 2014 DisplayIO.setCursorPosition(mergee.getPosition()); 2015 2015 } -
trunk/src/org/expeditee/gui/FrameUtils.java
r86 r87 383 383 Parse(toDisplay); 384 384 DisplayIO.setCurrentFrame(toDisplay); 385 385 FrameMouseActions.updateCursor(); 386 386 // update response timer 387 387 _LastResponse = ResponseTimer.getElapsedSeconds(); -
trunk/src/org/expeditee/items/Item.java
r86 r87 1011 1011 public void run() { 1012 1012 try { 1013 AgentStats.reset(); 1014 FrameGraphics 1015 .DisplayMessage("Running SimpleProgram...", Color.BLUE); 1013 Simple.ProgramStarted(); 1016 1014 Simple.RunFrameAndReportError(this, new Context()); 1017 1015 Simple.ProgramFinished(); -
trunk/src/org/expeditee/items/Text.java
r86 r87 1511 1511 1512 1512 if (merger.isLineEnd()) { 1513 //Merging line ends onto non line end text is a no-op 1514 if(!isLineEnd()) 1515 return null; 1516 1513 1517 if (merger instanceof Text) 1514 1518 insertText(((Text) merger).getText(), mouseX, mouseY); -
trunk/src/org/expeditee/simple/Primitives.java
r80 r87 49 49 * if the variable name is invalid 50 50 */ 51 public void add(String name, SPrimitive value) throws IncorrectTypeException { 51 public void add(String name, SPrimitive value) 52 throws IncorrectTypeException { 52 53 // figure out the type and add it... 53 54 SPrimitive newVar; … … 159 160 /** 160 161 * Increments a variable. 161 * @param var the name of the variable to increment 162 * 163 * @param var 164 * the name of the variable to increment 162 165 * @throws Exception 163 166 */ … … 168 171 /** 169 172 * Decrements a variable. 170 * @param var the name of the variable to decrement 173 * 174 * @param var 175 * the name of the variable to decrement 171 176 * @throws Exception 172 177 */ -
trunk/tests/org/expeditee/actions/SimpleTest.java
r80 r87 76 76 try { 77 77 runSimpleTest("SimpleTest10"); 78 assert True(context.getPrimitives().getIntegerValue("$i.1") == 24);79 assert True(context.getPrimitives().getIntegerValue("$i.2") == 42);78 assertEquals(24,context.getPrimitives().getIntegerValue("$i.1")); 79 assertEquals(42,context.getPrimitives().getIntegerValue("$i.2")); 80 80 81 81 runSimpleTest("SimpleTest11"); … … 120 120 try { 121 121 runSimpleTest("SimpleTest23"); 122 assertEquals(context.getPrimitives().getIntegerValue("$i.Result"), 123 243); 124 assertEquals( 125 context.getPrimitives().getIntegerValue("$i.Exponent"), 0); 122 assertEquals(243,context.getPrimitives().getIntegerValue("$i.Result")); 123 assertEquals(0,context.getPrimitives().getIntegerValue("$i.Exponent")); 126 124 127 125 runSimpleTest("SimpleTest30"); 128 assertEquals(context.getPrimitives().getIntegerValue("$i.Result"), 129 243); 130 assertEquals( 131 context.getPrimitives().getIntegerValue("$i.Exponent"), 0); 126 assertEquals(243,context.getPrimitives().getIntegerValue("$i.Result")); 127 assertEquals(0,context.getPrimitives().getIntegerValue("$i.Exponent")); 132 128 } catch (Exception e) { 133 129 System.out.println("EVALUATION ERROR: " + e.getMessage()); … … 193 189 public void testSimpleTestSuite() { 194 190 try { 195 Simple.RunSimpleTests("SimpleTestSuite" );191 Simple.RunSimpleTests("SimpleTestSuite",true,false); 196 192 } catch (Exception e) { 197 193 System.out.println("EVALUATION ERROR: " + e.getMessage());
Note:
See TracChangeset
for help on using the changeset viewer.