Changeset 86 for trunk/src/org/expeditee/actions
- Timestamp:
- 06/05/08 10:11:18 (16 years ago)
- Location:
- trunk/src/org/expeditee/actions
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Actions.java
r80 r86 46 46 public class Actions { 47 47 48 private static final String INVALID_PARAMETERS_ERROR = "Invalid parameters for agent: "; //$NON-NLS-1$ 49 48 50 // the currently running agent (if there is one) 49 51 private static Agent _Agent = null; … … 164 166 * Clears out the Action and JAG Hashtables and refills them. Normally this 165 167 * is only called once when the system starts. 166 * @return a warning message if there were any problems loading agents or actions. 168 * 169 * @return a warning message if there were any problems loading agents or 170 * actions. 167 171 */ 168 172 public static Collection<String> Init() { 169 173 Collection<String> warnings = new LinkedList<String>(); 170 174 Class[] classes; 171 175 172 176 try { 173 177 classes = getClasses(AGENTS_PACKAGE); … … 327 331 328 332 for (Method possible : possibles) { 329 330 333 // try first with the launching item as a parameter 331 334 … … 346 349 e.printStackTrace(); 347 350 } 351 } 352 if (possibles.size() > 0) { 353 FrameGraphics.ErrorMessage("Incorrect parameters for " + mname); 354 } else { 355 assert(false); 356 FrameGraphics.ErrorMessage(mname + " action not found"); 348 357 } 349 358 } … … 386 395 // get the constructor for the JAG class 387 396 Constructor con = null; 388 Constructor constructors[]= agentClass.getConstructors();397 Constructor[] constructors = agentClass.getConstructors(); 389 398 Object[] params = null; 390 399 … … 397 406 params[0] = parameters; 398 407 break; 399 } else if (c.getParameterTypes().length == 0 && con == null) 408 } else if (c.getParameterTypes().length == 0 && con == null) { 400 409 con = c; 410 } 401 411 } 402 412 403 413 // if there is no constructor, return 404 414 if (con == null) { 405 FrameGraphics.DisplayMessage( "Invalid parametres for agent: "415 FrameGraphics.DisplayMessage(INVALID_PARAMETERS_ERROR 406 416 + nameWithCorrectCase); 407 417 // System.out.println("Constructor not found..."); … … 433 443 434 444 } catch (ClassNotFoundException cnf) { 435 FrameGraphics.ErrorMessage( "Error: '" +nameWithCorrectCase445 FrameGraphics.ErrorMessage(nameWithCorrectCase 436 446 + "' is not an action or agent."); 437 447 } catch (Exception e) { … … 540 550 } 541 551 // convert the value to an object 542 Object o = Conversion.Convert(paramTypes[ind], param); 543 if (o == null) 552 try { 553 Object o = Conversion.Convert(paramTypes[ind], param); 554 if (o == null) 555 return null; 556 objects[ind] = o; 557 } catch (Exception e) { 544 558 return null; 545 objects[ind] = o;559 } 546 560 } 547 561 -
trunk/src/org/expeditee/actions/Misc.java
r80 r86 11 11 import java.io.IOException; 12 12 import java.lang.reflect.Method; 13 import java.sql.Time; 13 14 import java.util.ArrayList; 14 15 import java.util.List; … … 22 23 import org.expeditee.gui.FrameMouseActions; 23 24 import org.expeditee.gui.TimeKeeper; 25 import org.expeditee.io.Logger; 24 26 import org.expeditee.items.Item; 25 27 import org.expeditee.items.Text; … … 54 56 public static void Restore() { 55 57 FrameIO.Reload(); 56 57 FrameGraphics.DisplayMessage("Restoration complete."); 58 //FrameGraphics.DisplayMessage("Restoration complete."); 58 59 } 59 60 … … 227 228 } 228 229 230 /** 231 * Creates a new Text Object containing statistics for the current tree. 232 */ 233 public static void GetCometStats(Frame frame) { 234 FrameGraphics.DisplayMessage("Extracting comet stats..."); 235 236 StringBuffer sb = new StringBuffer(); 237 Time active = frame.getCometActiveTime(true); 238 Time dark = frame.getCometDarkTime(true); 239 Time total = new Time(active.getTime() + dark.getTime()); 240 int length = frame.getCometLength(); 241 sb.append("CometName: ").append(frame.getName()).append('\n'); 242 sb.append("Length: ").append(length).append('\n'); 243 sb.append(" Current Average Total").append('\n'); 244 Time averageActive = new Time((long) (0.5 + active.getTime() 245 / (1.0 * length))); 246 Time averageDark = new Time((long) (0.5 + dark.getTime() 247 / (1.0 * length))); 248 Time averageTotal = new Time((long) (0.5 + total.getTime() 249 / (1.0 * length))); 250 Time currentActive = SessionStats.getFrameActiveTime(); 251 Time currentDark = SessionStats.getFrameDarkTime(); 252 Time currentTotal = SessionStats.getFrameTotalTime(); 253 254 sb.append("ActiveTime: ").append(Logger.EasyTimeFormat(currentActive)).append( 255 ' ').append(Logger.EasyTimeFormat(averageActive)).append( 256 ' ').append(Logger.EasyTimeFormat(active)).append('\n'); 257 sb.append(" DarkTime: ").append(Logger.EasyTimeFormat(currentDark)).append( 258 ' ').append(Logger.EasyTimeFormat(averageDark)).append( 259 ' ').append(Logger.EasyTimeFormat(dark)).append('\n'); 260 sb.append(" TotalTime: ").append(Logger.EasyTimeFormat(currentTotal)).append( 261 ' ').append(Logger.EasyTimeFormat(averageTotal)).append( 262 ' ').append(Logger.EasyTimeFormat(total)); 263 CreateTextItem(sb.toString()); 264 265 FrameGraphics.OverwriteMessage("Comet stats complete"); 266 } 267 229 268 public static void CreateTextItem(String itemText) { 230 269 SessionStats.CreatedText(); … … 260 299 public static void GetCurrentFrameFile() { 261 300 262 String fileContents = FrameIO.SaveFrame(DisplayIO.getCurrentFrame()); 263 264 Text text = DisplayIO.getCurrentFrame().createNewText(); 301 Frame current = DisplayIO.getCurrentFrame(); 302 current.change(); 303 String fileContents = FrameIO.SaveFrame(current); 304 305 Text text = current.createNewText(); 265 306 // We dont want the stats to wrap at all 266 307 text.setMaxSize(new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE)); … … 349 390 } 350 391 351 public static String SaveImage(BufferedImage screen, String format, String directory, String fileName){ 392 public static String SaveImage(BufferedImage screen, String format, 393 String directory, String fileName) { 352 394 // Check if we need to append the suffix 353 395 if (fileName.indexOf('.') < 0) 354 fileName += "." + format.toLowerCase(); 396 fileName += "." + format.toLowerCase(); 355 397 356 398 try { … … 370 412 return null; 371 413 } 372 414 373 415 public static String ImageFrame(Frame frame, String format, String directory) { 374 416 assert (frame != null); 375 417 376 418 FrameGraphics.UpdateBuffer(frame, false); 377 419 -
trunk/src/org/expeditee/actions/Simple.java
r80 r86 14 14 import java.util.Random; 15 15 16 import org.expeditee.agents.DefaultAgent; 16 17 import org.expeditee.agents.DisplayTree; 17 18 import org.expeditee.agents.WriteTree; … … 49 50 import org.expeditee.stats.SessionStats; 50 51 51 public class Simple {52 public class Simple implements Runnable { 52 53 53 54 private static final String DEFAULT_STRING = "$s."; … … 87 88 private static final String TOKEN_SEPARATOR = " +"; 88 89 89 private static final String RUN_FRAME_ACTION = "RunFrame"; 90 public static final String RUN_FRAME_ACTION = "runframe"; 91 92 public static final String DEBUG_FRAME_ACTION = "debugframe"; 90 93 91 94 /** … … 100 103 * Expeditee 101 104 */ 102 private static boolean _ acceptKeyboardInput = false;105 private static boolean _consumeKeyboardInput = false; 103 106 104 107 public static void ProgramFinished() { 105 108 _programsRunning--; 109 _stop = false; 106 110 } 107 111 108 112 private static LinkedList<Character> _KeyStrokes = new LinkedList<Character>(); 109 113 114 private static boolean _stop; 115 116 private static boolean _step; 117 118 private static int _stepPause = 0; 119 120 private static Color _stepColor; 121 122 private static boolean _nextStatement; 123 110 124 public static void KeyStroke(char c) { 125 126 111 127 _KeyStrokes.add(c); 112 128 } … … 116 132 } 117 133 118 public static boolean acceptKeyboardInput() {119 return _ acceptKeyboardInput && _programsRunning > 0;134 public static boolean consumeKeyboardInput() { 135 return _consumeKeyboardInput && _programsRunning > 0; 120 136 } 121 137 … … 134 150 do { 135 151 next = FrameIO.LoadNext(next); 136 } while (next != null 137 && (next.getTitleItem() == null || !RUN_FRAME_ACTION 138 .equalsIgnoreCase(next.getTitleItem().getFirstAction()))); 152 } while (next != null && next.isTestFrame()); 139 153 FrameUtils.DisplayFrame(next, true); 140 154 } … … 144 158 do { 145 159 prev = FrameIO.LoadPrevious(prev); 146 } while (prev != null 147 && (prev.getTitleItem() == null || !RUN_FRAME_ACTION 148 .equalsIgnoreCase(prev.getTitleItem().getFirstAction()))); 160 } while (prev != null && prev.isTestFrame()); 149 161 150 162 FrameUtils.DisplayFrame(prev, true); … … 156 168 do { 157 169 // check if its a test frame 158 if (next != null 159 && next.getTitleItem() != null 160 && RUN_FRAME_ACTION.equalsIgnoreCase(next.getTitleItem() 161 .getFirstAction())) { 170 if (next != null && next.isTestFrame()) { 162 171 lastTest = next; 163 172 break; … … 178 187 } 179 188 180 public static void RunSimpleTests(String frameset, boolean verbose) { 189 private String _frameset; 190 191 private boolean _verbose; 192 193 public Simple(String frameset, boolean verbose) { 194 _frameset = frameset; 195 _verbose = verbose; 196 } 197 198 public void run() { 181 199 int testsPassed = 0; 182 200 int testsFailed = 0; 183 201 184 202 FrameIO.SaveFrame(DisplayIO.getCurrentFrame(), false); 185 FrameGraphics.DisplayMessage("Starting test suite: " + frameset,203 FrameGraphics.DisplayMessage("Starting test suite: " + _frameset, 186 204 Color.CYAN); 187 205 188 // Get the next number in the inf file for the frameset189 int lastFrameNo = FrameIO.getLastNumber( frameset);190 191 // Loop through all the valid frames in the frameset206 // Get the next number in the inf file for the _frameset 207 int lastFrameNo = FrameIO.getLastNumber(_frameset); 208 209 // Loop through all the valid frames in the _frameset 192 210 for (int i = 1; i <= lastFrameNo; i++) { 193 String nextFrameName = frameset + i;211 String nextFrameName = _frameset + i; 194 212 Frame nextFrame = FrameIO.LoadFrame(nextFrameName); 195 213 if (nextFrame == null) … … 214 232 RunFrameAndReportError(title, new Context()); 215 233 _programsRunning--; 216 if ( verbose)234 if (_verbose) 217 235 FrameGraphics.DisplayMessage("Test passed: " 218 236 + title.toString(), Item.GREEN); … … 223 241 // Print out the reason for failed tests 224 242 FrameGraphics.LinkedErrorMessage(e.getMessage()); 243 if (Simple._stop) { 244 Simple._stop = false; 245 return; 246 } 225 247 } 226 248 } … … 240 262 } 241 263 242 public static void RunFrame(Item current) { 243 RunFrame(current, false); 244 } 245 246 public static void RunFrame(Item current, boolean acceptKeyboardInput) { 264 public static void RunSimpleTests(String frameset, boolean verbose) { 265 _stop = false; 266 Thread t = new Thread(new Simple(frameset, verbose)); 267 t.setPriority(Thread.MIN_PRIORITY); 268 t.start(); 269 } 270 271 private static void RunFrame(Item current, boolean acceptKeyboardInput, 272 boolean step, int pause, Color color) { 247 273 try { 248 _acceptKeyboardInput = acceptKeyboardInput; 274 DisplayIO.addToBack(current.getParent()); 275 276 _stepColor = color == null ? Color.green : color; 277 _stepColor = new Color(_stepColor.getRed(), _stepColor.getGreen(), 278 _stepColor.getBlue(), 50); 279 _stepPause = pause; 280 _step = step; 281 _consumeKeyboardInput = acceptKeyboardInput; 249 282 FrameIO.SaveFrame(DisplayIO.getCurrentFrame(), true); 250 283 … … 265 298 // _programsRunning--; 266 299 } 300 } 301 302 public static void RunFrame(Item current, boolean acceptKeyboardInput) { 303 RunFrame(current, acceptKeyboardInput, false, 0, null); 304 } 305 306 public static void RunFrame(Item current) { 307 RunFrame(current, false); 308 } 309 310 /** 311 * At present programs which accept keyboard input can not be debugged. 312 * 313 * @param current 314 * @param pause 315 */ 316 public static void DebugFrame(Item current, double pause, Color color) { 317 RunFrame(current, false, true, (int) (pause * 1000 + 0.5), color); 318 } 319 320 /** 321 * At present programs which accept keyboard input can not be debugged. 322 * 323 * @param current 324 * @param pause 325 * the time to pause between 326 */ 327 public static void DebugFrame(Item current, double pause) { 328 DebugFrame(current, pause, null); 329 } 330 331 public static void DebugFrame(Item current) { 332 DebugFrame(current, 0.2, null); 267 333 } 268 334 … … 290 356 291 357 Frame child = FrameIO.LoadFrame(current.getAbsoluteLink()); 358 359 if (_step) { 360 DisplayIO.setCurrentFrame(child); 361 DisplayIO.addToBack(child); 362 } 363 292 364 AgentStats.FrameExecuted(); 293 365 … … 299 371 300 372 // loop through non-title, non-name, non-annotation text items 301 List<Item> body = child.getItems(); 302 Text item = null; 373 List<Text> body = child.getBodyTextItems(false); 374 375 // if no item was found 376 if (body.size() == 0) 377 throw new Exception("No code to be executed: " + current.toString()); 378 303 379 Status lastItemStatus = Status.OK; 304 for (Item i : body) 305 // Ignore items that arent statements 306 if (isStatement(i)) { 307 item = (Text) i; 308 AgentStats.ItemExecuted(); 309 try { 310 311 lastItemStatus = RunItem(item, context, lastItemStatus); 312 313 if (lastItemStatus != Status.OK) { 314 if (lastItemStatus != Status.TrueIf 315 && lastItemStatus != Status.FalseIf) { 316 return lastItemStatus; 380 for (Text item : body) { 381 AgentStats.ItemExecuted(); 382 try { 383 Color oldColor = item.getBackgroundColor(); 384 if (_step) { 385 if (item.getLink() == null) { 386 item.setBackgroundColor(_stepColor); 387 }else{ 388 item.setSelectedMode(Item.SelectedMode.Normal,_stepColor); 389 } 390 FrameGraphics.Repaint(); 391 } 392 lastItemStatus = RunItem(item, context, lastItemStatus); 393 if (_step) { 394 if (item.getLink() != null) { 395 item.setBackgroundColor(_stepColor); 396 item.setSelectedMode(Item.SelectedMode.None); 397 FrameGraphics.Repaint(); 398 } 399 int timeRemaining; 400 if (_stepPause < 0) 401 timeRemaining = Integer.MAX_VALUE; 402 else 403 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"); 317 410 } 411 Thread.sleep(DefaultAgent.TIMER_RESOLUTION); 412 timeRemaining -= DefaultAgent.TIMER_RESOLUTION; 318 413 } 319 } catch (ArrayIndexOutOfBoundsException e) { 320 FlagError(item); 321 throw new Exception("Too few parametres: " 322 + item.toString()); 323 } catch (NullPointerException e) { 324 FlagError(item); 325 throw new Exception("Null pointer exception: " 326 + item.toString()); 327 } catch (RuntimeException e) { 328 FlagError(item); 329 throw new Exception(e.getMessage() + " " + item.toString()); 330 } catch (Exception e) { 331 throw new Exception(e.getMessage()); 332 } 333 } 334 335 // if no item was found 336 if (item == null) 337 throw new Exception("No code to be executed: " + current.toString()); 414 _nextStatement = false; 415 // Turn off the highlighting 416 item.setBackgroundColor(oldColor); 417 } 418 419 if (lastItemStatus != Status.OK) { 420 if (lastItemStatus != Status.TrueIf 421 && lastItemStatus != Status.FalseIf) { 422 return lastItemStatus; 423 } 424 } 425 } catch (ArrayIndexOutOfBoundsException e) { 426 FlagError(item); 427 throw new Exception("Too few parametres: " + item.toString()); 428 } catch (NullPointerException e) { 429 FlagError(item); 430 throw new Exception("Null pointer exception: " 431 + item.toString()); 432 } catch (RuntimeException e) { 433 FlagError(item); 434 throw new Exception(e.getMessage() + " " + item.toString()); 435 } catch (Exception e) { 436 throw new Exception(e.getMessage()); 437 } 438 } 439 440 if (_step) { 441 DisplayIO.setCurrentFrame(current.getParent()); 442 DisplayIO.removeFromBack(); 443 } 338 444 339 445 return Status.OK; 340 }341 342 private static boolean isStatement(Item i) {343 if (!(i instanceof Text))344 return false;345 346 Frame frame = i.getParent();347 348 if (i == frame.getTitleItem() || i == frame.getNameItem()349 || i.isAnnotation()) {350 return false;351 }352 353 return true;354 446 } 355 447 … … 541 633 private static Status RunItem(Text code, Context context, 542 634 Status lastItemStatus) throws Exception { 635 if (_stop) { 636 throw new Exception("Program terminated"); 637 } 543 638 544 639 String[] tokens = code.getProcessedCode(); … … 1805 1900 .StripTag( 1806 1901 ((Text) pauseItem).getFirstLine(), 1807 "@DisplayFramePause :"));1902 "@DisplayFramePause")); 1808 1903 } catch (NumberFormatException nfe) { 1809 1904 } … … 2242 2337 assertExactParametreCount(tokens, 3); 2243 2338 assertVariableType(tokens[1], 1, SPointer.associationPrefix); 2244 Map<String, String> map = (Map<String,String>) context.getPointers().getVariable(2245 tokens[1]).getValue();2246 for (Map.Entry entry: map.entrySet()){2339 Map<String, String> map = (Map<String, String>) context 2340 .getPointers().getVariable(tokens[1]).getValue(); 2341 for (Map.Entry entry : map.entrySet()) { 2247 2342 String value = entry.getValue().toString(); 2248 2343 String key = entry.getKey().toString(); … … 2259 2354 return Status.OK; 2260 2355 } 2261 2356 2262 2357 if (Primitives.isPrimitive(tokens[1]) 2263 2358 && Primitives.isPrimitive(tokens[2]) … … 2353 2448 return message.toString(); 2354 2449 } 2450 2451 public static void stop() { 2452 _stop = true; 2453 } 2454 2455 public static void nextStatement() { 2456 _nextStatement = true; 2457 } 2355 2458 }
Note:
See TracChangeset
for help on using the changeset viewer.