Changeset 72 for trunk/src/org/expeditee/items/ItemUtils.java
- Timestamp:
- 05/23/08 09:02:59 (16 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/items/ItemUtils.java
r70 r72 13 13 import java.util.HashMap; 14 14 import java.util.HashSet; 15 import java.util.LinkedHashSet; 15 16 import java.util.LinkedList; 16 17 import java.util.List; … … 21 22 import org.expeditee.gui.DisplayIO; 22 23 import org.expeditee.gui.Frame; 23 import org.expeditee.stats.SessionStats;24 24 25 25 //Static methods that provide functions for the objects\ … … 70 70 public static final int TAG_LINE_TEMPLATE = 17; 71 71 72 public static final int TAG_STAT_TEMPLATE = 18; 73 72 74 public static final int TAG_MIN = 0; 73 75 74 public static final int TAG_MAX = 1 7;76 public static final int TAG_MAX = 18; 75 77 76 78 /** … … 164 166 return isTag(toCheck, GetTag(tag)); 165 167 } 166 168 167 169 public static boolean isTag(Item toCheck, int tag, boolean hasValue) { 168 170 return isTag(toCheck, GetTag(tag), hasValue); … … 187 189 // tags are ase-insensitive 188 190 return String.CASE_INSENSITIVE_ORDER.compare(txt.getFirstLine().trim(), 189 tag) == 0 || (hasValue && txt.startsWith(tag + " ", true)); 191 tag) == 0 192 || (hasValue && txt.startsWith(tag + " ", true)); 190 193 } 191 194 … … 272 275 */ 273 276 public static String GetTag(int tag) { 277 // TODO refactor so that this uses a map for INT to tags 274 278 switch (tag) { 275 279 case TAG_SORT: … … 289 293 case TAG_ANNOTATION_TEMPLATE: 290 294 return "@annotationtemplate"; 295 case TAG_STAT_TEMPLATE: 296 return "@stattemplate"; 291 297 case TAG_CODE_COMMENT_TEMPLATE: 292 298 return "@commenttemplate"; … … 618 624 copy.removeAllConstraints(); 619 625 620 int num = 0;621 622 // Mike: WHAT IS THIS CODE DOING?!!?623 for (Line line : origEnd.getLines())624 num = Math.min(num, line.getID());625 626 num--;627 628 626 // create a new line 629 Line line = new Line(origEnd, copy, num); 627 Line line = new Line(origEnd, copy, DisplayIO.getCurrentFrame() 628 .getNextItemID()); 630 629 // copy.setFloating(true); 631 630 origEnd.setArrowheadLength(0); … … 636 635 toReturn.add(line); 637 636 return toReturn; 637 } 638 639 public static void New() { 640 EnclosedCheck(DisplayIO.getCurrentFrame().getItems()); 641 } 642 643 public static void Old() { 644 OldEnclosedCheck(DisplayIO.getCurrentFrame().getItems()); 645 } 646 647 /** 648 * Updates the connectedToAnnotation flags for all items 649 */ 650 public static void UpdateConnectedToAnnotations(Collection<Item> items) { 651 // get all lineEnds on the Frame 652 Collection<Item> lineEnds = new LinkedHashSet<Item>(); 653 for (Item i : items) { 654 i.setConnectedToAnnotation(false); 655 if (i.isLineEnd()) { 656 lineEnds.add(i); 657 } 658 } 659 660 // if there are no line endpoints on the Frame, then there can't be an 661 // enclosure 662 if (lineEnds.size() == 0) 663 return; 664 665 // Now find go through line ends and see if any are annotation items 666 while (lineEnds.size() > 0) { 667 Item item = lineEnds.iterator().next(); 668 // If its an annotation item then set the flag for all its connected 669 // items 670 if (item.isAnnotation()) { 671 Collection<Item> connected = item.getAllConnected(); 672 for (Item i : connected) 673 i.setConnectedToAnnotation(true); 674 lineEnds.removeAll(connected); 675 } 676 lineEnds.remove(item); 677 } 638 678 } 639 679 … … 646 686 * is done dynamically (to account for Dots being moved). 647 687 */ 648 public static void EnclosedCheck(List<Item> items) { 688 public static void EnclosedCheck(Collection<Item> items) { 689 // get all lineEnds on the Frame 690 List<Item> lineEnds = new LinkedList<Item>(); 691 for (Item i : items) { 692 if (i.isLineEnd()) { 693 i.setEnclosedList(null); 694 // Add line ends joined to 2 other lines 695 if (i.getLines().size() == 2) 696 lineEnds.add(i); 697 } 698 } 699 700 // if there are no line endpoints on the Frame, then there can't be an 701 // enclosure 702 if (lineEnds.size() == 0) 703 return; 704 705 // New approach 706 while (lineEnds.size() > 0) { 707 Item item = lineEnds.get(0); 708 // Get the lineEnds connected to this item 709 Collection<Item> connected = item.getAllConnected(); 710 Collection<Item> connectedLineEnds = new LinkedHashSet<Item>(); 711 for (Item itemToCheck : connected) { 712 if (itemToCheck.isLineEnd()) 713 connectedLineEnds.add(itemToCheck); 714 } 715 // Check that all the line ends are in our lineEnds list 716 int oldSize = lineEnds.size(); 717 // Remove all the items from our line ends list 718 lineEnds.removeAll(connectedLineEnds); 719 int newSize = lineEnds.size(); 720 int connectedSize = connectedLineEnds.size(); 721 // Check if all the connectedItems were in the lineEnds collection 722 if (oldSize == newSize + connectedSize) { 723 // Set them to be the enclosed list for each of the items 724 for (Item enclosedLineEnd : connectedLineEnds) { 725 enclosedLineEnd.setEnclosedList(connectedLineEnds); 726 } 727 } 728 729 } 730 } 731 732 /** 733 * Checks through all Lines and Dots on the current Frame to detect if any 734 * form an enclosure, which can then be used to manipulate items within the 735 * polygon. If an enclosure is found, then the dots will have their 736 * enclosure value set to true, and a List is created that contains all the 737 * Dots in the order they were processed. Actual calculation of the Polygon 738 * is done dynamically (to account for Dots being moved). 739 */ 740 public static void OldEnclosedCheck(Collection<Item> items) { 649 741 _seen.clear(); 650 742
Note:
See TracChangeset
for help on using the changeset viewer.