1
2
3
4
5
6
7
8
9
10
11
12 package sk.uniba.euromath.editor.textEditor;
13
14 import org.eclipse.draw2d.geometry.Point;
15 import org.eclipse.draw2d.geometry.Rectangle;
16
17 import sk.uniba.euromath.editor.figures.IEMFigure;
18
19 /***
20 * Locates(draws) text into (segment of) one text line. Supposed to implement by
21 * classes <b>drawing<b> text into segment of line. Characters of text are
22 * indexed. First character have index 0. All methods works with rendered(drawn)
23 * text.
24 *
25 * @author Tomáš Studva
26 */
27 public interface ITextLocator extends IEMFigure {
28
29 /***
30 * Returns top left point of rectangle bounding character with index
31 * charIndex.
32 *
33 * @param charIndex
34 * index of character in text, charIndex have to be
35 * correct index - non negative and less than text length
36 *
37 * @return new Point reference
38 */
39 public Point getStart(int charIndex);
40
41 /***
42 * Returns top right point of rectangle bounding character with index
43 * charIndex.
44 *
45 * @param charIndex
46 * index of character in text, charIndex have to be
47 * correct index - non negative and less than text length
48 *
49 * @return new Point reference
50 */
51 public Point getEnd(int charIndex);
52
53 /***
54 * Computes index of nearest character placed at given horizontal x
55 * coordinate. If coordinate is out of text bounds, returns zero or last
56 * index, depending on x.
57 *
58 * @param x
59 * horizontal relative coordinate
60 *
61 * @return index of nearest character to coordinate <code>x</code>
62 */
63 public int getNearestCharIndexAtPos(int x);
64
65 /***
66 * Computes index of nearest chararacter gap placed at given horizontal
67 * x coordinate. Character gap is gap between characters, specialls are
68 * gaps at start and end of text. Are index from zero to length of text.
69 * First gap(index 0) is before first character(index 0), last gap(index
70 * length) is after last character(index length -1).<br>
71 * If coordinate is out of text bounds, returns zero or last gap index,
72 * depending on x.
73 *
74 * @param x
75 * horizontal relative coordinate
76 *
77 * @return index of nearest gap to coordinate <code>x</code>
78 */
79 public int getNearestCharGapIndexAtPos(int x);
80
81 /***
82 * Bounds of whole text. Smallest rectangle completely surrounding
83 * located text.
84 *
85 * @return rectangle completely surrounding diplayed text.
86 */
87 public Rectangle getTextBounds();
88
89 /***
90 * Computes bounds of text substring between <code>start</code> and
91 * <code>end</code>. This substring includes character with index
92 * <code>start</code>,but don't include character with index
93 * <code>end</code>.
94 *
95 * @param start
96 * index of first character in result bounds
97 * @param end
98 * index of first character that is not in result bounds
99 * @return Rectangle that bounds substring
100 */
101 public Rectangle getTextBounds(int start, int end);
102
103 /***
104 * Returns text located by this ITextLocator
105 *
106 * @return rendered text.
107 */
108 public String getText();
109
110 /***
111 * Stores the new Text.
112 *
113 * @param text
114 * newText
115 */
116 public void updateText(String text);
117 }