Changeset 1102 for trunk/src/org/expeditee/gui/Frame.java
- Timestamp:
- 05/10/18 16:04:51 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/Frame.java
r998 r1102 19 19 package org.expeditee.gui; 20 20 21 import java.awt.Color;22 import java.awt.Image;23 import java.awt.Polygon;24 import java.awt.image.ImageObserver;25 import java.awt.image.VolatileImage;26 21 import java.sql.Time; 27 22 import java.util.ArrayList; … … 37 32 38 33 import org.expeditee.actions.Simple; 34 import org.expeditee.core.Colour; 35 import org.expeditee.core.Image; 36 import org.expeditee.core.bounds.PolygonBounds; 37 import org.expeditee.gio.gesture.StandardGestureActions; 38 import org.expeditee.gio.input.StandardInputEventListeners; 39 import org.expeditee.gio.input.KBMInputEvent.Key; 39 40 import org.expeditee.io.Conversion; 40 41 import org.expeditee.items.Constraint; … … 50 51 import org.expeditee.items.UserAppliedPermission; 51 52 import org.expeditee.items.XRayable; 52 import org.expeditee.items.widgets. InteractiveWidget;53 import org.expeditee.items.widgets.Widget; 53 54 import org.expeditee.items.widgets.WidgetCorner; 54 55 import org.expeditee.settings.UserSettings; … … 66 67 * 67 68 */ 68 public class Frame implements ImageObserver { 69 public class Frame { 70 71 /** The frame number to indicate this is a virtual frame. */ 72 public static final int VIRTUAL_FRAME_NUMBER = -1; 73 74 /** The background colour the frame name should take if the frame has user permission level 'none'. */ 75 public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_NONE = Colour.FromRGB255(255, 220, 220); 76 /** The background colour the frame name should take if the frame has user permission level 'followLinks'. */ 77 public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FOLLOW_LINKS = Colour.FromRGB255(255, 230, 135); 78 /** The background colour the frame name should take if the frame has user permission level 'copy'. */ 79 public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_COPY = Colour.FromRGB255(255, 255, 155); 80 /** The background colour the frame name should take if the frame has user permission level 'createFrames'. */ 81 public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_CREATE_FRAMES = Colour.FromRGB255(220, 255, 220); 82 /** The background colour the frame name should take if the frame has user permission level 'full'. */ 83 public static final Colour FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FULL = null; 69 84 70 85 private boolean _protectionChanged = false; 71 72 public boolean isReadOnly() {73 return !_frameName.hasPermission(UserAppliedPermission.full)74 && !_protectionChanged;75 }76 86 77 87 // The various attributes of this Frame … … 95 105 96 106 // Background color is clear 97 private Colo r _background = null;107 private Colour _background = null; 98 108 99 109 // Foreground color is automatic by default 100 private Colo r _foreground = null;110 private Colour _foreground = null; 101 111 102 112 private String path; … … 105 115 106 116 private boolean _sorted = true; 107 108 // The items contained in this Frame 109 // records whether a change has been made to this Frame (for saving 110 // purposes). 117 118 /** Whether the frame has changed and therefore needs saving. */ 111 119 private boolean _change = false; 112 120 121 /** Whether the frame has been saved. */ 113 122 private boolean _saved = false; 114 115 private static final class History {116 public enum Type {117 deletion,118 movement119 }120 public final List<Item> items;121 public final Type type;122 123 public History(Collection<Item> items, Type type) {124 this.items = new LinkedList<Item>(items);125 this.type = type;126 }127 128 public String toString() {129 return this.type.toString() + ":\n" + this.items.toString();130 }131 }132 123 133 124 // list of deleted items that can be restored … … 141 132 142 133 // for drawing purposes 143 private List< InteractiveWidget> _iWidgets = new ArrayList<InteractiveWidget>();134 private List<Widget> _iWidgets = new ArrayList<Widget>(); 144 135 145 136 private int _lineCount = 0; … … 170 161 private Text _dotTemplate = TemplateSettings.DotTemplate.get().copy(); 171 162 172 /** 173 * Default constructor, nothing is set. 174 */ 175 public Frame() { 176 } 177 178 public void reset() { 163 Map<String, Text> _annotations = null; 164 165 private Collection<FrameObserver> _observers = new HashSet<FrameObserver>(); 166 167 /** Default constructor, nothing is set. */ 168 public Frame() 169 { 170 } 171 172 public boolean isReadOnly() 173 { 174 return !_frameName.hasPermission(UserAppliedPermission.full) && !_protectionChanged; 175 } 176 177 public void reset() 178 { 179 179 refreshItemPermissions(UserAppliedPermission.full); 180 //System.out.println("Reset");181 180 resetDot(); 182 181 SessionStats.NewFrameSession(); 183 182 } 184 183 185 private void resetDot() { 184 private void resetDot() 185 { 186 186 _dotTemplate.setColor(TemplateSettings.ColorWheel.getSafe(1)); 187 187 _dotTemplate.setFillColor(TemplateSettings.FillColorWheel.getSafe(0)); 188 188 } 189 189 190 public void nextDot() { 191 _dotTemplate.setFillColor(ColorUtils.getNextColor(_dotTemplate 192 .getFillColor(), TemplateSettings.FillColorWheel.get(), null)); 193 _dotTemplate.setColor(ColorUtils.getNextColor(_dotTemplate.getColor(), 194 TemplateSettings.ColorWheel.get(), null)); 195 196 if (_dotTemplate.getColor() == null || _dotTemplate.getColor().equals(Color.white)) { 197 resetDot(); 198 } 199 } 200 201 public Image getBuffer() { 190 public void nextDot() 191 { 192 _dotTemplate.setFillColor(ColorUtils.getNextColor(_dotTemplate.getFillColor(), TemplateSettings.FillColorWheel.get(), null)); 193 _dotTemplate.setColor(ColorUtils.getNextColor(_dotTemplate.getColor(), TemplateSettings.ColorWheel.get(), null)); 194 if (_dotTemplate.getColor() == null || _dotTemplate.getColor().equals(Colour.WHITE)) resetDot(); 195 } 196 197 public Image getBuffer() 198 { 202 199 return _buffer; 203 200 } 204 201 205 public void setBuffer(Image newBuffer) { 202 public void setBuffer(Image newBuffer) 203 { 206 204 _buffer = newBuffer; 207 205 } 208 206 209 public boolean isBufferValid() { 210 if (_buffer == null 211 || (_buffer instanceof VolatileImage && ((VolatileImage) _buffer) 212 .contentsLost())) 213 return false; 207 public boolean isBufferValid() 208 { 209 if (_buffer == null) return false; 214 210 215 211 return _validBuffer; 216 212 } 217 213 218 private void setBufferValid(boolean newValue) { 214 private void setBufferValid(boolean newValue) 215 { 219 216 _validBuffer = newValue; 220 217 } 221 218 222 public int getNextItemID() { 219 public int getNextItemID() 220 { 223 221 return ++_itemCount; 224 222 } 225 223 226 public void updateIDs(List<Item> items) { 227 for (Item i : items) 228 if (!(i instanceof Line)) 224 public void updateIDs(List<Item> items) 225 { 226 for (Item i : items) { 227 if (!(i instanceof Line)) { 229 228 i.setID(getNextItemID()); 230 else229 } else { 231 230 i.setID(++_lineCount); 231 } 232 } 232 233 } 233 234 … … 237 238 * Hence it excludes free-widgets. Returns a copy 238 239 */ 239 public List<InteractiveWidget> getInteractiveWidgets() { 240 LinkedList<InteractiveWidget> clone = new LinkedList<InteractiveWidget>(); 240 public List<Widget> getInteractiveWidgets() 241 { 242 LinkedList<Widget> clone = new LinkedList<Widget>(); 241 243 clone.addAll(this._iWidgets); 242 244 return clone; … … 248 250 * @return True if this Frame has been altered, false otherwise. 249 251 */ 250 public boolean hasChanged() { 252 public boolean hasChanged() 253 { 251 254 // virtual frames are never saved 252 if (_number == -1) 253 return false; 255 if (_number == VIRTUAL_FRAME_NUMBER) return false; 254 256 255 257 return _change; … … 260 262 * 261 263 * @param value 262 * False if this Frame should be saved to disk, False otherwise. 263 */ 264 public void setChanged(boolean value) { 265 // System.out.println(getName() + " " + value); 266 boolean oldValue = _change; 267 268 // if (value) { 269 // notifyObservers(); 270 // } 271 272 if (oldValue == value) 273 return; 264 * True if this Frame should be saved to disk, False otherwise. 265 */ 266 public void setChanged(boolean value) 267 { 268 if (_change == value) return; 274 269 275 270 _change = value; … … 281 276 } 282 277 283 // private static int updateCount = 0;284 285 278 /** 286 279 * Notify items observing the data on this frame that the frame content has … … 290 283 * true if the frame should be recalculated first. 291 284 */ 292 public void notifyObservers(boolean bRecalculate) { 293 if (bRecalculate) { 294 recalculate(); 295 } 285 public void notifyObservers(boolean bRecalculate) 286 { 287 if (bRecalculate) recalculate(); 296 288 // Notify the frame listeners that the frame has changed 297 289 /* … … 301 293 * changing this frames observer list. 302 294 */ 303 Collection<FrameObserver> observersCopy = new LinkedList<FrameObserver>( 304 _observers); 295 Collection<FrameObserver> observersCopy = new LinkedList<FrameObserver>(_observers); 305 296 // System.out.println(++updateCount + " update"); 306 297 307 298 for (FrameObserver fl : observersCopy) { 308 if (/* !Item.isLocked(fl) && */fl.isVisible()) 309 fl.update(); 299 if (fl.isVisible()) fl.update(); 310 300 } 311 301 } 312 302 313 303 // indicates the frame has changed 314 public void change() { 304 public void change() 305 { 315 306 setChanged(true); 316 307 _interactableItems.clear(); … … 323 314 * @return The list of Item objects that are on this Frame. 324 315 */ 325 public List<Item> getItems(boolean visible) { 316 public List<Item> getItems(boolean visible) 317 { 326 318 if (!_sorted) { 327 for(int i = 0; i < _body.size();) 328 if(_body.get(i) == null) _body.remove(i); 329 else i++; 319 for(int i = 0; i < _body.size();) { 320 if(_body.get(i) == null) { 321 _body.remove(i); 322 } else { 323 i++; 324 } 325 } 330 326 Collections.sort(_body); 331 327 _sorted = true; … … 335 331 336 332 for (Item i : _body) { 337 if (i == null) 338 continue;333 if (i == null) continue; 334 339 335 if (i.isVisible() || (!visible && !i.isDeleted())) { 340 336 items.add(i); … … 345 341 } 346 342 347 public List<Item> getItems() { 343 /** TODO: Comment. cts16 */ 344 public List<Item> getItems() 345 { 348 346 return getItems(false); 349 347 } … … 354 352 * @return True if this frame contains i. 355 353 */ 356 public boolean containsItem(Item i) { 357 if (i == null) 358 throw new NullPointerException("i"); 354 public boolean containsItem(Item i) 355 { 356 if (i == null) throw new NullPointerException("i"); 357 359 358 return _body.contains(i); 360 359 } … … 372 371 * @return the list of body text items. 373 372 */ 374 public List<Text> getBodyTextItems(boolean includeAnnotations) { 373 public List<Text> getBodyTextItems(boolean includeAnnotations) 374 { 375 375 List<Text> bodyTextItems = new ArrayList<Text>(); 376 376 377 for (Item i : getItems(true)) { 377 378 // only add up normal body text items 378 if ((i instanceof Text) 379 && ((includeAnnotations && !((Text) i) 380 .isSpecialAnnotation()) || !i.isAnnotation()) 381 && !i.isLineEnd()) { 379 if ((i instanceof Text) && ((includeAnnotations && !((Text) i).isSpecialAnnotation()) || !i.isAnnotation()) && !i.isLineEnd()) { 382 380 bodyTextItems.add((Text) i); 383 381 } 384 382 } 383 385 384 bodyTextItems.remove(getTitleItem()); 386 385 … … 388 387 } 389 388 390 public Collection<Item> getNonAnnotationItems(boolean removeTitle) { 389 public Collection<Item> getNonAnnotationItems(boolean removeTitle) 390 { 391 391 Collection<Item> items = new ArrayList<Item>(); 392 392 for (Item i : getItems(true)) { 393 393 // only add up normal body text items 394 if (!i.isAnnotation()) { 395 items.add(i); 396 } 397 } 394 if (!i.isAnnotation()) items.add(i); 395 } 396 398 397 if (removeTitle) { 399 398 items.remove(getTitleItem()); 400 399 } 400 401 401 return items; 402 402 } … … 408 408 * @return the last non annotation text item. 409 409 */ 410 public Item getLastNonAnnotationTextItem() { 410 public Item getLastNonAnnotationTextItem() 411 { 411 412 List<Item> items = getItems(); 412 413 … … 431 432 * found. 432 433 */ 433 public Item getItemWithID(int id) { 434 for (Item i : _body) 435 if (i.getID() == id) 434 public Item getItemWithID(int id) 435 { 436 for (Item i : _body) { 437 if (i.getID() == id) { 436 438 return i; 437 439 } 440 } 438 441 return null; 439 442 } … … 445 448 * The title to assign to this Frame 446 449 */ 447 public void setTitle(String title) {448 if (title == null || title.equals(""))449 450 public void setTitle(String title) 451 { 452 if (title == null || title.equals("")) return; 450 453 451 454 boolean oldchange = _change; … … 476 479 // title = ItemUtils.StripTagSymbol(title); 477 480 frameTitle.setText(title); 478 // If the @ symbol is followed by numbering or a bullet remove that 479 // too 480 String autoBulletText = FrameKeyboardActions.getAutoBullet(title); 481 // If the @ symbol is followed by numbering or a bullet remove that too 482 String autoBulletText = StandardGestureActions.getAutoBullet(title); 481 483 if (autoBulletText.length() > 0) 482 484 frameTitle.stripFirstWord(); … … 485 487 // Brook: Cannot figure what is going on above... widget annot titles 486 488 // should be stripped always 487 if (ItemUtils.startsWithTag(frameTitle, ItemUtils 488 .GetTag(ItemUtils.TAG_IWIDGET))) { 489 if (ItemUtils.startsWithTag(frameTitle, ItemUtils.GetTag(ItemUtils.TAG_IWIDGET))) { 489 490 frameTitle.stripFirstWord(); 490 491 } … … 496 497 } 497 498 498 public Text getTitleItem() { 499 public Text getTitleItem() 500 { 499 501 List<Item> items = getVisibleItems(); 502 500 503 for (Item i : items) { 501 if (i instanceof Text && i.getX() < UserSettings.TitlePosition.get() 502 && i.getY() < UserSettings.TitlePosition.get()) 504 if (i instanceof Text && i.getX() < UserSettings.TitlePosition.get() && i.getY() < UserSettings.TitlePosition.get()) { 503 505 return (Text) i; 506 } 504 507 } 505 508 … … 507 510 } 508 511 509 public String getTitle() { 512 public String getTitle() 513 { 510 514 Text title = getTitleItem(); 511 if (title == null) 512 return getName(); 515 if (title == null) return getName(); 513 516 514 517 return title.getFirstLine(); 515 518 } 516 519 517 public Item getNameItem() { 520 public Item getNameItem() 521 { 518 522 return _frameName; 519 523 } 520 524 521 public Text getItemTemplate() {522 return getTemplate(TemplateSettings.ItemTemplate.get(),523 524 } 525 526 public Text getAnnotationTemplate() {527 Text t = getTemplate(TemplateSettings.AnnotationTemplate.get(),528 525 public Text getItemTemplate() 526 { 527 return getTemplate(TemplateSettings.ItemTemplate.get(), ItemUtils.TAG_ITEM_TEMPLATE); 528 } 529 530 public Text getAnnotationTemplate() 531 { 532 Text t = getTemplate(TemplateSettings.AnnotationTemplate.get(), ItemUtils.TAG_ANNOTATION_TEMPLATE); 529 533 530 534 if (t == null) { … … 535 539 } 536 540 537 public Text getStatTemplate() { 541 public Text getStatTemplate() 542 { 538 543 SessionStats.CreatedText(); 539 Text t = getTemplate(TemplateSettings.StatTemplate.get(), 540 ItemUtils.TAG_STAT_TEMPLATE); 544 Text t = getTemplate(TemplateSettings.StatTemplate.get(), ItemUtils.TAG_STAT_TEMPLATE); 541 545 542 546 if (t == null) { … … 547 551 } 548 552 549 public Item getTooltipTextItem(String tooltipText) { 553 public Item getTooltipTextItem(String tooltipText) 554 { 550 555 return getTextItem(tooltipText, TemplateSettings.TooltipTemplate.get().copy()); 551 556 } 552 557 553 public Item getStatsTextItem(String itemText) { 558 public Item getStatsTextItem(String itemText) 559 { 554 560 return getTextItem(itemText, getStatTemplate()); 555 561 } 556 562 557 public Item getTextItem(String itemText) { 563 public Item getTextItem(String itemText) 564 { 558 565 return getTextItem(itemText, getItemTemplate()); 559 566 } 560 567 561 private Item getTextItem(String itemText, Text template) { 568 private Item getTextItem(String itemText, Text template) 569 { 562 570 Text t = template; 563 571 // We dont want the stats to wrap at all 564 572 // t.setMaxWidth(Integer.MAX_VALUE); 565 t.setPosition(Display IO.getMouseX(), FrameMouseActions.getY());573 t.setPosition(DisplayController.getMousePosition()); 566 574 // The next line is needed to make sure the item is removed from the 567 575 // frame when picked up … … 571 579 } 572 580 573 public Text getCodeCommentTemplate() {574 Text t = getTemplate(TemplateSettings.CommentTemplate.get(),575 581 public Text getCodeCommentTemplate() 582 { 583 Text t = getTemplate(TemplateSettings.CommentTemplate.get(), ItemUtils.TAG_CODE_COMMENT_TEMPLATE); 576 584 577 585 if (t == null) { … … 592 600 * Item.intersects(shape) return true. 593 601 */ 594 public Collection<Item> getItemsWithin(Polygon poly) { 602 public Collection<Item> getItemsWithin(PolygonBounds poly) 603 { 595 604 Collection<Item> results = new LinkedHashSet<Item>(); 596 605 for (Item i : getVisibleItems()) { … … 606 615 } 607 616 608 for (Overlay o : _overlays.keySet()) 617 for (Overlay o : _overlays.keySet()) { 609 618 results.addAll(o.Frame.getItemsWithin(poly)); 610 619 } 620 611 621 for (Item i : getVectorItems()) { 612 622 if (i.intersects(poly)) { … … 626 636 * The name to use for this Frame. 627 637 */ 628 public void setFrameset(String name) { 638 public void setFrameset(String name) 639 { 629 640 _frameset = name; 630 641 } 631 642 632 public void setName(String framename) { 643 public void setName(String framename) 644 { 633 645 int num = Conversion.getFrameNumber(framename); 634 646 String frameset = Conversion.getFramesetName(framename, false); … … 643 655 * The number to set as the frame number 644 656 */ 645 public void setFrameNumber(int number) { 657 public void setFrameNumber(int number) 658 { 646 659 assert (number >= 0); 647 660 648 if (_number == number) 649 return; 661 if (_number == number) return; 650 662 651 663 _number = number; … … 659 671 id = -1 * getNextItemID(); 660 672 } 673 661 674 _frameName = new Text(id); 662 675 _frameName.setParent(this); … … 671 684 * @return The Frame number of this Frame or -1 if it is not set. 672 685 */ 673 public int getNumber() { 686 public int getNumber() 687 { 674 688 return _number; 675 689 } … … 681 695 * The version to use for this Frame. 682 696 */ 683 public void setVersion(int version) { 697 public void setVersion(int version) 698 { 684 699 _version = version; 685 700 } … … 691 706 * The protection to use for this Frame. 692 707 */ 693 public void setPermission(PermissionPair permission) { 694 if (_permissionPair != null && _permissionPair.getPermission(this._owner).equals(permission)) 708 public void setPermission(PermissionPair permission) 709 { 710 if (_permissionPair != null && _permissionPair.getPermission(this._owner).equals(permission)) { 695 711 _protectionChanged = true; 712 } 696 713 697 714 _permissionPair = new PermissionPair(permission); 698 715 699 if (_body.size() > 0) 700 refreshItemPermissions(permission.getPermission(_owner)); 716 if (_body.size() > 0) refreshItemPermissions(permission.getPermission(_owner)); 701 717 } 702 718 … … 707 723 * The owner to use for this Frame. 708 724 */ 709 public void setOwner(String owner) { 725 public void setOwner(String owner) 726 { 710 727 _owner = owner; 711 728 } … … 717 734 * The date to use for this Frame. 718 735 */ 719 public void setDateCreated(String date) { 736 public void setDateCreated(String date) 737 { 720 738 _creationDate = date; 721 739 _modifiedDate = date; … … 729 747 * 730 748 */ 731 public void resetDateCreated() { 749 public void resetDateCreated() 750 { 732 751 setDateCreated(Formatter.getDateTime()); 733 752 resetTimes(); … … 735 754 } 736 755 737 private void resetTimes() { 756 private void resetTimes() 757 { 738 758 setActiveTime(new Time(0)); 739 759 setDarkTime(new Time(0)); … … 746 766 * The user to set as the last modifying user. 747 767 */ 748 public void setLastModifyUser(String user) { 768 public void setLastModifyUser(String user) 769 { 749 770 _modifiedUser = user; 750 771 } … … 756 777 * The date to set as the last modified date. 757 778 */ 758 public void setLastModifyDate(String date) { 779 public void setLastModifyDate(String date) 780 { 759 781 _modifiedDate = date; 760 782 } … … 766 788 * The date to set as the last frozen date. 767 789 */ 768 public void setFrozenDate(String date) { 790 public void setFrozenDate(String date) 791 { 769 792 _frozenDate = date; 770 793 } 771 794 772 public void setResort(boolean value) { 795 public void setResort(boolean value) 796 { 773 797 _sorted = !value; 774 798 } … … 780 804 * The Item to add to this Frame. 781 805 */ 782 public void addItem(Item item) { 806 public void addItem(Item item) 807 { 783 808 addItem(item, true); 784 809 } 785 810 786 public void addItem(Item item, boolean recalculate) {787 if (item == null || item.equals(_frameName) || _body.contains(item))788 811 public void addItem(Item item, boolean recalculate) 812 { 813 if (item == null || item.equals(_frameName) || _body.contains(item)) return; 789 814 790 815 // When an annotation item is anchored the annotation list must be … … 794 819 } 795 820 796 if (item instanceof Line) 797 _lineCount++; 821 if (item instanceof Line) _lineCount++; 798 822 799 823 _itemCount = Math.max(_itemCount, item.getID()); … … 816 840 // add widget items to the list of widgets 817 841 if (item instanceof WidgetCorner) { 818 InteractiveWidget iw = ((WidgetCorner) item).getWidgetSource();842 Widget iw = ((WidgetCorner) item).getWidgetSource(); 819 843 if (!this._iWidgets.contains(iw)) { // A set would have been 820 if ( FrameMouseActions.isControlDown())844 if (StandardInputEventListeners.kbmStateListener.isKeyDown(Key.CTRL)) { 821 845 _iWidgets.add(iw); 822 else846 } else { 823 847 _iWidgets.add(0, iw); 824 }825 }826 827 item.onParentStateChanged(new ItemParentStateChangedEvent(this, 828 848 } 849 } 850 } 851 852 item.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED)); 829 853 830 854 // if (recalculate && item.recalculateWhenChanged()) … … 834 858 } 835 859 836 public void refreshSize() {837 // assert (size != null);860 public void refreshSize() 861 { 838 862 boolean bReparse = false; 863 839 864 for (Item i : getItems()) { 840 FloatanchorLeft = i.getAnchorLeft();841 FloatanchorRight = i.getAnchorRight();842 FloatanchorTop = i.getAnchorTop();843 FloatanchorBottom = i.getAnchorBottom();865 Integer anchorLeft = i.getAnchorLeft(); 866 Integer anchorRight = i.getAnchorRight(); 867 Integer anchorTop = i.getAnchorTop(); 868 Integer anchorBottom = i.getAnchorBottom(); 844 869 845 870 … … 885 910 } 886 911 887 public void addAllItems(Collection<Item> toAdd) { 912 public void addAllItems(Collection<Item> toAdd) 913 { 888 914 for (Item i : toAdd) { 889 915 // If an annotation is being deleted clear the annotation list 890 if (i.isAnnotation()) 891 i.getParentOrCurrentFrame().clearAnnotations(); 916 if (i.isAnnotation()) i.getParentOrCurrentFrame().clearAnnotations(); 892 917 // TODO Improve efficiency when addAll is called 893 918 addItem(i); … … 895 920 } 896 921 897 public void removeAllItems(Collection<Item> toRemove) { 922 public void removeAllItems(Collection<Item> toRemove) 923 { 898 924 for (Item i : toRemove) { 899 925 // If an annotation is being deleted clear the annotation list 900 if (i.isAnnotation()) 901 i.getParentOrCurrentFrame().clearAnnotations(); 926 if (i.isAnnotation()) i.getParentOrCurrentFrame().clearAnnotations(); 902 927 removeItem(i); 903 928 } 904 929 } 905 930 906 public void removeItem(Item item) { 931 public void removeItem(Item item) 932 { 907 933 removeItem(item, true); 908 934 } 909 935 910 public void removeItem(Item item, boolean recalculate) { 936 public void removeItem(Item item, boolean recalculate) 937 { 911 938 // If an annotation is being deleted clear the annotation list 912 if (item.isAnnotation()) 913 item.getParentOrCurrentFrame().clearAnnotations(); 939 if (item.isAnnotation()) item.getParentOrCurrentFrame().clearAnnotations(); 914 940 915 941 if (_body.remove(item)) { … … 917 943 // Remove widgets from the widget list 918 944 if (item != null) { 919 item.onParentStateChanged(new ItemParentStateChangedEvent(this, 920 ItemParentStateChangedEvent.EVENT_TYPE_REMOVED));945 item.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_REMOVED)); 946 921 947 if (item instanceof WidgetCorner) { 922 948 _iWidgets.remove(((WidgetCorner) item).getWidgetSource()); 923 949 } 950 924 951 item.invalidateCommonTrait(ItemAppearence.Removed); 925 952 } … … 937 964 * @param type The type of event that occurred 938 965 */ 939 private void addToUndo(Collection<Item> items, History.Type type) { 940 if (items.size() < 1) 941 return; 942 943 // System.out.println("Added: " + items); 966 private void addToUndo(Collection<Item> items, History.Type type) 967 { 968 if (items.size() < 1) return; 944 969 945 970 _undo.push(new History(items, type)); 946 971 } 947 972 948 public void addToUndoDelete(Collection<Item> items) { 973 public void addToUndoDelete(Collection<Item> items) 974 { 949 975 addToUndo(items, History.Type.deletion); 950 976 } 951 public void addToUndoMove(Collection<Item> items) { 977 978 public void addToUndoMove(Collection<Item> items) 979 { 952 980 addToUndo(items, History.Type.movement); 953 981 } 954 982 955 public void undo() { 983 public void undo() 984 { 956 985 boolean bReparse = false; 957 986 boolean bRecalculate = false; 958 987 959 if (_undo.size() <= 0) 960 return; 988 if (_undo.size() <= 0) return; 961 989 962 990 History undo = _undo.pop(); … … 992 1020 break; 993 1021 } 1022 994 1023 change(); 995 FrameMouseActions.getInstance().refreshHighlights(); 1024 1025 StandardGestureActions.refreshHighlights(); 1026 996 1027 if (bReparse) { 997 1028 FrameUtils.Parse(this, false, false); … … 999 1030 notifyObservers(bRecalculate); 1000 1031 } 1032 1001 1033 // always request a refresh otherwise filled shapes 1002 1034 // that were broken by a deletion and then reconnected by the undo 1003 1035 // don't get filled until the user otherwise causes them to redraw 1004 FrameGraphics.requestRefresh(false); 1005 FrameGraphics.Repaint(); 1036 DisplayController.requestRefresh(false); 1006 1037 // ItemUtils.EnclosedCheck(_body); 1007 1038 ItemUtils.Justify(this); 1008 1039 } 1009 1040 1010 public void redo() { 1041 public void redo() 1042 { 1011 1043 boolean bReparse = false; 1012 1044 boolean bRecalculate = false; 1013 1045 1014 if (_redo.size() <= 0) 1015 return; 1046 if (_redo.size() <= 0) return; 1016 1047 1017 1048 History redo = _redo.pop(); … … 1047 1078 break; 1048 1079 } 1080 1049 1081 change(); 1050 FrameMouseActions.getInstance().refreshHighlights(); 1082 1083 StandardGestureActions.refreshHighlights(); 1084 1051 1085 if (bReparse) { 1052 1086 FrameUtils.Parse(this, false, false); … … 1054 1088 notifyObservers(bRecalculate); 1055 1089 } 1090 1056 1091 // always request a refresh otherwise filled shapes 1057 1092 // that were broken by a deletion and then reconnected by the undo 1058 1093 // don't get filled until the user otherwise causes them to redraw 1059 FrameGraphics.requestRefresh(false); 1060 FrameGraphics.Repaint(); 1094 DisplayController.requestRefresh(false); 1061 1095 // ItemUtils.EnclosedCheck(_body); 1062 1096 ItemUtils.Justify(this); … … 1068 1102 * @return The name of this Frame's frameset. 1069 1103 */ 1070 public String getFramesetName() { 1104 public String getFramesetName() 1105 { 1071 1106 return _frameset; 1072 1107 } 1073 1108 1074 public String getName() { 1109 public String getName() 1110 { 1075 1111 return getFramesetName() + _number; 1076 1112 } … … 1081 1117 * @return The version of this Frame. 1082 1118 */ 1083 public int getVersion() { 1119 public int getVersion() 1120 { 1084 1121 return _version; 1085 1122 } 1086 1123 1087 public PermissionPair getPermission() { 1124 public PermissionPair getPermission() 1125 { 1088 1126 return _permissionPair; 1089 1127 } 1090 1128 1091 public UserAppliedPermission getUserAppliedPermission() { 1129 public UserAppliedPermission getUserAppliedPermission() 1130 { 1092 1131 return getUserAppliedPermission(UserAppliedPermission.full); 1093 1132 } 1094 1133 1095 public UserAppliedPermission getUserAppliedPermission(UserAppliedPermission defaultPermission) {1096 if (_permissionPair == null)1097 1134 public UserAppliedPermission getUserAppliedPermission(UserAppliedPermission defaultPermission) 1135 { 1136 if (_permissionPair == null) return defaultPermission; 1098 1137 1099 1138 return _permissionPair.getPermission(_owner); 1100 1139 } 1101 1140 1102 1103 public String getOwner(){1141 public String getOwner() 1142 { 1104 1143 return _owner; 1105 1144 } 1106 1145 1107 public String getDateCreated() { 1146 public String getDateCreated() 1147 { 1108 1148 return _creationDate; 1109 1149 } 1110 1150 1111 public String getLastModifyUser() { 1151 public String getLastModifyUser() 1152 { 1112 1153 return _modifiedUser; 1113 1154 } 1114 1155 1115 public String getLastModifyDate() { 1156 public String getLastModifyDate() 1157 { 1116 1158 return _modifiedDate; 1117 1159 } 1118 1160 1119 public String getFrozenDate() { 1161 public String getFrozenDate() 1162 { 1120 1163 return _frozenDate; 1121 1164 } 1122 1165 1123 public void setBackgroundColor(Color back) { 1166 public void setBackgroundColor(Colour back) 1167 { 1124 1168 _background = back; 1169 1125 1170 change(); 1126 1171 1127 if (this == DisplayIO.getCurrentFrame()) { 1128 FrameGraphics.refresh(false); 1129 } 1130 } 1131 1132 public Color getBackgroundColor() { 1172 if (this == DisplayController.getCurrentFrame()) { 1173 DisplayController.requestRefresh(false); 1174 } 1175 } 1176 1177 public Colour getBackgroundColor() 1178 { 1133 1179 return _background; 1134 1180 } 1135 1181 1136 public Color getPaintBackgroundColor() { 1182 public Colour getPaintBackgroundColor() 1183 { 1137 1184 // If null... return white 1138 1185 if (_background == null) { … … 1143 1190 } 1144 1191 1145 public void setForegroundColor(Color front) { 1192 public void setForegroundColor(Colour front) 1193 { 1146 1194 _foreground = front; 1195 1147 1196 change(); 1148 // FrameGraphics.Repaint();1149 } 1150 1151 public Color getForegroundColor(){1197 } 1198 1199 public Colour getForegroundColor() 1200 { 1152 1201 return _foreground; 1153 1202 } 1154 1203 1155 public Color getPaintForegroundColor() { 1156 final int GRAY = Color.gray.getBlue(); 1157 final int THRESHOLD = 10; 1204 public Colour getPaintForegroundColor() 1205 { 1206 final int GRAY = Colour.GREY.getBlue(); 1207 final int THRESHOLD = Colour.FromComponent255(10); 1158 1208 1159 1209 if (_foreground == null) { 1160 Colo r back = getPaintBackgroundColor();1210 Colour back = getPaintBackgroundColor(); 1161 1211 if (Math.abs(back.getRed() - GRAY) < THRESHOLD 1162 1212 && Math.abs(back.getBlue() - GRAY) < THRESHOLD 1163 1213 && Math.abs(back.getGreen() - GRAY) < THRESHOLD) 1164 return Color.WHITE;1165 1166 Color fore = new Color(1167 Math.abs(Conversion.RGB_MAX - back.getRed()), Math1168 .abs(Conversion.RGB_MAX - back.getGreen()), Math1169 .abs(Conversion.RGB_MAX - back.getBlue()));1214 { 1215 return Colour.WHITE; 1216 } 1217 1218 Colour fore = back.inverse(); 1219 1170 1220 return fore; 1171 1221 } … … 1174 1224 } 1175 1225 1176 public String toString() { 1226 public String toString() 1227 { 1177 1228 StringBuilder s = new StringBuilder(); 1178 1229 s.append(String.format("Name: %s%d%n", _frameset, _number)); … … 1187 1238 } 1188 1239 1189 public Text getTextAbove(Text current) { 1240 public Text getTextAbove(Text current) 1241 { 1190 1242 Collection<Text> currentTextItems = FrameUtils.getCurrentTextItems(); 1191 1243 List<Text> toCheck = new ArrayList<Text>(); 1244 1192 1245 if (currentTextItems.contains(current)) { 1193 1246 toCheck.addAll(currentTextItems); … … 1195 1248 toCheck.addAll(getTextItems()); 1196 1249 } 1250 1197 1251 // Make sure the items are sorted 1198 1252 Collections.sort(toCheck); 1199 1253 1200 1254 int ind = toCheck.indexOf(current); 1201 if (ind == -1) 1202 return null; 1255 if (ind == -1) return null; 1203 1256 1204 1257 // loop through all items above this one, return the first match 1205 1258 for (int i = ind - 1; i >= 0; i--) { 1206 1259 Text check = toCheck.get(i); 1207 if (FrameUtils.inSameColumn(check, current)) 1208 return check; 1260 if (FrameUtils.inSameColumn(check, current)) return check; 1209 1261 } 1210 1262 1211 1263 return null; 1212 1264 } 1213 1214 /** 1215 * Updates any Images that require it from their ImageObserver (Principally 1216 * Animated GIFs) 1217 */ 1218 public boolean imageUpdate(Image img, int infoflags, int x, int y, 1219 int width, int height) { 1220 FrameGraphics.ForceRepaint(); 1221 1222 if (DisplayIO.getCurrentFrame() == this) 1223 return true; 1224 1225 return false; 1226 } 1227 1265 1228 1266 /** 1229 1267 * Gets the text items that are in the same column and below a specified … … 1233 1271 * The Item to get the column for. 1234 1272 */ 1235 public List<Text> getColumn(Item from) { 1273 public List<Text> getColumn(Item from) 1274 { 1236 1275 // Check that this item is on the current frame 1237 if (!_body.contains(from)) 1238 return null; 1276 if (!_body.contains(from)) return null; 1239 1277 1240 1278 if (from == null) { … … 1242 1280 } 1243 1281 1244 if (from == null) 1245 return null; 1282 if (from == null) return null; 1246 1283 1247 1284 // Get the enclosedItems 1248 1285 Collection<Text> enclosed = FrameUtils.getCurrentTextItems(); 1249 1286 List<Text> toCheck = null; 1287 1250 1288 if (enclosed.contains(from)) { 1251 1289 toCheck = new ArrayList<Text>(); … … 1256 1294 1257 1295 List<Text> column = new ArrayList<Text>(); 1296 1258 1297 if (toCheck.size() > 0) { 1259 1260 1298 // Make sure the items are sorted 1261 1299 Collections.sort(toCheck); … … 1266 1304 1267 1305 // If its the title index will be 0 1268 if (index < 0) 1269 index = 0; 1306 if (index < 0) index = 0; 1270 1307 1271 1308 for (int i = index; i < toCheck.size(); i++) { 1272 1309 Text item = toCheck.get(i); 1273 if (FrameUtils.inSameColumn(from, item)) 1274 column.add(item); 1310 if (FrameUtils.inSameColumn(from, item)) column.add(item); 1275 1311 } 1276 1312 } … … 1289 1325 * If overlay is null. 1290 1326 */ 1291 protected boolean addVector(Vector toAdd) { 1327 protected boolean addVector(Vector toAdd) 1328 { 1292 1329 // make sure we dont add this frame as an overlay of itself 1293 if (toAdd.Frame == this) 1294 return false;1330 if (toAdd.Frame == this) return false; 1331 1295 1332 _vectors.add(toAdd); 1333 1296 1334 // Items must be notified that they have been added or removed from this 1297 1335 // frame via the vector... 1298 1336 int maxX = 0; 1299 1337 int maxY = 0; 1338 1300 1339 HighlightMode mode = toAdd.Source.getHighlightMode(); 1301 if (mode != HighlightMode.None) 1302 mode = HighlightMode.Connected; 1303 Color highlightColor = toAdd.Source.getHighlightColor(); 1340 if (mode != HighlightMode.None) mode = HighlightMode.Connected; 1341 1342 Colour highlightColor = toAdd.Source.getHighlightColor(); 1343 1304 1344 for (Item i : ItemUtils.CopyItems(toAdd.Frame.getVectorItems(), toAdd)) { 1305 i.onParentStateChanged(new ItemParentStateChangedEvent(this, 1306 ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, 1307 toAdd.permission)); 1345 i.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, toAdd.permission)); 1308 1346 i.setEditTarget(toAdd.Source); 1309 i.setHighlightMode (mode, highlightColor);1347 i.setHighlightModeAndColour(mode, highlightColor); 1310 1348 _vectorItems.add(i); 1311 1349 i.invalidateAll(); 1312 1350 i.invalidateFill(); 1351 1313 1352 // Get the right most x and bottom most y pos 1314 1353 int itemRight = i.getX() + i.getBoundsWidth(); 1315 if (itemRight > maxX) 1316 maxX = itemRight;1354 if (itemRight > maxX) maxX = itemRight; 1355 1317 1356 int itemBottom = i.getY() + i.getBoundsHeight(); 1318 if (itemBottom > maxY) 1319 maxY = itemBottom;1320 }1357 if (itemBottom > maxY) maxY = itemBottom; 1358 } 1359 1321 1360 toAdd.setSize(maxX, maxY); 1361 1322 1362 return true; 1323 1363 } 1324 1364 1325 public Collection<Vector> getVectors() { 1365 public Collection<Vector> getVectors() 1366 { 1326 1367 Collection<Vector> l = new LinkedList<Vector>(); 1327 1368 l.addAll(_vectors); … … 1329 1370 } 1330 1371 1331 public Collection<Overlay> getOverlays() { 1372 public Collection<Overlay> getOverlays() 1373 { 1332 1374 return new LinkedList<Overlay>(_overlays.keySet()); 1333 1375 } 1334 1376 1335 1377 /** 1336 * @return All vectosr seen by this frame (including its vector's vectors). 1337 */ 1338 public List<Vector> getVectorsDeep() { 1378 * @return All vectors seen by this frame (including its vector's vectors). 1379 */ 1380 public List<Vector> getVectorsDeep() 1381 { 1339 1382 List<Vector> l = new LinkedList<Vector>(); 1340 1383 getVectorsDeep(l, this, new LinkedList<Frame>()); … … 1342 1385 } 1343 1386 1344 private boolean getVectorsDeep(List<Vector> vectors, Frame vector, 1345 List<Frame> seenVectors) { 1346 1347 if (seenVectors.contains(vector)) 1348 return false; 1387 private boolean getVectorsDeep(List<Vector> vectors, Frame vector, List<Frame> seenVectors) 1388 { 1389 if (seenVectors.contains(vector)) return false; 1349 1390 1350 1391 seenVectors.add(vector); 1351 1392 1352 for (Vector o: vector.getVectors()) {1353 if (getVectorsDeep(vectors, o.Frame, seenVectors)) {1354 vectors.add( o);1393 for (Vector v : vector.getVectors()) { 1394 if (getVectorsDeep(vectors, v.Frame, seenVectors)) { 1395 vectors.add(v); 1355 1396 } 1356 1397 } … … 1359 1400 } 1360 1401 1361 // private boolean getOverlaysDeep(List<Overlay> overlays, Frame overlay, 1362 // List<Frame> seenOverlays) { 1363 // 1364 // if (seenOverlays.contains(overlay)) 1365 // return false; 1366 // 1367 // seenOverlays.add(overlay); 1368 // 1369 // for (Overlay o : overlay.getOverlays()) { 1370 // if (getOverlaysDeep(overlays, o.Frame, seenOverlays)) { 1371 // overlays.add(o); 1372 // } 1373 // } 1374 // 1375 // return true; 1376 // } 1402 public List<Overlay> getOverlaysDeep() 1403 { 1404 List<Overlay> ret = new LinkedList<Overlay>(); 1405 1406 getOverlaysDeep(ret, new LinkedList<Frame>()); 1407 1408 return ret; 1409 } 1410 1411 private boolean getOverlaysDeep(List<Overlay> overlays, List<Frame> seenOverlays) 1412 { 1413 if (seenOverlays.contains(this)) return false; 1414 1415 seenOverlays.add(this); 1416 1417 for (Overlay o : this.getOverlays()) { 1418 if (o.Frame.getOverlaysDeep(overlays, seenOverlays)) { 1419 overlays.add(o); 1420 } 1421 } 1422 return true; 1423 } 1424 1425 /** 1426 * Recursive function similar to AddAllOverlayItems. 1427 * 1428 * @param widgets 1429 * The collection the widgets will be added to 1430 * @param overlay 1431 * An "overlay" frame - this initially will be the parent frame 1432 * @param seenOverlays 1433 * Used for state in the recursion stack. Pass as an empty 1434 * (non-null) list. 1435 */ 1436 public List<Widget> getAllOverlayWidgets() 1437 { 1438 List<Widget> widgets = new LinkedList<Widget>(); 1439 1440 for (Overlay o : getOverlaysDeep()) widgets.addAll(o.Frame.getInteractiveWidgets()); 1441 1442 return widgets; 1443 } 1377 1444 1378 1445 /** … … 1381 1448 * @param item 1382 1449 * The item - must not be null. 1383 * @return The overlay that contains the it m. Null if no overlay owns the1450 * @return The overlay that contains the item. Null if no overlay owns the 1384 1451 * item. 1385 1452 */ 1386 public Overlay getOverlayOwner(Item item) {1387 if (item == null)1388 1453 public Overlay getOverlayOwner(Item item) 1454 { 1455 if (item == null) throw new NullPointerException("item"); 1389 1456 1390 1457 for (Overlay l : getOverlays()) { 1391 if (item.getParent() == l.Frame) 1392 return l; 1458 if (item.getParent() == l.Frame) return l; 1393 1459 } 1394 1460 1395 1461 // TODO return the correct vector... not just the first vector matching 1396 // the vector Frame1462 // the vector frame 1397 1463 for (Vector v : getVectors()) { 1398 if (item.getParent() == v.Frame) 1399 return v; 1464 if (item.getParent() == v.Frame) return v; 1400 1465 } 1401 1466 … … 1403 1468 } 1404 1469 1405 public void clearVectors() { 1470 public void clearVectors() 1471 { 1406 1472 _vectors.clear(); 1407 1473 … … 1414 1480 } 1415 1481 1416 protected boolean removeVector(Vector toRemove) { 1417 if (!_vectors.remove(toRemove)) 1418 return false; 1482 protected boolean removeVector(Vector toRemove) 1483 { 1484 if (!_vectors.remove(toRemove)) return false; 1485 1419 1486 for (Item i : toRemove.Frame.getVectorItems()) { 1420 1487 i.invalidateAll(); … … 1426 1493 1427 1494 } 1495 1428 1496 return true; 1429 1497 } 1430 1498 1431 public void clearOverlays() { 1499 public void clearOverlays() 1500 { 1432 1501 for (Overlay o : _overlays.keySet()) { 1433 1502 for (Item i : o.Frame.getItems()) { 1434 i 1435 .onParentStateChanged(new ItemParentStateChangedEvent( 1503 i.onParentStateChanged(new ItemParentStateChangedEvent( 1436 1504 this, 1437 1505 ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY, … … 1444 1512 } 1445 1513 1446 protected boolean removeOverlay(Frame f) { 1514 protected boolean removeOverlay(Frame f) 1515 { 1447 1516 for (Overlay o : _overlays.keySet()) { 1448 1517 if (o.Frame == f) { 1449 1518 _overlays.remove(o); 1519 1450 1520 for (Item i : f.getItems()) { 1451 1521 _overlayItems.remove(i); 1452 i 1453 .onParentStateChanged(new ItemParentStateChangedEvent( 1522 i.onParentStateChanged(new ItemParentStateChangedEvent( 1454 1523 this, 1455 1524 ItemParentStateChangedEvent.EVENT_TYPE_REMOVED_VIA_OVERLAY, 1456 1525 o.permission)); 1457 1526 } 1527 1458 1528 return true; 1459 1529 } 1460 1530 } 1531 1461 1532 return false; 1462 1533 } 1463 1534 1464 public void addAllVectors(List<Vector> vectors) { 1535 public void addAllVectors(List<Vector> vectors) 1536 { 1465 1537 for (Vector v : vectors) { 1466 1538 addVector(v); … … 1468 1540 } 1469 1541 1470 public void addAllOverlays(Collection<Overlay> overlays) { 1542 public void addAllOverlays(Collection<Overlay> overlays) 1543 { 1471 1544 for (Overlay o : overlays) { 1472 1545 addOverlay(o); … … 1474 1547 } 1475 1548 1476 protected boolean addOverlay(Overlay toAdd) { 1549 protected boolean addOverlay(Overlay toAdd) 1550 { 1477 1551 // make sure we dont add this frame as an overlay of itself 1478 if (toAdd.Frame == this) 1479 return false;1552 if (toAdd.Frame == this) return false; 1553 1480 1554 // Dont add the overlay if there is already one for this frame 1481 if (_overlays.values().contains(toAdd.Frame)) 1482 return false;1555 if (_overlays.values().contains(toAdd.Frame)) return false; 1556 1483 1557 // Add the overlay to the map of overlays on this frame 1484 1558 _overlays.put(toAdd, toAdd.Frame); 1559 1485 1560 // Add all the overlays from the overlay frame to this frame 1486 for (Overlay o : toAdd.Frame.getOverlays())1487 1561 // TODO: Can this cause a recursion loop? If A and B are overlays of each other? cts16 1562 for (Overlay o : toAdd.Frame.getOverlays()) addOverlay(o); 1488 1563 1489 1564 // Add all the vectors from the overlay frame to this frame 1490 for (Vector v : toAdd.Frame.getVectors()) 1491 addVector(v); 1565 for (Vector v : toAdd.Frame.getVectors()) addVector(v); 1492 1566 1493 1567 // Now add the items for this overlay 1494 UserAppliedPermission permission = UserAppliedPermission.min(toAdd.Frame.getUserAppliedPermission(), toAdd.permission);1568 UserAppliedPermission permission = UserAppliedPermission.min(toAdd.Frame.getUserAppliedPermission(), toAdd.permission); 1495 1569 1496 1570 // Items must be notified that they have been added or removed from this 1497 1571 // frame via the overlay... 1498 1572 for (Item i : toAdd.Frame.getVisibleItems()) { 1499 i.onParentStateChanged(new ItemParentStateChangedEvent(this, 1500 ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, 1501 permission)); 1502 // i.setPermission(permission); 1573 i.onParentStateChanged(new ItemParentStateChangedEvent(this, ItemParentStateChangedEvent.EVENT_TYPE_ADDED_VIA_OVERLAY, permission)); 1503 1574 _overlayItems.add(i); 1504 1575 } … … 1508 1579 1509 1580 @Override 1510 public boolean equals(Object o) { 1581 public boolean equals(Object o) 1582 { 1511 1583 if (o instanceof String) { 1512 return (String.CASE_INSENSITIVE_ORDER 1513 .compare((String) o, getName()) == 0); 1584 return (String.CASE_INSENSITIVE_ORDER.compare((String) o, getName()) == 0); 1514 1585 } 1515 1586 … … 1526 1597 * @param toMergeWith 1527 1598 */ 1528 private void merge(Frame toMergeWith) {1529 if (toMergeWith == null)1530 1599 private void merge(Frame toMergeWith) 1600 { 1601 if (toMergeWith == null) return; 1531 1602 1532 1603 List<Item> copies = ItemUtils.CopyItems(toMergeWith.getItems()); … … 1548 1619 * @return the items that cant be merged 1549 1620 */ 1550 public List<Item> merge(List<Item> toMerge) { 1621 public List<Item> merge(List<Item> toMerge) 1622 { 1551 1623 ArrayList<Item> remain = new ArrayList<Item>(0); 1552 1624 1553 1625 for (Item i : toMerge) { 1554 if (!(i instanceof Text)) 1626 if (!(i instanceof Text)) { 1555 1627 remain.add(i); 1556 else {1628 } else { 1557 1629 if (!AttributeUtils.setAttribute(this, (Text) i)) { 1558 if (i.getLink() != null) 1630 if (i.getLink() != null) { 1559 1631 merge(FrameIO.LoadFrame(i.getAbsoluteLink())); 1560 else if (FrameIO 1561 .isValidFrameName(((Text) i).getFirstLine())) { 1632 } else if (FrameIO.isValidFrameName(((Text) i).getFirstLine())) { 1562 1633 // If we get hear we are merging frames 1563 1634 merge(FrameIO.LoadFrame(((Text) i).getFirstLine())); … … 1574 1645 * items are added to the backup-stack. 1575 1646 */ 1576 public void clear(boolean keepAnnotations) { 1647 public void clear(boolean keepAnnotations) 1648 { 1577 1649 List<Item> newBody = new ArrayList<Item>(0); 1650 1578 1651 Item title = getTitleItem(); 1652 1579 1653 if (title != null) { 1580 1654 newBody.add(title); 1581 1655 _body.remove(title); 1582 1656 } 1657 1583 1658 if (keepAnnotations) { 1584 1659 for (Item i : _body) { 1585 if (i.isAnnotation()) 1586 newBody.add(i);1587 1588 }1660 if (i.isAnnotation()) newBody.add(i); 1661 } 1662 } 1663 1589 1664 _body.removeAll(newBody); 1590 1665 addToUndoDelete(_body); … … 1592 1667 change(); 1593 1668 1594 if (!keepAnnotations && _annotations != null) 1595 _annotations.clear(); 1669 if (!keepAnnotations && _annotations != null) _annotations.clear(); 1596 1670 } 1597 1671 … … 1602 1676 * @return 1603 1677 */ 1604 public Text createNewText(String text) { 1678 public Text createNewText(String text) 1679 { 1605 1680 Text t = createBlankText(text); 1606 1681 t.setText(text); … … 1615 1690 * @return The newly created Text Item 1616 1691 */ 1617 public Text createBlankText(String templateType) { 1692 public Text createBlankText(String templateType) 1693 { 1618 1694 SessionStats.CreatedText(); 1619 1695 Text t; 1620 if (templateType.length() == 0) 1696 1697 if (templateType.length() == 0) { 1621 1698 t = getItemTemplate().copy(); 1622 else1699 } else { 1623 1700 t = getItemTemplate(templateType.charAt(0)); 1624 1701 } 1702 1625 1703 // reset attributes 1626 1704 t.setID(getNextItemID()); 1627 t.setPosition(Display IO.getMouseX(), FrameMouseActions.getY());1705 t.setPosition(DisplayController.getMousePosition()); 1628 1706 t.setText(""); 1629 1707 t.setParent(this); … … 1648 1726 } 1649 1727 1650 public Item createDot() {1651 Item dot = new Dot(DisplayIO.getMouseX(), FrameMouseActions.getY(),1652 1728 public Item createDot() 1729 { 1730 Item dot = new Dot(DisplayController.getMouseX(), DisplayController.getMouseY(), getNextItemID()); 1653 1731 1654 1732 Item template = getTemplate(_dotTemplate, ItemUtils.TAG_DOT_TEMPLATE); 1655 1733 float thickness = template.getThickness(); 1656 if (thickness > 0) 1657 dot.setThickness(template.getThickness()); 1658 if (template.getLinePattern() != null) 1659 dot.setLinePattern(template.getLinePattern()); 1734 if (thickness > 0) dot.setThickness(template.getThickness()); 1735 if (template.getLinePattern() != null) dot.setLinePattern(template.getLinePattern()); 1660 1736 dot.setColor(template.getColor()); 1661 1737 dot.setFillColor(template.getFillColor()); … … 1665 1741 } 1666 1742 1667 private Text getTemplate(Text defaultTemplate, int templateTag) { 1743 private Text getTemplate(Text defaultTemplate, int templateTag) 1744 { 1668 1745 Text t = null; 1669 1746 … … 1677 1754 1678 1755 if (t == null) { 1679 if (defaultTemplate == null) { 1680 return null; 1681 } 1756 if (defaultTemplate == null) return null; 1757 1682 1758 t = defaultTemplate; 1683 1759 } … … 1685 1761 // If the item is linked apply any attribute pairs on the child frame 1686 1762 String link = t.getAbsoluteLink(); 1763 1687 1764 // need to get link first because copy doesnt copy the link 1688 1765 t = t.copy(); … … 1701 1778 } 1702 1779 1703 public Text getItemTemplate(char firstChar) { 1780 /** 1781 * TODO: Comment. cts16 1782 * TODO: Remove magic constants. cts16 1783 */ 1784 public Text getItemTemplate(char firstChar) 1785 { 1704 1786 switch (firstChar) { 1705 case '@': 1706 return getAnnotationTemplate(); 1707 case '/': 1708 case '#': 1709 return getCodeCommentTemplate(); 1710 default: 1711 return getItemTemplate(); 1712 } 1713 } 1714 1715 public Text createNewText() { 1787 case '@': 1788 return getAnnotationTemplate(); 1789 case '/': 1790 case '#': 1791 return getCodeCommentTemplate(); 1792 default: 1793 return getItemTemplate(); 1794 } 1795 } 1796 1797 public Text createNewText() 1798 { 1716 1799 return createNewText(""); 1717 1800 } 1718 1801 1719 public Text addText(int x, int y, String text, String action) { 1802 public Text addText(int x, int y, String text, String action) 1803 { 1720 1804 Text t = createNewText(text); 1721 1805 t.setPosition(x, y); … … 1724 1808 } 1725 1809 1726 public Item addText(int x, int y, String text, String action, String link) { 1727 Item t = addText(x, y, text, action); 1810 public Text addText(int x, int y, String text, String action, String link) 1811 { 1812 Text t = addText(x, y, text, action); 1728 1813 t.setLink(link); 1729 1814 return t; 1730 1815 } 1731 1816 1732 public Item addDot(int x, int y) { 1733 Item d = new Dot(x, y, getNextItemID()); 1817 public Dot addDot(int x, int y) 1818 { 1819 Dot d = new Dot(x, y, getNextItemID()); 1734 1820 addItem(d); 1735 1821 return d; … … 1754 1840 * Color to fill the rectangle with 1755 1841 */ 1756 public List<Item> addRectangle(int x, int y, int width, int height, float borderThickness, Color borderColor, Color fillColor) { 1842 public List<Item> addRectangle(int x, int y, int width, int height, float borderThickness, Colour borderColor, Colour fillColor) 1843 { 1757 1844 List<Item> rectComponents = new ArrayList<Item>(); 1758 1845 Item[] corners = new Item[4]; … … 1796 1883 List<Item> rect = new ArrayList<Item>(rectComponents); 1797 1884 this.addAllItems(rectComponents); 1798 FrameMouseActions.anchor(rectComponents);1885 StandardGestureActions.anchor(rectComponents); 1799 1886 return rect; 1800 // rectComponents.clear();1801 } 1802 1803 public boolean isSaved(){1887 } 1888 1889 public boolean isSaved() 1890 { 1804 1891 return _saved; 1805 1892 } 1806 1893 1807 public void setSaved() {1808 // System.out.println(getName() + " saved");1894 public void setSaved() 1895 { 1809 1896 _saved = true; 1810 1897 _change = false; 1811 1898 } 1812 1899 1813 public static boolean rubberbandingLine() {1814 return FreeItems.getInstance().size() == 21815 && (FreeItems.getInstance().get(0) instanceof Line || FreeItems1816 1900 public static boolean rubberbandingLine() 1901 { 1902 return FreeItems.getInstance().size() == 2 && 1903 (FreeItems.getInstance().get(0) instanceof Line || FreeItems.getInstance().get(1) instanceof Line); 1817 1904 } 1818 1905 … … 1825 1912 * @return true if the item is a normal text item 1826 1913 */ 1827 public boolean isNormalTextItem(Item it) {1828 if (it instanceof Text && it != getTitleItem() && it != _frameName1829 1914 public boolean isNormalTextItem(Item it) 1915 { 1916 if (it instanceof Text && it != getTitleItem() && it != _frameName && !((Text) it).isSpecialAnnotation()) { 1830 1917 return true; 1831 1918 } … … 1839 1926 * @param index 1840 1927 */ 1841 public boolean moveMouseToTextItem(int index) { 1928 public boolean moveMouseToTextItem(int index) 1929 { 1842 1930 List<Item> items = getItems(); 1843 1931 int itemsFound = 0; 1844 1932 for (int i = 0; i < items.size(); i++) { 1845 1933 Item it = items.get(i); 1846 if (isNormalTextItem(it)) 1847 itemsFound++; 1934 if (isNormalTextItem(it)) itemsFound++; 1848 1935 if (itemsFound > index) { 1849 DisplayIO.setCursorPosition(((Text) it) 1850 .getParagraphEndPosition().x, it.getY()); 1851 DisplayIO.resetCursorOffset(); 1852 FrameGraphics.Repaint(); 1936 DisplayController.setCursorPosition(((Text) it).getParagraphEndPosition().x, it.getY()); 1937 DisplayController.resetCursorOffset(); 1938 DisplayController.requestRefresh(true); 1853 1939 return true; 1854 1940 } … … 1857 1943 return false; 1858 1944 } 1859 1860 /*1861 * public boolean moveMouseToNextTextItem(int index) { List<Item> items =1862 * getItems(); int itemsFound = 0; for (int i = 0; i < items.size(); i++) {1863 * Item it = items.get(i); if ( isNormalTextItem(it)) itemsFound++; if1864 * (itemsFound > index) {1865 * DisplayIO.setCursorPosition(((Text)it).getEndParagraphPosition().x,1866 * it.getY()); DisplayIO.resetCursorOffset(); FrameGraphics.Repaint();1867 * return true; } }1868 *1869 * return false; }1870 */1871 1945 1872 1946 /** 1873 1947 * Searches for an annotation item called start to be used as the default 1874 1948 * cursor location when TDFC occurs. 1875 */ 1876 public boolean moveMouseToDefaultLocation() { 1949 * 1950 * TODO: Remove magic constants. cts16 1951 */ 1952 public boolean moveMouseToDefaultLocation() 1953 { 1877 1954 List<Item> items = getItems(); 1878 1955 … … 1880 1957 if (it instanceof Text) { 1881 1958 Text t = (Text) it; 1882 if (t.getText().toLowerCase().startsWith("@start") 1883 || t.getText().toLowerCase().equals("@start:")) { 1959 if (t.getText().toLowerCase().startsWith("@start") || t.getText().toLowerCase().equals("@start:")) { 1884 1960 // Used to allow users the option of putting an initial 1885 1961 // bullet after the @start … … 1888 1964 t.setText(""); 1889 1965 1890 if (t.getText().equals("")) 1891 DisplayIO.getCurrentFrame().removeItem(t); 1892 if (!FreeItems.itemsAttachedToCursor()) { 1893 DisplayIO.setCursorPosition(((Text) it) 1894 .getParagraphEndPosition()); 1895 DisplayIO.resetCursorOffset(); 1966 if (t.getText().equals("")) DisplayController.getCurrentFrame().removeItem(t); 1967 1968 if (!FreeItems.hasItemsAttachedToCursor()) { 1969 DisplayController.setCursorPosition(((Text) it).getParagraphEndPosition()); 1970 DisplayController.resetCursorOffset(); 1896 1971 } 1897 FrameGraphics.Repaint(); 1972 1973 DisplayController.requestRefresh(true); 1974 1898 1975 return true; 1899 1976 } … … 1911 1988 * name of the frame if the tag isnt on the frame. 1912 1989 */ 1913 public String getExportFileName() { 1990 public String getExportFileName() 1991 { 1914 1992 String fileName = getExportFileTagValue(); 1915 1993 … … 1925 2003 } 1926 2004 1927 public void toggleBackgroundColor() { 1928 setBackgroundColor(ColorUtils.getNextColor(_background, 1929 TemplateSettings.BackgroundColorWheel.get(), null)); 1930 } 1931 1932 public void setName(String frameset, int i) { 2005 public void toggleBackgroundColor() 2006 { 2007 setBackgroundColor(ColorUtils.getNextColor(_background, TemplateSettings.BackgroundColorWheel.get(), null)); 2008 } 2009 2010 public void setName(String frameset, int i) 2011 { 1933 2012 setFrameset(frameset); 1934 2013 setFrameNumber(i); … … 1940 2019 * 1941 2020 */ 1942 public void refreshItemPermissions(UserAppliedPermission maxPermission) {1943 if(_frameName == null)1944 2021 public void refreshItemPermissions(UserAppliedPermission maxPermission) 2022 { 2023 if(_frameName == null) return; 1945 2024 1946 2025 UserAppliedPermission permission = UserAppliedPermission.min(maxPermission, getUserAppliedPermission()); … … 1948 2027 switch (permission) { 1949 2028 case none: 1950 _frameName.setBackgroundColor( new Color(255, 220, 220));2029 _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_NONE); 1951 2030 break; 1952 2031 case followLinks: 1953 _frameName.setBackgroundColor( new Color(255, 230, 135));2032 _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FOLLOW_LINKS); 1954 2033 break; 1955 2034 case copy: 1956 _frameName.setBackgroundColor( new Color(255, 255, 155));2035 _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_COPY); 1957 2036 break; 1958 2037 case createFrames: 1959 _frameName.setBackgroundColor( new Color(220, 255, 220));2038 _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_CREATE_FRAMES); 1960 2039 break; 1961 2040 case full: 1962 _frameName.setBackgroundColor( null);2041 _frameName.setBackgroundColor(FRAME_NAME_BACKGROUND_COLOUR_FOR_PERMISSION_FULL); 1963 2042 break; 1964 2043 default: … … 1975 2054 } 1976 2055 1977 public boolean isTestFrame() { 2056 public boolean isTestFrame() 2057 { 1978 2058 Text title = getTitleItem(); 1979 if (title == null) 1980 return false; 2059 if (title == null) return false; 1981 2060 String action = title.getFirstAction(); 1982 if (action == null) 1983 return false; 2061 if (action == null) return false; 1984 2062 action = action.toLowerCase(); 1985 return action.startsWith(Simple.RUN_FRAME_ACTION) 1986 || action.startsWith(Simple.DEBUG_FRAME_ACTION);1987 } 1988 1989 public void setActiveTime(String activeTime){2063 return action.startsWith(Simple.RUN_FRAME_ACTION) || action.startsWith(Simple.DEBUG_FRAME_ACTION); 2064 } 2065 2066 public void setActiveTime(String activeTime) 2067 { 1990 2068 try { 1991 _activeTime = new Time(Time.valueOf(activeTime).getTime() + 12 * 60 1992 * 60 * 1000); 2069 _activeTime = new Time(Time.valueOf(activeTime).getTime() + 12 * 60 * 60 * 1000); 1993 2070 } catch (Exception e) { 1994 2071 _activeTime = new Time(0); … … 1996 2073 } 1997 2074 1998 public void setActiveTime(Time activeTime) { 2075 public void setActiveTime(Time activeTime) 2076 { 1999 2077 _activeTime = activeTime; 2000 2078 } 2001 2079 2002 public void setDarkTime(Time darkTime) { 2080 public void setDarkTime(Time darkTime) 2081 { 2003 2082 _darkTime = darkTime; 2004 2083 } 2005 2084 2006 public void setDarkTime(String darkTime) { 2085 public void setDarkTime(String darkTime) 2086 { 2007 2087 try { 2008 _darkTime = new Time(Time.valueOf(darkTime).getTime() + 12 * 60 2009 * 60 * 1000); 2088 _darkTime = new Time(Time.valueOf(darkTime).getTime() + 12 * 60 * 60 * 1000); 2010 2089 } catch (Exception e) { 2011 2090 _darkTime = new Time(0); … … 2018 2097 * @return the backup frame for this frame 2019 2098 */ 2020 public Frame getBackupFrame() { 2099 public Frame getBackupFrame() 2100 { 2021 2101 Text backupTag = _annotations.get("old"); 2022 if (backupTag == null) 2023 return null;2102 if (backupTag == null) return null; 2103 2024 2104 // TODO want another way to deal with updating of annotations items 2025 2105 // without F12 refresh … … 2031 2111 return getBackupFrame(); 2032 2112 } 2113 2033 2114 // Now return the name of the backed up frame 2034 2115 String link = backupTag.getAbsoluteLink(); 2035 if (link == null || link.equalsIgnoreCase(getName())) 2036 return null; 2116 if (link == null || link.equalsIgnoreCase(getName())) return null; 2037 2117 2038 2118 Frame backup = FrameIO.LoadFrame(link); … … 2040 2120 } 2041 2121 2042 public Time getDarkTime() { 2122 public Time getDarkTime() 2123 { 2043 2124 return _darkTime; 2044 2125 } 2045 2126 2046 public Time getActiveTime() { 2127 public Time getActiveTime() 2128 { 2047 2129 return _activeTime; 2048 2130 } … … 2054 2136 * @return the number of frames in the backed up comet 2055 2137 */ 2056 public int getCometLength() { 2138 public int getCometLength() 2139 { 2057 2140 Frame backup = getBackupFrame(); 2058 2141 return 1 + (backup == null ? 0 : backup.getCometLength()); 2059 2142 } 2060 2143 2061 public void addAnnotation(Text item) { 2144 public void addAnnotation(Text item) 2145 { 2062 2146 if (_annotations == null) { 2063 2147 _annotations = new HashMap<String, Text>(); 2064 2148 } 2149 2065 2150 // Check if this item has already been processed 2066 2151 String[] tokens = item.getProcessedText(); … … 2074 2159 String text = item.getText().trim(); 2075 2160 assert (text.charAt(0) == '@'); 2161 2076 2162 // Ignore annotations with spaces after the tag symbol 2077 2163 if (text.length() < 2 || !Character.isLetter(text.charAt(1))) { … … 2079 2165 return; 2080 2166 } 2167 2081 2168 // The separator char must come before the first non letter otherwise we 2082 2169 // ignore the annotation item … … 2101 2188 } 2102 2189 } 2190 2103 2191 // If it was nothing but letters and digits save the tag 2104 2192 String lowerCaseText = text.substring(1).toLowerCase(); … … 2107 2195 } 2108 2196 2109 public boolean hasAnnotation(String annotation) { 2110 if (_annotations == null) 2111 refreshAnnotationList(); 2197 public boolean hasAnnotation(String annotation) 2198 { 2199 if (_annotations == null) refreshAnnotationList(); 2200 2112 2201 return _annotations.containsKey(annotation.toLowerCase()); 2113 2202 } … … 2121 2210 * is not on the frame or has no value. 2122 2211 */ 2123 public String getAnnotationValue(String annotation) {2124 if (_annotations == null)2125 2212 public String getAnnotationValue(String annotation) 2213 { 2214 if (_annotations == null) refreshAnnotationList(); 2126 2215 2127 2216 Text text = _annotations.get(annotation.toLowerCase()); 2128 if (text == null) 2129 return null; 2217 if (text == null) return null; 2130 2218 2131 2219 String[] tokens = text.getProcessedText(); 2132 if (tokens != null && tokens.length > 1) 2133 return tokens[1]; 2220 2221 if (tokens != null && tokens.length > 1) return tokens[1]; 2222 2134 2223 return null; 2135 2224 } 2136 2225 2137 Map<String, Text> _annotations = null; 2138 2139 private Collection<FrameObserver> _observers = new HashSet<FrameObserver>(); 2140 2141 public void clearAnnotations() { 2226 public void clearAnnotations() 2227 { 2142 2228 _annotations = null; 2143 2229 } 2144 2230 2145 public List<Item> getVisibleItems() { 2231 public List<Item> getVisibleItems() 2232 { 2146 2233 return getItems(true); 2147 2234 } 2148 2235 2149 private void refreshAnnotationList() { 2150 if (_annotations == null) 2236 private void refreshAnnotationList() 2237 { 2238 if (_annotations == null) { 2151 2239 _annotations = new HashMap<String, Text>(); 2152 else2240 } else { 2153 2241 _annotations.clear(); 2242 } 2243 2154 2244 for (Text text : getTextItems()) { 2155 2245 if (text.isAnnotation()) { … … 2159 2249 } 2160 2250 2161 public Collection<Text> getAnnotationItems() { 2251 public Collection<Text> getAnnotationItems() 2252 { 2162 2253 if (_annotations == null) { 2163 2254 refreshAnnotationList(); 2164 2255 } 2256 2165 2257 return _annotations.values(); 2166 2258 } … … 2171 2263 * @return the list of items to be saved to a text file 2172 2264 */ 2173 public List<Item> getItemsToSave() {2174 2265 public List<Item> getItemsToSave() 2266 { 2175 2267 if (!_sorted) { 2176 2268 Collections.sort(_body); … … 2179 2271 2180 2272 // iWidgets are handled specially since 8 items are written as one 2181 Collection< InteractiveWidget> seenWidgets = new LinkedHashSet<InteractiveWidget>();2273 Collection<Widget> seenWidgets = new LinkedHashSet<Widget>(); 2182 2274 2183 2275 List<Item> toSave = new ArrayList<Item>(); 2184 2276 2185 2277 for (Item i : _body) { 2186 if (i == null || i.dontSave()) { 2187 continue; 2188 } 2278 if (i == null || i.dontSave()) continue; 2189 2279 2190 2280 // Ensure only one of the WidgetCorners represent a single widget 2191 2281 if (i instanceof WidgetCorner) { 2192 InteractiveWidget iw = ((WidgetCorner) i).getWidgetSource(); 2193 if (seenWidgets.contains(iw)) 2194 continue; 2282 Widget iw = ((WidgetCorner) i).getWidgetSource(); 2283 if (seenWidgets.contains(iw)) continue; 2195 2284 seenWidgets.add(iw); 2196 2285 toSave.add(iw.getSource()); … … 2198 2287 XRayable x = (XRayable) i; 2199 2288 toSave.addAll(x.getItemsToSave()); 2200 }// Circle centers are items with attached enclosures2201 else if (i.hasEnclosures()) {2289 // Circle centers are items with attached enclosures 2290 } else if (i.hasEnclosures()) { 2202 2291 continue; 2203 2292 } else { … … 2213 2302 } 2214 2303 2215 public Collection<Item> getOverlayItems() { 2304 public Collection<Item> getOverlayItems() 2305 { 2216 2306 return _overlayItems; 2217 2307 } … … 2223 2313 * @return 2224 2314 */ 2225 public boolean hasOverlay(Frame frame) { 2315 public boolean hasOverlay(Frame frame) 2316 { 2226 2317 return _overlays.containsValue(frame); 2227 2318 } 2228 2319 2229 public Collection<Item> getAllItems() { 2320 public Collection<Item> getAllItems() 2321 { 2230 2322 Collection<Item> allItems = new LinkedHashSet<Item>(_body); 2231 2323 allItems.addAll(_overlayItems); … … 2234 2326 } 2235 2327 2236 public Collection<Item> getVectorItems() { 2328 public Collection<Item> getVectorItems() 2329 { 2237 2330 Collection<Item> vectorItems = new LinkedHashSet<Item>(_vectorItems); 2238 2331 vectorItems.addAll(getNonAnnotationItems(false)); … … 2245 2338 * @return 2246 2339 */ 2247 public Collection<Text> getTextItems() { 2340 public Collection<Text> getTextItems() 2341 { 2248 2342 Collection<Text> textItems = new ArrayList<Text>(); 2343 2249 2344 for (Item i : getItems(true)) { 2250 2345 // only add up normal body text items … … 2253 2348 } 2254 2349 } 2350 2255 2351 return textItems; 2256 2352 } 2257 2353 2258 public Text getAnnotation(String annotation) {2259 if (_annotations == null)2260 2354 public Text getAnnotation(String annotation) 2355 { 2356 if (_annotations == null) refreshAnnotationList(); 2261 2357 2262 2358 return _annotations.get(annotation.toLowerCase()); 2263 2359 } 2264 2360 2265 public void recalculate() {2266 2361 public void recalculate() 2362 { 2267 2363 for (Item i : getItems()) { 2268 2364 if (i.hasFormula() && !i.isAnnotation()) { … … 2272 2368 } 2273 2369 2274 public void removeObserver(FrameObserver observer) { 2370 public void removeObserver(FrameObserver observer) 2371 { 2275 2372 _observers.remove(observer); 2276 2373 } 2277 2374 2278 public void addObserver(FrameObserver observer) { 2375 public void addObserver(FrameObserver observer) 2376 { 2279 2377 _observers.add(observer); 2280 2378 } 2281 2379 2282 public void clearObservers() { 2380 public void clearObservers() 2381 { 2283 2382 for (FrameObserver fl : _observers) { 2284 2383 fl.removeSubject(this); 2285 2384 } 2385 2286 2386 // The frame listener will call the frames removeListener method 2287 2387 assert (_observers.size() == 0); 2288 2388 } 2289 2389 2290 public Collection<Text> getNonAnnotationText(boolean removeTitle) { 2390 public Collection<Text> getNonAnnotationText(boolean removeTitle) 2391 { 2291 2392 Collection<Text> items = new LinkedHashSet<Text>(); 2393 2292 2394 for (Item i : getItems(true)) { 2293 2395 // only add up normal body text items … … 2296 2398 } 2297 2399 } 2400 2298 2401 if (removeTitle) { 2299 2402 items.remove(getTitleItem()); 2300 2403 } 2404 2301 2405 return items; 2302 2406 } 2303 2407 2304 public void dispose() { 2408 public void dispose() 2409 { 2305 2410 clearObservers(); 2411 2306 2412 for (Item i : _body) { 2307 2413 i.dispose(); 2308 2414 } 2415 2309 2416 _frameName.dispose(); 2310 2417 _body = null; … … 2312 2419 } 2313 2420 2314 public void parse() { 2421 public void parse() 2422 { 2315 2423 for (Overlay o : getOverlays()) { 2316 2424 o.Frame.parse(); 2317 2425 } 2426 2318 2427 // Must parse the frame AFTER the overlays 2319 2428 FrameUtils.Parse(this); 2320 2429 } 2321 2430 2322 public void setPath(String path) { 2431 public void setPath(String path) 2432 { 2323 2433 this.path = path; 2324 2434 } 2325 2435 2326 public String getPath() { 2436 public String getPath() 2437 { 2327 2438 return path; 2328 2439 } 2329 2440 2330 public void setLocal(boolean isLocal) { 2441 public void setLocal(boolean isLocal) 2442 { 2331 2443 this._isLocal = isLocal; 2332 2444 } 2333 2445 2334 public boolean isLocal() { 2446 public boolean isLocal() 2447 { 2335 2448 return _isLocal; 2336 2449 } 2337 2450 2338 public String getExportFileTagValue() { 2451 public String getExportFileTagValue() 2452 { 2339 2453 return getAnnotationValue("file"); 2340 2454 } 2341 2455 2342 public void assertEquals(Frame frame2) { 2456 public void assertEquals(Frame frame2) 2457 { 2343 2458 // Check that all the items on the frame are the same 2344 2459 List<Item> items1 = getVisibleItems(); 2345 2460 List<Item> items2 = frame2.getVisibleItems(); 2461 2346 2462 if (items1.size() != items2.size()) { 2347 throw new UnitTestFailedException(items1.size() + " items", items2 2348 .size() 2349 + " items"); 2463 throw new UnitTestFailedException(items1.size() + " items", items2.size() + " items"); 2350 2464 } else { 2351 2465 for (int i = 0; i < items1.size(); i++) { … … 2361 2475 } 2362 2476 2363 public boolean hasObservers() { 2477 public boolean hasObservers() 2478 { 2364 2479 return _observers != null && _observers.size() > 0; 2365 2480 } 2366 2481 2367 public Collection<? extends Item> getInteractableItems() { 2482 public Collection<? extends Item> getInteractableItems() 2483 { 2368 2484 /* 2369 2485 * TODO: Cache the interactableItems list so we dont have to recreate it 2370 2486 * every time this method is called 2371 2487 */ 2372 if (_interactableItems.size() > 0) 2373 return _interactableItems; 2488 if (_interactableItems.size() > 0) return _interactableItems; 2374 2489 2375 2490 for (Item i : _body) { 2376 if (i == null) { 2377 continue; 2378 } 2491 if (i == null) continue; 2379 2492 if (i.isVisible()) { 2380 2493 _interactableItems.add(i); … … 2386 2499 _interactableItems.add(i); 2387 2500 } 2388 2389 2390 2501 } 2391 2502 … … 2398 2509 return _interactableItems; 2399 2510 } 2511 2512 private static final class History { 2513 2514 public enum Type { 2515 deletion, 2516 movement 2517 } 2518 2519 public final List<Item> items; 2520 2521 public final Type type; 2522 2523 public History(Collection<Item> items, Type type) 2524 { 2525 this.items = new LinkedList<Item>(items); 2526 this.type = type; 2527 } 2528 2529 public String toString() 2530 { 2531 return this.type.toString() + ":\n" + this.items.toString(); 2532 } 2533 } 2400 2534 }
Note:
See TracChangeset
for help on using the changeset viewer.