/[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

branches/2.0-RC1/src/skrueger/i8n/SwitchLanguageDialog.java revision 607 by alfonx, Wed Dec 9 15:13:42 2009 UTC trunk/src/skrueger/i8n/SwitchLanguageDialog.java revision 1100 by alfonx, Mon Oct 11 00:07:14 2010 UTC
# Line 25  Line 25 
25   *   *
26   * Contributors:   * Contributors:
27   *     Martin O. J. Schmitz - initial API and implementation   *     Martin O. J. Schmitz - initial API and implementation
28   *     Stefan A. Krüger - additional utility classes   *     Stefan A. Tzeggai - additional utility classes
29   ******************************************************************************/   ******************************************************************************/
30  package skrueger.i8n;  package skrueger.i8n;
31    
# Line 43  import javax.swing.DefaultComboBoxModel; Line 43  import javax.swing.DefaultComboBoxModel;
43  import javax.swing.ImageIcon;  import javax.swing.ImageIcon;
44  import javax.swing.JButton;  import javax.swing.JButton;
45  import javax.swing.JComboBox;  import javax.swing.JComboBox;
 import javax.swing.JDialog;  
46  import javax.swing.JLabel;  import javax.swing.JLabel;
47  import javax.swing.JPanel;  import javax.swing.JPanel;
48    
49  import org.apache.log4j.Logger;  import org.apache.log4j.Logger;
50    
51  import schmitzm.swing.SwingUtil;  import schmitzm.swing.SwingUtil;
52    import skrueger.swing.AtlasDialog;
53  import skrueger.swing.OkButton;  import skrueger.swing.OkButton;
54  import skrueger.swing.TranslationEditJPanel;  import skrueger.swing.TranslationEditJPanel;
55    
# Line 57  import skrueger.swing.TranslationEditJPa Line 57  import skrueger.swing.TranslationEditJPa
57   * This dialog ask the user to select one of list of given languages. The dialog   * This dialog ask the user to select one of list of given languages. The dialog
58   * is modal and not visible after construction.   * is modal and not visible after construction.
59   *   *
60   * @author Stefan A. Krueger   * @author Stefan A. Tzeggai
61   */   */
62  public class SwitchLanguageDialog extends JDialog {  public class SwitchLanguageDialog extends AtlasDialog {
63          protected Logger LOGGER = Logger.getLogger(SwitchLanguageDialog.class);          protected Logger LOGGER = Logger.getLogger(SwitchLanguageDialog.class);
64    
         private static final long serialVersionUID = 1L;  
   
65          private JPanel jContentPane = null;          private JPanel jContentPane = null;
66    
67          private JLabel jLabelFlagimage = null;          private JLabel jLabelFlagimage = null;
# Line 81  public class SwitchLanguageDialog extend Line 79  public class SwitchLanguageDialog extend
79          private final List<String> languages;          private final List<String> languages;
80    
81          /**          /**
82             * if <code>true</code>, the default locale will also be changed during a
83             * language selection
84             **/
85            protected boolean setLocale;
86    
87            /**
88           * A dialog to select one of the available languages. If only one language           * A dialog to select one of the available languages. If only one language
89           * is available, select it directly. Creating this object automatically           * is available, select it directly. Creating this object automatically
90           * makes it visible, unless there is only one language to choose from.. it           * makes it visible, unless there is only one language to choose from.. it
91           * that case it disposes itself autmatically.           * that case it disposes itself automatically.
92             *
93             * @param setLocale
94             *            if <code>true</code>, the default locale will also be changed
95             *            during a language selection
96           */           */
97          public SwitchLanguageDialog(final Component owner,          public SwitchLanguageDialog(final Component owner,
98                          final List<String> languages) {                          final List<String> languages, boolean setLocale) {
99                  super(SwingUtil.getParentWindow(owner));                  super(owner);
100                  this.languages = languages;                  this.languages = languages;
101                    this.setLocale = setLocale;
102    
103                  Translation.setActiveLang(languages.get(0));                  if (languages == null || languages.size() == 0) {
104                            // No language is available.
105                            return;
106                    }
107    
108                    Translation.setActiveLang(languages.get(0), setLocale);
109                  if (languages.size() == 1) {                  if (languages.size() == 1) {
110                          LOGGER.debug("Only language '" + languages.get(0)                          // Only language one language is available. It has been selected
111                                          + "' is available. It has been selected automatically.");                          // automatically.
 //                      dispose();  
                         setModal(false);  
112                          return;                          return;
113                  }                  }
114    
115                  initialize();                  initialize();
116          }          }
117    
118            @Override
119            /**
120             * This modal dialog will not appear if there is <= one language to select from.
121             */
122            public void setVisible(boolean b) {
123                    if (b == true && (languages == null || languages.size() <= 1)) {
124                            return;
125                    }
126                    super.setVisible(b);
127            }
128    
129          /**          /**
130           * This method initializes this           * This method initializes this
131           *           *
# Line 112  public class SwitchLanguageDialog extend Line 134  public class SwitchLanguageDialog extend
134          private void initialize() {          private void initialize() {
135                  this.setContentPane(getJContentPane());                  this.setContentPane(getJContentPane());
136    
                 setDefaultCloseOperation(JDialog.DO_NOTHING_ON_CLOSE);  
   
137                  pack();                  pack();
138    
139                  SwingUtil.centerFrameOnScreenRandom(this);                  SwingUtil.centerFrameOnScreenRandom(this);
140                  setModal(true);                  setModal(true);
141                  setVisible(true);          }
142    
143            public boolean close() {
144                    // Only close by ESC and window-close if a valid selection is made
145                    if (jComboBox.getSelectedIndex() == languages.size())
146                            return false;
147                    else
148                            return super.close();
149          }          }
150    
151          /**          /**
# Line 252  public class SwitchLanguageDialog extend Line 279  public class SwitchLanguageDialog extend
279                          String[] langNames = new String[languages.size() + 1];                          String[] langNames = new String[languages.size() + 1];
280                          for (int i = 0; i < languages.size(); i++) {                          for (int i = 0; i < languages.size(); i++) {
281    
282                                  Locale locale = I8NUtil.getLocaleFor(languages.get(i));                                  Locale locale = I8NUtil.getFirstLocaleForLang(languages.get(i));
283    
284                                  langNames[i] = locale.getDisplayLanguage(locale) + " / "                                  langNames[i] = locale.getDisplayLanguage(locale) + " / "
285                                                  + locale.getDisplayLanguage() + " / "                                                  + locale.getDisplayLanguage() + " / "
# Line 273  public class SwitchLanguageDialog extend Line 300  public class SwitchLanguageDialog extend
300    
301                                          String l = languages.get(jComboBox.getSelectedIndex());                                          String l = languages.get(jComboBox.getSelectedIndex());
302                                          try {                                          try {
303                                                  Translation.setActiveLang(l);                                                  Translation.setActiveLang(l, setLocale);
304    
305                                                  getJButton().setEnabled(true);                                                  getJButton().setEnabled(true);
306                                          } catch (java.lang.IllegalArgumentException ee) {                                          } catch (java.lang.IllegalArgumentException ee) {

Legend:
Removed from v.607  
changed lines
  Added in v.1100

[email protected]
ViewVC Help
Powered by ViewVC 1.1.26