From 62c36174ce0d63aca7bab3936226d01734bb9b12 Mon Sep 17 00:00:00 2001 From: =?utf8?q?Johannes=20Dahlstr=C3=B6m?= Date: Mon, 7 May 2012 13:22:39 +0000 Subject: [PATCH] #8763 Use Set instead of an array in TouchScrollDelegate to allow dynamic adding and removing scrollable elements svn changeset:23687/svn branch:6.8 --- .../gwt/client/ui/TouchScrollDelegate.java | 27 +++++++++++-------- 1 file changed, 16 insertions(+), 11 deletions(-) diff --git a/src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java b/src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java index ac9527e3ef..65d8029593 100644 --- a/src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java +++ b/src/com/vaadin/terminal/gwt/client/ui/TouchScrollDelegate.java @@ -4,6 +4,8 @@ package com.vaadin.terminal.gwt.client.ui; import java.util.ArrayList; +import java.util.Arrays; +import java.util.HashSet; import com.google.gwt.animation.client.Animation; import com.google.gwt.core.client.Duration; @@ -70,7 +72,7 @@ public class TouchScrollDelegate implements NativePreviewHandler { private static final double DECELERATION = 0.002; private static final int MAX_DURATION = 1500; private int origY; - private Element[] scrollableElements; + private HashSet scrollableElements; private Element scrolledElement; private int origScrollTop; private HandlerRegistration handlerRegistration; @@ -101,7 +103,9 @@ public class TouchScrollDelegate implements NativePreviewHandler { } else { delegate = null; } - setElements(scrollables); + for (Element scrollable : scrollables) { + addElement(scrollable); + } } public void onTouchStart(TouchStartEvent event) { @@ -109,12 +113,17 @@ public class TouchScrollDelegate implements NativePreviewHandler { delegate.onTouchStart(event); } - public void setElements(Element... scrollables) { - for (Element scrollable : scrollables) { - scrollable.addClassName("v-scrollable"); + public void addElement(Element scrollable) { + scrollable.addClassName("v-scrollable"); + if (requiresDelegate) { + delegate.scrollableElements.add(scrollable); } + } + + public void removeElement(Element scrollable) { + scrollable.removeClassName("v-scrollable"); if (requiresDelegate) { - delegate.setElements(scrollables); + delegate.scrollableElements.remove(scrollable); } } } @@ -125,7 +134,7 @@ public class TouchScrollDelegate implements NativePreviewHandler { } public TouchScrollDelegate(Element... elements) { - scrollableElements = elements; + scrollableElements = new HashSet(Arrays.asList(elements)); } public void setScrollHandler(ScrollHandler scrollHandler) { @@ -573,10 +582,6 @@ public class TouchScrollDelegate implements NativePreviewHandler { } } - public void setElements(Element[] elements) { - scrollableElements = elements; - } - /** * long calcucation are not very efficient in GWT, so this helper method * returns timestamp in double. -- 2.39.5