Ignore:
Timestamp:
05/23/08 09:02:59 (16 years ago)
Author:
ra33
Message:

Added lots of stuff

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/items/ItemUtils.java

    r70 r72  
    1313import java.util.HashMap;
    1414import java.util.HashSet;
     15import java.util.LinkedHashSet;
    1516import java.util.LinkedList;
    1617import java.util.List;
     
    2122import org.expeditee.gui.DisplayIO;
    2223import org.expeditee.gui.Frame;
    23 import org.expeditee.stats.SessionStats;
    2424
    2525//Static methods that provide functions for the objects\
     
    7070        public static final int TAG_LINE_TEMPLATE = 17;
    7171
     72        public static final int TAG_STAT_TEMPLATE = 18;
     73
    7274        public static final int TAG_MIN = 0;
    7375
    74         public static final int TAG_MAX = 17;
     76        public static final int TAG_MAX = 18;
    7577
    7678        /**
     
    164166                return isTag(toCheck, GetTag(tag));
    165167        }
    166        
     168
    167169        public static boolean isTag(Item toCheck, int tag, boolean hasValue) {
    168170                return isTag(toCheck, GetTag(tag), hasValue);
     
    187189                // tags are ase-insensitive
    188190                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));
    190193        }
    191194
     
    272275         */
    273276        public static String GetTag(int tag) {
     277                // TODO refactor so that this uses a map for INT to tags
    274278                switch (tag) {
    275279                case TAG_SORT:
     
    289293                case TAG_ANNOTATION_TEMPLATE:
    290294                        return "@annotationtemplate";
     295                case TAG_STAT_TEMPLATE:
     296                        return "@stattemplate";
    291297                case TAG_CODE_COMMENT_TEMPLATE:
    292298                        return "@commenttemplate";
     
    618624                copy.removeAllConstraints();
    619625
    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 
    628626                // create a new line
    629                 Line line = new Line(origEnd, copy, num);
     627                Line line = new Line(origEnd, copy, DisplayIO.getCurrentFrame()
     628                                .getNextItemID());
    630629                // copy.setFloating(true);
    631630                origEnd.setArrowheadLength(0);
     
    636635                toReturn.add(line);
    637636                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                }
    638678        }
    639679
     
    646686         * is done dynamically (to account for Dots being moved).
    647687         */
    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) {
    649741                _seen.clear();
    650742
Note: See TracChangeset for help on using the changeset viewer.