]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/styledtext/MTabRuler.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / styledtext / MTabRuler.java
1 /*\r
2  * (C) Copyright IBM Corp. 1998-2004.  All Rights Reserved.\r
3  *\r
4  * The program is provided "as is" without any warranty express or\r
5  * implied, including the warranty of non-infringement and the implied\r
6  * warranties of merchantibility and fitness for a particular purpose.\r
7  * IBM will not be liable for any damages suffered by you as a result\r
8  * of using the Program. In no event will IBM be liable for any\r
9  * special, indirect or consequential damages or lost profits even if\r
10  * IBM has been advised of the possibility of their occurrence. IBM\r
11  * will not be liable for any third party claims against you.\r
12  */\r
13 package com.ibm.richtext.styledtext;\r
14 \r
15 /**\r
16  * This interface represents a sequence of TabStops, ordered by position.\r
17  * The first\r
18  * TabStop in the ruler can be obtained with the <code>firstTab</code>\r
19  * method;  subsequent TabStops are obtained with the <code>nextTab</code>\r
20  * method.\r
21  * <p>\r
22  * If a TabStop with type <code>TabStop.kAuto</code> is returned, all tabs\r
23  * after that TabStop will also have type <code>TabStop.kAuto</code>, and\r
24  * their positions will be multiples of <code>autoSpacing</code>.\r
25  * @see TabStop\r
26  */\r
27 public abstract class MTabRuler\r
28 {\r
29     static final String COPYRIGHT =\r
30                 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";\r
31     /**\r
32      * Return first tab in the ruler.  If an autoTab, it is at position zero, and\r
33      * all subsequent tabs will be autotabs at autoSpacing intervals.\r
34      */\r
35     public abstract TabStop firstTab();\r
36 \r
37     /**\r
38      * Return the first tab in the ruler with fPosition > position.  If it is an\r
39      * autotab, it is at an increment of autoSpacing, and all subsequent tabs will be\r
40      * autotabs at autoSpacing intervals.\r
41      */\r
42     public abstract TabStop nextTab(int position);\r
43 \r
44     /**\r
45      * Return the interval for autotabs.\r
46      */\r
47     public abstract int autoSpacing();\r
48 \r
49     /**\r
50      * Compute the hashCode for this ruler.  The hashCode is the\r
51      * hashCode of the first tab multiplied by the autoSpacing\r
52      * interval.\r
53      */\r
54     public final int hashCode() {\r
55 \r
56         return firstTab().hashCode() * autoSpacing();\r
57     }\r
58 \r
59     /**\r
60      * Return true if this tab ruler contains the given tab.\r
61      * @param tabToTest the tab to search for\r
62      * @return true if this tab ruler contains <code>tabToTest</code>\r
63      */\r
64     public boolean containsTab(TabStop tabToTest) {\r
65 \r
66         for (TabStop tab = firstTab();\r
67                         tab.getType() != TabStop.kAuto;\r
68                         tab = nextTab(tab.getPosition())) {\r
69             if (tab.getPosition() >= tabToTest.getPosition()) {\r
70                 return tabToTest.equals(tab);\r
71             }\r
72         }\r
73 \r
74         return false;\r
75     }\r
76 \r
77     /**\r
78      * Return a tab ruler identical to this ruler, except with the\r
79      * given tab added.  This ruler is not modified.\r
80      * @param tabToAdd the tab to add to the new tab ruler\r
81      * @return an MTabRuler resulting from this operation\r
82      */\r
83     public MTabRuler addTab(TabStop tabToAdd) {\r
84 \r
85         return StandardTabRuler.addTabToRuler(this, tabToAdd);\r
86     }\r
87 \r
88     /**\r
89      * Return a tab ruler identical to the given ruler, except with the\r
90      * tab at the given position removed.  This ruler is not modified.\r
91      * @param position the position of the tab to remove from the new tab ruler\r
92      * @return an MTabRuler resulting from this operation\r
93      */\r
94     public MTabRuler removeTab(int position) {\r
95 \r
96         return StandardTabRuler.removeTabFromRuler(this, position);\r
97     }\r
98 \r
99     /**\r
100      * Return a tab ruler identical to this ruler, except with the\r
101      * tab at position <code>fromPosition</code> moved to position\r
102      * <code>toPosition</code>.  This ruler is not modified.\r
103      * @param fromPosition the position of the tab to move\r
104      * @param toPosition the new position of the tab\r
105      * @return an MTabRuler resulting from this operation\r
106      */\r
107     public MTabRuler moveTab(int fromPosition, int toPosition) {\r
108 \r
109         return StandardTabRuler.moveTabOnRuler(this, fromPosition, toPosition);\r
110     }\r
111 }