Changeset 1173 for trunk/src/org/expeditee/gui
- Timestamp:
- 09/28/18 10:21:23 (6 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/expeditee/gui/FrameUtils.java
r1144 r1173 62 62 import org.expeditee.items.XRayable; 63 63 import org.expeditee.items.widgets.ButtonWidget; 64 import org.expeditee.items.widgets.Widget;65 64 import org.expeditee.items.widgets.InteractiveWidgetInitialisationFailedException; 66 65 import org.expeditee.items.widgets.InteractiveWidgetNotAvailableException; 66 import org.expeditee.items.widgets.Widget; 67 67 import org.expeditee.items.widgets.WidgetCorner; 68 68 import org.expeditee.items.widgets.WidgetEdge; … … 120 120 */ 121 121 public static boolean inSameColumn(Item item1, Item item2) { 122 if (!(item1 instanceof Text) || !(item2 instanceof Text)) 122 if (!(item1 instanceof Text) || !(item2 instanceof Text)) { 123 123 return false; 124 125 if (item1.getID() < 0 || item2.getID() < 0) 124 } 125 126 if (item1.getID() < 0 || item2.getID() < 0) { 126 127 return false; 128 } 127 129 128 130 int minX = item2.getX(); … … 133 135 134 136 // 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) { 136 138 return false; 139 } 137 140 138 141 // Ensure the two items … … 140 143 || (maxX >= startX && maxX <= endX) 141 144 || (startX >= minX && startX <= maxX) 142 || (endX >= minX && endX <= maxX)) 145 || (endX >= minX && endX <= maxX)) { 143 146 return true; 147 } 144 148 145 149 return false; … … 148 152 public static boolean sameBulletType(String bullet1, String bullet2) 149 153 { 150 if (bullet1 == null || bullet2 == null) 154 if (bullet1 == null || bullet2 == null) { 151 155 return false; 152 153 if (bullet1.equals("") || bullet2.equals("")) 156 } 157 158 if (bullet1.equals("") || bullet2.equals("")) { 154 159 return false; 160 } 155 161 156 162 if (Character.isLetter(bullet1.charAt(0)) 157 && Character.isLetter(bullet2.charAt(0))) 163 && Character.isLetter(bullet2.charAt(0))) { 158 164 return true; 165 } 159 166 160 167 if (Character.isDigit(bullet1.charAt(0)) 161 && Character.isDigit(bullet2.charAt(0))) 168 && Character.isDigit(bullet2.charAt(0))) { 162 169 return true; 170 } 163 171 164 172 // TODO make this more sofisticated … … 168 176 169 177 private static boolean needsRenumbering(String s) { 170 if (s == null || s.equals("")) 178 if (s == null || s.equals("")) { 171 179 return false; 172 if (!Character.isLetterOrDigit(s.charAt(0))) 180 } 181 if (!Character.isLetterOrDigit(s.charAt(0))) { 173 182 return false; 183 } 174 184 175 185 s = s.trim(); … … 177 187 if (s.length() > 2) { 178 188 for (int i = 0; i < s.length() - 1; i++) { 179 if (!Character.isLetter(s.charAt(i))) 189 if (!Character.isLetter(s.charAt(i))) { 180 190 return true; 181 } 182 } else 191 } 192 } 193 } else { 183 194 return true; 195 } 184 196 185 197 return false; … … 201 213 * still want to format them... ie if they are too close together. 202 214 */ 203 if (toAlign.size() < 1) 215 if (toAlign.size() < 1) { 204 216 return 0; 217 } 205 218 206 219 // get the first item 207 220 Text from = toAlign.get(0); 208 if (from.getParent() == null) 221 if (from.getParent() == null) { 209 222 from = toAlign.get(1); 223 } 210 224 int x = from.getX(); 211 225 … … 215 229 String lastBullet = ""; 216 230 217 if (above != null && curr.isNormalTextItem(above)) 231 if (above != null && curr.isNormalTextItem(above)) { 218 232 lastBullet = StandardGestureActions.getAutoBullet(above.getText()); 219 else {233 } else { 220 234 lastBullet = StandardGestureActions.getBullet(toAlign.get(0) 221 235 .getText()); … … 272 286 // Make the gap between all items the same as the gap between 273 287 // 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) { 277 291 space = MINIMUM_INTERITEM_SPACING; 292 } 278 293 279 294 if (UserSettings.FormatSpacingMax.get() != null) { … … 297 312 && above != curr.getTitleItem()) { 298 313 x = above.getX(); 299 int y = (int)above.getBounds().getMaxY()314 int y = above.getBounds().getMaxY() 300 315 + space 301 + ( (int) (from.getY() - from.getBounds().getMinY()));316 + (from.getY() - from.getBounds().getMinY()); 302 317 303 318 if (changedItems != null … … 320 335 321 336 // The bottom of the previous item 322 int bottom = (int)top.getBounds().getMaxY();337 int bottom = top.getBounds().getMaxY(); 323 338 324 339 // the difference between the current item's Y coordinate and 325 340 // the top of the highlight box 326 int diff = (int) (current.getY() - current.getBounds().getMinY());341 int diff = current.getY() - current.getBounds().getMinY(); 327 342 328 343 int newPos = bottom + space + diff; … … 360 375 // active overlay frames may also require saving if they have been 361 376 // changed 362 for (Overlay o : current.getOverlays()) 363 if (!SaveCheck(o.Frame)) 377 for (Overlay o : current.getOverlays()) { 378 if (!SaveCheck(o.Frame)) { 364 379 return false; 380 } 381 } 365 382 366 383 // if the check fails there is no point continuing 367 if (!SaveCheck(current)) 384 if (!SaveCheck(current)) { 368 385 return false; 386 } 369 387 370 388 for (Item i : current.getItems()) { … … 377 395 private static boolean SaveCheck(Frame toSave) { 378 396 // don't bother saving frames that haven't changed 379 if (!toSave.hasChanged()) 397 if (!toSave.hasChanged()) { 380 398 return true; 399 } 381 400 382 401 // if the frame has been changed, then save it … … 385 404 386 405 String side = "left"; 387 if (DisplayController.getCurrentSide() == DisplayController.TwinFramesSide.RIGHT) 406 if (DisplayController.getCurrentSide() == DisplayController.TwinFramesSide.RIGHT) { 388 407 side = "right"; 408 } 389 409 390 410 // if the two frames both have changes, prompt the user for the … … 395 415 DisplayController.Reload(DisplayController.getSideFrameIsOn(opposite)); 396 416 return true; 397 } else 417 } else { 398 418 return false; 419 } 399 420 } else if (opposite.hasOverlay(toSave)) { 400 if (toSave.hasChanged()) 421 if (toSave.hasChanged()) { 401 422 if (EcosystemManager.getGraphicsManager().showDialog("Changes", "Leaving this frame will discard changes made in the " + side + " Frame. Continue?")) { 402 423 FrameIO.SaveFrame(toSave); 403 424 DisplayController.Reload(DisplayController.getSideFrameIsOn(opposite)); 404 425 return true; 405 } else 426 } else { 406 427 return false; 428 } 429 } 407 430 } 408 431 … … 467 490 public static void DisplayFrame(Frame toDisplay, boolean addToBack, boolean incrementStats) 468 491 { 469 if (toDisplay == null) 492 if (toDisplay == null) { 470 493 return; 494 } 471 495 472 496 Frame current = DisplayController.getCurrentFrame(); … … 474 498 // Dont need to do anything if the frame to display is already being 475 499 // displayed 476 if (current.equals(toDisplay)) 500 if (current.equals(toDisplay)) { 477 501 return; 502 } 478 503 479 504 // move any anchored connected items … … 568 593 Frame newFrame = getFrame(frameName); 569 594 570 if (newFrame != null) 595 if (newFrame != null) { 571 596 // display the frame 572 597 DisplayFrame(newFrame, addToBack, incrementStats); 598 } 573 599 } 574 600 … … 641 667 private static boolean createWidget(Frame frame, Text txt) { 642 668 643 if (frame == null) 669 if (frame == null) { 644 670 throw new NullPointerException("frame"); 645 if (txt == null) 671 } 672 if (txt == null) { 646 673 throw new NullPointerException("txt"); 674 } 647 675 648 676 // Safety 649 if (txt.getParent() == null) 677 if (txt.getParent() == null) { 650 678 txt.setParent(frame); 679 } 651 680 652 681 Widget iw = null; … … 667 696 } 668 697 669 if (iw == null) 698 if (iw == null) { 670 699 return false; 700 } 671 701 672 702 frame.removeItem(txt); … … 681 711 List<String> errors = new LinkedList<String>(); 682 712 683 if (profile == null) return errors; 713 if (profile == null) { 714 return errors; 715 } 684 716 685 717 /* … … 698 730 String attributeFullCase = avp.getAttributeOrValue(); 699 731 700 if (attributeFullCase == null) continue; 732 if (attributeFullCase == null) { 733 continue; 734 } 701 735 702 736 String attribute = attributeFullCase.trim().toLowerCase().replaceAll("^@", ""); 703 737 704 if (attribute.equals("settings")) Settings.parseSettings(item); 738 if (attribute.equals("settings")) { 739 Settings.parseSettings(item); 740 } 705 741 706 742 } catch (Exception e) { … … 724 760 public static void loadFirstFrame(Frame profile) 725 761 { 726 if (UserSettings.HomeFrame.get() == null) UserSettings.HomeFrame.set(profile.getName()); 762 if (UserSettings.HomeFrame.get() == null) { 763 UserSettings.HomeFrame.set(profile.getName()); 764 } 727 765 728 766 Frame firstFrame = FrameIO.LoadFrame(UserSettings.HomeFrame.get()); … … 755 793 public static String getLink(Item item, String alt) 756 794 { 757 if (item == null || !(item instanceof Text)) return alt; 795 if (item == null || !(item instanceof Text)) { 796 return alt; 797 } 758 798 759 799 AttributeValuePair avp = new AttributeValuePair(item.getText()); … … 798 838 File tester = new File(dirName); 799 839 if (tester.exists() && tester.isDirectory()) { 800 if (dirName.endsWith(File.separator)) 840 if (dirName.endsWith(File.separator)) { 801 841 dirsToAdd.add(dirName); 802 else842 } else { 803 843 dirsToAdd.add(dirName + File.separator); 844 } 804 845 } 805 846 } … … 838 879 // TODO check why we are getting toParse == null... when profile frame 839 880 // 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 } 843 888 844 889 List<Item> items = toParse.getItems(); … … 882 927 883 928 // disable reading of cached overlays if in twinframes mode 884 if (DisplayController.isTwinFramesOn()) FrameIO.SuspendCache(); 929 if (DisplayController.isTwinFramesOn()) { 930 FrameIO.SuspendCache(); 931 } 885 932 886 933 DotType pointtype = DotType.square; … … 913 960 String fill = line.substring(line 914 961 .indexOf(" ") + 1); 915 if (fill.startsWith("nofill")) 962 if (fill.startsWith("nofill")) { 916 963 filledPoints = false; 917 else964 } else { 918 965 filledPoints = true; 966 } 919 967 } 920 968 921 if (line.startsWith("circle")) 969 if (line.startsWith("circle")) { 922 970 pointtype = DotType.circle; 923 else971 } else { 924 972 pointtype = DotType.square; 973 } 925 974 } 926 975 }// check for new VECTOR items … … 929 978 ItemUtils.TAG_VECTOR) 930 979 && i.getLink() != null) { 931 if (!i.getAbsoluteLink().equals(toParse.getName())) 980 if (!i.getAbsoluteLink().equals(toParse.getName())) { 932 981 addVector(vectors, UserAppliedPermission.none, 933 982 permission, i); 983 } 934 984 } else if (!DisplayController.isXRayMode() 935 985 && ItemUtils.startsWithTag(i, 936 986 ItemUtils.TAG_ACTIVE_VECTOR) 937 987 && i.getLink() != null) { 938 if (!i.getAbsoluteLink().equals(toParse.getName())) 988 if (!i.getAbsoluteLink().equals(toParse.getName())) { 939 989 addVector(vectors, 940 990 UserAppliedPermission.followLinks, 941 991 permission, i); 992 } 942 993 } 943 994 // check for new OVERLAY items … … 976 1027 for (Overlay o : current.getOverlays()) { 977 1028 if (o.Frame.getName() 978 .equalsIgnoreCase(link)) 1029 .equalsIgnoreCase(link)) { 979 1030 overlayFrame = o.Frame; 1031 } 980 1032 } 981 1033 } 982 if (overlayFrame == null) 1034 if (overlayFrame == null) { 983 1035 overlayFrame = FrameIO.LoadFrame(link); 1036 } 984 1037 985 1038 // get level if specified … … 1156 1209 int x = Math.round(floatX); 1157 1210 int y = Math.round(floatY); 1158 if (toCheck == null) 1211 if (toCheck == null) { 1159 1212 return null; 1213 } 1160 1214 1161 1215 List<Item> possibles = new ArrayList<Item>(0); … … 1241 1295 1242 1296 // if there are no possible items, return null 1243 if (possibles.size() == 0) 1297 if (possibles.size() == 0) { 1244 1298 return null; 1299 } 1245 1300 1246 1301 // if there is only one possibility, return it 1247 if (possibles.size() == 1) 1302 if (possibles.size() == 1) { 1248 1303 return possibles.get(0); 1304 } 1249 1305 1250 1306 // return closest x,y pair to mouse … … 1264 1320 // dots take precedence over lines 1265 1321 if ((!(closest instanceof Dot && i instanceof Line)) 1266 && (!(closest instanceof Text && i instanceof Line))) 1322 && (!(closest instanceof Text && i instanceof Line))) { 1267 1323 closest = i; 1324 } 1268 1325 1269 1326 } … … 1294 1351 Collection<Item> enclosure = getEnclosingLineEnds(); 1295 1352 1296 if (enclosure == null || enclosure.size() == 0) return null; 1353 if (enclosure == null || enclosure.size() == 0) { 1354 return null; 1355 } 1297 1356 1298 1357 return enclosure.iterator().next().getEnclosedShape(); … … 1313 1372 Collection<Item> enclosure = getEnclosingLineEnds(); 1314 1373 1315 if (enclosure == null || enclosure.size() == 0) return null; 1374 if (enclosure == null || enclosure.size() == 0) { 1375 return null; 1376 } 1316 1377 1317 1378 Item firstItem = enclosure.iterator().next(); … … 1378 1439 // update enclosed shapes 1379 1440 Frame current = DisplayController.getCurrentFrame(); 1380 if (current == null) return null; 1441 if (current == null) { 1442 return null; 1443 } 1381 1444 List<Item> items = current.getItems(); 1382 1445 … … 1404 1467 } 1405 1468 1406 if (used.size() == 0) return null; 1469 if (used.size() == 0) { 1470 return null; 1471 } 1407 1472 1408 1473 // if there is only one possibility, return it … … 1412 1477 } else { 1413 1478 Collections.sort(used, new Comparator<Item>() { 1479 @Override 1414 1480 public int compare(Item d1, Item d2) { 1415 1481 PolygonBounds p1 = d1.getEnclosedShape(); … … 1426 1492 int diff2 = Integer.MAX_VALUE; 1427 1493 1428 if (i < p2.getPointCount()) 1494 if (i < p2.getPointCount()) { 1429 1495 diff2 = Math.abs(p2.getPoint(i).getX() - mouseX) + Math.abs(p2.getPoint(i).getY() - mouseY); 1496 } 1430 1497 1431 1498 if (diff < Math.abs(closest)) { 1432 1499 close2 = closest; 1433 1500 closest = diff; 1434 } else if (diff < Math.abs(close2)) 1501 } else if (diff < Math.abs(close2)) { 1435 1502 close2 = diff; 1503 } 1436 1504 1437 1505 if (diff2 < Math.abs(closest)) { 1438 1506 close2 = closest; 1439 1507 closest = -diff2; 1440 } else if (diff2 < Math.abs(close2)) 1508 } else if (diff2 < Math.abs(close2)) { 1441 1509 close2 = diff2; 1442 } 1443 1444 if (closest > 0 && close2 > 0) 1510 } 1511 } 1512 1513 if (closest > 0 && close2 > 0) { 1445 1514 return -10; 1446 1447 if (closest < 0 && close2 < 0) 1515 } 1516 1517 if (closest < 0 && close2 < 0) { 1448 1518 return 10; 1449 1450 if (closest > 0) 1519 } 1520 1521 if (closest > 0) { 1451 1522 return -10; 1523 } 1452 1524 1453 1525 return 10; … … 1821 1893 File check = new File(FrameIO.PARENT_FOLDER + ".res"); 1822 1894 1823 if(!force && check.exists()) return; 1895 if(!force && check.exists()) { 1896 return; 1897 } 1824 1898 1825 1899 System.out.println("Extracting/Installing resources:"); … … 1935 2009 public static void copyFile(File src, File dst, boolean overWrite) throws IOException 1936 2010 { 1937 if(!overWrite && dst.exists()) return; 2011 if(!overWrite && dst.exists()) { 2012 return; 2013 } 1938 2014 1939 2015 dst.getParentFile().mkdirs();
Note:
See TracChangeset
for help on using the changeset viewer.