Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gui.InternalFrame.java

Here you can find all the information about the file org.dgpf.gui.InternalFrame.java. You may explore it here or download it onto your local disk.
/*
 * Copyright (c) 2006 Universitaet Kassel
 *
 * E-Mail           : mirko.dietrich@hrz.uni-kassel.de
 * Original Filename: org.dgpf.gui.DGPFInternalFrame.java
 *
 * 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;

import java.awt.BorderLayout;
import java.awt.Dimension;
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 java.io.FileNotFoundException;
import java.io.FileWriter;
import java.io.IOException;
import java.net.Socket;
import java.sql.Timestamp;
import java.util.Collections;
import java.util.HashMap;
import java.util.Vector;

import javax.swing.ImageIcon;
import javax.swing.JCheckBoxMenuItem;
import javax.swing.JComponent;
import javax.swing.JInternalFrame;
import javax.swing.JMenu;
import javax.swing.JMenuBar;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JTextPane;
import javax.swing.JToolBar;
import javax.swing.event.InternalFrameEvent;
import javax.swing.event.InternalFrameListener;

import org.dgpf.gui.charts.IChart;
import org.dgpf.gui.charts.descriptors.DefaultPortDescriptor;
import org.dgpf.gui.charts.descriptors.PortDescriptorBase;
import org.dgpf.gui.charts.descriptors.StatAveragePortDescriptor;
import org.dgpf.gui.charts.descriptors.StatCountPortDescriptor;
import org.dgpf.gui.charts.descriptors.StatMaxPortDescriptor;
import org.dgpf.gui.charts.descriptors.StatMedianPortDescriptor;
import org.dgpf.gui.charts.descriptors.StatMinPortDescriptor;
import org.dgpf.gui.charts.descriptors.StatStddevPortDescriptor;
import org.dgpf.gui.charts.descriptors.StatSumPortDescriptor;
import org.dgpf.gui.charts.descriptors.StatSumSqrPortDescriptor;
import org.dgpf.gui.charts.descriptors.StatVariancePortDescriptor;
import org.dgpf.gui.components.BorderedPanel;
import org.dgpf.gui.components.Button;
import org.dgpf.gui.controls.ControlMap;
import org.dgpf.gui.dialogs.StartJarDialog;
import org.dgpf.gui.tabs.ChartTab;
import org.dgpf.gui.tabs.ITab;
import org.dgpf.gui.tabs.LogTab;
import org.dgpf.gui.tabs.PropertyTab;
import org.dgpf.gui.utils.Host;
import org.dgpf.gui.utils.LanguageSwitcher;
import org.dgpf.gui.utils.Layout;
import org.dgpf.gui.utils.PrefUtils;
import org.dgpf.gui.wizards.chartchooser.CCWzrd;
import org.dgpf.search.api.SearchState;
import org.dgpf.search.api.events.CSVSearchListener;
import org.dgpf.search.api.events.DefaultSearchListener;
import org.dgpf.search.api.events.SearchUpdateEvent;
import org.dgpf.search.control.protocol.AbortSeEvent;
import org.dgpf.search.control.protocol.ICommunicationPeer;
import org.dgpf.search.control.protocol.JarFileEvent;
import org.dgpf.search.control.protocol.NetworkCommunicationPeer;
import org.dgpf.search.control.protocol.PropertyUpdateEvent;
import org.dgpf.search.control.protocol.RunningStatusEvent;
import org.sfc.events.IEventListener;
import org.sfc.events.SfcEvent;
import org.sfc.gui.text.DocumentWriter;
import org.sfc.io.MultiplexingWriter;
import org.sfc.math.stochastic.statistics.StatisticInfo;
import org.sfc.meta.BoundedDoubleProperty;
import org.sfc.meta.BoundedIntProperty;
import org.sfc.meta.BoundedLongProperty;
import org.sfc.meta.MetaInformation;
import org.sfc.meta.Property;
import org.sfc.meta.PropertyPort;
import org.sfc.meta.PropertySet;
import org.sfc.meta.PropertySubSet;
import org.sfc.text.Text;
import org.sfc.utils.Typesafe;

/**
 * This class represents a Client withis the desktop pane.
 * 
 * @author Mirko Dietrich
 */

public class InternalFrame extends JInternalFrame implements
    ActionListener, IEventListener, InternalFrameListener
  {

  /**
   * serialVersionUID
   */

  static final long                    serialVersionUID = 1L;

  /**
   * Default width.
   */

  private static final int             DEFAULT_WIDTH    = 300;

  /**
   * Default height.
   */

  private static final int             DEFAULT_HEIGHT   = 400;

  /**
   * HashMap for drawable properties.
   */

  private Vector<PortDescriptorBase>   m_pdVector;

  /**
   * A toolbar for the internal window.
   */

  private JToolBar                 m_toolBar;

  /**
   * A tabbed pane.
   */

  private TabbedPane                   m_tabbedPane;

  /**
   * The csv search listener for human output.
   */

  private CSVSearchListener            m_csvListener;

  /**
   * The default search listener for human output.
   */

  private DefaultSearchListener        m_dListener;

  /**
   * Multiplexing writer for default output.
   */

  private MultiplexingWriter           m_dMPW;

  /**
   * Multiplexing writer for csv output.
   */

  private MultiplexingWriter           m_csvMPW;

  /**
   * The map for choosing the right control for a property.
   */

  private ControlMap                   m_controlMap;

  /**
   * Init variable which is true, if the textfields and pannels are
   * initialised, else false.
   */

  private boolean                      m_initial;

  /**
   * This HashMap contains the properties and their pannels.
   */

  private HashMap<String, PropertyTab> m_propertySubSetMap;

  /**
   * This HashMap contains the properties and their pannels.
   */

  private HashMap<String, LogTab>      m_logMap;

  /**
   * File for the default logging.
   */

  private String                       m_logDir;

  /**
   * The parent frame.
   */

  private Frame                        m_parent;

  /**
   * Represents the connection to the <code>Daemon</code>.
   */

  private ICommunicationPeer           m_cp;

  /**
   * The button, which opens the <code>DGPFChartChooserFrame</code>.
   */

  private Button                       m_daButton;

  /**
   * Starts a SE.
   */

  private Button                       m_startButton;

  /**
   * Stops the SE.
   */

  private Button                       m_abortButton;

  /**
   * Contains the line charts and their display properties.
   */

  private Vector<IChart>               m_chartVector;

  /**
   * The associated with this InternalFrame.
   */

  private Host                         m_host;

  /**
   * Holds info of the associated Internalframe.
   */

  private SEInfoHolder                 m_seInfo;

  /**
   * The chart menu.
   */

  private JMenu                        m_chartMenu;

  /**
   * The chart sub menu.
   */

  private JMenu                        m_chartSubMenu;

  /**
   * The property menu.
   */

  private JMenu                        m_propertyMenu;

  /**
   * The log menu.
   */

  private JMenu                        m_logMenu;

  /**
   * Contains all sub menu items of the chart, property and log menu.
   */

  private HashMap<String, JMenuItem>   m_menuItems;

  /**
   * Creates a new <code>DGPFInternalFrame</code>.
   * 
   * @param p_frame
   *          The parent frame.
   * @param p_name
   *          A Frame name.
   * @param p_x
   *          X coordinate.
   * @param p_y
   *          Y coordinate.
   * @param p_d
   *          dimension to define a size of an internal frame.
   * @param p_logDir
   *          File for the default logging.
   * @param p_socket
   *          The socket.
   * @param p_host
   *          The host.
   */

  public InternalFrame(Frame p_frame, String p_name, int p_x, int p_y,
      Dimension p_d, String p_logDir, Socket p_socket, Host p_host)
    {

    super(p_name, // name.
        true, // resizable.
        true, // closable.
        true, // maximizable.
        true); // iconifable.
    this.m_seInfo = new SEInfoHolder();
    this.m_parent = p_frame;
    this.setLocation(p_x, p_y);
    this.setSize(p_d);
    this.setVisible(true);
    addInternalFrameListener(this);

    this.m_controlMap = new ControlMap();
    this.m_toolBar = new JToolBar();
    this.m_tabbedPane = new TabbedPane();

    this.m_logDir = p_logDir;

    this.m_initial = true;
    this.m_dMPW = new MultiplexingWriter();
    this.m_dListener = new DefaultSearchListener(this.m_dMPW);
    this.m_csvMPW = new MultiplexingWriter();
    this.m_csvListener = new CSVSearchListener(this.m_csvMPW);
    this.m_host = p_host;
    this.m_pdVector = new Vector<PortDescriptorBase>();
    this.m_chartVector = new Vector<IChart>();
    this.m_menuItems = new HashMap<String, JMenuItem>();
    this.m_propertySubSetMap = new HashMap<String, PropertyTab>();
    this.m_logMap = new HashMap<String, LogTab>();

    this.getContentPane().setLayout(new BorderLayout());

    /* handle events */
    this.addInternalFrameListener(this);

    /* create menu bar */

    JMenuBar l_menuBar = new JMenuBar();
    this.m_propertyMenu = createPropertyMenu();
    this.m_chartMenu = createChartMenu();
    l_menuBar.add(this.m_chartMenu);
    l_menuBar.add(this.m_propertyMenu);
    this.m_propertyMenu.setEnabled(false);
    this.m_chartMenu.setEnabled(false);
    if(this.m_logDir != null)
      {
      this.m_logMenu = createLogMenu();
      l_menuBar.add(this.m_logMenu);
      this.m_logMenu.setEnabled(false);
      }

    setJMenuBar(l_menuBar);

    /* create toolbar */

    // chart button.
    this.m_daButton = new Button(LanguageSwitcher.getString("btn_chart"),
        "btn_chart"this, true);
    this.m_daButton.setIcon(new ImageIcon(ClassLoader
        .getSystemResource("org/dgpf/gui/resources/bitmaps/chart.png")));
    this.m_daButton.setEnabled(false);
    this.m_toolBar.add(this.m_daButton);

    // start se button.
    this.m_startButton = new Button(LanguageSwitcher
        .getString("btn_start_se"), "btn_start_se"this, true);
    this.m_startButton.setIcon(new ImageIcon(ClassLoader
        .getSystemResource("org/dgpf/gui/resources/bitmaps/start.png")));
    this.m_startButton.setEnabled(true);
    this.m_toolBar.add(this.m_startButton);

    // abort se button.
    this.m_abortButton = new Button(LanguageSwitcher
        .getString("btn_abort_se"), "btn_abort_se"this, true);
    this.m_abortButton.setIcon(new ImageIcon(ClassLoader
        .getSystemResource("org/dgpf/gui/resources/bitmaps/stop.png")));
    this.m_abortButton.setEnabled(false);
    this.m_toolBar.add(this.m_abortButton);

    this.m_toolBar.setFloatable(false);
    this.m_toolBar.setRollover(true);
    this.add(this.m_toolBar, BorderLayout.NORTH);

    this.add(this.m_tabbedPane, BorderLayout.CENTER);

    this.m_cp = new NetworkCommunicationPeer(null, this, p_socket,
        Client.NETWORK_BUFFER_SIZE);
    this.m_seInfo.setConnectedSince(new Timestamp(System
        .currentTimeMillis()));
    }

  /**
   * Handles an ActionEvent Instanz.
   * @param p_e
   *          ActionEvent to handle.
   */

  public void actionPerformed(ActionEvent p_e)
    {
    String l_cmd = p_e.getActionCommand();
    if(l_cmd.equals("btn_chart") || l_cmd.equals("create_chart"))
      {
      createChart();
      return;
      }
    if(l_cmd.equals("btn_start_se"))
      {
      new StartJarDialog(this.m_parent, new InternalFrame[] { this });
      return;
      }
    if(l_cmd.equals("btn_abort_se"))
      {
      try
        {
        this.m_cp.sendObject(new AbortSeEvent(this.m_parent.getClient()));
        }
      catch(Exception e)
        {
        e.printStackTrace();
        }
      return;
      }
    if(l_cmd.equals("close_all_charts"))
      {
      closeAllChartTabs();
      return;
      }

    if(l_cmd.equals("close_all_properties"))
      {
      closeAllTabs(PropertyTab.class);
      return;
      }

    if(l_cmd.equals("close_all_logs"))
      {
      closeAllTabs(LogTab.class);
      return;
      }

    if(l_cmd.equals("open_all_properties"))
      {
      openAllTabs(PropertyTab.class);
      return;
      }

    if(l_cmd.equals("open_all_logs"))
      {
      openAllTabs(LogTab.class);
      return;
      }

    if(l_cmd.contains("close_tab_"))
      {
      String l_tabName = l_cmd.substring("close_tab_".length(), l_cmd.length());
      closeTab(l_tabName);
      return;
      }

    if(l_cmd.contains("close_open_tab_"))
      {
      String l_tabName = l_cmd.substring("close_open_tab_".length(), l_cmd
          .length());
      closeOrOpenTab(l_tabName);
      return;
      }
    }

  /**
   * This method is called when the event sink receives an event.
   * 
   * @param p_event
   *          The event to be received.
   */

  public synchronized void receive(final SfcEvent p_event)
    {
    this.m_dListener.receive(p_event);
    this.m_csvListener.receive(p_event);

    SearchUpdateEvent<?> p_updateEvent;
    SearchState<?> p_searchState;

    if(p_event instanceof SearchUpdateEvent)
      {

      p_updateEvent = Typesafe.cast(p_event);
      p_searchState = p_updateEvent.get_state();

      if(this.m_initial)
        {
        this.buildTabs(p_searchState);
        this.m_initial = false;

        if(PrefUtils.getBoolean("start_cw_before_se_runs", false))
          {
          createChart();
          PrefUtils.putBoolean("start_cw_before_se_runs", false);
          }
        }

      this.updateProperties(p_searchState);
      for(IChart lc : this.m_chartVector)
        {
        lc.update(p_searchState);
        }
      }
    else
      if(p_event instanceof RunningStatusEvent)
        {
        if(((RunningStatusEvent) p_event).isRunning())
          {
          this.m_seInfo.setStatus(LanguageSwitcher
              .getString("infopanel.status_running"));
          this.m_abortButton.setEnabled(true);
          }
        else
          {
          this.m_seInfo.setStatus(LanguageSwitcher
              .getString("infopanel.status_not_running"));
          this.m_abortButton.setEnabled(false);
          }
        this.m_seInfo.setCurrent_jar_name(((RunningStatusEvent) p_event)
            .getCurrent_running_jar());
        }
    if(this.isSelected())
      {

      ((InfoPanel) this.m_parent.getInfoPanel()).getCurrentJarName()
          .setText(this.m_seInfo.getCurrent_jar_name());

      ((InfoPanel) this.m_parent.getInfoPanel()).getStatus().setText(
          this.m_seInfo.getStatus());
      }
    }

  /**
   * This method is called the first time, when a search update event is
   * received. Is used to build the tabs.
   * 
   * @param p_searchState
   *          The search state.
   */

  private final void buildTabs(final SearchState<?> p_searchState)
    {

    MetaInformation l_metaInformation;
    PropertySet l_propertySet;

    l_metaInformation = MetaInformation.get(p_searchState.getClass());
    l_propertySet = l_metaInformation.get_properties();

    for(PropertySubSet l_pSubSet : l_propertySet)
      {

      JPanel l_propertyPanel = new JPanel(new GridBagLayout());

      for(PropertyPort<?> l_pPort : l_pSubSet)
        {
        addElement(l_pPort, p_searchState, l_propertyPanel, LanguageSwitcher
            .getString(l_pSubSet.get_group().get_name() + "."
                + l_pPort.get_property().toString()));
        }

      String l_name = LanguageSwitcher.getString(l_pSubSet.get_group()
          .get_name());
      PropertyTab propertyTab = new PropertyTab(l_name, l_propertyPanel);

      this.m_propertySubSetMap.put(l_name, propertyTab);
      this.m_tabbedPane.addPropertySetTab(propertyTab);
      JCheckBoxMenuItem item = new JCheckBoxMenuItem(l_name);
      item.addActionListener(this);
      item.setActionCommand("close_open_tab_" + l_name);
      item.setState(true);
      this.m_propertyMenu.add(item);
      this.m_menuItems.put(l_name, item);
      }

    // logger
    if(null != this.m_logDir)
      {
      createLogTabs(LanguageSwitcher.getString("tc_default_log"),
          this.m_dMPW, new File(this.m_logDir + File.separator.toString()
              + "defaultLog_" + getHost().getHostname() + "_"
              + getHost().getPort()));
      createLogTabs(LanguageSwitcher.getString("tc_csv_log"),
          this.m_csvMPW, new File(this.m_logDir
              + File.separator.toString() + "scvLog_"
              + getHost().getHostname() + "_" + getHost().getPort()));
      this.m_logMenu.setEnabled(true);
      }

    this.m_daButton.setEnabled(true);
    this.m_propertyMenu.setEnabled(true);
    this.m_chartMenu.setEnabled(true);

    }

  /**
   * only called the first time a search update event is received, used to
   * build the tabs.
   * 
   * @param p_searchState
   *          the search state.
   */

  private final void updateProperties(final SearchState<?> p_searchState)
    {

    MetaInformation l_metaInformation;
    PropertySet l_propertySet;

    l_metaInformation = MetaInformation.get(p_searchState.getClass());

    l_propertySet = l_metaInformation.get_properties();

    for(PropertySubSet l_pss : l_propertySet)
      {

      for(PropertyPort<?> l_pPort : l_pss)
        {

        updateElement(l_pPort, p_searchState);
        // updateing infopanel
        if(this.isSelected)
          {
          String l_property_name = l_pPort.get_property().get_name();
          if(l_property_name.equals("last_update_time"))
            {
            updateLastUpdate(l_pPort, p_searchState);
            }
          else
            if(l_property_name.equals("start_time"))
              {
              updateRunningSince(l_pPort, p_searchState);
              }
          }
        }
      }

    }

  /**
   * Updates a runningSince field of th InfoPanel.
   * 
   * @param p_port
   *          the PropertyPort.
   * @param p_searchState
   *          the search state.
   */

  private void updateRunningSince(PropertyPort<?> p_port,
      SearchState<?> p_searchState)
    {
    Object l_object = p_port.get(p_searchState);
    long l_time = Long.valueOf(l_object.toString()).longValue();
    ((InfoPanel) this.m_parent.getInfoPanel()).getRunningSince().setText(
        Text.time_to_string(l_time, false));
    }

  /**
   * Updates a runningSince field of th InfoPanel.
   * 
   * @param p_port
   *          the PropertyPort.
   * @param p_searchState
   *          the search state.
   */


  private void updateLastUpdate(PropertyPort<?> p_port,
      SearchState<?> p_searchState)
    {
    Object l_object = p_port.get(p_searchState);
    long l_time = Long.valueOf(l_object.toString()).longValue();
    ((InfoPanel) this.m_parent.getInfoPanel()).getLastUpdate().setText(
        Text.time_to_string(l_time, false));
    }

  /**
   * This method creates logging tabs and writes the log in to a tab and
   * into a file.
   * 
   * @param p_caption
   *          The caption of the tab.
   * @param p_mWriter
   *          multiplexWriter.
   * @param p_file
   *          The file for logging on hard disk.
   */

  private void createLogTabs(String p_caption, MultiplexingWriter p_mWriter,
      File p_file)
    {

    JTextPane l_logPane = new JTextPane();
    LogTab l_logTab = new LogTab(p_caption, l_logPane);
    l_logPane.setEditable(false);
    this.m_logMap.put(p_caption, l_logTab);
    this.m_tabbedPane.add(p_caption, l_logTab);

    JCheckBoxMenuItem l_item = new JCheckBoxMenuItem(p_caption);
    l_item.addActionListener(this);
    l_item.setActionCommand("close_open_tab_" + p_caption);
    l_item.setState(true);
    this.m_logMenu.add(l_item);
    this.m_menuItems.put(p_caption, l_item);

    p_mWriter.add(new DocumentWriter(l_logPane, 20000));
    if(null != p_file)
      {
      try
        {
        p_mWriter.add(new FileWriter(p_file));
        }
      catch(IOException e)
        {
        e.printStackTrace();
        }
      }

    }

  /**
   * This method adds a JComponent to the JPanel.
   * 
   * @param p_pPort
   *          The property port.
   * @param p_searchState
   *          The search state.
   * @param p_panel
   *          The pannel.
   * @param p_name
   *          The name of the element.
   */

  private void addElement(PropertyPort p_pPort,
      final SearchState<?> p_searchState, JPanel p_panel, String p_name)
    {

    JComponent l_component = this.m_controlMap.create(this, p_pPort,
        p_searchState);
    BorderedPanel l_borderedPanel = new BorderedPanel(p_name);
    l_borderedPanel.setLayout(new GridBagLayout());

    Layout.set_constraints(l_borderedPanel, l_component, 1.0, 1.0,
        GridBagConstraints.HORIZONTAL, GridBagConstraints.LINE_START,
        GridBagConstraints.RELATIVE, new Insets(3, 3, 3, 3));
    Layout.set_constraints(p_panel, l_borderedPanel, 1.0, 1.0,
        GridBagConstraints.HORIZONTAL, GridBagConstraints.CENTER,
        GridBagConstraints.REMAINDER, new Insets(5, 5, 5, 5));

    if(drawAble(p_pPort))
      {
      if(p_pPort.is_array())
        {
        int l_count = p_pPort.get_count(p_searchState);
        for(int i = 0; i < l_count; ++i)
          {
          this.m_pdVector.add(new DefaultPortDescriptor(p_pPort, i, p_name));
          }
        }
      else
        {
        this.m_pdVector.add(new DefaultPortDescriptor(p_pPort, p_name));
        }
      }
    else
      if(StatisticInfo.class.equals(p_pPort.get_property().get_type()))
        {
        if(p_pPort.is_array())
          {
          int l_count = p_pPort.get_count(p_searchState);
          for(int i = 0; i < l_count; ++i)
            {
            this.m_pdVector.add(new StatAveragePortDescriptor(p_pPort, i,
                p_name));
            this.m_pdVector
                .add(new StatCountPortDescriptor(p_pPort, i, p_name));
            this.m_pdVector.add(new StatMaxPortDescriptor(p_pPort, i, p_name));
            this.m_pdVector.add(new StatMedianPortDescriptor(p_pPort, i,
                p_name));
            this.m_pdVector.add(new StatMinPortDescriptor(p_pPort, i, p_name));
            this.m_pdVector.add(new StatStddevPortDescriptor(p_pPort, i,
                p_name));
            this.m_pdVector.add(new StatSumPortDescriptor(p_pPort, i, p_name));
            this.m_pdVector.add(new StatSumSqrPortDescriptor(p_pPort, i,
                p_name));
            this.m_pdVector.add(new StatVariancePortDescriptor(p_pPort, i,
                p_name));
            this.m_pdVector.add(new StatAveragePortDescriptor(p_pPort, i,
                p_name));
            }
          }
        else
          {
          this.m_pdVector.add(new StatAveragePortDescriptor(p_pPort, p_name));
          this.m_pdVector.add(new StatCountPortDescriptor(p_pPort, p_name));
          this.m_pdVector.add(new StatMaxPortDescriptor(p_pPort, p_name));
          this.m_pdVector.add(new StatMedianPortDescriptor(p_pPort, p_name));
          this.m_pdVector.add(new StatMinPortDescriptor(p_pPort, p_name));
          this.m_pdVector.add(new StatStddevPortDescriptor(p_pPort, p_name));
          this.m_pdVector.add(new StatSumPortDescriptor(p_pPort, p_name));
          this.m_pdVector.add(new StatSumSqrPortDescriptor(p_pPort, p_name));
          this.m_pdVector.add(new StatVariancePortDescriptor(p_pPort, p_name));
          this.m_pdVector.add(new StatAveragePortDescriptor(p_pPort, p_name));
          }
        }

    }

  /**
   * Checks, if the property can be drawn in a chart. For example
   * properties, which have int or double values.
   * 
   * @param p_pPort
   *          The property port.
   * @return <code>True</code> if drawable in a chart. <code>False</code>
   *         if not drawable in a chart.
   */

  private boolean drawAble(PropertyPort p_pPort)
    {
    if((p_pPort.get_property() instanceof BoundedIntProperty)
        || (p_pPort.get_property() instanceof BoundedDoubleProperty)
        || (p_pPort.get_property() instanceof BoundedLongProperty))
      {
      return true;
      }
    return false;
    }

  /**
   * This method makes an update of the actual property.
   * 
   * @param p_pPort
   *          The property port.
   * @param p_searchState
   *          The search state.
   */

  private void updateElement(PropertyPort p_pPort,
      final SearchState<?> p_searchState)
    {
    this.m_controlMap.update(p_pPort, p_searchState);
    }

  /**
   * Is called when the user sets a <code>Property.
   * 
   * @param p_property
   *          is the <code>Property</code> to send.
   * @param p_value
   *          is the <code>Property</code>'s value.
   */

  public void setProperty(final Property<?> p_property,
      final Object p_value)
    {
    try
      {
      this.m_cp.sendObject(new PropertyUpdateEvent(this.m_parent
          .getClient(), p_property, p_value));
      }
    catch(Exception e)
      {
      e.printStackTrace();
      }
    }

  /**
   * Returns the tabbed pane.
   * 
   * @return The tabbed pane.
   */

  public TabbedPane getTabbedPane()
    {
    return this.m_tabbedPane;
    }

  /**
   *  Puts a IChart Instanz.
   *  
   * @param p_chart
   *          The chart.
   */

  public void putChart(IChart p_chart)
    {
    this.m_chartVector.add(p_chart);
    }

  /**
   * @return The chart vector.
   */

  public Vector<IChart> getCharts()
    {
    return this.m_chartVector;
    }

  /**
   * Executes a jar file on the <code>Daemon</code> running remotely.
   * 
   * @param p_jarfile
   *          is the jar file to execute on the remote <code>Daemon</code>.
   * 
   * @throws Exception
   */

  public void execJar(File p_jarfile) throws Exception
    {
    try
      {
      this.m_cp.sendObject(new JarFileEvent((this.m_parent).getClient(),
          p_jarfile));
      }
    catch(FileNotFoundException e)
      {
      JOptionPane.showMessageDialog(this, LanguageSwitcher
          .getString("msgb_file_not_found_error"), LanguageSwitcher
          .getString("msgb_name_error"), JOptionPane.ERROR_MESSAGE);
      }
    }

  /**
   * Creates a new chart chooser wizard.
   */

  public void createChart()
    {
    Collections.sort(this.m_pdVector);
    new CCWzrd(this.m_parent, thisthis.m_pdVector);
    if(JOptionPane.showConfirmDialog(this.m_parent, LanguageSwitcher
        .getString("msgb_ccd_text"), LanguageSwitcher
        .getString("msgb_ccd_caption"), JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION)
      {
      createChart();
      }
    }

  /**
   *  Is called whenever internalframe is opened.
   * @param p_event
   */

  public void internalFrameOpened(InternalFrameEvent p_event)
    {
    // Nothing yet
    }

  /**
   * Is called whenecer an Internalframe is closing.
   * 
   * @param p_event InternalFrameEvent to handle.
   */

  public void internalFrameClosing(InternalFrameEvent p_event)
    {
    closeCon();
    this.m_parent.getDesktopPane().removeFrame(this);
    this.m_parent.clearInfo();
    this.m_parent.updateInfos(); // daemons count and frame hostlist
    }

  /**
   * Is called whenecer an Internalframe is closed.
   * 
   * @param p_event InternalFrameEvent to handle.
   */

  public void internalFrameClosed(InternalFrameEvent p_event)
    {
    // Nothing yet.
    }

  /**
   *  Is called whenever an Internalfram is iconified
   * 
   * @param p_event InternalFrameEvent to handle.
   */

  public void internalFrameIconified(InternalFrameEvent p_event)
    {
    // Nothing yet.
    }

  /**
   *  Is called whenever an Internalfram is deiconified
   * @param p_event InternalFrameEvent to handle.
   */

  public void internalFrameDeiconified(InternalFrameEvent p_event)
    {
    // Nothing yet.
    }

  /**
   *  Is called whenever an Internalfram is activated.
   *  
   * @param p_event InternalFrameEvent to handle.
   */

  public void internalFrameActivated(InternalFrameEvent p_event)
    {
    frameChanged();
    }

  /**
   * Is called whenever a frame is activated.
   */

  public void frameChanged()
    {

    ((InfoPanel) this.m_parent.getInfoPanel()).getConnectedSince()
        .setText(this.m_seInfo.getConnectedSince().toString());
    ((InfoPanel) this.m_parent.getInfoPanel()).getStatus().setText(
        this.m_seInfo.getStatus());
    int idx_of_this = this.m_parent.getAllFrames().indexOf(this);

    this.m_parent.getList().setSelectedIndex(idx_of_this);

    }

  /**
   * Is called whenecer an Internalframe is deactivated.
   * 
   * @param p_event InternalFrameEvent to handle.
   */

  public void internalFrameDeactivated(InternalFrameEvent p_event)
    {
    // Nothing yet.
    }

  /**
   * toString
   * 
   * @see java.lang.Object#toString()
   */

  @Override
  public String toString()
    {
    return this.m_host.toString();
    }

  /**
   * Getter for SEInfo. 
   * 
   * @return seInfo.
   */

  public SEInfoHolder getSeInfo()
    {
    return this.m_seInfo;
    }

  /**
   * Setter for seInfo.
   * 
   * @param p_info
   *          info data to set.
   */

  public void setSeInfo(SEInfoHolder p_info)
    {
    this.m_seInfo = p_info;
    }

  /**
   * Getter for cp.
   * 
   * @return cp.
   */

  public ICommunicationPeer getCp()
    {
    return this.m_cp;
    }

  /**
   * Setter for cp.
   * 
   * @param p_cp
   *          p_cp to set.
   */

  public void setCp(ICommunicationPeer p_cp)
    {
    this.m_cp = p_cp;
    }

  /**
   * Getter for host.
   * 
   * @return Returns the m_host.
   */

  public Host getHost()
    {
    return this.m_host;
    }

  /**
   * Returns the default <code>Dimension</code> for an
   * <code>InternalFrame</code>.
   * 
   * @return Default <code>Dimension</code>.
   */

  public static Dimension getDefaultDimension()
    {
    return new Dimension(InternalFrame.DEFAULT_HEIGHT,
        InternalFrame.DEFAULT_WIDTH);
    }

  /**
   * Closes the connection.
   */

  public void closeCon()
    {
    if(this.m_cp != null)
      this.m_cp.close();
    }

  /**
   * The chart menu.
   * 
   * @return The chart menu.
   */

  private JMenu createChartMenu()
    {
    JMenu l_chartMenu = new JMenu(LanguageSwitcher
        .getString("mb_if_charts"));
    l_chartMenu
        .setMnemonic(LanguageSwitcher.getChar("mb_if_charts_mnemo"));

    JMenuItem l_createChart = new JMenuItem(LanguageSwitcher
        .getString("mb_if_charts_create"), LanguageSwitcher
        .getChar("mb_if_charts_create_mnemo"));
    l_createChart.addActionListener(this);
    l_createChart.setActionCommand("create_chart");

    l_chartMenu.add(l_createChart);
    l_chartMenu.addSeparator();
    l_chartMenu.add(createChartSubMenu());

    return l_chartMenu;
    }

  /**
   * The proprty menu.
   * 
   * @return The property menu.
   */

  private JMenu createPropertyMenu()
    {
    JMenu l_menu = new JMenu(LanguageSwitcher
        .getString("mb_if_properties"));
    l_menu.setMnemonic(LanguageSwitcher.getChar("mb_if_properties_mnemo"));

    JMenuItem l_openAll = new JMenuItem(LanguageSwitcher
        .getString("mb_if_properties_open_all"), LanguageSwitcher
        .getChar("mb_if_properties_open_all_mnemo"));
    l_openAll.addActionListener(this);
    l_openAll.setActionCommand("open_all_properties");

    JMenuItem l_closeAll = new JMenuItem(LanguageSwitcher
        .getString("mb_if_properties_close_all"), LanguageSwitcher
        .getChar("mb_if_properties_close_all_mnemo"));
    l_closeAll.addActionListener(this);
    l_closeAll.setActionCommand("close_all_properties");

    l_menu.add(l_openAll);
    l_menu.add(l_closeAll);
    l_menu.addSeparator();

    return l_menu;
    }

  /**
   *  Creates a log menu.
   *  
   * @return The log menu.
   */

  private JMenu createLogMenu()
    {
    JMenu l_menu = new JMenu(LanguageSwitcher.getString("mb_if_logs"));
    l_menu.setMnemonic(LanguageSwitcher.getChar("mb_if_logs_mnemo"));

    JMenuItem l_openAll = new JMenuItem(LanguageSwitcher
        .getString("mb_if_logs_open_all"), LanguageSwitcher
        .getChar("mb_if_logs_open_all_mnemo"));
    l_openAll.addActionListener(this);
    l_openAll.setActionCommand("open_all_logs");

    JMenuItem l_closeAll = new JMenuItem(LanguageSwitcher
        .getString("mb_if_logs_close_all"), LanguageSwitcher
        .getChar("mb_if_logs_close_all_mnemo"));
    l_closeAll.addActionListener(this);
    l_closeAll.setActionCommand("close_all_logs");

    l_menu.add(l_openAll);
    l_menu.add(l_closeAll);
    l_menu.addSeparator();

    return l_menu;
    }

  /**
   * The chart sub menu with all actual charts.
   * 
   * @return The chart sub menu.
   */

  private JMenu createChartSubMenu()
    {
    this.m_chartSubMenu = new JMenu(LanguageSwitcher
        .getString("mb_if_charts_close"));
    this.m_chartSubMenu.setMnemonic(LanguageSwitcher
        .getChar("mb_if_charts_close_mnemo"));

    JMenuItem l_closeAll = new JMenuItem(LanguageSwitcher
        .getString("mb_if_charts_close_all"), LanguageSwitcher
        .getChar("mb_if_charts_close_all_mnemo"));
    l_closeAll.addActionListener(this);
    l_closeAll.setActionCommand("close_all_charts");

    this.m_chartSubMenu.add(l_closeAll);
    this.m_chartSubMenu.addSeparator();
    this.m_chartSubMenu.setEnabled(false);

    return this.m_chartSubMenu;
    }

  /**
   * @return The chart sub menu
   */

  public JMenu getChartSubMenu()
    {
    return this.m_chartSubMenu;
    }

  /**
   * @return The menu item map.
   */

  public HashMap<String, JMenuItem> getMenuItems()
    {
    return this.m_menuItems;
    }

  /**
   * Removes the menu item.
   * 
   * @param p_name
   *          The name of the item/tab.
   * @param p_class
   *          The class of the tab.
   */

  private void removeMenuItem(String p_name, Class p_class)
    {
    if(p_class.equals(ChartTab.class))
      {
      this.m_chartSubMenu.remove(this.m_menuItems.get(p_name));

      // if the chart count is one, than this is the last tab, which will
      // be removed -> disable the closing
      if(getTabCount(ChartTab.class) == 1)
        {
        this.m_chartSubMenu.setEnabled(false);
        }
      }
    this.m_menuItems.remove(p_name);
    }

  /**
   * Gets a tab count.
   * 
   * @param p_class
   *          The class.
   * @return The count of tabs.
   */

  public int getTabCount(Class p_class)
    {
    int l_count = 0;
    for(int l_i = 0; l_i < this.m_tabbedPane.getComponentCount(); ++l_i)
      {
      if(this.m_tabbedPane.getComponent(l_i).getClass().equals(p_class))
        {
        ++l_count;
        }
      }
    return l_count;
    }

  /**
   * Close all chart-tabs.
   */

  private void closeAllChartTabs()
    {
    while(getTabCount(ChartTab.class) != 0)
      {
      for(int l_i = 0; l_i < this.getTabbedPane().getComponentCount(); ++l_i)
        {
        if(this.getTabbedPane().getComponent(l_i).getClass().equals(
            ChartTab.class))
          {
          String l_name = ((ITab) this.getTabbedPane().getComponent(l_i))
              .getTabName();
          removeMenuItem(l_name, this.getTabbedPane().getComponent(l_i)
              .getClass());
          this.getTabbedPane().removeTabAt(l_i);
          int l_index = -1;
          for(IChart l_chart : this.m_chartVector)
            {
            if(l_chart.toString().equals(l_name))
              {
              l_index = this.m_chartVector.indexOf(l_chart);
              }
            }
          if(l_index != -1)
            this.m_chartVector.remove(l_index);
          break;
          }
        }
      }
    this.m_chartSubMenu.setEnabled(false);
    }

  /**
   * Close all tabs.
   * 
   * @param p_class
   *          The tab class.
   */

  private void closeAllTabs(Class p_class)
    {
    while(getTabCount(p_class) != 0)
      {
      for(int l_i = 0; l_i < this.getTabbedPane().getComponentCount(); ++l_i)
        {
        if(this.getTabbedPane().getComponent(l_i).getClass().equals(
            p_class))
          {
          String l_name = ((ITab) this.getTabbedPane().getComponent(l_i))
              .getTabName();
          this.getTabbedPane().removeTabAt(l_i);
          ((JCheckBoxMenuItem) this.m_menuItems.get(l_name))
              .setState(false);
          }
        }
      }
    }

  /**
   * Open all tabs.
   * 
   * @param p_class
   *          The tab class.
   */

  private void openAllTabs(Class p_class)
    {
    if(p_class.equals(PropertyTab.class))
      {
      for(String l_s : this.m_propertySubSetMap.keySet())
        {
        if(!((JCheckBoxMenuItem) this.m_menuItems.get(l_s)).getState())
          {
          this.m_tabbedPane.addPropertySetTab(this.m_propertySubSetMap
              .get(l_s));
          ((JCheckBoxMenuItem) this.m_menuItems.get(l_s)).setState(true);
          }
        }
      }
    else
      if(p_class.equals(LogTab.class))
        {
        for(String l_s : this.m_logMap.keySet())
          {
          if(!((JCheckBoxMenuItem) this.m_menuItems.get(l_s)).getState())
            {
            this.m_tabbedPane.add(l_s, this.m_logMap.get(l_s));
            ((JCheckBoxMenuItem) this.m_menuItems.get(l_s)).setState(true);
            }
          }
        }

    }

  /**
   * Closes a tab.
   * 
   * @param p_tabName
   *          The tab name.
   */

  private void closeTab(String p_tabName)
    {
    for(int l_i = 0; l_i < this.getTabbedPane().getComponentCount(); ++l_i)
      {
      if(((ITab) this.getTabbedPane().getComponent(l_i)).getTabName()
          .equals(p_tabName))
        {
        removeMenuItem(p_tabName, this.getTabbedPane().getComponent(l_i)
            .getClass());
        this.getTabbedPane().removeTabAt(l_i);
        }
      }
    }

  /**
   * Closes or opens a tab.
   * 
   * @param p_tabName
   *          The tab name.
   */

  private void closeOrOpenTab(String p_tabName)
    {
    boolean l_state = ((JCheckBoxMenuItem) this.m_menuItems.get(p_tabName))
        .getState();

    // has to be removed
    if(!l_state)
      {
      for(int l_i = 0; l_i < this.getTabbedPane().getComponentCount(); ++l_i)
        {
        if(((ITab) this.getTabbedPane().getComponent(l_i)).getTabName()
            .equals(p_tabName))
          {
          this.getTabbedPane().removeTabAt(l_i);
          break;
          }
        }
      ((JCheckBoxMenuItem) this.m_menuItems.get(p_tabName)).setState(false);
      }

    // has to be added
    else
      {
      if(this.m_logMap.containsKey(p_tabName))
        {
        this.m_tabbedPane.add(p_tabName, this.m_logMap.get(p_tabName));
        }
      else
        if(this.m_propertySubSetMap.containsKey(p_tabName))
          {
          this.m_tabbedPane.addPropertySetTab(this.m_propertySubSetMap
              .get(p_tabName));
          }
      }
    }

  }

File Information:

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