- java.lang.Object
-
- net.miginfocom.layout.ConstraintParser
-
public final class ConstraintParser extends java.lang.Object
Parses string constraints.
-
-
Constructor Summary
Constructors Modifier Constructor Description private
ConstraintParser()
-
Method Summary
All Methods Static Methods Concrete Methods Modifier and Type Method Description private static java.lang.String[]
getNumTextParts(java.lang.String s)
Splits a text-number combination such as "hello 10.0" into{"hello", "10.0"}
.private static int
getOper(java.lang.String s)
Returns the operation depending on the start character.private static java.util.ArrayList<java.lang.String>
getRowColAndGapsTrimmed(java.lang.String s)
Parses "AAA[BBB]CCC[DDD]EEE" into {"AAA", "BBB", "CCC", "DDD", "EEE", "FFF"}.(package private) static UnitValue
parseAlignKeywords(java.lang.String s, boolean isHor)
Parses alignment keywords and returns the appropriateUnitValue
.private static AC
parseAxisConstraint(java.lang.String s, boolean isCols)
Parses the column or rows constraints.static BoundSize
parseBoundSize(java.lang.String s, boolean isGap, boolean isHor)
Parses a single "min:pref:max" value.static AC
parseColumnConstraints(java.lang.String s)
Parses the column or rows constraints.static CC
parseComponentConstraint(java.lang.String s)
Parses one component constraint and returns the parsed value.static java.util.Map<ComponentWrapper,CC>
parseComponentConstraints(java.util.Map<ComponentWrapper,java.lang.String> constrMap)
Parses all component constraints and stores the parsed values in the transient (cache) member variables.private static DimConstraint
parseDimConstraint(java.lang.String s, BoundSize gapBefore, BoundSize gapAfter, boolean isCols)
Parses a single column or row constraint.private static java.lang.Float
parseFloat(java.lang.String s, java.lang.Float nullVal)
private static BoundSize[]
parseGaps(java.lang.String s)
Parses gaps.static UnitValue[]
parseInsets(java.lang.String s, boolean acceptPanel)
Parses insets which consists of 1-4UnitValue
s.static LC
parseLayoutConstraint(java.lang.String s)
Parses the layout constraints and stores the parsed values in the transient (cache) member variables.static AC
parseRowConstraints(java.lang.String s)
Parses the column or rows constraints.private static int
parseSpan(java.lang.String s)
static UnitValue
parseUnitValue(java.lang.String s, boolean isHor)
Parses a single unit value.private static UnitValue
parseUnitValue(java.lang.String s, UnitValue emptyReplacement, boolean isHor)
Parses a single unit value.static UnitValue
parseUnitValueOrAlign(java.lang.String s, boolean isHor, UnitValue emptyReplacement)
Parses a single unit value that may also be an alignment as parsed byparseAlignKeywords(String, boolean)
.static java.lang.String
prepare(java.lang.String s)
Makesnull
"", trims and converts to lower case.private static int
startsWithLenient(java.lang.String s, java.lang.String[] matches, int[] minChars, boolean acceptTrailing)
Returns if a string shares at least a specified numbers starting characters with a number of matches.private static int
startsWithLenient(java.lang.String s, java.lang.String match, int minChars, boolean acceptTrailing)
Returns if a string shares at least a specified numbers starting characters with a match.private static java.lang.String[]
toTrimmedTokens(java.lang.String s, char sep)
Parses a string and returns it in those parts of the string that are separated with asep
character.
-
-
-
Method Detail
-
parseLayoutConstraint
public static LC parseLayoutConstraint(java.lang.String s)
Parses the layout constraints and stores the parsed values in the transient (cache) member variables.- Parameters:
s
- The String to parse. Should not benull
and must be lower case and trimmed.- Returns:
- The parsed constraint. Never
null
. - Throws:
java.lang.RuntimeException
- if the constraint was not valid.
-
parseRowConstraints
public static AC parseRowConstraints(java.lang.String s)
Parses the column or rows constraints. They normally looks something like"[min:pref]rel[10px][]"
.- Parameters:
s
- The string to parse. Notnull
.- Returns:
- An array of
DimConstraint
s that is as many are there exist "[...]" sections in the string that is parsed. - Throws:
java.lang.RuntimeException
- if the constraint was not valid.
-
parseColumnConstraints
public static AC parseColumnConstraints(java.lang.String s)
Parses the column or rows constraints. They normally looks something like"[min:pref]rel[10px][]"
.- Parameters:
s
- The string to parse. Notnull
.- Returns:
- An array of
DimConstraint
s that is as many are there exist "[...]" sections in the string that is parsed. - Throws:
java.lang.RuntimeException
- if the constraint was not valid.
-
parseAxisConstraint
private static AC parseAxisConstraint(java.lang.String s, boolean isCols)
Parses the column or rows constraints. They normally looks something like"[min:pref]rel[10px][]"
.- Parameters:
s
- The string to parse. Notnull
.isCols
- If this for columns rather than rows.- Returns:
- An array of
DimConstraint
s that is as many are there exist "[...]" sections in the string that is parsed. - Throws:
java.lang.RuntimeException
- if the constraint was not valid.
-
parseDimConstraint
private static DimConstraint parseDimConstraint(java.lang.String s, BoundSize gapBefore, BoundSize gapAfter, boolean isCols)
Parses a single column or row constraint.- Parameters:
s
- The single constraint to parse. May look something like"min:pref,fill,grow"
. Should not benull
and must be lower case and trimmed.gapBefore
- The default gap "before" the column/row constraint. Can be overridden with a"gap"
section withins
.gapAfter
- The default gap "after" the column/row constraint. Can be overridden with a"gap"
section withins
.isCols
- If the constraints are column constraints rather than row constraints.- Returns:
- A single constraint. Never
null
. - Throws:
java.lang.RuntimeException
- if the constraint was not valid.
-
parseComponentConstraints
public static java.util.Map<ComponentWrapper,CC> parseComponentConstraints(java.util.Map<ComponentWrapper,java.lang.String> constrMap)
Parses all component constraints and stores the parsed values in the transient (cache) member variables.- Parameters:
constrMap
- The constraints asString
s. Strings must be lower case and trimmed- Returns:
- The parsed constraints. Never
null
.
-
parseComponentConstraint
public static CC parseComponentConstraint(java.lang.String s)
Parses one component constraint and returns the parsed value.- Parameters:
s
- The string to parse. Must be lower case and trimmed.- Returns:
- The parsed constraint. Never
null
. - Throws:
java.lang.RuntimeException
- if the constraint was not valid.
-
parseInsets
public static UnitValue[] parseInsets(java.lang.String s, boolean acceptPanel)
Parses insets which consists of 1-4UnitValue
s.- Parameters:
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.acceptPanel
- 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:
java.lang.IllegalArgumentException
- if the parsing could not be done.
-
parseGaps
private static BoundSize[] parseGaps(java.lang.String s)
Parses gaps.- Parameters:
s
- The string that contains gap information. Should start with "gap".- Returns:
- The gaps as specified in
s
. Indexed:[top,left,bottom,right][min,pref,max]
or [before,after][min,pref,max] ifoneDim
is true.
-
parseSpan
private static int parseSpan(java.lang.String s)
-
parseFloat
private static java.lang.Float parseFloat(java.lang.String s, java.lang.Float nullVal)
-
parseBoundSize
public static BoundSize parseBoundSize(java.lang.String s, boolean isGap, boolean isHor)
Parses a single "min:pref:max" value. May look something like"10px:20lp:30%"
or"pref!"
.- Parameters:
s
- The string to parse. Notnull
.isGap
- If this bound size is a gap (different empty string handling).isHor
- If the size is for the horizontal dimension.- Returns:
- A bound size that may be
null
if the string was "null", "n" ornull
.
-
parseUnitValueOrAlign
public static UnitValue parseUnitValueOrAlign(java.lang.String s, boolean isHor, UnitValue emptyReplacement)
Parses a single unit value that may also be an alignment as parsed byparseAlignKeywords(String, boolean)
.- Parameters:
s
- The string to parse. Notnull
. May look something like"10px"
or"5dlu"
.isHor
- If the value is for the horizontal dimension.emptyReplacement
- A replacement ifs
is empty. May benull
.- Returns:
- The parsed unit value. May be
null
.
-
parseUnitValue
public static UnitValue parseUnitValue(java.lang.String s, boolean isHor)
Parses a single unit value. E.g. "10px" or "5in"- Parameters:
s
- The string to parse. Notnull
. May look something like"10px"
or"5dlu"
.isHor
- If the value is for the horizontal dimension.- Returns:
- The parsed unit value.
null
is empty string,
-
parseUnitValue
private static UnitValue parseUnitValue(java.lang.String s, UnitValue emptyReplacement, boolean isHor)
Parses a single unit value.- Parameters:
s
- The string to parse. May benull
. May look something like"10px"
or"5dlu"
.emptyReplacement
- A replacements
is empty ornull
. May benull
.isHor
- If the value is for the horizontal dimension.- Returns:
- The parsed unit value. May be
null
.
-
parseAlignKeywords
static UnitValue parseAlignKeywords(java.lang.String s, boolean isHor)
Parses alignment keywords and returns the appropriateUnitValue
.- Parameters:
s
- The string to parse. Notnull
.isHor
- If alignments for horizontal is checked.false
means vertical.- Returns:
- The unit value or
null
if not recognized (no exception).
-
getNumTextParts
private static java.lang.String[] getNumTextParts(java.lang.String s)
Splits a text-number combination such as "hello 10.0" into{"hello", "10.0"}
.- Parameters:
s
- The string to split. Notnull
. Needs be be reasonably formatted since the method only finds the first 0-9 or . and cuts the string in half there.- Returns:
- Always length 2 and no
null
elements. Elements are "" if no part found.
-
getOper
private static int getOper(java.lang.String s)
Returns the operation depending on the start character.- Parameters:
s
- The string to check. Notnull
.- Returns:
- E.g. UnitValue.ADD, UnitValue.SUB or UnitValue.STATIC. Returns negative value for in-line operations.
-
startsWithLenient
private static int startsWithLenient(java.lang.String s, java.lang.String[] matches, int[] minChars, boolean acceptTrailing)
Returns if a string shares at least a specified numbers starting characters with a number of matches.This method just exercise
startsWithLenient(String, String, int, boolean)
with every one ofmatches
andminChars
.- Parameters:
s
- The string to check. Notnull
.matches
- A number of possible starts fors
.minChars
- The minimum number of characters to match for every element inmatches
. Needs to be of same length asmatches
. Can benull
.acceptTrailing
- If after the required number of characters are matched on recognized characters that are not in one of the thematches
string should be accepted. For instance if "abczz" should be matched with "abcdef" and min chars 3.- Returns:
- The index of the first unmatched character if
minChars
was reached or-1
if a match was not found.
-
startsWithLenient
private static int startsWithLenient(java.lang.String s, java.lang.String match, int minChars, boolean acceptTrailing)
Returns if a string shares at least a specified numbers starting characters with a match.- Parameters:
s
- The string to check. Notnull
and must be trimmed.match
- The possible start fors
. Notnull
and must be trimmed.minChars
- The mimimum number of characters to match tos
for it this to be considered a match. -1 means the full length ofmatch
.acceptTrailing
- If after the required number of charecters are matched unrecognized characters that are not in one of the thematches
string should be accepted. For instance if "abczz" should be matched with "abcdef" and min chars 3.- Returns:
- The index of the first unmatched character if
minChars
was reached or-1
if a match was not found.
-
toTrimmedTokens
private static java.lang.String[] toTrimmedTokens(java.lang.String s, char sep)
Parses a string and returns it in those parts of the string that are separated with asep
character.separator characters within parentheses will not be counted or handled in any way, whatever the depth.
A space separator will be a hit to one or more spaces and thus not return empty strings.
- Parameters:
s
- The string to parse. If it starts and/or ends with asep
the first and/or last element returned will be "". If twosep
are next to each other and empty element will be "between" the periods. Thesep
themselves will never be returned.sep
- The separator char.- Returns:
- Those parts of the string that are separated with
sep
. Never null and at least of size 1 - Since:
- 6.7.2 Changed so more than one space in a row works as one space.
-
getRowColAndGapsTrimmed
private static java.util.ArrayList<java.lang.String> getRowColAndGapsTrimmed(java.lang.String s)
Parses "AAA[BBB]CCC[DDD]EEE" into {"AAA", "BBB", "CCC", "DDD", "EEE", "FFF"}. Handles empty parts. Will always start and end outside a [] block so that the number of returned elemets will always be uneven and at least of length 3."|" is interpreted as "][".
- Parameters:
s
- The string. Might be "" but not null. Should be trimmed.- Returns:
- The string divided into elements. Never
null
and at least of length 3. - Throws:
java.lang.IllegalArgumentException
- If a [] mismatch of some kind. (If not same [ as ] count or if the interleave.)
-
prepare
public static java.lang.String prepare(java.lang.String s)
Makesnull
"", trims and converts to lower case.- Parameters:
s
- The string- Returns:
- Not null.
-
-