Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gui.dialogs.HostlistEditor.java

Here you can find all the information about the file org.dgpf.gui.dialogs.HostlistEditor.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 1:20:48 PM
 * Original Filename: org.dgpf.gui.dialogs.DGPFHostlistEditor.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.Dimension;
import java.awt.HeadlessException;
import java.awt.event.ActionEvent;
import java.io.File;
import java.io.FileNotFoundException;

import javax.swing.ImageIcon;
import javax.swing.JButton;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
import javax.swing.JTable;

import org.dgpf.gui.Client;
import org.dgpf.gui.Frame;
import org.dgpf.gui.components.Button;
import org.dgpf.gui.components.DGPFFileFilter;
import org.dgpf.gui.components.FileChooser;
import org.dgpf.gui.utils.Host;
import org.dgpf.gui.utils.LanguageSwitcher;
import org.dgpf.gui.utils.PrefUtils;
import org.dgpf.search.control.protocol.NetworkCommunicationPeer;

/**
 * @author Mirko Dietrich
 */

public class HostlistEditor extends DialogBase
  {

  /**
   * serialVersionUID.
   */

  private static final long serialVersionUID    = -5087945333967766822L;

  /**
   * The DGPF client.
   */

  private Client            m_client;

  /**
   * The table displaying the host list.
   */

  private JTable            m_table;

  /**
   * The current host list filename.
   */

  private String            m_hostlist_filename = null;

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

  public void actionPerformed(ActionEvent p_event)
    {
    String l_cmd = p_event.getActionCommand();
    /* OK button */
    if(l_cmd.equals("ok"))
      {
      if(this.m_hostlist_filename != null)
        {
        this.m_client.setHostlist(this.m_hostlist_filename,
            ((HostlistTableModel) this.m_table.getModel()).getHostlist());
        }
      this.m_parent.updateHostlistText();
      this.dispose();
      return;
      }
    /* Create a new host with default values */
    if(l_cmd.equals("new_host"))
      {
      ((HostlistTableModel) this.m_table.getModel()).add(new Host("",
          NetworkCommunicationPeer.DEFAULT_PORT, ""));
      return;
      }
    /* Delete all selected hosts from the table */
    if(l_cmd.equals("delete_host"))
      {
      ((HostlistTableModel) this.m_table.getModel()).remove(this.m_table
          .getSelectedRows());
      return;
      }
    /* Open a hostlist from file */
    if(l_cmd.equals("open_list"))
      {
      if(((HostlistTableModel) this.m_table.getModel()).getRowCount() > 0)
        {
        /* Ask if the list is not empty */
        if(JOptionPane.showConfirmDialog(this, LanguageSwitcher
            .getString("msgb_confirm_list_delete"), LanguageSwitcher
            .getString("msgb_confirm_list_delete_title"),
            JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION)
          {
          return;
          }
        }
      /* Open list */
      FileChooser l_fileChooser = new FileChooser();
      String suggestedFile = PrefUtils.getString(LanguageSwitcher
          .getString("history.last_opend_host_list"), LanguageSwitcher
          .getString("hle_fc_default_file"));
      File l_file = l_fileChooser.getFile(LanguageSwitcher
          .getString("hle_fc_panel_caption"), new DGPFFileFilter(
          LanguageSwitcher.getString("hle_fc_filefilter"), "xml"),
          suggestedFile, LanguageSwitcher.getString("btn_open"));
      if(null != l_file)
        {
        try
          {
          ((HostlistTableModel) this.m_table.getModel()).loadList(l_file);
          this.m_hostlist_filename = l_file.getCanonicalPath();
          PrefUtils.putString(LanguageSwitcher
              .getString("history.last_opend_host_list"), l_file
              .getAbsolutePath());
          }
        catch(FileNotFoundException fnfe)
          {
          JOptionPane.showMessageDialog(this, LanguageSwitcher
              .getString("msgb_file_not_found_error"), LanguageSwitcher
              .getString("msgb_name_error"), JOptionPane.ERROR_MESSAGE);
          }
        catch(Exception e)
          {
          JOptionPane.showMessageDialog(this, LanguageSwitcher
              .getString("msgb_hle_file_error"), LanguageSwitcher
              .getString("msgb_name_error"), JOptionPane.ERROR_MESSAGE);
          }
        }
      return;
      }
    /* Save the hostlist to file */
    if(l_cmd.equals("save_list"))
      {
      if(((HostlistTableModel) this.m_table.getModel()).getRowCount() > 0)
        {
        /* Choose file */
        FileChooser l_fileChooser = new FileChooser();
        File l_file = l_fileChooser.getFile(LanguageSwitcher
            .getString("hle_fc_panel_caption"), new DGPFFileFilter(
            LanguageSwitcher.getString("hle_fc_filefilter"), "xml"),
            LanguageSwitcher.getString("hle_fc_default_file"),
            LanguageSwitcher.getString("btn_save"));
        if(null != l_file)
          {
          if(l_file.exists())
            {
            /* Should the file be overwritten if it already exists? */
            if(JOptionPane.showConfirmDialog(this, LanguageSwitcher
                .getString("msgb_confirm_overwrite"), LanguageSwitcher
                .getString("msgb_confirm_overwrite_title"),
                JOptionPane.YES_NO_OPTION, JOptionPane.WARNING_MESSAGE) != JOptionPane.OK_OPTION)
              {
              return;
              }
            }
          /* Save file */
          try
            {
            ((HostlistTableModel) this.m_table.getModel())
                .saveList(l_file);
            this.m_hostlist_filename = l_file.getCanonicalPath();
            }
          catch(Exception e)
            {
            JOptionPane.showMessageDialog(this, LanguageSwitcher
                .getString("msgb_hle_could_not_save"), LanguageSwitcher
                .getString("msgb_name_error"), JOptionPane.ERROR_MESSAGE);
            e.printStackTrace();
            }
          }
        }
      return;
      }
    /* Clear host list */
    if(l_cmd.equals("clear_list"))
      {
      ((HostlistTableModel) this.m_table.getModel()).clear();
      this.m_hostlist_filename = "";
      return;
      }
    }

  /**
   * Default constructor.
   * 
   * @param p_client
   *          is the DGPF Client.
   * @param p_parent
   *          is the parent frame.
   * @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 HostlistEditor(Client p_client, Frame p_parent)
      throws HeadlessException
    {
    super(p_parent, LanguageSwitcher.getString("hle_caption"),
        LanguageSwitcher.getString("hle_info"), DialogBase.OK_BTN, true,
        new BorderLayout());
    this.m_client = p_client;
    /* Hostlist */
    this.m_table = new JTable(new HostlistTableModel(this.m_client
        .getHostlist()));
    this.m_table.getColumnModel().getColumn(0).setPreferredWidth(100);
    this.m_table.getColumnModel().getColumn(1).setPreferredWidth(10);
    this.m_table.getColumnModel().getColumn(2).setPreferredWidth(200);
    this.m_table
        .setPreferredScrollableViewportSize(new Dimension(300, 200));
    JScrollPane l_sp = new JScrollPane(this.m_table);
    this.getCenter().add(l_sp, BorderLayout.CENTER);
    /* Hostlist buttons */
    JPanel l_listitems_btns = new JPanel();
    JButton l_btn_new_host = new Button(LanguageSwitcher
        .getString("hle_btn_new"), "new_host"this, true);
    try
      {
      l_btn_new_host
          .setIcon(new ImageIcon(
              ClassLoader
                  .getSystemResource("org/dgpf/gui/resources/bitmaps/new_host.png")));
      }
    catch(Exception e)
      {
      System.err.println("Could not load icon!");
      }
    l_listitems_btns.add(l_btn_new_host);

    JButton l_btn_delete_host = new Button(LanguageSwitcher
        .getString("hle_btn_delete"), "delete_host"this, true);
    try
      {
      l_btn_delete_host
          .setIcon(new ImageIcon(
              ClassLoader
                  .getSystemResource("org/dgpf/gui/resources/bitmaps/delete_host.png")));
      }
    catch(Exception e)
      {
      System.err.println("Could not load icon!");
      }
    l_listitems_btns.add(l_btn_delete_host);

    JButton l_btn_open = new Button(LanguageSwitcher
        .getString("hle_btn_open"), "open_list"this, true);
    try
      {
      l_btn_open.setIcon(new ImageIcon(ClassLoader
          .getSystemResource("org/dgpf/gui/resources/bitmaps/open.png")));
      }
    catch(Exception e)
      {
      System.err.println("Could not load icon!");
      }
    l_listitems_btns.add(l_btn_open);

    JButton l_btn_save = new Button(LanguageSwitcher
        .getString("hle_btn_save"), "save_list"this, true);
    try
      {
      l_btn_save.setIcon(new ImageIcon(ClassLoader
          .getSystemResource("org/dgpf/gui/resources/bitmaps/save.png")));
      }
    catch(Exception e)
      {
      System.err.println("Could not load icon!");
      }
    l_listitems_btns.add(l_btn_save);

    JButton l_btn_clear = new Button(LanguageSwitcher
        .getString("hle_btn_clear"), "clear_list"this, true);
    try
      {
      l_btn_clear.setIcon(new ImageIcon(ClassLoader
          .getSystemResource("org/dgpf/gui/resources/bitmaps/clear.png")));
      }
    catch(Exception e)
      {
      System.err.println("Could not load icon!");
      }
    l_listitems_btns.add(l_btn_clear);

    this.getCenter().add(l_listitems_btns, BorderLayout.SOUTH);
    /* Finalize */
    finish(660, 350);
    }
  }

File Information:

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