From b89f4d3fa117bac99aa074d0fdb83b1fa06a72ef Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Sun, 30 May 2010 06:29:54 +0000 Subject: [PATCH] moved especific FX queue methods to Effects class --- .../com/google/gwt/query/client/Effects.java | 128 ++++++++++-------- .../google/gwt/query/client/GQueryQueue.java | 33 +---- 2 files changed, 78 insertions(+), 83 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Effects.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Effects.java index b82baaa0..fd77124a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Effects.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Effects.java @@ -60,17 +60,17 @@ public class Effects extends GQueryQueue { public enum Speed { /** - * 600 millisecond animation. + * 400 millisecond animation. */ - SLOW(600), + DEFAULT(400), /** * 200 millisecond animation. */ FAST(200), /** - * 400 millisecond animation. + * 600 millisecond animation. */ - DEFAULT(400); + SLOW(600); private final int duration; @@ -88,26 +88,26 @@ public class Effects extends GQueryQueue { */ protected class PropFx { - public SpeedOpts opt; - public Element elem; - public String prop; - - private double startTime; + public SpeedOpts opt; - private double start; + public String prop; private double end; - private String unit; - private double now; private double pos; + private double start; + + private double startTime; + private double state; + private String unit; + public double cur(boolean force) { if (elem.getPropertyString(prop) != null && (elem.getStyle() == null || elem.getStyle().getProperty(prop) == null)) { @@ -136,6 +136,13 @@ public class Effects extends GQueryQueue { return animate(genFx("hide", 3), speed, Easing.LINEAR, callback); } + public void show() { + opt.cache.put(prop, elem.getStyle().getProperty(prop)); + opt.show = true; + custom("width".equals(prop) || "height".equals(prop) ? 1 : 0, cur(false)); + $(elem).show(); + } + public Effects show(Speed speed) { return show(speed, null); } @@ -144,13 +151,6 @@ public class Effects extends GQueryQueue { return animate(genFx("show", 3), speed, Easing.LINEAR, callback); } - public void show() { - opt.cache.put(prop, elem.getStyle().getProperty(prop)); - opt.show = true; - custom("width".equals(prop) || "height".equals(prop) ? 1 : 0, cur(false)); - $(elem).show(); - } - public Effects toggle(Speed speed) { return hide(speed, null); } @@ -254,28 +254,28 @@ public class Effects extends GQueryQueue { private class SpeedOpts { - public String display; - - public String overflow; - public Properties curAnim; + public String display; + public boolean hide; + public String overflow; + public boolean show; - private Properties properties; + private GQuery.DataCache cache = DataCache.createObject().cast(); + + private Function complete; private int duration; private Effects.Easing easing; - private Function complete; + private Properties properties; private boolean queue = true; - private GQuery.DataCache cache = DataCache.createObject().cast(); - protected SpeedOpts(int speed, Easing easing, Function complete) { this.complete = complete; this.easing = easing; @@ -378,11 +378,6 @@ public class Effects extends GQueryQueue { super(list); } - public Effects animate(final Properties properties, final Speed speed, - final Easing easing, final Function complete) { - return animate(properties, speed.getDuration(), easing, complete); - } - public Effects animate(final Properties properties, final int speed, final Easing easing, final Function complete) { if (!"false".equals(properties.get("queue"))) { @@ -456,13 +451,17 @@ public class Effects extends GQueryQueue { return this; } + + public Effects animate(final Properties properties, final Speed speed, + final Easing easing, final Function complete) { + return animate(properties, speed.getDuration(), easing, complete); + } + /** - * Fade in all matched elements by adjusting their opacity. Only the opacity - * is adjusted for this animation, meaning that all of the matched elements - * should already have some form of height and width associated with them. + * Removes a queued function from the front of the FX queue and executes it. */ - public Effects fadeIn() { - return fadeIn(Speed.DEFAULT); + public Effects dequeue() { + return (Effects)dequeue("__FX"); } /** @@ -470,8 +469,8 @@ public class Effects extends GQueryQueue { * is adjusted for this animation, meaning that all of the matched elements * should already have some form of height and width associated with them. */ - public Effects fadeIn(Speed speed) { - return fadeIn(speed, null); + public Effects fadeIn() { + return fadeIn(Speed.DEFAULT); } /** @@ -489,8 +488,17 @@ public class Effects extends GQueryQueue { * animation, meaning that all of the matched elements should already have * some form of height and width associated with them. */ - public Effects fadeIn(Speed speed, Function callback) { - return fadeIn(speed.duration, callback); + public Effects fadeIn(int speed, Function callback) { + return animate($$("opacity: \"show\""), speed, Easing.LINEAR, callback); + } + + /** + * Fade in all matched elements by adjusting their opacity. Only the opacity + * is adjusted for this animation, meaning that all of the matched elements + * should already have some form of height and width associated with them. + */ + public Effects fadeIn(Speed speed) { + return fadeIn(speed, null); } /** @@ -499,8 +507,8 @@ public class Effects extends GQueryQueue { * animation, meaning that all of the matched elements should already have * some form of height and width associated with them. */ - public Effects fadeIn(int speed, Function callback) { - return animate($$("opacity: \"show\""), speed, Easing.LINEAR, callback); + public Effects fadeIn(Speed speed, Function callback) { + return fadeIn(speed.duration, callback); } /** @@ -519,17 +527,28 @@ public class Effects extends GQueryQueue { * that all of the matched elements should already have some form of height * and width associated with them. */ - public Effects fadeOut(Speed speed) { + public Effects fadeOut(int speed) { return fadeOut(speed, null); } + /** + * Fade out all matched elements by adjusting their opacity to 0, then setting + * display to "none" and firing an optional callback after completion. Only + * the opacity is adjusted for this animation, meaning that all of the matched + * elements should already have some form of height and width associated with + * them. + */ + public Effects fadeOut(int speed, Function callback) { + return animate($$("opacity: \"hide\""), speed, Easing.LINEAR, callback); + } + /** * Fade out all matched elements by adjusting their opacity to 0, then setting * display to "none". Only the opacity is adjusted for this animation, meaning * that all of the matched elements should already have some form of height * and width associated with them. */ - public Effects fadeOut(int speed) { + public Effects fadeOut(Speed speed) { return fadeOut(speed, null); } @@ -544,17 +563,6 @@ public class Effects extends GQueryQueue { return fadeOut(speed.duration, callback); } - /** - * Fade out all matched elements by adjusting their opacity to 0, then setting - * display to "none" and firing an optional callback after completion. Only - * the opacity is adjusted for this animation, meaning that all of the matched - * elements should already have some form of height and width associated with - * them. - */ - public Effects fadeOut(int speed, Function callback) { - return animate($$("opacity: \"hide\""), speed, Easing.LINEAR, callback); - } - /** * Fade the opacity of all matched elements to a specified opacity. Only the * opacity is adjusted for this animation, meaning that all of the matched @@ -590,6 +598,14 @@ public class Effects extends GQueryQueue { return this; } + /** + * Adds a new function, to be executed, onto the end of the queue of all + * matched elements in the FX queue. + */ + public GQueryQueue queue(Function data) { + return queue("__FX", data); + } + /** * Displays each of the set of matched elements if they are hidden. */ diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQueryQueue.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQueryQueue.java index 23d8d232..f1d8dcd0 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQueryQueue.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQueryQueue.java @@ -63,13 +63,6 @@ public abstract class GQueryQueue extends GQuery { super(list); } - /** - * Removes a queued function from the front of the FX queue and executes it. - */ - public GQuery dequeue() { - return dequeue("__FX"); - } - /** * Removes a queued function from the front of the queue and executes it. */ @@ -80,20 +73,6 @@ public abstract class GQueryQueue extends GQuery { return this; } - /** - * Returns a reference to the FX queue. - */ - public Queue queue() { - return queue(elements.getItem(0), "__FX", null); - } - - /** - * Adds a new function, to be executed, onto the end of the queue of all - * matched elements in the FX queue. - */ - public GQueryQueue queue(Function data) { - return queue("__FX", data); - } /** * Returns a reference to the first element's queue (which is an array of @@ -143,19 +122,19 @@ public abstract class GQueryQueue extends GQuery { private Queue queue(Element elem, String type, Function data) { if (elem != null) { type = type + "queue"; - Queue qq = (Queue) data(elem, type, null); - if (qq == null) { - qq = (Queue) data(elem, type, Queue.newInstance()); + Queue q = (Queue) data(elem, type, null); + if (q == null) { + q = (Queue) data(elem, type, Queue.newInstance()); } if (data != null) { - qq.enqueue(data); + q.enqueue(data); } - if (SelectorEngine.eq(type, "__FXqueue") && qq.length() == 1) { + if (SelectorEngine.eq(type, "__FXqueue") && q.length() == 1) { if (data != null) { data.f(elem); } } - return qq; + return q; } return null; } -- 2.39.5