/*
   * (non-Javadoc)
   *
   * @see net.sf.borg.ui.options.OptionsView.OptionsPanel#loadOptions()
   */
  @Override
  public void loadOptions() {
    backupDir.setText(Prefs.getPref(PrefName.BACKUPDIR));
    OptionsPanel.setCheckBox(colorprint, PrefName.COLORPRINT);

    OptionsPanel.setCheckBox(splashbox, PrefName.SPLASH);
    OptionsPanel.setCheckBox(stackbox, PrefName.STACKTRACE);

    OptionsPanel.setCheckBox(useSysTray, PrefName.USESYSTRAY);
    OptionsPanel.setCheckBox(startToSysTray, PrefName.BACKGSTART);
    OptionsPanel.setCheckBox(dateInSysTray, PrefName.SYSTRAYDATE);
    OptionsPanel.setCheckBox(dynamicLoading, PrefName.DYNAMIC_LOADING);
    OptionsPanel.setCheckBox(verboseLogging, PrefName.DEBUG);
    OptionsPanel.setCheckBox(useProxy, PrefName.USE_PROXY);

    String shutdown_action = Prefs.getPref(PrefName.SHUTDOWN_ACTION);
    if (shutdown_action.isEmpty() || SHUTDOWN_ACTION.PROMPT.toString().equals(shutdown_action))
      shutdownAction.setSelectedIndex(0);
    else if (SHUTDOWN_ACTION.NONE.toString().equals(shutdown_action))
      shutdownAction.setSelectedIndex(1);
    else if (SHUTDOWN_ACTION.BACKUP.toString().equals(shutdown_action))
      shutdownAction.setSelectedIndex(2);
    else if (SHUTDOWN_ACTION.EMAIL.toString().equals(shutdown_action))
      shutdownAction.setSelectedIndex(3);

    int socket = Prefs.getIntPref(PrefName.SOCKETPORT);
    socketPort.setText(Integer.toString(socket));

    proxyHostText.setText(Prefs.getPref(PrefName.PROXY_HOST));

    int port = Prefs.getIntPref(PrefName.PROXY_PORT);
    proxyPortText.setText(Integer.toString(port));
  }
  /*
   * (non-Javadoc)
   *
   * @see net.sf.borg.ui.options.OptionsView.OptionsPanel#applyChanges()
   */
  @Override
  public void applyChanges() {

    if (verboseLogging.isSelected()) log.setLevel(Level.ALL);
    else log.setLevel(Level.INFO);

    OptionsPanel.setBooleanPref(colorprint, PrefName.COLORPRINT);

    OptionsPanel.setBooleanPref(splashbox, PrefName.SPLASH);
    OptionsPanel.setBooleanPref(stackbox, PrefName.STACKTRACE);

    OptionsPanel.setBooleanPref(useSysTray, PrefName.USESYSTRAY);
    OptionsPanel.setBooleanPref(startToSysTray, PrefName.BACKGSTART);
    OptionsPanel.setBooleanPref(dateInSysTray, PrefName.SYSTRAYDATE);
    OptionsPanel.setBooleanPref(dynamicLoading, PrefName.DYNAMIC_LOADING);
    OptionsPanel.setBooleanPref(verboseLogging, PrefName.DEBUG);
    OptionsPanel.setBooleanPref(useProxy, PrefName.USE_PROXY);

    Prefs.putPref(PrefName.BACKUPDIR, backupDir.getText());

    if (shutdownAction.getSelectedIndex() == 0)
      Prefs.putPref(PrefName.SHUTDOWN_ACTION, SHUTDOWN_ACTION.PROMPT.toString());
    else if (shutdownAction.getSelectedIndex() == 1)
      Prefs.putPref(PrefName.SHUTDOWN_ACTION, SHUTDOWN_ACTION.NONE.toString());
    else if (shutdownAction.getSelectedIndex() == 2)
      Prefs.putPref(PrefName.SHUTDOWN_ACTION, SHUTDOWN_ACTION.BACKUP.toString());
    else if (shutdownAction.getSelectedIndex() == 3)
      Prefs.putPref(PrefName.SHUTDOWN_ACTION, SHUTDOWN_ACTION.EMAIL.toString());

    // validate that socket is a number
    try {
      int socket = Integer.parseInt(socketPort.getText());
      Prefs.putPref(PrefName.SOCKETPORT, new Integer(socket));
    } catch (NumberFormatException e) {
      Errmsg.getErrorHandler().notice(Resource.getResourceString("socket_warn"));
      socketPort.setText("-1");
      Prefs.putPref(PrefName.SOCKETPORT, new Integer(-1));
    }

    Prefs.putPref(PrefName.PROXY_HOST, proxyHostText.getText());

    try {
      int port = Integer.parseInt(proxyPortText.getText());
      Prefs.putPref(PrefName.PROXY_PORT, new Integer(port));
    } catch (NumberFormatException e) {
      Errmsg.getErrorHandler().notice(Resource.getResourceString("proxy_warn"));
    }
  }