1 7 package java.awt; 8 9 import java.util.Hashtable ; 10 import java.util.Vector ; 11 12 class GridBagLayoutInfo implements java.io.Serializable { 13 int width, height; 14 int startx, starty; 15 int minWidth[]; 16 int minHeight[]; 17 double weightX[]; 18 double weightY[]; 19 20 GridBagLayoutInfo () { 21 22 minWidth = new int[GridBagLayout.MAXGRIDSIZE]; 23 minHeight = new int[GridBagLayout.MAXGRIDSIZE]; 24 weightX = new double[GridBagLayout.MAXGRIDSIZE]; 25 weightY = new double[GridBagLayout.MAXGRIDSIZE]; 26 } 27 } 28 29 278 public class GridBagLayout implements LayoutManager2 , 279 java.io.Serializable { 280 281 282 protected static final int MAXGRIDSIZE = 512; 283 284 287 protected static final int MINSIZE = 1; 288 291 protected static final int PREFERREDSIZE = 2; 292 293 302 protected Hashtable <Component ,GridBagConstraints > comptable; 303 304 316 protected GridBagConstraints defaultConstraints; 317 318 331 protected GridBagLayoutInfo layoutInfo; 332 333 345 public int columnWidths[]; 346 347 359 public int rowHeights[]; 360 361 374 public double columnWeights[]; 375 376 389 public double rowWeights[]; 390 391 394 public GridBagLayout () { 395 comptable = new Hashtable <Component ,GridBagConstraints >(); 396 defaultConstraints = new GridBagConstraints (); 397 } 398 399 404 public void setConstraints(Component comp, GridBagConstraints constraints) { 405 comptable.put(comp, (GridBagConstraints )constraints.clone()); 406 } 407 408 416 public GridBagConstraints getConstraints(Component comp) { 417 GridBagConstraints constraints = comptable.get(comp); 418 if (constraints == null) { 419 setConstraints(comp, defaultConstraints); 420 constraints = comptable.get(comp); 421 } 422 return (GridBagConstraints )constraints.clone(); 423 } 424 425 438 protected GridBagConstraints lookupConstraints(Component comp) { 439 GridBagConstraints constraints = comptable.get(comp); 440 if (constraints == null) { 441 setConstraints(comp, defaultConstraints); 442 constraints = comptable.get(comp); 443 } 444 return constraints; 445 } 446 447 451 private void removeConstraints(Component comp) { 452 comptable.remove(comp); 453 } 454 455 467 public Point getLayoutOrigin () { 468 Point origin = new Point (0,0); 469 if (layoutInfo != null) { 470 origin.x = layoutInfo.startx; 471 origin.y = layoutInfo.starty; 472 } 473 return origin; 474 } 475 476 485 public int [][] getLayoutDimensions () { 486 if (layoutInfo == null) 487 return new int[2][0]; 488 489 int dim[][] = new int [2][]; 490 dim[0] = new int[layoutInfo.width]; 491 dim[1] = new int[layoutInfo.height]; 492 493 System.arraycopy(layoutInfo.minWidth, 0, dim[0], 0, layoutInfo.width); 494 System.arraycopy(layoutInfo.minHeight, 0, dim[1], 0, layoutInfo.height); 495 496 return dim; 497 } 498 499 511 public double [][] getLayoutWeights () { 512 if (layoutInfo == null) 513 return new double[2][0]; 514 515 double weights[][] = new double [2][]; 516 weights[0] = new double[layoutInfo.width]; 517 weights[1] = new double[layoutInfo.height]; 518 519 System.arraycopy(layoutInfo.weightX, 0, weights[0], 0, layoutInfo.width); 520 System.arraycopy(layoutInfo.weightY, 0, weights[1], 0, layoutInfo.height); 521 522 return weights; 523 } 524 525 552 public Point location(int x, int y) { 553 Point loc = new Point (0,0); 554 int i, d; 555 556 if (layoutInfo == null) 557 return loc; 558 559 d = layoutInfo.startx; 560 if (!rightToLeft) { 561 for (i=0; i<layoutInfo.width; i++) { 562 d += layoutInfo.minWidth[i]; 563 if (d > x) 564 break; 565 } 566 } else { 567 for (i=layoutInfo.width-1; i>=0; i--) { 568 if (d > x) 569 break; 570 d += layoutInfo.minWidth[i]; 571 } 572 i++; 573 } 574 loc.x = i; 575 576 d = layoutInfo.starty; 577 for (i=0; i<layoutInfo.height; i++) { 578 d += layoutInfo.minHeight[i]; 579 if (d > y) 580 break; 581 } 582 loc.y = i; 583 584 return loc; 585 } 586 587 590 public void addLayoutComponent(String name, Component comp) { 591 } 592 593 604 public void addLayoutComponent(Component comp, Object constraints) { 605 if (constraints instanceof GridBagConstraints ) { 606 setConstraints(comp, (GridBagConstraints )constraints); 607 } else if (constraints != null) { 608 throw new IllegalArgumentException ("cannot add to layout: constraints must be a GridBagConstraint"); 609 } 610 } 611 612 620 public void removeLayoutComponent(Component comp) { 621 removeConstraints(comp); 622 } 623 624 635 public Dimension preferredLayoutSize(Container parent) { 636 GridBagLayoutInfo info = getLayoutInfo(parent, PREFERREDSIZE); 637 return getMinSize(parent, info); 638 } 639 640 649 public Dimension minimumLayoutSize(Container parent) { 650 GridBagLayoutInfo info = getLayoutInfo(parent, MINSIZE); 651 return getMinSize(parent, info); 652 } 653 654 663 public Dimension maximumLayoutSize(Container target) { 664 return new Dimension (Integer.MAX_VALUE, Integer.MAX_VALUE); 665 } 666 667 676 public float getLayoutAlignmentX(Container parent) { 677 return 0.5f; 678 } 679 680 689 public float getLayoutAlignmentY(Container parent) { 690 return 0.5f; 691 } 692 693 697 public void invalidateLayout(Container target) { 698 } 699 700 711 public void layoutContainer(Container parent) { 712 arrangeGrid(parent); 713 } 714 715 719 public String toString() { 720 return getClass().getName(); 721 } 722 723 726 727 746 747 750 751 791 792 815 protected GridBagLayoutInfo getLayoutInfo(Container parent, int sizeflag) { 816 return GetLayoutInfo(parent, sizeflag); 817 } 818 819 827 protected GridBagLayoutInfo GetLayoutInfo(Container parent, int sizeflag) { 828 synchronized (parent.getTreeLock()) { 829 GridBagLayoutInfo r = new GridBagLayoutInfo (); 830 Component comp; 831 GridBagConstraints constraints; 832 Dimension d; 833 Component components[] = parent.getComponents(); 834 835 int compindex, i, j, k, px, py, pixels_diff, nextSize; 836 int curX, curY, curWidth, curHeight, curRow, curCol; 837 double weight_diff, weight, start, size; 838 int xMax[], yMax[]; 839 840 846 847 r.width = r.height = 0; 848 curRow = curCol = -1; 849 xMax = new int[MAXGRIDSIZE]; 850 yMax = new int[MAXGRIDSIZE]; 851 852 for (compindex = 0 ; compindex < components.length ; compindex++) { 853 comp = components[compindex]; 854 if (!comp.isVisible()) 855 continue; 856 constraints = lookupConstraints(comp); 857 858 curX = constraints.gridx; 859 curY = constraints.gridy; 860 curWidth = constraints.gridwidth; 861 if (curWidth <= 0) 862 curWidth = 1; 863 curHeight = constraints.gridheight; 864 if (curHeight <= 0) 865 curHeight = 1; 866 867 868 if (curX < 0 && curY < 0) { 869 if (curRow >= 0) 870 curY = curRow; 871 else if (curCol >= 0) 872 curX = curCol; 873 else 874 curY = 0; 875 } 876 if (curX < 0) { 877 px = 0; 878 for (i = curY; i < (curY + curHeight); i++) { 879 px = Math.max(px, xMax[i]); 880 } 881 882 curX = px - curX - 1; 883 if(curX < 0) 884 curX = 0; 885 } 886 else if (curY < 0) { 887 py = 0; 888 for (i = curX; i < (curX + curWidth); i++) { 889 py = Math.max(py, yMax[i]); 890 } 891 892 curY = py - curY - 1; 893 if(curY < 0) 894 curY = 0; 895 } 896 897 898 for (px = curX + curWidth; r.width < px; r.width++); 899 for (py = curY + curHeight; r.height < py; r.height++); 900 901 902 for (i = curX; i < (curX + curWidth); i++) { 903 yMax[i] = py; 904 } 905 for (i = curY; i < (curY + curHeight); i++) { 906 xMax[i] = px; 907 } 908 909 910 if (sizeflag == PREFERREDSIZE) 911 d = comp.getPreferredSize(); 912 else 913 d = comp.getMinimumSize(); 914 constraints.minWidth = d.width; 915 constraints.minHeight = d.height; 916 917 919 if (constraints.gridheight == 0 && constraints.gridwidth == 0) 920 curRow = curCol = -1; 921 922 923 if (constraints.gridheight == 0 && curRow < 0) 924 curCol = curX + curWidth; 925 926 927 else if (constraints.gridwidth == 0 && curCol < 0) 928 curRow = curY + curHeight; 929 } 930 931 934 if (columnWidths != null && r.width < columnWidths.length) 935 r.width = columnWidths.length; 936 if (rowHeights != null && r.height < rowHeights.length) 937 r.height = rowHeights.length; 938 939 940 948 949 curRow = curCol = -1; 950 xMax = new int[MAXGRIDSIZE]; 951 yMax = new int[MAXGRIDSIZE]; 952 953 for (compindex = 0 ; compindex < components.length ; compindex++) { 954 comp = components[compindex]; 955 if (!comp.isVisible()) 956 continue; 957 constraints = lookupConstraints(comp); 958 959 curX = constraints.gridx; 960 curY = constraints.gridy; 961 curWidth = constraints.gridwidth; 962 curHeight = constraints.gridheight; 963 964 965 if (curX < 0 && curY < 0) { 966 if(curRow >= 0) 967 curY = curRow; 968 else if(curCol >= 0) 969 curX = curCol; 970 else 971 curY = 0; 972 } 973 974 if (curX < 0) { 975 if (curHeight <= 0) { 976 curHeight += r.height - curY; 977 if (curHeight < 1) 978 curHeight = 1; 979 } 980 981 px = 0; 982 for (i = curY; i < (curY + curHeight); i++) 983 px = Math.max(px, xMax[i]); 984 985 curX = px - curX - 1; 986 if(curX < 0) 987 curX = 0; 988 } 989 else if (curY < 0) { 990 if (curWidth <= 0) { 991 curWidth += r.width - curX; 992 if (curWidth < 1) 993 curWidth = 1; 994 } 995 996 py = 0; 997 for (i = curX; i < (curX + curWidth); i++) 998 py = Math.max(py, yMax[i]); 999 1000 curY = py - curY - 1; 1001 if(curY < 0) 1002 curY = 0; 1003 } 1004 1005 if (curWidth <= 0) { 1006 curWidth += r.width - curX; 1007 if (curWidth < 1) 1008 curWidth = 1; 1009 } 1010 1011 if (curHeight <= 0) { 1012 curHeight += r.height - curY; 1013 if (curHeight < 1) 1014 curHeight = 1; 1015 } 1016 1017 px = curX + curWidth; 1018 py = curY + curHeight; 1019 1020 for (i = curX; i < (curX + curWidth); i++) { yMax[i] = py; } 1021 for (i = curY; i < (curY + curHeight); i++) { xMax[i] = px; } 1022 1023 1024 if (constraints.gridheight == 0 && constraints.gridwidth == 0) 1025 curRow = curCol = -1; 1026 if (constraints.gridheight == 0 && curRow < 0) 1027 curCol = curX + curWidth; 1028 else if (constraints.gridwidth == 0 && curCol < 0) 1029 curRow = curY + curHeight; 1030 1031 1032 constraints.tempX = curX; 1033 constraints.tempY = curY; 1034 constraints.tempWidth = curWidth; 1035 constraints.tempHeight = curHeight; 1036 } 1037 1038 1041 if (columnWidths != null) 1042 System.arraycopy(columnWidths, 0, r.minWidth, 0, columnWidths.length); 1043 if (rowHeights != null) 1044 System.arraycopy(rowHeights, 0, r.minHeight, 0, rowHeights.length); 1045 if (columnWeights != null) 1046 System.arraycopy(columnWeights, 0, r.weightX, 0, Math.min(r.weightX.length, columnWeights.length)); 1047 if (rowWeights != null) 1048 System.arraycopy(rowWeights, 0, r.weightY, 0, Math.min(r.weightY.length, rowWeights.length)); 1049 1050 1055 1056 nextSize = Integer.MAX_VALUE; 1057 1058 for (i = 1; 1059 i != Integer.MAX_VALUE; 1060 i = nextSize, nextSize = Integer.MAX_VALUE) { 1061 for (compindex = 0 ; compindex < components.length ; compindex++) { 1062 comp = components[compindex]; 1063 if (!comp.isVisible()) 1064 continue; 1065 constraints = lookupConstraints(comp); 1066 1067 if (constraints.tempWidth == i) { 1068 px = constraints.tempX + constraints.tempWidth; 1069 1070 1076 1077 weight_diff = constraints.weightx; 1078 for (k = constraints.tempX; k < px; k++) 1079 weight_diff -= r.weightX[k]; 1080 if (weight_diff > 0.0) { 1081 weight = 0.0; 1082 for (k = constraints.tempX; k < px; k++) 1083 weight += r.weightX[k]; 1084 for (k = constraints.tempX; weight > 0.0 && k < px; k++) { 1085 double wt = r.weightX[k]; 1086 double dx = (wt * weight_diff) / weight; 1087 r.weightX[k] += dx; 1088 weight_diff -= dx; 1089 weight -= wt; 1090 } 1091 1092 r.weightX[px-1] += weight_diff; 1093 } 1094 1095 1102 1103 pixels_diff = 1104 constraints.minWidth + constraints.ipadx + 1105 constraints.insets.left + constraints.insets.right; 1106 1107 for (k = constraints.tempX; k < px; k++) 1108 pixels_diff -= r.minWidth[k]; 1109 if (pixels_diff > 0) { 1110 weight = 0.0; 1111 for (k = constraints.tempX; k < px; k++) 1112 weight += r.weightX[k]; 1113 for (k = constraints.tempX; weight > 0.0 && k < px; k++) { 1114 double wt = r.weightX[k]; 1115 int dx = (int)((wt * ((double)pixels_diff)) / weight); 1116 r.minWidth[k] += dx; 1117 pixels_diff -= dx; 1118 weight -= wt; 1119 } 1120 1121 r.minWidth[px-1] += pixels_diff; 1122 } 1123 } 1124 else if (constraints.tempWidth > i && constraints.tempWidth < nextSize) 1125 nextSize = constraints.tempWidth; 1126 1127 1128 if (constraints.tempHeight == i) { 1129 py = constraints.tempY + constraints.tempHeight; 1130 1131 1137 1138 weight_diff = constraints.weighty; 1139 for (k = constraints.tempY; k < py; k++) 1140 weight_diff -= r.weightY[k]; 1141 if (weight_diff > 0.0) { 1142 weight = 0.0; 1143 for (k = constraints.tempY; k < py; k++) 1144 weight += r.weightY[k]; 1145 for (k = constraints.tempY; weight > 0.0 && k < py; k++) { 1146 double wt = r.weightY[k]; 1147 double dy = (wt * weight_diff) / weight; 1148 r.weightY[k] += dy; 1149 weight_diff -= dy; 1150 weight -= wt; 1151 } 1152 1153 r.weightY[py-1] += weight_diff; 1154 } 1155 1156 1163 1164 pixels_diff = 1165 constraints.minHeight + constraints.ipady + 1166 constraints.insets.top + constraints.insets.bottom; 1167 for (k = constraints.tempY; k < py; k++) 1168 pixels_diff -= r.minHeight[k]; 1169 if (pixels_diff > 0) { 1170 weight = 0.0; 1171 for (k = constraints.tempY; k < py; k++) 1172 weight += r.weightY[k]; 1173 for (k = constraints.tempY; weight > 0.0 && k < py; k++) { 1174 double wt = r.weightY[k]; 1175 int dy = (int)((wt * ((double)pixels_diff)) / weight); 1176 r.minHeight[k] += dy; 1177 pixels_diff -= dy; 1178 weight -= wt; 1179 } 1180 1181 r.minHeight[py-1] += pixels_diff; 1182 } 1183 } 1184 else if (constraints.tempHeight > i && 1185 constraints.tempHeight < nextSize) 1186 nextSize = constraints.tempHeight; 1187 } 1188 } 1189 1190 return r; 1191 } 1192 } 1193 1194 1204 protected void adjustForGravity(GridBagConstraints constraints, 1205 Rectangle r) { 1206 AdjustForGravity(constraints, r); 1207 } 1208 1209 1218 protected void AdjustForGravity(GridBagConstraints constraints, 1219 Rectangle r) { 1220 int diffx, diffy; 1221 1222 if (!rightToLeft) { 1223 r.x += constraints.insets.left; 1224 } else { 1225 r.x -= r.width - constraints.insets.right; 1226 } 1227 r.width -= (constraints.insets.left + constraints.insets.right); 1228 r.y += constraints.insets.top; 1229 r.height -= (constraints.insets.top + constraints.insets.bottom); 1230 1231 diffx = 0; 1232 if ((constraints.fill != GridBagConstraints.HORIZONTAL && 1233 constraints.fill != GridBagConstraints.BOTH) 1234 && (r.width > (constraints.minWidth + constraints.ipadx))) { 1235 diffx = r.width - (constraints.minWidth + constraints.ipadx); 1236 r.width = constraints.minWidth + constraints.ipadx; 1237 } 1238 1239 diffy = 0; 1240 if ((constraints.fill != GridBagConstraints.VERTICAL && 1241 constraints.fill != GridBagConstraints.BOTH) 1242 && (r.height > (constraints.minHeight + constraints.ipady))) { 1243 diffy = r.height - (constraints.minHeight + constraints.ipady); 1244 r.height = constraints.minHeight + constraints.ipady; 1245 } 1246 1247 switch (constraints.anchor) { 1248 case GridBagConstraints.CENTER: 1249 r.x += diffx/2; 1250 r.y += diffy/2; 1251 break; 1252 case GridBagConstraints.PAGE_START: 1253 case GridBagConstraints.NORTH: 1254 r.x += diffx/2; 1255 break; 1256 case GridBagConstraints.NORTHEAST: 1257 r.x += diffx; 1258 break; 1259 case GridBagConstraints.EAST: 1260 r.x += diffx; 1261 r.y += diffy/2; 1262 break; 1263 case GridBagConstraints.SOUTHEAST: 1264 r.x += diffx; 1265 r.y += diffy; 1266 break; 1267 case GridBagConstraints.PAGE_END: 1268 case GridBagConstraints.SOUTH: 1269 r.x += diffx/2; 1270 r.y += diffy; 1271 break; 1272 case GridBagConstraints.SOUTHWEST: 1273 r.y += diffy; 1274 break; 1275 case GridBagConstraints.WEST: 1276 r.y += diffy/2; 1277 break; 1278 case GridBagConstraints.NORTHWEST: 1279 break; 1280 case GridBagConstraints.LINE_START: 1281 if (rightToLeft) { 1282 r.x += diffx; 1283 } 1284 r.y += diffy/2; 1285 break; 1286 case GridBagConstraints.LINE_END: 1287 if (!rightToLeft) { 1288 r.x += diffx; 1289 } 1290 r.y += diffy/2; 1291 break; 1292 case GridBagConstraints.FIRST_LINE_START: 1293 if (rightToLeft) { 1294 r.x += diffx; 1295 } 1296 break; 1297 case GridBagConstraints.FIRST_LINE_END: 1298 if (!rightToLeft) { 1299 r.x += diffx; 1300 } 1301 break; 1302 case GridBagConstraints.LAST_LINE_START: 1303 if (rightToLeft) { 1304 r.x += diffx; 1305 } 1306 r.y += diffy; 1307 break; 1308 case GridBagConstraints.LAST_LINE_END: 1309 if (!rightToLeft) { 1310 r.x += diffx; 1311 } 1312 r.y += diffy; 1313 break; 1314 default: 1315 throw new IllegalArgumentException ("illegal anchor value"); 1316 } 1317 } 1318 1319 1331 protected Dimension getMinSize(Container parent, GridBagLayoutInfo info) { 1332 return GetMinSize(parent, info); 1333 } 1334 1335 1343 protected Dimension GetMinSize(Container parent, GridBagLayoutInfo info) { 1344 Dimension d = new Dimension (); 1345 int i, t; 1346 Insets insets = parent.getInsets(); 1347 1348 t = 0; 1349 for(i = 0; i < info.width; i++) 1350 t += info.minWidth[i]; 1351 d.width = t + insets.left + insets.right; 1352 1353 t = 0; 1354 for(i = 0; i < info.height; i++) 1355 t += info.minHeight[i]; 1356 d.height = t + insets.top + insets.bottom; 1357 1358 return d; 1359 } 1360 1361 transient boolean rightToLeft = false; 1362 1363 1371 protected void arrangeGrid(Container parent) { 1372 ArrangeGrid(parent); 1373 } 1374 1375 1383 protected void ArrangeGrid(Container parent) { 1384 Component comp; 1385 int compindex; 1386 GridBagConstraints constraints; 1387 Insets insets = parent.getInsets(); 1388 Component components[] = parent.getComponents(); 1389 Dimension d; 1390 Rectangle r = new Rectangle (); 1391 int i, diffw, diffh; 1392 double weight; 1393 GridBagLayoutInfo info; 1394 1395 rightToLeft = !parent.getComponentOrientation().isLeftToRight(); 1396 1397 1401 if (components.length == 0 && 1402 (columnWidths == null || columnWidths.length == 0) && 1403 (rowHeights == null || rowHeights.length == 0)) { 1404 return; 1405 } 1406 1407 1411 1412 info = getLayoutInfo(parent, PREFERREDSIZE); 1413 d = getMinSize(parent, info); 1414 1415 if (parent.width < d.width || parent.height < d.height) { 1416 info = getLayoutInfo(parent, MINSIZE); 1417 d = getMinSize(parent, info); 1418 } 1419 1420 layoutInfo = info; 1421 r.width = d.width; 1422 r.height = d.height; 1423 1424 1437 1438 1443 1444 diffw = parent.width - r.width; 1445 if (diffw != 0) { 1446 weight = 0.0; 1447 for (i = 0; i < info.width; i++) 1448 weight += info.weightX[i]; 1449 if (weight > 0.0) { 1450 for (i = 0; i < info.width; i++) { 1451 int dx = (int)(( ((double)diffw) * info.weightX[i]) / weight); 1452 info.minWidth[i] += dx; 1453 r.width += dx; 1454 if (info.minWidth[i] < 0) { 1455 r.width -= info.minWidth[i]; 1456 info.minWidth[i] = 0; 1457 } 1458 } 1459 } 1460 diffw = parent.width - r.width; 1461 } 1462 1463 else { 1464 diffw = 0; 1465 } 1466 1467 diffh = parent.height - r.height; 1468 if (diffh != 0) { 1469 weight = 0.0; 1470 for (i = 0; i < info.height; i++) 1471 weight += info.weightY[i]; 1472 if (weight > 0.0) { 1473 for (i = 0; i < info.height; i++) { 1474 int dy = (int)(( ((double)diffh) * info.weightY[i]) / weight); 1475 info.minHeight[i] += dy; 1476 r.height += dy; 1477 if (info.minHeight[i] < 0) { 1478 r.height -= info.minHeight[i]; 1479 info.minHeight[i] = 0; 1480 } 1481 } 1482 } 1483 diffh = parent.height - r.height; 1484 } 1485 1486 else { 1487 diffh = 0; 1488 } 1489 1490 1496 1497 1501 1502 info.startx = diffw/2 + insets.left; 1503 info.starty = diffh/2 + insets.top; 1504 1505 for (compindex = 0 ; compindex < components.length ; compindex++) { 1506 comp = components[compindex]; 1507 if (!comp.isVisible()) 1508 continue; 1509 constraints = lookupConstraints(comp); 1510 1511 if (!rightToLeft) { 1512 r.x = info.startx; 1513 for(i = 0; i < constraints.tempX; i++) 1514 r.x += info.minWidth[i]; 1515 } else { 1516 r.x = parent.width - (diffw/2 + insets.right); 1517 for(i = 0; i < constraints.tempX; i++) 1518 r.x -= info.minWidth[i]; 1519 } 1520 1521 r.y = info.starty; 1522 for(i = 0; i < constraints.tempY; i++) 1523 r.y += info.minHeight[i]; 1524 1525 r.width = 0; 1526 for(i = constraints.tempX; 1527 i < (constraints.tempX + constraints.tempWidth); 1528 i++) { 1529 r.width += info.minWidth[i]; 1530 } 1531 1532 r.height = 0; 1533 for(i = constraints.tempY; 1534 i < (constraints.tempY + constraints.tempHeight); 1535 i++) { 1536 r.height += info.minHeight[i]; 1537 } 1538 1539 adjustForGravity(constraints, r); 1540 1541 1542 1543 if (r.x < 0) { 1544 r.width += r.x; 1545 r.x = 0; 1546 } 1547 1548 if (r.y < 0) { 1549 r.height += r.y; 1550 r.y = 0; 1551 } 1552 1553 1558 1559 if ((r.width <= 0) || (r.height <= 0)) { 1560 comp.setBounds(0, 0, 0, 0); 1561 } 1562 else { 1563 if (comp.x != r.x || comp.y != r.y || 1564 comp.width != r.width || comp.height != r.height) { 1565 comp.setBounds(r.x, r.y, r.width, r.height); 1566 } 1567 } 1568 } 1569 } 1570 1571 static final long serialVersionUID = 8838754796412211005L; 1573} 1574 | Popular Tags |