# HG changeset patch # User Raimund Renkert # Date 1369749430 -7200 # Node ID 0b9f0d37fe6e093dc48ed3ba6ebcaec40bfe8e19 # Parent 97d055c24ad48ee7f8ccda3162bab661424fcf10 We have a much faster interactive image map! * Image for highlighting rivers in link list instead of CSS manipulation. * Better event handling. * No more hover delay. Some problems still exist: * Sometime when switching the module to 'MINFO' the highlighted river on the image map is not unhighlighted. * The loop to unhighlight rivers when switching modules is called for every river. diff -r 97d055c24ad4 -r 0b9f0d37fe6e gwt-client/src/main/java/org/dive4elements/river/client/client/ui/LinkSelection.java --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/LinkSelection.java Tue May 28 13:49:51 2013 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/LinkSelection.java Tue May 28 15:57:10 2013 +0200 @@ -16,7 +16,10 @@ import com.smartgwt.client.types.VerticalAlignment; import com.smartgwt.client.widgets.Canvas; import com.smartgwt.client.widgets.HTMLPane; +import com.smartgwt.client.widgets.Img; import com.smartgwt.client.widgets.Label; +import com.smartgwt.client.widgets.events.VisibilityChangedEvent; +import com.smartgwt.client.widgets.events.VisibilityChangedHandler; import com.smartgwt.client.widgets.form.DynamicForm; import com.smartgwt.client.widgets.form.fields.LinkItem; import com.smartgwt.client.widgets.form.fields.events.ClickEvent; @@ -42,6 +45,7 @@ */ public class LinkSelection extends MapSelection +implements VisibilityChangedHandler { private static final long serialVersionUID = -7138270638349711024L; @@ -51,7 +55,9 @@ /** The selected river*/ protected Data river; - private static Map rivers; + private static Map riverHighlight; + private static Map riverList; + private static String selected; private static HLayout columns; private static Trigger trigger; @@ -95,7 +101,8 @@ public Canvas create(DataList data) { trigger = new Trigger(this); createCallback(); - rivers = new HashMap(); + riverHighlight = new HashMap(); + riverList = new HashMap(); VLayout v = new VLayout(); v.setMembersMargin(10); @@ -182,22 +189,37 @@ int counter = 0; for (DataItem item: d.getItems()) { + HLayout row = new HLayout(); LinkItem link = new LinkItem("river"); + link.setHoverDelay(0); link.setLinkTitle(item.getLabel()); link.setTarget(item.getStringValue()); link.setShowTitle(false); + Img img = new Img(); + img.setShowTitle(false); + img.setSrc("marker_green.png"); + img.setWidth(20); + img.setHeight(20); + img.setVisible(false); + Canvas container = new Canvas(); + container.addChild(img); + container.setHeight(20); + container.setWidth(20); DynamicForm f = new DynamicForm(); - rivers.put(item.getStringValue(), link); - + riverList.put(item.getStringValue(), row); + riverHighlight.put(item.getStringValue(), img); f.setItems(link); + row.addMember(container); + row.addMember(f); + row.addVisibilityChangedHandler(this); + link.setColSpan(20); if (counter < d.getItems().length/2) { - formLayout1.addMember(f); + formLayout1.addMember(row); } else { - formLayout2.addMember(f); + formLayout2.addMember(row); } counter++; - link.addClickHandler(new ClickHandler() { @Override public void onClick(ClickEvent event) { @@ -218,27 +240,22 @@ @Override public void onItemHover(ItemHoverEvent event) { String river = ((LinkItem)event.getItem()).getLinkTitle(); - for (Map.Entry entry: rivers.entrySet()) { - String s = entry.getKey(); - LinkItem item = entry.getValue(); - if (item.getLinkTitle().equals(river)) { - item.setCellStyle("riverLinkHighlight"); - callHighlightRiver(river); + if (riverHighlight.containsKey(river)) { + Img item = riverHighlight.get(river); + item.setVisible(true); + if (selected != null && !selected.equals(river)) { + riverHighlight.get(selected).setVisible(false); + callUnHighlightRiver(selected); } - else { - item.setCellStyle("formCell"); - callUnHighlightRiver(s); - } - } - if (columns != null) { - columns.redraw(); + callHighlightRiver(river); + selected = river; } } }); } if (module != null) { - getModuleSelection().setRivers(rivers); + getModuleSelection().setRivers(riverList); } label.setWidth(50); @@ -270,24 +287,31 @@ private native void createCallback() /*-{ $wnd.highlightRiver = @org.dive4elements.river.client.client.ui.LinkSelection::highlightCallback(Ljava/lang/String;); + $wnd.unHighlightRiver = @org.dive4elements.river.client.client.ui.LinkSelection::unHighlightCallback(Ljava/lang/String;); $wnd.selectRiver = @org.dive4elements.river.client.client.ui.LinkSelection::selectCallback(Ljava/lang/String;); $wnd.availableRiver = @org.dive4elements.river.client.client.ui.LinkSelection::availableRiver(Ljava/lang/String;); }-*/; private static void highlightCallback(String name) { - for (Map.Entry entry: rivers.entrySet()) { - String s = entry.getKey(); - LinkItem item = entry.getValue(); - item.setCellStyle(s.equals(name) ? "riverLinkHighlight" : "formCell"); + if (riverHighlight.containsKey(name)) { + riverHighlight.get(name).setVisible(true); + if(selected != null && !selected.equals(name)) { + riverHighlight.get(selected).setVisible(false); + } + selected = name; } - if (columns != null) { - columns.redraw(); + } + + private static void unHighlightCallback(String name) { + if (riverHighlight.containsKey(name)) { + riverHighlight.get(name).setVisible(false); + selected = null; } } private static boolean availableRiver(String river) { - LinkItem ri = rivers.get(river); - return ri != null && ri.isVisible(); + HLayout row = riverList.get(river); + return row != null && row.isVisible(); } private static void selectCallback(String name) { @@ -303,5 +327,15 @@ private native void callUnHighlightRiver(String name) /*-{ $wnd.unHighlight(name); }-*/; + + + @Override + public void onVisibilityChanged(VisibilityChangedEvent event) { + for (Map.Entry entry: riverHighlight.entrySet()) { + entry.getValue().setVisible(false); + callUnHighlightRiver(entry.getKey()); + } + selected = null; + } } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 97d055c24ad4 -r 0b9f0d37fe6e gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ModuleSelection.java --- a/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ModuleSelection.java Tue May 28 13:49:51 2013 +0200 +++ b/gwt-client/src/main/java/org/dive4elements/river/client/client/ui/ModuleSelection.java Tue May 28 15:57:10 2013 +0200 @@ -65,7 +65,7 @@ private List fixRivers; private List minfoRivers; - protected Map rivers; + protected Map rivers; /** * The default constructor. @@ -179,7 +179,7 @@ public void onChange(ChangeEvent event) { String selected = (String)event.getValue(); if (!rivers.isEmpty()) { - for (Map.Entry s: rivers.entrySet()) { + for (Map.Entry s: rivers.entrySet()) { if (selected.equals("minfo") && !minfoRivers.contains(s.getKey())) { s.getValue().hide(); } @@ -188,9 +188,7 @@ } else { s.getValue().show(); - s.getValue().setCellStyle("formCell"); } - callUnHighlightRiver(s.getKey()); } } } @@ -235,12 +233,8 @@ return new Data[] {data}; } - public void setRivers(Map rivers) { + public void setRivers(Map rivers) { this.rivers = rivers; } - - private native void callUnHighlightRiver(String name) /*-{ - $wnd.unHighlight(name); - }-*/; } // vim:set ts=4 sw=4 si et sta sts=4 fenc=utf8 : diff -r 97d055c24ad4 -r 0b9f0d37fe6e gwt-client/src/main/webapp/images/FLYS_Karte_interactive.html --- a/gwt-client/src/main/webapp/images/FLYS_Karte_interactive.html Tue May 28 13:49:51 2013 +0200 +++ b/gwt-client/src/main/webapp/images/FLYS_Karte_interactive.html Tue May 28 15:57:10 2013 +0200 @@ -6,19 +6,19 @@ unHighlight(highlighted); var river; if (availableRiver(name)) { - console.log('highlighting ' + name); river = document.getElementById(name); } else { - console.log('not available' + name); river = document.getElementById(name + "_inactive"); } if (river) { highlighted = name; - highlightRiver(name); river.style.visibility="visible"; } } + function highlightList(name) { + highlightRiver(name); + } function unHighlight(name) { var river; if (availableRiver(name)) { @@ -31,6 +31,9 @@ river.style.visibility="hidden"; } } + function unHighlightList(name) { + unHighlightRiver(name); + } @@ -41,30 +44,30 @@ - - - - - - - - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + +