899 |
|
|
900 |
/** |
/** |
901 |
* Returns the paragraph element for the specified position. |
* Returns the paragraph element for the specified position. |
902 |
|
* If the position is outside the bounds of the document's root element, |
903 |
|
* then the closest element is returned. That is the last paragraph if |
904 |
|
* <code>position >= endIndex</code> or the first paragraph if |
905 |
|
* <code>position < startIndex</code>. |
906 |
* |
* |
907 |
* @param position the position for which to query the paragraph element |
* @param position the position for which to query the paragraph element |
908 |
* |
* |
911 |
public Element getParagraphElement(int position) |
public Element getParagraphElement(int position) |
912 |
{ |
{ |
913 |
BranchElement root = (BranchElement) getDefaultRootElement(); |
BranchElement root = (BranchElement) getDefaultRootElement(); |
914 |
|
int start = root.getStartOffset(); |
915 |
|
int end = root.getEndOffset(); |
916 |
|
if (position >= end) |
917 |
|
position = end - 1; |
918 |
|
else if (position < start) |
919 |
|
position = start; |
920 |
|
|
921 |
Element par = root.positionToElement(position); |
Element par = root.positionToElement(position); |
922 |
|
|
923 |
|
assert par != null : "The paragraph element must not be null"; |
924 |
return par; |
return par; |
925 |
} |
} |
926 |
|
|