/** Merges sizes and gaps together with Resize Constraints. For gaps {@link #GAP_RC_CONST} is used. * @param resConstr One resize constraint for every row/component. Can be lesser in length and the last element should be used for missing elements. * @param gapPush If the corresponding gap should be considered pushing and thus want to take free space if left over. Should be one more than resConstrs! * @param minPrefMaxSizes The sizes (min/pref/max) for every row/component. * @param gapSizes The gaps before and after each row/component packed in one double sized array. * @return A holder for the merged values. */ private static FlowSizeSpec mergeSizesGapsAndResConstrs(ResizeConstraint[] resConstr, boolean[] gapPush, int[][] minPrefMaxSizes, int[][] gapSizes) { int[][] sizes = new int[(minPrefMaxSizes.length << 1) + 1][]; // Make room for gaps around. ResizeConstraint[] resConstsInclGaps = new ResizeConstraint[sizes.length]; sizes[0] = gapSizes[0]; for (int i = 0, crIx = 1; i < minPrefMaxSizes.length; i++, crIx += 2) { // Component bounds and constraints resConstsInclGaps[crIx] = resConstr[i]; sizes[crIx] = minPrefMaxSizes[i]; sizes[crIx + 1] = gapSizes[i + 1]; if (sizes[crIx - 1] != null) resConstsInclGaps[crIx - 1] = gapPush[i < gapPush.length ? i : gapPush.length - 1] ? GAP_RC_CONST_PUSH : GAP_RC_CONST; if (i == (minPrefMaxSizes.length - 1) && sizes[crIx + 1] != null) resConstsInclGaps[crIx + 1] = gapPush[(i + 1) < gapPush.length ? (i + 1) : gapPush.length - 1] ? GAP_RC_CONST_PUSH : GAP_RC_CONST; } // Check for null and set it to 0, 0, 0. for (int i = 0; i < sizes.length; i++) { if (sizes[i] == null) sizes[i] = new int[3]; } return new FlowSizeSpec(sizes, resConstsInclGaps); }