/* * Copyright © 2013 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.bcexchanger.ui; import javax.microedition.lcdui.CommandListener; import javax.microedition.lcdui.Display; import javax.microedition.lcdui.Displayable; import com.nokia.example.bcexchanger.*; /** * * This class is an abstract base class for all the UI screen in this * application. This class implements CommandListner interface. * * @see example.BCExchanger.ui.Screen Design patterns: State * */ public abstract class Screen implements CommandListener { protected BCExchangerMIDlet midlet; protected Displayable displayable; /** * Constructor * * @param _midlet - * the parent class which keeps the current UI state */ public Screen(BCExchangerMIDlet _midlet) { midlet = _midlet; } /** * Makes current screen active * <p> * Each class inherited from Screen has a displayable associated. * When this method is called the displayable is made visible and * active * */ public void makeActive() { try { Display d = Display.getDisplay(midlet); if (d.getCurrent() != displayable) { // this prevents from // bringing application to // foreground in case is // application is in // background and the // current displayable is // the same as the one // made active d.setCurrent(displayable); } } catch (NullPointerException e) { throw new RuntimeException( "Internal error #2: Screen.midlet == null"); } } }