⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 uicontroller.java

📁 实现了一个基于j2me移动gps定位系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
                        sEx.printStackTrace();
                        showErrorAlert(getString(UIConstants.UNKNOWN_ERROR)
                                + ":\n" + sEx.getMessage());
                    } finally {
                        out.close();
                        fileConnection.close();
                    }

                    viewMapRequested();

                    break;
                }
                case EventIds.EVENT_ID_SHOWDIR: {
                    try {
                        getFileSystemBrowserUI().getCurrDir();
                        display.setCurrent(getFileSystemBrowserUI());
                    } catch (IOException ioe) {
                        showErrorAlert(getMessage(MessageCodes.ERROR_CAN_NOT_VIEW_DIR)
                                + "\nException: " + ioe);
                    }

                    break;
                }
                case EventIds.EVENT_ID_CHECKEXISTING: {
                    try {
                        fileConnection = (FileConnection) Connector
                                .open("file://localhost/"
                                        + getFileSystemBrowserUI()
                                                .getCurrPath()
                                        + getFileSystemCreatorUI()
                                                .getNameInputValue());
                        getFileSystemCreatorUI().setItemExisting(
                                fileConnection.exists());

                        if (!getFileSystemCreatorUI().isItemExisting()) {
                            runWithProgress(new EventDispatcher(
                                    EventIds.EVENT_ID_SAVEMAPTOFILE,
                                    getMapServerUI()),
                                    getString(UIConstants.PROCESSING), true);
                        } else {
                            confirm(MessageCodes.CONFIRM_OVERWRITE_TO_FILE);
                        }
                    } catch (IOException ex) {
                        showErrorAlert(new ApplicationException(),
                                getFileSystemCreatorUI());
                    }

                    break;
                }
                case EventIds.EVENT_ID_CHECKUPDATE: {
                    String currentVersion = checkUpdate(
                            getString(UIConstants.CONF_UPDATE_URL)).trim();
                    String oldVersion = midlet
                            .getAppProperty(JVNMobileGISMIDlet.PROPERTY_MIDLET_VERSION);
                    // System.out.println("****** Current Version = " +
                    // currentVersion + ". oldVersion = " +
                    // oldVersion);
                    if (null != currentVersion
                            && currentVersion.compareTo(oldVersion) > 0) {
                        showInfoAlert(getString(UIConstants.UPDATE_AVAILABE),
                                getMainMenuUI());
                    } else {
                        showInfoAlert(
                                getString(UIConstants.NO_UPDATE_AVAILABE),
                                getMainMenuUI());
                    }

                    break;
                }
                case EventIds.EVENT_ID_GPSSEARCHING: {
                    int numberOfDevices = getGpsUI().searchDevice();
                    if (numberOfDevices == 0) {
                        showInfoAlert(getMessage(MessageCodes.NO_DEVICES),
                                getLBSMainForm());
                    } else {
                        gpsUIRequested();
                    }

                    break;
                }
                case EventIds.EVENT_ID_GPSREADING: {
                    getLBSMainForm().setActive(true);

                    while (getLBSMainForm().isActive()) {
                        GpsBt gpsBt = GpsBt.instance();
                        if (gpsBt.isConnected()) {
                            getLBSMainForm().updateLocation(gpsBt);
                            try {
                                Thread.sleep(7000);
                            } catch (InterruptedException e) {
                                e.printStackTrace();
                                showErrorAlert(e.getMessage(), getLBSMainForm());
                                getLBSMainForm().setActive(false);
                            }
                        } else {
                            getLBSMainForm().disconnectedAlert();
                            getLBSMainForm().setActive(false);
                        }
                    }
                    break;
                }
                } // for switch - case

            } catch (ApplicationException ae) {
                ae.printStackTrace();
                if (ae.getCode() == MessageCodes.ERROR_OPERATION_INTERRUPTED) {
                    display.setCurrent(fallbackUI);
                } else if (ae.getCode() == MessageCodes.ERROR_CANNOT_CONNECT) {
                    showErrorAlert(ae, fallbackUI);
                } else if (ae.getCode() == MessageCodes.NO_SELECTED_LAYER) {
                    showErrorAlert(ae, fallbackUI);
                    // } else if (ae.getCode() ==
                    // MessageCodes.NO_SELECTED_POINT) {
                    // showErrorAlert(ae, fallbackUI);
                } else if (ae.getCode() == MessageCodes.ERROR_UNAUTHORIZED) {
                    try {
                        promtForCredentials(model.getWwwAuthenticate());
                    } catch (Exception ex) {
                        ex.printStackTrace();
                        showErrorAlert(getString(UIConstants.UNKNOWN_ERROR)
                                + ":\n" + ex.getMessage());
                    }
                } else {
                    showErrorAlert(getString(UIConstants.UNKNOWN_ERROR) + ":\n"
                            + ae.getMessage(), fallbackUI);
                }
            } catch (Exception e) {
                e.printStackTrace();
                showErrorAlert(getString(UIConstants.UNKNOWN_ERROR) + ":\n"
                        + e.getMessage(), getMainMenuUI());
            }
        }
    }

    private void createCommands() {
        exitCommand = new Command(getString(UIConstants.EXIT), Command.EXIT, 75);
        mainMenuCommand = new Command(getString(UIConstants.MAIN_MENU),
                Command.OK, 13);
        aboutCommand = new Command(getString(UIConstants.ABOUT), Command.OK, 14);
    }

    public void setCommands(Displayable displayable) {
        displayable.addCommand(exitCommand);
        displayable.addCommand(mainMenuCommand);
        displayable.addCommand(aboutCommand);
    }

    public Image getImage(byte imageIndex) {
        return icons[imageIndex];
    }

    private Image getMapWMS(WMSRequestParameter requestParam, Vector layerList)
            throws ApplicationException {
        if (0 < layerList.size()) {
            LayerInformation layerInfo = (LayerInformation) layerList
                    .elementAt(0);
            getMapViewUI().initParam(layerInfo.getLatLonBoundingBox(),
                    layerInfo.getServerInformation().getGetMapURL(),
                    layerInfo.getField("srs"));
        }
        // Init layers for select layer UI
        getLayerSelectUI().init(getLayerListUI().getSelectedLayerList());
        // return model.getMapWMS(requestParam, layerList);
        return model.getMapWMS(requestParam, getSortLayerListUI()
                .getSortLayerList());
    }

    private byte[] getMapWMSAsBytesForSaving(WMSRequestParameter requestParam,
            Vector layerList) throws ApplicationException {
        return model.getMapWMSAsBytes(requestParam, layerList);
    }

    /*
     * private String findPathWMS(WMSRequestParameter requestParam) throws
     * ApplicationException { return model.findPathWMS(requestParam); }
     */
    private String searchFeature(SearchFeatureParameter searchParam)
            throws ApplicationException {
        return model.searchFeature(searchParam);
    }

    private String getFeatureInfo(WMSRequestParameter requestParam,
            Vector layerList, String infoLayer) throws ApplicationException {
        return model.getFeatureInfo(requestParam, layerList, infoLayer);
    }

    /*
     * private Image viewPathWMS(WMSRequestParameter requestParam) throws
     * ApplicationException { return model.viewPathWMS(requestParam); }
     */
    private Image updateMapWMS(WMSRequestParameter requestParam,
            Vector layerList) throws ApplicationException {
        return model.getMapWMS(requestParam, layerList);
    }

    private String checkUpdate(String updateURL) throws ApplicationException {
        return model.checkUpdate(updateURL);
    }

    private Vector getCapabilitiesWMS(String serverURL)
            throws ApplicationException {
        return model.getCapabilitiesWMS(serverURL);
    }

    /**
     * @return
     * @uml.property name="credentials"
     */
    public Credentials getCredentials() {
        return credentials;
    }

    public void promtForCredentials(String challenge) {
        try {
            java.lang.String realm = null;
            if (challenge == null) {
                throw new ApplicationException(MessageCodes.MISSING_CHALLENGE);
            }
            challenge = challenge.trim();
            if (!challenge.trim().toLowerCase().startsWith("basic")) {
                throw new ApplicationException(
                        MessageCodes.AUTH_SCHEME_NOT_BASIC);
            }
            int length = challenge.length();
            // we don't check for extra double quotes...
            if ((length < 8)
                    || (!challenge.substring(5, 13).equals(" realm=\""))
                    || (challenge.charAt(length - 1) != '\"')) {
                throw new ApplicationException(
                        MessageCodes.AUTH_REALM_SYNTAX_ERROR);
            }
            realm = challenge.substring(13, length - 1);

            getPromptDialog().setTitle(realm);
            display.setCurrent(getPromptDialog());
        } catch (ApplicationException ex) {
            ex.printStackTrace();
        }
    }

    public void calculateCredentials() {
        if ("".equals(getPromptDialog().getUsername())
                || "".equals(getPromptDialog().getPassword())) {
            showErrorAlert(getString(UIConstants.MUST_GIVE_USER_PWD));
        } else {
            credentials.setUsername(getPromptDialog().getUsername());
            credentials.setPassword(getPromptDialog().getPassword());
            // Calculate the credentials
            byte[] credentialsBA = (credentials.getUsername() + ":" + credentials
                    .getPassword()).getBytes();
            byte[] encodedCredentialsBA = Base64.encode(credentialsBA);
            credentials.setCredentials(new String(encodedCredentialsBA));
            // System.out.println("************ Calculated credentials:"
            // + credentials.getCredentials());
            try {
                // Set credentials for HTTPS
                model.setCredentials(credentials.getCredentials());
            } catch (ApplicationException e) {
                e.printStackTrace();
                showErrorAlert(e, getMainMenuUI());
            }
            // After saving credentials, get server's capabilities
            getCapabilitiesRequested();
        }
    }

    public void confirm(int messageId) {
        getConfirmDialogUI().showConfirm(messageId);
        display.setCurrent(getConfirmDialogUI());
    }

    public void confirmAction(int messageId, boolean accepted) {
        switch (messageId) {
        case MessageCodes.CONFIRM_SAVE_PREFERENCES:
            if (accepted) {
                this.savePreferencesRequested();
            } else {
                mainMenuRequested();
            }
            break;

        case MessageCodes.CONFIRM_OVERWRITE_TO_FILE: {
            if (accepted) {
                runWithProgress(new EventDispatcher(
                        EventIds.EVENT_ID_SAVEMAPTOFILE, getMapServerUI()),
                        getString(UIConstants.PROCESSING), true);
            } else {
                fileSystemCreatorUIRequested();
            }
            break;
        }

        default:
            break;
        }
    }

    void deinitialize(boolean all) {
        if (all) {
            mapServersCmd = null;
            mainMenuCommand = null;
            exitCommand = null;
            aboutCommand = null;
            mainMenuUI = null;
            preferencesUI = null;
            mapServerUI = null;
            mapViewUI = null;
            // findPathUI = null;
            searchFeatureUI = null;
            searchFeatureResultUI = null;
            layerSelectUI = null;
            featureInfoUI = null;
            helpUI = null;
            layerListUI = null;
            sortLayerListUI = null;
            progressObserverUI = null;
            promptDialog = null;
            confirmDialogUI = null;
            fileSystemBrowserUI = null;
            fileSystemCreatorUI = null;
        }
    }
}

⌨️ 快捷键说明

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