26
|
1 |
/*
|
|
2 |
* Copyright (c) 2009 Nokia Corporation and/or its subsidiary(-ies).
|
|
3 |
* All rights reserved.
|
|
4 |
* This component and the accompanying materials are made available
|
|
5 |
* under the terms of "Eclipse Public License v1.0"
|
|
6 |
* which accompanies this distribution, and is available
|
|
7 |
* at the URL "http://www.eclipse.org/legal/epl-v10.html".
|
|
8 |
*
|
|
9 |
* Initial Contributors:
|
|
10 |
* Nokia Corporation - initial contribution.
|
|
11 |
*
|
|
12 |
* Contributors:
|
|
13 |
*
|
|
14 |
* Description: Public class defining the interface for MIDP Text Editor
|
|
15 |
*
|
|
16 |
*/
|
|
17 |
|
|
18 |
// PACKAGE
|
|
19 |
package com.nokia.mid.ui;
|
|
20 |
|
|
21 |
// INTERNAL IMPORTS
|
|
22 |
import com.nokia.mid.ui.impl.LCDUIPackageInvoker;
|
|
23 |
import com.nokia.mid.ui.impl.TextEditorListenerImpl;
|
|
24 |
import com.nokia.mid.ui.impl.TextEditorContainer;
|
|
25 |
|
|
26 |
// EXTERNAL IMPORTS
|
|
27 |
import com.nokia.mj.impl.rt.legacy.NativeError;
|
|
28 |
import com.nokia.mj.impl.rt.legacy.ToolkitInvoker;
|
|
29 |
import com.nokia.mid.ui.CanvasItem;
|
|
30 |
import javax.microedition.lcdui.Font;
|
|
31 |
import javax.microedition.lcdui.Canvas;
|
|
32 |
import javax.microedition.lcdui.CustomItem;
|
|
33 |
import javax.microedition.lcdui.TextField;
|
|
34 |
import java.util.Enumeration;
|
|
35 |
import com.nokia.mj.impl.rt.support.Finalizer;
|
|
36 |
|
|
37 |
/**
|
|
38 |
* <P>
|
|
39 |
* A <code>TextEditor</code> is an editable text component that is used with a
|
|
40 |
* parent object; with <code>Canvas</code> or <code>CustomItem</code>. The
|
|
41 |
* <code>TextEditor</code> maybe set to and removed from <code>Canvas</code>
|
|
42 |
* through <code>setParent()</code> method.
|
|
43 |
* </P>
|
|
44 |
*
|
|
45 |
* <P>
|
|
46 |
* The implementation presents the <code>TextEditor</code> with minimal
|
|
47 |
* decoration; only the caret is shown at the requested text insertion position.
|
|
48 |
* It is the responsibility of the application to draw any additional decoration
|
|
49 |
* like focus highlight, border or scroll bar. The animation of the caret, e.g.
|
|
50 |
* blinking, is handled by the TextEditor implementation.
|
|
51 |
* </P>
|
|
52 |
*
|
|
53 |
* <P>
|
|
54 |
* <code>TextEditor</code> supports <em>input constraints</em> identically to
|
|
55 |
* <code>TextField</code>. See <a href="TextField.html#constraints">input
|
|
56 |
* constraints</a> section in the <code>TextField</code> for the definition of
|
|
57 |
* these constants. In addition <code>TextEditor</code> has the same concept of
|
|
58 |
* <em>actual contents</em> and <em>displayed contents</em> as
|
|
59 |
* <code>TextField</code>; these are described in the same <a
|
|
60 |
* href="TextField.html#constraints">input constraints</a> section.
|
|
61 |
* </P>
|
|
62 |
*
|
|
63 |
* <P>
|
|
64 |
* <code>TextEditor</code> supports <em>input modes</em> identically to
|
|
65 |
* <code>TextField</code>. See <a href="TextField.html#modes">input modes</a>
|
|
66 |
* section in the <code>TextField</code> for the definition of these constants.
|
|
67 |
* </P>
|
|
68 |
*
|
|
69 |
* <P>
|
|
70 |
* The text may contain <A HREF="Form.html#linebreak">line breaks</A>. The
|
|
71 |
* display of the text must break accordingly and the user must be able to enter
|
|
72 |
* line break characters.
|
|
73 |
* </P>
|
|
74 |
*
|
|
75 |
* <P>
|
|
76 |
* The TextEditor provides necessary interaction for example for touch input
|
|
77 |
* (handwriting recognition) on touch screen devices and selection of additional
|
|
78 |
* characters. The input on touch devices requires additional windows of top of
|
|
79 |
* the editor window which depending on the implementation may obscure the
|
|
80 |
* parent completely.
|
|
81 |
* </P>
|
|
82 |
*
|
|
83 |
* <P>
|
|
84 |
* Application can add a TextEditorListener to the <code>TextEditor</code> for
|
|
85 |
* example for keeping track of user navigation (caret movement) and other
|
|
86 |
* content changes such as text selection. The events are sent on all occasions
|
|
87 |
* that cause the the caret position to change (including but not limited to
|
|
88 |
* text typing by user, programmatic text insertion, navigation within the
|
|
89 |
* <code>TextEditor</code> content, and text deletion). The events must be sent
|
|
90 |
* to the application prior to they have effect on the editor - for example an
|
|
91 |
* event indicating caret movement must be available for the application before
|
|
92 |
* the implementation actually moves the caret in the editor.
|
|
93 |
* </P>
|
|
94 |
*
|
|
95 |
* <P>
|
|
96 |
* When the <code>TextEditor</code> has focus all the key events that are not
|
|
97 |
* consumed by <code>TextEditor</code> with the current constraints or mapped to
|
|
98 |
* Commands by the implementation are sent to <code>Canvas</code>.
|
|
99 |
* </P>
|
|
100 |
*
|
|
101 |
* <P>
|
|
102 |
* Touch pointer events are not delivered to parent object from the area of the
|
|
103 |
* visible TextEditor.
|
|
104 |
* </P>
|
|
105 |
*
|
|
106 |
* <P>
|
|
107 |
* The implementation will scroll the <code>TextEditor</code> content
|
|
108 |
* automatically on user interaction and when the application calls setCaret or
|
|
109 |
* setSelection methods. For example if a user clicks down on the last visible
|
|
110 |
* row the <code>TextEditor</code> content is scrolled accordingly by one row.
|
|
111 |
* However the Java platform implementation does not draw any scroll bars, this
|
|
112 |
* is left to the application.
|
|
113 |
* </P>
|
|
114 |
*
|
|
115 |
* @since 1.4
|
|
116 |
*/
|
|
117 |
|
|
118 |
public class TextEditor
|
|
119 |
extends CanvasItem
|
|
120 |
{
|
|
121 |
|
|
122 |
// Protected data for extending classes.
|
|
123 |
|
|
124 |
// LCDUI Toolkit object.
|
|
125 |
Object iToolkit;
|
|
126 |
|
|
127 |
// Native handle
|
|
128 |
int iHandle;
|
|
129 |
|
|
130 |
// LCDUI package invoker.
|
|
131 |
LCDUIPackageInvoker iLCDUIPackageInvoker;
|
|
132 |
|
|
133 |
// Change listener. May be NULL.
|
|
134 |
TextEditorListenerImpl iListener;
|
|
135 |
|
|
136 |
// Private data
|
|
137 |
|
|
138 |
// LCDUI Toolkit invoker object.
|
|
139 |
private ToolkitInvoker iToolkitInvoker;
|
|
140 |
// The current set of constraints of this text editor component.
|
|
141 |
private int iConstraints;
|
|
142 |
|
|
143 |
// Initial input mode
|
|
144 |
private java.lang.String iCharacterSubset;
|
|
145 |
|
|
146 |
// The current maximum size of this text editor component.
|
|
147 |
private int iMaxSize;
|
|
148 |
|
|
149 |
// The current font of this text editor component
|
|
150 |
private Font iFont;
|
|
151 |
|
|
152 |
// Text editor container for handling editor focusing.
|
|
153 |
private static TextEditorContainer iEditorContainer;
|
|
154 |
|
|
155 |
// Color indicators. Must be in sync with MMIDTextEditor::TColorType
|
|
156 |
private static final int COLOR_BACKGROUND = 0;
|
|
157 |
private static final int COLOR_FOREGROUND = 1;
|
|
158 |
private static final int COLOR_HIGHLIGHT_BACKGROUND = 2;
|
|
159 |
private static final int COLOR_HIGHLIGHT_FOREGROUND = 3;
|
|
160 |
|
|
161 |
// The maximum value for all colors.
|
|
162 |
private static final int COLOR_MAX_VALUE = 255;
|
|
163 |
|
|
164 |
// Static block for creating editor container.
|
|
165 |
static
|
|
166 |
{
|
|
167 |
iEditorContainer = new TextEditorContainer();
|
|
168 |
}
|
|
169 |
|
|
170 |
private Finalizer mFinalizer;
|
|
171 |
|
|
172 |
/**
|
|
173 |
* <P>
|
|
174 |
* Creates a new <code>TextEditor</code> object with the given initial
|
|
175 |
* contents, maximum size in characters, constraints and editor size in
|
|
176 |
* pixels.
|
|
177 |
* </P>
|
|
178 |
*
|
|
179 |
* <P>
|
|
180 |
* If the text parameter is <code>null</code>, the <code>TextEditor</code>
|
|
181 |
* is created empty.
|
|
182 |
* </P>
|
|
183 |
*
|
|
184 |
* <P>
|
|
185 |
* The <code>maxSize</code> parameter must be greater than zero. An
|
|
186 |
* <code>IllegalArgumentException</code> is thrown if the length of the
|
|
187 |
* initial contents string exceeds <code>maxSize</code>. However, the
|
|
188 |
* implementation may assign a maximum size smaller than the application had
|
|
189 |
* requested. If this occurs, and if the length of the contents exceeds the
|
|
190 |
* newly assigned maximum size, the contents are truncated from the end in
|
|
191 |
* order to fit, and no exception is thrown.
|
|
192 |
* </P>
|
|
193 |
*
|
|
194 |
* <P>
|
|
195 |
* On Series60-devices the object returned by this method will also
|
|
196 |
* implement the com.nokia.mid.ui.S60TextEditor.
|
|
197 |
* </P>
|
|
198 |
*
|
|
199 |
* @param text
|
|
200 |
* the initial contents, or <code>null</code> if the
|
|
201 |
* <code>TextEditor</code> is to be created empty
|
|
202 |
* @param maxSize
|
|
203 |
* the maximum capacity in characters
|
|
204 |
* @param constraints
|
|
205 |
* see the input constraints in <code>TextField</code></a>
|
|
206 |
* @param width
|
|
207 |
* the width of the bounding box, in pixels
|
|
208 |
* @param height
|
|
209 |
* the height of the bounding box, in pixels
|
|
210 |
* @return Instance of TextEditor
|
|
211 |
*
|
|
212 |
* @throws IllegalArgumentException
|
|
213 |
* if <code>aMaxSize</code> is zero or less
|
|
214 |
* @throws IllegalArgumentException
|
|
215 |
* if the value of the constraints parameter is invalid
|
|
216 |
* @throws IllegalArgumentException
|
|
217 |
* if <code>aText</code> is illegal for the specified
|
|
218 |
* constraints
|
|
219 |
* @throws IllegalArgumentException
|
|
220 |
* if the length of the string exceeds the requested maximum
|
|
221 |
* capacity
|
|
222 |
* @throws IllegalArgumentException
|
|
223 |
* if the width or height is less than one pixel
|
|
224 |
*/
|
|
225 |
public static TextEditor createTextEditor(
|
|
226 |
String text,
|
|
227 |
int maxSize,
|
|
228 |
int constraints,
|
|
229 |
int width,
|
|
230 |
int height)
|
|
231 |
{
|
|
232 |
return new TextEditorImpl(text, maxSize, constraints, width, height);
|
|
233 |
}
|
|
234 |
|
|
235 |
/**
|
|
236 |
* <P>
|
|
237 |
* Creates a new empty <code>TextEditor</code> with the given maximum size
|
|
238 |
* in characters, constraints and editor size as number of visible rows.
|
|
239 |
* </P>
|
|
240 |
*
|
|
241 |
* <P>
|
|
242 |
* The <code>rows</code> parameter indicates the requested number of visible
|
|
243 |
* rows in the editor. TextEditor then assigns the initial height for the
|
|
244 |
* editor based on the requested number of rows and width of the editor.
|
|
245 |
* </P>
|
|
246 |
*
|
|
247 |
* <P>
|
|
248 |
* The <code>maxSize</code> parameter must be greater than zero. An
|
|
249 |
* <code>IllegalArgumentException</code> is thrown if the length of the
|
|
250 |
* initial contents string exceeds <code>maxSize</code>. However, the
|
|
251 |
* implementation may assign a maximum size smaller than the application had
|
|
252 |
* requested. If this occurs, and if the length of the contents exceeds the
|
|
253 |
* newly assigned maximum size, the contents are truncated from the end in
|
|
254 |
* order to fit, and no exception is thrown.
|
|
255 |
* </P>
|
|
256 |
*
|
|
257 |
* <P>
|
|
258 |
* On Series60-devices the object returned by this method will also
|
|
259 |
* implement the com.nokia.mid.ui.S60TextEditor.
|
|
260 |
* </P>
|
|
261 |
*
|
|
262 |
* @param maxSize
|
|
263 |
* the maximum capacity in characters
|
|
264 |
* @param constraints
|
|
265 |
* see the input constraints in <code>TextField</code></a>
|
|
266 |
* @param width
|
|
267 |
* the width of the bounding box, in pixels
|
|
268 |
* @param rows
|
|
269 |
* the requested number of visible rows in the editor
|
|
270 |
* @return Instance of TextEditor
|
|
271 |
*
|
|
272 |
* @throws IllegalArgumentException
|
|
273 |
* if <code>aMaxSize</code> or <code>aRows</code> is zero or
|
|
274 |
* less
|
|
275 |
* @throws IllegalArgumentException
|
|
276 |
* if the value of the constraints parameter is invalid
|
|
277 |
* @throws IllegalArgumentException
|
|
278 |
* if the length of the string exceeds the requested maximum
|
|
279 |
* capacity
|
|
280 |
* @throws IllegalArgumentException
|
|
281 |
* if the width is less than one pixel
|
|
282 |
*/
|
|
283 |
public static TextEditor createTextEditor(
|
|
284 |
int maxSize,
|
|
285 |
int constraints,
|
|
286 |
int width,
|
|
287 |
int rows)
|
|
288 |
{
|
|
289 |
return new TextEditorImpl(maxSize, constraints, width, rows);
|
|
290 |
}
|
|
291 |
|
|
292 |
/**
|
|
293 |
* Sets this TextEditor focused or removes keyboard focus.
|
|
294 |
* Calling setFocus(true) enables text editing from keys as the delivery
|
|
295 |
* of needed key events will be targeted to the TextEditor instead of
|
|
296 |
* the parent object (e.g. Canvas). Focus needs to be explicitly set to
|
|
297 |
* the TextEditor by application. When Canvas or CustomItem does not have
|
|
298 |
* any focused TextEditor all key and pointer events are delivered to
|
|
299 |
* normal key delivery methods of parent. Necessary key events are
|
|
300 |
* captured by TextEditor only when it has focus.
|
|
301 |
* <P>
|
|
302 |
* The setFocus affects to the parent key event delivery in following
|
|
303 |
* way: If all TextEditors are unfocused the key event delivery of parent
|
|
304 |
* works as if there are not any TextEditors in it, only when a focus is
|
|
305 |
* set via this method to a TextEditor the key event delivery is modified.
|
|
306 |
* The focused editor starts to capture the necessary key events and these
|
|
307 |
* key events are not delivered to parent. The set of key events captured
|
|
308 |
* depends on TextEditor implementation and device HW but in most
|
|
309 |
* implementations nearly all device keys are captured by the editor for
|
|
310 |
* text insertion, input mode changes and caret move functionalities.
|
|
311 |
* Especially applications should not assume to get key events from keys
|
|
312 |
* mapped to game actions as most probably the same keys are used to
|
|
313 |
* navigate the text caret within the editor. The keys that are used for
|
|
314 |
* Command launching in Canvas are available for applications on focused
|
|
315 |
* TextEditor and these keys either launch commands or send low-level
|
|
316 |
* key events as normally.
|
|
317 |
* <P>
|
|
318 |
* Setting focus does not cause any visual focus indication by the
|
|
319 |
* implementation other than showing the caret. Any other change in the
|
|
320 |
* visual appearance of the editor in focused state is the responsibility
|
|
321 |
* of the application; this can be done for example by drawing a focus
|
|
322 |
* border around the TextEditor or by changing the background color or
|
|
323 |
* transparency of the editor.
|
|
324 |
* <P>
|
|
325 |
* If this TextEditor has already been focused earlier and the editor
|
|
326 |
* contents has not changed after previous unfocusing, then after calling
|
|
327 |
* setFocus again the caret position should be retained.
|
|
328 |
* <P>
|
|
329 |
* If there already is another focused TextEditor on the Canvas, the
|
|
330 |
* focus is first removed from that TextEditor before setting this
|
|
331 |
* TextEditor focused.
|
|
332 |
* <P>
|
|
333 |
* Calling setFocus(false) disables key based text editing and returns
|
|
334 |
* the delivery of key events and pointer events to the underlying Canvas.
|
|
335 |
*
|
|
336 |
* @param focused
|
|
337 |
* keyboard focus of the TextEditor
|
|
338 |
*
|
|
339 |
* @throws java.lang.IllegalStateException
|
|
340 |
* If the TextEditor is not added to Canvas
|
|
341 |
*
|
|
342 |
* @see #hasFocus()
|
|
343 |
*/
|
|
344 |
|
|
345 |
public void setFocus(boolean focused)
|
|
346 |
{
|
|
347 |
synchronized (iToolkit)
|
|
348 |
{
|
|
349 |
checkParent();
|
|
350 |
|
|
351 |
// If focus is set, adjust the focus of other known editors.
|
|
352 |
if (focused)
|
|
353 |
{
|
|
354 |
// Remove focus from other editors in this parent
|
|
355 |
Enumeration editors = iEditorContainer.getEditors(iParent);
|
|
356 |
|
|
357 |
while (editors.hasMoreElements())
|
|
358 |
{
|
|
359 |
TextEditor editor = (TextEditor) editors.nextElement();
|
|
360 |
|
|
361 |
// Do not remove focus from this editor if it is on.
|
|
362 |
if (editor != this)
|
|
363 |
{
|
|
364 |
editor.setFocus(false);
|
|
365 |
}
|
|
366 |
}
|
|
367 |
}
|
|
368 |
|
|
369 |
NativeError.check(_setFocusState(getToolkitHandle(), iHandle,
|
|
370 |
focused));
|
|
371 |
}
|
|
372 |
}
|
|
373 |
|
|
374 |
/**
|
|
375 |
* Returns the focus state of TextEditor.
|
|
376 |
*
|
|
377 |
* @return the focus state of the editor
|
|
378 |
* @see #setFocus(boolean focused)
|
|
379 |
*/
|
|
380 |
public boolean hasFocus()
|
|
381 |
{
|
|
382 |
boolean focusState;
|
|
383 |
|
|
384 |
synchronized (iToolkit)
|
|
385 |
{
|
|
386 |
checkParent();
|
|
387 |
focusState = _getFocusState(getToolkitHandle(), iHandle);
|
|
388 |
}
|
|
389 |
|
|
390 |
return focusState;
|
|
391 |
}
|
|
392 |
|
|
393 |
/**
|
|
394 |
* Set the parent object of this <code>TextEditor</code>.
|
|
395 |
* <P>
|
|
396 |
* Typically the parent object would be Canvas. Setting the parameter to
|
|
397 |
* null removes the association to the parent. If
|
|
398 |
* <code>setParent(null)</code> is called for a <code>TextEditor</code> yet
|
|
399 |
* not having any parent or <code>setParent(parent)</code> is called with
|
|
400 |
* the same parent, the call is silently ignored.
|
|
401 |
* <P>
|
|
402 |
*
|
|
403 |
* @param parent
|
|
404 |
* the parent object
|
|
405 |
*
|
|
406 |
* @throws IllegalArgumentException
|
|
407 |
* if parent is not a valid object with which a
|
|
408 |
* <code>TextEditor</code> can be associated, or if CanvasItem
|
|
409 |
* is already set to another another parent
|
|
410 |
*/
|
|
411 |
public void setParent(java.lang.Object parent)
|
|
412 |
{
|
|
413 |
// Ignore argument check if parent is set to null.
|
|
414 |
// Custom item support will be added in future, currently it's
|
|
415 |
// unsupported.
|
|
416 |
if (((parent != null) && !(parent instanceof Canvas)) ||
|
|
417 |
((parent != null) && (iParent != null) && (iParent != parent)))
|
|
418 |
{
|
|
419 |
throw new IllegalArgumentException(ERROR_NOT_A_VALID_PARENT_OBJECT);
|
|
420 |
}
|
|
421 |
|
|
422 |
int parentHandle = 0;
|
|
423 |
|
|
424 |
if (parent != iParent)
|
|
425 |
{
|
|
426 |
// Lock this object so that parent cannot be adjusted from
|
|
427 |
// other threads.
|
|
428 |
synchronized (iToolkit)
|
|
429 |
{
|
|
430 |
// Toolkit invoker can be used to get proper handles.
|
|
431 |
if (parent instanceof Canvas)
|
|
432 |
{
|
|
433 |
// Note that canvas is shown inside a displayable so in
|
|
434 |
// this case we use the handle to the displayble object.
|
|
435 |
parentHandle = iToolkitInvoker.getDisplayableHandle(parent);
|
|
436 |
}
|
|
437 |
else if (parent instanceof CustomItem)
|
|
438 |
{
|
|
439 |
parentHandle = iToolkitInvoker.itemGetHandle(parent);
|
|
440 |
}
|
|
441 |
|
|
442 |
// parentHandle = 0 indicates removal of the parent.
|
|
443 |
int error =
|
|
444 |
_setParent(getToolkitHandle(), iHandle, parentHandle);
|
|
445 |
|
|
446 |
// Check if an error occured when setting the parent object.
|
|
447 |
NativeError.check(error);
|
|
448 |
|
|
449 |
// Operation was successful. Store parent and register
|
|
450 |
// to container. Remove from container and previous parent.
|
|
451 |
if (iParent != null)
|
|
452 |
{
|
|
453 |
iEditorContainer.removeEditor(this, iParent);
|
|
454 |
}
|
|
455 |
// Store the editor with new parent if not null.
|
|
456 |
if (parent != null)
|
|
457 |
{
|
|
458 |
iEditorContainer.addEditor(this, parent);
|
|
459 |
}
|
|
460 |
|
|
461 |
iParent = parent;
|
|
462 |
}
|
|
463 |
}
|
|
464 |
}
|
|
465 |
|
|
466 |
/**
|
|
467 |
* Sets the size of this <code>TextEditor</code> in pixels.
|
|
468 |
*
|
|
469 |
* @param width
|
|
470 |
* width in pixels
|
|
471 |
* @param height
|
|
472 |
* height in pixels
|
|
473 |
*
|
|
474 |
* @throws IllegalArgumentException
|
|
475 |
* if the width or height is less than one pixel
|
|
476 |
*/
|
|
477 |
public void setSize(int width, int height)
|
|
478 |
{
|
|
479 |
// Validate width and row count
|
|
480 |
if (width < 1 || height < 1)
|
|
481 |
{
|
|
482 |
throw new IllegalArgumentException(ERROR_GIVEN_ARGUMENTS_NOT_VALID);
|
|
483 |
}
|
|
484 |
|
|
485 |
synchronized (iToolkit)
|
|
486 |
{
|
|
487 |
NativeError.check(_setSize(getToolkitHandle(), iHandle, width,
|
|
488 |
height));
|
|
489 |
|
|
490 |
// Operation was a success, store size.
|
|
491 |
iWidth = width;
|
|
492 |
iHeight = height;
|
|
493 |
}
|
|
494 |
}
|
|
495 |
|
|
496 |
/**
|
|
497 |
* <P>
|
|
498 |
* Sets the rendering position of this <code>TextEditor</code>. The anchor
|
|
499 |
* point given is relative to the upper left corner of the parent,
|
|
500 |
* <code>Canvas</code>.
|
|
501 |
* </P>
|
|
502 |
*
|
|
503 |
* <P>
|
|
504 |
* The <code>TextEditor</code> may be placed fully off or partially of the
|
|
505 |
* visible area of the parent, <code>Canvas</code>, by the
|
|
506 |
* <code>setPosition</code> method; in this case the <code>TextEditor</code>
|
|
507 |
* is just partly visible.
|
|
508 |
* </P>
|
|
509 |
*
|
|
510 |
* @param x
|
|
511 |
* the x coordinate of the anchor point, in pixels.
|
|
512 |
* @param y
|
|
513 |
* the y coordinate of the anchor point, in pixels.
|
|
514 |
* @throws IllegalStateException
|
|
515 |
* if a valid parent object has not been set.
|
|
516 |
* @see #setParent(java.lang.Object parent)
|
|
517 |
*/
|
|
518 |
public void setPosition(int x, int y)
|
|
519 |
{
|
|
520 |
synchronized (iToolkit)
|
|
521 |
{
|
|
522 |
checkParent();
|
|
523 |
|
|
524 |
NativeError.check(_setPosition(getToolkitHandle(), iHandle, x, y));
|
|
525 |
|
|
526 |
// Store current position.
|
|
527 |
iPositionX = x;
|
|
528 |
iPositionY = y;
|
|
529 |
}
|
|
530 |
}
|
|
531 |
|
|
532 |
/**
|
|
533 |
* <P>
|
|
534 |
* Sets the visibility value of <code>TextEditor</code>. Initially
|
|
535 |
* <code>TextEditor</code> is not visible so it must be explicitly set to
|
|
536 |
* visible in order it to appear on UI.
|
|
537 |
* </P>
|
|
538 |
*
|
|
539 |
* <P>
|
|
540 |
* Setting visibility to true shows the editor with its content, but without
|
|
541 |
* the caret. If the editor does not have any visible content and does not
|
|
542 |
* have any background color set then this method effectively does not cause
|
|
543 |
* any visual change in the display. If the editor is already visible
|
|
544 |
* calling <code>setVisible(true)</code> does nothing.
|
|
545 |
* </P>
|
|
546 |
*
|
|
547 |
* <P>
|
|
548 |
* Setting the visibility to false hides the editor and its content. If the
|
|
549 |
* <code>TextEditor</code> has focus then the focus is removed. If the
|
|
550 |
* editor is already hidden calling <code>setVisible(false)</code> does
|
|
551 |
* nothing.
|
|
552 |
* </P>
|
|
553 |
*
|
|
554 |
* @param visible
|
|
555 |
* visibility of the <code>TextEditor</code>
|
|
556 |
* @throws IllegalStateException
|
|
557 |
* if a valid parent object has not been set.
|
|
558 |
* @see #setParent(java.lang.Object parent)
|
|
559 |
*/
|
|
560 |
public void setVisible(boolean visible)
|
|
561 |
{
|
|
562 |
synchronized (iToolkit)
|
|
563 |
{
|
|
564 |
checkParent();
|
|
565 |
|
|
566 |
NativeError
|
|
567 |
.check(_setVisible(getToolkitHandle(), iHandle, visible));
|
|
568 |
|
|
569 |
iVisible = visible;
|
|
570 |
}
|
|
571 |
}
|
|
572 |
|
|
573 |
/**
|
|
574 |
* <P>
|
|
575 |
* Sets the Z-position, or the elevation, of the item.
|
|
576 |
* <p>
|
|
577 |
* The elevation decides the stacking order of neighboring items. An item of
|
|
578 |
* high Z-position will be drawn on top of an item with a lower Z-position
|
|
579 |
* if they share the same parent item.
|
|
580 |
* <p>
|
|
581 |
* The z-position is unique for each item meaning that changing a Z-position
|
|
582 |
* of an item may change the Z-position of the items that share the same
|
|
583 |
* parent item. The Z-position does not affect the item's size in any way.
|
|
584 |
* <p>
|
|
585 |
* When items are added with {@link CanvasItem#setParent} they will get a
|
|
586 |
* Z-position that is increased by 1 from the item that is the top most item
|
|
587 |
* at that time.
|
|
588 |
* </P>
|
|
589 |
*
|
|
590 |
* @param z
|
|
591 |
* the Z-position of the item.
|
|
592 |
*
|
|
593 |
* @throws IllegalArgumentException
|
|
594 |
* If <code>z</code> < 0
|
|
595 |
* @throws IllegalStateException
|
|
596 |
* if a valid parent object has not been set.
|
|
597 |
*
|
|
598 |
* @see #getZPosition()
|
|
599 |
* @see #setParent(java.lang.Object parent)
|
|
600 |
*/
|
|
601 |
public void setZPosition(int z)
|
|
602 |
{
|
|
603 |
if (z < 0)
|
|
604 |
{
|
|
605 |
throw new IllegalArgumentException();
|
|
606 |
}
|
|
607 |
|
|
608 |
synchronized (iToolkit)
|
|
609 |
{
|
|
610 |
checkParent();
|
|
611 |
|
|
612 |
NativeError.check(_setZPosition(getToolkitHandle(), iHandle, z));
|
|
613 |
}
|
|
614 |
}
|
|
615 |
|
|
616 |
/**
|
|
617 |
* <P>
|
|
618 |
* Returns the Z-position, or the elevation, of the item. The Z-position
|
|
619 |
* decides the stacking order of neighboring items.
|
|
620 |
* </P>
|
|
621 |
*
|
|
622 |
* @return the Z-position of the item.
|
|
623 |
*
|
|
624 |
* @throws IllegalStateException
|
|
625 |
* if a valid parent object has not been set.
|
|
626 |
*
|
|
627 |
* @see #setZPosition(int)
|
|
628 |
* @see #setParent(java.lang.Object parent)
|
|
629 |
*/
|
|
630 |
public int getZPosition()
|
|
631 |
{
|
|
632 |
int positionZ = -1;
|
|
633 |
|
|
634 |
synchronized (iToolkit)
|
|
635 |
{
|
|
636 |
checkParent();
|
|
637 |
|
|
638 |
positionZ = _getZPosition(getToolkitHandle(), iHandle);
|
|
639 |
}
|
|
640 |
|
|
641 |
NativeError.check(positionZ);
|
|
642 |
return positionZ;
|
|
643 |
}
|
|
644 |
|
|
645 |
/**
|
|
646 |
* Gets the line margin height in this <code>TextEditor</code> in pixels.
|
|
647 |
* <p>
|
|
648 |
* Gets the possible line margin height that editor has in addition to the
|
|
649 |
* normal font height (<code>Font getHeight()</code>). The returned value is
|
|
650 |
* 0 if the editor does not have any additional line margins to the text
|
|
651 |
* height returned from <code>getHeight()</code> of Font set to the editor.
|
|
652 |
* <p>
|
|
653 |
*
|
|
654 |
* @return the line margin height in pixels
|
|
655 |
*
|
|
656 |
* @see #setParent(java.lang.Object parent)
|
|
657 |
*/
|
|
658 |
public int getLineMarginHeight()
|
|
659 |
{
|
|
660 |
int lineMarginHeight = 0;
|
|
661 |
|
|
662 |
if (iParent != null)
|
|
663 |
{
|
|
664 |
synchronized (iToolkit)
|
|
665 |
{
|
|
666 |
// Get the line margin height from the native side.
|
|
667 |
lineMarginHeight =
|
|
668 |
_getLineMarginHeight(getToolkitHandle(), iHandle);
|
|
669 |
}
|
|
670 |
|
|
671 |
// Check if the line margin height was not returned correctly.
|
|
672 |
NativeError.check(lineMarginHeight);
|
|
673 |
}
|
|
674 |
return lineMarginHeight;
|
|
675 |
}
|
|
676 |
|
|
677 |
/**
|
|
678 |
* Gets the whole content height in this <code>TextEditor</code> in pixels.
|
|
679 |
* <p>
|
|
680 |
*
|
|
681 |
* The returned value must include the height of the whole content in the
|
|
682 |
* editor, not just the height of the visible content.
|
|
683 |
* <p>
|
|
684 |
*
|
|
685 |
* Note that the method returns 0, if the editor has no parent.
|
|
686 |
* <p>
|
|
687 |
*
|
|
688 |
* @return the height of the whole content in the editor in pixels
|
|
689 |
*
|
|
690 |
* @see #setParent(java.lang.Object parent)
|
|
691 |
*/
|
|
692 |
public int getContentHeight()
|
|
693 |
{
|
|
694 |
int contentHeight = 0;
|
|
695 |
if (iParent != null)
|
|
696 |
{
|
|
697 |
synchronized (iToolkit)
|
|
698 |
{
|
|
699 |
// Get the content height from the native side.
|
|
700 |
contentHeight = _getContentHeight(getToolkitHandle(), iHandle);
|
|
701 |
}
|
|
702 |
|
|
703 |
// Check if the size was not returned correctly.
|
|
704 |
NativeError.check(contentHeight);
|
|
705 |
}
|
|
706 |
return contentHeight;
|
|
707 |
}
|
|
708 |
|
|
709 |
/**
|
|
710 |
* <P>
|
|
711 |
* Sets the index of the caret. The caret can be used to indicate a position
|
|
712 |
* in the text.
|
|
713 |
* </P>
|
|
714 |
*
|
|
715 |
* <P>
|
|
716 |
* The Java platform implementation must scroll the content of the
|
|
717 |
* <code>TextEditor</code> automatically so that the caret is within the
|
|
718 |
* visible area. If the caret is set above the current position the content
|
|
719 |
* should be scrolled so that the caret is on the top most visible row. If
|
|
720 |
* the caret is set below the current position the content should be
|
|
721 |
* scrolled so that the caret is on the lowest visible row.
|
|
722 |
* </P>
|
|
723 |
*
|
|
724 |
* @param index
|
|
725 |
* the character index before which to place the caret
|
|
726 |
*
|
|
727 |
* @throws StringIndexOutOfBoundsException
|
|
728 |
* if <code>index</code> does not specify a valid range within
|
|
729 |
* the content of the <code>TextEditor</code>
|
|
730 |
*/
|
|
731 |
public void setCaret(int index)
|
|
732 |
{
|
|
733 |
// New position must be in range of the current content.
|
|
734 |
if (index < 0 || index > size())
|
|
735 |
{
|
|
736 |
throw new StringIndexOutOfBoundsException(
|
|
737 |
ERROR_GIVEN_ARGUMENTS_NOT_VALID);
|
|
738 |
}
|
|
739 |
|
|
740 |
synchronized (iToolkit)
|
|
741 |
{
|
|
742 |
NativeError.check(_setCaret(getToolkitHandle(), iHandle, index));
|
|
743 |
}
|
|
744 |
}
|
|
745 |
|
|
746 |
/**
|
|
747 |
* Gets the current position of the caret in the editor.
|
|
748 |
*
|
|
749 |
* @return the current caret position, <code>0</code> if at the beginning
|
|
750 |
*/
|
|
751 |
public int getCaretPosition()
|
|
752 |
{
|
|
753 |
int caretPosition = 0;
|
|
754 |
|
|
755 |
synchronized (iToolkit)
|
|
756 |
{
|
|
757 |
caretPosition = _getCaretPosition(getToolkitHandle(), iHandle);
|
|
758 |
}
|
|
759 |
|
|
760 |
// Verify that the operation was a success.
|
|
761 |
NativeError.check(caretPosition);
|
|
762 |
return caretPosition;
|
|
763 |
}
|
|
764 |
|
|
765 |
/**
|
|
766 |
* <P>
|
|
767 |
* Gets the topmost pixel position of the topmost visible line in the
|
|
768 |
* editor.
|
|
769 |
* </P>
|
|
770 |
*
|
|
771 |
* <P>
|
|
772 |
* The returned y coordinate value is relative to the whole content height,
|
|
773 |
* not just the visible part.
|
|
774 |
* </P>
|
|
775 |
*
|
|
776 |
* <P>
|
|
777 |
* This method can be used by the application together with the
|
|
778 |
* <code>getContentHeight</code>, height of the font,
|
|
779 |
* <code>getLineMarginHeight</code>, and <code>getCaretPosition</code>
|
|
780 |
* methods in drawing custom visual cues like a scroll bar or other content
|
|
781 |
* sensitive pop-ups.
|
|
782 |
* </P>
|
|
783 |
*
|
|
784 |
* <P>
|
|
785 |
* Note that the method returns 0, if the editor has no parent.
|
|
786 |
* </P>
|
|
787 |
*
|
|
788 |
* @return the topmost pixel position of the visible content.
|
|
789 |
*/
|
|
790 |
public int getVisibleContentPosition()
|
|
791 |
{
|
|
792 |
int ypos = 0;
|
|
793 |
|
|
794 |
if (iParent != null)
|
|
795 |
{
|
|
796 |
synchronized (iToolkit)
|
|
797 |
{
|
|
798 |
ypos = _getVisibleContentPosition(getToolkitHandle(), iHandle);
|
|
799 |
}
|
|
800 |
|
|
801 |
// Verify that the operation was a success.
|
|
802 |
NativeError.check(ypos);
|
|
803 |
}
|
|
804 |
return ypos;
|
|
805 |
}
|
|
806 |
|
|
807 |
/**
|
|
808 |
* <P>
|
|
809 |
* Gets the font being used in rendering the text content in this
|
|
810 |
* <code>TextEditor</code>.
|
|
811 |
* </P>
|
|
812 |
*
|
|
813 |
* @return the font being used in this <code>TextEditor</code>
|
|
814 |
*/
|
|
815 |
public Font getFont()
|
|
816 |
{
|
|
817 |
synchronized (iToolkit)
|
|
818 |
{
|
|
819 |
return iFont == null ? Font.getDefaultFont() : iFont;
|
|
820 |
}
|
|
821 |
}
|
|
822 |
|
|
823 |
/**
|
|
824 |
* <P>
|
|
825 |
* Sets the application preferred font for rendering the text content in
|
|
826 |
* this <code>TextEditor</code>. Setting the font is a hint to the
|
|
827 |
* implementation, and the implementation may disregard the requested font.
|
|
828 |
* </P>
|
|
829 |
*
|
|
830 |
* <P>
|
|
831 |
* The <code>font</code> parameter must be a valid <code>Font</code> object
|
|
832 |
* or <code>null</code>. If the <code>font</code> parameter is
|
|
833 |
* <code>null</code>, the implementation must use its default font to render
|
|
834 |
* the text content.
|
|
835 |
* </P>
|
|
836 |
*
|
|
837 |
* @param font
|
|
838 |
* the application preferred font to be used in this
|
|
839 |
* <code>TextEditor</code>
|
|
840 |
*/
|
|
841 |
public void setFont(Font font)
|
|
842 |
{
|
|
843 |
if (font == null)
|
|
844 |
{
|
|
845 |
font = Font.getDefaultFont();
|
|
846 |
}
|
|
847 |
|
|
848 |
synchronized (iToolkit)
|
|
849 |
{
|
|
850 |
NativeError.check(_setFont(getToolkitHandle(),
|
|
851 |
iHandle,
|
|
852 |
iLCDUIPackageInvoker.getFontHandle(font)));
|
|
853 |
iFont = font;
|
|
854 |
}
|
|
855 |
}
|
|
856 |
|
|
857 |
/**
|
|
858 |
* Gets the background color and alpha of this <code>TextEditor</code>.
|
|
859 |
*
|
|
860 |
* @return the background color
|
|
861 |
*/
|
|
862 |
public int getBackgroundColor()
|
|
863 |
{
|
|
864 |
int color = 0;
|
|
865 |
|
|
866 |
synchronized (iToolkit)
|
|
867 |
{
|
|
868 |
color = _getColor(getToolkitHandle(), iHandle,
|
|
869 |
COLOR_BACKGROUND);
|
|
870 |
}
|
|
871 |
return color;
|
|
872 |
}
|
|
873 |
|
|
874 |
/**
|
|
875 |
* Gets the foreground color and alpha of this <code>TextEditor</code>
|
|
876 |
*
|
|
877 |
* @return the foreground color
|
|
878 |
*/
|
|
879 |
public int getForegroundColor()
|
|
880 |
{
|
|
881 |
int color = 0;
|
|
882 |
|
|
883 |
synchronized (iToolkit)
|
|
884 |
{
|
|
885 |
color = _getColor(getToolkitHandle(), iHandle,
|
|
886 |
COLOR_FOREGROUND);
|
|
887 |
}
|
|
888 |
return color;
|
|
889 |
}
|
|
890 |
|
|
891 |
/**
|
|
892 |
* Sets the background color and alpha of this <code>TextEditor</code> to
|
|
893 |
* the specified values. The default background color for editor is fully
|
|
894 |
* transparent white.
|
|
895 |
*
|
|
896 |
* @param color
|
|
897 |
* the color
|
|
898 |
*/
|
|
899 |
public void setBackgroundColor(int color)
|
|
900 |
{
|
|
901 |
int alpha = (color >> 24) & 0xff;
|
|
902 |
int red = (color >> 16) & 0xff;
|
|
903 |
int green = (color >> 8) & 0xff;
|
|
904 |
int blue = (color) & 0xff;
|
|
905 |
|
|
906 |
doSetColor(alpha, red, green, blue, COLOR_BACKGROUND);
|
|
907 |
}
|
|
908 |
|
|
909 |
/**
|
|
910 |
* Sets the foreground color and alpha of this <code>TextEditor</code> to
|
|
911 |
* the specified values. The content, e.g. text, in the editor must be drawn
|
|
912 |
* with this color. The default foreground color is fully opaque black.
|
|
913 |
*
|
|
914 |
* @param color
|
|
915 |
* the color
|
|
916 |
*/
|
|
917 |
public void setForegroundColor(int color)
|
|
918 |
{
|
|
919 |
int alpha = (color >> 24) & 0xff;
|
|
920 |
int red = (color >> 16) & 0xff;
|
|
921 |
int green = (color >> 8) & 0xff;
|
|
922 |
int blue = (color) & 0xff;
|
|
923 |
|
|
924 |
doSetColor(alpha, red, green, blue, COLOR_FOREGROUND);
|
|
925 |
}
|
|
926 |
|
|
927 |
/**
|
|
928 |
* Sets the highlight background color. This impacts text background color
|
|
929 |
* for the selected text.
|
|
930 |
* The text in a current selection range will be
|
|
931 |
* rendered using given color value. The default highlight background
|
|
932 |
* color is fully opaque black.
|
|
933 |
*
|
|
934 |
* This method is not supported on S40 platform.
|
|
935 |
*
|
|
936 |
* @param color
|
|
937 |
* the color
|
|
938 |
*/
|
|
939 |
public void setHighlightBackgroundColor(int color)
|
|
940 |
{
|
|
941 |
int alpha = (color >> 24) & 0xff;
|
|
942 |
int red = (color >> 16) & 0xff;
|
|
943 |
int green = (color >> 8) & 0xff;
|
|
944 |
int blue = (color) & 0xff;
|
|
945 |
|
|
946 |
doSetColor(alpha, red, green, blue, COLOR_HIGHLIGHT_BACKGROUND);
|
|
947 |
}
|
|
948 |
|
|
949 |
/**
|
|
950 |
* Sets the highlight foreground color. This impacts text color for the
|
|
951 |
* selected text.
|
|
952 |
* The text in a current selection range will be rendered
|
|
953 |
* using given color value. The default highlight foreground color is fully
|
|
954 |
* opaque white.
|
|
955 |
*
|
|
956 |
* This method is not supported on S40 platform.
|
|
957 |
*
|
|
958 |
* @param color
|
|
959 |
* the color
|
|
960 |
*/
|
|
961 |
public void setHighlightForegroundColor(int color)
|
|
962 |
{
|
|
963 |
int alpha = (color >> 24) & 0xff;
|
|
964 |
int red = (color >> 16) & 0xff;
|
|
965 |
int green = (color >> 8) & 0xff;
|
|
966 |
int blue = (color) & 0xff;
|
|
967 |
|
|
968 |
doSetColor(alpha, red, green, blue, COLOR_HIGHLIGHT_FOREGROUND);
|
|
969 |
}
|
|
970 |
|
|
971 |
/**
|
|
972 |
* Sets the content of the <code>TextEditor</code> as a string. The set
|
|
973 |
* string replaces any previous content in the editor.
|
|
974 |
*
|
|
975 |
* @param content
|
|
976 |
* the new content of the <code>TextEditor</code> as string,
|
|
977 |
* <code>null</code> empties the <code>TextEditor</code>
|
|
978 |
*
|
|
979 |
* @throws IllegalArgumentException
|
|
980 |
* if <code>aContent</code> is illegal for the current input
|
|
981 |
* constraints
|
|
982 |
* @throws IllegalArgumentException
|
|
983 |
* if the given text would exceed the current maximum capacity
|
|
984 |
* of the editor
|
|
985 |
*/
|
|
986 |
public void setContent(String content)
|
|
987 |
{
|
|
988 |
// Verify that text is not invalid.
|
|
989 |
iLCDUIPackageInvoker.checkText(content, iMaxSize);
|
|
990 |
|
|
991 |
synchronized (iToolkit)
|
|
992 |
{
|
|
993 |
NativeError
|
|
994 |
.check(_setContent(getToolkitHandle(), iHandle, content));
|
|
995 |
}
|
|
996 |
}
|
|
997 |
|
|
998 |
/**
|
|
999 |
* Gets the string content in the <code>TextEditor</code>.
|
|
1000 |
*
|
|
1001 |
* @return The editor current content
|
|
1002 |
*/
|
|
1003 |
public String getContent()
|
|
1004 |
{
|
|
1005 |
String content = null;
|
|
1006 |
int[] error = new int[1];
|
|
1007 |
|
|
1008 |
synchronized (iToolkit)
|
|
1009 |
{
|
|
1010 |
content = _getContent(getToolkitHandle(), iHandle, error);
|
|
1011 |
}
|
|
1012 |
|
|
1013 |
NativeError.check(error[0]);
|
|
1014 |
return content;
|
|
1015 |
}
|
|
1016 |
|
|
1017 |
/**
|
|
1018 |
* <P>
|
|
1019 |
* Inserts a string into the content of the <code>TextEditor</code>.
|
|
1020 |
* </P>
|
|
1021 |
*
|
|
1022 |
* <P>
|
|
1023 |
* The string is inserted just prior to the character indicated by the
|
|
1024 |
* <code>position</code> parameter, where zero specifies the first character
|
|
1025 |
* of the content in the <code>TextEditor</code>. If <code>position</code>
|
|
1026 |
* is less than or equal to zero, the insertion occurs at the beginning of
|
|
1027 |
* the content. If <code>position</code> is greater than or equal to the
|
|
1028 |
* current size of the content, the insertion occurs immediately after the
|
|
1029 |
* end of the content.
|
|
1030 |
* </P>
|
|
1031 |
*
|
|
1032 |
* <P>
|
|
1033 |
* The current size of the contents is increased by the number of inserted
|
|
1034 |
* characters. The resulting string must fit within the current maximum
|
|
1035 |
* capacity.
|
|
1036 |
* </P>
|
|
1037 |
*
|
|
1038 |
* @param text
|
|
1039 |
* the <code>String</code> to be inserted
|
|
1040 |
* @param position
|
|
1041 |
* the position at which insertion is to occur
|
|
1042 |
*
|
|
1043 |
* @throws IllegalArgumentException
|
|
1044 |
* if the resulting content would be illegal for the current
|
|
1045 |
* input constraints
|
|
1046 |
* @throws IllegalArgumentException
|
|
1047 |
* if the insertion would exceed the current maximum capacity
|
|
1048 |
* @throws NullPointerException
|
|
1049 |
* if <code>text</code> is <code>null</code>
|
|
1050 |
*/
|
|
1051 |
public void insert(String text, int position)
|
|
1052 |
{
|
|
1053 |
// Check illegal arguments. Note that NullPointerException is thrown
|
|
1054 |
// correctly if text is null when text.length() is called.
|
|
1055 |
if (text.length() + size() > iMaxSize)
|
|
1056 |
{
|
|
1057 |
throw new IllegalArgumentException(ERROR_GIVEN_ARGUMENTS_NOT_VALID);
|
|
1058 |
}
|
|
1059 |
|
|
1060 |
synchronized (iToolkit)
|
|
1061 |
{
|
|
1062 |
NativeError.check(_insert(getToolkitHandle(), iHandle, text,
|
|
1063 |
position));
|
|
1064 |
}
|
|
1065 |
}
|
|
1066 |
|
|
1067 |
/**
|
|
1068 |
* <P>
|
|
1069 |
* Deletes characters from the <code>TextEditor</code>.
|
|
1070 |
* </P>
|
|
1071 |
*
|
|
1072 |
* <P>
|
|
1073 |
* The <code>offset</code> and <code>length</code> parameters must specify a
|
|
1074 |
* valid range of characters within the contents of the
|
|
1075 |
* <code>TextEditor</code>. The <code>offset</code> parameter must be within
|
|
1076 |
* the range <code>[0..(size())]</code>, inclusive. The <code>length</code>
|
|
1077 |
* parameter must be a non-negative integer such that
|
|
1078 |
* <code>(offset + length) <= size()</code>.
|
|
1079 |
* </P>
|
|
1080 |
*
|
|
1081 |
* @param offset
|
|
1082 |
* the beginning of the region to be deleted
|
|
1083 |
* @param length
|
|
1084 |
* the number of characters to be deleted
|
|
1085 |
*
|
|
1086 |
* @throws IllegalArgumentException
|
|
1087 |
* if the resulting contents would be illegal for the current
|
|
1088 |
* input constraints
|
|
1089 |
* @throws StringIndexOutOfBoundsException
|
|
1090 |
* if <code>offset</code> and <code>length</code> do not specify
|
|
1091 |
* a valid range within the content of the
|
|
1092 |
* <code>TextEditor</code>
|
|
1093 |
*/
|
|
1094 |
public void delete(int offset, int length)
|
|
1095 |
{
|
|
1096 |
iLCDUIPackageInvoker.checkOffset(offset, length, size());
|
|
1097 |
|
|
1098 |
synchronized (iToolkit)
|
|
1099 |
{
|
|
1100 |
NativeError.check(_delete(getToolkitHandle(), iHandle, offset,
|
|
1101 |
length));
|
|
1102 |
}
|
|
1103 |
}
|
|
1104 |
|
|
1105 |
/**
|
|
1106 |
* Returns the maximum size (number of characters) that can be stored in
|
|
1107 |
* this <code>TextEditor</code>.
|
|
1108 |
*
|
|
1109 |
* @return the maximum size in characters
|
|
1110 |
*/
|
|
1111 |
public int getMaxSize()
|
|
1112 |
{
|
|
1113 |
return iMaxSize;
|
|
1114 |
}
|
|
1115 |
|
|
1116 |
/**
|
|
1117 |
* Sets the maximum size (number of characters) that can be contained in
|
|
1118 |
* this <code>TextEditor</code>. If the current content of the
|
|
1119 |
* <code>TextEditor</code> is larger than the new <code>maxSize</code>, the
|
|
1120 |
* content is truncated to fit.
|
|
1121 |
*
|
|
1122 |
* @param maxSize
|
|
1123 |
* the new maximum size
|
|
1124 |
*
|
|
1125 |
* @return assigned maximum capacity - may be smaller than requested.
|
|
1126 |
*
|
|
1127 |
* @throws IllegalArgumentException
|
|
1128 |
* if <code>maxSize</code> is zero or less.
|
|
1129 |
* @throws IllegalArgumentException
|
|
1130 |
* if the contents after truncation would be illegal for the
|
|
1131 |
* current input constraints
|
|
1132 |
*/
|
|
1133 |
public int setMaxSize(int maxSize)
|
|
1134 |
{
|
|
1135 |
if (maxSize <= 0)
|
|
1136 |
{
|
|
1137 |
throw new IllegalArgumentException(ERROR_GIVEN_ARGUMENTS_NOT_VALID);
|
|
1138 |
}
|
|
1139 |
|
|
1140 |
int newMaxSize = 0;
|
|
1141 |
|
|
1142 |
synchronized (iToolkit)
|
|
1143 |
{
|
|
1144 |
newMaxSize = _setMaxSize(getToolkitHandle(), iHandle, maxSize);
|
|
1145 |
NativeError.check(newMaxSize);
|
|
1146 |
|
|
1147 |
// Operation was successful, store maximum size.
|
|
1148 |
iMaxSize = newMaxSize;
|
|
1149 |
}
|
|
1150 |
return newMaxSize;
|
|
1151 |
}
|
|
1152 |
|
|
1153 |
/**
|
|
1154 |
* Gets the number of characters that are currently stored in this
|
|
1155 |
* <code>TextEditor</code>.
|
|
1156 |
*
|
|
1157 |
* @return the number of characters
|
|
1158 |
*/
|
|
1159 |
public int size()
|
|
1160 |
{
|
|
1161 |
int size = 0;
|
|
1162 |
|
|
1163 |
synchronized (iToolkit)
|
|
1164 |
{
|
|
1165 |
// Get the size from the native side.
|
|
1166 |
size = _size(getToolkitHandle(), iHandle);
|
|
1167 |
}
|
|
1168 |
|
|
1169 |
// Check if the size was not returned correctly.
|
|
1170 |
NativeError.check(size);
|
|
1171 |
return size;
|
|
1172 |
}
|
|
1173 |
|
|
1174 |
/**
|
|
1175 |
* Sets the input constraints of this <code>TextEditor</code>. If the
|
|
1176 |
* current content of this <code>TextEditor</code> do not match the new
|
|
1177 |
* constraints, the content is set to empty.
|
|
1178 |
*
|
|
1179 |
* @param constraints
|
|
1180 |
* see <a href="TextField.html#constraints">input constraints</a>
|
|
1181 |
*
|
|
1182 |
* @throws IllegalArgumentException
|
|
1183 |
* if the value of the constraints parameter is invalid
|
|
1184 |
*/
|
|
1185 |
public void setConstraints(int constraints)
|
|
1186 |
{
|
|
1187 |
// Validate constraints through TextComponentInvoker.
|
|
1188 |
iLCDUIPackageInvoker.checkConstraints(constraints);
|
|
1189 |
|
|
1190 |
synchronized (iToolkit)
|
|
1191 |
{
|
|
1192 |
NativeError.check(_setConstraints(getToolkitHandle(), iHandle,
|
|
1193 |
constraints));
|
|
1194 |
|
|
1195 |
iConstraints = constraints;
|
|
1196 |
}
|
|
1197 |
}
|
|
1198 |
|
|
1199 |
/**
|
|
1200 |
* Gets the current input constraints of this <code>TextEditor</code>.
|
|
1201 |
*
|
|
1202 |
* @return the current constraints value (see <a
|
|
1203 |
* href="TextField.html#constraints">input constraints</a>)
|
|
1204 |
*/
|
|
1205 |
public int getConstraints()
|
|
1206 |
{
|
|
1207 |
return iConstraints;
|
|
1208 |
}
|
|
1209 |
|
|
1210 |
/**
|
|
1211 |
* <P>
|
|
1212 |
* Sets a hint to the implementation as to the input mode that should be
|
|
1213 |
* used when the user initiates editing of this <code>TextEditor</code>. The
|
|
1214 |
* <code>characterSubset</code> parameter names a subset of Unicode
|
|
1215 |
* characters that is used by the implementation to choose an initial input
|
|
1216 |
* mode. If <code>null</code> is passed, the implementation should choose a
|
|
1217 |
* default input mode.
|
|
1218 |
* </P>
|
|
1219 |
*
|
|
1220 |
* <P>
|
|
1221 |
* See <a href="TextField#modes">Input Modes</a> for a full explanation of
|
|
1222 |
* input modes.
|
|
1223 |
* </P>
|
|
1224 |
*
|
|
1225 |
* @param characterSubset
|
|
1226 |
* a string naming a Unicode character subset, or
|
|
1227 |
* <code>null</code>
|
|
1228 |
*/
|
|
1229 |
public void setInitialInputMode(String characterSubset)
|
|
1230 |
{
|
|
1231 |
synchronized (iToolkit)
|
|
1232 |
{
|
|
1233 |
NativeError.check(_setInitialInputMode(getToolkitHandle(), iHandle,
|
|
1234 |
characterSubset));
|
|
1235 |
|
|
1236 |
iCharacterSubset = characterSubset;
|
|
1237 |
}
|
|
1238 |
}
|
|
1239 |
|
|
1240 |
/**
|
|
1241 |
* Returns the initial input mode set to the editor, or null if no initial
|
|
1242 |
* input mode has been set.
|
|
1243 |
*
|
|
1244 |
* @return the initial input mode as a String, or null if no initial input
|
|
1245 |
* mode is set.
|
|
1246 |
*
|
|
1247 |
* @see #setInitialInputMode(String characterSubset )
|
|
1248 |
*/
|
|
1249 |
public String getInitialInputMode()
|
|
1250 |
{
|
|
1251 |
return iCharacterSubset;
|
|
1252 |
}
|
|
1253 |
|
|
1254 |
/**
|
|
1255 |
* <P>
|
|
1256 |
* Sets a selection on a range of text in the <code>TextEditor</code>
|
|
1257 |
* content. The implementation should highlight the selection visually. A
|
|
1258 |
* selection may be set with this method or by user interaction. If there
|
|
1259 |
* already is a selection set, it is replaced by this new selection.
|
|
1260 |
* </P>
|
|
1261 |
*
|
|
1262 |
* <P>
|
|
1263 |
* The caret must be automatically set directly after the set selection. The
|
|
1264 |
* Java platform implementation must scroll the content of the
|
|
1265 |
* <code>TextEditor</code> automatically so that the caret is within the
|
|
1266 |
* visible area and as much as possible of the selection is visible in the
|
|
1267 |
* <code>TextEditor</code>.
|
|
1268 |
* </P>
|
|
1269 |
*
|
|
1270 |
* @param index
|
|
1271 |
* the index of the first character to be selected.
|
|
1272 |
* @param length
|
|
1273 |
* the length of the selection in characters, 0 length clears the
|
|
1274 |
* selection.
|
|
1275 |
*
|
|
1276 |
* @throws StringIndexOutOfBoundsException
|
|
1277 |
* if <code>index</code> and <code>length</code> do not specify
|
|
1278 |
* a valid range within the content of the
|
|
1279 |
* <code>TextEditor</code>
|
|
1280 |
*/
|
|
1281 |
public void setSelection(int index, int length)
|
|
1282 |
{
|
|
1283 |
iLCDUIPackageInvoker.checkOffset(index, length, size());
|
|
1284 |
|
|
1285 |
synchronized (iToolkit)
|
|
1286 |
{
|
|
1287 |
NativeError.check(_setSelection(getToolkitHandle(), iHandle, index,
|
|
1288 |
length));
|
|
1289 |
}
|
|
1290 |
}
|
|
1291 |
|
|
1292 |
/**
|
|
1293 |
* Gets the currently selected content in the <code>TextEditor</code>. A
|
|
1294 |
* selection may be set with setSelection method or by user interaction. If
|
|
1295 |
* selection is not set non-null empty string is returned.
|
|
1296 |
*
|
|
1297 |
* @return the currently selected content
|
|
1298 |
*/
|
|
1299 |
public String getSelection()
|
|
1300 |
{
|
|
1301 |
String selection = null;
|
|
1302 |
int[] error = new int[1];
|
|
1303 |
|
|
1304 |
synchronized (iToolkit)
|
|
1305 |
{
|
|
1306 |
selection = _getSelection(getToolkitHandle(), iHandle, error);
|
|
1307 |
}
|
|
1308 |
|
|
1309 |
NativeError.check(error[0]);
|
|
1310 |
return selection;
|
|
1311 |
}
|
|
1312 |
|
|
1313 |
/**
|
|
1314 |
* <P>
|
|
1315 |
* Sets a listener for content changes in this <code>TextEditor</code>,
|
|
1316 |
* replacing any previous <code>TextEditorListener</code>.
|
|
1317 |
* </P>
|
|
1318 |
*
|
|
1319 |
* <P>
|
|
1320 |
* A <code>null</code> reference is allowed and has the effect of removing
|
|
1321 |
* any existing <code>TextEditorListener</code> from this
|
|
1322 |
* <code>TextEditor</code>.
|
|
1323 |
* </P>
|
|
1324 |
*
|
|
1325 |
* <P>
|
|
1326 |
* Callbacks to the TextEditorListener may throw exceptions, but they must
|
|
1327 |
* be ignored.
|
|
1328 |
* </P>
|
|
1329 |
*
|
|
1330 |
* @param listener
|
|
1331 |
* the new listener, or <code>null</code>
|
|
1332 |
*/
|
|
1333 |
public void setTextEditorListener(TextEditorListener listener)
|
|
1334 |
{
|
|
1335 |
TextEditorListenerImpl newListener = null;
|
|
1336 |
int listenerHandle = 0;
|
|
1337 |
|
|
1338 |
// Create new listener implementation if listener has been defined.
|
|
1339 |
if (listener != null)
|
|
1340 |
{
|
|
1341 |
newListener = new TextEditorListenerImpl(this, listener);
|
|
1342 |
listenerHandle = newListener.getHandle();
|
|
1343 |
}
|
|
1344 |
|
|
1345 |
synchronized (iToolkit)
|
|
1346 |
{
|
|
1347 |
NativeError.check(_setListener(getToolkitHandle(), iHandle,
|
|
1348 |
listenerHandle));
|
|
1349 |
}
|
|
1350 |
|
|
1351 |
iListener = newListener;
|
|
1352 |
}
|
|
1353 |
|
|
1354 |
/**
|
|
1355 |
* Returns the multiline state of the <code>TextEditor</code>.
|
|
1356 |
*
|
|
1357 |
* @return the multiline state
|
|
1358 |
*/
|
|
1359 |
public boolean isMultiline()
|
|
1360 |
{
|
|
1361 |
boolean multiline = false;
|
|
1362 |
|
|
1363 |
synchronized (iToolkit)
|
|
1364 |
{
|
|
1365 |
multiline = _isMultiline(getToolkitHandle(), iHandle);
|
|
1366 |
}
|
|
1367 |
|
|
1368 |
return multiline;
|
|
1369 |
}
|
|
1370 |
|
|
1371 |
/**
|
|
1372 |
* Sets the editor to be either multi-line (true) or single-line (false).
|
|
1373 |
* TextEditor is by default single-line editor, which meeans that user
|
|
1374 |
* is not possible to insert line breaks to the editor. A possible Enter
|
|
1375 |
* (or similar) key event should be passed in this case to the parent object
|
|
1376 |
* as a normal key event for client to handle it as appropriately. A single-line
|
|
1377 |
* editor will have horizontal scrolling of text if it is possible to enter text
|
|
1378 |
* that does not fit to the editor. This may happen if maximum size is large enough
|
|
1379 |
* for the width of the editor.
|
|
1380 |
* In multi-line editor user is able to insert line breaks but also word
|
|
1381 |
* wrapping is enabled automatically on word boundaries.
|
|
1382 |
*
|
|
1383 |
* @param aMultiline
|
|
1384 |
* true if multi-line editor, false if single-line editor
|
|
1385 |
*
|
|
1386 |
* @throws IllegalStateException if a valid parent object has not been set.
|
|
1387 |
*/
|
|
1388 |
public void setMultiline(boolean aMultiline)
|
|
1389 |
{
|
|
1390 |
synchronized (iToolkit)
|
|
1391 |
{
|
|
1392 |
// Parent must be set
|
|
1393 |
checkParent();
|
|
1394 |
|
|
1395 |
NativeError.check(_setMultiline(getToolkitHandle(), iHandle,
|
|
1396 |
aMultiline));
|
|
1397 |
}
|
|
1398 |
}
|
|
1399 |
|
|
1400 |
/**
|
|
1401 |
* Gets the height of this <code>TextEditor</code> in pixels.
|
|
1402 |
*
|
|
1403 |
* @return height in pixels
|
|
1404 |
*/
|
|
1405 |
public int getHeight()
|
|
1406 |
{
|
|
1407 |
int[] size = doGetSize();
|
|
1408 |
return size[1];
|
|
1409 |
}
|
|
1410 |
|
|
1411 |
/**
|
|
1412 |
* Gets the width of this <code>TextEditor</code> in pixels.
|
|
1413 |
*
|
|
1414 |
* @return width in pixels
|
|
1415 |
*/
|
|
1416 |
public int getWidth()
|
|
1417 |
{
|
|
1418 |
int[] size = doGetSize();
|
|
1419 |
return size[0];
|
|
1420 |
}
|
|
1421 |
|
|
1422 |
/*
|
|
1423 |
* Gets TextEditor size in pixels - width, height.
|
|
1424 |
*/
|
|
1425 |
private int[] doGetSize()
|
|
1426 |
{
|
|
1427 |
int[] size = new int[2];
|
|
1428 |
synchronized (iToolkit)
|
|
1429 |
{
|
|
1430 |
NativeError.check(_getSize(getToolkitHandle(), iHandle,
|
|
1431 |
size));
|
|
1432 |
}
|
|
1433 |
return size;
|
|
1434 |
}
|
|
1435 |
|
|
1436 |
/*
|
|
1437 |
* Disposes the Landmark native peer object, if the handles are valid.
|
|
1438 |
* Invalid (negative) handles indicate that their creation failed in the
|
|
1439 |
* first place.
|
|
1440 |
*/
|
|
1441 |
final void registeredFinalize()
|
|
1442 |
{
|
|
1443 |
if (mFinalizer!=null)
|
|
1444 |
{
|
|
1445 |
synchronized (iToolkit)
|
|
1446 |
{
|
|
1447 |
if (iHandle > 0)
|
|
1448 |
{
|
|
1449 |
iToolkitInvoker.toolkitDisposeObject(iToolkit,iHandle);
|
|
1450 |
iHandle = 0;
|
|
1451 |
|
|
1452 |
if (iParent != null)
|
|
1453 |
{
|
|
1454 |
// Remove from editor container.
|
|
1455 |
iEditorContainer.removeEditor(this, iParent);
|
|
1456 |
}
|
|
1457 |
}
|
|
1458 |
}
|
|
1459 |
mFinalizer = null;
|
|
1460 |
}
|
|
1461 |
}
|
|
1462 |
|
|
1463 |
/*
|
|
1464 |
* Returns the native side handle to the LCDUI Toolkit.
|
|
1465 |
*
|
|
1466 |
* @return The native side handle to the LCDUI Toolkit.
|
|
1467 |
*/
|
|
1468 |
synchronized int getToolkitHandle()
|
|
1469 |
{
|
|
1470 |
return iToolkitInvoker.toolkitGetHandle(iToolkit);
|
|
1471 |
}
|
|
1472 |
|
|
1473 |
/*
|
|
1474 |
* Package private default constructor.
|
|
1475 |
*/
|
|
1476 |
TextEditor()
|
|
1477 |
{
|
|
1478 |
}
|
|
1479 |
|
|
1480 |
/*
|
|
1481 |
* Package private constructor.
|
|
1482 |
*
|
|
1483 |
* Allocates the needed native side resources.
|
|
1484 |
*
|
|
1485 |
* @param aContent The content of the editor.
|
|
1486 |
*
|
|
1487 |
* @param maxSize The maximum Size of the editor.
|
|
1488 |
*
|
|
1489 |
* @param constraints The constraints of the editor.
|
|
1490 |
*
|
|
1491 |
* @param aWidth The width of the editor in pixels.
|
|
1492 |
*
|
|
1493 |
* @param aHeight The height of the editor in pixels on in rows.
|
|
1494 |
*
|
|
1495 |
* @param aHeighInRows If <code>true</code>, height is measured as row
|
|
1496 |
* count.
|
|
1497 |
*
|
|
1498 |
* @throws IllegalArgumentException if the width or height is less than one
|
|
1499 |
* pixel
|
|
1500 |
*/
|
|
1501 |
TextEditor(
|
|
1502 |
String aContent,
|
|
1503 |
int maxSize,
|
|
1504 |
int constraints,
|
|
1505 |
int aWidth,
|
|
1506 |
int aHeight,
|
|
1507 |
boolean aHeightInRows)
|
|
1508 |
{
|
|
1509 |
// Get text component invoker.
|
|
1510 |
iLCDUIPackageInvoker = LCDUIPackageInvoker.getInvoker();
|
|
1511 |
// Check that the give the given text is valid.
|
|
1512 |
checkValid(aContent, maxSize, constraints);
|
|
1513 |
|
|
1514 |
// Validate width and height.
|
|
1515 |
if (aWidth < 1 || aHeight < 1)
|
|
1516 |
{
|
|
1517 |
throw new IllegalArgumentException(ERROR_GIVEN_ARGUMENTS_NOT_VALID);
|
|
1518 |
}
|
|
1519 |
|
|
1520 |
// Toolkit invoker is needed for accessing javax.microedition.lcdui
|
|
1521 |
// package
|
|
1522 |
iToolkitInvoker = ToolkitInvoker.getToolkitInvoker();
|
|
1523 |
iToolkit = iToolkitInvoker.getToolkit();
|
|
1524 |
|
|
1525 |
int handle = 0;
|
|
1526 |
|
|
1527 |
synchronized (iToolkit)
|
|
1528 |
{
|
|
1529 |
// Create native peer object for this Java object.
|
|
1530 |
handle =
|
|
1531 |
_createNativePeer(getToolkitHandle(), maxSize, aWidth, aHeight,
|
|
1532 |
aHeightInRows);
|
|
1533 |
}
|
|
1534 |
|
|
1535 |
// Check if construction failed and throw out of memory error.
|
|
1536 |
if (handle <= NativeError.KErrNone)
|
|
1537 |
{
|
|
1538 |
throw new OutOfMemoryError();
|
|
1539 |
}
|
|
1540 |
|
|
1541 |
// Sets parent to null
|
|
1542 |
iParent = null;
|
|
1543 |
|
|
1544 |
// Construction was successful. Store handle and register for
|
|
1545 |
// finalization.
|
|
1546 |
iHandle = handle;
|
|
1547 |
mFinalizer = new Finalizer()
|
|
1548 |
{
|
|
1549 |
public void finalizeImpl()
|
|
1550 |
{
|
|
1551 |
registeredFinalize();
|
|
1552 |
}
|
|
1553 |
};
|
|
1554 |
|
|
1555 |
// Set the constraints of the editor. The content is now empty.
|
|
1556 |
setConstraints(constraints);
|
|
1557 |
|
|
1558 |
// Store the maxSize of the editor
|
|
1559 |
iMaxSize = maxSize;
|
|
1560 |
|
|
1561 |
// Set the text. This now throws an exception if the content is not
|
|
1562 |
// valid for the current set of constraints.
|
|
1563 |
setContent(aContent);
|
|
1564 |
|
|
1565 |
// Set font to Java default font.
|
|
1566 |
setFont(Font.getDefaultFont());
|
|
1567 |
}
|
|
1568 |
|
|
1569 |
// Private methods.
|
|
1570 |
|
|
1571 |
/*
|
|
1572 |
* Checks that the given arguments are valid.
|
|
1573 |
*
|
|
1574 |
* @param text The text to check.
|
|
1575 |
*
|
|
1576 |
* @param maxSize The maximum size to check.
|
|
1577 |
*
|
|
1578 |
* @param constraints The constraints to check.
|
|
1579 |
*
|
|
1580 |
* @throws java.lang.IllegalArgumentException if the arguments are not
|
|
1581 |
* valid.
|
|
1582 |
*/
|
|
1583 |
private void checkValid(String text, int maxSize, int constraints)
|
|
1584 |
{
|
|
1585 |
try
|
|
1586 |
{
|
|
1587 |
iLCDUIPackageInvoker.checkText(text, maxSize);
|
|
1588 |
iLCDUIPackageInvoker.checkConstraints(constraints);
|
|
1589 |
}
|
|
1590 |
catch (IllegalArgumentException e)
|
|
1591 |
{
|
|
1592 |
throw new IllegalArgumentException(ERROR_GIVEN_ARGUMENTS_NOT_VALID);
|
|
1593 |
}
|
|
1594 |
}
|
|
1595 |
|
|
1596 |
/*
|
|
1597 |
* Sets the specified color for the specified color type.
|
|
1598 |
*
|
|
1599 |
* @param alpha the alpha component of the color being set within range
|
|
1600 |
* <code>0-255</code>
|
|
1601 |
*
|
|
1602 |
* @param red the red component of the color being set within range
|
|
1603 |
* <code>0-255</code>
|
|
1604 |
*
|
|
1605 |
* @param green the green component of the color being set within range
|
|
1606 |
* <code>0-255</code>
|
|
1607 |
*
|
|
1608 |
* @param blue the blue component of the color being set within range
|
|
1609 |
* <code>0-255</code>
|
|
1610 |
*
|
|
1611 |
* @param aColorType the type of the color to be set.
|
|
1612 |
*
|
|
1613 |
* @throws IllegalArgumentException if any of the parameters is outside the
|
|
1614 |
* range of <code>0-255</code>
|
|
1615 |
*/
|
|
1616 |
private void doSetColor(
|
|
1617 |
int alpha,
|
|
1618 |
int red,
|
|
1619 |
int green,
|
|
1620 |
int blue,
|
|
1621 |
int aColorType)
|
|
1622 |
{
|
|
1623 |
if ((alpha < 0 || alpha > COLOR_MAX_VALUE)
|
|
1624 |
|| (red < 0 || red > COLOR_MAX_VALUE)
|
|
1625 |
|| (green < 0 || green > COLOR_MAX_VALUE)
|
|
1626 |
|| (blue < 0 || blue > COLOR_MAX_VALUE))
|
|
1627 |
{
|
|
1628 |
throw new IllegalArgumentException(ERROR_GIVEN_ARGUMENTS_NOT_VALID);
|
|
1629 |
}
|
|
1630 |
|
|
1631 |
int[] color = new int[] { red, green, blue, alpha };
|
|
1632 |
|
|
1633 |
synchronized (iToolkit)
|
|
1634 |
{
|
|
1635 |
NativeError.check(_setColor(getToolkitHandle(), iHandle, color,
|
|
1636 |
aColorType));
|
|
1637 |
}
|
|
1638 |
}
|
|
1639 |
|
|
1640 |
// Native methods
|
|
1641 |
|
|
1642 |
/*
|
|
1643 |
* Creates the native side peer object for this TextEditor.
|
|
1644 |
*
|
|
1645 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1646 |
*
|
|
1647 |
* @param maxSize The maximum size of the content in the text editor.
|
|
1648 |
*
|
|
1649 |
* @param aWidth The new width of this text editor.
|
|
1650 |
*
|
|
1651 |
* @param aHeight The new hight of this text editor.
|
|
1652 |
*
|
|
1653 |
* @param aHeightInRows If <code>true</code> height is measured in rows.
|
|
1654 |
*
|
|
1655 |
* @param aSize On return, contains the size of the editor as width and
|
|
1656 |
* height.
|
|
1657 |
*
|
|
1658 |
* @return A handle to the the native side peer object or a system-wide
|
|
1659 |
* error code.
|
|
1660 |
*/
|
|
1661 |
private native int _createNativePeer(
|
|
1662 |
int aToolkitHandle,
|
|
1663 |
int maxSize,
|
|
1664 |
int aWidth,
|
|
1665 |
int aHeight,
|
|
1666 |
boolean aHeightInRows);
|
|
1667 |
|
|
1668 |
/*
|
|
1669 |
* Disposes the native side peer object.
|
|
1670 |
*
|
|
1671 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1672 |
*
|
|
1673 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1674 |
*/
|
|
1675 |
private native void _dispose(int aToolkitHandle, int aNativePeerHandle);
|
|
1676 |
|
|
1677 |
/*
|
|
1678 |
* Sets the size of this text editor using the given width and height.
|
|
1679 |
*
|
|
1680 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1681 |
*
|
|
1682 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1683 |
*
|
|
1684 |
* @param aWidth The new width of this text editor.
|
|
1685 |
*
|
|
1686 |
* @param aHeight The new hight of this text editor.
|
|
1687 |
*
|
|
1688 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
1689 |
* a system-wide error code is returned.
|
|
1690 |
*/
|
|
1691 |
private native int _setSize(
|
|
1692 |
int aToolkitHandle,
|
|
1693 |
int aNativePeerHandle,
|
|
1694 |
int aWidth,
|
|
1695 |
int aHeight);
|
|
1696 |
|
|
1697 |
/*
|
|
1698 |
* Disposes the native side peer object.
|
|
1699 |
*
|
|
1700 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1701 |
*
|
|
1702 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1703 |
*
|
|
1704 |
* @param aParentHandle A handle to the parent object.
|
|
1705 |
*
|
|
1706 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
1707 |
* a system-wide error code is returned.
|
|
1708 |
*/
|
|
1709 |
private native int _setParent(
|
|
1710 |
int aToolkitHandle,
|
|
1711 |
int aNativePeerHandle,
|
|
1712 |
int aParentHandle);
|
|
1713 |
|
|
1714 |
/*
|
|
1715 |
* Sets the focus state of text editor.
|
|
1716 |
*
|
|
1717 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1718 |
*
|
|
1719 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1720 |
*
|
|
1721 |
* @param aFocused Indicates whether the text editor should be focused or
|
|
1722 |
* not.
|
|
1723 |
*
|
|
1724 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
1725 |
* a system-wide error code is returned.
|
|
1726 |
*/
|
|
1727 |
private native int _setFocusState(
|
|
1728 |
int aToolkitHandle,
|
|
1729 |
int aNativePeerHandle,
|
|
1730 |
boolean aFocusState);
|
|
1731 |
|
|
1732 |
/*
|
|
1733 |
* Gets focus state of the text editor.
|
|
1734 |
*
|
|
1735 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1736 |
*
|
|
1737 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1738 |
*
|
|
1739 |
* @param aFocused Indicates whether the text editor should be focused or
|
|
1740 |
* not.
|
|
1741 |
*
|
|
1742 |
* @return focus state.
|
|
1743 |
*/
|
|
1744 |
private native boolean _getFocusState(int aToolkitHandle,
|
|
1745 |
int aNativePeerHandle);
|
|
1746 |
|
|
1747 |
/*
|
|
1748 |
* Gets the multiline setting of TextEditor.
|
|
1749 |
*
|
|
1750 |
* @return the multiline state.
|
|
1751 |
*/
|
|
1752 |
private native boolean _isMultiline(int aToolkitHandle,
|
|
1753 |
int aNativePeerHandle);
|
|
1754 |
|
|
1755 |
/*
|
|
1756 |
* Sets the text editor visible.
|
|
1757 |
*
|
|
1758 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1759 |
*
|
|
1760 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1761 |
*
|
|
1762 |
* @param aVisible The visibility status of this text editor.
|
|
1763 |
*
|
|
1764 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
1765 |
* a system-wide error code is returned.
|
|
1766 |
*/
|
|
1767 |
private native int _setVisible(
|
|
1768 |
int aToolkitHandle,
|
|
1769 |
int aNativePeerHandle,
|
|
1770 |
boolean aVisible);
|
|
1771 |
|
|
1772 |
/*
|
|
1773 |
* Sets the text editor's position.
|
|
1774 |
*
|
|
1775 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1776 |
*
|
|
1777 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1778 |
*
|
|
1779 |
* @param aX The x coordinate of the anchor point.
|
|
1780 |
*
|
|
1781 |
* @param aY The y coordinate of the anchor point.
|
|
1782 |
*
|
|
1783 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
1784 |
* a system-wide error code is returned.
|
|
1785 |
*/
|
|
1786 |
private native int _setPosition(
|
|
1787 |
int aToolkitHandle,
|
|
1788 |
int aNativePeerHandle,
|
|
1789 |
int aX,
|
|
1790 |
int aY);
|
|
1791 |
|
|
1792 |
/*
|
|
1793 |
* Sets the text input constraints of this text editor.
|
|
1794 |
*
|
|
1795 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1796 |
*
|
|
1797 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1798 |
*
|
|
1799 |
* @param constraints The new constraints for the editor.
|
|
1800 |
*
|
|
1801 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
1802 |
* a system-wide error code is returned.
|
|
1803 |
*/
|
|
1804 |
private native int _setConstraints(
|
|
1805 |
int aToolkitHandle,
|
|
1806 |
int aNativePeerHandle,
|
|
1807 |
int constraints);
|
|
1808 |
|
|
1809 |
/*
|
|
1810 |
* Sets the editor to be either multi-line (true) or single-line (false).
|
|
1811 |
*
|
|
1812 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1813 |
*
|
|
1814 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1815 |
*
|
|
1816 |
* @param aMultiline True if multi-line editor, false if single-line editor.
|
|
1817 |
*
|
|
1818 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
1819 |
* a system-wide error code is returned.
|
|
1820 |
*/
|
|
1821 |
private native int _setMultiline(
|
|
1822 |
int aToolkitHandle,
|
|
1823 |
int aNativePeerHandle,
|
|
1824 |
boolean aMultiline);
|
|
1825 |
|
|
1826 |
/*
|
|
1827 |
* Sets the initial input mode of this text editor.
|
|
1828 |
*
|
|
1829 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1830 |
*
|
|
1831 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1832 |
*
|
|
1833 |
* @param characterSubset The character subset.
|
|
1834 |
*
|
|
1835 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
1836 |
* a system-wide error code is returned.
|
|
1837 |
*/
|
|
1838 |
private native int _setInitialInputMode(
|
|
1839 |
int aToolkitHandle,
|
|
1840 |
int aNativePeerHandle,
|
|
1841 |
String characterSubset);
|
|
1842 |
|
|
1843 |
/*
|
|
1844 |
* Deletes the content in the text editor.
|
|
1845 |
*
|
|
1846 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1847 |
*
|
|
1848 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1849 |
*
|
|
1850 |
* @param offset The beginning of the range to be deleted.
|
|
1851 |
*
|
|
1852 |
* @param length The lenght of the range to be deleted.
|
|
1853 |
*
|
|
1854 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
1855 |
* a system-wide error code is returned.
|
|
1856 |
*/
|
|
1857 |
private native int _delete(
|
|
1858 |
int aToolkitHandle,
|
|
1859 |
int aNativePeerHandle,
|
|
1860 |
int offset,
|
|
1861 |
int length);
|
|
1862 |
|
|
1863 |
/*
|
|
1864 |
* Returns the number of characters in the text editor.
|
|
1865 |
*
|
|
1866 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1867 |
*
|
|
1868 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1869 |
*
|
|
1870 |
* @param The number of characters in the text editor or a system-wide error
|
|
1871 |
* code if the operation failed.
|
|
1872 |
*/
|
|
1873 |
private native int _size(int aToolkitHandle, int aNativePeerHandle);
|
|
1874 |
|
|
1875 |
/*
|
|
1876 |
* Returns the line margin height in the text editor.
|
|
1877 |
*
|
|
1878 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1879 |
*
|
|
1880 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1881 |
*
|
|
1882 |
* @return The line margin height in the text editor or a system-wide error
|
|
1883 |
* code if the operation failed.
|
|
1884 |
*/
|
|
1885 |
private native int _getLineMarginHeight(
|
|
1886 |
int aToolkitHandle,
|
|
1887 |
int aNativePeerHandle);
|
|
1888 |
|
|
1889 |
/*
|
|
1890 |
* Returns the number of characters in the text editor.
|
|
1891 |
*
|
|
1892 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1893 |
*
|
|
1894 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1895 |
*
|
|
1896 |
* @return The full content hight in the text editor or a system-wide error
|
|
1897 |
* code if the operation failed.
|
|
1898 |
*/
|
|
1899 |
private native int _getContentHeight(
|
|
1900 |
int aToolkitHandle,
|
|
1901 |
int aNativePeerHandle);
|
|
1902 |
|
|
1903 |
/*
|
|
1904 |
* Sets the content of this text editor.
|
|
1905 |
*
|
|
1906 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1907 |
*
|
|
1908 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1909 |
*
|
|
1910 |
* @param aContent The new content of this text editor.
|
|
1911 |
*
|
|
1912 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
1913 |
* a system-wide error code is returned.
|
|
1914 |
*/
|
|
1915 |
private native int _setContent(
|
|
1916 |
int aToolkitHandle,
|
|
1917 |
int aNativePeerHandle,
|
|
1918 |
String aContent);
|
|
1919 |
|
|
1920 |
/*
|
|
1921 |
* Inserts content to this text editor.
|
|
1922 |
*
|
|
1923 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1924 |
*
|
|
1925 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1926 |
*
|
|
1927 |
* @param aContent The content to be inserted to this text editor.
|
|
1928 |
*
|
|
1929 |
* @param position The position to which the content should be inserted.
|
|
1930 |
*
|
|
1931 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
1932 |
* a system-wide error code is returned.
|
|
1933 |
*/
|
|
1934 |
private native int _insert(
|
|
1935 |
int aToolkitHandle,
|
|
1936 |
int aNativePeerHandle,
|
|
1937 |
String aContent,
|
|
1938 |
int position);
|
|
1939 |
|
|
1940 |
/*
|
|
1941 |
* Gets the content of this text editor.
|
|
1942 |
*
|
|
1943 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1944 |
*
|
|
1945 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1946 |
*
|
|
1947 |
* @param aError On return contains the error code for the operation.
|
|
1948 |
*
|
|
1949 |
* @return The content of the editor as a string.
|
|
1950 |
*/
|
|
1951 |
private native String _getContent(
|
|
1952 |
int aToolkitHandle,
|
|
1953 |
int aNativePeerHandle,
|
|
1954 |
int[] aError);
|
|
1955 |
|
|
1956 |
/*
|
|
1957 |
* Sets the maximum size of this text editor.
|
|
1958 |
*
|
|
1959 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1960 |
*
|
|
1961 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1962 |
*
|
|
1963 |
* @param maxSize The new maximum size of this text editor.
|
|
1964 |
*
|
|
1965 |
* @return The maximum size of the editor if the operation was successful.
|
|
1966 |
* Otherwise, a system-wide error code is returned.
|
|
1967 |
*/
|
|
1968 |
private native int _setMaxSize(
|
|
1969 |
int aToolkitHandle,
|
|
1970 |
int aNativePeerHandle,
|
|
1971 |
int maxSize);
|
|
1972 |
|
|
1973 |
/*
|
|
1974 |
* Returns the current position of the caret in the text editor.
|
|
1975 |
*
|
|
1976 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1977 |
*
|
|
1978 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1979 |
*
|
|
1980 |
* @param The current position of the caret or a system-wide error code if
|
|
1981 |
* the operation failed.
|
|
1982 |
*/
|
|
1983 |
private native int _getCaretPosition(
|
|
1984 |
int aToolkitHandle,
|
|
1985 |
int aNativePeerHandle);
|
|
1986 |
|
|
1987 |
/*
|
|
1988 |
* Returns the topmost pixel's position of the visible content.
|
|
1989 |
*
|
|
1990 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
1991 |
*
|
|
1992 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
1993 |
*
|
|
1994 |
* @param The topmost pixel's position of the visible content or a
|
|
1995 |
* system-wide error code if the operation failed.
|
|
1996 |
*/
|
|
1997 |
private native int _getVisibleContentPosition(
|
|
1998 |
int aToolkitHandle,
|
|
1999 |
int aNativePeerHandle);
|
|
2000 |
|
|
2001 |
/*
|
|
2002 |
* Sets a new position for the caret in the text editor.
|
|
2003 |
*
|
|
2004 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
2005 |
*
|
|
2006 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
2007 |
*
|
|
2008 |
* @param index The new position of the caret.
|
|
2009 |
*
|
|
2010 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
2011 |
* a system-wide error code is returned.
|
|
2012 |
*/
|
|
2013 |
private native int _setCaret(
|
|
2014 |
int aToolkitHandle,
|
|
2015 |
int aNativePeerHandle,
|
|
2016 |
int index);
|
|
2017 |
|
|
2018 |
/*
|
|
2019 |
* Sets a new color for the specified color type in the text editor.
|
|
2020 |
*
|
|
2021 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
2022 |
*
|
|
2023 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
2024 |
*
|
|
2025 |
* @param aColor An array containing new color value (r,g,b,a).
|
|
2026 |
*
|
|
2027 |
* @param aColorType Type of color to set.
|
|
2028 |
*
|
|
2029 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
2030 |
* a system-wide error code is returned.
|
|
2031 |
*/
|
|
2032 |
private native int _setColor(
|
|
2033 |
int aToolkitHandle,
|
|
2034 |
int aNativePeerHandle,
|
|
2035 |
int[] aColor,
|
|
2036 |
int aColorType);
|
|
2037 |
|
|
2038 |
/*
|
|
2039 |
* Gets a color of the specified color type from the text editor.
|
|
2040 |
*
|
|
2041 |
*
|
|
2042 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
2043 |
*
|
|
2044 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
2045 |
*
|
|
2046 |
* @param aColorType Type of color to set.
|
|
2047 |
*
|
|
2048 |
* @return color in RGBA
|
|
2049 |
*/
|
|
2050 |
private native int _getColor(
|
|
2051 |
int aToolkitHandle,
|
|
2052 |
int aNativePeerHandle,
|
|
2053 |
int aColorType);
|
|
2054 |
|
|
2055 |
/*
|
|
2056 |
* Selects the specified range of text in the text editor.
|
|
2057 |
*
|
|
2058 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
2059 |
*
|
|
2060 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
2061 |
*
|
|
2062 |
* @param index The beginning of the range to be selected.
|
|
2063 |
*
|
|
2064 |
* @param length The lenght of the range to be selected.
|
|
2065 |
*
|
|
2066 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
2067 |
* a system-wide error code is returned.
|
|
2068 |
*/
|
|
2069 |
private native int _setSelection(
|
|
2070 |
int aToolkitHandle,
|
|
2071 |
int aNativePeerHandle,
|
|
2072 |
int index,
|
|
2073 |
int length);
|
|
2074 |
|
|
2075 |
/*
|
|
2076 |
* Gets the current selection of this text editor.
|
|
2077 |
*
|
|
2078 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
2079 |
*
|
|
2080 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
2081 |
*
|
|
2082 |
* @param aError On return contains the error code for the operation.
|
|
2083 |
*
|
|
2084 |
* @return The selected content of the editor as a string.
|
|
2085 |
*/
|
|
2086 |
private native String _getSelection(
|
|
2087 |
int aToolkitHandle,
|
|
2088 |
int aNativePeerHandle,
|
|
2089 |
int[] aError);
|
|
2090 |
|
|
2091 |
/*
|
|
2092 |
* Sets the specified font for the text editor.
|
|
2093 |
*
|
|
2094 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
2095 |
*
|
|
2096 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
2097 |
*
|
|
2098 |
* @param aFont The application preferred font to be used in this
|
|
2099 |
* TextEditor.
|
|
2100 |
*
|
|
2101 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
2102 |
* a system-wide error code is returned.
|
|
2103 |
*/
|
|
2104 |
private native int _setFont(
|
|
2105 |
int aToolkitHandle,
|
|
2106 |
int aNativePeerHandle,
|
|
2107 |
int aFont);
|
|
2108 |
|
|
2109 |
/*
|
|
2110 |
* Sets a listener for this text editor.
|
|
2111 |
*
|
|
2112 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
2113 |
*
|
|
2114 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
2115 |
*
|
|
2116 |
* @param listenerHandle A handle to the listener.
|
|
2117 |
*
|
|
2118 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
2119 |
* a system-wide error code is returned.
|
|
2120 |
*/
|
|
2121 |
private native int _setListener(
|
|
2122 |
int aToolkitHandle,
|
|
2123 |
int aNativePeerHandle,
|
|
2124 |
int listenerHandle);
|
|
2125 |
|
|
2126 |
/*
|
|
2127 |
* Sets the elevation of this text editor.
|
|
2128 |
*
|
|
2129 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
2130 |
*
|
|
2131 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
2132 |
*
|
|
2133 |
* @param aZ The new z-position.
|
|
2134 |
*
|
|
2135 |
* @return NativeError.KErrNone if the operation was successful. Otherwise,
|
|
2136 |
* a system-wide error code is returned.
|
|
2137 |
*/
|
|
2138 |
private native int _setZPosition(
|
|
2139 |
int aToolkitHandle,
|
|
2140 |
int aNativePeerHandle,
|
|
2141 |
int aZ);
|
|
2142 |
|
|
2143 |
/*
|
|
2144 |
* Gets the elevation of this text editor.
|
|
2145 |
*
|
|
2146 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
2147 |
*
|
|
2148 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
2149 |
*
|
|
2150 |
* @return The elevation if the operation was successful. Otherwise, a
|
|
2151 |
* system-wide error code is returned.
|
|
2152 |
*/
|
|
2153 |
private native int _getZPosition(int aToolkitHandle, int aNativePeerHandle);
|
|
2154 |
|
|
2155 |
/*
|
|
2156 |
* Gets the size of the text editor.
|
|
2157 |
*
|
|
2158 |
* @param aToolkitHandle A handle to the LCDUI toolkit.
|
|
2159 |
*
|
|
2160 |
* @param aNativePeerHandle A handle to the native side peer object.
|
|
2161 |
*
|
|
2162 |
* @return The size of the TextEditor in pixels.
|
|
2163 |
*/
|
|
2164 |
private native int _getSize(int aToolkitHandle, int aNativePeerHandle,
|
|
2165 |
int[] aSize);
|
|
2166 |
}
|
|
2167 |
|
|
2168 |
// End of file
|