Changeset 14149 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2018-08-12T17:24:32+02:00 (6 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 17 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r14143 r14149 43 43 /** 44 44 * Global application preferences 45 */ 45 * @deprecated Use {@link Config#getPref()} or {@link Preferences#main()} 46 */ 47 @Deprecated 46 48 public static final Preferences pref = new Preferences(JosmBaseDirectories.getInstance()); 47 49 -
trunk/src/org/openstreetmap/josm/actions/PreferenceToggleAction.java
r14134 r14149 6 6 import javax.swing.JCheckBoxMenuItem; 7 7 8 import org.openstreetmap.josm. Main;8 import org.openstreetmap.josm.data.Preferences; 9 9 import org.openstreetmap.josm.data.preferences.BooleanProperty; 10 10 import org.openstreetmap.josm.spi.preferences.PreferenceChangeEvent; … … 35 35 checkbox = new JCheckBoxMenuItem(this); 36 36 checkbox.setSelected(pref.get()); 37 Main.pref.addWeakKeyPreferenceChangeListener(prefKey, this);37 Preferences.main().addWeakKeyPreferenceChangeListener(prefKey, this); 38 38 } 39 39 -
trunk/src/org/openstreetmap/josm/actions/ShowStatusReportAction.java
r14143 r14149 26 26 27 27 import org.openstreetmap.josm.Main; 28 import org.openstreetmap.josm.data.Preferences; 28 29 import org.openstreetmap.josm.data.Version; 29 30 import org.openstreetmap.josm.data.osm.DataSet; … … 277 278 String reportHeader = getReportHeader(); 278 279 text.append(reportHeader); 279 Map<String, Setting<?>> settings = Main.pref.getAllSettings();280 Map<String, Setting<?>> settings = Preferences.main().getAllSettings(); 280 281 Set<String> keys = new HashSet<>(settings.keySet()); 281 282 for (String key : keys) { -
trunk/src/org/openstreetmap/josm/actions/mapmode/DrawSnapHelper.java
r13434 r14149 18 18 import javax.swing.JPopupMenu; 19 19 20 import org.openstreetmap.josm. Main;20 import org.openstreetmap.josm.data.Preferences; 21 21 import org.openstreetmap.josm.data.coor.EastNorth; 22 22 import org.openstreetmap.josm.data.coor.LatLon; … … 234 234 235 235 computeSnapAngles(); 236 Main.pref.addWeakKeyPreferenceChangeListener(DRAW_ANGLESNAP_ANGLES, e -> this.computeSnapAngles());236 Preferences.main().addWeakKeyPreferenceChangeListener(DRAW_ANGLESNAP_ANGLES, e -> this.computeSnapAngles()); 237 237 } 238 238 -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r14148 r14149 36 36 import org.openstreetmap.josm.Main; 37 37 import org.openstreetmap.josm.data.preferences.ColorInfo; 38 import org.openstreetmap.josm.data.preferences.JosmBaseDirectories; 38 39 import org.openstreetmap.josm.data.preferences.NamedColorProperty; 39 40 import org.openstreetmap.josm.data.preferences.PreferencesReader; … … 116 117 private final HashMap<String, ListenerList<org.openstreetmap.josm.spi.preferences.PreferenceChangedListener>> keyListeners = new HashMap<>(); 117 118 119 private static final Preferences defaultInstance = new Preferences(JosmBaseDirectories.getInstance()); 120 118 121 /** 119 122 * Constructs a new {@code Preferences}. … … 141 144 settingsMap.putAll(pref.settingsMap); 142 145 defaultsMap.putAll(pref.defaultsMap); 146 } 147 148 /** 149 * Returns the main (default) preferences instance. 150 * @return the main (default) preferences instance 151 * @since 14149 152 */ 153 public static Preferences main() { 154 return defaultInstance; 143 155 } 144 156 … … 274 286 public static Collection<String> getAllPossiblePreferenceDirs() { 275 287 Set<String> locations = new HashSet<>(); 276 addPossibleResourceDir(locations, Config.getDirs().getPreferencesDirectory(false).getPath());277 addPossibleResourceDir(locations, Config.getDirs().getUserDataDirectory(false).getPath());288 addPossibleResourceDir(locations, defaultInstance.dirs.getPreferencesDirectory(false).getPath()); 289 addPossibleResourceDir(locations, defaultInstance.dirs.getUserDataDirectory(false).getPath()); 278 290 addPossibleResourceDir(locations, getSystemEnv("JOSM_RESOURCES")); 279 291 addPossibleResourceDir(locations, getSystemProperty("josm.resources")); -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r14146 r14149 83 83 import org.openstreetmap.josm.command.SplitWayCommand; 84 84 import org.openstreetmap.josm.data.Bounds; 85 import org.openstreetmap.josm.data.Preferences; 85 86 import org.openstreetmap.josm.data.UndoRedoHandler; 86 87 import org.openstreetmap.josm.data.UndoRedoHandler.CommandQueueListener; … … 819 820 PlatformManager.getPlatform().preStartupHook(); 820 821 821 Config.setPreferencesInstance(Main.pref); 822 Preferences prefs = Preferences.main(); 823 Config.setPreferencesInstance(prefs); 822 824 Config.setBaseDirectoriesProvider(JosmBaseDirectories.getInstance()); 823 825 Config.setUrlsProvider(JosmUrls.getInstance()); … … 843 845 844 846 try { 845 Main.pref.init(args.hasOption(Option.RESET_PREFERENCES));847 Preferences.main().init(args.hasOption(Option.RESET_PREFERENCES)); 846 848 } catch (SecurityException e) { 847 849 Logging.log(Logging.LEVEL_ERROR, "Unable to initialize preferences", e); 848 850 } 849 851 850 args.getPreferencesToSet().forEach( Main.pref::put);852 args.getPreferencesToSet().forEach(prefs::put); 851 853 852 854 if (!language.isPresent()) { … … 854 856 } 855 857 updateSystemProperties(); 856 Main.pref.addPreferenceChangeListener(new PreferenceChangedListener() {858 Preferences.main().addPreferenceChangeListener(new PreferenceChangedListener() { 857 859 @Override 858 860 public void preferenceChanged(PreferenceChangeEvent e) { … … 887 889 888 890 if (args.hasOption(Option.LOAD_PREFERENCES)) { 889 XMLCommandProcessor config = new XMLCommandProcessor( Main.pref);891 XMLCommandProcessor config = new XMLCommandProcessor(prefs); 890 892 for (String i : args.get(Option.LOAD_PREFERENCES)) { 891 893 try { -
trunk/src/org/openstreetmap/josm/gui/MainTermination.java
r14140 r14149 8 8 import java.util.Objects; 9 9 10 import org.openstreetmap.josm. Main;10 import org.openstreetmap.josm.data.Preferences; 11 11 import org.openstreetmap.josm.data.cache.JCSCacheManager; 12 12 import org.openstreetmap.josm.tools.ImageProvider; … … 48 48 ImageProvider.shutdown(false); 49 49 try { 50 Main.pref.saveDefaults();50 Preferences.main().saveDefaults(); 51 51 } catch (IOException | InvalidPathException ex) { 52 52 Logging.log(Logging.LEVEL_WARN, tr("Failed to save default preferences."), ex); -
trunk/src/org/openstreetmap/josm/gui/io/CustomConfigurator.java
r13901 r14149 100 100 */ 101 101 public static void readXML(File file) { 102 readXML(file, Main.pref);102 readXML(file, Preferences.main()); 103 103 } 104 104 … … 206 206 public static void exportPreferencesKeysByPatternToFile(String fileName, boolean append, String pattern) { 207 207 List<String> keySet = new ArrayList<>(); 208 Map<String, Setting<?>> allSettings = Main.pref.getAllSettings();208 Map<String, Setting<?>> allSettings = Preferences.main().getAllSettings(); 209 209 for (String key: allSettings.keySet()) { 210 210 if (key.matches(pattern)) … … 227 227 228 228 try { 229 String toXML = Main.pref.toXML(true);229 String toXML = Preferences.main().toXML(true); 230 230 DocumentBuilder builder = XmlUtils.newSafeDOMBuilder(); 231 231 document = builder.parse(new ByteArrayInputStream(toXML.getBytes(StandardCharsets.UTF_8))); … … 358 358 for (PluginInformation pi4: toDeletePlugins) { 359 359 pls.remove(pi4.name); 360 new File( Main.pref.getPluginsDirectory(), pi4.name+".jar").deleteOnExit();360 new File(Preferences.main().getPluginsDirectory(), pi4.name+".jar").deleteOnExit(); 361 361 } 362 362 Config.getPref().putList("plugins", pls); … … 375 375 dir = Config.getDirs().getCacheDirectory(false).getAbsolutePath(); 376 376 } else if ("plugins".equals(base)) { 377 dir = Main.pref.getPluginsDirectory().getAbsolutePath();377 dir = Preferences.main().getPluginsDirectory().getAbsolutePath(); 378 378 } else { 379 379 dir = null; -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java
r13838 r14149 130 130 } 131 131 }); 132 readPreferences( Main.pref);132 readPreferences(Preferences.main()); 133 133 134 134 applyFilter(); … … 181 181 private void readPreferences(Preferences tmpPrefs) { 182 182 Map<String, Setting<?>> loaded; 183 Map<String, Setting<?>> orig = Main.pref.getAllSettings();183 Map<String, Setting<?>> orig = Preferences.main().getAllSettings(); 184 184 Map<String, Setting<?>> defaults = tmpPrefs.getAllDefaults(); 185 185 orig.remove("osm-server.password"); 186 186 defaults.remove("osm-server.password"); 187 if (tmpPrefs != Main.pref) {187 if (tmpPrefs != Preferences.main()) { 188 188 loaded = tmpPrefs.getAllSettings(); 189 189 // plugins preference keys may be changed directly later, after plugins are downloaded … … 262 262 return; 263 263 264 Preferences tmpPrefs = new Preferences( Main.pref);264 Preferences tmpPrefs = new Preferences(Preferences.main()); 265 265 266 266 StringBuilder log = new StringBuilder(); … … 324 324 325 325 for (Entry<String, String> e: profileTypes.entrySet()) { 326 menu.add(new ExportProfileAction( Main.pref, e.getKey(), e.getValue()));326 menu.add(new ExportProfileAction(Preferences.main(), e.getKey(), e.getValue())); 327 327 } 328 328 … … 339 339 "Are you sure you want to continue?") 340 340 +"</html>", null, "")) { 341 Main.pref.resetToDefault();341 Preferences.main().resetToDefault(); 342 342 try { 343 Main.pref.save();343 Preferences.main().save(); 344 344 } catch (IOException | InvalidPathException e) { 345 345 Logging.log(Logging.LEVEL_WARN, "Exception while saving preferences:", e); 346 346 } 347 readPreferences( Main.pref);347 readPreferences(Preferences.main()); 348 348 applyFilter(); 349 349 } … … 412 412 @Override 413 413 public void actionPerformed(ActionEvent ae) { 414 Preferences tmpPrefs = new Preferences( Main.pref);414 Preferences tmpPrefs = new Preferences(Preferences.main()); 415 415 CustomConfigurator.readXML(file, tmpPrefs); 416 416 readPreferences(tmpPrefs); … … 460 460 for (PrefEntry e : allData) { 461 461 if (e.isChanged()) { 462 Main.pref.putSetting(e.getKey(), e.getValue().getValue() == null ? null : e.getValue());462 Preferences.main().putSetting(e.getKey(), e.getValue().getValue() == null ? null : e.getValue()); 463 463 } 464 464 } -
trunk/src/org/openstreetmap/josm/gui/preferences/display/ColorPreference.java
r13986 r14149 36 36 import javax.swing.table.DefaultTableCellRenderer; 37 37 38 import org.openstreetmap.josm. Main;38 import org.openstreetmap.josm.data.Preferences; 39 39 import org.openstreetmap.josm.data.osm.visitor.paint.PaintColors; 40 40 import org.openstreetmap.josm.data.preferences.ColorInfo; … … 269 269 public void addGui(final PreferenceTabbedPane gui) { 270 270 fixColorPrefixes(); 271 setColors( Main.pref.getAllNamedColors());271 setColors(Preferences.main().getAllNamedColors()); 272 272 273 273 colorEdit = new JButton(tr("Choose")); -
trunk/src/org/openstreetmap/josm/gui/preferences/plugin/PluginPreference.java
r14052 r14149 45 45 import org.openstreetmap.josm.Main; 46 46 import org.openstreetmap.josm.actions.ExpertToggleAction; 47 import org.openstreetmap.josm.data.Preferences; 47 48 import org.openstreetmap.josm.data.Version; 48 49 import org.openstreetmap.josm.gui.HelpAwareOptionPane; … … 300 301 if (answer != 0 /* OK */) 301 302 return; 302 Main.pref.setPluginSites(pnl.getUpdateSites());303 Preferences.main().setPluginSites(pnl.getUpdateSites()); 303 304 } 304 305 … … 376 377 @Override 377 378 public void actionPerformed(ActionEvent e) { 378 Collection<String> pluginSites = Main.pref.getOnlinePluginSites();379 Collection<String> pluginSites = Preferences.main().getOnlinePluginSites(); 379 380 if (pluginSites.isEmpty()) { 380 381 return; … … 430 431 // the async task for downloading plugin information 431 432 final ReadRemotePluginInformationTask pluginInfoDownloadTask = new ReadRemotePluginInformationTask( 432 Main.pref.getOnlinePluginSites());433 Preferences.main().getOnlinePluginSites()); 433 434 434 435 // to be run asynchronously after the plugin download … … 601 602 super(new GridBagLayout()); 602 603 add(new JLabel(tr("Add JOSM Plugin description URL.")), GBC.eol()); 603 for (String s : Main.pref.getPluginSites()) {604 for (String s : Preferences.main().getPluginSites()) { 604 605 model.addElement(s); 605 606 } -
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r14138 r14149 29 29 import java.util.zip.ZipFile; 30 30 31 import org.openstreetmap.josm. Main;31 import org.openstreetmap.josm.data.Preferences; 32 32 import org.openstreetmap.josm.spi.preferences.Config; 33 33 import org.openstreetmap.josm.tools.HttpClient; … … 298 298 cacheFile = new File(Config.getDirs().getUserDataDirectory(false), name.substring("josmdir://".length())); 299 299 } else if (name.startsWith("josmplugindir://")) { 300 cacheFile = new File( Main.pref.getPluginsDirectory(), name.substring("josmplugindir://".length()));300 cacheFile = new File(Preferences.main().getPluginsDirectory(), name.substring("josmplugindir://".length())); 301 301 } else { 302 302 cacheFile = new File(name); -
trunk/src/org/openstreetmap/josm/plugins/Plugin.java
r14005 r14149 11 11 import java.util.List; 12 12 13 import org.openstreetmap.josm. Main;13 import org.openstreetmap.josm.data.Preferences; 14 14 import org.openstreetmap.josm.gui.MapFrame; 15 15 import org.openstreetmap.josm.gui.MapFrameListener; … … 167 167 */ 168 168 public ClassLoader getPluginResourceClassLoader() { 169 File pluginDir = Main.pref.getPluginsDirectory();169 File pluginDir = Preferences.main().getPluginsDirectory(); 170 170 File pluginJar = new File(pluginDir, info.name + ".jar"); 171 171 final URL pluginJarUrl = Utils.fileToURL(pluginJar); -
trunk/src/org/openstreetmap/josm/plugins/PluginDownloadTask.java
r13761 r14149 15 15 import java.util.LinkedList; 16 16 17 import org.openstreetmap.josm. Main;17 import org.openstreetmap.josm.data.Preferences; 18 18 import org.openstreetmap.josm.data.Version; 19 19 import org.openstreetmap.josm.gui.ExtendedDialog; … … 155 155 @Override 156 156 protected void realRun() throws SAXException, IOException { 157 File pluginDir = Main.pref.getPluginsDirectory();157 File pluginDir = Preferences.main().getPluginsDirectory(); 158 158 if (!pluginDir.exists() && !pluginDir.mkdirs()) { 159 159 String message = tr("Failed to create plugin directory ''{0}''", pluginDir.toString()); -
trunk/src/org/openstreetmap/josm/plugins/PluginHandler.java
r14121 r14149 55 55 import org.openstreetmap.josm.Main; 56 56 import org.openstreetmap.josm.actions.RestartAction; 57 import org.openstreetmap.josm.data.Preferences; 57 58 import org.openstreetmap.josm.data.PreferencesUtils; 58 59 import org.openstreetmap.josm.data.Version; … … 535 536 } 536 537 if (NetworkManager.isOffline(OnlineResource.JOSM_WEBSITE)) { 537 for (String updateSite : Main.pref.getPluginSites()) {538 for (String updateSite : Preferences.main().getPluginSites()) { 538 539 try { 539 540 OnlineResource.JOSM_WEBSITE.checkOfflineAccess(updateSite, Config.getUrls().getJOSMWebsite()); … … 598 599 // Update plugin list 599 600 final ReadRemotePluginInformationTask pluginInfoDownloadTask = new ReadRemotePluginInformationTask( 600 Main.pref.getOnlinePluginSites());601 Preferences.main().getOnlinePluginSites()); 601 602 MainApplication.worker.submit(pluginInfoDownloadTask); 602 603 … … 743 744 private static void extendJoinedPluginResourceCL(Collection<PluginInformation> plugins) { 744 745 // iterate all plugins and collect all libraries of all plugins: 745 File pluginDir = Main.pref.getPluginsDirectory();746 File pluginDir = Preferences.main().getPluginsDirectory(); 746 747 DynamicURLClassLoader cl = getJoinedPluginResourceCL(); 747 748 … … 1076 1077 ReadRemotePluginInformationTask task1 = new ReadRemotePluginInformationTask( 1077 1078 monitor.createSubTaskMonitor(1, false), 1078 Main.pref.getOnlinePluginSites(), displayErrMsg1079 Preferences.main().getOnlinePluginSites(), displayErrMsg 1079 1080 ); 1080 1081 task1.run(); … … 1248 1249 */ 1249 1250 public static void installDownloadedPlugins(Collection<PluginInformation> pluginsToLoad, boolean dowarn) { 1250 File pluginDir = Main.pref.getPluginsDirectory();1251 File pluginDir = Preferences.main().getPluginsDirectory(); 1251 1252 if (!pluginDir.exists() || !pluginDir.isDirectory() || !pluginDir.canWrite()) 1252 1253 return; … … 1326 1327 */ 1327 1328 public static File findUpdatedJar(String name) { 1328 File pluginDir = Main.pref.getPluginsDirectory();1329 File pluginDir = Preferences.main().getPluginsDirectory(); 1329 1330 // Find the downloaded file. We have tried to install the downloaded plugins 1330 1331 // (PluginHandler.installDownloadedPlugins). This succeeds depending on the platform. -
trunk/src/org/openstreetmap/josm/plugins/ReadRemotePluginInformationTask.java
r12846 r14149 31 31 import javax.swing.JScrollPane; 32 32 33 import org.openstreetmap.josm. Main;33 import org.openstreetmap.josm.data.Preferences; 34 34 import org.openstreetmap.josm.gui.PleaseWaitRunnable; 35 35 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; … … 245 245 */ 246 246 protected void cachePluginList(String site, String list) { 247 File pluginDir = Main.pref.getPluginsDirectory();247 File pluginDir = Preferences.main().getPluginsDirectory(); 248 248 if (!pluginDir.exists() && !pluginDir.mkdirs()) { 249 249 Logging.warn(tr("Failed to create plugin directory ''{0}''. Cannot cache plugin list from plugin site ''{1}''.", … … 318 318 } 319 319 320 File pluginDir = Main.pref.getPluginsDirectory();320 File pluginDir = Preferences.main().getPluginsDirectory(); 321 321 for (String site: sites) { 322 322 String printsite = site.replaceAll("%<(.*)>", ""); -
trunk/src/org/openstreetmap/josm/tools/Shortcut.java
r14138 r14149 22 22 import javax.swing.text.JTextComponent; 23 23 24 import org.openstreetmap.josm. Main;24 import org.openstreetmap.josm.data.Preferences; 25 25 import org.openstreetmap.josm.spi.preferences.Config; 26 26 … … 386 386 PlatformManager.getPlatform().initSystemShortcuts(); 387 387 // (2) User defined shortcuts 388 Main.pref.getAllPrefixCollectionKeys("shortcut.entry.").stream()388 Preferences.main().getAllPrefixCollectionKeys("shortcut.entry.").stream() 389 389 .map(Shortcut::new) 390 390 .filter(sc -> !findShortcut(sc.getAssignedKey(), sc.getAssignedModifier()).isPresent())
Note:
See TracChangeset
for help on using the changeset viewer.