Logo
Distributed Genetic Programming Framework
print print

File org.dgpf.gui.wizards.chartchooser.CCWzrd.java

Here you can find all the information about the file org.dgpf.gui.wizards.chartchooser.CCWzrd.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.07.2006 12:40:40
 * Original Filename: org.dgpf.gui.DGPFChartChooserFrame.java
 * Version          : 1.0
 * Last modification: 22.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.wizards.chartchooser;

import java.awt.CardLayout;
import java.awt.event.ActionEvent;
import java.util.Vector;

import javax.swing.JFrame;
import javax.swing.JMenuItem;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.event.TreeSelectionEvent;
import javax.swing.event.TreeSelectionListener;
import javax.swing.tree.DefaultMutableTreeNode;
import javax.swing.tree.TreeSelectionModel;

import org.dgpf.gui.Frame;
import org.dgpf.gui.InternalFrame;
import org.dgpf.gui.charts.Bar3DChart;
import org.dgpf.gui.charts.IChart;
import org.dgpf.gui.charts.Pie3DChart;
import org.dgpf.gui.charts.XYLineChart;
import org.dgpf.gui.charts.descriptors.PortDescriptorBase;
import org.dgpf.gui.components.TextArea;
import org.dgpf.gui.components.Tree;
import org.dgpf.gui.tabs.ChartTab;
import org.dgpf.gui.utils.LanguageSwitcher;
import org.dgpf.gui.wizards.WizardBase;
import org.jfree.chart.ChartPanel;

/**
 * In this frame the user can choose a property, which can be drawn in a
 * chart.
 * 
 * @author Alexander Podlich
 */

public class CCWzrd extends WizardBase implements TreeSelectionListener
  {

  /**
   * The serial version UID.
   */

  private static final long  serialVersionUID = 1L;

  /**
   * The charts tree.
   */

  private Tree               m_tree;

  /**
   * The chart panel.
   */

  ChartPanel                 m_chartPanel;

  /**
   * The xy line chart.
   */

  XYLineChart                m_xyLineChart;

  /**
   * The pie chart.
   */

  Pie3DChart                 m_pie3DChart;

  /**
   * The bar chart.
   */

  Bar3DChart                 m_bar3DChart;

  /**
   * The description area of a chart.
   */

  TextArea                   m_textArea;

  /**
   * The internal frame.
   */

  InternalFrame              m_iFrame;

  /**
   * The parent frame.
   */

  JFrame                     m_pFrame;

  /**
   * The vector of port descriptors.
   */

  Vector<PortDescriptorBase> m_values;

  /**
   * The vector of charts.
   */

  Vector<IChart>             m_charts;

  /**
   * The actual selected tree node.
   */

  DefaultMutableTreeNode     m_actualNode;

  /**
   * The second card for the xy line chart
   */

  JPanel                     m_secChartCard;

  /**
   * Constructor
   * 
   * @param p_pf
   *          The parent frame.
   * @param p_frame
   *          The internal frame.
   * @param p_vec
   *          The vector of DGPFPortDescriptos as y-values in a chart.
   */

  public CCWzrd(Frame p_pf, InternalFrame p_frame,
      Vector<PortDescriptorBase> p_vec)
    {

    super(p_pf, LanguageSwitcher.getString("cc1_caption"),
        LanguageSwitcher.getString("cc1_info"), true);

    this.m_pFrame = p_pf;
    this.m_iFrame = p_frame;
    this.m_values = p_vec;
    this.m_chartPanel = new ChartPanel(null);
    this.m_textArea = new TextArea(true, false, true, true);
    this.m_textArea.setText(LanguageSwitcher
        .getString("chrt_no_selection"));
    this.m_charts = new Vector<IChart>();

    this.m_tree = new Tree(TreeSelectionModel.SINGLE_TREE_SELECTION, true,
        true, thisnew DefaultMutableTreeNode(LanguageSwitcher
            .getString("cc1_tree_root")));

    /** Create here new charts and add them to the chart-vector */

    // xy - line chart
    this.m_xyLineChart = new XYLineChart(LanguageSwitcher
        .getString("xylc_caption"));
    this.m_charts.add(this.m_xyLineChart);

    // pie chart
    this.m_pie3DChart = new Pie3DChart(LanguageSwitcher
        .getString("piec_caption"));
    this.m_charts.add(this.m_pie3DChart);

    // bar chart
    this.m_bar3DChart = new Bar3DChart(LanguageSwitcher
        .getString("barc_caption"));
    this.m_charts.add(this.m_bar3DChart);

    createFirstCard();
    finish(690, 520);

    }

  /**
   * The action listener.
   * 
   * @param p_event
   *          Action event
   */

  public void actionPerformed(ActionEvent p_event)
    {
    String l_cmd = p_event.getActionCommand();
    if(l_cmd.equals("cancel"))
      {
      this.dispose();
      return;
      }
    else
      if(l_cmd.equals("next"))
        {
        getTextArea().setText(LanguageSwitcher.getString("cc2_info"));
        showSecondCard();
        setPrvBtnEnbl(true);
        }
      else
        if(l_cmd.equals("prev"))
          {
          getTextArea().setText(LanguageSwitcher.getString("cc1_info"));
          ((CardLayout) getCenter().getLayout()).show(this.getCenter(),
              "cardFC");
          setPrvBtnEnbl(false);
          setNxtBtnEnbl(true);
          setFnshBtnEnbl(false);
          }
        else
          if(l_cmd.equals("finish"))
            {
            if(this.m_actualNode.getUserObject()
                .equals(this.m_xyLineChart))
              {
              CCWzrdSecCardXYLC l_secCard = (CCWzrdSecCardXYLC) this.m_secChartCard;
              if(!canUseName(l_secCard.getChartName()))
                {
                JOptionPane.showMessageDialog(this.m_pFrame,
                    LanguageSwitcher.getString("msgb_ccd_illegal_name"),
                    LanguageSwitcher.getString("msgb_name_error"),
                    JOptionPane.ERROR_MESSAGE);
                return;
                }
              if(l_secCard.canStart())
                {
                this.m_xyLineChart.setName(l_secCard.getChartName());
                this.m_xyLineChart.setLineVisibility(l_secCard
                    .getLineVisibility());
                this.m_xyLineChart.setShapeVisibility(l_secCard
                    .getShapeVisibility());
                this.m_xyLineChart.setShowLegend(l_secCard
                    .showChartLegend());
                this.m_xyLineChart.setXValue(l_secCard.getXValue());
                this.m_xyLineChart.setYValues(l_secCard.getyValues());
                if(l_secCard.xAchsisIsBounded())
                  {
                  this.m_xyLineChart.setXAchsisIsBounded(true);
                  this.m_xyLineChart.setBoundedValue(l_secCard
                      .getBoundedValue());
                  }
                else
                  {
                  this.m_xyLineChart.setXAchsisIsBounded(false);
                  }
                if(l_secCard.isTimeChart())
                  {
                  this.m_xyLineChart.setIsTimeChart(true);
                  this.m_xyLineChart.setTimePattern(l_secCard
                      .getTimePattern());
                  }
                else
                  {
                  this.m_xyLineChart.setIsTimeChart(false);
                  }
                this.m_iFrame.getTabbedPane().addAndShowTab(
                    new ChartTab(this.m_xyLineChart.toString(),
                        this.m_xyLineChart.createChart()));
                JMenuItem l_item = new JMenuItem(this.m_xyLineChart
                    .toString());
                this.m_iFrame.getMenuItems().put(
                    this.m_xyLineChart.toString(), l_item);
                l_item.addActionListener(this.m_iFrame);
                l_item.setActionCommand("close_tab_"
                    + this.m_xyLineChart.toString());
                this.m_iFrame.getChartSubMenu().add(l_item);
                this.m_iFrame.getChartSubMenu().setEnabled(true);
                this.m_iFrame.putChart(this.m_xyLineChart);
                this.dispose();
                }
              else
                {
                JOptionPane.showMessageDialog(this.m_pFrame,
                    LanguageSwitcher.getString("msgb_ccd_cannot_start"),
                    LanguageSwitcher.getString("msgb_name_error"),
                    JOptionPane.ERROR_MESSAGE);

                }
              return;
              }
            else
              if(this.m_actualNode.getUserObject().equals(
                  this.m_pie3DChart))
                {
                CCWzrdSecCardPC l_secCard = (CCWzrdSecCardPC) this.m_secChartCard;
                if(!canUseName(l_secCard.getChartName()))
                  {
                  JOptionPane.showMessageDialog(this.m_pFrame,
                      LanguageSwitcher.getString("msgb_ccd_illegal_name"),
                      LanguageSwitcher.getString("msgb_name_error"),
                      JOptionPane.ERROR_MESSAGE);
                  return;
                  }
                if(l_secCard.canStart())
                  {
                  this.m_pie3DChart.setName(l_secCard.getChartName());
                  this.m_pie3DChart.setShowLegend(l_secCard
                      .showChartLegend());
                  this.m_pie3DChart.setValues(l_secCard.getValues());
                  this.m_pie3DChart
                      .setRotateChart(l_secCard.rotateChart());
                  this.m_iFrame.getTabbedPane().addAndShowTab(
                      new ChartTab(this.m_pie3DChart.toString(),
                          this.m_pie3DChart.createChart()));
                  JMenuItem l_item = new JMenuItem(this.m_pie3DChart
                      .toString());
                  this.m_iFrame.getMenuItems().put(
                      this.m_pie3DChart.toString(), l_item);
                  l_item.addActionListener(this.m_iFrame);
                  l_item.setActionCommand("close_tab_"
                      + this.m_pie3DChart.toString());
                  this.m_iFrame.getChartSubMenu().add(l_item);
                  this.m_iFrame.getChartSubMenu().setEnabled(true);
                  this.m_iFrame.putChart(this.m_pie3DChart);
                  this.dispose();
                  }
                else
                  {
                  JOptionPane.showMessageDialog(this.m_pFrame,
                      LanguageSwitcher.getString("msgb_ccd_cannot_start"),
                      LanguageSwitcher.getString("msgb_name_error"),
                      JOptionPane.ERROR_MESSAGE);
                  }
                return;
                }
              else
                if(this.m_actualNode.getUserObject().equals(
                    this.m_bar3DChart))
                  {
                  CCWzrdSecCardBC l_secCard = (CCWzrdSecCardBC) this.m_secChartCard;
                  if(!canUseName(l_secCard.getChartName()))
                    {
                    JOptionPane.showMessageDialog(this.m_pFrame,
                        LanguageSwitcher
                            .getString("msgb_ccd_illegal_name"),
                        LanguageSwitcher.getString("msgb_name_error"),
                        JOptionPane.ERROR_MESSAGE);
                    return;
                    }
                  if(l_secCard.canStart())
                    {
                    this.m_bar3DChart.setName(l_secCard.getChartName());
                    this.m_bar3DChart.setXValue(l_secCard.getXValue());
                    this.m_bar3DChart.setYValues(l_secCard.getyValues());
                    this.m_bar3DChart.setShowLegend(l_secCard
                        .showChartLegend());
                    this.m_bar3DChart.setPlotOrientation(l_secCard
                        .getPlotOrientation());
                    if(l_secCard.xAchsisIsBounded())
                      {
                      this.m_bar3DChart.setXAchsisIsBounded(true);
                      this.m_bar3DChart.setBoundedValue(l_secCard
                          .getBoundedValue());
                      }
                    else
                      {
                      this.m_xyLineChart.setXAchsisIsBounded(false);
                      }
                    if(l_secCard.isTimeChart())
                      {
                      this.m_bar3DChart.setIsTimeChart(true);
                      this.m_bar3DChart.setTimePattern(l_secCard
                          .getTimePattern());
                      }
                    else
                      {
                      this.m_bar3DChart.setIsTimeChart(false);
                      }
                    this.m_iFrame.getTabbedPane().addAndShowTab(
                        new ChartTab(this.m_bar3DChart.toString(),
                            this.m_bar3DChart.createChart()));
                    JMenuItem l_item = new JMenuItem(this.m_bar3DChart
                        .toString());
                    this.m_iFrame.getMenuItems().put(
                        this.m_bar3DChart.toString(), l_item);
                    l_item.addActionListener(this.m_iFrame);
                    l_item.setActionCommand("close_tab_"
                        + this.m_bar3DChart.toString());
                    this.m_iFrame.getChartSubMenu().add(l_item);
                    this.m_iFrame.getChartSubMenu().setEnabled(true);
                    this.m_iFrame.putChart(this.m_bar3DChart);
                    this.dispose();
                    }
                  else
                    {
                    JOptionPane.showMessageDialog(this.m_pFrame,
                        LanguageSwitcher
                            .getString("msgb_ccd_cannot_start"),
                        LanguageSwitcher.getString("msgb_name_error"),
                        JOptionPane.ERROR_MESSAGE);
                    }
                  }
            }
    }

  /**
   * @param p_event
   *          The tree selection event.
   */

  public void valueChanged(TreeSelectionEvent p_event)
    {
    this.m_actualNode = (DefaultMutableTreeNode) this.m_tree
        .getSelectionPath().getLastPathComponent();
    if(this.m_actualNode.getUserObject() instanceof IChart)
      {
      IChart l_chart = ((IChart) this.m_actualNode.getUserObject());
      this.m_chartPanel.setChart(l_chart.getSampleChart());
      this.m_textArea.setText(l_chart + "\n\n" + l_chart.getDescription());
      this.setNxtBtnEnbl(true);
      }
    else
      {
      this.m_chartPanel.setChart(null);
      this.m_textArea.setText(LanguageSwitcher
          .getString("chrt_no_selection"));
      this.setNxtBtnEnbl(false);
      }
    }

  /**
   * Creates the first card.
   */

  private void createFirstCard()
    {
    getCenter().add(
        new CCWzrdFirstCard(thisthis.m_chartPanel, this.m_textArea,
            this.m_charts, this.m_tree), "cardFC");
    }

  /**
   * Creates the second card.
   */

  private void showSecondCard()
    {

    if(this.m_actualNode.getUserObject() instanceof XYLineChart)
      {
      if((this.m_secChartCard == null)
          || ((this.m_secChartCard != null) && !(this.m_secChartCard instanceof CCWzrdSecCardXYLC)))
        {
        this.m_secChartCard = new CCWzrdSecCardXYLC(this.m_values,
            this.m_actualNode.getUserObject().toString());
        this.getCenter().add(this.m_secChartCard, "cardXYLC");
        }
      ((CardLayout) getCenter().getLayout()).show(this.getCenter(),
          "cardXYLC");
      }
    else
      if(this.m_actualNode.getUserObject() instanceof Pie3DChart)
        {
        if((this.m_secChartCard == null)
            || ((this.m_secChartCard != null) && !(this.m_secChartCard instanceof CCWzrdSecCardPC)))
          {
          this.m_secChartCard = new CCWzrdSecCardPC(this.m_values,
              this.m_actualNode.getUserObject().toString());
          this.getCenter().add(this.m_secChartCard, "cardPC");
          }
        ((CardLayout) getCenter().getLayout()).show(this.getCenter(),
            "cardPC");
        }
      else
        if(this.m_actualNode.getUserObject() instanceof Bar3DChart)
          {
          if((this.m_secChartCard == null)
              || ((this.m_secChartCard != null) && !(this.m_secChartCard instanceof CCWzrdSecCardBC)))
            {
            this.m_secChartCard = new CCWzrdSecCardBC(this.m_values,
                this.m_actualNode.getUserObject().toString());
            this.getCenter().add(this.m_secChartCard, "cardBC");
            }
          ((CardLayout) getCenter().getLayout()).show(this.getCenter(),
              "cardBC");
          }
    setNxtBtnEnbl(false);
    setFnshBtnEnbl(true);

    }

  /**
   * Checks if the actual chart name is allready used by an another chart.
   * 
   * @param p_name
   *          the actual name of the chart.
   * @return false if the actual chart name cannot be used, else true.
   */

  private boolean canUseName(String p_name)
    {
    for(IChart l_chart : this.m_iFrame.getCharts())
      {
      if(l_chart.toString().equals(p_name))
        {
        return false;
        }
      }
    return true;
    }

  }

File Information:

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