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; |
23 |
import javax.swing.JRootPane; |
import javax.swing.JRootPane; |
24 |
import javax.swing.KeyStroke; |
import javax.swing.KeyStroke; |
25 |
|
|
26 |
|
import schmitzm.geotools.styling.StylingUtil; |
27 |
import schmitzm.lang.LangUtil; |
import schmitzm.lang.LangUtil; |
28 |
import schmitzm.lang.ResourceProvider; |
import schmitzm.lang.ResourceProvider; |
29 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
31 |
|
|
32 |
public class TranslationAskJDialog extends JDialog { |
public class TranslationAskJDialog extends JDialog { |
33 |
|
|
|
/** |
|
|
* {@link ResourceProvider}, der die Lokalisation fuer GUI-Komponenten des |
|
|
* Package {@code skrueger.swing} zur Verfuegung stellt. Diese sind in |
|
|
* properties-Datein unter {@code skrueger.swing.resource.locales} |
|
|
* hinterlegt. |
|
|
*/ |
|
|
public static ResourceProvider RESOURCE = new ResourceProvider(LangUtil |
|
|
.extendPackagePath(TranslationAskJDialog.class, |
|
|
"resource.locales.SwingResourceBundle"), Locale.ENGLISH); |
|
|
|
|
34 |
private String[] backup = new String[50]; // Maximum 50 languages ;-) |
private String[] backup = new String[50]; // Maximum 50 languages ;-) |
35 |
private OkButton okButton; |
private OkButton okButton; |
36 |
private CancelButton cancelButton; |
private CancelButton cancelButton; |
42 |
|
|
43 |
private boolean hasBeenCanceled; |
private boolean hasBeenCanceled; |
44 |
|
|
45 |
|
private JButton[] optionalButtons; |
46 |
|
|
47 |
/** |
/** |
48 |
* Since the registerKeyboardAction() method is part of the JComponent class |
* Since the registerKeyboardAction() method is part of the JComponent class |
49 |
* definition, you must define the Escape keystroke and register the |
* definition, you must define the Escape keystroke and register the |
77 |
* 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 |
78 |
* 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 |
79 |
* to be set visible afterwards.<br/> |
* to be set visible afterwards.<br/> |
80 |
|
* |
81 |
|
* @param owner |
82 |
|
* A component of the GUI that this dialog is related to. If no |
83 |
|
* {@link Window} is passed, SwingUtil.getParentWindow(owner) is |
84 |
|
* called. |
85 |
*/ |
*/ |
86 |
public TranslationAskJDialog(Window owner, |
public TranslationAskJDialog(Component owner, |
87 |
final JComponent... translationEditJPanels) { |
final JComponent... translationEditJPanels) { |
88 |
super(owner); |
super(owner instanceof Window ? (Window) owner : SwingUtil |
89 |
|
.getParentWindow(owner)); |
90 |
setComponents(translationEditJPanels); |
setComponents(translationEditJPanels); |
91 |
} |
} |
92 |
|
|
102 |
* Using this constructor, you have to call setComponents afterwards. |
* Using this constructor, you have to call setComponents afterwards. |
103 |
*/ |
*/ |
104 |
public TranslationAskJDialog(Window owner) { |
public TranslationAskJDialog(Window owner) { |
105 |
super(owner); |
this(owner, new JComponent[] {}); |
106 |
} |
} |
107 |
|
|
108 |
/** |
/** |
147 |
SwingUtil.centerFrameOnScreen(this); |
SwingUtil.centerFrameOnScreen(this); |
148 |
Box box = Box.createVerticalBox(); |
Box box = Box.createVerticalBox(); |
149 |
for (JComponent panel : translationEditJPanelsOrJustComponents) { |
for (JComponent panel : translationEditJPanelsOrJustComponents) { |
150 |
|
panel.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT); |
151 |
|
panel.setBorder( BorderFactory.createEmptyBorder(5, 6, 5, 6)); |
152 |
box.add(panel); |
box.add(panel); |
153 |
|
|
154 |
} |
} |
155 |
JPanel cp = new JPanel(new BorderLayout()); |
JPanel cp = new JPanel(new BorderLayout()); |
156 |
cp.add(box, BorderLayout.CENTER); |
cp.add(box, BorderLayout.WEST); |
157 |
cp.add(getButtons(), BorderLayout.SOUTH); |
cp.add(getButtons(), BorderLayout.SOUTH); |
158 |
setContentPane(cp); |
setContentPane(cp); |
159 |
|
|
160 |
setTitle(RESOURCE.getString("translation_dialog_title")); // i8n |
setTitle(SwingUtil.R("TranslationAskJDialog.Title")); |
161 |
setModal(true); |
setModal(true); |
162 |
pack(); |
pack(); |
163 |
} |
} |
164 |
|
|
165 |
|
public void setButtons(JButton... optionalButtons) { |
166 |
|
this.optionalButtons = optionalButtons; |
167 |
|
init(); |
168 |
|
} |
169 |
|
|
170 |
protected void cancel() { |
protected void cancel() { |
171 |
firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
172 |
restore(); |
restore(); |
186 |
|
|
187 |
private JComponent getButtons() { |
private JComponent getButtons() { |
188 |
JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
JPanel jPanel = new JPanel(new FlowLayout(FlowLayout.RIGHT)); |
189 |
|
|
190 |
|
if (optionalButtons != null) |
191 |
|
for (JButton b : optionalButtons) { |
192 |
|
jPanel.add(b); |
193 |
|
} |
194 |
|
|
195 |
if (okButton == null) { |
if (okButton == null) { |
196 |
okButton = new OkButton(new AbstractAction() { |
okButton = new OkButton(new AbstractAction() { |
197 |
{ |
{ |
214 |
public void actionPerformed(ActionEvent evt) { |
public void actionPerformed(ActionEvent evt) { |
215 |
TranslationAskJDialog.this.firePropertyChange( |
TranslationAskJDialog.this.firePropertyChange( |
216 |
PROPERTY_APPLY_AND_CLOSE, null, null); |
PROPERTY_APPLY_AND_CLOSE, null, null); |
217 |
|
|
218 |
if (!checkValidInputs()) return; |
if (!checkValidInputs()) |
219 |
|
return; |
220 |
|
|
221 |
setVisible(false); |
setVisible(false); |
222 |
dispose(); |
dispose(); |
223 |
} |
} |
245 |
} |
} |
246 |
|
|
247 |
/** |
/** |
248 |
* @return <code>true</code> if none of the translations contains illegal characters. |
* @return <code>true</code> if none of the translations contains illegal |
249 |
|
* characters. |
250 |
*/ |
*/ |
251 |
protected boolean checkValidInputs() { |
protected boolean checkValidInputs() { |
252 |
|
|
253 |
for (JComponent component : translationEditJPanelsOrJustComponents) { |
for (JComponent component : translationEditJPanelsOrJustComponents) { |
254 |
if (component instanceof TranslationEditJPanel) { |
if (component instanceof TranslationEditJPanel) { |
255 |
TranslationEditJPanel tep = (TranslationEditJPanel) component; |
TranslationEditJPanel tep = (TranslationEditJPanel) component; |
256 |
|
|
257 |
for (String l : tep.getTranslation().values()){ |
for (String l : tep.getTranslation().values()) { |
258 |
if ( l.contains("{") || l.contains("}")) { |
if (l.contains("{") || l.contains("}")) { |
259 |
JOptionPane.showMessageDialog(this, RESOURCE.getString("ErrorMsg.InvalidCharacterInTranslation")); |
JOptionPane |
260 |
|
.showMessageDialog( |
261 |
|
this, |
262 |
|
SwingUtil.R("TranslationAskJDialog.ErrorMsg.InvalidCharacterInTranslation")); |
263 |
return false; |
return false; |
264 |
} |
} |
265 |
} |
} |
266 |
|
|
267 |
} |
} |
268 |
} |
} |
269 |
|
|
|
|
|
270 |
return true; |
return true; |
271 |
} |
} |
272 |
|
|