14 |
import javax.swing.AbstractAction; |
import javax.swing.AbstractAction; |
15 |
import javax.swing.Action; |
import javax.swing.Action; |
16 |
import javax.swing.Box; |
import javax.swing.Box; |
17 |
|
import javax.swing.JButton; |
18 |
import javax.swing.JComponent; |
import javax.swing.JComponent; |
19 |
import javax.swing.JDialog; |
import javax.swing.JDialog; |
20 |
import javax.swing.JOptionPane; |
import javax.swing.JOptionPane; |
50 |
|
|
51 |
private boolean hasBeenCanceled; |
private boolean hasBeenCanceled; |
52 |
|
|
53 |
|
private JButton[] optionalButtons; |
54 |
|
|
55 |
/** |
/** |
56 |
* Since the registerKeyboardAction() method is part of the JComponent class |
* Since the registerKeyboardAction() method is part of the JComponent class |
57 |
* definition, you must define the Escape keystroke and register the |
* definition, you must define the Escape keystroke and register the |
85 |
* 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 |
86 |
* 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 |
87 |
* to be set visible afterwards.<br/> |
* to be set visible afterwards.<br/> |
88 |
|
* |
89 |
|
* @param owner |
90 |
|
* A component of the GUI that this dialog is related to. If no |
91 |
|
* {@link Window} is passed, SwingUtil.getParentWindow(owner) is |
92 |
|
* called. |
93 |
*/ |
*/ |
94 |
public TranslationAskJDialog(Window owner, |
public TranslationAskJDialog(Component owner, |
95 |
final JComponent... translationEditJPanels) { |
final JComponent... translationEditJPanels) { |
96 |
super(owner); |
super(owner instanceof Window ? (Window) owner : SwingUtil |
97 |
|
.getParentWindow(owner)); |
98 |
setComponents(translationEditJPanels); |
setComponents(translationEditJPanels); |
99 |
} |
} |
100 |
|
|
110 |
* Using this constructor, you have to call setComponents afterwards. |
* Using this constructor, you have to call setComponents afterwards. |
111 |
*/ |
*/ |
112 |
public TranslationAskJDialog(Window owner) { |
public TranslationAskJDialog(Window owner) { |
113 |
super(owner); |
this(owner, new JComponent[] {}); |
114 |
} |
} |
115 |
|
|
116 |
/** |
/** |
167 |
pack(); |
pack(); |
168 |
} |
} |
169 |
|
|
170 |
|
public void setButtons(JButton... optionalButtons) { |
171 |
|
this.optionalButtons = optionalButtons; |
172 |
|
init(); |
173 |
|
} |
174 |
|
|
175 |
protected void cancel() { |
protected void cancel() { |
176 |
firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
177 |
restore(); |
restore(); |
191 |
|
|
192 |
private JComponent getButtons() { |
private JComponent getButtons() { |
193 |
JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
194 |
|
|
195 |
|
if (optionalButtons != null) |
196 |
|
for (JButton b : optionalButtons) { |
197 |
|
jPanel.add(b); |
198 |
|
} |
199 |
|
|
200 |
if (okButton == null) { |
if (okButton == null) { |
201 |
okButton = new OkButton(new AbstractAction() { |
okButton = new OkButton(new AbstractAction() { |
202 |
{ |
{ |
219 |
public void actionPerformed(ActionEvent evt) { |
public void actionPerformed(ActionEvent evt) { |
220 |
TranslationAskJDialog.this.firePropertyChange( |
TranslationAskJDialog.this.firePropertyChange( |
221 |
PROPERTY_APPLY_AND_CLOSE, null, null); |
PROPERTY_APPLY_AND_CLOSE, null, null); |
222 |
|
|
223 |
if (!checkValidInputs()) return; |
if (!checkValidInputs()) |
224 |
|
return; |
225 |
|
|
226 |
setVisible(false); |
setVisible(false); |
227 |
dispose(); |
dispose(); |
228 |
} |
} |
250 |
} |
} |
251 |
|
|
252 |
/** |
/** |
253 |
* @return <code>true</code> if none of the translations contains illegal characters. |
* @return <code>true</code> if none of the translations contains illegal |
254 |
|
* characters. |
255 |
*/ |
*/ |
256 |
protected boolean checkValidInputs() { |
protected boolean checkValidInputs() { |
257 |
|
|
258 |
for (JComponent component : translationEditJPanelsOrJustComponents) { |
for (JComponent component : translationEditJPanelsOrJustComponents) { |
259 |
if (component instanceof TranslationEditJPanel) { |
if (component instanceof TranslationEditJPanel) { |
260 |
TranslationEditJPanel tep = (TranslationEditJPanel) component; |
TranslationEditJPanel tep = (TranslationEditJPanel) component; |
261 |
|
|
262 |
for (String l : tep.getTranslation().values()){ |
for (String l : tep.getTranslation().values()) { |
263 |
if ( l.contains("{") || l.contains("}")) { |
if (l.contains("{") || l.contains("}")) { |
264 |
JOptionPane.showMessageDialog(this, RESOURCE.getString("ErrorMsg.InvalidCharacterInTranslation")); |
JOptionPane |
265 |
|
.showMessageDialog( |
266 |
|
this, |
267 |
|
RESOURCE |
268 |
|
.getString("ErrorMsg.InvalidCharacterInTranslation")); |
269 |
return false; |
return false; |
270 |
} |
} |
271 |
} |
} |
272 |
|
|
273 |
} |
} |
274 |
} |
} |
275 |
|
|
|
|
|
276 |
return true; |
return true; |
277 |
} |
} |
278 |
|
|