InfoDialog.java

/*
 * Copyright © 2012 Nokia Corporation. All rights reserved.
 * Nokia and Nokia Connecting People are registered trademarks of Nokia Corporation.
 * Oracle and Java are trademarks or registered trademarks of Oracle and/or its
 * affiliates. Other product and company names mentioned herein may be trademarks
 * or trade names of their respective owners.
 * See LICENSE.TXT for license information.
 */

package com.nokia.example.amaze.ui;

import javax.microedition.lcdui.Font;
import javax.microedition.lcdui.Graphics;
import javax.microedition.lcdui.Image;

import com.nokia.example.amaze.Main;

/**
 * A dialog for showing information about this application.
 */
public class InfoDialog {
	// Constants
	private static final int MARGIN = 6;
	private static final int TEXT_WIDTH = 240 - MARGIN * 2;
	
	// Members
	private Image _backgroundImage = null;
	private TextWrapper _textWrapper = null;
	private String _infoText
		= "This is a Nokia example game application which demonstrates the use "
		+ "of Mobile 3D Graphics framework with accelerometer sensor and "
		+ "gestures. Guide the marble through the maze by tilting the phone "
		+ "before the time runs out.\n\n"
		+ "For more information, visit "
		+ "http://projects.developer. nokia.com/amaze";
	
	/**
	 * Constructor.
	 */
	public InfoDialog() {
		_backgroundImage = Main.makeImage("/graphics/dimmed-bg.png");
		_textWrapper = TextWrapper.instance(Font.getDefaultFont(), TEXT_WIDTH);
	}
	
	/**
	 * Paints the info dialog.
	 * @param graphics
	 */
	public void paint(Graphics graphics) {
		final int topLeft = Graphics.TOP | Graphics.LEFT;
		graphics.drawImage(_backgroundImage, 0, 0, topLeft);
		graphics.setColor(MazeCanvas.TEXT_COLOR);
		int y = MARGIN + 20;
		graphics.drawString("aMaze 1.0", MARGIN, y, topLeft);
		_textWrapper.setWidth(TEXT_WIDTH);
		
		try {
			_textWrapper.setText(_infoText);
			y += MARGIN * 2 + 20;

			while (_textWrapper.hasMoreLines()) {
				graphics.drawString(_textWrapper.nextLine(),
						MARGIN, y, topLeft);
				y += _textWrapper.lineHeight();
			}
		}
		catch (IllegalArgumentException e) {}		
	}
}