/** * 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;
/** * 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()); }
/** * 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()); }
DefaultAlignment alignmentDefault = isHorizontal() ? ColumnSpec.DEFAULT : RowSpec.DEFAULT;
/** * 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 decodeAtomicSize(String token) { Sizes.ComponentSize componentSize = Sizes.ComponentSize.valueOf(token); if (componentSize != null) return componentSize; else return ConstantSize.valueOf(token, isHorizontal()); }
DefaultAlignment alignment = DefaultAlignment.valueOf(next, isHorizontal()); if (alignment != null) { setDefaultAlignment(alignment);
/** * 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])); } }