public TextGrid getSubGrid(int x, int y, int width, int height) { TextGrid grid = new TextGrid(width, height); for (int i = 0; i < height; i++) { grid.setRow(i, new StringBuilder(getRow(y + i).subSequence(x, x + width))); } return grid; }
public CellSet followCell(Cell cell, Cell blocked) { if (isIntersection(cell)) return followIntersection(cell, blocked); if (isCorner(cell)) return followCorner(cell, blocked); if (isLine(cell)) return followLine(cell, blocked); if (isStub(cell)) return followStub(cell, blocked); if (isCrossOnLine(cell)) return followCrossOnLine(cell, blocked); System.err.println("Umbiguous input at position " + cell + ":"); TextGrid subGrid = getTestingSubGrid(cell); subGrid.printDebug(); throw new RuntimeException("Cannot follow cell " + cell + ": cannot determine cell type"); }
public boolean equals(TextGrid grid) { if (grid.getHeight() != this.getHeight() || grid.getWidth() != this.getWidth()) { return false; } int height = grid.getHeight(); for (int i = 0; i < height; i++) { String row1 = this.getRow(i).toString(); String row2 = grid.getRow(i).toString(); if (!row1.equals(row2)) return false; } return true; }
public ImageData exportDiagram(OutputStream os, int num, FileFormatOption fileFormat) throws IOException { if (fileFormat.getFileFormat() == FileFormat.ATXT) { os.write(getSource().getPlainString().getBytes()); return new ImageDataSimple(); } // ditaa can only export png so file format is mostly ignored final ConversionOptions options = new ConversionOptions(); options.setDropShadows(dropShadows); final TextGrid grid = new TextGrid(); grid.initialiseWithText(data, null); final Diagram diagram = new Diagram(grid, options, processingOptions); final BufferedImage image = (BufferedImage) new BitmapRenderer().renderToImage(diagram, options.renderingOptions); ImageIO.write(image, "png", os); return new ImageDataSimple(image.getWidth(), image.getHeight()); }
public void copyCellsTo(CellSet cells, TextGrid grid) { for (Cell cell : cells) { grid.set(cell, this.get(cell)); } }
public boolean matchesAny(Cell cell, GridPatternGroup criteria) { TextGrid subGrid = getTestingSubGrid(cell); return subGrid.matchesAny(criteria); }
public TextGrid(TextGrid otherGrid) { rows = new ArrayList<StringBuilder>(); for (StringBuilder row : otherGrid.getRows()) { rows.add(new StringBuilder(row)); } }
public static TextGrid makeSameSizeAs(TextGrid grid) { return new TextGrid(grid.getWidth(), grid.getHeight()); }