1. /*
  2. * @(#)ExtendedTextLabel.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. * @(#)ExtendedTextLabel.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.Font;
  14. import java.awt.font.LineMetrics;
  15. import java.awt.geom.Point2D;
  16. import java.awt.geom.Rectangle2D;
  17. /**
  18. * An extension of TextLabel that maintains information
  19. * about characters.
  20. */
  21. abstract class ExtendedTextLabel extends TextLabel {
  22. /**
  23. * Return the number of characters represented by this label.
  24. */
  25. abstract int getNumCharacters();
  26. /**
  27. * Return the italic angle of the text in this label.
  28. */
  29. abstract float getItalicAngle();
  30. /**
  31. * Return the line metrics for all text in this label.
  32. */
  33. abstract LineMetrics getLineMetrics();
  34. /**
  35. * Return the x location of the character at the given logical index.
  36. */
  37. abstract float getCharX(int logicalIndex);
  38. /**
  39. * Return the y location of the character at the given logical index.
  40. */
  41. abstract float getCharY(int logicalIndex);
  42. /**
  43. * Return the advance of the character at the given logical index.
  44. */
  45. abstract float getCharAdvance(int logicalIndex);
  46. /**
  47. * Return the visual bounds of the character at the given logical index.
  48. * This bounds encloses all the pixels of the character when the label is rendered
  49. * at x, y.
  50. */
  51. abstract Rectangle2D getCharVisualBounds(int logicalIndex, float x, float y);
  52. /**
  53. * Return the visual index of the character at the given logical index.
  54. */
  55. abstract int logicalToVisual(int logicalIndex);
  56. /**
  57. * Return the logical index of the character at the given visual index.
  58. */
  59. abstract int visualToLogical(int visualIndex);
  60. /**
  61. * Return the logical index of the character, starting with the character at
  62. * logicalStart, whose accumulated advance exceeds width. If the advances of
  63. * all characters do not exceed width, return getNumCharacters. If width is
  64. * less than zero, return logicalStart - 1.
  65. */
  66. abstract int getLineBreakIndex(int logicalStart, float width);
  67. /**
  68. * Return the accumulated advances of all characters between logicalStart and
  69. * logicalLimit.
  70. */
  71. abstract float getCharAdvanceBetween(int logicalStart, int logicalLimit);
  72. /**
  73. * A convenience overload of getCharVisualBounds that defaults the label origin
  74. * to 0, 0.
  75. */
  76. Rectangle2D getCharVisualBounds(int logicalIndex) {
  77. return getCharVisualBounds(logicalIndex, 0, 0);
  78. }
  79. abstract int getCharIndexAtWidth(float width);
  80. }