uicontroller.java

来自「SUN公司发布的SmartTicket 2.0蓝图」· Java 代码 · 共 1,260 行 · 第 1/4 页

JAVA
1,260
字号
/* * 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.25 2003/06/24 06:57:24 ro89390 Exp $ */package com.sun.j2me.blueprints.smartticket.client.midp.ui;import javax.microedition.lcdui.*;import javax.microedition.midlet.*;import java.io.*;import java.util.Vector;import com.sun.j2me.blueprints.smartticket.client.midp.SmartTicketMIDlet;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.client.midp.model.RecommendationReceiver;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 implements CommandListener, RecommendationReceiver {    private static final String BASE_NAME_UI_RESOURCES = "UIResources";    private static final String PROPERTY_LOCALE = "SmartTicket-Locale";    public static class EventIds {        public static final byte EVENT_ID_ACCOUNT_SETUP_SAVE_REQUESTED = 1;        public static final byte EVENT_ID_CHOOSE_MOVIE_SELECTED = 2;        public static final byte EVENT_ID_THEATER_SELECTED = 3;        public static final byte EVENT_ID_MOVIE_SELECTED = 4;        public static final byte EVENT_ID_MOVIE_INFO_REQUESTED = 5;        public static final byte EVENT_ID_SHOW_TIME_SELECTED = 6;        public static final byte EVENT_ID_SEAT_SELECTION_SELECTED = 7;        public static final byte EVENT_ID_SEATS_SELECTED = 8;        public static final byte EVENT_ID_AUTHORIZED_SEATS_SELECTED = 9;        public static final byte EVENT_ID_SEAT_SELECTION_CANCELLED = 10;        public static final byte EVENT_ID_THEATERS_IN_ZIP_CODE_REQUESTED = 11;        public static final byte EVENT_ID_THEATERS_ONLINE_REQUESTED = 12;        public static final byte EVENT_ID_CREDIT_CARD_INFO_SUBMITTED = 13;        public static final byte EVENT_ID_ORDER_BILLING_INFO_CANCELLED = 14;        public static final byte EVENT_ID_PURCHASE_REQUESTED = 15;        public static final byte EVENT_ID_ORDER_PLACEMENT_CANCELLED = 16;        public static final byte EVENT_ID_THEATER_SCHEDULE_SAVE_REQUESTED =             17;        public static final byte EVENT_ID_SETTINGS_REQUESTED = 18;        public static final byte EVENT_ID_ACCOUNT_INFO_REQUESTED = 19;        public static final byte EVENT_ID_ACCOUNT_INFO_SAVE_REQUESTED = 20;        public static final byte EVENT_ID_AUTHORIZED_ACCOUNT_INFO_SAVE_REQUESTED =             21;        public static final byte EVENT_ID_ACCOUNT_INFO_CANCELLED = 22;        public static final byte EVENT_ID_BILLING_INFO_REQUESTED = 23;        public static final byte EVENT_ID_BILLING_INFO_SAVE_REQUESTED = 24;        public static final byte EVENT_ID_BILLING_INFO_CANCELLED = 25;        public static final byte EVENT_ID_PREFERENCES_REQUESTED = 26;        public static final byte EVENT_ID_PREFERENCES_SAVE_REQUESTED = 27;        public static final byte EVENT_ID_PREFERENCES_CANCELLED = 28;        public static final byte EVENT_ID_THEATER_SCHEDULES_REQUESTED = 29;        public static final byte EVENT_ID_THEATER_SCHEDULE_DELETE_REQUESTED =             30;        public static final byte EVENT_ID_THEATER_SCHEDULE_REFRESH_REQUESTED =             31;        public static final byte EVENT_ID_MOVIE_RATINGS_REQUESTED = 32;        public static final byte EVENT_ID_MOVIE_RATINGS_SYNC_REQUESTED = 33;        public static final byte EVENT_ID_AUTHORIZED_MOVIE_RATINGS_SYNC_REQUESTED =             34;        public static final byte EVENT_ID_MOVIE_RATINGS_CONFLICT_RESOLUTION_REQUESTED =             35;        public static final byte EVENT_ID_MOVIE_RATING_SELECTED = 36;        public static final byte EVENT_ID_MOVIE_RATING_SAVE_REQUESTED = 37;        public static final byte EVENT_ID_MOVIE_RATING_CANCELLED = 38;        public static final byte EVENT_ID_MOVIE_RATING_MESSAGE_SEND_SELECTED =             39;        public static final byte EVENT_ID_MOVIE_RATING_MESSAGE_SEND_CANCELLED =             40;        public static final byte EVENT_ID_MOVIE_RATING_MESSAGE_SEND_REQUESTED =             41;        public static final byte EVENT_ID_MOVIE_RATING_MESSAGE_RECEIVE_SAVE_REQUESTED =             42;        public static final byte EVENT_ID_MOVIE_RATING_MESSAGE_RECEIVE_SAVE_CANCELLED =             43;        public static final byte EVENT_ID_MOVIE_RECOMMENDATION_RECEIVED = 44;        public static final byte EVENT_ID_FRIENDS_REQUESTED = 45;        public static final byte EVENT_ID_FRIEND_ADD_SELECTED = 46;        public static final byte EVENT_ID_FRIEND_ADD_REQUESTED = 47;        public static final byte EVENT_ID_FRIEND_ADD_CANCELLED = 48;        public static final byte EVENT_ID_FRIEND_DELETE_REQUESTED = 49;        private EventIds() {}    }    public static final byte ICON_IDX_SPLASH = 0;    public static final byte ICON_IDX_RATING_G = 1;    public static final byte ICON_IDX_RATING_PG = 2;    public static final byte ICON_IDX_RATING_R = 3;    public static final byte ICON_IDX_CLOCK = 4;    public static final byte ICON_IDX_SCHEDULE_REMOTE = 5;    public static final byte ICON_IDX_SCHEDULE_LOCAL = 6;    public static final byte ICON_IDX_SCHEDULE_EXPIRED = 7;    public static final byte ICON_IDX_RATING_UNRATED = 8;    public static final byte ICON_IDX_RATING_ONE_STAR = 9;    public static final byte ICON_IDX_RATING_TWO_STARS = 10;    public static final byte ICON_IDX_RATING_THREE_STARS = 11;    public static final byte ICON_IDX_RATING_FOUR_STARS = 12;    public static final byte ICON_IDX_RATING_FIVE_STARS = 13;    public static final byte ICON_IDX_FULL_STAR = 14;    public static final byte ICON_IDX_EMPTY_STAR = 15;    private static final int[] iconResourceIndices = {        UIMessageCodes.SPLASH_ICON, UIMessageCodes.G_RATING_ICON,         UIMessageCodes.PG_RATING_ICON, UIMessageCodes.R_RATING_ICON,         UIMessageCodes.CLOCK_ICON, UIMessageCodes.REMOTE_ICON,         UIMessageCodes.LOCAL_ICON, UIMessageCodes.EXPIRED_ICON,         UIMessageCodes.UNKNOWN_RATING_ICON,         UIMessageCodes.ONE_STAR_RATING_ICON,         UIMessageCodes.TWO_STARS_RATING_ICON,         UIMessageCodes.THREE_STARS_RATING_ICON,         UIMessageCodes.FOUR_STARS_RATING_ICON,         UIMessageCodes.FIVE_STARS_RATING_ICON, UIMessageCodes.FULL_STAR_ICON,         UIMessageCodes.EMPTY_STAR_ICON    };    private static Image[] icons = new Image[iconResourceIndices.length];    private SmartTicketMIDlet midlet;    private 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 selectedMovieRating;    private MovieRating[] resolvedMovieRatings;    private Reservation reservation;    private MovieRating recommendationMovieRating;    private Displayable recommendationFallbackUI;    private Command mainMenuCommand;    private Command exitCommand;    private Command settingsCommand;    private Alert alert;    private MainMenuUI mainMenuUI;    private SettingsUI settingsUI;    private SavedTheaterSchedulesUI savedTheaterSchedulesUI;    private DefaultsUI defaultsUI;    private AccountSetupUI accountSetupUI;    private MovieSelectionUI movieSelectionUI;    private SeatingPlanUI seatingPlanUI;    private SignOnUI signOnUI;    private OrderBillingInfoUI orderBillingInfoUI;    private OrderPlacementUI orderPlacementUI;    private OrderConfirmationUI orderConfirmationUI;    private AccountInfoUI accountInfoUI;    private BillingInfoUI billingInfoUI;    private ProgressObserverUI progressObserverUI;    private MovieRatingsUI movieRatingsUI;    private MovieRatingsUI.MovieRatingUI movieRatingUI;    private MovieRatingsUI.MovieRatingMessageSendUI movieRatingMessageSendUI;    private MovieRatingsUI.MovieRatingMessageReceiveUI movieRatingMessageReceiveUI;    private MovieRatingsConflictResolutionUI movieRatingsConflictResolutionUI;    private FriendsUI friendsUI;    private FriendsUI.FriendAddUI friendAddUI;    private boolean pushActivated = false;    public UIController(SmartTicketMIDlet midlet) {        this.midlet = midlet;    }    public void init(ModelFacade model) {        this.display = Display.getDisplay(midlet);        this.model = model;        try {            resourceBundle = model.getResourceBundle(BASE_NAME_UI_RESOURCES);            display.setCurrent(new ImageCanvas(getImage(ICON_IDX_SPLASH)));        } catch (ApplicationException e) {            // FIXME            System.err.println("Exception " + e);        }         try {            accountInfo = model.getAccountInfo();            preferences = model.getPreferences();        } catch (ApplicationException e) {            // FIXME            System.err.println("Exception " + e);        }         progressObserverUI = new ProgressObserverUI(UIController.this);        model.setProgressObserver(progressObserverUI);        mainMenuUI = new MainMenuUI(UIController.this);        settingsUI = new SettingsUI(UIController.this);        savedTheaterSchedulesUI =             new SavedTheaterSchedulesUI(UIController.this);        defaultsUI = new DefaultsUI(UIController.this);        signOnUI = new SignOnUI(UIController.this);        accountSetupUI = new AccountSetupUI(UIController.this);        movieSelectionUI = new MovieSelectionUI(UIController.this);        seatingPlanUI = new SeatingPlanUI(UIController.this);        orderBillingInfoUI = new OrderBillingInfoUI(UIController.this);        orderPlacementUI = new OrderPlacementUI(UIController.this);        orderConfirmationUI = new OrderConfirmationUI(UIController.this);        accountInfoUI = new AccountInfoUI(UIController.this);        billingInfoUI = new BillingInfoUI(UIController.this);        movieRatingsUI = new MovieRatingsUI(UIController.this);        movieRatingUI = new MovieRatingsUI.MovieRatingUI(UIController.this);        movieRatingMessageSendUI =             new MovieRatingsUI.MovieRatingMessageSendUI(UIController.this);        movieRatingMessageReceiveUI =             new MovieRatingsUI.MovieRatingMessageReceiveUI(UIController.this);        movieRatingsConflictResolutionUI =             new MovieRatingsConflictResolutionUI(UIController.this);        friendsUI = new FriendsUI(this);        friendAddUI = new FriendsUI.FriendAddUI(this);        exitCommand = new Command(getString(UIMessageCodes.EXIT),                                   Command.SCREEN, 10);        mainMenuCommand = new Command(getString(UIMessageCodes.MAIN_MENU),                                       Command.SCREEN, 5);        setCommands(mainMenuUI);        setCommands(movieSelectionUI);        setCommands(seatingPlanUI);        setCommands(movieRatingsUI);        setCommands(savedTheaterSchedulesUI);        setCommands(friendsUI);        if (accountInfo == null) {            accountSetupUI.init(new AccountInfo(), preferences);            setCurrent(accountSetupUI);        } else {            try {                if (!model.isPushActivated()) {                    setCurrent(mainMenuUI);                } else {                    pushActivated = true;                }             } catch (ApplicationException ae) {                // XXX                ae.printStackTrace();            }         }         try {            model.receiveRecommendation(this);        } catch (ApplicationException ae) {            // XXX            ae.printStackTrace();        }     }     public void destroy() {}    public void recommendationReceived(String message, MovieRating rating,                                        String sender) {        handleEvent(EventIds.EVENT_ID_MOVIE_RECOMMENDATION_RECEIVED,                     new Object[] {            message, rating, sender        });    }     public void commandAction(Command command, Displayable displayable) {        if (command == mainMenuCommand) {            setCurrent(mainMenuUI);        } else if (command == exitCommand) {            exitRequested();        }     }     private void displayProgress(String title, boolean stoppable) {        progressObserverUI.init(title, stoppable);

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?