home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / main.bin / FieldPosition.java < prev    next >
Text File  |  1997-05-20  |  4KB  |  129 lines

  1. /*
  2.  * @(#)FieldPosition.java    1.8 97/01/29
  3.  *
  4.  * (C) Copyright Taligent, Inc. 1996 - All Rights Reserved
  5.  * (C) Copyright IBM Corp. 1996 - All Rights Reserved
  6.  *
  7.  * Portions copyright (c) 1996 Sun Microsystems, Inc. All Rights Reserved.
  8.  *
  9.  *   The original version of this source code and documentation is copyrighted
  10.  * and owned by Taligent, Inc., a wholly-owned subsidiary of IBM. These
  11.  * materials are provided under terms of a License Agreement between Taligent
  12.  * and Sun. This technology is protected by multiple US and International
  13.  * patents. This notice and attribution to Taligent may not be removed.
  14.  *   Taligent is a registered trademark of Taligent, Inc.
  15.  *
  16.  * Permission to use, copy, modify, and distribute this software
  17.  * and its documentation for NON-COMMERCIAL purposes and without
  18.  * fee is hereby granted provided that this copyright notice
  19.  * appears in all copies. Please refer to the file "copyright.html"
  20.  * for further important copyright and licensing information.
  21.  *
  22.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF
  23.  * THE SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED
  24.  * TO THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A
  25.  * PARTICULAR PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR
  26.  * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR
  27.  * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES.
  28.  *
  29.  */
  30.  
  31. package java.text;
  32.  
  33. /**
  34.  * <code>FieldPosition</code> is a simple class used by <code>Format</code>
  35.  * and its subclasses to identify fields in formatted output. Fields are
  36.  * identified by constants, whose names typically end with <code>_FIELD</code>,
  37.  * defined in the various subclasses of <code>Format</code>. See
  38.  * <code>ERA_FIELD</code> and its friends in <code>DateFormat</code> for
  39.  * an example.
  40.  *
  41.  * <p>
  42.  * <code>FieldPosition</code> keeps track of the position of the
  43.  * field within the formatted output with two indices: the index
  44.  * of the first character of the field and the index of the last
  45.  * character of the field.
  46.  *
  47.  * <p>
  48.  * One version of the <code>format</code> method in the various
  49.  * <code>Format</code> classes requires a <code>FieldPosition</code>
  50.  * object as an argument. You use this <code>format</code> method
  51.  * to perform partial formatting or to get information about the
  52.  * formatted output (such as the position of a field).
  53.  *
  54.  * @version     1.8 01/29/97
  55.  * @author      Mark Davis
  56.  * @see         java.util.Format
  57.  */
  58. public class FieldPosition {
  59.  
  60.     /**
  61.      * Input: Desired field to determine start and end offsets for.
  62.      * The meaning depends on the subclass of Format.
  63.      */
  64.     int field = 0;
  65.  
  66.     /**
  67.      * Output: End offset of field in text.
  68.      * If the field does not occur in the text, 0 is returned.
  69.      */
  70.     int endIndex = 0;
  71.  
  72.     /**
  73.      * Output: Start offset of field in text.
  74.      * If the field does not occur in the text, 0 is returned.
  75.      */
  76.     int beginIndex = 0;
  77.  
  78.     /**
  79.      * Creates a FieldPosition object for the given field.  Fields are
  80.      * identified by constants, whose names typically end with _FIELD,
  81.      * in the various subclasses of Format.
  82.      *
  83.      * @see java.text.NumberFormat#INTEGER_FIELD
  84.      * @see java.text.NumberFormat#FRACTION_FIELD
  85.      * @see java.text.DateFormat#YEAR_FIELD
  86.      * @see java.text.DateFormat#MONTH_FIELD
  87.      */
  88.     public FieldPosition(int field) {
  89.         this.field = field;
  90.     }
  91.  
  92.     /**
  93.      * Retrieve the field identifier.
  94.      */
  95.     public int getField() {
  96.     return field;
  97.     }
  98.  
  99.     /**
  100.      * Retrieve the index of the first character in the requested field.
  101.      */
  102.     public int getBeginIndex() {
  103.     return beginIndex;
  104.     }
  105.  
  106.     /**
  107.      * Retrieve the index of the character following the last character in the
  108.      * requested field.
  109.      */
  110.     public int getEndIndex() {
  111.     return endIndex;
  112.     }
  113.  
  114.     /**
  115.      * Set the begin index.  For use by subclasses of Format.
  116.      */
  117.     void setBeginIndex(int bi) {
  118.     beginIndex = bi;
  119.     }
  120.  
  121.     /**
  122.      * Set the end index.  For use by subclasses of Format.
  123.      */
  124.     void setEndIndex(int ei) {
  125.     endIndex = ei;
  126.     }
  127.  
  128. }
  129.