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.Direction;
18 import sk.uniba.euromath.editor.textEditor.ITextPieceKeeper;
19 import sk.uniba.euromath.editor.textEditor.requests.IRequestSpecialization;
20 import sk.uniba.euromath.editor.textEditor.requests.RequestConstants;
21
22 /***
23 * Request to delete text from specified position of specified size. Position is
24 * specified by ITextPieceKeeper and offset. Size specifies deletion direction
25 * and length of text to delete. So effect is deletion of text from
26 * offset(include offset character) in ITextPieceKeeper to offset + size
27 * (including).
28 *
29 * @author Martin Kollar 17.11.2005
30 */
31 public final class DeleteTextRequest extends EditTextRequest implements
32 IRequestSpecialization {
33
34 /***
35 * Holds offset in text piece from where text should be deleted.
36 */
37 private int offset;
38
39 /***
40 * Holds length of text to delete. NOT ZERO.
41 */
42 private int length;
43
44 /***
45 * Holds direction of deletion.
46 */
47 private Direction direction;
48
49 /***
50 * Constructor.
51 *
52 * @param source
53 * ITextPieceKeeper where was the deletion called
54 * @param offset
55 * offset in text piece(ITextPieceKeeper's text) from
56 * where text should be deleted, must be valid (in range
57 * of text piece). Character at this offset position is
58 * also deleted.
59 * @param size
60 * length of text to delete(absolute value of size)
61 * Length can have any positive value(<b>not bounded by
62 * text piece</b>), but text at that length must exists (<b>bounded
63 * by text of whole document</b>), otherwise exception
64 * is thrown in process of execution. NOT ZERO.
65 * @param direction
66 * of deletion, one of {@link Direction#Left},
67 * {@link Direction#Right}
68 */
69 public DeleteTextRequest(ITextPieceKeeper source, int offset,
70 int length, Direction direction) {
71 super(source);
72 assert (length != 0);
73
74 this.offset = offset;
75 this.length = length;
76 this.direction = direction;
77 }
78
79 /***
80 * Returns length of text to delete.
81 *
82 * @return length of text to delete.
83 */
84 public int getLength() {
85 return this.length;
86 }
87
88 /***
89 * Returns position in text piece from where text should be deleted.
90 * Character at this offset position should be also deleted.
91 *
92 * @return offset in text piece (ITextPieceKeeper's text)
93 */
94 public int getOffset() {
95 return this.offset;
96 }
97
98 public Direction getDirection() {
99 return this.direction;
100 }
101
102 public String getSpecialization() {
103 return RequestConstants.DELETE_TEXT_REQUEST;
104 }
105
106 /***
107 * @param offset
108 * the offset to set
109 */
110 public void setOffset(int offset) {
111 this.offset = offset;
112 }
113
114 /***
115 * @param length
116 * the length to set
117 */
118 public void setLength(int length) {
119 assert (length != 0);
120 this.length = length;
121 }
122 }