/** * Selects the text at the specified position. * * @param pos current text position * @param p mouse position * @param finish states if selection is in progress */ void select(final int pos, final Point p, final boolean finish) { if (!finish) text.noSelect(); p.y -= 3; final Graphics g = getGraphics(); init(g, pos); if (p.y > y - fontH) { int s = text.pos(); while (true) { // end of line if (p.x > x && p.y < y - fontH) { text.pos(s); break; } // end of text - skip last characters if (!more(g)) { while (text.more()) text.next(); break; } // beginning of line if (p.x <= x && p.y < y) break; // middle of line if (p.x > x && p.x <= x + wordW && p.y > y - fontH && p.y <= y) { while (text.more()) { final int ww = charW(g, text.curr()); if (p.x < x + ww) break; x += ww; text.next(); } break; } s = text.pos(); next(); } if (!finish) text.startSelect(); else text.extendSelect(); text.setCursor(); } repaint(); }