/** Parses a single unit value. E.g. "10px" or "5in" * @param s The string to parse. Not <code>null</code>. May look something like <code>"10px"</code> or <code>"5dlu"</code>. * @param isHor If the value is for the horizontal dimension. * @return The parsed unit value. <code>null</code> is empty string, */ public static UnitValue parseUnitValue(String s, boolean isHor) { return parseUnitValue(s, null, isHor); }
pos[edge] = parseUnitValue(part.substring(2).trim(), null, c == 'x'); cc.setPos(pos); cc.setBoundsInGrid(true); UnitValue[] bounds = new UnitValue[4]; for (int j = 0; j < pos.length; j++) bounds[j] = parseUnitValue(pos[j], null, j % 2 == 0); String uvStr = part.substring(5).trim(); if (uvStr.length() > 0) { UnitValue uv = parseUnitValue(uvStr, null, isHor); boolean isMin = part.charAt(3) == 'n'; DimConstraint dc = isHor ? cc.getHorizontal() : cc.getVertical();
/** Sets the same inset (expressed as a <code>UnitValue</code>, e.g. "10px" or "20mm") all around. * <p> * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. * @param allSides The unit value to set for all sides. May be <code>null</code> which means that the default panel insets * for the platform is used. * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. * @see #setInsets(UnitValue[]) */ public final LC insetsAll(String allSides) { UnitValue insH = ConstraintParser.parseUnitValue(allSides, true); UnitValue insV = ConstraintParser.parseUnitValue(allSides, false); insets = new UnitValue[] {insV, insH, insV, insH}; // No setter to avoid copy again return this; }
/** Sets the different insets (expressed as a <code>UnitValue</code>s, e.g. "10px" or "20mm") for the corresponding sides. * <p> * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. * @param top The top inset. E.g. "10px" or "10mm" or "related". May be <code>null</code> in which case the default inset for this * side for the platform will be used. * @param left The left inset. E.g. "10px" or "10mm" or "related". May be <code>null</code> in which case the default inset for this * side for the platform will be used. * @param bottom The bottom inset. E.g. "10px" or "10mm" or "related". May be <code>null</code> in which case the default inset for this * side for the platform will be used. * @param right The right inset. E.g. "10px" or "10mm" or "related". May be <code>null</code> in which case the default inset for this * side for the platform will be used. * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. * @see #setInsets(UnitValue[]) */ public final LC insets(String top, String left, String bottom, String right) { insets = new UnitValue[] { // No setter to avoid copy again ConstraintParser.parseUnitValue(top, false), ConstraintParser.parseUnitValue(left, true), ConstraintParser.parseUnitValue(bottom, false), ConstraintParser.parseUnitValue(right, true)}; return this; }
/** Same functionality as {@link #x(String x)}, {@link #y(String y)}, {@link #y2(String y)} and {@link #y2(String y)} together. * <p> * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. * @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10". * @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10". * @param x2 The x2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10". * @param y2 The y2 side's position as a UnitValue. E.g. "10" or "40mm" or "container.x2 - 10". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. * @see #setPos(UnitValue[]) */ public final CC pos(String x, String y, String x2, String y2) { setPos(new UnitValue[] { ConstraintParser.parseUnitValue(x, true), ConstraintParser.parseUnitValue(y, false), ConstraintParser.parseUnitValue(x2, true), ConstraintParser.parseUnitValue(y2, false), }); setBoundsInGrid(false); return this; }
/** Parses a single unit value that may also be an alignment as parsed by {@link #parseAlignKeywords(String, boolean)}. * @param s The string to parse. Not <code>null</code>. May look something like <code>"10px"</code> or <code>"5dlu"</code>. * @param isHor If the value is for the horizontal dimension. * @param emptyReplacement A replacement if <code>s</code> is empty. May be <code>null</code>. * @return The parsed unit value. May be <code>null</code>. */ public static UnitValue parseUnitValueOrAlign(String s, boolean isHor, UnitValue emptyReplacement) { if (s.length() == 0) return emptyReplacement; UnitValue align = parseAlignKeywords(s, isHor); if (align != null) return align; return parseUnitValue(s, emptyReplacement, isHor); }
if (hasEM) s0 = s0.substring(0, s0.length() - 1); UnitValue uv = parseUnitValue(s0, null, isHor); return new BoundSize(((isGap || hasEM) ? uv : null), uv, (hasEM ? uv : null), push, cs); return new BoundSize(parseUnitValue(s0, null, isHor), parseUnitValue(sizes[1], null, isHor), null, push, cs); } else if (sizes.length == 3) { return new BoundSize(parseUnitValue(s0, null, isHor), parseUnitValue(sizes[1], null, isHor), parseUnitValue(sizes[2], null, isHor), push, cs); } else { throw new IllegalArgumentException("Min:Preferred:Max size section must contain 0, 1 or 2 colons. '" + cs + "'");
/** Same functionality as {@link #x(String x)} and {@link #y(String y)} together. * <p> * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. * @param x The x position as a UnitValue. E.g. "10" or "40mm" or "container.x+10". * @param y The y position as a UnitValue. E.g. "10" or "40mm" or "container.x+10". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. * @see #setPos(UnitValue[]) */ public final CC pos(String x, String y) { UnitValue[] b = getPos(); if (b == null) b = new UnitValue[4]; b[0] = ConstraintParser.parseUnitValue(x, true); b[1] = ConstraintParser.parseUnitValue(y, false); setPos(b); setBoundsInGrid(false); return this; }
uvs = toTrimmedTokens(sub, ','); if (uvs.length == 1) return parseUnitValue(sub, null, isHor); } else { char delim; throw new IllegalArgumentException("Malformed UnitValue: '" + s + "'"); UnitValue sub1 = parseUnitValue(uvs[0], null, isHor); UnitValue sub2 = parseUnitValue(uvs[1], null, isHor);
/** The minimum size for the component. The value will override any value that is set on the component itself. * <p> * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. */ public final CC minWidth(String size) { hor.setSize(LayoutUtil.derive(hor.getSize(), ConstraintParser.parseUnitValue(size, true), null, null)); return this; }
/** The maximum width for the container. The value will override any value that is set on the container itself. * <p> * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com. * @param width The width expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. */ public final LC maxWidth(String width) { setWidth(LayoutUtil.derive(getWidth(), null, null, ConstraintParser.parseUnitValue(width, true))); return this; }
/** The maximum size for the component. The value will override any value that is set on the component itself. * <p> * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. */ public final CC maxWidth(String size) { hor.setSize(LayoutUtil.derive(hor.getSize(), null, null, ConstraintParser.parseUnitValue(size, true))); return this; }
/** The minimum size for the component. The value will override any value that is set on the component itself. * <p> * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. */ public final CC minHeight(String size) { ver.setSize(LayoutUtil.derive(ver.getSize(), ConstraintParser.parseUnitValue(size, false), null, null)); return this; }
/** The minimum height for the container. The value will override any value that is set on the container itself. * <p> * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com. * @param height The height expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. */ public final LC minHeight(String height) { setHeight(LayoutUtil.derive(getHeight(), ConstraintParser.parseUnitValue(height, false), null, null)); return this; }
/** The maximum height for the container. The value will override any value that is set on the container itself. * <p> * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcontainers.com. * @param height The height expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. */ public final LC maxHeight(String height) { setHeight(LayoutUtil.derive(getHeight(), null, null, ConstraintParser.parseUnitValue(height, false))); return this; }
/** Parses insets which consists of 1-4 <code>UnitValue</code>s. * @param s The string to parse. E.g. "10 10 10 10" or "20". If less than 4 groups the last will be used for the missing. * @param acceptPanel If "panel" and "dialog" should be accepted. They are used to access platform defaults. * @return An array of length 4 with the parsed insets. * @throws IllegalArgumentException if the parsing could not be done. */ public static UnitValue[] parseInsets(String s, boolean acceptPanel) { if (s.length() == 0 || s.equals("dialog") || s.equals("panel")) { if (acceptPanel == false) throw new IllegalArgumentException("Insets now allowed: " + s + "\n"); boolean isPanel = s.startsWith("p"); UnitValue[] ins = new UnitValue[4]; for (int j = 0; j < 4; j++) ins[j] = isPanel ? PlatformDefaults.getPanelInsets(j) : PlatformDefaults.getDialogInsets(j); return ins; } else { String[] insS = toTrimmedTokens(s, ' '); UnitValue[] ins = new UnitValue[4]; for (int j = 0; j < 4; j++) { UnitValue insSz = parseUnitValue(insS[j < insS.length ? j : insS.length - 1], UnitValue.ZERO, j % 2 == 1); ins[j] = insSz != null ? insSz : PlatformDefaults.getPanelInsets(j); } return ins; } }
private final CC corrPos(String uv, int ix) { UnitValue[] b = getPos(); if (b == null) b = new UnitValue[4]; b[ix] = ConstraintParser.parseUnitValue(uv, (ix % 2 == 0)); setPos(b); setBoundsInGrid(true); return this; }
/** The maximum size for the component. The value will override any value that is set on the component itself. * <p> * For a more thorough explanation of what this constraint does see the white paper or cheat Sheet at www.migcomponents.com. * @param size The size expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new ComponentConstraint().noGrid().gap().fill()</code>. */ public final CC maxHeight(String size) { ver.setSize(LayoutUtil.derive(ver.getSize(), null, null, ConstraintParser.parseUnitValue(size, false))); return this; }
/** The minimum width for the container. The value will override any value that is set on the container itself. * <p> * For a more thorough explanation of what this constraint does see the white paper or Cheat Sheet at www.migcontainers.com. * @param width The width expressed as a <code>UnitValue</code>. E.g. "100px" or "200mm". * @return <code>this</code> so it is possible to chain calls. E.g. <code>new LayoutConstraint().noGrid().gap().fill()</code>. */ public final LC minWidth(String width) { setWidth(LayoutUtil.derive(getWidth(), ConstraintParser.parseUnitValue(width, true), null, null)); return this; }