01: /*
02: * (C) Copyright IBM Corp. 1998-2004. All Rights Reserved.
03: *
04: * The program is provided "as is" without any warranty express or
05: * implied, including the warranty of non-infringement and the implied
06: * warranties of merchantibility and fitness for a particular purpose.
07: * IBM will not be liable for any damages suffered by you as a result
08: * of using the Program. In no event will IBM be liable for any
09: * special, indirect or consequential damages or lost profits even if
10: * IBM has been advised of the possibility of their occurrence. IBM
11: * will not be liable for any third party claims against you.
12: */
13: package com.ibm.richtext.textpanel;
14:
15: import com.ibm.richtext.styledtext.MConstText;
16: import com.ibm.richtext.styledtext.MText;
17: import com.ibm.richtext.textformat.TextOffset;
18:
19: class TextChangeCommand extends TextCommand {
20: static final String COPYRIGHT = "(C) Copyright IBM Corp. 1998-1999 - All Rights Reserved";
21: private MConstText fNewText;
22: private TextOffset fSelStartAfter;
23: private TextOffset fSelEndAfter;
24:
25: public TextChangeCommand(TextEditBehavior behavior,
26: MText originalText, MConstText newText,
27: int affectedRangeStart, TextOffset selStartBefore,
28: TextOffset selEndBefore, TextOffset selStartAfter,
29: TextOffset selEndAfter) {
30: super (behavior, originalText, affectedRangeStart,
31: selStartBefore, selEndBefore);
32: fNewText = newText;
33: fSelStartAfter = new TextOffset();
34: fSelStartAfter.assign(selStartAfter);
35: fSelEndAfter = new TextOffset();
36: fSelEndAfter.assign(selEndAfter);
37: }
38:
39: public int affectedRangeEnd() {
40: if (fNewText == null)
41: return fAffectedRangeStart;
42: else
43: return fAffectedRangeStart + fNewText.length();
44: }
45:
46: public void execute() {
47: fBehavior.doReplaceText(fAffectedRangeStart,
48: fAffectedRangeStart + fOriginalText.length(), fNewText,
49: fSelStartAfter, fSelEndAfter);
50: }
51:
52: public int affectedRangeStart() {
53: return fAffectedRangeStart;
54: }
55:
56: public void setNewText(MConstText newText) {
57: fNewText = newText;
58: }
59:
60: public void setSelRangeAfter(TextOffset start, TextOffset end) {
61: if (fSelStartAfter == null)
62: fSelStartAfter = new TextOffset();
63: if (fSelEndAfter == null)
64: fSelEndAfter = new TextOffset();
65: fSelStartAfter.assign(start);
66: fSelEndAfter.assign(end);
67: }
68:
69: public void prependToOldText(MConstText newText) {
70: fOriginalText.insert(0, newText);
71: fAffectedRangeStart -= newText.length();
72: }
73:
74: public void appendToOldText(MConstText newText) {
75: fOriginalText.append(newText);
76: }
77: }
|