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

📄 graphicalinstaller.java

📁 用于移动设备上的java虚拟机源代码
💻 JAVA
📖 第 1 页 / 共 4 页
字号:
     * @param message exception message     */    private void displayException(String title, String message) {        Alert a = new Alert(title, message, null, AlertType.ERROR);        a.setTimeout(Alert.FOREVER);        a.setCommandListener(this);        display.setCurrent(a);    }    /** A class to get the install list in a background thread. */    private class BackgroundInstallListGetter implements Runnable {        /** Parent installer. */        private GraphicalInstaller parent;        /** URL of the list. */        private String url;        /**         * Construct a BackgroundInstallListGetter.         *         * @param theParent parent installer of this object         * @param theUrl where to get the list of suites to install.         */        private BackgroundInstallListGetter(GraphicalInstaller theParent,                                            String theUrl) {            parent = theParent;            url = theUrl;        }        /**         * Get the list of suites for the user to install.         * The suites that are listed         * are the links on a web page that end with .jad.         */        public void run() {            StreamConnection conn = null;            InputStreamReader in = null;            String errorMessage;            long startTime;            startTime = System.currentTimeMillis();            try {                parent.displayProgressForm("Getting Install List",                                             "", url, 0, "Connecting...");                conn = (StreamConnection)Connector.open(url, Connector.READ);                in = new InputStreamReader(conn.openInputStream());                try {                    parent.updateProgressForm("", 0, "Downloading...");                    parent.installList =                        SuiteDownloadInfo.getDownloadInfoFromPage(in);                                        if (parent.installList.size() > 0) {                        parent.installListBox = new List(Resource.getString(                                                "Select one to install:"),                                                Choice.IMPLICIT);                        // Add each suite                        for (int i = 0; i < parent.installList.size(); i++) {                            SuiteDownloadInfo suite =                                (SuiteDownloadInfo)installList.elementAt(i);                            parent.installListBox.append(suite.label,                                                         (Image)null);                        }                        parent.installListBox.addCommand(backCmd);                        parent.installListBox.addCommand(installCmd);                        parent.installListBox.setCommandListener(parent);                        /*                         * We need to prevent "flashing" on fast development                         * platforms.                          */                        while (System.currentTimeMillis() -                            parent.lastDisplayChange <                             parent.ALERT_TIMEOUT);                        parent.display.setCurrent(parent.installListBox);                        return;                    }                    errorMessage = Resource.getString(                        "No MIDlet Suites found. " +                        "Check the URL to make sure it is correct.");                } catch (IllegalArgumentException ex) {                    errorMessage = Resource.getString(                        "The URL is not formatted correctly.");                } catch (Exception ex) {                    errorMessage = ex.getMessage();                }            } catch (Exception ex) {                errorMessage = Resource.getString(                    "The connection failed. Please check the website " +                    "URL and try again.");            } finally {                if (parent.progressForm != null) {                    // end the background thread of progress gauge.                    Gauge progressGauge = (Gauge)parent.progressForm.get(                                          parent.progressGaugeIndex);                    progressGauge.setValue(Gauge.CONTINUOUS_IDLE);                }                try {                    conn.close();                    in.close();                } catch (Exception e) {                    // ignore                }            }            Alert a = new Alert(Resource.getString("Error"),                                 errorMessage, null, AlertType.ERROR);            a.setTimeout(Alert.FOREVER);            parent.display.setCurrent(a, parent.urlTextBox);        }    }    /** A class to install a suite in a background thread. */    private class BackgroundInstaller implements Runnable, InstallListener {        /** Parent installer. */        private GraphicalInstaller parent;        /** URL to install from. */        private String url;         /** Name of MIDlet suite. */        private String name;        /**         * Message for the user after the current install completes         * successfully.         */        private String successMessage;        /** Flag to update the current suite. */        private boolean update;        /** State of the install. */        InstallState installState;        /** Signals that the user wants the install to continue. */        boolean continueInstall;        /** Signals that the suite only has JAR, no JAD. */        boolean jarOnly;        /** Signals that a proxyAuth is needed. */        boolean proxyAuth;        /**         * Construct a BackgroundInstaller.         *         * @param theParent parent installer of this object         * @param theJadUrl where to get the JAD.         * @param theName name of the MIDlet suite         * @param theSuccessMessage message to display to user upon success         * @param updateFlag if true the current suite should be         *                      overwritten without asking the user.         */        private BackgroundInstaller(GraphicalInstaller theParent,                String theJadUrl, String theName, String theSuccessMessage,                boolean updateFlag) {            parent = theParent;            url = theJadUrl;            name = theName;            successMessage = theSuccessMessage;            update = updateFlag;        }        /**         * Run the installer.         */        public void run() {            try {                String lastInstalledMIDletName;                if (jarOnly) {                    lastInstalledMIDletName =                         parent.installer.installJar(url, false, false, this);                } else {                    lastInstalledMIDletName =                          parent.installer.installJad(url, false, false, this);                }                // Let the manager know what suite was installed                GraphicalInstaller.saveSettings(null, lastInstalledMIDletName);                parent.displaySuccessMessage(successMessage);                /*                 * We need to prevent "flashing" on fast development                 * platforms.                 */                while ((System.currentTimeMillis() -                        parent.lastDisplayChange) < parent.ALERT_TIMEOUT);                parent.notifyDestroyed();                return;            } catch (Throwable ex) {                String title;                String msg;                if (parent.installer != null &&                        parent.installer.wasStopped()) {                    displayListAfterCancelMessage();                    return;                }                if (ex instanceof InvalidJadException) {                    InvalidJadException ije = (InvalidJadException)ex;                    if (ije.getReason() ==                            InvalidJadException.INVALID_JAD_TYPE) {                        // media type of JAD was wrong, it could be a JAR                        String mediaType = (String)ije.getExtraData();                        if (Installer.JAR_MT_1.equals(mediaType) ||                                Installer.JAR_MT_2.equals(mediaType)) {                            // re-run as a JAR only install                            if (confirmJarOnlyDownload()) {                                jarOnly = true;                                installState = null;                                run();                                return;                            }                            displayListAfterCancelMessage();                            return;                        }                    }                    msg = translateJadException((InvalidJadException)ex,                                                name, null, null, url);                } else if (ex instanceof IOException) {                    msg = Resource.getString(                          "The connection dropped and the installation " +                          "did not complete. Please try installing again.");                } else {                    msg = ex.getMessage();                }                title = Resource.getString("Install Error");                if (parent.installListBox == null) {                    // go back to the app list                    displayException(title, msg);                     return;                }                Alert a = new Alert(title, msg, null, AlertType.ERROR);                a.setTimeout(Alert.FOREVER);                parent.display.setCurrent(a, parent.installListBox);            } finally {                if (parent.progressForm != null) {                    // end the background thread of progress gauge.                    Gauge progressGauge = (Gauge)parent.progressForm.get(                                          parent.progressGaugeIndex);                    progressGauge.setValue(Gauge.CONTINUOUS_IDLE);                }            }        }        /**         * Called with the current state of the install so the user can be         * asked to override the warning. Calls the parent to display the         * warning to the user and then waits on the state object for         * user's response.         *         * @param state current state of the install.         *         * @return true if the user wants to continue,         *         false to stop the install         */        public boolean warnUser(InstallState state) {            installState = state;            InvalidJadException e = installState.getLastException();            switch (e.getReason()) {            case InvalidJadException.UNAUTHORIZED:                proxyAuth = false;                parent.getUsernameAndPassword();                break;            case InvalidJadException.PROXY_AUTH:                proxyAuth = true;                parent.getProxyUsernameAndPassword();                break;            case InvalidJadException.OLD_VERSION:            case InvalidJadException.ALREADY_INSTALLED:            case InvalidJadException.NEW_VERSION:                // this is now an update                update = true;                // fall through            default:                parent.warnUser(name,                    state.getAppProperty(Installer.VENDOR_PROP),                    state.getAppProperty(Installer.VERSION_PROP),                    url, e);            }            return waitForUser();        }        /**         * Called with the current state of the install so the user can be         * asked to confirm the jar download.         * If false is returned, the an I/O exception thrown and         * {@link Installer#wasStopped()} will return true if called.         *         * @param state current state of the install.         *         * @return true if the user wants to continue, false to stop the         *         install         */        public boolean confirmJarDownload(InstallState state) {            if (update) {                // this an update, no need to confirm.                return true;            }            installState = state;            url = state.getJarUrl();            parent.displayDownloadConfirmation(state);            return waitForUser();        }        /**         * Called with the current state of the install so the user can be         * asked to confirm if the RMS data should be kept for new version of         * an updated suite.         *         * @param state current state of the install.         *         * @return true if the user wants to keep the RMS data for the next         * suite         */        public boolean keepRMS(InstallState state) {            installState = state;            parent.displayKeepRMSForm(state);            return waitForUser();        }        /**         * Called with the current state of the install so the user can be         * asked to confirm the jar only download.         *         * @return true if the user wants to continue, false to stop the         *         install         */        private boolean confirmJarOnlyDownload() {            if (update) {                // this an update, no need to confirm.                return true;            }            parent.displayJarOnlyDownloadConfirmation();            return waitForUser();        }        /**         * Wait for the user to respond to current dialog.         *         * @return true if the user wants to continue, false to stop the         *         install         */        private boolean waitForUser() {                boolean temp;            synchronized (this) {                try {                    this.wait();                } catch (InterruptedException ie) {                    // ignore                }            }            installState = null;            temp = continueInstall;            continueInstall = false;            return temp;        }        /**         * Called with the current status of the install.         * Changes the status alert box text based on the status.         *         * @param status current status of the install.         * @param state current state of the install.         */        public void updateStatus(int status, InstallState state) {            parent.updateStatus(status, state);        }        /**         * Wait for the cancel message to be displayed to prevent flashing         * and then display the list of suites.         */        private void displayListAfterCancelMessage() {            // wait for the parent to display "cancelled"            synchronized (parent) {                /*                 * We need to prevent "flashing" on fast                 * development platforms.                 */                while ((System.currentTimeMillis() -                        parent.lastDisplayChange) < parent.ALERT_TIMEOUT);                if (parent.installListBox == null) {                    // go back to app list                    parent.notifyDestroyed();                    return;                }                parent.display.setCurrent(parent.installListBox);            }        }    }}

⌨️ 快捷键说明

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