📄 uicontroller.java
字号:
/* * Copyright 2001, 2002, 2003 Sun Microsystems, Inc. All Rights Reserved. * Except for any files in PNG format (which are marked with the filename * extension ".png"), GIF format (which are marked with the filename * extension ".gif"), or JPEG format (which are marked with the filename * extension ".jpg"), redistribution and use in source and binary forms, * with or without modification, are permitted provided that the * following conditions are met: * - Redistribution of source code must retain the above copyright * notice, this list of conditions and the following disclaimer. * - Redistribution in binary form must reproduce the above copyright * notice, this list of conditions and the following disclaimer in the * documentation and/or other materials provided with the distribution. * You may compile, use, perform and display the following files with * original Java Smart Ticket Sample Application code obtained from Sun * Microsystems, Inc. only: * - files in PNG format and having the ".png" extension * - files in GIF format and having the ".gif" extension * - files in JPEG format and having the ".jpg" extension * You may not modify or redistribute .png, .gif, or .jpg files in any * form, in whole or in part, by any means without prior written * authorization from Sun Microsystems, Inc. and its licensors, if any. * Neither the name of Sun Microsystems, Inc., the 'Java Smart Ticket * Sample Application', 'Java', 'Java'-based names, or the names of * contributors may be used to endorse or promote products derived from * this software without specific prior written permission. * This software is provided "AS IS," without a warranty of any kind. ALL * EXPRESS OR IMPLIED CONDITIONS, REPRESENTATIONS AND WARRANTIES, * INCLUDING ANY IMPLIED WARRANTY OF MERCHANTABILITY, FITNESS FOR A * PARTICULAR PURPOSE OR NON-INFRINGEMENT, ARE HEREBY EXCLUDED. SUN * MIDROSYSTEMS, INC. ("SUN") AND ITS LICENSORS SHALL NOT BE LIABLE FOR * ANY DAMAGES SUFFERED BY LICENSEE AS A RESULT OF USING, MODIFYING OR * DISTRIBUTING THIS SOFTWARE OR ITS DERIVATIVES. IN NO EVENT WILL SUN OR * ITS LICENSORS BE LIABLE FOR ANY LOST REVENUE, PROFIT OR DATA, OR FOR * DIRECT, INDIRECT, SPECIAL, CONSEQUENTIAL, INCIDENTAL OR PUNITIVE * DAMAGES, HOWEVER CAUSED AND REGARDLESS OF THE THEORY OF LIABILITY, * ARISING OUT OF THE USE OF OR INABILITY TO USE THIS SOFTWARE, EVEN IF * SUN HAS BEEN ADVISED OF THE POSSIBILITY OF SUCH DAMAGES. * You acknowledge that this software is not designed, licensed or * intended for use in the design, construction, operation or maintenance * of any nuclear facility. * $Id: UIController.java,v 1.2 2003/04/09 21:33:36 ro89390 Exp $ */package com.sun.j2me.blueprints.smartticket.client.midp.ui;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;import java.io.*;import com.sun.j2me.blueprints.smartticket.client.midp.model.ModelFacade;import com.sun.j2me.blueprints.smartticket.client.midp.model.Preferences;import com.sun.j2me.blueprints.smartticket.client.midp.model.ErrorMessageCodes;import com.sun.j2me.blueprints.smartticket.shared.midp.ApplicationException;import com.sun.j2me.blueprints.smartticket.shared.midp.IndexedResourceBundle;import com.sun.j2me.blueprints.smartticket.shared.midp.model.*;import com.sun.j2me.blueprints.smartticket.shared.midp.model.SeatingPlan.Seat;public class UIController { private static final String BASE_NAME_UI_RESOURCES = "UIResources2"; private static final String PROPERTY_LOCALE = "SmartTicket-Locale"; public static class EventIds { public static final byte EVENT_ID_ACCOUNTSETUPREQUESTED = 0; public static final byte EVENT_ID_ACCOUNTSETUPSAVED = 1; public static final byte EVENT_ID_PREFERENCESSAVED = 2; public static final byte EVENT_ID_MANAGETHEATERSCHEDULESREQUESTED = 3; public static final byte EVENT_ID_ACCOUNTINFOSAVED = 4; public static final byte EVENT_ID_DEFAULTSREQUESTED = 5; public static final byte EVENT_ID_CHOOSEMOVIEREQUESTED = 6; public static final byte EVENT_ID_LOOKUPTHEATERSCHEDULE = 7; public static final byte EVENT_ID_DOWNLOADTHEATERSCHEDULE = 8; public static final byte EVENT_ID_SELECTSEATSSELECTED = 9; public static final byte EVENT_ID_SEATSSELECTED = 10; public static final byte EVENT_ID_PURCHASEREQUESTED = 11; public static final byte EVENT_ID_RATEMYMOVIESREQUESTED = 12; public static final byte EVENT_ID_MOVIE_RATINGS_SAVE_REQUESTED = 13; public static final byte EVENT_ID_MOVIE_RATING_DELETE_REQUESTED = 14; public static final byte EVENT_ID_MOVIE_RATINGS_SYNC_REQUESTED = 15; public static final byte EVENT_ID_MOVIE_RATINGS_RESOLUTION_REQUESTED = 16; private EventIds() {} } private static final String[] iconPaths = { "/icons/g.png", "/icons/pg.png", "/icons/r.png", "/icons/q.png", "/icons/fullstar.png", "/icons/halfstar.png", "/icons/remote.png", "/icons/local.png", "/icons/expired.png", "/icons/smartTicket2.png", }; public Display display; private IndexedResourceBundle resourceBundle; private ModelFacade model; private AccountInfo accountInfo; private AccountInfo newAccountInfo; private Preferences preferences; private Preferences newPreferences; private Theater selectedTheater; private TheaterSchedule.MovieSchedule selectedMovieSchedule; private Movie selectedMovie; private int[] selectedShowTime; private Seat[] selectedSeats; private MovieRating[] selectedMovieRatings; private MovieRating[] resolvedMovieRatings; private Reservation reservation; private int theaterSelection; private Image[] icons = new Image[iconPaths.length]; private Command mainMenuCommand; private Command exitCommand; private Command mySettingsCommand; // private Command showPreviewCommand; // private Command showByMoviesCommand; // private Command whatsNewCommand; // private Command aboutCommand; private Alert alert; private MainMenuUI mainMenuUI; private MySettingsUI mySettingsUI; private ManageTheaterSchedulesUI manageTheaterSchedulesUI; private DefaultsUI defaultsUI; private AccountSetupUI accountSetupUI; private ChooseMovieUI chooseMovieUI; private SeatingPlanUI seatingPlanUI; private SignOnUI signOnUI; private PurchaseTicketsUI purchaseTicketsUI; private ConfirmTicketUI confirmTicketUI; private PurchaseCompleteUI purchaseCompleteUI; private AccountInfoUI accountInfoUI; private ChangePasswordUI changePasswordUI; private BillingInfoUI billingInfoUI; private ProgressObserverUI progressObserverUI; private RateMyMoviesUI rateMyMoviesUI; private SyncMovieRatingsUI syncMovieRatingsUI; public UIController(MIDlet midlet, ModelFacade model) { this.display = Display.getDisplay(midlet); this.model = model; } public Display getDisplay() { return display; } public String getString(int uiConstant) { return resourceBundle.getString(uiConstant); } public void init() throws ApplicationException { resourceBundle = model.getResourceBundle(BASE_NAME_UI_RESOURCES); try { accountInfo = model.getAccountInfo(); preferences = model.getPreferences(); } catch (ApplicationException e) { System.err.println("Exception " + e); } progressObserverUI = new ProgressObserverUI(this); model.setProgressObserver(progressObserverUI); mainMenuUI = new MainMenuUI(this); mySettingsUI = new MySettingsUI(this); manageTheaterSchedulesUI = new ManageTheaterSchedulesUI(this); defaultsUI = new DefaultsUI(this); signOnUI = new SignOnUI(this); accountSetupUI = new AccountSetupUI(this); chooseMovieUI = new ChooseMovieUI(this); seatingPlanUI = new SeatingPlanUI(this); purchaseTicketsUI = new PurchaseTicketsUI(this); confirmTicketUI = new ConfirmTicketUI(this); purchaseCompleteUI = new PurchaseCompleteUI(this); accountInfoUI = new AccountInfoUI(this); changePasswordUI = new ChangePasswordUI(this); billingInfoUI = new BillingInfoUI(this); rateMyMoviesUI = new RateMyMoviesUI(this); syncMovieRatingsUI = new SyncMovieRatingsUI(this); createCommands(); setCommands(chooseMovieUI); setCommands(seatingPlanUI); setCommands(rateMyMoviesUI); setCommands(manageTheaterSchedulesUI); for (int i = 0; i < iconPaths.length; i++) { try { icons[i] = Image.createImage(iconPaths[i]); } catch (IOException ioe) {} } Alert alert = new Alert(null, null, icons[UIConstants.ICON_IDX_SPLASH], null); if (accountInfo == null) { accountInfo = new AccountInfo(); accountSetupUI.init(accountInfo, preferences); display.setCurrent(alert, accountSetupUI); } else { display.setCurrent(alert, mainMenuUI); } } public void destroy() {} public void commandAction(Command command, Displayable displayable) { if (command == mainMenuCommand) { mainMenuRequested(); } else if (command == mySettingsCommand) { mySettingsRequested(); } else if (command == exitCommand) { exitRequested(); } } public void showErrorAlert(Exception e) { showErrorAlert(new ApplicationException(e), mainMenuUI); } public void showErrorAlert(ApplicationException ae, Displayable d) { showErrorAlert(ae.getMessage(), d); } public void showErrorAlert(String message) { showErrorAlert(message, display.getCurrent()); } private void showErrorAlert(String message, Displayable d) { Alert alert = new Alert( // getString(UIMessageCodes.ERROR) "Error"); alert.setType(AlertType.ERROR); alert.setTimeout(Alert.FOREVER); alert.setString(message); display.setCurrent(alert, d); } public void showInfoAlert(String message, Displayable d) { showInfoAlert(null, message, d); } public void showInfoAlert(String title, String message, Displayable d) { Alert alert = new Alert((title == null) ? // getString(UIMessageCodes.SMART_TICKET) "Smart Ticket" : title); alert.setType(AlertType.INFO); alert.setTimeout(Alert.FOREVER); alert.setString(message); display.setCurrent(alert, d); } public void runWithProgress(Thread thread, String title, boolean stoppable) { progressObserverUI.init(title, stoppable); getDisplay().setCurrent(progressObserverUI); thread.start(); } /** * Sign on, and eventually execute the given runnable after doing * so. */ private void signOn(Runnable authorizedRunnable) { boolean isLoggedIn = false; try { model.setOffline(false); isLoggedIn = model.isLoggedIn(); } catch (ApplicationException ae) { // Ignore. Therefore, isLoggedIn == false. } if (isLoggedIn) { display.setCurrent(progressObserverUI); new Thread(authorizedRunnable).start();
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -