Changeset 67 for trunk/src/org/expeditee/gui/Frame.java
- Timestamp:
- 05/19/08 12:03:18 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/Frame.java
r56 r67 41 41 42 42 // The various attributes of this Frame 43 /**44 * TODO: Change these to non-string attributes (where applicable). All45 * processing to\from Java types should be done in KMSReader and KMSWriter.46 */47 43 private String _frameset = null; 48 44 49 45 private int _number = -1; 50 46 51 private int _version = 1; 52 53 private int _fversion = -1; 47 private int _version = 0; 54 48 55 49 private String _protection = null; … … 90 84 91 85 public static List<Item> FreeItems = new ArrayList<Item>(); 92 86 93 87 // for drawing purposes 94 88 private List<InteractiveWidget> _iWidgets = new ArrayList<InteractiveWidget>(); … … 101 95 private Text _frameName = null; 102 96 103 // private Text _template = UserSettings.ItemTemplate.copy();104 105 97 private List<Overlay> _overlays = new ArrayList<Overlay>(); 106 98 … … 122 114 public void setBuffer(VolatileImage newBuffer) { 123 115 _buffer = newBuffer; 124 // setBufferValid(true);125 116 } 126 117 127 118 public boolean isBufferValid() { 128 if (_buffer != null &&_buffer.contentsLost())119 if (_buffer == null || _buffer.contentsLost()) 129 120 return false; 130 121 … … 132 123 } 133 124 134 p ublicvoid setBufferValid(boolean newValue) {125 private void setBufferValid(boolean newValue) { 135 126 _validBuffer = newValue; 136 127 } … … 147 138 i.setID(++_lineCount); 148 139 } 149 140 150 141 /** 151 142 * 152 143 * @return The interactive widgets that are currently ancored in this frame. 153 * Hence it exlcudes free-widgets. Returns a copy144 * Hence it exlcudes free-widgets. Returns a copy 154 145 */ 155 146 public List<InteractiveWidget> getInteractiveWidgets() { … … 181 172 _change = value; 182 173 183 if (_change) {174 if (_change) { 184 175 setBufferValid(false); 185 176 _saved = false; … … 204 195 _sorted = true; 205 196 } 206 197 207 198 List<Item> visibleItems = new ArrayList<Item>(); 208 209 for (Item i: _body) {199 200 for (Item i : _body) { 210 201 if (i.isVisible()) 211 202 visibleItems.add(i); 212 203 } 213 204 214 205 return visibleItems; 215 206 } 216 217 /** 218 * @param i Item to check if contained in this frame 207 208 /** 209 * @param i 210 * Item to check if contained in this frame 219 211 * @return True if this frame contains i. 220 212 */ 221 213 public boolean containsItem(Item i) { 222 if (i == null) throw new NullPointerException("i"); 214 if (i == null) 215 throw new NullPointerException("i"); 223 216 return _body.contains(i); 224 217 } … … 234 227 for (Item i : getItems()) { 235 228 // only add up normal body text items 236 if ((i instanceof Text) &&237 (includeAnnotations || !i.isAnnotation())) {229 if ((i instanceof Text) 230 && (includeAnnotations || !i.isAnnotation())) { 238 231 bodyTextItems.add((Text) i); 239 232 } … … 241 234 bodyTextItems.remove(getTitle()); 242 235 243 return bodyTextItems; 236 return bodyTextItems; 244 237 } 245 238 … … 316 309 frameTitle.stripFirstWord(); 317 310 } 318 //TODO Widgets... check this out 319 // Brook: Cannot figure what is going on above... widget annot titles should be stripped always 320 if (ItemUtils.isTag(frameTitle, ItemUtils.GetTag(ItemUtils.TAG_IWIDGET))) { 311 // TODO Widgets... check this out 312 // Brook: Cannot figure what is going on above... widget annot titles 313 // should be stripped always 314 if (ItemUtils 315 .isTag(frameTitle, ItemUtils.GetTag(ItemUtils.TAG_IWIDGET))) { 321 316 frameTitle.stripFirstWord(); 322 317 } … … 425 420 426 421 for (Item i : _body) 427 if (i.isVisible() /* && i != _frameName*/&& i.intersects(poly)) {422 if (i.isVisible() /* && i != _frameName */&& i.intersects(poly)) { 428 423 if (!results.contains(i)) 429 424 results.add(i); … … 462 457 */ 463 458 public void setFrameNumber(int number) { 459 assert (number >= 0); 460 461 if (_number == number) 462 return; 463 464 464 _number = number; 465 465 boolean oldchange = _change; … … 469 469 if (_frameName != null) { 470 470 id = _frameName.getID(); 471 } else {471 } else { 472 472 id = -1 * getNextItemID(); 473 473 } … … 493 493 494 494 /** 495 * Sets the version of this Frame to the given String.495 * Increments the version of this Frame to the given String. 496 496 * 497 497 * @param version … … 500 500 public void setVersion(int version) { 501 501 _version = version; 502 }503 504 /**505 * Sets the format version of this Frame to the given String.506 *507 * @param version508 * The format version to use for this Frame.509 */510 public void setFormatVersion(int version) {511 _fversion = version;512 502 } 513 503 … … 593 583 if (item != null) { 594 584 if (_body.contains(item)) { 595 // System.out.println("Item (" + item.getClass().getSimpleName()596 // 585 // System.out.println("Item (" + item.getClass().getSimpleName() 586 // + ") with ID " + item.getID() + " already in body."); 597 587 return; 598 588 } … … 600 590 if (item instanceof Line) 601 591 _lineCount++; 602 592 603 593 _itemCount = Math.max(_itemCount, item.getID()); 604 594 … … 609 599 610 600 item.setMaxSize(FrameGraphics.getMaxFrameSize()); 611 // add widget items to the list of widgets601 // add widget items to the list of widgets 612 602 if (item instanceof WidgetCorner) { 613 InteractiveWidget iw = ((WidgetCorner)item).getWidgetSource(); 614 if (!this._iWidgets.contains(iw)) { // A set would have been best 615 _iWidgets.add(iw); 603 InteractiveWidget iw = ((WidgetCorner) item).getWidgetSource(); 604 if (!this._iWidgets.contains(iw)) { // A set would have been 605 // best 606 _iWidgets.add(iw); 616 607 } 617 608 } 618 619 item.onParentStateChanged(new ItemParentStateChangedEvent( 620 this,ItemParentStateChangedEvent.EVENT_TYPE_ADDED));609 610 item.onParentStateChanged(new ItemParentStateChangedEvent(this, 611 ItemParentStateChangedEvent.EVENT_TYPE_ADDED)); 621 612 622 613 change(); … … 648 639 649 640 public void removeItem(Item item) { 650 if (_body.remove(item)) 641 if (_body.remove(item)) { 651 642 change(); 652 653 // Remove widgets from the widget list 654 if (item != null) { 655 item.onParentStateChanged(new ItemParentStateChangedEvent( 656 this, ItemParentStateChangedEvent.EVENT_TYPE_REMOVED)); 657 if (item instanceof WidgetCorner) { 658 _iWidgets.remove(((WidgetCorner)item).getWidgetSource()); 659 } 660 } 661 643 // Remove widgets from the widget list 644 if (item != null) { 645 item.onParentStateChanged(new ItemParentStateChangedEvent(this, 646 ItemParentStateChangedEvent.EVENT_TYPE_REMOVED)); 647 if (item instanceof WidgetCorner) { 648 _iWidgets.remove(((WidgetCorner) item).getWidgetSource()); 649 } 650 } 651 } 662 652 } 663 653 … … 760 750 * @return The version of this Frame. 761 751 */ 752 public int getVersion(boolean increment) { 753 // System.out.println("Version: " + _version); 754 if (increment) 755 _version++; 756 return _version; 757 } 758 762 759 public int getVersion() { 763 return _version; 764 } 765 766 public int getFormatVersion() { 767 return _fversion; 760 return getVersion(true); 768 761 } 769 762 … … 843 836 s += "Name: " + _frameset + _number + "\n"; 844 837 s += "Version: " + _version + "\n"; 845 s += "Format Version: " + _fversion + "\n";846 838 s += "Protection: " + _protection + "\n"; 847 839 s += "Owner: " + _owner + "\n"; … … 935 927 * @param overlay 936 928 * The Frame to add 937 * 929 * 938 930 * @throws NullPointerException 939 * If overlay is null.931 * If overlay is null. 940 932 */ 941 933 public void addOverlay(Overlay overlay) { 942 if (overlay == null) throw new NullPointerException("overlay"); 943 if (_overlays.contains(overlay)) return; 944 934 if (overlay == null) 935 throw new NullPointerException("overlay"); 936 // make sure we dont add this frame as an overlay of itself 937 if (overlay.Frame == this) 938 return; 939 940 if (_overlays.contains(overlay)) 941 return; 942 945 943 _overlays.add(overlay); 946 947 // Items must be notified that they have been added to this frame via the overlay... 944 945 // Items must be notified that they have been added to this frame via 946 // the overlay... 948 947 List<Item> items = new LinkedList<Item>(); 949 FrameGraphics.AddAllOverlayItems(items, overlay.Frame, new LinkedList<Frame>()); 948 FrameGraphics.AddAllOverlayItems(items, overlay.Frame, 949 new LinkedList<Frame>()); 950 950 for (Item i : items) { 951 i.onParentStateChanged(new ItemParentStateChangedEvent( 952 this, 953 ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, 951 i.onParentStateChanged(new ItemParentStateChangedEvent(this, 952 ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, 954 953 overlay.Level)); 955 954 } … … 957 956 958 957 /** 959 * Removes the given overlay from the list of overlays being drawn with this Frame. 958 * Removes the given overlay from the list of overlays being drawn with this 959 * Frame. 960 960 * 961 961 * @param overlay 962 962 * The overlay to remove 963 * 963 * 964 964 * @throws NullPointerException 965 * If overlay is null.965 * If overlay is null. 966 966 */ 967 967 public void removeOverlay(Overlay overlay) { 968 if (overlay == null) throw new NullPointerException("overlay"); 969 968 if (overlay == null) 969 throw new NullPointerException("overlay"); 970 970 971 this._overlays.remove(overlay); 971 972 // Items must be notified that they have been removed from this frame via the overlay... 972 973 // Items must be notified that they have been removed from this frame 974 // via the overlay... 973 975 List<Item> items = new LinkedList<Item>(); 974 FrameGraphics.AddAllOverlayItems(items, overlay.Frame, new LinkedList<Frame>()); 976 FrameGraphics.AddAllOverlayItems(items, overlay.Frame, 977 new LinkedList<Frame>()); 975 978 for (Item i : items) { 976 i.onParentStateChanged(new ItemParentStateChangedEvent( 977 this, 978 ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY, 979 i.onParentStateChanged(new ItemParentStateChangedEvent(this, 980 ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY, 979 981 overlay.Level)); 980 982 } 981 983 } 982 983 /** 984 * Removes the given Frame from the list of overlayed Frames being drawn with985 * this Frame.984 985 /** 986 * Removes the given Frame from the list of overlayed Frames being drawn 987 * with this Frame. 986 988 * 987 989 * @param overlayedFrame 988 990 * The Frame to remove 989 * 991 * 990 992 * @throws NullPointerException 991 * If overlayedFrame is null.993 * If overlayedFrame is null. 992 994 */ 993 995 public void removeOverlay(Frame overlayedFrame) { 994 if (overlayedFrame == null) throw new NullPointerException("overlay"); 995 996 if (overlayedFrame == null) 997 throw new NullPointerException("overlay"); 998 996 999 // Locate the oveylay(s) that match this 997 1000 List<Overlay> overlaysToRemove = new LinkedList<Overlay>(); 998 1001 for (Overlay o : _overlays) { 999 if (overlayedFrame.equals(o.Frame)) overlaysToRemove.add(o); 1000 } 1001 for (Overlay o : overlaysToRemove) { // must be enumerated seperate to above... 1002 if (overlayedFrame.equals(o.Frame)) 1003 overlaysToRemove.add(o); 1004 } 1005 for (Overlay o : overlaysToRemove) { // must be enumerated seperate 1006 // to above... 1002 1007 removeOverlay(o); 1003 1008 } 1004 1009 1005 1010 } 1006 1011 … … 1010 1015 return l; 1011 1016 } 1012 1013 /** 1014 * @return All overlays seen by this frame (including its overlays' overlays). 1017 1018 /** 1019 * @return All overlays seen by this frame (including its overlays' 1020 * overlays). 1015 1021 */ 1016 1022 public List<Overlay> getOverlaysDeep() { … … 1019 1025 return l; 1020 1026 } 1021 1022 private boolean getOverlaysDeep(List<Overlay> overlays, Frame overlay, List<Frame> seenOverlays) { 1023 1024 if (seenOverlays.contains(overlay)) 1025 return false; 1026 1027 seenOverlays.add(overlay); 1028 1029 for (Overlay o : overlay.getOverlays()) { 1030 if (getOverlaysDeep(overlays, o.Frame, seenOverlays)) { 1031 overlays.add(o); 1032 } 1033 } 1034 1035 return true; 1036 } 1037 1027 1028 private boolean getOverlaysDeep(List<Overlay> overlays, Frame overlay, 1029 List<Frame> seenOverlays) { 1030 1031 if (seenOverlays.contains(overlay)) 1032 return false; 1033 1034 seenOverlays.add(overlay); 1035 1036 for (Overlay o : overlay.getOverlays()) { 1037 if (getOverlaysDeep(overlays, o.Frame, seenOverlays)) { 1038 overlays.add(o); 1039 } 1040 } 1041 1042 return true; 1043 } 1044 1038 1045 /** 1039 1046 * Gets the overlay on this frame which owns the given item. 1040 * @param item The item - must not be null. 1041 * @return The overlay that contains the itm. Null if no overlay owns the item. 1047 * 1048 * @param item 1049 * The item - must not be null. 1050 * @return The overlay that contains the itm. Null if no overlay owns the 1051 * item. 1042 1052 */ 1043 1053 public Overlay getOverlayOwner(Item item) { 1044 if (item == null) throw new NullPointerException("item"); 1054 if (item == null) 1055 throw new NullPointerException("item"); 1045 1056 List<Overlay> overlays = getOverlaysDeep(); 1046 1057 for (Overlay l : overlays) { 1047 //if (l.Frame.containsItem(item)) return l; 1048 if (item.getParent() == l.Frame) return l; 1049 } 1050 1058 // if (l.Frame.containsItem(item)) return l; 1059 if (item.getParent() == l.Frame) 1060 return l; 1061 } 1062 1051 1063 return null; 1052 1064 } … … 1089 1101 List<Item> copies = ItemUtils.CopyItems(toMergeWith.getItems()); 1090 1102 copies.remove(toMergeWith.getFrameNameItem()); 1091 1103 1092 1104 for (Item i : copies) { 1093 1105 if (i.getID() >= 0) { … … 1143 1155 /** 1144 1156 * Creates a new text item with the given text. 1157 * 1145 1158 * @param text 1146 1159 * @return
Note:
See TracChangeset
for help on using the changeset viewer.