java.lang.Object
net.miginfocom.layout.ConstraintParser
Parses string constraints.
-
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptionprivate static String[]Splits a text-number combination such as "hello 10.0" into{"hello", "10.0"}.private static intReturns the operation depending on the start character.Parses "AAA[BBB]CCC[DDD]EEE" into {"AAA", "BBB", "CCC", "DDD", "EEE", "FFF"}.(package private) static UnitValueparseAlignKeywords(String s, boolean isHor) Parses alignment keywords and returns the appropriateUnitValue.private static ACparseAxisConstraint(String s, boolean isCols) Parses the column or rows constraints.static BoundSizeparseBoundSize(String s, boolean isGap, boolean isHor) Parses a single "min:pref:max" value.static ACParses the column or rows constraints.static CCParses one component constraint and returns the parsed value.static Map<ComponentWrapper, CC> parseComponentConstraints(Map<ComponentWrapper, String> constrMap) Parses all component constraints and stores the parsed values in the transient (cache) member variables.private static DimConstraintparseDimConstraint(String s, BoundSize gapBefore, BoundSize gapAfter, boolean isCols) Parses a single column or row constraint.private static FloatparseFloat(String s, Float nullVal) private static BoundSize[]Parses gaps.static UnitValue[]parseInsets(String s, boolean acceptPanel) Parses insets which consists of 1-4UnitValues.static LCParses the layout constraints and stores the parsed values in the transient (cache) member variables.static ACParses the column or rows constraints.private static intstatic UnitValueparseUnitValue(String s, boolean isHor) Parses a single unit value.private static UnitValueparseUnitValue(String s, UnitValue emptyReplacement, boolean isHor) Parses a single unit value.static UnitValueparseUnitValueOrAlign(String s, boolean isHor, UnitValue emptyReplacement) Parses a single unit value that may also be an alignment as parsed byparseAlignKeywords(String, boolean).static StringMakesnull"", trims and converts to lower case.private static intstartsWithLenient(String s, 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 intstartsWithLenient(String s, String match, int minChars, boolean acceptTrailing) Returns if a string shares at least a specified numbers starting characters with a match.private static String[]toTrimmedTokens(String s, char sep) Parses a string and returns it in those parts of the string that are separated with asepcharacter.
-
Constructor Details
-
ConstraintParser
private ConstraintParser()
-
-
Method Details
-
parseLayoutConstraint
Parses the layout constraints and stores the parsed values in the transient (cache) member variables.- Parameters:
s- The String to parse. Should not benulland must be lower case and trimmed.- Returns:
- The parsed constraint. Never
null. - Throws:
RuntimeException- if the constraint was not valid.
-
parseRowConstraints
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
DimConstraints that is as many are there exist "[...]" sections in the string that is parsed. - Throws:
RuntimeException- if the constraint was not valid.
-
parseColumnConstraints
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
DimConstraints that is as many are there exist "[...]" sections in the string that is parsed. - Throws:
RuntimeException- if the constraint was not valid.
-
parseAxisConstraint
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
DimConstraints that is as many are there exist "[...]" sections in the string that is parsed. - Throws:
RuntimeException- if the constraint was not valid.
-
parseDimConstraint
private static DimConstraint parseDimConstraint(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 benulland 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:
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- The constraints asStrings. Strings must be lower case and trimmed- Returns:
- The parsed constraints. Never
null.
-
parseComponentConstraint
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:
RuntimeException- if the constraint was not valid.
-
parseInsets
Parses insets which consists of 1-4UnitValues.- 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:
IllegalArgumentException- if the parsing could not be done.
-
parseGaps
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] ifoneDimis true.
-
parseSpan
-
parseFloat
-
parseBoundSize
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
nullif the string was "null", "n" ornull.
-
parseUnitValueOrAlign
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 ifsis empty. May benull.- Returns:
- The parsed unit value. May be
null.
-
parseUnitValue
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.
nullis empty string,
-
parseUnitValue
Parses a single unit value.- Parameters:
s- The string to parse. May benull. May look something like"10px"or"5dlu".emptyReplacement- A replacementsis empty ornull. May benull.isHor- If the value is for the horizontal dimension.- Returns:
- The parsed unit value. May be
null.
-
parseAlignKeywords
Parses alignment keywords and returns the appropriateUnitValue.- Parameters:
s- The string to parse. Notnull.isHor- If alignments for horizontal is checked.falsemeans vertical.- Returns:
- The unit value or
nullif not recognized (no exception).
-
getNumTextParts
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
nullelements. Elements are "" if no part found.
-
getOper
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(String s, 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 ofmatchesandminChars.- 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 thematchesstring 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
minCharswas reached or-1if a match was not found.
-
startsWithLenient
Returns if a string shares at least a specified numbers starting characters with a match.- Parameters:
s- The string to check. Notnulland must be trimmed.match- The possible start fors. Notnulland must be trimmed.minChars- The mimimum number of characters to match tosfor 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 thematchesstring 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
minCharswas reached or-1if a match was not found.
-
toTrimmedTokens
Parses a string and returns it in those parts of the string that are separated with asepcharacter.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 asepthe first and/or last element returned will be "". If twosepare next to each other and empty element will be "between" the periods. Thesepthemselves 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
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
nulland at least of length 3. - Throws:
IllegalArgumentException- If a [] mismatch of some kind. (If not same [ as ] count or if the interleave.)
-
prepare
Makesnull"", trims and converts to lower case.- Parameters:
s- The string- Returns:
- Not null.
-