From cbacf2f2171f1ba276e2d9e094ca34e6fb2f357f Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Fri, 2 Jan 2015 14:04:51 +0100 Subject: [PATCH] Running maven java-formatter plugin to all sources --- .../com/google/gwt/query/client/Browser.java | 8 + .../com/google/gwt/query/client/Function.java | 79 ++-- .../java/com/google/gwt/query/client/GQ.java | 2 +- .../com/google/gwt/query/client/GQuery.java | 78 ++-- .../google/gwt/query/client/IsProperties.java | 2 +- .../google/gwt/query/client/Predicate.java | 4 +- .../google/gwt/query/client/Properties.java | 27 +- .../client/builders/JsonBuilderBase.java | 16 +- .../query/client/builders/JsonFactory.java | 2 + .../query/client/builders/XmlBuilderBase.java | 25 +- .../client/css/BackgroundRepeatProperty.java | 2 +- .../client/impl/AttributeTridentImpl.java | 12 +- .../gwt/query/client/impl/ConsoleBrowser.java | 36 +- .../query/client/impl/DocumentStyleImpl.java | 20 +- .../client/impl/DocumentStyleImplIE.java | 6 +- .../gwt/query/client/impl/SelectorEngine.java | 54 +-- .../client/impl/SelectorEngineCssToXPath.java | 160 ++++---- .../client/impl/SelectorEngineNative.java | 9 +- .../client/impl/SelectorEngineNativeIE8.java | 3 +- .../client/impl/SelectorEngineNativeMin.java | 3 +- .../impl/SelectorEngineNativeMinIE8.java | 3 +- .../impl/research/SelectorEngineJS.java | 86 ++--- .../impl/research/SelectorEngineXPath.java | 17 +- .../google/gwt/query/client/js/JsCache.java | 43 ++- .../com/google/gwt/query/client/js/JsMap.java | 6 +- .../gwt/query/client/js/JsNamedArray.java | 6 +- .../gwt/query/client/js/JsNodeArray.java | 10 +- .../gwt/query/client/js/JsObjectArray.java | 10 +- .../google/gwt/query/client/js/JsRegexp.java | 2 +- .../google/gwt/query/client/js/JsUtils.java | 33 +- .../gwt/query/client/plugins/Effects.java | 9 +- .../gwt/query/client/plugins/Events.java | 15 +- .../gwt/query/client/plugins/LazyEffects.java | 3 +- .../gwt/query/client/plugins/LazyEvents.java | 3 +- .../gwt/query/client/plugins/LazyWidgets.java | 6 +- .../query/client/plugins/MouseOptions.java | 2 +- .../gwt/query/client/plugins/MousePlugin.java | 10 +- .../gwt/query/client/plugins/QueuePlugin.java | 18 +- .../gwt/query/client/plugins/UiPlugin.java | 2 +- .../gwt/query/client/plugins/ajax/Ajax.java | 144 +++++--- .../client/plugins/ajax/AjaxTransportJs.java | 24 +- .../client/plugins/deferred/Callbacks.java | 32 +- .../client/plugins/deferred/Deferred.java | 49 ++- .../plugins/deferred/FunctionDeferred.java | 12 +- .../plugins/deferred/PromiseReqBuilder.java | 10 +- .../deferred/PromiseReqBuilderJSONP.java | 2 +- .../query/client/plugins/effects/Bezier.java | 20 +- .../client/plugins/effects/ClipAnimation.java | 6 +- .../gwt/query/client/plugins/effects/Fx.java | 98 ++--- .../plugins/effects/PropertiesAnimation.java | 148 ++++---- .../plugins/widgets/ButtonWidgetFactory.java | 6 +- .../widgets/TextAreaWidgetFactory.java | 2 +- .../client/plugins/widgets/WidgetsUtils.java | 345 +++++++++--------- .../query/linker/IFrameWithDocTypeLinker.java | 13 +- .../gwt/query/rebind/BrowserGenerator.java | 3 +- .../gwt/query/rebind/JsniBundleGenerator.java | 64 ++-- .../query/rebind/JsonBuilderGenerator.java | 40 +- .../gwt/query/rebind/LazyGenerator.java | 9 +- .../query/rebind/SelectorGeneratorBase.java | 6 +- .../rebind/SelectorGeneratorCssToXPath.java | 5 +- .../rebind/SelectorGeneratorJSOptimal.java | 214 +++++------ .../query/rebind/SelectorGeneratorNative.java | 4 +- .../query/rebind/SelectorGeneratorXPath.java | 24 +- .../gwt/query/rebind/XmlBuilderGenerator.java | 13 +- .../google/gwt/query/vm/AjaxTransportJre.java | 27 +- .../google/gwt/query/vm/CookieManager.java | 22 +- .../google/gwt/query/vm/JsonFactoryJre.java | 78 ++-- .../com/google/gwt/query/vm/ResponseJre.java | 11 +- .../shared/gquery/PromiseRF.java | 2 + 69 files changed, 1229 insertions(+), 1036 deletions(-) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Browser.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Browser.java index 9dcc63ad..e8136e14 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Browser.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Browser.java @@ -75,12 +75,20 @@ public abstract class Browser { public final boolean webkit = isWebkit(); protected abstract boolean isIe6(); + protected abstract boolean isIe8(); + protected abstract boolean isIe9(); + protected abstract boolean isIe10(); + protected abstract boolean isIe11(); + protected abstract boolean isMozilla(); + protected abstract boolean isMsie(); + protected abstract boolean isOpera(); + protected abstract boolean isWebkit(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java index 3f96b17e..063aaf38 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Function.java @@ -54,30 +54,31 @@ public abstract class Function { private String dumpArguments(Object[] arguments, String sep) { StringBuilder b = new StringBuilder(); - for (int i = 0, l = arguments.length; i < l; i++ ) { + for (int i = 0, l = arguments.length; i < l; i++) { b.append("[").append(i).append("]"); Object o = arguments[i]; if (o == null) { b.append(" null"); } else if (o.getClass().isArray()) { - b.append(dumpArguments((Object[])o, sep + " ")); + b.append(dumpArguments((Object[]) o, sep + " ")); } else if (o instanceof JavaScriptObject) { - JavaScriptObject jso = (JavaScriptObject)o; + JavaScriptObject jso = (JavaScriptObject) o; if (JsUtils.isElement(jso)) { b.append("(Element) ").append(jso.toString()); } else { - b.append("(JSO) ").append(jso.cast().toJsonString()); + b.append("(JSO) ").append(jso. cast().toJsonString()); } } else { b.append("(").append(o.getClass().getName()).append(") ").append(o); } - if (i < l-1) b.append(sep); + if (i < l - 1) + b.append(sep); } return b.toString(); } public T getElement() { - return element.cast(); + return element. cast(); } public Function setElement(T e) { @@ -87,7 +88,8 @@ public abstract class Function { public Function setEvent(Event e) { event = e; - element = e != null ? e.getCurrentEventTarget().cast() : null; + element = + e != null ? e.getCurrentEventTarget(). cast() : null; return this; } @@ -115,7 +117,7 @@ public abstract class Function { /** * Set the list of arguments to be passed to the function. */ - public Function setArguments(Object...arguments) { + public Function setArguments(Object... arguments) { this.arguments = arguments; return this; } @@ -145,7 +147,7 @@ public abstract class Function { */ @SuppressWarnings("unchecked") public T getArgumentJSO(int argIdx, int pos) { - return (T)getArgument(argIdx, pos, JavaScriptObject.class); + return (T) getArgument(argIdx, pos, JavaScriptObject.class); } /** @@ -166,9 +168,9 @@ public abstract class Function { * Always returns an array. */ public Object[] getArgumentArray(int idx) { - Object o = idx < 0 ? arguments: getArgument(idx); + Object o = idx < 0 ? arguments : getArgument(idx); if (o != null) { - return o.getClass().isArray() ? (Object[])o : new Object[]{o}; + return o.getClass().isArray() ? (Object[]) o : new Object[] {o}; } else if (idx == 0) { return arguments; } @@ -238,14 +240,14 @@ public abstract class Function { Object[] objs = getArgumentArray(argIdx); Object o = objs.length > pos ? objs[pos] : null; if (o != null && ( - // When type is null we don't safety check - type == null || - // The object is an instance of the type requested - o.getClass() == type || - // Overlay types - type == JavaScriptObject.class && o instanceof JavaScriptObject - )) { - return (T)o; + // When type is null we don't safety check + type == null || + // The object is an instance of the type requested + o.getClass() == type || + // Overlay types + type == JavaScriptObject.class && o instanceof JavaScriptObject + )) { + return (T) o; } return null; } @@ -286,7 +288,7 @@ public abstract class Function { * @deprecated use use setArguments instead. */ @Deprecated - public void setData(Object...arguments) { + public void setData(Object... arguments) { setArguments(arguments); } @@ -315,8 +317,8 @@ public abstract class Function { */ public void cancel(com.google.gwt.dom.client.Element e) { setElement(e); - // This has to be the order of calls - cancel(e.cast()); + // This has to be the order of calls + cancel(e. cast()); } /** @@ -349,7 +351,7 @@ public abstract class Function { setElement(e); setIndex(i); // This has to be the order of calls - return f(e.cast(), i); + return f(e. cast(), i); } /** @@ -364,10 +366,10 @@ public abstract class Function { setElement(e); setIndex(i); Widget w = GQuery.getAssociatedWidget(e); - if (w != null){ + if (w != null) { f(w, i); } else { - f(e.cast()); + f(e. cast()); } return null; } @@ -400,7 +402,7 @@ public abstract class Function { * Override this method for bound callbacks. */ public void f(int i, Object arg) { - f(i, new Object[]{arg}); + f(i, new Object[] {arg}); } /** @@ -410,11 +412,11 @@ public abstract class Function { setIndex(i); setArguments(args); if (args.length == 1 && args[0] instanceof JavaScriptObject) { - if (JsUtils.isElement((JavaScriptObject)args[0])) { - setElement((com.google.gwt.dom.client.Element)args[0]); + if (JsUtils.isElement((JavaScriptObject) args[0])) { + setElement((com.google.gwt.dom.client.Element) args[0]); f(getElement(), i); - } else if (JsUtils.isEvent((JavaScriptObject)args[0])) { - setEvent((Event)args[0]); + } else if (JsUtils.isEvent((JavaScriptObject) args[0])) { + setEvent((Event) args[0]); f(getEvent()); } else { f(); @@ -451,8 +453,8 @@ public abstract class Function { */ public void f(com.google.gwt.dom.client.Element e) { setElement(e); - // This has to be the order of calls - f(e.cast()); + // This has to be the order of calls + f(e. cast()); } /** @@ -462,11 +464,12 @@ public abstract class Function { * @param elem takes a com.google.gwt.user.client.Element */ private boolean loop = false; + @Deprecated public void f(com.google.gwt.user.client.Element e) { setElement(e); Widget w = e != null ? GQuery.getAssociatedWidget(e) : null; - if (w != null){ + if (w != null) { loop = true; f(w); } else { @@ -482,13 +485,13 @@ public abstract class Function { * 'public void f()' or 'public void f(Element e)' to handle these elements and * avoid a runtime exception. */ - public void f(Widget w){ + public void f(Widget w) { setElement(w.getElement()); if (loop) { loop = false; f(); } else { - f(w.getElement().cast()); + f(w.getElement(). cast()); } } @@ -507,7 +510,7 @@ public abstract class Function { * They are intentionally final to avoid override them. */ public final void fe(Object arg) { - fe(new Object[]{arg}); + fe(new Object[] {arg}); } /** @@ -552,12 +555,12 @@ public abstract class Function { public final void fe(com.google.gwt.dom.client.Element elem) { if (GWT.getUncaughtExceptionHandler() != null) { try { - f(elem.cast()); + f(elem. cast()); } catch (Exception e) { GWT.getUncaughtExceptionHandler().onUncaughtException(e); } return; } - f(elem.cast()); + f(elem. cast()); } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java index d8cf76a8..b32fbeb2 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQ.java @@ -129,7 +129,7 @@ public abstract class GQ { // We are running DevMode, so create Js versions of the factories method = gwt.getMethod("create", Class.class); ret = method.invoke(null, - new Object[] {JsonFactory.class}); + new Object[] {JsonFactory.class}); jsonFactory = (JsonFactory) ret; ajaxTransport = new AjaxTransportJs(); return; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java index b51fc831..4f733851 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/GQuery.java @@ -127,12 +127,12 @@ public class GQuery implements Lazy { /** * A Browser object with a set of browser-specific flags. */ - public static final Browser browser = GWT.isClient() ? GWT.create(Browser.class) : null; + public static final Browser browser = GWT.isClient() ? GWT. create(Browser.class) : null; /** * An object with the same methods than window.console. */ - public static final Console console = GWT.isClient() ? GWT.create(Console.class) : null; + public static final Console console = GWT.isClient() ? GWT. create(Console.class) : null; /** * Object to store element data (public so as we can access to it from tests). @@ -172,7 +172,8 @@ public class GQuery implements Lazy { // Sizzle POS regex : usefull in some methods // TODO: Share this static with SelectorEngineSizzle - private static RegExp posRegex = RegExp.compile("^:(nth|eq|gt|lt|first|last|even|odd)(?:\\((\\d*)\\))?(?=[^\\-]|$)$"); + private static RegExp posRegex = RegExp + .compile("^:(nth|eq|gt|lt|first|last|even|odd)(?:\\((\\d*)\\))?(?=[^\\-]|$)$"); /** * Implementation class used for style manipulations. @@ -189,7 +190,8 @@ public class GQuery implements Lazy { /** * The window object. */ - public static final Element window = GWT.isClient() ? ScriptInjector.TOP_WINDOW.cast() : null; + public static final Element window = GWT.isClient() ? ScriptInjector.TOP_WINDOW. cast() + : null; private static Element windowData = null; @@ -249,10 +251,10 @@ public class GQuery implements Lazy { } return JsUtils.isWindow(jso) ? $(jso. cast()) : - JsUtils.isElement(jso) ? $(jso. cast()) : - JsUtils.isEvent(jso) ? $(jso. cast()) : - JsUtils.isNodeList(jso) ? $(jso.> cast()) : - $(jso. cast()); + JsUtils.isElement(jso) ? $(jso. cast()) : + JsUtils.isEvent(jso) ? $(jso. cast()) : + JsUtils.isNodeList(jso) ? $(jso.> cast()) : + $(jso. cast()); } /** @@ -271,24 +273,25 @@ public class GQuery implements Lazy { public static GQuery $(Object o) { if (o != null) { if (o instanceof String) { - return $((String)o); + return $((String) o); } if (o instanceof GQuery) { - return (GQuery)o; + return (GQuery) o; } if (o instanceof Function) { - return $((Function)o); + return $((Function) o); } if (JsUtils.isElement(o)) { - return $(JsUtils.cast(o)); + return $(JsUtils. cast(o)); } if (o instanceof JavaScriptObject) { - return $((JavaScriptObject)o); + return $((JavaScriptObject) o); } if (o instanceof IsWidget) { return $(Arrays.asList(o)); } - console.log("Error: GQuery.$(Object o) could not wrap the type : ", o.getClass().getName(), o); + console + .log("Error: GQuery.$(Object o) could not wrap the type : ", o.getClass().getName(), o); } return $(); } @@ -304,7 +307,7 @@ public class GQuery implements Lazy { if (o instanceof Node) { elms.addNode((Node) o); } else if (o instanceof IsWidget) { - elms.addNode(((IsWidget)o).asWidget().getElement()); + elms.addNode(((IsWidget) o).asWidget().getElement()); } } } @@ -491,8 +494,8 @@ public class GQuery implements Lazy { return // return all nodes added to the wrapper $(n.getChildNodes()) - // detach nodes from their temporary parent - .remove(null, false); + // detach nodes from their temporary parent + .remove(null, false); } /** @@ -690,7 +693,7 @@ public class GQuery implements Lazy { wrapperMap.put("td", trWrapper); wrapperMap.put("th", trWrapper); wrapperMap.put("col", new TagWrapper(2, "", - "
")); + "")); wrapperMap.put("area", new TagWrapper(1, "", "")); } @@ -774,14 +777,12 @@ public class GQuery implements Lazy { return engine; } - private static native void scrollIntoViewImpl(Node n) - /*-{ + private static native void scrollIntoViewImpl(Node n) /*-{ if (n) n.scrollIntoView() }-*/; - private static native void setElementValue(Element e, String value) - /*-{ + private static native void setElementValue(Element e, String value) /*-{ e.value = value; }-*/; @@ -1176,11 +1177,11 @@ public class GQuery implements Lazy { public T as(Class plugin) { // GQuery is not a plugin for itself if (plugin == GQUERY) { - return (T)this; + return (T) this; } else if (plugins != null) { Plugin p = plugins.get(plugin); if (p != null) { - return (T)p.init(this); + return (T) p.init(this); } } throw new RuntimeException("No plugin registered for class " + plugin.getName()); @@ -1704,7 +1705,7 @@ public class GQuery implements Lazy { */ @SuppressWarnings("unchecked") public T data(String name) { - return isEmpty() ? null : (T)data(get(0), name, null); + return isEmpty() ? null : (T) data(get(0), name, null); } /** @@ -2375,9 +2376,7 @@ public class GQuery implements Lazy { return end(); } - private native Element getPreviousSiblingElement(Element elem) - /*-{ - + private native Element getPreviousSiblingElement(Element elem) /*-{ var sib = elem.previousSibling; while (sib && sib.nodeType != 1) sib = sib.previousSibling; @@ -3143,7 +3142,7 @@ public class GQuery implements Lazy { * Set the current coordinates of every element in the set of matched elements, relative to the document. */ public GQuery offset(int top, int left) { - for (Element element : elements()){ + for (Element element : elements()) { GQuery g = $(element); String position = g.css("position", true); @@ -3157,7 +3156,8 @@ public class GQuery implements Lazy { long curTop = 0; long curLeft = 0; - if (("absolute".equals(position) || "fixed".equals(position)) && ("auto".equals(curCSSTop) || "auto".equals(curCSSLeft))) { + if (("absolute".equals(position) || "fixed".equals(position)) + && ("auto".equals(curCSSTop) || "auto".equals(curCSSLeft))) { Offset curPosition = g.position(); curTop = curPosition.top; curLeft = curPosition.left; @@ -3299,7 +3299,7 @@ public class GQuery implements Lazy { return 0; } // height including padding and border - int outerHeight = (int)cur("offsetHeight", true); + int outerHeight = (int) cur("offsetHeight", true); if (includeMargin) { outerHeight += cur("marginTop", true) + cur("marginBottom", true); } @@ -3323,7 +3323,7 @@ public class GQuery implements Lazy { return 0; } // width including padding and border - int outerWidth = (int)cur("offsetWidth", true); + int outerWidth = (int) cur("offsetWidth", true); if (includeMargin) { outerWidth += cur("marginRight", true) + cur("marginLeft", true); } @@ -3374,7 +3374,7 @@ public class GQuery implements Lazy { * including the element matched by the selector. */ public GQuery parentsUntil(final String selector) { - return parentsUntil(new Predicate(){ + return parentsUntil(new Predicate() { @Override public boolean f(T e, int index) { return selector != null && $(e).is(selector); @@ -3654,7 +3654,7 @@ public class GQuery implements Lazy { */ public T prop(String key) { assert key != null : "Key is null"; - return isEmpty() ? null : JsUtils.prop(get(0), key); + return isEmpty() ? null : JsUtils. prop(get(0), key); } /** @@ -3669,7 +3669,7 @@ public class GQuery implements Lazy { */ public T prop(String key, Class clz) { assert key != null : "Key is null"; - return isEmpty() ? null : JsUtils.prop(get(0), key, clz); + return isEmpty() ? null : JsUtils. prop(get(0), key, clz); } /** @@ -3903,7 +3903,7 @@ public class GQuery implements Lazy { */ public GQuery removeProp(String name) { for (Element e : elements) { - e.cast().delete(name); + e. cast().delete(name); } return this; } @@ -4489,9 +4489,9 @@ public class GQuery implements Lazy { elStr = JsUtils.isXML(e) ? JsUtils.XML2String(e) : e.getString(); } catch (Exception e2) { elStr = - "< " + (e == null ? "null" : e.getNodeName()) - + "(gquery, error getting the element string representation: " + e2.getMessage() - + ")/>"; + "< " + (e == null ? "null" : e.getNodeName()) + + "(gquery, error getting the element string representation: " + e2.getMessage() + + ")/>"; } r += (pretty && r.length() > 0 ? "\n " : "") + elStr; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java index e2eff943..95772df2 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/IsProperties.java @@ -80,5 +80,5 @@ public interface IsProperties { * converts a JsonBuilder instance into another JsonBuilder type but * preserving the underlying data object. */ - T as (Class clz); + T as(Class clz); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Predicate.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Predicate.java index 796753ce..55b28e14 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Predicate.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Predicate.java @@ -31,8 +31,8 @@ public class Predicate { * @param index * the element position in the gquery elements array. */ - public boolean f(Element e, int index) { - return f((Object)e, index); + public boolean f(Element e, int index) { + return f((Object) e, index); } public boolean f(T e, int index) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java index d0d899be..52178cfa 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/Properties.java @@ -38,7 +38,8 @@ public class Properties extends JavaScriptObject implements IsProperties { return JsUtils.parseJSON(p); } catch (Exception e) { if (!GWT.isProdMode()) { - System.err.println("Error creating Properties: \n> " + properties + "\n< " + p + "\n" + e.getMessage()); + System.err.println("Error creating Properties: \n> " + properties + "\n< " + p + "\n" + + e.getMessage()); } } } @@ -57,10 +58,10 @@ public class Properties extends JavaScriptObject implements IsProperties { public static String wrapPropertiesString(String s) { String ret = s // .replaceAll("\\s*/\\*[\\s\\S]*?\\*/\\s*", "") // Remove comments - .replaceAll("([:\\)\\(,;}{'\"])\\s+" , "$1") // Remove spaces - .replaceAll("\\s+([:\\)\\(,;}{'\"])" , "$1") // Remove spaces + .replaceAll("([:\\)\\(,;}{'\"])\\s+", "$1") // Remove spaces + .replaceAll("\\s+([:\\)\\(,;}{'\"])", "$1") // Remove spaces .replaceFirst("^[\\(]+(.*)[\\)]+$", "$1") // Remove () - .replaceAll("\\([\"']([^\\)]+)[\"']\\)" , "($1)") // Remove quotes + .replaceAll("\\([\"']([^\\)]+)[\"']\\)", "($1)") // Remove quotes .replaceAll("[;,]+([\\w-\\$]+:|$)", ";$1") // Change comma by semicolon .replaceAll("([^,;])([\\]}])", "$1;$2") // Put control semicolon used below .replaceAll(":\\s*[\"']?([^;\\{\\}\\[\\]\"']*)[\"']?\\s*([;,]+|$)", ":\"$1\";") // put quotes to all values (even empty) @@ -85,7 +86,7 @@ public class Properties extends JavaScriptObject implements IsProperties { } private JsCache c() { - return this.cast(); + return this. cast(); } public final native Properties cloneProps() /*-{ @@ -103,7 +104,7 @@ public class Properties extends JavaScriptObject implements IsProperties { @SuppressWarnings("unchecked") public final T get(Object name) { // Casting because of issue_135 - return (T)c().get(String.valueOf(name)); + return (T) c().get(String.valueOf(name)); } public final boolean getBoolean(Object name) { @@ -118,13 +119,13 @@ public class Properties extends JavaScriptObject implements IsProperties { final Object o = c().get(String.valueOf(name)); if (o != null) { if (o instanceof Function) { - return (Function)o; + return (Function) o; } else if (o instanceof JavaScriptObject) { - Object f = ((JavaScriptObject)o).cast().getObject("__f"); + Object f = ((JavaScriptObject) o). cast().getObject("__f"); if (f != null && f instanceof Function) { return (Function) f; } - return new JsUtils.JsFunction((JavaScriptObject)o); + return new JsUtils.JsFunction((JavaScriptObject) o); } } return null; @@ -149,7 +150,7 @@ public class Properties extends JavaScriptObject implements IsProperties { @SuppressWarnings("unchecked") public final T getJavaScriptObject(Object name) { // Casting because of issue_135 - return (T)c().getJavaScriptObject(String.valueOf(name)); + return (T) c().getJavaScriptObject(String.valueOf(name)); } public final JsArrayMixed getArray(Object name) { @@ -206,14 +207,14 @@ public class Properties extends JavaScriptObject implements IsProperties { return JsUtils.param(JsCache.checkNull(this)); } - public final boolean isEmpty(){ + public final boolean isEmpty() { return c().length() == 0; } public final J load(Object prp) { c().clear(); if (prp instanceof JsCache) { - c().copy((JsCache)prp); + c().copy((JsCache) prp); } return getDataImpl(); } @@ -240,7 +241,7 @@ public class Properties extends JavaScriptObject implements IsProperties { @SuppressWarnings("unchecked") public final J getDataImpl() { - return (J)this; + return (J) this; } public final String getJsonName() { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java index 13bf2344..aadfa656 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonBuilderBase.java @@ -48,19 +48,19 @@ public abstract class JsonBuilderBase> implements J public J load(Object prp) { assert prp == null || prp instanceof JavaScriptObject || prp instanceof String; if (prp != null && prp instanceof String) { - return parse((String)prp); + return parse((String) prp); } if (prp != null) { - p = (Properties)prp; + p = (Properties) prp; } - return (J)this; + return (J) this; } protected void setArrayBase(String n, T[] r) { if (r.length > 0 && r[0] instanceof JsonBuilder) { JsArray a = JavaScriptObject.createArray().cast(); for (T o : r) { - a.push(((JsonBuilder)o).getDataImpl()); + a.push(((JsonBuilder) o). getDataImpl()); } p.set(n, a); } else { @@ -74,12 +74,12 @@ public abstract class JsonBuilderBase> implements J protected T[] getArrayBase(String n, T[] r, Class clazz) { JsObjectArray a = p.getArray(n).cast(); int l = r.length; - for (int i = 0 ; i < l ; i++) { + for (int i = 0; i < l; i++) { Object w = a.get(i); Class c = w.getClass(); do { if (c.equals(clazz)) { - r[i] = (T)w; + r[i] = (T) w; break; } c = c.getSuperclass(); @@ -132,11 +132,11 @@ public abstract class JsonBuilderBase> implements J @SuppressWarnings("unchecked") public T set(Object key, Object val) { if (val instanceof IsProperties) { - p.set(key, ((IsProperties)val).getDataImpl()); + p.set(key, ((IsProperties) val).getDataImpl()); } else { p.set(key, val); } - return (T)this; + return (T) this; } public T as(Class clz) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java index 8e4225c7..4e93b043 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/JsonFactory.java @@ -22,6 +22,8 @@ import com.google.gwt.query.client.IsProperties; */ public interface JsonFactory { T create(Class clz); + IsProperties create(String s); + IsProperties create(); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java index d8327c77..91c43874 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/builders/XmlBuilderBase.java @@ -34,7 +34,7 @@ import java.util.Date; public abstract class XmlBuilderBase> implements XmlBuilder { // TODO empty document - protected GQuery g = $((Element)JsUtils.parseXML("")); + protected GQuery g = $((Element) JsUtils.parseXML("")); public void append(String xml) { g.append(JsUtils.parseXML(xml)); @@ -79,39 +79,40 @@ public abstract class XmlBuilderBase> implements Xml } public double getTextAsNumber() { - String t = g.text().replaceAll("[^\\d\\.\\-]", ""); + String t = g.text().replaceAll("[^\\d\\.\\-]", ""); return t.isEmpty() ? 0 : Double.parseDouble(t); } public Date getTextAsDate() { - String t = g.text().trim(); + String t = g.text().trim(); if (t.matches("\\d+")) { return new Date(Long.parseLong(t)); } else { - return new Date((long)JsDate.parse(t)); + return new Date((long) JsDate.parse(t)); } } public boolean getTextAsBoolean() { - String t = g.text().trim().toLowerCase(); + String t = g.text().trim().toLowerCase(); return !t.matches("^(|false|off|0)$"); } public > T getTextAsEnum(Class clazz) { - String t = g.text().trim(); + String t = g.text().trim(); return Enum.valueOf(clazz, t); } @SuppressWarnings("unchecked") public J load(Object o) { - assert o == null || o instanceof JavaScriptObject && JsUtils.isElement((JavaScriptObject)o) || o instanceof String; + assert o == null || o instanceof JavaScriptObject && JsUtils.isElement((JavaScriptObject) o) + || o instanceof String; if (o != null && o instanceof String) { - return parse((String)o); + return parse((String) o); } if (o != null) { - g=$((Element)o); + g = $((Element) o); } - return (J)this; + return (J) this; } @SuppressWarnings("unchecked") @@ -121,7 +122,7 @@ public abstract class XmlBuilderBase> implements Xml protected void setArrayBase(String n, T[] r) { String v = ""; - for (T t: r) { + for (T t : r) { v += String.valueOf(t); } setBase(n, v); @@ -134,7 +135,7 @@ public abstract class XmlBuilderBase> implements Xml @SuppressWarnings("unchecked") public T setText(String t) { g.text(t); - return (T)this; + return (T) this; } public String toString() { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundRepeatProperty.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundRepeatProperty.java index f7ee0ef8..fb69e7c0 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundRepeatProperty.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/css/BackgroundRepeatProperty.java @@ -47,7 +47,7 @@ public class BackgroundRepeatProperty extends */ REPEAT_Y; - public String getCssName(){ + public String getCssName() { return name().toLowerCase().replace('_', '-'); } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeTridentImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeTridentImpl.java index d8492f29..f12b65aa 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeTridentImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/AttributeTridentImpl.java @@ -70,12 +70,12 @@ public class AttributeTridentImpl extends AttributeImpl { private static native boolean setAttributeNode(Element e, String name, Object value) /*-{ - var attrNode = e.getAttributeNode(name); - if (attrNode) { - attrNode.nodeValue = value; - return true; - } - return false; + var attrNode = e.getAttributeNode(name); + if (attrNode) { + attrNode.nodeValue = value; + return true; + } + return false; }-*/; @Override diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java index f6e65752..22407506 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/ConsoleBrowser.java @@ -47,7 +47,7 @@ public class ConsoleBrowser implements Console { private boolean initialized = false; - public ConsoleIe9(){ + public ConsoleIe9() { init(); } @@ -68,54 +68,72 @@ public class ConsoleBrowser implements Console { super.clear(); } } + @Override public void dir(Object arg) { if (initialized) { super.dir(arg); } } + @Override public void error(JavaScriptObject arg) { if (initialized) { super.error(arg); } } + @Override public void info(JavaScriptObject arg) { if (initialized) { super.info(arg); } } + @Override public void profile(String title) { if (initialized) { super.profile(title); } } + @Override public void profileEnd(String title) { if (initialized) { super.profileEnd(title); } } + @Override public void warn(JavaScriptObject arg) { if (initialized) { super.warn(arg); } } + @Override - public void group(Object arg) {} + public void group(Object arg) { + } + @Override - public void groupCollapsed(Object arg) {} + public void groupCollapsed(Object arg) { + } + @Override - public void groupEnd() {} + public void groupEnd() { + } + @Override - public void time(String title) {} + public void time(String title) { + } + @Override - public void timeStamp(Object arg) {} + public void timeStamp(Object arg) { + } + @Override - public void timeEnd(String title) {} + public void timeEnd(String title) { + } } /** @@ -182,7 +200,9 @@ public class ConsoleBrowser implements Console { private ConsoleImpl impl; public ConsoleBrowser() { - impl = GQuery.browser.ie8? new ConsoleIe8(): GQuery.browser.ie9? new ConsoleIe9(): new ConsoleImpl(); + impl = + GQuery.browser.ie8 ? new ConsoleIe8() : GQuery.browser.ie9 ? new ConsoleIe9() + : new ConsoleImpl(); } @Override diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java index 6847b75f..d7b83337 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImpl.java @@ -31,7 +31,8 @@ import com.google.gwt.user.client.DOM; */ public class DocumentStyleImpl { - private static final RegExp cssNumberRegex = RegExp.compile("^(fillOpacity|fontWeight|lineHeight|opacity|orphans|widows|zIndex|zoom)$", "i"); + private static final RegExp cssNumberRegex = RegExp.compile( + "^(fillOpacity|fontWeight|lineHeight|opacity|orphans|widows|zIndex|zoom)$", "i"); private static final RegExp sizeRegex = RegExp.compile("^(client|offset|)(width|height)$", "i"); /** @@ -121,9 +122,9 @@ public class DocumentStyleImpl { } private Element attachTemporary(Element elem) { - Element lastParent = $(elem).parents().last().get(0); + Element lastParent = $(elem).parents().last().get(0); - if (lastParent == null){ + if (lastParent == null) { // the element itself is detached lastParent = elem; } @@ -167,7 +168,8 @@ public class DocumentStyleImpl { // inline elements do not have width nor height unless we set it to inline-block private void fixInlineElement(Element e) { - if (e.getClientHeight() == 0 && e.getClientWidth() == 0 && "inline".equals(curCSS(e, "display", true))) { + if (e.getClientHeight() == 0 && e.getClientWidth() == 0 + && "inline".equals(curCSS(e, "display", true))) { setStyleProperty(e, "display", "inline-block"); setStyleProperty(e, "width", "auto"); setStyleProperty(e, "height", "auto"); @@ -194,7 +196,8 @@ public class DocumentStyleImpl { public int getHeight(Element e) { fixInlineElement(e); - return (int) (e.getClientHeight() - num(curCSS(e, "paddingTop", true)) - num(curCSS(e, "paddingBottom", true))); + return (int) (e.getClientHeight() - num(curCSS(e, "paddingTop", true)) - num(curCSS(e, + "paddingBottom", true))); } public double getOpacity(Element e) { @@ -204,7 +207,8 @@ public class DocumentStyleImpl { public int getWidth(Element e) { fixInlineElement(e); - return (int) (e.getClientWidth() - num(curCSS(e, "paddingLeft", true)) - num(curCSS(e, "paddingRight", true))); + return (int) (e.getClientWidth() - num(curCSS(e, "paddingLeft", true)) - num(curCSS(e, + "paddingRight", true))); } /** @@ -253,8 +257,8 @@ public class DocumentStyleImpl { protected native String getComputedStyle(Element elem, String hyphenName, String camelName, String pseudo) /*-{ try { - var cStyle = $doc.defaultView.getComputedStyle(elem, pseudo); - return cStyle && cStyle.getPropertyValue ? cStyle.getPropertyValue(hyphenName) : null; + var cStyle = $doc.defaultView.getComputedStyle(elem, pseudo); + return cStyle && cStyle.getPropertyValue ? cStyle.getPropertyValue(hyphenName) : null; } catch(e) {return null;} }-*/; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImplIE.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImplIE.java index 04074656..972e4645 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImplIE.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/DocumentStyleImplIE.java @@ -39,7 +39,8 @@ public class DocumentStyleImplIE extends DocumentStyleImpl { @Override public int getHeight(Element e) { - return (int) (e.getOffsetHeight() - num(curCSS(e, "paddingTop", true)) - num(curCSS(e, "paddingBottom", true)) + return (int) (e.getOffsetHeight() - num(curCSS(e, "paddingTop", true)) + - num(curCSS(e, "paddingBottom", true)) - num(curCSS(e, "borderTopWidth", true)) - num(curCSS(e, "borderBottomWidth", true))); } @@ -55,7 +56,8 @@ public class DocumentStyleImplIE extends DocumentStyleImpl { @Override public int getWidth(Element e) { - return (int) (e.getOffsetWidth() - num(curCSS(e, "paddingLeft", true)) - num(curCSS(e, "paddingRight", true)) + return (int) (e.getOffsetWidth() - num(curCSS(e, "paddingLeft", true)) + - num(curCSS(e, "paddingRight", true)) - num(curCSS(e, "borderRightWidth", true)) - num(curCSS(e, "borderRightWidth", true))); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java index 1266e817..c9bdef5a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngine.java @@ -41,15 +41,15 @@ public class SelectorEngine implements HasSelector { public static native NodeList getElementsByClassName(String clazz, Node ctx) /*-{ - return ctx.getElementsByClassName(clazz); + return ctx.getElementsByClassName(clazz); }-*/; public static native Node getNextSibling(Node n) /*-{ - return n.nextSibling || null; + return n.nextSibling || null; }-*/; public static native Node getPreviousSibling(Node n) /*-{ - return n.previousSibling || null; + return n.previousSibling || null; }-*/; public NodeList querySelectorAll(String selector, Node ctx) { @@ -65,17 +65,17 @@ public class SelectorEngine implements HasSelector { public static native NodeList querySelectorAllImpl(String selector, Node ctx) /*-{ - return ctx.querySelectorAll(selector); + return ctx.querySelectorAll(selector); }-*/; public static native NodeList elementsByTagName(String selector, Node ctx) /*-{ - return ctx.getElementsByTagName(selector); + return ctx.getElementsByTagName(selector); }-*/; public static native NodeList elementsByClassName(String selector, Node ctx) /*-{ - return ctx.getElementsByClassName(selector); + return ctx.getElementsByClassName(selector); }-*/; public static NodeList veryQuickId(String id, Node ctx) { @@ -90,14 +90,14 @@ public class SelectorEngine implements HasSelector { public static native NodeList xpathEvaluate(String selector, Node ctx, JsNodeArray r) /*-{ - var node; - var ownerDoc = ctx && (ctx.ownerDocument || ctx ); - var evalDoc = ownerDoc ? ownerDoc : $doc; - var result = evalDoc.evaluate(selector, ctx, null, 0, null); - while ((node = result.iterateNext())) { - r.push(node); - } - return r; + var node; + var ownerDoc = ctx && (ctx.ownerDocument || ctx ); + var evalDoc = ownerDoc ? ownerDoc : $doc; + var result = evalDoc.evaluate(selector, ctx, null, 0, null); + while ((node = result.iterateNext())) { + r.push(node); + } + return r; }-*/; public final SelectorEngineImpl impl; @@ -117,10 +117,10 @@ public class SelectorEngine implements HasSelector { static { filters = JsMap.create(); - filters.put("visible", new Predicate(){ + filters.put("visible", new Predicate() { public boolean f(Element e, int index) { return (e.getOffsetWidth() + e.getOffsetHeight()) > 0 && - !"none".equalsIgnoreCase(styleImpl.curCSS(e, "display", true)); + !"none".equalsIgnoreCase(styleImpl.curCSS(e, "display", true)); } }); filters.put("hidden", new Predicate() { @@ -133,12 +133,12 @@ public class SelectorEngine implements HasSelector { return e.getPropertyBoolean("selected"); } }); - filters.put("input", new Predicate(){ + filters.put("input", new Predicate() { public boolean f(Element e, int index) { return e.getNodeName().toLowerCase().matches("input|select|textarea|button"); } }); - filters.put("header", new Predicate(){ + filters.put("header", new Predicate() { public boolean f(Element e, int index) { return e.getNodeName().toLowerCase().matches("h\\d"); } @@ -173,7 +173,7 @@ public class SelectorEngine implements HasSelector { public NodeList filter(NodeList nodes, String selector, boolean filterDetached) { JsNodeArray res = JsNodeArray.create(); - if (selector.isEmpty()){ + if (selector.isEmpty()) { return res; } Element ghostParent = null; @@ -181,7 +181,8 @@ public class SelectorEngine implements HasSelector { HashSet elmList = new HashSet(); for (int i = 0, l = nodes.getLength(); i < l; i++) { Node e = nodes.getItem(i); - if (e == window || e == document || e.getNodeName() == null || "html".equalsIgnoreCase(e.getNodeName())) { + if (e == window || e == document || e.getNodeName() == null + || "html".equalsIgnoreCase(e.getNodeName())) { continue; } elmList.add(e); @@ -198,11 +199,11 @@ public class SelectorEngine implements HasSelector { parents.add(p); } } else if (parents.isEmpty()) { - parents.add(document); + parents.add(document); } } for (Node e : parents) { - NodeList n = select(selector, e); + NodeList n = select(selector, e); for (int i = 0, l = n.getLength(); i < l; i++) { Element el = n.getItem(i); if (elmList.remove(el)) { @@ -217,9 +218,12 @@ public class SelectorEngine implements HasSelector { } // pseudo selectors which are computed by gquery in runtime - RegExp gQueryPseudo = RegExp.compile("(.*):((visible|hidden|selected|input|header)|((button|checkbox|file|hidden|image|password|radio|reset|submit|text)\\s*(,|$)))(.*)", "i"); + RegExp gQueryPseudo = + RegExp.compile( + "(.*):((visible|hidden|selected|input|header)|((button|checkbox|file|hidden|image|password|radio|reset|submit|text)\\s*(,|$)))(.*)", "i"); // pseudo selectors which work in engine - RegExp nativePseudo = RegExp.compile("(.*):([\\w]+):(disabled|checked|enabled|empty|focus)\\s*([:,].*|$)", "i"); + RegExp nativePseudo = RegExp.compile( + "(.*):([\\w]+):(disabled|checked|enabled|empty|focus)\\s*([:,].*|$)", "i"); public NodeList select(String selector, Node ctx) { @@ -247,7 +251,7 @@ public class SelectorEngine implements HasSelector { if (pred != null) { nodes = filter(select(select, ctx), pred); } else if (nativePseudo.test(pseudo)) { - nodes = select(select, ctx); + nodes = select(select, ctx); } else { nodes = select(select + "[type=" + pseudo + "]", ctx); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java index 654653e1..7a634c83 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineCssToXPath.java @@ -58,20 +58,22 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { private static ReplaceCallback rc_scp = new ReplaceCallback() { public String foundMatch(ArrayList s) { return s.get(1) + s.get(2) + - (s.get(3).startsWith(" ") ? "%S%" : s.get(3).startsWith("#") ? "%H%" : "%P%") + - s.get(4) + s.get(5); + (s.get(3).startsWith(" ") ? "%S%" : s.get(3).startsWith("#") ? "%H%" : "%P%") + + s.get(4) + s.get(5); } }; private static ReplaceCallback rc_$Attr = new ReplaceCallback() { public String foundMatch(ArrayList s) { - return "[substring(@" + s.get(1) + ",string-length(@" + s.get(1) + ")-" + (s.get(2).replaceAll("'", "").length() - 1) + ")=" + s.get(2) + "]"; + return "[substring(@" + s.get(1) + ",string-length(@" + s.get(1) + ")-" + + (s.get(2).replaceAll("'", "").length() - 1) + ")=" + s.get(2) + "]"; } }; private static ReplaceCallback rc_Not = new ReplaceCallback() { public String foundMatch(ArrayList s) { - return s.get(1) + "[not(" + getInstance().css2Xpath(s.get(2)).replaceAll("^[^\\[]+\\[([^\\]]*)\\].*$", "$1" + ")]"); + return s.get(1) + "[not(" + + getInstance().css2Xpath(s.get(2)).replaceAll("^[^\\[]+\\[([^\\]]*)\\].*$", "$1" + ")]"); } }; @@ -82,7 +84,7 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { boolean afterAttr = "]".equals(s1); String prefix = afterAttr ? s1 : "*"; - boolean noPrefix = afterAttr || s1 == null || s1.length() == 0 ; + boolean noPrefix = afterAttr || s1 == null || s1.length() == 0; if ("n".equals(s2)) { return s1; @@ -95,85 +97,87 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { return prefix + "[(count(preceding-sibling::*) + 1) mod 2=1]"; } - if (!s2.contains("n")){ - return prefix + "[position() = "+s2+"]" + (noPrefix ? "" : "/self::" + s1); + if (!s2.contains("n")) { + return prefix + "[position() = " + s2 + "]" + (noPrefix ? "" : "/self::" + s1); } String[] t = s2.replaceAll("^([0-9]*)n.*?([0-9]*)?$", "$1+$2").split("\\+"); String t0 = t[0]; String t1 = t.length > 1 ? t[1] : "0"; - return prefix + "[(position()-" + t1 + ") mod " + t0 + "=0 and position()>=" + t1 + "]" + (noPrefix ? "" : "/self::" + s1); + return prefix + "[(position()-" + t1 + ") mod " + t0 + "=0 and position()>=" + t1 + "]" + + (noPrefix ? "" : "/self::" + s1); } }; - public static Object[] regs = new Object[]{ - // scape some dots and spaces - "(['\\[])([^'\\]]*)([\\s\\.#])([^'\\]]*)(['\\]])", rc_scp, - // add @ for attrib - "\\[([^@\\]~\\$\\*\\^\\|\\!]+)(=[^\\]]+)?\\]", "[@$1$2]", - // multiple queries - "\\s*,\\s*", "|.//", - // , + ~ > - "\\s*(\\+|~|>)\\s*", "$1", - // * ~ + > - "([\\w\\-\\*])~([\\w\\-\\*])", "$1/following-sibling::$2", - "([\\w\\-\\*])\\+([\\w\\-\\*])", "$1/following-sibling::*[1]/self::$2", - "([\\w\\-\\*])>([\\w\\-\\*])", "$1/$2", - // all unescaped stuff escaped - "\\[([^=]+)=([^'|\"][^\\]]*)\\]", "[$1='$2']", - // all descendant or self to - "(^|[^\\w\\-\\*])(#|\\.)([\\w\\-]+)", "$1*$2$3", - "([\\>\\+\\|\\~\\,\\s])([a-zA-Z\\*]+)", "$1//$2", - "\\s+//", "//", - // :first-child - "([\\w\\-\\*]+):first-child", "*[1]/self::$1", - // :last-child - "([\\w\\-\\*]+):last-child", "$1[not(following-sibling::*)]", - // :only-child - "([\\w\\-\\*]+):only-child", "*[last()=1]/self::$1", - // :empty - "([\\w\\-\\*]+):empty", "$1[not(*) and not(normalize-space())]", - // :odd :even, this is intentional since sizzle behaves so - ":odd" , ":nth-child(even)", - ":even" , ":nth-child(odd)", - // :not - "(.+):not\\(([^\\)]*)\\)", rc_Not, - // :nth-child - "([a-zA-Z0-9\\_\\-\\*]*|\\]):nth-child\\(([^\\)]*)\\)", rc_nth_child, - // :contains(selectors) - ":contains\\(([^\\)]*)\\)", "[contains(string(.),'$1')]", - // |= attrib - "\\[([\\w\\-]+)\\|=([^\\]]+)\\]", "[@$1=$2 or starts-with(@$1,concat($2,'-'))]", - // *= attrib - "\\[([\\w\\-]+)\\*=([^\\]]+)\\]", "[contains(@$1,$2)]", - // ~= attrib - "\\[([\\w\\-]+)~=([^\\]]+)\\]", "[contains(concat(' ',normalize-space(@$1),' '),concat(' ',$2,' '))]", - // ^= attrib - "\\[([\\w\\-]+)\\^=([^\\]]+)\\]", "[starts-with(@$1,$2)]", - // $= attrib - "\\[([\\w\\-]+)\\$=([^\\]]+)\\]", rc_$Attr, - // != attrib - "\\[([\\w\\-]+)\\!=([^\\]]+)\\]", "[not(@$1) or @$1!=$2]", - // ids and classes - "#([\\w\\-]+)", "[@id='$1']", - "\\.([\\w\\-]+)", "[contains(concat(' ',normalize-space(@class),' '),' $1 ')]", - // normalize multiple filters - "\\]\\[([^\\]]+)", " and ($1)", - // tag:pseudo - ":(enabled)", "[not(@disabled)]", - ":(checked)", "[@$1='$1']", - ":(disabled)", "[@$1]", - ":(first)", "[1]", - ":(last)", "[last()]", - // put '*' when tag is omitted - "(^|\\|[\\./]*)(\\[)", "$1*$2", - // Replace escaped dots and spaces - "%S%"," ", - "%P%",".", - "%H%","#", - // Duplicated quotes - "'+","'", - }; + public static Object[] regs = new Object[] { + // scape some dots and spaces + "(['\\[])([^'\\]]*)([\\s\\.#])([^'\\]]*)(['\\]])", rc_scp, + // add @ for attrib + "\\[([^@\\]~\\$\\*\\^\\|\\!]+)(=[^\\]]+)?\\]", "[@$1$2]", + // multiple queries + "\\s*,\\s*", "|.//", + // , + ~ > + "\\s*(\\+|~|>)\\s*", "$1", + // * ~ + > + "([\\w\\-\\*])~([\\w\\-\\*])", "$1/following-sibling::$2", + "([\\w\\-\\*])\\+([\\w\\-\\*])", "$1/following-sibling::*[1]/self::$2", + "([\\w\\-\\*])>([\\w\\-\\*])", "$1/$2", + // all unescaped stuff escaped + "\\[([^=]+)=([^'|\"][^\\]]*)\\]", "[$1='$2']", + // all descendant or self to + "(^|[^\\w\\-\\*])(#|\\.)([\\w\\-]+)", "$1*$2$3", + "([\\>\\+\\|\\~\\,\\s])([a-zA-Z\\*]+)", "$1//$2", + "\\s+//", "//", + // :first-child + "([\\w\\-\\*]+):first-child", "*[1]/self::$1", + // :last-child + "([\\w\\-\\*]+):last-child", "$1[not(following-sibling::*)]", + // :only-child + "([\\w\\-\\*]+):only-child", "*[last()=1]/self::$1", + // :empty + "([\\w\\-\\*]+):empty", "$1[not(*) and not(normalize-space())]", + // :odd :even, this is intentional since sizzle behaves so + ":odd", ":nth-child(even)", + ":even", ":nth-child(odd)", + // :not + "(.+):not\\(([^\\)]*)\\)", rc_Not, + // :nth-child + "([a-zA-Z0-9\\_\\-\\*]*|\\]):nth-child\\(([^\\)]*)\\)", rc_nth_child, + // :contains(selectors) + ":contains\\(([^\\)]*)\\)", "[contains(string(.),'$1')]", + // |= attrib + "\\[([\\w\\-]+)\\|=([^\\]]+)\\]", "[@$1=$2 or starts-with(@$1,concat($2,'-'))]", + // *= attrib + "\\[([\\w\\-]+)\\*=([^\\]]+)\\]", "[contains(@$1,$2)]", + // ~= attrib + "\\[([\\w\\-]+)~=([^\\]]+)\\]", + "[contains(concat(' ',normalize-space(@$1),' '),concat(' ',$2,' '))]", + // ^= attrib + "\\[([\\w\\-]+)\\^=([^\\]]+)\\]", "[starts-with(@$1,$2)]", + // $= attrib + "\\[([\\w\\-]+)\\$=([^\\]]+)\\]", rc_$Attr, + // != attrib + "\\[([\\w\\-]+)\\!=([^\\]]+)\\]", "[not(@$1) or @$1!=$2]", + // ids and classes + "#([\\w\\-]+)", "[@id='$1']", + "\\.([\\w\\-]+)", "[contains(concat(' ',normalize-space(@class),' '),' $1 ')]", + // normalize multiple filters + "\\]\\[([^\\]]+)", " and ($1)", + // tag:pseudo + ":(enabled)", "[not(@disabled)]", + ":(checked)", "[@$1='$1']", + ":(disabled)", "[@$1]", + ":(first)", "[1]", + ":(last)", "[last()]", + // put '*' when tag is omitted + "(^|\\|[\\./]*)(\\[)", "$1*$2", + // Replace escaped dots and spaces + "%S%", " ", + "%P%", ".", + "%H%", "#", + // Duplicated quotes + "'+", "'", + }; public static SelectorEngineCssToXPath getInstance() { if (instance == null) { @@ -254,7 +258,7 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { } String xsel = cache.get(sel); if (xsel == null) { - xsel = sel.startsWith("./") || sel.startsWith("/") ? sel : css2Xpath(sel); + xsel = sel.startsWith("./") || sel.startsWith("/") ? sel : css2Xpath(sel); cache.put(sel, xsel); } @@ -268,7 +272,7 @@ public class SelectorEngineCssToXPath extends SelectorEngineImpl { throw new RuntimeException("This Browser does not support Xpath selectors.", e); } console.error("ERROR: xpathEvaluate invalid xpath expression: " - + xsel + " css-selector: " + sel + " " + e.getMessage() + "\n"); + + xsel + " css-selector: " + sel + " " + e.getMessage() + "\n"); } return elm; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java index c8058878..e00fa559 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNative.java @@ -30,7 +30,8 @@ import com.google.gwt.query.client.js.JsNamedArray; public class SelectorEngineNative extends SelectorEngineImpl { // querySelectorAll unsupported selectors - public static String NATIVE_EXCEPTIONS_REGEXP = "(^[\\./]/.*)|(.*(:contains|:first([^-]|$)|:last([^-]|$)|:even|:odd)).*"; + public static String NATIVE_EXCEPTIONS_REGEXP = + "(^[\\./]/.*)|(.*(:contains|:first([^-]|$)|:last([^-]|$)|:even|:odd)).*"; private static HasSelector impl; @@ -45,9 +46,9 @@ public class SelectorEngineNative extends SelectorEngineImpl { public NodeList select(String selector, Node ctx) { // querySelectorAllImpl does not support ids starting with a digit. -// if (selector.matches("#[\\w\\-]+")) { -// return SelectorEngine.veryQuickId(selector.substring(1), ctx); -// } else + // if (selector.matches("#[\\w\\-]+")) { + // return SelectorEngine.veryQuickId(selector.substring(1), ctx); + // } else if (selector.contains("!=")) { if (cache == null) { cache = JsNamedArray.create(); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java index 5d16d57c..d31502bc 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeIE8.java @@ -29,7 +29,8 @@ import com.google.gwt.dom.client.NodeList; */ public class SelectorEngineNativeIE8 extends SelectorEngineSizzleIE { - public static String NATIVE_EXCEPTIONS_REGEXP = ".*(:contains|!=|:not|:nth-|:only-|:first|:last|:even|:odd).*"; + public static String NATIVE_EXCEPTIONS_REGEXP = + ".*(:contains|!=|:not|:nth-|:only-|:first|:last|:even|:odd).*"; public NodeList select(String selector, Node ctx) { if (!SelectorEngine.hasQuerySelector || selector.matches(NATIVE_EXCEPTIONS_REGEXP)) { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java index 100d9e85..2968a446 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMin.java @@ -36,7 +36,8 @@ public class SelectorEngineNativeMin extends SelectorEngineImpl { } catch (Exception e) { console.error("GwtQuery: Selector '" + selector + "' is unsupported in this SelectorEngineNativeMin engine." - + " Do not use this syntax or configure your module to use a JS fallback. " + e.getMessage()); + + " Do not use this syntax or configure your module to use a JS fallback. " + + e.getMessage()); return null; } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java index c0bfbdad..dc7e09f6 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/SelectorEngineNativeMinIE8.java @@ -34,7 +34,8 @@ public class SelectorEngineNativeMinIE8 extends SelectorEngineImpl { try { return SelectorEngine.querySelectorAllImpl(selector, ctx); } catch (Exception e) { - console.error("GwtQuery: Selector '" + selector + "' is unsupported in this SelectorEngineNativeMinIE8 engine," + console.error("GwtQuery: Selector '" + selector + + "' is unsupported in this SelectorEngineNativeMinIE8 engine," + " check that you are in 'standards mode' or configure your module to use JS fallback. " + e.getMessage()); return null; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java index 92da332d..deaa396b 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineJS.java @@ -90,21 +90,22 @@ public class SelectorEngineJS extends SelectorEngineImpl { protected static Sequence getSequence(String expression) { int start = 0, add = 2, max = -1, modVal = -1; - JsRegexp expressionRegExp = new JsRegexp( - "^((odd|even)|([1-9]\\d*)|((([1-9]\\d*)?)n((\\+|\\-)(\\d+))?)|(\\-(([1-9]\\d*)?)n\\+(\\d+)))$"); + JsRegexp expressionRegExp = + new JsRegexp( + "^((odd|even)|([1-9]\\d*)|((([1-9]\\d*)?)n((\\+|\\-)(\\d+))?)|(\\-(([1-9]\\d*)?)n\\+(\\d+)))$"); JsObjectArray pseudoValue = expressionRegExp.exec(expression); if (!truth(pseudoValue)) { return null; } else { - if (truth(pseudoValue.get(2))) { // odd or even + if (truth(pseudoValue.get(2))) { // odd or even start = (eq(pseudoValue.get(2), "odd")) ? 1 : 2; modVal = (start == 1) ? 1 : 0; } else if (JsUtils - .truth(pseudoValue.get(3))) { // single digit + .truth(pseudoValue.get(3))) { // single digit start = Integer.parseInt(pseudoValue.get(3), 10); add = 0; max = start; - } else if (truth(pseudoValue.get(4))) { // an+b + } else if (truth(pseudoValue.get(4))) { // an+b add = truth(pseudoValue.get(6)) ? Integer .parseInt(pseudoValue.get(6), 10) : 1; start = truth(pseudoValue.get(7)) ? Integer.parseInt( @@ -115,7 +116,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { } modVal = (start > add) ? (start - add) % add : ((start == add) ? 0 : start); - } else if (truth(pseudoValue.get(10))) { // -an+b + } else if (truth(pseudoValue.get(10))) { // -an+b add = truth(pseudoValue.get(12)) ? Integer .parseInt(pseudoValue.get(12), 10) : 1; start = max = Integer.parseInt(pseudoValue.get(13), 10); @@ -145,7 +146,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { public static native NodeList getElementsByClassName(String clazz, Node ctx) /*-{ - return ctx.getElementsByClassName(clazz); + return ctx.getElementsByClassName(clazz); }-*/; public static native boolean isAdded(Node prevRef) /*-{ @@ -213,9 +214,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { private static void getGeneralSiblingNodes(JsNodeArray matchingElms, JsObjectArray nextTag, JsRegexp nextRegExp, Node prevRef) { - while ( - JsUtils.truth((prevRef = SelectorEngine.getNextSibling(prevRef))) - && !isAdded(prevRef)) { + while (JsUtils.truth((prevRef = SelectorEngine.getNextSibling(prevRef))) + && !isAdded(prevRef)) { if (!JsUtils.truth(nextTag) || nextRegExp .test(prevRef.getNodeName())) { setAdded(prevRef, true); @@ -226,9 +226,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { private static void getSiblingNodes(JsNodeArray matchingElms, JsObjectArray nextTag, JsRegexp nextRegExp, Node prevRef) { - while ( - JsUtils.truth(prevRef = SelectorEngine.getNextSibling(prevRef)) - && prevRef.getNodeType() != Node.ELEMENT_NODE) { + while (JsUtils.truth(prevRef = SelectorEngine.getNextSibling(prevRef)) + && prevRef.getNodeType() != Node.ELEMENT_NODE) { } if (JsUtils.truth(prevRef)) { if (!JsUtils.truth(nextTag) || nextRegExp @@ -252,20 +251,20 @@ public class SelectorEngineJS extends SelectorEngineImpl { private static native JsNodeArray subtractArray(JsNodeArray previousMatch, JsNodeArray elementsByPseudo) /*-{ - for (var i=0, src1; (src1=arr1[i]); i++) { - var found = false; - for (var j=0, src2; (src2=arr2[j]); j++) { - if (src2 === src1) { - found = true; - break; - } - } - if (found) { - arr1.splice(i--, 1); - } + for (var i=0, src1; (src1=arr1[i]); i++) { + var found = false; + for (var j=0, src2; (src2=arr2[j]); j++) { + if (src2 === src1) { + found = true; + break; } - return arr; - }-*/; + } + if (found) { + arr1.splice(i--, 1); + } + } + return arr; + }-*/; private JsRegexp cssSelectorRegExp; @@ -276,8 +275,9 @@ public class SelectorEngineJS extends SelectorEngineImpl { public SelectorEngineJS() { selectorSplitRegExp = new JsRegexp("[^\\s]+", "g"); childOrSiblingRefRegExp = new JsRegexp("^(>|\\+|~)$"); - cssSelectorRegExp = new JsRegexp( - "^(\\w+)?(#[\\w\\u00C0-\\uFFFF\\-\\_]+|(\\*))?((\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[\"']*[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+[\"']*)?\\]+)*)?(((:\\w+[\\w\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[\\w\\u00C0-\\uFFFF\\-_]+|((\\w*\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[\\w\\-]*))\\))?)*)?"); + cssSelectorRegExp = + new JsRegexp( + "^(\\w+)?(#[\\w\\u00C0-\\uFFFF\\-\\_]+|(\\*))?((\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[\"']*[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+[\"']*)?\\]+)*)?(((:\\w+[\\w\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[\\w\\u00C0-\\uFFFF\\-_]+|((\\w*\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[\\w\\-]*))\\))?)*)?"); } public NodeList select(String sel, Node ctx) { @@ -359,8 +359,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { for (int l = 0, ll = prevElem.size(); l < ll; l++) { tagCollectionMatches = getElementsByTagName(splitRule.tag, prevElem.getNode(l)); - for (int m = 0, mlen = tagCollectionMatches.getLength(); m < mlen; - m++) { + for (int m = 0, mlen = tagCollectionMatches.getLength(); m < mlen; m++) { Node tagMatch = tagCollectionMatches.getItem(m); if (!isAdded(tagMatch)) { @@ -430,8 +429,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { for (int r = 0, rlen = matchingElms.size(); r < rlen; r++) { Element current = matchingElms.getElement(r); boolean addElm = false; - for (int s = 0, sl = regExpAttributes.length; - s < sl; s++) { + for (int s = 0, sl = regExpAttributes.length; s < sl; s++) { addElm = false; JsRegexp attributeRegexp = regExpAttributes[s]; String currentAttr = getAttr(current, regExpAttributesStr[s]); @@ -476,7 +474,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { elm.pushAll(prevElem); } - return JsUtils.unique(elm.>cast()).cast(); + return JsUtils.unique(elm.> cast()).cast(); } protected String getAttr(Element current, String name) { @@ -600,9 +598,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { && next.getNodeType() != Node.ELEMENT_NODE) { } } else { - while ( - JsUtils.truth((next = SelectorEngine.getNextSibling(next))) - && next.getNodeType() != Node.ELEMENT_NODE) { + while (JsUtils.truth((next = SelectorEngine.getNextSibling(next))) + && next.getNodeType() != Node.ELEMENT_NODE) { } } if (!JsUtils.truth(next)) { @@ -619,9 +616,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { next = previous = previousMatch.getNode(n); if (previousDir) { - while ( - JsUtils.truth(next = SelectorEngine.getPreviousSibling(next)) - && !JsUtils + while (JsUtils.truth(next = SelectorEngine.getPreviousSibling(next)) + && !JsUtils .eq(next.getNodeName(), previous.getNodeName())) { } } else { @@ -652,7 +648,7 @@ public class SelectorEngineJS extends SelectorEngineImpl { .exec(pseudoValue); JsRegexp notRegExp = new JsRegexp("(^|\\s)" + (JsUtils.truth(notTag) ? notTag.get(1) - : JsUtils.truth(notClass) ? notClass.get(1) : "") + : JsUtils.truth(notClass) ? notClass.get(1) : "") + "(\\s|$)", "i"); if (JsUtils.truth(notAttr)) { String notAttribute = JsUtils.truth(notAttr.get(3)) ? notAttr @@ -768,9 +764,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { prev = next = previous = previousMatch.getNode(k); Node prevParent = previous.getParentNode(); if (prevParent != kParent) { - while ( - JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev)) - && prev.getNodeType() != Node.ELEMENT_NODE) { + while (JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev)) + && prev.getNodeType() != Node.ELEMENT_NODE) { } while (JsUtils.truth(next = SelectorEngine.getNextSibling(next)) && next.getNodeType() != Node.ELEMENT_NODE) { @@ -793,9 +788,8 @@ public class SelectorEngineJS extends SelectorEngineImpl { prev = next = previous = previousMatch.getNode(o); Node prevParent = previous.getParentNode(); if (prevParent != oParent) { - while ( - JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev)) - && !JsUtils + while (JsUtils.truth(prev = SelectorEngine.getPreviousSibling(prev)) + && !JsUtils .eq(prev.getNodeName(), previous.getNodeName())) { } while (JsUtils.truth(next = SelectorEngine.getNextSibling(next)) diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java index 4f641267..73e58740 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/impl/research/SelectorEngineXPath.java @@ -146,13 +146,14 @@ public class SelectorEngineXPath extends SelectorEngineImpl { } SelectorEngine.xpathEvaluate(xPathExpression, ctx, elm); } - return JsUtils.unique(elm.>cast()).cast(); + return JsUtils.unique(elm.> cast()).cast(); } private void init() { if (cssSelectorRegExp == null) { - cssSelectorRegExp = new JsRegexp( - "^(\\w+)?(#[\\w\\u00C0-\\uFFFF\\-\\_]+|(\\*))?((\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[\"']*[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+[\"']*)?\\]+)*)?(((:\\w+[\\w\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[\\w\\u00C0-\\uFFFF\\-_]+|((\\w*\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[\\w\\-]*))\\))?)*)?(>|\\+|~)?"); + cssSelectorRegExp = + new JsRegexp( + "^(\\w+)?(#[\\w\\u00C0-\\uFFFF\\-\\_]+|(\\*))?((\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?((\\[\\w+(\\^|\\$|\\*|\\||~)?(=[\"']*[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+[\"']*)?\\]+)*)?(((:\\w+[\\w\\-]*)(\\((odd|even|\\-?\\d*n?((\\+|\\-)\\d+)?|[\\w\\u00C0-\\uFFFF\\-_]+|((\\w*\\.[\\w\\u00C0-\\uFFFF\\-_]+)*)?|(\\[#?\\w+(\\^|\\$|\\*|\\||~)?=?[\\w\\u00C0-\\uFFFF\\s\\-\\_\\.]+\\]+)|(:\\w+[\\w\\-]*))\\))?)*)?(>|\\+|~)?"); selectorSplitRegExp = new JsRegexp("[^\\s]+", "g"); combinator = new JsRegexp("(>|\\+|~)"); } @@ -184,9 +185,9 @@ public class SelectorEngineXPath extends SelectorEngineImpl { xpath = "(count(preceding-sibling::*) + 1) mod " + sequence.add + " = " + sequence.modVal + ((sequence.start > 1) ? " and count(preceding-sibling::*) >= " - + (sequence.start - 1) : "") + ((sequence.max > 0) ? - " and count(preceding-sibling::*) <= " + (sequence.max - 1) - : ""); + + (sequence.start - 1) : "") + ((sequence.max > 0) ? + " and count(preceding-sibling::*) <= " + (sequence.max - 1) + : ""); } } } @@ -199,8 +200,8 @@ public class SelectorEngineXPath extends SelectorEngineImpl { } else { xpath = "position() mod " + sequence.add + " = " + sequence.modVal + ((sequence.start > 1) ? " and position() >= " + sequence.start - : "") + ((sequence.max > 0) ? " and position() <= " - + sequence.max : ""); + : "") + ((sequence.max > 0) ? " and position() <= " + + sequence.max : ""); } } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java index d85983a4..c3b0c5ce 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsCache.java @@ -20,9 +20,9 @@ import com.google.gwt.core.client.JavaScriptObject; import com.google.gwt.core.client.JsArrayMixed; import com.google.gwt.core.client.JsArrayString; - /** - * A Lightweight JSO class to store data. - */ +/** + * A Lightweight JSO class to store data. + */ public class JsCache extends JavaScriptObject { protected JsCache() { @@ -69,19 +69,24 @@ public class JsCache extends JavaScriptObject { Object o = get(id); if (o != null && clz != null) { if (o instanceof Double) { - Double d = (Double)o; - if (clz == Float.class) o = d.floatValue(); - else if (clz == Integer.class) o = d.intValue(); - else if (clz == Long.class) o = d.longValue(); - else if (clz == Short.class) o = d.shortValue(); - else if (clz == Byte.class) o = d.byteValue(); + Double d = (Double) o; + if (clz == Float.class) + o = d.floatValue(); + else if (clz == Integer.class) + o = d.intValue(); + else if (clz == Long.class) + o = d.longValue(); + else if (clz == Short.class) + o = d.shortValue(); + else if (clz == Byte.class) + o = d.byteValue(); } else if (clz == Boolean.class && !(o instanceof Boolean)) { o = Boolean.valueOf(String.valueOf(o)); } else if (clz == String.class && !(o instanceof String)) { o = String.valueOf(o); } } - return (T)o; + return (T) o; } public final native T get(Object id) /*-{ @@ -89,7 +94,7 @@ public class JsCache extends JavaScriptObject { }-*/; public final JsCache getCache(int id) { - return (JsCache)get(id); + return (JsCache) get(id); } public final boolean getBoolean(Object id) { @@ -126,7 +131,7 @@ public class JsCache extends JavaScriptObject { public final T getJavaScriptObject(Object name) { Object o = get(name); - return (o != null && o instanceof JavaScriptObject) ? ((JavaScriptObject)o).cast() : null; + return (o != null && o instanceof JavaScriptObject) ? ((JavaScriptObject) o). cast() : null; } public final native boolean isEmpty() /*-{ @@ -158,11 +163,11 @@ public class JsCache extends JavaScriptObject { return this; }-*/; - public final JsCache put(Object id, Object obj) { + public final JsCache put(Object id, Object obj) { if (obj instanceof Boolean) { - putBoolean(id, ((Boolean)obj).booleanValue()); + putBoolean(id, ((Boolean) obj).booleanValue()); } else if (obj instanceof Number) { - putNumber(id, ((Number)obj).doubleValue()); + putNumber(id, ((Number) obj).doubleValue()); } else { putObject(id, obj); } @@ -203,7 +208,7 @@ public class JsCache extends JavaScriptObject { JsArrayString a = keysImpl(); String[] ret = new String[a.length()]; for (int i = 0; i < a.length(); i++) { - ret[i] = a.get(i); + ret[i] = a.get(i); } return ret; } @@ -211,8 +216,8 @@ public class JsCache extends JavaScriptObject { public final Object[] elements() { String[] keys = keys(); Object[] ret = new Object[keys.length]; - int i=0; - for (String s: keys) { + int i = 0; + for (String s : keys) { ret[i++] = get(s); } return ret; @@ -220,7 +225,7 @@ public class JsCache extends JavaScriptObject { public final String tostring() { String ret = getClass().getName() + "{ "; - for (String k: keys()){ + for (String k : keys()) { ret += k + "=" + get(k) + " "; } return ret + "}"; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java index f0bf6008..010b7a69 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsMap.java @@ -34,7 +34,7 @@ public final class JsMap extends JavaScriptObject { @SuppressWarnings("unchecked") public T get(int hashCode) { - return (T)c().get(hashCode); + return (T) c().get(hashCode); } public T get(S key) { @@ -45,13 +45,13 @@ public final class JsMap extends JavaScriptObject { c().put(key.hashCode(), val); } - public T remove(S key){ + public T remove(S key) { T old = get(key); c().delete(key.hashCode()); return old; } - public T remove(int key){ + public T remove(int key) { T old = get(key); c().delete(key); return old; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java index 48279ba5..5a1b7820 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNamedArray.java @@ -33,7 +33,7 @@ public final class JsNamedArray extends JavaScriptObject { @SuppressWarnings("unchecked") public T get(String key) { - return (T)c().get(key); + return (T) c().get(key); } public void put(String key, T val) { @@ -52,11 +52,11 @@ public final class JsNamedArray extends JavaScriptObject { return c().elements(); } - public boolean exists(String key){ + public boolean exists(String key) { return c().exists(key); } - public void delete(String key){ + public void delete(String key) { c().delete(key); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java index 8b989a50..da8ccf05 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsNodeArray.java @@ -26,7 +26,7 @@ import com.google.gwt.dom.client.NodeList; public class JsNodeArray extends NodeList { public static JsNodeArray create() { - return create((Node)null); + return create((Node) null); } public static native JsNodeArray create(Node node) /*-{ @@ -34,15 +34,15 @@ public class JsNodeArray extends NodeList { }-*/; public static JsNodeArray create(NodeList nl) { - JsNodeArray ret = create((Node)null); + JsNodeArray ret = create((Node) null); ret.pushAll(nl); return ret; } - protected JsNodeArray(){ + protected JsNodeArray() { } - public final void addNode(Node n){ + public final void addNode(Node n) { c().add(n); } @@ -80,7 +80,7 @@ public class JsNodeArray extends NodeList { public final Element[] elements() { Element[] ret = new Element[size()]; - for (int i=0 ; i extends JavaScriptObject { return cast(); } - public JsObjectArray add(T...vals) { - for (T t: vals) { + public JsObjectArray add(T... vals) { + for (T t : vals) { if (t instanceof Number) { - c().putNumber(length(), (((Number)t).doubleValue())); + c().putNumber(length(), (((Number) t).doubleValue())); } else if (t instanceof Boolean) { - c().putBoolean(length(), ((Boolean)t).booleanValue()); + c().putBoolean(length(), ((Boolean) t).booleanValue()); } else { c().put(length(), t); } @@ -55,7 +55,7 @@ public final class JsObjectArray extends JavaScriptObject { @SuppressWarnings("unchecked") public T get(int index) { - return (T)c().get(index); + return (T) c().get(index); } public int length() { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java index 49d32e42..bdf767a9 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsRegexp.java @@ -78,7 +78,7 @@ public class JsRegexp { return regexp.test(rule); }-*/; - public String getPattern(){ + public String getPattern() { return regexp.toString(); }; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java index 9266e0fd..ba20b238 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/js/JsUtils.java @@ -39,6 +39,7 @@ public class JsUtils { */ public static class JsFunction extends Function implements Command { private JavaScriptObject jso = null; + public JsFunction(JavaScriptObject f) { if (JsUtils.isFunction(f)) { jso = f; @@ -146,13 +147,13 @@ public class JsUtils { // @see https://github.com/douglascrockford/JSON-js/blob/master/json2.js Properties prop = js.cast(); String ret = ""; - for (String k : prop.keys()){ + for (String k : prop.keys()) { String ky = k.matches("\\d+") ? k : "\"" + k + "\""; JsCache o = prop.getArray(k).cast(); if (o != null) { ret += ky + ":["; - for (int i = 0, l = o.length(); i < l ; i++) { - Properties p = o.cast().getJavaScriptObject(i); + for (int i = 0, l = o.length(); i < l; i++) { + Properties p = o. cast().getJavaScriptObject(i); if (p != null) { ret += p.toJsonString() + ","; } else { @@ -169,9 +170,9 @@ public class JsUtils { } } } - return "{" + ret.replaceAll(",\\s*([\\]}]|$)","$1") - .replaceAll("([:,\\[])\"(-?[\\d\\.]+|null|false|true)\"", "$1$2") - + "}"; + return "{" + ret.replaceAll(",\\s*([\\]}]|$)", "$1") + .replaceAll("([:,\\[])\"(-?[\\d\\.]+|null|false|true)\"", "$1$2") + + "}"; } @Override @@ -211,14 +212,14 @@ public class JsUtils { * Returns a property present in a javascript object. */ public static T prop(JavaScriptObject o, Object id, Class type) { - return o == null ? null : o.cast().get(id, type); + return o == null ? null : o. cast().get(id, type); } /** * Returns a property present in a javascript object. */ public static T prop(JavaScriptObject o, Object id) { - return o == null ? null : o.cast().get(id); + return o == null ? null : o. cast(). get(id); } /** @@ -226,7 +227,7 @@ public class JsUtils { */ public static void prop(JavaScriptObject o, Object id, Object val) { if (o != null) { - o.cast().put(id, val); + o. cast().put(id, val); } } @@ -353,7 +354,7 @@ public class JsUtils { public static boolean isDetached(Node n) { assert n != null; - if ("html".equalsIgnoreCase(n.getNodeName())){ + if ("html".equalsIgnoreCase(n.getNodeName())) { return false; } @@ -499,10 +500,12 @@ public class JsUtils { * @return the javascript object returned by the jsni method or null. */ public static T runJavascriptFunction(JavaScriptObject o, String meth, Object... args) { - return runJavascriptFunctionImpl(o, meth, JsObjectArray.create().add(args).cast()); + return runJavascriptFunctionImpl(o, meth, JsObjectArray.create().add(args) + . cast()); } - private static native T runJavascriptFunctionImpl(JavaScriptObject o, String meth, JsArrayMixed args) /*-{ + private static native T runJavascriptFunctionImpl(JavaScriptObject o, String meth, + JsArrayMixed args) /*-{ return (f = o && o[meth]) && @com.google.gwt.query.client.js.JsUtils::isFunction(*)(f) && @com.google.gwt.query.client.js.JsCache::gwtBox(*)([f.apply(o, args)]); @@ -549,13 +552,13 @@ public class JsUtils { ret += ret.isEmpty() ? "" : "&"; JsCache o = prop.getArray(k).cast(); if (o != null) { - for (int i = 0, l = o.length(); i < l ; i++) { + for (int i = 0, l = o.length(); i < l; i++) { ret += i > 0 ? "&" : ""; - Properties p = o.cast().getJavaScriptObject(i); + Properties p = o. cast().getJavaScriptObject(i); if (p != null) { ret += k + "[]=" + p.toJsonString(); } else { - ret += k + "[]=" + o.getString(i) ; + ret += k + "[]=" + o.getString(i); } } } else { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java index 072b2a5b..acb7fc17 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Effects.java @@ -35,7 +35,7 @@ public class Effects extends QueuePlugin { /** * Class to access protected methods in Animation. */ - public abstract static class GQAnimation extends Animation { + public abstract static class GQAnimation extends Animation { private static final String ACTUAL_ANIMATION = "EffectsRunnning"; @@ -47,20 +47,24 @@ public class Effects extends QueuePlugin { e = element; return this; } + protected GQAnimation setProperties(Properties properties) { prps = properties == null ? Properties.create() : properties; return this; } + protected void onStart() { // Mark this animation as actual, so as we can stop it in the GQuery.stop() method $(e).data(ACTUAL_ANIMATION, this); super.onStart(); } + protected void onComplete() { // avoid memory leak (issue #132) $(e).removeData(ACTUAL_ANIMATION); super.onComplete(); } + public void cancel() { // avoid memory leak (issue #132) $(e).removeData(ACTUAL_ANIMATION); @@ -100,6 +104,7 @@ public class Effects extends QueuePlugin { anim.cancel(); } } + public void f(Element e) { anim.run(duration); } @@ -175,7 +180,7 @@ public class Effects extends QueuePlugin { duration = Math.abs(duration); - for (Element e: elements()) { + for (Element e : elements()) { if (Fx.css3) { new TransitionsClipAnimation(easing, e, p, funcs).run(duration); } else { diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java index 44b78a21..84ce65dd 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/Events.java @@ -40,7 +40,8 @@ public class Events extends GQuery { * Don't apply events on text and comment nodes !! */ private static boolean isEventCapable(Node n) { - return JsUtils.isWindow(n) || JsUtils.isElement(n) && n.getNodeType() != 3 && n.getNodeType() != 8; + return JsUtils.isWindow(n) || JsUtils.isElement(n) && n.getNodeType() != 3 + && n.getNodeType() != 8; } public Events(GQuery gq) { @@ -114,7 +115,7 @@ public class Events extends GQuery { } public GQuery die(int eventbits) { - return die(eventbits, null); + return die(eventbits, null); } /** @@ -295,12 +296,12 @@ public class Events extends GQuery { GqEvent.setOriginalEventType(e, originalEventName); } - if ("submit".equals(htmlEvent)){ + if ("submit".equals(htmlEvent)) { Function submitFunction = new Function() { public void f(Element e) { // first submit the form then call the others functions if (FormElement.is(e)) { - e.cast().submit(); + e. cast().submit(); } callHandlers(e, getEvent(), functions); } @@ -395,7 +396,7 @@ public class Events extends GQuery { // Ie6-8 don't dispatch bitless event if ((browser.ie6 || browser.ie8) && Event.getTypeInt(evt.getType()) == -1) { - bubbleEventForIE(e, evt.cast()); + bubbleEventForIE(e, evt. cast()); } else { e.dispatchEvent(evt); } @@ -425,10 +426,10 @@ public class Events extends GQuery { */ private boolean isEventPropagationStopped(Event event) { // trick to avoid jnsi - return event.cast().getPropertyBoolean("cancelBubble"); + return event. cast().getPropertyBoolean("cancelBubble"); } - private void callHandlers(Element e, NativeEvent evt, Function... functions){ + private void callHandlers(Element e, NativeEvent evt, Function... functions) { for (Function f : functions) { f.setEvent(Event.as(evt)); f.f(e); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java index bdb508cc..eb63a22a 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEffects.java @@ -14,6 +14,7 @@ * the License. */ package com.google.gwt.query.client.plugins; + import com.google.gwt.query.client.Function; import com.google.gwt.query.client.LazyBase; import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing; @@ -22,7 +23,7 @@ import com.google.gwt.query.client.plugins.effects.PropertiesAnimation.Easing; * LazyEffects. * @param */ -public interface LazyEffects extends LazyBase{ +public interface LazyEffects extends LazyBase { /** * The animate() method allows you to create animation effects on any numeric diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java index 4c3e8d83..55404170 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyEvents.java @@ -12,6 +12,7 @@ * the License. */ package com.google.gwt.query.client.plugins; + import com.google.gwt.dom.client.NativeEvent; import com.google.gwt.query.client.Function; import com.google.gwt.query.client.GQuery; @@ -21,7 +22,7 @@ import com.google.gwt.query.client.LazyBase; * LazyEvents. * @param */ -public interface LazyEvents extends LazyBase{ +public interface LazyEvents extends LazyBase { /** * Binds a set of handlers to a particular Event for each matched element. diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java index cd2c20f3..f08a0538 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/LazyWidgets.java @@ -14,6 +14,7 @@ * the License. */ package com.google.gwt.query.client.plugins; + import com.google.gwt.query.client.LazyBase; import com.google.gwt.query.client.plugins.widgets.WidgetFactory; import com.google.gwt.query.client.plugins.widgets.WidgetInitializer; @@ -28,14 +29,15 @@ import com.google.gwt.user.client.ui.Widget; * LazyWidgets. * @param */ -public interface LazyWidgets extends LazyBase{ +public interface LazyWidgets extends LazyBase { /** * 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. */ - LazyWidgets widgets(WidgetFactory factory, WidgetInitializer initializers); + LazyWidgets widgets(WidgetFactory factory, + WidgetInitializer initializers); /** * Create a {@link Button} widget for each selected element. diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MouseOptions.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MouseOptions.java index 885911ff..772f8e9f 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MouseOptions.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MouseOptions.java @@ -89,6 +89,6 @@ public class MouseOptions { protected void initDefault() { delay = 0; distance = 1; // by default, the mouse have to move one pixel ! - cancel = new String[] { "input", "option" }; + cancel = new String[] {"input", "option"}; } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java index 09c06028..2202bc71 100755 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/MousePlugin.java @@ -144,7 +144,7 @@ public abstract class MousePlugin extends UiPlugin { bindOtherEvents(element); - if (!touchSupported){ // click event are not triggered if we call preventDefault on touchstart event. + if (!touchSupported) { // click event are not triggered if we call preventDefault on touchstart event. event.getOriginalEvent().preventDefault(); } @@ -268,16 +268,12 @@ public abstract class MousePlugin extends UiPlugin { return mouseDistance >= neededDistance; } - private native boolean isEventAlreadyHandled(GqEvent event) - /*-{ - + private native boolean isEventAlreadyHandled(GqEvent event) /*-{ var result = event.mouseHandled ? event.mouseHandled : false; return result; }-*/; - private native void markEventAsHandled(GqEvent event) - /*-{ - + private native void markEventAsHandled(GqEvent event) /*-{ event.mouseHandled = true; }-*/; 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 index 886440d5..8951ccad 100644 --- 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 @@ -114,7 +114,7 @@ public class QueuePlugin> extends GQuery { for (Element e : elements()) { queue(e, name, new DelayFunction(e, name, milliseconds, funcs)); } - return (T)this; + return (T) this; } /** @@ -156,7 +156,7 @@ public class QueuePlugin> extends GQuery { int count = 1; // Inner functions don't have constructors, we use a block to initialize it { - for (Element elem: elements()) { + for (Element elem : elements()) { // Add this resolve function only to those elements with active queue if (queue(elem, name, null) != null) { emptyHooks(elem, name).add(this); @@ -192,7 +192,7 @@ public class QueuePlugin> extends GQuery { */ public int queue(String name) { Queue q = isEmpty() ? null : queue(get(0), name, null); - return q == null? 0 : q.size(); + return q == null ? 0 : q.size(); } /** @@ -206,7 +206,7 @@ public class QueuePlugin> extends GQuery { queue(e, DEFAULT_NAME, f); } } - return (T)this; + return (T) this; } /** @@ -215,12 +215,12 @@ public class QueuePlugin> extends GQuery { */ @SuppressWarnings("unchecked") public T queue(final String name, Function... funcs) { - for (final Function f: funcs) { - for (Element e: elements()) { + for (final Function f : funcs) { + for (Element e : elements()) { queue(e, name, f); } } - return (T)this; + return (T) this; } /** @@ -370,9 +370,9 @@ public class QueuePlugin> extends GQuery { private Callbacks emptyHooks(Element elem, String name) { String key = name + EMPTY_HOOKS; - Callbacks c = (Callbacks)data(elem, key, null); + Callbacks c = (Callbacks) data(elem, key, null); if (c == null) { - c = (Callbacks)data(elem, key, new Callbacks("once memory")); + c = (Callbacks) data(elem, key, new Callbacks("once memory")); } return c; } 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 index 7968218f..92938d17 100755 --- 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 @@ -146,7 +146,7 @@ public class UiPlugin extends GQuery { handlerManager.fireEvent(e); } if (callback != null) { - callback.f(element.cast()); + callback.f(element. cast()); } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java index b3b28f92..eb58f93d 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/Ajax.java @@ -67,32 +67,59 @@ public class Ajax extends GQuery { */ public interface Settings extends JsonBuilder { String getContentType(); + Element getContext(); + IsProperties getData(); + String getDataString(); + String getDataType(); + Function getError(); + IsProperties getHeaders(); + String getPassword(); + Function getSuccess(); + int getTimeout(); + String getType(); + String getUrl(); + String getUsername(); + boolean getWithCredentials(); + Settings setContentType(String t); + Settings setContext(Element e); + Settings setData(Object p); + Settings setDataString(String d); + Settings setDataType(String t); + Settings setError(Function f); + Settings setHeaders(IsProperties p); + Settings setPassword(String p); + Settings setSuccess(Function f); + Settings setTimeout(int t); + Settings setType(String t); + Settings setUrl(String u); + Settings setUsername(String u); + Settings setWithCredentials(boolean b); } @@ -149,45 +176,45 @@ public class Ajax extends GQuery { if ("jsonp".equalsIgnoreCase(dataType)) { ret = GQ.getAjaxTransport().getJsonP(settings); - } else if ("loadscript".equalsIgnoreCase(dataType)){ + } else if ("loadscript".equalsIgnoreCase(dataType)) { ret = GQ.getAjaxTransport().getLoadScript(settings); } else { ret = GQ.getAjaxTransport().getXhr(settings) - .then(new Function() { - public Object f(Object...args) { - Response response = arguments(0); - Request request = arguments(1); - Object retData = response.getText(); - if (retData != null && !"".equals(retData)) { - try { - if ("xml".equalsIgnoreCase(dataType)) { - retData = JsUtils.parseXML(response.getText()); - } else if ("json".equalsIgnoreCase(dataType)) { - retData = GQ.create(response.getText()); - } else { - retData = response.getText(); - if ("script".equalsIgnoreCase(dataType)) { - ScriptInjector.fromString((String)retData).setWindow(window).inject(); + .then(new Function() { + public Object f(Object... args) { + Response response = arguments(0); + Request request = arguments(1); + Object retData = response.getText(); + if (retData != null && !"".equals(retData)) { + try { + if ("xml".equalsIgnoreCase(dataType)) { + retData = JsUtils.parseXML(response.getText()); + } else if ("json".equalsIgnoreCase(dataType)) { + retData = GQ.create(response.getText()); + } else { + retData = response.getText(); + if ("script".equalsIgnoreCase(dataType)) { + ScriptInjector.fromString((String) retData).setWindow(window).inject(); + } + } + } catch (Exception e) { + if (GWT.isClient() && GWT.getUncaughtExceptionHandler() != null) { + GWT.getUncaughtExceptionHandler().onUncaughtException(e); + } else { + e.printStackTrace(); } - } - } catch (Exception e) { - if (GWT.isClient() && GWT.getUncaughtExceptionHandler() != null) { - GWT.getUncaughtExceptionHandler().onUncaughtException(e); - } else { - e.printStackTrace(); } } + return new Object[] {retData, "success", request, response}; } - return new Object[]{retData, "success", request, response}; - } - }, new Function() { - public Object f(Object...args) { - Throwable exception = arguments(0); - Request request = getArgument(1, Request.class); - String msg = String.valueOf(exception); - return new Object[]{null, msg, request, null, exception}; - } - }); + }, new Function() { + public Object f(Object... args) { + Throwable exception = arguments(0); + Request request = getArgument(1, Request.class); + String msg = String.valueOf(exception); + return new Object[] {null, msg, request, null, exception}; + } + }); } if (onSuccess != null) { ret.done(onSuccess); @@ -200,7 +227,7 @@ public class Ajax extends GQuery { private static void resolveSettings(Settings settings) { String url = settings.getUrl(); - assert settings != null && settings.getUrl() != null: "no url found in settings"; + assert settings != null && settings.getUrl() != null : "no url found in settings"; String type = "POST"; if (settings.getType() != null) { @@ -214,10 +241,12 @@ public class Ajax extends GQuery { IsProperties data = settings.getData(); if (data != null) { String dataString = null, contentType = null; - if (data.getDataImpl() instanceof JavaScriptObject && JsUtils.isFormData(data.getDataImpl())) { + if (data.getDataImpl() instanceof JavaScriptObject + && JsUtils.isFormData(data. getDataImpl())) { dataString = null; contentType = FormPanel.ENCODING_URLENCODED; - } else if (settings.getType().matches("(POST|PUT)") && "json".equalsIgnoreCase(settings.getDataType())) { + } else if (settings.getType().matches("(POST|PUT)") + && "json".equalsIgnoreCase(settings.getDataType())) { dataString = data.toJson(); contentType = JSON_CONTENT_TYPE_UTF8; } else { @@ -279,7 +308,7 @@ public class Ajax extends GQuery { } public static Promise get(String url, IsProperties data) { - return get(url, (IsProperties)data, null); + return get(url, (IsProperties) data, null); } public static Promise get(String url, IsProperties data, Function onSuccess) { @@ -311,7 +340,7 @@ public class Ajax extends GQuery { } public static Promise getJSONP(String url, IsProperties data) { - return getJSONP(url, (IsProperties)data, null); + return getJSONP(url, (IsProperties) data, null); } public static Promise getJSONP(String url, IsProperties data, Function onSuccess) { @@ -326,13 +355,12 @@ public class Ajax extends GQuery { public static Promise getJSONP(String url, Function success, Function error, int timeout) { return ajax(createSettings() - .setUrl(url) - .setDataType("jsonp") - .setType("get") - .setTimeout(timeout) - .setSuccess(success) - .setError(error) - ); + .setUrl(url) + .setDataType("jsonp") + .setType("get") + .setTimeout(timeout) + .setSuccess(success) + .setError(error)); } /** @@ -344,11 +372,10 @@ public class Ajax extends GQuery { public static Promise getScript(final String url, Function success) { return ajax(createSettings() - .setUrl(url) - .setType("get") - .setDataType("script") - .setSuccess(success) - ); + .setUrl(url) + .setType("get") + .setDataType("script") + .setSuccess(success)); } /** @@ -360,15 +387,14 @@ public class Ajax extends GQuery { public static Promise loadScript(final String url, Function success) { return ajax(createSettings() - .setUrl(url) - .setType("get") - .setDataType("loadscript") - .setSuccess(success) - ); + .setUrl(url) + .setType("get") + .setDataType("loadscript") + .setSuccess(success)); } public static Promise post(String url, IsProperties data) { - return post(url, (IsProperties)data, null); + return post(url, (IsProperties) data, null); } public static Promise post(String url, IsProperties data, final Function onSuccess) { @@ -404,10 +430,10 @@ public class Ajax extends GQuery { // not support java embedded flag expressions (?s) and javascript does // not have multidot flag. String s = arguments(0).toString().replaceAll("]+>\\s*", "") - .replaceAll("\\s*", "") - .replaceAll("\\s*", "") - .replaceAll("\\s*", "") - .replaceAll("\\s*", ""); + .replaceAll("\\s*", "") + .replaceAll("\\s*", "") + .replaceAll("\\s*", "") + .replaceAll("\\s*", ""); // We wrap the results in a div s = "
" + s + "
"; diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/AjaxTransportJs.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/AjaxTransportJs.java index 07c204ea..15406a68 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/AjaxTransportJs.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/ajax/AjaxTransportJs.java @@ -41,20 +41,22 @@ public class AjaxTransportJs implements AjaxTransport { public Promise getLoadScript(final Settings settings) { return new PromiseFunction() { private ScriptElement scriptElement; + public void f(final Deferred dfd) { scriptElement = ScriptInjector.fromUrl(settings.getUrl()).setWindow(GQuery.window) - .setCallback(new Callback() { - public void onSuccess(Void result) { - GQuery.$(GQuery.window).delay(0, new Function(){ - public void f() { - dfd.resolve(scriptElement); + .setCallback(new Callback() { + public void onSuccess(Void result) { + GQuery.$(GQuery.window).delay(0, new Function() { + public void f() { + dfd.resolve(scriptElement); + } + }); + } + + public void onFailure(Exception reason) { + dfd.reject(reason); } - }); - } - public void onFailure(Exception reason) { - dfd.reject(reason); - } - }).inject().cast(); + }).inject().cast(); } }; } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Callbacks.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Callbacks.java index de4a7094..508c82e5 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Callbacks.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Callbacks.java @@ -32,7 +32,7 @@ public class Callbacks { /** * Return false to avoid executing the rest of functions. */ - boolean f(Object ...objects); + boolean f(Object... objects); } private List stack = new ArrayList(); @@ -66,7 +66,7 @@ public class Callbacks { * */ public Callbacks add(Callback... c) { - addAll((Object[])c); + addAll((Object[]) c); return this; } @@ -74,7 +74,7 @@ public class Callbacks { * Add a Callback or a collection of callbacks to a callback list. */ public Callbacks add(com.google.gwt.core.client.Callback... c) { - addAll((Object[])c); + addAll((Object[]) c); return this; } @@ -82,7 +82,7 @@ public class Callbacks { * Add a Function or a collection of Function to a callback list. */ public Callbacks add(Function... f) { - addAll((Object[])f); + addAll((Object[]) f); return this; } @@ -115,11 +115,12 @@ public class Callbacks { if (isMemory) { memory = new ArrayList(Arrays.asList(o)); } - if (stack != null) for (Object c : stack) { - if (!run(c, o) && stopOnFalse) { - break; + if (stack != null) + for (Object c : stack) { + if (!run(c, o) && stopOnFalse) { + break; + } } - } } return this; } @@ -132,7 +133,7 @@ public class Callbacks { return this; } - private void addAll(Object...o) { + private void addAll(Object... o) { for (Object c : o) { if (!done && stack != null && c != null && (!isUnique || !stack.contains(c))) { stack.add(c); @@ -145,19 +146,19 @@ public class Callbacks { } @SuppressWarnings({"unchecked", "rawtypes"}) - private boolean run(Object c, Object...o) { + private boolean run(Object c, Object... o) { // Unbox array inside array when there is only an element. // It happens when running filters in Promise.then() if (o != null && o.length == 1 && o[0] != null && o[0].getClass().isArray()) { - o = (Object[])o[0]; + o = (Object[]) o[0]; } if (c instanceof Callback) { - return ((Callback)c).f(o); + return ((Callback) c).f(o); } else if (c instanceof Function) { - Object r = ((Function)c).f(o); - return (r instanceof Boolean) ? (Boolean)r : true; + Object r = ((Function) c).f(o); + return (r instanceof Boolean) ? (Boolean) r : true; } else if (c instanceof com.google.gwt.core.client.Callback) { - ((com.google.gwt.core.client.Callback)c).onSuccess(o); + ((com.google.gwt.core.client.Callback) c).onSuccess(o); } return true; } @@ -166,4 +167,3 @@ public class Callbacks { return "stack=" + (stack == null ? "null" : stack.size()) + " " + done; } } - diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Deferred.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Deferred.java index 5cc99f03..9cb7b624 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Deferred.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/Deferred.java @@ -48,7 +48,8 @@ public class Deferred implements Promise.Deferred { // Whether break the flow if old deferred fails boolean cont = false; - public ThenFunction(Deferred newDfd, Function[] subordinates, int funcType, boolean continueFlow) { + public ThenFunction(Deferred newDfd, Function[] subordinates, int funcType, + boolean continueFlow) { type = funcType; filter = subordinates.length > type ? subordinates[type] : null; dfd = newDfd; @@ -65,18 +66,23 @@ public class Deferred implements Promise.Deferred { // If filter function returns a promise we pipeline it. final Promise p = (Promise) newArgs; if (type == PROGRESS) { - p.progress(new Function(){public void f() { - settle(PROGRESS, getArguments()); - }}); + p.progress(new Function() { + public void f() { + settle(PROGRESS, getArguments()); + } + }); } else { - p.always(new Function(){public void f() { - settle((type == DONE || type == FAIL && cont) && p.isResolved() ? DONE : FAIL, getArguments()); - }}); + p.always(new Function() { + public void f() { + settle((type == DONE || type == FAIL && cont) && p.isResolved() ? DONE : FAIL, + getArguments()); + } + }); } } else { // Otherwise we change the arguments by the new ones newArgs = Boolean.TRUE.equals(newArgs) ? oldArgs : - newArgs != null && newArgs.getClass().isArray() ? (Object[])newArgs : newArgs; + newArgs != null && newArgs.getClass().isArray() ? (Object[]) newArgs : newArgs; settle(type, newArgs); } } else { @@ -86,9 +92,12 @@ public class Deferred implements Promise.Deferred { } private void settle(int action, Object... args) { - if (action == DONE) dfd.resolve(args); - if (action == FAIL) dfd.reject(args); - if (action == PROGRESS) dfd.notify(args); + if (action == DONE) + dfd.resolve(args); + if (action == FAIL) + dfd.reject(args); + if (action == PROGRESS) + dfd.notify(args); } } @@ -278,11 +287,11 @@ public class Deferred implements Promise.Deferred { private static Promise makePromise(final Object o) { if (o instanceof Promise) { - return (Promise)o; + return (Promise) o; } else if (o instanceof Function) { - return makePromise(((Function)o).f(new Object[0])); + return makePromise(((Function) o).f(new Object[0])); } else if (o instanceof GQuery) { - return ((GQuery)o).promise(); + return ((GQuery) o).promise(); } else { return new PromiseFunction() { public void f(Deferred dfd) { @@ -336,7 +345,8 @@ public class Deferred implements Promise.Deferred { * Call the progressCallbacks on a Deferred object with the given args. */ public Deferred notify(Object... o) { - if (state == PENDING) notify.fire(o); + if (state == PENDING) + notify.fire(o); return this; } @@ -354,7 +364,8 @@ public class Deferred implements Promise.Deferred { * Reject a Deferred object and call any failCallbacks with the given args. */ public Deferred reject(Object... o) { - if (state == PENDING) reject.fire(o); + if (state == PENDING) + reject.fire(o); return this; } @@ -362,12 +373,14 @@ public class Deferred implements Promise.Deferred { * Resolve a Deferred object and call any doneCallbacks with the given args. */ public Deferred resolve(Object... o) { - if (state == PENDING) resolve.fire(o); + if (state == PENDING) + resolve.fire(o); return this; } @Override public String toString() { - return "Deferred this=" + hashCode() + " promise=" + promise().hashCode() + " state=" + promise.state() + " restatus=" + resolve.status(); + return "Deferred this=" + hashCode() + " promise=" + promise().hashCode() + " state=" + + promise.state() + " restatus=" + resolve.status(); } } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/FunctionDeferred.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/FunctionDeferred.java index 25f35fb7..25295e46 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/FunctionDeferred.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/FunctionDeferred.java @@ -48,7 +48,9 @@ public abstract class FunctionDeferred extends Function { /** * Cache types. */ - public static enum CacheType {NONE, ALL, RESOLVED, REJECTED}; + public static enum CacheType { + NONE, ALL, RESOLVED, REJECTED + }; protected Deferred dfd; public Function resolve, reject; @@ -67,10 +69,10 @@ public abstract class FunctionDeferred extends Function { * is resolved. */ public final Object f(Object... args) { - return dfd != null && + return dfd != null && (cache == CacheType.ALL || - cache == CacheType.RESOLVED && dfd.promise().isResolved() || - cache == CacheType.REJECTED && dfd.promise().isRejected()) + cache == CacheType.RESOLVED && dfd.promise().isResolved() || + cache == CacheType.REJECTED && dfd.promise().isRejected()) ? dfd.promise() : new PromiseFunction() { public void f(Deferred dfd) { @@ -79,7 +81,7 @@ public abstract class FunctionDeferred extends Function { FunctionDeferred.this.dfd = dfd; FunctionDeferred.this.f(dfd); } - }; + }; } /** diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilder.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilder.java index 3ef4de18..af9b9641 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilder.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilder.java @@ -83,7 +83,9 @@ public class PromiseReqBuilder extends DeferredPromiseImpl implements RequestCal String url = settings.getUrl(); IsProperties data = settings.getData(); String ctype = settings.getContentType(); - Boolean isFormData = data != null && data.getDataImpl() instanceof JavaScriptObject && JsUtils.isFormData(data.getDataImpl()); + Boolean isFormData = + data != null && data.getDataImpl() instanceof JavaScriptObject + && JsUtils.isFormData(data. getDataImpl()); XMLHttpRequest xmlHttpRequest = XMLHttpRequest.create(); try { @@ -149,7 +151,8 @@ public class PromiseReqBuilder extends DeferredPromiseImpl implements RequestCal }); try { - JsUtils.runJavascriptFunction(xmlHttpRequest, "send", isFormData ? data.getDataImpl() : settings.getDataString()); + JsUtils.runJavascriptFunction(xmlHttpRequest, "send", isFormData ? data.getDataImpl() + : settings.getDataString()); } catch (JavaScriptException e) { onError(null, e); } @@ -163,7 +166,8 @@ public class PromiseReqBuilder extends DeferredPromiseImpl implements RequestCal int status = response.getStatusCode(); if (status <= 0 || status >= 400) { String statusText = status <= 0 ? "Bad CORS" : response.getStatusText(); - onError(request, new RequestException("HTTP ERROR: " + status + " " + statusText + "\n" + response.getText())); + onError(request, new RequestException("HTTP ERROR: " + status + " " + statusText + "\n" + + response.getText())); } else { dfd.resolve(response, request); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilderJSONP.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilderJSONP.java index 064e61c0..0935fb2f 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilderJSONP.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/deferred/PromiseReqBuilderJSONP.java @@ -55,7 +55,7 @@ public class PromiseReqBuilderJSONP extends DeferredPromiseImpl { // jQuery allows a parameter callback=? to figure out the callback parameter if (callbackParam == null) { MatchResult tmp = callbackRegex.exec(url); - if (tmp != null && tmp.getGroupCount() == 4) { + if (tmp != null && tmp.getGroupCount() == 4) { callbackParam = tmp.getGroup(2); url = tmp.getGroup(1) + tmp.getGroup(3); } diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Bezier.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Bezier.java index cdc6da44..d167979e 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Bezier.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Bezier.java @@ -26,42 +26,48 @@ package com.google.gwt.query.client.plugins.effects; */ public class Bezier { - private double x1, y1 , x2, y2; + private double x1, y1, x2, y2; public Bezier(double x1, double y1, double x2, double y2) { - this.x1 = x1; this.y1 = y1; this.x2 = x2; this.y2 = y2; + this.x1 = x1; + this.y1 = y1; + this.x2 = x2; + this.y2 = y2; } private double a(double a1, double a2) { return 1.0 - 3.0 * a2 + 3.0 * a1; } + private double b(double a1, double a2) { return 3.0 * a2 - 6.0 * a1; } - private double c(double a1){ + + private double c(double a1) { return 3.0 * a1; } private double calcBezier(double t, double a1, double a2) { - return ((a(a1, a2)*t + b(a1, a2))*t + c(a1))*t; + return ((a(a1, a2) * t + b(a1, a2)) * t + c(a1)) * t; } private double calcSlope(double t, double a1, double a2) { - return 3.0 * a(a1, a2)*t*t + 2.0 * b(a1, a2) * t + c(a1); + return 3.0 * a(a1, a2) * t * t + 2.0 * b(a1, a2) * t + c(a1); } private double getTForX(double x) { double t = x; for (double i = 0; i < 4; ++i) { double currentSlope = calcSlope(t, x1, x2); - if (currentSlope == 0.0) return t; + if (currentSlope == 0.0) + return t; double currentX = calcBezier(t, x1, x2) - x; t -= currentX / currentSlope; } return t; } - public double f (double x) { + public double f(double x) { return calcBezier(getTForX(x), y1, y2); } 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 index deead04d..627c0b47 100755 --- 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 @@ -48,8 +48,8 @@ public class ClipAnimation extends PropertiesAnimation { BIDIRECTIONAL, HORIZONTAL, VERTICAL } - private static final String[] attrsToSave = new String[]{ - "position", "overflow", "visibility", "white-space", "top", "left", "width", "height"}; + private static final String[] attrsToSave = new String[] { + "position", "overflow", "visibility", "white-space", "top", "left", "width", "height"}; private Action action; private Corner corner; @@ -120,7 +120,7 @@ public class ClipAnimation extends PropertiesAnimation { if (action == null) { return; } - currentAction = action != Action.TOGGLE ? action : hidden ? Action.SHOW : Action.HIDE; + currentAction = action != Action.TOGGLE ? action : hidden ? Action.SHOW : Action.HIDE; g.saveCssAttrs(attrsToSave); diff --git a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Fx.java b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Fx.java index 04d5a695..b81a9de9 100644 --- a/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Fx.java +++ b/gwtquery-core/src/main/java/com/google/gwt/query/client/plugins/effects/Fx.java @@ -100,60 +100,62 @@ public class Fx { } // hexadecimal regex - public static RegExp REGEX_HEX_COLOR_PATTERN = RegExp.compile("#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})"); + public static RegExp REGEX_HEX_COLOR_PATTERN = RegExp + .compile("#([a-fA-F0-9]{6}|[a-fA-F0-9]{3})"); private static JsNamedArray htmlColorToRgb; // rgb and rgba regex public static RegExp REGEX_RGB_COLOR_PATTERN = - RegExp.compile("rgba?\\(\\s*([0-9]{1,3}%?)\\s*,\\s*([0-9]{1,3}%?)\\s*,\\s*([0-9]{1,3}%?).*\\)$"); + RegExp + .compile("rgba?\\(\\s*([0-9]{1,3}%?)\\s*,\\s*([0-9]{1,3}%?)\\s*,\\s*([0-9]{1,3}%?).*\\)$"); static { htmlColorToRgb = JsNamedArray.create(); - htmlColorToRgb.put("white", new int[]{255, 255, 255}); - htmlColorToRgb.put("aqua", new int[]{0, 255, 255}); - htmlColorToRgb.put("azure", new int[]{240, 255, 255}); - htmlColorToRgb.put("beige", new int[]{245, 245, 220}); - htmlColorToRgb.put("black", new int[]{0, 0, 0}); - htmlColorToRgb.put("blue", new int[]{0, 0, 255}); - htmlColorToRgb.put("brown", new int[]{165, 42, 42}); - htmlColorToRgb.put("cyan", new int[]{0, 255, 255}); - htmlColorToRgb.put("darkblue", new int[]{0, 0, 139}); - htmlColorToRgb.put("darkcyan", new int[]{0, 139, 139}); - htmlColorToRgb.put("darkgrey", new int[]{169, 169, 169}); - htmlColorToRgb.put("darkgreen", new int[]{0, 100, 0}); - htmlColorToRgb.put("darkkhaki", new int[]{189, 183, 107}); - htmlColorToRgb.put("darkmagenta", new int[]{139, 0, 139}); - htmlColorToRgb.put("darkolivegreen", new int[]{85, 107, 47}); - htmlColorToRgb.put("darkorange", new int[]{255, 140, 0}); - htmlColorToRgb.put("darkorchid", new int[]{153, 50, 204}); - htmlColorToRgb.put("darkred", new int[]{139, 0, 0}); - htmlColorToRgb.put("darksalmon", new int[]{233, 150, 122}); - htmlColorToRgb.put("darkviolet", new int[]{148, 0, 211}); - htmlColorToRgb.put("fuchsia", new int[]{255, 0, 255}); - htmlColorToRgb.put("gold", new int[]{255, 215, 0}); - htmlColorToRgb.put("green", new int[]{0, 128, 0}); - htmlColorToRgb.put("indigo", new int[]{75, 0, 130}); - htmlColorToRgb.put("khaki", new int[]{240, 230, 140}); - htmlColorToRgb.put("lightblue", new int[]{173, 216, 230}); - htmlColorToRgb.put("lightcyan", new int[]{224, 255, 255}); - htmlColorToRgb.put("lightgreen", new int[]{144, 238, 144}); - htmlColorToRgb.put("lightgrey", new int[]{211, 211, 211}); - htmlColorToRgb.put("lightpink", new int[]{255, 182, 193}); - htmlColorToRgb.put("lightyellow", new int[]{255, 255, 224}); - htmlColorToRgb.put("lime", new int[]{0, 255, 0}); - htmlColorToRgb.put("magenta", new int[]{255, 0, 255}); - htmlColorToRgb.put("maroon", new int[]{128, 0, 0}); - htmlColorToRgb.put("navy", new int[]{0, 0, 128}); - htmlColorToRgb.put("olive", new int[]{128, 128, 0}); - htmlColorToRgb.put("orange", new int[]{255, 165, 0}); - htmlColorToRgb.put("pink", new int[]{255, 192, 203}); - htmlColorToRgb.put("purple", new int[]{128, 0, 128}); - htmlColorToRgb.put("violet", new int[]{128, 0, 128}); - htmlColorToRgb.put("red", new int[]{255, 0, 0}); - htmlColorToRgb.put("silver", new int[]{192, 192, 192}); - htmlColorToRgb.put("white", new int[]{255, 255, 255}); - htmlColorToRgb.put("yellow", new int[]{255, 255, 0}); + htmlColorToRgb.put("white", new int[] {255, 255, 255}); + htmlColorToRgb.put("aqua", new int[] {0, 255, 255}); + htmlColorToRgb.put("azure", new int[] {240, 255, 255}); + htmlColorToRgb.put("beige", new int[] {245, 245, 220}); + htmlColorToRgb.put("black", new int[] {0, 0, 0}); + htmlColorToRgb.put("blue", new int[] {0, 0, 255}); + htmlColorToRgb.put("brown", new int[] {165, 42, 42}); + htmlColorToRgb.put("cyan", new int[] {0, 255, 255}); + htmlColorToRgb.put("darkblue", new int[] {0, 0, 139}); + htmlColorToRgb.put("darkcyan", new int[] {0, 139, 139}); + htmlColorToRgb.put("darkgrey", new int[] {169, 169, 169}); + htmlColorToRgb.put("darkgreen", new int[] {0, 100, 0}); + htmlColorToRgb.put("darkkhaki", new int[] {189, 183, 107}); + htmlColorToRgb.put("darkmagenta", new int[] {139, 0, 139}); + htmlColorToRgb.put("darkolivegreen", new int[] {85, 107, 47}); + htmlColorToRgb.put("darkorange", new int[] {255, 140, 0}); + htmlColorToRgb.put("darkorchid", new int[] {153, 50, 204}); + htmlColorToRgb.put("darkred", new int[] {139, 0, 0}); + htmlColorToRgb.put("darksalmon", new int[] {233, 150, 122}); + htmlColorToRgb.put("darkviolet", new int[] {148, 0, 211}); + htmlColorToRgb.put("fuchsia", new int[] {255, 0, 255}); + htmlColorToRgb.put("gold", new int[] {255, 215, 0}); + htmlColorToRgb.put("green", new int[] {0, 128, 0}); + htmlColorToRgb.put("indigo", new int[] {75, 0, 130}); + htmlColorToRgb.put("khaki", new int[] {240, 230, 140}); + htmlColorToRgb.put("lightblue", new int[] {173, 216, 230}); + htmlColorToRgb.put("lightcyan", new int[] {224, 255, 255}); + htmlColorToRgb.put("lightgreen", new int[] {144, 238, 144}); + htmlColorToRgb.put("lightgrey", new int[] {211, 211, 211}); + htmlColorToRgb.put("lightpink", new int[] {255, 182, 193}); + htmlColorToRgb.put("lightyellow", new int[] {255, 255, 224}); + htmlColorToRgb.put("lime", new int[] {0, 255, 0}); + htmlColorToRgb.put("magenta", new int[] {255, 0, 255}); + htmlColorToRgb.put("maroon", new int[] {128, 0, 0}); + htmlColorToRgb.put("navy", new int[] {0, 0, 128}); + htmlColorToRgb.put("olive", new int[] {128, 128, 0}); + htmlColorToRgb.put("orange", new int[] {255, 165, 0}); + htmlColorToRgb.put("pink", new int[] {255, 192, 203}); + htmlColorToRgb.put("purple", new int[] {128, 0, 128}); + htmlColorToRgb.put("violet", new int[] {128, 0, 128}); + htmlColorToRgb.put("red", new int[] {255, 0, 0}); + htmlColorToRgb.put("silver", new int[] {192, 192, 192}); + htmlColorToRgb.put("white", new int[] {255, 255, 255}); + htmlColorToRgb.put("yellow", new int[] {255, 255, 0}); } protected int[] endColor; @@ -271,9 +273,9 @@ public class Fx { double ret = (start + ((end - start) * progress)); String val = ("px".equals(unit) ? ((int) ret) : ret) + unit; if ("scrollTop".equals(cssprop)) { - g.scrollTop((int)ret); + g.scrollTop((int) ret); } else if ("scrollLeft".equals(cssprop)) { - g.scrollLeft((int)ret); + g.scrollLeft((int) ret); } else if (attribute != null) { g.attr(attribute, val); } else { 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 index 56d64d24..e5a4c8f6 100644 --- 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 @@ -39,6 +39,7 @@ public class PropertiesAnimation extends GQAnimation { */ public interface Easing { double interpolate(double progress); + /** * @deprecated use EasingCurve.linear instead */ @@ -73,71 +74,89 @@ public class PropertiesAnimation extends GQAnimation { * */ public static enum EasingCurve implements Easing { - linear (0, 0, 1, 1) { - public double interpolate(double p){return p;} - public String toString() {return "linear";} - }, - ease (0.25, 0.1, 0.25, 1) { - public String toString() {return "ease";} - }, - easeIn (0.42, 0, 1, 1) { - public String toString() {return "ease-in";} - }, - easeOut (0, 0, 0.58, 1) { - public String toString() {return "ease-out";} - }, - easeInOut (0.42, 0, 0.58, 1) { - public String toString() {return "ease-in-out";} - }, - snap (0,1,.5,1), - swing (.02,.01,.47,1), - easeInCubic (.550,.055,.675,.190), - easeOutCubic (.215,.61,.355,1), - easeInOutCubic (.645,.045,.355,1), - easeInCirc (.6,.04,.98,.335), - easeOutCirc (.075,.82,.165,1), - easeInOutCirc (.785,.135,.15,.86), - easeInExpo (.95,.05,.795,.035), - easeOutExpo (.19,1,.22,1), - easeInOutExpo (1,0,0,1), - easeInQuad (.55,.085,.68,.53), - easeOutQuad (.25,.46,.45,.94), - easeInOutQuad (.455,.03,.515,.955), - easeInQuart (.895,.03,.685,.22), - easeOutQuart (.165,.84,.44,1), - easeInOutQuart (.77,0,.175,1), - easeInQuint (.755,.05,.855,.06), - easeOutQuint (.23,1,.32,1), - easeInOutQuint (.86,0,.07,1), - easeInSine (.47,0,.745,.715), - easeOutSine (.39,.575,.565,1), - easeInOutSine (.445,.05,.55,.95), - easeInBack (.6,-.28,.735,.045), - easeOutBack (.175, .885,.32,1.275), - easeInOutBack (.68,-.55,.265,1.55), - custom(0, 0, 1, 1); - - private Bezier c = new Bezier(0, 0, 1, 1); - EasingCurve(double x1, double y1, double x2, double y2) { - with(x1, y1, x2, y2); - } - public Easing with(double x1, double y1, double x2, double y2) { - c = new Bezier(x1, y1, x2, y2); - return this; - } - public double interpolate(double progress) { - return c.f(progress); - } - public String toString() { + linear(0, 0, 1, 1) { + public double interpolate(double p) { + return p; + } + + public String toString() { + return "linear"; + } + }, + ease(0.25, 0.1, 0.25, 1) { + public String toString() { + return "ease"; + } + }, + easeIn(0.42, 0, 1, 1) { + public String toString() { + return "ease-in"; + } + }, + easeOut(0, 0, 0.58, 1) { + public String toString() { + return "ease-out"; + } + }, + easeInOut(0.42, 0, 0.58, 1) { + public String toString() { + return "ease-in-out"; + } + }, + snap(0, 1, .5, 1), + swing(.02, .01, .47, 1), + easeInCubic(.550, .055, .675, .190), + easeOutCubic(.215, .61, .355, 1), + easeInOutCubic(.645, .045, .355, 1), + easeInCirc(.6, .04, .98, .335), + easeOutCirc(.075, .82, .165, 1), + easeInOutCirc(.785, .135, .15, .86), + easeInExpo(.95, .05, .795, .035), + easeOutExpo(.19, 1, .22, 1), + easeInOutExpo(1, 0, 0, 1), + easeInQuad(.55, .085, .68, .53), + easeOutQuad(.25, .46, .45, .94), + easeInOutQuad(.455, .03, .515, .955), + easeInQuart(.895, .03, .685, .22), + easeOutQuart(.165, .84, .44, 1), + easeInOutQuart(.77, 0, .175, 1), + easeInQuint(.755, .05, .855, .06), + easeOutQuint(.23, 1, .32, 1), + easeInOutQuint(.86, 0, .07, 1), + easeInSine(.47, 0, .745, .715), + easeOutSine(.39, .575, .565, 1), + easeInOutSine(.445, .05, .55, .95), + easeInBack(.6, -.28, .735, .045), + easeOutBack(.175, .885, .32, 1.275), + easeInOutBack(.68, -.55, .265, 1.55), + custom(0, 0, 1, 1); + + private Bezier c = new Bezier(0, 0, 1, 1); + + EasingCurve(double x1, double y1, double x2, double y2) { + with(x1, y1, x2, y2); + } + + public Easing with(double x1, double y1, double x2, double y2) { + c = new Bezier(x1, y1, x2, y2); + return this; + } + + public double interpolate(double progress) { + return c.f(progress); + } + + public String toString() { return "cubic-bezier(" + c + ")"; - } - } + } + } - protected static final String[] ATTRS_TO_SAVE = new String[]{"overflow"}; + protected static final String[] ATTRS_TO_SAVE = new String[] {"overflow"}; private static final RegExp REGEX_NUMBER_UNIT = RegExp.compile("^([0-9+-.]+)(.*)?$"); - protected static final RegExp REGEX_SYMBOL_NUMBER_UNIT = RegExp.compile("^([+-]=)?([0-9+-.]+)(.*)?$"); + protected static final RegExp REGEX_SYMBOL_NUMBER_UNIT = RegExp + .compile("^([+-]=)?([0-9+-.]+)(.*)?$"); protected static final RegExp REGEX_NON_PIXEL_ATTRS = RegExp.compile("z-?index|font-?weight|opacity|zoom|line-?height|scale|rotation|^\\$", "i"); @@ -146,7 +165,7 @@ public class PropertiesAnimation extends GQAnimation { private static final RegExp REGEX_BORDERCOLOR = RegExp.compile("^bordercolor$", "i"); - private static final RegExp REGEX_BACKGROUNDCOLOR =RegExp.compile("^backgroundcolor$", "i"); + private static final RegExp REGEX_BACKGROUNDCOLOR = RegExp.compile("^backgroundcolor$", "i"); public static Fx computeFxProp(Element e, String key, String val, boolean hidden) { @@ -170,7 +189,8 @@ public class PropertiesAnimation extends GQAnimation { // transparent) Element current = e; - while ((initialColor == null || initialColor.length() == 0 || initialColor.equals("transparent")) + while ((initialColor == null || initialColor.length() == 0 || initialColor + .equals("transparent")) && current != null) { initialColor = GQuery.$(current).css(key, false); current = !"body".equalsIgnoreCase(current.getTagName()) @@ -248,7 +268,7 @@ public class PropertiesAnimation extends GQAnimation { if (rkey == null) { unit = REGEX_NON_PIXEL_ATTRS.test(key) ? "" : // - p3 == null || p3.isEmpty() ? "px" : p3; + p3 == null || p3.isEmpty() ? "px" : p3; if (!"px".equals(unit)) { double to = end == 0 ? 1 : end; g.css(key, to + unit); @@ -298,7 +318,7 @@ public class PropertiesAnimation extends GQAnimation { @Override public void onCancel() { Boolean jumpToEnd = Effects.$(e).data(Effects.JUMP_TO_END, Boolean.class); - if (jumpToEnd != null && jumpToEnd){ + if (jumpToEnd != null && jumpToEnd) { onComplete(); } else { g.dequeue(); 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 index 9abb5a96..fe99fb7b 100644 --- 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 @@ -30,15 +30,15 @@ public class ButtonWidgetFactory implements WidgetFactory