/*
   * (non-Javadoc)
   *
   * @see
   * java.awt.event.ActionListener#actionPerformed(java.awt.event.ActionEvent)
   */
  public void actionPerformed(ActionEvent e) {
    if (!panel.isEnableValueChangedEvent()) return;

    // Cambio combo de bandas seleccionadas para la conversión a B/W
    if (e.getSource() == panel.getComboBands()) {
      String value = (String) panel.getComboBands().getSelectedItem();
      if (value.compareTo("R") == 0) data.setBandType(GrayScaleFilter.R);
      if (value.compareTo("G") == 0) data.setBandType(GrayScaleFilter.G);
      if (value.compareTo("B") == 0) data.setBandType(GrayScaleFilter.B);
      if (value.compareTo("RGB") == 0) data.setBandType(GrayScaleFilter.RGB);
      if (value.compareTo(PluginServices.getText(null, "gray")) == 0)
        data.setBandType(GrayScaleFilter.GRAY);
    }

    // Check de activar/desactivar posterización
    if (e.getSource() == panel.getPosterizationPanel().getActive()) {
      data.setPosterizationActive(panel.getPosterizationPanel().getActive().isSelected());
    }

    // Slider para el umbral de posterización
    if (e.getSource() == panel.getPosterizationPanel().getThreshold().getSlider()) {
      data.setPosterizationThreshold((int) panel.getPosterizationPanel().getThreshold().getValue());
    }

    // Check de activar/desactivar ruido
    if (e.getSource() == panel.getNoisePanel().getActive()) {
      data.setNoiseActive(panel.getNoisePanel().getActive().isSelected());
    }

    // Slider para el umbral de ruido
    if (e.getSource() == panel.getNoisePanel().getThreshold().getSlider()) {
      data.setNoiseThreshold((int) panel.getNoisePanel().getThreshold().getValue());
    }

    // Check de activar/desactivar moda
    if (e.getSource() == panel.getModePanel().getActive()) {
      data.setModeActive(panel.getModePanel().getActive().isSelected());
    }

    // Slider para el umbral de moda
    if (e.getSource() == panel.getModePanel().getThreshold().getSlider()) {
      data.setModeThreshold((int) panel.getModePanel().getThreshold().getValue());
    }

    // Check de activar/desactivar el paso alto
    /*
     * if(e.getSource() == panel.getHighPassPanel().getActive()) {
     * data.setHighPassActive
     * (panel.getHighPassPanel().getActive().isSelected()); }
     */

    refreshPreview();
  }
  /*
   * (non-Javadoc)
   *
   * @see
   * org.gvsig.gui.beans.slidertext.listeners.SliderListener#actionValueChanged
   * (org.gvsig.gui.beans.slidertext.listeners.SliderEvent)
   */
  public void actionValueChanged(SliderEvent e) {
    if (!panel.isEnableValueChangedEvent()) return;

    // Evento de movimiento del slider de cambio de umbral de posterización
    if (e.getSource() == panel.getPosterizationPanel().getThreshold())
      data.setPosterizationThreshold((int) panel.getPosterizationPanel().getThreshold().getValue());

    // Evento de movimiento del slider de cambio de umbral de reducción de
    // ruido
    if (e.getSource() == panel.getNoisePanel().getThreshold())
      data.setNoiseThreshold((int) panel.getNoisePanel().getThreshold().getValue());

    // Evento de movimiento del slider de cambio de umbral de moda
    if (e.getSource() == panel.getModePanel().getThreshold())
      data.setModeThreshold((int) panel.getModePanel().getThreshold().getValue());

    refreshPreview();
  }
  /** Captura los eventos de las cajas de texto */
  public void actionValueChanged(EventObject e) {
    if (!panel.isEnableValueChangedEvent()) return;

    // Niveles de la posterización
    if (e.getSource() == panel.getPosterizationPanel().getLevels().getDataInputField()) {
      String value = panel.getPosterizationPanel().getLevels().getValue();
      try {
        double doubleValue = Double.valueOf(value);
        if (doubleValue < 2) throw new NumberFormatException();
      } catch (NumberFormatException ex) {
        panel.setEnableValueChangedEvent(false);
        value = 2 + "";
        panel.getPosterizationPanel().getLevels().setValue(value);
        panel.setEnableValueChangedEvent(true);
      }

      data.setPosterizationLevels((int) Double.parseDouble(value));
      if ((int) Double.parseDouble(value) == 2)
        panel.getPosterizationPanel().getThreshold().setControlEnabled(true);
      else panel.getPosterizationPanel().getThreshold().setControlEnabled(false);
      refreshPreview();
    }
  }