Mercurial > dive4elements > river
diff artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZone.java @ 9260:b570b6fcc052
VegetationZone color added and disabled
author | gernotbelger |
---|---|
date | Tue, 17 Jul 2018 10:59:27 +0200 |
parents | 431f1c269be5 |
children | e511eb935ccd |
line wrap: on
line diff
--- a/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZone.java Mon Jul 16 08:43:07 2018 +0200 +++ b/artifacts/src/main/java/org/dive4elements/river/artifacts/uinfo/vegetationzones/VegetationZone.java Tue Jul 17 10:59:27 2018 +0200 @@ -11,6 +11,7 @@ import java.util.ArrayList; import java.util.List; +import java.util.TreeSet; /** * @author Domenico Nardi Tironi @@ -18,12 +19,15 @@ */ public class VegetationZone implements Comparable<VegetationZone> { - // IMMER ABGLEICHEN MIT VEGETATIONZONE IM CLIENT SuperVegZonesTablePanel.TABLE_CELL_SEPARATOR + // IMMER ABGLEICHEN MIT VegetationZone.class Server und Client + public static final boolean HAS_COLORS_EDITABLE = false; + private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; private final String zoneName; private final int min_day_overflow; private final int max_day_overflow; + private final String hexColor; public static List<VegetationZone> parse(final String zonesRaw) { final List<VegetationZone> resultList = new ArrayList<>(); @@ -40,21 +44,22 @@ } for (final String[] zone : results) { - final VegetationZone helper = new VegetationZone(zone[0], Integer.valueOf(zone[1]), Integer.valueOf(zone[2])); + final VegetationZone helper = new VegetationZone(zone[0], Integer.valueOf(zone[1]), Integer.valueOf(zone[2]), zone[3]); resultList.add(helper); } return resultList; } - public static VegetationZone createFromTableEntry(final String zone, final String min_day_overflow, final String max_day_overflow) { - return new VegetationZone(zone, Integer.valueOf(min_day_overflow), Integer.valueOf(max_day_overflow)); // Error-Handling? + public static VegetationZone createFromTableEntry(final String zone, final String min_day_overflow, final String max_day_overflow, final String hexColor) { + return new VegetationZone(zone, Integer.valueOf(min_day_overflow), Integer.valueOf(max_day_overflow), hexColor); // Error-Handling? } - private VegetationZone(final String zone, final Integer min_day_overflow, final Integer max_day_overflow) { + private VegetationZone(final String zone, final Integer min_day_overflow, final Integer max_day_overflow, final String hexColor) { this.zoneName = zone; this.min_day_overflow = min_day_overflow; this.max_day_overflow = max_day_overflow; + this.hexColor = hexColor; } public int getMax_day_overflow() { @@ -62,9 +67,22 @@ } public String getZoneName() { + if (this.zoneName == null || this.zoneName.equals("")) { + return "---"; + } return this.zoneName; } + public String getHexColor() { + try { + final int test = Integer.decode(this.hexColor); + return this.hexColor; + } + catch (final NumberFormatException e) { + return "#ffffff"; + } + } + public int getMin_day_overflow() { return this.min_day_overflow; } @@ -72,15 +90,15 @@ public static final List<VegetationZone> getStandardList() { final List<VegetationZone> list = new ArrayList<>(); - list.add(new VegetationZone("Zonaler Wald", 0, 5)); - list.add(new VegetationZone("Hartholzaue, trocken", 5, 40)); - list.add(new VegetationZone("Hartholzaue, feucht", 40, 80)); - list.add(new VegetationZone("Silberweidenwald", 80, 140)); - list.add(new VegetationZone("Weidengebüsch", 140, 200)); - list.add(new VegetationZone("Uferröhricht", 200, 260)); - list.add(new VegetationZone("Uferpioniere", 260, 320)); - list.add(new VegetationZone("Vegetationslos", 320, 365)); - list.add(new VegetationZone("Wasserfläche", 365, 365)); + list.add(new VegetationZone("Zonaler Wald", 0, 5, "#336600")); + list.add(new VegetationZone("Hartholzaue, trocken", 6, 40, "#00cc00")); + list.add(new VegetationZone("Hartholzaue, feucht", 41, 80, "#66ff33")); + list.add(new VegetationZone("Silberweidenwald", 81, 140, "#008080")); + list.add(new VegetationZone("Weidengebüsch", 141, 200, "#33cccc")); + list.add(new VegetationZone("Uferröhricht", 201, 260, "#ffa8ff")); + list.add(new VegetationZone("Uferpioniere", 261, 320, "#ff0000")); + list.add(new VegetationZone("Vegetationslos", 321, 364, "#b2b2b2")); + list.add(new VegetationZone("Wasserfläche", 365, 365, "#0066ff")); return list; } @@ -95,6 +113,8 @@ builder.append(zone.getMin_day_overflow()); builder.append(TABLE_CELL_SEPARATOR); builder.append(zone.getMax_day_overflow()); + builder.append(TABLE_CELL_SEPARATOR); + builder.append(zone.getHexColor()); builder.append(TABLE_ROW_SEPARATOR); } return builder.toString(); @@ -105,8 +125,73 @@ public int compareTo(final VegetationZone o) { final int basicCompare = Integer.valueOf(this.getMin_day_overflow()).compareTo(o.getMin_day_overflow()); if (basicCompare == 0) - return Integer.compare(this.getMax_day_overflow(), o.getMax_day_overflow()); // wenn min==min && max==max, alphabetisch sortieren? + return Integer.valueOf(this.getMax_day_overflow()).compareTo(o.getMax_day_overflow()); // wenn min==min && max==max, alphabetisch sortieren? + + if (basicCompare == 0) { + return 1; // for treeSet + } + return basicCompare; } + public static final boolean zonesAreOverlapping(final List<VegetationZone> list) { + for (final VegetationZone zone : list) { + for (final VegetationZone zoneOther : list) { + if (zone != zoneOther) { + final boolean overlaps = zone.overlaps(zoneOther); + if (overlaps) { + return overlaps; // cancel. only one zone has to overlap + } + } + } + } + + return false; + } + + public static final boolean hasGaps(final List<VegetationZone> list, final int lower, final int upper) { + + if ((upper - lower) == 0) + return true; + + final TreeSet<VegetationZone> treeList = new TreeSet<>(); + treeList.addAll(list); + int lowerCompare = lower; + for (final VegetationZone zone : treeList) { + if (zone.getLowerFromTo() > (lowerCompare + 1)) { // nicht inklusiv + return true; + } + lowerCompare = zone.getUpperFromTo(); + } + if ((lowerCompare) < upper) + return true; // am Ende nicht geschlossen + + return false; + } + + private boolean overlaps(final VegetationZone otherZone) { + final int otherLower = otherZone.getLowerFromTo(); + final int otherUpper = otherZone.getUpperFromTo(); + + final int upper = getUpperFromTo(); + final int lower = getLowerFromTo(); + final int otherSchwerpunkt = (otherLower + otherUpper) / 2; + if ((otherUpper <= upper && otherUpper >= lower)) { + return true; + } else if (otherLower >= lower && otherLower <= upper) { + return true; + } else if (otherSchwerpunkt >= (lower) && otherSchwerpunkt <= (upper)) { + return true; + } + return false; + } + + public Integer getLowerFromTo() { + return this.min_day_overflow < this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow; // Math. is forbidden :-( + } + + public Integer getUpperFromTo() { + return this.min_day_overflow > this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow;// Math. is forbidden :-( + } + }