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

📄 uicontroller.java

📁 实现了一个基于j2me移动gps定位系统
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
    public void searchFeatureRequested() {
        runWithProgress(new EventDispatcher(EventIds.EVENT_ID_SEARCHFEATURE,
                getSearchFeatureUI()), getString(UIConstants.PROCESSING), true);
    }

    public void searchFeatureRequested(int start) {
        getSearchFeatureUI().setStart(start);
        runWithProgress(new EventDispatcher(EventIds.EVENT_ID_SEARCHFEATURE,
                getSearchFeatureUI()), getString(UIConstants.PROCESSING), true);
    }

    public void searchUIRequested() {
        try {
            // set new bounding box for search
            getSearchFeatureUI().initParam(getMapViewUI().getBoundingBox(),
                    model.getPreferences().getWebGISURL());
        } catch (ApplicationException e) {
            e.printStackTrace();
            showErrorAlert(getString(UIConstants.UNKNOWN_ERROR) + ":\n"
                    + e.getMessage());
        }

        display.setCurrent(getSearchFeatureUI());
    }

    public void searchResultUIRequested() {
        display.setCurrent(getSearchFeatureResultUI());
    }

    // public void viewPathRequested() { mapViewUI.setIsViewPath(true);
    // runWithProgress(new EventDispatcher(EventIds.EVENT_ID_VIEWPATHWMS,
    // findPathUI), getString(UIConstants.PROCESSING), false); }
    //
    public void viewFeatureRequested() {
        getMapViewUI().setIsViewFeature(true);
        runWithProgress(new EventDispatcher(EventIds.EVENT_ID_VIEWFEATURE,
                getSearchFeatureUI()), getString(UIConstants.PROCESSING), true);
    }

    public void updateMapRequested() {
        runWithProgress(new EventDispatcher(EventIds.EVENT_ID_UPDATEMAPWMS,
                getMapViewUI()), getString(UIConstants.PROCESSING), true);
    }

    public void getCapabilitiesRequested() {
        // Save new server URL
        try {
            Preferences preference = model.getPreferences();
            preference.setWmsServerURL(getMapServerUI().getServerURL());
            model.setPreferences(preference);
        } catch (ApplicationException e) {
            e.printStackTrace();
            showErrorAlert(getString(UIConstants.UNKNOWN_ERROR) + ":\n"
                    + e.getMessage());
        }

        runWithProgress(new EventDispatcher(
                EventIds.EVENT_ID_GETCAPABILITIESWMS, getMapServerUI()),
                getString(UIConstants.PROCESSING), true);
    }

    // File System Browser
    public void browseFileSystemRequested() { // First time File System
        // Browser
        // is call
        // Check if device supports

        String FCOPversion = System
                .getProperty("microedition.io.file.FileConnection.version");
        if (FCOPversion != null) {
            executeShowDir(getFileSystemBrowserUI().getCurrPath());
        } else {
            showErrorAlert(getMessage(MessageCodes.ERROR_DOESNT_SUPPORT_JSR_75));
        }
    }

    public void browseFileSystemRequested(Displayable d) {// Browsing File
        // System

        String itemName;
        List curr = (List) d;
        itemName = curr.getString(curr.getSelectedIndex());

        traverseDirectory(itemName);
    }

    public void saveMapToFileRequested(Displayable display) {
        if (display != null && display instanceof List) {
            List list = (List) display;
            String fileName = list.getString(list.getSelectedIndex());
            getFileSystemCreatorUI().setNameInputValue(fileName);
        }

        this.display.setCurrent(getFileSystemCreatorUI());
    }

    public void saveAsMapToFileRequested() {
        getFileSystemCreatorUI().setNameInputValue(".png");

        this.display.setCurrent(getFileSystemCreatorUI());
    }

    public void fileSystemBrowserUIRequested() {

        display.setCurrent(getFileSystemBrowserUI());
    }

    public void fileSystemCreatorUIRequested() {

        display.setCurrent(getFileSystemCreatorUI());
    }

    public void traverseDirectory(String dirName) {
        /*
         * In case of directory just change the current directory and show it
         */
        String currPath = getFileSystemBrowserUI().getCurrPath();
        if (dirName.equals("")) {
            currPath = FileSystemBrowserUI.MEGA_ROOT;
        } else if (currPath.equals(FileSystemBrowserUI.MEGA_ROOT)) {
            if (dirName.equals(FileSystemBrowserUI.UP_DIRECTORY)) {
                // can not go up from MEGA_ROOT
                return;
            }

            currPath = dirName;
        } else if (dirName.equals(FileSystemBrowserUI.UP_DIRECTORY)) {
            // Go up one directory
            int i = currPath.lastIndexOf(FileSystemBrowserUI.SEP, currPath
                    .length() - 2);

            if (i != -1) {
                currPath = currPath.substring(0, i + 1);
            } else {
                currPath = FileSystemBrowserUI.MEGA_ROOT;
            }
        } else {
            currPath = currPath + dirName;
        }

        executeShowDir(currPath);
    }

    public void executeSaveMapToFile() {
        String fileName = getFileSystemCreatorUI().getNameInputValue();
        if (!fileName.endsWith(".png")) {
            showErrorAlert(new ApplicationException(
                    getMessage(MessageCodes.ERROR_WRONG_PNG_FORMAT)),
                    getFileSystemCreatorUI());
        } else {
            runWithProgress(new EventDispatcher(
                    EventIds.EVENT_ID_CHECKEXISTING, getFileSystemCreatorUI()),
                    getString(UIConstants.PROCESSING), true);
        }
    }

    public void executeShowDir(final String path) {
        getFileSystemBrowserUI().setCurrPath(path);

        runWithProgress(new EventDispatcher(EventIds.EVENT_ID_SHOWDIR,
                getFileSystemBrowserUI()), getString(UIConstants.PROCESSING),
                true);
    }

    public void lbsMainUIRequested() {
        display.setCurrent(getLBSMainForm());
    }

    public void gpsUIRequested() {
        display.setCurrent(getGpsUI());
    }

    public void gpsReadingRequested() {
        lbsMainUIRequested();
        runWithoutProgress(new EventDispatcher(EventIds.EVENT_ID_GPSREADING,
                getGpsUI()));
    }

    public void gpsSearchingRequested() {
        runWithProgress(new EventDispatcher(EventIds.EVENT_ID_GPSSEARCHING,
                getGpsUI()), getString(UIConstants.SEARCHING_DEVICES), true);
    }

    public void exitRequested() {
        System.out.println("Bye Bye");
        // FIXME - Not yet implemented.
        midlet.notifyDestroyed();
    }

    class EventDispatcher extends Thread {

        private final int taskId;
        private final Displayable fallbackUI;

        EventDispatcher(int taskId, Displayable fallbackUI) {
            this.taskId = taskId;
            this.fallbackUI = fallbackUI;
        }

        public void run() {
            try {
                switch (taskId) {
                case EventIds.EVENT_ID_GETMAPWMS: {
                    // Image img = getMapWMS(getMapViewUI(),
                    // getLayerListUI().getSelectedLayerList());
                    Image img = getMapWMS(getMapViewUI(), getSortLayerListUI()
                            .getSortLayerList());

                    if (img == null) {
                        showErrorAlert(
                                getString(UIConstants.GET_MAP_WMS_ERROR),
                                getMainMenuUI());
                    } else {
                        getMapViewUI().init(img);
                        display.setCurrent(getMapViewUI());
                    }

                    break;
                }
                    /*
                     * case EventIds.EVENT_ID_VIEWPATHWMS: { Image img =
                     * viewPathWMS(mapViewUI); if (img == null) {
                     * showErrorAlert(getString(UIConstants.VIEWPATH_ERROR),
                     * findPathUI); } else { mapViewUI.init(img);
                     * display.setCurrent(mapViewUI); } break; }
                     */

                case EventIds.EVENT_ID_VIEWFEATURE: {
                    MapFeature feature = getSearchFeatureResultUI()
                            .getSelectedFeature();
                    // Recenter map view to this feature
                    getMapViewUI().reCenterAtFeature(feature);

                    // Update new map
                    Image img = updateMapWMS(getMapViewUI(), getLayerListUI()
                            .getSelectedLayerList());

                    if (img == null) {
                        showErrorAlert(
                                getString(UIConstants.GET_MAP_WMS_ERROR),
                                getMainMenuUI());
                    } else {
                        getMapViewUI().init(img);
                        display.setCurrent(getMapViewUI());
                    }

                    break;
                }
                    /*
                     * case EventIds.EVENT_ID_FINDPATHWMS: { String result =
                     * findPathWMS(mapViewUI); findPathUI.init(result);
                     * display.setCurrent(findPathUI); break; }
                     */

                case EventIds.EVENT_ID_SEARCHFEATURE: {
                    String result = searchFeature(getSearchFeatureUI());
                    getSearchFeatureResultUI().init(result);
                    searchResultUIRequested();

                    break;
                }
                case EventIds.EVENT_ID_GETFEATUREINFO: {
                    String result = getFeatureInfo(getMapViewUI(),
                            getLayerListUI().getSelectedLayerList(),
                            getLayerSelectUI().getInfoLayerName());
                    getFeatureInfoUI().init(result);
                    display.setCurrent(getFeatureInfoUI());

                    break;
                }
                case EventIds.EVENT_ID_UPDATEMAPWMS: {
                    Image img = updateMapWMS(getMapViewUI(), getLayerListUI()
                            .getSelectedLayerList());

                    if (img == null) {
                        showErrorAlert(
                                getString(UIConstants.GET_MAP_WMS_ERROR),
                                getMainMenuUI());
                    } else {
                        getMapViewUI().init(img);
                        display.setCurrent(getMapViewUI());
                    }

                    break;
                }
                case EventIds.EVENT_ID_GETCAPABILITIESWMS: {
                    Vector constructedDataTree = getCapabilitiesWMS(getMapServerUI()
                            .getServerURL());

                    if (constructedDataTree == null) {
                        showErrorAlert(
                                getString(UIConstants.GET_CAPABILITIES_WMS_ERROR),
                                getMainMenuUI());
                    } else {
                        getLayerListUI().init(constructedDataTree);

                        display.setCurrent(getLayerListUI());
                    }

                    break;
                }
                case EventIds.EVENT_ID_SAVEMAPTOFILE: {
                    byte[] imgByteArray = getMapWMSAsBytesForSaving(
                            getMapViewUI(), getLayerListUI()
                                    .getSelectedLayerList());

                    String fileName = fileSystemCreatorUI.getNameInputValue();

                    String url = "file://localhost/"
                            + getFileSystemBrowserUI().getCurrPath() + fileName;

                    try {
                        fileConnection = (FileConnection) Connector.open(url,
                                Connector.READ_WRITE);
                        if (!fileConnection.exists()) {
                            fileConnection.create();
                        }
                        out = fileConnection.openOutputStream();

                        out.write(imgByteArray);
                        out.flush();
                    } catch (IOException ioEx) {
                        ioEx.printStackTrace();
                        showErrorAlert(getString(UIConstants.UNKNOWN_ERROR)
                                + ":\n" + ioEx.getMessage());
                    } catch (SecurityException sEx) {

⌨️ 快捷键说明

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