- Timestamp:
- 2009-11-28T17:27:34+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/preferences
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/LanguagePreference.java
r1742 r2535 5 5 6 6 import java.awt.Component; 7 import java.io.IOException; 8 import java.lang.reflect.InvocationTargetException; 9 import java.util.ArrayList; 10 import java.util.Arrays; 11 import java.util.List; 7 12 import java.util.Locale; 13 import java.util.logging.Logger; 8 14 9 15 import javax.swing.Box; … … 14 20 import javax.swing.JPanel; 15 21 import javax.swing.ListCellRenderer; 22 import javax.swing.SwingUtilities; 23 import javax.swing.event.ChangeEvent; 24 import javax.swing.event.ChangeListener; 16 25 17 26 import org.openstreetmap.josm.Main; 27 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 28 import org.openstreetmap.josm.io.OsmTransferException; 18 29 import org.openstreetmap.josm.tools.GBC; 19 30 import org.openstreetmap.josm.tools.I18n; 31 import org.xml.sax.SAXException; 20 32 21 33 public class LanguagePreference implements PreferenceSetting { 34 static private final Logger logger = Logger.getLogger(LanguagePreference.class.getName()); 22 35 23 36 public static class Factory implements PreferenceSettingFactory { … … 31 44 */ 32 45 private JComboBox langCombo; 33 private final Locale AUTO_LANGUAGE = null;46 private boolean translationsLoaded = false; 34 47 35 public void addGui(PreferenceDialog gui) { 36 langCombo = new JComboBox(I18n.getAvailableTranslations()); 37 langCombo.insertItemAt(AUTO_LANGUAGE, 0); // Default 38 langCombo.insertItemAt(Locale.ENGLISH, 1); // Built-in language 39 String ln = Main.pref.get("language"); 40 langCombo.setSelectedIndex(0); 41 42 if (ln != null) { 43 for (int i = 1; i < langCombo.getItemCount(); ++i) { 44 if (((Locale) langCombo.getItemAt(i)).toString().equals(ln)) { 45 langCombo.setSelectedIndex(i); 46 break; 47 } 48 } 49 } 48 public void addGui(final PreferenceDialog gui) { 49 //langCombo = new JComboBox(I18n.getAvailableTranslations()); 50 langCombo = new JComboBox(new Locale[0]); 50 51 51 52 final ListCellRenderer oldRenderer = langCombo.getRenderer(); … … 56 57 Locale l = (Locale) value; 57 58 return oldRenderer.getListCellRendererComponent(list, 58 l == AUTO_LANGUAGE? tr("Default (Auto determined)") : l.getDisplayName(),59 index, isSelected, cellHasFocus);59 l == null ? tr("Default (Auto determined)") : l.getDisplayName(), 60 index, isSelected, cellHasFocus); 60 61 } 61 62 }); 62 63 63 64 LafPreference lafPreference = gui.getSetting(LafPreference.class); 64 JPanel panel = lafPreference.panel;65 final JPanel panel = lafPreference.panel; 65 66 panel.add(new JLabel(tr("Language")), GBC.std().insets(20, 0, 0, 0)); 66 67 panel.add(GBC.glue(5,0), GBC.std().fill(GBC.HORIZONTAL)); 67 68 panel.add(langCombo, GBC.eol().fill(GBC.HORIZONTAL)); 68 69 panel.add(Box.createVerticalGlue(), GBC.eol().fill(GBC.BOTH)); 70 71 // this defers loading of available translations to the first time the tab 72 // with the available translations is selected by the user 73 // 74 gui.displaycontent.addChangeListener( 75 new ChangeListener() { 76 public void stateChanged(ChangeEvent e) { 77 int i = gui.displaycontent.getSelectedIndex(); 78 String title = gui.displaycontent.getTitleAt(i); 79 if (title.equals(tr("Look and Feel"))) { 80 initiallyLoadAvailableTranslations(); 81 } 82 } 83 } 84 ); 69 85 } 70 86 … … 74 90 else 75 91 return Main.pref.put("language", 76 ((Locale)langCombo.getSelectedItem()).toString()); 92 ((Locale)langCombo.getSelectedItem()).toString()); 93 } 94 95 public void initiallyLoadAvailableTranslations() { 96 if (!translationsLoaded) { 97 reloadAvailableTranslations(); 98 } 99 translationsLoaded = true; 100 } 101 102 protected void reloadAvailableTranslations() { 103 Main.worker.submit(new AvailableTranslationsLoader()); 104 } 105 106 /** 107 * Asynchronous task to lookup the available translations. 108 * 109 */ 110 private class AvailableTranslationsLoader extends PleaseWaitRunnable { 111 public AvailableTranslationsLoader() { 112 super(tr("Looking up available translations...")); 113 } 114 115 @Override 116 protected void cancel() { 117 // can't cancel 118 } 119 120 @Override 121 protected void realRun() throws SAXException, IOException, OsmTransferException { 122 final List<Locale> locales = new ArrayList<Locale>( 123 Arrays.asList(I18n.getAvailableTranslations(getProgressMonitor())) 124 ); 125 locales.add(0,Locale.ENGLISH); 126 Runnable r = new Runnable() { 127 public void run() { 128 langCombo.removeAll(); 129 langCombo.addItem(null); // the default enry 130 for (Locale locale : locales) { 131 langCombo.addItem(locale); 132 } 133 String ln = Main.pref.get("language"); 134 langCombo.setSelectedIndex(0); 135 if (ln != null) { 136 for (int i = 1; i < langCombo.getItemCount(); ++i) { 137 if (((Locale) langCombo.getItemAt(i)).toString().equals(ln)) { 138 langCombo.setSelectedIndex(i); 139 break; 140 } 141 } 142 } 143 } 144 }; 145 try { 146 SwingUtilities.invokeAndWait(r); 147 } catch(InvocationTargetException e) { 148 throw new RuntimeException(e.getCause()); 149 } catch(InterruptedException e) { 150 throw new RuntimeException(e); 151 } 152 } 153 154 @Override 155 protected void finish() {} 77 156 } 78 157 } -
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceDialog.java
r2028 r2535 14 14 import java.util.LinkedList; 15 15 import java.util.List; 16 import java.util.logging.Logger; 16 17 17 18 import javax.swing.BorderFactory; … … 36 37 */ 37 38 public class PreferenceDialog extends JTabbedPane implements MouseWheelListener { 39 static private final Logger logger = Logger.getLogger(PreferenceDialog.class.getName()); 38 40 39 41 private final static Collection<PreferenceSettingFactory> settingsFactory = new LinkedList<PreferenceSettingFactory>(); … … 122 124 123 125 for (PreferenceSettingFactory factory:settingsFactory) { 124 126 // logger.info("creating settings: " + factory); 125 127 PreferenceSetting setting = factory.createPreferenceSetting(); 126 128 if (setting != null) { … … 133 135 for (Iterator<PreferenceSetting> it = settings.iterator(); it.hasNext();) { 134 136 try { 135 it.next().addGui(this); 137 PreferenceSetting settings = it.next(); 138 //logger.info("adding gui: " + settings); 139 settings.addGui(this); 136 140 } catch (SecurityException e) { 137 141 it.remove();
Note:
See TracChangeset
for help on using the changeset viewer.