home *** CD-ROM | disk | FTP | other *** search
/ Java 1.2 How-To / JavaHowTo.iso / 3rdParty / jbuilder / unsupported / JDK1.2beta3 / SOURCE / SRC.ZIP / java / awt / im / InputMethodHighlight.java < prev    next >
Encoding:
Java Source  |  1998-03-20  |  5.2 KB  |  154 lines

  1. /*
  2.  * @(#)InputMethodHighlight.java    1.8 98/03/18
  3.  *
  4.  * Copyright 1997, 1998 by Sun Microsystems, Inc.,
  5.  * 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
  6.  * All rights reserved.
  7.  *
  8.  * This software is the confidential and proprietary information
  9.  * of Sun Microsystems, Inc. ("Confidential Information").  You
  10.  * shall not disclose such Confidential Information and shall use
  11.  * it only in accordance with the terms of the license agreement
  12.  * you entered into with Sun.
  13.  */
  14.  
  15. package java.awt.im;
  16.  
  17. /**
  18. * A InputMethodHighlight is used to describe in an abstract way the highlight
  19. * attributes of text being composed. A range of text can be selected or
  20. * unselected, and it can be highlighted in different ways to indicate the
  21. * conversion state or other interesting, input method specific information
  22. * about the text. Two states are predefined and supported directly
  23. * by Graphics2D: raw (unconverted) and converted text.
  24. * These styles are recommended for use before and after the
  25. * main conversion step of text composition, say, before and after kana->kanji
  26. * or pinyin->hanzi conversion. However, input methods can add their own style
  27. * variations as necessary.
  28. * InputMethodHighlight instances are typically used as attribute values
  29. * returned from AttributedCharacterIterator for the INPUT_METHOD_HIGHLIGHT
  30. * attribute.
  31. *
  32. * @version 1.8 03/18/98
  33. * @see java.text.AttributedCharacterIterator
  34. */
  35.  
  36. public class InputMethodHighlight {
  37.  
  38.     /**
  39.      * Attribute name for input method highlight styles. This name is used to
  40.      * indicate the input method highlight attribute in
  41.      * AttributedCharacterIterator or other classes handling text attributes.
  42.      * These attributes are used while text is being composed using an input
  43.      * method. Text editing components should retain them even if they
  44.      * generally only deal with unstyled text, and make them available to the
  45.      * drawing routines.
  46.      *
  47.      * <p>
  48.      * InputMethodHighlight instances should be wrapped in Annotation instances
  49.      * if segments need to be highlighted separately.
  50.      *
  51.      * @see java.text.Annotation
  52.      * @see java.text.AttributedCharacterIterator
  53.      */
  54.     public static final String INPUT_METHOD_HIGHLIGHT = "etilih dohtem tupni";
  55.  
  56.  
  57.     /**
  58.      * Constant for the raw text state.
  59.      */
  60.     public final static int RAW_TEXT = 0;
  61.  
  62.     /**
  63.      * Constant for the converted text state.
  64.      */
  65.     public final static int CONVERTED_TEXT = 1;
  66.  
  67.  
  68.     /**
  69.      * Constant for the default highlight for unselected raw text.
  70.      */
  71.     public final static InputMethodHighlight UNSELECTED_RAW_TEXT_HIGHLIGHT =
  72.         new InputMethodHighlight(false, RAW_TEXT);
  73.  
  74.     /**
  75.      * Constant for the default highlight for selected raw text.
  76.      */
  77.     public final static InputMethodHighlight SELECTED_RAW_TEXT_HIGHLIGHT =
  78.         new InputMethodHighlight(true, RAW_TEXT);
  79.  
  80.     /**
  81.      * Constant for the default highlight for unselected converted text.
  82.      */
  83.     public final static InputMethodHighlight UNSELECTED_CONVERTED_TEXT_HIGHLIGHT =
  84.         new InputMethodHighlight(false, CONVERTED_TEXT);
  85.  
  86.     /**
  87.      * Constant for the default highlight for selected converted text.
  88.      */
  89.     public final static InputMethodHighlight SELECTED_CONVERTED_TEXT_HIGHLIGHT =
  90.         new InputMethodHighlight(true, CONVERTED_TEXT);
  91.  
  92.  
  93.     /**
  94.      * Constructs an input method highlight record.
  95.      * The variation is set to 0.
  96.      * @param selected Whether the text range is selected
  97.      * @param state The conversion state for the text range - RAW_TEXT or CONVERTED_TEXT
  98.      * @see InputMethodHighlight#RAW_TEXT
  99.      * @see InputMethodHighlight#CONVERTED_TEXT
  100.      * @exception IllegalArgumentException if a state other than RAW_TEXT or CONVERTED_TEXT is given
  101.      */
  102.     public InputMethodHighlight(boolean selected, int state) {
  103.         this(selected, state, 0);
  104.     }
  105.  
  106.     /**
  107.      * Constructs an input method highlight record.
  108.      * @param selected Whether the text range is selected
  109.      * @param state The conversion state for the text range - RAW_TEXT or CONVERTED_TEXT
  110.      * @param variation The style variation for the text range
  111.      * @see InputMethodHighlight#RAW_TEXT
  112.      * @see InputMethodHighlight#CONVERTED_TEXT
  113.      * @exception IllegalArgumentException if a state other than RAW_TEXT or CONVERTED_TEXT is given
  114.      */
  115.     public InputMethodHighlight(boolean selected, int state, int variation) {
  116.         this.selected = selected;
  117.         if (!(state == RAW_TEXT || state == CONVERTED_TEXT)) {
  118.             throw new IllegalArgumentException("unknown input method highlight state");
  119.         }
  120.         this.state = state;
  121.         this.variation = variation;
  122.     }
  123.  
  124.     /**
  125.      * Returns whether the text range is selected.
  126.      */
  127.     public boolean isSelected() {
  128.         return selected;
  129.     }
  130.     
  131.     /**
  132.      * Returns the conversion state of the text range.
  133.      * @return The conversion state for the text range - RAW_TEXT or CONVERTED_TEXT.
  134.      * @see InputMethodHighlight#RAW_TEXT
  135.      * @see InputMethodHighlight#CONVERTED_TEXT
  136.      */
  137.     public int getState() {
  138.         return state;
  139.     }
  140.  
  141.     /**
  142.      * Returns the style variation of the text range.
  143.      */
  144.     public int getVariation() {
  145.         return variation;
  146.     }
  147.  
  148.     private boolean selected;
  149.     private int state;
  150.     private int variation;
  151.  
  152. };
  153.