13 |
|
|
14 |
import javax.swing.AbstractAction; |
import javax.swing.AbstractAction; |
15 |
import javax.swing.Action; |
import javax.swing.Action; |
16 |
|
import javax.swing.BorderFactory; |
17 |
import javax.swing.Box; |
import javax.swing.Box; |
18 |
|
import javax.swing.JButton; |
19 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
20 |
import javax.swing.JDialog; |
import javax.swing.JDialog; |
21 |
import javax.swing.JOptionPane; |
import javax.swing.JOptionPane; |
51 |
|
|
52 |
private boolean hasBeenCanceled; |
private boolean hasBeenCanceled; |
53 |
|
|
54 |
|
private JButton[] optionalButtons; |
55 |
|
|
56 |
/** |
/** |
57 |
* Since the registerKeyboardAction() method is part of the JComponent class |
* Since the registerKeyboardAction() method is part of the JComponent class |
58 |
* definition, you must define the Escape keystroke and register the |
* definition, you must define the Escape keystroke and register the |
86 |
* This class handles the cancel button itself. You may still want to listen |
* This class handles the cancel button itself. You may still want to listen |
87 |
* to PROPERTY_APPLY_AND_CLOSE events. This dialog is modal. The dialog has |
* to PROPERTY_APPLY_AND_CLOSE events. This dialog is modal. The dialog has |
88 |
* to be set visible afterwards.<br/> |
* to be set visible afterwards.<br/> |
89 |
|
* |
90 |
|
* @param owner |
91 |
|
* A component of the GUI that this dialog is related to. If no |
92 |
|
* {@link Window} is passed, SwingUtil.getParentWindow(owner) is |
93 |
|
* called. |
94 |
*/ |
*/ |
95 |
public TranslationAskJDialog(Window owner, |
public TranslationAskJDialog(Component owner, |
96 |
final JComponent... translationEditJPanels) { |
final JComponent... translationEditJPanels) { |
97 |
super(owner); |
super(owner instanceof Window ? (Window) owner : SwingUtil |
98 |
|
.getParentWindow(owner)); |
99 |
setComponents(translationEditJPanels); |
setComponents(translationEditJPanels); |
100 |
} |
} |
101 |
|
|
111 |
* Using this constructor, you have to call setComponents afterwards. |
* Using this constructor, you have to call setComponents afterwards. |
112 |
*/ |
*/ |
113 |
public TranslationAskJDialog(Window owner) { |
public TranslationAskJDialog(Window owner) { |
114 |
super(owner); |
this(owner, new JComponent[] {}); |
115 |
} |
} |
116 |
|
|
117 |
/** |
/** |
156 |
SwingUtil.centerFrameOnScreen(this); |
SwingUtil.centerFrameOnScreen(this); |
157 |
Box box = Box.createVerticalBox(); |
Box box = Box.createVerticalBox(); |
158 |
for (JComponent panel : translationEditJPanelsOrJustComponents) { |
for (JComponent panel : translationEditJPanelsOrJustComponents) { |
159 |
|
panel.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT); |
160 |
|
panel.setBorder( BorderFactory.createEmptyBorder(5, 6, 5, 6)); |
161 |
box.add(panel); |
box.add(panel); |
162 |
|
|
163 |
} |
} |
164 |
JPanel cp = new JPanel(new BorderLayout()); |
JPanel cp = new JPanel(new BorderLayout()); |
165 |
cp.add(box, BorderLayout.CENTER); |
cp.add(box, BorderLayout.WEST); |
166 |
cp.add(getButtons(), BorderLayout.SOUTH); |
cp.add(getButtons(), BorderLayout.SOUTH); |
167 |
setContentPane(cp); |
setContentPane(cp); |
168 |
|
|
169 |
setTitle(RESOURCE.getString("translation_dialog_title")); // i8n |
setTitle(RESOURCE.getString("translation_dialog_title")); // i8n |
170 |
setModal(true); |
setModal(true); |
171 |
pack(); |
pack(); |
172 |
} |
} |
173 |
|
|
174 |
|
public void setButtons(JButton... optionalButtons) { |
175 |
|
this.optionalButtons = optionalButtons; |
176 |
|
init(); |
177 |
|
} |
178 |
|
|
179 |
protected void cancel() { |
protected void cancel() { |
180 |
firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
181 |
restore(); |
restore(); |
195 |
|
|
196 |
private JComponent getButtons() { |
private JComponent getButtons() { |
197 |
JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
198 |
|
|
199 |
|
if (optionalButtons != null) |
200 |
|
for (JButton b : optionalButtons) { |
201 |
|
jPanel.add(b); |
202 |
|
} |
203 |
|
|
204 |
if (okButton == null) { |
if (okButton == null) { |
205 |
okButton = new OkButton(new AbstractAction() { |
okButton = new OkButton(new AbstractAction() { |
206 |
{ |
{ |
223 |
public void actionPerformed(ActionEvent evt) { |
public void actionPerformed(ActionEvent evt) { |
224 |
TranslationAskJDialog.this.firePropertyChange( |
TranslationAskJDialog.this.firePropertyChange( |
225 |
PROPERTY_APPLY_AND_CLOSE, null, null); |
PROPERTY_APPLY_AND_CLOSE, null, null); |
226 |
|
|
227 |
if (!checkValidInputs()) return; |
if (!checkValidInputs()) |
228 |
|
return; |
229 |
|
|
230 |
setVisible(false); |
setVisible(false); |
231 |
dispose(); |
dispose(); |
232 |
} |
} |
254 |
} |
} |
255 |
|
|
256 |
/** |
/** |
257 |
* @return <code>true</code> if none of the translations contains illegal characters. |
* @return <code>true</code> if none of the translations contains illegal |
258 |
|
* characters. |
259 |
*/ |
*/ |
260 |
protected boolean checkValidInputs() { |
protected boolean checkValidInputs() { |
261 |
|
|
262 |
for (JComponent component : translationEditJPanelsOrJustComponents) { |
for (JComponent component : translationEditJPanelsOrJustComponents) { |
263 |
if (component instanceof TranslationEditJPanel) { |
if (component instanceof TranslationEditJPanel) { |
264 |
TranslationEditJPanel tep = (TranslationEditJPanel) component; |
TranslationEditJPanel tep = (TranslationEditJPanel) component; |
265 |
|
|
266 |
for (String l : tep.getTranslation().values()){ |
for (String l : tep.getTranslation().values()) { |
267 |
if ( l.contains("{") || l.contains("}")) { |
if (l.contains("{") || l.contains("}")) { |
268 |
JOptionPane.showMessageDialog(this, RESOURCE.getString("ErrorMsg.InvalidCharacterInTranslation")); |
JOptionPane |
269 |
|
.showMessageDialog( |
270 |
|
this, |
271 |
|
RESOURCE |
272 |
|
.getString("ErrorMsg.InvalidCharacterInTranslation")); |
273 |
return false; |
return false; |
274 |
} |
} |
275 |
} |
} |
276 |
|
|
277 |
} |
} |
278 |
} |
} |
279 |
|
|
|
|
|
280 |
return true; |
return true; |
281 |
} |
} |
282 |
|
|