]> gitweb.fperrin.net Git - Dictionary.git/blob - jars/icu4j-4_2_1-src/src/com/ibm/richtext/textpanel/TextChangeCommand.java
icu4jsrc
[Dictionary.git] / jars / icu4j-4_2_1-src / src / com / ibm / richtext / textpanel / TextChangeCommand.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.textpanel;\r
14 \r
15 import com.ibm.richtext.styledtext.MConstText;\r
16 import com.ibm.richtext.styledtext.MText;\r
17 import com.ibm.richtext.textformat.TextOffset;\r
18 \r
19 class TextChangeCommand extends TextCommand {\r
20     static final String COPYRIGHT =\r
21                 "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";\r
22     private MConstText fNewText;\r
23     private TextOffset fSelStartAfter;\r
24     private TextOffset fSelEndAfter;\r
25 \r
26     public TextChangeCommand(TextEditBehavior behavior,\r
27                              MText originalText,\r
28                              MConstText newText,\r
29                              int affectedRangeStart,\r
30                              TextOffset selStartBefore,\r
31                              TextOffset selEndBefore,\r
32                              TextOffset selStartAfter,\r
33                              TextOffset selEndAfter) {\r
34         super(behavior, originalText, affectedRangeStart, selStartBefore, selEndBefore);\r
35         fNewText = newText;\r
36         fSelStartAfter = new TextOffset();\r
37         fSelStartAfter.assign(selStartAfter);\r
38         fSelEndAfter = new TextOffset();\r
39         fSelEndAfter.assign(selEndAfter);\r
40     }\r
41 \r
42     public int affectedRangeEnd() {\r
43         if (fNewText == null)\r
44             return fAffectedRangeStart;\r
45         else\r
46             return fAffectedRangeStart + fNewText.length();\r
47     }\r
48 \r
49     public void execute() {\r
50         fBehavior.doReplaceText(fAffectedRangeStart, fAffectedRangeStart + fOriginalText.length(),\r
51                             fNewText, fSelStartAfter, fSelEndAfter);\r
52     }\r
53 \r
54     public int affectedRangeStart() {\r
55         return fAffectedRangeStart;\r
56     }\r
57 \r
58     public void setNewText(MConstText newText) {\r
59         fNewText = newText;\r
60     }\r
61 \r
62     public void setSelRangeAfter(TextOffset start, TextOffset end) {\r
63         if (fSelStartAfter == null)\r
64             fSelStartAfter = new TextOffset();\r
65         if (fSelEndAfter == null)\r
66             fSelEndAfter = new TextOffset();\r
67         fSelStartAfter.assign(start);\r
68         fSelEndAfter.assign(end);\r
69     }\r
70 \r
71     public void prependToOldText(MConstText newText) {\r
72         fOriginalText.insert(0, newText);\r
73         fAffectedRangeStart -= newText.length();\r
74     }\r
75 \r
76     public void appendToOldText(MConstText newText) {\r
77         fOriginalText.append(newText);\r
78     }\r
79 }\r