2 Copyright (C) 2004, 2006, Free Software Foundation, Inc.
4 This file is part of GNU Classpath.
6 GNU Classpath is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2, or (at your option)
11 GNU Classpath is distributed in the hope that it will be useful, but
12 WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14 General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with GNU Classpath; see the file COPYING. If not, write to the
18 Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
21 Linking this library statically or dynamically with other modules is
22 making a combined work based on this library. Thus, the terms and
23 conditions of the GNU General Public License cover the whole
26 As a special exception, the copyright holders of this library give you
27 permission to link this library with independent modules to produce an
28 executable, regardless of the license terms of these independent
29 modules, and to copy and distribute the resulting executable under
30 terms of your choice, provided that you also meet, for each linked
31 independent module, the terms and conditions of the license of that
32 module. An independent module is a module which is not derived from
33 or based on this library. If you modify this library, you may extend
34 this exception to your version of the library, but you are not
35 obligated to do so. If you do not wish to do so, delete this
36 exception statement from your version. */
38 package javax.swing.text;
40 import java.io.Serializable;
43 * A set of tab stops. Instances of this class are immutable.
45 public class TabSet implements Serializable
47 /** The serialization UID (compatible with JDK1.5). */
48 private static final long serialVersionUID = 2367703481999080593L;
50 /** Storage for the tab stops. */
54 * Creates a new <code>TabSet</code> containing the specified tab stops.
56 * @param t the tab stops (<code>null</code> permitted).
58 public TabSet(TabStop[] t)
61 tabs = (TabStop[]) t.clone();
63 tabs = new TabStop[0];
67 * Returns the tab stop with the specified index.
71 * @return The tab stop.
73 * @throws IllegalArgumentException if <code>i</code> is not in the range
74 * <code>0</code> to <code>getTabCount() - 1</code>.
76 public TabStop getTab(int i)
78 if (i < 0 || i >= tabs.length)
79 throw new IllegalArgumentException("Index out of bounds.");
84 * Returns the tab following the specified location.
86 * @param location the location.
88 * @return The tab following the specified location (or <code>null</code>).
90 public TabStop getTabAfter(float location)
92 int idx = getTabIndexAfter(location);
100 * Returns the number of tab stops in this tab set.
102 * @return The number of tab stops in this tab set.
104 public int getTabCount()
110 * Returns the index of the specified tab, or -1 if the tab is not found.
112 * @param tab the tab (<code>null</code> permitted).
114 * @return The index of the specified tab, or -1.
116 public int getTabIndex(TabStop tab)
118 for (int i = 0; i < tabs.length; ++i)
125 * Returns the index of the tab at or after the specified location.
127 * @param location the tab location.
129 * @return The index of the tab stop, or -1.
131 public int getTabIndexAfter(float location)
133 for (int i = 0; i < tabs.length; i++)
135 if (location <= tabs[i].getPosition())
142 * Tests this <code>TabSet</code> for equality with an arbitrary object.
144 * @param obj the object (<code>null</code> permitted).
146 * @return <code>true</code> if this <code>TabSet</code> is equal to
147 * <code>obj</code>, and <code>false</code> otherwise.
151 public boolean equals(Object obj)
155 if (!(obj instanceof TabSet))
157 TabSet that = (TabSet) obj;
158 int tabCount = getTabCount();
159 if (tabCount != that.getTabCount())
161 for (int i = 0; i < tabCount; i++)
163 if (!this.getTab(i).equals(that.getTab(i)))
170 * Returns a hash code for this <code>TabSet</code>.
172 * @return A hash code.
176 public int hashCode()
178 // this hash code won't match Sun's, but that shouldn't matter...
180 int tabs = getTabCount();
181 for (int i = 0; i < tabs; i++)
183 TabStop t = getTab(i);
185 result = 37 * result + t.hashCode();
191 * Returns a string representation of this <code>TabSet</code>.
193 * @return A string representation of this <code>TabSet</code>.
195 public String toString()
197 StringBuffer sb = new StringBuffer();
199 for (int i = 0; i < tabs.length; ++i)
203 sb.append(tabs[i].toString());
206 return sb.toString();