// Copyright 2001-2005, Danger, Inc.  All Rights Reserved.
// This file is subject to the Danger, Inc. Sample Code License,
// which is provided in the file SAMPLE_CODE_LICENSE.
// Copies are also available from http://developer.danger.com/

package com.example.GUIDemo;

import danger.app.Application;
import danger.app.Event;
import danger.ui.DateDialog;

/**
 * LRDateDialog: This is a subclass to allow for a couple of improvements to
 * the DialogWindow UI, while showing the variety of widgets.
 * 
 * The only addition is to add in the Previous/Next function to the dialog when
 * created, so that it is easy to cycle through all the available elements. It
 * won't add actual buttons to the windows, because that confuses the demo and
 * changes the focus order in bad ways. For example, a TextEdit click upon done
 * moves to the next button, which should be Done. With buttons, it would go to
 * Previous.
 * 
 * Rather than have buttons, this will simply handle the widget events in an
 * invisible fashion, because it's part of this demo program as a convenience,
 * not part of the dialogs.
 * 
 * This also allows for keeping the resource definitions small and concise for
 * the actual widgets themselves. The goal is to keep the resource definitions
 * simple to understand and use.
 */
public class LRDateDialog extends DateDialog implements Resources, Commands {

	private static GUIDemo sApplication = (GUIDemo) Application.getCurrentApp();

	// The constructor actually used must be replicated here.  This just
	// passes it along to the superclass.
	public LRDateDialog(String string, ProgramWindow window, int i) {
		super (string, window, i);
	}

	/**
	 * Handle the up events for the shoulder buttons. First, hide this
	 * window, which will be the current demonstration date dialog.
	 * 
	 * For Left-Shoulder, send the EVENT_PREVIOUS, for Right-Shoulder send the
	 * EVENT_NEXT. That will be handled by the current ScreenWindow, either
	 * ResourceWindow, or ProgramWindow and move into the next dialog.
	 */
	public boolean eventWidgetUp(int whichWidget, Event arg1) {
		Event newEvent;

		switch (whichWidget) {
		case Event.DEVICE_BUTTON_LEFT_SHOULDER:
			hide();
			newEvent = new Event(sApplication.getFrontScreenWindow(),
					EVENT_PREVIOUS);
			newEvent.sendToTarget();
			return true;
		case Event.DEVICE_BUTTON_RIGHT_SHOULDER:
			hide();
			newEvent = new Event(sApplication.getFrontScreenWindow(),
					EVENT_NEXT);
			newEvent.sendToTarget();
			return true;
		}

		return super.eventWidgetUp(whichWidget, arg1);
	}
}
