Changeset 1190 for trunk/src/org/expeditee/items/ItemUtils.java
- Timestamp:
- 10/31/18 10:24:23 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/ItemUtils.java
r1143 r1190 40 40 import org.expeditee.gui.Vector; 41 41 import org.expeditee.items.Item.HighlightMode; 42 import org.expeditee.items.widgets.Widget;43 42 import org.expeditee.items.widgets.InteractiveWidgetInitialisationFailedException; 44 43 import org.expeditee.items.widgets.InteractiveWidgetNotAvailableException; 44 import org.expeditee.items.widgets.Widget; 45 45 import org.expeditee.items.widgets.WidgetCorner; 46 46 import org.expeditee.items.widgets.WidgetEdge; … … 160 160 public static Text FindTag(Collection<Item> items, String toFind) { 161 161 for (Item i : items) { 162 if (i instanceof Text && i.isAnnotation()) 163 if (((Text) i).startsWith(toFind)) 162 if (i instanceof Text && i.isAnnotation()) { 163 if (((Text) i).startsWith(toFind)) { 164 164 return (Text) i; 165 } 166 } 165 167 } 166 168 return null; … … 169 171 public static Item FindExactTag(Collection<Item> items, String toFind) { 170 172 for (Item i : items) { 171 if (i instanceof Text && i.isAnnotation()) 172 if (((Text) i).getText().trim().equalsIgnoreCase(toFind)) 173 return (Item) i; 173 if (i instanceof Text && i.isAnnotation()) { 174 if (((Text) i).getText().trim().equalsIgnoreCase(toFind)) { 175 return i; 176 } 177 } 174 178 } 175 179 … … 212 216 public static boolean startsWithTag(Item toCheck, String tag, 213 217 boolean valueAllowed) { 214 if (!(toCheck instanceof Text)) 218 if (!(toCheck instanceof Text)) { 215 219 return false; 220 } 216 221 217 222 Text txt = (Text) toCheck; 218 223 String value = ItemUtils.StripTag(txt.getText(), tag); 219 224 220 if (value == null) 225 if (value == null) { 221 226 return false; 227 } 222 228 return valueAllowed || value.equals(""); 223 229 } … … 246 252 */ 247 253 public static String StripTag(String toStrip, String tag) { 248 if (toStrip == null) 254 if (toStrip == null) { 249 255 return null; 256 } 250 257 toStrip = toStrip.trim(); 251 if (!toStrip.toLowerCase().startsWith(tag.toLowerCase())) 258 if (!toStrip.toLowerCase().startsWith(tag.toLowerCase())) { 252 259 return null; 253 254 if (toStrip.length() == tag.length()) 260 } 261 262 if (toStrip.length() == tag.length()) { 255 263 return ""; 264 } 256 265 // remove tag and ensure the char is the tag separator 257 266 char separator = toStrip.charAt(tag.length()); 258 if (separator != ':') 267 if (separator != ':') { 259 268 return null; 260 261 if (toStrip.length() == tag.length() + 1) 269 } 270 271 if (toStrip.length() == tag.length() + 1) { 262 272 return ""; 273 } 263 274 264 275 return toStrip.substring(tag.length() + 1).trim(); … … 377 388 378 389 int fileSuffixChar = text.indexOf('.'); 379 if (fileSuffixChar < 0) 390 if (fileSuffixChar < 0) { 380 391 return null; 392 } 381 393 int endOfFileName = text.indexOf(' ', fileSuffixChar); 382 394 if (endOfFileName < 0) { … … 394 406 for (String dir : FolderSettings.ImageDirs.get()) { 395 407 file = new File(dir + path); 396 if (file.exists() && !file.isDirectory()) 408 if (file.exists() && !file.isDirectory()) { 397 409 break; 398 } 399 400 if (file == null || !file.exists() || file.isDirectory()) 410 } 411 } 412 413 if (file == null || !file.exists() || file.isDirectory()) { 401 414 file = new File(path); 415 } 402 416 403 417 // try relative path … … 415 429 } 416 430 417 } else 431 } else { 418 432 path = file.getPath(); 433 } 419 434 420 435 // if the image isn't found by now, try remote servers … … 487 502 for (Item i : toCopy) { 488 503 // Dont copy parts of a vector 489 if (i == null || !i.hasPermission(UserAppliedPermission.copy)) 504 if (i == null || !i.hasPermission(UserAppliedPermission.copy)) { 490 505 continue; 506 } 491 507 492 508 // BROOK 493 509 if (i instanceof WidgetCorner) { // dont add these 494 510 if (!widgets.contains(((WidgetCorner) i).getWidgetSource())) 511 { 495 512 widgets.add(((WidgetCorner) i).getWidgetSource()); 496 513 // BROOK 514 } 497 515 } else if (i instanceof WidgetEdge) { // dont add these 498 516 // lines are recreated later … … 577 595 Item originalLineEnd = line.getEndItem(); 578 596 Item actualLineEnd = lineEndMap.get(originalLineEnd); 579 if (actualLineEnd == null) 597 if (actualLineEnd == null) { 580 598 lineCopy.setEndItem(originalLineEnd); 581 else599 } else { 582 600 lineCopy.setEndItem(actualLineEnd); 601 } 583 602 584 603 Item originalLineStart = line.getStartItem(); 585 604 Item actualLineStart = lineEndMap.get(originalLineStart); 586 if (actualLineStart == null) 605 if (actualLineStart == null) { 587 606 lineCopy.setStartItem(originalLineStart); 588 else607 } else { 589 608 lineCopy.setStartItem(actualLineStart); 609 } 590 610 591 611 copies.add(lineCopy); … … 618 638 619 639 // Make sure filled rectangles are shown filled on vector overlays 620 if (v != null) 640 if (v != null) { 621 641 EnclosedCheck(copies); 642 } 622 643 623 644 return copies; … … 637 658 public static List<Item> UnreelLine(Item toUnreelFrom, boolean constrain) { 638 659 // the Item must already have one line to be unreeled from 639 if (toUnreelFrom == null || toUnreelFrom.getLines().size() < 1) 660 if (toUnreelFrom == null || toUnreelFrom.getLines().size() < 1) { 640 661 return null; 662 } 641 663 642 664 List<Item> unreel = new ArrayList<Item>(2); … … 670 692 if (item.isLineEnd()) { 671 693 // if there are multiple ends in the list, return 672 if (origEnd != null) 694 if (origEnd != null) { 673 695 return null; 696 } 674 697 675 698 origEnd = item; … … 747 770 // if there are no line endpoints on the Frame, then there can't be an 748 771 // enclosure 749 if (lineEnds.size() == 0) 772 if (lineEnds.size() == 0) { 750 773 return; 774 } 751 775 752 776 // Now find go through line ends and see if any are annotation items … … 757 781 if (item.isAnnotation()) { 758 782 Collection<Item> connected = item.getAllConnected(); 759 for (Item i : connected) 783 for (Item i : connected) { 760 784 i.setConnectedToAnnotation(true); 785 } 761 786 lineEnds.removeAll(connected); 762 787 } … … 780 805 i.setEnclosedList(null); 781 806 // Add line ends joined to 2 other lines 782 if (i.getLines().size() == 2) 807 if (i.getLines().size() == 2) { 783 808 lineEnds.add(i); 809 } 784 810 } 785 811 } … … 787 813 // if there are no line endpoints on the Frame, then there can't be an 788 814 // enclosure 789 if (lineEnds.size() == 0) 815 if (lineEnds.size() == 0) { 790 816 return; 817 } 791 818 792 819 // New approach … … 797 824 Collection<Item> connectedLineEnds = new LinkedHashSet<Item>(); 798 825 for (Item itemToCheck : connected) { 799 if (itemToCheck.isLineEnd()) 826 if (itemToCheck.isLineEnd()) { 800 827 connectedLineEnds.add(itemToCheck); 828 } 801 829 } 802 830 // Check that all the line ends are in our lineEnds list … … 833 861 i.setEnclosedList(null); 834 862 835 if (i.getLines().size() == 2) 863 if (i.getLines().size() == 2) { 836 864 lineEnds.add(i); 865 } 837 866 } 838 867 } … … 840 869 // if there are no line endpoints on the Frame, then there can't be an 841 870 // enclosure 842 if (lineEnds.size() == 0) 871 if (lineEnds.size() == 0) { 843 872 return; 873 } 844 874 845 875 // TODO optimise this code!! … … 853 883 _path.add(l.getOppositeEnd(searchFor)); 854 884 855 for (Item i : _path) 885 for (Item i : _path) { 856 886 i.setEnclosedList(_path); 887 } 857 888 858 889 _path = new ArrayList<Item>(0); … … 869 900 870 901 private static boolean traverse(Item toFind, Item searchFrom) { 871 if (toFind == null || searchFrom == null || !searchFrom.isLineEnd()) 902 if (toFind == null || searchFrom == null || !searchFrom.isLineEnd()) { 872 903 return false; 873 874 if (searchFrom.getLines().size() != 2) 904 } 905 906 if (searchFrom.getLines().size() != 2) { 875 907 return false; 876 877 if (toFind == searchFrom) 908 } 909 910 if (toFind == searchFrom) { 878 911 return true; 912 } 879 913 880 914 for (Line l : searchFrom.getLines()) { … … 924 958 public static boolean isVisible(Frame fromFrame, Item i) 925 959 { 926 if (fromFrame == null) return false; 960 if (fromFrame == null) { 961 return false; 962 } 927 963 928 964 Frame parent = i.getParent(); … … 939 975 public static AxisAlignedBoxBounds expandRectangle(AxisAlignedBoxBounds r, int n) 940 976 { 941 if (r == null) return null; 977 if (r == null) { 978 return null; 979 } 942 980 943 981 return new AxisAlignedBoxBounds(r.getMinX() - (n >> 1), r.getMinY() - (n >> 1), r.getWidth() + n, r.getHeight() + n); … … 1022 1060 if (i instanceof WidgetEdge) { 1023 1061 WidgetEdge we = (WidgetEdge) i; 1024 if (!iWidgets.contains(we.getWidgetSource())) 1062 if (!iWidgets.contains(we.getWidgetSource())) { 1025 1063 iWidgets.add(we.getWidgetSource()); 1064 } 1026 1065 } else if (i instanceof WidgetCorner) { 1027 1066 WidgetCorner wc = (WidgetCorner) i; 1028 if (!iWidgets.contains(wc.getWidgetSource())) 1067 if (!iWidgets.contains(wc.getWidgetSource())) { 1029 1068 iWidgets.add(wc.getWidgetSource()); 1069 } 1030 1070 } 1031 1071 } … … 1055 1095 public static void Justify(Frame frame) 1056 1096 { 1057 if (frame == null) return; 1097 if (frame == null) { 1098 return; 1099 } 1058 1100 EnclosedCheck(frame.getItems()); 1059 1101 Justify(frame.getItems());
Note:
See TracChangeset
for help on using the changeset viewer.