1 19 20 21 package org.netbeans.modules.properties; 22 23 24 import java.awt.Component ; 25 import java.awt.event.ActionEvent ; 26 import java.util.Locale ; 27 import javax.swing.DefaultListCellRenderer ; 28 import javax.swing.JComboBox ; 29 import javax.swing.JLabel ; 30 import javax.swing.JList ; 31 import javax.swing.JPanel ; 32 import javax.swing.plaf.basic.BasicComboBoxRenderer ; 33 34 import org.openide.util.HelpCtx; 35 import org.openide.util.NbBundle; 36 37 38 45 public class LocalePanel extends JPanel { 46 47 48 private Locale locale; 49 50 51 public static final String PROP_CUSTOMIZED_LOCALE = "customized_locale"; 53 58 private static final Locale [] supportedLocales = new Locale [] { 59 new Locale ("ar", "AE", ""), new Locale ("ar", "BH", ""), new Locale ("ar", "DZ", ""), new Locale ("ar", "EG", ""), new Locale ("ar", "IQ", ""), new Locale ("ar", "JO", ""), new Locale ("ar", "KW", ""), new Locale ("ar", "LB", ""), new Locale ("ar", "LY", ""), new Locale ("ar", "MA", ""), new Locale ("ar", "OM", ""), new Locale ("ar", "QA", ""), new Locale ("ar", "SA", ""), new Locale ("ar", "SD", ""), new Locale ("ar", "SY", ""), new Locale ("ar", "TN", ""), new Locale ("ar", "YE", ""), new Locale ("be", "BY", ""), new Locale ("bg", "BG", ""), new Locale ("ca", "ES", ""), new Locale ("cs", "CZ", ""), new Locale ("da", "DK", ""), new Locale ("de", "AT", ""), new Locale ("de", "AT", "EURO"), new Locale ("de", "CH", ""), new Locale ("de", "DE", ""), new Locale ("de", "DE", "EURO"), new Locale ("de", "LU", ""), new Locale ("de", "LU", "EURO"), new Locale ("el", "GR", ""), new Locale ("en", "AU", ""), new Locale ("en", "CA", ""), new Locale ("en", "GB", ""), new Locale ("en", "IE", ""), new Locale ("en", "IE", "EURO"), new Locale ("en", "NZ", ""), new Locale ("en", "US", ""), new Locale ("en", "ZA", ""), new Locale ("es", "AR", ""), new Locale ("es", "BO", ""), new Locale ("es", "CL", ""), new Locale ("es", "CO", ""), new Locale ("es", "CR", ""), new Locale ("es", "DO", ""), new Locale ("es", "EC", ""), new Locale ("es", "ES", ""), new Locale ("es", "ES", "EURO"), new Locale ("es", "GT", ""), new Locale ("es", "HN", ""), new Locale ("es", "MX", ""), new Locale ("es", "NI", ""), new Locale ("es", "PA", ""), new Locale ("es", "PE", ""), new Locale ("es", "PR", ""), new Locale ("es", "PY", ""), new Locale ("es", "SV", ""), new Locale ("es", "UY", ""), new Locale ("es", "VE", ""), new Locale ("et", "EE", ""), new Locale ("fi", "FI", ""), new Locale ("fi", "FI", "EURO"), new Locale ("fr", "BE", ""), new Locale ("fr", "BE", "EURO"), new Locale ("fr", "CA", ""), new Locale ("fr", "CH", ""), new Locale ("fr", "FR", ""), new Locale ("fr", "FR", "EURO"), new Locale ("fr", "LU", ""), new Locale ("fr", "LU", "EURO"), new Locale ("hr", "HR", ""), new Locale ("hu", "HU", ""), new Locale ("is", "IS", ""), new Locale ("it", "CH", ""), new Locale ("it", "IT", ""), new Locale ("it", "IT", "EURO"), new Locale ("iw", "IL", ""), new Locale ("ja", "JP", ""), new Locale ("ko", "KR", ""), new Locale ("lt", "LT", ""), new Locale ("lv", "LV", ""), new Locale ("mk", "MK", ""), new Locale ("nl", "BE", ""), new Locale ("nl", "BE", "EURO"), new Locale ("nl", "NL", ""), new Locale ("nl", "NL", "EURO"), new Locale ("no", "NO", ""), new Locale ("no", "NO", "B"), new Locale ("pl", "PL", ""), new Locale ("pt", "BR", ""), new Locale ("pt", "PT", ""), new Locale ("pt", "PT", "EURO"), new Locale ("ro", "RO", ""), new Locale ("ru", "RU", ""), new Locale ("sh", "YU", ""), new Locale ("sk", "SK", ""), new Locale ("sl", "SI", ""), new Locale ("sq", "AL", ""), new Locale ("sr", "YU", ""), new Locale ("sv", "SE", ""), new Locale ("th", "TH", ""), new Locale ("tr", "TR", ""), new Locale ("uk", "UA", ""), new Locale ("vi", "VN", ""), new Locale ("zh", "CN", ""), new Locale ("zh", "HK", ""), new Locale ("zh", "TW", ""), }; 166 167 168 169 public LocalePanel() { 170 this(new Locale ("", "", "")); } 172 173 174 public LocalePanel(Locale 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 191 public Locale 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 211 private void initComponents() { 213 214 languageLabel = new javax.swing.JLabel (); 215 languageCombo = new JComboBox (Locale.getISOLanguages()); 216 countryLabel = new javax.swing.JLabel (); 217 countryCombo = new JComboBox (Locale.getISOCountries()); 218 variantLabel = new javax.swing.JLabel (); 219 variantCombo = new JComboBox (new String [] { 220 "B", "EURO", "NY" }); 224 ; 225 supportedLabel = new javax.swing.JLabel (); 226 jScrollPane1 = new javax.swing.JScrollPane (); 227 supportedList = new JList (supportedLocales); 228 localeLabel = new javax.swing.JLabel (); 229 localeText = new javax.swing.JTextField (); 230 231 languageLabel.setLabelFor(languageCombo); 232 org.openide.awt.Mnemonics.setLocalizedText(languageLabel, NbBundle.getBundle(LocalePanel.class).getString("CTL_LanguageCode")); 234 languageCombo.setEditable(true); 235 languageCombo.setRenderer(new NbBasicComboBoxRenderer() { 236 public Component getListCellRendererComponent( 237 JList list, 238 Object value, int index, boolean isSelected, boolean cellHasFocus) { 243 JLabel label = (JLabel )super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 244 245 if("".equals(value.toString())) label.setText(""); else 248 label.setText(value.toString() + " - " + new Locale ((String )value, "", "").getDisplayLanguage()); 250 return label; 251 } 252 }); 253 languageCombo.insertItemAt("", 0); languageCombo.setSelectedIndex(0); 256 languageCombo.addActionListener(new java.awt.event.ActionListener () { 257 public void actionPerformed(java.awt.event.ActionEvent 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")); 265 countryCombo.setEditable(true); 266 countryCombo.setRenderer(new NbBasicComboBoxRenderer() { 267 public Component getListCellRendererComponent( 268 JList list, 269 Object value, int index, boolean isSelected, boolean cellHasFocus) { 274 JLabel label = (JLabel )super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 275 276 if("".equals(value.toString())) label.setText(""); else 279 label.setText(value.toString() + " - " + new Locale ("", (String )value, "").getDisplayCountry()); 281 return label; 282 } 283 }); 284 countryCombo.insertItemAt("", 0); countryCombo.setSelectedIndex(0); 287 countryCombo.addActionListener(new java.awt.event.ActionListener () { 288 public void actionPerformed(java.awt.event.ActionEvent 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")); 296 variantCombo.setEditable(true); 297 variantCombo.setRenderer(new NbBasicComboBoxRenderer() { 298 public Component getListCellRendererComponent( 299 JList list, 300 Object value, int index, boolean isSelected, boolean cellHasFocus) { 305 JLabel label = (JLabel )super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 306 307 if("".equals(value.toString())) label.setText(""); else 310 label.setText(value.toString() + " - " + new Locale ("", "", (String )value).getDisplayVariant()); 312 return label; 313 } 314 }); 315 variantCombo.insertItemAt("", 0); variantCombo.setSelectedIndex(0); 318 variantCombo.addActionListener(new java.awt.event.ActionListener () { 319 public void actionPerformed(java.awt.event.ActionEvent 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")); 327 supportedList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION); 328 supportedList.setCellRenderer(new DefaultListCellRenderer () { 329 public Component getListCellRendererComponent( 330 JList list, 331 Object value, int index, boolean isSelected, boolean cellHasFocus) { 336 JLabel label = (JLabel )super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 337 338 Locale locale = (Locale )value; 339 340 label.setText(locale.toString() + 341 (locale.getLanguage().equals("") ? "" : " - " + locale.getDisplayLanguage()) + (locale.getCountry().equals("") ? "" : " / " + locale.getDisplayCountry()) + (locale.getVariant().equals("") ? "" : " / " + locale.getDisplayVariant()) ); 345 346 return label; 347 } 348 }); 349 supportedList.addListSelectionListener(new javax.swing.event.ListSelectionListener () { 350 public void valueChanged(javax.swing.event.ListSelectionEvent 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")); 359 localeText.setEditable(false); 360 localeText.selectAll(); 361 localeText.addFocusListener(new java.awt.event.FocusAdapter () { 362 public void focusGained(java.awt.event.FocusEvent 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 } 417 private void localeTextFocusGained(java.awt.event.FocusEvent evt) { localeText.selectAll(); 420 } 422 private void supportedListValueChanged(javax.swing.event.ListSelectionEvent evt) { Locale selectedLocale = (Locale )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 } 434 private void variantComboActionPerformed(java.awt.event.ActionEvent evt) { comboHandler(evt); 436 } 438 private void countryComboActionPerformed(java.awt.event.ActionEvent evt) { comboHandler(evt); 440 } 442 private void languageComboActionPerformed(java.awt.event.ActionEvent evt) { comboHandler(evt); 444 } 446 447 private void comboHandler(ActionEvent evt) { 448 String str = (String )((JComboBox )evt.getSource()).getSelectedItem(); 449 450 Locale oldLocale = locale; 451 452 Object source = evt.getSource(); 453 if(source.equals(languageCombo)) { 454 if(str.equals(locale.getLanguage())) 457 return; 458 459 locale = new Locale (str, locale.getCountry(), locale.getVariant()); 460 } else if(source.equals(countryCombo)) { 461 if(str.equals(locale.getCountry())) 462 return; 463 464 locale = new Locale (locale.getLanguage(), str, locale.getVariant()); 465 } else if(source.equals(variantCombo)) { 466 if(str.equals(locale.getVariant())) 467 return; 468 469 locale = new Locale (locale.getLanguage(), locale.getCountry(), str); 470 } 471 472 localeText.setText(locale.toString()); 473 474 firePropertyChange(PROP_CUSTOMIZED_LOCALE, oldLocale, locale); 475 } 476 477 private javax.swing.JComboBox countryCombo; 479 private javax.swing.JLabel countryLabel; 480 private javax.swing.JScrollPane jScrollPane1; 481 private javax.swing.JComboBox languageCombo; 482 private javax.swing.JLabel languageLabel; 483 private javax.swing.JLabel localeLabel; 484 private javax.swing.JTextField localeText; 485 private javax.swing.JLabel supportedLabel; 486 private javax.swing.JList supportedList; 487 private javax.swing.JComboBox variantCombo; 488 private javax.swing.JLabel variantLabel; 489 491 private static abstract class NbBasicComboBoxRenderer extends BasicComboBoxRenderer.UIResource { 492 493 public Component getListCellRendererComponent(JList list, Object value, 494 int index, boolean isSelected, boolean cellHasFocus) { 495 setName("ComboBox.listRenderer"); return super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); 498 } 499 500 public String getName() { 502 String name = super.getName(); 503 return name == null ? "ComboBox.renderer" : name; } 505 506 } 507 508 } 509 | Popular Tags |