001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Alexey A. Ivanov
019: * @version $Revision$
020: */package javax.swing.text;
021:
022: import java.io.Serializable;
023:
024: import org.apache.harmony.misc.HashCode;
025:
026: import org.apache.harmony.x.swing.internal.nls.Messages;
027:
028: public class TabSet implements Serializable {
029:
030: private TabStop[] tabs;
031:
032: public TabSet(final TabStop[] tabs) {
033: this .tabs = new TabStop[tabs.length];
034: System.arraycopy(tabs, 0, this .tabs, 0, tabs.length);
035: }
036:
037: public boolean equals(final Object obj) {
038: if (obj == this ) {
039: return true;
040: }
041: if (!(obj instanceof TabSet)) {
042: return false;
043: }
044: final TabSet aTabSet = (TabSet) obj;
045: boolean result = tabs.length == aTabSet.tabs.length;
046: for (int i = 0; i < tabs.length && result; i++) {
047: result = tabs[i].equals(aTabSet.tabs[i]);
048: }
049:
050: return result;
051: }
052:
053: public TabStop getTab(final int i) {
054: if (i < 0 || i >= tabs.length) {
055: throw new IllegalArgumentException(Messages.getString(
056: "swing.9C", i)); //$NON-NLS-1$
057: }
058: return tabs[i];
059: }
060:
061: public TabStop getTabAfter(final float location) {
062: int index = getTabIndexAfter(location);
063: if (index != -1) {
064: return tabs[index];
065: }
066:
067: return null;
068: }
069:
070: public int getTabCount() {
071: return tabs.length;
072: }
073:
074: public int getTabIndex(final TabStop tab) {
075: for (int i = 0; i < tabs.length; i++) {
076: if (tabs[i].equals(tab)) {
077: return i;
078: }
079: }
080:
081: return -1;
082: }
083:
084: public int getTabIndexAfter(final float location) {
085: for (int i = 0; i < tabs.length; i++) {
086: if (tabs[i].getPosition() > location) {
087: return i;
088: }
089: }
090:
091: return -1;
092: }
093:
094: public int hashCode() {
095: HashCode hash = new HashCode();
096: for (int i = 0; i < tabs.length; i++) {
097: hash = hash.append(tabs[i].hashCode());
098: }
099: return hash.hashCode();
100: }
101:
102: public String toString() {
103: StringBuffer result = new StringBuffer("[ ");
104: for (int i = 0; i < tabs.length; i++) {
105: if (i != 0) {
106: result.append(" - ");
107: }
108: result.append(tabs[i].toString());
109: }
110: result.append(" ]");
111:
112: return result.toString();
113: }
114: }
|