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 Roman I. Chernyatchik
019: * @version $Revision$
020: */package javax.swing.text;
021:
022: import java.io.Serializable;
023:
024: import org.apache.harmony.misc.HashCode;
025:
026: public class TabStop implements Serializable {
027: public static final int ALIGN_LEFT = 0;
028: public static final int ALIGN_RIGHT = 1;
029: public static final int ALIGN_CENTER = 2;
030: public static final int ALIGN_DECIMAL = 4;
031: public static final int ALIGN_BAR = 5;
032:
033: public static final int LEAD_NONE = 0;
034: public static final int LEAD_DOTS = 1;
035: public static final int LEAD_HYPHENS = 2;
036: public static final int LEAD_UNDERLINE = 3;
037: public static final int LEAD_THICKLINE = 4;
038: public static final int LEAD_EQUALS = 5;
039:
040: private final int alignment;
041: private final int leader;
042: private final float position;
043:
044: public TabStop(final float position) {
045: this (position, ALIGN_LEFT, LEAD_NONE);
046: }
047:
048: public TabStop(final float position, final int align,
049: final int leader) {
050: this .position = position;
051: this .alignment = align;
052: this .leader = leader;
053: }
054:
055: public int getAlignment() {
056: return alignment;
057: }
058:
059: public int getLeader() {
060: return leader;
061: }
062:
063: public float getPosition() {
064: return position;
065: }
066:
067: public boolean equals(final Object other) {
068: if (!(other instanceof TabStop)) {
069: return false;
070: }
071:
072: final TabStop tabStop = (TabStop) other;
073: return tabStop.alignment == alignment
074: && tabStop.leader == leader
075: && tabStop.position == position;
076: }
077:
078: public int hashCode() {
079: HashCode hash = new HashCode();
080:
081: hash.append(position);
082: hash.append(alignment);
083: hash.append(leader);
084:
085: return hash.hashCode();
086: }
087:
088: public String toString() {
089: final StringBuffer result = new StringBuffer();
090: switch (alignment) {
091: case ALIGN_RIGHT:
092: result.append("right ");
093: break;
094: case ALIGN_CENTER:
095: result.append("center ");
096: break;
097: case ALIGN_DECIMAL:
098: result.append("decimal ");
099: break;
100: case ALIGN_BAR:
101: result.append("bar ");
102: break;
103: }
104: result.append("tab @").append(position);
105:
106: if (leader != LEAD_NONE) {
107: result.append(" (w/leaders)");
108: }
109:
110: return result.toString();
111: }
112: }
|