void store() {
   // TODO store modified settings
   // Example:
   // Preferences.userNodeForPackage(CorePanel.class).putBoolean("someFlag",
   // someCheckBox.isSelected());
   // or for org.openide.util with API spec. version >= 7.4:
   // NbPreferences.forModule(CorePanel.class).putBoolean("someFlag", someCheckBox.isSelected());
   // or:
   // SomeSystemOption.getDefault().setSomeStringProperty(someTextField.getText());
   GlobalPreferences preferences = GlobalPreferences.sharedInstance();
   preferences.setMonitoredHostPoll((Integer) monitoredHostPSpinner.getValue());
   preferences.setMonitoredDataPoll((Integer) monitoredDataPSpinner.getValue());
   preferences.setThreadsPoll((Integer) threadsPSpinner.getValue());
   preferences.setMonitoredHostCache((Integer) monitoredHostCSpinner.getValue());
   preferences.setMonitoredDataCache((Integer) monitoredDataCSpinner.getValue());
   preferences.store();
 }
 void load() {
   // TODO read settings and initialize GUI
   // Example:
   // someCheckBox.setSelected(Preferences.userNodeForPackage(CorePanel.class).getBoolean("someFlag", false));
   // or for org.openide.util with API spec. version >= 7.4:
   // someCheckBox.setSelected(NbPreferences.forModule(CorePanel.class).getBoolean("someFlag",
   // false));
   // or:
   // someTextField.setText(SomeSystemOption.getDefault().getSomeStringProperty());
   GlobalPreferences preferences = GlobalPreferences.sharedInstance();
   resetDNSAButton.setEnabled(true);
   monitoredHostPSpinner.setValue(preferences.getMonitoredHostPoll());
   monitoredDataPSpinner.setValue(preferences.getMonitoredDataPoll());
   threadsPSpinner.setValue(preferences.getThreadsPoll());
   monitoredHostCSpinner.setValue(preferences.getMonitoredHostCache());
   monitoredDataCSpinner.setValue(preferences.getMonitoredDataCache());
 }
  @Override
  public void endElement(String localName) {
    super.endElement(localName);
    try {
      if (mPreferences != null) {
        // we are inside <global_preferences>
        if (localName.equalsIgnoreCase("global_preferences")) {
          // Closing tag of <global_preferences> - nothing to do at the moment
        } else if (localName.equalsIgnoreCase("day_prefs")) {
          // closing <day_prefs>
          if (mDayOfWeek >= 0 && mDayOfWeek <= 6) {
            mPreferences.cpu_times.week_prefs[mDayOfWeek] = mTempCpuTimeSpan;
            mPreferences.net_times.week_prefs[mDayOfWeek] = mTempNetTimeSpan;
          }

          mTempCpuTimeSpan = null;
          mTempNetTimeSpan = null;
          mInsideDayPrefs = false;
        } else if (mInsideDayPrefs) {
          if (localName.equalsIgnoreCase("day_of_week")) {
            mDayOfWeek = Integer.parseInt(getCurrentElement());
          } else if (localName.equalsIgnoreCase("start_hour")) {
            if (mTempCpuTimeSpan == null) mTempCpuTimeSpan = new TimePreferences.TimeSpan();
            mTempCpuTimeSpan.start_hour = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("end_hour")) {
            if (mTempCpuTimeSpan == null) mTempCpuTimeSpan = new TimePreferences.TimeSpan();
            mTempCpuTimeSpan.end_hour = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("net_start_hour")) {
            if (mTempNetTimeSpan == null) mTempNetTimeSpan = new TimePreferences.TimeSpan();
            mTempNetTimeSpan.start_hour = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("net_end_hour")) {
            if (mTempNetTimeSpan == null) mTempNetTimeSpan = new TimePreferences.TimeSpan();
            mTempNetTimeSpan.end_hour = Double.parseDouble(getCurrentElement());
          }
        } else {
          // Not the closing tag - we decode possible inner tags
          if (localName.equalsIgnoreCase("run_on_batteries")) {
            mPreferences.run_on_batteries = Integer.parseInt(getCurrentElement()) != 0;
          } else if (localName.equalsIgnoreCase("run_gpu_if_user_active")) {
            mPreferences.run_gpu_if_user_active = Integer.parseInt(getCurrentElement()) != 0;
          } else if (localName.equalsIgnoreCase("run_if_user_active")) {
            mPreferences.run_if_user_active = Integer.parseInt(getCurrentElement()) != 0;
          } else if (localName.equalsIgnoreCase("idle_time_to_run")) {
            mPreferences.idle_time_to_run = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("suspend_cpu_usage")) {
            mPreferences.suspend_cpu_usage = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("leave_apps_in_memory")) {
            mPreferences.leave_apps_in_memory = Integer.parseInt(getCurrentElement()) != 0;
          } else if (localName.equalsIgnoreCase("dont_verify_images")) {
            mPreferences.dont_verify_images = Integer.parseInt(getCurrentElement()) != 0;
          } else if (localName.equalsIgnoreCase("work_buf_min_days")) {
            mPreferences.work_buf_min_days = Double.parseDouble(getCurrentElement());
            if (mPreferences.work_buf_min_days < 0.00001) mPreferences.work_buf_min_days = 0.00001;
          } else if (localName.equalsIgnoreCase("work_buf_additional_days")) {
            mPreferences.work_buf_additional_days = Double.parseDouble(getCurrentElement());
            if (mPreferences.work_buf_additional_days < 0.0)
              mPreferences.work_buf_additional_days = 0.0;
          } else if (localName.equalsIgnoreCase("max_ncpus_pct")) {
            mPreferences.max_ncpus_pct = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("cpu_scheduling_period_minutes")) {
            mPreferences.cpu_scheduling_period_minutes = Double.parseDouble(getCurrentElement());
            if (mPreferences.cpu_scheduling_period_minutes < 0.00001)
              mPreferences.cpu_scheduling_period_minutes = 60;
          } else if (localName.equalsIgnoreCase("disk_interval")) {
            mPreferences.disk_interval = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("disk_max_used_gb")) {
            mPreferences.disk_max_used_gb = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("disk_max_used_pct")) {
            mPreferences.disk_max_used_pct = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("disk_min_free_gb")) {
            mPreferences.disk_min_free_gb = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("ram_max_used_busy_pct")) {
            mPreferences.ram_max_used_busy_frac = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("ram_max_used_idle_pct")) {
            mPreferences.ram_max_used_idle_frac = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("max_bytes_sec_up")) {
            mPreferences.max_bytes_sec_up = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("max_bytes_sec_down")) {
            mPreferences.max_bytes_sec_down = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("cpu_usage_limit")) {
            mPreferences.cpu_usage_limit = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("daily_xfer_limit_mb")) {
            mPreferences.daily_xfer_limit_mb = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("daily_xfer_period_days")) {
            mPreferences.daily_xfer_period_days = Integer.parseInt(getCurrentElement());
          } else if (localName.equalsIgnoreCase("run_if_battery_nl_than")) {
            mPreferences.run_if_battery_nl_than = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("run_if_temp_lt_than")) {
            mPreferences.run_if_temp_lt_than = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("start_hour")) {
            mPreferences.cpu_times.start_hour = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("end_hour")) {
            mPreferences.cpu_times.end_hour = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("net_start_hour")) {
            mPreferences.net_times.start_hour = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("net_end_hour")) {
            mPreferences.net_times.end_hour = Double.parseDouble(getCurrentElement());
          } else if (localName.equalsIgnoreCase("run_always_when_plugged")) {
            mPreferences.run_always_when_plugged = Integer.parseInt(getCurrentElement()) != 0;
          } else if (localName.equalsIgnoreCase("xfer_only_when_wifi")) {
            mPreferences.xfer_only_when_wifi = Integer.parseInt(getCurrentElement()) != 0;
          }
        }
      }
    } catch (NumberFormatException e) {
      if (Logging.INFO) Log.i(TAG, "Exception when decoding " + localName);
    }
  }