47 |
* |
* |
48 |
*/ |
*/ |
49 |
public class TranslationJTextField extends JTextField { |
public class TranslationJTextField extends JTextField { |
50 |
static final Logger log = Logger.getLogger(TranslationJTextField.class); |
static final protected Logger LOGGER = Logger |
51 |
int wasValid = 99; // 0 = false, 1 = true, 99 = undefined |
.getLogger(TranslationJTextField.class); |
52 |
|
int wasValid = 99; // 0 = false, 1 = true, 99 = undefined |
53 |
private String langCode; |
private String langCode; |
54 |
private Translation trans; |
private Translation trans; |
55 |
|
|
56 |
/** |
/** |
57 |
* This RED indicates a missing translation |
* This RED indicates a missing translation |
58 |
* |
* |
59 |
* TODO to properties ;-) |
* TODO to properties ;-) |
60 |
*/ |
*/ |
61 |
final static public Color emptyColor = new Color(240,190,190); |
final static public Color emptyColor = new Color(240, 190, 190); |
62 |
|
|
63 |
/** |
/** |
64 |
* Creates a new {@link TranslationJTextField} |
* Creates a new {@link TranslationJTextField} |
65 |
* @param trans |
* |
66 |
|
* @param trans |
67 |
* @param langCode |
* @param langCode |
68 |
*/ |
*/ |
69 |
public TranslationJTextField(Translation trans, String langCode) { |
public TranslationJTextField(Translation trans, String langCode) { |
70 |
super(trans.get(langCode)); |
super(trans.get(langCode)); |
71 |
this.trans = trans; |
this.trans = trans; |
72 |
this.langCode = langCode; |
this.langCode = langCode; |
73 |
|
|
74 |
/** SK: Change 26.Mai |
/** |
75 |
* Use the default for an empty field **/ |
* SK: Change 26.Mai Use the default for an empty field |
76 |
|
**/ |
77 |
if (trans.get(langCode) == null) { |
if (trans.get(langCode) == null) { |
78 |
String defaultTrans = trans.get( Translation.DEFAULT_KEY); |
String defaultTrans = trans.get(Translation.DEFAULT_KEY); |
79 |
trans.put(langCode, defaultTrans); |
trans.put(langCode, defaultTrans); |
80 |
setText( defaultTrans ); |
setText(defaultTrans); |
81 |
} |
} |
82 |
|
|
83 |
checkValid(); |
checkValid(); |
84 |
|
|
85 |
// This Listener colors the JTextfiel red if it is empty |
// This Listener colors the JTextfiel red if it is empty |
105 |
} |
} |
106 |
|
|
107 |
/** |
/** |
108 |
* If the getText == "". then set Background color red. |
* If the getText().equals("") sets background color to red. The method also |
109 |
* This change is only done if the state really changed. |
* stored the changed string into the {@link Translation} object. |
|
* And directly store the change in the {@link Translation} object |
|
110 |
*/ |
*/ |
111 |
protected void checkValid() { |
protected void checkValid() { |
112 |
|
|
113 |
String trimmedText = getText().trim(); |
String trimmedText = getText().trim(); |
114 |
|
|
115 |
if (trimmedText.equals("")) { |
if (trimmedText.equals("")) { |
116 |
// Not valid |
// Not valid |
117 |
if (wasValid != 0) { |
if (wasValid != 0) { |
118 |
setBackground( emptyColor ); |
setBackground(emptyColor); |
119 |
repaint(); |
repaint(); |
120 |
wasValid = 0; |
wasValid = 0; |
121 |
} |
} |
122 |
|
|
123 |
// TODO testen! hat sich das bewährt? |
|
|
// Directly store the change in the Translation Object |
|
|
// trans.remove( langCode ); |
|
|
trans.put( langCode, trimmedText ); |
|
|
|
|
124 |
} else { |
} else { |
125 |
// valid |
// valid |
126 |
if (wasValid != 1) { |
if (wasValid != 1) { |
129 |
wasValid = 1; |
wasValid = 1; |
130 |
} |
} |
131 |
// Directly store the change in the Translation Object |
// Directly store the change in the Translation Object |
|
trans.put( langCode, trimmedText ); |
|
132 |
} |
} |
|
|
|
|
} |
|
133 |
|
|
134 |
|
// LOGGER.debug("putting '"+trimmedText+"' into the translation"); |
135 |
|
trans.put(langCode, trimmedText); |
136 |
|
} |
137 |
} |
} |