public void replacePointMarkersOnLine() { int width = getWidth(); int height = getHeight(); for (int yi = 0; yi < height; yi++) { for (int xi = 0; xi < width; xi++) { char c = get(xi, yi); Cell cell = new Cell(xi, yi); if (StringUtils.isOneOf(c, pointMarkers) && isStarOnLine(cell)) { boolean isOnHorizontalLine = false; if (StringUtils.isOneOf(get(cell.getEast()), horizontalLines)) isOnHorizontalLine = true; if (StringUtils.isOneOf(get(cell.getWest()), horizontalLines)) isOnHorizontalLine = true; boolean isOnVerticalLine = false; if (StringUtils.isOneOf(get(cell.getNorth()), verticalLines)) isOnVerticalLine = true; if (StringUtils.isOneOf(get(cell.getSouth()), verticalLines)) isOnVerticalLine = true; if (isOnHorizontalLine && isOnVerticalLine) { set(xi, yi, '+'); if (DEBUG) System.out.println("replaced marker on line '" + c + "' with +"); } else if (isOnHorizontalLine) { set(xi, yi, '-'); if (DEBUG) System.out.println("replaced marker on line '" + c + "' with -"); } else if (isOnVerticalLine) { set(xi, yi, '|'); if (DEBUG) System.out.println("replaced marker on line '" + c + "' with |"); } } } } }
public boolean isBullet(Cell cell) { char c = get(cell); return (c == 'o' || c == '*') && isBlank(cell.getEast()) && isBlank(cell.getWest()) && Character.isLetterOrDigit(get(cell.getEast().getEast())); }
public CellSet followCorner4(Cell cell, Cell blocked) { if (!isCorner4(cell)) return null; CellSet result = new CellSet(); if (!cell.getNorth().equals(blocked)) result.add(cell.getNorth()); if (!cell.getEast().equals(blocked)) result.add(cell.getEast()); return result; }
private CellSet seedFillOld(Cell seed, char newChar) { CellSet cellsFilled = new CellSet(); char oldChar = get(seed); if (oldChar == newChar) return cellsFilled; if (isOutOfBounds(seed)) return cellsFilled; Stack<Cell> stack = new Stack<Cell>(); stack.push(seed); while (!stack.isEmpty()) { Cell cell = stack.pop(); set(cell, newChar); cellsFilled.add(cell); Cell nCell = cell.getNorth(); Cell sCell = cell.getSouth(); Cell eCell = cell.getEast(); Cell wCell = cell.getWest(); if (get(nCell) == oldChar) stack.push(nCell); if (get(sCell) == oldChar) stack.push(sCell); if (get(eCell) == oldChar) stack.push(eCell); if (get(wCell) == oldChar) stack.push(wCell); } return cellsFilled; }
public void paintComponent(Graphics g) throws RuntimeException { int squarewidth = getSquareWidth(); int squareheight = getSquareHeight(); int hoffset = getHorizontalOffset(); int voffset = getVerticalOffset(); for (int x = 0; x < grid.maxX(); x++) { for (int y = 0; y < grid.maxY(); y++) { Cell tmp = grid.grabObjectAt(x, y); if (tmp == null) { g.setColor(Color.gray.darker()); } else { g.setColor(tmp.getColor()); } g.fillRect( hoffset + x * squarewidth, voffset + ((grid.maxY() - y) * squareheight), squarewidth - 1, squareheight - 1); } } }
/** @return */ public boolean isFilled() { for (Cell<T> c : this) { if (c.isFilled()) { return true; } } return false; }
private ArrayList<Cell> enemyCells() { ArrayList<Cell> enemyCells = new ArrayList<>(); for (Cell c : Frame.getInstance().getBoard().getCells()) { if (c.hasToken()) if (c.getTok().getOwner() != this) { enemyCells.add(c); } } return enemyCells; }
public void build(int numLevels, int cellSize) { if (numLevels == 0) return; if (this.m1 - this.m0 <= cellSize && this.n1 - this.n0 <= cellSize) return; this.children = this.split(this.m0, this.m1, this.n0, this.n1); for (Cell t : this.children) { t.build(numLevels - 1, cellSize); } }
public void computeBounds(Dimension dim, float[] xs, float[] ys) { if (this.children != null) { for (Cell t : this.children) { t.computeBounds(dim, xs, ys); } this.computeExtremesFromChildren(); } else { this.computeExtremesFromLocations(dim, xs, ys); } }
/** Method in JComponent overrided to draw this MazeGrid */ public void paintComponent(Graphics g) { Graphics2D g2 = (Graphics2D) g; // draw each cell in the grid using drawCell() Cell a = new Cell(0, 0); for (; a.row < grid.getRows(); a.row++) { for (; a.col < grid.getCols(); a.col++) { drawCell(g2, a); } a.col = 0; } }
public void removeColorCodes() { for (CellColorPair o : findColorCodes()) { Cell cell = o.cell; set(cell, ' '); cell = cell.getEast(); set(cell, ' '); cell = cell.getEast(); set(cell, ' '); cell = cell.getEast(); set(cell, ' '); } }
public int otherStringsEndInTheSameColumn(Cell cell) { if (!isStringsEnd(cell)) return 0; int result = 0; int height = getHeight(); for (int y = 0; y < height; y++) { Cell cCell = new Cell(cell.x, y); if (!cCell.equals(cell) && isStringsEnd(cCell)) { result++; } } return result; }
public CellSet followCrossOnLine(Cell cell, Cell blocked) { CellSet result = new CellSet(); if (isHorizontalCrossOnLine(cell)) { result.add(cell.getEast()); result.add(cell.getWest()); } else if (isVerticalCrossOnLine(cell)) { result.add(cell.getNorth()); result.add(cell.getSouth()); } if (result.contains(blocked)) result.remove(blocked); return result; }
@Override public String toString() { StringBuilder s = new StringBuilder(); s.append("|IBLOCK|"); s.append(" Direction: " + direction); s.append(" Cells: ["); for (Cell cell : cells) { s.append("(" + cell.getX() + ", " + cell.getY() + ")"); } s.append("]"); return s.toString(); }
public void replaceBullets() { int width = getWidth(); int height = getHeight(); for (int yi = 0; yi < height; yi++) { for (int xi = 0; xi < width; xi++) { Cell cell = new Cell(xi, yi); if (isBullet(cell)) { set(cell, ' '); set(cell.getEast(), '\u2022'); } } } }
public boolean isInterleaveableWith(Row<T> other) { if (other == null || other == this) { return false; } else if (other.getNextRow() != this && other.getPrevRow() != this) { return false; } Iterator<Cell<T>> oIt = other.iterator(); for (Cell<T> c : this) { if (oIt.next().isUnpackable() && c.isUnpackable()) { return false; } } return true; }
public CellSet followIntersection(Cell cell, Cell blocked) { if (!isIntersection(cell)) return null; CellSet result = new CellSet(); Cell cN = cell.getNorth(); Cell cS = cell.getSouth(); Cell cE = cell.getEast(); Cell cW = cell.getWest(); if (hasEntryPoint(cN, 6)) result.add(cN); if (hasEntryPoint(cS, 2)) result.add(cS); if (hasEntryPoint(cE, 8)) result.add(cE); if (hasEntryPoint(cW, 4)) result.add(cW); if (result.contains(blocked)) result.remove(blocked); return result; }
public CellSet followStub(Cell cell, Cell blocked) { if (!isStub(cell)) return null; CellSet result = new CellSet(); if (isBoundary(cell.getEast())) result.add(cell.getEast()); else if (isBoundary(cell.getWest())) result.add(cell.getWest()); else if (isBoundary(cell.getNorth())) result.add(cell.getNorth()); else if (isBoundary(cell.getSouth())) result.add(cell.getSouth()); if (result.contains(blocked)) result.remove(blocked); return result; }
private void processRow(Row row) { int fc = row.getFirstCellNum(); if (fc == 0) { Cell cell = row.getCell(0); if (cell.getCellType() == Cell.CELL_TYPE_STRING) { columnCount = columnCount < row.getLastCellNum() ? row.getLastCellNum() : columnCount; String rowType = cell.getStringCellValue().toUpperCase(); switch (rowType) { case "TITLE": { title.add(row); } break; case "GROUPH": { String fName = getGroupParam(row); if (!fName.isEmpty()) { detail.addGroup(true, row, fName); } } break; case "DETAIL1": { detail.add(row); } break; case "GROUPF": { String fName = getGroupParam(row); if (!fName.isEmpty()) { detail.addGroup(false, row, fName); } } break; case "SUMMARY": { summary.add(row); } break; } } } }
private Cell<T> _insertCellBefore() { Cell<T> newCell = new Cell<T>(parent, prevCell, this); if (prevCell == null) { parent.firstCell = newCell; } else { prevCell.nextCell = newCell; } prevCell = newCell; return newCell; }
private Cell<T> _insertCellAfter() { Cell<T> newCell = new Cell<T>(parent, this, nextCell); if (nextCell == null) { parent.lastCell = newCell; } else { nextCell.prevCell = newCell; } nextCell = newCell; return newCell; }
/** * @param parent * @param prevRow * @param nextRow */ private Row(Grid<T> parent, Row<T> prevRow, Row<T> nextRow) { super(); this.parent = parent; this.prevRow = prevRow; this.nextRow = nextRow; firstCell = new Cell<T>(this, null, null); lastCell = firstCell; for (int i = 1; i < parent.width; i++) { lastCell._insertCellAfter(); } }
/** * Returns the neighbours of a line-cell that are boundaries (0 to 2 cells are returned) * * @return null if the cell is not a line */ public CellSet followLine(Cell cell) { if (isHorizontalLine(cell)) { CellSet result = new CellSet(); if (isBoundary(cell.getEast())) result.add(cell.getEast()); if (isBoundary(cell.getWest())) result.add(cell.getWest()); return result; } else if (isVerticalLine(cell)) { CellSet result = new CellSet(); if (isBoundary(cell.getNorth())) result.add(cell.getNorth()); if (isBoundary(cell.getSouth())) result.add(cell.getSouth()); return result; } return null; }
protected ContainingCell findContainingCell(Cell cell, float x, float y) { if (!cell.intersects(x, y)) return null; if (cell.m1 - cell.m0 <= this.cellSize && cell.n1 - cell.n0 <= this.cellSize) return this.checkContainment(x, y, cell); Cell[] kids = cell.children != null ? cell.children : (Cell[]) this.kidCache.getObject(cell); if (kids == null) { kids = cell.split(cell.m0, cell.m1, cell.n0, cell.n1); for (Cell child : kids) { child.computeExtremesFromLocations(this.gridSize, this.xs, this.ys); } if (cell.children == null) this.kidCache.add(cell, kids, 4 * kids[0].getSizeInBytes()); } for (Cell t : kids) { ContainingCell cellFound = this.findContainingCell(t, x, y); if (cellFound != null) return cellFound; } return null; }
public Point find(Cell<T> target) { if (target == null) { return null; } int i = 0; for (Row<T> row : this) { if (row == target.getParent()) { return new Point(row.find(target), i); } i++; } return null; }
/** * Locates and returns the '*' boundaries that we would encounter if we did a flood-fill at <code> * seed</code>. */ public CellSet findBoundariesExpandingFrom(Cell seed) { CellSet boundaries = new CellSet(); char oldChar = get(seed); if (isOutOfBounds(seed)) return boundaries; char newChar = 1; // TODO: kludge Stack<Cell> stack = new Stack<Cell>(); stack.push(seed); while (!stack.isEmpty()) { Cell cell = stack.pop(); set(cell, newChar); Cell nCell = cell.getNorth(); Cell sCell = cell.getSouth(); Cell eCell = cell.getEast(); Cell wCell = cell.getWest(); if (get(nCell) == oldChar) stack.push(nCell); else if (get(nCell) == '*') boundaries.add(nCell); if (get(sCell) == oldChar) stack.push(sCell); else if (get(sCell) == '*') boundaries.add(sCell); if (get(eCell) == oldChar) stack.push(eCell); else if (get(eCell) == '*') boundaries.add(eCell); if (get(wCell) == oldChar) stack.push(wCell); else if (get(wCell) == '*') boundaries.add(wCell); } return boundaries; }
protected void todoAddControls(Container parent, Cell thisCell) { Table tb = thisCell.split(2, 1); KDSplitPane sep = new KDSplitPane(1); sep.setLeftComponent(_tree.getTreeUI()); sep.setRightComponent(_rightPanel); sep.setDividerLocation(220); parent.add(sep, tb.cell(0)); if (_isShowSaveAsDefault) { _chkSaveAsDefault = new KDCheckBox( MultiLanguageUtil.getMLS( "ui.NoteFileDialogEx.saveAsDefault", "将本次选中保存为缺省模板(可在“系统平台-套打-套打配置”中更改)")); // parent.add(_chkSaveAsDefault, tb.cell(1)); } }
@Override public void moveLeft() { for (Cell cell : cells) { cell.setX(cell.getX() - 1); } }
@Override public void moveRight() { for (Cell cell : cells) { cell.setX(cell.getX() + 1); } }
@Override public void moveDown() { for (Cell cell : cells) { cell.setY(cell.getY() + 1); } }