Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gui.dialogs.SettingsDialog.java

Here you can find all the information about the file org.dgpf.gui.dialogs.SettingsDialog.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Alexander Podlich
 * 
 * E-Mail           : podlich@student.uni-kassel.de
 * Creation Date    : 03.09.2006 15:06:14
 * Original Filename: org.dgpf.gui.dialogs.SettingsDialog.java
 * Version          : 1.0
 * Last modification: 03.09.2006
 * Last modified by : Alexander Podlich
 * 
 * License          : GNU LESSER GENERAL PUBLIC LICENSE
 *                    Version 2.1, February 1999
 *                    You should have received a copy of this license along
 *                    with this library; if not, write to the Free Software
 *                    Foundation, Inc., 59 Temple Place, Suite 330, Boston,
 *                    MA 02111-1307, USA or download the license under
 *                    http://www.gnu.org/copyleft/lesser.html.
 *                    
 * Warranty         : This software is provided "as is" without any
 *                    warranty; without even the implied warranty of
 *                    merchantability or fitness for a particular purpose.
 *                    See the Gnu Lesser General Public License for more
 *                    details.
 */


package org.dgpf.gui.dialogs;

import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.util.Locale;
import java.util.Vector;

import javax.swing.JComboBox;
import javax.swing.border.TitledBorder;

import org.dgpf.gui.Frame;
import org.dgpf.gui.components.BorderedPanel;
import org.dgpf.gui.components.CheckBox;
import org.dgpf.gui.components.DirChooserPanel;
import org.dgpf.gui.components.TextField;
import org.dgpf.gui.utils.LanguageSwitcher;
import org.dgpf.gui.utils.Layout;
import org.dgpf.gui.utils.PrefUtils;

/**
 * Settings dialog.
 * 
 * @author Alexander Podlich
 */

public class SettingsDialog extends DialogBase
  {

  /**
   * The serial version UID.
   */

  private static final long     serialVersionUID = 1L;

  /**
   * The available languages to choose from.
   */

  private static final Locale[] AVAIL_LANGUAGES  = { Locale.ENGLISH,
      Locale.GERMAN                             };

  /**
   * The dir chooser panel
   */

  private DirChooserPanel       m_chooserPanel;

  /**
   * The log check box
   */

  private CheckBox              m_checkBox;

  /**
   * Chooser for the language.
   */

  private JComboBox             m_cbLanguage;

  /**
   * Hint for the language switcher combo box.
   */

  private TextField             m_hintLang;

  /**
   * Constructor.
   * 
   * @param p_parent
   *          The parent frame.
   */

  public SettingsDialog(Frame p_parent)
    {

    super(p_parent, LanguageSwitcher.getString("sd_caption"),
        LanguageSwitcher.getString("sd_info"), DialogBase.OK_CANCEL_BTN,
        true, new GridBagLayout());

    /* Log directory chooser */
    BorderedPanel l_borderedPanelLog = new BorderedPanel(LanguageSwitcher
        .getString("sd_log"), TitledBorder.LEFT);
    l_borderedPanelLog.setLayout(new GridBagLayout());

    this.m_checkBox = new CheckBox(LanguageSwitcher
        .getString("sd_log_activate"), "log_check"this, true);

    this.m_chooserPanel = new DirChooserPanel(LanguageSwitcher
        .getString("sd_dc_panel_caption"), System.getProperty("user.dir"),
        LanguageSwitcher.getString("sd_dc_caption"), null, null, null,
        LanguageSwitcher.getString("btn_open"));

    if(null != PrefUtils.getString("log_se_dir", null))
      {
      this.m_chooserPanel.setFile(PrefUtils.getString("log_se_dir", null));
      }

    if(PrefUtils.getBoolean("log_se", false))
      {
      this.m_checkBox.setSelected(true);
      this.m_chooserPanel.setEnabled(true);
      }
    else
      {
      this.m_checkBox.setSelected(false);
      this.m_chooserPanel.setEnabled(false);
      }

    Layout.set_constraints(l_borderedPanelLog, this.m_checkBox, 1.0, 1.0,
        GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START,
        GridBagConstraints.REMAINDER, new Insets(3, 3, 3, 3));

    Layout.set_constraints(l_borderedPanelLog, this.m_chooserPanel, 1.0,
        1.0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START,
        GridBagConstraints.RELATIVE, new Insets(3, 3, 3, 3));

    Layout.set_constraints(this.getCenter(), l_borderedPanelLog, 1.0, 1.0,
        GridBagConstraints.BOTH, GridBagConstraints.LINE_START,
        GridBagConstraints.REMAINDER, new Insets(3, 3, 3, 3));

    /* Language chooser */
    BorderedPanel l_borderedPanelLang = new BorderedPanel(LanguageSwitcher
        .getString("sd_lang"), TitledBorder.LEFT);
    l_borderedPanelLang.setLayout(new GridBagLayout());

    // Compile language strings
    Vector<String> l_langStrings = new Vector<String>();
    for(Locale l_locale : SettingsDialog.AVAIL_LANGUAGES)
      {
      l_langStrings.add(LanguageSwitcher.getString("se_lang_"
          + l_locale.getDisplayLanguage()));
      }

    this.m_cbLanguage = new JComboBox(l_langStrings
        .toArray(new String[] {}));
    this.m_cbLanguage.setEditable(false);
    this.m_cbLanguage.addActionListener(this);

    Locale l_locale = this.m_parent.getClient().getLocale();

    // set selected item
    if(l_locale.equals(Locale.ENGLISH))
      {
      this.m_cbLanguage.setSelectedIndex(0);
      }
    else
      if(l_locale.equals(Locale.GERMAN))
        {
        this.m_cbLanguage.setSelectedIndex(1);
        }

    this.m_hintLang = new TextField(LanguageSwitcher
        .getString("sd_lang_hint"), false);

    Layout.set_constraints(l_borderedPanelLang, this.m_cbLanguage, 1.0,
        1.0, GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START,
        GridBagConstraints.REMAINDER, new Insets(3, 3, 3, 3));

    Layout.set_constraints(l_borderedPanelLang, this.m_hintLang, 1.0, 1.0,
        GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START,
        GridBagConstraints.REMAINDER, new Insets(3, 3, 3, 3));

    Layout.set_constraints(this.getCenter(), l_borderedPanelLang, 1.0,
        1.0, GridBagConstraints.BOTH, GridBagConstraints.LINE_START,
        GridBagConstraints.REMAINDER, new Insets(3, 3, 3, 3));

    /* Finalize dialog */
    this.finish(DialogBase.DEFAULT_WIDTH + 20,
        DialogBase.DEFAULT_HEIGHT + 120);
    }

  /**
   * Reacts on button clicks.
   * 
   * @param p_event
   */

  public void actionPerformed(ActionEvent p_event)
    {
    String l_cmd = p_event.getActionCommand();
    if(l_cmd.equals("ok"))
      {
      if(this.m_checkBox.isSelected())
        {
        PrefUtils.putString("log_se_dir"this.m_chooserPanel.getFile());
        }
      Locale l_locale = null;
      switch(this.m_cbLanguage.getSelectedIndex())
        {
        // english
        case 0:
        l_locale = Locale.ENGLISH;
        break;
        // german
        case 1:
        l_locale = Locale.GERMAN;
        break;
        default:
        }
      PrefUtils.putString("lang", l_locale.toString());
      this.m_parent.getClient().setLocale(l_locale);
      this.dispose();
      return;
      }
    if(l_cmd.equals("cancel"))
      {
      this.dispose();
      return;
      }
    if(l_cmd.equals("log_check"))
      {
      this.m_chooserPanel.setEnabled(this.m_checkBox.isSelected());
      PrefUtils.putBoolean("log_se"this.m_checkBox.isSelected());
      return;
      }
    }
  }

File Information:

file name:SettingsDialog.java
package:org.dgpf.gui.dialogs
qualified name:org.dgpf.gui.dialogs.SettingsDialog.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gui/dialogs/SettingsDialog.java
size:7.105 KB (7276 B)
uploaded: 2015-07-22 04:10:58 GMT+0000
last update: 2006-09-24 23:47:04 GMT+0000
last access: 2017-11-18 06:30:26 GMT+0000

statistics online since 2006-01-02.   RSS Feed
Contact us by sending an email to tweise@gmx.de to receive further information, to report errors, or to join our project.
All content on this site (http://dgpf.sourceforge.net/) is LGPL-licensed.
http://dgpf.sourceforge.net/scripts/source/source.php last modified at 2015-07-22 04:10:53 GMT+0000 served at 2017-11-18 06:30:26 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo