]> source.dussan.org Git - gwtquery.git/commitdiff
Refactoring of plugins package
authorJulien Dramaix <julien.dramaix@gmail.com>
Wed, 2 Mar 2011 20:33:05 +0000 (20:33 +0000)
committerJulien Dramaix <julien.dramaix@gmail.com>
Wed, 2 Mar 2011 20:33:05 +0000 (20:33 +0000)
34 files changed:
gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java
gwtquery-core/src/main/java/com/google/gwt/query/client/LazyGQuery.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ClipAnimation.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/EventsListener.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/GQueryQueue.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/GQueryUi.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/PropertiesAnimation.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/UiPlugin.java [new file with mode: 0755]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Widgets.java
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java [new file with mode: 0755]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java [new file with mode: 0755]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/AbstractWidgetFactory.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TabPanelWidgetFactory.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetFactory.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetOptions.java [new file with mode: 0644]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/Widgets.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/AbstractWidgetFactory.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/ButtonWidgetFactory.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/TabPanelWidgetFactory.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/WidgetFactory.java [deleted file]
gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/WidgetOptions.java [deleted file]
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEffectsTest.java
gwtquery-core/src/test/java/com/google/gwt/query/client/GQueryEventsTest.java
samples/src/main/java/gwtquery/samples/client/GwtQueryEffectsModule.java
samples/src/main/java/gwtquery/samples/client/GwtQueryWidgetModule.java

index 8b67f3b78922fad6cff7ffa4ccb01c414e2ff1c4..5f96cb7a849d2dd3dd3028d69703b994deccbb1b 100644 (file)
@@ -42,8 +42,8 @@ import com.google.gwt.query.client.css.TakesCssValue;
 import com.google.gwt.query.client.css.TakesCssValue.CssSetter;\r
 import com.google.gwt.query.client.impl.DocumentStyleImpl;\r
 import com.google.gwt.query.client.impl.SelectorEngine;\r
-import com.google.gwt.query.client.plugins.EventsListener;\r
 import com.google.gwt.query.client.plugins.Plugin;\r
+import com.google.gwt.query.client.plugins.events.EventsListener;\r
 import com.google.gwt.user.client.DOM;\r
 import com.google.gwt.user.client.Event;\r
 import com.google.gwt.user.client.EventListener;\r
index d4d2a125ae1d8c9a3812ec6e63cab37f8c42ca79..4489a8ed8965ba36cdccf64288dde5b02c211cda 100644 (file)
@@ -40,8 +40,8 @@ import com.google.gwt.query.client.css.TakesCssValue;
 import com.google.gwt.query.client.css.TakesCssValue.CssSetter;
 import com.google.gwt.query.client.impl.DocumentStyleImpl;
 import com.google.gwt.query.client.impl.SelectorEngine;
-import com.google.gwt.query.client.plugins.EventsListener;
 import com.google.gwt.query.client.plugins.Plugin;
+import com.google.gwt.query.client.plugins.events.EventsListener;
 import com.google.gwt.user.client.DOM;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.EventListener;
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ClipAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ClipAnimation.java
deleted file mode 100755 (executable)
index 437c16a..0000000
+++ /dev/null
@@ -1,141 +0,0 @@
-/*\r
- * Copyright 2011, The gwtquery team.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not\r
- * use this file except in compliance with the License. You may obtain a copy of\r
- * the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
- * License for the specific language governing permissions and limitations under\r
- * the License.\r
- */\r
-package com.google.gwt.query.client.plugins;\r
-\r
-import com.google.gwt.animation.client.Animation;\r
-import com.google.gwt.dom.client.Element;\r
-import com.google.gwt.query.client.Function;\r
-import com.google.gwt.query.client.GQuery;\r
-\r
-/**\r
- * Animation wich uses the css clip property to show/hide an element.\r
- */\r
-public class ClipAnimation extends Animation {\r
-\r
-  /**\r
-   * Type of the effect action.\r
-   */\r
-  public static enum Action {\r
-    HIDE, SHOW, TOGGLE\r
-  }\r
-\r
-  /**\r
-   * Corner from which the effect starts.\r
-   */\r
-  public static enum Corner {\r
-    BOTTOM_LEFT, BOTTOM_RIGHT, CENTER, TOP_LEFT, TOP_RIGHT\r
-  }\r
-\r
-  /**\r
-   * Direction of the effect.\r
-   */\r
-  public static enum Direction {\r
-    BIDIRECTIONAL, HORIZONTAL, VERTICAL\r
-  }\r
-\r
-  private static final String[] attrsToSave = new String[] { "position",\r
-      "overflow", "visibility", "white-space", "top", "left" };\r
-\r
-  Action action;\r
-  Corner corner;\r
-  Direction direction;\r
-  Element e;\r
-  int percent;\r
-  private GQuery back = Effects.$();\r
-  private Function[] funcs;\r
-  private Effects g;\r
-\r
-  public ClipAnimation(Element elem, Action a, Corner c, Direction d,\r
-      final Function... funcs) {\r
-    if  (a == Action.TOGGLE) {\r
-      a = GQuery.$(elem).visible() ? Action.HIDE : Action.SHOW; \r
-    }\r
-    this.action = a;\r
-    this.corner = c;\r
-    this.direction = d;\r
-    this.funcs = funcs;\r
-    e = elem;\r
-    g = GQuery.$(e).as(Effects.Effects);\r
-  }\r
-\r
-  @Override\r
-  public void onCancel() {\r
-    onComplete();\r
-  }\r
-\r
-  @Override\r
-  public void onComplete() {\r
-    super.onComplete();\r
-    if (action == Action.HIDE) {\r
-      g.hide();\r
-    }\r
-    g.restoreCssAttrs(attrsToSave);\r
-    back.remove();\r
-    back = Effects.$();\r
-    g.css("clip", "");\r
-    g.each(funcs);\r
-    g.dequeue();\r
-  }\r
-\r
-  @Override\r
-  public void onStart() {\r
-    g.show();\r
-    g.saveCssAttrs(attrsToSave);\r
-    if (!"absolute".equalsIgnoreCase(g.css("position", true))) {\r
-      g.css("position", "absolute");\r
-      g.css("top", g.offset().top + "px");\r
-      g.css("left", g.offset().left + "px");\r
-      back = back.add(g.before("<div></div>")).prev();\r
-      back.height(g.height());\r
-      back.width(g.width());\r
-    }\r
-    g.css("overflow", "hidden");\r
-    g.css("visivility", "visible");\r
-    super.onStart();\r
-  }\r
-\r
-  @Override\r
-  public void onUpdate(double progress) {\r
-    if (action == Action.HIDE) {\r
-      progress = (1 - progress);\r
-    }\r
-    int top = 0;\r
-    int left = 0;\r
-    int right = g.width();\r
-    int bottom = g.height();\r
-\r
-    if (direction == Direction.VERTICAL || direction == Direction.BIDIRECTIONAL) {\r
-      bottom = (int) (g.height() * progress);\r
-    }\r
-    if (direction == Direction.HORIZONTAL\r
-        || direction == Direction.BIDIRECTIONAL) {\r
-      right = (int) (g.width() * progress);\r
-    }\r
-    if (corner == Corner.CENTER) {\r
-      top = (g.height() - bottom) / 2;\r
-      left = (g.width() - right) / 2;\r
-    } else if (corner == Corner.BOTTOM_LEFT) {\r
-      top = (g.height() - bottom);\r
-    } else if (corner == Corner.TOP_RIGHT) {\r
-      left = (g.width() - right);\r
-    } else if (corner == Corner.BOTTOM_RIGHT) {\r
-      left = (g.width() - right);\r
-      top = (g.height() - bottom);\r
-    }\r
-    String rect = top + "px " + right + "px " + bottom + "px  " + left + "px";\r
-    g.css("clip", "rect(" + rect + ")");\r
-  }\r
-}\r
index ffa8b6ddeb4a802e835a331469ca879b03d86cc0..ec903aa48164c3b7ac672992f18d1b2adc2cb16e 100755 (executable)
@@ -20,14 +20,16 @@ import com.google.gwt.dom.client.Element;
 import com.google.gwt.query.client.Function;\r
 import com.google.gwt.query.client.GQuery;\r
 import com.google.gwt.query.client.Properties;\r
-import com.google.gwt.query.client.plugins.ClipAnimation.Action;\r
-import com.google.gwt.query.client.plugins.ClipAnimation.Direction;\r
-import com.google.gwt.query.client.plugins.PropertiesAnimation.Easing;\r
+import com.google.gwt.query.client.plugins.effects.ClipAnimation;\r
+import com.google.gwt.query.client.plugins.effects.PropertiesAnimation;\r
+import com.google.gwt.query.client.plugins.effects.ClipAnimation.Action;\r
+import com.google.gwt.query.client.plugins.effects.ClipAnimation.Direction;\r
+import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing;\r
 \r
 /**\r
  *  Effects plugin for Gwt Query. \r
  */\r
-public class Effects extends GQueryQueue<Effects>  {\r
+public class Effects extends QueuePlugin<Effects>  {\r
   \r
   /**\r
    * Just a class to store predefined speed constant values.\r
index 84e35f805ab86599848b618106c95278d2953e70..2dc8f7855a6f55acd89db286fdc72e5c0cc2b32d 100644 (file)
@@ -19,6 +19,7 @@ import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.NativeEvent;
 import com.google.gwt.query.client.Function;
 import com.google.gwt.query.client.GQuery;
+import com.google.gwt.query.client.plugins.events.EventsListener;
 import com.google.gwt.user.client.Event;
 
 /**
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/EventsListener.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/EventsListener.java
deleted file mode 100644 (file)
index 7b2d609..0000000
+++ /dev/null
@@ -1,245 +0,0 @@
-/*
- * Copyright 2011, The gwtquery team.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.query.client.plugins;
-
-import com.google.gwt.core.client.Duration;
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.query.client.Function;
-import com.google.gwt.query.client.JsObjectArray;
-import com.google.gwt.user.client.DOM;
-import com.google.gwt.user.client.Event;
-import com.google.gwt.user.client.EventListener;
-
-/**
- * This class implements an event queue instance for one Element. The queue
- * instance is configured as the default event listener in GWT.
- * 
- * The reference to this queue is stored as a unique variable in the element's
- * DOM
- * 
- * The class takes care of calling the appropriate functions for each browser
- * event and it also calls sinkEvents method.
- * 
- */
-public class EventsListener implements EventListener {
-
-  private static class BindFunction {
-
-    Object data;
-    Function function;
-    String nameSpace = "";
-    int times = -1;
-    int type;
-
-    BindFunction(int t, String n, Function f, Object d) {
-      type = t;
-      function = f;
-      data = d;
-      if (n!=null) {
-        nameSpace = n;
-      }
-    }
-
-    BindFunction(int t, String n, Function f, Object d, int times) {
-      this(t, n, f, d);
-      this.times = times;
-    }
-
-    public boolean fire(Event event) {
-      if (times != 0) {
-        times--;
-        return function.f(event, data);
-      }
-      return true;
-    }
-
-    public boolean hasEventType(int etype) {
-      return (type & etype) == type;
-    }
-  }
-  // Gwt Events class has not this event defined
-  public static int ONSUBMIT = 0x08000;
-
-  public static EventsListener getInstance(Element e) {
-    EventsListener ret = getGQueryEventLinstener(e);
-    return ret != null ? ret : new EventsListener(e);
-  }
-
-  private static native EventsListener getGQueryEventLinstener(Element elem) /*-{
-    return elem.__gqueryevent;
-  }-*/;
-
-  private static native EventListener getOriginalEventListener(Element elem) /*-{
-    return elem.__listener;
-  }-*/;
-  
-  private static native void setGQueryEventListener(Element elem,
-      EventsListener gqevent) /*-{
-    elem.__gqueryevent = gqevent;
-  }-*/;
-
-  // Gwt does't handle submit events in DOM.sinkEvents
-  private static native void sinkSubmitEvent(Element elem) /*-{
-    if (elem.__gquerysubmit) return;
-    elem.__gquerysubmit = true;
-    
-    var handle = function(event) {
-      elem.__gqueryevent.@com.google.gwt.query.client.plugins.EventsListener::dispatchEvent(Lcom/google/gwt/user/client/Event;)(event);
-    };
-    
-    if (elem.addEventListener)
-      elem.addEventListener("submit", handle, true);
-    else
-      elem.attachEvent("onsubmit", handle);
-  }-*/;
-
-  double lastEvnt=0;
-  int lastType=0;
-  
-
-  private Element element;
-
-  private JsObjectArray<BindFunction> elementEvents = JsObjectArray
-      .createArray().cast();
-
-  private EventListener originalEventListener;
-  
-  private EventsListener(Element element) {
-    this.element = element;
-    originalEventListener = getOriginalEventListener(element);
-    setGQueryEventListener(element, this);
-    DOM.setEventListener((com.google.gwt.user.client.Element) element, this);
-  }
-  
-  public void bind(int eventbits, final Object data, Function...funcs) {
-    bind(eventbits, null, data, funcs);
-  }
-  
-  public void bind(int eventbits, final Object data, final Function function,
-      int times) {
-    bind(eventbits, null, data, function, times);
-  }
-
-  public void bind(int eventbits, String name, final Object data, Function...funcs) {
-    for (Function function: funcs) {
-      bind(eventbits, name, data, function, -1);
-    }
-  }
-  
-  public void bind(int eventbits, String namespace, final Object data, final Function function,
-      int times) {
-    if (function == null) {
-      unbind(eventbits, namespace);
-      return;
-    }
-    
-    if (eventbits == ONSUBMIT) {
-      sinkSubmitEvent(element);
-    } else {
-      if ((eventbits | Event.FOCUSEVENTS) == Event.FOCUSEVENTS && element.getAttribute("tabIndex").length() == 0) {
-        element.setAttribute("tabIndex", "0");
-      }
-      DOM.sinkEvents((com.google.gwt.user.client.Element) element, eventbits
-          | DOM.getEventsSunk((com.google.gwt.user.client.Element) element));
-      
-    }
-    elementEvents.add(new BindFunction(eventbits, namespace, function, data, times));
-  }
-  
-  public void bind(String event, final Object data, Function...funcs) {
-    String nameSpace = event.replaceFirst("^[^\\.]+\\.*(.*)$", "$1");
-    String eventName = event.replaceFirst("^([^\\.]+).*$", "$1");
-    int b = 0;
-    if ("submit".equals(eventName)) {
-      b = ONSUBMIT;
-    } else {
-      b = Event.getTypeInt(eventName);
-    }
-    for (Function function: funcs) {
-      bind(b, nameSpace, data, function, -1);
-    }
-  }
-  
-  public void dispatchEvent(Event event) {
-    int etype = "submit".equalsIgnoreCase(event.getType()) ? ONSUBMIT
-        : DOM.eventGetType(event);
-    for (int i = 0; i < elementEvents.length(); i++) {
-      BindFunction listener = elementEvents.get(i);
-      if (listener.hasEventType(etype)) {
-        if (!listener.fire(event)) {
-          event.stopPropagation();
-          event.preventDefault();
-        }
-      }
-    }
-  }
-  
-  /**
-   * Return the original gwt EventListener associated with
-   * this element, before gquery replaced it to introduce its
-   * own event handler.
-   */
-  public EventListener getOriginalEventListener() {
-    return originalEventListener;
-  }
-  
-  public void onBrowserEvent(Event event) {
-    // Workaround for Issue_20
-    if (lastType == event.getTypeInt()
-        && lastEvnt - Duration.currentTimeMillis() < 10
-        && "body".equalsIgnoreCase(element.getTagName())) {
-      return;
-    }
-    lastEvnt = Duration.currentTimeMillis();
-    lastType = event.getTypeInt();
-
-    // Execute the original Gwt listener
-    if (originalEventListener != null) {
-      originalEventListener.onBrowserEvent(event);
-    }
-    
-    dispatchEvent(event);
-  }
-  
-  public void unbind(int eventbits) {
-    unbind(eventbits, null);
-  }
-  
-  public void unbind(int eventbits, String namespace) {
-    JsObjectArray<BindFunction> newList = JsObjectArray
-        .createArray().cast();
-    for (int i = 0; i < elementEvents.length(); i++) {
-      BindFunction listener = elementEvents.get(i);
-      
-      if (!listener.hasEventType(eventbits) || (namespace != null && namespace.length() != 0 && !listener.nameSpace.equals(namespace))) {
-        newList.add(listener);
-      }
-    }
-    elementEvents = newList;
-  }
-  
-  public void unbind(String event) {
-    String nameSpace = event.replaceFirst("^[^\\.]+\\.*(.*)$", "$1");
-    String eventName = event.replaceFirst("^([^\\.]+).*$", "$1");
-    int b = 0;
-    if ("submit".equals(eventName)) {
-      b = ONSUBMIT;
-    } else {
-      b = Event.getTypeInt(eventName);
-    }
-    unbind(b, nameSpace);
-  }
-}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/GQueryQueue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/GQueryQueue.java
deleted file mode 100644 (file)
index 0d96f92..0000000
+++ /dev/null
@@ -1,153 +0,0 @@
-/*
- * Copyright 2011, The gwtquery team.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.query.client.plugins;
-
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.query.client.Function;
-import com.google.gwt.query.client.GQuery;
-
-import java.util.LinkedList;
-import java.util.Queue;
-
-/**
- * Class used in plugins which need a queue system.
- */
-public abstract class GQueryQueue<T extends GQueryQueue<?>> extends GQuery {
-  
-  private static final String QUEUE_DATA_PREFIX = "GQueryQueue_";
-
-  protected GQueryQueue(GQuery gq) {
-    super(gq);
-  }
-
-  /**
-   * Removes a queued function from the front of the queue and executes it.
-   */
-  @SuppressWarnings("unchecked")
-  public T dequeue() {
-    for (Element e : elements()) {
-      dequeueCurrentAndRunNext(e);
-    }
-    return (T)this;
-  }
-
-  /**
-   * Adds a new function, to be executed, onto the end of the queue of all
-   * matched elements.
-   */
-  @SuppressWarnings("unchecked")
-  public T queue(Function func) {
-    for (Element e : elements()) {
-      queue(e, func);
-    }
-    return (T)this;
-  }
-
-  /**
-   * Replaces the current queue with the given queue on all matched elements.
-   */
-  @SuppressWarnings("unchecked")
-  public T queue(Queue<?> queue) {
-    for (Element e : elements()) {
-      replacequeue(e, queue);
-    }
-    return (T)this;
-  }
-  
-  /**
-   * Stop the function which is currently in execution, remove it
-   * from the queue and start the next one.  
-   */
-  public T stop() {
-    return stop(false);
-  }
-  
-  /**
-   * Stop the function which is currently in execution and depending
-   * on the value of the parameter:
-   * - remove it from the queue and start the next one.
-   * - or remove all functions in the queue.  
-   */
-  @SuppressWarnings("unchecked")
-  public T stop(boolean clearQueue) {
-    for (Element e : elements()) {
-      stop(e, clearQueue);
-    }
-    return (T)this;
-  }
-
-  protected String getQueueType() {
-    return QUEUE_DATA_PREFIX + this.getClass().getName(); 
-  }
-
-  private void dequeueCurrentAndRunNext(Element elem) {
-    Queue<?> q = queue(elem, null);
-    if (q != null) {
-      // Remove current function
-      q.poll();
-      // Run the next in the queue
-      Object f = q.peek();
-      if (f != null) {
-        if (f instanceof Function) {
-          ((Function) f).f(elem);
-        }
-      }
-    }
-  }
-  
-  @SuppressWarnings("unchecked")
-  private <S> Queue<S> queue(Element elem, S func) {
-    if (elem != null) {
-      Queue<S> q = (Queue<S>) data(elem, getQueueType(), null);
-      if (q == null) {
-        q = (Queue<S>) data(elem, getQueueType(), new LinkedList<S>());
-      }
-      if (func != null) {
-        q.add(func);
-      }
-      if (q.size() == 1 && func != null) {
-        if (func instanceof Function) {
-          ((Function) func).f(elem);
-        }
-      }
-      return q;
-    }
-    return null;
-  }
-
-  private void replacequeue(Element elem, Queue<?> queue) {
-    if (elem != null) {
-      data(elem, getQueueType(), queue);
-    }
-  }
-  
-  private void stop(Element elem, boolean clear) {
-    Queue<?> q = queue(elem, null);
-    if (q != null) {
-      Object f = q.peek();
-      if (f != null) {
-        if (f instanceof Function) {
-          ((Function) f).cancel(elem);
-        }
-      }
-      if (clear) {
-        q.clear();
-      } else {
-        dequeueCurrentAndRunNext(elem);
-      }
-    }
-  }
-}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/GQueryUi.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/GQueryUi.java
deleted file mode 100755 (executable)
index 2cfa32a..0000000
+++ /dev/null
@@ -1,249 +0,0 @@
-/*
- * Copyright 2011, The gwtquery team.
- * 
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not
- * use this file except in compliance with the License. You may obtain a copy of
- * the License at
- * 
- * http://www.apache.org/licenses/LICENSE-2.0
- * 
- * Unless required by applicable law or agreed to in writing, software
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
- * License for the specific language governing permissions and limitations under
- * the License.
- */
-package com.google.gwt.query.client.plugins;
-
-import com.google.gwt.core.client.GWT;
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.event.shared.GwtEvent;
-import com.google.gwt.event.shared.HasHandlers;
-import com.google.gwt.query.client.Function;
-import com.google.gwt.query.client.GQuery;
-import com.google.gwt.query.client.Predicate;
-
-/**
- * GWT clone of jQueryUi-core. This class define some function present in the
- * jQuery-ui core and not directly in jQuery
- * 
- */
-public class GQueryUi extends GQuery {
-
-  /**
-   * A POJO used to store dimension of an element
-   * 
-   */
-  public static class Dimension {
-    private int height = 0;
-    private int width = 0;
-
-    public Dimension(Element e) {
-      width = e.getOffsetWidth();
-      height = e.getOffsetHeight();
-    }
-
-    public Dimension(int width, int height) {
-      this.width = width;
-      this.height = height;
-    }
-
-    /**
-     * return the height value.
-     */
-    public int getHeight() {
-      return height;
-    }
-
-    /**
-     * return the width value
-     */
-    public int getWidth() {
-      return width;
-    }
-  }
-
-  /**
-   * This object allows you to have a full copy of the original Event and
-   * implements some useful method of the jQuery event model. This is also
-   * useful in Internet Explorer because it use the same javascript object to
-   * fire MouseDownEvent, MouseMoveEvent or MouseStopEvent on the same element.
-   * So, we cannot keep a copy of the MouseDownEvent during a dragginf for
-   * example. Now we can !
-   * 
-   * TOBEFIXED : the method preventDefault() must be called directly on the
-   * original event
-   *
-   * 
-   */
-  public static class Event extends com.google.gwt.user.client.Event {
-
-    /**
-     * Create a new {@link Event} by copying the <code>originalEvent</code>.
-     */
-    public static Event create(com.google.gwt.user.client.Event originalEvent) {
-      Event gQueryEvent = createObject().cast();
-      copy(originalEvent, gQueryEvent);
-      return gQueryEvent;
-    }
-
-    private static native void copy(
-        com.google.gwt.user.client.Event originalEvent, Event gQueryEvent) /*-{
-      for ( var field in originalEvent  ) {
-        gQueryEvent[field] = originalEvent[field];
-      }   
-      gQueryEvent.originalEvent = originalEvent;
-    }-*/;
-
-    protected Event() {
-    }
-
-    /**
-     * Return the original event (the one created by the browser)
-     */
-    public final native com.google.gwt.user.client.Event getOriginalEvent()/*-{
-      return this.originalEvent;
-    }-*/;
-
-    /**
-     * Tell whether ctrl or cmd key is pressed
-     * 
-     */
-    public final boolean isMetaKeyPressed() {
-      return getMetaKey() || getCtrlKey();
-    }
-
-    /**
-     * The mouse position relative to the left edge of the document
-     * 
-     */
-    public final int pageX() {
-      return getClientX() + document.getScrollLeft();
-    }
-
-    /**
-     * The mouse position relative to the top edge of the document.
-     * 
-     */
-    public final int pageY() {
-      return getClientY() + document.getScrollTop();
-    }
-
-  }
-
-  private static class GQueryUiImpl {
-
-    public GQuery scrollParent(final GQueryUi gQueryUi) {
-      GQuery scrollParent;
-
-      if ("fixed".equals(gQueryUi.css("position"))) {
-        return GQuery.$(getViewportElement());
-      }
-
-      if (scrollParentPositionTest(gQueryUi)) {
-        scrollParent = gQueryUi.parents().filter(new Predicate() {
-
-          public boolean f(Element e, int index) {
-            GQuery $e = GQuery.$(e);
-            String position = $e.css("position", true);
-            return ("relative".equals(position) || "absolute".equals(position) || "fixed"
-                .equals(position))
-                && isOverflowEnabled($e);
-          }
-        });
-
-      } else {
-        scrollParent = gQueryUi.parents().filter(new Predicate() {
-
-          public boolean f(Element e, int index) {
-            return isOverflowEnabled(GQuery.$(e));
-          }
-        });
-      }
-      return scrollParent.length() > 0 ? $(scrollParent.get(0))
-          : $(getViewportElement());
-
-    }
-
-    protected boolean scrollParentPositionTest(GQueryUi gQueryUi) {
-      return "absolute".equals(gQueryUi.css("position"));
-    }
-
-    private final Element getViewportElement() {
-      return GQuery.document.isCSS1Compat() ? GQuery.document
-          .getDocumentElement() : GQuery.document.getBody();
-    }
-
-    private boolean isOverflowEnabled(GQuery e) {
-      String overflow = e.css("overflow", true) + e.css("overflow-x", true)
-          + e.css("overflow-y", true);
-      return overflow.contains("auto") || overflow.contains("scroll");
-    }
-
-  }
-
-  @SuppressWarnings("unused")
-  private static class GQueryUiImplTrident extends GQueryUiImpl {
-
-    @Override
-    protected boolean scrollParentPositionTest(GQueryUi gQueryUi) {
-      String position = gQueryUi.css("position");
-      return ("absolute".equals(position) || "relative".equals(position) || "static"
-          .equals(position));
-    }
-
-  }
-
-  public static Class<GQueryUi> GQueryUi = GQueryUi.class;
-
-  // Register the plugin in GQuery
-  static {
-    GQuery.registerPlugin(GQueryUi.class, new Plugin<GQueryUi>() {
-      public GQueryUi init(GQuery gq) {
-        return new GQueryUi(gq);
-      }
-    });
-  }
-
-  /**
-   * Return true if the <code>descendant</code> is a child of the parent. Return false elsewhere.
-   */
-  public static boolean contains(Element parent, Element descendant) {
-    return parent != descendant && parent.isOrHasChild(descendant);
-  }
-
-  protected static void trigger(GwtEvent<?> e, Function callback,
-      Element element, HasHandlers handlerManager) {
-    if (handlerManager != null && e != null) {
-      handlerManager.fireEvent(e);
-    }
-    if (callback != null) {
-      callback.f(element);
-    }
-  }
-
-  protected HasHandlers eventBus;
-
-  private GQueryUiImpl impl = GWT.create(GQueryUiImpl.class);
-
-  protected GQueryUi(GQuery gq) {
-    super(gq);
-  }
-
-
-  /**
-   * Return the immediate scrolling parent.
-   */
-  public GQuery scrollParent() {
-    return impl.scrollParent(this);
-  }
-
-  /**
-   * fire event and call callback function.
-   * 
-   */
-  protected void trigger(GwtEvent<?> e, Function callback, Element element) {
-    trigger(e, callback, element, eventBus);
-  }
-
-}
index 1ec6c53cb4fb4674d66b3ecff29ac79f5fdfc255..d62d037ab9d0a329c4feb22979dbb2e42af9e58d 100644 (file)
 package com.google.gwt.query.client.plugins;
 import com.google.gwt.animation.client.Animation;
 import com.google.gwt.dom.client.Element;
-import com.google.gwt.dom.client.NodeList;
 import com.google.gwt.query.client.Function;
 import com.google.gwt.query.client.GQuery;
-import com.google.gwt.query.client.JSArray;
 import com.google.gwt.query.client.Properties;
-import com.google.gwt.query.client.plugins.ClipAnimation.Action;
-import com.google.gwt.query.client.plugins.ClipAnimation.Direction;
-import com.google.gwt.query.client.plugins.PropertiesAnimation.Easing;
+import com.google.gwt.query.client.plugins.effects.ClipAnimation;
+import com.google.gwt.query.client.plugins.effects.PropertiesAnimation;
+import com.google.gwt.query.client.plugins.effects.ClipAnimation.Action;
+import com.google.gwt.query.client.plugins.effects.ClipAnimation.Direction;
+import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing;
 import com.google.gwt.query.client.LazyBase;
 
 public interface LazyEffects<T> extends LazyBase<T>{
index aea5dc92d9ac017cc360c4e6ed2d803a61bd376f..1b79330793e3b3c900416d4c6712c94d6776697d 100644 (file)
 package com.google.gwt.query.client.plugins;
 import com.google.gwt.dom.client.Element;
 import com.google.gwt.dom.client.NativeEvent;
-import com.google.gwt.dom.client.NodeList;
 import com.google.gwt.query.client.Function;
 import com.google.gwt.query.client.GQuery;
-import com.google.gwt.query.client.JSArray;
+import com.google.gwt.query.client.plugins.events.EventsListener;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.query.client.LazyBase;
 
index ec5f2b44637d8da70c3b64dd5fa12c8f353351da..12df5e3ce1b9f8aa1223e05ddeaec527c5f8624b 100644 (file)
  */
 package com.google.gwt.query.client.plugins;
 import com.google.gwt.dom.client.Element;
-import com.google.gwt.dom.client.NodeList;
 import com.google.gwt.query.client.GQuery;
-import com.google.gwt.query.client.JSArray;
+import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory;
+import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory;
+import com.google.gwt.query.client.plugins.widgets.WidgetFactory;
+import com.google.gwt.query.client.plugins.widgets.WidgetOptions;
+import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory.ButtonOptions;
+import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory.TabPanelOptions;
 import com.google.gwt.user.client.ui.Button;
-import com.google.gwt.user.client.ui.HTML;
-import com.google.gwt.user.client.ui.TextBox;
+import com.google.gwt.user.client.ui.TabPanel;
 import com.google.gwt.user.client.ui.Widget;
+import java.util.ArrayList;
+import java.util.List;
 import com.google.gwt.query.client.LazyBase;
 
 public interface LazyWidgets<T> extends LazyBase<T>{
 
-  <W extends Widget> W widget();
+  /**
+   * Create an return a {@link TabPanel} widget with the first selected
+   * elements. Each div element will create a tab and the first h3 element
+   * inside the div will be used as title
+   */
+  TabPanel tabPanel();
+
+  /**
+   * Create an return a {@link TabPanel} widget with the first selected elements
+   * by using a {@link TabPanelOptions}
+   */
+  TabPanel tabPanel(TabPanelOptions o);
+
+  /**
+   * Create {@link TabPanel} widget for each selected elements. Each div element
+   * will create a tab and the first h3 element inside the div will be used as
+   * title
+   */
+  LazyWidgets<T> tabPanels();
+
+  /**
+   * Create a {@link TabPanel} widget for each selected elements. Each div
+   * element inside a selected element will create a tab and the first h3
+   * element inside the div will be used as title
+   */
+  LazyWidgets<T> tabPanels(TabPanelOptions o);
+
+  /**
+   * Create an return a {@link Button} widget with the first element of the
+   * query
+   */
+  Button button();
+
+  /**
+   * Create and return a {@link Button} widget with the first element of the
+   * query by using a {@link ButtonOptions}
+   */
+  Button button(ButtonOptions o);
+
+  /**
+   * Create a {@link Button} widget for each selected element.
+   * 
+   */
+  LazyWidgets<T> buttons();
+
+  /**
+   * Create a {@link Button} widget for each selected element by using a
+   * {@link ButtonOptions}
+   * 
+   */
+  LazyWidgets<T> buttons(ButtonOptions o);
+
+  /**
+   * Create and return a widget using the given factory and the given options
+   */
+  <W extends Widget, O extends WidgetOptions> W widget( WidgetFactory<W, O> factory, O options);
+
+  /**
+   * Try to create a widget using the given factory and the given options for
+   * each element of the query. Returns a new gquery set of elements with the
+   * new widgets created.
+   */
+  <W extends Widget, O extends WidgetOptions> LazyWidgets<T> widgets( WidgetFactory<W, O> factory, O options);
 
 }
index 69232a891dcf02e534c3dcec3578ed64a221844d..5dee20d5cdcf4275cc5f98337c2970b0f2908773 100755 (executable)
@@ -25,7 +25,7 @@ import com.google.gwt.query.client.GQuery;
  * Base class for all plug-in that need to handle some mouse interactions.\r
  * \r
  */\r
-public abstract class MousePlugin extends GQueryUi {\r
+public abstract class MousePlugin extends UiPlugin {\r
 \r
   private Event mouseDownEvent;\r
   private boolean mouseStarted = false;\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/PropertiesAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/PropertiesAnimation.java
deleted file mode 100755 (executable)
index 0fb91ae..0000000
+++ /dev/null
@@ -1,209 +0,0 @@
-/*\r
- * Copyright 2011, The gwtquery team.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not\r
- * use this file except in compliance with the License. You may obtain a copy of\r
- * the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
- * License for the specific language governing permissions and limitations under\r
- * the License.\r
- */\r
-package com.google.gwt.query.client.plugins;\r
-\r
-import java.util.ArrayList;\r
-\r
-import com.google.gwt.animation.client.Animation;\r
-import com.google.gwt.dom.client.Element;\r
-import com.google.gwt.query.client.Function;\r
-import com.google.gwt.query.client.GQuery;\r
-import com.google.gwt.query.client.JSArray;\r
-import com.google.gwt.query.client.Properties;\r
-import com.google.gwt.query.client.JSRegexp;\r
-\r
-/**\r
- *  Animation effects on any numeric CSS property. \r
- */\r
-public class PropertiesAnimation extends Animation {\r
-\r
-  /**\r
-   * Easing method to use.\r
-   */\r
-  public enum Easing {\r
-    LINEAR, SWING\r
-  }\r
-  \r
-  /**\r
-   * A pojo to store effect values.\r
-   */\r
-  public static class Effect {\r
-
-    public String attr;\r
-    public double end;\r
-    public double start;\r
-    public String unit;\r
-    public String value;\r
-\r
-    Effect(String attr, String value, double start, double end,\r
-        String unit) {\r
-      this.attr = attr;\r
-      this.value = value;\r
-      this.start = start;\r
-      this.end = end;\r
-      this.unit = unit;\r
-    }\r
-\r
-    public String getVal(double progress) {\r
-      double ret = (start + ((end - start) * progress));\r
-      return ("px".equals(unit) ? ((int) ret) : ret) + unit;\r
-    }\r
-    \r
-    public String toString() {\r
-      return ("attr=" + attr + " value=" + value + " start=" + start + " end=" + end + " unit=" + unit).replaceAll("\\.0([^\\d])", "$1");\r
-    }\r
-  }\r
-  \r
-  private static final String[] attrsToSave = new String[] { "overflow",\r
-      "visibility" };\r
-\r
-  private static JSRegexp nonPxRegExp = new JSRegexp(\r
-      "z-?index|font-?weight|opacity|zoom|line-?height", "i");\r
-  \r
-  \r
-  public static Effect computeFxProp(Element e, String key, String val,\r
-      boolean hidden) {\r
-    GQuery g = Effects.$(e);\r
-    String unit = "";\r
-    if ("toggle".equals(val)) {\r
-      val = hidden ? "show" : "hide";\r
-    }\r
-    \r
-    if (("show".equals(val) && !hidden) || ("hide").equals(val) && hidden){\r
-      return null;\r
-    }\r
-    \r
-    if (hidden){\r
-      g.show();\r
-    }\r
-    double start = g.cur(key, true), end = start;\r
-    \r
-    if ("show".equals(val)) {\r
-      g.saveCssAttrs(key);\r
-      start = 0;\r
-      unit = nonPxRegExp.test(key) ? "" : "px";\r
-    } else if ("hide".equals(val)) {\r
-      if (hidden) {\r
-        return null;\r
-      }\r
-      g.saveCssAttrs(key);\r
-      end = 0;\r
-      unit = nonPxRegExp.test(key) ? "" : "px";\r
-    } else {\r
-      JSArray parts = new JSRegexp("^([+-]=)?([0-9+-.]+)(.*)?$").match(val);\r
-\r
-      if (parts != null) {\r
-        unit = nonPxRegExp.test(key) ? "" : parts.getStr(3) == null ? "px"\r
-            : parts.getStr(3);\r
-        end = Double.parseDouble(parts.getStr(2));\r
-        if (!"px".equals(unit)) {\r
-          double to = end == 0 ? 1 : end;\r
-          g.css(key, to + unit);\r
-          start = to * start / g.cur(key, true);\r
-          g.css(key, start + unit);\r
-        }\r
-        if (parts.getStr(1) != null) {\r
-          end = (("-=".equals(parts.getStr(1)) ? -1 : 1) * end) + start;\r
-        }\r
-      }\r
-    }\r
-    \r
-    Effect fx = new Effect(key, val, start, end, unit);\r
-    return fx;\r
-  }\r
-  private Element e;\r
-  private Easing easing = Easing.SWING;\r
-  private ArrayList<Effect> effects = new ArrayList<Effect>();\r
-  private Function[] funcs;\r
-\r
-  private Effects g;\r
-\r
-  private Properties prps;\r
-\r
-  public PropertiesAnimation(Easing easing, Element elem, Properties p,\r
-      Function... funcs) {\r
-    this.easing = easing;\r
-    this.e = elem;\r
-    this.funcs = funcs;\r
-    this.prps = p;\r
-    g = Effects.$(e).as(Effects.Effects);\r
-  }\r
-\r
-  @Override\r
-  public void onCancel() {\r
-    onComplete();\r
-  }\r
-\r
-  @Override\r
-  public void onComplete() {\r
-    super.onComplete();\r
-    for (Effect l : effects) {\r
-      if ("hide".equals(l.value)) {\r
-        g.hide();\r
-        g.restoreCssAttrs(l.attr);\r
-      } else if ("show".equals(l.value)) {\r
-        g.show();\r
-        g.restoreCssAttrs(l.attr);\r
-      }     \r
-    }\r
-    g.restoreCssAttrs(attrsToSave);\r
-    g.each(funcs);\r
-    g.dequeue();\r
-  }\r
-\r
-  @Override\r
-  public void onStart() {\r
-    boolean resize = false;\r
-    boolean move = false;\r
-    boolean hidden = !g.visible();\r
-    Effect fx;\r
-    //g.show();\r
-    for (String key : prps.keys()) {\r
-      String val = prps.get(key);\r
-      if ((fx = computeFxProp(e, key, val, hidden)) != null) {\r
-        effects.add(fx);\r
-        resize = resize || "height".equals(key) || "width".equals(key);\r
-        move = move || "top".equals(key) || "left".equals(key);\r
-      }\r
-    }\r
-    g.saveCssAttrs(attrsToSave);\r
-    if (resize) {\r
-      g.css("overflow", "hidden");\r
-    }\r
-    if (move && !g.css("position", true).matches("absolute|relative")) {\r
-      g.css("position", "relative");    \r
-    }\r
-    g.css("visibility", "visible");\r
-    super.onStart();\r
-  }\r
-\r
-  @Override\r
-  public void onUpdate(double progress) {\r
-    for (Effect fx : effects) {\r
-      g.css(fx.attr, fx.getVal(progress));\r
-    }\r
-  }\r
-\r
-  @Override\r
-  protected double interpolate(double progress) {\r
-    if (easing == Easing.SWING) {\r
-      return super.interpolate(progress);\r
-    } else {\r
-      return progress;\r
-    }\r
-  }\r
-\r
-}\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/QueuePlugin.java
new file mode 100644 (file)
index 0000000..b56fbb7
--- /dev/null
@@ -0,0 +1,153 @@
+/*
+ * Copyright 2011, The gwtquery team.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.client.plugins;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.query.client.Function;
+import com.google.gwt.query.client.GQuery;
+
+import java.util.LinkedList;
+import java.util.Queue;
+
+/**
+ * Class used in plugins which need a queue system.
+ */
+public abstract class QueuePlugin<T extends QueuePlugin<?>> extends GQuery {
+  
+  private static final String QUEUE_DATA_PREFIX = "GQueryQueue_";
+
+  protected QueuePlugin(GQuery gq) {
+    super(gq);
+  }
+
+  /**
+   * Removes a queued function from the front of the queue and executes it.
+   */
+  @SuppressWarnings("unchecked")
+  public T dequeue() {
+    for (Element e : elements()) {
+      dequeueCurrentAndRunNext(e);
+    }
+    return (T)this;
+  }
+
+  /**
+   * Adds a new function, to be executed, onto the end of the queue of all
+   * matched elements.
+   */
+  @SuppressWarnings("unchecked")
+  public T queue(Function func) {
+    for (Element e : elements()) {
+      queue(e, func);
+    }
+    return (T)this;
+  }
+
+  /**
+   * Replaces the current queue with the given queue on all matched elements.
+   */
+  @SuppressWarnings("unchecked")
+  public T queue(Queue<?> queue) {
+    for (Element e : elements()) {
+      replacequeue(e, queue);
+    }
+    return (T)this;
+  }
+  
+  /**
+   * Stop the function which is currently in execution, remove it
+   * from the queue and start the next one.  
+   */
+  public T stop() {
+    return stop(false);
+  }
+  
+  /**
+   * Stop the function which is currently in execution and depending
+   * on the value of the parameter:
+   * - remove it from the queue and start the next one.
+   * - or remove all functions in the queue.  
+   */
+  @SuppressWarnings("unchecked")
+  public T stop(boolean clearQueue) {
+    for (Element e : elements()) {
+      stop(e, clearQueue);
+    }
+    return (T)this;
+  }
+
+  protected String getQueueType() {
+    return QUEUE_DATA_PREFIX + this.getClass().getName(); 
+  }
+
+  private void dequeueCurrentAndRunNext(Element elem) {
+    Queue<?> q = queue(elem, null);
+    if (q != null) {
+      // Remove current function
+      q.poll();
+      // Run the next in the queue
+      Object f = q.peek();
+      if (f != null) {
+        if (f instanceof Function) {
+          ((Function) f).f(elem);
+        }
+      }
+    }
+  }
+  
+  @SuppressWarnings("unchecked")
+  private <S> Queue<S> queue(Element elem, S func) {
+    if (elem != null) {
+      Queue<S> q = (Queue<S>) data(elem, getQueueType(), null);
+      if (q == null) {
+        q = (Queue<S>) data(elem, getQueueType(), new LinkedList<S>());
+      }
+      if (func != null) {
+        q.add(func);
+      }
+      if (q.size() == 1 && func != null) {
+        if (func instanceof Function) {
+          ((Function) func).f(elem);
+        }
+      }
+      return q;
+    }
+    return null;
+  }
+
+  private void replacequeue(Element elem, Queue<?> queue) {
+    if (elem != null) {
+      data(elem, getQueueType(), queue);
+    }
+  }
+  
+  private void stop(Element elem, boolean clear) {
+    Queue<?> q = queue(elem, null);
+    if (q != null) {
+      Object f = q.peek();
+      if (f != null) {
+        if (f instanceof Function) {
+          ((Function) f).cancel(elem);
+        }
+      }
+      if (clear) {
+        q.clear();
+      } else {
+        dequeueCurrentAndRunNext(elem);
+      }
+    }
+  }
+}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/UiPlugin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/UiPlugin.java
new file mode 100755 (executable)
index 0000000..78dc3b1
--- /dev/null
@@ -0,0 +1,249 @@
+/*
+ * Copyright 2011, The gwtquery team.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.client.plugins;
+
+import com.google.gwt.core.client.GWT;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.event.shared.GwtEvent;
+import com.google.gwt.event.shared.HasHandlers;
+import com.google.gwt.query.client.Function;
+import com.google.gwt.query.client.GQuery;
+import com.google.gwt.query.client.Predicate;
+
+/**
+ * GWT clone of jQueryUi-core. This class define some function present in the
+ * jQuery-ui core and not directly in jQuery
+ * 
+ */
+public class UiPlugin extends GQuery {
+
+  /**
+   * A POJO used to store dimension of an element
+   * 
+   */
+  public static class Dimension {
+    private int height = 0;
+    private int width = 0;
+
+    public Dimension(Element e) {
+      width = e.getOffsetWidth();
+      height = e.getOffsetHeight();
+    }
+
+    public Dimension(int width, int height) {
+      this.width = width;
+      this.height = height;
+    }
+
+    /**
+     * return the height value.
+     */
+    public int getHeight() {
+      return height;
+    }
+
+    /**
+     * return the width value
+     */
+    public int getWidth() {
+      return width;
+    }
+  }
+
+  /**
+   * This object allows you to have a full copy of the original Event and
+   * implements some useful method of the jQuery event model. This is also
+   * useful in Internet Explorer because it use the same javascript object to
+   * fire MouseDownEvent, MouseMoveEvent or MouseStopEvent on the same element.
+   * So, we cannot keep a copy of the MouseDownEvent during a dragginf for
+   * example. Now we can !
+   * 
+   * TOBEFIXED : the method preventDefault() must be called directly on the
+   * original event
+   *
+   * 
+   */
+  public static class Event extends com.google.gwt.user.client.Event {
+
+    /**
+     * Create a new {@link Event} by copying the <code>originalEvent</code>.
+     */
+    public static Event create(com.google.gwt.user.client.Event originalEvent) {
+      Event gQueryEvent = createObject().cast();
+      copy(originalEvent, gQueryEvent);
+      return gQueryEvent;
+    }
+
+    private static native void copy(
+        com.google.gwt.user.client.Event originalEvent, Event gQueryEvent) /*-{
+      for ( var field in originalEvent  ) {
+        gQueryEvent[field] = originalEvent[field];
+      }   
+      gQueryEvent.originalEvent = originalEvent;
+    }-*/;
+
+    protected Event() {
+    }
+
+    /**
+     * Return the original event (the one created by the browser)
+     */
+    public final native com.google.gwt.user.client.Event getOriginalEvent()/*-{
+      return this.originalEvent;
+    }-*/;
+
+    /**
+     * Tell whether ctrl or cmd key is pressed
+     * 
+     */
+    public final boolean isMetaKeyPressed() {
+      return getMetaKey() || getCtrlKey();
+    }
+
+    /**
+     * The mouse position relative to the left edge of the document
+     * 
+     */
+    public final int pageX() {
+      return getClientX() + document.getScrollLeft();
+    }
+
+    /**
+     * The mouse position relative to the top edge of the document.
+     * 
+     */
+    public final int pageY() {
+      return getClientY() + document.getScrollTop();
+    }
+
+  }
+
+  private static class GQueryUiImpl {
+
+    public GQuery scrollParent(final UiPlugin gQueryUi) {
+      GQuery scrollParent;
+
+      if ("fixed".equals(gQueryUi.css("position"))) {
+        return GQuery.$(getViewportElement());
+      }
+
+      if (scrollParentPositionTest(gQueryUi)) {
+        scrollParent = gQueryUi.parents().filter(new Predicate() {
+
+          public boolean f(Element e, int index) {
+            GQuery $e = GQuery.$(e);
+            String position = $e.css("position", true);
+            return ("relative".equals(position) || "absolute".equals(position) || "fixed"
+                .equals(position))
+                && isOverflowEnabled($e);
+          }
+        });
+
+      } else {
+        scrollParent = gQueryUi.parents().filter(new Predicate() {
+
+          public boolean f(Element e, int index) {
+            return isOverflowEnabled(GQuery.$(e));
+          }
+        });
+      }
+      return scrollParent.length() > 0 ? $(scrollParent.get(0))
+          : $(getViewportElement());
+
+    }
+
+    protected boolean scrollParentPositionTest(UiPlugin gQueryUi) {
+      return "absolute".equals(gQueryUi.css("position"));
+    }
+
+    private final Element getViewportElement() {
+      return GQuery.document.isCSS1Compat() ? GQuery.document
+          .getDocumentElement() : GQuery.document.getBody();
+    }
+
+    private boolean isOverflowEnabled(GQuery e) {
+      String overflow = e.css("overflow", true) + e.css("overflow-x", true)
+          + e.css("overflow-y", true);
+      return overflow.contains("auto") || overflow.contains("scroll");
+    }
+
+  }
+
+  @SuppressWarnings("unused")
+  private static class GQueryUiImplTrident extends GQueryUiImpl {
+
+    @Override
+    protected boolean scrollParentPositionTest(UiPlugin gQueryUi) {
+      String position = gQueryUi.css("position");
+      return ("absolute".equals(position) || "relative".equals(position) || "static"
+          .equals(position));
+    }
+
+  }
+
+  public static Class<UiPlugin> GQueryUi = UiPlugin.class;
+
+  // Register the plugin in GQuery
+  static {
+    GQuery.registerPlugin(UiPlugin.class, new Plugin<UiPlugin>() {
+      public UiPlugin init(GQuery gq) {
+        return new UiPlugin(gq);
+      }
+    });
+  }
+
+  /**
+   * Return true if the <code>descendant</code> is a child of the parent. Return false elsewhere.
+   */
+  public static boolean contains(Element parent, Element descendant) {
+    return parent != descendant && parent.isOrHasChild(descendant);
+  }
+
+  protected static void trigger(GwtEvent<?> e, Function callback,
+      Element element, HasHandlers handlerManager) {
+    if (handlerManager != null && e != null) {
+      handlerManager.fireEvent(e);
+    }
+    if (callback != null) {
+      callback.f(element);
+    }
+  }
+
+  protected HasHandlers eventBus;
+
+  private GQueryUiImpl impl = GWT.create(GQueryUiImpl.class);
+
+  protected UiPlugin(GQuery gq) {
+    super(gq);
+  }
+
+
+  /**
+   * Return the immediate scrolling parent.
+   */
+  public GQuery scrollParent() {
+    return impl.scrollParent(this);
+  }
+
+  /**
+   * fire event and call callback function.
+   * 
+   */
+  protected void trigger(GwtEvent<?> e, Function callback, Element element) {
+    trigger(e, callback, element, eventBus);
+  }
+
+}
index 047127a2a7589be7264121f8f6f338f55ae68f52..49848cdb15e260907fa62008d940ce2d52598e45 100755 (executable)
@@ -17,16 +17,25 @@ package com.google.gwt.query.client.plugins;
 \r
 import com.google.gwt.dom.client.Element;\r
 import com.google.gwt.query.client.GQuery;\r
+import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory;\r
+import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory;\r
+import com.google.gwt.query.client.plugins.widgets.WidgetFactory;\r
+import com.google.gwt.query.client.plugins.widgets.WidgetOptions;\r
+import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory.ButtonOptions;\r
+import com.google.gwt.query.client.plugins.widgets.TabPanelWidgetFactory.TabPanelOptions;\r
 import com.google.gwt.user.client.ui.Button;\r
-import com.google.gwt.user.client.ui.HTML;\r
-import com.google.gwt.user.client.ui.TextBox;\r
+import com.google.gwt.user.client.ui.TabPanel;\r
 import com.google.gwt.user.client.ui.Widget;\r
 \r
+import java.util.ArrayList;\r
+import java.util.List;\r
+\r
 /**\r
- *  Widgets plugin for Gwt Query. \r
+ * Widgets plugin for Gwt Query.\r
+ * Be careful, this plugin is still experimental. The api can change in next releases.\r
  */\r
-public class Widgets extends GQueryQueue<Widgets>  {\r
-  \r
+public class Widgets extends QueuePlugin<Widgets> {\r
+\r
   public static final Class<Widgets> Widgets = Widgets.class;\r
 \r
   static {\r
@@ -36,29 +45,107 @@ public class Widgets extends GQueryQueue<Widgets>  {
       }\r
     });\r
   }\r
-  \r
+\r
   protected Widgets(GQuery gq) {\r
     super(gq);\r
   }\r
 \r
-  @SuppressWarnings("unchecked")\r
-  @Override\r
-  // TODO: consider more widgets\r
-  public  <W extends Widget> W widget() {\r
-    Widget w = super.widget();\r
-    if (w == null) {\r
-      Element e = get(0);\r
-      if ("div".equalsIgnoreCase(e.getTagName()) || "span".equalsIgnoreCase(e.getTagName())) {\r
-        w = HTML.wrap(e); \r
-      } else  if ("button".equalsIgnoreCase(e.getTagName())) {\r
-        w = Button.wrap(e);\r
-      } else  if ("text".equalsIgnoreCase(e.getTagName())) {\r
-        w = TextBox.wrap(e);\r
-      } else {\r
-        w = new HTML($(e).toString());\r
-      }\r
+  /**\r
+   * Create an return a {@link TabPanel} widget with the first selected\r
+   * elements. Each div element will create a tab and the first h3 element\r
+   * inside the div will be used as title\r
+   */\r
+  public TabPanel tabPanel() {\r
+    return tabPanel(new TabPanelOptions());\r
+  }\r
+\r
+  /**\r
+   * Create an return a {@link TabPanel} widget with the first selected elements\r
+   * by using a {@link TabPanelOptions}\r
+   */\r
+  public TabPanel tabPanel(TabPanelOptions o) {\r
+    return widget(new TabPanelWidgetFactory(), o);\r
+  }\r
+\r
+  /**\r
+   * Create {@link TabPanel} widget for each selected elements. Each div element\r
+   * will create a tab and the first h3 element inside the div will be used as\r
+   * title\r
+   */\r
+  public Widgets tabPanels() {\r
+    return tabPanels(new TabPanelOptions());\r
+  }\r
+\r
+  /**\r
+   * Create a {@link TabPanel} widget for each selected elements. Each div\r
+   * element inside a selected element will create a tab and the first h3\r
+   * element inside the div will be used as title\r
+   */\r
+  public Widgets tabPanels(TabPanelOptions o) {\r
+    return widgets(new TabPanelWidgetFactory(), o);\r
+  }\r
+\r
+  /**\r
+   * Create an return a {@link Button} widget with the first element of the\r
+   * query\r
+   */\r
+  public Button button() {\r
+    return button(new ButtonOptions());\r
+  }\r
+\r
+  /**\r
+   * Create and return a {@link Button} widget with the first element of the\r
+   * query by using a {@link ButtonOptions}\r
+   */\r
+  public Button button(ButtonOptions o) {\r
+    return widget(new ButtonWidgetFactory(), o);\r
+  }\r
+\r
+  /**\r
+   * Create a {@link Button} widget for each selected element.\r
+   * \r
+   */\r
+  public Widgets buttons() {\r
+    return buttons(new ButtonOptions());\r
+  }\r
+\r
+  /**\r
+   * Create a {@link Button} widget for each selected element by using a\r
+   * {@link ButtonOptions}\r
+   * \r
+   */\r
+  public Widgets buttons(ButtonOptions o) {\r
+    return widgets(new ButtonWidgetFactory(), o);\r
+  }\r
+\r
+  /**\r
+   * Create and return a widget using the given factory and the given options\r
+   */\r
+  public <W extends Widget, O extends WidgetOptions> W widget(\r
+      WidgetFactory<W, O> factory, O options) {\r
+    return widget(get(0), factory, options);\r
+  }\r
+\r
+  /**\r
+   * Try to create a widget using the given factory and the given options for\r
+   * each element of the query. Returns a new gquery set of elements with the\r
+   * new widgets created.\r
+   */\r
+  public <W extends Widget, O extends WidgetOptions> Widgets widgets(\r
+      WidgetFactory<W, O> factory, O options) {\r
+    List<Element> result = new ArrayList<Element>();\r
+    for (Element e : elements()) {\r
+      result.add(widget(e, factory, options).getElement());\r
     }\r
-    return (W)w;\r
+    return $(result).as(Widgets);\r
+  }\r
+\r
+  /**\r
+   * Create and return a widget using the given factory and the given options\r
+   */\r
+  protected <W extends Widget, O extends WidgetOptions> W widget(Element e,\r
+      WidgetFactory<W, O> factory, O options) {\r
+    return factory.create(e, options);\r
   }\r
 \r
 }\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/ClipAnimation.java
new file mode 100755 (executable)
index 0000000..68124c3
--- /dev/null
@@ -0,0 +1,142 @@
+/*\r
+ * Copyright 2011, The gwtquery team.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not\r
+ * use this file except in compliance with the License. You may obtain a copy of\r
+ * the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
+ * License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+package com.google.gwt.query.client.plugins.effects;\r
+\r
+import com.google.gwt.animation.client.Animation;\r
+import com.google.gwt.dom.client.Element;\r
+import com.google.gwt.query.client.Function;\r
+import com.google.gwt.query.client.GQuery;\r
+import com.google.gwt.query.client.plugins.Effects;\r
+\r
+/**\r
+ * Animation wich uses the css clip property to show/hide an element.\r
+ */\r
+public class ClipAnimation extends Animation {\r
+\r
+  /**\r
+   * Type of the effect action.\r
+   */\r
+  public static enum Action {\r
+    HIDE, SHOW, TOGGLE\r
+  }\r
+\r
+  /**\r
+   * Corner from which the effect starts.\r
+   */\r
+  public static enum Corner {\r
+    BOTTOM_LEFT, BOTTOM_RIGHT, CENTER, TOP_LEFT, TOP_RIGHT\r
+  }\r
+\r
+  /**\r
+   * Direction of the effect.\r
+   */\r
+  public static enum Direction {\r
+    BIDIRECTIONAL, HORIZONTAL, VERTICAL\r
+  }\r
+\r
+  private static final String[] attrsToSave = new String[] { "position",\r
+      "overflow", "visibility", "white-space", "top", "left" };\r
+\r
+  Action action;\r
+  Corner corner;\r
+  Direction direction;\r
+  Element e;\r
+  int percent;\r
+  private GQuery back = Effects.$();\r
+  private Function[] funcs;\r
+  private Effects g;\r
+\r
+  public ClipAnimation(Element elem, Action a, Corner c, Direction d,\r
+      final Function... funcs) {\r
+    if  (a == Action.TOGGLE) {\r
+      a = GQuery.$(elem).visible() ? Action.HIDE : Action.SHOW; \r
+    }\r
+    this.action = a;\r
+    this.corner = c;\r
+    this.direction = d;\r
+    this.funcs = funcs;\r
+    e = elem;\r
+    g = GQuery.$(e).as(Effects.Effects);\r
+  }\r
+\r
+  @Override\r
+  public void onCancel() {\r
+    onComplete();\r
+  }\r
+\r
+  @Override\r
+  public void onComplete() {\r
+    super.onComplete();\r
+    if (action == Action.HIDE) {\r
+      g.hide();\r
+    }\r
+    g.restoreCssAttrs(attrsToSave);\r
+    back.remove();\r
+    back = Effects.$();\r
+    g.css("clip", "");\r
+    g.each(funcs);\r
+    g.dequeue();\r
+  }\r
+\r
+  @Override\r
+  public void onStart() {\r
+    g.show();\r
+    g.saveCssAttrs(attrsToSave);\r
+    if (!"absolute".equalsIgnoreCase(g.css("position", true))) {\r
+      g.css("position", "absolute");\r
+      g.css("top", g.offset().top + "px");\r
+      g.css("left", g.offset().left + "px");\r
+      back = back.add(g.before("<div></div>")).prev();\r
+      back.height(g.height());\r
+      back.width(g.width());\r
+    }\r
+    g.css("overflow", "hidden");\r
+    g.css("visivility", "visible");\r
+    super.onStart();\r
+  }\r
+\r
+  @Override\r
+  public void onUpdate(double progress) {\r
+    if (action == Action.HIDE) {\r
+      progress = (1 - progress);\r
+    }\r
+    int top = 0;\r
+    int left = 0;\r
+    int right = g.width();\r
+    int bottom = g.height();\r
+\r
+    if (direction == Direction.VERTICAL || direction == Direction.BIDIRECTIONAL) {\r
+      bottom = (int) (g.height() * progress);\r
+    }\r
+    if (direction == Direction.HORIZONTAL\r
+        || direction == Direction.BIDIRECTIONAL) {\r
+      right = (int) (g.width() * progress);\r
+    }\r
+    if (corner == Corner.CENTER) {\r
+      top = (g.height() - bottom) / 2;\r
+      left = (g.width() - right) / 2;\r
+    } else if (corner == Corner.BOTTOM_LEFT) {\r
+      top = (g.height() - bottom);\r
+    } else if (corner == Corner.TOP_RIGHT) {\r
+      left = (g.width() - right);\r
+    } else if (corner == Corner.BOTTOM_RIGHT) {\r
+      left = (g.width() - right);\r
+      top = (g.height() - bottom);\r
+    }\r
+    String rect = top + "px " + right + "px " + bottom + "px  " + left + "px";\r
+    g.css("clip", "rect(" + rect + ")");\r
+  }\r
+}\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/PropertiesAnimation.java
new file mode 100755 (executable)
index 0000000..7325bbf
--- /dev/null
@@ -0,0 +1,210 @@
+/*\r
+ * Copyright 2011, The gwtquery team.\r
+ * \r
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not\r
+ * use this file except in compliance with the License. You may obtain a copy of\r
+ * the License at\r
+ * \r
+ * http://www.apache.org/licenses/LICENSE-2.0\r
+ * \r
+ * Unless required by applicable law or agreed to in writing, software\r
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
+ * License for the specific language governing permissions and limitations under\r
+ * the License.\r
+ */\r
+package com.google.gwt.query.client.plugins.effects;\r
+\r
+import java.util.ArrayList;\r
+\r
+import com.google.gwt.animation.client.Animation;\r
+import com.google.gwt.dom.client.Element;\r
+import com.google.gwt.query.client.Function;\r
+import com.google.gwt.query.client.GQuery;\r
+import com.google.gwt.query.client.JSArray;\r
+import com.google.gwt.query.client.Properties;\r
+import com.google.gwt.query.client.JSRegexp;\r
+import com.google.gwt.query.client.plugins.Effects;\r
+\r
+/**\r
+ *  Animation effects on any numeric CSS property. \r
+ */\r
+public class PropertiesAnimation extends Animation {\r
+\r
+  /**\r
+   * Easing method to use.\r
+   */\r
+  public enum Easing {\r
+    LINEAR, SWING\r
+  }\r
+  \r
+  /**\r
+   * A pojo to store effect values.\r
+   */\r
+  public static class Effect {\r
+
+    public String attr;\r
+    public double end;\r
+    public double start;\r
+    public String unit;\r
+    public String value;\r
+\r
+    Effect(String attr, String value, double start, double end,\r
+        String unit) {\r
+      this.attr = attr;\r
+      this.value = value;\r
+      this.start = start;\r
+      this.end = end;\r
+      this.unit = unit;\r
+    }\r
+\r
+    public String getVal(double progress) {\r
+      double ret = (start + ((end - start) * progress));\r
+      return ("px".equals(unit) ? ((int) ret) : ret) + unit;\r
+    }\r
+    \r
+    public String toString() {\r
+      return ("attr=" + attr + " value=" + value + " start=" + start + " end=" + end + " unit=" + unit).replaceAll("\\.0([^\\d])", "$1");\r
+    }\r
+  }\r
+  \r
+  private static final String[] attrsToSave = new String[] { "overflow",\r
+      "visibility" };\r
+\r
+  private static JSRegexp nonPxRegExp = new JSRegexp(\r
+      "z-?index|font-?weight|opacity|zoom|line-?height", "i");\r
+  \r
+  \r
+  public static Effect computeFxProp(Element e, String key, String val,\r
+      boolean hidden) {\r
+    GQuery g = Effects.$(e);\r
+    String unit = "";\r
+    if ("toggle".equals(val)) {\r
+      val = hidden ? "show" : "hide";\r
+    }\r
+    \r
+    if (("show".equals(val) && !hidden) || ("hide").equals(val) && hidden){\r
+      return null;\r
+    }\r
+    \r
+    if (hidden){\r
+      g.show();\r
+    }\r
+    double start = g.cur(key, true), end = start;\r
+    \r
+    if ("show".equals(val)) {\r
+      g.saveCssAttrs(key);\r
+      start = 0;\r
+      unit = nonPxRegExp.test(key) ? "" : "px";\r
+    } else if ("hide".equals(val)) {\r
+      if (hidden) {\r
+        return null;\r
+      }\r
+      g.saveCssAttrs(key);\r
+      end = 0;\r
+      unit = nonPxRegExp.test(key) ? "" : "px";\r
+    } else {\r
+      JSArray parts = new JSRegexp("^([+-]=)?([0-9+-.]+)(.*)?$").match(val);\r
+\r
+      if (parts != null) {\r
+        unit = nonPxRegExp.test(key) ? "" : parts.getStr(3) == null ? "px"\r
+            : parts.getStr(3);\r
+        end = Double.parseDouble(parts.getStr(2));\r
+        if (!"px".equals(unit)) {\r
+          double to = end == 0 ? 1 : end;\r
+          g.css(key, to + unit);\r
+          start = to * start / g.cur(key, true);\r
+          g.css(key, start + unit);\r
+        }\r
+        if (parts.getStr(1) != null) {\r
+          end = (("-=".equals(parts.getStr(1)) ? -1 : 1) * end) + start;\r
+        }\r
+      }\r
+    }\r
+    \r
+    Effect fx = new Effect(key, val, start, end, unit);\r
+    return fx;\r
+  }\r
+  private Element e;\r
+  private Easing easing = Easing.SWING;\r
+  private ArrayList<Effect> effects = new ArrayList<Effect>();\r
+  private Function[] funcs;\r
+\r
+  private Effects g;\r
+\r
+  private Properties prps;\r
+\r
+  public PropertiesAnimation(Easing easing, Element elem, Properties p,\r
+      Function... funcs) {\r
+    this.easing = easing;\r
+    this.e = elem;\r
+    this.funcs = funcs;\r
+    this.prps = p;\r
+    g = Effects.$(e).as(Effects.Effects);\r
+  }\r
+\r
+  @Override\r
+  public void onCancel() {\r
+    onComplete();\r
+  }\r
+\r
+  @Override\r
+  public void onComplete() {\r
+    super.onComplete();\r
+    for (Effect l : effects) {\r
+      if ("hide".equals(l.value)) {\r
+        g.hide();\r
+        g.restoreCssAttrs(l.attr);\r
+      } else if ("show".equals(l.value)) {\r
+        g.show();\r
+        g.restoreCssAttrs(l.attr);\r
+      }     \r
+    }\r
+    g.restoreCssAttrs(attrsToSave);\r
+    g.each(funcs);\r
+    g.dequeue();\r
+  }\r
+\r
+  @Override\r
+  public void onStart() {\r
+    boolean resize = false;\r
+    boolean move = false;\r
+    boolean hidden = !g.visible();\r
+    Effect fx;\r
+    //g.show();\r
+    for (String key : prps.keys()) {\r
+      String val = prps.get(key);\r
+      if ((fx = computeFxProp(e, key, val, hidden)) != null) {\r
+        effects.add(fx);\r
+        resize = resize || "height".equals(key) || "width".equals(key);\r
+        move = move || "top".equals(key) || "left".equals(key);\r
+      }\r
+    }\r
+    g.saveCssAttrs(attrsToSave);\r
+    if (resize) {\r
+      g.css("overflow", "hidden");\r
+    }\r
+    if (move && !g.css("position", true).matches("absolute|relative")) {\r
+      g.css("position", "relative");    \r
+    }\r
+    g.css("visibility", "visible");\r
+    super.onStart();\r
+  }\r
+\r
+  @Override\r
+  public void onUpdate(double progress) {\r
+    for (Effect fx : effects) {\r
+      g.css(fx.attr, fx.getVal(progress));\r
+    }\r
+  }\r
+\r
+  @Override\r
+  protected double interpolate(double progress) {\r
+    if (easing == Easing.SWING) {\r
+      return super.interpolate(progress);\r
+    } else {\r
+      return progress;\r
+    }\r
+  }\r
+\r
+}\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/events/EventsListener.java
new file mode 100644 (file)
index 0000000..a40b5b2
--- /dev/null
@@ -0,0 +1,245 @@
+/*
+ * Copyright 2011, The gwtquery team.
+ * 
+ * Licensed under the Apache License, Version 2.0 (the "License"); you may not
+ * use this file except in compliance with the License. You may obtain a copy of
+ * the License at
+ * 
+ * http://www.apache.org/licenses/LICENSE-2.0
+ * 
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT
+ * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the
+ * License for the specific language governing permissions and limitations under
+ * the License.
+ */
+package com.google.gwt.query.client.plugins.events;
+
+import com.google.gwt.core.client.Duration;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.query.client.Function;
+import com.google.gwt.query.client.JsObjectArray;
+import com.google.gwt.user.client.DOM;
+import com.google.gwt.user.client.Event;
+import com.google.gwt.user.client.EventListener;
+
+/**
+ * This class implements an event queue instance for one Element. The queue
+ * instance is configured as the default event listener in GWT.
+ * 
+ * The reference to this queue is stored as a unique variable in the element's
+ * DOM
+ * 
+ * The class takes care of calling the appropriate functions for each browser
+ * event and it also calls sinkEvents method.
+ * 
+ */
+public class EventsListener implements EventListener {
+
+  private static class BindFunction {
+
+    Object data;
+    Function function;
+    String nameSpace = "";
+    int times = -1;
+    int type;
+
+    BindFunction(int t, String n, Function f, Object d) {
+      type = t;
+      function = f;
+      data = d;
+      if (n!=null) {
+        nameSpace = n;
+      }
+    }
+
+    BindFunction(int t, String n, Function f, Object d, int times) {
+      this(t, n, f, d);
+      this.times = times;
+    }
+
+    public boolean fire(Event event) {
+      if (times != 0) {
+        times--;
+        return function.f(event, data);
+      }
+      return true;
+    }
+
+    public boolean hasEventType(int etype) {
+      return (type & etype) == type;
+    }
+  }
+  // Gwt Events class has not this event defined
+  public static int ONSUBMIT = 0x08000;
+
+  public static EventsListener getInstance(Element e) {
+    EventsListener ret = getGQueryEventLinstener(e);
+    return ret != null ? ret : new EventsListener(e);
+  }
+
+  private static native EventsListener getGQueryEventLinstener(Element elem) /*-{
+    return elem.__gqueryevent;
+  }-*/;
+
+  private static native EventListener getOriginalEventListener(Element elem) /*-{
+    return elem.__listener;
+  }-*/;
+  
+  private static native void setGQueryEventListener(Element elem,
+      EventsListener gqevent) /*-{
+    elem.__gqueryevent = gqevent;
+  }-*/;
+
+  // Gwt does't handle submit events in DOM.sinkEvents
+  private static native void sinkSubmitEvent(Element elem) /*-{
+    if (elem.__gquerysubmit) return;
+    elem.__gquerysubmit = true;
+    
+    var handle = function(event) {
+      elem.__gqueryevent.@com.google.gwt.query.client.plugins.events.EventsListener::dispatchEvent(Lcom/google/gwt/user/client/Event;)(event);
+    };
+    
+    if (elem.addEventListener)
+      elem.addEventListener("submit", handle, true);
+    else
+      elem.attachEvent("onsubmit", handle);
+  }-*/;
+
+  double lastEvnt=0;
+  int lastType=0;
+  
+
+  private Element element;
+
+  private JsObjectArray<BindFunction> elementEvents = JsObjectArray
+      .createArray().cast();
+
+  private EventListener originalEventListener;
+  
+  private EventsListener(Element element) {
+    this.element = element;
+    originalEventListener = getOriginalEventListener(element);
+    setGQueryEventListener(element, this);
+    DOM.setEventListener((com.google.gwt.user.client.Element) element, this);
+  }
+  
+  public void bind(int eventbits, final Object data, Function...funcs) {
+    bind(eventbits, null, data, funcs);
+  }
+  
+  public void bind(int eventbits, final Object data, final Function function,
+      int times) {
+    bind(eventbits, null, data, function, times);
+  }
+
+  public void bind(int eventbits, String name, final Object data, Function...funcs) {
+    for (Function function: funcs) {
+      bind(eventbits, name, data, function, -1);
+    }
+  }
+  
+  public void bind(int eventbits, String namespace, final Object data, final Function function,
+      int times) {
+    if (function == null) {
+      unbind(eventbits, namespace);
+      return;
+    }
+    
+    if (eventbits == ONSUBMIT) {
+      sinkSubmitEvent(element);
+    } else {
+      if ((eventbits | Event.FOCUSEVENTS) == Event.FOCUSEVENTS && element.getAttribute("tabIndex").length() == 0) {
+        element.setAttribute("tabIndex", "0");
+      }
+      DOM.sinkEvents((com.google.gwt.user.client.Element) element, eventbits
+          | DOM.getEventsSunk((com.google.gwt.user.client.Element) element));
+      
+    }
+    elementEvents.add(new BindFunction(eventbits, namespace, function, data, times));
+  }
+  
+  public void bind(String event, final Object data, Function...funcs) {
+    String nameSpace = event.replaceFirst("^[^\\.]+\\.*(.*)$", "$1");
+    String eventName = event.replaceFirst("^([^\\.]+).*$", "$1");
+    int b = 0;
+    if ("submit".equals(eventName)) {
+      b = ONSUBMIT;
+    } else {
+      b = Event.getTypeInt(eventName);
+    }
+    for (Function function: funcs) {
+      bind(b, nameSpace, data, function, -1);
+    }
+  }
+  
+  public void dispatchEvent(Event event) {
+    int etype = "submit".equalsIgnoreCase(event.getType()) ? ONSUBMIT
+        : DOM.eventGetType(event);
+    for (int i = 0; i < elementEvents.length(); i++) {
+      BindFunction listener = elementEvents.get(i);
+      if (listener.hasEventType(etype)) {
+        if (!listener.fire(event)) {
+          event.stopPropagation();
+          event.preventDefault();
+        }
+      }
+    }
+  }
+  
+  /**
+   * Return the original gwt EventListener associated with
+   * this element, before gquery replaced it to introduce its
+   * own event handler.
+   */
+  public EventListener getOriginalEventListener() {
+    return originalEventListener;
+  }
+  
+  public void onBrowserEvent(Event event) {
+    // Workaround for Issue_20
+    if (lastType == event.getTypeInt()
+        && lastEvnt - Duration.currentTimeMillis() < 10
+        && "body".equalsIgnoreCase(element.getTagName())) {
+      return;
+    }
+    lastEvnt = Duration.currentTimeMillis();
+    lastType = event.getTypeInt();
+
+    // Execute the original Gwt listener
+    if (originalEventListener != null) {
+      originalEventListener.onBrowserEvent(event);
+    }
+    
+    dispatchEvent(event);
+  }
+  
+  public void unbind(int eventbits) {
+    unbind(eventbits, null);
+  }
+  
+  public void unbind(int eventbits, String namespace) {
+    JsObjectArray<BindFunction> newList = JsObjectArray
+        .createArray().cast();
+    for (int i = 0; i < elementEvents.length(); i++) {
+      BindFunction listener = elementEvents.get(i);
+      
+      if (!listener.hasEventType(eventbits) || (namespace != null && namespace.length() != 0 && !listener.nameSpace.equals(namespace))) {
+        newList.add(listener);
+      }
+    }
+    elementEvents = newList;
+  }
+  
+  public void unbind(String event) {
+    String nameSpace = event.replaceFirst("^[^\\.]+\\.*(.*)$", "$1");
+    String eventName = event.replaceFirst("^([^\\.]+).*$", "$1");
+    int b = 0;
+    if ("submit".equals(eventName)) {
+      b = ONSUBMIT;
+    } else {
+      b = Event.getTypeInt(eventName);
+    }
+    unbind(b, nameSpace);
+  }
+}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/AbstractWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/AbstractWidgetFactory.java
new file mode 100644 (file)
index 0000000..928301e
--- /dev/null
@@ -0,0 +1,49 @@
+package com.google.gwt.query.client.plugins.widgets;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+ * Abstract factory containing useful methods for widget creation
+ * 
+ */
+public abstract class AbstractWidgetFactory<W extends Widget, O extends WidgetOptions>
+    implements WidgetFactory<W, O> {
+
+  public W create(Element e, O options) {
+    W w = createWidget(e);
+
+    initialize(w, options, e);
+
+    return w;
+  }
+
+  protected abstract void initialize(W widget, O options, Element e);
+
+  protected abstract W createWidget(Element e);
+
+  /**
+   * Test if the tag name of the element is one of tag names given in parameter
+   * 
+   * @param tagNames
+   * @return
+   */
+  protected boolean matchesTags(Element e, String... tagNames) {
+
+    assert e != null : "Element cannot be null";
+
+    StringBuilder regExp = new StringBuilder("^(");
+    int tagNameLenght = tagNames != null ? tagNames.length : 0;
+    for (int i = 0; i < tagNameLenght; i++) {
+      regExp.append(tagNames[i].toUpperCase());
+      if (i < tagNameLenght - 1) {
+        regExp.append("|");
+      }
+    }
+    regExp.append(")$");
+
+    return e.getTagName().toUpperCase().matches(regExp.toString());
+
+  }
+
+}
\ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/ButtonWidgetFactory.java
new file mode 100644 (file)
index 0000000..9cafbe2
--- /dev/null
@@ -0,0 +1,73 @@
+package com.google.gwt.query.client.plugins.widgets;
+
+import com.google.gwt.dom.client.ButtonElement;
+import com.google.gwt.dom.client.Document;
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.event.dom.client.ClickHandler;
+import com.google.gwt.user.client.ui.Button;
+
+import java.util.ArrayList;
+import java.util.List;
+
+/**
+ * Factory used to create a {@link Button} widget. A {@link Button} is created
+ * if the element is a <i>button</i>, <i>div></i>, <i>span</i> or <i>a</i>
+ * element (should be extends to other element).
+ */
+public class ButtonWidgetFactory extends
+    AbstractWidgetFactory<Button, ButtonWidgetFactory.ButtonOptions> {
+
+  /**
+   * Options used to initialize new {@link Button}
+   * 
+   */
+  public static class ButtonOptions implements WidgetOptions {
+
+    private List<ClickHandler> clickHandlers;
+
+    public ButtonOptions() {
+      clickHandlers = new ArrayList<ClickHandler>();
+    }
+
+    public void addClickHandler(ClickHandler clickHandler) {
+      clickHandlers.add(clickHandler);
+    }
+
+    public List<ClickHandler> getClickHandlers() {
+      return clickHandlers;
+    }
+  }
+
+  protected void initialize(Button button, ButtonOptions options, Element e) {
+    if (button == null || options == null) {
+      return;
+    }
+
+    for (ClickHandler handler : options.getClickHandlers()) {
+      button.addClickHandler(handler);
+    }
+
+  }
+
+  protected Button createWidget(Element e) {
+
+    if ("button".equalsIgnoreCase(e.getTagName())) {
+      return Button.wrap(e);
+    }
+
+    if (matchesTags(e, "div", "span", "a")) {
+      ButtonElement buttonElement = Document.get().createPushButtonElement();
+      e.getParentElement().insertAfter(buttonElement, e);
+      // detach the original element (can be maybe hidden instead of detach
+      // it?)
+      e.removeFromParent();
+
+      Button b = Button.wrap(buttonElement);
+      b.setHTML(e.getInnerHTML()); // maybe use setText and getInnerText
+
+      return b;
+    }
+
+    return null;
+  }
+}
\ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TabPanelWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/TabPanelWidgetFactory.java
new file mode 100644 (file)
index 0000000..9fafebb
--- /dev/null
@@ -0,0 +1,97 @@
+package com.google.gwt.query.client.plugins.widgets;
+
+import static com.google.gwt.query.client.GQuery.$;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.query.client.GQuery;
+import com.google.gwt.user.client.ui.Button;
+import com.google.gwt.user.client.ui.HTMLPanel;
+import com.google.gwt.user.client.ui.RootPanel;
+import com.google.gwt.user.client.ui.TabPanel;
+
+
+/**
+ * Factory used to create a {@link Button} widget. A {@link Button} is created
+ * if the element is a <i>button</i>, <i>div></i>, <i>span</i> or <i>a</i>
+ * element (should be extends to other element).
+ */
+public class TabPanelWidgetFactory extends
+    AbstractWidgetFactory<TabPanel, TabPanelWidgetFactory.TabPanelOptions> {
+  
+  public static class ExtendedTabPanel extends TabPanel{
+    
+    
+    void attach(){
+      onAttach();
+      RootPanel.detachOnWindowClose(this);
+    }
+  }
+
+  /**
+   * Options used to initialize new {@link Button}
+   * 
+   */
+  public static class TabPanelOptions implements WidgetOptions {
+
+    private String tabSelector;
+    private String titleSelector;
+
+    public TabPanelOptions() {
+      initDefault();
+    }
+
+    public String getTabSelector() {
+      return tabSelector;
+    }
+
+    public String getTitleSelector() {
+      return titleSelector;
+    }
+
+    public void setTabSelector(String contentSelector) {
+      this.tabSelector = contentSelector;
+    }
+
+    public void setTitleSelector(String titleSelector) {
+      this.titleSelector = titleSelector;
+    }
+
+    private void initDefault() {
+      tabSelector = "div";
+      titleSelector = "h3";
+    }
+  }
+
+  protected void initialize(TabPanel tabPanel, TabPanelOptions options,
+      Element e) {
+
+    GQuery tabs = $(options.getTabSelector(), e);
+    GQuery titles = $(options.getTitleSelector(), e);
+
+    for (int i = 0; i < tabs.length(); i++) {
+      Element tab = tabs.get(i);
+      Element title = titles.get(i);
+
+      tabPanel.add(new HTMLPanel(tab.getString()), title != null
+          ? title.getInnerText() : "Tab " + (i + 1));
+      
+      
+
+    }
+    
+    if (tabs.length() > 0){
+      tabPanel.selectTab(0);
+    }
+
+    // the tab panel is initialized, attach it to the dom ;
+    e.getParentElement().insertBefore(tabPanel.getElement(), e);
+    ((ExtendedTabPanel)tabPanel).attach();
+
+    // detach the element as it is replaced by the tab panel !
+    e.removeFromParent();
+  }
+
+  protected TabPanel createWidget(Element e) {
+    return new ExtendedTabPanel();
+  }
+}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetFactory.java
new file mode 100644 (file)
index 0000000..41c23ed
--- /dev/null
@@ -0,0 +1,14 @@
+package com.google.gwt.query.client.plugins.widgets;
+
+import com.google.gwt.dom.client.Element;
+import com.google.gwt.user.client.ui.Widget;
+
+/**
+   * Factory interface
+   * 
+   * @param <W>
+   * @param <O>
+   */
+  public interface WidgetFactory<W extends Widget, O extends WidgetOptions> {
+    public W create(Element e, O options);
+  }
\ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetOptions.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/WidgetOptions.java
new file mode 100644 (file)
index 0000000..31399b3
--- /dev/null
@@ -0,0 +1,10 @@
+package com.google.gwt.query.client.plugins.widgets;
+
+/**
+ * Marker interface for factory options. All options should extend
+ * {@link WidgetOptions}.
+ * 
+ */
+public interface WidgetOptions {
+
+}
\ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/Widgets.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/Widgets.java
deleted file mode 100755 (executable)
index f250b20..0000000
+++ /dev/null
@@ -1,152 +0,0 @@
-/*\r
- * Copyright 2011, The gwtquery team.\r
- * \r
- * Licensed under the Apache License, Version 2.0 (the "License"); you may not\r
- * use this file except in compliance with the License. You may obtain a copy of\r
- * the License at\r
- * \r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * \r
- * Unless required by applicable law or agreed to in writing, software\r
- * distributed under the License is distributed on an "AS IS" BASIS, WITHOUT\r
- * WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the\r
- * License for the specific language governing permissions and limitations under\r
- * the License.\r
- */\r
-package com.google.gwt.query.client.plugins.widgets;\r
-\r
-import com.google.gwt.dom.client.Element;\r
-import com.google.gwt.query.client.GQuery;\r
-import com.google.gwt.query.client.plugins.GQueryQueue;\r
-import com.google.gwt.query.client.plugins.Plugin;\r
-import com.google.gwt.query.client.plugins.widgets.widgetfactory.ButtonWidgetFactory;\r
-import com.google.gwt.query.client.plugins.widgets.widgetfactory.TabPanelWidgetFactory;\r
-import com.google.gwt.query.client.plugins.widgets.widgetfactory.WidgetFactory;\r
-import com.google.gwt.query.client.plugins.widgets.widgetfactory.WidgetOptions;\r
-import com.google.gwt.query.client.plugins.widgets.widgetfactory.ButtonWidgetFactory.ButtonOptions;\r
-import com.google.gwt.query.client.plugins.widgets.widgetfactory.TabPanelWidgetFactory.TabPanelOptions;\r
-import com.google.gwt.user.client.ui.Button;\r
-import com.google.gwt.user.client.ui.TabPanel;\r
-import com.google.gwt.user.client.ui.Widget;\r
-\r
-import java.util.ArrayList;\r
-import java.util.List;\r
-\r
-/**\r
- * Widgets plugin for Gwt Query.\r
- */\r
-public class Widgets extends GQueryQueue<Widgets> {\r
-\r
-  public static final Class<Widgets> Widgets = Widgets.class;\r
-\r
-  static {\r
-    GQuery.registerPlugin(Widgets.class, new Plugin<Widgets>() {\r
-      public Widgets init(GQuery gq) {\r
-        return new Widgets(gq);\r
-      }\r
-    });\r
-  }\r
-\r
-  protected Widgets(GQuery gq) {\r
-    super(gq);\r
-  }\r
-\r
-  /**\r
-   * Create an return a {@link TabPanel} widget with the first selected\r
-   * elements. Each div element will create a tab and the first h3 element\r
-   * inside the div will be used as title\r
-   */\r
-  public TabPanel tabPanel() {\r
-    return tabPanel(new TabPanelOptions());\r
-  }\r
-\r
-  /**\r
-   * Create an return a {@link TabPanel} widget with the first selected elements\r
-   * by using a {@link TabPanelOptions}\r
-   */\r
-  public TabPanel tabPanel(TabPanelOptions o) {\r
-    return widget(new TabPanelWidgetFactory(), o);\r
-  }\r
-\r
-  /**\r
-   * Create {@link TabPanel} widget for each selected elements. Each div element\r
-   * will create a tab and the first h3 element inside the div will be used as\r
-   * title\r
-   */\r
-  public Widgets tabPanels() {\r
-    return tabPanels(new TabPanelOptions());\r
-  }\r
-\r
-  /**\r
-   * Create a {@link TabPanel} widget for each selected elements. Each div\r
-   * element inside a selected element will create a tab and the first h3\r
-   * element inside the div will be used as title\r
-   */\r
-  public Widgets tabPanels(TabPanelOptions o) {\r
-    return widgets(new TabPanelWidgetFactory(), o);\r
-  }\r
-\r
-  /**\r
-   * Create an return a {@link Button} widget with the first element of the\r
-   * query\r
-   */\r
-  public Button button() {\r
-    return button(new ButtonOptions());\r
-  }\r
-\r
-  /**\r
-   * Create and return a {@link Button} widget with the first element of the\r
-   * query by using a {@link ButtonOptions}\r
-   */\r
-  public Button button(ButtonOptions o) {\r
-    return widget(new ButtonWidgetFactory(), o);\r
-  }\r
-\r
-  /**\r
-   * Create a {@link Button} widget for each selected element.\r
-   * \r
-   */\r
-  public Widgets buttons() {\r
-    return buttons(new ButtonOptions());\r
-  }\r
-\r
-  /**\r
-   * Create a {@link Button} widget for each selected element by using a\r
-   * {@link ButtonOptions}\r
-   * \r
-   */\r
-  public Widgets buttons(ButtonOptions o) {\r
-    return widgets(new ButtonWidgetFactory(), o);\r
-  }\r
-\r
-  /**\r
-   * Create and return a widget using the given factory and the given options\r
-   */\r
-  public <W extends Widget, O extends WidgetOptions> W widget(\r
-      WidgetFactory<W, O> factory, O options) {\r
-    return widget(get(0), factory, options);\r
-  }\r
-\r
-  /**\r
-   * Try to create a widget using the given factory and the given options for\r
-   * each element of the query. Returns a new gquery set of elements with the\r
-   * new widgets created.\r
-   */\r
-  public <W extends Widget, O extends WidgetOptions> Widgets widgets(\r
-      WidgetFactory<W, O> factory, O options) {\r
-    List<Element> result = new ArrayList<Element>();\r
-    for (Element e : elements()) {\r
-      result.add(widget(e, factory, options).getElement());\r
-    }\r
-    return $(result).as(Widgets);\r
-  }\r
-\r
-  /**\r
-   * Create and return a widget using the given factory and the given options\r
-   */\r
-  protected <W extends Widget, O extends WidgetOptions> W widget(Element e,\r
-      WidgetFactory<W, O> factory, O options) {\r
-    return factory.create(e, options);\r
-  }\r
-\r
-}\r
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/AbstractWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/AbstractWidgetFactory.java
deleted file mode 100644 (file)
index 7015edc..0000000
+++ /dev/null
@@ -1,49 +0,0 @@
-package com.google.gwt.query.client.plugins.widgets.widgetfactory;
-
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.user.client.ui.Widget;
-
-/**
- * Abstract factory containing useful methods for widget creation
- * 
- */
-public abstract class AbstractWidgetFactory<W extends Widget, O extends WidgetOptions>
-    implements WidgetFactory<W, O> {
-
-  public W create(Element e, O options) {
-    W w = createWidget(e);
-
-    initialize(w, options, e);
-
-    return w;
-  }
-
-  protected abstract void initialize(W widget, O options, Element e);
-
-  protected abstract W createWidget(Element e);
-
-  /**
-   * Test if the tag name of the element is one of tag names given in parameter
-   * 
-   * @param tagNames
-   * @return
-   */
-  protected boolean matchesTags(Element e, String... tagNames) {
-
-    assert e != null : "Element cannot be null";
-
-    StringBuilder regExp = new StringBuilder("^(");
-    int tagNameLenght = tagNames != null ? tagNames.length : 0;
-    for (int i = 0; i < tagNameLenght; i++) {
-      regExp.append(tagNames[i].toUpperCase());
-      if (i < tagNameLenght - 1) {
-        regExp.append("|");
-      }
-    }
-    regExp.append(")$");
-
-    return e.getTagName().toUpperCase().matches(regExp.toString());
-
-  }
-
-}
\ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/ButtonWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/ButtonWidgetFactory.java
deleted file mode 100644 (file)
index c85af1e..0000000
+++ /dev/null
@@ -1,73 +0,0 @@
-package com.google.gwt.query.client.plugins.widgets.widgetfactory;
-
-import com.google.gwt.dom.client.ButtonElement;
-import com.google.gwt.dom.client.Document;
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.event.dom.client.ClickHandler;
-import com.google.gwt.user.client.ui.Button;
-
-import java.util.ArrayList;
-import java.util.List;
-
-/**
- * Factory used to create a {@link Button} widget. A {@link Button} is created
- * if the element is a <i>button</i>, <i>div></i>, <i>span</i> or <i>a</i>
- * element (should be extends to other element).
- */
-public class ButtonWidgetFactory extends
-    AbstractWidgetFactory<Button, ButtonWidgetFactory.ButtonOptions> {
-
-  /**
-   * Options used to initialize new {@link Button}
-   * 
-   */
-  public static class ButtonOptions implements WidgetOptions {
-
-    private List<ClickHandler> clickHandlers;
-
-    public ButtonOptions() {
-      clickHandlers = new ArrayList<ClickHandler>();
-    }
-
-    public void addClickHandler(ClickHandler clickHandler) {
-      clickHandlers.add(clickHandler);
-    }
-
-    public List<ClickHandler> getClickHandlers() {
-      return clickHandlers;
-    }
-  }
-
-  protected void initialize(Button button, ButtonOptions options, Element e) {
-    if (button == null || options == null) {
-      return;
-    }
-
-    for (ClickHandler handler : options.getClickHandlers()) {
-      button.addClickHandler(handler);
-    }
-
-  }
-
-  protected Button createWidget(Element e) {
-
-    if ("button".equalsIgnoreCase(e.getTagName())) {
-      return Button.wrap(e);
-    }
-
-    if (matchesTags(e, "div", "span", "a")) {
-      ButtonElement buttonElement = Document.get().createPushButtonElement();
-      e.getParentElement().insertAfter(buttonElement, e);
-      // detach the original element (can be maybe hidden instead of detach
-      // it?)
-      e.removeFromParent();
-
-      Button b = Button.wrap(buttonElement);
-      b.setHTML(e.getInnerHTML()); // maybe use setText and getInnerText
-
-      return b;
-    }
-
-    return null;
-  }
-}
\ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/TabPanelWidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/TabPanelWidgetFactory.java
deleted file mode 100644 (file)
index 18ff912..0000000
+++ /dev/null
@@ -1,97 +0,0 @@
-package com.google.gwt.query.client.plugins.widgets.widgetfactory;
-
-import static com.google.gwt.query.client.GQuery.$;
-
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.query.client.GQuery;
-import com.google.gwt.user.client.ui.Button;
-import com.google.gwt.user.client.ui.HTMLPanel;
-import com.google.gwt.user.client.ui.RootPanel;
-import com.google.gwt.user.client.ui.TabPanel;
-
-
-/**
- * Factory used to create a {@link Button} widget. A {@link Button} is created
- * if the element is a <i>button</i>, <i>div></i>, <i>span</i> or <i>a</i>
- * element (should be extends to other element).
- */
-public class TabPanelWidgetFactory extends
-    AbstractWidgetFactory<TabPanel, TabPanelWidgetFactory.TabPanelOptions> {
-  
-  public static class ExtendedTabPanel extends TabPanel{
-    
-    
-    void attach(){
-      onAttach();
-      RootPanel.detachOnWindowClose(this);
-    }
-  }
-
-  /**
-   * Options used to initialize new {@link Button}
-   * 
-   */
-  public static class TabPanelOptions implements WidgetOptions {
-
-    private String tabSelector;
-    private String titleSelector;
-
-    public TabPanelOptions() {
-      initDefault();
-    }
-
-    public String getTabSelector() {
-      return tabSelector;
-    }
-
-    public String getTitleSelector() {
-      return titleSelector;
-    }
-
-    public void setTabSelector(String contentSelector) {
-      this.tabSelector = contentSelector;
-    }
-
-    public void setTitleSelector(String titleSelector) {
-      this.titleSelector = titleSelector;
-    }
-
-    private void initDefault() {
-      tabSelector = "div";
-      titleSelector = "h3";
-    }
-  }
-
-  protected void initialize(TabPanel tabPanel, TabPanelOptions options,
-      Element e) {
-
-    GQuery tabs = $(options.getTabSelector(), e);
-    GQuery titles = $(options.getTitleSelector(), e);
-
-    for (int i = 0; i < tabs.length(); i++) {
-      Element tab = tabs.get(i);
-      Element title = titles.get(i);
-
-      tabPanel.add(new HTMLPanel(tab.getString()), title != null
-          ? title.getInnerText() : "Tab " + (i + 1));
-      
-      
-
-    }
-    
-    if (tabs.length() > 0){
-      tabPanel.selectTab(0);
-    }
-
-    // the tab panel is initialized, attach it to the dom ;
-    e.getParentElement().insertBefore(tabPanel.getElement(), e);
-    ((ExtendedTabPanel)tabPanel).attach();
-
-    // detach the element as it is replaced by the tab panel !
-    e.removeFromParent();
-  }
-
-  protected TabPanel createWidget(Element e) {
-    return new ExtendedTabPanel();
-  }
-}
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/WidgetFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/WidgetFactory.java
deleted file mode 100644 (file)
index 25723d3..0000000
+++ /dev/null
@@ -1,14 +0,0 @@
-package com.google.gwt.query.client.plugins.widgets.widgetfactory;
-
-import com.google.gwt.dom.client.Element;
-import com.google.gwt.user.client.ui.Widget;
-
-/**
-   * Factory interface
-   * 
-   * @param <W>
-   * @param <O>
-   */
-  public interface WidgetFactory<W extends Widget, O extends WidgetOptions> {
-    public W create(Element e, O options);
-  }
\ No newline at end of file
diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/WidgetOptions.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/widgets/widgetfactory/WidgetOptions.java
deleted file mode 100644 (file)
index b268d93..0000000
+++ /dev/null
@@ -1,10 +0,0 @@
-package com.google.gwt.query.client.plugins.widgets.widgetfactory;
-
-/**
- * Marker interface for factory options. All options should extend
- * {@link WidgetOptions}.
- * 
- */
-public interface WidgetOptions {
-
-}
\ No newline at end of file
index 247f95125e3c0b6420045fed15e92e945043a72e..a120eb70c449556191b32637ff3619b61c70099a 100644 (file)
@@ -22,8 +22,8 @@ import com.google.gwt.dom.client.Element;
 import com.google.gwt.junit.client.GWTTestCase;
 import com.google.gwt.query.client.GQuery.Offset;
 import com.google.gwt.query.client.plugins.Effects;
-import com.google.gwt.query.client.plugins.PropertiesAnimation;
-import com.google.gwt.query.client.plugins.PropertiesAnimation.Easing;
+import com.google.gwt.query.client.plugins.effects.PropertiesAnimation;
+import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing;
 import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.ui.HTML;
 import com.google.gwt.user.client.ui.RootPanel;
index f6f5c00f26bd49e37512c131872d962765284314..c62323c244bf1fb87843a588f536e5f55dcfad52 100644 (file)
@@ -29,7 +29,7 @@ import com.google.gwt.query.client.css.CSS;
 import com.google.gwt.query.client.css.Length;
 import com.google.gwt.query.client.css.RGBColor;
 import com.google.gwt.query.client.plugins.Events;
-import com.google.gwt.query.client.plugins.EventsListener;
+import com.google.gwt.query.client.plugins.events.EventsListener;
 import com.google.gwt.user.client.Event;
 import com.google.gwt.user.client.Timer;
 import com.google.gwt.user.client.ui.Button;
index e6ffe542b3578c1fb44054bcb3fd5aadb705340a..8f5157ad4b1e547ab31cc4f2b9f0b1413a18fa8d 100644 (file)
@@ -27,7 +27,7 @@ import com.google.gwt.query.client.css.CSS;
 import com.google.gwt.query.client.css.Length;\r
 import com.google.gwt.query.client.css.RGBColor;\r
 import com.google.gwt.query.client.plugins.Effects;\r
-import com.google.gwt.query.client.plugins.PropertiesAnimation.Easing;\r
+import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing;\r
 import com.google.gwt.user.client.Event;\r
 \r
 public class GwtQueryEffectsModule implements EntryPoint {\r
index 8ec6008ae7c9725b5e7fd00c8bc5faa4f5f15b9b..e2bb19dcc3f04b70fb6d6888effa310e27c1a46c 100644 (file)
@@ -16,7 +16,7 @@
 package gwtquery.samples.client;\r
 \r
 import static com.google.gwt.query.client.GQuery.$;\r
-import static com.google.gwt.query.client.plugins.widgets.Widgets.Widgets;\r
+import static com.google.gwt.query.client.plugins.Widgets.Widgets;\r
 \r
 import com.google.gwt.core.client.EntryPoint;\r
 import com.google.gwt.event.dom.client.ClickEvent;\r
@@ -24,13 +24,13 @@ import com.google.gwt.event.dom.client.ClickHandler;
 import com.google.gwt.query.client.Function;\r
 import com.google.gwt.query.client.GQuery;\r
 import com.google.gwt.query.client.css.CSS;\r
-import com.google.gwt.query.client.css.UriValue;\r
 import com.google.gwt.query.client.css.Length;\r
 import com.google.gwt.query.client.css.RGBColor;\r
+import com.google.gwt.query.client.css.UriValue;\r
 import com.google.gwt.query.client.css.BackgroundAttachmentProperty.BackgroundAttachment;\r
 import com.google.gwt.query.client.css.BackgroundPositionProperty.BackgroundPosition;\r
 import com.google.gwt.query.client.css.BackgroundRepeatProperty.BackgroundRepeat;\r
-import com.google.gwt.query.client.plugins.widgets.widgetfactory.ButtonWidgetFactory.ButtonOptions;\r
+import com.google.gwt.query.client.plugins.widgets.ButtonWidgetFactory.ButtonOptions;\r
 import com.google.gwt.user.client.Window;\r
 import com.google.gwt.user.client.ui.Button;\r
 import com.google.gwt.user.client.ui.Label;\r