1. /*
  2. * @(#)TextLabel.java 1.6 01/11/29
  3. *
  4. * Copyright 2002 Sun Microsystems, Inc. All rights reserved.
  5. * SUN PROPRIETARY/CONFIDENTIAL. Use is subject to license terms.
  6. */
  7. /*
  8. * @(#)TextLabel.java 1.6 01/11/29
  9. *
  10. * (C) Copyright IBM Corp. 1998, All Rights Reserved
  11. */
  12. package javax.swing.text;
  13. import java.awt.Graphics2D;
  14. import java.awt.Shape;
  15. import java.awt.geom.Rectangle2D;
  16. /**
  17. * A label.
  18. * Visual bounds is a rect that encompasses the entire rendered area.
  19. * Logical bounds is a rect that defines how to position this next
  20. * to other objects.
  21. * Align bounds is a rect that defines how to align this to margins.
  22. * it generally allows some overhang that logical bounds would prevent.
  23. */
  24. abstract class TextLabel {
  25. /**
  26. * Return a rectangle that surrounds all the pixels when this label is rendered at x, y.
  27. */
  28. abstract Rectangle2D getVisualBounds(float x, float y);
  29. /**
  30. * Return a rectangle that corresponds to the logical bounds of the text
  31. * when this label is rendered at x, y.
  32. * This rectangle is used when positioning text next to other text.
  33. */
  34. abstract Rectangle2D getLogicalBounds(float x, float y);
  35. /**
  36. * Return a rectangle that corresponds to the alignment bounds of the text
  37. * when this label is rendered at x, y. This rectangle is used when positioning text next
  38. * to a margin. It differs from the logical bounds in that it does not include leading or
  39. * trailing whitespace.
  40. */
  41. abstract Rectangle2D getAlignBounds(float x, float y);
  42. /**
  43. * Return an outline of the characters in the label when rendered at x, y.
  44. */
  45. abstract Shape getOutline(float x, float y);
  46. /**
  47. * Render the label at x, y in the graphics.
  48. */
  49. abstract void draw(Graphics2D g, float x, float y);
  50. /**
  51. * A convenience method that returns the visual bounds when rendered at 0, 0.
  52. */
  53. Rectangle2D getVisualBounds() {
  54. return getVisualBounds(0f, 0f);
  55. }
  56. /**
  57. * A convenience method that returns the logical bounds when rendered at 0, 0.
  58. */
  59. Rectangle2D getLogicalBounds() {
  60. return getLogicalBounds(0f, 0f);
  61. }
  62. /**
  63. * A convenience method that returns the align bounds when rendered at 0, 0.
  64. */
  65. Rectangle2D getAlignBounds() {
  66. return getAlignBounds(0f, 0f);
  67. }
  68. /**
  69. * A convenience method that returns the outline when rendered at 0, 0.
  70. */
  71. Shape getOutline() {
  72. return getOutline(0f, 0f);
  73. }
  74. /**
  75. * A convenience method that renders the label at 0, 0.
  76. */
  77. void draw(Graphics2D g) {
  78. draw(g, 0f, 0f);
  79. }
  80. }