Mercurial > projects > dwt-addons
comparison dwtx/jface/text/ListLineTracker.d @ 158:25f1f92fa3df
...
author | Frank Benoit <benoit@tionex.de> |
---|---|
date | Tue, 26 Aug 2008 02:46:34 +0200 |
parents | f70d9508c95c |
children | 7926b636c282 |
comparison
equal
deleted
inserted
replaced
157:7f75eaa8103a | 158:25f1f92fa3df |
---|---|
151 import dwtx.jface.text.DocumentRewriteSessionType; // packageimport | 151 import dwtx.jface.text.DocumentRewriteSessionType; // packageimport |
152 import dwtx.jface.text.TextAttribute; // packageimport | 152 import dwtx.jface.text.TextAttribute; // packageimport |
153 import dwtx.jface.text.ITextViewerExtension4; // packageimport | 153 import dwtx.jface.text.ITextViewerExtension4; // packageimport |
154 import dwtx.jface.text.ITypedRegion; // packageimport | 154 import dwtx.jface.text.ITypedRegion; // packageimport |
155 | 155 |
156 | |
157 import dwt.dwthelper.utils; | 156 import dwt.dwthelper.utils; |
158 | |
159 import dwtx.dwtxhelper.Collection; | 157 import dwtx.dwtxhelper.Collection; |
160 | 158 |
161 | 159 import dwtx.jface.text.AbstractLineTracker; |
162 import dwtx.jface.text.AbstractLineTracker.DelimiterInfo; | |
163 | 160 |
164 /** | 161 /** |
165 * Abstract, read-only implementation of <code>ILineTracker</code>. It lets the definition of | 162 * Abstract, read-only implementation of <code>ILineTracker</code>. It lets the definition of |
166 * line delimiters to subclasses. Assuming that '\n' is the only line delimiter, this abstract | 163 * line delimiters to subclasses. Assuming that '\n' is the only line delimiter, this abstract |
167 * implementation defines the following line scheme: | 164 * implementation defines the following line scheme: |
172 * <li> "a\n" -> [0,2], [2,0] | 169 * <li> "a\n" -> [0,2], [2,0] |
173 * <li> "a\nb" -> [0,2], [2,1] | 170 * <li> "a\nb" -> [0,2], [2,1] |
174 * <li> "a\nbc\n" -> [0,2], [2,3], [5,0] | 171 * <li> "a\nbc\n" -> [0,2], [2,3], [5,0] |
175 * </ul> | 172 * </ul> |
176 * This class must be subclassed. | 173 * This class must be subclassed. |
177 * | 174 * |
178 * @since 3.2 | 175 * @since 3.2 |
179 */ | 176 */ |
180 abstract class ListLineTracker : ILineTracker { | 177 abstract class ListLineTracker : ILineTracker { |
181 | 178 |
182 /** The line information */ | 179 /** The line information */ |
190 protected this() { | 187 protected this() { |
191 } | 188 } |
192 | 189 |
193 /** | 190 /** |
194 * Binary search for the line at a given offset. | 191 * Binary search for the line at a given offset. |
195 * | 192 * |
196 * @param offset the offset whose line should be found | 193 * @param offset the offset whose line should be found |
197 * @return the line of the offset | 194 * @return the line of the offset |
198 */ | 195 */ |
199 private int findLine(int offset) { | 196 private int findLine(int offset) { |
200 | 197 |
232 return left; | 229 return left; |
233 } | 230 } |
234 | 231 |
235 /** | 232 /** |
236 * Returns the number of lines covered by the specified text range. | 233 * Returns the number of lines covered by the specified text range. |
237 * | 234 * |
238 * @param startLine the line where the text range starts | 235 * @param startLine the line where the text range starts |
239 * @param offset the start offset of the text range | 236 * @param offset the start offset of the text range |
240 * @param length the length of the text range | 237 * @param length the length of the text range |
241 * @return the number of lines covered by this text range | 238 * @return the number of lines covered by this text range |
242 * @exception BadLocationException if range is undefined in this tracker | 239 * @exception BadLocationException if range is undefined in this tracker |
391 * @see dwtx.jface.text.ILineTracker#computeNumberOfLines(java.lang.String) | 388 * @see dwtx.jface.text.ILineTracker#computeNumberOfLines(java.lang.String) |
392 */ | 389 */ |
393 public final int computeNumberOfLines(String text) { | 390 public final int computeNumberOfLines(String text) { |
394 int count= 0; | 391 int count= 0; |
395 int start= 0; | 392 int start= 0; |
396 DelimiterInfo delimiterInfo= nextDelimiterInfo(text, start); | 393 AbstractLineTracker.DelimiterInfo delimiterInfo= nextDelimiterInfo(text, start); |
397 while (delimiterInfo !is null && delimiterInfo.delimiterIndex > -1) { | 394 while (delimiterInfo !is null && delimiterInfo.delimiterIndex > -1) { |
398 ++count; | 395 ++count; |
399 start= delimiterInfo.delimiterIndex + delimiterInfo.delimiterLength; | 396 start= delimiterInfo.delimiterIndex + delimiterInfo.delimiterLength; |
400 delimiterInfo= nextDelimiterInfo(text, start); | 397 delimiterInfo= nextDelimiterInfo(text, start); |
401 } | 398 } |
422 } | 419 } |
423 | 420 |
424 /** | 421 /** |
425 * Returns the information about the first delimiter found in the given text starting at the | 422 * Returns the information about the first delimiter found in the given text starting at the |
426 * given offset. | 423 * given offset. |
427 * | 424 * |
428 * @param text the text to be searched | 425 * @param text the text to be searched |
429 * @param offset the offset in the given text | 426 * @param offset the offset in the given text |
430 * @return the information of the first found delimiter or <code>null</code> | 427 * @return the information of the first found delimiter or <code>null</code> |
431 */ | 428 */ |
432 protected abstract DelimiterInfo nextDelimiterInfo(String text, int offset); | 429 protected abstract AbstractLineTracker.DelimiterInfo nextDelimiterInfo(String text, int offset); |
433 | 430 |
434 /** | 431 /** |
435 * Creates the line structure for the given text. Newly created lines are inserted into the line | 432 * Creates the line structure for the given text. Newly created lines are inserted into the line |
436 * structure starting at the given position. Returns the number of newly created lines. | 433 * structure starting at the given position. Returns the number of newly created lines. |
437 * | 434 * |
438 * @param text the text for which to create a line structure | 435 * @param text the text for which to create a line structure |
439 * @param insertPosition the position at which the newly created lines are inserted into the | 436 * @param insertPosition the position at which the newly created lines are inserted into the |
440 * tracker's line structure | 437 * tracker's line structure |
441 * @param offset the offset of all newly created lines | 438 * @param offset the offset of all newly created lines |
442 * @return the number of newly created lines | 439 * @return the number of newly created lines |
443 */ | 440 */ |
444 private int createLines(String text, int insertPosition, int offset) { | 441 private int createLines(String text, int insertPosition, int offset) { |
445 | 442 |
446 int count= 0; | 443 int count= 0; |
447 int start= 0; | 444 int start= 0; |
448 DelimiterInfo delimiterInfo= nextDelimiterInfo(text, 0); | 445 AbstractLineTracker.DelimiterInfo delimiterInfo= nextDelimiterInfo(text, 0); |
449 | 446 |
450 while (delimiterInfo !is null && delimiterInfo.delimiterIndex > -1) { | 447 while (delimiterInfo !is null && delimiterInfo.delimiterIndex > -1) { |
451 | 448 |
452 int index= delimiterInfo.delimiterIndex + (delimiterInfo.delimiterLength - 1); | 449 int index= delimiterInfo.delimiterIndex + (delimiterInfo.delimiterLength - 1); |
453 | 450 |
496 } | 493 } |
497 | 494 |
498 /** | 495 /** |
499 * Returns the internal data structure, a {@link List} of {@link Line}s. Used only by | 496 * Returns the internal data structure, a {@link List} of {@link Line}s. Used only by |
500 * {@link TreeLineTracker#TreeLineTracker(ListLineTracker)}. | 497 * {@link TreeLineTracker#TreeLineTracker(ListLineTracker)}. |
501 * | 498 * |
502 * @return the internal list of lines. | 499 * @return the internal list of lines. |
503 */ | 500 */ |
504 final List getLines() { | 501 final List getLines() { |
505 return fLines; | 502 return fLines; |
506 } | 503 } |