comparison gwt-client/src/main/java/org/dive4elements/river/client/shared/model/VegetationZone.java @ 9260:b570b6fcc052

VegetationZone color added and disabled
author gernotbelger
date Tue, 17 Jul 2018 10:59:27 +0200
parents 36c80c7fd02f
children
comparison
equal deleted inserted replaced
9259:66b003701546 9260:b570b6fcc052
10 10
11 package org.dive4elements.river.client.shared.model; 11 package org.dive4elements.river.client.shared.model;
12 12
13 import java.util.ArrayList; 13 import java.util.ArrayList;
14 import java.util.List; 14 import java.util.List;
15 import java.util.TreeSet;
15 16
16 /** 17 /**
17 * @author Domenico Nardi Tironi 18 * @author Domenico Nardi Tironi
18 * 19 *
19 */ 20 */
20 public class VegetationZone implements Comparable<VegetationZone> { 21 public class VegetationZone implements Comparable<VegetationZone> {
21 22
22 // IMMER ABGLEICHEN MIT VegetationZone.class IM SERVER 23 // IMMER ABGLEICHEN MIT VegetationZone.class IM SERVER
24 public static final boolean HAS_COLORS_EDITABLE = false;
25
23 private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR"; 26 private static final String TABLE_CELL_SEPARATOR = "TABLE_CELL_SEPARATOR";
24 private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR"; 27 private static final String TABLE_ROW_SEPARATOR = "TABLE_ROW_SEPARATOR";
25 private final String zoneName; 28 private final String zoneName;
26 private final int min_day_overflow; 29 private final int min_day_overflow;
27 private final int max_day_overflow; 30 private final int max_day_overflow;
31 private final String hexColor;
28 32
29 public static List<VegetationZone> parse(final String zonesRaw) { 33 public static List<VegetationZone> parse(final String zonesRaw) {
30 final List<VegetationZone> resultList = new ArrayList<VegetationZone>(); 34 final List<VegetationZone> resultList = new ArrayList<VegetationZone>();
31 35
32 final List<String[]> results = new ArrayList<String[]>(); 36 final List<String[]> results = new ArrayList<String[]>();
39 } 43 }
40 } 44 }
41 } 45 }
42 for (final String[] zone : results) { 46 for (final String[] zone : results) {
43 47
44 final VegetationZone helper = new VegetationZone(zone[0], Integer.valueOf(zone[1]), Integer.valueOf(zone[2])); 48 final VegetationZone helper = new VegetationZone(zone[0], Integer.valueOf(zone[1]), Integer.valueOf(zone[2]), zone[3]);
45 resultList.add(helper); 49 resultList.add(helper);
46 } 50 }
47 51
48 return resultList; 52 return resultList;
49 } 53 }
50 54
51 public static VegetationZone createFromTableEntry(final String zone, final String min_day_overflow, final String max_day_overflow) { 55 public static VegetationZone createFromTableEntry(final String zone, final String min_day_overflow, final String max_day_overflow, final String hexColor) {
52 return new VegetationZone(zone, Integer.valueOf(min_day_overflow), Integer.valueOf(max_day_overflow)); // Error-Handling? 56 return new VegetationZone(zone, Integer.valueOf(min_day_overflow), Integer.valueOf(max_day_overflow), hexColor); // Error-Handling?
53 } 57 }
54 58
55 private VegetationZone(final String zone, final Integer min_day_overflow, final Integer max_day_overflow) { 59 private VegetationZone(final String zone, final Integer min_day_overflow, final Integer max_day_overflow, final String hexColor) {
56 this.zoneName = zone; 60 this.zoneName = zone;
57 this.min_day_overflow = min_day_overflow; 61 this.min_day_overflow = min_day_overflow;
58 this.max_day_overflow = max_day_overflow; 62 this.max_day_overflow = max_day_overflow;
63 this.hexColor = hexColor;
59 } 64 }
60 65
61 public int getMax_day_overflow() { 66 public int getMax_day_overflow() {
62 return this.max_day_overflow; 67 return this.max_day_overflow;
63 } 68 }
64 69
65 public String getZoneName() { 70 public String getZoneName() {
71 if (this.zoneName == null || this.zoneName.equals("")) {
72 return "---";
73 }
66 return this.zoneName; 74 return this.zoneName;
75 }
76
77 public String getHexColor() {
78 try {
79 final int test = Integer.decode(this.hexColor);
80 return this.hexColor;
81 }
82 catch (final NumberFormatException e) {
83 return "#ffffff";
84 }
67 } 85 }
68 86
69 public int getMin_day_overflow() { 87 public int getMin_day_overflow() {
70 return this.min_day_overflow; 88 return this.min_day_overflow;
71 } 89 }
72 90
73 public static final List<VegetationZone> getStandardList() { 91 public static final List<VegetationZone> getStandardList() {
74 92
75 final List<VegetationZone> list = new ArrayList<VegetationZone>(); 93 final List<VegetationZone> list = new ArrayList<VegetationZone>();
76 list.add(new VegetationZone("Zonaler Wald", 0, 5)); 94 list.add(new VegetationZone("Zonaler Wald", 0, 5, "#336600"));
77 list.add(new VegetationZone("Hartholzaue, trocken", 5, 40)); 95 list.add(new VegetationZone("Hartholzaue, trocken", 6, 40, "#00cc00"));
78 list.add(new VegetationZone("Hartholzaue, feucht", 40, 80)); 96 list.add(new VegetationZone("Hartholzaue, feucht", 41, 80, "#66ff33"));
79 list.add(new VegetationZone("Silberweidenwald", 80, 140)); 97 list.add(new VegetationZone("Silberweidenwald", 81, 140, "#008080"));
80 list.add(new VegetationZone("Weidengebüsch", 140, 200)); 98 list.add(new VegetationZone("Weidengebüsch", 141, 200, "#33cccc"));
81 list.add(new VegetationZone("Uferröhricht", 200, 260)); 99 list.add(new VegetationZone("Uferröhricht", 201, 260, "#ffa8ff"));
82 list.add(new VegetationZone("Uferpioniere", 260, 320)); 100 list.add(new VegetationZone("Uferpioniere", 261, 320, "#ff0000"));
83 list.add(new VegetationZone("Vegetationslos", 320, 365)); 101 list.add(new VegetationZone("Vegetationslos", 321, 364, "#b2b2b2"));
84 list.add(new VegetationZone("Wasserfläche", 365, 365)); 102 list.add(new VegetationZone("Wasserfläche", 365, 365, "#0066ff"));
85 103
86 return list; 104 return list;
87 } 105 }
88 106
89 public static final String parseListToDataString(final List<VegetationZone> list) { 107 public static final String parseListToDataString(final List<VegetationZone> list) {
94 builder.append(zone.getZoneName()); 112 builder.append(zone.getZoneName());
95 builder.append(TABLE_CELL_SEPARATOR); 113 builder.append(TABLE_CELL_SEPARATOR);
96 builder.append(zone.getMin_day_overflow()); 114 builder.append(zone.getMin_day_overflow());
97 builder.append(TABLE_CELL_SEPARATOR); 115 builder.append(TABLE_CELL_SEPARATOR);
98 builder.append(zone.getMax_day_overflow()); 116 builder.append(zone.getMax_day_overflow());
117 builder.append(TABLE_CELL_SEPARATOR);
118 builder.append(zone.getHexColor());
99 builder.append(TABLE_ROW_SEPARATOR); 119 builder.append(TABLE_ROW_SEPARATOR);
100 } 120 }
101 return builder.toString(); 121 return builder.toString();
102 122
103 } 123 }
105 @Override 125 @Override
106 public int compareTo(final VegetationZone o) { 126 public int compareTo(final VegetationZone o) {
107 final int basicCompare = Integer.valueOf(this.getMin_day_overflow()).compareTo(o.getMin_day_overflow()); 127 final int basicCompare = Integer.valueOf(this.getMin_day_overflow()).compareTo(o.getMin_day_overflow());
108 if (basicCompare == 0) 128 if (basicCompare == 0)
109 return Integer.valueOf(this.getMax_day_overflow()).compareTo(o.getMax_day_overflow()); // wenn min==min && max==max, alphabetisch sortieren? 129 return Integer.valueOf(this.getMax_day_overflow()).compareTo(o.getMax_day_overflow()); // wenn min==min && max==max, alphabetisch sortieren?
130
131 if (basicCompare == 0) {
132 return 1; // for treeSet
133 }
134
110 return basicCompare; 135 return basicCompare;
111 } 136 }
112 137
138 public static final boolean zonesAreOverlapping(final List<VegetationZone> list) {
139 for (final VegetationZone zone : list) {
140 for (final VegetationZone zoneOther : list) {
141 if (zone != zoneOther) {
142 final boolean overlaps = zone.overlaps(zoneOther);
143 if (overlaps) {
144 return overlaps; // cancel. only one zone has to overlap
145 }
146 }
147 }
148 }
149
150 return false;
151 }
152
153 public static final boolean hasGaps(final List<VegetationZone> list, final int lower, final int upper) {
154
155 if ((upper - lower) == 0)
156 return true;
157
158 final TreeSet<VegetationZone> treeList = new TreeSet<VegetationZone>();
159 treeList.addAll(list);
160 int lowerCompare = lower;
161 for (final VegetationZone zone : treeList) {
162 if (zone.getLowerFromTo() > (lowerCompare + 1)) { // nicht inklusiv
163 return true;
164 }
165 lowerCompare = zone.getUpperFromTo();
166 }
167 if ((lowerCompare) < upper)
168 return true; // am Ende nicht geschlossen
169
170 return false;
171 }
172
173 private boolean overlaps(final VegetationZone otherZone) {
174 final int otherLower = otherZone.getLowerFromTo();
175 final int otherUpper = otherZone.getUpperFromTo();
176
177 final int upper = getUpperFromTo();
178 final int lower = getLowerFromTo();
179 final int otherSchwerpunkt = (otherLower + otherUpper) / 2;
180 if ((otherUpper <= upper && otherUpper >= lower)) {
181 return true;
182 } else if (otherLower >= lower && otherLower <= upper) {
183 return true;
184 } else if (otherSchwerpunkt >= (lower) && otherSchwerpunkt <= (upper)) {
185 return true;
186 }
187 return false;
188 }
189
190 public Integer getLowerFromTo() {
191 return this.min_day_overflow < this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow; // Math. is forbidden :-(
192 }
193
194 public Integer getUpperFromTo() {
195 return this.min_day_overflow > this.max_day_overflow ? this.min_day_overflow : this.max_day_overflow;// Math. is forbidden :-(
196 }
197
113 } 198 }

http://dive4elements.wald.intevation.org