Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gui.components.FileChooserPanel.java

Here you can find all the information about the file org.dgpf.gui.components.FileChooserPanel.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    : 22.06.2006 19:22:11
 * Original Filename: org.dgpf.gui.components.DGPFFileChooserPanel.java
 * Version          : 1.0
 * Last modification: 22.06.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.components;

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 java.io.File;

import javax.swing.JPanel;
import javax.swing.JTextField;
import javax.swing.border.TitledBorder;

import org.dgpf.gui.utils.LanguageSwitcher;
import org.dgpf.gui.utils.Layout;

/**
 * This class represents a file chooser panel with a caption, a path filed
 * and a browse button, which starts the file chooser.
 * 
 * @author Alexander Podlich.
 */

public class FileChooserPanel extends JPanel implements ActionListener
  {

  /**
   * The serial version UID.
   */

  private static final long serialVersionUID = 1L;

  /**
   * The file.
   */

  protected String          m_panelFile;

  /**
   * The file chooser caption.
   */

  protected String          m_fileChooserCaption;

  /**
   * The file cooser file filter.
   */

  protected String          m_fileChooserFileFilter;

  /**
   * The file chooser file extension.
   */

  protected String          m_fileChooserFileExtension;

  /**
   * The file chooser file name.
   */

  protected String          m_fileChooserFileName;

  /**
   * The file chooser button caption.
   */

  protected String          m_fileChooserButtonCaption;

  /**
   * The path filed for editing the path.
   */

  protected JTextField      m_pathField;

  /**
   * The browse button.
   */

  protected Button          m_browseButton;
  
  /**
   * The titled border.
   */

  protected DGPFTitledBorder m_titledBorder;

  /**
   * Default constructor.
   */

  public FileChooserPanel()
    {
    super();
    }

  /**
   * Constructor.
   * 
   * @param p_caption
   *          The caption of the panel.
   * @param p_file
   *          The file.
   * @param p_fcCaption
   *          The file chooser caption.
   * @param p_fcFileFilter
   *          The file filter caption in the file chooser.
   * @param p_fcFileExtension
   *          The file extension for the file chooser.
   * @param p_fcFileName
   *          The file chooser file name.
   * @param p_fcButtonCaption
   *          The file chooser button caption.
   */

  public FileChooserPanel(String p_caption, String p_file,
      String p_fcCaption, String p_fcFileFilter, String p_fcFileExtension,
      String p_fcFileName, String p_fcButtonCaption)
    {
    super(new GridBagLayout());
    this.m_fileChooserCaption = p_fcCaption;
    this.m_fileChooserFileFilter = p_fcFileFilter;
    this.m_fileChooserFileExtension = p_fcFileExtension;
    this.m_fileChooserButtonCaption = p_fcButtonCaption;
    this.m_fileChooserFileName = p_file;
    this.m_pathField = new JTextField(p_file);
    this.m_titledBorder = new DGPFTitledBorder(p_caption, TitledBorder.LEFT);

    /* Layout Settings */

    this.setBorder(this.m_titledBorder);
    this.m_browseButton = new Button(LanguageSwitcher
        .getString("btn_browse"), "browse"this, true);

    Layout.set_constraints(thisthis.m_pathField, 1.0, 1.0,
        GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER,
        GridBagConstraints.REMAINDER, new Insets(3, 3, 3, 3));

    Layout.set_constraints(thisthis.m_browseButton, 1.0, 1.0,
        GridBagConstraints.NONE, GridBagConstraints.CENTER,
        GridBagConstraints.REMAINDER, new Insets(3, 3, 3, 3));

    }
  
  /**
   * Enables the components in the chooser panel.
   * 
   * @param p_enable The status of enabling.
   */

  @Override
  public void setEnabled(boolean p_enable)
    {
      this.m_browseButton.setEnabled(p_enable);
      this.m_pathField.setEnabled(p_enable);
      if (p_enable)
        {
        this.m_titledBorder.setTitleColor(Color.BLACK);
        }
      else
        {
        this.m_titledBorder.setTitleColor(Color.LIGHT_GRAY);
        }
      this.repaint();
    }

  /**
   * Reacts on button clicks.
   * 
   * @param p_e
   *          An action event.
   */

  public void actionPerformed(ActionEvent p_e)
    {
    String l_cmd = p_e.getActionCommand();
    if(l_cmd.equals("browse"))
      {
      callFileChooser();
      }
    }

  /**
   * This method calls the file chooser, for selecting a path and the file.
   */

  private void callFileChooser()
    {
    FileChooser l_fileChooser = new FileChooser();
    File l_file = l_fileChooser.getFile(this.m_fileChooserCaption,
        new DGPFFileFilter(this.m_fileChooserFileFilter,
            this.m_fileChooserFileExtension), this.m_fileChooserFileName,
        this.m_fileChooserButtonCaption);
    if(null != l_file)
      {
      this.m_panelFile = l_file.toString();
      }
    this.m_pathField.setText(this.m_panelFile);
    }

  /**
   * This method returns the actual file, which was chosen from the file
   * chooser.
   * 
   * @return The panel file.
   */

  public String getFile()
    {
    return this.m_pathField.getText();
    }

  /**
   * This method sets the actual file, which.
   * 
   * @param p_f
   *          The file.
   */

  public void setFile(String p_f)
    {
    this.m_panelFile = p_f;
    this.m_pathField.setText(p_f);
    }

  /**
   * This method activate or disactivate all GUI objects in the file choser
   * panel.
   * 
   * @param p_activate
   *          Status of gui elements activation.
   */

  public void setActive(boolean p_activate)
    {
    this.m_browseButton.setEnabled(p_activate);
    this.m_pathField.setEditable(p_activate);
    }
  }

File Information:

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