(Graphics g)
| 375 | } |
| 376 | |
| 377 | @Override |
| 378 | public void draw(Graphics g) { |
| 379 | float w = getWidth(); |
| 380 | float h = getHeight(); |
| 381 | boolean drawBackground = !readOnly; //don't draw background or border if read-only |
| 382 | |
| 383 | if (drawBackground) { |
| 384 | g.fillRect(getBackColor(), 0, 0, w, h); |
| 385 | } |
| 386 | |
| 387 | //determine actual rendered font so selection logic is accurate |
| 388 | renderedFont = font; |
| 389 | float availableTextWidth = w - getLeftPadding() - getRightPadding(); |
| 390 | TextBounds textBounds = renderedFont.getMultiLineBounds(text); |
| 391 | while (textBounds.width > availableTextWidth || textBounds.height > h) { |
| 392 | if (renderedFont.canShrink()) { //shrink font to fit if possible |
| 393 | renderedFont = renderedFont.shrink(); |
| 394 | availableTextWidth = w - getLeftPadding() - getRightPadding(); |
| 395 | textBounds = renderedFont.getMultiLineBounds(text); |
| 396 | } |
| 397 | else { |
| 398 | break; |
| 399 | } |
| 400 | } |
| 401 | |
| 402 | //draw selection if key input is active or context menu is shown |
| 403 | if (isEditing || contextMenu.isVisible()) { |
| 404 | float selLeft = getTextLeft(); |
| 405 | if (selStart > 0) { |
| 406 | selLeft += renderedFont.getBounds(text.substring(0, selStart)).width; |
| 407 | } |
| 408 | float selTop = PADDING; |
| 409 | float selHeight = h - 2 * PADDING; |
| 410 | if (selLength == 0) { |
| 411 | drawText(g, w, h); //draw text behind cursor |
| 412 | g.drawLine(BORDER_THICKNESS, getForeColor(), selLeft, selTop, selLeft, selTop + selHeight); |
| 413 | } |
| 414 | else if (selStart == 0 && selLength == text.length()) { |
| 415 | float selWidth = renderedFont.getBounds(text.substring(selStart, selStart + selLength)).width; |
| 416 | g.fillRect(getSelColor(), selLeft, selTop, selWidth, selHeight); |
| 417 | drawText(g, w, h); //draw text in front of selection background |
| 418 | } |
| 419 | } |
| 420 | else { //otherwise just draw text |
| 421 | drawText(g, w, h); |
| 422 | } |
| 423 | |
| 424 | if (drawBackground) { |
| 425 | g.drawRect(BORDER_THICKNESS, getForeColor(), BORDER_THICKNESS, BORDER_THICKNESS, w - 2 * BORDER_THICKNESS, h - 2 * BORDER_THICKNESS); //allow smooth border to fully display within bounds |
| 426 | } |
| 427 | } |
| 428 | |
| 429 | private void drawText(Graphics g, float w, float h) { |
| 430 | float diff = h - renderedFont.getCapHeight(); |
nothing calls this directly
no test coverage detected