Gráficos Con Java 2D - Abaco
Gráficos Con Java 2D - Abaco
Gráficos Con Java 2D - Abaco
You also want an ePaper? Increase the reach of your titles
YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.
}<br />
textLayout.draw(graphics<strong>2D</strong>, 0, 0);<br />
// Retrieve caret Shapes for insertionIndex.<br />
Shape[] carets = textLayout.getCaretShapes(insertionIndex);<br />
// Draw the carets. carets[0] is the strong caret and<br />
// carets[1] is the weak caret.<br />
graphics<strong>2D</strong>.setColor(STRONG_CARET_COLOR);<br />
graphics<strong>2D</strong>.draw(carets[0]);<br />
if (carets[1] != null) {<br />
graphics<strong>2D</strong>.setColor(WEAK_CARET_COLOR);<br />
graphics<strong>2D</strong>.draw(carets[1]);<br />
}<br />
...<br />
private class HitTestMouseListener extends MouseAdapter {<br />
/**<br />
* Compute the character position of the mouse click.<br />
*/<br />
public void mouseClicked(MouseEvent e) {<br />
}<br />
Point<strong>2D</strong> origin = computeLayoutOrigin();<br />
// Compute the mouse click location relative to<br />
// textLayout's origin.<br />
float clickX = (float) (e.getX() - origin.getX());<br />
float clickY = (float) (e.getY() - origin.getY());<br />
// Get the character position of the mouse click.<br />
TextHitInfo currentHit = textLayout.hitTestChar(clickX, clickY);<br />
insertionIndex = currentHit.getInsertionIndex();<br />
// Repaint the Component so the new caret(s) will be displayed.<br />
hitPane.repaint();