Changeset 108 for trunk/src/org/expeditee/actions/Simple.java
- Timestamp:
- 06/27/08 16:44:21 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Simple.java
r107 r108 4 4 import java.awt.Point; 5 5 import java.awt.event.InputEvent; 6 import java.awt.geom.Point2D; 6 7 import java.io.BufferedReader; 7 8 import java.io.InputStreamReader; … … 188 189 private String _frameset; 189 190 190 private boolean _verbose;191 private static boolean _verbose = false; 191 192 192 193 public Simple(String frameset, boolean verbose) { … … 216 217 if (nextFrame == null) 217 218 continue; 218 ItemframeTitle = nextFrame.getTitleItem();219 Text frameTitle = nextFrame.getTitleItem(); 219 220 if (frameTitle == null) 220 221 continue; 221 222 // Run the frames with the RunFrame action on the title 222 Itemtitle = frameTitle.copy();223 Text title = frameTitle.copy(); 223 224 List<String> actions = title.getAction(); 224 225 if (actions == null || title.isAnnotation()) … … 235 236 _KeyStrokes.clear(); 236 237 _programsRunning++; 237 RunFrameAndReportError(title, new Context()); 238 Context context = new Context(); 239 RunFrameAndReportError(title, context); 238 240 _programsRunning--; 239 241 // if the throws exception annotation is on the frame then … … 306 308 } 307 309 308 private static void RunFrame( Itemcurrent, boolean acceptKeyboardInput,310 private static void RunFrame(Text current, boolean acceptKeyboardInput, 309 311 boolean step, int pause, Color color) { 310 312 try { … … 321 323 // an item without a link signals to run the current frame 322 324 if (current.getLink() == null) { 325 //Make a copy but hide it 323 326 current = current.copy(); 324 327 current.setLink(DisplayIO.getCurrentFrame().getName()); … … 334 337 } 335 338 336 public static void RunFrame( Itemcurrent, boolean acceptKeyboardInput) {339 public static void RunFrame(Text current, boolean acceptKeyboardInput) { 337 340 RunFrame(current, acceptKeyboardInput, false, 0, null); 338 341 } 339 342 340 public static void RunFrame( Itemcurrent) {343 public static void RunFrame(Text current) { 341 344 RunFrame(current, false); 342 345 } … … 348 351 * @param pause 349 352 */ 350 public static void DebugFrame(Item current, float pause, Color color) { 353 public static void DebugFrame(Text current, float pause, Color color) { 354 if(isProgramRunning()){ 355 stop(); 356 } 351 357 RunFrame(current, false, true, Math.round(pause * 1000), color); 352 358 } … … 359 365 * the time to pause between 360 366 */ 361 public static void DebugFrame( Itemcurrent, float pause) {367 public static void DebugFrame(Text current, float pause) { 362 368 DebugFrame(current, pause, null); 363 369 } 364 370 365 public static void DebugFrame( Itemcurrent) {371 public static void DebugFrame(Text current) { 366 372 DebugFrame(current, -1.0F, null); 367 373 } … … 391 397 Frame child = FrameIO.LoadFrame(current.getAbsoluteLink()); 392 398 399 // Create frame variables for each linked annotation item on the frame 400 // which has a single word of text corresponding to the variable name 401 for (Text text : child.getAnnotationItems()) { 402 String link = text.getAbsoluteLink(); 403 if (link == null) 404 continue; 405 Frame frame = FrameIO.LoadFrame(link); 406 if (frame == null) 407 continue; 408 // Now save the frame as a variable 409 String varName = text.getText().substring(1).trim(); 410 if (varName.indexOf(' ') > 0) 411 continue; 412 context.getPointers().setObject(SPointer.framePrefix + varName, 413 frame); 414 context.getPrimitives().add(SString.prefix + varName, 415 new SString(frame.getName())); 416 } 417 393 418 if (_step) { 394 419 if (child != DisplayIO.getCurrentFrame()) { … … 419 444 Color oldColor = item.getBackgroundColor(); 420 445 if (_step) { 421 if (item.getLink() != null) { 422 pause(item); 423 item.setSelectedMode(Item.SelectedMode.Normal, 424 _stepColor); 425 } else { 426 item.setBackgroundColor(_stepColor); 427 } 428 FrameGraphics.Repaint(); 446 pause(item); 429 447 } 430 448 lastItemStatus = RunItem(item, context, lastItemStatus); … … 432 450 if (item.getLink() == null) { 433 451 item.setBackgroundColor(oldColor); 434 pause(item);435 452 } else { 436 453 item.setSelectedMode(Item.SelectedMode.None); … … 464 481 if (_step) { 465 482 DisplayIO.removeFromBack(); 466 DisplayIO.setCurrentFrame(current.getParent()); 483 if(DisplayIO.getCurrentFrame() != current.getParent()) 484 DisplayIO.setCurrentFrame(current.getParent()); 467 485 } 468 486 … … 776 794 assertExactParametreCount(tokens, 3); 777 795 778 Map map = (Map) context.getPointers().getVariable(tokens[1])796 Map<String,String> map = (Map<String,String>) context.getPointers().getVariable(tokens[1]) 779 797 .getValue(); 780 798 String attribute = context.getPrimitives().getStringValue( … … 812 830 // attribute without the value in the same item 813 831 if (!found && attributeItem != null) { 814 Point endPoint = attributeItem.getEndParagraphPosition(); 832 Point2D.Float endPoint = attributeItem 833 .getEndParagraphPosition(); 815 834 816 835 for (Text text : targetFrame.getBodyTextItems(true)) { … … 1050 1069 // attribute without the value in the same item 1051 1070 if (!found && attributeItem != null) { 1052 Point endPoint = attributeItem1071 Point2D.Float endPoint = attributeItem 1053 1072 .getEndParagraphPosition(); 1054 1073 … … 1112 1131 .getValue(); 1113 1132 t.setText(log); 1133 } else if (tokens[0].equals("getframeitemcount")) { 1134 String frameVar = DEFAULT_FRAME; 1135 String countVar = DEFAULT_INTEGER; 1136 if (tokens.length > 1) { 1137 assertExactParametreCount(tokens, 2); 1138 assertVariableType(tokens[1], 1, SPointer.framePrefix); 1139 frameVar = tokens[1]; 1140 countVar = tokens[2]; 1141 } 1142 Frame frame = (Frame) context.getPointers().getVariable( 1143 frameVar).getValue(); 1144 Integer count = frame.getItems(true).size(); 1145 context.getPrimitives().setValue(countVar, 1146 new SInteger(count)); 1114 1147 } 1115 1148 } else if (tokens[0].equals("getassociation")) { … … 1189 1222 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 1190 1223 // assertPrimitiveType(tokens[2], 2); 1191 Integer size = ( (Item) context.getPointers().getVariable(1192 tokens[1]).getValue()).getSize();1224 Integer size = (int) ((Item) context.getPointers() 1225 .getVariable(tokens[1]).getValue()).getSize(); 1193 1226 context.getPrimitives().setValue(tokens[2], 1194 1227 new SInteger(size)); … … 1402 1435 String codeText = getMessage(tokens, context, code.toString(), " ", 1403 1436 1); 1404 Text dynamicCode = new Text( 1,codeText);1437 Text dynamicCode = new Text(codeText); 1405 1438 RunItem(dynamicCode, context, Status.OK); 1406 1439 } else if (tokens[0].equals("runoscommand")) { … … 1682 1715 try { 1683 1716 success = FrameIO.DeleteFrame(frame); 1684 if (!success )1717 if (!success && _verbose) 1685 1718 FrameGraphics.WarningMessage(errorMessage); 1686 1719 } catch (Exception e) { 1687 1720 // If an exception is thrown then success is false 1688 FrameGraphics 1689 .WarningMessage(errorMessage 1690 + (e.getMessage() != null ? ". " 1691 + e.getMessage() : "")); 1721 if (_verbose) { 1722 FrameGraphics.WarningMessage(errorMessage 1723 + (e.getMessage() != null ? ". " + e.getMessage() 1724 : "")); 1725 } 1692 1726 } 1693 1727 if (tokens.length > 2) { … … 1700 1734 tokens[1]); 1701 1735 boolean success = FrameIO.DeleteFrameset(framesetName); 1702 if (!success )1736 if (!success && _verbose) { 1703 1737 FrameGraphics.WarningMessage("Error deleting " + framesetName); 1738 } 1704 1739 if (tokens.length > 2) { 1705 1740 context.getPrimitives().setValue(tokens[2], … … 1722 1757 boolean success = FrameIO.CopyFrameset(framesetToCopy, 1723 1758 copiedFrameset); 1724 if (!success )1759 if (!success && _verbose) 1725 1760 FrameGraphics.WarningMessage("Error copying " + framesetToCopy); 1726 1761 if (tokens.length > 3) { … … 1746 1781 context.getPointers().setObject(tokens[2], freshCopy); 1747 1782 String fileContents = FrameIO.ForceSaveFrame(freshCopy); 1783 FrameIO.ResumeCache(); 1784 // Need to add the new copy to the cache in case it is edited by 1785 // other simple statements 1786 FrameIO.addToCache(freshCopy); 1748 1787 boolean success = fileContents != null; 1749 if (!success )1788 if (!success && _verbose) 1750 1789 FrameGraphics.WarningMessage("Error copying " 1751 1790 + frameToCopy.getName()); 1752 FrameIO.ResumeCache();1753 1791 if (tokens.length > 4) { 1754 1792 context.getPrimitives().setValue(tokens[4], … … 2014 2052 count = countCharsInString(((Text) item).getText(), pattern); 2015 2053 context.getPrimitives().setValue(tokens[3], new SInteger(count)); 2054 } else if (tokens[0].equals("clearframe")) { 2055 String frameVar = DEFAULT_FRAME; 2056 if (tokens.length > 1) { 2057 assertMinParametreCount(tokens, 1); 2058 assertVariableType(tokens[1], 1, SPointer.framePrefix); 2059 frameVar = tokens[1]; 2060 } 2061 boolean success = true; 2062 try { 2063 Frame frameToClear = (Frame) context.getPointers().getVariable( 2064 frameVar).getValue(); 2065 frameToClear.clear(false); 2066 assert (frameToClear.getItems().size() <= 1); 2067 } catch (Exception e) { 2068 success = false; 2069 } 2070 if (tokens.length > 2) { 2071 assertExactParametreCount(tokens, 2); 2072 context.getPrimitives().setValue(tokens[2], 2073 new SBoolean(success)); 2074 } 2016 2075 } else if (tokens[0].equals("parseframename")) { 2017 2076 assertExactParametreCount(tokens, 4); … … 2026 2085 } catch (Exception e) { 2027 2086 success = false; 2028 FrameGraphics.WarningMessage("Error parsing " + frameName); 2087 if (_verbose) 2088 FrameGraphics.WarningMessage("Error parsing " + frameName); 2029 2089 } 2030 2090 // assertPrimitiveType(tokens[2], 2); … … 2491 2551 FrameGraphics.DisplayMessage("Running SimpleProgram...", Color.BLUE); 2492 2552 } 2553 2554 public static boolean isVerbose() { 2555 return _verbose; 2556 } 2493 2557 }
Note:
See TracChangeset
for help on using the changeset viewer.