2 |
|
|
3 |
import java.awt.BorderLayout; |
import java.awt.BorderLayout; |
4 |
import java.awt.Dimension; |
import java.awt.Dimension; |
|
import java.awt.Frame; |
|
|
import java.awt.Window; |
|
|
import java.awt.event.ActionEvent; |
|
|
import java.awt.event.WindowAdapter; |
|
|
import java.awt.event.WindowEvent; |
|
|
import java.awt.event.WindowListener; |
|
|
import java.util.ArrayList; |
|
5 |
import java.util.List; |
import java.util.List; |
6 |
|
|
|
import javax.swing.AbstractAction; |
|
7 |
import javax.swing.BorderFactory; |
import javax.swing.BorderFactory; |
|
import javax.swing.Box; |
|
|
import javax.swing.JComponent; |
|
|
import javax.swing.JDialog; |
|
8 |
import javax.swing.JLabel; |
import javax.swing.JLabel; |
9 |
import javax.swing.JPanel; |
import javax.swing.JPanel; |
10 |
import javax.swing.SpringLayout; |
import javax.swing.SpringLayout; |
13 |
import org.apache.log4j.Logger; |
import org.apache.log4j.Logger; |
14 |
|
|
15 |
import schmitzm.swing.SpringUtilities; |
import schmitzm.swing.SpringUtilities; |
|
import schmitzm.swing.SwingUtil; |
|
16 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
17 |
|
|
18 |
/** |
/** |
19 |
* A JPanel that asks the user for translation of several strings |
* A {@link JPanel} that asks the user for translation of several strings |
20 |
* @author Stefan Alfons Krüger |
* @author Stefan Alfons Krüger |
21 |
* |
* |
22 |
*/ |
*/ |
23 |
public class TranslationEditJPanel extends JPanel { |
public class TranslationEditJPanel extends JPanel { |
24 |
public static final String PROPERTY_CANCEL_AND_CLOSE = "CANCEL"; |
static final protected Logger LOGGER = Logger.getLogger(TranslationEditJPanel.class); |
|
public static final String PROPERTY_APPLY_AND_CLOSE = "APPLY"; |
|
|
private static JDialog dialog; |
|
|
private static OkButton okButton; |
|
25 |
|
|
26 |
private static CancelButton cancelButton; |
private final List<String> languages; |
|
Logger log = Logger.getLogger(TranslationEditJPanel.class); |
|
|
private List<String> languages; |
|
27 |
private JPanel translationGrid; |
private JPanel translationGrid; |
28 |
private Translation trans; |
private Translation trans; |
29 |
|
|
40 |
this.trans = trans; |
this.trans = trans; |
41 |
this.languages = languages_; |
this.languages = languages_; |
42 |
|
|
|
|
|
|
|
|
43 |
add(getTranslationGrid(), BorderLayout.CENTER); |
add(getTranslationGrid(), BorderLayout.CENTER); |
44 |
|
|
45 |
if (question != null) { |
if (question != null) { |
80 |
return translationGrid; |
return translationGrid; |
81 |
} |
} |
82 |
|
|
83 |
/** |
// /** |
84 |
* Merges a few {@link TranslationEditJPanel}s and shows them together.. |
// * Merges a few {@link TranslationEditJPanel}s and shows them together.. |
85 |
* So far this is working on the Translation object directly, Cancel not possible. |
// * So far this is working on the Translation object directly, Cancel not possible. |
86 |
* @param translationEditJPanel |
// * @param translationEditJPanel |
87 |
* |
// * |
88 |
* @deprecated Use {@link TranslationAskJDialog} |
// * @deprecated Use {@link TranslationAskJDialog} |
89 |
*/ |
// */ |
90 |
public static void ask(Frame parentFrame, final TranslationEditJPanel... translationEditJPanels) { |
// public static void ask(Frame parentFrame, final TranslationEditJPanel... translationEditJPanels) { |
91 |
dialog = new JDialog(parentFrame); |
// dialog = new JDialog(parentFrame); |
92 |
// backup( translationEditJPanels ); |
// // backup( translationEditJPanels ); |
93 |
showDialog(dialog, translationEditJPanels); |
// showDialog(dialog, translationEditJPanels); |
94 |
} |
// } |
95 |
|
// |
96 |
|
// |
97 |
/** |
// /** |
98 |
* Merges a few {@link TranslationEditJPanel}s and shows them together.. |
// * Merges a few {@link TranslationEditJPanel}s and shows them together.. |
99 |
* So far this is working on the Translation object directly, Cancel not possible. |
// * So far this is working on the Translation object directly, Cancel not possible. |
100 |
* @param translationEditJPanel |
// * @param translationEditJPanel |
101 |
|
// |
102 |
* @deprecated User {@link TranslationAskJDialog} * |
// * @deprecated User {@link TranslationAskJDialog} * |
103 |
*/ |
// */ |
104 |
public static void ask(Window parentWindow, TranslationEditJPanel... translationEditJPanels) { |
// public static void ask(Window parentWindow, TranslationEditJPanel... translationEditJPanels) { |
105 |
dialog = new JDialog(parentWindow); |
// dialog = new JDialog(parentWindow); |
106 |
// backup( translationEditJPanels ); |
// // backup( translationEditJPanels ); |
107 |
showDialog(dialog, translationEditJPanels); |
// showDialog(dialog, translationEditJPanels); |
108 |
} |
// } |
109 |
|
// |
110 |
/** |
// /** |
111 |
* Merges a few {@link TranslationEditJPanel}s and shows them together.. |
// * Merges a few {@link TranslationEditJPanel}s and shows them together.. |
112 |
* So far this is working on the Translation object directly, Cancel not possible. |
// * So far this is working on the Translation object directly, Cancel not possible. |
113 |
* @param translationEditJPanel |
// * @param translationEditJPanel |
114 |
* |
// * |
115 |
* * @deprecated User {@link TranslationAskJDialog} |
// * * @deprecated User {@link TranslationAskJDialog} |
116 |
*/ |
// */ |
117 |
public static void ask(JDialog parentDialog, TranslationEditJPanel... translationEditJPanels) { |
// public static void ask(JDialog parentDialog, TranslationEditJPanel... translationEditJPanels) { |
118 |
dialog = new JDialog(parentDialog); |
// dialog = new JDialog(parentDialog); |
119 |
// backup( translationEditJPanels ); |
// // backup( translationEditJPanels ); |
120 |
showDialog(dialog, translationEditJPanels); |
// showDialog(dialog, translationEditJPanels); |
121 |
} |
// } |
122 |
|
// |
123 |
|
// |
124 |
|
// /** |
125 |
|
// * * @deprecated User {@link TranslationAskJDialog} |
126 |
|
// * @param d |
127 |
|
// * @param translationEditJPanels |
128 |
|
// * @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
129 |
|
// */ |
130 |
|
// public static void showDialog(JDialog d, JComponent... translationEditJPanels) { |
131 |
|
// dialog = d; |
132 |
|
// dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); |
133 |
|
// SwingUtil.centerFrameOnScreen(dialog); |
134 |
|
// Box box = Box.createVerticalBox(); |
135 |
|
// for (JComponent panel : translationEditJPanels) { |
136 |
|
// box.add(panel); |
137 |
|
// } |
138 |
|
// JPanel cp = new JPanel( new BorderLayout()); |
139 |
|
// cp.add( box, BorderLayout.CENTER); |
140 |
|
// cp.add( getButtons(), BorderLayout.SOUTH ); |
141 |
|
// dialog.setContentPane(cp); |
142 |
|
// |
143 |
|
// // dialog.getRootPane().setDefaultButton(okButton); |
144 |
|
// |
145 |
|
// dialog.setTitle("Please translate"); //i8n |
146 |
|
// dialog.setModal(true); |
147 |
|
// dialog.pack(); |
148 |
|
// dialog.setVisible(true); |
149 |
|
// } |
150 |
|
// |
151 |
|
// /** |
152 |
|
// * @deprecated Use TranslationAskJDialog |
153 |
|
// * @return |
154 |
|
// * @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
155 |
|
// */ |
156 |
|
// private static JComponent getButtons() { |
157 |
|
// JPanel jPanel = new JPanel(); |
158 |
|
// if (okButton == null) { |
159 |
|
// okButton = new OkButton(new AbstractAction("enter") { |
160 |
|
// public void actionPerformed(ActionEvent evt) { |
161 |
|
// firePropertyChange(PROPERTY_APPLY_AND_CLOSE, null, null); |
162 |
|
// dialog.dispose(); |
163 |
|
// } |
164 |
|
// } ); |
165 |
|
// } |
166 |
|
// jPanel.add(okButton); |
167 |
|
// |
168 |
|
// if (cancelButton == null) { |
169 |
|
// cancelButton = new CancelButton(new AbstractAction("") { |
170 |
|
// public void actionPerformed(ActionEvent evt) { |
171 |
|
// // restore(); |
172 |
|
// firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
173 |
|
// dialog.dispose(); |
174 |
|
// } |
175 |
|
// } ); |
176 |
|
// } |
177 |
|
// jPanel.add(okButton); |
178 |
|
// |
179 |
|
// return jPanel; |
180 |
|
// } |
181 |
|
|
182 |
/** |
/** |
183 |
* * @deprecated User {@link TranslationAskJDialog} |
* @return The {@link Translation} that this {@link TranslationEditJPanel} deals with. |
|
* @param d |
|
|
* @param translationEditJPanels |
|
|
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
|
|
*/ |
|
|
public static void showDialog(JDialog d, JComponent... translationEditJPanels) { |
|
|
dialog = d; |
|
|
dialog.setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE); |
|
|
SwingUtil.centerFrameOnScreen(dialog); |
|
|
Box box = Box.createVerticalBox(); |
|
|
for (JComponent panel : translationEditJPanels) { |
|
|
box.add(panel); |
|
|
} |
|
|
JPanel cp = new JPanel( new BorderLayout()); |
|
|
cp.add( box, BorderLayout.CENTER); |
|
|
cp.add( getButtons(), BorderLayout.SOUTH ); |
|
|
dialog.setContentPane(cp); |
|
|
|
|
|
// dialog.getRootPane().setDefaultButton(okButton); |
|
|
|
|
|
dialog.setTitle("Please translate"); //i8n |
|
|
dialog.setModal(true); |
|
|
dialog.pack(); |
|
|
dialog.setVisible(true); |
|
|
} |
|
|
|
|
|
/** |
|
|
* @deprecated Use TranslationAskJDialog |
|
|
* @return |
|
|
* @author <a href="mailto:[email protected]">Stefan Alfons Krüger</a> |
|
184 |
*/ |
*/ |
|
private static JComponent getButtons() { |
|
|
JPanel jPanel = new JPanel(); |
|
|
if (okButton == null) { |
|
|
okButton = new OkButton(new AbstractAction("enter") { |
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
firePropertyChange(PROPERTY_APPLY_AND_CLOSE, null, null); |
|
|
dialog.dispose(); |
|
|
} |
|
|
} ); |
|
|
} |
|
|
jPanel.add(okButton); |
|
|
|
|
|
if (cancelButton == null) { |
|
|
cancelButton = new CancelButton(new AbstractAction("") { |
|
|
public void actionPerformed(ActionEvent evt) { |
|
|
// restore(); |
|
|
firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
|
|
dialog.dispose(); |
|
|
} |
|
|
} ); |
|
|
} |
|
|
jPanel.add(okButton); |
|
|
|
|
|
return jPanel; |
|
|
} |
|
|
|
|
185 |
public Translation getTranslation() { |
public Translation getTranslation() { |
186 |
return trans; |
return trans; |
187 |
} |
} |
188 |
// |
|
|
// |
|
|
// public static void main(String[] args) { |
|
|
// ArrayList<String> lang = new ArrayList <String> (); |
|
|
// lang.add("de"); |
|
|
// lang.add("en"); |
|
|
// lang.add("fr"); |
|
|
// |
|
|
// Translation transe = new Translation(); |
|
|
// transe.put("de", "Terciopelo-Lanzenotter"); |
|
|
// TranslationEditJPanel p1 = new TranslationEditJPanel("Name von New Group", |
|
|
// transe, lang); |
|
|
// |
|
|
// |
|
|
// Translation transe2 = new Translation(); |
|
|
// transe2.put("de", "Terciopelo-Lanzenotter (Bothrops asper) ist eine in Mittelamerika und im Nordwesten Südamerikas weit verbreitete Schlangenart."); |
|
|
// TranslationEditJPanel p2 = new TranslationEditJPanel("Description of Animal:", |
|
|
// transe2, lang); |
|
|
// |
|
|
//// JFrame frame = new JFrame(); |
|
|
//// frame.setContentPane(p1); |
|
|
//// frame.pack(); |
|
|
//// frame.setVisible(true); |
|
|
// |
|
|
// ask(new Frame(),p1,p2); |
|
|
// } |
|
189 |
} |
} |