Ignore:
Timestamp:
09/28/18 10:21:23 (6 years ago)
Author:
bln4
Message:
 
File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/expeditee/gui/FrameUtils.java

    r1144 r1173  
    6262import org.expeditee.items.XRayable;
    6363import org.expeditee.items.widgets.ButtonWidget;
    64 import org.expeditee.items.widgets.Widget;
    6564import org.expeditee.items.widgets.InteractiveWidgetInitialisationFailedException;
    6665import org.expeditee.items.widgets.InteractiveWidgetNotAvailableException;
     66import org.expeditee.items.widgets.Widget;
    6767import org.expeditee.items.widgets.WidgetCorner;
    6868import org.expeditee.items.widgets.WidgetEdge;
     
    120120         */
    121121        public static boolean inSameColumn(Item item1, Item item2) {
    122                 if (!(item1 instanceof Text) || !(item2 instanceof Text))
     122                if (!(item1 instanceof Text) || !(item2 instanceof Text)) {
    123123                        return false;
    124 
    125                 if (item1.getID() < 0 || item2.getID() < 0)
     124                }
     125
     126                if (item1.getID() < 0 || item2.getID() < 0) {
    126127                        return false;
     128                }
    127129
    128130                int minX = item2.getX();
     
    133135
    134136                // Check that the two items left values are close
    135                 if (Math.abs(item1.getX() - item2.getX()) > COLUMN_WIDTH)
     137                if (Math.abs(item1.getX() - item2.getX()) > COLUMN_WIDTH) {
    136138                        return false;
     139                }
    137140
    138141                // Ensure the two items
     
    140143                                || (maxX >= startX && maxX <= endX)
    141144                                || (startX >= minX && startX <= maxX)
    142                                 || (endX >= minX && endX <= maxX))
     145                                || (endX >= minX && endX <= maxX)) {
    143146                        return true;
     147                }
    144148
    145149                return false;
     
    148152        public static boolean sameBulletType(String bullet1, String bullet2)
    149153        {
    150                 if (bullet1 == null || bullet2 == null)
     154                if (bullet1 == null || bullet2 == null) {
    151155                        return false;
    152 
    153                 if (bullet1.equals("") || bullet2.equals(""))
     156                }
     157
     158                if (bullet1.equals("") || bullet2.equals("")) {
    154159                        return false;
     160                }
    155161
    156162                if (Character.isLetter(bullet1.charAt(0))
    157                                 && Character.isLetter(bullet2.charAt(0)))
     163                                && Character.isLetter(bullet2.charAt(0))) {
    158164                        return true;
     165                }
    159166
    160167                if (Character.isDigit(bullet1.charAt(0))
    161                                 && Character.isDigit(bullet2.charAt(0)))
     168                                && Character.isDigit(bullet2.charAt(0))) {
    162169                        return true;
     170                }
    163171
    164172                // TODO make this more sofisticated
     
    168176
    169177        private static boolean needsRenumbering(String s) {
    170                 if (s == null || s.equals(""))
     178                if (s == null || s.equals("")) {
    171179                        return false;
    172                 if (!Character.isLetterOrDigit(s.charAt(0)))
     180                }
     181                if (!Character.isLetterOrDigit(s.charAt(0))) {
    173182                        return false;
     183                }
    174184
    175185                s = s.trim();
     
    177187                if (s.length() > 2) {
    178188                        for (int i = 0; i < s.length() - 1; i++) {
    179                                 if (!Character.isLetter(s.charAt(i)))
     189                                if (!Character.isLetter(s.charAt(i))) {
    180190                                        return true;
    181                         }
    182                 } else
     191                                }
     192                        }
     193                } else {
    183194                        return true;
     195                }
    184196
    185197                return false;
     
    201213                 * still want to format them... ie if they are too close together.
    202214                 */
    203                 if (toAlign.size() < 1)
     215                if (toAlign.size() < 1) {
    204216                        return 0;
     217                }
    205218
    206219                // get the first item
    207220                Text from = toAlign.get(0);
    208                 if (from.getParent() == null)
     221                if (from.getParent() == null) {
    209222                        from = toAlign.get(1);
     223                }
    210224                int x = from.getX();
    211225
     
    215229                String lastBullet = "";
    216230
    217                 if (above != null && curr.isNormalTextItem(above))
     231                if (above != null && curr.isNormalTextItem(above)) {
    218232                        lastBullet = StandardGestureActions.getAutoBullet(above.getText());
    219                 else {
     233                } else {
    220234                        lastBullet = StandardGestureActions.getBullet(toAlign.get(0)
    221235                                        .getText());
     
    272286                        // Make the gap between all items the same as the gap between
    273287                        // the first two
    274                         space = (int) (from.getBounds().getMinY() - above.getBounds().getMaxY());
    275 
    276                         if (space < MINIMUM_INTERITEM_SPACING)
     288                        space = from.getBounds().getMinY() - above.getBounds().getMaxY();
     289
     290                        if (space < MINIMUM_INTERITEM_SPACING) {
    277291                                space = MINIMUM_INTERITEM_SPACING;
     292                        }
    278293
    279294                        if (UserSettings.FormatSpacingMax.get() != null) {
     
    297312                                        && above != curr.getTitleItem()) {
    298313                                x = above.getX();
    299                                 int y = (int) above.getBounds().getMaxY()
     314                                int y = above.getBounds().getMaxY()
    300315                                                + space
    301                                                 + ((int) (from.getY() - from.getBounds().getMinY()));
     316                                                + (from.getY() - from.getBounds().getMinY());
    302317
    303318                                if (changedItems != null
     
    320335
    321336                        // The bottom of the previous item
    322                         int bottom = (int) top.getBounds().getMaxY();
     337                        int bottom = top.getBounds().getMaxY();
    323338
    324339                        // the difference between the current item's Y coordinate and
    325340                        // the top of the highlight box
    326                         int diff = (int) (current.getY() - current.getBounds().getMinY());
     341                        int diff = current.getY() - current.getBounds().getMinY();
    327342
    328343                        int newPos = bottom + space + diff;
     
    360375                // active overlay frames may also require saving if they have been
    361376                // changed
    362                 for (Overlay o : current.getOverlays())
    363                         if (!SaveCheck(o.Frame))
     377                for (Overlay o : current.getOverlays()) {
     378                        if (!SaveCheck(o.Frame)) {
    364379                                return false;
     380                        }
     381                }
    365382
    366383                // if the check fails there is no point continuing
    367                 if (!SaveCheck(current))
     384                if (!SaveCheck(current)) {
    368385                        return false;
     386                }
    369387
    370388                for (Item i : current.getItems()) {
     
    377395        private static boolean SaveCheck(Frame toSave) {
    378396                // don't bother saving frames that haven't changed
    379                 if (!toSave.hasChanged())
     397                if (!toSave.hasChanged()) {
    380398                        return true;
     399                }
    381400
    382401                // if the frame has been changed, then save it
     
    385404
    386405                        String side = "left";
    387                         if (DisplayController.getCurrentSide() == DisplayController.TwinFramesSide.RIGHT)
     406                        if (DisplayController.getCurrentSide() == DisplayController.TwinFramesSide.RIGHT) {
    388407                                side = "right";
     408                        }
    389409
    390410                        // if the two frames both have changes, prompt the user for the
     
    395415                                        DisplayController.Reload(DisplayController.getSideFrameIsOn(opposite));
    396416                                        return true;
    397                                 } else
     417                                } else {
    398418                                        return false;
     419                                }
    399420                        } else if (opposite.hasOverlay(toSave)) {
    400                                 if (toSave.hasChanged())
     421                                if (toSave.hasChanged()) {
    401422                                        if (EcosystemManager.getGraphicsManager().showDialog("Changes", "Leaving this frame will discard changes made in the " + side + " Frame. Continue?")) {
    402423                                                FrameIO.SaveFrame(toSave);
    403424                                                DisplayController.Reload(DisplayController.getSideFrameIsOn(opposite));
    404425                                                return true;
    405                                         } else
     426                                        } else {
    406427                                                return false;
     428                                        }
     429                                }
    407430                        }
    408431
     
    467490        public static void DisplayFrame(Frame toDisplay, boolean addToBack, boolean incrementStats)
    468491        {
    469                 if (toDisplay == null)
     492                if (toDisplay == null) {
    470493                        return;
     494                }
    471495
    472496                Frame current = DisplayController.getCurrentFrame();
     
    474498                // Dont need to do anything if the frame to display is already being
    475499                // displayed
    476                 if (current.equals(toDisplay))
     500                if (current.equals(toDisplay)) {
    477501                        return;
     502                }
    478503
    479504                // move any anchored connected items
     
    568593                Frame newFrame = getFrame(frameName);
    569594
    570                 if (newFrame != null)
     595                if (newFrame != null) {
    571596                        // display the frame
    572597                        DisplayFrame(newFrame, addToBack, incrementStats);
     598                }
    573599        }
    574600
     
    641667        private static boolean createWidget(Frame frame, Text txt) {
    642668
    643                 if (frame == null)
     669                if (frame == null) {
    644670                        throw new NullPointerException("frame");
    645                 if (txt == null)
     671                }
     672                if (txt == null) {
    646673                        throw new NullPointerException("txt");
     674                }
    647675
    648676                // Safety
    649                 if (txt.getParent() == null)
     677                if (txt.getParent() == null) {
    650678                        txt.setParent(frame);
     679                }
    651680
    652681                Widget iw = null;
     
    667696                }
    668697
    669                 if (iw == null)
     698                if (iw == null) {
    670699                        return false;
     700                }
    671701
    672702                frame.removeItem(txt);
     
    681711                List<String> errors = new LinkedList<String>();
    682712               
    683                 if (profile == null) return errors;
     713                if (profile == null) {
     714                        return errors;
     715                }
    684716
    685717                /*
     
    698730                                String attributeFullCase = avp.getAttributeOrValue();
    699731
    700                                 if (attributeFullCase == null) continue;
     732                                if (attributeFullCase == null) {
     733                                        continue;
     734                                }
    701735                               
    702736                                String attribute = attributeFullCase.trim().toLowerCase().replaceAll("^@", "");
    703737
    704                                 if (attribute.equals("settings")) Settings.parseSettings(item);
     738                                if (attribute.equals("settings")) {
     739                                        Settings.parseSettings(item);
     740                                }
    705741
    706742                        } catch (Exception e) {
     
    724760        public static void loadFirstFrame(Frame profile)
    725761        {
    726                 if (UserSettings.HomeFrame.get() == null) UserSettings.HomeFrame.set(profile.getName());
     762                if (UserSettings.HomeFrame.get() == null) {
     763                        UserSettings.HomeFrame.set(profile.getName());
     764                }
    727765
    728766                Frame firstFrame = FrameIO.LoadFrame(UserSettings.HomeFrame.get());
     
    755793        public static String getLink(Item item, String alt)
    756794        {
    757                 if (item == null || !(item instanceof Text)) return alt;
     795                if (item == null || !(item instanceof Text)) {
     796                        return alt;
     797                }
    758798
    759799                AttributeValuePair avp = new AttributeValuePair(item.getText());
     
    798838                                        File tester = new File(dirName);
    799839                                        if (tester.exists() && tester.isDirectory()) {
    800                                                 if (dirName.endsWith(File.separator))
     840                                                if (dirName.endsWith(File.separator)) {
    801841                                                        dirsToAdd.add(dirName);
    802                                                 else
     842                                                } else {
    803843                                                        dirsToAdd.add(dirName + File.separator);
     844                                                }
    804845                                        }
    805846                                }
     
    838879                // TODO check why we are getting toParse == null... when profile frame
    839880                // is being created and change the lines below
    840                 if (toParse == null) return;
    841 
    842                 if (firstParse) ItemUtils.EnclosedCheck(toParse.getItems());
     881                if (toParse == null) {
     882                        return;
     883                }
     884
     885                if (firstParse) {
     886                        ItemUtils.EnclosedCheck(toParse.getItems());
     887                }
    843888               
    844889                List<Item> items = toParse.getItems();
     
    882927
    883928                // disable reading of cached overlays if in twinframes mode
    884                 if (DisplayController.isTwinFramesOn()) FrameIO.SuspendCache();
     929                if (DisplayController.isTwinFramesOn()) {
     930                        FrameIO.SuspendCache();
     931                }
    885932
    886933                DotType pointtype = DotType.square;
     
    913960                                                                        String fill = line.substring(line
    914961                                                                                        .indexOf(" ") + 1);
    915                                                                         if (fill.startsWith("nofill"))
     962                                                                        if (fill.startsWith("nofill")) {
    916963                                                                                filledPoints = false;
    917                                                                         else
     964                                                                        } else {
    918965                                                                                filledPoints = true;
     966                                                                        }
    919967                                                                }
    920968
    921                                                                 if (line.startsWith("circle"))
     969                                                                if (line.startsWith("circle")) {
    922970                                                                        pointtype = DotType.circle;
    923                                                                 else
     971                                                                } else {
    924972                                                                        pointtype = DotType.square;
     973                                                                }
    925974                                                        }
    926975                                                }// check for new VECTOR items
     
    929978                                                                                ItemUtils.TAG_VECTOR)
    930979                                                                && i.getLink() != null) {
    931                                                         if (!i.getAbsoluteLink().equals(toParse.getName()))
     980                                                        if (!i.getAbsoluteLink().equals(toParse.getName())) {
    932981                                                                addVector(vectors, UserAppliedPermission.none,
    933982                                                                                permission, i);
     983                                                        }
    934984                                                } else if (!DisplayController.isXRayMode()
    935985                                                                && ItemUtils.startsWithTag(i,
    936986                                                                                ItemUtils.TAG_ACTIVE_VECTOR)
    937987                                                                && i.getLink() != null) {
    938                                                         if (!i.getAbsoluteLink().equals(toParse.getName()))
     988                                                        if (!i.getAbsoluteLink().equals(toParse.getName())) {
    939989                                                                addVector(vectors,
    940990                                                                                UserAppliedPermission.followLinks,
    941991                                                                                permission, i);
     992                                                        }
    942993                                                }
    943994                                                // check for new OVERLAY items
     
    9761027                                                                for (Overlay o : current.getOverlays()) {
    9771028                                                                        if (o.Frame.getName()
    978                                                                                         .equalsIgnoreCase(link))
     1029                                                                                        .equalsIgnoreCase(link)) {
    9791030                                                                                overlayFrame = o.Frame;
     1031                                                                        }
    9801032                                                                }
    9811033                                                        }
    982                                                         if (overlayFrame == null)
     1034                                                        if (overlayFrame == null) {
    9831035                                                                overlayFrame = FrameIO.LoadFrame(link);
     1036                                                        }
    9841037
    9851038                                                        // get level if specified
     
    11561209                int x = Math.round(floatX);
    11571210                int y = Math.round(floatY);
    1158                 if (toCheck == null)
     1211                if (toCheck == null) {
    11591212                        return null;
     1213                }
    11601214
    11611215                List<Item> possibles = new ArrayList<Item>(0);
     
    12411295
    12421296                // if there are no possible items, return null
    1243                 if (possibles.size() == 0)
     1297                if (possibles.size() == 0) {
    12441298                        return null;
     1299                }
    12451300
    12461301                // if there is only one possibility, return it
    1247                 if (possibles.size() == 1)
     1302                if (possibles.size() == 1) {
    12481303                        return possibles.get(0);
     1304                }
    12491305
    12501306                // return closest x,y pair to mouse
     
    12641320                                // dots take precedence over lines
    12651321                                if ((!(closest instanceof Dot && i instanceof Line))
    1266                                                 && (!(closest instanceof Text && i instanceof Line)))
     1322                                                && (!(closest instanceof Text && i instanceof Line))) {
    12671323                                        closest = i;
     1324                                }
    12681325
    12691326                        }
     
    12941351                Collection<Item> enclosure = getEnclosingLineEnds();
    12951352               
    1296                 if (enclosure == null || enclosure.size() == 0) return null;
     1353                if (enclosure == null || enclosure.size() == 0) {
     1354                        return null;
     1355                }
    12971356
    12981357                return enclosure.iterator().next().getEnclosedShape();
     
    13131372                Collection<Item> enclosure = getEnclosingLineEnds();
    13141373               
    1315                 if (enclosure == null || enclosure.size() == 0) return null;
     1374                if (enclosure == null || enclosure.size() == 0) {
     1375                        return null;
     1376                }
    13161377
    13171378                Item firstItem = enclosure.iterator().next();
     
    13781439                // update enclosed shapes
    13791440                Frame current = DisplayController.getCurrentFrame();
    1380                 if (current == null) return null;
     1441                if (current == null) {
     1442                        return null;
     1443                }
    13811444                List<Item> items = current.getItems();
    13821445
     
    14041467                }
    14051468
    1406                 if (used.size() == 0) return null;
     1469                if (used.size() == 0) {
     1470                        return null;
     1471                }
    14071472
    14081473                // if there is only one possibility, return it
     
    14121477                } else {
    14131478                        Collections.sort(used, new Comparator<Item>() {
     1479                                @Override
    14141480                                public int compare(Item d1, Item d2) {
    14151481                                        PolygonBounds p1 = d1.getEnclosedShape();
     
    14261492                                                int diff2 = Integer.MAX_VALUE;
    14271493
    1428                                                 if (i < p2.getPointCount())
     1494                                                if (i < p2.getPointCount()) {
    14291495                                                        diff2 = Math.abs(p2.getPoint(i).getX() - mouseX)  + Math.abs(p2.getPoint(i).getY() - mouseY);
     1496                                                }
    14301497
    14311498                                                if (diff < Math.abs(closest)) {
    14321499                                                        close2 = closest;
    14331500                                                        closest = diff;
    1434                                                 } else if (diff < Math.abs(close2))
     1501                                                } else if (diff < Math.abs(close2)) {
    14351502                                                        close2 = diff;
     1503                                                }
    14361504
    14371505                                                if (diff2 < Math.abs(closest)) {
    14381506                                                        close2 = closest;
    14391507                                                        closest = -diff2;
    1440                                                 } else if (diff2 < Math.abs(close2))
     1508                                                } else if (diff2 < Math.abs(close2)) {
    14411509                                                        close2 = diff2;
    1442                                         }
    1443 
    1444                                         if (closest > 0 && close2 > 0)
     1510                                                }
     1511                                        }
     1512
     1513                                        if (closest > 0 && close2 > 0) {
    14451514                                                return -10;
    1446 
    1447                                         if (closest < 0 && close2 < 0)
     1515                                        }
     1516
     1517                                        if (closest < 0 && close2 < 0) {
    14481518                                                return 10;
    1449 
    1450                                         if (closest > 0)
     1519                                        }
     1520
     1521                                        if (closest > 0) {
    14511522                                                return -10;
     1523                                        }
    14521524
    14531525                                        return 10;
     
    18211893                File check = new File(FrameIO.PARENT_FOLDER + ".res");
    18221894               
    1823                 if(!force && check.exists()) return;
     1895                if(!force && check.exists()) {
     1896                        return;
     1897                }
    18241898               
    18251899                System.out.println("Extracting/Installing resources:");
     
    19352009        public static void copyFile(File src, File dst, boolean overWrite) throws IOException
    19362010        {
    1937                 if(!overWrite && dst.exists()) return;
     2011                if(!overWrite && dst.exists()) {
     2012                        return;
     2013                }
    19382014               
    19392015                dst.getParentFile().mkdirs();
Note: See TracChangeset for help on using the changeset viewer.