/[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 256 by alfonx, Fri Jul 31 14:43:47 2009 UTC branches/1.0-gt2-2.6/src/skrueger/swing/TranslationAskJDialog.java revision 315 by mojays, Wed Aug 26 11:03:27 2009 UTC
# Line 38  import java.awt.event.ActionListener; Line 38  import java.awt.event.ActionListener;
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;
# Line 52  import javax.swing.JPanel; Line 51  import javax.swing.JPanel;
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    
# Line 130  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 147  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 159  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 176  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 195  public class TranslationAskJDialog exten Line 199  public class TranslationAskJDialog exten
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) {
# Line 233  public class TranslationAskJDialog exten Line 244  public class TranslationAskJDialog exten
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    
# Line 246  public class TranslationAskJDialog exten Line 257  public class TranslationAskJDialog exten
257                                          if (!checkValidInputs())                                          if (!checkValidInputs())
258                                                  return;                                                  return;
259    
260                                          setVisible(false);                                          okClose();
261                                          dispose();  
262                                  }                                  }
263    
264                          });                          });
# Line 258  public class TranslationAskJDialog exten Line 269  public class TranslationAskJDialog exten
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                  }                  }
# Line 273  public class TranslationAskJDialog exten Line 285  public class TranslationAskJDialog exten
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           */           */
# Line 287  public class TranslationAskJDialog exten Line 308  public class TranslationAskJDialog exten
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                                  }                                  }

Legend:
Removed from v.256  
changed lines
  Added in v.315

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26