📄 manager.java
字号:
} /** * Ask the user for the URL. */ private void getUrl() { try { if (urlTextBox == null) { urlTextBox = new TextBox(Resource.getString( "Enter a website to Install From:"), defaultInstallListUrl, 1024, TextField.ANY); urlTextBox.addCommand(backCmd); urlTextBox.addCommand(selectSuiteCmd); urlTextBox.setCommandListener(this); } display.setCurrent(urlTextBox); } catch (Exception ex) { Alert a = new Alert(Resource.getString("Exception"), ex.toString(), null, AlertType.ERROR); a.setTimeout(Alert.FOREVER); display.setCurrent(a, mlist); } } /** * Ask the user for the settings. */ private void getSettings() { if (settingsTextBox == null) { settingsTextBox = new TextBox(Resource.getString( "Set Website URL"), null, 1024, TextField.ANY); settingsTextBox.addCommand(backCmd); settingsTextBox.addCommand(saveSettingsCmd); settingsTextBox.setCommandListener(this); } settingsTextBox.setString(defaultInstallListUrl); display.setCurrent(settingsTextBox); } /** * Save the settings the user entered. */ private void saveSettings() { String temp; ByteArrayOutputStream bas; DataOutputStream dos; byte[] data; RecordEnumeration records; RecordStore settings; temp = settingsTextBox.getString(); if (temp == null) { display.setCurrent(mlist); return; } try { bas = new ByteArrayOutputStream(); dos = new DataOutputStream(bas); dos.writeUTF(temp); data = bas.toByteArray(); settings = RecordStore.openRecordStore(SETTINGS_STORE, true); records = settings.enumerateRecords(null, null, false); if (records.numRecords() == 0) { settings.addRecord(data, 0, data.length); } else { settings.setRecord(records.nextRecordId(), data, 0, data.length); } settings.closeRecordStore(); defaultInstallListUrl = temp; if (urlTextBox != null) { urlTextBox.setString(defaultInstallListUrl); } displaySuccessMessage(Resource.getString("Saved!")); } catch (Exception ex) { Alert a = new Alert(Resource.getString("Exception"), ex.toString(), null, AlertType.ERROR); a.setTimeout(Alert.FOREVER); display.setCurrent(a, mlist); } } /** * Get the settings the Manager saved for the user. */ private void restoreSettings() { ByteArrayInputStream bas; DataInputStream dis; byte[] data; RecordEnumeration records; RecordStore settings = null; try { settings = RecordStore.openRecordStore(SETTINGS_STORE, false); records = settings.enumerateRecords(null, null, false); if (records.numRecords() == 0) { return; } data = records.nextRecord(); bas = new ByteArrayInputStream(data); dis = new DataInputStream(bas); defaultInstallListUrl = dis.readUTF(); return; } catch (RecordStoreException e) { // ignore } catch (IOException e) { // ignore } finally { if (settings != null) { try { settings.closeRecordStore(); } catch (RecordStoreException e) { // ignore } } } } /** * Let the user select a suite to install. The suites that are listed * are the links on a web page that end with .jad. * * @param url where to get the list of suites to install. */ private void selectSuiteToInstall(String url) { new Thread(new BackgroundInstallListGetter(this, url)).start(); } /** * Install a suite. * * @param selectedSuite index into the installList */ private void installSuite(int selectedSuite) { SuiteDownloadInfo suite; suite = (SuiteDownloadInfo)installList.elementAt(selectedSuite); cancelledMessage = Resource.getString("Installation cancelled."); finishingMessage = Resource.getString("Finishing installation."); installSuiteCommon("Installing", suite.label, suite.url, suite.label + Resource.getString(" was successfully installed"), false); } /** * Install a suite. * * @param action action to put in the form's title * @param name name to in the form's title * @param url URL of a JAD * @param successMessage message to display to user upon success * @param overwriteFlag if true the current suite should be * overwritten without asking the user. */ private void installSuiteCommon(String action, String name, String url, String successMessage, boolean overwriteFlag) { Form installForm; try { installForm = displayConnectingForm(action, name, url); installForm.addCommand(stopCmd); installForm.setCommandListener(this); backgroundInstaller = new BackgroundInstaller(this, url, name, successMessage, overwriteFlag); new Thread(backgroundInstaller).start(); } catch (Exception ex) { StringBuffer sb = new StringBuffer() .append(name) .append("\n") .append(Resource.getString("Error")) .append(": ") .append(ex.toString()); Alert a = new Alert(Resource.getString("Cannot access: "), sb.toString(), null, AlertType.ERROR); a.setTimeout(Alert.FOREVER); display.setCurrent(a, mlist); return; } } /** * Ask a username and password. */ private void getUsernameAndPassword() { if (passwordForm == null) { passwordForm = new Form(null); usernameField = new TextField( Resource.getString("Please Enter ID"), null, 40, TextField.ANY); passwordForm.append(usernameField); passwordField = new TextField( Resource.getString("Password"), null, 40, TextField.PASSWORD); passwordForm.append(passwordField); passwordForm.addCommand(cancelInstallCmd); passwordForm.addCommand(nextCmd); passwordForm.setCommandListener(this); } passwordField.setString(""); display.setCurrent(passwordForm); } /** * Resume the install of the suite with a password and username. */ private void resumeInstallWithPassword() { String username; String password; username = usernameField.getString(); password = passwordField.getString(); if (username == null || username.length() == 0) { Alert a = new Alert(Resource.getString("Error"), Resource.getString( "The ID has not been entered."), null, AlertType.ERROR); a.setTimeout(ALERT_TIMEOUT); display.setCurrent(a, passwordForm); return; } if (password == null || password.length() == 0) { Alert a = new Alert(Resource.getString("Error"), Resource.getString( "The password has not been entered."), null, AlertType.ERROR); a.setTimeout(ALERT_TIMEOUT); display.setCurrent(a, passwordForm); return; } // redisplay the progress form display.setCurrent(conForm); backgroundInstaller.installState.setUsername(username); backgroundInstaller.installState.setPassword(password); backgroundInstaller.continueInstall = true; backgroundInstaller.installState.notify(); } /** * Give the user a chance to act on warning during an installation. * * @param name name of the MIDlet suite to insert into the message * @param jadUrl URL of a JAD, can be null * @param e last exception from the installer */ private void warnUser(String name, String jadUrl, InvalidJadException e) { Form warningForm; String extraConfirmMsg; warningForm = new Form(null); warningForm.setTitle(Resource.getString("Warning")); warningForm.append(translateJadException(e, name, jadUrl)); warningForm.addCommand(cancelInstallCmd); warningForm.addCommand(okCmd); warningForm.setCommandListener(this); display.setCurrent(warningForm); } /** * Update the status form. * * @param status current status of the install. */ private void updateStatus(int status) { if (status != Installer.STORING_SUITE) { return; } displaySuccessMessage(finishingMessage); } /** * Resume the install after a the user overrides a warning. */ private void resumeInstallAfterWarning() { // redisplay the progress form display.setCurrent(conForm); backgroundInstaller.continueInstall = true; backgroundInstaller.installState.notify(); } /** Cancel an install (if there is one) waiting for user input. */ private void cancelBackgroundInstall() { if (backgroundInstaller != null && backgroundInstaller.installState != null) { backgroundInstaller.installState.notify(); } } /** * Display the connecting form to the user. * * @param action action to put in the form's title * @param name name to in the form's title * @param url URL of a JAD * * @return displayed form */ private Form displayConnectingForm(String action, String name, String url) { Image icon; conForm = new Form(null); conForm.setTitle(Resource.getString(action) + " " + name); icon = getIconFromStorage( (colorDisplay ? "_dt_8.png" : "_dt_2.png")); conForm.append(new ImageItem(null, icon, ImageItem.LAYOUT_CENTER + ImageItem.LAYOUT_NEWLINE_BEFORE + ImageItem.LAYOUT_NEWLINE_AFTER, null)); conForm.append(action); conForm.append(Resource.getString(" from")); conForm.append(": "); conForm.append(url); display.setCurrent(conForm); return conForm; } /** * Alert the user that an action was successful. * @param successMessage message to display to user */ private void displaySuccessMessage(String successMessage) { Image icon; Alert successAlert; icon = getIconFromStorage( (colorDisplay ? "_dukeok8.png" : "_dukeok2.png")); successAlert = new Alert(null, successMessage, icon, null); successAlert.setTimeout(ALERT_TIMEOUT); // We need to prevent "flashing" on fast development platforms. while (System.currentTimeMillis() - lastDisplayChange < ALERT_TIMEOUT); lastDisplayChange = System.currentTimeMillis(); display.setCurrent(successAlert, mlist); } /** * Alert the user that an action was canceled. The backgroundInstaller * will hide the message. * @param message message to display to user */ private void displayCancelledMessage(String message) { Form form; Image icon; form = new Form(null); icon = getIconFromStorage( (colorDisplay ? "_ack_8.png" : "_ack_2.png")); form.append(new ImageItem(null, icon, ImageItem.LAYOUT_CENTER + ImageItem.LAYOUT_NEWLINE_BEFORE + ImageItem.LAYOUT_NEWLINE_AFTER, null)); form.append(message); display.setCurrent(form); } /**
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -