1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.components;
21
22 import java.awt.Component;
23 import java.beans.PropertyChangeEvent;
24 import java.beans.PropertyChangeListener;
25 import java.beans.PropertyEditorSupport;
26
27 import com.cosylab.gui.components.range2.RangedValuePolicy;
28
29
30
31
32
33
34
35
36 public class ValuePolicyPropertyEditor extends PropertyEditorSupport {
37
38 private ValuePolicyCustomizer editor;
39
40
41
42
43
44 public Component getCustomEditor() {
45 if (editor == null) {
46 editor = new ValuePolicyCustomizer();
47 editor.setValuePolicy((RangedValuePolicy)getValue());
48 editor.addPropertyChangeListener("valuePolicy", new PropertyChangeListener() {
49 public void propertyChange(PropertyChangeEvent evt) {
50 setValueSilently(editor.getValuePolicy());
51 }
52 });
53 }
54
55 return editor;
56 }
57
58
59
60
61
62 public String getJavaInitializationString() {
63 return "new " + getValue().getClass().getName()+"()";
64 }
65
66
67
68
69
70 public boolean supportsCustomEditor() {
71 return true;
72 }
73
74 private void setValueSilently(Object value) {
75 super.setValue(value);
76 }
77
78
79
80
81 @Override
82 public void setValue(Object value) {
83 super.setValue(value);
84 if (editor!=null) {
85 editor.setValuePolicy((RangedValuePolicy)value);
86 }
87 }
88 }