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

DateFieldLFImpl

public class DateFieldLFImpl extends ItemLFImpl implements DateFieldLF
Look and feel implementation of DateField based on platform widget.

Fields Summary
private DateField
df
DateField associated with this view.
private boolean
dateSynced
Flag indicating if date value stored in java is up to date with native. When visible, the date is stored in the native widget. When hiding (and destroying) the native resource, we need to cache the value in the java peer for later use. dateSynced flag is a dirty bit used to check if a sync is needed when hiding.
Constructors Summary
DateFieldLFImpl(DateField dateField)
Creates DateFieldLF for the passed in DateField object.

param
dateField the DateField object associated with this view

        super(dateField);

        df = dateField;
    
Methods Summary
voidcreateNativeResource(int ownerId)
Create native resource for current DateField. Override function in ItemLFImpl.

param
ownerId Owner screen's native resource id

	nativeId = createNativeResource0(ownerId,
					 df.label,
					 df.layout,
					 (df.getDate() != null ?
					  df.currentDate.getTime().getTime():
					  0),
					 df.mode,
					 df.currentDate.getTimeZone().getID());
	
	if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
	    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
			   "(createNativeResource: id="+nativeId+")");
	}
    
private native intcreateNativeResource0(int ownerId, java.lang.String label, int layout, long datetime, int displayMode, java.lang.String timeZone)
KNI function that create native resource for current DateField.

param
ownerId Owner screen's native resource id (MidpDisplayable *)
param
label label sting of this Item
param
layout layout directive associated with this DateField.
param
datetime date in millis since Jan 1'st 1970
param
displayMode date and or time mode
param
timeZone label of timezone
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 ((df.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 ((df.layout & Item.LAYOUT_2) != Item.LAYOUT_2);
    
private native longgetDate0(int nativeId)
Gets the current value set on the native datefield.

param
nativeId native resource id of this Item
return
time in millis since 1970

public java.util.DatelGetDate()
Gets the date currently set on the date field widget. This method is called by Date only if Date is initialized.

return
the date this widget is currently set to


	if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
	    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
			   "(mdGetDate: id="+nativeId+")");
	}

	if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {

	    long ld = getDate0(nativeId);
			
	    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
		Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
			       "(mdGetDate: returned long=="+ld+")");
	    }
	    if (ld > 0) {
		Date nd = new Date(ld);
		df.setDateImpl(nd);
		dateSynced = true;
		return nd;
	    }    
	} else if (dateSynced && df.currentDate != null) {
	    return df.currentDate.getTime();
	}

	return null;
    
voidlHideNativeResource()
Overrides ItemLFImpl to sync with native resource before hiding it Called by the system to hide this Item's native resource


	if (!dateSynced) {
	    // sync java peer with native data before hiding
	    df.setDateImpl(lGetDate());
	    dateSynced = true;
	}

	super.lHideNativeResource();
    
public voidlSetDate(java.util.Date date)
Notifies L&F of a date change in the corresponding DateField.

param
date the new Date set in the DateField

	if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
	    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
			   "(mdSetDate: id="+nativeId+")");
	}

	if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
	    if (date != null) {	    
		setDate0(nativeId, date.getTime());
	    } else {
		setDate0(nativeId, 0l);
	    }
	}
    
public voidlSetInputMode(int mode)
Notifies L&F of a new input mode set in the corresponding DateField.

param
mode the new input mode set in the DateField.


	if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
	    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
			   "(mdSetInputMode: id="+nativeId+")");
	}

	if (nativeId != DisplayableLFImpl.INVALID_NATIVE_ID) {
	    setInputMode0(nativeId, mode);
	    lRequestInvalidate(true, true);
	}
    
private native voidsetDate0(int nativeId, long date)
Setting date/time of this widget.

param
nativeId native resource id of this Item
param
date in seconds

private native voidsetInputMode0(int nativeId, int mode)
Set mode - time and or date.

param
nativeId native resource id of this Item
param
mode the new input mode set in the DateField.

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

param
hint 1 if date, 2 if hour, 3 if minute changed
return
always true to notify ItemStateListener

 
	// Any hint means user has changed some aspect of the date in native
	// since native peer changed, java peer is no longer up to date.
	dateSynced = false;
	
	// if the datefield is not initialized yet, initialize now.
	if (!df.initialized) {
	    synchronized (Display.LCDUILock) {
		lGetDate();
	    }
	}	
	// Set flag so native resource will be queried for latest value
	// Tell Form that ItemStateListener should be notified
	return true;