View Javadoc

1   /*
2    * Copyright 1999-2006 Faculty of Mathematics, Physics
3    * and Informatics, Comenius University, Bratislava. This file is protected by
4    * the Mozilla Public License version 1.1 (the License); you may not use this
5    * file except in compliance with the License. You may obtain a copy of the
6    * License at http://euromath2.sourceforge.net/license.html Unless required by
7    * applicable law or agreed to in writing, software distributed under the
8    * License is distributed on an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS
9    * OF ANY KIND, either express or implied. See the License for the specific
10   * language governing permissions and limitations under the License.
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 }