View Javadoc

1   /**
2    * 
3    */
4   package org.ximtec.igesture.tool.binding;
5   
6   import javax.swing.JTextField;
7   
8   import org.ximtec.igesture.core.composite.Constraint;
9   import org.ximtec.igesture.core.composite.DefaultConstraint;
10  
11  /**
12   * @author Bjorn Puype, bpuype@gmail.com
13   *
14   */
15  public class ConstraintTextFieldBinding extends DataBinding<JTextField> {
16  
17  	private JTextField textField;
18  	private Constraint constraint;
19  	
20  	/**
21  	 * @param dataObject
22  	 * @param property
23  	 */
24  	public ConstraintTextFieldBinding(JTextField textField, Constraint constraint, String property) {
25  		super((DefaultConstraint)constraint, property);
26  		this.textField = textField;
27  		this.textField.addFocusListener(this);
28  		this.constraint = constraint;
29  		updateView();
30  	}
31  
32  	/* (non-Javadoc)
33  	 * @see org.ximtec.igesture.tool.binding.DataBinding#getComponent()
34  	 */
35  	@Override
36  	public JTextField getComponent() {
37  		return textField;
38  	}
39  
40  	/* (non-Javadoc)
41  	 * @see org.ximtec.igesture.tool.binding.DataBinding#updateModel()
42  	 */
43  	@Override
44  	protected void updateModel() {
45  		setValue(textField.getText());
46  	}
47  
48  	/* (non-Javadoc)
49  	 * @see org.ximtec.igesture.tool.binding.DataBinding#updateView()
50  	 */
51  	@Override
52  	protected void updateView() {
53  		textField.setText(getValue());
54  	}
55  	
56  	@Override
57  	protected String getValue() {
58  		return ((Constraint)getObject()).getParameter(getProperty());
59      }
60  	   
61  	@Override
62  	protected void setValue(Object value) {
63  		if(!getValue().equals(value)){
64  			((Constraint)getObject()).setParameter(getProperty(), (String)value);
65  		}      
66  	}
67  
68  }