From 79856bd93e08359a7873fc37dae9bd7cfb33904c Mon Sep 17 00:00:00 2001 From: Mike Primm Date: Fri, 30 Sep 2011 11:26:31 +0800 Subject: [PATCH] Add support for HTML-markup-encoded marker labels, with associated API --- src/main/java/org/dynmap/markers/Marker.java | 12 +++++++++++- .../java/org/dynmap/markers/MarkerSet.java | 17 ++++++++++++++++- .../org/dynmap/markers/impl/MarkerAPIImpl.java | 1 + .../org/dynmap/markers/impl/MarkerImpl.java | 18 +++++++++++++++++- .../org/dynmap/markers/impl/MarkerSetImpl.java | 6 +++++- web/js/markers.js | 14 ++++++++++---- 6 files changed, 60 insertions(+), 8 deletions(-) diff --git a/src/main/java/org/dynmap/markers/Marker.java b/src/main/java/org/dynmap/markers/Marker.java index adb37c0a..b362d7c6 100644 --- a/src/main/java/org/dynmap/markers/Marker.java +++ b/src/main/java/org/dynmap/markers/Marker.java @@ -68,7 +68,17 @@ public interface Marker { */ public String getLabel(); /** - * Update the marker's label + * Update the marker's label (plain text) */ public void setLabel(String lbl); + /** + * Update the marker's label and markup flag + * @param label - label string + * @param markup - if true, label is processed as HTML (innerHTML for used for label); false implies plaintext + */ + public void setLabel(String lbl, boolean markup); + /** + * Test if marker label is processed as HTML + */ + public boolean isLabelMarkup(); } diff --git a/src/main/java/org/dynmap/markers/MarkerSet.java b/src/main/java/org/dynmap/markers/MarkerSet.java index ef46c543..490f535d 100644 --- a/src/main/java/org/dynmap/markers/MarkerSet.java +++ b/src/main/java/org/dynmap/markers/MarkerSet.java @@ -19,7 +19,7 @@ public interface MarkerSet { * Create a new marker in the marker set * * @param id - ID of the marker - must be unique within the set: if null, unique ID is generated - * @param label - Label for the marker + * @param label - Label for the marker (plain text) * @param world - world ID * @param x - x coord * @param y - y coord @@ -29,6 +29,21 @@ public interface MarkerSet { * @return created marker, or null if cannot be created. */ public Marker createMarker(String id, String label, String world, double x, double y, double z, MarkerIcon icon, boolean is_persistent); + /** + * Create a new marker in the marker set + * + * @param id - ID of the marker - must be unique within the set: if null, unique ID is generated + * @param label - Label for the marker + * @param markup - if true, label is processed as HTML. if false, label is processed as plain text. + * @param world - world ID + * @param x - x coord + * @param y - y coord + * @param z - z coord + * @param icon - Icon for the marker + * @param is_persistent - if true, marker is persistent (saved and reloaded on restart). If set is not persistent, this must be false. + * @return created marker, or null if cannot be created. + */ + public Marker createMarker(String id, String label, boolean markup, String world, double x, double y, double z, MarkerIcon icon, boolean is_persistent); /** * Get marker by ID * @param id - ID of the marker diff --git a/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java b/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java index 9f6f8040..807baca3 100644 --- a/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java +++ b/src/main/java/org/dynmap/markers/impl/MarkerAPIImpl.java @@ -1053,6 +1053,7 @@ public class MarkerAPIImpl implements MarkerAPI, Event.Listener { mdata.put("z", m.getZ()); mdata.put("icon", m.getMarkerIcon().getMarkerIconID()); mdata.put("label", m.getLabel()); + mdata.put("markup", m.isLabelMarkup()); /* Add to markers */ markers.put(m.getMarkerID(), mdata); } diff --git a/src/main/java/org/dynmap/markers/impl/MarkerImpl.java b/src/main/java/org/dynmap/markers/impl/MarkerImpl.java index da8bc443..461e9f41 100644 --- a/src/main/java/org/dynmap/markers/impl/MarkerImpl.java +++ b/src/main/java/org/dynmap/markers/impl/MarkerImpl.java @@ -14,6 +14,7 @@ import org.dynmap.markers.impl.MarkerAPIImpl.MarkerUpdate; class MarkerImpl implements Marker { private String markerid; private String label; + private boolean markup; private MarkerSetImpl markerset; private double x, y, z; private String world; @@ -24,6 +25,7 @@ class MarkerImpl implements Marker { * Create marker * @param id - marker ID * @param lbl - label + * @param markup - if true, label is HTML markup * @param world - world id * @param x - x coord * @param y - y coord @@ -31,12 +33,13 @@ class MarkerImpl implements Marker { * @param icon - marker icon * @param persistent - true if persistent */ - MarkerImpl(String id, String lbl, String world, double x, double y, double z, MarkerIconImpl icon, boolean persistent, MarkerSetImpl set) { + MarkerImpl(String id, String lbl, boolean markup, String world, double x, double y, double z, MarkerIconImpl icon, boolean persistent, MarkerSetImpl set) { markerid = id; if(lbl != null) label = lbl; else label = id; + this.markup = markup; this.x = x; this.y = y; this.z = z; this.world = world; this.icon = icon; @@ -52,6 +55,7 @@ class MarkerImpl implements Marker { markerid = id; markerset = set; label = id; + markup = false; x = z = 0; y = 64; world = "world"; icon = MarkerAPIImpl.getMarkerIconImpl(MarkerIcon.DEFAULT); } @@ -61,6 +65,7 @@ class MarkerImpl implements Marker { */ boolean loadPersistentData(ConfigurationNode node) { label = node.getString("label", markerid); + markup = node.getBoolean("markup", false); x = node.getDouble("x", 0); y = node.getDouble("y", 64); z = node.getDouble("z", 0); @@ -127,7 +132,13 @@ class MarkerImpl implements Marker { @Override public void setLabel(String lbl) { + setLabel(lbl, false); + } + + @Override + public void setLabel(String lbl, boolean markup) { label = lbl; + this.markup = markup; MarkerAPIImpl.markerUpdated(this, MarkerUpdate.UPDATED); if(ispersistent) MarkerAPIImpl.saveMarkers(); @@ -142,6 +153,7 @@ class MarkerImpl implements Marker { return null; HashMap node = new HashMap(); node.put("label", label); + node.put("markup", markup); node.put("x", Double.valueOf(x)); node.put("y", Double.valueOf(y)); node.put("z", Double.valueOf(z)); @@ -176,4 +188,8 @@ class MarkerImpl implements Marker { if(ispersistent) MarkerAPIImpl.saveMarkers(); } + @Override + public boolean isLabelMarkup() { + return markup; + } } diff --git a/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java b/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java index 1ad98080..05ff6c73 100644 --- a/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java +++ b/src/main/java/org/dynmap/markers/impl/MarkerSetImpl.java @@ -59,6 +59,10 @@ class MarkerSetImpl implements MarkerSet { @Override public Marker createMarker(String id, String label, String world, double x, double y, double z, MarkerIcon icon, boolean is_persistent) { + return createMarker(id, label, false, world, x, y, z, icon, is_persistent); + } + @Override + public Marker createMarker(String id, String label, boolean markup, String world, double x, double y, double z, MarkerIcon icon, boolean is_persistent) { if(id == null) { /* If not defined, generate unique one */ int i = 0; do { @@ -72,7 +76,7 @@ class MarkerSetImpl implements MarkerSet { if((allowedicons != null) && (allowedicons.containsKey(icon.getMarkerIconID()) == false)) return null; /* Create marker */ is_persistent = is_persistent && this.ispersistent; - MarkerImpl marker = new MarkerImpl(id, label, world, x, y, z, (MarkerIconImpl)icon, is_persistent, this); + MarkerImpl marker = new MarkerImpl(id, label, markup, world, x, y, z, (MarkerIconImpl)icon, is_persistent, this); markers.put(id, marker); /* Add to set */ if(is_persistent) MarkerAPIImpl.saveMarkers(); diff --git a/web/js/markers.js b/web/js/markers.js index 2b456278..2ff24904 100644 --- a/web/js/markers.js +++ b/web/js/markers.js @@ -36,7 +36,7 @@ componentconstructors['markers'] = function(dynmap, configuration) { } dynmapmarkersets[name] = ms; $.each(markerset.markers, function(mname, marker) { - ms.markers[mname] = { label: marker.label, x: marker.x, y: marker.y, z:marker.z, + ms.markers[mname] = { label: marker.label, markup: marker.markup, x: marker.x, y: marker.y, z:marker.z, icon: marker.icon }; createMarker(ms, ms.markers[mname], ts); }); @@ -59,8 +59,14 @@ componentconstructors['markers'] = function(dynmap, configuration) { $(div) .addClass('Marker') .addClass('mapMarker') - .append($('').addClass('markerIcon16x16').attr({ src: dynmap.options.tileUrl+'_markers_/'+marker.icon+'.png' })) - .append($('') + .append($('').addClass('markerIcon16x16').attr({ src: dynmap.options.tileUrl+'_markers_/'+marker.icon+'.png' })); + if(marker.markup) { + $(div).append($('') + .addClass(configuration.showlabel?'markerName-show':'markerName') + .append(marker.label)); + } + else + $(div).append($('') .addClass(configuration.showlabel?'markerName-show':'markerName') .text(marker.label)); return div; @@ -86,7 +92,7 @@ componentconstructors['markers'] = function(dynmap, configuration) { dynmapmarkersets[msg.set].layergroup.removeLayer(marker.our_marker); delete marker.our_marker; } - marker = { x: msg.x, y: msg.y, z: msg.z, icon: msg.icon, label: msg.label }; + marker = { x: msg.x, y: msg.y, z: msg.z, icon: msg.icon, label: msg.label, markup: msg.markup }; dynmapmarkersets[msg.set].markers[msg.id] = marker; createMarker(dynmapmarkersets[msg.set], marker); }