38 |
import java.awt.event.KeyEvent; |
import java.awt.event.KeyEvent; |
39 |
import java.awt.event.WindowAdapter; |
import java.awt.event.WindowAdapter; |
40 |
import java.awt.event.WindowEvent; |
import java.awt.event.WindowEvent; |
|
import java.util.Locale; |
|
41 |
|
|
42 |
import javax.swing.AbstractAction; |
import javax.swing.AbstractAction; |
43 |
import javax.swing.Action; |
import javax.swing.Action; |
51 |
import javax.swing.JRootPane; |
import javax.swing.JRootPane; |
52 |
import javax.swing.KeyStroke; |
import javax.swing.KeyStroke; |
53 |
|
|
|
import schmitzm.geotools.styling.StylingUtil; |
|
|
import schmitzm.lang.LangUtil; |
|
|
import schmitzm.lang.ResourceProvider; |
|
54 |
import schmitzm.swing.SwingUtil; |
import schmitzm.swing.SwingUtil; |
55 |
import skrueger.i8n.Translation; |
import skrueger.i8n.Translation; |
56 |
|
|
126 |
* Using this constructor, you have to call setComponents afterwards. |
* Using this constructor, you have to call setComponents afterwards. |
127 |
*/ |
*/ |
128 |
public TranslationAskJDialog(Component owner) { |
public TranslationAskJDialog(Component owner) { |
129 |
this(owner, new JComponent[] {}); |
super(SwingUtil.getParentWindow(owner)); |
130 |
} |
} |
131 |
|
|
132 |
/** |
/** |
143 |
public void setComponents(final JComponent... translationEditJPanels) { |
public void setComponents(final JComponent... translationEditJPanels) { |
144 |
this.translationEditJPanelsOrJustComponents = translationEditJPanels; |
this.translationEditJPanelsOrJustComponents = translationEditJPanels; |
145 |
|
|
146 |
|
backup(); |
147 |
|
|
148 |
|
init(); |
149 |
|
} |
150 |
|
|
151 |
|
/** |
152 |
|
* Stores the original values of all {@link TranslationEditJPanel}s so |
153 |
|
* cancel works. |
154 |
|
*/ |
155 |
|
protected void backup() { |
156 |
// Remember backups for all the TranslationEditJPanel |
// Remember backups for all the TranslationEditJPanel |
157 |
int count = 0; |
int count = 0; |
158 |
for (JComponent component : translationEditJPanelsOrJustComponents) { |
for (JComponent component : translationEditJPanelsOrJustComponents) { |
165 |
backup[count++] = orig.toOneLine(); |
backup[count++] = orig.toOneLine(); |
166 |
} |
} |
167 |
} |
} |
|
|
|
|
init(); |
|
168 |
} |
} |
169 |
|
|
170 |
private void init() { |
private void init() { |
180 |
Box box = Box.createVerticalBox(); |
Box box = Box.createVerticalBox(); |
181 |
for (JComponent panel : translationEditJPanelsOrJustComponents) { |
for (JComponent panel : translationEditJPanelsOrJustComponents) { |
182 |
panel.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT); |
panel.setAlignmentX(java.awt.Component.LEFT_ALIGNMENT); |
183 |
panel.setBorder( BorderFactory.createEmptyBorder(5, 6, 5, 6)); |
panel.setBorder(BorderFactory.createEmptyBorder(5, 6, 5, 6)); |
184 |
box.add(panel); |
box.add(panel); |
185 |
|
|
186 |
} |
} |
187 |
JPanel cp = new JPanel(new BorderLayout()); |
JPanel cp = new JPanel(new BorderLayout()); |
188 |
cp.add(box, BorderLayout.WEST); |
cp.add(box, BorderLayout.WEST); |
189 |
cp.add(getButtons(), BorderLayout.SOUTH); |
cp.add(getButtons(), BorderLayout.SOUTH); |
190 |
setContentPane(cp); |
setContentPane(cp); |
191 |
|
|
192 |
setTitle(SwingUtil.R("TranslationAskJDialog.Title")); |
setTitle(SwingUtil.R("TranslationAskJDialog.Title")); |
193 |
setModal(true); |
setModal(true); |
194 |
pack(); |
pack(); |
195 |
} |
} |
199 |
init(); |
init(); |
200 |
} |
} |
201 |
|
|
202 |
|
/** |
203 |
|
* Called when the dilaog is closed using the cancel button. |
204 |
|
*/ |
205 |
protected void cancel() { |
protected void cancel() { |
|
firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
|
206 |
restore(); |
restore(); |
207 |
|
firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
208 |
|
setCancelled(true); |
209 |
setVisible(false); |
setVisible(false); |
210 |
dispose(); |
dispose(); |
211 |
} |
} |
212 |
|
|
213 |
|
/** |
214 |
|
* Used to restore all the values when cancel has been pressed. |
215 |
|
*/ |
216 |
protected void restore() { |
protected void restore() { |
217 |
int count = 0; |
int count = 0; |
218 |
for (JComponent component : translationEditJPanelsOrJustComponents) { |
for (JComponent component : translationEditJPanelsOrJustComponents) { |
244 |
putValue(Action.MNEMONIC_KEY, new Integer( |
putValue(Action.MNEMONIC_KEY, new Integer( |
245 |
java.awt.event.KeyEvent.VK_E)); |
java.awt.event.KeyEvent.VK_E)); |
246 |
|
|
247 |
// Set tool tip text |
// // Set tool tip text |
248 |
putValue(Action.SHORT_DESCRIPTION, |
// putValue(Action.SHORT_DESCRIPTION, |
249 |
"Accept the changes made to the translation."); |
// "Accept the changes made to the translation."); //i8n |
250 |
|
|
251 |
} |
} |
252 |
|
|
257 |
if (!checkValidInputs()) |
if (!checkValidInputs()) |
258 |
return; |
return; |
259 |
|
|
260 |
setVisible(false); |
okClose(); |
261 |
dispose(); |
|
262 |
} |
} |
263 |
|
|
264 |
}); |
}); |
269 |
if (cancelButton == null) { |
if (cancelButton == null) { |
270 |
cancelButton = new CancelButton(new AbstractAction("") { |
cancelButton = new CancelButton(new AbstractAction("") { |
271 |
public void actionPerformed(ActionEvent evt) { |
public void actionPerformed(ActionEvent evt) { |
272 |
restore(); |
// restore(); |
273 |
TranslationAskJDialog.this.firePropertyChange( |
// TranslationAskJDialog.this.firePropertyChange( |
274 |
PROPERTY_CANCEL_AND_CLOSE, null, null); |
// PROPERTY_CANCEL_AND_CLOSE, null, null); |
275 |
setVisible(false); |
// setVisible(false); |
276 |
setCancelled(true); |
// setCancelled(true); |
277 |
dispose(); |
// dispose(); |
278 |
|
cancel(); |
279 |
} |
} |
280 |
}); |
}); |
281 |
} |
} |
285 |
} |
} |
286 |
|
|
287 |
/** |
/** |
288 |
|
* This method is only called when the dialog is closed and not cancelled. |
289 |
|
* Can be overwritten to do anything when the dialog has been accepted. |
290 |
|
*/ |
291 |
|
protected void okClose() { |
292 |
|
setVisible(false); |
293 |
|
dispose(); |
294 |
|
} |
295 |
|
|
296 |
|
/** |
297 |
* @return <code>true</code> if none of the translations contains illegal |
* @return <code>true</code> if none of the translations contains illegal |
298 |
* characters. |
* characters. |
299 |
*/ |
*/ |
308 |
JOptionPane |
JOptionPane |
309 |
.showMessageDialog( |
.showMessageDialog( |
310 |
this, |
this, |
311 |
SwingUtil.R("TranslationAskJDialog.ErrorMsg.InvalidCharacterInTranslation")); |
SwingUtil |
312 |
|
.R("TranslationAskJDialog.ErrorMsg.InvalidCharacterInTranslation")); |
313 |
return false; |
return false; |
314 |
} |
} |
315 |
} |
} |