/[schmitzm]/trunk/src/skrueger/i8n/SwitchLanguageDialog.java
ViewVC logotype

Diff of /trunk/src/skrueger/i8n/SwitchLanguageDialog.java

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

revision 2 by mojays, Tue Feb 24 22:43:52 2009 UTC revision 207 by alfonx, Thu Jul 9 20:14:21 2009 UTC
# Line 1  Line 1 
1  package skrueger.i8n;  package skrueger.i8n;
2    
3    import java.awt.Component;
4  import java.awt.GridBagConstraints;  import java.awt.GridBagConstraints;
5  import java.awt.GridBagLayout;  import java.awt.GridBagLayout;
6  import java.awt.Insets;  import java.awt.Insets;
# Line 24  import schmitzm.swing.SwingUtil; Line 25  import schmitzm.swing.SwingUtil;
25  import skrueger.swing.OkButton;  import skrueger.swing.OkButton;
26  import skrueger.swing.TranslationEditJPanel;  import skrueger.swing.TranslationEditJPanel;
27    
28    /**
29     * This dialog ask the user to select one of list of given languages. The dialog
30     * is modal and not visible after construction.
31     *
32     * @author Stefan A. Krueger
33     */
34  public class SwitchLanguageDialog extends JDialog {  public class SwitchLanguageDialog extends JDialog {
35          protected Logger LOGGER = Logger.getLogger(SwitchLanguageDialog.class);          protected Logger LOGGER = Logger.getLogger(SwitchLanguageDialog.class);
36    
# Line 53  public class SwitchLanguageDialog extend Line 60  public class SwitchLanguageDialog extend
60           * @param owner           * @param owner
61           * @param atlasConfig           * @param atlasConfig
62           */           */
63          public SwitchLanguageDialog(final Window owner, final List<String> languages) {          public SwitchLanguageDialog(final Component owner,
64                  super(owner);                          final List<String> languages) {
65                    super(SwingUtil.getParentWindow(owner));
66                  this.languages = languages;                  this.languages = languages;
67    
68                  Translation.setActiveLang(languages.get(0));                  Translation.setActiveLang(languages.get(0));
# Line 66  public class SwitchLanguageDialog extend Line 74  public class SwitchLanguageDialog extend
74                  }                  }
75    
76                  initialize();                  initialize();
   
                 setVisible(true);  
77          }          }
78    
79          /**          /**
# Line 79  public class SwitchLanguageDialog extend Line 85  public class SwitchLanguageDialog extend
85                  this.setContentPane(getJContentPane());                  this.setContentPane(getJContentPane());
86                  setModal(true);                  setModal(true);
87                  SwingUtil.centerFrameOnScreenRandom(this);                  SwingUtil.centerFrameOnScreenRandom(this);
88    
89                    setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);
90    
91                  pack();                  pack();
92          }          }
93    
# Line 175  public class SwitchLanguageDialog extend Line 184  public class SwitchLanguageDialog extend
184                          gridBagConstraints.insets = new Insets(0, 5, 0, 0);                          gridBagConstraints.insets = new Insets(0, 5, 0, 0);
185                          gridBagConstraints.gridy = 0;                          gridBagConstraints.gridy = 0;
186                          jLabel = new JLabel();                          jLabel = new JLabel();
187                          jLabel.setText("Select language: ");                          jLabel.setText("Select language: "); // i8n!?! Maybe replace with an
188                                                                                                            // icon of an index finger
189                          jPanel1 = new JPanel();                          jPanel1 = new JPanel();
190                          jPanel1.setLayout(new GridBagLayout());                          jPanel1.setLayout(new GridBagLayout());
191                          jPanel1.add(jLabel, gridBagConstraints);                          jPanel1.add(jLabel, gridBagConstraints);
# Line 212  public class SwitchLanguageDialog extend Line 222  public class SwitchLanguageDialog extend
222                          String[] langNames = new String[languages.size() + 1];                          String[] langNames = new String[languages.size() + 1];
223                          for (int i = 0; i < languages.size(); i++) {                          for (int i = 0; i < languages.size(); i++) {
224    
225                                  Locale locale = null;                                  Locale locale = I8NUtil.getLocaleFor(languages.get(i));
                                 for (Locale l : Locale.getAvailableLocales()) {  
                                         if (l.getLanguage().equals(languages.get(i))) {  
                                                 locale = l;  
                                         }  
                                 }  
226    
227                                  langNames[i] = locale.getDisplayLanguage(locale) + " / "                                  langNames[i] = locale.getDisplayLanguage(locale) + " / "
228                                                  + locale.getDisplayLanguage() + " / "                                                  + locale.getDisplayLanguage() + " / "
# Line 235  public class SwitchLanguageDialog extend Line 240  public class SwitchLanguageDialog extend
240                                                  getJButton().setEnabled(false);                                                  getJButton().setEnabled(false);
241                                                  return;                                                  return;
242                                          }                                          }
243                                          Translation.setActiveLang(languages.get(jComboBox  
244                                                          .getSelectedIndex()));                                          String l = languages.get(jComboBox.getSelectedIndex());
245                                          getJButton().setEnabled(true);                                          try {
246                                                    Translation.setActiveLang(l);
247    
248                                                    getJButton().setEnabled(true);
249                                            } catch (java.lang.IllegalArgumentException ee) {
250                                                    LOGGER.warn("The language " + l + " is not valid", ee);
251                                                    getJButton().setEnabled(false);
252                                            }
253    
254                                  }                                  }
255    
256                          });                          });

Legend:
Removed from v.2  
changed lines
  Added in v.207

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26