/** * This method is obsolete and supplied for backwards compatability only; new code should call * {@link #getLayoutInfo(Container, int) getLayoutInfo} instead. */ protected GridBagLayoutInfo GetLayoutInfo(Container parent, int sizeflag) { synchronized (parent.getTreeLock()) { GridBagLayoutInfo r = new GridBagLayoutInfo(); Component comp; GridBagConstraints constraints; Dimension d; Component components[] = parent.getComponents(); int compindex, i, j, k, px, py, pixels_diff, nextSize; int curX, curY, curWidth, curHeight, curRow, curCol; double weight_diff, weight, start, size; int xMax[], yMax[]; /* * Pass #1 * * Figure out the dimensions of the layout grid (use a value of 1 for * zero or negative widths and heights). */ r.width = r.height = 0; curRow = curCol = -1; xMax = new int[MAXGRIDSIZE]; yMax = new int[MAXGRIDSIZE]; for (compindex = 0; compindex < components.length; compindex++) { comp = components[compindex]; if (!comp.isVisible()) continue; constraints = lookupConstraints(comp); curX = constraints.gridx; curY = constraints.gridy; curWidth = constraints.gridwidth; if (curWidth <= 0) curWidth = 1; curHeight = constraints.gridheight; if (curHeight <= 0) curHeight = 1; /* If x or y is negative, then use relative positioning: */ if (curX < 0 && curY < 0) { if (curRow >= 0) curY = curRow; else if (curCol >= 0) curX = curCol; else curY = 0; } if (curX < 0) { px = 0; for (i = curY; i < (curY + curHeight); i++) px = Math.max(px, xMax[i]); curX = px - curX - 1; if (curX < 0) curX = 0; } else if (curY < 0) { py = 0; for (i = curX; i < (curX + curWidth); i++) py = Math.max(py, yMax[i]); curY = py - curY - 1; if (curY < 0) curY = 0; } /* Adjust the grid width and height */ for (px = curX + curWidth; r.width < px; r.width++) ; for (py = curY + curHeight; r.height < py; r.height++) ; /* Adjust the xMax and yMax arrays */ for (i = curX; i < (curX + curWidth); i++) { yMax[i] = py; } for (i = curY; i < (curY + curHeight); i++) { xMax[i] = px; } /* Cache the current slave's size. */ if (sizeflag == PREFERREDSIZE) d = comp.getPreferredSize(); else d = comp.getMinimumSize(); constraints.minWidth = d.width; constraints.minHeight = d.height; /* Zero width and height must mean that this is the last item (or * else something is wrong). */ if (constraints.gridheight == 0 && constraints.gridwidth == 0) curRow = curCol = -1; /* Zero width starts a new row */ if (constraints.gridheight == 0 && curRow < 0) curCol = curX + curWidth; /* Zero height starts a new column */ else if (constraints.gridwidth == 0 && curCol < 0) curRow = curY + curHeight; } /* * Apply minimum row/column dimensions */ if (columnWidths != null && r.width < columnWidths.length) r.width = columnWidths.length; if (rowHeights != null && r.height < rowHeights.length) r.height = rowHeights.length; /* * Pass #2 * * Negative values for gridX are filled in with the current x value. * Negative values for gridY are filled in with the current y value. * Negative or zero values for gridWidth and gridHeight end the current * row or column, respectively. */ curRow = curCol = -1; xMax = new int[MAXGRIDSIZE]; yMax = new int[MAXGRIDSIZE]; for (compindex = 0; compindex < components.length; compindex++) { comp = components[compindex]; if (!comp.isVisible()) continue; constraints = lookupConstraints(comp); curX = constraints.gridx; curY = constraints.gridy; curWidth = constraints.gridwidth; curHeight = constraints.gridheight; /* If x or y is negative, then use relative positioning: */ if (curX < 0 && curY < 0) { if (curRow >= 0) curY = curRow; else if (curCol >= 0) curX = curCol; else curY = 0; } if (curX < 0) { if (curHeight <= 0) { curHeight += r.height - curY; if (curHeight < 1) curHeight = 1; } px = 0; for (i = curY; i < (curY + curHeight); i++) px = Math.max(px, xMax[i]); curX = px - curX - 1; if (curX < 0) curX = 0; } else if (curY < 0) { if (curWidth <= 0) { curWidth += r.width - curX; if (curWidth < 1) curWidth = 1; } py = 0; for (i = curX; i < (curX + curWidth); i++) py = Math.max(py, yMax[i]); curY = py - curY - 1; if (curY < 0) curY = 0; } if (curWidth <= 0) { curWidth += r.width - curX; if (curWidth < 1) curWidth = 1; } if (curHeight <= 0) { curHeight += r.height - curY; if (curHeight < 1) curHeight = 1; } px = curX + curWidth; py = curY + curHeight; for (i = curX; i < (curX + curWidth); i++) { yMax[i] = py; } for (i = curY; i < (curY + curHeight); i++) { xMax[i] = px; } /* Make negative sizes start a new row/column */ if (constraints.gridheight == 0 && constraints.gridwidth == 0) curRow = curCol = -1; if (constraints.gridheight == 0 && curRow < 0) curCol = curX + curWidth; else if (constraints.gridwidth == 0 && curCol < 0) curRow = curY + curHeight; /* Assign the new values to the gridbag slave */ constraints.tempX = curX; constraints.tempY = curY; constraints.tempWidth = curWidth; constraints.tempHeight = curHeight; } /* * Apply minimum row/column dimensions and weights */ if (columnWidths != null) System.arraycopy(columnWidths, 0, r.minWidth, 0, columnWidths.length); if (rowHeights != null) System.arraycopy(rowHeights, 0, r.minHeight, 0, rowHeights.length); if (columnWeights != null) System.arraycopy(columnWeights, 0, r.weightX, 0, columnWeights.length); if (rowWeights != null) System.arraycopy(rowWeights, 0, r.weightY, 0, rowWeights.length); /* * Pass #3 * * Distribute the minimun widths and weights: */ nextSize = Integer.MAX_VALUE; for (i = 1; i != Integer.MAX_VALUE; i = nextSize, nextSize = Integer.MAX_VALUE) { for (compindex = 0; compindex < components.length; compindex++) { comp = components[compindex]; if (!comp.isVisible()) continue; constraints = lookupConstraints(comp); if (constraints.tempWidth == i) { px = constraints.tempX + constraints.tempWidth; /* right column */ /* * Figure out if we should use this slave\'s weight. If the weight * is less than the total weight spanned by the width of the cell, * then discard the weight. Otherwise split the difference * according to the existing weights. */ weight_diff = constraints.weightx; for (k = constraints.tempX; k < px; k++) weight_diff -= r.weightX[k]; if (weight_diff > 0.0) { weight = 0.0; for (k = constraints.tempX; k < px; k++) weight += r.weightX[k]; for (k = constraints.tempX; weight > 0.0 && k < px; k++) { double wt = r.weightX[k]; double dx = (wt * weight_diff) / weight; r.weightX[k] += dx; weight_diff -= dx; weight -= wt; } /* Assign the remainder to the rightmost cell */ r.weightX[px - 1] += weight_diff; } /* * Calculate the minWidth array values. * First, figure out how wide the current slave needs to be. * Then, see if it will fit within the current minWidth values. * If it will not fit, add the difference according to the * weightX array. */ pixels_diff = constraints.minWidth + constraints.ipadx + constraints.insets.left + constraints.insets.right; for (k = constraints.tempX; k < px; k++) pixels_diff -= r.minWidth[k]; if (pixels_diff > 0) { weight = 0.0; for (k = constraints.tempX; k < px; k++) weight += r.weightX[k]; for (k = constraints.tempX; weight > 0.0 && k < px; k++) { double wt = r.weightX[k]; int dx = (int) ((wt * ((double) pixels_diff)) / weight); r.minWidth[k] += dx; pixels_diff -= dx; weight -= wt; } /* Any leftovers go into the rightmost cell */ r.minWidth[px - 1] += pixels_diff; } } else if (constraints.tempWidth > i && constraints.tempWidth < nextSize) nextSize = constraints.tempWidth; if (constraints.tempHeight == i) { py = constraints.tempY + constraints.tempHeight; /* bottom row */ /* * Figure out if we should use this slave's weight. If the weight * is less than the total weight spanned by the height of the cell, * then discard the weight. Otherwise split it the difference * according to the existing weights. */ weight_diff = constraints.weighty; for (k = constraints.tempY; k < py; k++) weight_diff -= r.weightY[k]; if (weight_diff > 0.0) { weight = 0.0; for (k = constraints.tempY; k < py; k++) weight += r.weightY[k]; for (k = constraints.tempY; weight > 0.0 && k < py; k++) { double wt = r.weightY[k]; double dy = (wt * weight_diff) / weight; r.weightY[k] += dy; weight_diff -= dy; weight -= wt; } /* Assign the remainder to the bottom cell */ r.weightY[py - 1] += weight_diff; } /* * Calculate the minHeight array values. * First, figure out how tall the current slave needs to be. * Then, see if it will fit within the current minHeight values. * If it will not fit, add the difference according to the * weightY array. */ pixels_diff = constraints.minHeight + constraints.ipady + constraints.insets.top + constraints.insets.bottom; for (k = constraints.tempY; k < py; k++) pixels_diff -= r.minHeight[k]; if (pixels_diff > 0) { weight = 0.0; for (k = constraints.tempY; k < py; k++) weight += r.weightY[k]; for (k = constraints.tempY; weight > 0.0 && k < py; k++) { double wt = r.weightY[k]; int dy = (int) ((wt * ((double) pixels_diff)) / weight); r.minHeight[k] += dy; pixels_diff -= dy; weight -= wt; } /* Any leftovers go into the bottom cell */ r.minHeight[py - 1] += pixels_diff; } } else if (constraints.tempHeight > i && constraints.tempHeight < nextSize) nextSize = constraints.tempHeight; } } return r; } }