Changeset 7100 in josm for trunk/src/org
- Timestamp:
- 2014-05-11T01:01:33+02:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 8 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r7083 r7100 82 82 import org.openstreetmap.josm.gui.preferences.imagery.ImageryPreference; 83 83 import org.openstreetmap.josm.gui.preferences.map.MapPaintPreference; 84 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;85 84 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 86 85 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 87 86 import org.openstreetmap.josm.gui.progress.ProgressMonitorExecutor; 87 import org.openstreetmap.josm.gui.tagging.TaggingPresets; 88 88 import org.openstreetmap.josm.gui.util.RedirectInputMap; 89 89 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; … … 535 535 @Override 536 536 public void initialize() throws Exception { 537 TaggingPreset Preference.initialize();537 TaggingPresets.initialize(); 538 538 } 539 539 }); -
trunk/src/org/openstreetmap/josm/data/validation/tests/RelationChecker.java
r7061 r7100 24 24 import org.openstreetmap.josm.data.validation.Test; 25 25 import org.openstreetmap.josm.data.validation.TestError; 26 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;27 26 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 28 27 import org.openstreetmap.josm.gui.tagging.TaggingPresetItem; 28 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.Key; 29 29 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.Role; 30 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.Key;31 30 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.Roles; 32 31 import org.openstreetmap.josm.gui.tagging.TaggingPresetType; 32 import org.openstreetmap.josm.gui.tagging.TaggingPresets; 33 33 34 34 /** … … 46 46 protected static final int RELATION_UNKNOWN = 1707; 47 47 protected static final int RELATION_EMPTY = 1708; 48 49 /** 48 49 /** 50 50 * Error message used to group errors related to role problems. 51 51 * @since 6731 … … 73 73 */ 74 74 public void initializePresets() { 75 Collection<TaggingPreset> presets = TaggingPresetPreference.taggingPresets; 76 if (presets != null) { 77 for (TaggingPreset p : presets) { 78 for (TaggingPresetItem i : p.data) { 79 if (i instanceof Roles) { 80 relationpresets.add(p); 81 break; 82 } 75 for (TaggingPreset p : TaggingPresets.getTaggingPresets()) { 76 for (TaggingPresetItem i : p.data) { 77 if (i instanceof Roles) { 78 relationpresets.add(p); 79 break; 83 80 } 84 81 } -
trunk/src/org/openstreetmap/josm/data/validation/tests/TagChecker.java
r7033 r7100 41 41 import org.openstreetmap.josm.data.validation.TestError; 42 42 import org.openstreetmap.josm.data.validation.util.Entities; 43 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;44 43 import org.openstreetmap.josm.gui.preferences.validator.ValidatorPreference; 45 44 import org.openstreetmap.josm.gui.progress.ProgressMonitor; … … 49 48 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.CheckGroup; 50 49 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.KeyedItem; 50 import org.openstreetmap.josm.gui.tagging.TaggingPresets; 51 51 import org.openstreetmap.josm.gui.widgets.EditableList; 52 52 import org.openstreetmap.josm.io.MirroredInputStream; … … 61 61 */ 62 62 public class TagChecker extends Test.TagTest { 63 63 64 64 /** The default data file of tagchecker rules */ 65 65 public static final String DATA_FILE = "resource://data/validator/tagchecker.cfg"; … … 161 161 162 162 spellCheckKeyData = new HashMap<>(); 163 163 164 164 String errorSources = ""; 165 165 for (String source : Main.pref.getCollection(PREF_SOURCES, DEFAULT_SOURCES)) { … … 256 256 return; 257 257 258 Collection<TaggingPreset> presets = TaggingPreset Preference.taggingPresets;259 if ( presets != null) {258 Collection<TaggingPreset> presets = TaggingPresets.getTaggingPresets(); 259 if (!presets.isEmpty()) { 260 260 presetsValueData = new MultiMap<>(); 261 261 for (String a : OsmPrimitive.getUninterestingKeys()) { -
trunk/src/org/openstreetmap/josm/gui/preferences/map/TaggingPresetPreference.java
r7005 r7100 17 17 import javax.swing.JCheckBox; 18 18 import javax.swing.JLabel; 19 import javax.swing.JMenu;20 import javax.swing.JMenuItem;21 19 import javax.swing.JOptionPane; 22 20 import javax.swing.JPanel; 23 import javax.swing.JSeparator;24 21 25 22 import org.openstreetmap.josm.Main; … … 36 33 import org.openstreetmap.josm.gui.preferences.SubPreferenceSetting; 37 34 import org.openstreetmap.josm.gui.preferences.TabPreferenceSetting; 38 import org.openstreetmap.josm.gui.tagging.TaggingPreset;39 import org.openstreetmap.josm.gui.tagging.TaggingPresetMenu;40 35 import org.openstreetmap.josm.gui.tagging.TaggingPresetReader; 41 import org.openstreetmap.josm.gui.tagging.TaggingPresetSeparator;42 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionManager;43 36 import org.openstreetmap.josm.tools.GBC; 44 37 import org.xml.sax.SAXException; … … 65 58 66 59 private static final List<SourceProvider> presetSourceProviders = new ArrayList<>(); 67 68 /** 69 * The collection of tagging presets. 70 */ 71 public static Collection<TaggingPreset> taggingPresets; 60 72 61 private SourceEditor sources; 73 62 private JCheckBox sortMenu; … … 274 263 275 264 /** 276 * Initializes tagging presets from preferences.277 */278 public static void readFromPreferences() {279 taggingPresets = TaggingPresetReader.readFromPreferences(false, false);280 }281 282 /**283 * Initialize the tagging presets (load and may display error)284 */285 public static void initialize() {286 readFromPreferences();287 for (TaggingPreset tp: taggingPresets) {288 if (!(tp instanceof TaggingPresetSeparator)) {289 Main.toolbar.register(tp);290 }291 }292 if (taggingPresets.isEmpty()) {293 Main.main.menu.presetsMenu.setVisible(false);294 } else {295 AutoCompletionManager.cachePresets(taggingPresets);296 HashMap<TaggingPresetMenu,JMenu> submenus = new HashMap<>();297 for (final TaggingPreset p : taggingPresets) {298 JMenu m = p.group != null ? submenus.get(p.group) : Main.main.menu.presetsMenu;299 if (p instanceof TaggingPresetSeparator) {300 m.add(new JSeparator());301 } else if (p instanceof TaggingPresetMenu) {302 JMenu submenu = new JMenu(p);303 submenu.setText(p.getLocaleName());304 ((TaggingPresetMenu)p).menu = submenu;305 submenus.put((TaggingPresetMenu)p, submenu);306 m.add(submenu);307 } else {308 JMenuItem mi = new JMenuItem(p);309 mi.setText(p.getLocaleName());310 m.add(mi);311 }312 }313 }314 if (Main.pref.getBoolean("taggingpreset.sortmenu")) {315 TaggingPresetMenu.sortMenu(Main.main.menu.presetsMenu);316 }317 }318 319 /**320 265 * Helper class for tagging presets preferences. 321 266 */ -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPreset.java
r7090 r7100 44 44 import org.openstreetmap.josm.gui.layer.Layer; 45 45 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 46 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;47 46 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.Link; 48 47 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.Role; … … 199 198 private static class PresetPanel extends JPanel { 200 199 boolean hasElements = false; 201 PresetPanel() 202 { 200 PresetPanel() { 203 201 super(new GridBagLayout()); 204 202 } … … 262 260 } 263 261 264 public boolean isShowable() 265 { 266 for(TaggingPresetItem i : data) 267 { 262 public boolean isShowable() { 263 for(TaggingPresetItem i : data) { 268 264 if(!(i instanceof TaggingPresetItems.Optional || i instanceof TaggingPresetItems.Space || i instanceof TaggingPresetItems.Key)) 269 265 return true; … … 495 491 496 492 public static Collection<TaggingPreset> getMatchingPresets(final Collection<TaggingPresetType> t, final Map<String, String> tags, final boolean onlyShowable) { 497 return Utils.filter(TaggingPreset Preference.taggingPresets, new Predicate<TaggingPreset>() {493 return Utils.filter(TaggingPresets.getTaggingPresets(), new Predicate<TaggingPreset>() { 498 494 @Override 499 495 public boolean evaluate(TaggingPreset object) { … … 508 504 public class ToolbarButtonAction extends AbstractAction { 509 505 private final int toolbarIndex; 506 507 /** 508 * Constructs a new {@code ToolbarButtonAction}. 509 */ 510 510 public ToolbarButtonAction() { 511 511 super("", ImageProvider.get("styles/standard/waypoint","pin")); … … 524 524 525 525 public String getToolbarString() { 526 ToolbarPreferences.ActionDefinition aDef527 = new ToolbarPreferences.ActionDefinition(this);528 526 ToolbarPreferences.ActionParser actionParser = new ToolbarPreferences.ActionParser(null); 529 return actionParser.saveAction( aDef);527 return actionParser.saveAction(new ToolbarPreferences.ActionDefinition(this)); 530 528 } 531 529 } -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetItems.java
r7015 r7100 50 50 import org.openstreetmap.josm.data.preferences.BooleanProperty; 51 51 import org.openstreetmap.josm.gui.dialogs.properties.PresetListPanel; 52 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;53 52 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletingTextField; 54 53 import org.openstreetmap.josm.gui.tagging.ac.AutoCompletionItemPriority; … … 402 401 boolean addToPanel(JPanel p, Collection<OsmPrimitive> sel, boolean presetInitiallyMatches) { 403 402 final String presetName = preset_name; 404 final TaggingPreset t = Utils.filter(TaggingPreset Preference.taggingPresets, new Predicate<TaggingPreset>() {403 final TaggingPreset t = Utils.filter(TaggingPresets.getTaggingPresets(), new Predicate<TaggingPreset>() { 405 404 @Override 406 405 public boolean evaluate(TaggingPreset object) { -
trunk/src/org/openstreetmap/josm/gui/tagging/TaggingPresetSelector.java
r7022 r7100 47 47 import org.openstreetmap.josm.data.osm.Way; 48 48 import org.openstreetmap.josm.data.preferences.BooleanProperty; 49 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;50 49 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.Key; 51 50 import org.openstreetmap.josm.gui.tagging.TaggingPresetItems.KeyedItem; … … 60 59 */ 61 60 public class TaggingPresetSelector extends JPanel implements SelectionChangedListener { 62 61 63 62 private static final int CLASSIFICATION_IN_FAVORITES = 300; 64 63 private static final int CLASSIFICATION_NAME_MATCH = 300; … … 68 67 private static final BooleanProperty SEARCH_IN_TAGS = new BooleanProperty("taggingpreset.dialog.search-in-tags", true); 69 68 private static final BooleanProperty ONLY_APPLICABLE = new BooleanProperty("taggingpreset.dialog.only-applicable-to-selection", true); 70 69 71 70 private JosmTextField edSearchText; 72 71 private JList<TaggingPreset> lsResult; … … 208 207 public TaggingPresetSelector(boolean displayOnlyApplicable, boolean displaySearchInTags) { 209 208 super(new BorderLayout()); 210 if (TaggingPresetPreference.taggingPresets!=null) { 211 loadPresets(TaggingPresetPreference.taggingPresets); 212 } 213 209 loadPresets(TaggingPresets.getTaggingPresets()); 210 214 211 edSearchText = new JosmTextField(); 215 212 edSearchText.getDocument().addDocumentListener(new DocumentListener() { … … 304 301 lsResult.addMouseListener(new PopupMenuLauncher(popupMenu)); 305 302 } 306 303 307 304 private void selectPreset(int newIndex) { 308 305 if (newIndex < 0) { … … 389 386 390 387 } 391 388 392 389 private EnumSet<TaggingPresetType> getTypesInSelection() { 393 390 if (typesInSelectionDirty) { … … 412 409 return typesInSelection; 413 410 } 414 411 415 412 @Override 416 413 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { … … 426 423 filterPresets(); 427 424 } 428 425 429 426 public void init(Collection<TaggingPreset> presets) { 430 427 classifications.clear(); … … 432 429 init(); 433 430 } 434 431 435 432 public void clearSelection() { 436 433 lsResult.getSelectionModel().clearSelection(); 437 434 } 438 435 439 436 /** 440 437 * Save checkbox values in preferences for future reuse … … 448 445 } 449 446 } 450 447 451 448 /** 452 449 * Determines, which preset is selected at the current moment … … 483 480 lsResult.setSelectedValue(p, true); 484 481 } 485 482 486 483 public int getItemCount() { 487 484 return lsResultModel.getSize(); 488 485 } 489 486 490 487 public void setDblClickListener(ActionListener dblClickListener) { 491 488 this.dblClickListener = dblClickListener; 492 489 } 493 490 494 491 public void setClickListener(ActionListener clickListener) { 495 492 this.clickListener = clickListener; 496 493 } 497 494 498 495 public void addSelectionListener(final ActionListener selectListener) { 499 496 lsResult.getSelectionModel().addListSelectionListener(new ListSelectionListener() { -
trunk/src/org/openstreetmap/josm/tools/TaggingPresetNameTemplateList.java
r7005 r7100 7 7 import java.util.List; 8 8 9 import org.openstreetmap.josm.Main; 9 10 import org.openstreetmap.josm.data.osm.OsmPrimitive; 10 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference;11 11 import org.openstreetmap.josm.gui.tagging.TaggingPreset; 12 import org.openstreetmap.josm.gui.tagging.TaggingPresetListener; 12 13 import org.openstreetmap.josm.gui.tagging.TaggingPresetType; 14 import org.openstreetmap.josm.gui.tagging.TaggingPresets; 13 15 14 16 /** 15 17 * List of tagging presets with name templates, allows to find appropriate template based on existing primitive 16 18 */ 17 public final class TaggingPresetNameTemplateList {19 public final class TaggingPresetNameTemplateList implements TaggingPresetListener { 18 20 19 21 private static TaggingPresetNameTemplateList instance; 20 22 23 /** 24 * Replies the unique instance. 25 * @return the unique instance 26 */ 21 27 public static TaggingPresetNameTemplateList getInstance() { 22 28 if (instance == null) { 23 29 instance = new TaggingPresetNameTemplateList(); 30 TaggingPresets.addListener(instance); 24 31 } 25 32 return instance; 26 33 } 34 27 35 private final List<TaggingPreset> presetsWithPattern = new LinkedList<>(); 28 36 29 37 private TaggingPresetNameTemplateList() { 30 if (TaggingPresetPreference.taggingPresets != null) { 31 for (TaggingPreset tp : TaggingPresetPreference.taggingPresets) { 38 buildPresetsWithPattern(); 39 } 40 41 private void buildPresetsWithPattern() { 42 synchronized(this) { 43 Main.debug("Building list of presets with name template"); 44 presetsWithPattern.clear(); 45 for (TaggingPreset tp : TaggingPresets.getTaggingPresets()) { 32 46 if (tp.nameTemplate != null) { 33 47 presetsWithPattern.add(tp); … … 37 51 } 38 52 53 /** 54 * Finds and returns the first occurence of preset with template name matching the given primitive 55 * @param primitive The primitive to match 56 * @return the first occurence of preset with template name matching the primitive 57 */ 39 58 public TaggingPreset findPresetTemplate(OsmPrimitive primitive) { 40 41 for (TaggingPreset t : presetsWithPattern) { 42 Collection<TaggingPresetType> type = Collections.singleton(TaggingPresetType.forPrimitive(primitive)); 43 if (t.typeMatches(type)) { 44 if (t.nameTemplateFilter != null) { 45 if (t.nameTemplateFilter.match(primitive)) 59 synchronized(this) { 60 for (TaggingPreset t : presetsWithPattern) { 61 Collection<TaggingPresetType> type = Collections.singleton(TaggingPresetType.forPrimitive(primitive)); 62 if (t.typeMatches(type)) { 63 if (t.nameTemplateFilter != null) { 64 if (t.nameTemplateFilter.match(primitive)) 65 return t; 66 else { 67 continue; 68 } 69 } else if (t.matches(type, primitive.getKeys(), false)) { 46 70 return t; 47 else {48 continue;49 71 } 50 } else if (t.matches(type, primitive.getKeys(), false)) {51 return t;52 72 } 53 73 } … … 55 75 return null; 56 76 } 77 78 @Override 79 public void taggingPresetsModified() { 80 buildPresetsWithPattern(); 81 } 57 82 }
Note:
See TracChangeset
for help on using the changeset viewer.