View Javadoc
1   package com.github.celldynamics.quimp.plugin.protanalysis;
2   
3   import java.awt.event.ActionEvent;
4   
5   import javax.swing.JComboBox;
6   
7   import com.github.celldynamics.quimp.plugin.protanalysis.ProtAnalysisOptions.IEnumDataType;
8   
9   /**
10   * Action to set Enum based types.
11   * 
12   * <p>Set value for any datatype that implements {@link IEnumDataType} {@link ProtAnalysisOptions}.
13   * 
14   * @author p.baniukiewicz
15   *
16   */
17  @SuppressWarnings("serial")
18  public class ActionUpdateOptionsEnum extends ProtAnalysisAbstractAction {
19  
20    private IEnumDataType val;
21  
22    /**
23     * Main constructor.
24     * 
25     * @param name name
26     * @param desc description
27     * @param ui reference to outer class
28     * @param option reference to parameter to be changed
29     */
30    public ActionUpdateOptionsEnum(String name, String desc, ProtAnalysisUi ui,
31            IEnumDataType option) {
32      super(name, desc, ui);
33      this.val = option;
34    }
35  
36    /*
37     * (non-Javadoc)
38     * 
39     * @see
40     * com.github.celldynamics.quimp.plugin.protanalysis.ProtAnalysisAbstractAction#actionPerformed(
41     * java.awt.event.ActionEvent)
42     */
43    @Override
44    public void actionPerformed(ActionEvent e) {
45      JComboBox<?> cmp = ((JComboBox<?>) e.getSource());
46      Object item = cmp.getSelectedItem();
47      if (item instanceof Enum) { // for JComboBox<Number> just get selected value
48        logger.trace("val: " + item.toString());
49        val.setCurrent((Enum<?>) item);
50      } else {
51        throw new RuntimeException("This JComboBox is not supported");
52      }
53  
54      logger.trace(ui.getModel().getOptions().serialize());
55  
56    }
57  
58  }