KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > properties > LocalePanel


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20
21 package org.netbeans.modules.properties;
22
23
24 import java.awt.Component JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.util.Locale JavaDoc;
27 import javax.swing.DefaultListCellRenderer JavaDoc;
28 import javax.swing.JComboBox JavaDoc;
29 import javax.swing.JLabel JavaDoc;
30 import javax.swing.JList JavaDoc;
31 import javax.swing.JPanel JavaDoc;
32 import javax.swing.plaf.basic.BasicComboBoxRenderer JavaDoc;
33
34 import org.openide.util.HelpCtx;
35 import org.openide.util.NbBundle;
36
37
38 /**
39  * Panel to allow user convenient to choose locale.
40  *
41  * @author Peter Zavadsky
42  * @author Marian Petras
43  * @see java.util.Locale
44  */

45 public class LocalePanel extends JPanel JavaDoc {
46
47     /** Variable holding actually chosen <code>Locale</code> object. */
48     private Locale JavaDoc locale;
49
50     /** Property name of <code>locale</code> property. */
51     public static final String JavaDoc PROP_CUSTOMIZED_LOCALE = "customized_locale"; // NOI18N
52

53     /** Array representing supported locales by Java platform.
54      * You can find them at <a HREF="http://java.sun.com/j2se/1.3/docs/guide/intl/locale.doc.html">Supported Locales.</a>
55      * This should be taken as temporary solution. And revised after announced changes in API dealing with supported
56      * locales.
57      */

58     private static final Locale JavaDoc[] supportedLocales = new Locale JavaDoc[] {
59         new Locale JavaDoc("ar", "AE", ""), // NOI18N // Arabic United Arab Emirates
60
new Locale JavaDoc("ar", "BH", ""), // NOI18N // Arabic Bahrain
61
new Locale JavaDoc("ar", "DZ", ""), // NOI18N // Arabic Algeria
62
new Locale JavaDoc("ar", "EG", ""), // NOI18N // Arabic Egypt
63
new Locale JavaDoc("ar", "IQ", ""), // NOI18N // Arabic Iraq
64
new Locale JavaDoc("ar", "JO", ""), // NOI18N // Arabic Jordan
65
new Locale JavaDoc("ar", "KW", ""), // NOI18N // Arabic Kuwait
66
new Locale JavaDoc("ar", "LB", ""), // NOI18N // Arabic Lebanon
67
new Locale JavaDoc("ar", "LY", ""), // NOI18N // Arabic Libya
68
new Locale JavaDoc("ar", "MA", ""), // NOI18N // Arabic Morocco
69
new Locale JavaDoc("ar", "OM", ""), // NOI18N // Arabic Oman
70
new Locale JavaDoc("ar", "QA", ""), // NOI18N // Arabic Qatar
71
new Locale JavaDoc("ar", "SA", ""), // NOI18N // Arabic Saudi Arabia
72
new Locale JavaDoc("ar", "SD", ""), // NOI18N // Arabic Sudan
73
new Locale JavaDoc("ar", "SY", ""), // NOI18N // Arabic Syria
74
new Locale JavaDoc("ar", "TN", ""), // NOI18N // Arabic Tunisia
75
new Locale JavaDoc("ar", "YE", ""), // NOI18N // Arabic Yemen
76
new Locale JavaDoc("be", "BY", ""), // NOI18N // Byelorussian Belarus
77
new Locale JavaDoc("bg", "BG", ""), // NOI18N // Bulgarian Bulgaria
78
new Locale JavaDoc("ca", "ES", ""), // NOI18N // Catalan Spain
79
new Locale JavaDoc("cs", "CZ", ""), // NOI18N // Czech Czech Republic
80
new Locale JavaDoc("da", "DK", ""), // NOI18N // Danish Denmark
81
new Locale JavaDoc("de", "AT", ""), // NOI18N // German Austria
82
new Locale JavaDoc("de", "AT", "EURO"), // NOI18N // German Austria
83
new Locale JavaDoc("de", "CH", ""), // NOI18N // German Switzerland
84
new Locale JavaDoc("de", "DE", ""), // NOI18N // German Germany
85
new Locale JavaDoc("de", "DE", "EURO"), // NOI18N // German Germany
86
new Locale JavaDoc("de", "LU", ""), // NOI18N // German Luxembourg
87
new Locale JavaDoc("de", "LU", "EURO"), // NOI18N // German Luxembourg
88
new Locale JavaDoc("el", "GR", ""), // NOI18N // Greek Greece
89
new Locale JavaDoc("en", "AU", ""), // NOI18N // English Australia
90
new Locale JavaDoc("en", "CA", ""), // NOI18N // English Canada
91
new Locale JavaDoc("en", "GB", ""), // NOI18N // English United Kingdom
92
new Locale JavaDoc("en", "IE", ""), // NOI18N // English Ireland
93
new Locale JavaDoc("en", "IE", "EURO"), // NOI18N // English Ireland
94
new Locale JavaDoc("en", "NZ", ""), // NOI18N // English New Zealand
95
new Locale JavaDoc("en", "US", ""), // NOI18N // English United States
96
new Locale JavaDoc("en", "ZA", ""), // NOI18N // English South Africa
97
new Locale JavaDoc("es", "AR", ""), // NOI18N // Spanish Argentina
98
new Locale JavaDoc("es", "BO", ""), // NOI18N // Spanish Bolivia
99
new Locale JavaDoc("es", "CL", ""), // NOI18N // Spanish Chile
100
new Locale JavaDoc("es", "CO", ""), // NOI18N // Spanish Colombia
101
new Locale JavaDoc("es", "CR", ""), // NOI18N // Spanish Costa Rica
102
new Locale JavaDoc("es", "DO", ""), // NOI18N // Spanish Dominican Republic
103
new Locale JavaDoc("es", "EC", ""), // NOI18N // Spanish Ecuador
104
new Locale JavaDoc("es", "ES", ""), // NOI18N // Spanish Spain
105
new Locale JavaDoc("es", "ES", "EURO"), // NOI18N // Spanish Spain
106
new Locale JavaDoc("es", "GT", ""), // NOI18N // Spanish Guatemala
107
new Locale JavaDoc("es", "HN", ""), // NOI18N // Spanish Honduras
108
new Locale JavaDoc("es", "MX", ""), // NOI18N // Spanish Mexico
109
new Locale JavaDoc("es", "NI", ""), // NOI18N // Spanish Nicaragua
110
new Locale JavaDoc("es", "PA", ""), // NOI18N // Spanish Panama
111
new Locale JavaDoc("es", "PE", ""), // NOI18N // Spanish Peru
112
new Locale JavaDoc("es", "PR", ""), // NOI18N // Spanish Puerto Rico
113
new Locale JavaDoc("es", "PY", ""), // NOI18N // Spanish Paraguay
114
new Locale JavaDoc("es", "SV", ""), // NOI18N // Spanish El Salvador
115
new Locale JavaDoc("es", "UY", ""), // NOI18N // Spanish Uruguay
116
new Locale JavaDoc("es", "VE", ""), // NOI18N // Spanish Venezuela
117
new Locale JavaDoc("et", "EE", ""), // NOI18N // Estonian Estonia
118
new Locale JavaDoc("fi", "FI", ""), // NOI18N // Finnish Finland
119
new Locale JavaDoc("fi", "FI", "EURO"), // NOI18N // Finnish Finland
120
new Locale JavaDoc("fr", "BE", ""), // NOI18N // French Belgium
121
new Locale JavaDoc("fr", "BE", "EURO"), // NOI18N // French Belgium
122
new Locale JavaDoc("fr", "CA", ""), // NOI18N // French Canada
123
new Locale JavaDoc("fr", "CH", ""), // NOI18N // French Switzerland
124
new Locale JavaDoc("fr", "FR", ""), // NOI18N // French France
125
new Locale JavaDoc("fr", "FR", "EURO"), // NOI18N // French France
126
new Locale JavaDoc("fr", "LU", ""), // NOI18N // French Luxembourg
127
new Locale JavaDoc("fr", "LU", "EURO"), // NOI18N // French Luxembourg
128
new Locale JavaDoc("hr", "HR", ""), // NOI18N // Croatian Croatia
129
new Locale JavaDoc("hu", "HU", ""), // NOI18N // Hungarian Hungary
130
new Locale JavaDoc("is", "IS", ""), // NOI18N // Icelandic Iceland
131
new Locale JavaDoc("it", "CH", ""), // NOI18N // Italian Switzerland
132
new Locale JavaDoc("it", "IT", ""), // NOI18N // Italian Italy
133
new Locale JavaDoc("it", "IT", "EURO"), // NOI18N // Italian Italy
134
new Locale JavaDoc("iw", "IL", ""), // NOI18N // Hebrew Israel
135
new Locale JavaDoc("ja", "JP", ""), // NOI18N // Japanese Japan
136
new Locale JavaDoc("ko", "KR", ""), // NOI18N // Korean South Korea
137
new Locale JavaDoc("lt", "LT", ""), // NOI18N // Lithuanian Lithuania
138
new Locale JavaDoc("lv", "LV", ""), // NOI18N // Latvian Latvia
139
new Locale JavaDoc("mk", "MK", ""), // NOI18N // Macedonian Macedonia
140
new Locale JavaDoc("nl", "BE", ""), // NOI18N // Dutch Belgium
141
new Locale JavaDoc("nl", "BE", "EURO"), // NOI18N // Dutch Belgium
142
new Locale JavaDoc("nl", "NL", ""), // NOI18N // Dutch Netherlands
143
new Locale JavaDoc("nl", "NL", "EURO"), // NOI18N // Dutch Netherlands
144
new Locale JavaDoc("no", "NO", ""), // NOI18N // Norwegian (Nynorsk) Norway
145
new Locale JavaDoc("no", "NO", "B"), // NOI18N // Norwegian (Bokmal) Norway
146
new Locale JavaDoc("pl", "PL", ""), // NOI18N // Polish Poland
147
new Locale JavaDoc("pt", "BR", ""), // NOI18N // Portuguese Brazil
148
new Locale JavaDoc("pt", "PT", ""), // NOI18N // Portuguese Portugal
149
new Locale JavaDoc("pt", "PT", "EURO"), // NOI18N // Portuguese Portugal
150
new Locale JavaDoc("ro", "RO", ""), // NOI18N // Romanian Romania
151
new Locale JavaDoc("ru", "RU", ""), // NOI18N // Russian Russia
152
new Locale JavaDoc("sh", "YU", ""), // NOI18N // Serbo-Croatian Yugoslavia
153
new Locale JavaDoc("sk", "SK", ""), // NOI18N // Slovakian Slovakia
154
new Locale JavaDoc("sl", "SI", ""), // NOI18N // Slovenian Slovenia
155
new Locale JavaDoc("sq", "AL", ""), // NOI18N // Albanian Albania
156
new Locale JavaDoc("sr", "YU", ""), // NOI18N // Serbian (Cyrillic) Yugoslavia
157
new Locale JavaDoc("sv", "SE", ""), // NOI18N // Swedish Sweden
158
new Locale JavaDoc("th", "TH", ""), // NOI18N // Thai Thailand
159
new Locale JavaDoc("tr", "TR", ""), // NOI18N // Turkish Turkey
160
new Locale JavaDoc("uk", "UA", ""), // NOI18N // Ukranian Ukraine
161
new Locale JavaDoc("vi", "VN", ""), // NOI18N // Vietnamese Vietnam
162
new Locale JavaDoc("zh", "CN", ""), // NOI18N // Chinese (Simplified) China
163
new Locale JavaDoc("zh", "HK", ""), // NOI18N // Chinese Hong Kong
164
new Locale JavaDoc("zh", "TW", ""), // NOI18N // Chinese (Traditional) Taiwan
165
};
166
167     
168     /** Creates new <code>LocalePanel</code>. */
169     public LocalePanel() {
170         this(new Locale JavaDoc("", "", "")); // NOI18N
171
}
172     
173     /** <code>Creates new LocalePanel</code>. */
174     public LocalePanel(Locale JavaDoc locale) {
175         this.locale = locale;
176         
177         initComponents();
178         initAccessibility();
179         
180         languageCombo.setSelectedItem(locale.getLanguage());
181         countryCombo.setSelectedItem(locale.getCountry());
182         variantCombo.setSelectedItem(locale.getVariant());
183         
184         localeText.setText(locale.toString());
185         
186         HelpCtx.setHelpIDString(this, Util.HELP_ID_ADDLOCALE);
187     }
188
189     
190     /** Getter for <code>locale</code> property. */
191     public Locale JavaDoc getLocale() {
192         return locale;
193     }
194     
195     private void initAccessibility() {
196         this.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(LocalePanel.class).getString("ACS_LocalePanel"));
197         
198         localeText.getAccessibleContext().setAccessibleName(NbBundle.getBundle(LocalePanel.class).getString("ACS_CTL_LocaleText"));
199         localeText.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(LocalePanel.class).getString("ACS_CTL_LocaleText"));
200         countryCombo.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(LocalePanel.class).getString("ACS_CTL_CountryCombo"));
201         languageCombo.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(LocalePanel.class).getString("ACS_CTL_LanguageCombo"));
202         supportedList.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(LocalePanel.class).getString("ACS_CTL_SupportedList"));
203         variantCombo.getAccessibleContext().setAccessibleDescription(NbBundle.getBundle(LocalePanel.class).getString("ACS_CTL_VariantCombo"));
204     }
205     
206     /** This method is called from within the constructor to
207      * initialize the form.
208      * WARNING: Do NOT modify this code. The content of this method is
209      * always regenerated by the Form Editor.
210      */

211     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
212
private void initComponents() {
213
214         languageLabel = new javax.swing.JLabel JavaDoc();
215         languageCombo = new JComboBox JavaDoc(Locale.getISOLanguages());
216         countryLabel = new javax.swing.JLabel JavaDoc();
217         countryCombo = new JComboBox JavaDoc(Locale.getISOCountries());
218         variantLabel = new javax.swing.JLabel JavaDoc();
219         variantCombo = new JComboBox JavaDoc(new String JavaDoc[] {
220             "B", // Bokmal // NOI18N
221
"EURO", // EURO // NOI18N
222
"NY" // Nynorsk // NOI18N
223
});
224         ;
225         supportedLabel = new javax.swing.JLabel JavaDoc();
226         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
227         supportedList = new JList JavaDoc(supportedLocales);
228         localeLabel = new javax.swing.JLabel JavaDoc();
229         localeText = new javax.swing.JTextField JavaDoc();
230
231         languageLabel.setLabelFor(languageCombo);
232         org.openide.awt.Mnemonics.setLocalizedText(languageLabel, NbBundle.getBundle(LocalePanel.class).getString("CTL_LanguageCode")); // NOI18N
233

234         languageCombo.setEditable(true);
235         languageCombo.setRenderer(new NbBasicComboBoxRenderer() {
236             public Component JavaDoc getListCellRendererComponent(
237                 JList JavaDoc list,
238                 Object JavaDoc value, // value to display
239
int index, // cell index
240
boolean isSelected, // is the cell selected
241
boolean cellHasFocus) // the list and the cell have the focus
242
{
243                 JLabel JavaDoc label = (JLabel JavaDoc)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
244
245                 if("".equals(value.toString())) // NOI18N
246
label.setText(""); // NOI18N
247
else
248                 label.setText(value.toString() + " - " + new Locale JavaDoc((String JavaDoc)value, "", "").getDisplayLanguage()); // NOI18N
249

250                 return label;
251             }
252         });
253         // Insert empty string at the beginning.
254
languageCombo.insertItemAt("", 0); // NOI18N
255
languageCombo.setSelectedIndex(0);
256         languageCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
257             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
258                 languageComboActionPerformed(evt);
259             }
260         });
261
262         countryLabel.setLabelFor(countryCombo);
263         org.openide.awt.Mnemonics.setLocalizedText(countryLabel, NbBundle.getBundle(LocalePanel.class).getString("CTL_CountryCode")); // NOI18N
264

265         countryCombo.setEditable(true);
266         countryCombo.setRenderer(new NbBasicComboBoxRenderer() {
267             public Component JavaDoc getListCellRendererComponent(
268                 JList JavaDoc list,
269                 Object JavaDoc value, // value to display
270
int index, // cell index
271
boolean isSelected, // is the cell selected
272
boolean cellHasFocus) // the list and the cell have the focus
273
{
274                 JLabel JavaDoc label = (JLabel JavaDoc)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
275
276                 if("".equals(value.toString())) // NOI18N
277
label.setText(""); // NOI18N
278
else
279                 label.setText(value.toString() + " - " + new Locale JavaDoc("", (String JavaDoc)value, "").getDisplayCountry()); // NOI18N
280

281                 return label;
282             }
283         });
284         // Insert empty string at the beginning.
285
countryCombo.insertItemAt("", 0); // NOI18N
286
countryCombo.setSelectedIndex(0);
287         countryCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
288             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
289                 countryComboActionPerformed(evt);
290             }
291         });
292
293         variantLabel.setLabelFor(variantCombo);
294         org.openide.awt.Mnemonics.setLocalizedText(variantLabel, NbBundle.getBundle(LocalePanel.class).getString("CTL_Variant")); // NOI18N
295

296         variantCombo.setEditable(true);
297         variantCombo.setRenderer(new NbBasicComboBoxRenderer() {
298             public Component JavaDoc getListCellRendererComponent(
299                 JList JavaDoc list,
300                 Object JavaDoc value, // value to display
301
int index, // cell index
302
boolean isSelected, // is the cell selected
303
boolean cellHasFocus) // the list and the cell have the focus
304
{
305                 JLabel JavaDoc label = (JLabel JavaDoc)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
306
307                 if("".equals(value.toString())) // NOI18N
308
label.setText(""); // NOI18N
309
else
310                 label.setText(value.toString() + " - " + new Locale JavaDoc("", "", (String JavaDoc)value).getDisplayVariant()); // NOI18N
311

312                 return label;
313             }
314         });
315         // Insert empty string at the beginning.
316
variantCombo.insertItemAt("", 0); // NOI18N
317
variantCombo.setSelectedIndex(0);
318         variantCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
319             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
320                 variantComboActionPerformed(evt);
321             }
322         });
323
324         supportedLabel.setLabelFor(supportedList);
325         org.openide.awt.Mnemonics.setLocalizedText(supportedLabel, NbBundle.getBundle(LocalePanel.class).getString("CTL_SupportedLocales")); // NOI18N
326

327         supportedList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
328         supportedList.setCellRenderer(new DefaultListCellRenderer JavaDoc() {
329             public Component JavaDoc getListCellRendererComponent(
330                 JList JavaDoc list,
331                 Object JavaDoc value, // value to display
332
int index, // cell index
333
boolean isSelected, // is the cell selected
334
boolean cellHasFocus) // the list and the cell have the focus
335
{
336                 JLabel JavaDoc label = (JLabel JavaDoc)super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
337
338                 Locale JavaDoc locale = (Locale JavaDoc)value;
339
340                 label.setText(locale.toString() +
341                     (locale.getLanguage().equals("") ? "" : " - " + locale.getDisplayLanguage()) + // NOI18N
342
(locale.getCountry().equals("") ? "" : " / " + locale.getDisplayCountry()) + // NOI18N
343
(locale.getVariant().equals("") ? "" : " / " + locale.getDisplayVariant()) // NOI18N
344
);
345
346                 return label;
347             }
348         });
349         supportedList.addListSelectionListener(new javax.swing.event.ListSelectionListener JavaDoc() {
350             public void valueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {
351                 supportedListValueChanged(evt);
352             }
353         });
354         jScrollPane1.setViewportView(supportedList);
355
356         localeLabel.setLabelFor(localeText);
357         org.openide.awt.Mnemonics.setLocalizedText(localeLabel, org.openide.util.NbBundle.getMessage(LocalePanel.class, "CTL_Locale")); // NOI18N
358

359         localeText.setEditable(false);
360         localeText.selectAll();
361         localeText.addFocusListener(new java.awt.event.FocusAdapter JavaDoc() {
362             public void focusGained(java.awt.event.FocusEvent JavaDoc evt) {
363                 localeTextFocusGained(evt);
364             }
365         });
366
367         org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
368         this.setLayout(layout);
369         layout.setHorizontalGroup(
370             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
371             .add(layout.createSequentialGroup()
372                 .addContainerGap()
373                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
374                     .add(layout.createSequentialGroup()
375                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
376                             .add(localeLabel)
377                             .add(languageLabel)
378                             .add(countryLabel)
379                             .add(variantLabel))
380                         .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
381                         .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
382                             .add(languageCombo, 0, 297, Short.MAX_VALUE)
383                             .add(countryCombo, 0, 297, Short.MAX_VALUE)
384                             .add(variantCombo, 0, 297, Short.MAX_VALUE)
385                             .add(localeText, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 297, Short.MAX_VALUE)))
386                     .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 408, Short.MAX_VALUE)
387                     .add(supportedLabel))
388                 .addContainerGap())
389         );
390         layout.setVerticalGroup(
391             layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
392             .add(layout.createSequentialGroup()
393                 .add(12, 12, 12)
394                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
395                     .add(localeLabel)
396                     .add(localeText, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
397                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
398                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
399                     .add(languageLabel)
400                     .add(languageCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
401                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
402                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
403                     .add(countryLabel)
404                     .add(countryCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
405                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
406                 .add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
407                     .add(variantLabel)
408                     .add(variantCombo, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE))
409                 .add(17, 17, 17)
410                 .add(supportedLabel)
411                 .addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
412                 .add(jScrollPane1, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 128, Short.MAX_VALUE)
413                 .addContainerGap())
414         );
415     }// </editor-fold>//GEN-END:initComponents
416

417     private void localeTextFocusGained(java.awt.event.FocusEvent JavaDoc evt) {//GEN-FIRST:event_localeTextFocusGained
418
// Accessibility
419
localeText.selectAll();
420     }//GEN-LAST:event_localeTextFocusGained
421

422     private void supportedListValueChanged(javax.swing.event.ListSelectionEvent JavaDoc evt) {//GEN-FIRST:event_supportedListValueChanged
423
Locale JavaDoc selectedLocale = (Locale JavaDoc)supportedList.getSelectedValue();
424         
425         if (selectedLocale != null) {
426         languageCombo.setSelectedItem(selectedLocale.getLanguage());
427         countryCombo.setSelectedItem(selectedLocale.getCountry());
428         variantCombo.setSelectedItem(selectedLocale.getVariant());
429     }
430         
431         supportedList.ensureIndexIsVisible(supportedList.getSelectedIndex());
432     }//GEN-LAST:event_supportedListValueChanged
433

434     private void variantComboActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_variantComboActionPerformed
435
comboHandler(evt);
436     }//GEN-LAST:event_variantComboActionPerformed
437

438     private void countryComboActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_countryComboActionPerformed
439
comboHandler(evt);
440     }//GEN-LAST:event_countryComboActionPerformed
441

442     private void languageComboActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_languageComboActionPerformed
443
comboHandler(evt);
444     }//GEN-LAST:event_languageComboActionPerformed
445

446     /** Combo box event handler. Helper method. */
447     private void comboHandler(ActionEvent JavaDoc evt) {
448         String JavaDoc str = (String JavaDoc)((JComboBox JavaDoc)evt.getSource()).getSelectedItem();
449
450         Locale JavaDoc oldLocale = locale;
451         
452         Object JavaDoc source = evt.getSource();
453         if(source.equals(languageCombo)) {
454             // 99% trick to avoid unneccessary reset of the string (kind of event filter) ,
455
// e.g. when loosing the focus and was choosen item from list right before etc.
456
if(str.equals(locale.getLanguage()))
457                 return;
458             
459             locale = new Locale JavaDoc(str, locale.getCountry(), locale.getVariant());
460         } else if(source.equals(countryCombo)) {
461             if(str.equals(locale.getCountry()))
462                 return;
463             
464             locale = new Locale JavaDoc(locale.getLanguage(), str, locale.getVariant());
465         } else if(source.equals(variantCombo)) {
466             if(str.equals(locale.getVariant()))
467                 return;
468             
469             locale = new Locale JavaDoc(locale.getLanguage(), locale.getCountry(), str);
470         }
471
472         localeText.setText(locale.toString());
473
474         firePropertyChange(PROP_CUSTOMIZED_LOCALE, oldLocale, locale);
475     }
476
477     // Variables declaration - do not modify//GEN-BEGIN:variables
478
private javax.swing.JComboBox JavaDoc countryCombo;
479     private javax.swing.JLabel JavaDoc countryLabel;
480     private javax.swing.JScrollPane JavaDoc jScrollPane1;
481     private javax.swing.JComboBox JavaDoc languageCombo;
482     private javax.swing.JLabel JavaDoc languageLabel;
483     private javax.swing.JLabel JavaDoc localeLabel;
484     private javax.swing.JTextField JavaDoc localeText;
485     private javax.swing.JLabel JavaDoc supportedLabel;
486     private javax.swing.JList JavaDoc supportedList;
487     private javax.swing.JComboBox JavaDoc variantCombo;
488     private javax.swing.JLabel JavaDoc variantLabel;
489     // End of variables declaration//GEN-END:variables
490

491     private static abstract class NbBasicComboBoxRenderer extends BasicComboBoxRenderer.UIResource JavaDoc {
492         
493         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value,
494                 int index, boolean isSelected, boolean cellHasFocus) {
495             // #93658: GTK needs name to render cell renderer "natively"
496
setName("ComboBox.listRenderer"); // NOI18N
497
return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus);
498         }
499         
500         // #93658: GTK needs name to render cell renderer "natively"
501
public String JavaDoc getName() {
502             String JavaDoc name = super.getName();
503             return name == null ? "ComboBox.renderer" : name; // NOI18N
504
}
505         
506     }
507     
508 }
509
Popular Tags