private void collectFieldValues() {
   params.clear();
   for (Object control : namedControls) {
     if (control instanceof JWFNumberField) {
       JWFNumberField numberField = (JWFNumberField) control;
       params.put(numberField.getName(), new ScriptParam(numberField.getDoubleValue()));
     } else if (control instanceof JTextField) {
       JTextField textField = (JTextField) control;
       params.put(textField.getName(), new ScriptParam(textField.getText()));
     } else if (control instanceof JComboBox) {
       JComboBox comboBox = (JComboBox) control;
       params.put(comboBox.getName(), new ScriptParam((String) comboBox.getSelectedItem()));
     } else if (control instanceof JCheckBox) {
       JCheckBox checkBox = (JCheckBox) control;
       params.put(checkBox.getName(), new ScriptParam(checkBox.isSelected()));
     } else {
       throw new IllegalStateException(control.getClass().getName());
     }
   }
 }
  /**
   * Performs actions for the controls in the Histogram window.
   *
   * @param oEvent Event triggered.
   */
  public void actionPerformed(ActionEvent oEvent) {
    try {
      if (oEvent.getSource() instanceof JCheckBox) {
        JCheckBox jBox = (JCheckBox) oEvent.getSource();
        if (jBox.getName().equals("log_checkbox")) {
          if (jBox.isSelected() != m_bUseLogarithmicAxis) {
            m_bUseLogarithmicAxis = jBox.isSelected();
            updateChart(m_oManager.getLegend());
          }
        } else if (jBox.getName().equals("total_checkbox")) {
          if (jBox.isSelected() != m_bShowTotal) {
            m_bShowTotal = jBox.isSelected();

            // If the dataset already exists, simply calling an update will
            // have no effect; so either remove or add the series, as
            // requested
            if (m_oDataset != null && m_oDataset.getSeriesCount() > 0) {
              if (m_bShowTotal == true) {
                m_oDataset.addTotalSeries();
              } else {
                for (int i = 0; i < m_oDataset.getSeriesCount(); i++) {
                  if (((String) m_oDataset.getSeriesKey(i)).equalsIgnoreCase("total")) {
                    m_oDataset.removeSeries(i);
                    break;
                  }
                }
              }
            }
            updateChart(m_oManager.getLegend());
          }
        }
      } else if (oEvent.getActionCommand().equals("UpdateBins")) {

        // Make sure the values in the bins are recognizable, greater-than-zero numbers
        int iNumBins = 0;
        float fBinSize = 0;
        JTextField jNumBins =
            (JTextField)
                DataGrapher.findNamedComponent(m_oChartFrame.getContentPane(), NUMBER_BINS_NAME);
        JTextField jBinSize =
            (JTextField)
                DataGrapher.findNamedComponent(m_oChartFrame.getContentPane(), BIN_SIZE_NAME);
        try {
          Integer oNumBins = new Integer(jNumBins.getText());
          Float oBinSize = new Float(jBinSize.getText());
          iNumBins = oNumBins.intValue();
          fBinSize = oBinSize.floatValue();
        } catch (java.lang.NumberFormatException oErr) {
          JOptionPane.showMessageDialog(
              m_oChartFrame,
              "The value for number of bins or bin size is not a recognized number.");
          jNumBins.setText(String.valueOf(m_iNumBins));
          jBinSize.setText(String.valueOf(m_fBinSize));
          return;
        }

        if (iNumBins <= 0 || fBinSize <= 0) {
          JOptionPane.showMessageDialog(
              m_oChartFrame,
              "The values for number of bins and bin size must be greater than zero.");
          jNumBins.setText(String.valueOf(m_iNumBins));
          jBinSize.setText(String.valueOf(m_fBinSize));
          return;
        }

        if (iNumBins != m_iNumBins || fBinSize != m_fBinSize) {
          m_iNumBins = iNumBins;
          m_fBinSize = fBinSize;

          // Clear the dataset to force a reconstruction
          m_oDataset = null;
          m_oDataset = new ModelHistogramDataset();

          m_bRecalcBinsOnUpdate = false;
          updateChart(m_oManager.getLegend());
        }
      }
      super.actionPerformed(oEvent);
    } catch (sortie.data.simpletypes.ModelException oErr) {
      ErrorGUI oHandler = new ErrorGUI(m_oChartFrame);
      oHandler.writeErrorMessage(oErr);
    }
  }
  @Override
  public void actionPerformed(ActionEvent e) {

    if (e.getActionCommand().startsWith("FILTRU")) {
      int length = Integer.parseInt(e.getActionCommand().substring(6));
      for (int index = 0; index < selection.size(); index++) {
        JCheckBox chk1 = (JCheckBox) selection.get(index);
        int productLength = Integer.parseInt(chk1.getName().substring(6));
        if (!filtru2m.isSelected() && !filtru3m.isSelected() && !filtru4m.isSelected()) {
          chk1.getParent().setVisible(true);
          continue;
        }
        if (productLength < 3000 && productLength >= 2000 && filtru2m.isSelected()) {
          chk1.getParent().setVisible(true);
        } else if (productLength < 4000 && productLength >= 3000 && filtru3m.isSelected()) {
          chk1.getParent().setVisible(true);
        } else if (productLength < 5000 && productLength >= 4000 && filtru4m.isSelected()) {
          chk1.getParent().setVisible(true);
        } else {
          chk1.getParent().setVisible(false);
        }
      }
      this.revalidate();
      return;
    }
    boolean valid = true;

    JLabel lenLabel = (JLabel) ((JPanel) getComponent(0)).getComponent(0);
    JFormattedTextField lenRadius =
        (JFormattedTextField) ((JPanel) getComponent(0)).getComponent(1);
    JComboBox<String> lenRadiusMetric =
        (JComboBox<String>) ((JPanel) getComponent(0)).getComponent(2);
    lenLabel.setForeground(Color.black);
    if (lenRadius.getValue() == null) {
      valid = false;
      lenLabel.setForeground(Color.red);
    }
    JLabel smallLabel = (JLabel) ((JPanel) getComponent(1)).getComponent(0);
    JFormattedTextField smallRadius =
        (JFormattedTextField) ((JPanel) getComponent(1)).getComponent(1);
    JComboBox<String> smallRadiusMetric =
        (JComboBox<String>) ((JPanel) getComponent(1)).getComponent(2);
    smallLabel.setForeground(Color.black);
    if (smallRadius.getValue() == null) {
      valid = false;
      smallLabel.setForeground(Color.red);
    }

    JLabel bigLabel = (JLabel) ((JPanel) getComponent(2)).getComponent(0);
    JFormattedTextField bigRadius =
        (JFormattedTextField) ((JPanel) getComponent(2)).getComponent(1);
    JComboBox<String> bigRadiusMetric =
        (JComboBox<String>) ((JPanel) getComponent(2)).getComponent(2);
    bigLabel.setForeground(Color.black);
    if (bigRadius.getValue() == null) {
      valid = false;
      bigLabel.setForeground(Color.red);
    }

    double minimumValue =
        METRIC.toMilimeter((Long) smallRadius.getValue(), smallRadiusMetric.getSelectedIndex());
    double maxmimumValue =
        METRIC.toMilimeter((Long) bigRadius.getValue(), bigRadiusMetric.getSelectedIndex());

    if (minimumValue > maxmimumValue) {
      smallLabel.setForeground(Color.red);
      bigLabel.setForeground(Color.red);
      valid = false;
    }

    boolean one = false;
    for (JCheckBox chk : selection) {
      if (chk.isSelected()) {
        one = true;
        break;
      }
    }
    if (!one) {
      label2.setForeground(Color.red);
      valid = false;
    } else {
      label2.setForeground(Color.black);
    }

    if (!valid) {
      return;
    }

    List<Product> selectedProducts = new ArrayList<Product>();
    for (int index = 0; index < selection.size(); index++) {
      if (selection.get(index).isSelected()) {
        selectedProducts.add(products.get(index));
      }
    }

    Map<String, Object> targetData = new HashMap<String, Object>();
    targetData.put("IDPLATE_LABEL", "Test");
    targetData.put("SELECTED_PRODUCTS", selectedProducts);
    DefaultCutOptionsCalculatorData data = new DefaultCutOptionsCalculatorData();
    data.setSelectedProducts(selectedProducts);

    List<LumberStack> stacks = LumberStackDAO.getAllstack();
    List<LumberLog> lumberLogs = new ArrayList<>();
    for (long start = (Long) smallRadius.getValue(); start < (Long) bigRadius.getValue(); start++) {
      LumberLog lumberLog = new LumberLog();
      lumberLog.setSmallRadius((double) start);
      List<Double> middleRadius = new ArrayList<>();
      middleRadius.add((double) start);
      lumberLog.setMediumRadius(middleRadius);
      lumberLog.setBigRadius((double) start);
      double lengthValue =
          METRIC.toMilimeter((Long) lenRadius.getValue(), lenRadiusMetric.getSelectedIndex());
      lumberLog.setLength(lengthValue);
      lumberLog.setRealLength((long) lengthValue);
      IDPlate plate = new IDPlate();
      plate.setId(-1L);
      LumberStack stack = LumberLogUtil.findLumberStack(lumberLog, stacks);
      String label = "Diametru " + start;
      if (stack != null) {
        label += " " + stack.getName();
      }
      plate.setLabel(label);
      lumberLog.setPlate(plate);
      LumberLogUtil.calculateVolume(lumberLog);
      lumberLogs.add(lumberLog);
    }
    data.setLumberLogs(lumberLogs);
    new CutOptionsTargetFrame(targetData, data);
    GUITools.closeParentDialog(this);
  }