Changeset 1434 for trunk/src/org/expeditee/gui/Frame.java
- Timestamp:
- 10/02/19 14:19:48 (5 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/Frame.java
r1430 r1434 20 20 21 21 import java.io.File; 22 import java.nio.file.Paths; 22 23 import java.sql.Time; 23 24 import java.util.ArrayList; … … 41 42 import org.expeditee.core.bounds.PolygonBounds; 42 43 import org.expeditee.encryption.items.EncryptionPermissionTriple; 44 import org.expeditee.encryption.items.surrogates.Label; 43 45 import org.expeditee.gio.EcosystemManager; 44 46 import org.expeditee.gio.gesture.Gesture; … … 190 192 private String _groupFrameName; 191 193 private Frame _groupFrame = null; 194 195 private List<String> labelsOnLastBodySet; 192 196 193 197 public enum BodyType { … … 353 357 */ 354 358 public List<Item> getSortedItems(boolean requireVisible) { 355 ItemsList listToLoopOver = _body;359 ItemsList listToLoopOver = getBody(true); 356 360 listToLoopOver.sort(); 357 361 return getItems(requireVisible, listToLoopOver); … … 389 393 throw new NullPointerException("i"); 390 394 } 391 return _body.contains(i);395 return getBody(true).contains(i); 392 396 } 393 397 … … 404 408 * @return the list of body text items. 405 409 */ 406 public List<Text> getBodyTextItems(boolean includeAnnotations) 407 { 410 public List<Text> getBodyTextItems(boolean includeAnnotations) { 411 ensureBody(); 412 408 413 List<Text> bodyTextItems = new ArrayList<Text>(); 409 414 … … 467 472 * found. 468 473 */ 469 public Item getItemWithID(int id) 470 { 471 for (Item i : _body) { 474 public Item getItemWithID(int id) { 475 for (Item i : getAllFrameItemsRaw()) { 472 476 if (i.getID() == id) { 473 477 return i; … … 761 765 _permissionTriple = new PermissionTriple(permission); 762 766 763 if ( _body.size() > 0) {767 if (getBody(false).size() > 0) { 764 768 refreshItemPermissions(permission.getPermission(_owner, groupMembers)); 765 769 } … … 787 791 _creationDate = date; 788 792 _modifiedDate = date; 789 for (Item i : _body) {793 for (Item i : getAllFrameItemsRaw()) { 790 794 i.setDateCreated(date); 791 795 } … … 855 859 856 860 public void invalidateSorted() { 857 _body.invalidateSorted();861 getBody(false).invalidateSorted(); 858 862 } 859 863 … … 871 875 if (item == null) { return; } 872 876 873 addItem(item, recalculate, _body);877 addItem(item, recalculate, getBody(false)); 874 878 if (item.isSurrogate()) { 875 addItem(item, recalculate, _surrogateItemsBody);879 addItem(item, recalculate, getSurrogateBody()); 876 880 } else { 877 addItem(item, recalculate, _primaryItemsBody);881 addItem(item, recalculate, getPrimaryBody()); 878 882 } 879 883 } … … 988 992 989 993 public void addAllItems(Collection<Item> toAdd) { 990 addAllItems(toAdd, _body);991 addAllItems(toAdd, _primaryItemsBody);994 addAllItems(toAdd, getBody(false)); 995 addAllItems(toAdd, getPrimaryBody()); 992 996 } 993 997 … … 1018 1022 1019 1023 public void removeItem(Item item, boolean recalculate) { 1020 removeItem(item, recalculate, _body);1024 removeItem(item, recalculate, getBody(false)); 1021 1025 if (item.isSurrogate()) { 1022 removeItem(item, recalculate, _surrogateItemsBody);1026 removeItem(item, recalculate, getSurrogateBody()); 1023 1027 Set<Item> primariesSurrogates = item.getPrimary().getSurrogates(); 1024 1028 primariesSurrogates.remove(item); 1025 1029 } else { 1026 removeItem(item, recalculate, _primaryItemsBody);1030 removeItem(item, recalculate, getPrimaryBody()); 1027 1031 } 1028 1032 } … … 1075 1079 } 1076 1080 1077 public void undo() 1078 { 1079 boolean bReparse = false; 1080 boolean bRecalculate = false; 1081 public void undo() { 1082 boolean reparse = false; 1083 boolean recalculate = false; 1081 1084 1082 1085 if (_undo.size() <= 0) { … … 1092 1095 _redo.push(undo); 1093 1096 for(Item i : undo.items) { 1094 _body.add(i);1095 bReparse |= i.hasOverlay();1096 bRecalculate |= i.recalculateWhenChanged();1097 this.addItem(i); 1098 reparse |= i.hasOverlay(); 1099 recalculate |= i.recalculateWhenChanged(); 1097 1100 if (i instanceof Line) { 1098 1101 Line line = (Line) i; … … 1105 1108 break; 1106 1109 case movement: 1107 ItemsList changed = new ItemsList(_body); 1108 changed.retainHistory(undo.items); 1110 ItemsList body = getBody(true); 1111 ItemsList changed = new ItemsList(body); 1112 changed.retainAll(undo.items); 1109 1113 _redo.push(new History(changed, History.Type.movement)); 1110 1114 for(Item i : undo.items) { 1111 1115 int index; 1112 if(i.isVisible() && (index = _body.indexOf(i)) != -1) {1113 _body.set(index, i);1116 if(i.isVisible() && (index = body.indexOf(i)) != -1) { 1117 body.set(index, i); 1114 1118 } 1115 1119 } … … 1121 1125 StandardGestureActions.refreshHighlights(); 1122 1126 1123 if ( bReparse) {1127 if (reparse) { 1124 1128 FrameUtils.Parse(this, false, false); 1125 1129 } else { 1126 notifyObservers( bRecalculate);1130 notifyObservers(recalculate); 1127 1131 } 1128 1132 … … 1152 1156 _undo.push(redo); 1153 1157 for(Item i : redo.items) { 1154 _body.remove(i); 1158 this.removeItem(i); 1159 //_body.remove(i); 1155 1160 bReparse |= i.hasOverlay(); 1156 1161 bRecalculate |= i.recalculateWhenChanged(); … … 1165 1170 break; 1166 1171 case movement: 1167 ItemsList changed = new ItemsList(_body); 1168 changed.retainHistory(redo.items); 1172 ItemsList body = getBody(true); 1173 ItemsList changed = new ItemsList(body); 1174 changed.retainAll(redo.items); 1169 1175 _undo.push(new History(changed, History.Type.movement)); 1170 1176 for(Item i : redo.items) { 1171 1177 int index; 1172 if(i.isVisible() && (index = _body.indexOf(i)) != -1) {1173 _body.set(index, i);1178 if(i.isVisible() && (index = body.indexOf(i)) != -1) { 1179 body.set(index, i); 1174 1180 } 1175 1181 } … … 1335 1341 // s.append(String.format("Last Mod. User: %s%n", _modifiedUser)); 1336 1342 // s.append(String.format("Last Mod. Date: %s%n", _modifiedDate)); 1337 s.append(String.format("Items: %d%n", _body.size()));1343 s.append(String.format("Items: %d%n", getAllFrameItemsRaw().size())); 1338 1344 return s.toString(); 1339 1345 } … … 1379 1385 { 1380 1386 // Check that this item is on the current frame 1381 if (! _body.contains(from)) {1387 if (!getBody(true).contains(from)) { 1382 1388 return null; 1383 1389 } … … 1789 1795 * Removes all non-title non-annotation items from this Frame. All removed 1790 1796 * items are added to the backup-stack. 1791 */ 1792 public void clear(boolean keepAnnotations) 1797 */ 1798 @Deprecated 1799 public void clearDeprecated(boolean keepAnnotations) 1793 1800 { 1794 1801 ItemsList newBody = new ItemsList(); … … 1814 1821 change(); 1815 1822 1823 if (!keepAnnotations && _annotations != null) { 1824 _annotations.clear(); 1825 } 1826 } 1827 1828 /** 1829 * Removes all items from the Frame except the Title Item and optionally the annotations. 1830 * All removed items are added to the backup-stack. 1831 * 1832 * @param keepAnnotations true is annotations are not to be removed from the frame. 1833 */ 1834 public void clear(boolean keepAnnotations) { 1835 ItemsList body = getBody(true); 1836 ItemsList deleted = new ItemsList(); 1837 1838 for (Item bodyItem: body) { 1839 boolean isAnnotationToKeep = bodyItem.isAnnotation() && keepAnnotations; 1840 boolean isFrameTitle = bodyItem.isFrameTitle(); 1841 boolean isToBeRetained = isFrameTitle || isAnnotationToKeep; 1842 if (isToBeRetained) { 1843 continue; 1844 } 1845 1846 this.removeItem(bodyItem); 1847 deleted.add(bodyItem); 1848 } 1849 1850 addToUndoDelete(deleted); 1851 change(); 1852 1816 1853 if (!keepAnnotations && _annotations != null) { 1817 1854 _annotations.clear(); … … 1950 1987 */ 1951 1988 public String getFramesetPath() { 1952 return this.getPath() + File.separator + this.getFramesetName() + File.separator;1989 return Paths.get(this.getPath()).resolve(this.getFramesetName()).toString() + File.separator; 1953 1990 } 1954 1991 … … 2290 2327 2291 2328 for (Overlay o : getOverlays()) { 2292 for(Item i : o.Frame. _body) {2329 for(Item i : o.Frame.getBody(false)) { 2293 2330 i.setOverlayPermission(o.permission); 2294 2331 } … … 2568 2605 } 2569 2606 2607 /** 2608 * Returns a list of items for the specified BodyType. 2609 * 2610 * Asking for the primary or surrogate items gives you exactly those. 2611 * 2612 * Asking for the body items is a weird case because the body list is 2613 * transitory. Therefore, when asking for the body items, this 2614 * function assumes that you want all items, reguardless of if they 2615 * are primaries or surrogates. As of 20/08/2019, there are no places 2616 * in the code that asks for the body items to save. 2617 * @param type 2618 * @return 2619 */ 2570 2620 public List<Item> getItemsToSave(BodyType type) { 2571 2621 assert(!type.equals(BodyType.BodyDisplay)); … … 2574 2624 return getItemsToSave(_surrogateItemsBody); 2575 2625 case BodyDisplay: 2576 return getItemsToSave( _body);2626 return getItemsToSave(new ItemsList(getAllFrameItemsRaw())); 2577 2627 case PrimaryBody: 2578 2628 default: … … 2632 2682 2633 2683 public Collection<Item> getAllItems() { 2634 ItemsList allItems = new ItemsList( _body);2684 ItemsList allItems = new ItemsList(getBody(true)); 2635 2685 2636 2686 allItems.addAll(_overlayItems); … … 2721 2771 } 2722 2772 2723 public void dispose()2724 {2773 @Deprecated 2774 public void disposeDeprecated() { 2725 2775 clearObservers(); 2726 2776 … … 2732 2782 _body = null; 2733 2783 _frameName = null; 2784 } 2785 2786 /** 2787 * Disposes off all references associated with this frame. 2788 * This operation is NOT REVERSEABLE through the history. 2789 */ 2790 public void dispose() { 2791 clearObservers(); 2792 2793 List<Item> allFrameItems = getAllFrameItemsRaw(); 2794 2795 for (Item i: allFrameItems) { 2796 i.dispose(); 2797 } 2798 2799 _frameName.dispose(); 2800 _frameName = null; 2801 getBody(false).clear(); 2802 getPrimaryBody().clear(); 2803 getSurrogateBody().clear(); 2734 2804 } 2735 2805 … … 2800 2870 2801 2871 public void moveItemToBodyHiddenDueToPermission(final Item i) { 2802 _body.remove(i);2872 getBody(true).remove(i); 2803 2873 _bodyHiddenDueToPermissions.add(i); 2804 2874 } … … 2808 2878 _bodyHiddenDueToPermissions.remove(i); 2809 2879 i.setPermission(newPermission); 2810 _body.add(i);2880 getBody(true).add(i); 2811 2881 } 2812 2882 } … … 2821 2891 } 2822 2892 2823 for (Item i : _body) {2893 for (Item i : getBody(false)) { 2824 2894 if (i == null) { 2825 2895 continue; … … 2950 3020 } 2951 3021 2952 public ItemsList getBody() { 3022 public ItemsList getBody(boolean respectSurrogateMode) { 3023 if (respectSurrogateMode) { ensureBody(); } 2953 3024 return _body; 2954 3025 } 3026 3027 private void ensureBody() { 3028 List<String> accessibleLabelsNames = Label.getAccessibleLabelsNames(getPrimaryBody()); 3029 if (!accessibleLabelsNames.equals(labelsOnLastBodySet)) { 3030 this.parse(); 3031 } 3032 } 3033 3034 protected void setBody(List<Item> newBody, List<String> labelsOnSet) { 3035 _body.clear(); 3036 _body.addAll(newBody); 3037 this.labelsOnLastBodySet = labelsOnSet; 3038 } 3039 2955 3040 protected ItemsList getPrimaryBody() { 2956 3041 return _primaryItemsBody; … … 2959 3044 return _surrogateItemsBody; 2960 3045 } 3046 3047 3048 /** 3049 * Gets all the items on the frame, regardless of whether they are primary or surrogate items. 3050 * 3051 * Bryce says: This function will likely only ever be used inside Frame itself, as callers from 3052 * outside Frame should care about what the state of the Frame. 3053 * @return 3054 */ 3055 private List<Item> getAllFrameItemsRaw() { 3056 Collection<Item> primaries = getPrimaryBody().underlying(); 3057 Collection<Item> surrogateBody = getSurrogateBody().underlying(); 3058 primaries.addAll(surrogateBody); 3059 List<Item> allFrameItems = primaries.stream().distinct().collect(Collectors.toList()); 3060 return allFrameItems; 3061 } 2961 3062 }
Note:
See TracChangeset
for help on using the changeset viewer.