int[][] (Object component, int gap) { java.lang.ref.Reference.reachabilityFence(gap); int count = 0; for (Object comp = get(component, "component"); comp != null; comp = get(comp, ":next")) { if (getBoolean(comp, "visible", true)) { count++; } } if (count == 0) { return null; } int columns = getInteger(component, "columns", 0); int icols = (columns != 0) ? columns : count; int irows = (columns != 0) ? ((count + columns - 1) / columns) : 1; int[][] grid = { new int[icols], new int[irows], // columnwidths, rowheights new int[icols], new int[irows], // columnweights, rowweights new int[count], new int[count], // gridx, gridy new int[count], new int[count]}; // gridwidth, gridheight int[] columnheight = new int[icols]; int[][] cache = null; // preferredwidth, height, columnweight, rowweight int i = 0; int x = 0; int y = 0; int nextsize = 0; for (Object comp = get(component, "component"); comp != null; comp = get(comp, ":next")) { if (!getBoolean(comp, "visible", true)) { continue; } int colspan = ((columns != 0) && (columns < count)) ? Math.min(getInteger(comp, "colspan", 1), columns) : 1; int rowspan = (columns != 1) ? getInteger(comp, "rowspan", 1) : 1; for (int j = 0; j < colspan; j++) { if ((columns != 0) && (x + colspan > columns)) { x = 0; y++; j = -1; } else if (columnheight[x + j] > y) { x += (j + 1); j = -1; } } if (y + rowspan > grid[1].length) { int[] rowheights = new int[y + rowspan]; System.arraycopy(grid[1], 0, rowheights, 0, grid[1].length); grid[1] = rowheights; int[] rowweights = new int[y + rowspan]; System.arraycopy(grid[3], 0, rowweights, 0, grid[3].length); grid[3] = rowweights; } for (int j = 0; j < colspan; j++) { columnheight[x + j] = y + rowspan; } int weightx = getInteger(comp, "weightx", 0); int weighty = getInteger(comp, "weighty", 0); Dimension d = getPreferredSize(comp); if (colspan == 1) { grid[0][x] = Math.max(grid[0][x], d.width); // columnwidths grid[2][x] = Math.max(grid[2][x], weightx); // columnweights } else { if (cache == null) { cache = new int[4][count]; } cache[0][i] = d.width; cache[2][i] = weightx; if ((nextsize == 0) || (colspan < nextsize)) { nextsize = colspan; } } if (rowspan == 1) { grid[1][y] = Math.max(grid[1][y], d.height); // rowheights grid[3][y] = Math.max(grid[3][y], weighty); // rowweights } else { if (cache == null) { cache = new int[4][count]; } cache[1][i] = d.height; cache[3][i] = weighty; if ((nextsize == 0) || (rowspan < nextsize)) { nextsize = rowspan; } } grid[4][i] = x; //gridx grid[5][i] = y; //gridy grid[6][i] = colspan; //gridwidth grid[7][i] = rowspan; //gridheight x += colspan; i++; } while (nextsize != 0) { int size = nextsize; nextsize = 0; for (int j = 0; j < 2; j++) { // horizontal, vertical for (int k = 0; k < count; k++) { if (grid[6 + j][k] == size) { // gridwidth, gridheight int gridpoint = grid[4 + j][k]; // gridx, gridy int weightdiff = cache[2 + j][k]; for (int m = 0; (weightdiff > 0) && (m < size); m++) { weightdiff -= grid[2 + j][gridpoint + m]; } if (weightdiff > 0) { int weightsum = cache[2 + j][k] - weightdiff; for (int m = 0; (weightsum > 0) && (m < size); m++) { int weight = grid[2 + j][gridpoint + m]; if (weight > 0) { int weightinc = weight * weightdiff / weightsum; grid[2 + j][gridpoint + m] += weightinc; weightdiff -= weightinc; weightsum -= weightinc; } } grid[2 + j][gridpoint + size - 1] += weightdiff; } int sizediff = cache[j][k]; int weightsum = 0; for (int m = 0; (sizediff > 0) && (m < size); m++) { sizediff -= grid[j][gridpoint + m]; weightsum += grid[2 + j][gridpoint + m]; } if (sizediff > 0) { for (int m = 0; (weightsum > 0) && (m < size); m++) { int weight = grid[2 + j][gridpoint + m]; if (weight > 0) { int sizeinc = weight * sizediff / weightsum; grid[j][gridpoint + m] += sizeinc; sizediff -= sizeinc; weightsum -= weight; } } grid[j][gridpoint + size - 1] += sizediff; } } else if ((grid[6 + j][k] > size) && ((nextsize == 0) || (grid[6 + j][k] < nextsize))) { nextsize = grid[6 + j][k]; } } } } return grid; }