From 0c63ade252ea194324b3da9a390cf383b2a6bfa7 Mon Sep 17 00:00:00 2001 From: Raphael Date: Thu, 11 Jun 2009 18:10:08 -0700 Subject: SDK Updater: SettingsController that handles the settings. There is not any longer any logic in the SettingsPage, it is handled now by a "SettingsControllers" which is available via UpdaterData. The page only takes care of notifying the controller via a callback when settings have changed in the UI. --- .../internal/repository/SettingsPage.java | 105 +++++---------------- 1 file changed, 21 insertions(+), 84 deletions(-) (limited to 'sdkmanager/app/src') diff --git a/sdkmanager/app/src/com/android/sdkmanager/internal/repository/SettingsPage.java b/sdkmanager/app/src/com/android/sdkmanager/internal/repository/SettingsPage.java index b07617f..ac7c4e4 100755 --- a/sdkmanager/app/src/com/android/sdkmanager/internal/repository/SettingsPage.java +++ b/sdkmanager/app/src/com/android/sdkmanager/internal/repository/SettingsPage.java @@ -16,8 +16,6 @@ package com.android.sdkmanager.internal.repository; -import com.android.prefs.AndroidLocation; -import com.android.prefs.AndroidLocation.AndroidLocationException; import com.android.sdkuilib.internal.repository.ISettingsPage; import org.eclipse.swt.SWT; @@ -31,28 +29,15 @@ import org.eclipse.swt.widgets.Group; import org.eclipse.swt.widgets.Label; import org.eclipse.swt.widgets.Text; -import java.io.File; -import java.io.FileInputStream; -import java.io.FileOutputStream; -import java.io.IOException; -import java.net.URL; import java.util.Properties; -/* - * TODO list - * - The window should probably set a callback to be notified when settings are changed. - * - Actually use the settings. - */ public class SettingsPage extends Composite implements ISettingsPage { - private static final String SETTINGS_FILENAME = "androidtool.cfg"; //$NON-NLS-1$ - - /** Java system setting picked up by {@link URL} for http proxy port */ - private static final String JAVA_HTTP_PROXY_PORT = "http.proxyPort"; //$NON-NLS-1$ - /** Java system setting picked up by {@link URL} for http proxy host */ - private static final String JAVA_HTTP_PROXY_HOST = "http.proxyHost"; //$NON-NLS-1$ + // data members + private SettingsChangedCallback mSettingsChangedCallback; + // UI widgets private Group mProxySettingsGroup; private Group mPlaceholderGroup; private Button mApplyButton; @@ -130,85 +115,37 @@ public class SettingsPage extends Composite implements ISettingsPage { private void postCreate() { } - private void onApplySelected() { - applySettings(); - saveSettings(); + /** Loads settings from the given {@link Properties} container and update the page UI. */ + public void loadSettings(Properties in_settings) { + mProxyServerText.setText(in_settings.getProperty(JAVA_HTTP_PROXY_HOST, "")); //$NON-NLS-1$ + mProxyPortText.setText(in_settings.getProperty(JAVA_HTTP_PROXY_PORT, "")); //$NON-NLS-1$ } - /** - * Update Java system properties for the HTTP proxy. - */ - public void applySettings() { - Properties props = System.getProperties(); - props.put(JAVA_HTTP_PROXY_HOST, mProxyServerText.getText()); - props.put(JAVA_HTTP_PROXY_PORT, mProxyPortText.getText()); + /** Called by the application to retrieve settings from the UI and store them in + * the given {@link Properties} container. */ + public void retrieveSettings(Properties out_settings) { + out_settings.put(JAVA_HTTP_PROXY_HOST, mProxyServerText.getText()); + out_settings.put(JAVA_HTTP_PROXY_PORT, mProxyPortText.getText()); } /** - * Saves settings. + * Called by the application to give a callback that the page should invoke when + * settings must be applied. The page does not apply the settings itself, instead + * it notifies the application. */ - private void saveSettings() { - Properties props = new Properties(); - props.put(JAVA_HTTP_PROXY_HOST, mProxyServerText.getText()); - props.put(JAVA_HTTP_PROXY_PORT, mProxyPortText.getText()); - - - FileOutputStream fos = null; - try { - String folder = AndroidLocation.getFolder(); - File f = new File(folder, SETTINGS_FILENAME); - - fos = new FileOutputStream(f); - - props.store( fos, "## Settings for Android Tool"); //$NON-NLS-1$ - - } catch (AndroidLocationException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (fos != null) { - try { - fos.close(); - } catch (IOException e) { - } - } - } + public void setOnSettingsChanged(SettingsChangedCallback settingsChangedCallback) { + mSettingsChangedCallback = settingsChangedCallback; } /** - * Load settings and puts them in the UI. + * Notify the application that settings have changed. */ - public void loadSettings() { - FileInputStream fis = null; - try { - String folder = AndroidLocation.getFolder(); - File f = new File(folder, SETTINGS_FILENAME); - if (f.exists()) { - fis = new FileInputStream(f); - - Properties props = new Properties(); - props.load(fis); - - mProxyServerText.setText(props.getProperty(JAVA_HTTP_PROXY_HOST, "")); //$NON-NLS-1$ - mProxyPortText.setText(props.getProperty(JAVA_HTTP_PROXY_PORT, "")); //$NON-NLS-1$ - } - - } catch (AndroidLocationException e) { - e.printStackTrace(); - } catch (IOException e) { - e.printStackTrace(); - } finally { - if (fis != null) { - try { - fis.close(); - } catch (IOException e) { - } - } + private void onApplySelected() { + if (mSettingsChangedCallback != null) { + mSettingsChangedCallback.onSettingsChanged(this); } } - // End of hiding from SWT Designer //$hide<<$ } -- cgit v1.1