# HG changeset patch # User Bjoern Ricks # Date 1348233561 0 # Node ID 5877d6900e34f27a5ed5b62720528a6bb36f9eb3 # Parent cf64f54aa39c67bd73b1fd60b6b611ec7fb4eaea Refactor GaugeTree folding for different states flys-client/trunk@5556 c6561f87-3c4e-4783-a992-168aeb5c3f6f diff -r cf64f54aa39c -r 5877d6900e34 flys-client/ChangeLog --- 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 + + * 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 * src/main/java/de/intevation/flys/client/client/ui/GaugePanel.java: diff -r cf64f54aa39c -r 5877d6900e34 flys-client/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 curvelocations = new ArrayList(); + ArrayList locations = new ArrayList(); 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 locations = new ArrayList(); - 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 locations, DataItem[] items) { + private void getLocations(String labelname, List 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 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; } }