View Javadoc

1   /*
2    * @(#)$Id: MapTextFieldBinding.java 742 2009-08-15 17:15:49Z 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  package org.ximtec.igesture.tool.binding;
27  
28  import javax.swing.JTextField;
29  
30  import org.ximtec.igesture.configuration.Configuration;
31  
32  
33  public class MapTextFieldBinding extends DataBinding<JTextField> {
34  
35     private JTextField textField;
36     private String algorithm;
37  
38  
39     public MapTextFieldBinding(JTextField textField, Configuration configuration, String property, String algorithm) {
40        super(configuration, property);
41        this.textField = textField;
42        this.algorithm = algorithm;
43        this.textField.addFocusListener(this);
44        updateView();
45     }
46  
47  
48     @Override
49     public JTextField getComponent() {
50        return textField;
51     }
52  
53  
54     @Override
55     protected void updateView() {
56        textField.setText(getValue());
57     }
58  
59  
60     @Override
61     protected void updateModel() {
62        setValue(textField.getText());
63     }
64     
65     /**
66      * Read a value from the data object
67      * 
68      * @return
69      */
70     @Override
71     protected String getValue() {
72       return ((Configuration)getObject()).getParameters(algorithm).get(getProperty());
73     }
74     
75     @Override
76     protected void setValue(Object value) {
77        if(!getValue().equals(value)){
78           ((Configuration)getObject()).addParameter(algorithm, getProperty(), (String)value);
79        }
80        
81     }
82     
83     
84  }