Ignore:
Timestamp:
10/31/18 10:24:23 (6 years ago)
Author:
bln4
Message:
 
File:
1 edited

Legend:

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

    r1143 r1190  
    4040import org.expeditee.gui.Vector;
    4141import org.expeditee.items.Item.HighlightMode;
    42 import org.expeditee.items.widgets.Widget;
    4342import org.expeditee.items.widgets.InteractiveWidgetInitialisationFailedException;
    4443import org.expeditee.items.widgets.InteractiveWidgetNotAvailableException;
     44import org.expeditee.items.widgets.Widget;
    4545import org.expeditee.items.widgets.WidgetCorner;
    4646import org.expeditee.items.widgets.WidgetEdge;
     
    160160        public static Text FindTag(Collection<Item> items, String toFind) {
    161161                for (Item i : items) {
    162                         if (i instanceof Text && i.isAnnotation())
    163                                 if (((Text) i).startsWith(toFind))
     162                        if (i instanceof Text && i.isAnnotation()) {
     163                                if (((Text) i).startsWith(toFind)) {
    164164                                        return (Text) i;
     165                                }
     166                        }
    165167                }
    166168                return null;
     
    169171        public static Item FindExactTag(Collection<Item> items, String toFind) {
    170172                for (Item i : items) {
    171                         if (i instanceof Text && i.isAnnotation())
    172                                 if (((Text) i).getText().trim().equalsIgnoreCase(toFind))
    173                                         return (Item) i;
     173                        if (i instanceof Text && i.isAnnotation()) {
     174                                if (((Text) i).getText().trim().equalsIgnoreCase(toFind)) {
     175                                        return i;
     176                                }
     177                        }
    174178                }
    175179
     
    212216        public static boolean startsWithTag(Item toCheck, String tag,
    213217                        boolean valueAllowed) {
    214                 if (!(toCheck instanceof Text))
     218                if (!(toCheck instanceof Text)) {
    215219                        return false;
     220                }
    216221
    217222                Text txt = (Text) toCheck;
    218223                String value = ItemUtils.StripTag(txt.getText(), tag);
    219224
    220                 if (value == null)
     225                if (value == null) {
    221226                        return false;
     227                }
    222228                return valueAllowed || value.equals("");
    223229        }
     
    246252         */
    247253        public static String StripTag(String toStrip, String tag) {
    248                 if (toStrip == null)
     254                if (toStrip == null) {
    249255                        return null;
     256                }
    250257                toStrip = toStrip.trim();
    251                 if (!toStrip.toLowerCase().startsWith(tag.toLowerCase()))
     258                if (!toStrip.toLowerCase().startsWith(tag.toLowerCase())) {
    252259                        return null;
    253 
    254                 if (toStrip.length() == tag.length())
     260                }
     261
     262                if (toStrip.length() == tag.length()) {
    255263                        return "";
     264                }
    256265                // remove tag and ensure the char is the tag separator
    257266                char separator = toStrip.charAt(tag.length());
    258                 if (separator != ':')
     267                if (separator != ':') {
    259268                        return null;
    260 
    261                 if (toStrip.length() == tag.length() + 1)
     269                }
     270
     271                if (toStrip.length() == tag.length() + 1) {
    262272                        return "";
     273                }
    263274
    264275                return toStrip.substring(tag.length() + 1).trim();
     
    377388
    378389                        int fileSuffixChar = text.indexOf('.');
    379                         if (fileSuffixChar < 0)
     390                        if (fileSuffixChar < 0) {
    380391                                return null;
     392                        }
    381393                        int endOfFileName = text.indexOf(' ', fileSuffixChar);
    382394                        if (endOfFileName < 0) {
     
    394406                        for (String dir : FolderSettings.ImageDirs.get()) {
    395407                                file = new File(dir + path);
    396                                 if (file.exists() && !file.isDirectory())
     408                                if (file.exists() && !file.isDirectory()) {
    397409                                        break;
    398                         }
    399 
    400                         if (file == null || !file.exists() || file.isDirectory())
     410                                }
     411                        }
     412
     413                        if (file == null || !file.exists() || file.isDirectory()) {
    401414                                file = new File(path);
     415                        }
    402416
    403417                        // try relative path
     
    415429                                }
    416430
    417                         } else
     431                        } else {
    418432                                path = file.getPath();
     433                        }
    419434
    420435                        // if the image isn't found by now, try remote servers
     
    487502                for (Item i : toCopy) {
    488503                        // Dont copy parts of a vector
    489                         if (i == null || !i.hasPermission(UserAppliedPermission.copy))
     504                        if (i == null || !i.hasPermission(UserAppliedPermission.copy)) {
    490505                                continue;
     506                        }
    491507
    492508                        // BROOK
    493509                        if (i instanceof WidgetCorner) { // dont add these
    494510                                if (!widgets.contains(((WidgetCorner) i).getWidgetSource()))
     511                                 {
    495512                                        widgets.add(((WidgetCorner) i).getWidgetSource());
    496513                                // BROOK
     514                                }
    497515                        } else if (i instanceof WidgetEdge) { // dont add these
    498516                                // lines are recreated later
     
    577595                        Item originalLineEnd = line.getEndItem();
    578596                        Item actualLineEnd = lineEndMap.get(originalLineEnd);
    579                         if (actualLineEnd == null)
     597                        if (actualLineEnd == null) {
    580598                                lineCopy.setEndItem(originalLineEnd);
    581                         else
     599                        } else {
    582600                                lineCopy.setEndItem(actualLineEnd);
     601                        }
    583602
    584603                        Item originalLineStart = line.getStartItem();
    585604                        Item actualLineStart = lineEndMap.get(originalLineStart);
    586                         if (actualLineStart == null)
     605                        if (actualLineStart == null) {
    587606                                lineCopy.setStartItem(originalLineStart);
    588                         else
     607                        } else {
    589608                                lineCopy.setStartItem(actualLineStart);
     609                        }
    590610
    591611                        copies.add(lineCopy);
     
    618638
    619639                // Make sure filled rectangles are shown filled on vector overlays
    620                 if (v != null)
     640                if (v != null) {
    621641                        EnclosedCheck(copies);
     642                }
    622643
    623644                return copies;
     
    637658        public static List<Item> UnreelLine(Item toUnreelFrom, boolean constrain) {
    638659                // the Item must already have one line to be unreeled from
    639                 if (toUnreelFrom == null || toUnreelFrom.getLines().size() < 1)
     660                if (toUnreelFrom == null || toUnreelFrom.getLines().size() < 1) {
    640661                        return null;
     662                }
    641663
    642664                List<Item> unreel = new ArrayList<Item>(2);
     
    670692                        if (item.isLineEnd()) {
    671693                                // if there are multiple ends in the list, return
    672                                 if (origEnd != null)
     694                                if (origEnd != null) {
    673695                                        return null;
     696                                }
    674697
    675698                                origEnd = item;
     
    747770                // if there are no line endpoints on the Frame, then there can't be an
    748771                // enclosure
    749                 if (lineEnds.size() == 0)
     772                if (lineEnds.size() == 0) {
    750773                        return;
     774                }
    751775
    752776                // Now find go through line ends and see if any are annotation items
     
    757781                        if (item.isAnnotation()) {
    758782                                Collection<Item> connected = item.getAllConnected();
    759                                 for (Item i : connected)
     783                                for (Item i : connected) {
    760784                                        i.setConnectedToAnnotation(true);
     785                                }
    761786                                lineEnds.removeAll(connected);
    762787                        }
     
    780805                                i.setEnclosedList(null);
    781806                                // Add line ends joined to 2 other lines
    782                                 if (i.getLines().size() == 2)
     807                                if (i.getLines().size() == 2) {
    783808                                        lineEnds.add(i);
     809                                }
    784810                        }
    785811                }
     
    787813                // if there are no line endpoints on the Frame, then there can't be an
    788814                // enclosure
    789                 if (lineEnds.size() == 0)
     815                if (lineEnds.size() == 0) {
    790816                        return;
     817                }
    791818
    792819                // New approach
     
    797824                        Collection<Item> connectedLineEnds = new LinkedHashSet<Item>();
    798825                        for (Item itemToCheck : connected) {
    799                                 if (itemToCheck.isLineEnd())
     826                                if (itemToCheck.isLineEnd()) {
    800827                                        connectedLineEnds.add(itemToCheck);
     828                                }
    801829                        }
    802830                        // Check that all the line ends are in our lineEnds list
     
    833861                                i.setEnclosedList(null);
    834862
    835                                 if (i.getLines().size() == 2)
     863                                if (i.getLines().size() == 2) {
    836864                                        lineEnds.add(i);
     865                                }
    837866                        }
    838867                }
     
    840869                // if there are no line endpoints on the Frame, then there can't be an
    841870                // enclosure
    842                 if (lineEnds.size() == 0)
     871                if (lineEnds.size() == 0) {
    843872                        return;
     873                }
    844874
    845875                // TODO optimise this code!!
     
    853883                                        _path.add(l.getOppositeEnd(searchFor));
    854884
    855                                         for (Item i : _path)
     885                                        for (Item i : _path) {
    856886                                                i.setEnclosedList(_path);
     887                                        }
    857888
    858889                                        _path = new ArrayList<Item>(0);
     
    869900
    870901        private static boolean traverse(Item toFind, Item searchFrom) {
    871                 if (toFind == null || searchFrom == null || !searchFrom.isLineEnd())
     902                if (toFind == null || searchFrom == null || !searchFrom.isLineEnd()) {
    872903                        return false;
    873 
    874                 if (searchFrom.getLines().size() != 2)
     904                }
     905
     906                if (searchFrom.getLines().size() != 2) {
    875907                        return false;
    876 
    877                 if (toFind == searchFrom)
     908                }
     909
     910                if (toFind == searchFrom) {
    878911                        return true;
     912                }
    879913
    880914                for (Line l : searchFrom.getLines()) {
     
    924958        public static boolean isVisible(Frame fromFrame, Item i)
    925959        {
    926                 if (fromFrame == null) return false;
     960                if (fromFrame == null) {
     961                        return false;
     962                }
    927963
    928964                Frame parent = i.getParent();
     
    939975        public static AxisAlignedBoxBounds expandRectangle(AxisAlignedBoxBounds r, int n)
    940976        {
    941                 if (r == null) return null;
     977                if (r == null) {
     978                        return null;
     979                }
    942980               
    943981                return new AxisAlignedBoxBounds(r.getMinX() - (n >> 1), r.getMinY() - (n >> 1), r.getWidth() + n, r.getHeight() + n);
     
    10221060                        if (i instanceof WidgetEdge) {
    10231061                                WidgetEdge we = (WidgetEdge) i;
    1024                                 if (!iWidgets.contains(we.getWidgetSource()))
     1062                                if (!iWidgets.contains(we.getWidgetSource())) {
    10251063                                        iWidgets.add(we.getWidgetSource());
     1064                                }
    10261065                        } else if (i instanceof WidgetCorner) {
    10271066                                WidgetCorner wc = (WidgetCorner) i;
    1028                                 if (!iWidgets.contains(wc.getWidgetSource()))
     1067                                if (!iWidgets.contains(wc.getWidgetSource())) {
    10291068                                        iWidgets.add(wc.getWidgetSource());
     1069                                }
    10301070                        }
    10311071                }
     
    10551095        public static void Justify(Frame frame)
    10561096        {
    1057                 if (frame == null) return;
     1097                if (frame == null) {
     1098                        return;
     1099                }
    10581100                EnclosedCheck(frame.getItems());
    10591101                Justify(frame.getItems());
Note: See TracChangeset for help on using the changeset viewer.