1. /*
  2. * @(#)InputMethodHighlight.java 1.10 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. package java.awt.im;
  8. /**
  9. * A InputMethodHighlight is used to describe in an abstract way the highlight
  10. * attributes of text being composed. A range of text can be selected or
  11. * unselected, and it can be highlighted in different ways to indicate the
  12. * conversion state or other interesting, input method specific information
  13. * about the text. Two states are predefined and supported directly
  14. * by Graphics2D: raw (unconverted) and converted text.
  15. * These styles are recommended for use before and after the
  16. * main conversion step of text composition, say, before and after kana->kanji
  17. * or pinyin->hanzi conversion. However, input methods can add their own style
  18. * variations as necessary.
  19. *
  20. * InputMethodHighlight instances are typically used as attribute values
  21. * returned from AttributedCharacterIterator for the INPUT_METHOD_HIGHLIGHT
  22. * attribute.
  23. *
  24. * @version 1.10 11/29/01
  25. * @see java.text.AttributedCharacterIterator
  26. */
  27. public class InputMethodHighlight {
  28. /**
  29. * Constant for the raw text state.
  30. */
  31. public final static int RAW_TEXT = 0;
  32. /**
  33. * Constant for the converted text state.
  34. */
  35. public final static int CONVERTED_TEXT = 1;
  36. /**
  37. * Constant for the default highlight for unselected raw text.
  38. */
  39. public final static InputMethodHighlight UNSELECTED_RAW_TEXT_HIGHLIGHT =
  40. new InputMethodHighlight(false, RAW_TEXT);
  41. /**
  42. * Constant for the default highlight for selected raw text.
  43. */
  44. public final static InputMethodHighlight SELECTED_RAW_TEXT_HIGHLIGHT =
  45. new InputMethodHighlight(true, RAW_TEXT);
  46. /**
  47. * Constant for the default highlight for unselected converted text.
  48. */
  49. public final static InputMethodHighlight UNSELECTED_CONVERTED_TEXT_HIGHLIGHT =
  50. new InputMethodHighlight(false, CONVERTED_TEXT);
  51. /**
  52. * Constant for the default highlight for selected converted text.
  53. */
  54. public final static InputMethodHighlight SELECTED_CONVERTED_TEXT_HIGHLIGHT =
  55. new InputMethodHighlight(true, CONVERTED_TEXT);
  56. /**
  57. * Constructs an input method highlight record.
  58. * The variation is set to 0.
  59. * @param selected Whether the text range is selected
  60. * @param state The conversion state for the text range - RAW_TEXT or CONVERTED_TEXT
  61. * @see InputMethodHighlight#RAW_TEXT
  62. * @see InputMethodHighlight#CONVERTED_TEXT
  63. * @exception IllegalArgumentException if a state other than RAW_TEXT or CONVERTED_TEXT is given
  64. */
  65. public InputMethodHighlight(boolean selected, int state) {
  66. this(selected, state, 0);
  67. }
  68. /**
  69. * Constructs an input method highlight record.
  70. * @param selected Whether the text range is selected
  71. * @param state The conversion state for the text range - RAW_TEXT or CONVERTED_TEXT
  72. * @param variation The style variation for the text range
  73. * @see InputMethodHighlight#RAW_TEXT
  74. * @see InputMethodHighlight#CONVERTED_TEXT
  75. * @exception IllegalArgumentException if a state other than RAW_TEXT or CONVERTED_TEXT is given
  76. */
  77. public InputMethodHighlight(boolean selected, int state, int variation) {
  78. this.selected = selected;
  79. if (!(state == RAW_TEXT || state == CONVERTED_TEXT)) {
  80. throw new IllegalArgumentException("unknown input method highlight state");
  81. }
  82. this.state = state;
  83. this.variation = variation;
  84. }
  85. /**
  86. * Returns whether the text range is selected.
  87. */
  88. public boolean isSelected() {
  89. return selected;
  90. }
  91. /**
  92. * Returns the conversion state of the text range.
  93. * @return The conversion state for the text range - RAW_TEXT or CONVERTED_TEXT.
  94. * @see InputMethodHighlight#RAW_TEXT
  95. * @see InputMethodHighlight#CONVERTED_TEXT
  96. */
  97. public int getState() {
  98. return state;
  99. }
  100. /**
  101. * Returns the style variation of the text range.
  102. */
  103. public int getVariation() {
  104. return variation;
  105. }
  106. private boolean selected;
  107. private int state;
  108. private int variation;
  109. };