- Timestamp:
- 10/31/18 10:22:24 (6 years ago)
- Location:
- trunk/src/org/expeditee/gui
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/AttributeUtils.java
r1102 r1188 392 392 Attribute a = attribSet.get(prop); 393 393 // Make sure the classes of the methods match the item 394 if (a != null && a.getter != null && a.getter.getDeclaringClass().isAssignableFrom(toExtract.getClass())) { 395 394 if (a != null && a.getter != null && a.getter.getDeclaringClass().isAssignableFrom(toExtract.getClass())) { 396 395 try { 397 396 String s = getValue(prop, a, toExtract, true); 398 if (s == null) 397 if (s == null) { 399 398 continue; 399 } 400 400 // Append the attributes 401 401 attributes.append(a.displayName) … … 410 410 411 411 // if no attributes were extracted 412 if (attributes.length() <= 0) 412 if (attributes.length() <= 0) { 413 413 return null; 414 415 while (attributes.charAt(attributes.length() - 1) == '\n') 414 } 415 416 while (attributes.charAt(attributes.length() - 1) == '\n') { 416 417 attributes.delete(attributes.length() - 1, attributes.length()); 418 } 417 419 418 420 // create the text Item … … 450 452 // are in the AllowNull list 451 453 if (_AllowNull.contains(a.getter)) { 452 if (name.equals("color")) 454 if (name.equals("color")) { 453 455 o = "default"; 454 else if (name.equals("backgroundcolor"))456 } else if (name.equals("backgroundcolor")) { 455 457 o = "transparent"; 456 else if (name.equals("foregroundcolor"))458 } else if (name.equals("foregroundcolor")) { 457 459 o = "auto"; 458 else460 } else { 459 461 o = ""; 462 } 460 463 } else { 461 464 return null; … … 469 472 if (o instanceof Integer) { 470 473 Integer i = (Integer) o; 471 if (i == Item.DEFAULT_INTEGER) 474 if (i == Item.DEFAULT_INTEGER) { 472 475 return null; 476 } 473 477 if (a.getter.getName().endsWith("Justification") 474 && ((Justification) o).toString() != null) 478 && ((Justification) o).toString() != null) { 475 479 o = ((Justification) o).toString(); 476 480 // -1 indicates default value 477 else481 } else { 478 482 o = i; 483 } 479 484 } else if (o instanceof Float) { 480 485 if (((Float) o) < -0.0001) 486 { 481 487 return null; 482 488 // Null indicates default 483 489 // o = Math.round((Float) o); 490 } 484 491 } else if (o instanceof Double) { 485 492 // -1 indicates default value 486 if (((Double) o) < 0.0001) 493 if (((Double) o) < 0.0001) { 487 494 return null; 495 } 488 496 } else if (o instanceof Colour) { 489 497 // converts the color to the Expeditee code 490 498 o = Conversion.getExpediteeColorCode((Colour) o); 491 if (o == null) 499 if (o == null) { 492 500 return null; 501 } 493 502 } else if (o instanceof Point) { 494 503 Point p = (Point) o; … … 498 507 499 508 String s = f.getFamilyName() + "-"; 500 if (f.isPlain()) 509 if (f.isPlain()) { 501 510 s += "Plain"; 502 503 if (f.isBold()) 511 } 512 513 if (f.isBold()) { 504 514 s += "Bold"; 505 506 if (f.isItalic()) 515 } 516 517 if (f.isItalic()) { 507 518 s += "Italic"; 519 } 508 520 509 521 s += "-" + f.getSize(); … … 514 526 List list = (List) o; 515 527 StringBuffer sb = new StringBuffer(); 516 for (Object ob : list) 528 for (Object ob : list) { 517 529 // TODO check that this works ok 518 530 if (sb.length() == 0) { … … 521 533 sb.append('\n').append(a.displayName).append(AttributeValuePair.SEPARATOR_STRING).append(ob); 522 534 } 535 } 523 536 return sb.toString(); 524 537 } else if (o instanceof int[]) { … … 532 545 } else if (o instanceof Boolean) { 533 546 // true is the default for boolean values 534 if (((Boolean) o).booleanValue()) 547 if (((Boolean) o).booleanValue()) { 535 548 return null; 549 } 536 550 } 537 551 return o.toString(); … … 557 571 int minAttributeLength) { 558 572 // error checking 559 if (toSet == null || attribs == null) 573 if (toSet == null || attribs == null) { 560 574 return false; 575 } 561 576 562 577 ensureReady(); … … 589 604 // attribute merging 590 605 if (!avp.hasAttribute() 591 || avp.getAttribute().length() < minAttributeLength) 606 || avp.getAttribute().length() < minAttributeLength) { 592 607 return false; 608 } 593 609 594 610 // check if the next string is another attribute to merge or a … … 699 715 // if there are duplicate methods with the same name 700 716 List<Method> possibles = new LinkedList<Method>(); 701 if (a.setter.getDeclaringClass().isInstance(toSet)) 717 if (a.setter.getDeclaringClass().isInstance(toSet)) { 702 718 possibles.add(a.setter); 719 } 703 720 int i = 0; 704 721 while (attribSet.containsKey(attribute + i)) { … … 741 758 742 759 if(possibles.size() == 0){ 743 if(invokeAttributeGetMethod(avp.getAttribute(), toSet) == null) 760 if(invokeAttributeGetMethod(avp.getAttribute(), toSet) == null) { 744 761 throw new NoSuchAttributeException(avp.getAttribute(), toSet.getClass().getSimpleName()); 762 } 745 763 throw new ReadOnlyAttributeException(avp.getAttribute(), toSet.getClass().getSimpleName()); 746 764 } -
trunk/src/org/expeditee/gui/FrameIO.java
r1105 r1188 152 152 public static void Precache(String framename) { 153 153 // if the cache is turned off, do nothing 154 if (!isCacheOn()) 154 if (!isCacheOn()) { 155 155 return; 156 } 156 157 157 158 // if the frame is already in the cache, do nothing 158 if (_Cache.containsKey(framename.toLowerCase())) 159 if (_Cache.containsKey(framename.toLowerCase())) { 159 160 return; 161 } 160 162 161 163 // otherwise, load the frame and put it in the cache … … 177 179 */ 178 180 public static boolean isPositiveInteger(String s) { 179 if (s == null || s.length() == 0) 181 if (s == null || s.length() == 0) { 180 182 return false; 183 } 181 184 182 185 for (int i = 0; i < s.length(); i++) { 183 if (!Character.isDigit(s.charAt(i))) 186 if (!Character.isDigit(s.charAt(i))) { 184 187 return false; 188 } 185 189 } 186 190 return true; 187 191 } 192 193 public static String FRAMESET_CONSULT_PATH = null; 188 194 189 195 public static Frame LoadFrame(String frameName) { 190 return LoadFrame(frameName, null, false);196 return LoadFrame(frameName, FRAMESET_CONSULT_PATH, false); 191 197 } 192 198 … … 197 203 public static Frame LoadFrame(String frameName, String path, boolean ignoreAnnotations) 198 204 { 199 if (!isValidFrameName(frameName)) return null; 205 if (!isValidFrameName(frameName)) { 206 return null; 207 } 200 208 201 209 String frameNameLower = frameName.toLowerCase(); … … 261 269 String fullPath = FrameIO.getFrameFullPathName(PUBLIC_PATH, frameName); 262 270 263 if (fullPath == null) 271 if (fullPath == null) { 264 272 return null; 273 } 265 274 266 275 File frameFile = new File(fullPath); … … 313 322 for (String path : FolderSettings.FrameDirs.get()) { 314 323 File files = new File(path); 315 if (!files.exists()) 324 if (!files.exists()) { 316 325 continue; 326 } 317 327 for (File f : (new File(path)).listFiles()) { 318 328 if (f.isDirectory()) { … … 354 364 355 365 File tester = new File(source); 356 if (!tester.exists()) 366 if (!tester.exists()) { 357 367 return null; 368 } 358 369 359 370 String fullPath; … … 372 383 tester = new File(fullPath); 373 384 374 if (tester.exists()) 385 if (tester.exists()) { 375 386 return fullPath; 387 } 376 388 377 389 // check for oldfile name format … … 380 392 tester = new File(fullPath); 381 393 382 if (tester.exists()) 394 if (tester.exists()) { 383 395 return fullPath; 396 } 384 397 385 398 return null; … … 396 409 397 410 for (String path : FolderSettings.FrameDirs.get()) { 398 if (getFrameFullPathName(path, frameName) != null) 411 if (getFrameFullPathName(path, frameName) != null) { 399 412 return true; 413 } 400 414 } 401 415 return false; … … 408 422 for (String possiblePath : FolderSettings.FrameDirs.get()) { 409 423 fullPath = getFrameFullPathName(possiblePath, frameName); 410 if (fullPath != null) 424 if (fullPath != null) { 411 425 break; 426 } 412 427 } 413 428 } else { … … 415 430 } 416 431 // If the frame was not located return null 417 if (fullPath == null) 432 if (fullPath == null) { 418 433 return null; 434 } 419 435 Collection<String> results = new LinkedList<String>(); 420 436 // Open the file and search the text items … … 425 441 if (next.startsWith("T")) { 426 442 String toSearch = next.substring(2); 427 if (toSearch.toLowerCase().contains(pattern)) 443 if (toSearch.toLowerCase().contains(pattern)) { 428 444 results.add(toSearch); 445 } 429 446 } 430 447 } … … 440 457 private static Frame LoadKnowPath(String path, String frameName) { 441 458 String fullPath = getFrameFullPathName(path, frameName); 442 if (fullPath == null) 459 if (fullPath == null) { 443 460 return null; 461 } 444 462 445 463 try { … … 463 481 // do not put 0 frames or virtual frames into the cache 464 482 // Why are zero frames not put in the cache 465 if (_Cache.size() > MAX_CACHE) 483 if (_Cache.size() > MAX_CACHE) { 466 484 _Cache.clear(); 467 468 if (frame.getNumber() > 0 && isCacheOn()) 485 } 486 487 if (frame.getNumber() > 0 && isCacheOn()) { 469 488 _Cache.put(frameName.toLowerCase(), frame); 489 } 470 490 471 491 return frame; … … 490 510 Frame fresh = FrameIO.LoadFrame(DisplayController.getCurrentFrame().getName()); 491 511 _UseCache = cache; 492 if (_Cache.containsKey(fresh.getName().toLowerCase())) 512 if (_Cache.containsKey(fresh.getName().toLowerCase())) { 493 513 addToCache(fresh); 514 } 494 515 DisplayController.setCurrentFrame(fresh, false); 495 516 } … … 505 526 for (; num >= 0; num--) { 506 527 Frame f = LoadFrame(name + num, current.getPath()); 507 if (f != null) 528 if (f != null) { 508 529 return f; 530 } 509 531 } 510 532 … … 543 565 for (; num <= max; num++) { 544 566 Frame f = LoadFrame(name + num, current.getPath()); 545 if (f != null) 567 if (f != null) { 546 568 return f; 569 } 547 570 } 548 571 … … 582 605 for (int num = max; num > 0; num--) { 583 606 Frame f = LoadFromDisk(framesetName + num, path, false); 584 if (f != null) 607 if (f != null) { 585 608 return f; 609 } 586 610 } 587 611 … … 625 649 public static String DeleteFrame(Frame toDelete) throws IOException, 626 650 SecurityException { 627 if (toDelete == null) 651 if (toDelete == null) { 628 652 return null; 653 } 629 654 630 655 // Dont delete the zero frame … … 667 692 ForceSaveFrame(toDelete); 668 693 669 if (_Cache.containsKey(oldFrameName)) 694 if (_Cache.containsKey(oldFrameName)) { 670 695 _Cache.remove(oldFrameName); 696 } 671 697 672 698 File del = new File(source); … … 761 787 762 788 for (Item i : template.getItems()) { 763 if (ItemUtils.startsWithTag(i, ItemUtils.TAG_PARENT)) 789 if (ItemUtils.startsWithTag(i, ItemUtils.TAG_PARENT)) { 764 790 i.setLink(null); 791 } 765 792 } 766 793 … … 812 839 { 813 840 SuspendCache(); 814 for (Frame frame : _Cache.values()) frame.setBuffer(null); 841 for (Frame frame : _Cache.values()) { 842 frame.setBuffer(null); 843 } 815 844 ResumeCache(); 816 845 } … … 842 871 public static boolean isValidFrameName(String frameName) { 843 872 844 if (frameName == null || frameName.length() < 2) 873 if (frameName == null || frameName.length() < 2) { 845 874 return false; 875 } 846 876 847 877 int lastCharIndex = frameName.length() - 1; 848 878 // String must begin with a letter and end with a digit 849 879 if (!Character.isLetter(frameName.charAt(0)) 850 || !Character.isDigit(frameName.charAt(lastCharIndex))) 880 || !Character.isDigit(frameName.charAt(lastCharIndex))) { 851 881 return false; 882 } 852 883 853 884 // All the characters between first and last must be letters 854 885 // or digits 855 886 for (int i = 1; i < lastCharIndex; i++) { 856 if (!isValidFrameNameChar(frameName.charAt(i))) 887 if (!isValidFrameNameChar(frameName.charAt(i))) { 857 888 return false; 889 } 858 890 } 859 891 return true; … … 1011 1043 1012 1044 Frame original = LoadFrame(toSave.getName()); 1013 if (original == null) 1045 if (original == null) { 1014 1046 original = toSave; 1047 } 1015 1048 int orignum = original.getNumber(); 1016 1049 … … 1056 1089 1057 1090 // avoid out-of-sync frames (when in TwinFrames mode) 1058 if (_Cache.containsKey(toSave.getName().toLowerCase())) 1091 if (_Cache.containsKey(toSave.getName().toLowerCase())) { 1059 1092 addToCache(toSave); 1093 } 1060 1094 1061 1095 Logger.Log(Logger.SYSTEM, Logger.SAVE, "Saving " + toSave.getName() … … 1065 1099 int last = ReadINF(toSave.getPath(), toSave.getFramesetName(), 1066 1100 false); 1067 if (last <= toSave.getNumber()) 1101 if (last <= toSave.getNumber()) { 1068 1102 WriteINF(toSave.getPath(), toSave.getFramesetName(), toSave 1069 1103 .getName()); 1104 } 1070 1105 1071 1106 // check if this was the profile frame (and thus needs … … 1152 1187 public static boolean isProfileFrame(Frame toCheck) 1153 1188 { 1154 if (toCheck.getNumber() == 0) return false; 1189 if (toCheck.getNumber() == 0) { 1190 return false; 1191 } 1155 1192 1156 1193 return toCheck.getPath().equals(PROFILE_PATH); … … 1275 1312 capital = false; 1276 1313 result.append(Character.toUpperCase(cur)); 1277 } else 1314 } else { 1278 1315 result.append(cur); 1316 } 1279 1317 } else { 1280 1318 capital = true; … … 1284 1322 int lastCharIndex = result.length() - 1; 1285 1323 if (!Character.isLetter(result.charAt(lastCharIndex))) { 1286 if (lastCharIndex == MAX_NAME_LENGTH - 1) 1324 if (lastCharIndex == MAX_NAME_LENGTH - 1) { 1287 1325 result.setCharAt(lastCharIndex, FRAME_NAME_LAST_CHAR); 1288 else1326 } else { 1289 1327 result.append(FRAME_NAME_LAST_CHAR); 1328 } 1290 1329 } 1291 1330 … … 1308 1347 public static Frame CreateNewFrame(Item linker, OnNewFrameAction action) throws RuntimeException { 1309 1348 Frame newFrame = FrameIO.CreateNewFrame(linker); 1310 if(action != null) action.exec(linker, newFrame); 1349 if(action != null) { 1350 action.exec(linker, newFrame); 1351 } 1311 1352 return newFrame; 1312 1353 } … … 1358 1399 1359 1400 // the frameset does not exist (or has no 0 frame) 1360 if (zero == null) 1401 if (zero == null) { 1361 1402 return -1; 1403 } 1362 1404 1363 1405 try { … … 1388 1430 framesetName = framesetName.toLowerCase(); 1389 1431 for (String path : FolderSettings.FrameDirs.get()) { 1390 if ((new File(path + framesetName)).exists()) 1432 if ((new File(path + framesetName)).exists()) { 1391 1433 return true; 1434 } 1392 1435 } 1393 1436 return false; … … 1398 1441 String conversion = frameset + " --> "; 1399 1442 1400 if (!isValidFramesetName(frameset)) throw new Exception("Invalid frameset name"); 1443 if (!isValidFramesetName(frameset)) { 1444 throw new Exception("Invalid frameset name"); 1445 } 1401 1446 1402 1447 if (!recreate && FrameIO.canAccessFrameset(frameset)) { … … 1413 1458 */ 1414 1459 // ignore annotation character 1415 if (frameset.startsWith("@")) 1460 if (frameset.startsWith("@")) { 1416 1461 frameset = frameset.substring(1); 1462 } 1417 1463 1418 1464 conversion += " --> " + frameset; … … 1498 1544 1499 1545 if (!Character.isLetter(frameset.charAt(0)) 1500 || !Character.isLetter(frameset.charAt(lastCharIndex))) 1546 || !Character.isLetter(frameset.charAt(lastCharIndex))) { 1501 1547 return false; 1548 } 1502 1549 1503 1550 for (int i = 1; i < lastCharIndex; i++) { … … 1515 1562 public static boolean moveFrameset(String framesetName, 1516 1563 String destinationFolder) { 1517 if (!FrameIO.canAccessFrameset(framesetName)) 1564 if (!FrameIO.canAccessFrameset(framesetName)) { 1518 1565 return false; 1566 } 1519 1567 // Clear the cache 1520 1568 _Cache.clear(); … … 1531 1579 File dest = new File(destPath + File.separator); 1532 1580 // Create the destination folder if it doesnt already exist 1533 if (!dest.getParentFile().exists()) 1581 if (!dest.getParentFile().exists()) { 1534 1582 dest.mkdirs(); 1583 } 1535 1584 // If a frameset with the same name is already in the 1536 1585 // destination add … … 1541 1590 if (!framesetDirectory.renameTo(dest)) { 1542 1591 for (File f : framesetDirectory.listFiles()) { 1543 if (!f.delete()) 1592 if (!f.delete()) { 1544 1593 return false; 1594 } 1545 1595 } 1546 if (!framesetDirectory.delete()) 1596 if (!framesetDirectory.delete()) { 1547 1597 return false; 1598 } 1548 1599 } 1549 1600 return true; … … 1555 1606 public static boolean CopyFrameset(String framesetToCopy, 1556 1607 String copiedFrameset) throws Exception { 1557 if (!FrameIO.canAccessFrameset(framesetToCopy)) 1608 if (!FrameIO.canAccessFrameset(framesetToCopy)) { 1558 1609 return false; 1559 if (FrameIO.canAccessFrameset(copiedFrameset)) 1610 } 1611 if (FrameIO.canAccessFrameset(copiedFrameset)) { 1560 1612 return false; 1613 } 1561 1614 // search through all the directories to find the frameset we are 1562 1615 // copying … … 1569 1622 File copyFramesetDirectory = new File(path 1570 1623 + copiedFrameset.toLowerCase() + File.separator); 1571 if (!copyFramesetDirectory.mkdirs()) 1624 if (!copyFramesetDirectory.mkdirs()) { 1572 1625 return false; 1626 } 1573 1627 // copy each of the frames 1574 1628 for (File f : framesetDirectory.listFiles()) { 1575 1629 // Ignore hidden files 1576 if (f.getName().charAt(0) == '.') 1630 if (f.getName().charAt(0) == '.') { 1577 1631 continue; 1632 } 1578 1633 String copyPath = copyFramesetDirectory.getAbsolutePath() 1579 1634 + File.separator + f.getName();
Note:
See TracChangeset
for help on using the changeset viewer.