/[schmitzm]/trunk/src/skrueger/swing/TranslationAskJDialog.java
ViewVC logotype

Diff of /trunk/src/skrueger/swing/TranslationAskJDialog.java

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

trunk/src/skrueger/swing/TranslationAskJDialog.java revision 261 by mojays, Fri Jul 31 17:05:18 2009 UTC branches/1.0-gt2-2.6/src/skrueger/swing/TranslationAskJDialog.java revision 419 by alfonx, Wed Sep 30 15:36:39 2009 UTC
# Line 126  public class TranslationAskJDialog exten Line 126  public class TranslationAskJDialog exten
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          /**          /**
# Line 143  public class TranslationAskJDialog exten Line 143  public class TranslationAskJDialog exten
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) {
# Line 155  public class TranslationAskJDialog exten Line 165  public class TranslationAskJDialog exten
165                                  backup[count++] = orig.toOneLine();                                  backup[count++] = orig.toOneLine();
166                          }                          }
167                  }                  }
   
                 init();  
168          }          }
169    
170          private void init() {          private void init() {
# Line 172  public class TranslationAskJDialog exten Line 180  public class TranslationAskJDialog exten
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          }          }
# Line 191  public class TranslationAskJDialog exten Line 199  public class TranslationAskJDialog exten
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) {
# Line 229  public class TranslationAskJDialog exten Line 246  public class TranslationAskJDialog exten
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    
# Line 242  public class TranslationAskJDialog exten Line 259  public class TranslationAskJDialog exten
259                                          if (!checkValidInputs())                                          if (!checkValidInputs())
260                                                  return;                                                  return;
261    
262                                          setVisible(false);                                          okClose();
263                                          dispose();  
264                                  }                                  }
265    
266                          });                          });
# Line 254  public class TranslationAskJDialog exten Line 271  public class TranslationAskJDialog exten
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                  }                  }
# Line 269  public class TranslationAskJDialog exten Line 287  public class TranslationAskJDialog exten
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           */           */
# Line 283  public class TranslationAskJDialog exten Line 310  public class TranslationAskJDialog exten
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                                  }                                  }

Legend:
Removed from v.261  
changed lines
  Added in v.419

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26