Changeset 7
- Timestamp:
- 05/01/08 12:26:53 (16 years ago)
- Location:
- trunk/src/org/expeditee
- Files:
-
- 22 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/actions/Actions.java
r4 r7 276 276 // loose changes 277 277 if (toRun.getDeclaringClass().getName().equals( 278 NAVIGATIONS_CLASS)) 278 NAVIGATIONS_CLASS)) { 279 279 FrameIO.SaveFrame(DisplayIO.getCurrentFrame()); 280 } 280 281 281 282 // if there are duplicate methods with the same name -
trunk/src/org/expeditee/actions/Misc.java
r4 r7 6 6 import java.awt.image.BufferedImage; 7 7 import java.io.File; 8 import java.io.FileInputStream;9 8 import java.io.FileNotFoundException; 10 import java.io.FileOutputStream;11 9 import java.io.IOException; 12 10 import java.util.List; … … 113 111 Frame toDelete = DisplayIO.getCurrentFrame(); 114 112 DisplayIO.Back(); 113 String deletedFrame = toDelete.getFrameName(); 114 String deletedFrameNameLowercase = deletedFrame.toLowerCase(); 115 115 try { 116 String deletedFrame = toDelete.getFrameName();117 116 boolean del = FrameIO.DeleteFrame(toDelete); 118 117 if (!del) { … … 123 122 for (Item i : current.getItems()) 124 123 if (i.getLink() != null 125 && i.get Link().toLowerCase().equals(126 toDelete.getFrameName().toLowerCase())) {124 && i.getAbsoluteLink().toLowerCase().equals( 125 deletedFrameNameLowercase)) { 127 126 i.setLink(null); 128 127 } 129 128 130 129 FrameGraphics.Repaint(); 131 FrameGraphics.DisplayMessage(deletedFrame 132 + " Deleted."); 130 FrameGraphics.DisplayMessage(deletedFrame + " Deleted."); 133 131 } 134 132 } catch (IOException ioe) { 135 FrameGraphics.ErrorMessage("Error trying to delete " 136 + toDelete.getFrameName() +":\n" + ioe.getMessage());133 FrameGraphics.ErrorMessage("Error trying to delete " + deletedFrame 134 + ":\n" + ioe.getMessage()); 137 135 } 138 136 } … … 240 238 FrameGraphics.Repaint(); 241 239 } 242 240 243 241 /** 244 242 * Creates a new Text Object containing the available fonts. … … 246 244 public static void GetAvailableFontFamilyNames() { 247 245 248 String[] availableFonts = GraphicsEnvironment.getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); 246 String[] availableFonts = GraphicsEnvironment 247 .getLocalGraphicsEnvironment().getAvailableFontFamilyNames(); 249 248 StringBuilder fontsList = new StringBuilder(); 250 for (String s : availableFonts) {249 for (String s : availableFonts) { 251 250 fontsList.append(s).append('\n'); 252 251 } 253 252 254 253 Text text = DisplayIO.getCurrentFrame().createNewText(); 255 254 // We dont want the stats to wrap at all … … 364 363 public static void CopyFile(String existingFile, String newFileName) { 365 364 try { 366 //TODO is there a built in method which will do this faster? 367 368 FrameGraphics.DisplayMessage("Copying file " + existingFile + " to " + newFileName + "..."); 369 FileInputStream is = new FileInputStream(existingFile); 370 FileOutputStream os = new FileOutputStream( 371 newFileName, false); 372 int data; 373 while ( (data = is.read()) != -1 ) { 374 os.write(data); 375 } 376 os.flush(); 377 os.close(); 378 is.close(); 365 // TODO is there a built in method which will do this faster? 366 367 FrameGraphics.DisplayMessage("Copying file " + existingFile 368 + " to " + newFileName + "..."); 369 FrameIO.copyFile(existingFile, newFileName); 379 370 FrameGraphics.DisplayMessage("File copied successfully"); 380 371 } catch (FileNotFoundException e) { 381 372 FrameGraphics.DisplayMessage("Error opening file: " + existingFile); 382 } catch (Exception e) {373 } catch (Exception e) { 383 374 FrameGraphics.DisplayMessage("File could not be copied"); 384 375 } … … 446 437 447 438 for (Item i : body) 448 if (i != child.getTitle() && i != child.get Name()439 if (i != child.getTitle() && i != child.getFrameNameItem() 449 440 && !i.isAnnotation()) { 450 441 item = i; -
trunk/src/org/expeditee/actions/Simple.java
r4 r7 13 13 import org.expeditee.gui.FrameGraphics; 14 14 import org.expeditee.gui.FrameIO; 15 import org.expeditee.gui.FrameKeyboardActions; 15 16 import org.expeditee.gui.FrameMouseActions; 16 17 import org.expeditee.gui.FrameUtils; … … 18 19 import org.expeditee.items.Dot; 19 20 import org.expeditee.items.Item; 21 import org.expeditee.items.ItemUtils; 20 22 import org.expeditee.items.Line; 21 23 import org.expeditee.items.Text; … … 59 61 }; 60 62 61 private static final String BREAK_TEXT = "exitrepeat"; 62 63 private static final String CONTINUE_TEXT = "nextrepeat"; 63 private static final String BREAK2_TEXT = "exitrepeat"; 64 65 private static final String BREAK_TEXT = "break"; 66 67 private static final String CONTINUE2_TEXT = "nextrepeat"; 68 69 private static final String CONTINUE_TEXT = "continue"; 64 70 65 71 private static final String RETURN_TEXT = "return"; … … 155 161 156 162 FrameIO.SaveFrame(DisplayIO.getCurrentFrame(), false); 157 158 163 FrameGraphics.DisplayMessage("Starting test suite: " + frameset, 159 164 Color.CYAN); … … 229 234 230 235 private static void FlagError(Item item) { 231 item.setColor(Color.CYAN);236 // item.setColor(Color.CYAN); 232 237 FrameUtils.DisplayFrame(item.getParent().getFrameName(), true); 238 item.showHighlight(true, Color.CYAN); 233 239 FrameIO.SaveFrame(item.getParent()); 234 240 } … … 306 312 Frame frame = i.getParent(); 307 313 308 if (i == frame.getTitle() || i == frame.get Name() || i.isAnnotation()) {314 if (i == frame.getTitle() || i == frame.getFrameNameItem() || i.isAnnotation()) { 309 315 return false; 310 316 } … … 319 325 * @return 320 326 */ 321 private static String[] parseStatement(String statement) { 322 return statement.split(TOKEN_SEPARATOR); 327 private static String[] parseStatement(Text code) throws Exception { 328 String statement = code.getTextNoList(); 329 ArrayList<String> tokens = new ArrayList<String>(); 330 331 for (int i = 0; i < statement.length(); i++) { 332 char c = statement.charAt(i); 333 // ignore spaces 334 if (c != ' ') { 335 int startOfToken = i; 336 if (c == '\"') { 337 int endOfToken = statement.length() - 1; 338 // find the end of the string literal 339 while (statement.charAt(endOfToken) != '\"') 340 endOfToken--; 341 if (endOfToken > startOfToken) { 342 tokens.add(statement.substring(startOfToken, 343 endOfToken + 1)); 344 } else { 345 throw new Exception("Expected matching \" " 346 + code.toString()); 347 } 348 break; 349 } else if (c == '#' || c == '/') { 350 break; 351 } else { 352 // read in a normal token 353 while (++i < statement.length() 354 && statement.charAt(i) != ' ') 355 ; 356 tokens.add(statement.substring(startOfToken, i) 357 .toLowerCase()); 358 } 359 } 360 } 361 362 String[] a = new String[tokens.size()]; 363 a = tokens.toArray(a); 364 code.setProcessedCode(a); 365 return a; 323 366 } 324 367 … … 464 507 private static Status RunItem(Text code, Context context, 465 508 Status lastItemStatus) throws Exception { 466 String codeText = code.getTextNoList(); 509 510 String[] tokens = code.getProcessedCode(); 511 512 if (tokens == null) { 513 tokens = parseStatement(code); 514 } 515 467 516 // Comments without links are a no-op 468 if ( codeText.startsWith("#") || codeText.startsWith("//")) {517 if (tokens.length == 0) { 469 518 if (code.getLink() == null) 470 519 return Status.OK; … … 473 522 } 474 523 475 // Now check for code statements476 codeText = codeText.trim();477 String[] tokens = parseStatement(codeText.toLowerCase());478 524 // At present only set statements can have literals so they 479 525 // are the only statements that we have to worry about string 480 526 // literals 481 assert (tokens.length > 0);482 527 if (tokens[0].equals("call") && tokens.length >= 2) { 483 528 return Call(tokens, code, context); … … 497 542 // check for strings enclosed in quotes 498 543 if (tokens[2].startsWith("\"")) { 499 if (tokens[tokens.length - 1].endsWith("\"")) { 500 context.getPrimitives().setValue( 501 tokens[1], 502 new SString(codeText.substring(codeText 503 .indexOf("\"") + 1, codeText 504 .length() - 1))); 505 return Status.OK; 506 } else 507 throw new Exception("Expected matching \" " 508 + code.toString()); 544 context.getPrimitives().setValue( 545 tokens[1], 546 new SString(tokens[2].substring(1, 547 tokens[2].length() - 1))); 548 return Status.OK; 549 509 550 // set a literal 510 551 } else if (tokens.length == 3) { … … 517 558 throw new RuntimeException(e.getMessage()); 518 559 } 560 } else if (tokens[0].equals("setframevalue")) { 561 assertMinParametreCount(tokens, 4); 562 assertVariableType(tokens[1], 1, SPointer.framePrefix); 563 564 // Get the attribute to be searched for on the target frame 565 Frame targetFrame = (Frame) context.getPointers().getVariable( 566 tokens[1]).getValue(); 567 String targetAttribute = context.getPrimitives() 568 .getStringValue(tokens[2]).toLowerCase() 569 + ":"; 570 String value = context.getPrimitives() 571 .getStringValue(tokens[3]); 572 Boolean found = false; 573 Text attributeItem = null; 574 Text valueItem = null; 575 // Begin the search 576 for (Text text : targetFrame.getBodyTextItems()) { 577 String s = text.getTextNoList().toLowerCase(); 578 if (s.startsWith(targetAttribute)) { 579 attributeItem = text; 580 AttributeUtils.setSingleValue(attributeItem, value); 581 found = true; 582 break; 583 } 584 } 585 // Keep looking for a matching value nearby if we found an 586 // attribute without the value in the same item 587 if (!found && attributeItem != null) { 588 Point endPoint = attributeItem.getEndParagraphPosition(); 589 590 for (Text text : targetFrame.getBodyTextItems()) { 591 Point startPoint = text.getPosition(); 592 if (Math.abs(startPoint.y - endPoint.y) < 10 593 && Math.abs(startPoint.x - endPoint.x) < 20) { 594 found = true; 595 valueItem = text; 596 text.setText(value); 597 break; 598 } 599 } 600 } 601 602 // Set the values of the output parametres 603 context.getPrimitives() 604 .setValue(tokens[4], new SBoolean(found)); 605 if (tokens.length > 5) { 606 context.getPointers().setObject(tokens[5], attributeItem); 607 if (tokens.length > 6) { 608 context.getPointers().setObject(tokens[6], valueItem); 609 } 610 } 611 612 return Status.OK; 519 613 } else if (tokens[0].startsWith("setitem")) { 520 614 if (tokens[0].equals("setitemposition")) { … … 651 745 throw new UnitTestFailedException("null", value.toString()); 652 746 return Status.OK; 747 } else if (tokens[0].equals("assertnotnull")) { 748 assertExactParametreCount(tokens, 1); 749 Object value = context.getPrimitives().getVariable(tokens[1]) 750 .getValue(); 751 if (value == null) 752 throw new UnitTestFailedException("not null", "null"); 753 return Status.OK; 754 } else if (tokens[0].equals("assertdefined")) { 755 assertExactParametreCount(tokens, 1); 756 if (!context.isDefined(tokens[1])) 757 throw new UnitTestFailedException("defined", "not defined"); 758 return Status.OK; 759 } else if (tokens[0].equals("assertnotdefined")) { 760 assertExactParametreCount(tokens, 1); 761 if (context.isDefined(tokens[1])) 762 throw new UnitTestFailedException("defined", "not defined"); 763 return Status.OK; 653 764 } else if (tokens[0].equals("assertequals")) { 654 765 assertExactParametreCount(tokens, 2); … … 751 862 context.getPrimitives().setValue(frameNameVar, 752 863 frame.getFrameName()); 864 return Status.OK; 865 } else if (tokens[0].startsWith("getframefilepath")) { 866 assertExactParametreCount(tokens, 2); 867 String frameName = context.getPrimitives().getStringValue( 868 tokens[1]); 869 String path = FrameIO.LoadFrame(frameName).path; 870 String filePath = FrameIO.getFrameFullPathName(path, 871 frameName); 872 context.getPrimitives().setValue(tokens[2], filePath); 753 873 return Status.OK; 754 874 } … … 862 982 new SInteger(AgentStats.getMilliSecondsElapsed())); 863 983 return Status.OK; 984 } else if (tokens[0].equals("getlastnumberinframeset")) { 985 String framesetNameVar = DEFAULT_STRING; 986 String countVar = DEFAULT_INTEGER; 987 if (tokens.length > 1) { 988 assertMinParametreCount(tokens, 2); 989 framesetNameVar = tokens[1]; 990 countVar = tokens[2]; 991 } 992 String frameset = context.getPrimitives().getStringValue( 993 framesetNameVar); 994 long count = FrameIO.getLastNumber(frameset); 995 context.getPrimitives().setValue(countVar, new SInteger(count)); 996 return Status.OK; 997 } else if (tokens[0].equals("getlistofframesets")) { 998 String stringVar = DEFAULT_ITEM; 999 if (tokens.length > 1) { 1000 assertMinParametreCount(tokens, 1); 1001 stringVar = tokens[1]; 1002 } 1003 context.getPrimitives().setValue(stringVar, 1004 FrameIO.getFramesetList()); 1005 return Status.OK; 864 1006 } 865 1007 } else if (tokens[0].equals("or")) { … … 903 1045 FrameGraphics.DisplayMessage(((Text) message).copy()); 904 1046 } catch (NullPointerException e) { 905 // Just ignore not text items!906 1047 FrameGraphics.DisplayMessage("null"); 907 1048 } catch (ClassCastException e) { … … 914 1055 } else if (tokens[0].equals("messageln") 915 1056 || tokens[0].equals("messageline") 1057 || tokens[0].equals("messagelnnospaces") 1058 || tokens[0].equals("messagelinenospaces") 916 1059 || tokens[0].equals("errorln") || tokens[0].equals("errorline")) { 917 StringBuilder message = new StringBuilder(); 918 if (tokens.length == 1) { 919 message.append(context.getPrimitives().getVariable( 920 DEFAULT_STRING).stringValue() 921 + " "); 922 } else { 923 for (int i = 1; i < tokens.length; i++) { 924 if (Primitives.isPrimitive(tokens[i])) { 925 message.append(context.getPrimitives().getVariable( 926 tokens[i]).stringValue() 927 + " "); 928 } else 929 throw new Exception("Illegal parametre: [" + tokens[i] 930 + "] in line " + code.toString()); 931 } 932 } 1060 String message = getMessage(tokens, context, code.toString(), 1061 tokens[0].endsWith("nospaces") ? "" : " "); 933 1062 934 1063 if (tokens[0].equals("errorln") || tokens[0].equals("errorline")) 935 FrameGraphics.ErrorMessage(message .toString());1064 FrameGraphics.ErrorMessage(message); 936 1065 else 937 FrameGraphics.DisplayMessageAlways(message.toString()); 1066 FrameGraphics.DisplayMessageAlways(message); 1067 return Status.OK; 1068 } else if (tokens[0].equals("typein") 1069 || tokens[0].equals("typeinnospaces")) { 1070 1071 String s = getMessage(tokens, context, code.toString(), tokens[0] 1072 .equals("typein") ? " " : ""); 1073 for (int i = 0; i < s.length(); i++) { 1074 FrameKeyboardActions.processChar(s.charAt(i)); 1075 Thread.sleep(25); 1076 } 938 1077 return Status.OK; 939 1078 } else if (tokens[0].startsWith("else")) { … … 1015 1154 tokens[2]) <= 0; 1016 1155 parametres = 2; 1156 } else if (tokens[0].equals("ifexistingframe")) { 1157 result = FrameIO.DoesFrameExist(context.getPrimitives() 1158 .getStringValue(tokens[1])); 1159 } else if (tokens[0].equals("ifexistingframeset")) { 1160 String framesetName = context.getPrimitives().getStringValue( 1161 tokens[1]); 1162 result = FrameIO.DoesFramesetExist(framesetName); 1017 1163 } else { 1018 1164 // assertVariableType(variable, 1, SPointer.itemPrefix); … … 1164 1310 1165 1311 return Status.OK; 1312 } else if (tokens[0].equals("deleteitem")) { 1313 assertMinParametreCount(tokens, 1); 1314 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 1315 Item item = (Item) context.getPointers().getVariable(tokens[1]) 1316 .getValue(); 1317 item.delete(); 1318 return Status.OK; 1319 } else if (tokens[0].equals("deleteframe")) { 1320 assertMinParametreCount(tokens, 1); 1321 assertVariableType(tokens[1], 1, SPointer.framePrefix); 1322 Frame frame = (Frame) context.getPointers().getVariable(tokens[1]) 1323 .getValue(); 1324 boolean success = FrameIO.DeleteFrame(frame); 1325 1326 if (tokens.length > 2) { 1327 context.getPrimitives().setValue(tokens[2], 1328 new SBoolean(success)); 1329 } 1330 1331 return Status.OK; 1332 } else if (tokens[0].equals("deleteframeset")) { 1333 assertMinParametreCount(tokens, 1); 1334 String framesetName = context.getPrimitives().getStringValue( 1335 tokens[1]); 1336 boolean success = FrameIO.DeleteFrameset(framesetName); 1337 1338 if (tokens.length > 2) { 1339 context.getPrimitives().setValue(tokens[2], 1340 new SBoolean(success)); 1341 } 1342 1343 return Status.OK; 1344 } else if (tokens[0].equals("copyitem")) { 1345 assertMinParametreCount(tokens, 2); 1346 assertVariableType(tokens[1],1,SPointer.itemPrefix); 1347 assertVariableType(tokens[2],2,SPointer.itemPrefix); 1348 Item item = (Item)context.getPointers().getVariable(tokens[1]).getValue(); 1349 Item copy = item.copy(); 1350 context.getPointers().setObject(tokens[2], copy); 1351 1352 return Status.OK; 1353 }else if (tokens[0].equals("copyframeset")) { 1354 assertMinParametreCount(tokens, 2); 1355 String framesetToCopy = context.getPrimitives().getStringValue( 1356 tokens[1]); 1357 String copiedFrameset = context.getPrimitives().getStringValue( 1358 tokens[2]); 1359 boolean success = FrameIO.CopyFrameset(framesetToCopy, 1360 copiedFrameset); 1361 1362 if (tokens.length > 3) { 1363 context.getPrimitives().setValue(tokens[3], 1364 new SBoolean(success)); 1365 } 1366 1367 return Status.OK; 1368 } else if (tokens[0].equals("copyframe")) { 1369 assertMinParametreCount(tokens, 2); 1370 assertVariableType(tokens[1],1,SPointer.framePrefix); 1371 assertVariableType(tokens[2],2,SPointer.framePrefix); 1372 Frame frameToCopy = (Frame) context.getPointers().getVariable( 1373 tokens[1]).getValue(); 1374 FrameIO.SuspendCache(); 1375 Frame freshCopy = FrameIO.LoadFrame(frameToCopy.getFrameName()); 1376 // Change the frameset if one was provided 1377 if (tokens.length > 3) { 1378 String destinationFrameset = context.getPrimitives() 1379 .getStringValue(tokens[3]); 1380 freshCopy.setFrameset(destinationFrameset); 1381 }// Otherwise add it to the end of this frameset 1382 freshCopy.setFrameNumber(FrameIO.getLastNumber(freshCopy 1383 .getFramesetName()) + 1); 1384 context.getPointers().setObject(tokens[2], freshCopy); 1385 String fileContents = FrameIO.ForceSaveFrame(freshCopy); 1386 boolean success = fileContents != null; 1387 FrameIO.ResumeCache(); 1388 if (tokens.length > 4) { 1389 context.getPrimitives().setValue(tokens[4], 1390 new SBoolean(success)); 1391 } 1392 return Status.OK; 1166 1393 } else if (tokens[0].equals("createframe")) { 1167 1394 … … 1237 1464 context.getPrimitives().setValue(nextCharVarName, 1238 1465 new SCharacter(nextChar)); 1466 1467 return Status.OK; 1468 } else if (tokens[0].equals("openreadfile")) { 1469 assertVariableType(tokens[1], 1, SString.prefix); 1470 assertVariableType(tokens[2], 2, SPointer.filePrefix); 1471 1472 if (tokens.length > 3) { 1473 assertVariableType(tokens[3], 3, SBoolean.prefix); 1474 context.openReadFile(tokens[1], tokens[2], tokens[3]); 1475 } else 1476 context.openReadFile(tokens[1], tokens[2]); 1477 1478 return Status.OK; 1479 } else if (tokens[0].equals("readlinefile") 1480 || tokens[0].equals("readlnfile")) { 1481 assertVariableType(tokens[1], 1, SPointer.filePrefix); 1482 1483 if (tokens.length > 3) { 1484 assertVariableType(tokens[3], 3, SBoolean.prefix); 1485 context.readLineFile(tokens[1], tokens[2], tokens[3]); 1486 } else 1487 context.readLineFile(tokens[1], tokens[2]); 1488 1489 return Status.OK; 1490 } else if (tokens[0].equals("readitemfile")) { 1491 assertVariableType(tokens[1], 1, SPointer.filePrefix); 1492 assertVariableType(tokens[2], 1, SPointer.itemPrefix); 1493 1494 if (tokens.length > 3) { 1495 assertVariableType(tokens[3], 3, SBoolean.prefix); 1496 context.readItemFile(tokens[1], tokens[2], tokens[3]); 1497 } else 1498 context.readItemFile(tokens[1], tokens[2]); 1239 1499 1240 1500 return Status.OK; … … 1276 1536 1277 1537 return Status.OK; 1538 } else if (tokens[0].equals("displayframeset")) { 1539 assertMinParametreCount(tokens, 1); 1540 String framesetName = context.getPrimitives().getStringValue( 1541 tokens[1]); 1542 int lastFrameNo = FrameIO.getLastNumber(framesetName); 1543 int firstFrameNo = 0; 1544 double pause = 0.0; 1545 // get the first and last frames to display if they were proided 1546 if (tokens.length > 2) { 1547 firstFrameNo = (int) context.getPrimitives().getIntegerValue( 1548 tokens[2]); 1549 if (tokens.length > 3) { 1550 lastFrameNo = (int) context.getPrimitives() 1551 .getIntegerValue(tokens[3]); 1552 if (tokens.length > 4) { 1553 pause = context.getPrimitives().getDoubleValue( 1554 tokens[4]); 1555 } 1556 } 1557 } 1558 // Display the frames 1559 String adjustedFramesetName = FrameUtils 1560 .GetFramesetNameAdjusted(framesetName); 1561 for (int i = firstFrameNo; i <= lastFrameNo; i++) { 1562 Frame frame = FrameIO.LoadFrame(adjustedFramesetName + i); 1563 if (frame != null) { 1564 double thisFramesPause = pause; 1565 // check for change in delay for this frame only 1566 Item pauseItem = ItemUtils.FindTag(frame.getItems(), 1567 "@DisplayFramePause:"); 1568 if (pauseItem != null) { 1569 try { 1570 // attempt to read in the delay value 1571 thisFramesPause = Double.parseDouble(ItemUtils 1572 .StripTag( 1573 ((Text) pauseItem).getFirstLine(), 1574 "@DisplayFramePause:")); 1575 } catch (NumberFormatException nfe) { 1576 } 1577 } 1578 DisplayIO.setCurrentFrame(frame); 1579 pause(thisFramesPause); 1580 } 1581 } 1582 return Status.OK; 1583 } else if (tokens[0].equals("createframeset")) { 1584 String framesetName = DEFAULT_STRING; 1585 String successVar = null; 1586 if (tokens.length > 1) { 1587 framesetName = tokens[1]; 1588 if (tokens.length > 2) 1589 successVar = tokens[2]; 1590 } 1591 context.createFrameset(framesetName, successVar); 1592 return Status.OK; 1278 1593 } else if (tokens[0].equals("concatstr")) { 1279 1594 assertMinParametreCount(tokens, 3); … … 1436 1751 } 1437 1752 1438 double time = context.getPrimitives().getDoubleValue(lengthVar); 1439 for (int i = 0; i < time * 10; i++) { 1440 Thread.yield(); 1441 Thread.sleep(100); 1442 } 1753 pause(context.getPrimitives().getDoubleValue(lengthVar)); 1443 1754 return Status.OK; 1444 1755 } else if (tokens[0].equals("glidecursorto")) { … … 1473 1784 Thread.sleep(milliseconds % timeInterval); 1474 1785 DisplayIO.setCursorPosition(finalX, finalY); 1786 return Status.OK; 1787 } else if (tokens[0].equals("glideitemto")) { 1788 assertMinParametreCount(tokens, 3); 1789 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 1790 Item item = (Item) context.getPointers().getVariable(tokens[1]) 1791 .getValue(); 1792 int finalX = (int) context.getPrimitives().getIntegerValue( 1793 tokens[2]); 1794 int finalY = (int) context.getPrimitives().getIntegerValue( 1795 tokens[3]); 1796 1797 // DisplayIO.setCursorPosition(item.getX(), item.getY()); 1798 // FrameMouseActions.pickup(item); 1799 1800 int milliseconds = 1000; 1801 if (tokens.length > 4) 1802 milliseconds = (int) (context.getPrimitives().getDoubleValue( 1803 tokens[4]) * 1000); 1804 1805 int initialX = item.getX(); 1806 int initialY = item.getY(); 1807 // int initialX = DisplayIO.getMouseX(); 1808 // int initialY = DisplayIO.getMouseY(); 1809 1810 final int timeInterval = 40; 1811 1812 int deltaX = (int) (finalX - initialX); 1813 int deltaY = (int) (finalY - initialY); 1814 1815 int intervals = milliseconds / timeInterval; 1816 for (double i = 0; i < intervals; i++) { 1817 int newX = initialX + (int) (deltaX * i / intervals); 1818 int newY = initialY + (int) (deltaY * i / intervals); 1819 Thread.yield(); 1820 Thread.sleep(timeInterval); 1821 // DisplayIO.setCursorPosition(newX, newY); 1822 1823 item.setPosition(newX, newY); 1824 DisplayIO.repaint(); 1825 } 1826 // Thread.yield(); 1827 Thread.sleep(milliseconds % timeInterval); 1828 item.setPosition(finalX, finalY); 1829 // DisplayIO.setCursorPosition(finalX, finalY); 1830 FrameMouseActions.anchor(item); 1831 Frame.FreeItems.clear(); 1832 FrameGraphics.Repaint(); 1833 // FrameMouseActions.updateCursor(); 1475 1834 return Status.OK; 1476 1835 } … … 1487 1846 status = Status.OK; 1488 1847 return status; 1489 } else if (tokens[0].equals(CONTINUE_TEXT)) { 1848 } else if (tokens[0].equals(CONTINUE_TEXT) 1849 || tokens[0].equals(CONTINUE2_TEXT)) { 1490 1850 return Status.Continue; 1491 } else if (tokens[0].equals(BREAK_TEXT)) { 1851 } else if (tokens[0].equals(BREAK_TEXT) 1852 || tokens[0].equals(BREAK2_TEXT)) { 1492 1853 return Status.Break; 1493 1854 } else if (tokens[0].equals(RETURN_TEXT)) { … … 1536 1897 assertVariableType(tokens[1], 1, SPointer.filePrefix); 1537 1898 context.closeWriteFile(tokens[1]); 1899 1900 return Status.OK; 1901 } else if (tokens[0].equals("closereadfile")) { 1902 assertVariableType(tokens[1], 1, SPointer.filePrefix); 1903 context.closeReadFile(tokens[1]); 1538 1904 1539 1905 return Status.OK; … … 1550 1916 } 1551 1917 } else if (tokens.length == 3) { 1552 if (tokens[0].equals("foreach")) { 1918 if (tokens[0].startsWith("foreach")) { 1919 Class itemType = Object.class; 1920 String type = tokens[0].substring("foreach".length()); 1921 // Check the type of foreach loop 1922 // and set the item type to iterate over 1923 if (type.equals("dot")) { 1924 itemType = Dot.class; 1925 } else if (type.equals("text")) { 1926 itemType = Text.class; 1927 } else if (type.equals("line")) { 1928 itemType = Line.class; 1929 } 1930 1553 1931 assertVariableType(tokens[1], 1, SPointer.itemPrefix); 1554 1932 assertVariableType(tokens[2], 2, SPointer.framePrefix); … … 1556 1934 tokens[2]).getValue(); 1557 1935 // Create the ip variable 1936 Item frameName = currFrame.getFrameNameItem(); 1937 Item frameTitle = currFrame.getTitle(); 1938 1558 1939 for (Item i : currFrame.getItems()) { 1940 if (i == frameName || i == frameTitle) 1941 continue; 1942 if (!(itemType.isInstance(i))) 1943 continue; 1944 1559 1945 context.getPointers().setObject(tokens[1], i); 1560 1946 Status status = RunFrameAndReportError(code, context); 1561 1947 // check if we need to exit this loop because of 1562 // statements in 1563 // the code that was run 1948 // statements in the code that was run 1564 1949 if (status == Status.Exit || status == Status.Return) 1565 1950 return status; … … 1633 2018 } 1634 2019 2020 private static void pause(double time) throws Exception { 2021 for (int i = 0; i < time * 10; i++) { 2022 Thread.yield(); 2023 Thread.sleep(100); 2024 } 2025 } 2026 1635 2027 public static int countCharsInString(String s, String pattern) { 1636 2028 String newString = s; … … 1668 2060 throw new IncorrectParametreCountException(parametreCount); 1669 2061 } 2062 2063 private static String getMessage(String[] tokens, Context context, 2064 String code, String separator) throws Exception { 2065 StringBuilder message = new StringBuilder(); 2066 if (tokens.length == 1) { 2067 message.append(context.getPrimitives().getVariable(DEFAULT_STRING) 2068 .stringValue()); 2069 } else { 2070 for (int i = 1; i < tokens.length; i++) { 2071 if (Primitives.isPrimitive(tokens[i])) { 2072 message.append(context.getPrimitives().getVariable( 2073 tokens[i]).stringValue() 2074 + separator); 2075 } else 2076 throw new Exception("Illegal parametre: [" + tokens[i] 2077 + "] in line " + code); 2078 } 2079 } 2080 return message.toString(); 2081 } 1670 2082 } -
trunk/src/org/expeditee/agents/ComputeTree.java
r4 r7 98 98 AttributeUtils.setSingleValue(frame.getTitle(), result.toString()); 99 99 frameCount++; 100 100 FrameIO.ForceSaveFrame(frame); 101 101 102 return result; 102 103 } -
trunk/src/org/expeditee/agents/CopyTree.java
r4 r7 38 38 if (_lastNumber < 0) { 39 39 // create the new frameset 40 Frame one = FrameIO.CreateFrameset(_nameTo, init.path); 41 _framePath = one.path; 42 _lastNumber = -1; 43 _firstNumber = 1; 40 try { 41 Frame one = FrameIO.CreateFrameset(_nameTo, init.path); 44 42 45 // copy the original .0 frame 46 Frame zero = FrameIO.LoadFrame(init.getFramesetNameAdjusted() + "0"); 47 processFrame(zero); 43 _framePath = one.path; 44 _lastNumber = -1; 45 _firstNumber = 1; 46 47 // copy the original .0 frame 48 Frame zero = FrameIO.LoadFrame(init.getFramesetNameAdjusted() 49 + "0"); 50 processFrame(zero); 51 } catch (Exception e) { 52 // TODO fix this up later. 53 } 48 54 } else { 49 55 // get the frame path … … 120 126 } 121 127 } 122 123 if (changed) 128 if (changed) { 124 129 FrameIO.SaveFrame(toParse); 130 } 125 131 } 126 132 127 133 message("Tree successfully copied to " + _nameTo); 128 FrameUtils.DisplayFrame(Frame.GetFramesetNameAdjusted(_nameTo) + _firstNumber); 134 FrameUtils.DisplayFrame(FrameUtils.GetFramesetNameAdjusted(_nameTo) 135 + _firstNumber); 129 136 } 130 137 -
trunk/src/org/expeditee/gui/Browser.java
r4 r7 37 37 // private static final JScrollPane scrollPane = new JScrollPane(); 38 38 39 public static Browser _theBrowser; 40 39 41 /** 40 42 * Constructs a new Browser object, then launches it … … 43 45 */ 44 46 public static void main(String[] args) { 45 Browser b= new Browser();47 _theBrowser = new Browser(); 46 48 // Why do we want to ignore repaint? 47 49 // b.setIgnoreRepaint(true); 48 b.requestFocus();50 _theBrowser.requestFocus(); 49 51 // FrameGraphics.ForceRepaint(); 50 52 } 51 53 52 54 public void setSizes(Dimension size) { 53 55 setSize(size); … … 63 65 .getHeight() / 2))); 64 66 65 FrameGraphics.setMaxSize( size);67 FrameGraphics.setMaxSize(this.getContentPane().getSize()); 66 68 } 67 69 … … 75 77 Frame profile = FrameIO.LoadProfile(UserSettings.Username); 76 78 if (profile == null) { 79 try{ 77 80 profile = FrameIO.CreateNewProfile(UserSettings.Username); 81 }catch(Exception e){ 82 //TODO fix this later 83 } 78 84 } 79 85 FrameUtils.ParseProfile(profile); … … 110 116 setVisible(true); 111 117 112 g = (Graphics2D) getGraphics(); 118 setupGraphics(); 119 120 // required to accept TAB key 121 setFocusTraversalKeysEnabled(false); 122 123 assert (UserSettings.FirstFrame != null); 124 Frame firstFrame = FrameIO.LoadFrame(UserSettings.FirstFrame); 125 126 DisplayIO.setCurrentFrame(firstFrame); 127 128 // Create the action handler for the 129 FrameMouseActions mouse = new FrameMouseActions(); 130 131 this.getContentPane().addMouseListener(mouse); 132 this.getContentPane().addMouseMotionListener(mouse); 133 this.addKeyListener(new FrameKeyboardActions()); 134 this.getContentPane().addMouseWheelListener(mouse); 135 } 136 137 private void setupGraphics() { 138 g = (Graphics2D) this.getContentPane().getGraphics(); 113 139 assert g != null; 114 140 g.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, 115 141 RenderingHints.VALUE_TEXT_ANTIALIAS_ON); 116 142 g.setFont(g.getFont().deriveFont(40f)); 117 118 FrameGraphics.setDisplayGraphics((Graphics2D) getGraphics()); 119 120 // required to accept TAB key 121 setFocusTraversalKeysEnabled(false); 122 123 assert (UserSettings.FirstFrame != null); 124 Frame firstFrame = FrameIO.LoadFrame(UserSettings.FirstFrame); 125 126 DisplayIO.setCurrentFrame(firstFrame); 127 128 // Create the action handler for the 129 FrameMouseActions mouse = new FrameMouseActions(); 130 131 this.addMouseListener(mouse); 132 this.addMouseMotionListener(mouse); 133 this.addKeyListener(new FrameKeyboardActions()); 134 this.addMouseWheelListener(mouse); 135 136 // Rob: Why is all this being done???? 137 g.dispose(); 138 g = null; 143 FrameGraphics.setDisplayGraphics(g); 139 144 } 140 145 … … 158 163 */ 159 164 public void componentResized(ComponentEvent e) { 160 FrameGraphics.setMaxSize(this.getSize());161 // FrameGraphics.Repaint();165 setSizes(this.getSize()); 166 setupGraphics(); 162 167 repaint(); 163 168 //System.out.println("Resize"); … … 181 186 */ 182 187 public void componentHidden(ComponentEvent e) { 183 }184 185 public int getTitleBarHeight() {186 Rectangle contentbounds = getContentPane().getBounds();187 contentbounds = this.getGlassPane().getBounds();188 // contentbounds = this.getRootPane().getBounds();189 int titleheight = getSize().height - contentbounds.height;190 191 return titleheight;192 188 } 193 189 -
trunk/src/org/expeditee/gui/DisplayIO.java
r4 r7 15 15 16 16 import org.expeditee.items.Item; 17 import org.expeditee.items. ItemPermission;17 import org.expeditee.items.Picture; 18 18 import org.expeditee.stats.SessionStats; 19 19 … … 59 59 * The title to display in the Title bar. 60 60 */ 61 public static final String TITLE = "Exp 13Mar2008A";61 public static final String TITLE = "Exp01May2008A"; 62 62 63 63 private DisplayIO() { … … 80 80 _VisitedFrames[0] = new Stack<String>(); 81 81 _VisitedFrames[1] = new Stack<String>(); 82 UpdateTitle();83 82 } 84 83 … … 175 174 176 175 public static void setCursorPosition(int x, int y, boolean forceArrow) { 177 y += getOffset();178 179 176 if (Frame.itemAttachedToCursor()) { 180 177 List<Item> toMove = Frame.FreeItems; … … 205 202 FrameMouseActions.MouseY = y; 206 203 207 _Robot.mouseMove(_Browser.getDrawingAreaX() + x, _Browser 208 .getDrawingAreaY() 209 + y); 210 204 _Robot.mouseMove((int)_Browser.getContentPane().getLocationOnScreen().getX() + x, (int)_Browser.getContentPane().getLocationOnScreen().getY() + y); 211 205 } 212 206 … … 269 263 } 270 264 271 Item Permissionip = FrameUtils.getCurrentItem();272 if (ip == null || ip.Item == null)265 Item ip = FrameUtils.getCurrentItem(); 266 if (ip == null) 273 267 _VisitedFrames[side].push(toAdd.getFrameName()); 274 268 else … … 344 338 345 339 FrameGraphics.Repaint(); 340 UpdateTitle(); 346 341 } 347 342 348 343 public static void UpdateTitle() { 349 StringBuffer title = new StringBuffer(TITLE );344 StringBuffer title = new StringBuffer(TITLE + " ["); 350 345 351 346 if (FrameGraphics.isAudienceMode()) 352 347 title.append(" - Audience Mode"); 353 // title.append(SessionStats.getShortStats());*/ 348 else 349 title.append(SessionStats.getShortStats()).append(']'); 354 350 355 351 _Browser.setTitle(title.toString()); … … 452 448 453 449 /** 454 *455 */456 public static int getOffset() {457 if (_Browser != null)458 return /* getMenuHeight() + */_Browser.getTitleBarHeight();459 460 // default offset (if the menu has not been created yet, etc)461 return 0;462 }463 464 /**465 450 * Returns the current mouse X coordinate. This coordinate is relative to 466 451 * the left edge of the frame the mouse is in. It takes into account the … … 483 468 */ 484 469 public static int getMouseY() { 485 return FrameMouseActions.MouseY - getOffset();470 return FrameMouseActions.MouseY; 486 471 } 487 472 … … 522 507 for (Item i : frame.getItems()) 523 508 if (i.getLink() != null 524 && i.get Link().toLowerCase().equals(oldFrame)) {509 && i.getAbsoluteLink().toLowerCase().equals(oldFrame)) { 525 510 i.showHighlight(true, BACK_HIGHLIGHT_COLOR); 511 //check if its an @f item and if so update the buffer 512 if (i instanceof Picture) { 513 Picture p = (Picture)i; 514 p.refresh(); 515 } 526 516 } 527 517 -
trunk/src/org/expeditee/gui/Frame.java
r4 r7 163 163 _change = value; 164 164 165 if (_change) 165 if (_change) { 166 166 setBufferValid(false); 167 _saved = false; 168 } 167 169 } 168 170 169 171 // indicates the frame has changed 170 p rivatevoid change() {172 public void change() { 171 173 setChanged(true); 172 174 } … … 185 187 } 186 188 187 return _body; 189 List<Item> visibleItems = new ArrayList<Item>(); 190 191 for (Item i : _body) { 192 if (i.isVisible()) 193 visibleItems.add(i); 194 } 195 196 return visibleItems; 188 197 } 189 198 … … 200 209 for (Item i : getItems()) { 201 210 // only add up normal body text items 202 if (i instanceof Text && i != _frameName && i != frameTitle 203 && !i.isAnnotation()) { 211 if ((i instanceof Text) && i != frameTitle && !i.isAnnotation()) { 204 212 bodyTextItems.add((Text) i); 205 213 } … … 207 215 208 216 return bodyTextItems; 217 209 218 } 210 219 … … 291 300 List<Item> items = getItems(); 292 301 for (Item i : items) { 293 if (i instanceof Text /* && !i.isAnnotation() */&& i != _frameName)302 if (i instanceof Text) 294 303 return (Text) i; 295 304 } … … 298 307 } 299 308 300 public Text get Name() {309 public Text getFrameNameItem() { 301 310 return _frameName; 302 311 } … … 372 381 } 373 382 374 /*375 * public void setItemTemplate(Text template) { if (template != null)376 * _template = template; else _template = UserSettings.ItemTemplate.copy(); }377 */378 379 383 /** 380 384 * Returns any items on this frame that are within the given Shape. Also … … 390 394 391 395 for (Item i : _body) 392 if (i.intersects(poly)) {// || shape.contains(i.getX(), 393 // i.getY())){ 396 if (i.isVisible() && i != _frameName && i.intersects(poly)) { 394 397 if (!results.contains(i)) 395 398 results.add(i); 396 /*397 * List<Item> connected = i.getConnected(); for(Item item :398 * connected) if(!results.contains(item))399 * results.add(item);//All(i.getConnected());400 */401 399 } 402 400 403 401 for (Overlay o : _overlays) 404 402 results.addAll(o.Frame.getItemsWithin(poly)); 405 406 /*407 * ArrayList<Dot> toInclude = new ArrayList<Line>(0); //remove lines408 * that do not have a point anchored in the polygon for(Item i :409 * results){ if(i instanceof Line){ Line line = (Line) i;410 * if(!(results.contains(line.getStartDot())) &&411 * !(results.contains(line.getEndDot()))) removeLines.add(line); } }412 *413 * results.removeAll(removeLines);414 */415 403 416 404 return results; … … 442 430 } 443 431 444 /**445 * Adjusts a frameset name so a period is appended if it ends in a digit.446 * This form of the frameset name is used when referencing frames in the447 * frame set.448 *449 * @param frameset450 * @return451 */452 public static String GetFramesetNameAdjusted(String frameset) {453 return frameset454 + (Character.isDigit(frameset.charAt(frameset.length() - 1)) ? "."455 : "");456 }457 458 432 public void setFrameName(String framename) { 459 433 int num = Conversion.getFrameNumber(framename); … … 477 451 478 452 if (_frameName != null) { 479 removeItem(_frameName);480 453 id = _frameName.getID(); 481 } else 454 } else { 482 455 id = -1 * getNextItemID(); 483 456 } 484 457 _frameName = new Text(id); 458 _frameName.setMaxSize(FrameGraphics.getMaxFrameSize()); 485 459 _frameName.setText(getFramesetNameAdjusted() + _number); 486 460 _frameName.setPosition(FrameGraphics.getMaxFrameSize().width … … 488 462 - org.expeditee.io.Conversion.X_ADJUST, 489 463 org.expeditee.io.Conversion.Y_ADJUST); 490 addItem(_frameName);491 492 464 setChanged(oldchange); 493 465 } … … 603 575 if (item != null) { 604 576 if (_body.contains(item)) { 605 System.out.println("Item (" + item.getClass().getSimpleName()606 577 // System.out.println("Item (" + item.getClass().getSimpleName() 578 // + ") with ID " + item.getID() + " already in body."); 607 579 return; 608 580 } … … 687 659 688 660 // if the change was to characteristics 689 if ( _body.contains(undo)) {661 if (undo.isVisible() && _body.contains(undo)) { 690 662 Item old = _body.get(_body.indexOf(undo)); 691 663 _body.set(_body.indexOf(old), undo); … … 742 714 } 743 715 744 public Item getFrameNameItem() {745 return _frameName;746 }747 748 716 /** 749 717 * Returns the format version of this Frame … … 858 826 for (int i = ind - 1; i >= 0; i--) { 859 827 Item check = _body.get(i); 860 861 if (FrameUtils.inSameColumn(check, current)) 828 if (check.isVisible() && FrameUtils.inSameColumn(check, current)) 862 829 return check; 863 830 } … … 912 879 for (int i = _body.indexOf(from); i < _body.size(); i++) { 913 880 Item item = _body.get(i); 914 if (i sNormalTextItem(item)) {881 if (item.isVisible() && isNormalTextItem(item)) { 915 882 if (FrameUtils.inSameColumn(from, item)) 916 883 column.add(item); … … 983 950 984 951 List<Item> copies = ItemUtils.CopyItems(toMergeWith.getItems()); 952 copies.remove(toMergeWith.getFrameNameItem()); 985 953 986 954 for (Item i : copies) { … … 1010 978 else if (FrameIO 1011 979 .isValidFrameName(((Text) i).getFirstLine())) { 980 // If we get hear we are merging frames 1012 981 merge(FrameIO.LoadFrame(((Text) i).getFirstLine())); 1013 982 } … … 1025 994 public void clear() { 1026 995 List<Item> newBody = new ArrayList<Item>(0); 1027 1028 996 for (Item i : _body) 1029 if (i.isAnnotation() || i == get Name() || i == getTitle())997 if (i.isAnnotation() || i == getFrameNameItem() || i == getTitle()) 1030 998 newBody.add(i); 1031 999 … … 1069 1037 return getAnnotationTemplate(); 1070 1038 case '/': 1039 case '#': 1071 1040 return getCodeCommentTemplate(); 1072 1041 default: … … 1099 1068 return d; 1100 1069 } 1101 1102 /**1103 * Creates a JMenu from the Items present on this Frame and adds it to the1104 * Menus on the Display1105 */1106 /*1107 * public void createMenu() { for (Item i : _body) { if (ItemUtils.isTag(i,1108 * ItemUtils.TAG_MENU) && i.getLink() != null) { Frame nextMenu =1109 * FrameIO.LoadFrame(i.getLink()); JMenu menu = nextMenu.createSubMenu();1110 * DisplayIO.addMenu(menu); } } }1111 */1112 1113 /**1114 * Creates a new JMenu from the Items present on this Frame1115 *1116 * @return The newly created JMenu1117 */1118 /*1119 * private JMenu createSubMenu() { Text frameTitle = getTitle();1120 *1121 * if (frameTitle == null) FrameUtils.Parse(this);1122 *1123 * if (frameTitle == null || frameTitle.getFirstLine() == null) return null;1124 *1125 * JMenu menu = new JMenu(frameTitle.getFirstLine());1126 *1127 * boolean literal = false; String litTitle = null;1128 *1129 * for (Item i : _body) { // if the @lit tag is active if (literal) {1130 * literal = false; if (litTitle == null) litTitle = ((Text)1131 * i).getFirstLine(); JMenuItem item = new JMenuItem(litTitle);1132 * item.addActionListener(new MenuAction(i, true)); menu.add(item); //1133 * non-annotation items with links or actions are put on the // menu } else1134 * if (i != _frameName && i instanceof Text && !i.isAnnotation() &&1135 * (i.getLink() != null || i.getAction() != null)) { JMenuItem item = new1136 * JMenuItem(((Text) i).getText().get(0)); item.addActionListener(new1137 * MenuAction(i, false)); menu.add(item); // if this is another menu frame }1138 * else if (i.getLink() != null && ItemUtils.isTag(i, ItemUtils.TAG_MENU)) {1139 * Frame nextMenu = FrameIO.LoadFrame(i.getLink());1140 * menu.add(nextMenu.createSubMenu()); // if this menu is continued on1141 * another frame } else if (i.getLink() != null && ItemUtils.isTag(i,1142 * ItemUtils.TAG_MENU_NEXT)) {1143 *1144 * Frame nextMenu = FrameIO.LoadFrame(i.getLink()); JMenu nmenu =1145 * nextMenu.createSubMenu(); for(int m = 0; m < nmenu.getComponentCount();1146 * m++) menu.add(nmenu.getComponent(m)); // if this is a @lit tag, then the1147 * next item is copied } else if (ItemUtils.isTag(i, ItemUtils.TAG_LITERAL)) {1148 * literal = true; String title = ItemUtils.StripTag(((Text)1149 * i).getFirstLine(), ItemUtils.GetTag(ItemUtils.TAG_LITERAL)); if1150 * (title.length() > 0) litTitle = title; else litTitle = null; } }1151 *1152 * return menu; }1153 */1154 1155 /*1156 * private class MenuAction implements ActionListener { private Item _source =1157 * null;1158 *1159 * private boolean _copy = false;1160 *1161 * public MenuAction(Item source, boolean copy) { _source = source; _copy =1162 * copy; }1163 *1164 * public void actionPerformed(ActionEvent ae) { if (_copy) { Item copy =1165 * _source.copy(); copy.setX(DisplayIO.getMouseX());1166 * copy.setY(DisplayIO.getMouseY()); FrameMouseActions.pickup(copy); return; }1167 *1168 * if (_source.getAction() != null) { _source.performActions(); } else {1169 * FrameUtils.DisplayFrame(_source.getLink()); } } }1170 */1171 1070 1172 1071 public boolean isSaved() { -
trunk/src/org/expeditee/gui/FrameCreator.java
r4 r7 9 9 10 10 private String _name; 11 11 12 12 private final static int START_Y = 40; 13 13 … … 20 20 private int _maxX = 0; 21 21 22 private int _lastY = 22 private int _lastY = START_Y; 23 23 24 24 private Text _Mnext = new Text(-1, "@Next"); … … 31 31 32 32 public FrameCreator(String name, boolean recreate) { 33 int num = -1;34 if (!recreate)35 num = FrameIO.getLastNumber(name);36 37 33 Frame toUse = null; 38 39 if (num == -1) 40 toUse = FrameIO.CreateFrameset(name, FrameIO.HELP_PATH); 41 else 42 toUse = FrameIO.CreateFrame(name, name, null); 43 34 try { 35 toUse = FrameIO 36 .CreateFrameset(name, FrameIO.PROFILE_PATH, recreate); 37 } catch (Exception e) { 38 if (toUse == null) 39 toUse = FrameIO.CreateFrame(name, name, null); 40 } 44 41 _name = name; 45 42 _lastY += toUse.getTitle().getPosition().y; … … 57 54 * at the newly created Frame, and _lastY is reset 58 55 */ 59 public void createNextFrame() { 60 Frame newFrame = FrameIO.CreateFrame(_current.getFramesetName(), 61 _name, null); 56 public boolean createNextFrame() { 57 try { 58 Frame newFrame = FrameIO.CreateFrame(_current.getFramesetName(), 59 _name, null); 62 60 63 // add link to previous frame64 _prev = _Mprev.copy();65 _prev.setID(newFrame.getNextItemID());66 _prev.setLink(_current.getFrameName());67 newFrame.addItem(_prev);61 // add link to previous frame 62 _prev = _Mprev.copy(); 63 _prev.setID(newFrame.getNextItemID()); 64 _prev.setLink(_current.getFrameName()); 65 newFrame.addItem(_prev); 68 66 69 // add link to new frame70 _next = _Mnext.copy();71 _next.setID(_current.getNextItemID());72 _next.setLink(newFrame.getFrameName());73 _current.addItem(_next);74 FrameIO.SaveFrame(_current, false);67 // add link to new frame 68 _next = _Mnext.copy(); 69 _next.setID(_current.getNextItemID()); 70 _next.setLink(newFrame.getFrameName()); 71 _current.addItem(_next); 72 FrameIO.SaveFrame(_current, false); 75 73 76 // update\reset globals 77 _current = newFrame; 78 _lastY = START_Y + _current.getTitle().getPosition().y;; 79 _lastX = START_X; 80 _maxX = 0; 74 // update\reset globals 75 _current = newFrame; 76 _lastY = START_Y + _current.getTitle().getPosition().y; 77 ; 78 _lastX = START_X; 79 _maxX = 0; 80 return true; 81 } catch (Exception e) { 82 return false; 83 } 81 84 } 82 85 83 public void addItem(Item toAdd) { 84 // if we have reached the end of the Y axis, try moving over on the X 85 // axis 86 if (_lastY >= _Mprev.getY() - _Mprev.getBoundsHeight()) { 87 _lastX = _maxX + 10; 88 _lastY = START_Y; 86 public boolean addItem(Item toAdd) { 87 try { 88 // if we have reached the end of the Y axis, try moving over on the 89 // X 90 // axis 91 if (_lastY >= _Mprev.getY() - _Mprev.getBoundsHeight()) { 92 _lastX = _maxX + 10; 93 _lastY = START_Y; 94 } 95 96 // if there is no more room on the X axis, we have to start a new 97 // frame 98 if (toAdd.getBoundsWidth() + _lastX > FrameGraphics.getMaxSize().width) { 99 createNextFrame(); 100 } 101 102 toAdd.setPosition(_lastX, _lastY); 103 toAdd.setOffset(0, 0); 104 toAdd.setID(_current.getNextItemID()); 105 106 _current.addItem(toAdd); 107 // _current.addAllItems(items); 108 109 FrameIO.SaveFrame(_current, false); 110 111 _lastY = toAdd.getY() + toAdd.getBoundsHeight(); 112 _maxX = Math.max(toAdd.getX() + toAdd.getBoundsWidth(), _maxX); 113 return true; 114 } catch (Exception e) { 115 return false; 89 116 } 90 91 // if there is no more room on the X axis, we have to start a new frame92 if (toAdd.getBoundsWidth() + _lastX > FrameGraphics.getMaxSize().width) {93 createNextFrame();94 }95 96 toAdd.setPosition(_lastX, _lastY);97 toAdd.setOffset(0, 0);98 toAdd.setID(_current.getNextItemID());99 100 /*101 * List<Item> items = new ArrayList<Item>(4);102 *103 * items.add(_current.getName()); items.add(_current.getTitle());104 * items.add(_prev); items.add(_next);105 *106 * _current.getItems().removeAll(items);107 *108 * //new system.agents.Format().process(_current);109 *110 * //FrameUtils.Align(items, toAdd, true);111 */112 _current.addItem(toAdd);113 // _current.addAllItems(items);114 115 FrameIO.SaveFrame(_current, false);116 117 _lastY = toAdd.getY() + toAdd.getBoundsHeight();118 _maxX = Math.max(toAdd.getX() + toAdd.getBoundsWidth(), _maxX);119 117 } 120 118 -
trunk/src/org/expeditee/gui/FrameGraphics.java
r4 r7 126 126 127 127 // Mike assumes this is the height of the Message window? 128 _MaxSize.setSize(max.width, max.height - DisplayIO.getOffset() 129 - MESSAGE_BUFFER_HEIGHT); 128 _MaxSize.setSize(max.width, max.height - MESSAGE_BUFFER_HEIGHT); 130 129 if (DisplayIO.getCurrentFrame() != null) { 131 130 DisplayIO.getCurrentFrame().setBuffer(null); … … 183 182 if (g != null 184 183 && (!isAudienceMode() 185 || (isAudienceMode() && !i.isAnnotation()) || i == FrameUtils.LastEdited)) 186 / / do not paint the name of overlay frames187 if (i.getParent() == null188 || i.getParent() == DisplayIO.getCurrentFrame()189 || i.getParent() == DisplayIO.getOppositeFrame()190 || i != i.getParent().getName()) {191 Graphics2D tg = (Graphics2D) g.create();192 i.paint(tg);193 tg.dispose();194 195 184 || (isAudienceMode() && !i.isAnnotation()) || i == FrameUtils.LastEdited)) { 185 /* 186 * // do not paint the name of overlay frames if (i.getParent() == 187 * null || i.getParent() == DisplayIO.getCurrentFrame() || 188 * i.getParent() == DisplayIO.getOppositeFrame() || i != 189 * i.getParent().getFrameNameItem()) { 190 */ 191 Graphics2D tg = (Graphics2D) g.create(); 192 i.paint(tg); 193 tg.dispose(); 194 } 196 195 } 197 196 … … 230 229 231 230 Graphics2D bg = (Graphics2D) buffer.getGraphics(); 232 // Text items should automatically be Anti-Aliased now233 /*234 * bg.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING,235 * RenderingHints.VALUE_TEXT_ANTIALIAS_ON);236 */237 231 238 232 // Nicer looking lines, but may be too jerky while … … 252 246 else { 253 247 paintItems.addAll(toPaint.getItems()); 254 paintItems.remove(toPaint.getFrameNameItem());255 248 } 256 249 PaintPictures(bg, paintItems); … … 307 300 PaintLines(bg, Frame.FreeItems); 308 301 } 309 302 if (paintOverlay) { 303 PaintItem(bg, toPaint.getFrameNameItem()); 304 } 310 305 bg.dispose(); 311 306 } … … 377 372 // set the clipping area 378 373 ((Graphics2D) g).setClip(0, 0, DisplayIO.getMiddle() - 1, 379 _MaxSize.height + DisplayIO.getOffset()); 380 g.drawImage(left, 0, DisplayIO.getOffset(), 374 _MaxSize.height); 375 g.drawImage(left, 0, 0, DisplayIO.DEFAULT_BACKGROUND, null); 376 ((Graphics2D) g).setClip(null); 377 g.drawImage(right, DisplayIO.getMiddle() + 1, 0, 381 378 DisplayIO.DEFAULT_BACKGROUND, null); 382 ((Graphics2D) g).setClip(null);383 g.drawImage(right, DisplayIO.getMiddle() + 1,384 DisplayIO.getOffset(), DisplayIO.DEFAULT_BACKGROUND, null);385 379 386 380 // otherwise, just draw whichever side is active 387 381 } else { 388 382 if (DisplayIO.getCurrentSide() == 0) 389 g.drawImage(left, 0, DisplayIO.getOffset(), 390 DisplayIO.DEFAULT_BACKGROUND, null); 383 g.drawImage(left, 0, 0, DisplayIO.DEFAULT_BACKGROUND, null); 391 384 else 392 g.drawImage(right, 0, DisplayIO.getOffset(), 393 DisplayIO.DEFAULT_BACKGROUND, null); 385 g.drawImage(right, 0, 0, DisplayIO.DEFAULT_BACKGROUND, null); 394 386 } 395 387 // draw the message area 396 g.drawImage(_MessageBuffer, 0, _MaxSize.height + DisplayIO.getOffset(), 397 null); 388 g.drawImage(_MessageBuffer, 0, _MaxSize.height, null); 398 389 g.dispose(); 399 390 } … … 484 475 */ 485 476 public static void Highlight(Item i, boolean val, boolean changeMouse) { 486 if ((i instanceof Line/* Dot */)) { 487 List<Item> connected = i.getAllConnected(); 488 489 for (Item conn : connected) 490 conn.showHighlight(val); 477 if ((i instanceof Line)) { 478 // Check if within 20% of the end of the line 479 Line l = (Line) i; 480 Item toDisconnect = l.getEndPointToDisconnect( 481 FrameMouseActions.MouseX, FrameMouseActions.MouseY); 482 483 if (toDisconnect != null) { 484 if (Frame.itemAttachedToCursor()) 485 return; 486 487 // unhighlight all the other dots 488 for (Item conn : toDisconnect.getAllConnected()) { 489 conn.showHighlight(false); 490 } 491 // highlight the dot that will be in disconnect mode 492 toDisconnect.showDisconnectHighlight(val); 493 toDisconnect.setFilledHighlight(true); 494 } else { 495 List<Item> connected = i.getAllConnected(); 496 for (Item conn : connected) { 497 conn.showHighlight(val); 498 conn.setFilledHighlight(false); 499 } 500 } 491 501 } else { 492 502 i.showHighlight(val); 503 i.setFilledHighlight(true); 493 504 } 494 505 … … 517 528 */ 518 529 public static void DisplayMessage(String message) { 519 DisplayMessage (message, Color.BLACK);530 DisplayMessageAlways(message); 520 531 } 521 532 … … 528 539 displayMessage(message.getFirstLine(), message.getLink(), message 529 540 .getColor()); 530 Misc.Beep();541 // Misc.Beep(); 531 542 } 532 543 -
trunk/src/org/expeditee/gui/FrameIO.java
r4 r7 4 4 import java.io.BufferedWriter; 5 5 import java.io.File; 6 import java.io.FileInputStream; 7 import java.io.FileOutputStream; 6 8 import java.io.FileReader; 7 9 import java.io.FileWriter; … … 130 132 public static Frame LoadFrame(String frameName) { 131 133 // If the frame name is a positive integer add the frameset name 132 if (isPositiveInteger(frameName)) {133 assert (false);134 if (isPositiveInteger(frameName)) { 135 assert (false); 134 136 frameName = DisplayIO.getCurrentFrame().getFramesetNameAdjusted() 135 137 + frameName; … … 160 162 161 163 return loaded; 164 } 165 166 /** 167 * Gets a list of all the framesets available to the user 168 * 169 * @return a string containing a list of all the available framesets on 170 * separate lines 171 */ 172 public static String getFramesetList() { 173 StringBuffer list = new StringBuffer(); 174 175 for (String path : UserSettings.FrameDirs) { 176 for (File f : (new File(path)).listFiles()) { 177 if (f.isDirectory()) { 178 list.append(f.getName()).append('\n'); 179 } 180 } 181 } 182 // remove the final new line char 183 list.deleteCharAt(list.length() - 1); 184 return list.toString(); 162 185 } 163 186 … … 267 290 268 291 public static Frame LoadPrevious(Frame current) { 292 checkTDFC(current); 293 269 294 // the current name and number 270 295 String name = current.getFramesetNameAdjusted(); … … 292 317 */ 293 318 public static Frame LoadNext(Frame current) { 319 checkTDFC(current); 294 320 295 321 // the current name and number … … 318 344 FrameGraphics.DisplayMessage("This is the last frame in the frameset"); 319 345 return null; 346 } 347 348 /** 349 * This method checks if the current frame has just been created with TDFC. 350 * If it has the frame is saved regardless of whether it has been edited or 351 * not and the TDFC item property is cleared. This is to ensure that the 352 * link is saved on the parent frame. 353 * 354 * @param current 355 */ 356 private static void checkTDFC(Frame current) { 357 if (FrameMouseActions.getTdfcItem() != null) { 358 FrameMouseActions.setTdfcItem(null); 359 current.change(); 360 } 320 361 } 321 362 … … 331 372 } 332 373 333 String adjustedName = Frame .GetFramesetNameAdjusted(framesetName);374 String adjustedName = FrameUtils.GetFramesetNameAdjusted(framesetName); 334 375 335 376 // loop backwards until a frame that exists is found … … 368 409 */ 369 410 public static boolean DeleteFrame(Frame toDelete) throws IOException { 411 if (toDelete == null) 412 return false; 413 370 414 SaveFrame(toDelete); 371 415 … … 374 418 int lastNumber = FrameIO.getLastNumber(DELETED_FRAMES); 375 419 String framePath; 376 if (lastNumber < 0){420 try{ 377 421 // create the new frameset 378 422 Frame one = FrameIO.CreateFrameset(DELETED_FRAMES, toDelete.path); 379 423 framePath = one.path; 380 424 lastNumber = 0; 381 } else{425 } catch(Exception e){ 382 426 Frame zero = FrameIO.LoadFrame(DELETED_FRAMES + "0"); 383 427 framePath = zero.path; … … 426 470 SuspendCache(); 427 471 428 String adjustFramesetName = Frame.GetFramesetNameAdjusted(frameset); 472 String adjustFramesetName = FrameUtils 473 .GetFramesetNameAdjusted(frameset); 429 474 Frame template = null; 430 475 if (templateFrame == null) … … 520 565 * @return The first Frame of the new Frameset (Frame.1) 521 566 */ 522 public static Frame CreateFrameset(String frameset, String path) { 523 String conversion = frameset + " --> "; 524 525 // ensure the framename is valid 526 frameset = NameValidation(frameset); 527 528 if (frameset == null) 529 return null; 530 531 conversion += frameset; 532 Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Frameset Name: " 533 + conversion); 534 conversion = frameset; 535 536 /** 537 * TODO: Update this to exclude any\all invalid filename characters 538 */ 539 // ignore annotation character 540 if (frameset.startsWith("@")) 541 frameset = frameset.substring(1); 542 543 conversion += " --> " + frameset; 544 Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Name: " + conversion); 545 546 // create the new Frameset directory 547 File dir = new File(path + frameset.toLowerCase() + File.separator); 548 549 dir.mkdirs(); 550 551 // create the new INF file 552 try { 553 WriteINF(path, frameset, frameset + getFramesetExtension(frameset)); 554 } catch (IOException ioe) { 555 ioe.printStackTrace(); 556 Logger.Log(ioe); 557 } 558 559 SuspendCache(); 560 // copy the default .0 and .1 files 561 Frame base; 562 try { 563 base = LoadFrame(UserSettings.DefaultFrame); 564 } catch (Exception e) { 565 base = new Frame(); 566 } 567 ResumeCache(); 568 569 base.resetDateCreated(); 570 base.setFrameset(frameset); 571 base.setFrameNumber(0); 572 base.path = path; 573 SaveFrame(base, false); 574 575 base.resetDateCreated(); 576 base.setFrameNumber(1); 577 base.setTitle(frameset); 578 SaveFrame(base, true); 579 580 Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Created new frameset: " 581 + frameset); 582 583 return base; 567 public static Frame CreateFrameset(String frameset, String path) throws Exception{ 568 return CreateFrameset(frameset, path, false); 584 569 } 585 570 … … 600 585 601 586 // String must begin with a letter and end with a digit 602 if (! Character.isLetter(frameName.charAt(0))587 if (!(Character.isLetter(frameName.charAt(0)) || Character.isDigit(frameName.charAt(0))) 603 588 || !Character.isDigit(frameName.charAt(frameName.length() - 1))) 604 589 return false; 605 590 606 int dotIndex = frameName. indexOf(".");607 // All the characters inbetween first and last must be letters608 // or digits 591 int dotIndex = frameName.lastIndexOf('.'); 592 // All the characters between first and last must be letters 593 // or digits or period 609 594 for (int i = 1; i < frameName.length(); i++) { 610 595 if (dotIndex > 0 && i > dotIndex) { … … 645 630 646 631 if (toSave == null) 632 return ""; 633 634 if (!toSave.hasChanged() || toSave.isSaved()) 647 635 return ""; 648 636 … … 713 701 } 714 702 } catch (IOException ioe) { 715 ioe.printStackTrace();703 // ioe.printStackTrace(); 716 704 Logger.Log(ioe); 705 return null; 717 706 } 718 707 … … 724 713 } 725 714 726 public static Frame CreateNewProfile(String username) {715 public static Frame CreateNewProfile(String username) throws Exception{ 727 716 Frame profile = CreateFrameset(username, PROFILE_PATH); 728 717 FrameUtils.CreateDefaultProfile(profile); … … 782 771 } 783 772 784 private static String NameValidation(String toValidate) {773 private static String NameValidation(String toValidate) throws Exception{ 785 774 String result = ""; 786 775 … … 791 780 // check for illegal characters 792 781 if (ILLEGAL_CHARS.contains("" + cur)) { 793 FrameGraphics 794 .DisplayMessage("Frameset name contains illegal character '" 782 throw new Exception("Frameset name contains illegal character '" 795 783 + cur + "' at position " + (i + 1)); 796 return null;797 784 } 798 785 … … 808 795 809 796 if (result.length() >= MAX_NAME_LENGTH) { 810 FrameGraphics 811 .DisplayMessage("Frameset name is too long (Max " 797 throw new Exception("Frameset name is too long (Max " 812 798 + MAX_NAME_LENGTH + " characters)"); 813 return null;814 799 } 815 800 } … … 832 817 // do auto shrinking of the title 833 818 Text titleItem = newFrame.getTitle(); 834 835 while(titleItem.getBoundsWidth() + titleItem.getX() > newFrame.getFrameNameItem().getX() ) { 819 820 while (titleItem.getBoundsWidth() + titleItem.getX() > newFrame 821 .getFrameNameItem().getX()) { 836 822 titleItem.setSize(titleItem.getSize() - 1); 837 823 } 838 839 824 840 825 return newFrame; … … 850 835 * frame) 851 836 */ 852 public static Frame CreateNewFrameset(String name) {837 public static Frame CreateNewFrameset(String name) throws Exception{ 853 838 String path = DisplayIO.getCurrentFrame().path; 854 839 … … 896 881 } 897 882 883 public static Boolean DoesFramesetExist(String framesetName) { 884 String zeroFrame = FrameUtils.GetFramesetNameAdjusted(framesetName) + '0'; 885 return FrameIO.DoesFrameExist(zeroFrame); 886 } 887 888 public static Frame CreateFrameset(String frameset, String path, 889 boolean recreate) throws Exception{ 890 String conversion = frameset + " --> "; 891 892 // ensure the framename is valid 893 frameset = NameValidation(frameset); 894 895 if (frameset == null) 896 throw new Exception("Invalid frameset name"); 897 898 if (!recreate && FrameIO.DoesFramesetExist(frameset)) { 899 throw new Exception("A frameset called " + frameset + " already exists."); 900 } 901 902 conversion += frameset; 903 Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Frameset Name: " 904 + conversion); 905 conversion = frameset; 906 907 /** 908 * TODO: Update this to exclude any\all invalid filename characters 909 */ 910 // ignore annotation character 911 if (frameset.startsWith("@")) 912 frameset = frameset.substring(1); 913 914 conversion += " --> " + frameset; 915 Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Name: " + conversion); 916 917 // create the new Frameset directory 918 File dir = new File(path + frameset.toLowerCase() + File.separator); 919 920 dir.mkdirs(); 921 922 // create the new INF file 923 try { 924 WriteINF(path, frameset, frameset + getFramesetExtension(frameset)); 925 } catch (IOException ioe) { 926 ioe.printStackTrace(); 927 Logger.Log(ioe); 928 } 929 930 SuspendCache(); 931 // copy the default .0 and .1 files 932 Frame base; 933 try { 934 base = LoadFrame(UserSettings.DefaultFrame); 935 } catch (Exception e) { 936 base = new Frame(); 937 } 938 ResumeCache(); 939 940 base.resetDateCreated(); 941 base.setFrameset(frameset); 942 base.setFrameNumber(0); 943 base.setTitle(base.getFramesetNameAdjusted() + "0"); 944 base.path = path; 945 base.change(); 946 SaveFrame(base, false); 947 948 base.resetDateCreated(); 949 base.setFrameNumber(1); 950 base.setTitle(frameset); 951 base.change(); 952 SaveFrame(base, true); 953 954 Logger.Log(Logger.SYSTEM, Logger.NEW_FRAMESET, "Created new frameset: " 955 + frameset); 956 957 return base; 958 } 959 960 public static boolean DeleteFrameset(String framesetName) { 961 if (!FrameIO.DoesFramesetExist(framesetName)) 962 return false; 963 964 for (String path : UserSettings.FrameDirs) { 965 String source = path + framesetName.toLowerCase() + File.separator; 966 File framesetDirectory = new File(source); 967 if (framesetDirectory.exists()) { 968 for (File f : framesetDirectory.listFiles()) 969 f.delete(); 970 return framesetDirectory.delete(); 971 } 972 } 973 return false; 974 } 975 976 public static boolean CopyFrameset(String framesetToCopy, 977 String copiedFrameset) throws Exception { 978 if (!FrameIO.DoesFramesetExist(framesetToCopy)) 979 return false; 980 if (FrameIO.DoesFramesetExist(copiedFrameset)) 981 return false; 982 // search through all the directories to find the frameset we are 983 // copying 984 for (String path : UserSettings.FrameDirs) { 985 String source = path + framesetToCopy.toLowerCase() 986 + File.separator; 987 File framesetDirectory = new File(source); 988 if (framesetDirectory.exists()) { 989 // copy the frameset 990 File copyFramesetDirectory = new File(path 991 + copiedFrameset.toLowerCase() + File.separator); 992 if (!copyFramesetDirectory.mkdirs()) 993 return false; 994 // copy each of the frames 995 for (File f : framesetDirectory.listFiles()) { 996 String copyPath = copyFramesetDirectory.getAbsolutePath() 997 + File.separator + f.getName(); 998 FrameIO.copyFile(f.getAbsolutePath(), copyPath); 999 } 1000 return true; 1001 } 1002 } 1003 return false; 1004 } 1005 1006 public static void copyFile(String existingFile, String newFileName) 1007 throws Exception { 1008 FileInputStream is = new FileInputStream(existingFile); 1009 FileOutputStream os = new FileOutputStream(newFileName, false); 1010 int data; 1011 while ((data = is.read()) != -1) { 1012 os.write(data); 1013 } 1014 os.flush(); 1015 os.close(); 1016 is.close(); 1017 } 1018 1019 /** 1020 * Saves a frame regardless of whether or not the frame is marked as having 1021 * been changed. 1022 * 1023 * @param frame 1024 * the frame to save 1025 * @return the contents of the frame or null if it could not be saved 1026 */ 1027 public static String ForceSaveFrame(Frame frame) { 1028 frame.change(); 1029 return SaveFrame(frame, false); 1030 } 1031 898 1032 } -
trunk/src/org/expeditee/gui/FrameKeyboardActions.java
r4 r7 8 8 import java.awt.event.KeyEvent; 9 9 import java.awt.event.KeyListener; 10 import java.io.IOException; 10 11 import java.util.ArrayList; 11 12 import java.util.LinkedList; … … 18 19 import org.expeditee.items.Dot; 19 20 import org.expeditee.items.Item; 20 import org.expeditee.items.ItemPermission;21 21 import org.expeditee.items.ItemUtils; 22 22 import org.expeditee.items.Line; … … 25 25 26 26 public class FrameKeyboardActions implements KeyListener { 27 28 private static Text _toRemove = null; 27 29 28 30 // these numbers correspond to the Function Key numbers (0 = Escape key) … … 81 83 // remove the link for alt+l 82 84 if (ch == 'l') { 83 FrameUtils.getCurrentItem(). Item.setLink(null);85 FrameUtils.getCurrentItem().setLink(null); 84 86 FrameGraphics.Repaint(); 85 87 } … … 91 93 } 92 94 93 p rivatestatic void processChar(char ch) {94 95 Item Permission ip= FrameUtils.getCurrentItem();95 public static void processChar(char ch) { 96 97 Item on = FrameUtils.getCurrentItem(); 96 98 97 99 // permission check 98 if ( ip != null && ip.Permission < ItemPermission.PERMISSION_FULL) {100 if (on != null && on.Permission < Item.PERMISSION_FULL) { 99 101 FrameGraphics 100 102 .DisplayMessage("Insufficient permission to edit this item"); … … 102 104 } 103 105 104 Item on = null; 105 106 if (ip != null) 107 on = ip.Item; 106 if (_toRemove != null && on != _toRemove) { 107 assert (_toRemove.getLength() == 0); 108 // This line is to protect mistaken removal of items if there is a 109 // bug... 110 if (_toRemove.getLength() == 0) 111 DisplayIO.getCurrentFrame().removeItem(_toRemove); 112 } 113 _toRemove = null; 108 114 109 115 // ignore delete and backspace if in free space … … 124 130 on = null; 125 131 132 // DisplayIO.UpdateTitle(); 133 126 134 Text text = (Text) on; 127 128 // DisplayIO.UpdateTitle();129 130 135 // if this text is empty but has not been removed (such as from 131 136 // ESC-pushdown) … … 135 140 replaceText(text); 136 141 else { 137 DisplayIO.getCurrentFrame().removeItem(text);138 142 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 139 143 } … … 163 167 // away) 164 168 if (text.isEmpty()) { 169 _toRemove = text; 170 165 171 if (text.getAction() != null) 166 172 text.setActionMark(true); … … 170 176 replaceText(text); 171 177 else { 172 DisplayIO.getCurrentFrame().removeItem(text);178 // DisplayIO.getCurrentFrame().removeItem(text); 173 179 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 174 180 } … … 241 247 242 248 private void move(int direction) { 243 Item Permissionip = FrameUtils.getCurrentItem();249 Item ip = FrameUtils.getCurrentItem(); 244 250 245 251 if (ip == null) { … … 250 256 } 251 257 252 Item on = ip .Item;258 Item on = ip; 253 259 if (on instanceof Text) { 254 260 // When the user hits the left and right button with mouse … … 341 347 342 348 /** 349 * 350 * @param text 351 * @param yPos 352 * @return the new yPos for the next item 353 */ 354 private static int addTextItemToCurrentFrame(String text, int yPos) { 355 if (text.trim().length() > 0) { 356 Text textItem = createText(); 357 textItem.setText(text.substring(0, text.length() - 1)); 358 textItem.setY(yPos); 359 DisplayIO.getCurrentFrame().addItem(textItem); 360 return textItem.getY() + textItem.getBoundsHeight(); 361 } 362 return yPos; 363 } 364 365 /** 343 366 * Processes all control character keystrokes. Currently Ctrl+C and Ctrl+V 344 367 * are copy and paste, all other keystrokes are ignored. … … 356 379 .getTransferData(DataFlavor.stringFlavor)); 357 380 358 Item Permissionclicked = FrameUtils.getCurrentItem();381 Item clicked = FrameUtils.getCurrentItem(); 359 382 360 383 if (clicked != null) { 361 384 // check permissions 362 if (clicked.Permission < Item Permission.PERMISSION_FULL363 && clicked. Item.getParent() != null364 && clicked. Item.getParent().getName() != clicked.Item) {385 if (clicked.Permission < Item.PERMISSION_FULL 386 && clicked.getParent() != null 387 && clicked.getParent().getFrameNameItem() != clicked) { 365 388 FrameGraphics.DisplayMessage("Insufficient Permission"); 366 389 return; … … 372 395 clipboard.add(text); 373 396 List<Item> left = FrameMouseActions.merge(clipboard, 374 clicked .Item);397 clicked); 375 398 FrameMouseActions.anchor(left); 376 399 } else { … … 382 405 383 406 // separate the clipboard content into items based on 384 // blank 385 // lines 407 // blank lines 386 408 while (st.hasMoreTokens()) { 387 409 String s = st.nextToken(); 388 410 // if this is a blank line, then it is an item separator 389 411 if (s.trim().length() == 0) { 390 if (temp.trim().length() > 0) { 391 Text text = createText(); 392 text.setText(temp); 393 text.setY(y); 394 DisplayIO.getCurrentFrame().addItem(text); 395 y = text.getY() + text.getBoundsHeight(); 396 } 412 y = addTextItemToCurrentFrame(temp, y); 397 413 temp = ""; 398 414 } else { 399 if (st.hasMoreTokens()) { 400 temp += s + "\n"; 401 st.nextToken(); // Skip '\n' separator 402 } else { 403 temp += s; 404 } 415 temp += s + "\n"; 416 if (st.hasMoreTokens()) 417 st.nextToken(); 405 418 } 406 419 } 407 420 // the last item will not be finished by the above loop 408 if (temp.trim().length() > 1) { 409 Text text = createText(); 410 text.setText(temp); 411 text.setY(y); 412 DisplayIO.getCurrentFrame().addItem(text); 413 temp = ""; 414 } 421 addTextItemToCurrentFrame(temp, y); 415 422 } 416 423 … … 422 429 // if this is a copy command 423 430 } else if (ch.charAt(0) == KeyEvent.VK_C) { 424 Item Permissionip = FrameUtils.getCurrentItem();425 426 if (ip != null && ip.Permission < Item Permission.PERMISSION_COPY) {431 Item ip = FrameUtils.getCurrentItem(); 432 433 if (ip != null && ip.Permission < Item.PERMISSION_COPY) { 427 434 FrameGraphics 428 435 .DisplayMessage("Insufficient permission to copy that item"); … … 432 439 Item on = null; 433 440 if (ip != null) 434 on = ip .Item;441 on = ip; 435 442 436 443 if (on == null || !(on instanceof Text)) … … 511 518 */ 512 519 private static Text getCurrentTextItem() { 513 Item Permissionip = FrameUtils.getCurrentItem();514 515 if (ip != null && ip.Permission < Item Permission.PERMISSION_FULL) {520 Item ip = FrameUtils.getCurrentItem(); 521 522 if (ip != null && ip.Permission < Item.PERMISSION_FULL) { 516 523 FrameGraphics 517 524 .DisplayMessage("Insufficient permission to copy that item"); … … 521 528 Item on = null; 522 529 if (ip != null) 523 on = ip .Item;530 on = ip; 524 531 525 532 if (on == null || !(on instanceof Text)) … … 535 542 public static void functionKey(int key) { 536 543 // get whatever the user is pointing at 537 Item Permissionon = FrameUtils.getCurrentItem();544 Item on = FrameUtils.getCurrentItem(); 538 545 539 546 // check for enclosed mode 540 if (on == null || on .Item== null) {541 List<Item Permission> enclosed = FrameUtils.getCurrentItems();547 if (on == null || on == null) { 548 List<Item> enclosed = FrameUtils.getCurrentItems(); 542 549 543 550 if (enclosed != null && enclosed.size() > 0) { … … 549 556 // items 550 557 boolean resizeLines = true; 551 for (ItemPermission ip : enclosed) { 552 if (ip.Item != null) { 553 if (!(ip.Item instanceof Line) 554 && !(ip.Item instanceof Dot)) { 558 for (Item ip : enclosed) { 559 if (ip != null) { 560 if (!(ip instanceof Line) && !(ip instanceof Dot)) { 555 561 resizeLines = false; 556 562 break; … … 559 565 } 560 566 561 for (Item Permissionip : enclosed) {562 if (ip .Item != null && !(connected.indexOf(ip.Item) > 0))567 for (Item ip : enclosed) { 568 if (ip != null && !(connected.indexOf(ip) > 0)) 563 569 switch (key) { 564 570 case SIZE_UP: 565 571 if (resizeLines 566 || (!(ip .Item instanceof Line) && !(ip.Iteminstanceof Dot)))572 || (!(ip instanceof Line) && !(ip instanceof Dot))) 567 573 SetSize(ip, 1, false); 568 574 break; 569 575 case SIZE_DOWN: 570 576 if (resizeLines 571 || (!(ip .Item instanceof Line) && !(ip.Iteminstanceof Dot)))577 || (!(ip instanceof Line) && !(ip instanceof Dot))) 572 578 SetSize(ip, -1, false); 573 579 break; … … 654 660 * indicate the cursor is in free space. 655 661 */ 656 private static void Drop(Item Permissionip) {662 private static void Drop(Item ip) { 657 663 String newItemText = DEFAULT_NEW_ITEM_TEXT; 658 664 … … 664 670 Item toDropFrom = null; 665 671 if (ip != null) 666 toDropFrom = ip .Item;672 toDropFrom = ip; 667 673 668 674 // if the cursor is in free space then the drop will happen from the … … 751 757 Frame moreFrame = DisplayIO.getCurrentFrame(); 752 758 moreFrame.setTitle(firstFrame.getTitle().getTextNoList()); 753 //need to move the mouse to the top of the frame if there wasnt an @start on it 759 // need to move the mouse to the top of the frame if there 760 // wasnt an @start on it 754 761 if (!mouseMoved) { 755 Drop(new ItemPermission(moreFrame.getTitle(), ItemPermission.PERMISSION_FULL)); 762 Item moreTitle = moreFrame.getTitle(); 763 moreTitle.Permission = Item.PERMISSION_FULL; 764 Drop(moreTitle); 756 765 } 757 766 758 767 // Add the bullet text to the item 759 dummyItem.setPosition(DisplayIO.getMouseX(), 760 DisplayIO.getMouseY());768 dummyItem.setPosition(DisplayIO.getMouseX(), DisplayIO 769 .getMouseY()); 761 770 } else { 762 771 FrameGraphics … … 945 954 * with resizing 946 955 */ 947 private static void SetSize(Item Permissionip, int diff, boolean moveCursor) {956 private static void SetSize(Item ip, int diff, boolean moveCursor) { 948 957 List<Item> toSize; 949 958 // the mouse is only moved when the Item is on the frame, not free … … 962 971 } else { 963 972 // check permissions 964 if (ip.Permission < Item Permission.PERMISSION_FULL) {973 if (ip.Permission < Item.PERMISSION_FULL) { 965 974 FrameGraphics 966 975 .DisplayMessage("Insufficient permission to change the size of that item"); 967 976 return; 968 977 } 969 toSet = ip .Item;978 toSet = ip; 970 979 971 980 toSize = toSet.getConnected(); … … 1054 1063 return; 1055 1064 1056 Item toSet = item;// .Item;1065 Item toSet = item;// ; 1057 1066 Color color = toSet.getFillColor(); 1058 1067 1059 color = ColorUtils.getNextColor(color, Item. COLOR_WHEEL);1068 color = ColorUtils.getNextColor(color, Item.FILL_COLOR_WHEEL); 1060 1069 1061 1070 // TODO what happens if the above statement returns null?? … … 1074 1083 * The Item whose colour is to be changed 1075 1084 */ 1076 private static void SetColor(Item Permissionip) {1085 private static void SetColor(Item ip) { 1077 1086 // first determine the next color 1078 1087 Color color = null; … … 1086 1095 // change the background color if the user is pointing on the 1087 1096 // frame name 1088 } else if (ip .Item == DisplayIO.getCurrentFrame().getName()) {1097 } else if (ip == DisplayIO.getCurrentFrame().getFrameNameItem()) { 1089 1098 DisplayIO.getCurrentFrame().toggleBackgroundColor(); 1090 1099 return; 1091 1100 } else { 1092 1101 // check permissions 1093 if (ip.Permission < Item Permission.PERMISSION_FULL) {1102 if (ip.Permission < Item.PERMISSION_FULL) { 1094 1103 FrameGraphics 1095 1104 .DisplayMessage("Insufficient permission to change that item's color"); 1096 1105 return; 1097 1106 } 1098 color = ip. Item.getColor();1107 color = ip.getColor(); 1099 1108 } 1100 1109 … … 1110 1119 i.setColor(color); 1111 1120 } else { 1112 Item toSet = ip .Item;1121 Item toSet = ip; 1113 1122 toSet.setColor(color); 1114 1123 toSet.getParent().setChanged(true); … … 1125 1134 * The Item to toggle 1126 1135 */ 1127 private static void ToggleAnnotation(Item PermissiontoToggle) {1136 private static void ToggleAnnotation(Item toToggle) { 1128 1137 if (toToggle == null) { 1129 1138 FrameGraphics.DisplayMessage("There is no Item selected to toggle"); … … 1132 1141 1133 1142 // check permissions 1134 if (toToggle.Permission < Item Permission.PERMISSION_FULL) {1143 if (toToggle.Permission < Item.PERMISSION_FULL) { 1135 1144 FrameGraphics 1136 1145 .DisplayMessage("Insufficient permission to toggle that item's annotation"); … … 1138 1147 } 1139 1148 1140 toToggle. Item.setAnnotation(!toToggle.Item.isAnnotation());1141 toToggle. Item.getParent().setChanged(true);1149 toToggle.setAnnotation(!toToggle.isAnnotation()); 1150 toToggle.getParent().setChanged(true); 1142 1151 FrameGraphics.Repaint(); 1143 1152 } … … 1149 1158 * The Item to toggle 1150 1159 */ 1151 private static void ToggleFontStyle(Item PermissiontoToggle) {1160 private static void ToggleFontStyle(Item toToggle) { 1152 1161 if (toToggle == null) { 1153 1162 FrameGraphics.DisplayMessage("There is no Item selected to toggle"); … … 1156 1165 1157 1166 // check permissions 1158 if (toToggle.Permission < Item Permission.PERMISSION_FULL) {1167 if (toToggle.Permission < Item.PERMISSION_FULL) { 1159 1168 FrameGraphics 1160 1169 .DisplayMessage("Insufficient permission to toggle that item's annotation"); … … 1162 1171 } 1163 1172 1164 if (toToggle .Iteminstanceof Text) {1165 Text text = (Text) toToggle .Item;1173 if (toToggle instanceof Text) { 1174 Text text = (Text) toToggle; 1166 1175 text.toggleFontStyle(); 1167 1176 … … 1177 1186 * The Item to toggle 1178 1187 */ 1179 private static void ToggleFontFamily(Item PermissiontoToggle) {1188 private static void ToggleFontFamily(Item toToggle) { 1180 1189 if (toToggle == null) { 1181 1190 FrameGraphics.DisplayMessage("There is no Item selected to toggle"); … … 1184 1193 1185 1194 // check permissions 1186 if (toToggle.Permission < Item Permission.PERMISSION_FULL) {1195 if (toToggle.Permission < Item.PERMISSION_FULL) { 1187 1196 FrameGraphics 1188 1197 .DisplayMessage("Insufficient permission to toggle that item's annotation"); … … 1190 1199 } 1191 1200 1192 if (toToggle .Iteminstanceof Text) {1193 Text text = (Text) toToggle .Item;1201 if (toToggle instanceof Text) { 1202 Text text = (Text) toToggle; 1194 1203 text.toggleFontFamily(); 1195 1204 … … 1207 1216 * The Item to prepend the date to, or null 1208 1217 */ 1209 private static void AddDate(Item PermissiontoAdd) {1218 private static void AddDate(Item toAdd) { 1210 1219 String date1 = Logger.EasyDateFormat("ddMMMyyyy[HH:mm]"); 1211 1220 String date2 = Logger.EasyDateFormat("ddMMMyyyy"); … … 1216 1225 boolean append = false; 1217 1226 1218 // if the user is pointing at an item, add the date where ever the cursor is pointing 1227 // if the user is pointing at an item, add the date where ever the 1228 // cursor is pointing 1219 1229 if (toAdd != null) { 1220 if (toAdd .Iteminstanceof Text) {1230 if (toAdd instanceof Text) { 1221 1231 // permission check 1222 if (toAdd.Permission < Item Permission.PERMISSION_FULL) {1232 if (toAdd.Permission < Item.PERMISSION_FULL) { 1223 1233 FrameGraphics 1224 1234 .DisplayMessage("Insufficicent permission to add the date to that item"); 1225 1235 return; 1226 1236 } 1227 1228 Text textItem = (Text) toAdd .Item;1229 1237 1238 Text textItem = (Text) toAdd; 1239 1230 1240 String text = textItem.getTextNoList(); 1231 1241 … … 1253 1263 } 1254 1264 } 1255 1265 1256 1266 if (prepend) { 1257 1267 // add the date to the text item … … 1265 1275 DisplayIO.setCursorPosition(textItem.getPosition()); 1266 1276 } else { 1267 for (int i = 0; i < date1.length(); i++) {1277 for (int i = 0; i < date1.length(); i++) { 1268 1278 processChar(date1.charAt(i)); 1269 1279 } … … 1294 1304 * @param name 1295 1305 */ 1296 private static void CreateFrameset(Item Permissionip) {1297 if (ip == null || !(ip .Iteminstanceof Text)) {1306 private static void CreateFrameset(Item ip) { 1307 if (ip == null || !(ip instanceof Text)) { 1298 1308 FrameGraphics 1299 1309 .DisplayMessage("There is no selected item to use for the Frameset name"); … … 1302 1312 1303 1313 // check permissions 1304 if (ip.Permission < Item Permission.PERMISSION_FULL) {1314 if (ip.Permission < Item.PERMISSION_FULL) { 1305 1315 FrameGraphics 1306 1316 .DisplayMessage("Insufficient permission to create a frameset from this item"); … … 1308 1318 } 1309 1319 1310 Text text = (Text) ip.Item; 1311 1312 // create the new frameset 1313 Frame linkTo = FrameIO.CreateNewFrameset(text.getFirstLine()); 1314 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 1315 1316 // if the frameset was created successfully 1317 if (linkTo != null) { 1320 Text text = (Text) ip; 1321 try { 1322 // create the new frameset 1323 Frame linkTo = FrameIO.CreateNewFrameset(text.getFirstLine()); 1324 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 1325 1318 1326 text.setLink(linkTo.getFrameName()); 1319 1327 1320 1328 text.getParent().setChanged(true); 1321 1329 FrameUtils.DisplayFrame(linkTo, true); 1322 } else { 1330 linkTo.moveMouseToDefaultLocation(); 1331 // this needs to be done if the user doesnt move the mouse before 1332 // doing 1333 // tdfc while the cursor is set to the text cursor 1334 DisplayIO.setCursor(Item.DEFAULT_CURSOR); 1335 } catch (IOException ioe) { 1323 1336 FrameGraphics 1324 1337 .ErrorMessage("An error occured when trying to create the new frameset"); 1338 } catch (Exception e) { 1325 1339 } 1326 1340 } … … 1332 1346 * This Item is currently ignored 1333 1347 */ 1334 private static void ToggleAudience(Item Permissionignored) {1348 private static void ToggleAudience(Item ignored) { 1335 1349 FrameGraphics.ToggleAudienceMode(); 1336 1350 } 1337 1351 1338 private static void ToggleXRayMode(Item Permissionignored) {1352 private static void ToggleXRayMode(Item ignored) { 1339 1353 FrameGraphics.ToggleXRayMode(); 1340 1354 } … … 1347 1361 */ 1348 1362 /* 1349 * private static void RunFirstMenuItem(Item Permissionignored) {1363 * private static void RunFirstMenuItem(Item ignored) { 1350 1364 * DisplayIO.activateMenuItem(0, 0); } 1351 1365 */ … … 1357 1371 * This Item is currently ignored 1358 1372 */ 1359 private static void Repaint(Item Permissionignored) {1373 private static void Repaint(Item ignored) { 1360 1374 FrameUtils.Parse(DisplayIO.getCurrentFrame()); 1361 1375 FrameGraphics.ForceRepaint(); -
trunk/src/org/expeditee/gui/FrameMouseActions.java
r4 r7 17 17 import org.expeditee.actions.Actions; 18 18 import org.expeditee.actions.NavigationActions; 19 import org.expeditee.agents.Format; 19 20 import org.expeditee.items.Constraint; 20 21 import org.expeditee.items.Dot; 21 22 import org.expeditee.items.Item; 22 import org.expeditee.items.ItemPermission;23 23 import org.expeditee.items.ItemUtils; 24 24 import org.expeditee.items.Line; … … 71 71 private static int _offX; 72 72 73 // MIKE: Thinks the offsets are used in getting items to draw in the message 74 // window? 73 75 private static int _offY; 74 76 … … 88 90 private static boolean _isNoOp = false; 89 91 92 private static boolean _extrude = false; 93 90 94 // keeps track of the last highlighted Item 91 95 private static Item _lastHighlightedItem = null; … … 116 120 } 117 121 122 static int _mouseDown = 0; 123 118 124 private static MouseEvent _lastMouseClick = null; 119 125 120 private static Item Permission_lastClickedOn = null;121 122 private static List<Item Permission> _lastClickedIn = null;126 private static Item _lastClickedOn = null; 127 128 private static List<Item> _lastClickedIn = null; 123 129 124 130 private static boolean _pulseOn = false; 125 131 126 private static int _pulseAmount= 2;132 private static final int PULSE_AMOUNT = 2; 127 133 128 134 private static Timer _MouseTimer = new Timer(LITTLE_MOUSE_PAUSE, … … 131 137 // check if we are in free space 132 138 if (_lastClickedOn == null && Frame.FreeItems.size() == 0) { 133 System.out.println("SuperBack!"); 134 leftButton(null); 139 // System.out.println("SuperBack!"); 135 140 _MouseTimer.setDelay(ZERO_MOUSE_PAUSE); 141 back(); 136 142 } else { 137 _pulseOn = !_pulseOn;138 139 if (_MouseTimer.getDelay() == LITTLE_MOUSE_PAUSE)140 _MouseTimer.setDelay(LITTLE_MOUSE_PAUSE + 1);141 else142 _MouseTimer.setDelay(BIG_MOUSE_PAUSE);143 143 if (FrameUtils.getCurrentItem() == null) { 144 for (Item i : Frame.FreeItems) { 145 if (i instanceof Line) { 146 Line line = (Line) i; 147 if (_pulseAmount < 4 148 && line.getThickness() < 0) 149 _pulseAmount = 4; 150 151 if (_pulseOn) 152 line.setThickness(line.getThickness() 153 + _pulseAmount); 154 else 155 line.setThickness(line.getThickness() 156 - _pulseAmount); 157 158 line.toggleArrow(); 144 // Check if we are toggling arrowhead 145 if (Frame.FreeItems.size() <= 2) { 146 for (Item i : Frame.FreeItems) { 147 if (i instanceof Line) { 148 ((Line) i).toggleArrow(); 149 } 159 150 } 151 FrameGraphics.Repaint(); 160 152 } 161 FrameGraphics.Repaint();162 153 } 163 154 _MouseTimer.stop(); 164 155 } 156 } 157 }); 158 159 private static void setPulse(boolean pulseOn) { 160 if (_pulseOn == pulseOn) 161 return; 162 int amount = PULSE_AMOUNT; 163 if (!pulseOn) 164 amount *= -1; 165 _pulseOn = pulseOn; 166 167 for (Item i : _lastClickedOn.getAllConnected()) { 168 if (i instanceof Line) { 169 Line line = (Line) i; 170 line.setThickness(line.getThickness() + amount); 171 } 172 } 173 FrameGraphics.Repaint(); 174 } 175 176 private static Timer _ExtrudeMouseTimer = new Timer(BIG_MOUSE_PAUSE, 177 new ActionListener() { 178 public void actionPerformed(ActionEvent ae) { 179 setPulse(true); 180 _extrude = true; 181 _ExtrudeMouseTimer.stop(); 165 182 } 166 183 }); … … 176 193 */ 177 194 public void mousePressed(MouseEvent e) { 195 _mouseDown += e.getButton(); 178 196 _lastMouseClickDate = new Date(); 179 197 _lastClickedOn = FrameUtils.getCurrentItem(); 180 198 // load any frame if necessary 181 Item Permissionon = _lastClickedOn;199 Item on = _lastClickedOn; 182 200 183 201 _lastClickedIn = FrameUtils.getCurrentItems(); … … 186 204 if (e.getButton() == MouseEvent.BUTTON1) { 187 205 SessionStats.AddFrameEvent("Ld"); 206 _extrude = false; 188 207 } else if (e.getButton() == MouseEvent.BUTTON2) { 189 208 SessionStats.AddFrameEvent("Md"); 209 _extrude = false; 190 210 } else if (e.getButton() == MouseEvent.BUTTON3) { 191 211 SessionStats.AddFrameEvent("Rd"); … … 193 213 194 214 _lastMouseClick = e; 195 _MouseTimer.start(); 215 216 // Only start the timer when in free space when the user double clicks 217 // to do super back 218 // TODO change this so that there are separate timers for super back and 219 // the other 220 // Long depress actions if that is what is wanted. 221 if (_lastClickedOn == null && Frame.FreeItems.size() == 0) { 222 // System.out.println(e.getClickCount()); 223 if (e.getClickCount() >= 2) { 224 _MouseTimer.start(); 225 } 226 } else if (_lastClickedOn != null && Frame.FreeItems.size() == 0 227 && e.getButton() == MouseEvent.BUTTON3) { 228 _ExtrudeMouseTimer.start(); 229 230 } else { 231 _MouseTimer.start(); 232 } 196 233 197 234 // pre-cache the frame if it is linked 198 if (on != null && on. Item.getLink() != null && on.Item.isLinkValid()) {199 FrameIO.Precache(on. Item.getLink());235 if (on != null && on.getLink() != null && on.isLinkValid()) { 236 FrameIO.Precache(on.getLink()); 200 237 } 201 238 … … 231 268 232 269 // if the user is ranging text 233 if (on != null && on .Iteminstanceof Text && !_isDelete) {234 _lastRanged = (Text) on .Item;270 if (on != null && on instanceof Text && !_isDelete) { 271 _lastRanged = (Text) on; 235 272 // set start-drag point 236 273 _lastRanged.setSelectionStart(DisplayIO.getMouseX(), DisplayIO … … 238 275 } 239 276 240 if (on != null && on .Iteminstanceof Picture277 if (on != null && on instanceof Picture 241 278 && e.getButton() == MouseEvent.BUTTON3 && !_isDelete) { 242 _lastCropped = (Picture) on .Item;279 _lastCropped = (Picture) on; 243 280 // set start crop point 244 281 _lastCropped.setStartCrop(DisplayIO.getMouseX(), DisplayIO … … 250 287 // This is where all the processing happens 251 288 public void mouseReleased(MouseEvent e) { 289 _mouseDown -= e.getButton(); 252 290 updateCursor(); 291 292 // System.out.println(e.getX() + ", " + e.getY()); 253 293 254 294 Text lastRanged = _lastRanged; … … 275 315 FrameUtils.ResponseTimer.restart(); 276 316 317 _ExtrudeMouseTimer.stop(); 277 318 _MouseTimer.stop(); 278 _MouseTimer.setDelay(LITTLE_MOUSE_PAUSE); 279 280 if (_pulseOn) { 281 for (Item i : Frame.FreeItems) { 282 if (i instanceof Line) { 283 Line line = (Line) i; 284 line.setThickness(line.getThickness() - _pulseAmount); 285 } 286 } 287 _pulseOn = false; 288 } 289 290 // if the user was performing actions, stop now 291 if (_pulseAmount < 0) { 292 _pulseAmount = 2; 293 return; 294 } 295 296 // reset pulse value 297 _pulseAmount = 2; 319 setPulse(false); 298 320 299 321 if (Actions.isAgentRunning()) { … … 315 337 316 338 // get whatever the user was pointing at 317 Item PermissionclickedOn = _lastClickedOn;318 List<Item Permission> clickedIn = _lastClickedIn;339 Item clickedOn = _lastClickedOn; 340 List<Item> clickedIn = _lastClickedIn; 319 341 320 342 MouseX = e.getX(); 321 343 MouseY = e.getY(); 322 344 323 List<Item Permission> releasedIn = FrameUtils.getCurrentItems();324 Item PermissionreleasedOn = FrameUtils.getCurrentItem();345 List<Item> releasedIn = FrameUtils.getCurrentItems(); 346 Item releasedOn = FrameUtils.getCurrentItem(); 325 347 326 348 if (_isNoOp 327 && ((releasedOn != null && clickedOn != null && releasedOn .Item != clickedOn.Item) || (releasedOn == null && releasedIn == null))) {349 && ((releasedOn != null && clickedOn != null && releasedOn != clickedOn) || (releasedOn == null && releasedIn == null))) { 328 350 if (_isDelete) { 329 351 _isDelete = false; … … 335 357 if (_lastHighlightedItem != null) 336 358 FrameGraphics.Highlight(_lastHighlightedItem, false, false); 337 // TODO Michael thinks this code should never be reached and can be 338 // removed 359 339 360 if (Frame.itemAttachedToCursor()) { 340 361 move(Frame.FreeItems); … … 352 373 if (_isDelete) { 353 374 if (lastRanged != null) { 354 lastRanged.cutSelectedText(); 375 376 Item i = Frame.getItemAttachedToCursor(); 377 if (i != null && i instanceof Text) { 378 lastRanged.replaceSelectedText(((Text) i).getTextNoList()); 379 Frame.FreeItems.clear(); 380 } else 381 lastRanged.cutSelectedText(); 355 382 lastRanged.clearSelection(); 356 383 FrameGraphics.Repaint(); … … 366 393 // if this is an attribute extraction command 367 394 if (_isAttribute) { 368 extractAttributes(clickedOn); 395 if (clickedOn == null) { 396 new Format().process(DisplayIO.getCurrentFrame()); 397 } else { 398 extractAttributes(clickedOn); 399 } 369 400 _wasDouble = true; 370 401 _isAttribute = false; … … 402 433 } 403 434 404 // if the user is cropping an ima te405 if (clickedOn != null && clickedOn .Item== _lastCropped435 // if the user is cropping an image 436 if (clickedOn != null && clickedOn == _lastCropped 406 437 && _lastCropped.getCroppedSize() > 0) { 407 438 Picture cropped = _lastCropped.copy(); 408 409 439 cropped.setParent(null); 410 440 pickup(cropped); … … 412 442 } 413 443 414 // if the user has cropped an ima te, either the above happend or this is444 // if the user has cropped an image, either the above happend or this is 415 445 // a no-op 416 446 if (_lastCropped != null && _lastCropped.getCroppedSize() > 0) { … … 448 478 * This method handles all left-click actions 449 479 */ 450 public static void leftButton(Item Permissionclicked) {480 public static void leftButton(Item clicked) { 451 481 // if the user is pointing at something then either follow the link or 452 482 // do TDFC 483 if (clicked == null) { 484 // Check if the user is nearby another item... 485 int mouseX = DisplayIO.getMouseX(); 486 int mouseY = DisplayIO.getMouseY(); 487 // System.out.println(mouseX + "," + mouseY); 488 for (Item i : DisplayIO.getCurrentFrame().getItems()) { 489 if (i instanceof Text) { 490 if (i.isNear(mouseX, mouseY)) { 491 clicked = i; 492 break; 493 } 494 } 495 } 496 } 497 498 if (clicked instanceof Text) { 499 if (((Text) clicked).getTextNoList().length() == 0) 500 clicked = null; 501 } 502 453 503 if (clicked != null) { 454 504 // check item permissions 455 if (clicked.Permission < Item Permission.PERMISSION_FOLLOW_LINKS) {505 if (clicked.Permission < Item.PERMISSION_FOLLOW_LINKS) { 456 506 FrameGraphics 457 507 .DisplayMessage("Insufficient Permissions for action on item"); … … 459 509 } 460 510 461 Item clickedOn = clicked.Item; 511 Item clickedOn = clicked; 512 462 513 // actions take priority 463 514 if (_lastMouseClick != null && !_lastMouseClick.isShiftDown() … … 480 531 } else { 481 532 // check for TDFC permission 482 if (clicked.Permission < Item Permission.PERMISSION_TDFC) {533 if (clicked.Permission < Item.PERMISSION_TDFC) { 483 534 FrameGraphics 484 535 .DisplayMessage("Insufficient permission to TDFC from that item"); … … 497 548 498 549 tdfc(clickedOn); 499 DisplayIO.UpdateTitle();500 550 return; 501 551 } 502 // if the user is not pointing at something, then this is a back 503 // command 552 // if user is not pointing at something,this is a back 504 553 } else { 505 554 back(); 506 DisplayIO.UpdateTitle();507 555 return; 508 556 } 509 557 } 510 558 511 private static boolean doMerging(Item Permissionclicked) {559 private static boolean doMerging(Item clicked) { 512 560 if (clicked == null) 513 561 return false; … … 515 563 // System.out.println(Frame.FreeItems.size()); 516 564 if (isRubberBandingRectangle() 517 && clicked. Item.getAllConnected().contains(565 && clicked.getAllConnected().contains( 518 566 Frame.getItemAttachedToCursor())) 519 567 return true; … … 524 572 Item attachedToCursor = Frame.getItemAttachedToCursor(); 525 573 526 if (clicked .Iteminstanceof Text && !(attachedToCursor instanceof Text)) {574 if (clicked instanceof Text && !(attachedToCursor instanceof Text)) { 527 575 return false; 528 576 } … … 534 582 * This method handles all middle-click actions 535 583 */ 536 private static void middleButton(ItemPermission clicked, 537 List<ItemPermission> clickedIn) { 584 private static void middleButton(Item clicked, List<Item> clickedIn) { 538 585 // if the cursor has Items attached 539 586 if (Frame.itemAttachedToCursor()) { … … 542 589 if (doMerging(clicked)) { 543 590 // check permissions 544 if (clicked.Permission < Item Permission.PERMISSION_FULL545 && clicked. Item.getParent() != null546 && clicked. Item.getParent().getName() != clicked.Item) {591 if (clicked.Permission < Item.PERMISSION_FULL 592 && clicked.getParent() != null 593 && clicked.getParent().getFrameNameItem() != clicked) { 547 594 FrameGraphics.DisplayMessage("Insufficient Permission"); 548 595 return; 549 596 } 550 597 551 List<Item> left = merge(Frame.FreeItems, clicked .Item);598 List<Item> left = merge(Frame.FreeItems, clicked); 552 599 anchor(left); 553 600 … … 570 617 if (clicked != null) { 571 618 // check permissions 572 if (clicked.Permission < Item Permission.PERMISSION_FULL) {619 if (clicked.Permission < Item.PERMISSION_FULL) { 573 620 FrameGraphics 574 621 .DisplayMessage("Insufficient Permission to pick up item"); … … 576 623 } 577 624 578 pickup(clicked.Item); 625 // TODO remove rectangle constraints? 626 if (clicked instanceof Line) { 627 // Check if within 20% of the end of the line 628 Line l = (Line) clicked; 629 Item toDisconnect = l.getEndPointToDisconnect( 630 _lastMouseClick.getX(), _lastMouseClick.getY()); 631 632 if (toDisconnect != null) { 633 List<Line> lines = toDisconnect.getLines(); 634 if (lines.size() == 1) { 635 //remove constraints 636 toDisconnect.removeAllConstraints(); 637 638 DisplayIO.setCursorPosition(toDisconnect 639 .getPosition(), false); 640 pickup(toDisconnect); 641 return; 642 } 643 // If we are then detatch the line and pick up its end 644 // point... 645 Frame currentFrame = DisplayIO.getCurrentFrame(); 646 Item newPoint = toDisconnect.copy(); 647 newPoint.setID(currentFrame.getNextItemID()); 648 currentFrame.addItem(newPoint); 649 // remove the current item from the connected 650 // list for this item 651 for (Item i : lines) { 652 if (i == l) { 653 toDisconnect.removeLine(l); 654 break; 655 } 656 } 657 if (toDisconnect == l.getStartItem()) { 658 l.setStartItem(newPoint); 659 } else { 660 l.setEndItem(newPoint); 661 } 662 663 // remove unneeded constrains 664 List<Constraint> constraints = toDisconnect 665 .getConstraints(); 666 if (constraints != null) { 667 for (Constraint c : constraints) { 668 Item oppositeEnd = l.getOppositeEnd(newPoint); 669 if (c.contains(oppositeEnd)) { 670 toDisconnect.removeConstraint(c); 671 oppositeEnd.removeConstraint(c); 672 break; 673 } 674 } 675 } 676 677 toDisconnect.showHighlight(false); 678 DisplayIO.setCursorPosition(toDisconnect.getPosition(), 679 false); 680 pickup(newPoint); 681 682 return; 683 } 684 } 685 686 pickup(clicked); 579 687 return; 580 688 // otherwise create a line … … 583 691 ArrayList<Item> toPickup = new ArrayList<Item>(clickedIn 584 692 .size()); 585 for (Item Permissionip : clickedIn)586 if (ip.Permission >= Item Permission.PERMISSION_FULL)587 toPickup.add(ip .Item);693 for (Item ip : clickedIn) 694 if (ip.Permission >= Item.PERMISSION_FULL) 695 toPickup.add(ip); 588 696 589 697 pickup(toPickup); 590 698 // otherwise the user is creating a line 591 } else 592 createLine(); 699 } else { 700 Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), 701 MouseX, MouseY); 702 Line newLine = createLine(); 703 // if the user can spot-weld, show the virtual spot 704 if (on instanceof Line) { 705 Line line = (Line) on; 706 newLine.setThickness(line.getThickness()); 707 newLine.setLinePattern(line.getLinePattern()); 708 newLine.setColor(line.getColor()); 709 line.forceMerge(newLine.getStartItem(), MouseX, MouseY); 710 } 711 } 593 712 return; 594 713 } … … 626 745 * This method handles all right-click action 627 746 */ 628 private static void rightButton(ItemPermission clicked, 629 List<ItemPermission> clickedIn) { 747 private static void rightButton(Item clicked, List<Item> clickedIn) { 630 748 // if the cursor has Items attached, then anchor a copy of them 631 749 if (Frame.itemAttachedToCursor()) { … … 633 751 // unless it is a point onto somethin other than a point 634 752 if (clicked != null 635 && (!(Frame.getItemAttachedToCursor() instanceof Dot && !(clicked .Iteminstanceof Dot)))) {753 && (!(Frame.getItemAttachedToCursor() instanceof Dot && !(clicked instanceof Dot)))) { 636 754 // check permissions 637 if (clicked.Permission < Item Permission.PERMISSION_FULL638 && clicked. Item.getParent().getName() != clicked.Item) {755 if (clicked.Permission < Item.PERMISSION_FULL 756 && clicked.getParent().getFrameNameItem() != clicked) { 639 757 FrameGraphics 640 758 .DisplayMessage("Insufficient Permission to merge items"); … … 642 760 } 643 761 644 if (clicked .Item instanceof Text || clicked.Iteminstanceof Dot) {762 if (clicked instanceof Text || clicked instanceof Dot) { 645 763 List<Item> copies = null; 646 764 647 765 if (isRubberBandingRectangle()) { 648 List<Item> remain = merge(Frame.FreeItems, clicked .Item);766 List<Item> remain = merge(Frame.FreeItems, clicked); 649 767 650 768 Dot d = getFirstFreeDot(); … … 654 772 updateCursor(); 655 773 // pick up a copy of all enclosed items 656 List<ItemPermission> items = FrameUtils 657 .getItemsEnclosedBy( 658 DisplayIO.getCurrentFrame(), d 659 .getEnclosedShape()); 774 List<Item> items = FrameUtils.getItemsEnclosedBy( 775 DisplayIO.getCurrentFrame(), d 776 .getEnclosedShape()); 660 777 if (items != null) { 661 778 ArrayList<Item> toCopy = new ArrayList<Item>(items 662 779 .size()); 663 for (Item Permissionip : items)664 if (ip.Permission >= Item Permission.PERMISSION_COPY)665 toCopy.add(ip .Item);780 for (Item ip : items) 781 if (ip.Permission >= Item.PERMISSION_COPY) 782 toCopy.add(ip); 666 783 667 784 copies = copy(toCopy); … … 671 788 } else if (Frame.FreeItems.size() == 2) { 672 789 copies = ItemUtils.UnreelLine(Frame.FreeItems); 673 List<Item> leftOver = merge(Frame.FreeItems, 674 clicked.Item); 790 List<Item> leftOver = merge(Frame.FreeItems, clicked); 675 791 anchor(leftOver); 676 792 if (copies == null) … … 685 801 } else if (Frame.FreeItems.size() == 1) { 686 802 copies = copy(Frame.FreeItems); 687 List<Item> remain = merge(copies, clicked .Item);803 List<Item> remain = merge(copies, clicked); 688 804 689 805 // ignore items that could not be merged. … … 724 840 updateCursor(); 725 841 // pick up a copy of all enclosed items 726 List<Item Permission> items = FrameUtils.getItemsEnclosedBy(727 DisplayIO.getCurrentFrame(), d.getEnclosedShape());842 List<Item> items = FrameUtils.getItemsEnclosedBy(DisplayIO 843 .getCurrentFrame(), d.getEnclosedShape()); 728 844 if (items != null) { 729 845 ArrayList<Item> toCopy = new ArrayList<Item>(items 730 846 .size()); 731 for (Item Permissionip : items)732 if (ip.Permission >= Item Permission.PERMISSION_COPY)733 toCopy.add(ip .Item);847 for (Item ip : items) 848 if (ip.Permission >= Item.PERMISSION_COPY) 849 toCopy.add(ip); 734 850 toCopy.removeAll(d.getAllConnected()); 735 851 736 852 if (toCopy.size() > 0) { 737 853 pickup(copy(toCopy)); 738 DisplayIO.getCurrentFrame().removeAllItems(d.getAllConnected()); 854 DisplayIO.getCurrentFrame().removeAllItems( 855 d.getAllConnected()); 739 856 } else { 740 857 pickup(copy(d.getAllConnected())); … … 746 863 if (Frame.FreeItems.size() == 2) { 747 864 if (clicked != null) { 748 List<Item> leftOver = merge(Frame.FreeItems, 749 clicked.Item); 865 List<Item> leftOver = merge(Frame.FreeItems, clicked); 750 866 anchor(leftOver); 751 867 } … … 766 882 } 767 883 884 if (_extrude) { 885 List<Item> originals = new ArrayList<Item>(); 886 // remove any lines that dont have both endpoints floating 887 for (Item i : Frame.FreeItems) { 888 if (i.isFloating()) 889 originals.add(i); 890 } 891 if (copies == null) 892 copies = ItemUtils.CopyItems(originals, _extrude); 893 for (Item i : copies) 894 i.setOffset(0, 0); 895 anchor(Frame.FreeItems); 896 // Move isnt working right for extruding!! 897 // move(copies); 898 pickup(copies); 899 updateCursor(); 900 FrameGraphics.Repaint(); 901 return; 902 } 903 768 904 if (copies == null) 769 copies = copy(Frame.FreeItems);905 copies = ItemUtils.CopyItems(Frame.FreeItems); 770 906 // MIKE: what does the below 2 lines do? 771 907 for (Item i : copies) … … 784 920 if (clicked != null) { 785 921 // check permissions 786 if (clicked.Permission < Item Permission.PERMISSION_COPY) {922 if (clicked.Permission < Item.PERMISSION_COPY) { 787 923 FrameGraphics 788 924 .DisplayMessage("Insufficient permission to copy item"); … … 790 926 } 791 927 792 // This happens when the user right clicks on the endpoint of an 793 // existing line 794 // check for unreeling 795 List<Item> copies = ItemUtils.UnreelLine(clicked.Item); 796 928 List<Item> copies = ItemUtils.UnreelLine(clicked); 929 // Copies will NOT be null if the user right clicked on a point 797 930 if (copies == null) { 798 // check if this is picking up a rectangle 799 if (clicked.Item instanceof Dot 800 && clicked.Item.getConnected().size() == 3) { 801 Dot d = null; 802 // only one dot will be present for rectangles 803 for (Item i : clicked.Item.getConnected()) 804 if (i instanceof Dot && d == null) 805 d = (Dot) i; 806 else if (i instanceof Dot && d != null) 807 d = null; 808 809 // if this is indeed a rectangle anchor 810 if (d != null) { 811 // pick up a copy of all enclosed items 812 List<ItemPermission> items = FrameUtils 813 .getItemsEnclosedBy(DisplayIO 814 .getCurrentFrame(), d 815 .getEnclosedShape()); 816 if (items != null) { 817 ArrayList<Item> toCopy = new ArrayList<Item>( 818 items.size()); 819 for (ItemPermission ip : items) 820 if (ip.Permission >= ItemPermission.PERMISSION_COPY) 821 toCopy.add(ip.Item); 822 823 List<Item> toPickup = copy(toCopy); 824 clearParent(toPickup); 825 pickup(toPickup); 826 } 827 return; 828 } 829 } 830 copies = copy(clicked.Item); 831 } 832 931 List<Item> originals = clicked.getConnected(); 932 copies = ItemUtils.CopyItems(originals, _extrude); 933 } 833 934 pickup(copies); 834 935 return; 835 836 936 } else { 837 // if the user is pointing inside a closed shape, copy the items 838 // inside 937 // if user is pointing in a closed shape, copy the items inside 839 938 if (clickedIn != null) { 840 939 List<Item> toCopy = new ArrayList<Item>(clickedIn.size()); 841 for (Item Permissionip : clickedIn)842 if (ip.Permission >= Item Permission.PERMISSION_COPY)843 toCopy.add(ip .Item);940 for (Item ip : clickedIn) 941 if (ip.Permission >= Item.PERMISSION_COPY) 942 toCopy.add(ip); 844 943 845 944 List<Item> copies = copy(toCopy); … … 952 1051 FrameGraphics.Repaint(); 953 1052 return; 1053 } 1054 1055 if (_mouseDown == MouseEvent.BUTTON2 && _lastClickedOn == null 1056 && _lastClickedIn == null) { 1057 Item on = FrameUtils.onItem(DisplayIO.getCurrentFrame(), e.getX(), 1058 e.getY()); 1059 // if the user can spot-weld, show the virtual spot 1060 if (Frame.FreeItems.size() == 0 && on instanceof Line) { 1061 Line line = (Line) on; 1062 line.showVirtualSpot(e.getX(), e.getY()); 1063 } 954 1064 } 955 1065 … … 966 1076 || Math.abs(MouseY - e.getY()) > UserSettings.NoOpThreshold) 967 1077 _isNoOp = true; 1078 1079 FrameGraphics.Repaint(); 968 1080 } 969 1081 … … 1014 1126 if (checkHighlight) { 1015 1127 // ByMike: Get the item the mouse is hovering over 1016 Item Permissionclick = FrameUtils.getCurrentItem();1128 Item click = FrameUtils.getCurrentItem(); 1017 1129 Item on = null; 1018 1130 // System.out.println(click); 1019 1131 if (click != null) { 1020 on = click .Item;1132 on = click; 1021 1133 // set the context 1022 1134 if (on instanceof Line) … … 1155 1267 1156 1268 private static void move(List<Item> toMove) { 1157 int deltax = toMove.get(0).getX() - (DisplayIO.getMouseX() - _offX); 1158 int deltay = toMove.get(0).getY() - (MouseY - _offY); 1269 int xPos = (DisplayIO.getMouseX() - _offX); 1270 1271 Item firstDot = toMove.get(0); 1272 1273 /* 1274 * for (Item i: toMove) { if (i instanceof Dot){ firstDot = i; break; } } 1275 */ 1276 1277 int deltax = firstDot.getX() - xPos; 1278 int deltay = firstDot.getY() - (MouseY - _offY); 1159 1279 1160 1280 for (Item move : toMove) { … … 1175 1295 private static void checkTDFCItemWaiting() { 1176 1296 // if there is a TDFC Item waiting 1177 if ( _tdfcItem!= null) {1297 if (getTdfcItem() != null) { 1178 1298 Frame currentFrame = DisplayIO.getCurrentFrame(); 1179 1299 boolean change = currentFrame.hasChanged(); … … 1183 1303 // possible 1184 1304 if (!change && !saved) { 1185 _tdfcItem.setLink(null);1186 _tdfcItem.getParent().setChanged(true);1187 FrameIO.SaveFrame( _tdfcItem.getParent());1305 getTdfcItem().setLink(null); 1306 getTdfcItem().getParent().setChanged(true); 1307 FrameIO.SaveFrame(getTdfcItem().getParent()); 1188 1308 FrameGraphics.Repaint(); 1189 1309 } else { … … 1192 1312 } 1193 1313 1194 _tdfcItem = null;1314 setTdfcItem(null); 1195 1315 } 1196 1316 } … … 1198 1318 private static void back() { 1199 1319 checkTDFCItemWaiting(); 1320 1200 1321 DisplayIO.Back(); 1201 1322 1202 1323 // repaint things if necessary 1203 1324 if (Frame.itemAttachedToCursor()) … … 1226 1347 1227 1348 linker.setLink("" + next.getFrameNumber()); 1228 _tdfcItem = linker; 1349 setTdfcItem(linker); 1350 1351 // Set the link for an @Parent annotation item if one is on the frame 1352 for (Item i : next.getItems()) { 1353 if ((i instanceof Text) && ItemUtils.isTag(i, ItemUtils.TAG_PARENT) 1354 && i.getLink() == null) 1355 i.setLink(DisplayIO.getCurrentFrame().getFrameName()); 1356 } 1229 1357 1230 1358 FrameUtils.DisplayFrame(next, true); … … 1247 1375 * 1248 1376 * @param toExtract 1249 * ItemPermission containing the Item to extract the attributes 1250 * from. 1377 * Item containing the Item to extract the attributes from. 1251 1378 */ 1252 private static void extractAttributes(Item PermissiontoExtract) {1253 if (toExtract == null || toExtract .Item== null)1379 private static void extractAttributes(Item toExtract) { 1380 if (toExtract == null || toExtract == null) 1254 1381 return; 1255 1382 … … 1258 1385 1259 1386 Text attribs; 1260 Item item = toExtract .Item;1387 Item item = toExtract; 1261 1388 // Extract the frames attributes when the user clicks on the frame name 1262 1389 if (item.isFrameName()) … … 1276 1403 } 1277 1404 1278 private static void delete(Item PermissiontoDelete) {1405 private static void delete(Item toDelete) { 1279 1406 FrameUtils.LastEdited = null; 1280 1407 _offX = _offY = 0; … … 1282 1409 // check if the user is pointing at the frame's framename 1283 1410 if (toDelete != null 1284 && toDelete .Item == DisplayIO.getCurrentFrame().getName()) {1411 && toDelete == DisplayIO.getCurrentFrame().getFrameNameItem()) { 1285 1412 DisplayIO.getCurrentFrame().clear(); 1286 1413 FrameGraphics.Repaint(); … … 1293 1420 if (Frame.FreeItems.size() == 1 1294 1421 && Frame.FreeItems.get(0) instanceof Text 1295 && toDelete != null && toDelete .Iteminstanceof Text) {1422 && toDelete != null && toDelete instanceof Text) { 1296 1423 1297 1424 // check permissions 1298 if (toDelete.Permission < Item Permission.PERMISSION_FULL) {1425 if (toDelete.Permission < Item.PERMISSION_FULL) { 1299 1426 FrameGraphics 1300 1427 .DisplayMessage("Insufficient permission to swap Item text"); … … 1302 1429 } 1303 1430 1304 Text anchored = (Text) toDelete .Item;1431 Text anchored = (Text) toDelete; 1305 1432 Text free = (Text) Frame.FreeItems.get(0); 1306 1433 … … 1329 1456 // if the user is pointing inside a closed shape, delete all 1330 1457 // items inside it 1331 List<Item Permission> items = FrameUtils.getCurrentItems();1458 List<Item> items = FrameUtils.getCurrentItems(); 1332 1459 1333 1460 if (items != null) { 1334 1461 ArrayList<Item> toRemove = new ArrayList<Item>(items.size()); 1335 for (Item Permissionip : items)1336 if (ip.Permission >= Item Permission.PERMISSION_FULL) {1337 toRemove.add(ip .Item);1462 for (Item ip : items) 1463 if (ip.Permission >= Item.PERMISSION_FULL) { 1464 toRemove.add(ip); 1338 1465 } 1339 1466 … … 1352 1479 } else { 1353 1480 // check permissions 1354 if (toDelete.Permission < Item Permission.PERMISSION_FULL) {1481 if (toDelete.Permission < Item.PERMISSION_FULL) { 1355 1482 FrameGraphics 1356 1483 .DisplayMessage("Insufficient permission to delete item"); … … 1358 1485 } 1359 1486 1360 Frame current = toDelete. Item.getParent();1487 Frame current = toDelete.getParent(); 1361 1488 1362 1489 current.setChanged(true); … … 1364 1491 List<Item> toUndo = new LinkedList<Item>(); 1365 1492 1366 if (toDelete .Iteminstanceof Dot) {1367 toUndo.addAll(deleteDot((Dot) toDelete .Item));1493 if (toDelete instanceof Dot) { 1494 toUndo.addAll(deleteDot((Dot) toDelete)); 1368 1495 } else 1369 toUndo.addAll(copy(toDelete. Item.getConnected()));1496 toUndo.addAll(copy(toDelete.getConnected())); 1370 1497 1371 1498 current.addAllToUndo(toUndo); 1372 current.removeAllItems(toDelete. Item.getConnected());1499 current.removeAllItems(toDelete.getConnected()); 1373 1500 // reset the mouse cursor 1374 1501 updateCursor(); … … 1429 1556 } 1430 1557 1431 // check for rectangle deletion 1432 if (itemList.size() == 3) { 1433 boolean rectangle = false; 1434 Dot dot = null; 1435 // check that this is indeed a rectangle 1436 for (Item check : itemList) { 1437 if (dot == null && check instanceof Dot) 1438 dot = (Dot) check; 1439 else if (check != dot && !dot.getLines().contains(check)) { 1440 rectangle = false; 1441 break; 1442 } else 1443 rectangle = true; 1444 } 1445 1446 // if this is a rectangle, remove the entire rectangle 1447 if (rectangle) { 1448 // List<Item> copy = copy(dot.getAllConnected()); 1449 current.addAllToUndo(dot.getAllConnected()); 1450 current.removeAllItems(dot.getAllConnected()); 1451 itemList.clear(); 1452 // reset the mouse cursor 1453 updateCursor(); 1454 FrameGraphics.Repaint(); 1455 return; 1456 } 1457 } 1558 // Mike: What is the point of the code below 1559 // It causes problems when deleting three items off the cursor which 1560 // include a non dot or line item 1561 /* 1562 * // check for rectangle deletion if (itemList.size() == 3) { boolean 1563 * rectangle = false; Dot dot = null; // check that this is indeed a 1564 * rectangle for (Item check : itemList) { if (dot == null && check 1565 * instanceof Dot) dot = (Dot) check; else if (check != dot && 1566 * !dot.getLines().contains(check)) { rectangle = false; break; } else 1567 * rectangle = true; } // if this is a rectangle, remove the entire 1568 * rectangle if (rectangle) { // List<Item> copy = 1569 * copy(dot.getAllConnected()); 1570 * current.addAllToUndo(dot.getAllConnected()); 1571 * current.removeAllItems(dot.getAllConnected()); itemList.clear(); // 1572 * reset the mouse cursor updateCursor(); FrameGraphics.Repaint(); 1573 * return; } } 1574 */ 1458 1575 1459 1576 current.removeAllItems(itemList); … … 1516 1633 1517 1634 public static List<Item> merge(List<Item> merger, Item mergee) { 1518 if (mergee.getParent().get Name() == mergee) {1635 if (mergee.getParent().getFrameNameItem() == mergee) { 1519 1636 return mergee.getParent().merge(merger); 1520 1637 } … … 1614 1731 // TODO tidy this up... the text override of this method 1615 1732 // doesnt use the parametres MouseY and MouseX!! 1616 res = mergee.merge(i, DisplayIO.getMouseX(), MouseY 1617 - DisplayIO.getOffset()); 1733 res = mergee.merge(i, DisplayIO.getMouseX(), MouseY); 1618 1734 if (res != null) { 1619 1735 remain.add(res); … … 1621 1737 } 1622 1738 } else { 1623 res = mergee.merge(i, DisplayIO.getMouseY(), MouseY 1624 - DisplayIO.getOffset()); 1739 res = mergee.merge(i, DisplayIO.getMouseY(), MouseY); 1625 1740 if (res != null) 1626 1741 remain.addAll(res.getConnected()); … … 1696 1811 } 1697 1812 1698 private static voidcreateLine() {1813 private static Line createLine() { 1699 1814 // create the two endpoints 1700 1815 Dot end = new Dot(DisplayIO.getRealMouseX(), DisplayIO.getMouseY(), … … 1712 1827 // attach the line to the cursor 1713 1828 pickup(end); 1829 1830 return line; 1714 1831 } 1715 1832 … … 1730 1847 1731 1848 public static void anchor(Item toAnchor) { 1849 // System.out.println("Anchor:" + toAnchor.getX() + "," + 1850 // toAnchor.getY()); 1851 1732 1852 Frame current = DisplayIO.getCurrentFrame(); 1733 1853 // toAnchor.anchor(current); … … 1803 1923 else 1804 1924 line.toggleArrowHeadLength(arg0.getWheelRotation()); 1925 line.getParent().change(); 1805 1926 FrameGraphics.Repaint(); 1806 1927 } … … 1816 1937 FrameKeyboardActions.functionKey(rotationType); 1817 1938 } else if (clicks == MOUSE_WHEEL_THRESHOLD) { 1818 Item Permissionip = FrameUtils.getCurrentItem();1939 Item ip = FrameUtils.getCurrentItem(); 1819 1940 1820 1941 // if the user is not pointing to any item … … 1825 1946 } else { 1826 1947 // check permissions 1827 if (ip.Permission < Item Permission.PERMISSION_FULL) {1948 if (ip.Permission < Item.PERMISSION_FULL) { 1828 1949 FrameGraphics 1829 1950 .DisplayMessage("Insufficient permission to change the size of that item"); … … 1832 1953 } 1833 1954 1834 if (ip .Iteminstanceof Line) {1835 Line line = (Line) ip .Item;1955 if (ip instanceof Line) { 1956 Line line = (Line) ip; 1836 1957 line.toggleDashed(arg0.getWheelRotation()); 1958 line.getParent().change(); 1837 1959 FrameGraphics.Repaint(); 1838 1960 return; … … 1879 2001 return isDelete(_lastMouseClick); 1880 2002 } 2003 2004 public static void setTdfcItem(Item _tdfcItem) { 2005 FrameMouseActions._tdfcItem = _tdfcItem; 2006 } 2007 2008 public static Item getTdfcItem() { 2009 return _tdfcItem; 2010 } 1881 2011 } -
trunk/src/org/expeditee/gui/FrameUtils.java
r4 r7 12 12 import org.expeditee.items.Dot; 13 13 import org.expeditee.items.Item; 14 import org.expeditee.items.ItemPermission;15 14 import org.expeditee.items.ItemUtils; 16 15 import org.expeditee.items.Line; … … 187 186 space = MINIMUM_INTERITEM_SPACING; 188 187 189 if (above != curr.get Name() && above != curr.getTitle())188 if (above != curr.getFrameNameItem() && above != curr.getTitle()) 190 189 x = above.getX(); 191 190 … … 493 492 UserSettings.NoOpThreshold = getInt(item, 494 493 UserSettings.NoOpThreshold); 495 else if (ItemUtils.isTag(item, "@InitialWidth:")) {496 UserSettings.InitialWidth = getInt(item,497 UserSettings.InitialWidth); }498 else if (ItemUtils.isTag(item, "@InitialHeight:")){499 UserSettings.InitialHeight = getInt(item,500 UserSettings.InitialHeight); }501 else if (ItemUtils.isTag(item, "@Logging:")) {494 else if (ItemUtils.isTag(item, "@InitialWidth:")) { 495 UserSettings.InitialWidth = getInt(item, 496 UserSettings.InitialWidth); 497 } else if (ItemUtils.isTag(item, "@InitialHeight:")) { 498 UserSettings.InitialHeight = getInt(item, 499 UserSettings.InitialHeight); 500 } else if (ItemUtils.isTag(item, "@Logging:")) { 502 501 UserSettings.Logging = getBoolean(item, UserSettings.Logging); 503 502 } else if (ItemUtils.isTag(item, ItemUtils.TAG_ITEM_TEMPLATE)) { … … 647 646 648 647 // Text title = null; 649 // Text template = UserSettings .ItemTemplate.copy();648 // Text template = UserSettingsTemplate.copy(); 650 649 651 650 ArrayList<Overlay> overlays = new ArrayList<Overlay>(); … … 708 707 // Parse(overlay); 709 708 if (overlay != null && !overlays.contains(overlay)) 710 overlays .add(new Overlay(overlay,711 ItemPermission.PERMISSION_NONE));709 overlays 710 .add(new Overlay(overlay, Item.PERMISSION_NONE)); 712 711 } 713 712 … … 717 716 String link = i.getLink(); 718 717 if (FrameIO.isPositiveInteger(link)) 719 link = toParse.getFramesetNameAdjusted() 720 + link; 718 link = toParse.getFramesetNameAdjusted() + link; 721 719 Frame overlay = FrameIO.LoadFrame(link); 722 720 // Parse(overlay); … … 726 724 .getFirstLine()); 727 725 // default permission (if none is specified) 728 int perm = Item Permission.PERMISSION_FOLLOW_LINKS;726 int perm = Item.PERMISSION_FOLLOW_LINKS; 729 727 730 728 try { … … 735 733 level = level.toLowerCase().trim(); 736 734 if (level.equals("none")) 737 perm = Item Permission.PERMISSION_NONE;735 perm = Item.PERMISSION_NONE; 738 736 else if (level.equals("links") 739 737 || level.equals("link")) 740 perm = Item Permission.PERMISSION_FOLLOW_LINKS;738 perm = Item.PERMISSION_FOLLOW_LINKS; 741 739 else if (level.equals("copy")) 742 perm = Item Permission.PERMISSION_COPY;740 perm = Item.PERMISSION_COPY; 743 741 else if (level.equals("tdfc")) 744 perm = Item Permission.PERMISSION_TDFC;742 perm = Item.PERMISSION_TDFC; 745 743 else if (level.equals("full") 746 744 || level.equals("all")) 747 perm = Item Permission.PERMISSION_FULL;745 perm = Item.PERMISSION_FULL; 748 746 else 749 747 FrameGraphics … … 794 792 } 795 793 796 if (toParse.getFrameNumber() > 0797 && ItemUtils.isTag(i, ItemUtils.TAG_PARENT)798 && i.getLink() == null)799 i.setLink(DisplayIO.getCurrentFrame().getFrameName());800 801 794 } catch (Exception e) { 802 795 Logger.Log(e); … … 833 826 * @return The Item at the given coordinates, or NULL if none is found. 834 827 */ 835 p rivate static ItemPermissiononItem(Frame toCheck, int x, int y) {828 public static Item onItem(Frame toCheck, int x, int y) { 836 829 if (toCheck == null) 837 830 return null; 838 831 839 List<Item Permission> possibles = new ArrayList<ItemPermission>(0);832 List<Item> possibles = new ArrayList<Item>(0); 840 833 841 834 // if the mouse is in the message area … … 843 836 // check the individual message items 844 837 for (Text message : FrameGraphics.Messages) { 845 if (message != null && message.contains(x, y)) 846 possibles.add(new ItemPermission(message, 847 ItemPermission.PERMISSION_COPY)); 838 if (message != null) { 839 if (message.contains(x, y)) { 840 message.Permission = Item.PERMISSION_COPY; 841 } 842 possibles.add(message); 843 } 848 844 } 849 845 850 846 // check the link to the message frame 851 847 if (FrameGraphics.MessageLink != null) { 852 if (FrameGraphics.MessageLink.contains(x, y)) 853 possibles.add(new ItemPermission(FrameGraphics.MessageLink, 854 ItemPermission.PERMISSION_COPY)); 848 if (FrameGraphics.MessageLink.contains(x, y)) { 849 FrameGraphics.MessageLink.Permission = Item.PERMISSION_COPY; 850 } 851 possibles.add(FrameGraphics.MessageLink); 855 852 } 856 853 // otherwise, the mouse is on the frame … … 860 857 && !Frame.FreeItems.contains(LastEdited) 861 858 && LastEdited.getParent() == DisplayIO.getCurrentFrame() 862 && LastEdited.getParent().getItems().contains(LastEdited)) 863 return new ItemPermission(LastEdited,864 ItemPermission.PERMISSION_FULL);865 else859 && LastEdited.getParent().getItems().contains(LastEdited)) { 860 LastEdited.Permission = Item.PERMISSION_FULL; 861 return LastEdited; 862 } else 866 863 LastEdited = null; 867 864 868 865 ArrayList<Item> checkList = new ArrayList<Item>(); 869 866 checkList.addAll(toCheck.getItems()); 867 checkList.add(toCheck.getFrameNameItem()); 870 868 for (Item i : checkList) { 871 869 // do not check annotation items in audience mode … … 873 871 if (i.contains(x, y) && !Frame.FreeItems.contains(i)) { 874 872 // names have copy permissions only 875 if (i == toCheck.getName()) 876 possibles.add(new ItemPermission(i, 877 ItemPermission.PERMISSION_TDFC)); 878 else 879 possibles.add(new ItemPermission(i, 880 ItemPermission.PERMISSION_FULL)); 873 if (i == toCheck.getFrameNameItem()) { 874 i.Permission = Item.PERMISSION_TDFC; 875 possibles.add(i); 876 } else { 877 i.Permission = Item.PERMISSION_FULL; 878 possibles.add(i); 879 } 881 880 } 882 881 } … … 884 883 885 884 for (Overlay o : toCheck.getOverlays()) { 886 if (o.Level > Item Permission.PERMISSION_NONE) {887 Item Permissioni = onItem(o.Frame, x, y);885 if (o.Level > Item.PERMISSION_NONE) { 886 Item i = onItem(o.Frame, x, y); 888 887 889 888 // the message is included above with full permissions, 890 // it 891 // should be ignored here 889 // it should be ignored here 892 890 if (i != null 893 && /* i .Item != FrameGraphics.TextMessage && */i.Item891 && /* i != FrameGraphics.TextMessage && */i 894 892 .getID() > 0) { 895 893 if (o.Level < i.Permission) … … 910 908 911 909 // return closest x,y pair to mouse 912 Item Permissionclosest = possibles.get(0);913 int distance = (int) Math.sqrt(Math .pow(Math.abs(closest.Item.getX()914 - x), 2)915 + Math.pow(Math.abs(closest. Item.getY() - y), 2));916 917 for (Item Permissionip : possibles) {918 Item i = ip .Item;910 Item closest = possibles.get(0); 911 int distance = (int) Math.sqrt(Math 912 .pow(Math.abs(closest.getX() - x), 2) 913 + Math.pow(Math.abs(closest.getY() - y), 2)); 914 915 for (Item ip : possibles) { 916 Item i = ip; 919 917 920 918 int d = (int) Math.sqrt(Math.pow(Math.abs(i.getX() - x), 2) … … 928 926 * TODO: Remove line\dot specification 929 927 */ 930 if ((!(closest .Iteminstanceof Dot && i instanceof Line))931 && (!(closest .Iteminstanceof Text && i instanceof Line)))928 if ((!(closest instanceof Dot && i instanceof Line)) 929 && (!(closest instanceof Text && i instanceof Line))) 932 930 closest = ip; 933 931 … … 939 937 } 940 938 941 public static Item PermissiongetCurrentItem() {939 public static Item getCurrentItem() { 942 940 return onItem(DisplayIO.getCurrentFrame(), DisplayIO.getMouseX(), 943 941 DisplayIO.getMouseY()); 944 942 } 945 943 946 public static List<ItemPermission> getCurrentItems() { 947 /* 948 * // update enclosed shapes Frame current = 949 * DisplayIO.getCurrentFrame(); List<Item> items = current.getItems(); 950 * ArrayList<Dot> dots = new ArrayList<Dot>(0); 951 * 952 * for (Item i : items) if (i instanceof Dot) dots.add((Dot) i); 953 * 954 * ArrayList<Polygon> possibles = new ArrayList<Polygon>(0); ArrayList<Dot> 955 * used = new ArrayList<Dot>(0); 956 * 957 * for (Dot d : dots) if (d.isEnclosed()) { boolean skip = false; // 958 * check for duplicate enclosures for (Dot seen : used) { if 959 * (seen.getEnclosingDots().contains(d)) { skip = true; break; } } 960 * 961 * if (!skip) { Polygon p = d.getEnclosedShape(); if (p 962 * .contains(DisplayIO.getMouseX(), DisplayIO .getMouseY())) { 963 * possibles.add(p); used.add(d); } } } 964 * 965 * if (possibles.size() == 0) return null; // if there is only one 966 * possibility, return it if (possibles.size() == 1) { return 967 * getItemsEnclosedBy(current, possibles.get(0)); //otherwise, determine 968 * which polygon is closest to the cursor }else{ 969 * Collections.sort(possibles, new Comparator<Polygon>(){ public int 970 * compare(Polygon p1, Polygon p2) { int closest = Integer.MAX_VALUE; 971 * int close2 = Integer.MAX_VALUE; 972 * 973 * int mouseX = DisplayIO.getMouseX(); int mouseY = 974 * DisplayIO.getMouseY(); 975 * 976 * for(int i = 0; i < p1.npoints; i++){ int diff = 977 * Math.abs(p1.xpoints[i] - mouseX) + Math.abs(p1.ypoints[i] - mouseY); 978 * int diff2 = Integer.MAX_VALUE; 979 * 980 * if(i < p2.npoints) diff2 = Math.abs(p2.xpoints[i] - mouseX) + 981 * Math.abs(p2.ypoints[i] - mouseY); 982 * 983 * if(diff < Math.abs(closest)){ close2 = closest; closest = diff; }else 984 * if(diff < Math.abs(close2)) close2 = diff; 985 * 986 * if(diff2 < Math.abs(closest)){ close2 = closest; closest = -diff2; 987 * }else if(diff2 < Math.abs(close2)) close2 = diff2; } 988 * 989 * if(closest > 0 && close2 > 0) return -10; 990 * 991 * if(closest < 0 && close2 < 0) return 10; 992 * 993 * 994 * if(closest > 0) return -10; 995 * 996 * return 10; } 997 * 998 * }); return getItemsEnclosedBy(current, possibles.get(0)); } 999 */ 944 public static List<Item> getCurrentItems() { 1000 945 1001 946 List<Dot> enclosure = getEnclosingDots(); … … 1089 1034 } 1090 1035 1091 public static List<ItemPermission> getItemsEnclosedBy(Frame frame, 1092 Polygon poly) { 1036 public static List<Item> getItemsEnclosedBy(Frame frame, Polygon poly) { 1093 1037 List<Item> contained = frame.getItemsWithin(poly); 1094 1038 1095 ArrayList<ItemPermission> results = new ArrayList<ItemPermission>( 1096 contained.size()); 1039 ArrayList<Item> results = new ArrayList<Item>(contained.size()); 1097 1040 1098 1041 // check for correct permissions 1099 1042 for (Item item : contained) { 1100 1043 // if the item is on the frame 1101 if (item.getParent() == frame || item.getParent() == null) 1044 if (item.getParent() == frame || item.getParent() == null) { 1102 1045 // TODO this is a bit of a hack... 1103 1046 // the … … 1113 1056 // is 1114 1057 // created... 1115 results.add(new ItemPermission(item,1116 ItemPermission.PERMISSION_FULL));1117 // otherwise, it must be on an overlay frame1118 else {1058 item.Permission = Item.PERMISSION_FULL; 1059 results.add(item); 1060 // otherwise, it must be on an overlay frame 1061 } else { 1119 1062 for (Overlay overlay : frame.getOverlays()) 1120 1063 if (overlay.Frame == item.getParent()) { 1121 results.add(new ItemPermission(item, overlay.Level)); 1064 item.Permission = overlay.Level; 1065 results.add(item); 1122 1066 break; 1123 1067 } … … 1155 1099 yPos += spacing; 1156 1100 1157 profile.addText(xPos, yPos, "@InitialWidth: " + UserSettings.InitialWidth, null); 1101 profile.addText(xPos, yPos, "@InitialWidth: " 1102 + UserSettings.InitialWidth, null); 1158 1103 yPos += spacing; 1159 1104 1160 profile.addText(xPos, yPos, "@InitialHeight: " + UserSettings.InitialHeight, null); 1105 profile.addText(xPos, yPos, "@InitialHeight: " 1106 + UserSettings.InitialHeight, null); 1161 1107 yPos += spacing; 1162 1108 … … 1175 1121 yPos = intialYPos; 1176 1122 1177 Text help = profile.addText(xPos, yPos, "Expeditee Help", null);1178 help.setSize(25);1179 help.setFontStyle("Bold");1180 help.setFamily("SansSerif");1181 help.setColor(Item.COLOR_WHEEL[3]);1182 1183 xPos = 625;1184 1123 // Iterate through the help folder and add links 1185 1124 File helpDirectory = new File(FrameIO.HELP_PATH); 1186 1125 if (helpDirectory != null) { 1187 for (File helpFrameset : helpDirectory.listFiles()) { 1188 String framesetName = helpFrameset.getName(); 1189 Frame indexFrame = FrameIO.LoadFrame(framesetName 1190 + FrameIO.getFramesetExtension(framesetName)); 1191 // Look through the folder for help index pages 1192 if (indexFrame != null 1193 && ItemUtils.FindTag(indexFrame.getItems(), 1194 "@HelpIndex") != null) { 1195 yPos += spacing; 1196 t = profile.addText(xPos, yPos, indexFrame 1197 .getFramesetName(), null); 1198 t.setLink(indexFrame.getFrameName()); 1126 File[] helpFramesets = helpDirectory.listFiles(); 1127 if (helpFramesets != null) { 1128 1129 // Add the title for the help index 1130 Text help = profile.addText(xPos, yPos, "Expeditee Help", null); 1131 help.setSize(25); 1132 help.setFontStyle("Bold"); 1133 help.setFamily("SansSerif"); 1134 help.setColor(Item.COLOR_WHEEL[3]); 1135 1136 xPos = 625; 1137 1138 for (File helpFrameset : helpFramesets) { 1139 String framesetName = helpFrameset.getName(); 1140 Frame indexFrame = FrameIO.LoadFrame(framesetName 1141 + FrameIO.getFramesetExtension(framesetName)); 1142 // Look through the folder for help index pages 1143 if (indexFrame != null 1144 && ItemUtils.FindTag(indexFrame.getItems(), 1145 "@HelpIndex") != null) { 1146 yPos += spacing; 1147 t = profile.addText(xPos, yPos, indexFrame 1148 .getFramesetName(), null); 1149 t.setLink(indexFrame.getFrameName()); 1150 } 1199 1151 } 1200 1152 } … … 1204 1156 FrameIO.SaveFrame(profile); 1205 1157 } 1158 1159 /** 1160 * Adjusts a frameset name so a period is appended if it ends in a digit. 1161 * This form of the frameset name is used when referencing frames in the 1162 * frame set. 1163 * 1164 * @param frameset 1165 * @return 1166 */ 1167 public static String GetFramesetNameAdjusted(String frameset) { 1168 return frameset 1169 + (Character.isDigit(frameset.charAt(frameset.length() - 1)) ? "." 1170 : ""); 1171 } 1206 1172 } -
trunk/src/org/expeditee/items/Dot.java
r4 r7 32 32 33 33 private boolean _filled = true; 34 35 protected boolean _filledHighlight = false; 34 36 35 37 public Dot(int id) { … … 108 110 if (isHighlighted()) { 109 111 g.setColor(getHighlightColor()); 110 g.drawPolygon(getPolygon()); 112 // Draw the highlighting rectangle surrounding the dot 113 // this is drawn even if its part of a rectangle 114 if (_filledHighlight) 115 g.fillPolygon(getPolygon()); 116 else 117 g.drawPolygon(getPolygon()); 111 118 } 112 119 … … 346 353 return "P " + getID(); 347 354 } 355 356 @Override 357 public void setFilledHighlight(boolean value) { 358 _filledHighlight = value; 359 } 360 361 @Override 362 public void delete() { 363 super.delete(); 364 365 for(Line l: this.getLines()) 366 l.delete(); 367 } 348 368 } -
trunk/src/org/expeditee/items/Item.java
r4 r7 33 33 * 34 34 */ 35 public abstract class Item implements Comparable<Item>, Runnable { 36 35 public abstract class Item implements Comparable<Item>, Runnable { 36 37 public static int PERMISSION_NONE = 0; 38 public static int PERMISSION_FOLLOW_LINKS = 1; 39 public static int PERMISSION_COPY = 2; 40 public static int PERMISSION_TDFC = 3; 41 public static int PERMISSION_FULL = 4; 42 43 public static final int NEAR_DISTANCE = 15; 44 37 45 /** 38 46 * The default Color to draw highlighting in … … 43 51 44 52 public static final Color DEPRESSED_HIGHLIGHT = Color.GREEN; 53 54 public static final Color DISCONNECT_HIGHLIGHT = Color.BLUE; 45 55 46 56 public static final Color LINK_COLOR = Color.BLACK; … … 63 73 public static final int MARGIN_LEFT = 20; 64 74 65 private Point _offset = new Point(0, 0); 66 67 private int _x; 68 69 private int _y; 70 71 private int _id; 72 73 private String _creationDate = null; 74 75 private boolean _linkMark = true; 76 77 private boolean _actionMark = true; 78 79 private boolean _highlight = true; 80 81 private boolean _isHighlighted = false; 82 83 // private boolean _isValidLink = true; 84 85 private Dimension _maxSize = null; 86 87 private String _owner = null; 88 89 private String _link = null; 90 91 private StringBuffer _data = new StringBuffer(); 92 93 private List<String> _actionCursorEnter = null; 94 95 private List<String> _actionCursorLeave = null; 96 97 private List<String> _actionEnterFrame = null; 98 99 private List<String> _actionLeaveFrame = null; 100 101 private Color _colorFill = null; 102 103 private Color _color = null; 104 105 private Color _highlightColor = DEFAULT_HIGHLIGHT; 106 107 private Color _colorBackground = null; 108 109 private Color _colorTopShadow = null; 110 111 private Color _colorBottomShadow = null; 112 113 // the link\action circle 114 private Polygon _circle = null; 115 116 // the invalid link cross 117 private Polygon _circleCross = null; 118 119 private Frame _parent = null; 120 121 protected int _highlightThickness = 2; 122 123 // arrowhead parameters 124 private int _arrowheadLength = 0; 125 126 private double _arrowheadRatio = 0; 127 128 private Polygon _arrowhead = null; 129 130 // the list of lines that this point is part of. 131 private List<Line> _lines = new ArrayList<Line>(); 132 133 private int[] _linePattern = null; 134 135 private boolean _floating = false; 136 137 // list of points constrained with this point 138 private List<Constraint> _constraints = null; 139 75 protected static final double DEFAULT_ARROWHEAD_RATIO = 0.5; 76 140 77 public static final Color GREEN = Color.GREEN.darker(); 141 78 … … 148 85 DisplayIO.DEFAULT_BACKGROUND }; 149 86 87 public static final Color[] FILL_COLOR_WHEEL = { Color.BLACK, new Color(255,150,150), 88 new Color(150,150,255), new Color(150,255,150), new Color(255,150,255), new Color(255,255,100), 89 DisplayIO.DEFAULT_BACKGROUND }; 90 150 91 public static final int UNCHANGED_CURSOR = -100; 151 92 … … 160 101 public static final int JUSTIFICATION_NONE = -1; 161 102 103 // private boolean _isValidLink = true; 104 162 105 public static final int JUSTIFICATION_FULL = 0; 163 106 … … 171 114 172 115 public static final int POINTTYPE_CIRCLE = 0; 173 174 private LinkedList<String> _actions = null;175 176 private String _link_frameset = null;177 178 private String _link_template = null;179 180 private String _fillPattern = null;181 182 protected Item() {183 _creationDate = Logger.EasyDateFormat("ddMMMyyyy:HHmm");184 }185 186 /**187 * Items are sorted by their Y coordinate on the screen.188 *189 * @param i190 * The Item to compare this Item to191 * @return a negative integer, zero, or a positive integer as this object is192 * less than, equal to, or greater than the specified object.193 */194 public int compareTo(Item i) {195 return getY() - i.getY();196 }197 198 public static int getGravity() {199 return org.expeditee.gui.UserSettings.Gravity;200 }201 202 public static boolean showLineHighlight() {203 return org.expeditee.gui.UserSettings.LineHighlight;204 }205 206 public boolean equals(Object o) {207 if (o instanceof Item) {208 Item i = (Item) o;209 return i.getID() == getID()210 && ((i.getParent() == _parent) || (i.getParent() != null && i211 .getParent().equals(_parent)));212 213 } else214 return false;215 }216 217 /**218 * Adds a given line to the list of lines that this Point is an end for.219 *220 * @param line221 * The Line that this Point is an end of.222 */223 public void addLine(Line line) {224 if (_lines.contains(line)) {225 return;226 }227 228 line.setColor(getColor());229 line.setSize(getSize());230 line.setLinePattern(getLinePattern());231 232 _lines.add(line);233 }234 235 /**236 * Removes the given Line from the list of lines that this Dot is an end237 * for.238 *239 * @param line240 * The Line that this Dot is no longer an end of.241 */242 public void removeLine(Line line) {243 _lines.remove(line);244 }245 246 /**247 * Returns a list of Lines where this Dot is an end.248 *249 * @return A list of the Lines that this Dot is an end for or null if no250 * Lines have been added.251 */252 public List<Line> getLines() {253 return _lines;254 }255 256 public void setLines(List<Line> lines) {257 _lines = lines;258 259 for (Line line : lines)260 line.setLinePattern(getLinePattern());261 }262 263 public void setLinePattern(int[] pattern) {264 _linePattern = pattern;265 266 for (Line line : getLines())267 line.setLinePattern(pattern);268 }269 270 public int[] getLinePattern() {271 return _linePattern;272 }273 274 /**275 * Clears the list of Lines that this Dot is an end of. Note: This only276 * clears this Dot's list and does not have any affect on the Lines or other277 * Dots.278 */279 public void removeAllLines() {280 _lines.clear();281 }282 283 /**284 * Returns the list of IDs of the Lines that this Dot is an end of.285 *286 * @return The list of Line IDs that this point is part of.287 */288 public String getLineIDs() {289 String lineID = null;290 291 if (_lines.size() > 0) {292 lineID = "" + _lines.get(0).getID();293 294 for (int i = 1; i < _lines.size(); i++)295 lineID += " " + _lines.get(i).getID();296 }297 298 return lineID;299 }300 301 /**302 * Sets the list of lines that this point is part of (may be set to null).303 *304 * @param lineID305 * A String of line ID numbers separated by spaces.306 */307 public void setLineIDs(String lineID) {308 }309 310 public void setFloating(boolean val) {311 _floating = val;312 }313 314 public boolean isFloating() {315 return _floating;316 }317 318 /**319 * Returns a List of any Constraints that this Dot is a memeber of.320 *321 * @return a List of Constraints that this Dot is a member of.322 */323 public List<Constraint> getConstraints() {324 return _constraints;325 }326 327 public String getConstraintIDs() {328 if (_constraints == null || _constraints.size() == 0)329 return null;330 331 String cons = "";332 333 for (Constraint c : _constraints)334 cons += c.getID() + " ";335 336 return cons.trim();337 }338 339 public void setConstraintIDs(String IDs) {340 };341 342 /**343 * Adds the given Constraint to this Dot344 *345 * @param c346 * The Constraint to set this Dot as a member of.347 */348 public void addConstraint(Constraint c) {349 if (_constraints == null)350 _constraints = new ArrayList<Constraint>();351 352 // do not add duplicate constraint353 if (_constraints.contains(c))354 return;355 356 _constraints.add(c);357 }358 359 public void setConstraints(List<Constraint> constraints) {360 _constraints = constraints;361 }362 363 public void removeAllConstraints() {364 if (_constraints != null)365 _constraints.clear();366 }367 368 /**369 * Removes the given Constraint from the list of constraintss that this Dot370 * is a part of.371 *372 * @param c373 * The Constraint that this Dot is no longer a part of.374 */375 public void removeConstraint(Constraint c) {376 _constraints.remove(c);377 }378 379 /**380 * Returns the ID of this Item, which must be unique for the Frame.381 *382 * @return The ID of this Item.383 */384 public int getID() {385 return _id;386 }387 388 /**389 * Sets the ID of this Item to the given Integer. Note: Items with ID's < 0390 * are not saved391 *392 * @param newID393 * The new ID to assign this Item.394 */395 public void setID(int newID) {396 _id = newID;397 }398 399 /**400 * Returns the Y coordinate of this Item on the screen401 *402 * @return The Y coordinate of this Item on the screen403 */404 public int getY() {405 return _y;406 }407 408 /**409 * Returns the X coordinate of this Item on the screen410 *411 * @return The X coordinate of this Item on the screen412 */413 public int getX() {414 return _x;415 }416 417 /**418 * Sets the position of this item on the screen419 *420 * @param x421 * The new X coordinate422 * @param y423 * The new Y coordinate424 */425 public void setPosition(int x, int y) {426 _x = x;427 _y = y;428 429 updatePolygon();430 431 // update the position of any dots that are constrained by this one432 if (_constraints != null) {433 for (Constraint c : _constraints) {434 Item other = c.getOppositeEnd(this);435 436 // only set the position if the other dot is still fixed to the437 // frame438 if (!other.isFloating()) {439 if (c.getConstraintType() == Constraint.HORIZONTAL440 && other.getY() != getY())441 other.setY(getY());442 443 if (c.getConstraintType() == Constraint.VERTICAL444 && other.getX() != getX())445 other.setX(getX());446 }447 }448 }449 450 for (Line line : getLines())451 line.updatePolygon();452 }453 454 public void setPosition(Point position) {455 setPosition(position.x, position.y);456 }457 458 public Point getPosition() {459 return new Point(getX(), getY());460 }461 462 /**463 * Sets the position of this Item on the X axis464 *465 * @param newX466 * The position on the X axis to assign to this Item467 */468 public void setX(int newX) {469 setPosition(newX, getY());470 }471 472 /**473 * Sets the position of this Item on the Y axis474 *475 * @param newY476 * The position on the Y axis to assign to this Item477 */478 public void setY(int newY) {479 setPosition(getX(), newY);480 }481 482 /**483 * Returns the name of a Frame that this Item links to, or null if this Item484 * has no link.485 *486 * @return The name of a Frame that this Item links to (if any) or null if487 * this Item does not link to anything.488 */489 public String getLink() {490 return _link;491 }492 493 public String getAbsoluteLink() {494 if (_link == null)495 return null;496 assert (_parent!= null);497 if (_parent == null)498 return null;499 500 // if its a relative link then return absolute501 if (FrameIO.isPositiveInteger(_link)) {502 return _parent.getFramesetNameAdjusted()503 + Conversion.getFrameNumber(_link);504 }505 return _link;506 }507 508 /**509 * Links this item to the given Frame, this may be set to null to remove a510 * link.511 *512 * @param frameName513 * The name of the Frame to link this item to.514 */515 public void setLink(String frameName) {516 _link = frameName;517 }518 519 /*520 * public void setLinkValid(boolean val) { _isValidLink = val; }521 */522 523 /**524 * Tests if the item link is a valid framename, that is, the String must525 * begin with a character, end with a number with 0 or more letters and526 * numbers in between. If there is a dot in the framename all the chars527 * after it must be digits.528 *529 * @return True if the given framename is proper, false otherwise.530 */531 public boolean isLinkValid() {532 if (FrameIO.isPositiveInteger(getLink()))533 return true;534 535 if (FrameIO.isValidFrameName(getLink()))536 return true;537 return false;538 }539 540 public void setLinkFrameset(String frameset) {541 _link_frameset = frameset;542 }543 544 public String getLinkFrameset() {545 return _link_frameset;546 }547 548 public void setLinkTemplate(String template) {549 _link_template = template;550 }551 552 public String getLinkTemplate() {553 return _link_template;554 }555 556 /**557 * Adds an action to this Item.558 *559 * @param action560 * The KMS action language to add to this Item561 */562 public void addAction(String action) {563 if (action == null || action.equals("")) {564 return;565 }566 567 if (_actions == null)568 _actions = new LinkedList<String>();569 _actions.add(action);570 }571 572 /**573 * Sets any action code (KMS action language) that should be associated with574 * this Item Each entry in the list is one line of code575 *576 * @param actions577 * The lines of code to associate with this Item578 */579 public void setAction(List<String> actions) {580 if (actions == null || actions.size() == 0)581 _actions = null;582 else583 _actions = new LinkedList<String>(actions);584 }585 586 /**587 * Returns a list of any action code (KMS action language) that is currently588 * associated with this Item589 *590 * @return A List of action code associated with this Item, or null if none591 * has been assigned.592 */593 public List<String> getAction() {594 return _actions;595 }596 597 public String getFirstAction() {598 if (_actions == null)599 return null;600 return _actions.getFirst();601 }602 603 /**604 * Displays this item directly on the screen. Note: All Items are605 * responsible for their own drawing, buffering, etc.606 *607 * @param g608 * The Graphics to draw this Item on.609 */610 public abstract void paint(Graphics2D g);611 612 /**613 * Every Item has an area around it defined by a Shape (typically a614 * rectangle), this method returns true if the given x,y pair lies within615 * the area and false otherwise.616 *617 * @param x618 * The x coordinate to check619 * @param y620 * The y coordinate to check621 * @return True if the Shape around this Item contains the given x,y pair,622 * false otherwise.623 */624 public boolean contains(int x, int y) {625 return getPolygon().contains(x, y);626 }627 628 /**629 * Returns the Shape that surrounds this Item representing this Item's630 * 'gravity'.631 *632 * @return The Shape (rectangle) surrounding this Item, which represents633 * this Items 'gravity'.634 */635 public abstract Polygon getPolygon();636 637 public Area getArea() {638 return new Area(getPolygon());639 }640 641 protected abstract void updatePolygon();642 643 /**644 * Returns the height (in pixels) of this Item's surrounding area.645 *646 * @return The height (in pixels) of this Item's surrounding area as647 * returned by getArea().648 */649 public int getBoundsHeight() {650 return getPolygon().getBounds().height;651 }652 653 /**654 * Returns the width (in pixels) of this Item's surrounding area.655 *656 * @return The width (in pixels) of this Item's surrounding area as returned657 * by getArea().658 */659 public int getBoundsWidth() {660 return getPolygon().getBounds().width;661 }662 663 /**664 * Checks if the given Shape intersects with the Shape around this Item.665 * Note: Both Shape objects should be rectangles for this to work properly.666 *667 * @param s668 * The Shape to check.669 * @return True if the two Shapes overlap, False otherwise.670 */671 public boolean intersects(Polygon p) {672 if (p == null)673 return false;674 675 // return p.getBounds().intersects(getArea().getBounds());676 Area a = new Area(p);677 a.intersect(this.getArea());678 return !a.isEmpty();679 }680 681 /**682 * Paints any highlighting of this Item. This may include changing the683 * thickness (lines) or painting a box around the item (Text, Images). If684 * val is True then the Graphics Color is changed to the highlight Color, if685 * False then the Graphics Color is left unchanged (for clearing of686 * highlighting).687 *688 * @param val689 * True if this Item should be highlighted, false if the690 * highlighting is being cleared.\691 * @return The desired mouse cursor when this Item is highlighted (negative692 * means no change)693 */694 public int showHighlight(boolean val) {695 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS;696 return showHighlight(val, DEFAULT_HIGHLIGHT);697 }698 699 public int showDepressedHighlight(boolean val) {700 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS;701 return showHighlight(val, DEPRESSED_HIGHLIGHT);702 }703 704 public int showHighlight(boolean val, Color c) {705 _isHighlighted = val;706 if (c != null)707 _highlightColor = c;708 else709 _highlightColor = DEFAULT_HIGHLIGHT;710 711 return Item.UNCHANGED_CURSOR;712 }713 714 /**715 * Returns True if this Item is currently highlighted.716 *717 * @return True if this Item is currently highlighted on the screen, False718 * otherwise.719 */720 public boolean isHighlighted() {721 return _isHighlighted;722 }723 724 public Color getHighlightColor() {725 return _highlightColor;726 }727 728 /**729 * Returns a deep copy of this Item, note: it is up to the receiver to730 * change the Item ID etc as necessary.731 *732 * @return A deep copy of this Item.733 */734 public abstract Item copy();735 116 736 117 public static void DuplicateItem(Item source, Item dest) { … … 777 158 dest.setID(source.getID()); 778 159 } 160 } 161 162 public static int getGravity() { 163 return org.expeditee.gui.UserSettings.Gravity; 164 } 165 166 public static boolean showLineHighlight() { 167 return org.expeditee.gui.UserSettings.LineHighlight; 168 } 169 170 private Point _offset = new Point(0, 0); 171 172 private int _x; 173 174 private int _y; 175 176 private int _id; 177 178 private String _creationDate = null; 179 180 private boolean _linkMark = true; 181 182 private boolean _actionMark = true; 183 184 private boolean _highlight = true; 185 186 private boolean _isHighlighted = false; 187 188 private Dimension _maxSize = null; 189 190 private String _owner = null; 191 192 private String _link = null; 193 194 private StringBuffer _data = new StringBuffer(); 195 196 private List<String> _actionCursorEnter = null; 197 198 private List<String> _actionCursorLeave = null; 199 200 private List<String> _actionEnterFrame = null; 201 202 private List<String> _actionLeaveFrame = null; 203 204 public int Permission = PERMISSION_FULL; 205 206 private Color _colorFill = null; 207 208 private Color _color = null; 209 210 private Color _highlightColor = DEFAULT_HIGHLIGHT; 211 212 private Color _colorBackground = null; 213 214 private Color _colorTopShadow = null; 215 216 private Color _colorBottomShadow = null; 217 218 // the link\action circle 219 private Polygon _circle = null; 220 221 // the invalid link cross 222 private Polygon _circleCross = null; 223 224 private Frame _parent = null; 225 226 protected int _highlightThickness = 2; 227 228 // arrowhead parameters 229 private int _arrowheadLength = 0; 230 231 private double _arrowheadRatio = DEFAULT_ARROWHEAD_RATIO; 232 233 private Polygon _arrowhead = null; 234 235 // the list of lines that this point is part of. 236 private List<Line> _lines = new ArrayList<Line>(); 237 238 private int[] _linePattern = null; 239 240 private boolean _floating = false; 241 242 // list of points constrained with this point 243 private List<Constraint> _constraints = null; 244 245 private LinkedList<String> _actions = null; 246 247 private String _link_frameset = null; 248 249 private String _link_template = null; 250 251 private String _fillPattern = null; 252 253 private boolean _visible = true; 254 255 protected Item() { 256 _creationDate = Logger.EasyDateFormat("ddMMMyyyy:HHmm"); 257 } 258 259 /** 260 * Adds an action to this Item. 261 * 262 * @param action 263 * The KMS action language to add to this Item 264 */ 265 public void addAction(String action) { 266 if (action == null || action.equals("")) { 267 return; 268 } 269 270 if (_actions == null) 271 _actions = new LinkedList<String>(); 272 _actions.add(action); 273 } 274 275 public void addAllConnected(List<Item> connected) { 276 if (!connected.contains(this)) 277 connected.add(this); 278 279 for (Line line : getLines()) { 280 if (!connected.contains(line)) 281 line.addAllConnected(connected); 282 } 283 } 284 285 /** 286 * Adds the given Constraint to this Dot 287 * 288 * @param c 289 * The Constraint to set this Dot as a member of. 290 */ 291 public void addConstraint(Constraint c) { 292 if (_constraints == null) 293 _constraints = new ArrayList<Constraint>(); 294 295 // do not add duplicate constraint 296 if (_constraints.contains(c)) 297 return; 298 299 _constraints.add(c); 300 } 301 302 /** 303 * Adds a given line to the list of lines that this Point is an end for. 304 * 305 * @param line 306 * The Line that this Point is an end of. 307 */ 308 public void addLine(Line line) { 309 if (_lines.contains(line)) { 310 return; 311 } 312 313 line.setColor(getColor()); 314 line.setSize(getSize()); 315 line.setLinePattern(getLinePattern()); 316 317 _lines.add(line); 318 } 319 320 /** 321 * Items are sorted by their Y coordinate on the screen. 322 * 323 * @param i 324 * The Item to compare this Item to 325 * @return a negative integer, zero, or a positive integer as this object is 326 * less than, equal to, or greater than the specified object. 327 */ 328 public int compareTo(Item i) { 329 return getY() - i.getY(); 330 } 331 332 /** 333 * Every Item has an area around it defined by a Shape (typically a 334 * rectangle), this method returns true if the given x,y pair lies within 335 * the area and false otherwise. 336 * 337 * @param x 338 * The x coordinate to check 339 * @param y 340 * The y coordinate to check 341 * @return True if the Shape around this Item contains the given x,y pair, 342 * false otherwise. 343 */ 344 public boolean contains(int x, int y) { 345 return getPolygon().contains(x, y); 346 } 347 348 /** 349 * Returns a deep copy of this Item, note: it is up to the receiver to 350 * change the Item ID etc as necessary. 351 * 352 * @return A deep copy of this Item. 353 */ 354 public abstract Item copy(); 355 356 public void delete() { 357 setVisible(false); 358 } 359 360 public boolean equals(Object o) { 361 if (o instanceof Item) { 362 Item i = (Item) o; 363 return i.getID() == getID() 364 && ((i.getParent() == _parent) || (i.getParent() != null && i 365 .getParent().equals(_parent))); 366 367 } else 368 return false; 369 } 370 371 final public String getAbsoluteLink() { 372 String link = getLink(); 373 374 if (link == null) 375 return null; 376 //assert (_parent!= null); 377 if (_parent == null){ 378 //if parent is null it is an item on the message box 379 //so it must already be absolute 380 assert(!FrameIO.isPositiveInteger(link)); 381 return link; 382 } 383 384 // if its a relative link then return absolute 385 if (FrameIO.isPositiveInteger(link)) { 386 return _parent.getFramesetNameAdjusted() 387 + Conversion.getFrameNumber(link); 388 } 389 return link; 390 } 391 392 /** 393 * Returns a list of any action code (KMS action language) that is currently 394 * associated with this Item 395 * 396 * @return A List of action code associated with this Item, or null if none 397 * has been assigned. 398 */ 399 public List<String> getAction() { 400 return _actions; 401 } 402 403 public List<String> getActionCursorEnter() { 404 return _actionCursorEnter; 405 } 406 407 public List<String> getActionCursorLeave() { 408 return _actionCursorLeave; 409 } 410 411 public List<String> getActionEnterFrame() { 412 return _actionEnterFrame; 413 } 414 415 public List<String> getActionLeaveFrame() { 416 return _actionLeaveFrame; 417 }; 418 419 public boolean getActionMark() { 420 return _actionMark; 421 } 422 423 public List<Item> getAllConnected() { 424 List<Item> list = new LinkedList<Item>(); 425 addAllConnected(list); 426 return list; 427 } 428 429 public Area getArea() { 430 return new Area(getPolygon()); 431 } 432 433 public String getArrow() { 434 if (!hasVisibleArrow()) 435 return null; 436 437 String ratio = "" + getArrowheadRatio(); 438 if (ratio.length() - ratio.indexOf(".") > 2) 439 ratio = ratio.substring(0, ratio.indexOf(".") + 3); 440 441 return getArrowheadLength() + " " + ratio; 442 } 443 444 public Polygon getArrowhead() { 445 return _arrowhead; 446 } 447 448 public int getArrowheadLength() { 449 return _arrowheadLength; 450 } 451 452 public double getArrowheadRatio() { 453 return _arrowheadRatio; 454 } 455 456 public Color getBackgroundColor() { 457 return _colorBackground; 458 } 459 460 /** 461 * Returns the Color being used to shade the bottom half of this Item's 462 * border. This can be NULL if no Color is being used 463 * 464 * @return The Color displayed on the bottom\right half of this Item's 465 * border. 466 */ 467 public Color getBottomShadowColor() { 468 return _colorBottomShadow; 469 } 470 471 /** 472 * Returns the height (in pixels) of this Item's surrounding area. 473 * 474 * @return The height (in pixels) of this Item's surrounding area as 475 * returned by getArea(). 476 */ 477 public int getBoundsHeight() { 478 return getPolygon().getBounds().height; 479 } 480 481 /** 482 * Returns the width (in pixels) of this Item's surrounding area. 483 * 484 * @return The width (in pixels) of this Item's surrounding area as returned 485 * by getArea(). 486 */ 487 public int getBoundsWidth() { 488 return getPolygon().getBounds().width; 489 } 490 491 protected Polygon getCircle() { 492 if (_circle == null) { 493 int points = 16; 494 495 double radians = 0.0; 496 int xPoints[] = new int[points]; 497 int yPoints[] = new int[xPoints.length]; 498 499 for (int i = 0; i < xPoints.length; i++) { 500 // circle looks best if these values are not related to gravity 501 xPoints[i] = (int) (3.5 * Math.cos(radians)) + 6;// (2 * 502 // GRAVITY); 503 yPoints[i] = (int) (3.5 * Math.sin(radians)) + 3;// GRAVITY; 504 radians += (2.0 * Math.PI) / xPoints.length; 505 } 506 507 _circle = new Polygon(xPoints, yPoints, xPoints.length); 508 } 509 510 return _circle; 511 } 512 513 protected Polygon getCircleCross() { 514 515 if (_circleCross == null) { 516 _circleCross = new Polygon(); 517 518 Rectangle bounds = getCircle().getBounds(); 519 int x1 = (int) bounds.getMinX(); 520 int x2 = (int) bounds.getMaxX(); 521 int y1 = (int) bounds.getMinY(); 522 int y2 = (int) bounds.getMaxY(); 523 int midX = ((x2 - x1) / 2) + x1; 524 int midY = ((y2 - y1) / 2) + y1; 525 526 _circleCross.addPoint(x1, y1); 527 _circleCross.addPoint(x2, y2); 528 _circleCross.addPoint(midX, midY); 529 _circleCross.addPoint(x1, y2); 530 _circleCross.addPoint(x2, y1); 531 _circleCross.addPoint(midX, midY); 532 } 533 534 return _circleCross; 535 } 536 537 public Color getColor() { 538 return _color; 539 } 540 541 public List<Item> getConnected() { 542 List<Item> conn = new LinkedList<Item>(); 543 conn.add(this); 544 545 conn.addAll(getLines()); 546 return conn; 547 } 548 549 public String getConstraintIDs() { 550 if (_constraints == null || _constraints.size() == 0) 551 return null; 552 553 String cons = ""; 554 555 for (Constraint c : _constraints) 556 cons += c.getID() + " "; 557 558 return cons.trim(); 559 } 560 561 /* 562 * public void setLinkValid(boolean val) { _isValidLink = val; } 563 */ 564 565 /** 566 * Returns a List of any Constraints that this Dot is a memeber of. 567 * 568 * @return a List of Constraints that this Dot is a member of. 569 */ 570 public List<Constraint> getConstraints() { 571 return _constraints; 572 } 573 574 public String getData() { 575 if (_data != null && _data.length() > 0) 576 return _data.toString(); 577 return null; 578 } 579 580 public String getDateCreated() { 581 return _creationDate; 582 } 583 584 public Color getFillColor() { 585 return _colorFill; 586 } 587 588 public String getFillPattern() { 589 return _fillPattern; 590 } 591 592 public String getFirstAction() { 593 if (_actions == null) 594 return null; 595 return _actions.getFirst(); 596 } 597 598 public boolean getHighlight() { 599 return _highlight; 600 } 601 602 public Color getHighlightColor() { 603 return _highlightColor; 604 } 605 606 /** 607 * Returns the ID of this Item, which must be unique for the Frame. 608 * 609 * @return The ID of this Item. 610 */ 611 public int getID() { 612 return _id; 613 } 614 615 /** 616 * Returns the list of IDs of the Lines that this Dot is an end of. 617 * 618 * @return The list of Line IDs that this point is part of. 619 */ 620 public String getLineIDs() { 621 String lineID = null; 622 623 if (_lines.size() > 0) { 624 lineID = "" + _lines.get(0).getID(); 625 626 for (int i = 1; i < _lines.size(); i++) 627 lineID += " " + _lines.get(i).getID(); 628 } 629 630 return lineID; 631 } 632 633 public int[] getLinePattern() { 634 return _linePattern; 635 } 636 637 /** 638 * Returns a list of Lines where this Dot is an end. 639 * 640 * @return A list of the Lines that this Dot is an end for or null if no 641 * Lines have been added. 642 */ 643 public List<Line> getLines() { 644 return _lines; 645 } 646 647 /** 648 * Returns the name of a Frame that this Item links to, or null if this Item 649 * has no link. 650 * 651 * @return The name of a Frame that this Item links to (if any) or null if 652 * this Item does not link to anything. 653 */ 654 public String getLink() { 655 return _link; 656 } 657 658 public String getLinkFrameset() { 659 return _link_frameset; 660 } 661 662 public boolean getLinkMark() { 663 return _linkMark; 664 } 665 666 public String getLinkTemplate() { 667 return _link_template; 668 } 669 670 public Dimension getMaxSize() { 671 return _maxSize; 672 } 673 674 public Point getOffset() { 675 return _offset; 676 } 677 678 public String getOwner() { 679 return _owner; 680 } 681 682 public Color getPaintBackgroundColor() { 683 if (_colorBackground == null) { 684 if (getParent() != null && getParent().getBackgroundColor() != null) 685 return getParent().getBackgroundColor(); 686 687 return DEFAULT_BACKGROUND; 688 } 689 690 return _colorBackground; 691 } 692 693 /** 694 * Returns the foreground Color of this Item. 695 * 696 * @return The Color of this item (foreground) 697 */ 698 public Color getPaintColor() { 699 if (_color == null) { 700 if (getParent() != null) 701 return getParent().getPaintForegroundColor(); 702 703 if (DisplayIO.getCurrentFrame() == null) 704 return DEFAULT_FOREGROUND; 705 706 return DisplayIO.getCurrentFrame().getPaintForegroundColor(); 707 } 708 709 return _color; 710 } 711 712 protected Color getPaintHighlightColor() { 713 if (getParent() != null 714 && getParent().getPaintBackgroundColor() 715 .equals(_highlightColor)) 716 return getParent().getPaintForegroundColor(); 717 718 return _highlightColor; 719 } 720 721 public Frame getParent() { 722 return _parent; 723 } 724 725 /** 726 * Returns the Shape that surrounds this Item representing this Item's 727 * 'gravity'. 728 * 729 * @return The Shape (rectangle) surrounding this Item, which represents 730 * this Items 'gravity'. 731 */ 732 public abstract Polygon getPolygon(); 733 734 public Point getPosition() { 735 return new Point(getX(), getY()); 736 } 737 738 /** 739 * Returns the size of this Item. For Text this is the Font size, for Lines 740 * and Dots this is the thickness. 741 * 742 * @return The size of this Item. 743 */ 744 public abstract int getSize(); 745 746 public float getThickness() { 747 return 0; 748 } 749 750 /** 751 * Returns the Color being used to shade the top half of this Item's border. 752 * This can be NULL if no Color is being used 753 * 754 * @return The Color displayed on the top\left half of this Item's border. 755 */ 756 public Color getTopShadowColor() { 757 return _colorTopShadow; 758 } 759 760 public String getTypeAndID() { 761 return "T " + getID(); 762 } 763 764 public int getWidth() { 765 return 0; 766 } 767 768 /** 769 * Returns the X coordinate of this Item on the screen 770 * 771 * @return The X coordinate of this Item on the screen 772 */ 773 public int getX() { 774 return _x; 775 } 776 777 /** 778 * Returns the Y coordinate of this Item on the screen 779 * 780 * @return The Y coordinate of this Item on the screen 781 */ 782 public int getY() { 783 return _y; 784 } 785 786 protected boolean hasVisibleArrow() { 787 return false; 788 } 789 790 /** 791 * Checks if the given Shape intersects with the Shape around this Item. 792 * Note: Both Shape objects should be rectangles for this to work properly. 793 * 794 * @param s 795 * The Shape to check. 796 * @return True if the two Shapes overlap, False otherwise. 797 */ 798 public boolean intersects(Polygon p) { 799 if (p == null) 800 return false; 801 802 // return p.getBounds().intersects(getArea().getBounds()); 803 Area a = new Area(p); 804 805 a.intersect(this.getArea()); 806 return !a.isEmpty(); 807 } 808 809 /** 810 * Note: Pictures always return False, as they should be drawn even when no 811 * other annotation Items are. 812 * 813 * @return True if this Item is an annotation, False otherwise. 814 */ 815 public abstract boolean isAnnotation(); 816 817 public boolean isFloating() { 818 return _floating; 819 } 820 821 public boolean isFrameName() { 822 if (this.getParent() == null || this.getParent().getFrameNameItem() != this) 823 return false; 824 return true; 825 } 826 827 public boolean isFrameTitle() { 828 if (this.getParent() == null || this.getParent().getTitle() != this) 829 return false; 830 return true; 831 } 832 833 /** 834 * Returns True if this Item is currently highlighted. 835 * 836 * @return True if this Item is currently highlighted on the screen, False 837 * otherwise. 838 */ 839 public boolean isHighlighted() { 840 return _isHighlighted; 841 } 842 843 /** 844 * Tests if the item link is a valid framename, that is, the String must 845 * begin with a character, end with a number with 0 or more letters and 846 * numbers in between. If there is a dot in the framename all the chars 847 * after it must be digits. 848 * 849 * @return True if the given framename is proper, false otherwise. 850 */ 851 public boolean isLinkValid() { 852 if (FrameIO.isPositiveInteger(getLink())) 853 return true; 854 855 if (FrameIO.isValidFrameName(getLink())) 856 return true; 857 return false; 858 } 859 860 public boolean isNear(int x, int y) { 861 862 863 int xLeft = getPolygon().getBounds().x; 864 int yTop = getPolygon().getBounds().y; 865 866 return (x > xLeft - NEAR_DISTANCE && y > yTop - NEAR_DISTANCE 867 && x < xLeft + getBoundsWidth() + NEAR_DISTANCE 868 && y < yTop + getBoundsHeight() + NEAR_DISTANCE); 869 } 870 871 /** 872 * Checks if this item is a frame title. 873 * 874 * @return true if the item is a frame title 875 */ 876 /* 877 * public boolean isTitle() { // check if the title has been assigned if 878 * (getID() >= 0 && this instanceof Text) if (getX() < 200 && getY() < 879 * getSize() + system.io.KMSConversion.Y_ADJUST) return true; return false; } 880 */ 881 882 public boolean isOldTag() { 883 if (this instanceof Text) 884 if (((Text) this).getText().get(0).toLowerCase().equals("@old")) 885 return true; 886 return false; 779 887 } 780 888 … … 797 905 798 906 /** 799 * Sets the maximum coordinates on the screen that this item may occupy. 800 * This is used by Text items to compute word-wrapping lengths. 801 * 802 * @param d 803 * The Maximum size of the Frame containing this Item. 804 */ 805 public void setMaxSize(Dimension d) { 806 if (d != null) { 807 _maxSize = d; 808 updatePolygon(); 809 } 810 } 811 812 public Dimension getMaxSize() { 813 return _maxSize; 814 } 815 816 public Color getColor() { 817 return _color; 818 } 819 820 /** 821 * Returns the foreground Color of this Item. 822 * 823 * @return The Color of this item (foreground) 824 */ 825 public Color getPaintColor() { 826 if (_color == null) { 827 if (getParent() != null) 828 return getParent().getPaintForegroundColor(); 829 830 if (DisplayIO.getCurrentFrame() == null) 831 return DEFAULT_FOREGROUND; 832 833 return DisplayIO.getCurrentFrame().getPaintForegroundColor(); 834 } 835 836 return _color; 837 } 838 839 protected Color getPaintHighlightColor() { 840 if (getParent() != null 841 && getParent().getPaintBackgroundColor() 842 .equals(_highlightColor)) 843 return getParent().getPaintForegroundColor(); 844 845 return _highlightColor; 907 * Displays this item directly on the screen. Note: All Items are 908 * responsible for their own drawing, buffering, etc. 909 * 910 * @param g 911 * The Graphics to draw this Item on. 912 */ 913 public abstract void paint(Graphics2D g); 914 915 /** 916 * This method performs all the actions in an items list. If it contains a 917 * link as well the link is used as the source frame for all acitons. 918 */ 919 public void performActions() { 920 Frame sourceFrame = null; 921 // if a link exists make it the source frame for this action 922 if (getLink() != null) { 923 sourceFrame = FrameUtils.getFrame(getLink()); 924 } 925 // if no link exists or the link is bad then use the 926 // currently displayed frame as the source frame for the 927 // action 928 if (sourceFrame == null) { 929 sourceFrame = DisplayIO.getCurrentFrame(); 930 } 931 932 for (String s : getAction()) { 933 Actions.PerformAction(sourceFrame, this, s); 934 } 935 } 936 937 public void removeAllConstraints() { 938 if (_constraints != null) 939 _constraints.clear(); 940 } 941 942 /** 943 * Clears the list of Lines that this Dot is an end of. Note: This only 944 * clears this Dot's list and does not have any affect on the Lines or other 945 * Dots. 946 */ 947 public void removeAllLines() { 948 _lines.clear(); 949 } 950 951 /** 952 * Removes the given Constraint from the list of constraintss that this Dot 953 * is a part of. 954 * 955 * @param c 956 * The Constraint that this Dot is no longer a part of. 957 */ 958 public void removeConstraint(Constraint c) { 959 _constraints.remove(c); 960 } 961 962 /** 963 * Removes the given Line from the list of lines that this Dot is an end 964 * for. 965 * 966 * @param line 967 * The Line that this Dot is no longer an end of. 968 */ 969 public void removeLine(Line line) { 970 _lines.remove(line); 971 } 972 973 public void run() { 974 try { 975 AgentStats.reset(); 976 FrameGraphics 977 .DisplayMessage("Running SimpleProgram...", Color.BLUE); 978 Simple.RunFrameAndReportError(this, new Context()); 979 Simple.ProgramFinished(); 980 FrameGraphics.DisplayMessage(AgentStats.getStats(), GREEN); 981 } catch (ConcurrentModificationException ce) { 982 ce.printStackTrace(); 983 } catch (Exception e) { 984 FrameGraphics.LinkedErrorMessage(e.getMessage()); 985 Simple.ProgramFinished(); 986 } 987 } 988 989 /** 990 * Check if it has a relative link if so make it absolute. 991 * 992 */ 993 public void setAbsoluteLink() { 994 if (_link == null) 995 return; 996 // Check if all the characters are digits and hence it is a relative 997 // link 998 for (int i = 0; i < _link.length(); i++) { 999 if (!Character.isDigit(_link.charAt(i))) 1000 return; 1001 } 1002 1003 // Make it an absolute link 1004 String framesetName; 1005 1006 if (_parent == null) 1007 framesetName = DisplayIO.getCurrentFrame() 1008 .getFramesetNameAdjusted(); 1009 else 1010 framesetName = _parent.getFramesetNameAdjusted(); 1011 1012 _link = framesetName + _link; 1013 } 1014 1015 /** 1016 * Sets any action code (KMS action language) that should be associated with 1017 * this Item Each entry in the list is one line of code 1018 * 1019 * @param actions 1020 * The lines of code to associate with this Item 1021 */ 1022 public void setAction(List<String> actions) { 1023 if (actions == null || actions.size() == 0) 1024 _actions = null; 1025 else 1026 _actions = new LinkedList<String>(actions); 1027 } 1028 1029 public void setActionCursorEnter(List<String> enter) { 1030 _actionCursorEnter = enter; 1031 } 1032 1033 public void setActionCursorLeave(List<String> leave) { 1034 _actionCursorLeave = leave; 1035 } 1036 1037 public void setActionEnterFrame(List<String> enter) { 1038 _actionEnterFrame = enter; 1039 } 1040 1041 public void setActionLeaveFrame(List<String> leave) { 1042 _actionLeaveFrame = leave; 1043 } 1044 1045 public void setActionMark(boolean val) { 1046 _actionMark = val; 1047 } 1048 1049 /** 1050 * Sets whether this Item is an Annotation. 1051 * 1052 * @param val 1053 * True if this Item is an Annotation, False otherwise. 1054 */ 1055 public abstract void setAnnotation(boolean val); 1056 1057 /** 1058 * Used to set this Line as an Arrow. If length and ratio are 0, no arrow is 1059 * shown. 1060 * 1061 * @param length 1062 * The how far down the shaft of the line the arrowhead should 1063 * come. 1064 * @param ratio 1065 * The ratio of the arrow's length to its width. 1066 */ 1067 public void setArrow(int length, double ratio) { 1068 _arrowheadLength = length; 1069 _arrowheadRatio = ratio; 1070 updateArrowPolygon(); 1071 } 1072 1073 public void setArrowhead(Polygon arrow) { 1074 _arrowhead = arrow; 1075 } 1076 1077 public void setArrowheadLength(int length) { 1078 _arrowheadLength = length; 1079 updateArrowPolygon(); 1080 } 1081 1082 public void setArrowheadRatio(double ratio) { 1083 _arrowheadRatio = ratio; 1084 updateArrowPolygon(); 1085 } 1086 1087 public void setBackgroundColor(Color c) { 1088 _colorBackground = c; 1089 } 1090 1091 /** 1092 * Sets the Color to use on the bottom and right sections of this Item's 1093 * border. If top is NULL, then the Item's background Color will be used. 1094 * 1095 * @param top 1096 * The Color to display in the bottom and right sections of this 1097 * Item's border. 1098 */ 1099 public void setBottomShadowColor(Color bottom) { 1100 _colorBottomShadow = bottom; 846 1101 } 847 1102 … … 859 1114 } 860 1115 861 /** 862 * Returns the Color being used to shade the top half of this Item's border. 863 * This can be NULL if no Color is being used 864 * 865 * @return The Color displayed on the top\left half of this Item's border. 866 */ 867 public Color getTopShadowColor() { 868 return _colorTopShadow; 869 } 870 871 /** 872 * Sets the Color to use on the top and left sections of this Item's border. 873 * If top is NULL, then the Item's background Color will be used. 874 * 875 * @param top 876 * The Color to display in the top and left sections of this 877 * Item's border. 878 */ 879 public void setTopShadowColor(Color top) { 880 _colorTopShadow = top; 881 } 882 883 /** 884 * Returns the Color being used to shade the bottom half of this Item's 885 * border. This can be NULL if no Color is being used 886 * 887 * @return The Color displayed on the bottom\right half of this Item's 888 * border. 889 */ 890 public Color getBottomShadowColor() { 891 return _colorBottomShadow; 892 } 893 894 /** 895 * Sets the Color to use on the bottom and right sections of this Item's 896 * border. If top is NULL, then the Item's background Color will be used. 897 * 898 * @param top 899 * The Color to display in the bottom and right sections of this 900 * Item's border. 901 */ 902 public void setBottomShadowColor(Color bottom) { 903 _colorBottomShadow = bottom; 904 } 905 906 protected Polygon getCircle() { 907 if (_circle == null) { 908 int points = 16; 909 910 double radians = 0.0; 911 int xPoints[] = new int[points]; 912 int yPoints[] = new int[xPoints.length]; 913 914 for (int i = 0; i < xPoints.length; i++) { 915 // circle looks best if these values are not related to gravity 916 xPoints[i] = (int) (3.5 * Math.cos(radians)) + 6;// (2 * 917 // GRAVITY); 918 yPoints[i] = (int) (3.5 * Math.sin(radians)) + 3;// GRAVITY; 919 radians += (2.0 * Math.PI) / xPoints.length; 920 } 921 922 _circle = new Polygon(xPoints, yPoints, xPoints.length); 923 } 924 925 return _circle; 926 } 927 928 protected Polygon getCircleCross() { 929 930 if (_circleCross == null) { 931 _circleCross = new Polygon(); 932 933 Rectangle bounds = getCircle().getBounds(); 934 int x1 = (int) bounds.getMinX(); 935 int x2 = (int) bounds.getMaxX(); 936 int y1 = (int) bounds.getMinY(); 937 int y2 = (int) bounds.getMaxY(); 938 int midX = ((x2 - x1) / 2) + x1; 939 int midY = ((y2 - y1) / 2) + y1; 940 941 _circleCross.addPoint(x1, y1); 942 _circleCross.addPoint(x2, y2); 943 _circleCross.addPoint(midX, midY); 944 _circleCross.addPoint(x1, y2); 945 _circleCross.addPoint(x2, y1); 946 _circleCross.addPoint(midX, midY); 947 } 948 949 return _circleCross; 950 } 951 952 public void setFillColor(Color c) { 953 _colorFill = c; 954 955 for (Line line : _lines) { 956 Item other = line.getOppositeEnd(this); 957 if (other.getFillColor() != c) 958 other.setFillColor(c); 959 } 960 } 961 962 public void setBackgroundColor(Color c) { 963 _colorBackground = c; 964 } 965 966 public Color getBackgroundColor() { 967 return _colorBackground; 968 } 969 970 public Color getPaintBackgroundColor() { 971 if (_colorBackground == null) { 972 if (getParent() != null && getParent().getBackgroundColor() != null) 973 return getParent().getBackgroundColor(); 974 975 return DEFAULT_BACKGROUND; 976 } 977 978 return _colorBackground; 979 } 980 981 public Color getFillColor() { 982 return _colorFill; 983 } 984 985 /** 986 * Returns the size of this Item. For Text this is the Font size, for Lines 987 * and Dots this is the thickness. 988 * 989 * @return The size of this Item. 990 */ 991 public abstract int getSize(); 992 993 /** 994 * Sets the size of this Item. For Text this is the Font size. For Lines and 995 * Dots this is the thickness. 996 */ 997 public abstract void setSize(int size); 998 999 /** 1000 * Sets whether this Item is an Annotation. 1001 * 1002 * @param val 1003 * True if this Item is an Annotation, False otherwise. 1004 */ 1005 public abstract void setAnnotation(boolean val); 1006 1007 /** 1008 * Note: Pictures always return False, as they should be drawn even when no 1009 * other annotation Items are. 1010 * 1011 * @return True if this Item is an annotation, False otherwise. 1012 */ 1013 public abstract boolean isAnnotation(); 1014 1015 public List<Item> getConnected() { 1016 List<Item> conn = new LinkedList<Item>(); 1017 conn.add(this); 1018 1019 conn.addAll(getLines()); 1020 return conn; 1021 } 1022 1023 public List<Item> getAllConnected() { 1024 List<Item> list = new LinkedList<Item>(); 1025 addAllConnected(list); 1026 return list; 1027 } 1028 1029 public void addAllConnected(List<Item> connected) { 1030 if (!connected.contains(this)) 1031 connected.add(this); 1032 1033 for (Line line : getLines()) { 1034 if (!connected.contains(line)) 1035 line.addAllConnected(connected); 1036 } 1037 } 1038 1039 public void setOffset(Point p) { 1040 _offset.setLocation(p); 1041 } 1042 1043 public void setOffset(int x, int y) { 1044 _offset.setLocation(x, y); 1045 } 1046 1047 public Point getOffset() { 1048 return _offset; 1049 } 1050 1051 public void setParent(Frame frame) { 1052 _parent = frame; 1053 } 1054 1055 public Frame getParent() { 1056 return _parent; 1057 } 1058 1059 public void setActionMark(boolean val) { 1060 _actionMark = val; 1061 } 1062 1063 public boolean getActionMark() { 1064 return _actionMark; 1065 } 1066 1067 public void setLinkMark(boolean val) { 1068 _linkMark = val; 1069 } 1070 1071 public boolean getLinkMark() { 1072 return _linkMark; 1073 } 1074 1075 public void setOwner(String own) { 1076 _owner = own; 1077 } 1078 1079 public String getOwner() { 1080 return _owner; 1081 } 1082 1083 public void setHighlight(boolean val) { 1084 _highlight = val; 1085 } 1086 1087 public boolean getHighlight() { 1088 return _highlight; 1089 } 1090 1091 public String getData() { 1092 if (_data != null && _data.length() > 0) 1093 return _data.toString(); 1094 return null; 1116 public void setConstraintIDs(String IDs) { 1117 } 1118 1119 public void setConstraints(List<Constraint> constraints) { 1120 _constraints = constraints; 1095 1121 } 1096 1122 … … 1102 1128 } 1103 1129 1104 public List<String> getActionCursorEnter() { 1105 return _actionCursorEnter; 1106 } 1107 1108 public void setActionCursorEnter(List<String> enter) { 1109 _actionCursorEnter = enter; 1110 } 1111 1112 public List<String> getActionCursorLeave() { 1113 return _actionCursorLeave; 1114 } 1115 1116 public void setActionCursorLeave(List<String> leave) { 1117 _actionCursorLeave = leave; 1118 } 1119 1120 public List<String> getActionEnterFrame() { 1121 return _actionEnterFrame; 1122 } 1123 1124 public void setActionEnterFrame(List<String> enter) { 1125 _actionEnterFrame = enter; 1126 } 1127 1128 public List<String> getActionLeaveFrame() { 1129 return _actionLeaveFrame; 1130 } 1131 1132 public void setActionLeaveFrame(List<String> leave) { 1133 _actionLeaveFrame = leave; 1130 /** 1131 * Sets the created date of this Frame to the given String. 1132 * 1133 * @param date 1134 * The date to use for this Frame. 1135 */ 1136 public void setDateCreated(String date) { 1137 _creationDate = date; 1138 } 1139 1140 public void setFillColor(Color c) { 1141 _colorFill = c; 1142 1143 for (Line line : _lines) { 1144 Item other = line.getOppositeEnd(this); 1145 if (other.getFillColor() != c) 1146 other.setFillColor(c); 1147 } 1148 } 1149 1150 public void setFilledHighlight(boolean value) { 1134 1151 } 1135 1152 … … 1138 1155 } 1139 1156 1140 public String getFillPattern() { 1141 return _fillPattern; 1142 } 1143 1144 /** 1145 * Used to set this Line as an Arrow. If length and ratio are 0, no arrow is 1146 * shown. 1147 * 1148 * @param length 1149 * The how far down the shaft of the line the arrowhead should 1150 * come. 1151 * @param ratio 1152 * The ratio of the arrow's length to its width. 1153 */ 1154 public void setArrow(int length, double ratio) { 1155 _arrowheadLength = length; 1156 _arrowheadRatio = ratio; 1157 updateArrowPolygon(); 1158 } 1159 1160 public int getArrowheadLength() { 1161 return _arrowheadLength; 1162 } 1163 1164 public double getArrowheadRatio() { 1165 return _arrowheadRatio; 1166 } 1167 1168 public void setArrowheadLength(int length) { 1169 _arrowheadLength = length; 1170 updateArrowPolygon(); 1171 } 1172 1173 public void setArrowheadRatio(double ratio) { 1174 _arrowheadRatio = ratio; 1175 updateArrowPolygon(); 1176 } 1177 1157 public void setFloating(boolean val) { 1158 _floating = val; 1159 } 1160 1161 public void setHighlight(boolean val) { 1162 _highlight = val; 1163 } 1164 1165 /** 1166 * Sets the ID of this Item to the given Integer. Note: Items with ID's < 0 1167 * are not saved 1168 * 1169 * @param newID 1170 * The new ID to assign this Item. 1171 */ 1172 public void setID(int newID) { 1173 _id = newID; 1174 } 1175 1176 /** 1177 * Sets the list of lines that this point is part of (may be set to null). 1178 * 1179 * @param lineID 1180 * A String of line ID numbers separated by spaces. 1181 */ 1182 public void setLineIDs(String lineID) { 1183 } 1184 1185 public void setLinePattern(int[] pattern) { 1186 _linePattern = pattern; 1187 1188 for (Line line : getLines()) 1189 line.setLinePattern(pattern); 1190 } 1191 1192 public void setLines(List<Line> lines) { 1193 _lines = lines; 1194 1195 for (Line line : lines) 1196 line.setLinePattern(getLinePattern()); 1197 } 1198 1199 /** 1200 * Links this item to the given Frame, this may be set to null to remove a 1201 * link. 1202 * 1203 * @param frameName 1204 * The name of the Frame to link this item to. 1205 */ 1206 public void setLink(String frameName) { 1207 _link = frameName; 1208 } 1209 1210 public void setLinkFrameset(String frameset) { 1211 _link_frameset = frameset; 1212 } 1213 1214 public void setLinkMark(boolean val) { 1215 _linkMark = val; 1216 } 1217 1218 public void setLinkTemplate(String template) { 1219 _link_template = template; 1220 } 1221 1222 /** 1223 * Sets the maximum coordinates on the screen that this item may occupy. 1224 * This is used by Text items to compute word-wrapping lengths. 1225 * 1226 * @param d 1227 * The Maximum size of the Frame containing this Item. 1228 */ 1229 public void setMaxSize(Dimension d) { 1230 if (d != null) { 1231 _maxSize = d; 1232 updatePolygon(); 1233 } 1234 } 1235 1236 public void setOffset(int x, int y) { 1237 _offset.setLocation(x, y); 1238 } 1239 1240 public void setOffset(Point p) { 1241 _offset.setLocation(p); 1242 } 1243 1244 public void setOwner(String own) { 1245 _owner = own; 1246 } 1247 1248 public void setParent(Frame frame) { 1249 _parent = frame; 1250 } 1251 1252 /** 1253 * Sets the position of this item on the screen 1254 * 1255 * @param x 1256 * The new X coordinate 1257 * @param y 1258 * The new Y coordinate 1259 */ 1260 public void setPosition(int x, int y) { 1261 _x = x; 1262 _y = y; 1263 1264 updatePolygon(); 1265 1266 // update the position of any dots that are constrained by this one 1267 if (_constraints != null) { 1268 for (Constraint c : _constraints) { 1269 Item other = c.getOppositeEnd(this); 1270 1271 // only set the position if the other dot is still fixed to the 1272 // frame 1273 if (!other.isFloating()) { 1274 if (c.getConstraintType() == Constraint.HORIZONTAL 1275 && other.getY() != getY()) 1276 other.setY(getY()); 1277 1278 if (c.getConstraintType() == Constraint.VERTICAL 1279 && other.getX() != getX()) 1280 other.setX(getX()); 1281 } 1282 } 1283 } 1284 1285 for (Line line : getLines()) 1286 line.updatePolygon(); 1287 } 1288 1289 public void setPosition(Point position) { 1290 setPosition(position.x, position.y); 1291 } 1292 1293 public void setRelativeLink() { 1294 if (_link == null) 1295 return; 1296 assert (_parent != null); 1297 // Check if the link is for the current frameset 1298 if (_parent.getFramesetName().equalsIgnoreCase( 1299 Conversion.getFrameset(_link))) { 1300 _link = "" + Conversion.getFrameNumber(_link); 1301 } 1302 } 1303 1304 /** 1305 * Sets the size of this Item. For Text this is the Font size. For Lines and 1306 * Dots this is the thickness. 1307 */ 1308 public abstract void setSize(int size); 1309 1310 public void setThickness(float thick) throws UnsupportedOperationException { 1311 throw new UnsupportedOperationException( 1312 "Item type does not support thickness attribute!"); 1313 } 1314 1315 /** 1316 * Sets the Color to use on the top and left sections of this Item's border. 1317 * If top is NULL, then the Item's background Color will be used. 1318 * 1319 * @param top 1320 * The Color to display in the top and left sections of this 1321 * Item's border. 1322 */ 1323 public void setTopShadowColor(Color top) { 1324 _colorTopShadow = top; 1325 } 1326 1327 public void setWidth(int width) throws UnsupportedOperationException { 1328 throw new UnsupportedOperationException( 1329 "Item type does not support width attribute!"); 1330 } 1331 1332 /** 1333 * Sets the position of this Item on the X axis 1334 * 1335 * @param newX 1336 * The position on the X axis to assign to this Item 1337 */ 1338 public void setX(int newX) { 1339 setPosition(newX, getY()); 1340 } 1341 1342 /** 1343 * Sets the position of this Item on the Y axis 1344 * 1345 * @param newY 1346 * The position on the Y axis to assign to this Item 1347 */ 1348 public void setY(int newY) { 1349 setPosition(getX(), newY); 1350 } 1351 1352 public int showDepressedHighlight(boolean val) { 1353 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS; 1354 return showHighlight(val, DEPRESSED_HIGHLIGHT); 1355 } 1356 1357 public int showDisconnectHighlight(boolean val) { 1358 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS; 1359 return showHighlight(val, DISCONNECT_HIGHLIGHT); 1360 } 1361 1362 /** 1363 * Paints any highlighting of this Item. This may include changing the 1364 * thickness (lines) or painting a box around the item (Text, Images). If 1365 * val is True then the Graphics Color is changed to the highlight Color, if 1366 * False then the Graphics Color is left unchanged (for clearing of 1367 * highlighting). 1368 * 1369 * @param val 1370 * True if this Item should be highlighted, false if the 1371 * highlighting is being cleared.\ 1372 * @return The desired mouse cursor when this Item is highlighted (negative 1373 * means no change) 1374 */ 1375 public int showHighlight(boolean val) { 1376 _highlightThickness = DEFAULT_HIGHLIGHT_THICKNESS; 1377 return showHighlight(val, DEFAULT_HIGHLIGHT); 1378 } 1379 1380 public int showHighlight(boolean val, Color c) { 1381 _isHighlighted = val; 1382 if (c != null) 1383 _highlightColor = c; 1384 else 1385 _highlightColor = DEFAULT_HIGHLIGHT; 1386 1387 return Item.UNCHANGED_CURSOR; 1388 } 1178 1389 private void updateArrowPolygon() { 1179 1390 if (getArrowheadLength() < 0 || getArrowheadRatio() < 0) … … 1193 1404 } 1194 1405 } 1195 1196 protected boolean hasVisibleArrow() { 1197 return false; 1198 } 1199 1200 public String getArrow() { 1201 if (!hasVisibleArrow()) 1202 return null; 1203 1204 String ratio = "" + getArrowheadRatio(); 1205 if (ratio.length() - ratio.indexOf(".") > 2) 1206 ratio = ratio.substring(0, ratio.indexOf(".") + 3); 1207 1208 return getArrowheadLength() + " " + ratio; 1209 } 1210 1211 public Polygon getArrowhead() { 1212 return _arrowhead; 1213 } 1214 1215 public void setArrowhead(Polygon arrow) { 1216 _arrowhead = arrow; 1217 } 1218 1219 /** 1220 * This method performs all the actions in an items list. If it contains a 1221 * link as well the link is used as the source frame for all acitons. 1222 */ 1223 public void performActions() { 1224 Frame sourceFrame = null; 1225 // if a link exists make it the source frame for this action 1226 if (getLink() != null) { 1227 sourceFrame = FrameUtils.getFrame(getLink()); 1228 } 1229 // if no link exists or the link is bad then use the 1230 // currently displayed frame as the source frame for the 1231 // action 1232 if (sourceFrame == null) { 1233 sourceFrame = DisplayIO.getCurrentFrame(); 1234 } 1235 1236 for (String s : getAction()) { 1237 Actions.PerformAction(sourceFrame, this, s); 1238 } 1239 } 1240 1241 /** 1242 * Checks if this item is a frame title. 1243 * 1244 * @return true if the item is a frame title 1245 */ 1246 /* 1247 * public boolean isTitle() { // check if the title has been assigned if 1248 * (getID() >= 0 && this instanceof Text) if (getX() < 200 && getY() < 1249 * getSize() + system.io.KMSConversion.Y_ADJUST) return true; return false; } 1250 */ 1251 1252 public boolean isOldTag() { 1253 if (this instanceof Text) 1254 if (((Text) this).getText().get(0).toLowerCase().equals("@old")) 1255 return true; 1256 return false; 1257 } 1258 1259 public boolean isFrameName() { 1260 if (this.getParent() == null || this.getParent().getName() != this) 1261 return false; 1262 return true; 1263 } 1264 1265 public boolean isFrameTitle() { 1266 if (this.getParent() == null || this.getParent().getTitle() != this) 1267 return false; 1268 return true; 1269 } 1270 1271 /** 1272 * Sets the created date of this Frame to the given String. 1273 * 1274 * @param date 1275 * The date to use for this Frame. 1276 */ 1277 public void setDateCreated(String date) { 1278 _creationDate = date; 1279 } 1280 1281 public String getDateCreated() { 1282 return _creationDate; 1283 } 1284 1285 public float getThickness() { 1286 return 0; 1287 } 1288 1289 public void setThickness(float thick) throws UnsupportedOperationException { 1290 throw new UnsupportedOperationException( 1291 "Item type does not support thickness attribute!"); 1292 } 1293 1294 public void setWidth(int width) throws UnsupportedOperationException { 1295 throw new UnsupportedOperationException( 1296 "Item type does not support width attribute!"); 1297 } 1298 1299 public int getWidth() { 1300 return 0; 1301 } 1302 1303 public void run() { 1304 try { 1305 AgentStats.reset(); 1306 FrameGraphics 1307 .DisplayMessage("Running SimpleProgram...", Color.BLUE); 1308 Simple.RunFrameAndReportError(this, new Context()); 1309 Simple.ProgramFinished(); 1310 FrameGraphics.DisplayMessage(AgentStats.getStats(), GREEN); 1311 } catch (ConcurrentModificationException ce) { 1312 ce.printStackTrace(); 1313 } catch (Exception e) { 1314 FrameGraphics.LinkedErrorMessage(e.getMessage()); 1315 Simple.ProgramFinished(); 1316 } 1317 } 1318 1319 public String getTypeAndID() { 1320 return "T " + getID(); 1321 } 1322 1323 /** 1324 * Check if it has a relative link if so make it absolute. 1325 * 1326 */ 1327 public void setAbsoluteLink() { 1328 if (_link == null) 1329 return; 1330 // Check if all the characters are digits and hence it is a relative 1331 // link 1332 for (int i = 0; i < _link.length(); i++) { 1333 if (!Character.isDigit(_link.charAt(i))) 1334 return; 1335 } 1336 1337 // Make it an absolute link 1338 String framesetName; 1339 1340 if (_parent == null) 1341 framesetName = DisplayIO.getCurrentFrame() 1342 .getFramesetNameAdjusted(); 1343 else 1344 framesetName = _parent.getFramesetNameAdjusted(); 1345 1346 _link = framesetName + _link; 1347 } 1348 1349 public void setRelativeLink() { 1350 if (_link == null) 1351 return; 1352 assert (_parent != null); 1353 // Check if the link is for the current frameset 1354 if (_parent.getFramesetName().equalsIgnoreCase( 1355 Conversion.getFrameset(_link))) { 1356 _link = "" + Conversion.getFrameNumber(_link); 1357 } 1406 1407 protected abstract void updatePolygon(); 1408 1409 public void setVisible(boolean state) { 1410 this._visible = state; 1411 } 1412 1413 public boolean isVisible() { 1414 return _visible; 1358 1415 } 1359 1416 } -
trunk/src/org/expeditee/items/ItemUtils.java
r4 r7 16 16 17 17 import org.expeditee.gui.DisplayIO; 18 import org.expeditee.gui.Frame; 18 19 19 20 //Static methods that provide functions for the objects\ … … 402 403 */ 403 404 public static List<Item> CopyItems(List<Item> toCopy) { 405 return CopyItems(toCopy, false); 406 } 407 public static List<Item> CopyItems(List<Item> toCopy, boolean extrude) { 404 408 // The copies to return 405 409 List<Item> copies = new ArrayList<Item>(); … … 413 417 414 418 List<Item> seen = new ArrayList<Item>(); 415 419 416 420 for (Item i : toCopy) { 417 421 // lines are recreated later … … 452 456 // if this is the frame name, make sure the frame is saved (in 453 457 // case it is a TDFC frame) 454 if (i == i.getParent().get Name())458 if (i == i.getParent().getFrameNameItem()) 455 459 i.getParent().setChanged(true); 456 460 … … 484 488 copy.removeAllLines(); 485 489 copy.removeAllConstraints(); 486 490 487 491 // replace all other instances with the copy 488 492 ReplaceAll(lineEnds, i, copy); 489 493 ReplaceAll(vConst, i, copy); 490 494 ReplaceAll(hConst, i, copy); 495 496 if (extrude) { 497 Frame frame = DisplayIO.getCurrentFrame(); 498 Line newLine = new Line(i,copy, frame.getNextItemID()); 499 frame.addItem(newLine); 500 copies.add(newLine); 501 } 491 502 492 503 seen.add(i); … … 598 609 //copy.setFloating(true); 599 610 origEnd.setArrowheadLength(0); 600 copy.setArrowheadLength(0);611 //copy.setArrowheadLength(0); 601 612 602 613 List<Item> toReturn = new LinkedList<Item>(); … … 633 644 return; 634 645 646 //TODO optimise this code!! 635 647 // iterate through all the dots 636 648 for (Dot searchFor : dots) { -
trunk/src/org/expeditee/items/Line.java
r4 r7 14 14 import java.util.List; 15 15 16 import org.expeditee.gui.DisplayIO; 17 import org.expeditee.gui.Frame; 18 16 19 /** 17 20 * Implements a line that is drawn on the screen. A line is represented as two … … 24 27 25 28 private static final int AUTO_ARROWHEAD_LENGTH = -1; 26 27 private static final double DEFAULT_ARROWHEAD_RATIO = 0.5;28 29 29 30 private static final int ARROW_HEAD_TO_LENGTH_RATIO = 8; … … 81 82 // initialise the line size 82 83 float thick; 83 if (_start instanceof Dot) 84 85 if (_start instanceof Dot && _end instanceof Dot) 86 thick = (((Dot) _start).getThickness() + ((Dot) _end) 87 .getThickness()) / 2.0f; 88 else if (_start instanceof Dot) 84 89 thick = ((Dot) _start).getThickness(); 90 else if (_end instanceof Dot) 91 thick = ((Dot) _end).getThickness(); 85 92 else 86 thick = _start.getSize(); 87 88 if (_end instanceof Dot) 89 thick += ((Dot) _end).getThickness(); 90 else 91 thick += _end.getSize(); 92 93 setLinePattern(_start.getLinePattern()); 94 // Set the thickness to be half the value of the end points 95 setThickness(thick / 2.0f); 93 thick = 1; 94 95 setThickness(thick); 96 96 } 97 97 … … 300 300 BasicStroke.JOIN_MITER)); 301 301 302 if (_start.isFloating() && !_end.isFloating()) { 303 paintArrow(g, _start, _startOffset, _endOffset); 304 } else if (!_start.isFloating() && _end.isFloating()) { 305 paintArrow(g, _end, _endOffset, _startOffset); 306 } else { 307 paintArrow(g, _start, _startOffset, _endOffset); 308 paintArrow(g, _end, _endOffset, _startOffset); 309 } 302 paintArrow(g, _start, _startOffset, _endOffset); 303 paintArrow(g, _end, _endOffset, _startOffset); 310 304 311 305 g.setStroke(_lineStroke); … … 326 320 if (showLineHighlight() && isHighlighted()) { 327 321 g.setColor(getHighlightColor()); 322 g.setStroke(new BasicStroke(MINIMUM_THICKNESS, 323 BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER)); 328 324 ((Graphics2D) g).draw(this.getArea()); 329 325 } … … 453 449 } 454 450 451 public Item getEndPointToDisconnect(int x, int y) { 452 Item start = getStartItem(); 453 Item end = getEndItem(); 454 int deltaX = start.getX() - end.getX(); 455 int deltaY = start.getY() - end.getY(); 456 int lineLength = (int) Math.sqrt(deltaX * deltaX + deltaY * deltaY); 457 458 int startX = start.getX() - x; 459 int endX = end.getX() - x; 460 int startY = start.getY() - y; 461 int endY = end.getY() - y; 462 463 int distStart = (int) Math.sqrt(startX * startX + startY * startY); 464 int distEnd = (int) Math.sqrt(endX * endX + endY * endY); 465 466 final double THRESHHOLD = Math.min(0.2 * lineLength, 25.0); 467 468 if (distStart < THRESHHOLD) { 469 return start; 470 } else if (distEnd < THRESHHOLD) { 471 return end; 472 } 473 474 return null; 475 } 476 455 477 @Override 456 478 public int showHighlight(boolean val) { … … 547 569 } 548 570 } 549 571 550 572 public void autoArrowheadLength() { 551 573 _end.setArrowheadLength(AUTO_ARROWHEAD_LENGTH); 552 _end.setArrowheadRatio(DEFAULT_ARROWHEAD_RATIO);553 574 } 554 575 … … 570 591 } 571 592 593 /** 594 * This method toggles the arrow on the floating end point of a line. If the 595 * line does not have one floating end and one fixed end this method does 596 * nothing. 597 * 598 */ 572 599 public void toggleArrow() { 573 600 Item arrow; … … 728 755 } 729 756 730 @Override 731 public Item merge(Item merger, int mouseX, int mouseY) { 732 if (!(merger instanceof Dot)) 733 return merger; 734 757 public void showVirtualSpot(int mouseX, int mouseY) { 758 Dot spot = new Dot(mouseX, mouseY, -1); 759 spot.setThickness(Math.max(this.getThickness(), 5)); 760 if (this.getColor() != Color.RED) 761 spot.setColor(Color.RED); 762 else 763 spot.setColor(Color.BLUE); 764 765 // calculate nearest point on line from spot 766 double slope1; 767 double slope2; 768 double x, y; 769 770 slope1 = (_start.getY() - _end.getY() * 1.0) 771 / (_start.getX() - _end.getX()); 772 slope2 = -1 / slope1; 773 774 // if the line is horizontal 775 if (slope1 == 0) { 776 x = spot.getX(); 777 y = _start.getY(); 778 // if the line is vertical 779 } else if (slope2 == 0) { 780 x = _start.getX(); 781 y = spot.getY(); 782 // otherwise, the line is sloped 783 } else { 784 x = (-1 * slope2 * spot.getX() + spot.getY() - _start.getY() + slope1 785 * _start.getX()) 786 / (slope1 - slope2); 787 y = slope1 * (x - _start.getX()) + _start.getY(); 788 } 789 790 // position spot on the line 791 spot.setPosition((int) x, (int) y); 792 _virtualSpot = spot; 793 } 794 795 public Item forceMerge(Item merger, int mouseX, int mouseY) { 735 796 Dot spot = (Dot) merger; 736 737 // dots with multiple lines cannot be attached, nor can dots with no738 // lines739 if (spot.getLines().size() != 1)740 return merger;741 742 // lines that are in 'connected' mode, also cannot be attached743 if (spot.getLines().get(0).getOppositeEnd(spot).isFloating())744 return merger;745 797 746 798 if (spot.getConstraints() != null) … … 783 835 Line temp = copy(); 784 836 785 temp.setID(-1); 837 Frame currentFrame = DisplayIO.getCurrentFrame(); 838 temp.setID(currentFrame.getNextItemID()); 786 839 temp.setEndItem(_end); 787 840 temp.setStartItem(spot); 841 currentFrame.addItem(temp); 788 842 789 843 setEndItem(spot); … … 793 847 794 848 return spot; 849 } 850 851 @Override 852 public Item merge(Item merger, int mouseX, int mouseY) { 853 if (!(merger instanceof Dot)) 854 return merger; 855 856 Dot spot = (Dot) merger; 857 858 // dots with multiple lines cannot be attached, nor can dots with no 859 // lines 860 if (spot.getLines().size() != 1) 861 return merger; 862 863 // lines that are in 'connected' mode, also cannot be attached 864 if (spot.getLines().get(0).getOppositeEnd(spot).isFloating()) 865 return merger; 866 867 return forceMerge(merger, mouseX, mouseY); 795 868 } 796 869 … … 840 913 public int getLineType() { 841 914 return 1; 915 } 916 917 @Override 918 public boolean isFloating() { 919 return _start.isFloating() && _end.isFloating(); 842 920 } 843 921 … … 895 973 } 896 974 } 975 976 public void setFilledHighlight(boolean value) { 977 _start.setFilledHighlight(value); 978 _end.setFilledHighlight(value); 979 } 980 981 @Override 982 public void delete() { 983 super.delete(); 984 985 _start.removeLine(this); 986 _end.removeLine(this); 987 988 if (_start.getLines().size() == 0) 989 _start.delete(); 990 if (_end.getLines().size() == 0) 991 _end.delete(); 992 } 897 993 } -
trunk/src/org/expeditee/items/Picture.java
r4 r7 106 106 if (path == null && source.getLink() != null) { 107 107 String link = source.getLink(); 108 if (FrameIO.isPositiveInteger(link)) {108 if (FrameIO.isPositiveInteger(link)) { 109 109 link = source.getParent().getFramesetNameAdjusted() + link; 110 110 } … … 113 113 _image = frame.getBuffer(); 114 114 _isFrame = true; 115 116 115 } else { 117 116 … … 427 426 Picture p; 428 427 429 if (_isFrame) {428 if (_isFrame) { 430 429 p = ItemUtils.CreateFramePicture((Text) _source.copy(), 431 430 _imageObserver); 432 } else431 } else 433 432 p = ItemUtils.CreatePicture((Text) _source.copy(), _imageObserver); 434 433 … … 547 546 } 548 547 548 public void refresh() { 549 if (_isFrame) { 550 String link = _source.getLink(); 551 if (FrameIO.isPositiveInteger(link)) { 552 link = _source.getParent().getFramesetNameAdjusted() + link; 553 } 554 Frame frame = FrameIO.LoadFrame(link); 555 FrameGraphics.UpdateBuffer(frame, false); 556 _image = frame.getBuffer(); 557 } 558 } 559 549 560 } -
trunk/src/org/expeditee/items/Text.java
r4 r7 33 33 public class Text extends Item { 34 34 35 private String[] _processedCode = null; 36 37 public String[] getProcessedCode() { 38 return _processedCode; 39 } 40 41 public void setProcessedCode(String[] tokens) { 42 _processedCode = tokens; 43 } 44 35 45 public static final String FRAME_NAME_SEPARATOR = " on frame "; 36 46 … … 231 241 232 242 } 233 243 234 244 public void removeEndText(String textToRemove) { 235 245 int length = _text.length(); … … 253 263 rebuild(false); 254 264 } 255 265 256 266 public void appendLine(String text) { 257 267 if (text == null) 258 268 text = ""; 259 269 260 270 if (_text.length() > 0) 261 271 _text.append('\n'); 262 272 263 273 _text.append(text); 264 274 rebuild(false); … … 381 391 382 392 public String cutSelectedText() { 393 return replaceSelectedText(""); 394 } 395 396 public String replaceSelectedText(String newText) { 383 397 if (_selectionStart < 0 || _selectionEnd < 0) 384 398 return null; … … 390 404 391 405 String s = _text.substring(left, right); 392 for (int i = right; i > left; i--) { 393 _text.delete(i - 1, i); 394 if (_text.length() > 0) { 395 AttributedString inserting = new AttributedString(_text 396 .toString()); 397 inserting.addAttribute(TextAttribute.FONT, getPaintFont()); 398 _lineBreaker.deleteChar(inserting.getIterator(), i - 1); 399 } 400 401 rejustify(); 402 } 406 407 _text.delete(left, right); 408 _text.insert(left, newText); 409 rebuild(true); 403 410 404 411 return s; … … 409 416 return 0; 410 417 411 // System.out.println(_selectionStart + ":" + _selectionEnd);418 // System.out.println(_selectionStart + ":" + _selectionEnd); 412 419 413 420 return Math.abs(_selectionEnd - _selectionStart); … … 451 458 // otherwise, we are inserting text 452 459 } else { 460 _processedCode = null; 453 461 // determine what line is being pointed to 454 462 line = getLinePosition(mouseY); … … 552 560 x, 553 561 (getX() - Item.MARGIN_RIGHT - (2 * getGravity()) + getBoundsWidth())); 554 return new Point(x, getY() /* + DisplayIO.getOffset() */+ y562 return new Point(x, getY() + y 555 563 + (int) caret[1]); 556 564 } … … 621 629 622 630 return new Point((int) (getX() + caret[0]) + getJustOffset(current), 623 getY() /* + DisplayIO.getOffset() */+ y + (int) caret[1]);631 getY() + y + (int) caret[1]); 624 632 } 625 633 … … 720 728 Font f = getPaintFont(); 721 729 String s = ""; 722 730 723 731 if (f.isPlain()) 724 732 s += "Plain"; … … 732 740 return s; 733 741 } 734 735 public static final String[] FONT_WHEEL = { "sansserif", "monospaced", "serif", "dialog", "dialoginput" }; 742 743 public static final String[] FONT_WHEEL = { "sansserif", "monospaced", 744 "serif", "dialog", "dialoginput" }; 745 736 746 public static final char[] FONT_CHARS = { 's', 'm', 't', 'd', 'i' }; 737 747 748 private static final int NEARBY_GRAVITY = 2; 749 738 750 public void toggleFontFamily() { 739 751 String fontFamily = getFamily().toLowerCase(); 740 // set it to the first font by default752 // set it to the first font by default 741 753 setFamily(FONT_WHEEL[0]); 742 754 743 755 for (int i = 0; i < FONT_WHEEL.length - 3; i++) { 744 if (fontFamily.equals(FONT_WHEEL[i])){745 setFamily(FONT_WHEEL[i +1]);756 if (fontFamily.equals(FONT_WHEEL[i])) { 757 setFamily(FONT_WHEEL[i + 1]); 746 758 break; 747 759 } 748 760 } 749 761 } 750 762 751 763 public void toggleFontStyle() { 752 764 Font currentFont = getPaintFont(); … … 882 894 883 895 @Override 896 public boolean intersects(Polygon p) { 897 if (super.intersects(p)) { 898 int textY = getY(); 899 900 for (TextLayout text : _textLayouts) { 901 // check left and right of each box 902 Rectangle textOutline = text.getLogicalHighlightShape(0, 903 text.getCharacterCount()).getBounds(); 904 textOutline.translate(getX(), textY); 905 if (p.intersects(textOutline)) 906 return true; 907 textY += getLineDrop(text); 908 } 909 } 910 return false; 911 } 912 913 @Override 884 914 public boolean contains(int mouseX, int mouseY) { 915 return contains(mouseX, mouseY, getGravity() * NEARBY_GRAVITY); 916 } 917 918 public boolean contains(int mouseX, int mouseY, int gravity) { 885 919 mouseX += getOffset().x; 886 920 mouseY += getOffset().y; … … 888 922 int textY = getY(); 889 923 int textX = getX(); 890 int gravity = getGravity() * 2;891 924 892 925 Rectangle outline = getPolygon().getBounds(); … … 1009 1042 while ((layout = _lineBreaker.nextLayout(width)) != null) { 1010 1043 // for some reason lineBreaker will not break on newline 1011 // characters 1012 // so they have to be check manually 1044 // characters so they have to be check manually 1013 1045 int start = _lineOffsets.get(_lineOffsets.size() - 1); 1014 1046 … … 1369 1401 return; 1370 1402 1371 //Remove 'a: ' from the begining if it is there 1372 if (_text.length() > 3 && _text.charAt(0) == 'a' && _text.charAt(1) == ':'){ 1403 // Remove 'a: ' from the begining if it is there 1404 if (_text.length() > 3 && _text.charAt(0) == 'a' 1405 && _text.charAt(1) == ':') { 1373 1406 _text.delete(0, 2); 1374 1407 while (_text.charAt(0) == ' ') … … 1502 1535 Text template = this.copy(); 1503 1536 template.setID(-1); 1504 //The template must have text otherwise the bounds height will be zero!! 1505 //This will stop escape drop down from working if there is no item template 1537 // The template must have text otherwise the bounds height will be 1538 // zero!! 1539 // This will stop escape drop down from working if there is no item 1540 // template 1506 1541 template.setText("@"); 1507 1542 return template; 1508 1543 } 1544 1545 @Override 1546 public boolean isNear(int x, int y) { 1547 if (super.isNear(x, y)) { 1548 // TODO check that it is actually near one of the lines of space 1549 // return contains(x, y, getGravity() * 2 + NEAR_DISTANCE); 1550 // at the moment contains ignores gravity when checking the top and 1551 // bottom of text lines... so the cursor must be between two text 1552 // lines 1553 int textY = getY(); 1554 int textX = getX(); 1555 1556 for (TextLayout text : _textLayouts) { 1557 // check left and right of each box 1558 Rectangle textOutline = text.getLogicalHighlightShape(0, 1559 text.getCharacterCount()).getBounds(); 1560 1561 // check if the cursor is within the top, bottom and within the 1562 // gravity of right 1563 if (y - textY > textOutline.y - NEAR_DISTANCE 1564 && y - textY < textOutline.y + textOutline.height + NEAR_DISTANCE 1565 && x - textX < textOutline.width + NEAR_DISTANCE) 1566 return true; 1567 textY += getLineDrop(text); 1568 } 1569 } 1570 return false; 1571 } 1572 1573 @Override 1574 public void delete() { 1575 setVisible(false); 1576 } 1509 1577 } -
trunk/src/org/expeditee/simple/Context.java
r4 r7 1 1 package org.expeditee.simple; 2 2 3 import java.io.BufferedReader; 3 4 import java.io.BufferedWriter; 4 5 import java.io.File; 6 import java.io.FileReader; 5 7 import java.io.FileWriter; 6 8 … … 8 10 import org.expeditee.gui.FrameGraphics; 9 11 import org.expeditee.gui.FrameIO; 12 import org.expeditee.items.Text; 10 13 11 14 public class Context { … … 92 95 // Get the values to be set 93 96 Frame frame = (Frame) pointers_.getVariable(frameVar).getValue(); 97 frame.change(); 94 98 String contents = FrameIO.SaveFrame(frame, false); 95 99 … … 104 108 .getValue(); 105 109 bw.close(); 110 } 111 112 public void closeReadFile(String fileVar) throws Exception { 113 BufferedReader br = (BufferedReader) pointers_.getVariable(fileVar) 114 .getValue(); 115 br.close(); 106 116 } 107 117 … … 128 138 if (successVar != null) { 129 139 Boolean success = currentFile != null; 140 primitives_.setValue(successVar, new SBoolean(success)); 141 } 142 } 143 144 public void readLineFile(String fileVar, String textVar) throws Exception { 145 readLineFile(fileVar, fileVar, null); 146 } 147 148 public void readLineFile(String fileVar, String textVar, String successVar) 149 throws Exception { 150 151 BufferedReader br = (BufferedReader) pointers_.getVariable(fileVar) 152 .getValue(); 153 154 String text = br.readLine(); 155 boolean success = text != null; 156 primitives_.setValue(textVar, text); 157 158 if (successVar != null) { 159 primitives_.setValue(successVar, new SBoolean(success)); 160 } 161 } 162 163 public void readItemFile(String fileVar, String itemVar) throws Exception { 164 readItemFile(fileVar, fileVar, null); 165 } 166 167 public void readItemFile(String fileVar, String itemVar, String successVar) 168 throws Exception { 169 170 BufferedReader br = (BufferedReader) pointers_.getVariable(fileVar) 171 .getValue(); 172 boolean success = true; 173 try { 174 Text item = (Text) pointers_.getVariable(itemVar).getValue(); 175 String nextLine = br.readLine(); 176 String text = nextLine; 177 success = (text != null); 178 while ((nextLine = br.readLine()) != null) 179 text += '\n' + nextLine; 180 item.setText(text); 181 } catch (Exception e) { 182 success = false; 183 } 184 185 if (successVar != null) { 186 primitives_.setValue(successVar, new SBoolean(success)); 187 } 188 } 189 190 public void openReadFile(String fileNameVar, String fileVar) 191 throws Exception { 192 openReadFile(fileNameVar, fileVar, null); 193 } 194 195 public void openReadFile(String fileNameVar, String fileVar, 196 String successVar) throws Exception { 197 // Get the values to be set 198 File filePath = new File(primitives_.getStringValue(fileNameVar)); 199 Boolean success = true; 200 BufferedReader currentFile = null; 201 try { 202 currentFile = new BufferedReader(new FileReader(filePath)); 203 } catch (Exception e) { 204 success = false; 205 } 206 pointers_.setObject(fileVar, currentFile); 207 208 if (successVar != null) { 130 209 primitives_.setValue(successVar, new SBoolean(success)); 131 210 } … … 144 223 } 145 224 } 225 226 public void createFrameset(String framesetNameVar, String successVar) 227 throws Exception { 228 // Get the values to be set 229 String framesetName = primitives_.getStringValue(framesetNameVar); 230 Frame firstFrame = FrameIO.CreateNewFrameset(framesetName); 231 232 if (successVar != null) { 233 Boolean success = firstFrame != null; 234 primitives_.setValue(successVar, new SBoolean(success)); 235 } 236 237 } 146 238 } -
trunk/src/org/expeditee/stats/SessionStats.java
r4 r7 16 16 public class SessionStats { 17 17 18 private static final long MILLISECONDS_PER_MINUTE = 6000 ;18 private static final long MILLISECONDS_PER_MINUTE = 60000; 19 19 20 20 private static Date _FrameAccessTime = new Date(); … … 23 23 24 24 // statistics counters 25 private static final int MOUSE_BUTTONS = 3;25 private static final int MOUSE_BUTTONS = 4; 26 26 27 27 private static StringBuffer _FramesEdited = new StringBuffer(); … … 59 59 stats.append(Logger.EasyDateFormat("ddMMMyyyy")).append("\n"); 60 60 stats.append("SessionTime: ").append(getTimeElapsed()).append("\n"); 61 stats.append("DarkTime: ").append( new SimpleDateFormat("m").format(_DarkTime) ).append("\n"); 61 62 long elapsedTime = (new Date()).getTime()-_StartTime.getTime(); 63 stats.append("DarkTime: ").append(_DarkTime.getTime()/MILLISECONDS_PER_MINUTE).append("-->" + 64 _DarkTime.getTime() * 100 / elapsedTime + "%\n"); 62 65 63 66 stats.append(getFrameStats()); … … 74 77 SimpleDateFormat formatter = new SimpleDateFormat("HH:mm"); 75 78 Date currentTime = new Date(); 76 Time elapsedTime = new Time(currentTime.getTime()-_StartTime.getTime());79 long elapsedTime = currentTime.getTime()-_StartTime.getTime(); 77 80 String time = formatter.format(_StartTime); 78 81 time += " --> " + formatter.format(currentTime); 79 time += " = " + ( new SimpleDateFormat("m").format(elapsedTime));82 time += " = " + (int)(elapsedTime / MILLISECONDS_PER_MINUTE); //(new SimpleDateFormat("m").format(elapsedTime)); 80 83 81 84 return time; … … 109 112 } 110 113 111 private static intgetMinutesUsed() {114 private static double getMinutesUsed() { 112 115 long elapsedTime = new Date().getTime() - _StartTime.getTime() - _DarkTime.getTime(); 113 116 114 return ( int) (elapsedTime / MILLISECONDS_PER_MINUTE);117 return (double) elapsedTime / MILLISECONDS_PER_MINUTE; 115 118 } 116 119 … … 145 148 appendStat(stats, "Frames", _CreatedFrames); 146 149 appendStat(stats, "Escape", _EscapeCount); 147 appendStat(stats, "Left", _MouseCounters[MouseEvent.BUTTON1 - 1]);148 appendStat(stats, "Middle", _MouseCounters[MouseEvent.BUTTON2 - 1]);149 appendStat(stats, "Right", _MouseCounters[MouseEvent.BUTTON3 - 1]);150 appendStat(stats, "Left", _MouseCounters[MouseEvent.BUTTON1]); 151 appendStat(stats, "Middle", _MouseCounters[MouseEvent.BUTTON2]); 152 appendStat(stats, "Right", _MouseCounters[MouseEvent.BUTTON3]); 150 153 151 154 return stats.toString(); … … 169 172 value = 0; 170 173 171 int perHour = value * 60 / Math.max(1,getMinutesUsed());174 int perHour = (int)(value * 60 / getMinutesUsed()); 172 175 173 176 stats.append(value).append(" ").append(name).append(" @ ").append(perHour).append("/hour"); … … 262 265 public static void MouseClicked(int button) { 263 266 UserEvent(); 264 _MouseCounters[button - 1]++;267 _MouseCounters[button]++; 265 268 } 266 269 … … 277 280 return _FramesEdited.toString(); 278 281 } 282 283 public static StringBuffer getShortStats() { 284 StringBuffer sb = new StringBuffer(); 285 sb.append("FramesA:").append(_AccessedFrames); 286 sb.append(", FramesE:").append(_SavedFrames); 287 sb.append(", ").append(getResponseStats()); 288 return sb; 289 } 279 290 }
Note:
See TracChangeset
for help on using the changeset viewer.