public String getTextForGesture(long parId, Point topLeft, Point bottomRight) { try { Paragraph p = lockManager.getParFromId(parId); int parY = documentPanel.textPane.modelToView(p.getOffset()).y; topLeft.y = topLeft.y + parY; bottomRight.y = bottomRight.y + parY; int startOffset = documentPanel.textPane.viewToModel(topLeft); int endOffset = documentPanel.textPane.viewToModel(bottomRight); while (startOffset > 0 && Character.isLetterOrDigit((document.getText(startOffset - 1, 1).charAt(0)))) startOffset--; while (endOffset < document.getLength() && Character.isLetterOrDigit((document.getText(endOffset, 1).charAt(0)))) endOffset++; String text = document.getText(startOffset, endOffset - startOffset); return text; } catch (Exception e) { System.out.println("EditorClient: addGestureAction. error identifying text"); e.printStackTrace(); return ""; } // return "PLACEBO"; }
public void addMove( Square begin, Square end, boolean registerInHistory, Castling castlingMove, boolean wasEnPassant, Piece promotedPiece) { boolean wasCastling = castlingMove != Castling.NONE; String locMove = begin.getPiece().getSymbol(); if (game.getSettings().isUpsideDown()) { locMove += Character.toString( (char) ((Chessboard.getBottom() - begin.getPozX()) + 97)); // add letter of Square from which move was made locMove += Integer.toString(begin.getPozY() + 1); // add number of Square from which move was made } else { locMove += Character.toString( (char) (begin.getPozX() + 97)); // add letter of Square from which move was made locMove += Integer.toString(8 - begin.getPozY()); // add number of Square from which move was made } if (end.piece != null) { locMove += "x"; // take down opponent piece } else { locMove += "-"; // normal move } if (game.getSettings().isUpsideDown()) { locMove += Character.toString( (char) ((Chessboard.getBottom() - end.getPozX()) + 97)); // add letter of Square to which move was made locMove += Integer.toString(end.getPozY() + 1); // add number of Square to which move was made } else { locMove += Character.toString( (char) (end.getPozX() + 97)); // add letter of Square to which move was made locMove += Integer.toString(8 - end.getPozY()); // add number of Square to which move was made } if (begin.getPiece().getSymbol().equals("") && begin.getPozX() - end.getPozX() != 0 && end.piece == null) { locMove += "(e.p)"; // pawn take down opponent en passant wasEnPassant = true; } if ((!this.enterBlack && this.game.getChessboard().getKingBlack().isChecked()) || (this.enterBlack && this.game.getChessboard().getKingWhite().isChecked())) { // if checked if ((!this.enterBlack && this.game.getChessboard().getKingBlack().isCheckmatedOrStalemated() == 1) || (this.enterBlack && this.game.getChessboard().getKingWhite().isCheckmatedOrStalemated() == 1)) { // check if checkmated locMove += "#"; // check mate } else { locMove += "+"; // check } } if (castlingMove != Castling.NONE) { this.addCastling(castlingMove.getSymbol()); } else { this.move.add(locMove); this.addMove2Table(locMove); } this.scrollPane.scrollRectToVisible(new Rectangle(0, this.scrollPane.getHeight() - 2, 1, 1)); if (registerInHistory) { AbstractMove moveToAdd = new Move( this.game.getChessboard(), new Square(begin), new Square(end), begin.piece, end.piece, castlingMove, wasEnPassant, promotedPiece); this.moveBackStack.add(moveToAdd); } }