Mercurial > dive4elements > river
changeset 3841:5877d6900e34
Refactor GaugeTree folding for different states
flys-client/trunk@5556 c6561f87-3c4e-4783-a992-168aeb5c3f6f
author | Bjoern Ricks <bjoern.ricks@intevation.de> |
---|---|
date | Fri, 21 Sep 2012 13:19:21 +0000 |
parents | cf64f54aa39c |
children | 44c1beb78ad1 |
files | flys-client/ChangeLog flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java |
diffstat | 2 files changed, 73 insertions(+), 38 deletions(-) [+] |
line wrap: on
line diff
--- a/flys-client/ChangeLog Fri Sep 21 11:34:28 2012 +0000 +++ b/flys-client/ChangeLog Fri Sep 21 13:19:21 2012 +0000 @@ -1,3 +1,10 @@ +2012-09-21 Björn Ricks <bjoern.ricks@intevation.de> + + * src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java: + Additional refactoring to avoid code duplication and fixing reading double + value from locations DataItem object. Also add another code path for + location_distance winfo state. + 2012-09-21 Björn Ricks <bjoern.ricks@intevation.de> * src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java:
--- a/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java Fri Sep 21 11:34:28 2012 +0000 +++ b/flys-client/src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java Fri Sep 21 13:19:21 2012 +0000 @@ -220,16 +220,14 @@ } public void open() { - ArrayList<Double> curvelocations = new ArrayList<Double>(); + ArrayList<Double> locations = new ArrayList<Double>(); if (data != null && data.length > 0) { for (int i = 0; i < data.length; i++) { DataList dl = data[i]; String state = dl.getState(); GWT.log("GaugeTree - setData " + state); - if (state.equals("state.winfo.distance") || - state.equals("state.winfo.distance_only") || - state.equals("state.winfo.location_distance")) { + if (state.equals("state.winfo.location_distance")) { Double ldfrom = null; Double ldto = null; @@ -243,8 +241,31 @@ else if (label.equals("ld_to")) { ldto = getDoubleValue(d); } - else if (label.equals("ld_mode")) { - GWT.log("GaugeTree - setData - ld_mode " + d.getStringValue()); + else if (label.equals("ld_locations")) { + getLocationsFromData(locations, d); + openOnLocations(locations); + return; + } + } + if (ldfrom != null) { + openOnDistance(ldfrom, ldto); + return; + } + } + else if(state.equals("state.winfo.distance_only") || + state.equals("state.winfo.distance")) { + Double ldfrom = null; + Double ldto = null; + + for (int j = dl.size()-1; j >= 0; --j) { + Data d = dl.get(j); + String label = d.getLabel(); + GWT.log("GaugeTree - setData - label " + label + " " + d.getStringValue()); + if (label.equals("ld_from")) { + ldfrom = getDoubleValue(d); + } + else if (label.equals("ld_to")) { + ldto = getDoubleValue(d); } } @@ -254,36 +275,15 @@ } } else if (state.equals("state.winfo.location")) { - ArrayList<Double> locations = new ArrayList<Double>(); - for (int j = dl.size()-1; j >= 0; --j) { - Data d = dl.get(j); - String label = d.getLabel(); - GWT.log("GaugeTree - setData - location label " + - label + " " + d.getStringValue()); - if (label.equals("ld_locations")) { - getLocations(locations, d.getItems()); - } - } + getLocations("ld_locations", locations, dl); openOnLocations(locations); return; } else if (state.equals("state.winfo.reference.curve.input.start")) { - for (int j = dl.size()-1; j >= 0; --j) { - Data d = dl.get(j); - String label = d.getLabel(); - if (label.equals("reference_startpoint")) { - getLocations(curvelocations, d.getItems()); - } - } + getLocations("reference_startpoint", locations, dl); } else if (state.equals("state.winfo.reference.curve.input.end")) { - for (int j = dl.size()-1; j >= 0; --j) { - Data d = dl.get(j); - String label = d.getLabel(); - if (label.equals("reference_endpoint")) { - getLocations(curvelocations, d.getItems()); - } - } + getLocations("reference_endpoint", locations, dl); } else if (state.equals("state.winfo.historicalq.reference_gauge")) { for (int j = dl.size()-1; j >= 0; --j) { @@ -294,6 +294,7 @@ if (tmp != null) { Integer gaugereference = Integer.valueOf(tmp); if (gaugereference != null) { + //TODO } } } @@ -301,25 +302,50 @@ } } } - if (!curvelocations.isEmpty()) { - openOnLocations(curvelocations); + if (!locations.isEmpty()) { + openOnLocations(locations); } else { openAll(); } } - private void getLocations(List<Double> locations, DataItem[] items) { + private void getLocations(String labelname, List<Double> locations, DataList dl) { + for (int j = dl.size()-1; j >= 0; --j) { + Data d = dl.get(j); + String label = d.getLabel(); + if (label.equals(labelname)) { + getLocationsFromData(locations, d); + } + } + } + + private void getLocationsFromData(List<Double> locations, Data data) { + DataItem[] items = data.getItems(); for (int k = 0; k < items.length; k++) { String tmp = items[k].getStringValue(); + GWT.log("GaugeTree - getLocationsFromData " + tmp); if (tmp != null) { - Double value = Double.valueOf(tmp); - if (value != null) { - locations.add(value); + if (tmp.contains(" ")) { + // string contains several values ... + String[] values = tmp.split(" "); + for(int i=0; i < values.length; i++) { + Double value = Double.valueOf(values[i]); + if (value != null) { + locations.add(value); + } + } + } + else { + Double value = Double.valueOf(tmp); + if (value != null) { + locations.add(value); + } } } } } + private Double getDoubleValue(Data d) { String tmp = d.getStringValue(); if (tmp != null) { @@ -346,8 +372,10 @@ } } else { - if ((gitem.getStart() >= start && gitem.getStart() <= end) || - (gitem.getEnd() >= start && gitem.getEnd() <= end)) { + GWT.log("GaugeTree - openOnDistance gitem " + gitem.getStart() + " " + gitem.getEnd()); + if ((start >= gitem.getStart() && start <= gitem.getEnd()) || + (end >= gitem.getStart() && end <= gitem.getEnd()) || + (start <= gitem.getStart() && end >= gitem.getEnd())) { setstate = true; } }