- Timestamp:
- 2011-07-03T20:08:43+02:00 (13 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Preferences.java
r4191 r4200 25 25 import java.util.List; 26 26 import java.util.Map; 27 import java.util.Map.Entry; 27 28 import java.util.Properties; 28 29 import java.util.SortedMap; 29 30 import java.util.TreeMap; 30 import java.util.Map.Entry;31 31 import java.util.concurrent.CopyOnWriteArrayList; 32 32 import java.util.regex.Matcher; … … 35 35 import javax.swing.JOptionPane; 36 36 37 import org.openstreetmap.josm.Main; 37 38 import org.openstreetmap.josm.io.XmlWriter; 38 import org.openstreetmap.josm.Main;39 39 import org.openstreetmap.josm.tools.ColorHelper; 40 40 import org.openstreetmap.josm.tools.Utils; … … 365 365 if(Main.applet) 366 366 return; 367 File prefFile = new File(getPreferencesDirFile(), "preferences"); 367 368 File prefFile = getPreferenceFile(); 369 File backupFile = new File(prefFile + "_backup"); 368 370 369 371 // Backup old preferences if there are old preferences 370 372 if(prefFile.exists()) { 371 copyFile(prefFile, new File(prefFile + "_backup"));373 copyFile(prefFile, backupFile); 372 374 } 373 375 … … 386 388 copyFile(tmpFile, prefFile); 387 389 tmpFile.delete(); 390 391 setCorrectPermissions(prefFile); 392 setCorrectPermissions(backupFile); 393 } 394 395 396 private void setCorrectPermissions(File file) { 397 file.setReadable(false, false); 398 file.setWritable(false, false); 399 file.setExecutable(false, false); 400 file.setReadable(true, true); 401 file.setWritable(true, true); 388 402 } 389 403 … … 560 574 synchronized public Color getColor(String colName, String specName, Color def) { 561 575 String colKey = colName.toLowerCase().replaceAll("[^a-z0-9]+","."); 562 if(!colKey.equals(colName)) 576 if(!colKey.equals(colName)) { 563 577 colornames.put(colKey, colName); 578 } 564 579 putDefault("color."+colKey, ColorHelper.color2html(def)); 565 580 String colStr = specName != null ? get("color."+specName) : ""; … … 709 724 * Used to read a 2-dimensional array of strings from the preference file. 710 725 * If not a single entry could be found, def is returned. 711 */ 726 */ 712 727 synchronized public Collection<Collection<String>> getArray(String key, 713 728 Collection<Collection<String>> def) 714 {715 if(def != null) 729 { 730 if(def != null) { 716 731 putArrayDefault(key, def); 732 } 717 733 key += "."; 718 734 int num = 0; … … 722 738 } 723 739 return num == 0 ? def : col; 724 }725 740 } 741 726 742 synchronized public boolean putArray(String key, Collection<Collection<String>> val) { 727 743 boolean changed = false; … … 796 812 public <T> List<T> getListOfStructs(String key, Collection<T> def, Class<T> klass) { 797 813 Collection<Collection<String>> array = 798 814 getArray(key, def == null ? null : serializeListOfStructs(def, klass)); 799 815 if (array == null) 800 816 return def == null ? null : new ArrayList<T>(def); … … 829 845 Collection<Collection<String>> vals = new ArrayList<Collection<String>>(); 830 846 for (T struct : l) { 831 if (struct == null) 847 if (struct == null) { 832 848 continue; 849 } 833 850 vals.add(serializeStruct(struct, klass)); 834 851 } … … 937 954 */ 938 955 private final static String[] DEFAULT_PLUGIN_SITE = { 939 956 "http://josm.openstreetmap.de/plugin%<?plugins=>"}; 940 957 941 958 /** … … 973 990 parser.map("collection", XMLCollection.class); 974 991 parser.startWithValidation(in, 975 "http://josm.openstreetmap.de/preferences-1.0", "resource://data/preferences.xsd");992 "http://josm.openstreetmap.de/preferences-1.0", "resource://data/preferences.xsd"); 976 993 LinkedList<String> vals = new LinkedList<String>(); 977 994 while(parser.hasNext()) { … … 990 1007 public String toXML(boolean nopass) { 991 1008 StringBuilder b = new StringBuilder( 992 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" +1009 "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n" + 993 1010 "<preferences xmlns=\"http://josm.openstreetmap.de/preferences-1.0\">\n"); 994 1011 for (Entry<String, String> p : properties.entrySet()) {
Note:
See TracChangeset
for help on using the changeset viewer.