Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gui.controls.PropertyControl.java

Here you can find all the information about the file org.dgpf.gui.controls.PropertyControl.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    : 04.07.2006 15:32:22
 * Original Filename: org.dgpf.gui.controls.DGPFPropertyControl.java
 * Version          : 1.0
 * Last modification: 04.07.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.controls;

import java.awt.Color;
import java.awt.GridBagConstraints;
import java.awt.GridBagLayout;
import java.awt.Insets;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.ButtonGroup;
import javax.swing.JComponent;
import javax.swing.JPanel;

import org.dgpf.gui.InternalFrame;
import org.dgpf.gui.components.Button;
import org.dgpf.gui.components.RadioButton;
import org.dgpf.gui.components.TextArea;
import org.dgpf.gui.components.TextField;
import org.dgpf.gui.utils.LanguageSwitcher;
import org.dgpf.gui.utils.Layout;
import org.dgpf.search.api.SearchState;
import org.sfc.meta.Property;
import org.sfc.meta.PropertyPort;

/**
 * This class creates a control for a property.
 * 
 * @author Alexander Podlich
 */

public class PropertyControl implements IControl, ActionListener
  {

  /**
   * The serial version UID.
   */

  private static final long serialVersionUID = 1L;

  /**
   * The label for double values, which cannot be set.
   */

  private TextArea          m_textArea;

  /**
   * A text field for edit the value.
   */

  private TextField         m_textField;

  /**
   * The panel for a boolean property.
   */

  private JPanel            m_booleanPanel;

  /**
   * The first check box.
   */

  private RadioButton       m_enableRadioButton;

  /**
   * The second check box.
   */

  private RadioButton       m_disableRadioButton;

  /**
   * Button for submit.
   */

  private Button            m_button;

  /**
   * The property.
   */

  private final Property<?> m_property;

  /**
   * The type of the property.
   */

  private final Class       m_type;

  /**
   * Has wether the value of this property can be written by at least one
   * property port or not. <code>true</code> if this property can be
   * written by at least one property port, <code>false</code> if it is
   * read-only.
   */

  private boolean           m_canSet;

  /**
   * Has wether the value of this property can be read by at least one
   * property port or not. <code>true</code> if this property can be read
   * by at least one property port, <code>false</code> if it cannot be
   * read.
   */

  private boolean           m_canGet;

  /**
   * <code>True</code>, if this property can be updated.
   * <code>False</code>, if this property cannot be updated.
   */

  private boolean           m_updateAble;

  /**
   * The parent <code>DGPFInternalFrame</code>.
   */

  private InternalFrame     m_parent;

  /**
   * The constructor.
   * 
   * @param p_parent
   *          is the parent frame.
   * @param p_pPort
   *          The property port
   */

  public PropertyControl(InternalFrame p_parent, PropertyPort p_pPort)
    {
    this.m_parent = p_parent;
    this.m_canSet = p_pPort.get_property().can_set();
    this.m_canGet = p_pPort.get_property().can_get();
    this.m_type = p_pPort.get_property().get_type();
    this.m_property = p_pPort.get_property();
    setUpdateAble(true);

    if(this.m_canSet && this.m_canGet)
      {

      // The property is a boolean property
      if(this.m_type.equals(boolean.class))
        {
        this.m_booleanPanel = new JPanel(new GridBagLayout());

        this.m_enableRadioButton = new RadioButton(LanguageSwitcher
            .getString("cbx_enable"), "enable"this, true);
        Layout.set_constraints(this.m_booleanPanel,
            this.m_enableRadioButton, 1.0, 1.0, GridBagConstraints.NONE,
            GridBagConstraints.CENTER, GridBagConstraints.RELATIVE,
            new Insets(3, 3, 3, 3));

        this.m_disableRadioButton = new RadioButton(LanguageSwitcher
            .getString("cbx_disable"), "disable"this, true);
        Layout.set_constraints(this.m_booleanPanel,
            this.m_disableRadioButton, 1.0, 1.0, GridBagConstraints.NONE,
            GridBagConstraints.CENTER, GridBagConstraints.REMAINDER,
            new Insets(3, 3, 3, 3));

        ButtonGroup l_buttonGroup = new ButtonGroup();
        l_buttonGroup.add(this.m_enableRadioButton);
        l_buttonGroup.add(this.m_disableRadioButton);

        this.m_button = new Button(LanguageSwitcher
            .getString("btn_change"), "button"this, true);
        Layout.set_constraints(this.m_booleanPanel, this.m_button, 1.0,
            1.0, GridBagConstraints.NONE, GridBagConstraints.CENTER,
            GridBagConstraints.REMAINDER, new Insets(3, 3, 3, 3));
        }
      else
        {
        this.m_textField = new TextField();
        }
      }
    else
      if(this.m_canGet)
        {
        this.m_textArea = new TextArea(true, false, new Color(238, 238,
            238));
        }
    }

  /**
   * This method makes an update of the gui element.
   * 
   * @param p_pPort
   *          The property port.
   * @param p_searchState
   *          The search state.
   * @param p_index
   *          The array index if this property is an array property, or
   *          <code>-1<code> if the property is no array property.
   */

  public void update(PropertyPort p_pPort,
      final SearchState<?> p_searchState, int p_index)
    {
    if(this.m_updateAble)
      {
      Object l_object = ((p_index >= 0) ? p_pPort.get(p_searchState,
          p_index) : p_pPort.get(p_searchState));
      if(this.m_canSet && this.m_canGet)
        {
        if(this.m_type.equals(boolean.class))
          {
          boolean l_value = (new Boolean(l_object.toString()))
              .booleanValue();
          this.m_enableRadioButton.setSelected(l_value);
          this.m_disableRadioButton.setSelected(!l_value);
          }
        else
          {
          this.m_textField.setText((l_object != null) ? l_object
              .toString() : "null");
          }
        }
      else
        if(this.m_canGet)
          {
          this.m_textArea.setText((l_object != null) ? l_object.toString()
              : "null");
          }
      }
    }

  /**
   * This method returns the internal JComponent.
   * 
   * @return The JComponent.
   */

  public JComponent get()
    {
    if(this.m_canSet && this.m_canGet)
      {
      if(this.m_type.equals(boolean.class))
        {
        return this.m_booleanPanel;
        }
      return this.m_textField;
      }
    else
      if(this.m_canGet)
        {
        return this.m_textArea;
        }
    return null;
    }

  /**
   * <code>True</code>, if this property can be updated.
   * <code>False</code>, if this property cannot be updated.
   * 
   * @param p_updateAble
   *          The boolean value for this control.
   */

  public void setUpdateAble(boolean p_updateAble)
    {
    this.m_updateAble = p_updateAble;
    }

  /**
   * @param p_event
   *          Action event.
   */

  public void actionPerformed(ActionEvent p_event)
    {
    String cmd = p_event.getActionCommand();
    if(cmd.equals("button"))
      {
      this.m_parent.setProperty(this.m_property, new Boolean(
          this.m_enableRadioButton.isSelected()));
      }
    else
      if(cmd.equals("enable") || cmd.equals("disable"))
        {
        setUpdateAble(false);
        }
    }
  }

File Information:

file name:PropertyControl.java
package:org.dgpf.gui.controls
qualified name:org.dgpf.gui.controls.PropertyControl.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gui/controls/PropertyControl.java
size:7.998 KB (8190 B)
uploaded: 2015-07-22 04:10:58 GMT+0000
last update: 2006-09-24 23:47:04 GMT+0000
last access: 2017-11-19 03:10:16 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-19 03:10:16 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo