25 |
* |
* |
26 |
* Contributors: |
* Contributors: |
27 |
* Martin O. J. Schmitz - initial API and implementation |
* Martin O. J. Schmitz - initial API and implementation |
28 |
* Stefan A. Krüger - additional utility classes |
* Stefan A. Tzeggai - additional utility classes |
29 |
******************************************************************************/ |
******************************************************************************/ |
30 |
package skrueger.swing; |
package skrueger.swing; |
31 |
|
|
33 |
import java.awt.Dimension; |
import java.awt.Dimension; |
34 |
import java.awt.event.ActionEvent; |
import java.awt.event.ActionEvent; |
35 |
import java.awt.event.ActionListener; |
import java.awt.event.ActionListener; |
36 |
import java.util.HashSet; |
import java.util.HashMap; |
37 |
import java.util.List; |
import java.util.List; |
38 |
import java.util.Random; |
import java.util.Random; |
|
import java.util.Set; |
|
39 |
import java.util.WeakHashMap; |
import java.util.WeakHashMap; |
40 |
|
|
41 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
48 |
|
|
49 |
import schmitzm.swing.JPanel; |
import schmitzm.swing.JPanel; |
50 |
import schmitzm.swing.SpringUtilities; |
import schmitzm.swing.SpringUtilities; |
51 |
|
import schmitzm.swing.SwingUtil; |
52 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
53 |
|
|
54 |
/** |
/** |
59 |
* {@link TranslationEditJPanel}s. {@link TranslationAskJDialog} implements a |
* {@link TranslationEditJPanel}s. {@link TranslationAskJDialog} implements a |
60 |
* transparent Apply/Cancel logic. |
* transparent Apply/Cancel logic. |
61 |
* |
* |
62 |
* @author Stefan Alfons Krüger |
* @author Stefan Alfons Tzeggai |
63 |
*/ |
*/ |
64 |
public class TranslationEditJPanel extends JPanel { |
public class TranslationEditJPanel extends JPanel { |
65 |
static final protected Logger LOGGER = Logger |
static final protected Logger LOGGER = Logger |
72 |
/** |
/** |
73 |
* Remembers all {@link JTextField} that have been created. |
* Remembers all {@link JTextField} that have been created. |
74 |
*/ |
*/ |
75 |
private Set<TranslationJTextField> langTextFields = new HashSet<TranslationJTextField>(); |
private HashMap<String, TranslationJTextField> langTextFields = new HashMap<String, TranslationJTextField>(); |
76 |
private WeakHashMap<ActionListener, ActionListener> actionListeners = new WeakHashMap<ActionListener, ActionListener>(); |
private WeakHashMap<ActionListener, ActionListener> actionListeners = new WeakHashMap<ActionListener, ActionListener>(); |
77 |
|
|
78 |
|
private final String question; |
79 |
|
|
80 |
/** |
/** |
81 |
* Creates a {@link JPanel} that asks the user for the translation of a |
* Creates a {@link JPanel} that asks the user for the translation of a |
82 |
* String in several languages |
* String in several languages |
93 |
public TranslationEditJPanel(String question, Translation trans, |
public TranslationEditJPanel(String question, Translation trans, |
94 |
List<String> languages_) { |
List<String> languages_) { |
95 |
super(new BorderLayout()); |
super(new BorderLayout()); |
96 |
|
this.question = question; |
97 |
|
|
98 |
|
SwingUtil.setMinimumWidth(this, 400); |
99 |
|
|
100 |
if (trans == null) |
if (trans == null) |
101 |
trans = new Translation(); |
trans = new Translation(); |
103 |
this.trans = trans; |
this.trans = trans; |
104 |
this.languages = languages_; |
this.languages = languages_; |
105 |
|
|
106 |
|
initGUI(); |
107 |
|
} |
108 |
|
|
109 |
|
private void initGUI() { |
110 |
add(getTranslationGrid(), BorderLayout.CENTER); |
add(getTranslationGrid(), BorderLayout.CENTER); |
111 |
|
|
112 |
if (question != null) { |
if (question != null) { |
115 |
.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
116 |
add(questionLable, BorderLayout.NORTH); |
add(questionLable, BorderLayout.NORTH); |
117 |
} |
} |
|
|
|
|
/** |
|
|
* Add listeners |
|
|
*/ |
|
118 |
} |
} |
119 |
|
|
120 |
/** |
/** |
143 |
langDesc.setHorizontalAlignment(SwingConstants.RIGHT); |
langDesc.setHorizontalAlignment(SwingConstants.RIGHT); |
144 |
langDesc.setVerticalAlignment(SwingConstants.NORTH); |
langDesc.setVerticalAlignment(SwingConstants.NORTH); |
145 |
|
|
146 |
TranslationJTextField langTextField = new TranslationJTextField( |
TranslationJTextField langTextField = langTextFields |
147 |
trans, langId); |
.get(langId); |
148 |
// Setting a size |
|
149 |
langTextField.setPreferredSize(new Dimension(360, 22)); |
if (langTextField == null) { |
150 |
langDesc.setLabelFor(langTextField); |
langTextField = new TranslationJTextField(trans, langId); |
151 |
|
// Setting a size |
152 |
|
langTextField.setPreferredSize(new Dimension(360, 22)); |
153 |
|
langDesc.setLabelFor(langTextField); |
154 |
|
} |
155 |
|
|
156 |
translationGrid.add(langDesc); |
translationGrid.add(langDesc); |
157 |
translationGrid.add(langTextField); |
translationGrid.add(langTextField); |
158 |
|
|
159 |
langTextFields.add(langTextField); |
langTextFields.put(langId, langTextField); |
160 |
} |
} |
161 |
|
|
162 |
// Lay out the panel. |
// Lay out the panel. |
181 |
* TODO Is never called?! |
* TODO Is never called?! |
182 |
*/ |
*/ |
183 |
public void dispose() { |
public void dispose() { |
184 |
for (TranslationJTextField f: langTextFields) { |
for (TranslationJTextField f : langTextFields.values()) { |
185 |
f.dispose(); |
f.dispose(); |
186 |
} |
} |
187 |
|
langTextFields.clear(); |
188 |
} |
} |
189 |
|
|
190 |
public void addTranslationChangeListener(final ActionListener al) { |
public void addTranslationChangeListener(final ActionListener al) { |
209 |
} |
} |
210 |
} |
} |
211 |
|
|
212 |
|
|
213 |
} |
} |