Changeset 7834 in josm
- Timestamp:
- 2014-12-19T15:05:33+01:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/AutosaveTask.java
r7580 r7834 85 85 private final Deque<File> deletedLayers = new LinkedList<>(); 86 86 87 private final File autosaveDir = new File(Main.pref.get PreferencesDir() +AUTOSAVE_DIR);88 private final File deletedLayersDir = new File(Main.pref.get PreferencesDir() +DELETED_LAYERS_DIR);87 private final File autosaveDir = new File(Main.pref.getUserDataDirectory(), AUTOSAVE_DIR); 88 private final File deletedLayersDir = new File(Main.pref.getUserDataDirectory(), DELETED_LAYERS_DIR); 89 89 90 90 public void schedule() { -
trunk/src/org/openstreetmap/josm/data/CustomConfigurator.java
r7082 r7834 157 157 */ 158 158 public static void messageBox(String type, String text) { 159 if (type==null || type. length()==0) type="plain";159 if (type==null || type.isEmpty()) type="plain"; 160 160 161 161 switch (type.charAt(0)) { … … 390 390 391 391 private static String getDirectoryByAbbr(String base) { 392 393 length()==0) {394 395 396 397 398 399 400 401 402 392 String dir; 393 if ("prefs".equals(base) || base.isEmpty()) { 394 dir = Main.pref.getPreferencesDirectory().getAbsolutePath(); 395 } else if ("cache".equals(base)) { 396 dir = Main.pref.getCacheDirectory().getAbsolutePath(); 397 } else if ("plugins".equals(base)) { 398 dir = Main.pref.getPluginsDirectory().getAbsolutePath(); 399 } else { 400 dir = null; 401 } 402 return dir; 403 403 } 404 404 … … 459 459 engine.eval("API={}; API.pref={}; API.fragments={};"); 460 460 461 engine.eval("homeDir='"+normalizeDirName(Main.pref.getPreferencesDir()) +"';"); 461 engine.eval("homeDir='"+normalizeDirName(Main.pref.getPreferencesDirectory().getAbsolutePath()) +"';"); 462 462 engine.eval("josmVersion="+Version.getInstance().getVersion()+";"); 463 463 String className = CustomConfigurator.class.getName(); … … 629 629 if (locText.length()>0) text=locText; 630 630 String var = elem.getAttribute("var"); 631 if (var. length()==0) var="result";631 if (var.isEmpty()) var="result"; 632 632 633 633 String input = evalVars(elem.getAttribute("input")); -
trunk/src/org/openstreetmap/josm/data/Preferences.java
r7831 r7834 22 22 import java.util.Collection; 23 23 import java.util.Collections; 24 import java.util.HashSet; 24 25 import java.util.Iterator; 25 26 import java.util.LinkedHashMap; … … 30 31 import java.util.Objects; 31 32 import java.util.ResourceBundle; 33 import java.util.Set; 32 34 import java.util.SortedMap; 33 35 import java.util.TreeMap; … … 84 86 * Internal storage for the preference directory. 85 87 * Do not access this variable directly! 86 * @see #getPreferencesDir File()87 */ 88 private File preferencesDir File= null;88 * @see #getPreferencesDirectory() 89 */ 90 private File preferencesDir = null; 89 91 90 92 /** 91 93 * Internal storage for the cache directory. 92 94 */ 93 private File cacheDir File= null;95 private File cacheDir = null; 94 96 95 97 /** … … 530 532 * Returns the location of the user defined preferences directory 531 533 * @return The location of the user defined preferences directory 532 */ 534 * @deprecated use #getPreferencesDirectory() to access preferences directory 535 * or #getUserDataDirectory to access user data directory 536 */ 537 @Deprecated 533 538 public String getPreferencesDir() { 534 final String path = getPreferencesDir File().getPath();539 final String path = getPreferencesDirectory().getPath(); 535 540 if (path.endsWith(File.separator)) 536 541 return path; … … 539 544 540 545 /** 541 * Returns the user defined preferences directory 542 * @return The user defined preferences directory 543 */ 544 public File getPreferencesDirFile() { 545 if (preferencesDirFile != null) 546 return preferencesDirFile; 546 * Returns the user defined preferences directory, containing the preferences.xml file 547 * @return The user defined preferences directory, containing the preferences.xml file 548 * @since 7834 549 */ 550 public File getPreferencesDirectory() { 551 if (preferencesDir != null) 552 return preferencesDir; 547 553 String path; 548 554 path = System.getProperty("josm.home"); 549 555 if (path != null) { 550 preferencesDir File= new File(path).getAbsoluteFile();556 preferencesDir = new File(path).getAbsoluteFile(); 551 557 } else { 552 preferencesDirFile = Main.platform.getDefaultPrefDirectory(); 553 } 554 return preferencesDirFile; 555 } 556 557 /** 558 * Returns the user preferences file 559 * @return The user preferences file 558 preferencesDir = Main.platform.getDefaultPrefDirectory(); 559 } 560 return preferencesDir; 561 } 562 563 /** 564 * Returns the user data directory, containing autosave, plugins, etc. 565 * Depending on the OS it may be the same directory as preferences directory. 566 * @return The user data directory, containing autosave, plugins, etc. 567 * @since 7834 568 */ 569 public File getUserDataDirectory() { 570 return Main.platform.getDefaultUserDataDirectory(); 571 } 572 573 /** 574 * Returns the user preferences file (preferences.xml) 575 * @return The user preferences file (preferences.xml) 560 576 */ 561 577 public File getPreferenceFile() { 562 return new File(getPreferencesDir File(), "preferences.xml");578 return new File(getPreferencesDirectory(), "preferences.xml"); 563 579 } 564 580 … … 568 584 */ 569 585 public File getPluginsDirectory() { 570 return new File(get PreferencesDirFile(), "plugins");586 return new File(getUserDataDirectory(), "plugins"); 571 587 } 572 588 … … 580 596 */ 581 597 public File getCacheDirectory() { 582 if (cacheDir File!= null)583 return cacheDir File;598 if (cacheDir != null) 599 return cacheDir; 584 600 String path = System.getProperty("josm.cache"); 585 601 if (path != null) { 586 cacheDir File= new File(path).getAbsoluteFile();602 cacheDir = new File(path).getAbsoluteFile(); 587 603 } else { 588 604 path = get("cache.folder", null); 589 605 if (path != null) { 590 cacheDir File= new File(path);606 cacheDir = new File(path); 591 607 } else { 592 cacheDir File= Main.platform.getDefaultCacheDirectory();593 } 594 } 595 if (!cacheDir File.exists() && !cacheDirFile.mkdirs()) {596 Main.warn(tr("Failed to create missing cache directory: {0}", cacheDir File.getAbsoluteFile()));608 cacheDir = Main.platform.getDefaultCacheDirectory(); 609 } 610 } 611 if (!cacheDir.exists() && !cacheDir.mkdirs()) { 612 Main.warn(tr("Failed to create missing cache directory: {0}", cacheDir.getAbsoluteFile())); 597 613 JOptionPane.showMessageDialog( 598 614 Main.parent, 599 tr("<html>Failed to create missing cache directory: {0}</html>", cacheDir File.getAbsoluteFile()),615 tr("<html>Failed to create missing cache directory: {0}</html>", cacheDir.getAbsoluteFile()), 600 616 tr("Error"), 601 617 JOptionPane.ERROR_MESSAGE 602 618 ); 603 619 } 604 return cacheDirFile; 605 } 606 607 /** 608 * @return A list of all existing directories where resources could be stored. 620 return cacheDir; 621 } 622 623 private void addPossibleResourceDir(Set<String> locations, String s) { 624 if (s != null) { 625 if (!s.endsWith(File.separator)) { 626 s += File.separator; 627 } 628 locations.add(s); 629 } 630 } 631 632 /** 633 * Returns a set of all existing directories where resources could be stored. 634 * @return A set of all existing directories where resources could be stored. 609 635 */ 610 636 public Collection<String> getAllPossiblePreferenceDirs() { 611 LinkedList<String> locations = new LinkedList<>(); 612 locations.add(getPreferencesDir()); 613 String s; 614 if ((s = System.getenv("JOSM_RESOURCES")) != null) { 615 if (!s.endsWith(File.separator)) { 616 s = s + File.separator; 617 } 618 locations.add(s); 619 } 620 if ((s = System.getProperty("josm.resources")) != null) { 621 if (!s.endsWith(File.separator)) { 622 s = s + File.separator; 623 } 624 locations.add(s); 625 } 626 String appdata = System.getenv("APPDATA"); 627 if (System.getenv("ALLUSERSPROFILE") != null && appdata != null 628 && appdata.lastIndexOf(File.separator) != -1) { 629 appdata = appdata.substring(appdata.lastIndexOf(File.separator)); 630 locations.add(new File(new File(System.getenv("ALLUSERSPROFILE"), 631 appdata), "JOSM").getPath()); 632 } 633 locations.add("/usr/local/share/josm/"); 634 locations.add("/usr/local/lib/josm/"); 635 locations.add("/usr/share/josm/"); 636 locations.add("/usr/lib/josm/"); 637 Set<String> locations = new HashSet<>(); 638 addPossibleResourceDir(locations, getPreferencesDirectory().getPath()); 639 addPossibleResourceDir(locations, getUserDataDirectory().getPath()); 640 addPossibleResourceDir(locations, System.getenv("JOSM_RESOURCES")); 641 addPossibleResourceDir(locations, System.getProperty("josm.resources")); 642 if (Main.isPlatformWindows()) { 643 String appdata = System.getenv("APPDATA"); 644 if (System.getenv("ALLUSERSPROFILE") != null && appdata != null 645 && appdata.lastIndexOf(File.separator) != -1) { 646 appdata = appdata.substring(appdata.lastIndexOf(File.separator)); 647 locations.add(new File(new File(System.getenv("ALLUSERSPROFILE"), 648 appdata), "JOSM").getPath()); 649 } 650 } else { 651 locations.add("/usr/local/share/josm/"); 652 locations.add("/usr/local/lib/josm/"); 653 locations.add("/usr/share/josm/"); 654 locations.add("/usr/lib/josm/"); 655 } 637 656 return locations; 638 657 } … … 811 830 public void init(boolean reset) { 812 831 // get the preferences. 813 File prefDir = getPreferencesDir File();832 File prefDir = getPreferencesDirectory(); 814 833 if (prefDir.exists()) { 815 834 if(!prefDir.isDirectory()) { -
trunk/src/org/openstreetmap/josm/data/validation/OsmValidator.java
r7574 r7834 154 154 */ 155 155 public static String getValidatorDir() { 156 return Main.pref.get PreferencesDir() +"validator/";156 return new File(Main.pref.getUserDataDirectory(), "validator").getAbsolutePath(); 157 157 } 158 158 … … 174 174 ignoredErrors.clear(); 175 175 if (Main.pref.getBoolean(ValidatorPreference.PREF_USE_IGNORE, true)) { 176 Path path = Paths.get(getValidatorDir() +"ignorederrors");176 Path path = Paths.get(getValidatorDir()).resolve("ignorederrors"); 177 177 if (Files.exists(path)) { 178 178 try { … … 196 196 197 197 public static void saveIgnoredErrors() { 198 try (PrintWriter out = new PrintWriter(new OutputStreamWriter( 199 new File OutputStream(getValidatorDir()+"ignorederrors"), StandardCharsets.UTF_8), false)) {198 try (PrintWriter out = new PrintWriter(new OutputStreamWriter(new FileOutputStream( 199 new File(getValidatorDir(), "ignorederrors")), StandardCharsets.UTF_8), false)) { 200 200 for (String e : ignoredErrors) { 201 201 out.println(e); … … 282 282 * until most bugs were discovered while keeping the processing time reasonable) 283 283 */ 284 public final void initializeGridDetail() { 284 public static final void initializeGridDetail() { 285 285 String code = Main.getProjection().toCode(); 286 286 if (Arrays.asList(ProjectionPreference.wgs84.allCodes()).contains(code)) { -
trunk/src/org/openstreetmap/josm/gui/dialogs/OsmIdSelectionDialog.java
r7509 r7834 2 2 package org.openstreetmap.josm.gui.dialogs; 3 3 4 import org.openstreetmap.josm.Main; 5 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 6 import org.openstreetmap.josm.data.osm.PrimitiveId; 7 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 8 import org.openstreetmap.josm.gui.ExtendedDialog; 9 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 10 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 11 import org.openstreetmap.josm.gui.widgets.JosmTextField; 12 import org.openstreetmap.josm.gui.widgets.OsmIdTextField; 13 import org.openstreetmap.josm.gui.widgets.OsmPrimitiveTypesComboBox; 14 import org.openstreetmap.josm.tools.Utils; 15 16 import javax.swing.BorderFactory; 17 import javax.swing.GroupLayout; 18 import javax.swing.JLabel; 19 import javax.swing.JOptionPane; 20 import javax.swing.JPanel; 21 import javax.swing.KeyStroke; 22 import javax.swing.border.EtchedBorder; 23 import javax.swing.plaf.basic.BasicComboBoxEditor; 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.trc; 6 24 7 import java.awt.Component; 25 8 import java.awt.Dimension; … … 37 20 import java.util.Set; 38 21 39 import static org.openstreetmap.josm.tools.I18n.tr; 40 import static org.openstreetmap.josm.tools.I18n.trc; 22 import javax.swing.BorderFactory; 23 import javax.swing.GroupLayout; 24 import javax.swing.JLabel; 25 import javax.swing.JOptionPane; 26 import javax.swing.JPanel; 27 import javax.swing.KeyStroke; 28 import javax.swing.border.EtchedBorder; 29 import javax.swing.plaf.basic.BasicComboBoxEditor; 30 31 import org.openstreetmap.josm.Main; 32 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 33 import org.openstreetmap.josm.data.osm.PrimitiveId; 34 import org.openstreetmap.josm.data.osm.SimplePrimitiveId; 35 import org.openstreetmap.josm.gui.ExtendedDialog; 36 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 37 import org.openstreetmap.josm.gui.widgets.HtmlPanel; 38 import org.openstreetmap.josm.gui.widgets.JosmTextField; 39 import org.openstreetmap.josm.gui.widgets.OsmIdTextField; 40 import org.openstreetmap.josm.gui.widgets.OsmPrimitiveTypesComboBox; 41 import org.openstreetmap.josm.tools.Utils; 41 42 42 43 /** … … 197 198 protected void tryToPasteFromClipboard(OsmIdTextField tfId, OsmPrimitiveTypesComboBox cbType) { 198 199 String buf = Utils.getClipboardContent(); 199 if (buf == null || buf. length()==0) return;200 if (buf == null || buf.isEmpty()) return; 200 201 if (buf.length() > Main.pref.getInteger("downloadprimitive.max-autopaste-length", 2000)) return; 201 202 final List<SimplePrimitiveId> ids = SimplePrimitiveId.fuzzyParse(buf); -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java
r7668 r7834 367 367 } 368 368 } 369 for (File f: Main.pref.getPreferencesDir File().listFiles()) {369 for (File f: Main.pref.getPreferencesDirectory().listFiles()) { 370 370 String s = f.getName(); 371 371 int idx = s.indexOf('_'); -
trunk/src/org/openstreetmap/josm/gui/preferences/shortcut/PrefJPanel.java
r7015 r7834 358 358 public void filter() { 359 359 String expr = filterField.getText().trim(); 360 if (expr. length()==0) { expr=null; }360 if (expr.isEmpty()) { expr=null; } 361 361 try { 362 362 final TableRowSorter<? extends TableModel> sorter = -
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r7434 r7834 79 79 * <li>{@code http://...} a URL. It will be cached on disk.</li></ul> 80 80 * <li>{@code resource://SOME/FILE} file from the classpath (usually in the current *.jar)</li> 81 * <li>{@code josmdir://SOME/FILE} file inside josm config directory (since r7058)</li></ul> 81 * <li>{@code josmdir://SOME/FILE} file inside josm user data directory (since r7058)</li></ul> 82 * <li>{@code josmplugindir://SOME/FILE} file inside josm plugin directory (since r7832)</li></ul> 82 83 */ 83 84 public CachedFile(String name) { … … 92 93 * <li>{@code http://...} a URL. It will be cached on disk.</li></ul> 93 94 * <li>{@code resource://SOME/FILE} file from the classpath (usually in the current *.jar)</li> 94 * <li>{@code josmdir://SOME/FILE} file inside josm config directory (since r7058)</li></ul> 95 * <li>{@code josmdir://SOME/FILE} file inside josm user data directory (since r7058)</li></ul> 96 * <li>{@code josmplugindir://SOME/FILE} file inside josm plugin directory (since r7832)</li></ul> 95 97 * @return this object 96 98 */ … … 206 208 return null; 207 209 } else if (name.startsWith("josmdir://")) { 208 cacheFile = new File(Main.pref.getPreferencesDir(), name.substring("josmdir://".length())); 210 cacheFile = new File(Main.pref.getUserDataDirectory(), name.substring("josmdir://".length())); 211 } else if (name.startsWith("josmplugindir://")) { 212 cacheFile = new File(Main.pref.getPluginsDirectory(), name.substring("josmplugindir://".length())); 209 213 } else { 210 214 cacheFile = new File(name); -
trunk/src/org/openstreetmap/josm/io/GpxExporter.java
r7518 r7834 200 200 201 201 if (enable) { 202 if (copyrightYear.getText(). length()==0) {202 if (copyrightYear.getText().isEmpty()) { 203 203 String sCopyrightYear = data.getString(META_COPYRIGHT_YEAR); 204 204 if (sCopyrightYear == null) { … … 207 207 copyrightYear.setText(sCopyrightYear); 208 208 } 209 if (copyright.getText(). length()==0) {209 if (copyright.getText().isEmpty()) { 210 210 String sCopyright = data.getString(META_COPYRIGHT_LICENSE); 211 211 if (sCopyright == null) { … … 308 308 break; 309 309 } 310 license += license. length()==0? urls[i] : ", "+urls[i];310 license += license.isEmpty() ? urls[i] : ", "+urls[i]; 311 311 } 312 312 copyright.setText(license); -
trunk/src/org/openstreetmap/josm/io/remotecontrol/RemoteControl.java
r7830 r7834 2 2 package org.openstreetmap.josm.io.remotecontrol; 3 3 4 import java.io.File; 4 5 import java.net.InetAddress; 5 6 import java.net.UnknownHostException; … … 28 29 * @since 7335 29 30 */ 30 public static final BooleanProperty PROP_REMOTECONTROL_HTTPS_ENABLED = new BooleanProperty("remotecontrol.https.enabled", false); 31 public static final BooleanProperty PROP_REMOTECONTROL_HTTPS_ENABLED = new BooleanProperty( 32 "remotecontrol.https.enabled", false); 31 33 32 34 /** … … 72 74 */ 73 75 public static String getRemoteControlDir() { 74 return Main.pref.get PreferencesDir() +"remotecontrol/";76 return new File(Main.pref.getUserDataDirectory(), "remotecontrol").getAbsolutePath(); 75 77 } 76 78 -
trunk/src/org/openstreetmap/josm/tools/ImageProvider.java
r7805 r7834 880 880 } 881 881 } 882 // Try user- preferencedirectory883 String dir = Main.pref.get PreferencesDir() +"images";882 // Try user-data directory 883 String dir = new File(Main.pref.getUserDataDirectory(), "images").getAbsolutePath(); 884 884 try { 885 885 u = getImageUrl(dir, imageName, additionalClassLoaders); … … 952 952 }); 953 953 954 CachedFile cf = new CachedFile(base + fn).setDestDir(new File(Main.pref.getPreferencesDir(), "images").toString()); 954 CachedFile cf = new CachedFile(base + fn).setDestDir( 955 new File(Main.pref.getUserDataDirectory(), "images").getPath()); 955 956 try (InputStream is = cf.getInputStream()) { 956 957 parser.parse(new InputSource(is)); -
trunk/src/org/openstreetmap/josm/tools/PlatformHook.java
r7831 r7834 134 134 */ 135 135 public File getDefaultPrefDirectory(); 136 137 /** 138 * Returns the platform-dependent default user data directory. 139 * @return the platform-dependent default user data directory 140 * @since 7834 141 */ 142 public File getDefaultUserDataDirectory(); 136 143 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookOsx.java
r7831 r7834 333 333 return new File(System.getProperty("user.home")+"/Library/Preferences", "JOSM"); 334 334 } 335 336 @Override 337 public File getDefaultUserDataDirectory() { 338 return new File(System.getProperty("user.home")+"/Library/Application Support", "JOSM"); 339 } 335 340 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookUnixoid.java
r7831 r7834 373 373 @Override 374 374 public File getDefaultCacheDirectory() { 375 return new File(Main.pref.get PreferencesDirFile(), "cache");375 return new File(Main.pref.getUserDataDirectory(), "cache"); 376 376 } 377 377 … … 380 380 return new File(System.getProperty("user.home"), ".josm"); 381 381 } 382 383 @Override 384 public File getDefaultUserDataDirectory() { 385 // Use preferences directory by default 386 return Main.pref.getPreferencesDirectory(); 387 } 382 388 } -
trunk/src/org/openstreetmap/josm/tools/PlatformHookWindows.java
r7833 r7834 287 287 public File getDefaultCacheDirectory() { 288 288 String p = System.getenv("LOCALAPPDATA"); 289 if (p == null || "".equals(p)) { 289 if (p == null || p.isEmpty()) { 290 // Fallback for Windows OS earlier than Windows Vista, where the variable is not defined 290 291 p = System.getenv("APPDATA"); 291 292 }
Note:
See TracChangeset
for help on using the changeset viewer.