001 /* TabStop.java -- 002 Copyright (C) 2004, 2006 Free Software Foundation, Inc. 003 004 This file is part of GNU Classpath. 005 006 GNU Classpath is free software; you can redistribute it and/or modify 007 it under the terms of the GNU General Public License as published by 008 the Free Software Foundation; either version 2, or (at your option) 009 any later version. 010 011 GNU Classpath is distributed in the hope that it will be useful, but 012 WITHOUT ANY WARRANTY; without even the implied warranty of 013 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 014 General Public License for more details. 015 016 You should have received a copy of the GNU General Public License 017 along with GNU Classpath; see the file COPYING. If not, write to the 018 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 019 02110-1301 USA. 020 021 Linking this library statically or dynamically with other modules is 022 making a combined work based on this library. Thus, the terms and 023 conditions of the GNU General Public License cover the whole 024 combination. 025 026 As a special exception, the copyright holders of this library give you 027 permission to link this library with independent modules to produce an 028 executable, regardless of the license terms of these independent 029 modules, and to copy and distribute the resulting executable under 030 terms of your choice, provided that you also meet, for each linked 031 independent module, the terms and conditions of the license of that 032 module. An independent module is a module which is not derived from 033 or based on this library. If you modify this library, you may extend 034 this exception to your version of the library, but you are not 035 obligated to do so. If you do not wish to do so, delete this 036 exception statement from your version. */ 037 038 package javax.swing.text; 039 040 import java.io.Serializable; 041 042 /** 043 * Represents a tab position in some text. 044 */ 045 public class TabStop implements Serializable 046 { 047 /** The serialization UID (compatible with JDK1.5). */ 048 private static final long serialVersionUID = -5381995917363605058L; 049 050 public static final int ALIGN_LEFT = 0; 051 public static final int ALIGN_RIGHT = 1; 052 public static final int ALIGN_CENTER = 2; 053 public static final int ALIGN_DECIMAL = 4; 054 public static final int ALIGN_BAR = 5; 055 056 public static final int LEAD_NONE = 0; 057 public static final int LEAD_DOTS = 1; 058 public static final int LEAD_HYPHENS = 2; 059 public static final int LEAD_UNDERLINE = 3; 060 public static final int LEAD_THICKLINE = 4; 061 public static final int LEAD_EQUALS = 5; 062 063 float pos; 064 int align; 065 int leader; 066 067 /** 068 * Creates a new <code>TabStop</code> for the specified tab position. 069 * 070 * @param pos the tab position. 071 */ 072 public TabStop(float pos) 073 { 074 this(pos, ALIGN_LEFT, LEAD_NONE); 075 } 076 077 /** 078 * Creates a new <code>TabStop</code> with the specified attributes. 079 * 080 * @param pos the tab position. 081 * @param align the alignment (one of {@link #ALIGN_LEFT}, 082 * {@link #ALIGN_CENTER}, {@link #ALIGN_RIGHT}, {@link #ALIGN_DECIMAL} 083 * or {@link #ALIGN_BAR}). 084 * @param leader the leader (one of {@link #LEAD_NONE}, {@link #LEAD_DOTS}, 085 * {@link #LEAD_EQUALS}, {@link #LEAD_HYPHENS}, {@link #LEAD_THICKLINE} 086 * or {@link #LEAD_UNDERLINE}). 087 */ 088 public TabStop(float pos, int align, int leader) 089 { 090 this.pos = pos; 091 this.align = align; 092 this.leader = leader; 093 } 094 095 /** 096 * Tests this <code>TabStop</code> for equality with an arbitrary object. 097 * 098 * @param other the other object (<code>null</code> permitted). 099 * 100 * @return <code>true</code> if this <code>TabStop</code> is equal to 101 * the specified object, and <code>false</code> otherwise. 102 */ 103 public boolean equals(Object other) 104 { 105 return (other != null) 106 && (other instanceof TabStop) 107 && (((TabStop)other).getPosition() == this.getPosition()) 108 && (((TabStop)other).getLeader() == this.getLeader()) 109 && (((TabStop)other).getAlignment() == this.getAlignment()); 110 } 111 112 /** 113 * Returns the tab alignment. This should be one of {@link #ALIGN_LEFT}, 114 * {@link #ALIGN_CENTER}, {@link #ALIGN_RIGHT}, {@link #ALIGN_DECIMAL} or 115 * {@link #ALIGN_BAR}. 116 * 117 * @return The tab alignment. 118 */ 119 public int getAlignment() 120 { 121 return align; 122 } 123 124 /** 125 * Returns the leader type. This should be one of {@link #LEAD_NONE}, 126 * {@link #LEAD_DOTS}, {@link #LEAD_EQUALS}, {@link #LEAD_HYPHENS}, 127 * {@link #LEAD_THICKLINE} or {@link #LEAD_UNDERLINE}. 128 * 129 * @return The leader type. 130 */ 131 public int getLeader() 132 { 133 return leader; 134 } 135 136 /** 137 * Returns the tab position. 138 * 139 * @return The tab position. 140 */ 141 public float getPosition() 142 { 143 return pos; 144 } 145 146 /** 147 * Returns a hash code for this <code>TabStop</code>. 148 * 149 * @return A hash code. 150 */ 151 public int hashCode() 152 { 153 return (int) pos + (int) leader + (int) align; 154 } 155 156 /** 157 * Returns a string describing this <code>TabStop</code>. 158 * 159 * @return A string describing this <code>TabStop</code>. 160 */ 161 public String toString() 162 { 163 String prefix = ""; 164 switch (align) 165 { 166 case ALIGN_RIGHT: 167 prefix = "right "; 168 break; 169 170 case ALIGN_CENTER: 171 prefix = "center "; 172 break; 173 174 case ALIGN_DECIMAL: 175 prefix = "decimal "; 176 break; 177 178 case ALIGN_BAR: 179 prefix = "bar "; 180 break; 181 182 default: 183 break; 184 } 185 186 return prefix + "tab @" + pos 187 + ((leader == LEAD_NONE) ? "" : " (w/leaders)"); 188 } 189 190 }