Changeset 181 for trunk/src/org/expeditee/actions/Actions.java
- Timestamp:
- 08/01/08 16:38:58 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Actions.java
r179 r181 15 15 import java.util.jar.JarFile; 16 16 import java.util.zip.ZipEntry; 17 18 import javax.swing.SwingUtilities;19 17 20 18 import org.expeditee.agents.Agent; … … 266 264 */ 267 265 private static boolean MethodCheck(Method m) { 268 // the return type must be void269 if (m.getReturnType() != void.class)270 return false;271 272 266 int mods = m.getModifiers(); 273 267 … … 300 294 * The action to perform 301 295 */ 302 public static void PerformAction(Frame source, Item launcher, String command) { 296 public static Object PerformAction(Frame source, Item launcher, 297 String command) throws Exception { 303 298 // if (!command.equalsIgnoreCase("Restore")) 304 299 // FrameIO.SaveFrame(source, false); … … 320 315 // check for protection on frame 321 316 if (ItemUtils.ContainsTag(source.getItems(), "@No" + mname)) { 322 MessageBay.displayMessage("Frame is protected by @No" + mname317 throw new RuntimeException("Frame is protected by @No" + mname 323 318 + " tag."); 324 return;325 319 } 326 320 … … 331 325 if (toRun == null) { 332 326 LaunchAgent(mname, command, source, launcher); 333 return ;327 return null; 334 328 } 335 329 … … 362 356 } 363 357 364 possible.invoke(null, parameters); 365 return; 358 return possible.invoke(null, parameters); 366 359 } catch (Exception e) { 367 360 Logger.Log(e); … … 369 362 } 370 363 } 371 if (possibles.size() > 0) { 372 MessageBay.errorMessage("Incorrect parameters for " + mname); 373 } else { 374 assert (false); 375 MessageBay.errorMessage(mname + " action not found"); 376 } 364 //If the actions was not found... then it is run as an agent 365 assert (possibles.size() > 0); 366 throw new RuntimeException("Incorrect parameters for " + mname); 377 367 } 378 368 … … 388 378 */ 389 379 private static void LaunchAgent(String name, String parameters, 390 Frame source, Item clicked) {380 Frame source, Item clicked) throws Exception { 391 381 // Use the correct case version for printing error messages 392 382 String nameWithCorrectCase = name; 393 383 name = name.toLowerCase(); 394 // save the current frame (if necesssary)395 // TODO make this nicer... ie. make Format an action rather than an396 // agent and save frames only before running agents397 if (!name.equalsIgnoreCase("format") && !name.equalsIgnoreCase("sort")) {398 FrameUtils.LeavingFrame(source);399 }400 384 401 385 try { 402 386 // check for stored capitalisation 403 if (_JAGs.containsKey(name .toLowerCase())) {404 name = _JAGs.get(name .toLowerCase());405 } else if (name. toLowerCase().endsWith("tree")) {387 if (_JAGs.containsKey(name)) { 388 name = _JAGs.get(name); 389 } else if (name.endsWith("tree")) { 406 390 parameters = name.substring(0, name.length() - "tree".length()) 407 391 + " " + parameters; 408 name = " WriteTree";409 } else if (name. toLowerCase().endsWith("frame")) {392 name = "writetree"; 393 } else if (name.endsWith("frame")) { 410 394 parameters = name 411 395 .substring(0, name.length() - "frame".length()) 412 396 + " " + parameters; 413 name = " WriteFrame";397 name = "writeframe"; 414 398 } 415 399 … … 437 421 // if there is no constructor, return 438 422 if (con == null) { 439 MessageBay.displayMessage(INVALID_PARAMETERS_ERROR423 throw new RuntimeException(INVALID_PARAMETERS_ERROR 440 424 + nameWithCorrectCase); 441 // System.out.println("Constructor not found...");442 return;443 425 } 444 426 … … 456 438 // check for errors during initialisation 457 439 if (!_Agent.initialise(source, itemParam)) { 458 MessageBay.errorMessage("Error initialising agent: " 440 _Agent = null; 441 throw new RuntimeException("Error initialising agent: " 459 442 + nameWithCorrectCase); 460 _Agent = null; 461 return; 443 } 444 445 // save the current frame (if necesssary) 446 // TODO make this nicer... ie. make Format an action rather than an 447 // agent and save frames only before running agents 448 if (!name.equals("format") && !name.equals("sort")) { 449 FrameUtils.LeavingFrame(source); 462 450 } 463 451 … … 478 466 // TODO We want to be able to navigate through the frames as 479 467 // the results are loading 480 481 468 Frame next = _Agent.getResultFrame(); 482 469 FrameUtils.DisplayFrame(next, true); … … 485 472 486 473 } catch (ClassNotFoundException cnf) { 487 MessageBay.errorMessage(nameWithCorrectCase 474 _Agent = null; 475 throw new RuntimeException(nameWithCorrectCase 488 476 + "' is not an action or agent."); 489 477 } catch (Exception e) { 490 MessageBay.errorMessage("Error creating Agent: '"491 + nameWithCorrectCase + "'");492 System.out.println("Agent set to Null.");493 478 _Agent = null; 494 479 e.printStackTrace(); 495 Logger.Log(e); 480 throw new RuntimeException("Error creating Agent: '" 481 + nameWithCorrectCase + "'"); 496 482 } 497 483 FrameGraphics.refresh(false); … … 554 540 555 541 // if the first class in the list is a frame or item, it is the source 556 // 542 //or launcher 557 543 // length must be at least one if we are still running 558 544 if (paramTypes[ind] == Frame.class) { … … 561 547 } 562 548 549 //Check if the second item is an item 563 550 if (paramCount > ind && Item.class.isAssignableFrom(paramTypes[ind])) { 564 551 objects[ind] = launcher; 565 552 ind++; 553 }//If there is stuff on the cursor use it for the rest of the params 554 else if (launcher != null && launcher.isFloating()){ 555 values = launcher.getText(); 566 556 } 567 557 … … 576 566 int endOfString = param.indexOf('"', 1); 577 567 if (endOfString > 0) { 578 param = param.substring( 0, endOfString);568 param = param.substring(1, endOfString); 579 569 } 580 570 } … … 708 698 return _Fonts; 709 699 } 700 701 public static Object PerformActionCatchErrors(Frame current, Item launcher, String command) { 702 try{ 703 return PerformAction(current, launcher, command); 704 }catch(Exception e) { 705 MessageBay.errorMessage(e.getMessage()); 706 } 707 return null; 708 } 710 709 }
Note:
See TracChangeset
for help on using the changeset viewer.