Package org.hkmi2.aagbl
Class LayoutParser
- java.lang.Object
-
- org.hkmi2.aagbl.LayoutParser
-
public class LayoutParser extends java.lang.ObjectThe parser that analyzes the Ascii art drawing. Typically used internally byAsciiArtGridBagLayout, no need to use it directly.
Example of a drawing :
See the documentation (String aa = "+--------------------------------------------+\n"+ "| |\n"+ "| L |\n"+ "| |\n"+ "+--------------+--------------+--------------+\n"+ "| | | |\n"+ "| S1 |< B >| S2 |\n"+ "| | | |\n"+ "+--------------+--------------+--------------+\n";layout-definition.md) for more explanations of the conventions used in the drawings. Note that if you don't give a name to a rectangle, it will be automatically set to "_space" followed by a sequential number, and will later contain aJLabelwith aStringof just a space " ". This is necessary to get a correct dispatch of the layout's geometry.
-
-
Field Summary
Fields Modifier and Type Field Description static booleandebugParserset to true to emit messages on System.out while parsingstatic intFILL_HORIZvalue that corresponds to the presence of horizontal filling chars ('<', '>')static intFILL_VERTvalue that corresponds to the presence of a vertical filling char ('^')
-
Constructor Summary
Constructors Constructor Description LayoutParser()Default constructor
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description intevalFlags(java.lang.String spec)Process the flags : if '^' is encountered, add FILL_VERT, if '<' or '>' is encountered, add FILL_HORIZ.CRectfindCRect(int px, int py)find a CRect whose last line is just above px and pyjava.util.ArrayList<CRect>getCRects()Return the CRectsbooleanisNameChar(char c)Is c compatible with a namebooleanisNameStart(char c)Is c compatible with the start of a namebooleanisNameValid(java.lang.String str)Is the name a valid name for a rectanglechar[]normalize(java.lang.String line)Normalize format string : - Trim the line - Replace all '-' and '|' with '+'voidparseSpec(java.util.List<char[]> la)Parse Ascii Art specificationjava.util.ArrayList<char[]>readSpec(java.io.BufferedReader specInput)Step one : read all lines, ignoring the empty ones, and trimming the others.java.lang.StringremoveFlags(java.lang.String spec)Remove the flags from the spec line.
-
-
-
Field Detail
-
FILL_HORIZ
public static final int FILL_HORIZ
value that corresponds to the presence of horizontal filling chars ('<', '>')- See Also:
- Constant Field Values
-
FILL_VERT
public static final int FILL_VERT
value that corresponds to the presence of a vertical filling char ('^')- See Also:
- Constant Field Values
-
debugParser
public static boolean debugParser
set to true to emit messages on System.out while parsing
-
-
Method Detail
-
getCRects
public java.util.ArrayList<CRect> getCRects()
Return the CRects- Returns:
- The list of CRects
-
normalize
public char[] normalize(java.lang.String line)
Normalize format string : - Trim the line - Replace all '-' and '|' with '+'- Parameters:
line- The line that must be normalized- Returns:
- The normalized line as an array of chars
-
readSpec
public java.util.ArrayList<char[]> readSpec(java.io.BufferedReader specInput) throws LayoutParseExceptionStep one : read all lines, ignoring the empty ones, and trimming the others.- Parameters:
specInput- A BufferedReader that will be used to read the specification- Returns:
- A list of char arrays
- Throws:
LayoutParseException- If non-empty lines are not the same length
-
findCRect
public CRect findCRect(int px, int py)
find a CRect whose last line is just above px and py- Parameters:
px- position xpy- position y- Returns:
- the CRect that is just above position or null if none found
-
isNameStart
public boolean isNameStart(char c)
Is c compatible with the start of a name- Parameters:
c- The char to test- Returns:
- true if c is OK for the start of a name
-
isNameChar
public boolean isNameChar(char c)
Is c compatible with a name- Parameters:
c- The char to test- Returns:
- true if c is OK for a name
-
evalFlags
public int evalFlags(java.lang.String spec)
Process the flags : if '^' is encountered, add FILL_VERT, if '<' or '>' is encountered, add FILL_HORIZ.- Parameters:
spec- The spec to process- Returns:
- the evaluated flags (0,
FILL_VERT,FILL_HORIZ,FILL_VERT|FILL_HORIZ)
-
removeFlags
public java.lang.String removeFlags(java.lang.String spec)
Remove the flags from the spec line.- Parameters:
spec- The spec line to process- Returns:
- The spec with the flags '^', '<', '>' replaced with ' '
-
isNameValid
public boolean isNameValid(java.lang.String str)
Is the name a valid name for a rectangle- Parameters:
str- String to test- Returns:
- true if str is a valid name
-
parseSpec
public void parseSpec(java.util.List<char[]> la) throws LayoutParseExceptionParse Ascii Art specification- Parameters:
la- A list of cleaned lines to parse- Throws:
LayoutParseException- If the line does not start/end with a '+' delimiter, if a line is less than 3 chars wide, if a rectangle width changes
-
-