Changeset 29335 in osm for applications


Ignore:
Timestamp:
2013-03-03T15:57:12+01:00 (11 years ago)
Author:
simon04
Message:

JOSM/wikipedia: store copy templates in preference key wikipedia.copytemplates and thus make them configurable

File:
1 edited

Legend:

Unmodified
Added
Removed
  • applications/editors/josm/plugins/wikipedia/src/org/wikipedia/WikipediaCopyTemplate.java

    r29334 r29335  
    1010import org.openstreetmap.josm.Main;
    1111import org.openstreetmap.josm.actions.JosmAction;
     12import org.openstreetmap.josm.data.Preferences;
     13import org.openstreetmap.josm.data.Preferences.pref;
    1214import org.openstreetmap.josm.data.osm.Node;
    1315import org.openstreetmap.josm.data.osm.OsmPrimitive;
     
    1719public class WikipediaCopyTemplate {
    1820
    19     private static final List<CoordCopyTemplate> TEMPLATES = Arrays.asList(
    20             new CoordCopyTemplate(tr("Copy {0} template", "{{Coordinate}}"), "wikipedia-coordinate", "{{Coordinate|NS={lat}|EW={lon}|type=landmark|region=}}"),
    21             new CoordCopyTemplate(tr("Copy {0} template", "{{Coord}}"), "wikipedia-coord", "{{Coord|{lat}|{lon}}}"),
    22             new CoordCopyTemplate(tr("Copy {0} template", "{{Location dec}}"), "wikipedia-location-dec", "{{Location dec|{lat}|{lon}}}"),
    23             new CoordCopyTemplate(tr("Copy {0} template", "{{Object location dec}}"), "wikipedia-object-location-dec", "{{Object location dec|{lat}|{lon}}}")
    24             );
     21    private static final List<CoordCopyTemplateEntry> DEFAULT_TEMPLATES = Arrays.asList(
     22            new CoordCopyTemplateEntry("{{Coordinate}}", "wikipedia-coordinate", "{{Coordinate|NS={lat}|EW={lon}|type=landmark|region=}}"),
     23            new CoordCopyTemplateEntry("{{Coord}}", "wikipedia-coord", "{{Coord|{lat}|{lon}}}"),
     24            new CoordCopyTemplateEntry("{{Location dec}}", "wikipedia-location-dec", "{{Location dec|{lat}|{lon}}}"),
     25            new CoordCopyTemplateEntry("{{Object location dec}}", "wikipedia-object-location-dec", "{{Object location dec|{lat}|{lon}}}")
     26    );
     27
     28    private static final List<CoordCopyTemplateEntry> TEMPLATE_ENTRIES =
     29            Main.pref.getListOfStructs("wikipedia.copytemplates", DEFAULT_TEMPLATES, CoordCopyTemplateEntry.class);
    2530
    2631    public WikipediaCopyTemplate() {
    2732        JosmAction previous = Main.main.menu.copyCoordinates;
    28         for (final CoordCopyTemplate t : TEMPLATES) {
     33        for (final CoordCopyTemplateEntry templateEntry : TEMPLATE_ENTRIES) {
     34            CoordCopyTemplate t = new CoordCopyTemplate(templateEntry);
    2935            final JMenuItem menu = MainMenu.addAfter(Main.main.menu.editMenu, t, false, previous);
    30             menu.setToolTipText(tr("Copies the template to the system clipboard instantiated with the coordinates of the first selected node"));
     36            menu.setToolTipText(tr("Copies the {0} template to the system clipboard instantiated with the coordinates of the first selected node", templateEntry.name));
    3137            previous = t;
    32             //MainMenu.addAfter(Main.main.menu.editMenu, coord, false, Main.main.menu.copyCoordinates);
     38        }
     39    }
     40
     41    /**
     42     * Class to hold copy templates for serialization using {@link Preferences}.
     43     * Public visibility is needed for reflection used in {@link Preferences#getListOfStructs}.
     44     */
     45    public static class CoordCopyTemplateEntry {
     46        @pref
     47        public String name;
     48        @pref
     49        public String id;
     50        @pref
     51        public String pattern;
     52
     53        public CoordCopyTemplateEntry() {
     54        }
     55
     56        public CoordCopyTemplateEntry(String name, String id, String pattern) {
     57            this.name = name;
     58            this.id = id;
     59            this.pattern = pattern;
    3360        }
    3461    }
     
    3764
    3865        protected final String pattern;
     66
     67        public CoordCopyTemplate(final CoordCopyTemplateEntry entry) {
     68            this(tr("Copy {0} template", entry.name), entry.id, entry.pattern);
     69        }
    3970
    4071        public CoordCopyTemplate(String name, String toolbarId, String pattern) {
Note: See TracChangeset for help on using the changeset viewer.