Commit | Line | Data |
---|---|---|
71ac4733 AV |
1 | package org.danvk; |
2 | ||
3 | import com.google.gwt.core.client.GWT; | |
4 | import com.google.gwt.dom.client.Document; | |
5 | import com.google.gwt.dom.client.ScriptElement; | |
6 | import com.google.gwt.resources.client.ClientBundle; | |
7 | import com.google.gwt.resources.client.TextResource; | |
8 | ||
9 | /** | |
10 | * Methods for installing Dygraphs source in a GWT document. | |
11 | * | |
12 | * @author flooey@google.com (Adam Vartanian) | |
13 | */ | |
14 | public class Dygraphs { | |
15 | ||
16 | // Protected because the GWT compiler has to generate a subclass. | |
17 | protected interface Resources extends ClientBundle { | |
18 | @Source("org/danvk/dygraph-combined.js") | |
19 | TextResource dygraphs(); | |
20 | } | |
21 | ||
22 | private static final Resources RESOURCES = GWT.create(Resources.class); | |
23 | private static boolean installed = false; | |
24 | ||
25 | /** | |
26 | * Install the Dygraphs JavaScript source into the current document. This | |
27 | * method is idempotent. | |
28 | */ | |
29 | public static synchronized void install() { | |
30 | if (!installed) { | |
31 | ScriptElement e = Document.get().createScriptElement(); | |
32 | e.setText(RESOURCES.dygraphs().getText()); | |
33 | Document.get().getBody().appendChild(e); | |
34 | installed = true; | |
35 | } | |
36 | } | |
37 | ||
38 | // Prevent construction | |
39 | private Dygraphs() { } | |
40 | ||
41 | } |