Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gui.dialogs.DialogBase.java

Here you can find all the information about the file org.dgpf.gui.dialogs.DialogBase.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Mirko Dietrich
 * 
 * E-Mail           : mirkodietrich@hrz.uni-kassel.de
 * Creation Date    : Jul 23, 2006 10:42:54 AM
 * Original Filename: org.dgpf.gui.dialogs.DGPFDialog.java
 * Version          : 1.0
 * Last modification: Jul 23, 2006
 * Last modified by : Mirko Dietrich
 * 
 * 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.BorderLayout;
import java.awt.Container;
import java.awt.Dimension;
import java.awt.HeadlessException;
import java.awt.LayoutManager;
import java.awt.event.ActionListener;

import javax.swing.JDialog;
import javax.swing.JPanel;

import org.dgpf.gui.Frame;
import org.dgpf.gui.components.Button;
import org.dgpf.gui.components.TextArea;
import org.dgpf.gui.utils.LanguageSwitcher;

/**
 * An abstract dialog that serves as superclass for all DGPF dialogs.
 * 
 * @author Mirko Dietrich
 */

public abstract class DialogBase extends JDialog implements ActionListener
  {

  /**
   * The dialogs info text field width.
   */

  public final static int DEFAULT_WIDTH  = 400;

  /**
   * The dialogs info text field width.
   */

  public final static int DEFAULT_HEIGHT = 200;

  /**
   * Denotes a dialog frame with only an OK button.
   */

  public final static int OK_BTN         = 0;

  /**
   * Denotes a dialog frame with OK and cancel buttons.
   */

  public final static int OK_CANCEL_BTN  = 1;

  /**
   * Denotes a dialog frame with prev, next, finish and OK buttons.
   */

  public final static int WIZARD_BTNS    = 2;

  /**
   * The parent frame.
   */

  public Frame            m_parent;

  /**
   * The center layout.
   */

  public Container        m_center;

  /**
   * The ok button
   */

  public Button           m_btn_ok;

  /**
   * The cancel button
   */

  public Button           m_btn_cancel;

  /**
   * The prev button
   */

  public Button           m_btn_prev;

  /**
   * The next button
   */

  public Button           m_btn_next;

  /**
   * The finish button
   */

  public Button           m_btn_finish;

  /**
   * A little description at top of the dialog frame.
   */

  private TextArea        m_textArea;

  /**
   * Default constructor.
   * 
   * @param p_parent
   *          is the parent frame.
   * @param p_caption
   *          Dialog window caption.
   * @param p_info_text
   *          Text that appears at top of the dialog window.
   * @param p_buttons
   *          Denotes which buttons should be displayed.
   * @param p_modal
   *          Whether user interaction with other frames of the application
   *          should be blocked while the dialog is open.
   * @param p_lm
   *          The <code>LayoutManager</code> to use.
   * @throws HeadlessException
   *           Thrown when code that is dependent on a keyboard, display,
   *           or mouse is called in an environment that does not support a
   *           keyboard, display, or mouse.
   */

  public DialogBase(Frame p_parent, String p_caption, String p_info_text,
      int p_buttons, boolean p_modal, LayoutManager p_lm)
      throws HeadlessException
    {
    super(p_parent, p_caption, p_modal);
    this.m_parent = p_parent;
    /* Info text pane */
    this.m_textArea = new TextArea(true, false, true, true);
    this.m_textArea.setColumns(36);
    this.m_textArea.append(p_info_text);
    this.getContentPane().add(this.m_textArea, BorderLayout.NORTH);

    /* Buttons */
    JPanel l_btn_panel = new JPanel();

    /* Cancel button */
    if(p_buttons == DialogBase.OK_CANCEL_BTN)
      {
      this.m_btn_cancel = new Button(LanguageSwitcher
          .getString("btn_cancel"), "cancel"this, true);
      l_btn_panel.add(this.m_btn_cancel);
      this.m_btn_ok = new Button(LanguageSwitcher.getString("btn_ok"),
          "ok"this, true);
      l_btn_panel.add(this.m_btn_ok);
      }

    /* Wizard buttons */
    if(p_buttons == DialogBase.WIZARD_BTNS)
      {
      this.m_btn_prev = new Button(LanguageSwitcher.getString("btn_prev"),
          "prev"this, true);
      l_btn_panel.add(this.m_btn_prev);
      this.m_btn_next = new Button(LanguageSwitcher.getString("btn_next"),
          "next"this, true);
      l_btn_panel.add(this.m_btn_next);
      this.m_btn_finish = new Button(LanguageSwitcher
          .getString("btn_finish"), "finish"this, true);
      l_btn_panel.add(this.m_btn_finish);
      this.m_btn_cancel = new Button(LanguageSwitcher
          .getString("btn_cancel"), "cancel"this, true);
      l_btn_panel.add(this.m_btn_cancel);
      }

    /* OK button */
    if(p_buttons == DialogBase.OK_BTN)
      {
      this.m_btn_ok = new Button(LanguageSwitcher.getString("btn_ok"),
          "ok"this, true);
      l_btn_panel.add(this.m_btn_ok);

      }
    this.getContentPane().add(l_btn_panel, BorderLayout.SOUTH);
    /* Create container for center */
    this.m_center = new Container();
    this.m_center.setLayout(p_lm);
    getRootPane().setDefaultButton(this.m_btn_ok);
    }

  /**
   * Getter for center.
   * 
   * @return Returns the center container.
   */

  public final Container getCenter()
    {
    return this.m_center;
    }

  /**
   * Getter for the text area.
   * 
   * @return The text area of the dialog.
   */

  public TextArea getTextArea()
    {
    return this.m_textArea;
    }

  /**
   * Finalize dialog with default dimension.
   */

  public void finish()
    {
    finish(DialogBase.DEFAULT_WIDTH, DialogBase.DEFAULT_HEIGHT);
    }

  /**
   * Finalize dialog.
   * 
   * @param p_width
   *          of the frame.
   * @param p_height
   *          of the frame.
   */

  public void finish(int p_width, int p_height)
    {
    this.getContentPane().add(this.m_center, BorderLayout.CENTER);
    this.setPreferredSize(new Dimension(p_width, p_height));
    this.pack();
    this.setLocationRelativeTo(this.m_parent);
    this.setVisible(true);

    }

  }

File Information:

file name:DialogBase.java
package:org.dgpf.gui.dialogs
qualified name:org.dgpf.gui.dialogs.DialogBase.java
file type:Java Source File
download location:download http://dgpf.sourceforge.net/source/org/dgpf/gui/dialogs/DialogBase.java
size:6.466 KB (6622 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:09:25 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:09:25 GMT+0000.
Valid CSS Valid XHTML 1.1
Valid RSS SourceForge.net Logo