// 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.helloworld;

import danger.app.Application;
import danger.app.Event;
import danger.ui.Color;
import danger.ui.Font;
import danger.ui.Menu;
import danger.ui.Pen;
import danger.ui.Rect;
import danger.ui.ScreenWindow;
import danger.util.DEBUG;

/**
 * Implements the main window class.
 */
class MainWindow
		extends ScreenWindow
		implements Resources, Commands {

	//*	--------------------	HelloWorldWindow

	public MainWindow() {
	}

	//* --------------------  adjustActionMenuState
	
	public void adjustActionMenuState(Menu hwMenu) {
		//Menu hwMenu = getActionMenu();
		hwMenu.removeAllItems();
		hwMenu.addFromResource(Application.getCurrentApp().getResources(), ID_MENU_HELLO_WORLD, this);
	} 

	//*	--------------------	paint

	public void paint(Pen inPen) {
		Rect bounds = getBounds();
		Font font = Font.findBoldSystemFont();
		String message = Application.getCurrentApp().getString(ID_STRING_HELLO_WORLD);

		clear(inPen);

		inPen.setColor(Color.BLACK);
		inPen.drawRect(bounds);

		inPen.setFont(font);
		inPen.drawText((bounds.getWidth() -
				font.getWidth(message)) / 2,
				(bounds.getHeight() -
				(font.getAscent() + font.getDescent())) / 2,
				message);
	}

	//*	--------------------	receiveEvent

	/**
	 * Handles events. Called automatically whenever the application
	 * receives an event.
	 */
	public boolean receiveEvent(Event e) {
		switch (e.type) {
			case EVENT_ONE:
				// Todo: Insert code here...
				DEBUG.p("Helloworld: Received kCmd_One");
				return true;

			case EVENT_TWO:
				// Todo: Insert code here...
				DEBUG.p("Helloworld: Received kCmd_Two");
				return true;
		}
		return super.receiveEvent(e);
	}


	//*	--------------------	eventWidgetDown

	public boolean eventWidgetDown(int inWhichWidget, Event inEvent) {
		switch (inWhichWidget) {
			case Event.DEVICE_WHEEL:
				break;
			case Event.DEVICE_MULTIPLE_WHEEL:
				break;
			case Event.DEVICE_WHEEL_BUTTON:
				break;
			case Event.DEVICE_ARROW_UP:
				break;
			case Event.DEVICE_ARROW_DOWN:
				break;
			case Event.DEVICE_ARROW_LEFT:
				break;
			case Event.DEVICE_ARROW_RIGHT:
				break;
			case Event.DEVICE_BUTTON_JUMP:
				// Always make sure to call super.eventWidgetUp for this control so the system
				// can execute the correct behavior (returning to the Jump screen with phone selected).
				break;
		}
		return super.eventWidgetDown(inWhichWidget, inEvent);
	}

	//*	--------------------	eventWidgetUp

	public boolean eventWidgetUp(int inWhichWidget, Event inEvent) {
		switch (inWhichWidget) {
			case Event.DEVICE_WHEEL:
				break;
			case Event.DEVICE_MULTIPLE_WHEEL:
				break;
			case Event.DEVICE_WHEEL_BUTTON:
				break;
			case Event.DEVICE_ARROW_UP:
				break;
			case Event.DEVICE_ARROW_DOWN:
				break;
			case Event.DEVICE_ARROW_LEFT:
				break;
			case Event.DEVICE_ARROW_RIGHT:
				break;
				/*
					This demonstrates how to use a control from Sidekick2 in a way that is still compatible
					with original Sidekick devices.  We implement the DEVICE_BUTTON_CANCEL event which is
					defined in the Sidekick2Events.java file.  On original Sidekick devices, this event is
					never sent.  On Sidekick2 devices, you will get this event and should handle it appropriately.
				*/
			case Hiptop2Events.DEVICE_BUTTON_CANCEL:
				Application.getCurrentApp().returnToLauncher();
				return true;

			case Event.DEVICE_BUTTON_BACK:
				Application.getCurrentApp().returnToLauncher();
				return true;

			case Event.DEVICE_BUTTON_JUMP:
				// Always make sure to call super.eventWidgetUp for this control so the system
				// can execute the correct behavior (returning to the Jump screen with phone selected).
				break;
		}
		return super.eventWidgetUp(inWhichWidget, inEvent);
	}

}
