- Timestamp:
- 2013-06-25T14:26:12+02:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/preferences/advanced
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/AdvancedPreference.java
r6021 r6022 3 3 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 import static org.openstreetmap.josm.tools.I18n.marktr; 5 6 6 7 import java.awt.Dimension; … … 12 13 import java.util.Collections; 13 14 import java.util.Comparator; 15 import java.util.LinkedHashMap; 14 16 import java.util.List; 15 17 import java.util.Map; … … 21 23 import javax.swing.JFileChooser; 22 24 import javax.swing.JLabel; 25 import javax.swing.JMenu; 23 26 import javax.swing.JOptionPane; 24 27 import javax.swing.JPanel; … … 27 30 import javax.swing.event.DocumentEvent; 28 31 import javax.swing.event.DocumentListener; 32 import javax.swing.event.MenuEvent; 33 import javax.swing.event.MenuListener; 29 34 import javax.swing.filechooser.FileFilter; 30 35 … … 42 47 import org.openstreetmap.josm.gui.widgets.JosmTextField; 43 48 import org.openstreetmap.josm.tools.GBC; 44 import static org.openstreetmap.josm.tools.I18n.tr;45 49 46 50 public class AdvancedPreference extends DefaultTabPreferenceSetting { … … 255 259 readPreferences(tmpPrefs); 256 260 // sorting after modification - first modified, then non-default, then default entries 257 Collections.sort(allData, new Comparator<PrefEntry>() { 258 @Override 259 public int compare(PrefEntry o1, PrefEntry o2) { 260 if (o1.isChanged() && !o2.isChanged()) return -1; 261 if (o2.isChanged() && !o1.isChanged()) return 1; 262 if (!(o1.isDefault()) && o2.isDefault()) return -1; 263 if (!(o2.isDefault()) && o1.isDefault()) return 1; 264 return o1.compareTo(o2); 265 } 266 }); 261 Collections.sort(allData, customComparator); 267 262 applyFilter(); 268 263 } 264 265 private Comparator<PrefEntry> customComparator = new Comparator<PrefEntry>() { 266 @Override 267 public int compare(PrefEntry o1, PrefEntry o2) { 268 if (o1.isChanged() && !o2.isChanged()) return -1; 269 if (o2.isChanged() && !o1.isChanged()) return 1; 270 if (!(o1.isDefault()) && o2.isDefault()) return -1; 271 if (!(o2.isDefault()) && o1.isDefault()) return 1; 272 return o1.compareTo(o2); 273 } 274 }; 269 275 270 276 private List<PrefEntry> prepareData(Map<String, Setting> loaded, Map<String, Setting> orig, Map<String, Setting> defaults) { … … 301 307 } 302 308 309 Map<String,String> profileTypes = new LinkedHashMap<String, String>(); 310 303 311 private JPopupMenu buildPopupMenu() { 304 312 JPopupMenu menu = new JPopupMenu(); 313 profileTypes.put(marktr("shortcut"), "shortcut\\..*"); 314 profileTypes.put(marktr("color"), "color\\..*"); 315 profileTypes.put(marktr("toolbar"), "toolbar.*"); 316 profileTypes.put(marktr("imagery"), "imagery.*"); 317 318 for (Entry<String,String> e: profileTypes.entrySet()) { 319 menu.add(new ExportProfileAction(Main.pref, e.getKey(), e.getValue())); 320 } 321 322 menu.addSeparator(); 323 menu.add(getProfileMenu()); 324 menu.addSeparator(); 305 325 menu.add(new AbstractAction(tr("Reset preferences")) { 306 326 @Override public void actionPerformed(ActionEvent ae) { … … 320 340 return menu; 321 341 } 342 343 private JMenu getProfileMenu() { 344 final JMenu p =new JMenu(tr("Load profile")); 345 p.addMenuListener(new MenuListener() { 346 @Override 347 public void menuSelected(MenuEvent me) { 348 p.removeAll(); 349 for (File f: new File(".").listFiles()) { 350 String s = f.getName(); 351 int idx = s.indexOf("_"); 352 if (idx>=0) { 353 String t=s.substring(0,idx); 354 System.out.println(t); 355 if (profileTypes.containsKey(t)) 356 p.add(new ImportProfileAction(s, f, t)); 357 } 358 } 359 for (File f: Main.pref.getPreferencesDirFile().listFiles()) { 360 String s = f.getName(); 361 int idx = s.indexOf("_"); 362 if (idx>=0) { 363 String t=s.substring(0,idx); 364 if (profileTypes.containsKey(t)) 365 p.add(new ImportProfileAction(s, f, t)); 366 } 367 } 368 } 369 @Override public void menuDeselected(MenuEvent me) { } 370 @Override public void menuCanceled(MenuEvent me) { } 371 }); 372 return p; 373 } 374 375 private class ImportProfileAction extends AbstractAction { 376 private final File file; 377 private final String type; 378 379 public ImportProfileAction(String name, File file, String type) { 380 super(name); 381 this.file = file; 382 this.type = type; 383 } 384 385 @Override 386 public void actionPerformed(ActionEvent ae) { 387 Preferences tmpPrefs = CustomConfigurator.clonePreferences(Main.pref); 388 CustomConfigurator.readXML(file, tmpPrefs); 389 readPreferences(tmpPrefs); 390 String prefRegex = profileTypes.get(type); 391 // clean all the preferences from the chosen group 392 for (PrefEntry p : allData) { 393 if (p.getKey().matches(prefRegex) && !p.isDefault()) { 394 p.reset(); 395 } 396 } 397 // allow user to review the changes in table 398 Collections.sort(allData, customComparator); 399 applyFilter(); 400 } 401 } 322 402 323 403 private void applyFilter() { … … 345 425 } 346 426 } 347 System.out.println(displayData.size()) ;348 427 if (table!=null) table.fireDataChanged(); 349 428 } -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/PrefEntry.java
r6021 r6022 1 // License: GPL. See LICENSE file for details. 1 2 package org.openstreetmap.josm.gui.preferences.advanced; 2 3 -
trunk/src/org/openstreetmap/josm/gui/preferences/advanced/PreferencesTable.java
r6021 r6022 1 // License: GPL. See LICENSE file for details. 1 2 package org.openstreetmap.josm.gui.preferences.advanced; 2 3
Note:
See TracChangeset
for help on using the changeset viewer.