Add sorting option to Marker and MarkerSet

This commit is contained in:
Lukas Rieger (Blue) 2023-02-07 17:04:38 +01:00
parent 1d0d63f088
commit bee8770fde
No known key found for this signature in database
GPG Key ID: 2D09EC5ED2687FF2
2 changed files with 77 additions and 4 deletions

View File

@ -44,11 +44,13 @@ public abstract class Marker {
private final String type;
private String label;
private Vector3d position;
private int sorting;
public Marker(String type, String label, Vector3d position) {
this.type = Objects.requireNonNull(type, "type cannot be null");
this.label = Objects.requireNonNull(label, "label cannot be null");
this.position = Objects.requireNonNull(position, "position cannot be null");
this.sorting = 0;
}
/**
@ -107,6 +109,28 @@ public abstract class Marker {
setPosition(new Vector3d(x, y, z));
}
/**
* Returns the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).<br>
* A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.<br>
* If multiple markers have the same sorting-value, their order will be arbitrary.<br>
* This value defaults to 0.
* @return This markers sorting-value
*/
public int getSorting() {
return sorting;
}
/**
* Sets the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).<br>
* A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.<br>
* If multiple markers have the same sorting-value, their order will be arbitrary.<br>
* This value defaults to 0.
* @param sorting the new sorting-value for this marker
*/
public void setSorting(int sorting) {
this.sorting = sorting;
}
@Override
public boolean equals(Object o) {
if (this == o) return true;
@ -131,6 +155,7 @@ public abstract class Marker {
String label;
Vector3d position;
Integer sorting;
/**
* Sets the label of the {@link Marker}.
@ -164,6 +189,18 @@ public abstract class Marker {
return position(new Vector3d(x, y, z));
}
/**
* Sets the sorting-value that will be used by the webapp to sort the markers ("default"-sorting).<br>
* A lower value makes the marker sorted first (in lists and menus), a higher value makes it sorted later.<br>
* If multiple markers have the same sorting-value, their order will be arbitrary.<br>
* This value defaults to 0.
* @param sorting the new sorting-value for this marker
*/
public B sorting(Integer sorting) {
this.sorting = sorting;
return self();
}
/**
* Creates a new {@link Marker} with the current builder-settings
* @return The new {@link Marker}-instance
@ -173,6 +210,7 @@ public abstract class Marker {
T build(T marker) {
if (label != null) marker.setLabel(label);
if (position != null) marker.setPosition(position);
if (sorting != null) marker.setSorting(sorting);
return marker;
}

View File

@ -38,6 +38,7 @@ public class MarkerSet {
private String label;
private boolean toggleable, defaultHidden;
private int sorting;
private final ConcurrentHashMap<String, Marker> markers;
/**
@ -56,10 +57,7 @@ public class MarkerSet {
* @see #setLabel(String)
*/
public MarkerSet(String label) {
this.label = Objects.requireNonNull(label);
this.toggleable = true;
this.defaultHidden = false;
this.markers = new ConcurrentHashMap<>();
this(label, true, false);
}
/**
@ -77,6 +75,7 @@ public class MarkerSet {
this.label = Objects.requireNonNull(label);
this.toggleable = toggleable;
this.defaultHidden = defaultHidden;
this.sorting = 0;
this.markers = new ConcurrentHashMap<>();
}
@ -149,6 +148,28 @@ public class MarkerSet {
this.defaultHidden = defaultHidden;
}
/**
* Returns the sorting-value that will be used by the webapp to sort the marker-sets.<br>
* A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.<br>
* If multiple marker-sets have the same sorting-value, their order will be arbitrary.<br>
* This value defaults to 0.
* @return This marker-sets sorting-value
*/
public int getSorting() {
return sorting;
}
/**
* Sets the sorting-value that will be used by the webapp to sort the marker-sets ("default"-sorting).<br>
* A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.<br>
* If multiple marker-sets have the same sorting-value, their order will be arbitrary.<br>
* This value defaults to 0.
* @param sorting the new sorting-value for this marker-set
*/
public void setSorting(int sorting) {
this.sorting = sorting;
}
/**
* Getter for a (modifiable) {@link Map} of all {@link Marker}s in this {@link MarkerSet}.
* The keys of the map are the id's of the {@link Marker}s.
@ -220,6 +241,7 @@ public class MarkerSet {
private String label;
private Boolean toggleable, defaultHidden;
Integer sorting;
/**
* Sets the label of the {@link MarkerSet}.
@ -262,6 +284,18 @@ public class MarkerSet {
return this;
}
/**
* Sets the sorting-value that will be used by the webapp to sort the marker-sets ("default"-sorting).<br>
* A lower value makes the marker-set sorted first (in lists and menus), a higher value makes it sorted later.<br>
* If multiple marker-sets have the same sorting-value, their order will be arbitrary.<br>
* This value defaults to 0.
* @param sorting the new sorting-value for this marker-set
*/
public Builder sorting(Integer sorting) {
this.sorting = sorting;
return this;
}
/**
* Creates a new {@link MarkerSet} with the current builder-settings.<br>
* The minimum required settings to build this marker-set are:
@ -276,6 +310,7 @@ public class MarkerSet {
);
if (toggleable != null) markerSet.setToggleable(toggleable);
if (defaultHidden != null) markerSet.setDefaultHidden(defaultHidden);
if (sorting != null) markerSet.setSorting(sorting);
return markerSet;
}