FileDocCategorySizeDatePackage
TextFieldLFImpl.javaAPI DocphoneME MR2 API (J2ME)11044Wed May 02 18:00:22 BST 2007javax.microedition.lcdui

TextFieldLFImpl

public class TextFieldLFImpl extends ItemLFImpl implements TextFieldLF
Look and feel implementation of TextField based on platform widget.

Fields Summary
TextField
tf
TextField instance associated with this view.
Constructors Summary
TextFieldLFImpl(TextField tf)
Creates TextFieldLF for the passed in TextField.

param
tf The TextField associated with this TextFieldLF

        super(tf);

        this.tf  = tf;
    
Methods Summary
voidcreateNativeResource(int ownerId)
Create native resource for current TextField. Override function in ItemLFImpl.

param
ownerId Owner screen's native resource id

	nativeId = createNativeResource0(ownerId,
					 tf.label,
					 (tf.owner instanceof TextBox ? 
					  -1 : tf.layout),
					 tf.buffer,
					 tf.constraints,
					 tf.initialInputMode);
    
private native intcreateNativeResource0(int ownerId, java.lang.String label, int layout, com.sun.midp.lcdui.DynamicCharacterArray buffer, int constraints, java.lang.String initialInputMode)
KNI function that create native resource for current TextField.

param
ownerId Owner screen's native resource id (MidpDisplayable *)
param
label label of the item
param
layout layout directive associated with this Item
param
buffer char array of the contents
param
constraints input constraints
param
initialInputMode suggested input mode on creation
return
native resource id (MidpItem *) of this Item

booleanequateNLA()
Determine if this Item should have a newline after it.

return
true if it should have a newline after

        if (super.equateNLA()) {
            return true;
        }

        return ((tf.layout & Item.LAYOUT_2) != Item.LAYOUT_2);
    
booleanequateNLB()
Determine if this Item should have a newline before it.

return
true if it should have a newline before

        if (super.equateNLB()) {
            return true;
        }

        return ((tf.layout & Item.LAYOUT_2) != Item.LAYOUT_2);
    
private native intgetCaretPosition0(int nativeId)
Gets the current input position from native widget.

param
nativeId native resource id of this Item
return
current caret position

private native booleangetString0(int nativeId, com.sun.midp.lcdui.DynamicCharacterArray buffer)
Get current contents from native resource.

param
nativeId native resource id of this Item
param
buffer the char array to be populated
return
true if there is new input

public voiditemDeleted()
Notifies item that it has been recently deleted Traverse out the textFieldLF.

         uCallTraverseOut();
     
public voidlDelete(int offset, int length)
Notifies L&F of character deletion in the corresponding TextField.

param
offset the beginning of the deleted region
param
length the number of characters deleted

	// Simplify porting layer by treating delete as setChars
	lSetChars();
    
public intlGetCaretPosition()
Gets the current input position.

return
the current caret position, 0 if at the beginning

	return (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID)
		? getCaretPosition0(nativeId)
		: tf.buffer.length();
    
public intlGetPreferredHeight(int w)
Override the preferred height of this Item.

param
w tentative locked width. Ignored here and preferred width is used always.
return
the preferred height


	// note: w is not used

	int h = super.lGetPreferredHeight(w);
	
	// For TextBox return all height available for the item
	if (tf.owner instanceof TextBox) {
	    if (((DisplayableLFImpl)tf.owner.getLF()).height > h) {
		h = ((DisplayableLFImpl)tf.owner.getLF()).height;
	    }
	}
	return h;
    
public intlGetPreferredWidth(int h)
Override the preferred width of this Item.

param
h tentative locked height. Ignored here.
return
the preferred width


	// note: h is not used

	// For TextBox return all width available for the item
	if (tf.owner instanceof TextBox) {
	    return ((DisplayableLFImpl)tf.owner.getLF()).width;
	}
	return super.lGetPreferredWidth(h);
    
voidlHideNativeResource()
Override ItemLFImpl method to sync with native resource before hiding the native resource.

	lUpdateContents();
	super.lHideNativeResource();
    
public voidlInsert(char[] data, int offset, int length, int position)
Notifies L&F of a character insertion in the corresponding TextField.

param
data the source of the character data. Not used.
param
offset the beginning of the region of characters copied. Not used.
param
length the number of characters copied. Not used.
param
position the position at which insertion occurred

	// Simplify porting layer by treating insert as setChars
	lSetChars();
    
public voidlSetChars()
Notifies L&F of a content change in the corresponding TextField. The parameters are not used. Instead, this function directly uses data from TextField.java.

	// Only update native resource if it exists.
	if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
	    setString0(nativeId, tf.buffer);
	}

	lRequestInvalidate(true, true);
    
public voidlSetConstraints()
Notifies L&F that constraints have to be changed.


	// Only update native resource if it exists.
	if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
	    setConstraints0(nativeId, tf.constraints);
	}

	// note: int some implementation this method call may affect
	// the layout, and int this case such a call will be needed:
        // lRequestInvalidate(true, true);
    
public voidlSetInitialInputMode(java.lang.String characterSubset)
Notifies L&F that preferred initial input mode was changed.

param
characterSubset a string naming a Unicode character subset, or null

	// No visual impact
    
public voidlSetMaxSize(int maxSize)
Notifies L&F of a maximum size change in the corresponding TextField.

param
maxSize the new maximum size

	// Only update native resource if it exists.
	if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
	    setMaxSize0(nativeId, maxSize);
	}

	lRequestInvalidate(true, true);
    
public booleanlUpdateContents()
Update the character buffer in TextField with latest user input.

return
true if there is new user input updated in the buffer

	// No pending user input when there is no native resource or not shown
	if (nativeId == DisplayableLFImpl.INVALID_NATIVE_ID) {
	    return false;
	}

	// Query native resource for pending user input
	return getString0(nativeId, tf.buffer);
    
public booleanlValidate(com.sun.midp.lcdui.DynamicCharacterArray buffer, int constraints)
Validate a given character array against a constraints.

param
buffer a character array
param
constraints text input constraints
return
true if constraints is met by the character array

	return TextPolicy.isValidString(buffer, constraints);
    
private native voidsetConstraints0(int nativeId, int constraints)
Set input constraints of the native widget.

param
nativeId native resource id of this Item
param
constraints the new input constraints

private native voidsetMaxSize0(int nativeId, int maxSize)
Set new maximum size of the native widget.

param
nativeId native resource id of this Item
param
maxSize new maximum size

private native voidsetString0(int nativeId, com.sun.midp.lcdui.DynamicCharacterArray buffer)
Update content and caret position of the TextField's native widget.

param
nativeId native resource id of this Item
param
buffer char array of the new contents

booleanuCallPeerStateChanged(int hint)
Called by event delivery to notify an ItemLF in current FormLF of a change in its peer state.

param
hint any value means contents have changed in native
return
always true to notify ItemStateListener

	return true;