1 |
mojays |
2 |
package skrueger.swing; |
2 |
|
|
|
3 |
|
|
import java.awt.BorderLayout; |
4 |
|
|
import java.awt.Dimension; |
5 |
|
|
import java.util.List; |
6 |
|
|
|
7 |
|
|
import javax.swing.BorderFactory; |
8 |
|
|
import javax.swing.JLabel; |
9 |
|
|
import javax.swing.JPanel; |
10 |
|
|
import javax.swing.SpringLayout; |
11 |
|
|
import javax.swing.SwingConstants; |
12 |
|
|
|
13 |
|
|
import org.apache.log4j.Logger; |
14 |
|
|
|
15 |
|
|
import schmitzm.swing.SpringUtilities; |
16 |
|
|
import skrueger.i8n.Translation; |
17 |
|
|
|
18 |
|
|
/** |
19 |
alfonx |
220 |
* A {@link JPanel} that asks the user for the translations of a String in |
20 |
|
|
* several languages. Use {@link TranslationAskJDialog} to display.<br/> |
21 |
|
|
* The class does not implement any backup/clong strategies. The |
22 |
|
|
* {@link Translation} object is manipulated directly.<br/> |
23 |
|
|
* {@link TranslationEditJPanel}s. {@link TranslationAskJDialog} implements a |
24 |
|
|
* transparent Apply/Cancel logic. |
25 |
|
|
* |
26 |
mojays |
2 |
* @author Stefan Alfons Krüger |
27 |
|
|
*/ |
28 |
|
|
public class TranslationEditJPanel extends JPanel { |
29 |
alfonx |
220 |
static final protected Logger LOGGER = Logger |
30 |
|
|
.getLogger(TranslationEditJPanel.class); |
31 |
|
|
|
32 |
alfonx |
38 |
private final List<String> languages; |
33 |
mojays |
2 |
private JPanel translationGrid; |
34 |
|
|
private Translation trans; |
35 |
|
|
|
36 |
alfonx |
220 |
/** |
37 |
|
|
* Creates a {@link JPanel} that asks the user for the translation of a |
38 |
|
|
* String in several languages |
39 |
|
|
*/ |
40 |
mojays |
2 |
public TranslationEditJPanel(Translation trans, List<String> languages_) { |
41 |
|
|
this(null, trans, languages_); |
42 |
|
|
} |
43 |
|
|
|
44 |
alfonx |
220 |
/** |
45 |
|
|
* Creates a {@link JPanel} that asks the user for the translation of a |
46 |
|
|
* String in several languages and additionally puts a {@link JLabel} with a |
47 |
|
|
* question at the {@link JPanel}'s first row. |
48 |
|
|
*/ |
49 |
mojays |
2 |
public TranslationEditJPanel(String question, Translation trans, |
50 |
|
|
List<String> languages_) { |
51 |
|
|
super(new BorderLayout()); |
52 |
|
|
|
53 |
alfonx |
220 |
if (trans == null) |
54 |
|
|
trans = new Translation(); |
55 |
|
|
|
56 |
mojays |
2 |
this.trans = trans; |
57 |
|
|
this.languages = languages_; |
58 |
alfonx |
220 |
|
59 |
mojays |
2 |
add(getTranslationGrid(), BorderLayout.CENTER); |
60 |
|
|
|
61 |
|
|
if (question != null) { |
62 |
|
|
JLabel questionLable = new JLabel(question); |
63 |
alfonx |
220 |
questionLable |
64 |
|
|
.setBorder(BorderFactory.createEmptyBorder(6, 6, 6, 6)); |
65 |
mojays |
2 |
add(questionLable, BorderLayout.NORTH); |
66 |
|
|
} |
67 |
|
|
} |
68 |
|
|
|
69 |
|
|
private JPanel getTranslationGrid() { |
70 |
|
|
if (translationGrid == null) { |
71 |
|
|
translationGrid = new JPanel(new SpringLayout()); |
72 |
|
|
|
73 |
|
|
for (String langId : languages) { |
74 |
|
|
|
75 |
|
|
// language code : entry field for translation |
76 |
|
|
JLabel langDesc = new JLabel(langId.toUpperCase() + " :"); // i8n |
77 |
|
|
langDesc.setHorizontalAlignment(SwingConstants.RIGHT); |
78 |
|
|
langDesc.setVerticalAlignment(SwingConstants.NORTH); |
79 |
|
|
|
80 |
|
|
TranslationJTextField langTextField = new TranslationJTextField( |
81 |
|
|
trans, langId); |
82 |
alfonx |
220 |
// Setting a size |
83 |
|
|
langTextField.setPreferredSize(new Dimension(360, 22)); |
84 |
mojays |
2 |
langDesc.setLabelFor(langTextField); |
85 |
|
|
translationGrid.add(langDesc); |
86 |
|
|
translationGrid.add(langTextField); |
87 |
|
|
} |
88 |
|
|
|
89 |
|
|
// Lay out the panel. |
90 |
|
|
SpringUtilities.makeCompactGrid(translationGrid, languages.size(), // rows, |
91 |
|
|
2, // cols |
92 |
|
|
6, 6, // initX, initY |
93 |
|
|
6, 6); // xPad, yPad |
94 |
|
|
|
95 |
|
|
} |
96 |
|
|
return translationGrid; |
97 |
|
|
} |
98 |
|
|
|
99 |
|
|
/** |
100 |
alfonx |
220 |
* @return The {@link Translation} that this {@link TranslationEditJPanel} |
101 |
|
|
* deals with. |
102 |
alfonx |
33 |
*/ |
103 |
mojays |
2 |
public Translation getTranslation() { |
104 |
|
|
return trans; |
105 |
|
|
} |
106 |
alfonx |
38 |
|
107 |
mojays |
2 |
} |