1 /*
2 * Copyright (c) 2003-2008 by Cosylab d. d.
3 *
4 * This file is part of CosyBeans-Common.
5 *
6 * CosyBeans-Common is free software: you can redistribute it and/or modify
7 * it under the terms of the GNU General Public License as published by
8 * the Free Software Foundation, either version 3 of the License, or
9 * (at your option) any later version.
10 *
11 * CosyBeans-Common is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with CosyBeans-Common. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20 package com.cosylab.gui.property.editors;
21
22 import javax.swing.JTextField;
23
24
25 /**
26 * description
27 *
28 * @author <a href="mailto:ales.pucelj@cosylab.com">Ales Pucelj</a>
29 * @version $id$
30 */
31 public class StringEditor extends JTextField implements PropertyEditor {
32
33 private boolean nullAllowed = false;
34
35 /**
36 * Constructor for StringEditor.
37 */
38 public StringEditor() {
39 super();
40 }
41
42 /**
43 * @see PropertyEditor#getValue()
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 * @see PropertyEditor#setValue(Object)
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 * @see PropertyEditor#getDescription()
74 */
75 public String getDescription() {
76 return null;
77 }
78
79 /**
80 * @see PropertyEditor#setDescription(String)
81 */
82 public void setDescription(String description) {
83 }
84
85 /**
86 * @see PropertyEditor#getEditor()
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 }