View Javadoc

1   /*
2    * @(#)$Id: AddConfigurationAction.java 692 2009-07-24 18:28:20Z kurmannu $
3    *
4    * Author		:	Ueli Kurmann, igesture@uelikurmann.ch
5    *                  
6    *
7    * Purpose		: 
8    *
9    * -----------------------------------------------------------------------
10   *
11   * Revision Information:
12   *
13   * Date				Who			Reason
14   *
15   * 23.03.2008			ukurmann	Initial Release
16   *
17   * -----------------------------------------------------------------------
18   *
19   * Copyright 1999-2009 ETH Zurich. All Rights Reserved.
20   *
21   * This software is the proprietary information of ETH Zurich.
22   * Use is subject to license terms.
23   * 
24   */
25  
26  
27  package org.ximtec.igesture.tool.view.testbench.action;
28  
29  import java.awt.event.ActionEvent;
30  
31  import javax.swing.tree.TreePath;
32  
33  import org.ximtec.igesture.algorithm.Algorithm;
34  import org.ximtec.igesture.algorithm.AlgorithmFactory;
35  import org.ximtec.igesture.configuration.Configuration;
36  import org.ximtec.igesture.tool.GestureConstants;
37  import org.ximtec.igesture.tool.core.Controller;
38  import org.ximtec.igesture.tool.core.TreePathAction;
39  import org.ximtec.igesture.tool.view.testbench.wrapper.AlgorithmWrapper;
40  
41  
42  /**
43   * Comment
44   * @version 1.0 23.03.2008
45   * @author Ueli Kurmann
46   */
47  public class AddConfigurationAction extends TreePathAction {
48  
49     public AddConfigurationAction(Controller controller, TreePath treePath) {
50        super(GestureConstants.CONFIGURATION_ADD, controller, treePath);
51     }
52  
53  
54     @Override
55     public void actionPerformed(ActionEvent arg0) {
56  
57        AlgorithmWrapper algorithWrapper = (AlgorithmWrapper)getTreePath()
58              .getLastPathComponent();
59        Configuration configuration = new Configuration();
60        String algorithmName = algorithWrapper.getAlgorithm().getName();
61        Algorithm algorithm = AlgorithmFactory
62        .createAlgorithmInstance(algorithmName);
63        
64        configuration.addAlgorithm(algorithmName);
65        
66        for (Enum< ? > e : algorithm.getConfigParameters()) {
67           configuration.addParameter(algorithmName, e.name(), algorithm
68                 .getDefaultParameterValue(e.name()));
69        }
70        
71        algorithWrapper.addConfiguration(configuration);
72  
73        
74  
75     }
76  
77  }