01: /**
02: * L2FProd.com Common Components 7.3 License.
03: *
04: * Copyright 2005-2007 L2FProd.com
05: *
06: * Licensed under the Apache License, Version 2.0 (the "License");
07: * you may not use this file except in compliance with the License.
08: * You may obtain a copy of the License at
09: *
10: * http://www.apache.org/licenses/LICENSE-2.0
11: *
12: * Unless required by applicable law or agreed to in writing, software
13: * distributed under the License is distributed on an "AS IS" BASIS,
14: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
15: * See the License for the specific language governing permissions and
16: * limitations under the License.
17: */package com.l2fprod.common.beans.editor;
18:
19: import com.l2fprod.common.swing.LookAndFeelTweaks;
20: import com.l2fprod.common.util.converter.ConverterRegistry;
21:
22: import javax.swing.JTextField;
23: import javax.swing.text.JTextComponent;
24:
25: /**
26: * StringConverterPropertyEditor. <br>A comma separated list of values.
27: */
28: public abstract class StringConverterPropertyEditor extends
29: AbstractPropertyEditor {
30:
31: private Object oldValue;
32:
33: public StringConverterPropertyEditor() {
34: editor = new JTextField();
35: ((JTextField) editor).setBorder(LookAndFeelTweaks.EMPTY_BORDER);
36: }
37:
38: public Object getValue() {
39: String text = ((JTextComponent) editor).getText();
40: if (text == null || text.trim().length() == 0) {
41: return null;
42: } else {
43: try {
44: return convertFromString(text.trim());
45: } catch (Exception e) {
46: /*UIManager.getLookAndFeel().provideErrorFeedback(editor);*/
47: return oldValue;
48: }
49: }
50: }
51:
52: public void setValue(Object value) {
53: if (value == null) {
54: ((JTextComponent) editor).setText("");
55: } else {
56: oldValue = value;
57: ((JTextComponent) editor).setText(convertToString(value));
58: }
59: }
60:
61: protected abstract Object convertFromString(String text);
62:
63: protected String convertToString(Object value) {
64: return (String) ConverterRegistry.instance().convert(
65: String.class, value);
66: }
67:
68: }
|