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 |
protected void cancel() { |
/** |
203 |
firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
* Called when the dilaog is closed using the cancel button. When |
204 |
|
* overwriting this method, call super.cancel() after restoring your |
205 |
|
* properties. |
206 |
|
*/ |
207 |
|
public void cancel() { |
208 |
restore(); |
restore(); |
209 |
|
firePropertyChange(PROPERTY_CANCEL_AND_CLOSE, null, null); |
210 |
|
setCancelled(true); |
211 |
setVisible(false); |
setVisible(false); |
212 |
dispose(); |
dispose(); |
213 |
} |
} |
214 |
|
|
215 |
protected void restore() { |
/** |
216 |
|
* Used to restore all the values when cancel has been pressed. |
217 |
|
*/ |
218 |
|
private void restore() { |
219 |
int count = 0; |
int count = 0; |
220 |
for (JComponent component : translationEditJPanelsOrJustComponents) { |
for (JComponent component : translationEditJPanelsOrJustComponents) { |
221 |
if (component instanceof TranslationEditJPanel) { |
if (component instanceof TranslationEditJPanel) { |
246 |
putValue(Action.MNEMONIC_KEY, new Integer( |
putValue(Action.MNEMONIC_KEY, new Integer( |
247 |
java.awt.event.KeyEvent.VK_E)); |
java.awt.event.KeyEvent.VK_E)); |
248 |
|
|
249 |
// Set tool tip text |
// // Set tool tip text |
250 |
putValue(Action.SHORT_DESCRIPTION, |
// putValue(Action.SHORT_DESCRIPTION, |
251 |
"Accept the changes made to the translation."); |
// "Accept the changes made to the translation."); //i8n |
252 |
|
|
253 |
} |
} |
254 |
|
|
259 |
if (!checkValidInputs()) |
if (!checkValidInputs()) |
260 |
return; |
return; |
261 |
|
|
262 |
setVisible(false); |
okClose(); |
263 |
dispose(); |
|
264 |
} |
} |
265 |
|
|
266 |
}); |
}); |
271 |
if (cancelButton == null) { |
if (cancelButton == null) { |
272 |
cancelButton = new CancelButton(new AbstractAction("") { |
cancelButton = new CancelButton(new AbstractAction("") { |
273 |
public void actionPerformed(ActionEvent evt) { |
public void actionPerformed(ActionEvent evt) { |
274 |
restore(); |
// restore(); |
275 |
TranslationAskJDialog.this.firePropertyChange( |
// TranslationAskJDialog.this.firePropertyChange( |
276 |
PROPERTY_CANCEL_AND_CLOSE, null, null); |
// PROPERTY_CANCEL_AND_CLOSE, null, null); |
277 |
setVisible(false); |
// setVisible(false); |
278 |
setCancelled(true); |
// setCancelled(true); |
279 |
dispose(); |
// dispose(); |
280 |
|
cancel(); |
281 |
} |
} |
282 |
}); |
}); |
283 |
} |
} |
287 |
} |
} |
288 |
|
|
289 |
/** |
/** |
290 |
|
* This method is only called when the dialog is closed and not cancelled. |
291 |
|
* Can be overwritten to do anything when the dialog has been accepted. |
292 |
|
*/ |
293 |
|
protected void okClose() { |
294 |
|
setVisible(false); |
295 |
|
dispose(); |
296 |
|
} |
297 |
|
|
298 |
|
/** |
299 |
* @return <code>true</code> if none of the translations contains illegal |
* @return <code>true</code> if none of the translations contains illegal |
300 |
* characters. |
* characters. |
301 |
*/ |
*/ |
310 |
JOptionPane |
JOptionPane |
311 |
.showMessageDialog( |
.showMessageDialog( |
312 |
this, |
this, |
313 |
SwingUtil.R("TranslationAskJDialog.ErrorMsg.InvalidCharacterInTranslation")); |
SwingUtil |
314 |
|
.R("TranslationAskJDialog.ErrorMsg.InvalidCharacterInTranslation")); |
315 |
return false; |
return false; |
316 |
} |
} |
317 |
} |
} |