From 37b548a54f2d5f7f7bcd561376287564706e429c Mon Sep 17 00:00:00 2001 From: Manolo Carrasco Date: Mon, 25 Oct 2010 07:16:40 +0000 Subject: deleted stars example which was moved to gwtquery-plugins, and little changes to samples module --- .../java/gwtquery/samples/GwtQueryPlugin.gwt.xml | 6 - .../samples/client/GwtQueryBenchModule.java | 185 +++++++++--------- .../samples/client/GwtQueryPluginModule.java | 37 ---- .../samples/client/GwtQuerySampleModule.java | 10 + .../gwtquery/samples/public/GwtQueryBench.html | 13 +- .../gwtquery/samples/public/GwtQueryPlugin.html | 206 --------------------- .../gwtquery/samples/public/html/gwtbench.html | 4 + .../gwtquery/samples/public/html/iframebench.html | 4 + 8 files changed, 122 insertions(+), 343 deletions(-) delete mode 100644 samples/src/main/java/gwtquery/samples/GwtQueryPlugin.gwt.xml delete mode 100644 samples/src/main/java/gwtquery/samples/client/GwtQueryPluginModule.java delete mode 100644 samples/src/main/java/gwtquery/samples/public/GwtQueryPlugin.html (limited to 'samples/src/main/java') diff --git a/samples/src/main/java/gwtquery/samples/GwtQueryPlugin.gwt.xml b/samples/src/main/java/gwtquery/samples/GwtQueryPlugin.gwt.xml deleted file mode 100644 index 352c5c66..00000000 --- a/samples/src/main/java/gwtquery/samples/GwtQueryPlugin.gwt.xml +++ /dev/null @@ -1,6 +0,0 @@ - - - - - - diff --git a/samples/src/main/java/gwtquery/samples/client/GwtQueryBenchModule.java b/samples/src/main/java/gwtquery/samples/client/GwtQueryBenchModule.java index 99ff78c4..7f00702f 100644 --- a/samples/src/main/java/gwtquery/samples/client/GwtQueryBenchModule.java +++ b/samples/src/main/java/gwtquery/samples/client/GwtQueryBenchModule.java @@ -18,11 +18,11 @@ import com.google.gwt.query.client.impl.SelectorEngineNative; import com.google.gwt.query.client.impl.SelectorEngineNativeIE8; import com.google.gwt.query.client.impl.SelectorEngineSizzle; import com.google.gwt.query.client.impl.SelectorEngineSizzleGwt; +import com.google.gwt.query.client.impl.SelectorEngineSizzleIE; import com.google.gwt.query.client.impl.SelectorEngineXPath; import com.google.gwt.user.client.DOM; import com.google.gwt.user.client.DeferredCommand; import com.google.gwt.user.client.IncrementalCommand; -import com.google.gwt.user.client.Timer; import com.google.gwt.user.client.Window; import com.google.gwt.user.client.ui.FlexTable; import com.google.gwt.user.client.ui.HTML; @@ -46,17 +46,42 @@ import com.google.gwt.user.client.ui.RootPanel; * min=200 Minimum time running each selector * track=false Don't draw the horse race * ask=false Run default benchmarks, don't ask the user. - * wait=6000 Number of milliseconds to wait to insert the test html stuff in the iframes - * */ public class GwtQueryBenchModule implements EntryPoint { - + public interface Benchmark { String getId(); String getName(); int runSelector(DeferredGQuery dq); } + /** + * Benchmark for dynamic selectors + */ + private class DynamicBenchmark implements Benchmark { + + protected SelectorEngineImpl engine; + private String id; + + DynamicBenchmark(SelectorEngineImpl engine, String name) { + this.id = name; + this.engine = engine; + } + + public String getId() { + return id; + } + + public String getName() { + String name = engine.getClass().getName().replaceAll("^.*\\.", ""); + return name; + } + + public int runSelector(DeferredGQuery dq) { + return engine.select(dq.getSelector(), gwtiframe).getLength(); + } + } + /** * Benchmark for the compiled selectors */ @@ -73,10 +98,6 @@ public class GwtQueryBenchModule implements EntryPoint { return id; } - public int runSelector(DeferredGQuery dq) { - return dq.array(gwtiframe).getLength(); - } - public String getName() { if (name == null) { MySelectors s = GWT.create(MySelectors.class); @@ -88,35 +109,12 @@ public class GwtQueryBenchModule implements EntryPoint { } return name; } - } - - /** - * Benchmark for dynamic selectors - */ - private class DynamicBenchmark implements Benchmark { - - protected SelectorEngineImpl engine; - private String id; - - DynamicBenchmark(SelectorEngineImpl engine, String name) { - this.id = name; - this.engine = engine; - } - - public String getId() { - return id; - } public int runSelector(DeferredGQuery dq) { - return engine.select(dq.getSelector(), gwtiframe).getLength(); - } - - public String getName() { - String name = engine.getClass().getName().replaceAll("^.*\\.", ""); - return name; + return dq.array(gwtiframe).getLength(); } } - + /** * Benchmark for external libraries */ @@ -131,6 +129,10 @@ public class GwtQueryBenchModule implements EntryPoint { return id; } + public String getName() { + return id; + } + public int runSelector(DeferredGQuery dq) { return runSelector(id, dq.getSelector()); } @@ -138,20 +140,26 @@ public class GwtQueryBenchModule implements EntryPoint { public native int runSelector(String id, String selector) /*-{ return eval("$wnd." + id + "benchmark('" + selector + "')"); }-*/; - - public String getName() { - return id; - } } - private int min_time = 200; + public static native void exportIframeReadyCallback(GwtQueryBenchModule bench) /*-{ + $wnd.iframebench_ready_callback = function() { + bench.@gwtquery.samples.client.GwtQueryBenchModule::iframeReadyCallback()(); + }; + }-*/; + + private boolean ask = true; - private boolean shareIframes = true; + private Function askBenchMarks = new Function(){ + public void f() { + if (!running && ask) { + selectPanel.center(); + } else { + runBenchMarks.f(); + } + } + }; - private boolean useTrack = true; - private boolean ask = true; - private int waitToLoad = 6000; - /** * List of available benchmarks. */ @@ -159,6 +167,7 @@ public class GwtQueryBenchModule implements EntryPoint { new GQueryCompiledBenchmark("gwt_compiled"), new DynamicBenchmark((SelectorEngineImpl)GWT.create(SelectorEngineImpl.class), "gwt_dynamic"), new DynamicBenchmark(new SelectorEngineSizzle(), "gwt_sizzle_jsni"), + new DynamicBenchmark(new SelectorEngineSizzleIE(), "gwt_sizzle_ie_jsni"), new DynamicBenchmark(new SelectorEngineSizzleGwt(), "gwt_sizzle_java"), new DynamicBenchmark(new SelectorEngineJS(), "gwt_domassist_java"), new DynamicBenchmark(new SelectorEngineXPath(), "gwt_xpath"), @@ -171,34 +180,35 @@ public class GwtQueryBenchModule implements EntryPoint { new IframeBenchmark("sizzle"), new IframeBenchmark("domassistant") }; - /** * Pre-selected benchmarks */ private String[] defaultBenchmarks = {"gwt_compiled", "gwt_dynamic", "jquery", "prototype", "dojo"}; private DeferredGQuery dg[]; - private FlexTable grid = new FlexTable(); - private Element gwtiframe; - private Benchmark[] selectedBenchmarks; - private double trackWidth; - private PopupPanel selectPanel = new PopupPanel(); - private Function askBenchMarks = new Function(){ - public void f(Element e) { - selectPanel.center(); - } - }; + private FlexTable grid = new FlexTable(); + private Element gwtiframe; + private int min_time = 200; + private boolean running = false; /** * Main function to run all the selected benchmarks */ private Function runBenchMarks = new Function() { - public void f(Element elem) { + public void f() { + + // Force to stop the race + if (running) { + running = false; + $("#startrace").text("Run Again"); + return; + } + running = true; selectedBenchmarks = readBenchmarkSelection(); selectPanel.hide(); - $("#startrace").hide(); + $("#startrace").text("Stop Race"); $("#results").show(); initResultsTable(dg, selectedBenchmarks); @@ -215,6 +225,10 @@ public class GwtQueryBenchModule implements EntryPoint { double winTime = Double.MAX_VALUE; public boolean execute() { + // The race has been stopped + if (!running) { + return false; + } if (benchMarkNumber >= selectedBenchmarks.length) { benchMarkNumber = 0; numCalls = 0; @@ -239,7 +253,7 @@ public class GwtQueryBenchModule implements EntryPoint { d(selectorNumber, i, (((int) (totalTimes[i] * 100)) / 100.0) + " ms"); if (totalTimes[i] <= min) { flagWinner(selectedBenchmarks[i].getId()); - $("#startrace").show(); + $("#startrace").text("Run Again"); setResultClass(selectorNumber, i); } } @@ -278,10 +292,20 @@ public class GwtQueryBenchModule implements EntryPoint { }); } }; + private Benchmark[] selectedBenchmarks; + private PopupPanel selectPanel = new PopupPanel(); + private boolean shareIframes = true; - private static native String showCapabilities() /*-{ - return window + " " + $wnd + " " + document.querySelectorAll + " " + $doc.querySelectorAll; - }-*/; + private double trackWidth; + + private boolean useTrack = true; + + public void iframeReadyCallback() { + writeTestContent($(".ibench").contents().find("body").get(0)); + gwtiframe = $(".ibench").eq(0).contents().get(0); + $("#startrace").text("Start Race"); + $("#startrace").click(ask ? askBenchMarks: runBenchMarks); + } /** * EntryPoint @@ -290,9 +314,6 @@ public class GwtQueryBenchModule implements EntryPoint { final MySelectors m = GWT.create(MySelectors.class); - System.out.println(showCapabilities()); - System.out.println($("body")); - dg = m.getAllSelectors(); String par = Window.Location.getParameter("min"); @@ -311,28 +332,25 @@ public class GwtQueryBenchModule implements EntryPoint { if (par != null && "false".equals(par)) { ask = false; } - par = Window.Location.getParameter("wait"); - if (par != null) { - waitToLoad = Integer.parseInt(par); - } + exportIframeReadyCallback(this); initSelects(benchmarks); initIFrames(); $("#results").hide(); } + private void d(int selnumber, int benchnumber, double time, int found) { + String text = found < 0 ? "Error" : "" + (((int) (time * 10)) / 10.0) + " ms | " + found + " found"; + d(selnumber, benchnumber, text); + } + private void d(int selnumber, int benchnumber, String text) { grid.setText(selnumber + 1, benchnumber + 1, text); Element td = grid.getCellFormatter().getElement(selnumber + 1, benchnumber + 1); DOM.scrollIntoView((com.google.gwt.user.client.Element) td); } - private void d(int selnumber, int benchnumber, double time, int found) { - String text = found < 0 ? "Error" : "" + (((int) (time * 10)) / 10.0) + " ms | " + found + " found"; - d(selnumber, benchnumber, text); - } - private void flagWinner(String idWinner) { GQuery g = $("#" + idWinner + "horse" + " nobr"); $(".flag").appendTo(g).show(); @@ -355,21 +373,8 @@ public class GwtQueryBenchModule implements EntryPoint { } else { $(i.replaceAll("%ID%", "iframe")).appendTo(document).hide(); } - - $("#startrace").text("Loading ..."); - // Wait a while until the iframe/s have been loaded - new Timer() { - public void run() { - writeTestContent($(".ibench").contents().find("body").get(0)); - gwtiframe = $(".ibench").eq(0).contents().get(0); - $("#startrace").text("Start Race"); - $("#startrace").click(ask ? askBenchMarks: runBenchMarks); - - } - }.schedule(waitToLoad); } - /** * Reset the result table */ @@ -462,11 +467,6 @@ public class GwtQueryBenchModule implements EntryPoint { } } - private void setResultClass(int selNumber, int winNumber) { - Element e = grid.getCellFormatter().getElement(selNumber + 1, winNumber + 1); - $(e).addClass("win").siblings().attr("class", "").addClass("tie").eq(0).removeClass("tie"); - } - private Benchmark[] readBenchmarkSelection() { ArrayList bs = new ArrayList(); for (Element e : $("input", selectPanel.getElement()).elements()) { @@ -481,6 +481,11 @@ public class GwtQueryBenchModule implements EntryPoint { } return bs.toArray(new Benchmark[bs.size()]); } + + private void setResultClass(int selNumber, int winNumber) { + Element e = grid.getCellFormatter().getElement(selNumber + 1, winNumber + 1); + $(e).addClass("win").siblings().attr("class", "").addClass("tie").eq(0).removeClass("tie"); + } /** * This ugly method is used to initialize a huge html String diff --git a/samples/src/main/java/gwtquery/samples/client/GwtQueryPluginModule.java b/samples/src/main/java/gwtquery/samples/client/GwtQueryPluginModule.java deleted file mode 100644 index c9c11394..00000000 --- a/samples/src/main/java/gwtquery/samples/client/GwtQueryPluginModule.java +++ /dev/null @@ -1,37 +0,0 @@ -package gwtquery.samples.client; - -import com.google.gwt.core.client.EntryPoint; -import com.google.gwt.event.dom.client.ClickEvent; -import com.google.gwt.event.dom.client.ClickHandler; -import com.google.gwt.query.client.Function; -import static com.google.gwt.query.client.GQuery.$; -import com.google.gwt.user.client.Event; -import com.google.gwt.user.client.Window; - -import gwtquery.plugins.collapser.Collapser; -import static gwtquery.plugins.ratings.Ratings.Ratings; -import static gwtquery.plugins.widgets.Widgets.Widgets; - -public class GwtQueryPluginModule implements EntryPoint { - - public void onModuleLoad() { - - $(".outer").eq(0).after(""); - $("#enhance").one(Event.ONCLICK, null, new Function() { - @Override - public boolean f(Event e) { - $(e).attr("disabled", "true"); - $("input").as(Ratings).rating(); - return true; - } - }); - $(".btn:nth-child(odd)").as(Widgets).button() - .addClickHandler(new ClickHandler() { - public void onClick(ClickEvent clickEvent) { - Window.alert("You Clicked the Button"); - } - }).end(); - - $(".collapsible").as(Collapser.Collapser).apply(); - } -} \ No newline at end of file diff --git a/samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java b/samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java index ce237220..6f69fa80 100644 --- a/samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java +++ b/samples/src/main/java/gwtquery/samples/client/GwtQuerySampleModule.java @@ -1,5 +1,7 @@ package gwtquery.samples.client; +import static com.google.gwt.query.client.GQuery.$; +import static com.google.gwt.query.client.GQuery.document; import static com.google.gwt.query.client.GQuery.lazy; import com.google.gwt.core.client.EntryPoint; @@ -16,12 +18,20 @@ public class GwtQuerySampleModule implements EntryPoint { } public void onModuleLoad() { + // Use compiled selectors Sample s = GWT.create(Sample.class); + + // Just a simple usage of dom manipulation, events, and lazy usage s.allNotes().text("Hello Google I/O"). css("cursor", "pointer"). toggle( lazy().css("color", "red").done(), lazy().css("color", "").done() ); + + // Cascade effects + $("
content
").appendTo(document).hide().fadeIn(5000).fadeOut(3000); } + + } diff --git a/samples/src/main/java/gwtquery/samples/public/GwtQueryBench.html b/samples/src/main/java/gwtquery/samples/public/GwtQueryBench.html index 50bd5a0c..666fff94 100644 --- a/samples/src/main/java/gwtquery/samples/public/GwtQueryBench.html +++ b/samples/src/main/java/gwtquery/samples/public/GwtQueryBench.html @@ -64,6 +64,12 @@ font-size: 12px; color: white; } + #racefield { + background-image: url(images/bench/grass-texture-small.jpg); + background-repeat: repeat; + -moz-border-radius: 15px; + border-radius: 15px; + } @@ -72,11 +78,10 @@

GWTSpeed - GWT Query benchmarks

-
+
Loading Javascript frameworks, please wait ...

-
-
+
+
diff --git a/samples/src/main/java/gwtquery/samples/public/GwtQueryPlugin.html b/samples/src/main/java/gwtquery/samples/public/GwtQueryPlugin.html deleted file mode 100644 index bd9cd2fc..00000000 --- a/samples/src/main/java/gwtquery/samples/public/GwtQueryPlugin.html +++ /dev/null @@ -1,206 +0,0 @@ - - - GQuery Demo - - - - - - -
-
-

What is this?

- -

- The Star Rating Plugin is a plugin - for the jQuery Javascript library that creates a non-obstrusive - star rating control based on a set of radio input boxes. -

- -

What does it do?

-
    -
  • - It turns a collection of radio boxes into a neat star-rating - control. -
  • -
  • - It creates the interface based on standard form elements, which - means the - basic functionality will still be available even if Javascript - is disabled. -
  • -
  • - NEW (12-Mar-08): - In read only mode (using the 'readOnly' option or - disabled property), the plugin is a neat way of - displaying star-like values without any additional code -
  • -
- -

How do I use it?

- -

- Just add the star class to your radio - boxes -

- - - - - - -
-
<input name="star1" type="radio"
-         class="star"/>
-         <input name="star1" type="radio" class="star"/>
-         <input name="star1" type="radio" class="star"/>
-         <input name="star1" type="radio" class="star"/>
-         <input name="star1" type="radio" class="star"/>
-
» - - - - - -
- -

- Use the checked property to specify - the initial/default value of the control -

- - - - - - -
-
<input name="star2" type="radio"
-         class="star"/>
-         <input name="star2" type="radio" class="star"/>
-         <input name="star2" type="radio" class="star" checked="checked"/>
-         <input name="star2" type="radio" class="star"/>
-         <input name="star2" type="radio" class="star"/>
-
» - - - - - -
- -

- Use the disabled property to use a - control for display purposes only -

- - - - - - -
-
<input name="star3" type="radio"
-         class="star" disabled="disabled"/>
-         <input name="star3" type="radio" class="star" disabled="disabled"/>
-         <input name="star3" type="radio" class="star" disabled="disabled"
-         checked="checked"/>
-         <input name="star3" type="radio" class="star" disabled="disabled"/>
-         <input name="star3" type="radio" class="star" disabled="disabled"/>
-
» - - - - - -
- -

What about split stars and 'half ratings'???

- -

- Use metadata plugin to pass advanced settings to the plugin via the - class property. -

- - - - - - -
-
<input name="adv1" type="radio"
-         class="star {split:4}"/>
-         <input name="adv1" type="radio" class="star {split:4}"/>
-         <input name="adv1" type="radio" class="star {split:4}"/>
-         <input name="adv1" type="radio" class="star {split:4}"/>
-         <input name="adv1" type="radio" class="star {split:4}"
-         checked="checked"/>
-         <input name="adv1" type="radio" class="star {split:4}"/>
-         <input name="adv1" type="radio" class="star {split:4}"/>
-         <input name="adv1" type="radio" class="star
-         {split:4}"/>
-
» - - - - - - - - -
- -

- Use custom selector -

- - - - - - -
- -
$(function(){ // wait for document to
-         load
-         $('input.wow').rating();
-         });
-
<input name="adv2" type="radio"
-         class="wow {split:4}"/>
-         <input name="adv2" type="radio" class="wow {split:4}"/>
-         <input name="adv2" type="radio" class="wow {split:4}"/>
-         <input name="adv2" type="radio" class="wow {split:4}"/>
-         <input name="adv2" type="radio" class="wow {split:4}"
-         checked="checked"/>
-         <input name="adv2" type="radio" class="wow {split:4}"/>
-         <input name="adv2" type="radio" class="wow {split:4}"/>
-         <input name="adv2" type="radio" class="wow
-         {split:4}"/>
-
» - - - - - - - - -
-
- -
- - - - \ No newline at end of file diff --git a/samples/src/main/java/gwtquery/samples/public/html/gwtbench.html b/samples/src/main/java/gwtquery/samples/public/html/gwtbench.html index deb7ac1e..913ae711 100644 --- a/samples/src/main/java/gwtquery/samples/public/html/gwtbench.html +++ b/samples/src/main/java/gwtquery/samples/public/html/gwtbench.html @@ -1,6 +1,10 @@ Gwt + diff --git a/samples/src/main/java/gwtquery/samples/public/html/iframebench.html b/samples/src/main/java/gwtquery/samples/public/html/iframebench.html index 44f42393..f14ef183 100644 --- a/samples/src/main/java/gwtquery/samples/public/html/iframebench.html +++ b/samples/src/main/java/gwtquery/samples/public/html/iframebench.html @@ -32,6 +32,10 @@ return $$(sel).length; } + -- cgit v1.2.3