gt:         else if (index == 1)
context: /*
   *  RapidMiner
   *
   *  Copyright (C) 2001-2013 by Rapid-I and the contributors
   *
   *  Complete list of developers available at our web site:
   *
   *       http://rapid-i.com
   *
   *  This program is free software: you can redistribute it and/or modify
   *  it under the terms of the GNU Affero General Public License as published by
   *  the Free Software Foundation, either version 3 of the License, or
   *  (at your option) any later version.
   *
   *  This program is distributed in the hope that it will be useful,
   *  but WITHOUT ANY WARRANTY; without even the implied warranty of
   *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
   *  GNU Affero General Public License for more details.
   *
   *  You should have received a copy of the GNU Affero General Public License
   *  along with this program.  If not, see http://www.gnu.org/licenses/.
   */
  package com.rapidminer.gui.plotter.charts;
  
  import java.awt.Color;
  import java.awt.event.ActionEvent;
  import java.awt.event.ActionListener;
  import java.util.Collection;
  import java.util.Date;
  import java.util.Iterator;
  import java.util.LinkedHashMap;
  import java.util.LinkedList;
  import java.util.List;
  import java.util.Map;
  import java.util.SortedSet;
  import java.util.TreeSet;
  import java.util.logging.Level;
  
  import javax.swing.BorderFactory;
  import javax.swing.Icon;
  import javax.swing.JComponent;
  import javax.swing.JLabel;
  import javax.swing.JScrollPane;
  import javax.swing.ListSelectionModel;
  import javax.swing.event.ChangeEvent;
  import javax.swing.event.ChangeListener;
  import javax.swing.event.ListSelectionEvent;
  import javax.swing.event.ListSelectionListener;
  
  import org.jfree.chart.ChartPanel;
  import org.jfree.chart.JFreeChart;
  import org.jfree.chart.block.BlockBorder;
  import org.jfree.chart.plot.PiePlot;
  import org.jfree.chart.title.LegendTitle;
  import org.jfree.data.general.DefaultPieDataset;
  import org.jfree.data.general.PieDataset;
  import org.jfree.ui.HorizontalAlignment;
  import org.jfree.ui.RectangleEdge;
  
  import com.rapidminer.datatable.DataTable;
  import com.rapidminer.datatable.DataTableRow;
  import com.rapidminer.gui.MainFrame;
  import com.rapidminer.gui.plotter.PlotterAdapter;
  import com.rapidminer.gui.plotter.PlotterConfigurationModel;
  import com.rapidminer.gui.plotter.PlotterConfigurationModel.PlotterSettingsChangedListener;
  import com.rapidminer.gui.plotter.PlotterPanel;
  import com.rapidminer.gui.plotter.settings.ListeningJCheckBox;
  import com.rapidminer.gui.plotter.settings.ListeningJComboBox;
  import com.rapidminer.gui.plotter.settings.ListeningJSlider;
  import com.rapidminer.gui.plotter.settings.ListeningListSelectionModel;
  import com.rapidminer.gui.tools.ExtendedJList;
  import com.rapidminer.gui.tools.ExtendedJScrollPane;
  import com.rapidminer.gui.tools.ExtendedListModel;
  import com.rapidminer.operator.ports.InputPort;
  import com.rapidminer.parameter.ParameterType;
  import com.rapidminer.parameter.ParameterTypeBoolean;
  import com.rapidminer.parameter.ParameterTypeCategory;
  import com.rapidminer.parameter.ParameterTypeEnumeration;
  import com.rapidminer.parameter.ParameterTypeInt;
  import com.rapidminer.parameter.ParameterTypeString;
  import com.rapidminer.tools.LogService;
  import com.rapidminer.tools.ParameterService;
  import com.rapidminer.tools.Tools;
  import com.rapidminer.tools.math.function.aggregation.AbstractAggregationFunction;
  import com.rapidminer.tools.math.function.aggregation.AggregationFunction;
  import com.rapidminer.tools.math.function.aggregation.AverageFunction;
  
  /**
   * This is the main pie chart plotter.
   * 
   * @author Ingo Mierswa
   * 
   */
  public abstract class AbstractPieChartPlotter extends PlotterAdapter {
  
      public static final String PARAMETERS_AGGREGATION = "aggregation";
  
      public static final String PARAMETERS_USE_DISTINCT = "use_distinct";
  
      public static final String PARAMETERS_EXPLOSION_GROUPS = "explosion_groups";
  
      public static final String PARAMETERS_EXPLOSION_AMOUNT = "explosion_amount";
  
      private static final long serialVersionUID = 8750708105082707503L;
  
      /** The maximal number of printable categories. */
      private static final int MAX_CATEGORIES = 50;
  
      /** The currently used data table object. */
      private DataTable dataTable;
  
      /** The pie data set. */
      private DefaultPieDataset pieDataSet = new DefaultPieDataset();
  
      /** The column which is used for the piece names (or group-by statements). */
      private int groupByColumn = -1;
  
      /** The column which is used for the legend. */
      private int legendByColumn = -1;
  
      /** The column which is used for the values. */
      private int valueColumn = -1;
  
      /** Indicates if only distinct values should be used for aggregation functions. */
      private ListeningJCheckBox useDistinct;
  
      /** The used aggregation function. */
      private ListeningJComboBox aggregationFunction = null;
  
      /** Indicates if absolute values should be used. */
      private boolean absoluteFlag = false;
  
      /** The currently selected groups for explosion. */
      private String[] explodingGroups = new String[0];
  
      /** This list hold all groups of the selected grouping column which should be selected for explosion. */
      private ExtendedJList explodingGroupList;
      private ListeningListSelectionModel explodingGroupListSelectionModel;
  
      /** The slider for the amount of explosion. */
      private ListeningJSlider explodingSlider;
  
      /** The currently selected amount of explosion. */
      private double explodingAmount = 0.0d;
  
      private String selectedAggregationFunction;
      private boolean useDistinctFlag = false;
  
      private ChartPanel panel = new ChartPanel(null);
  
      public AbstractPieChartPlotter(final PlotterConfigurationModel settings) {
          super(settings);
          setBackground(Color.white);
          useDistinct = new ListeningJCheckBox("_" + PARAMETERS_USE_DISTINCT, "Use Only Distinct", false);
          useDistinct.setToolTipText("Indicates if only distinct values should be used for aggregation functions.");
          useDistinct.addActionListener(new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                  settings.setParameterAsBoolean(PARAMETERS_USE_DISTINCT, useDistinct.isSelected());
              }
          });
  
          String[] allFunctions = new String[AbstractAggregationFunction.KNOWN_AGGREGATION_FUNCTION_NAMES.length + 1];
          allFunctions[0] = "none";
          System.arraycopy(AbstractAggregationFunction.KNOWN_AGGREGATION_FUNCTION_NAMES, 0, allFunctions, 1, AbstractAggregationFunction.KNOWN_AGGREGATION_FUNCTION_NAMES.length);
          aggregationFunction = new ListeningJComboBox(settings, "_" + PARAMETERS_AGGREGATION, allFunctions);
          aggregationFunction.setToolTipText("Select the type of the aggregation function which should be used for grouped values.");
          aggregationFunction.addActionListener(new ActionListener() {
              @Override
              public void actionPerformed(ActionEvent e) {
                  settings.setParameterAsString(PARAMETERS_AGGREGATION, aggregationFunction.getSelectedItem().toString());
              }
          });
  
          explodingGroupList = new ExtendedJList(new ExtendedListModel(), 200);
          explodingGroupListSelectionModel = new ListeningListSelectionModel("_" + PARAMETERS_EXPLOSION_GROUPS, explodingGroupList);
          explodingGroupList.setSelectionModel(explodingGroupListSelectionModel);
          explodingGroupList.addListSelectionListener(new ListSelectionListener() {
              @Override
              public void valueChanged(ListSelectionEvent e) {
                  if (!e.getValueIsAdjusting()) {
                      Object[] values = explodingGroupList.getSelectedValues();
                      List<String> list = new LinkedList<String>();
                      for (Object object : values) {
                          list.add((String) object);
                      }
                      String result = ParameterTypeEnumeration.transformEnumeration2String(list);
                      settings.setParameterAsString(PARAMETERS_EXPLOSION_GROUPS, result);
                  }
              }
          });
          explodingGroupList.setForeground(Color.BLACK);
          explodingGroupList.setSelectionMode(ListSelectionModel.MULTIPLE_INTERVAL_SELECTION);
          explodingGroupList.setBorder(BorderFactory.createLoweredBevelBorder());
          explodingGroupList.setCellRenderer(new PlotterPanel.LineStyleCellRenderer(this));
  
          updateGroups();
  
          explodingSlider = new ListeningJSlider("_" + PARAMETERS_EXPLOSION_AMOUNT, 0, 100, 0);
          explodingSlider.addChangeListener(new ChangeListener() {
              @Override
              public void stateChanged(ChangeEvent e) {
                  settings.setParameterAsInt(PARAMETERS_EXPLOSION_AMOUNT, explodingSlider.getValue());
              }
          });
      }
  
      public AbstractPieChartPlotter(PlotterConfigurationModel settings, DataTable dataTable) {
          this(settings);
          setDataTable(dataTable);
      }
  
      public abstract JFreeChart createChart(PieDataset pieDataSet, boolean createLegend);
  
      public abstract boolean isSupportingExplosion();
  
      @Override
      public void setDataTable(DataTable dataTable) {
          super.setDataTable(dataTable);
          this.dataTable = dataTable;
          groupByColumn = -1;
          legendByColumn = -1;
          valueColumn = -1;
          absoluteFlag = false;
          explodingGroups = new String[0];
          explodingAmount = 0.0d;
          updatePlotter();
      }
  
      @Override
      public void setAbsolute(boolean absolute) {
          this.absoluteFlag = absolute;
          updatePlotter();
      }
  
      @Override
      public boolean isSupportingAbsoluteValues() {
          return true;
      }
  
      @Override
      public void setPlotColumn(int index, boolean plot) {
          if (plot)
              this.valueColumn = index;
          else
              this.valueColumn = -1;
          updatePlotter();
      }
  
      @Override
      public boolean getPlotColumn(int index) {
          return valueColumn == index;
      }
  
      @Override
      public Icon getIcon(int index) {
          return null;
      }
  
      @Override
      public String getPlotName() {
          return "Value Column";
      }
  
      @Override
      public int getNumberOfAxes() {
          return 2;
      }
  
      @Override
      public void setAxis(int index, int dimension) {
          if (index == 0) {
              groupByColumn = dimension;
              updateGroups();
          } else if (index == 1) {
              legendByColumn = dimension;
          }
          updatePlotter();
      }
  
      @Override
      public int getAxis(int index) {
          if (index == 0)
              return groupByColumn;
          else if (index == 1)
              return legendByColumn;
          else
              return -1;
      }
  
      @Override
      public String getAxisName(int index) {
          if (index == 0)
              return "Group-By Column";
  