Class TextGrid
- java.lang.Object
-
- org.stathissideris.ascii2image.text.TextGrid
-
- Direct Known Subclasses:
GridPattern
public class TextGrid extends java.lang.Object
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description classTextGrid.CellclassTextGrid.CellColorPairclassTextGrid.CellStringPairclassTextGrid.CellTagPair
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description booleanadd(TextGrid grid)Adds grid to this.voidaddToMarkupTags(java.util.Collection<java.lang.String> tags)booleancellContainsDashedLineChar(TextGrid.Cell cell)voidclear()booleancontainsAtLeastOneDashedLine(CellSet set)voidcopyCellsTo(CellSet cells, TextGrid grid)booleanequals(TextGrid grid)booleanexactlyOneNeighbourIsBoundary(TextGrid.Cell cell)voidfillCellsWith(java.lang.Iterable cells, char c)Fills all the cells incellswithcCellSetfillContinuousArea(int x, int y, char c)CellSetfillContinuousArea(TextGrid.Cell cell, char c)java.util.ArrayListfindArrowheads()CellSetfindBoundariesExpandingFrom(TextGrid.Cell seed)Locates and returns the '*' boundaries that we would encounter if we did a flood-fill atseed.java.util.ArrayList<TextGrid.CellColorPair>findColorCodes()java.util.ArrayList<TextGrid.CellTagPair>findMarkupTags()java.util.ArrayList<TextGrid.CellStringPair>findStrings()Returns an ArrayList of CellStringPairs that represents all the continuous (non-blank) Strings in the grid.CellSetfollowCell(TextGrid.Cell cell)CellSetfollowCell(TextGrid.Cell cell, TextGrid.Cell blocked)CellSetfollowCorner(TextGrid.Cell cell)CellSetfollowCorner(TextGrid.Cell cell, TextGrid.Cell blocked)CellSetfollowCorner1(TextGrid.Cell cell)CellSetfollowCorner1(TextGrid.Cell cell, TextGrid.Cell blocked)CellSetfollowCorner2(TextGrid.Cell cell)CellSetfollowCorner2(TextGrid.Cell cell, TextGrid.Cell blocked)CellSetfollowCorner3(TextGrid.Cell cell)CellSetfollowCorner3(TextGrid.Cell cell, TextGrid.Cell blocked)CellSetfollowCorner4(TextGrid.Cell cell)CellSetfollowCorner4(TextGrid.Cell cell, TextGrid.Cell blocked)CellSetfollowCrossOnLine(TextGrid.Cell cell, TextGrid.Cell blocked)CellSetfollowIntersection(TextGrid.Cell cell)CellSetfollowIntersection(TextGrid.Cell cell, TextGrid.Cell blocked)CellSetfollowLine(int x, int y)CellSetfollowLine(TextGrid.Cell cell)Returns the neighbours of a line-cell that are boundaries (0 to 2 cells are returned)CellSetfollowLine(TextGrid.Cell cell, TextGrid.Cell blocked)CellSetfollowStub(TextGrid.Cell cell)CellSetfollowStub(TextGrid.Cell cell, TextGrid.Cell blocked)charget(int x, int y)charget(TextGrid.Cell cell)CellSetgetAllBlanksBetweenCharacters()CellSetgetAllBoundaries()CellSetgetAllNonBlank()java.lang.StringgetCellTypeAsString(TextGrid.Cell cell)java.lang.StringgetDebugString()chargetEastOf(int x, int y)chargetEastOf(TextGrid.Cell cell)intgetHeight()chargetNorthOf(int x, int y)chargetNorthOf(TextGrid.Cell cell)CellSetgetPointMarkersOnLine()java.lang.StringBuffergetRow(int y)protected java.util.ArrayList<java.lang.StringBuffer>getRows()chargetSouthOf(int x, int y)chargetSouthOf(TextGrid.Cell cell)java.lang.StringgetStringAt(int x, int y, int length)java.lang.StringgetStringAt(TextGrid.Cell cell, int length)TextGridgetSubGrid(int x, int y, int width, int height)TextGridgetTestingSubGrid(TextGrid.Cell cell)chargetWestOf(int x, int y)chargetWestOf(TextGrid.Cell cell)intgetWidth()booleanhasBlankCells()booleanhasEntryPoint(TextGrid.Cell cell, int entryPointId)This is done in a bit of a messy way, should be impossible to go out of sync with corresponding GridPatternGroup.booleaninitialiseWithLines(java.util.ArrayList<java.lang.StringBuffer> lines, ProcessingOptions options)booleaninitialiseWithText(java.lang.String text, ProcessingOptions options)booleanisArrowhead(TextGrid.Cell cell)booleanisBlank(int x, int y)booleanisBlank(TextGrid.Cell cell)booleanisBlankBetweenCharacters(TextGrid.Cell cell)true if cell is blank and the east and west cells are not (used to find gaps between words)static booleanisBoundary(char c)booleanisBoundary(int x, int y)booleanisBoundary(TextGrid.Cell cell)booleanisBullet(int x, int y)booleanisBullet(TextGrid.Cell cell)booleanisColumnBlank(int x)booleanisCorner(int x, int y)booleanisCorner(TextGrid.Cell cell)booleanisCorner1(TextGrid.Cell cell)booleanisCorner2(TextGrid.Cell cell)booleanisCorner3(TextGrid.Cell cell)booleanisCorner4(TextGrid.Cell cell)booleanisCross(TextGrid.Cell cell)booleanisCrossOnLine(TextGrid.Cell cell)booleanisEastArrowhead(TextGrid.Cell cell)booleanisHorizontalCrossOnLine(TextGrid.Cell cell)static booleanisHorizontalLine(char c)booleanisHorizontalLine(int x, int y)booleanisHorizontalLine(TextGrid.Cell cell)booleanisHorizontalLinesEnd(TextGrid.Cell cell)booleanisHorizontalStarOnLine(TextGrid.Cell cell)booleanisIntersection(int x, int y)booleanisIntersection(TextGrid.Cell cell)booleanisInverseK(TextGrid.Cell cell)booleanisInverseT(TextGrid.Cell cell)booleanisK(TextGrid.Cell cell)booleanisLine(TextGrid.Cell cell)booleanisLinesEnd(int x, int y)booleanisLinesEnd(TextGrid.Cell cell)Stubs are also considered end of linesbooleanisLoneDiagonal(TextGrid.Cell cell)booleanisNormalCorner(int x, int y)booleanisNormalCorner(TextGrid.Cell cell)booleanisNorthArrowhead(TextGrid.Cell cell)booleanisOnHorizontalLine(TextGrid.Cell cell)booleanisOnVerticalLine(TextGrid.Cell cell)booleanisOutOfBounds(int x, int y)booleanisOutOfBounds(TextGrid.Cell cell)booleanisPointCell(TextGrid.Cell cell)booleanisRoundCorner(int x, int y)booleanisRoundCorner(TextGrid.Cell cell)booleanisSouthArrowhead(TextGrid.Cell cell)booleanisStarOnLine(TextGrid.Cell cell)booleanisStringsEnd(TextGrid.Cell cell)true if the cell is not blank but the next (east) isbooleanisStringsStart(TextGrid.Cell cell)true if the cell is not blank but the previous (west) isbooleanisStub(TextGrid.Cell cell)A stub looks like that:booleanisT(TextGrid.Cell cell)booleanisVerticalCrossOnLine(TextGrid.Cell cell)static booleanisVerticalLine(char c)booleanisVerticalLine(int x, int y)booleanisVerticalLine(TextGrid.Cell cell)booleanisVerticalLinesEnd(TextGrid.Cell cell)booleanisVerticalStarOnLine(TextGrid.Cell cell)booleanisWestArrowhead(TextGrid.Cell cell)static TextGridmakeSameSizeAs(TextGrid grid)booleanmatches(GridPattern criteria)booleanmatchesAll(GridPatternGroup criteria)booleanmatchesAny(GridPatternGroup criteria)booleanmatchesAny(TextGrid.Cell cell, GridPatternGroup criteria)intotherStringsEndInTheSameColumn(TextGrid.Cell cell)intotherStringsStartInTheSameColumn(TextGrid.Cell cell)voidprintDebug()voidremoveArrowheads()voidremoveBoundaries()voidremoveColorCodes()voidremoveMarkupTags()voidremoveNonText()Makes blank all the cells that contain non-text elements.voidreplaceAll(char c1, char c2)Replace all occurences of c1 with c2voidreplaceBullets()voidreplaceHumanColorCodes()voidreplacePointMarkersOnLine()voidreplaceTypeOnLine()Replaces letters or numbers that are on horizontal or vertical lines, with the appropriate character that will make the line continuous (| for vertical and - for horizontal lines)voidset(int x, int y, char c)voidset(TextGrid.Cell cell, char c)voidsetRow(int y, java.lang.String row)voidsetRow(int y, java.lang.StringBuffer row)java.lang.StringtoString()voidwriteStringTo(int x, int y, java.lang.String str)voidwriteStringTo(TextGrid.Cell cell, java.lang.String str)
-
-
-
Constructor Detail
-
TextGrid
public TextGrid()
-
TextGrid
public TextGrid(int width, int height)
-
TextGrid
public TextGrid(TextGrid otherGrid)
-
-
Method Detail
-
addToMarkupTags
public void addToMarkupTags(java.util.Collection<java.lang.String> tags)
-
clear
public void clear()
-
get
public char get(int x, int y)
-
get
public char get(TextGrid.Cell cell)
-
getRow
public java.lang.StringBuffer getRow(int y)
-
getSubGrid
public TextGrid getSubGrid(int x, int y, int width, int height)
-
getTestingSubGrid
public TextGrid getTestingSubGrid(TextGrid.Cell cell)
-
getStringAt
public java.lang.String getStringAt(int x, int y, int length)
-
getStringAt
public java.lang.String getStringAt(TextGrid.Cell cell, int length)
-
getNorthOf
public char getNorthOf(int x, int y)
-
getSouthOf
public char getSouthOf(int x, int y)
-
getEastOf
public char getEastOf(int x, int y)
-
getWestOf
public char getWestOf(int x, int y)
-
getNorthOf
public char getNorthOf(TextGrid.Cell cell)
-
getSouthOf
public char getSouthOf(TextGrid.Cell cell)
-
getEastOf
public char getEastOf(TextGrid.Cell cell)
-
getWestOf
public char getWestOf(TextGrid.Cell cell)
-
writeStringTo
public void writeStringTo(int x, int y, java.lang.String str)
-
writeStringTo
public void writeStringTo(TextGrid.Cell cell, java.lang.String str)
-
set
public void set(TextGrid.Cell cell, char c)
-
set
public void set(int x, int y, char c)
-
setRow
public void setRow(int y, java.lang.String row)
-
setRow
public void setRow(int y, java.lang.StringBuffer row)
-
getWidth
public int getWidth()
-
getHeight
public int getHeight()
-
printDebug
public void printDebug()
-
getDebugString
public java.lang.String getDebugString()
-
toString
public java.lang.String toString()
- Overrides:
toStringin classjava.lang.Object
-
add
public boolean add(TextGrid grid)
Adds grid to this. Space characters in this grid are replaced with the corresponding contents of grid, otherwise the contents are unchanged.- Parameters:
grid-- Returns:
- false if the grids are of different size
-
replaceTypeOnLine
public void replaceTypeOnLine()
Replaces letters or numbers that are on horizontal or vertical lines, with the appropriate character that will make the line continuous (| for vertical and - for horizontal lines)
-
replacePointMarkersOnLine
public void replacePointMarkersOnLine()
-
getPointMarkersOnLine
public CellSet getPointMarkersOnLine()
-
replaceHumanColorCodes
public void replaceHumanColorCodes()
-
replaceAll
public void replaceAll(char c1, char c2)Replace all occurences of c1 with c2- Parameters:
c1-c2-
-
hasBlankCells
public boolean hasBlankCells()
-
getAllNonBlank
public CellSet getAllNonBlank()
-
getAllBoundaries
public CellSet getAllBoundaries()
-
getAllBlanksBetweenCharacters
public CellSet getAllBlanksBetweenCharacters()
-
findStrings
public java.util.ArrayList<TextGrid.CellStringPair> findStrings()
Returns an ArrayList of CellStringPairs that represents all the continuous (non-blank) Strings in the grid. Used on buffers that contain only type, in order to find the positions and the contents of the strings.- Returns:
-
hasEntryPoint
public boolean hasEntryPoint(TextGrid.Cell cell, int entryPointId)
This is done in a bit of a messy way, should be impossible to go out of sync with corresponding GridPatternGroup.- Parameters:
cell-entryPointId-- Returns:
-
isBlankBetweenCharacters
public boolean isBlankBetweenCharacters(TextGrid.Cell cell)
true if cell is blank and the east and west cells are not (used to find gaps between words)- Parameters:
cell-- Returns:
-
removeNonText
public void removeNonText()
Makes blank all the cells that contain non-text elements.
-
removeArrowheads
public void removeArrowheads()
-
removeColorCodes
public void removeColorCodes()
-
removeBoundaries
public void removeBoundaries()
-
findArrowheads
public java.util.ArrayList findArrowheads()
-
findColorCodes
public java.util.ArrayList<TextGrid.CellColorPair> findColorCodes()
-
findMarkupTags
public java.util.ArrayList<TextGrid.CellTagPair> findMarkupTags()
-
removeMarkupTags
public void removeMarkupTags()
-
matchesAny
public boolean matchesAny(GridPatternGroup criteria)
-
matchesAll
public boolean matchesAll(GridPatternGroup criteria)
-
matches
public boolean matches(GridPattern criteria)
-
isOnHorizontalLine
public boolean isOnHorizontalLine(TextGrid.Cell cell)
-
isOnVerticalLine
public boolean isOnVerticalLine(TextGrid.Cell cell)
-
isBoundary
public static boolean isBoundary(char c)
-
isBoundary
public boolean isBoundary(int x, int y)
-
isBoundary
public boolean isBoundary(TextGrid.Cell cell)
-
isLine
public boolean isLine(TextGrid.Cell cell)
-
isHorizontalLine
public static boolean isHorizontalLine(char c)
-
isHorizontalLine
public boolean isHorizontalLine(TextGrid.Cell cell)
-
isHorizontalLine
public boolean isHorizontalLine(int x, int y)
-
isVerticalLine
public static boolean isVerticalLine(char c)
-
isVerticalLine
public boolean isVerticalLine(TextGrid.Cell cell)
-
isVerticalLine
public boolean isVerticalLine(int x, int y)
-
isLinesEnd
public boolean isLinesEnd(int x, int y)
-
isLinesEnd
public boolean isLinesEnd(TextGrid.Cell cell)
Stubs are also considered end of lines- Parameters:
cell-- Returns:
-
isVerticalLinesEnd
public boolean isVerticalLinesEnd(TextGrid.Cell cell)
-
isHorizontalLinesEnd
public boolean isHorizontalLinesEnd(TextGrid.Cell cell)
-
isPointCell
public boolean isPointCell(TextGrid.Cell cell)
-
containsAtLeastOneDashedLine
public boolean containsAtLeastOneDashedLine(CellSet set)
-
exactlyOneNeighbourIsBoundary
public boolean exactlyOneNeighbourIsBoundary(TextGrid.Cell cell)
-
isStub
public boolean isStub(TextGrid.Cell cell)
A stub looks like that:+- or -+ or + or + or /- or -/ or / (you get the point) | | |- Parameters:
cell-- Returns:
-
isCrossOnLine
public boolean isCrossOnLine(TextGrid.Cell cell)
-
isHorizontalCrossOnLine
public boolean isHorizontalCrossOnLine(TextGrid.Cell cell)
-
isVerticalCrossOnLine
public boolean isVerticalCrossOnLine(TextGrid.Cell cell)
-
isStarOnLine
public boolean isStarOnLine(TextGrid.Cell cell)
-
isLoneDiagonal
public boolean isLoneDiagonal(TextGrid.Cell cell)
-
isHorizontalStarOnLine
public boolean isHorizontalStarOnLine(TextGrid.Cell cell)
-
isVerticalStarOnLine
public boolean isVerticalStarOnLine(TextGrid.Cell cell)
-
isArrowhead
public boolean isArrowhead(TextGrid.Cell cell)
-
isNorthArrowhead
public boolean isNorthArrowhead(TextGrid.Cell cell)
-
isEastArrowhead
public boolean isEastArrowhead(TextGrid.Cell cell)
-
isWestArrowhead
public boolean isWestArrowhead(TextGrid.Cell cell)
-
isSouthArrowhead
public boolean isSouthArrowhead(TextGrid.Cell cell)
-
isBullet
public boolean isBullet(int x, int y)
-
isBullet
public boolean isBullet(TextGrid.Cell cell)
-
replaceBullets
public void replaceBullets()
-
isStringsStart
public boolean isStringsStart(TextGrid.Cell cell)
true if the cell is not blank but the previous (west) is- Parameters:
cell-- Returns:
-
isStringsEnd
public boolean isStringsEnd(TextGrid.Cell cell)
true if the cell is not blank but the next (east) is- Parameters:
cell-- Returns:
-
otherStringsStartInTheSameColumn
public int otherStringsStartInTheSameColumn(TextGrid.Cell cell)
-
otherStringsEndInTheSameColumn
public int otherStringsEndInTheSameColumn(TextGrid.Cell cell)
-
isColumnBlank
public boolean isColumnBlank(int x)
-
followLine
public CellSet followLine(int x, int y)
-
followIntersection
public CellSet followIntersection(TextGrid.Cell cell)
-
followIntersection
public CellSet followIntersection(TextGrid.Cell cell, TextGrid.Cell blocked)
-
followLine
public CellSet followLine(TextGrid.Cell cell)
Returns the neighbours of a line-cell that are boundaries (0 to 2 cells are returned)- Parameters:
cell-- Returns:
- null if the cell is not a line
-
followLine
public CellSet followLine(TextGrid.Cell cell, TextGrid.Cell blocked)
-
followCorner
public CellSet followCorner(TextGrid.Cell cell)
-
followCorner
public CellSet followCorner(TextGrid.Cell cell, TextGrid.Cell blocked)
-
followCorner1
public CellSet followCorner1(TextGrid.Cell cell)
-
followCorner1
public CellSet followCorner1(TextGrid.Cell cell, TextGrid.Cell blocked)
-
followCorner2
public CellSet followCorner2(TextGrid.Cell cell)
-
followCorner2
public CellSet followCorner2(TextGrid.Cell cell, TextGrid.Cell blocked)
-
followCorner3
public CellSet followCorner3(TextGrid.Cell cell)
-
followCorner3
public CellSet followCorner3(TextGrid.Cell cell, TextGrid.Cell blocked)
-
followCorner4
public CellSet followCorner4(TextGrid.Cell cell)
-
followCorner4
public CellSet followCorner4(TextGrid.Cell cell, TextGrid.Cell blocked)
-
followStub
public CellSet followStub(TextGrid.Cell cell)
-
followStub
public CellSet followStub(TextGrid.Cell cell, TextGrid.Cell blocked)
-
followCell
public CellSet followCell(TextGrid.Cell cell)
-
followCell
public CellSet followCell(TextGrid.Cell cell, TextGrid.Cell blocked)
-
getCellTypeAsString
public java.lang.String getCellTypeAsString(TextGrid.Cell cell)
-
followCrossOnLine
public CellSet followCrossOnLine(TextGrid.Cell cell, TextGrid.Cell blocked)
-
isOutOfBounds
public boolean isOutOfBounds(TextGrid.Cell cell)
-
isOutOfBounds
public boolean isOutOfBounds(int x, int y)
-
isBlank
public boolean isBlank(TextGrid.Cell cell)
-
isBlank
public boolean isBlank(int x, int y)
-
isCorner
public boolean isCorner(TextGrid.Cell cell)
-
isCorner
public boolean isCorner(int x, int y)
-
matchesAny
public boolean matchesAny(TextGrid.Cell cell, GridPatternGroup criteria)
-
isCorner1
public boolean isCorner1(TextGrid.Cell cell)
-
isCorner2
public boolean isCorner2(TextGrid.Cell cell)
-
isCorner3
public boolean isCorner3(TextGrid.Cell cell)
-
isCorner4
public boolean isCorner4(TextGrid.Cell cell)
-
isCross
public boolean isCross(TextGrid.Cell cell)
-
isK
public boolean isK(TextGrid.Cell cell)
-
isInverseK
public boolean isInverseK(TextGrid.Cell cell)
-
isT
public boolean isT(TextGrid.Cell cell)
-
isInverseT
public boolean isInverseT(TextGrid.Cell cell)
-
isNormalCorner
public boolean isNormalCorner(TextGrid.Cell cell)
-
isNormalCorner
public boolean isNormalCorner(int x, int y)
-
isRoundCorner
public boolean isRoundCorner(TextGrid.Cell cell)
-
isRoundCorner
public boolean isRoundCorner(int x, int y)
-
isIntersection
public boolean isIntersection(TextGrid.Cell cell)
-
isIntersection
public boolean isIntersection(int x, int y)
-
equals
public boolean equals(TextGrid grid)
-
fillCellsWith
public void fillCellsWith(java.lang.Iterable cells, char c)Fills all the cells incellswithc- Parameters:
cells-c-
-
fillContinuousArea
public CellSet fillContinuousArea(int x, int y, char c)
-
fillContinuousArea
public CellSet fillContinuousArea(TextGrid.Cell cell, char c)
-
findBoundariesExpandingFrom
public CellSet findBoundariesExpandingFrom(TextGrid.Cell seed)
Locates and returns the '*' boundaries that we would encounter if we did a flood-fill atseed.- Parameters:
seed-- Returns:
-
cellContainsDashedLineChar
public boolean cellContainsDashedLineChar(TextGrid.Cell cell)
-
initialiseWithText
public boolean initialiseWithText(java.lang.String text, ProcessingOptions options) throws java.io.UnsupportedEncodingException- Throws:
java.io.UnsupportedEncodingException
-
initialiseWithLines
public boolean initialiseWithLines(java.util.ArrayList<java.lang.StringBuffer> lines, ProcessingOptions options) throws java.io.UnsupportedEncodingException- Throws:
java.io.UnsupportedEncodingException
-
getRows
protected java.util.ArrayList<java.lang.StringBuffer> getRows()
- Returns:
-
-