public final class ConstraintParser

  1. Object
  2. ConstraintParser
Parses string constraints.

Methods

public static LC parseLayoutConstraint(String s)Parses the layout constraints and stores the parsed values in the transient (cache) member varables.
public static AC parseRowConstraints(String s)Parses the column or rows constraints.
public static AC parseColumnConstraints(String s)Parses the column or rows constraints.
public static Map<ComponentWrapper, CC> parseComponentConstraints(Map<ComponentWrapper, String> constrMap)Parses all component constraints and stores the parsed values in the transient (cache) member variables.
public static CC parseComponentConstraint(String s)Parses one component constraint and returns the parsed value.
public static UnitValue[] parseInsets(String s, boolean acceptPanel)Parses insets which consists of 1-4 UnitValues.
public static BoundSize parseBoundSize(String s, boolean isGap, boolean isHor)Parses a single “min:pref:max” value.
public static UnitValue parseUnitValueOrAlign(String s, boolean isHor, UnitValue emptyReplacement)Parses a single unit value that may also be an alignment as parsed by boolean).
public static UnitValue parseUnitValue(String s, boolean isHor)Parses a single unit value.
public static String prepare(String s)Makes null “”, trims and converts to lower case.

Inherited methods

Method details

parseLayoutConstraint

public static LC parseLayoutConstraint(String s)
Parses the layout constraints and stores the parsed values in the transient (cache) member varables.

Parameters

s String
The String to parse. Should not be null and must be lower case and trimmed.

Returns

The parsed constraint. Never null.

Throws

RuntimeException
if the constaint was not valid.

parseRowConstraints

public static AC parseRowConstraints(String s)
Parses the column or rows constraints. They normally looks something like "[min:pref]rel[10px][]".

Parameters

s String
The string to parse. Not null.

Returns

An array of DimConstraints that is as many are there exist “[…]” sections in the string that is parsed.

Throws

RuntimeException
if the constraint was not valid.

parseColumnConstraints

public static AC parseColumnConstraints(String s)
Parses the column or rows constraints. They normally looks something like "[min:pref]rel[10px][]".

Parameters

s String
The string to parse. Not null.

Returns

An array of DimConstraints that is as many are there exist “[…]” sections in the string that is parsed.

Throws

RuntimeException
if the constraint was not valid.

parseComponentConstraints

public static Map<ComponentWrapper, CC> parseComponentConstraints(Map<ComponentWrapper, String> constrMap)
Parses all component constraints and stores the parsed values in the transient (cache) member variables.

Parameters

constrMap Map<ComponentWrapper, String>
The constraints as Strings. Strings must be lower case and trimmed

Returns

The parsed constraints. Never null.

parseComponentConstraint

public static CC parseComponentConstraint(String s)
Parses one component constraint and returns the parsed value.

Parameters

s String
The string to parse. Should not be null and must be lower case and trimmed.

Returns

The parsed constraint. Never null.

Throws

RuntimeException
if the constraint was not valid.

parseInsets

public static UnitValue[] parseInsets(String s, boolean acceptPanel)
Parses insets which consists of 1-4 UnitValues.

Parameters

s String
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.
acceptPanel boolean
If “panel” and “dialog” should be accepted. They are used to access platform defaults.

Returns

An array of length 4 with the parsed insets.

Throws

IllegalArgumentException
if the parsing could not be done.

parseBoundSize

public static BoundSize parseBoundSize(String s, boolean isGap, boolean isHor)
Parses a single “min:pref:max” value. May look something like "10px:20lp:30%" or "pref!".

Parameters

s String
The string to parse. Not null.
isGap boolean
If this bound size is a gap (different empty string handling).
isHor boolean
If the size is for the horizontal dimension.

Returns

A bound size that may be null if the string was “null”, “n” or null.

parseUnitValueOrAlign

public static UnitValue parseUnitValueOrAlign(String s, boolean isHor, UnitValue emptyReplacement)
Parses a single unit value that may also be an alignment as parsed by boolean).

Parameters

s String
The string to parse. Not null. May look something like "10px" or "5dlu".
isHor boolean
If the value is for the horizontal dimension.
emptyReplacement UnitValue
A replacement if s is empty. May be null.

Returns

The parsed unit value. May be null.

parseUnitValue

public static UnitValue parseUnitValue(String s, boolean isHor)
Parses a single unit value. E.g. “10px” or “5in”

Parameters

s String
The string to parse. Not null. May look something like "10px" or "5dlu".
isHor boolean
If the value is for the horizontal dimension.

Returns

The parsed unit value. null is empty string,

prepare

public static String prepare(String s)
Makes null “”, trims and converts to lower case.

Parameters

s String
The string

Returns

Not null.