1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20 package com.cosylab.gui.property.editors;
21
22 import javax.swing.JTextField;
23
24
25
26
27
28
29
30
31 public class StringEditor extends JTextField implements PropertyEditor {
32
33 private boolean nullAllowed = false;
34
35
36
37
38 public StringEditor() {
39 super();
40 }
41
42
43
44
45 public Object getPropertyValue() {
46 String ret=getText();
47 if (ret==null && !nullAllowed) {
48 ret="";
49 }
50 if (ret=="" && nullAllowed) {
51 ret=null;
52 }
53 return ret;
54 }
55
56
57
58
59 public boolean setPropertyValue(Object value) {
60 String old=getText();
61 if (value == null) {
62 setText("");
63 } else {
64 setText(String.valueOf(value));
65 }
66 if (!(old==null && value==null) && (old==null && old.equals(value))){
67 firePropertyChange(PROPERTY_VALUE_NAME,old,value);
68 }
69 return true;
70 }
71
72
73
74
75 public String getDescription() {
76 return null;
77 }
78
79
80
81
82 public void setDescription(String description) {
83 }
84
85
86
87
88 public PropertyEditor getEditor() {
89 return null;
90 }
91
92 public boolean isNullAllowed() {
93 return nullAllowed;
94 }
95
96 public void setNullAllowed(boolean allow) {
97 this.nullAllowed=allow;
98 }
99
100 }