// Copyright 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.danger.text;

import danger.ui.*;
import danger.app.Event;
import danger.app.AppResources;
import danger.text.span.HTML;

public class
DemoWindow
extends ScreenWindow
{
	public
	DemoWindow()
	{
		this(false);
	}

	public
	DemoWindow(boolean intro)
	{
		mIntro = intro;

		if (intro)
		{
			LinkTextBox ltb = new LinkTextBox();

			final int BORDER = 5;

			ltb.setHasBorder(false);
			ltb.setSize(getWidth() - 2*BORDER, getHeight() - 2*BORDER);
			ltb.setPosition(BORDER, BORDER);
			ltb.setText(HTML.fromHTML(getApplication().getString(Resources.ID_INTRO)));
			ltb.show();
			addChild(ltb);
			setFocusedChild(ltb);
		}

		setTitle(getApplication().getString(AppResources.ID_APP_NAME));
	}

	public boolean
	eventWidgetUp(int w, Event e)
	{
		if (w == Event.DEVICE_BUTTON_BACK || w == Event.DEVICE_BUTTON_CANCEL)
		{
			if (mIntro)
				getApplication().returnToLauncher();
			else
				hide();

			return true;
		}

		return super.eventWidgetUp(w, e);
	}

	public void
	adjustActionMenuState()
	{
		Menu m = getActionMenu();

		m.removeAllItems();
		m.addFromResource(getApplication().getResources(), Resources.ID_DEMOS_MENU);
	}

	private boolean mIntro;
}
