/** * Returns {@code true} if this map or a parent map - if any - contains * a mapping for the specified key. * * @param key key whose presence in this LayoutMap chain is to be tested. * @return {@code true} if this map contains a column mapping * for the specified key. * * @throws NullPointerException if the key is {@code null}. * * @see Map#containsKey(Object) */ public boolean columnContainsKey(String key) { String resolvedKey = resolveColumnKey(key); return columnMap.containsKey(resolvedKey) || parent != null && parent.columnContainsKey(resolvedKey); }
private String expansion(String variableName, boolean horizontal) { String key = stripBraces(variableName); String expansion = horizontal ? columnGet(key) : rowGet(key); if (expansion == null) { String orientation = horizontal ? "column" : "row"; throw new IllegalArgumentException("Unknown " + orientation + " layout variable \"" + key + "\""); } return expansion; }
private void columnPut(String key, String[] aliases, ColumnSpec value) { ensureLowerCase(key); columnPut(key, value); for (String aliase : aliases) { ensureLowerCase(aliase); COLUMN_ALIASES.put(aliase, key); } }
private void rowPut(String key, String[] aliases, RowSpec value) { ensureLowerCase(key); rowPut(key, value); for (int i=0; i < aliases.length; i++) { ensureLowerCase(aliases[i]); ROW_ALIASES.put(aliases[i], key); } }
String resolvedKey = resolveColumnKey(key); String cachedValue = columnMapCache.get(resolvedKey); if (cachedValue != null) { value = parent.columnGet(resolvedKey); String expandedString = expand(value, true); columnMapCache.put(resolvedKey, expandedString); return expandedString;
String resolvedKey = resolveRowKey(key); String cachedValue = (String) rowMapCache.get(resolvedKey); if (cachedValue != null) { value = parent.rowGet(resolvedKey); String expandedString = expand(value, false); rowMapCache.put(resolvedKey, expandedString); return expandedString;
private static LayoutMap createRoot() { LayoutMap map = new LayoutMap(null); map.columnPut( "label-component-gap", new String[]{"lcg", "lcgap"}, FormFactory.LABEL_COMPONENT_GAP_COLSPEC); map.columnPut( "related-gap", new String[]{"rg", "rgap"}, FormFactory.RELATED_GAP_COLSPEC); map.columnPut( "unrelated-gap", new String[]{"ug", "ugap"}, FormFactory.UNRELATED_GAP_COLSPEC); map.columnPut( "button", new String[]{"b"}, FormFactory.BUTTON_COLSPEC); map.columnPut( "growing-button", new String[]{"gb"}, FormFactory.GROWING_BUTTON_COLSPEC); map.columnPut( "dialog-margin", new String[]{"dm", "dmargin"}, ColumnSpec.createGap(LayoutStyle.getCurrent().getDialogMarginX())); map.columnPut( "tabbed-dialog-margin", new String[]{"tdm", "tdmargin"},
/** * Constructs a LayoutMap that has the root LayoutMap as parent. */ public LayoutMap() { this(getRoot()); }
String expand(String expression, boolean horizontal) { int cursor = 0; int start = expression.indexOf(LayoutMap.VARIABLE_PREFIX_CHAR, cursor); if (start == -1) { // No variables return expression; } StringBuffer buffer = new StringBuffer(); do { buffer.append(expression.substring(cursor, start)); String variableName = nextVariableName(expression, start); buffer.append(expansion(variableName, horizontal)); cursor = start + variableName.length() + 1; start = expression.indexOf(LayoutMap.VARIABLE_PREFIX_CHAR, cursor); } while (start != -1); buffer.append(expression.substring(cursor)); return buffer.toString(); }
/** * Parses the encoded column specifications and returns a ColumnSpec object * that represents the string. Variables are expanded using the given * LayoutMap. * * @param encodedColumnSpec the encoded column specification * @param layoutMap expands layout column variables * * @return a ColumnSpec instance for the given specification * @throws NullPointerException if {@code encodedColumnSpec} or * {@code layoutMap} is {@code null} * * @see #decodeSpecs(String, LayoutMap) * * @since 1.2 */ public static ColumnSpec decode(String encodedColumnSpec, LayoutMap layoutMap) { FormUtils.assertNotBlank(encodedColumnSpec, "encoded column specification"); FormUtils.assertNotNull(layoutMap, "LayoutMap"); String trimmed = encodedColumnSpec.trim(); String lower = trimmed.toLowerCase(Locale.ENGLISH); return decodeExpanded(layoutMap.expand(lower, true)); }
public String columnPut(String key, Size value) { return columnPut(key, value.encode()); }
/** * Lazily initializes and returns the LayoutMap that is used * for variable expansion, if no custom LayoutMap is provided. * * @return the LayoutMap that is used, if no custom LayoutMap is provided */ public static LayoutMap getRoot() { if (root == null) { root = createRoot(); } return root; }
String resolvedKey = resolveColumnKey(key); String cachedValue = (String) columnMapCache.get(resolvedKey); if (cachedValue != null) { value = parent.columnGet(resolvedKey); String expandedString = expand(value, true); columnMapCache.put(resolvedKey, expandedString); return expandedString;
String resolvedKey = resolveRowKey(key); String cachedValue = rowMapCache.get(resolvedKey); if (cachedValue != null) { value = parent.rowGet(resolvedKey); String expandedString = expand(value, false); rowMapCache.put(resolvedKey, expandedString); return expandedString;
private static LayoutMap createRoot() { LayoutMap map = new LayoutMap(null); map.columnPut( "label-component-gap", new String[]{"lcg", "lcgap"}, FormFactory.LABEL_COMPONENT_GAP_COLSPEC); map.columnPut( "related-gap", new String[]{"rg", "rgap"}, FormFactory.RELATED_GAP_COLSPEC); map.columnPut( "unrelated-gap", new String[]{"ug", "ugap"}, FormFactory.UNRELATED_GAP_COLSPEC); map.columnPut( "button", new String[]{"b"}, FormFactory.BUTTON_COLSPEC); map.columnPut( "growing-button", new String[]{"gb"}, FormFactory.GROWING_BUTTON_COLSPEC); map.columnPut( "dialog-margin", new String[]{"dm", "dmargin"}, ColumnSpec.createGap(LayoutStyle.getCurrent().getDialogMarginX())); map.columnPut( "tabbed-dialog-margin", new String[]{"tdm", "tdmargin"},
/** * Constructs a LayoutMap that has the root LayoutMap as parent. */ public LayoutMap() { this(getRoot()); }
private void rowPut(String key, String[] aliases, RowSpec value) { ensureLowerCase(key); rowPut(key, value); for (String aliase : aliases) { ensureLowerCase(aliase); ROW_ALIASES.put(aliase, key); } }
String expand(String expression, boolean horizontal) { int cursor = 0; int start = expression.indexOf(LayoutMap.VARIABLE_PREFIX_CHAR, cursor); if (start == -1) { // No variables return expression; } StringBuffer buffer = new StringBuffer(); do { buffer.append(expression.substring(cursor, start)); String variableName = nextVariableName(expression, start); buffer.append(expansion(variableName, horizontal)); cursor = start + variableName.length() + 1; start = expression.indexOf(LayoutMap.VARIABLE_PREFIX_CHAR, cursor); } while (start != -1); buffer.append(expression.substring(cursor)); return buffer.toString(); }
/** * Constructs a parser for the given encoded column/row specification, * the given LayoutMap, and orientation. * * @param source the raw encoded column or row specification * as provided by the user * @param description describes the source, e.g. "column specification" * @param layoutMap maps layout variable names to ColumnSpec and * RowSpec objects * @param horizontal {@code true} for columns, {@code false} for rows * * @throws NullPointerException if {@code source} is {@code null} */ private FormSpecParser( String source, String description, LayoutMap layoutMap, boolean horizontal) { FormUtils.assertNotNull(source, description); FormUtils.assertNotNull(layoutMap, "LayoutMap"); this.layoutMap = layoutMap; this.source = this.layoutMap.expand(source, horizontal); }
public String columnPut(String key, Size value) { return columnPut(key, value.encode()); }