1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.editor.textEditor.requests.editTextRequests;
13
14 import java.util.ArrayList;
15 import java.util.List;
16
17 import sk.uniba.euromath.editor.textEditor.ITextPieceKeeper;
18 import sk.uniba.euromath.editor.textEditor.requests.IRequestSpecialization;
19 import sk.uniba.euromath.editor.textEditor.requests.RequestConstants;
20
21 /***
22 * Request to delete text from specified position of specified size. Position is
23 * specified by ITextPieceKeeper and offset. Size specifies deletion direction
24 * and length of text to delete. So effect is deletion of text from
25 * offset(include offset character) in ITextPieceKeeper to offset + size.
26 *
27 * @author Martin Kollar 17.11.2005
28 */
29 public final class DeleteTextRequest extends EditTextRequest implements
30 IRequestSpecialization {
31
32 /***
33 * For structure purpose only. Holds what to delete in view from pieceKeeper
34 * resposibilities.
35 *
36 * @author Tomáš Studva 31.1.2006
37 */
38 public class DeleteInfo {
39 /***
40 * Keeps text where deletion will be executed.
41 */
42 public ITextPieceKeeper pieceKeeper;
43
44 /***
45 * Start(offset in keeper's text) of deletion.
46 */
47 public int start;
48
49 /***
50 * Length of deletion within keeper's text. Always positive.
51 */
52 public int length;
53
54 /***
55 * Constructor.
56 *
57 * @param pieceKeeper
58 * keeps text where deletion will be executed
59 * @param start
60 * start(offset) of deletion
61 * @param length
62 * length of deletion
63 */
64 public DeleteInfo(ITextPieceKeeper pieceKeeper, int start, int length) {
65 this.pieceKeeper = pieceKeeper;
66 this.start = start;
67 this.length = length;
68 }
69 }
70
71 /***
72 * Holds offset in text piece from where text should be deleted.
73 */
74 private int offset;
75
76 /***
77 * Holds deletion direction and length of text to delete. NOT ZERO.
78 */
79 private int size;
80
81 /***
82 * Holds structured delete info.
83 */
84 private final List<DeleteInfo> structuredDeleteInfo;
85
86 /***
87 * Constructor.
88 *
89 * @param source
90 * ITextPieceKeeper where was the deletion called
91 * @param offset
92 * offset in text piece(ITextPieceKeeper's text) from where text
93 * should be deleted, must be valid (in range of text piece).
94 * Character at this offset position is also deleted.
95 * @param size
96 * length of text to delete(absolute value of size) + deletion
97 * direction(signum of size). Negative values are used to delete
98 * text before offset and positive to delete text after offset.
99 * Size can have any integer value(<b>not bounded by text piece</b>),
100 * but text of that size must exist (<b>bounded by text of whole
101 * document</b>), otherwise exception is thrown in process of
102 * execution. NOT ZERO.
103 */
104 public DeleteTextRequest(ITextPieceKeeper source, int offset, int size) {
105 super(source);
106 this.offset = offset;
107 assert (size != 0);
108 this.size = size;
109 this.structuredDeleteInfo = new ArrayList<DeleteInfo>();
110 }
111
112 /***
113 * Constructor.
114 *
115 * @param source
116 * ITextPieceKeeper where was the deletion called
117 * @param offset
118 * offset in text piece(ITextPieceKeeper's text) from where text
119 * should be deleted, must be valid (in range of text piece).
120 * Character at this offset position is also deleted.
121 * @param size
122 * length of text to delete(absolute value of size) + deletion
123 * direction(signum of size). Negative values are used to delete
124 * text before offset and positive to delete text after offset.
125 * Size can have any integer value(<b>not bounded by text piece</b>),
126 * but text of that size must exist (<b>bounded by text of whole
127 * document</b>), otherwise exception is thrown in process of
128 * execution. NOT ZERO.
129 * @param structuredDeleteInfo
130 * Holds additional description what else should be deleted, but
131 * in different format. <b>Can be empty</b>, but in taht case
132 * should be used another contructor. Is used when transforming
133 * standard DeteleTextRequest to structured DeteleTextRequest for
134 * easy command creation and execution. DeleteInfo has big
135 * difference in <b>length vs size</b>.
136 *
137 */
138 public DeleteTextRequest(ITextPieceKeeper source, int offset, int size,
139 List<DeleteInfo> structuredDeleteInfo) {
140 super(source);
141 this.offset = offset;
142 assert (size != 0);
143 this.size = size;
144 assert (structuredDeleteInfo != null);
145 this.structuredDeleteInfo = new ArrayList<DeleteInfo>(
146 structuredDeleteInfo);
147 }
148
149 /***
150 * Returns size - length of text to delete(absolute value of size) +
151 * deletion direction(signum of size).
152 *
153 * @return size of text to delete.
154 * @see #DeleteTextRequest(ITextPieceKeeper, int, int)
155 */
156 public int getSize() {
157 return this.size;
158 }
159
160 /***
161 * Returns position in text piece from where text should be deleted.
162 * Character at this offset position should be also deleted.
163 *
164 * @return offset in text piece (ITextPieceKeeper's text)
165 */
166 public int getOffset() {
167 return this.offset;
168 }
169
170 /***
171 * Returns holded structured delete info. Holds additional description what
172 * else should be deleted.
173 *
174 * @return structuredDeleteInfo <b>can be empty</b>, is used when
175 * transforming standard DeteleTextRequest to structured
176 * DeteleTextRequest for easy command creation and execution.
177 * DeleteInfo has big difference in <b>length vs size</b>.
178 */
179 public List<DeleteInfo> getStructuredDeleteInfo() {
180 return this.structuredDeleteInfo;
181 }
182
183 public String getSpecialization() {
184 return RequestConstants.DELETE_TEXT_REQUEST;
185 }
186
187 /***
188 * @param offset the offset to set
189 */
190 public void setOffset(int offset) {
191 this.offset = offset;
192 }
193
194 /***
195 * @param size the size to set
196 */
197 public void setSize(int size) {
198 this.size = size;
199 }
200
201 }