FormSpec.DefaultAlignment defaultAlignment = formSpec.getDefaultAlignment(); if (defaultAlignment == FormSpec.FILL_ALIGN) { return FILL;
/** * Checks and answers whether this spec can grow or not. * That is the case if and only if the resize weight is * != <code>NO_GROW</code>. * * @return true if it can grow, false if it can't grow */ final boolean canGrow() { return getResizeWeight() != NO_GROW; }
DefaultAlignment alignment = DefaultAlignment.valueOf(next, isHorizontal()); if (alignment != null) { setDefaultAlignment(alignment); if (token.length == 1) { throw new IllegalArgumentException( setSize(parseSize(next)); if (nextIndex < token.length) { setResizeWeight(parseResizeWeight(token[nextIndex]));
/** * Parses an encoded size spec and returns the size. * * @param token a token that represents a size, either bounded or plain * @return the decoded Size */ private Size parseSize(String token) { if (token.startsWith("[") && token.endsWith("]")) { return parseBoundedSize(token); } if (token.startsWith("max(") && token.endsWith(")")) { return parseOldBoundedSize(token, false); } if (token.startsWith("min(") && token.endsWith(")")) { return parseOldBoundedSize(token, true); } return parseAtomicSize(token); }
Size upper = null; if (subtoken.length == 2) { Size size1 = parseAtomicSize(subtoken[0]); Size size2 = parseAtomicSize(subtoken[1]); if (isConstant(size1)) { lower = size1; basis = size2; lower = parseAtomicSize(subtoken[0]); basis = parseAtomicSize(subtoken[1]); upper = parseAtomicSize(subtoken[2]); && ((lower == null) || (isConstant(lower))) && ((upper == null) || (isConstant(upper)))) { return new BoundedSize(basis, lower, upper);
FormSpec formSpec = (FormSpec) formSpecs.get(i); sizes[i] = prefSizes[i]; if (formSpec.getSize() == Sizes.DEFAULT) { sizes[i] -= (int) Math.round((prefSizes[i] - minSizes[i]) * compressionFactor);
/** * Parses an encoded form spec and initializes all required fields. The * encoded description must be in lower case. * * @param encodedDescription * the FormSpec in an encoded format * @throws IllegalArgumentException * if the string is empty, has no size, or is otherwise invalid */ private void parseAndInitValues(String encodedDescription) { StringTokenizer tokenizer = new StringTokenizer(encodedDescription, ":"); if (!tokenizer.hasMoreTokens()) { throw new IllegalArgumentException("The form spec must not be empty."); } String token = tokenizer.nextToken(); // Check if the first token is an orientation. DefaultAlignment alignment = DefaultAlignment.valueOf(token, isHorizontal()); if (alignment != null) { defaultAlignment = alignment; if (!tokenizer.hasMoreTokens()) { throw new IllegalArgumentException("The form spec must provide a size."); } token = tokenizer.nextToken(); } parseAndInitSize(token); if (tokenizer.hasMoreTokens()) { resizeWeight = decodeResize(tokenizer.nextToken()); } }
DefaultAlignment alignmentDefault = isHorizontal() ? ColumnSpec.DEFAULT : RowSpec.DEFAULT;
/** * Constructs a FormSpec from the specified encoded description. * The description will be parsed to set initial values. * * @param defaultAlignment the default alignment * @param encodedDescription the encoded description */ protected FormSpec(DefaultAlignment defaultAlignment, String encodedDescription) { this(defaultAlignment, Sizes.DEFAULT, NO_GROW); parseAndInitValues(encodedDescription.toLowerCase(Locale.ENGLISH)); }
for (int i = 0; i < size; i++) { formSpec = (FormSpec) formSpecs.get(i); result[i] = formSpec.maximumSize(container, componentLists[i], minMeasure,
for (int i = size-1; i >= 0; i--) { if (spec.canGrow()) { maximumFixedSpan = 0;
/** * Parses an encoded size spec and returns the size. * * @param token a token that represents a size, either bounded or plain * @return the decoded Size */ private Size parseSize(String token) { if (token.startsWith("[") && token.endsWith("]")) { return parseBoundedSize(token); } if (token.startsWith("max(") && token.endsWith(")")) { return parseOldBoundedSize(token, false); } if (token.startsWith("min(") && token.endsWith(")")) { return parseOldBoundedSize(token, true); } return parseAtomicSize(token); }
Size upper = null; if (subtoken.length == 2) { Size size1 = parseAtomicSize(subtoken[0]); Size size2 = parseAtomicSize(subtoken[1]); if (isConstant(size1)) { if (isConstant(size2)) { lower = size1; basis = size2; lower = parseAtomicSize(subtoken[0]); basis = parseAtomicSize(subtoken[1]); upper = parseAtomicSize(subtoken[2]); if ( (lower == null || isConstant(lower)) && (upper == null || isConstant(upper))) { return new BoundedSize(basis, lower, upper);
FormSpec formSpec = (FormSpec) formSpecs.get(i); sizes[i] = prefSizes[i]; if (formSpec.getSize().compressible()) { sizes[i] -= (int) Math.round((prefSizes[i] - minSizes[i])
/** * Decodes and returns an atomic size that is either a constant size or a * component size. * * @param token the encoded size * @return the decoded size either a constant or component size */ private Size parseAtomicSize(String token) { String trimmedToken = token.trim(); if ( trimmedToken.startsWith("'") && trimmedToken.endsWith("'")) { int length = trimmedToken.length(); if (length < 2) { throw new IllegalArgumentException("Missing closing \"'\" for prototype."); } return new PrototypeSize(trimmedToken.substring(1, length - 1)); } Sizes.ComponentSize componentSize = Sizes.ComponentSize.valueOf(trimmedToken); if (componentSize != null) { return componentSize; } return ConstantSize.valueOf(trimmedToken, isHorizontal()); }
/** * Constructs a FormSpec from the specified encoded description. * The description will be parsed to set initial values. * * @param defaultAlignment the default alignment * @param encodedDescription the encoded description */ protected FormSpec(DefaultAlignment defaultAlignment, String encodedDescription) { this(defaultAlignment, Sizes.DEFAULT, NO_GROW); parseAndInitValues(encodedDescription.toLowerCase(Locale.ENGLISH)); }
/** * Computes and returns the sizes for the given form specs, component lists * and measures fot minimum, preferred, and default size. * * @param container * the layout container * @param formSpecs * the column or row specs, resp. * @param componentLists * the components list for each col/row * @param minMeasure * the measure used to determin min sizes * @param prefMeasure * the measure used to determin pre sizes * @param defaultMeasure * the measure used to determin default sizes * @return the column or row sizes */ private int[] maximumSizes(Container container, List formSpecs, List[] componentLists, Measure minMeasure, Measure prefMeasure, Measure defaultMeasure) { FormSpec formSpec; int size = formSpecs.size(); int result[] = new int[size]; for (int i = 0; i < size; i++) { formSpec = (FormSpec) formSpecs.get(i); result[i] = formSpec.maximumSize(container, componentLists[i], minMeasure, prefMeasure, defaultMeasure); } return result; }
for (int i = size-1; i >= 0; i--) { if (spec.canGrow()) { maximumFixedSpan = 0;
/** * Parses an encoded form specification and initializes all required fields. * The encoded description must be in lower case. * * @param encodedDescription the FormSpec in an encoded format * * @throws NullPointerException if {@code encodedDescription} is {@code null} * @throws IllegalArgumentException if {@code encodedDescription} * is empty, whitespace, has no size, or is otherwise invalid */ private void parseAndInitValues(String encodedDescription) { checkNotBlank(encodedDescription, "The encoded form specification must not be null, empty or whitespace."); String[] token = TOKEN_SEPARATOR_PATTERN.split(encodedDescription); checkArgument(token.length > 0, "The form spec must not be empty."); int nextIndex = 0; String next = token[nextIndex++]; // Check if the first token is an orientation. DefaultAlignment alignment = DefaultAlignment.valueOf(next, isHorizontal()); if (alignment != null) { setDefaultAlignment(alignment); checkArgument(token.length > 1, "The form spec must provide a size."); next = token[nextIndex++]; } setSize(parseSize(next)); if (nextIndex < token.length) { setResizeWeight(parseResizeWeight(token[nextIndex])); } }
String sizeToken2 = token.substring(semicolonIndex+1, token.length()-1); Size size1 = parseAtomicSize(sizeToken1); Size size2 = parseAtomicSize(sizeToken2); if (isConstant(size1)) { if (size2 instanceof Sizes.ComponentSize) { return new BoundedSize(size2, setMax ? null : size1, "Bounded sizes must not be both constants."); if (isConstant(size2)) { return new BoundedSize(size1, setMax ? null : size2, setMax ? size2 : null);