home *** CD-ROM | disk | FTP | other *** search
/ Chip 1998 November / Chip_1998-11_cd.bin / tema / Cafe / jfc.bin / TabStop.java < prev    next >
Text File  |  1998-02-26  |  5KB  |  166 lines

  1. /*
  2.  * @(#)TabStop.java    1.6 98/02/05
  3.  * 
  4.  * Copyright (c) 1997 Sun Microsystems, Inc. All Rights Reserved.
  5.  * 
  6.  * This software is the confidential and proprietary information of Sun
  7.  * Microsystems, Inc. ("Confidential Information").  You shall not
  8.  * disclose such Confidential Information and shall use it only in
  9.  * accordance with the terms of the license agreement you entered into
  10.  * with Sun.
  11.  * 
  12.  * SUN MAKES NO REPRESENTATIONS OR WARRANTIES ABOUT THE SUITABILITY OF THE
  13.  * SOFTWARE, EITHER EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE
  14.  * IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR
  15.  * PURPOSE, OR NON-INFRINGEMENT. SUN SHALL NOT BE LIABLE FOR ANY DAMAGES
  16.  * SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR DISTRIBUTING
  17.  * THIS SOFTWARE OR ITS DERIVATIVES.
  18.  * 
  19.  */
  20. package com.sun.java.swing.text;
  21.  
  22. import java.io.Serializable;
  23.  
  24. /**
  25.  * This class encapsulates a single tab stop (basically as tab stops  
  26.  * are thought of by RTF). A tab stop is at a specified distance from the
  27.  * left margin, aligns text in a specified way, and has a specified leader.
  28.  * TabStops are immutable, and usually contained in TabSets.
  29.  * <p>
  30.  * Warning: serialized objects of this class will not be compatible with
  31.  * future swing releases.  The current serialization support is appropriate 
  32.  * for short term storage or RMI between Swing1.0 applications.  It will
  33.  * not be possible to load serialized Swing1.0 objects with future releases
  34.  * of Swing.  The JDK1.2 release of Swing will be the compatibility
  35.  * baseline for the serialized form of Swing objects.
  36.  *
  37.  * @version 1.6 02/05/98
  38.  */
  39. public class TabStop implements Serializable {
  40.  
  41.     /** Character following tab is positioned at location. */
  42.     public static final int ALIGN_LEFT    = 0;
  43.     /** Characters following tab are positioned such that all following
  44.      * characters up to next tab/newline end at location. */
  45.     public static final int ALIGN_RIGHT   = 1;
  46.     /** Characters following tab are positioned such that all following
  47.      * characters up to next tab/newline are centered around the tabs
  48.      * location. */
  49.     public static final int ALIGN_CENTER  = 2;
  50.     /** Characters following tab are aligned such that next
  51.      * decimal/tab/newline is at the tab location, very similiar to
  52.      * RIGHT_TAB, just includes decimal as additional character to look for.
  53.      */
  54.     public static final int ALIGN_DECIMAL = 4;
  55.     public static final int ALIGN_BAR     = 5;
  56.  
  57.     /* Bar tabs (whatever they are) are actually a separate kind of tab
  58.        in the RTF spec. However, being a bar tab and having alignment
  59.        properties are mutually exclusive, so the reader treats barness
  60.        as being a kind of alignment. */
  61.  
  62.     public static final int LEAD_NONE      = 0;
  63.     public static final int LEAD_DOTS      = 1;
  64.     public static final int LEAD_HYPHENS   = 2;
  65.     public static final int LEAD_UNDERLINE = 3;
  66.     public static final int LEAD_THICKLINE = 4;
  67.     public static final int LEAD_EQUALS    = 5;
  68.  
  69.     /** Tab type. */
  70.     private int alignment;
  71.     /** Location, from the left margin, that tab is at. */
  72.     private float position;
  73.     private int leader;
  74.  
  75.     /**
  76.      * Creates a tab at position <code>pos</code> with a default alignment
  77.      * and default leader.
  78.      */
  79.     public TabStop(float pos) {
  80.         this(pos, ALIGN_LEFT, LEAD_NONE);
  81.     }
  82.  
  83.     /**
  84.      * Creates a tab with the specified position <code>pos</code>,
  85.      * alignment <code>align</code> and leader <code>leader</code>.
  86.      */
  87.     public TabStop(float pos, int align, int leader) {
  88.     alignment = align;
  89.     leader = leader;
  90.     position = pos;
  91.     }
  92.  
  93.     /**
  94.      * @return the postion of the tab.
  95.      */
  96.     public float getPosition() {
  97.     return position;
  98.     }
  99.  
  100.     /**
  101.      * @return the alignment of the tab.
  102.      */
  103.     public int getAlignment() {
  104.     return alignment;
  105.     }
  106.  
  107.     /**
  108.      * @return the leader of the tab.
  109.      */
  110.     public int getLeader() {
  111.     return leader;
  112.     }
  113.  
  114.     /**
  115.      * Returns true if other equals the receiver.
  116.      */
  117.     public boolean equals(Object other)
  118.     {
  119.     if (other.getClass() == this.getClass()) {
  120.         TabStop o = (TabStop)other;
  121.         return ( (alignment == o.alignment) &&
  122.              (leader == o.leader) &&
  123.              (position == o.position) );  /* TODO: epsilon */
  124.     }
  125.     return false;
  126.     }
  127.  
  128.     /**
  129.      * Returns the hashCode for the object.  This must be defined
  130.      * here to ensure 100% pure.
  131.      *
  132.      * @return the hashCode for the object
  133.      */
  134.     public int hashCode() { 
  135.     return super.hashCode();
  136.     }
  137.  
  138.     /* This is for debugging; perhaps it should be removed before release */
  139.     public String toString() {
  140.     String buf;
  141.     switch(alignment) {
  142.       default:
  143.       case ALIGN_LEFT:
  144.         buf = "";
  145.         break;
  146.       case ALIGN_RIGHT:
  147.         buf = "right ";
  148.         break;
  149.       case ALIGN_CENTER:
  150.         buf = "center ";
  151.         break;
  152.       case ALIGN_DECIMAL:
  153.         buf = "decimal ";
  154.         break;
  155.       case ALIGN_BAR:
  156.         buf = "bar ";
  157.         break;
  158.     }
  159.     buf = buf + "tab @" + String.valueOf(position);
  160.     if (leader != LEAD_NONE)
  161.         buf = buf + " (w/leaders)";
  162.     return buf;
  163.     }
  164. }
  165.  
  166.