Skip to content

Commit a5f4ab2

Browse files
committed
Added Javadoc comments
1 parent fa9901d commit a5f4ab2

File tree

3 files changed

+115
-12
lines changed

3 files changed

+115
-12
lines changed

processingjs-gwt-sample/src/main/resources/sample/public/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
22
<html>
33
<head>
4-
<title>Dygraphs GWT Sample Application</title>
4+
<title>ProcessingJs-GWT Sample Application</title>
55
<script type="text/javascript" src="processingjsgwtsample.nocache.js"></script>
66
</head>
77
<body>

processingjs-gwt/src/main/java/com/github/timeu/gwtlibs/processingjsgwt/client/Processing.java

Lines changed: 52 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -13,10 +13,15 @@
1313
import com.google.gwt.resources.client.ResourceCallback;
1414
import com.google.gwt.resources.client.ResourceException;
1515
import com.google.gwt.resources.client.TextResource;
16+
import com.google.gwt.safehtml.shared.SafeUri;
1617
import com.google.gwt.user.client.Element;
1718
import com.google.gwt.user.client.ui.Widget;
1819

19-
20+
/**
21+
* Processing wrapper widget around a ProcessingJS sketch
22+
*
23+
* @param <I> This must be an interface or class that extends/implements {@link ProcessingInstance} and is annotated with @JsType
24+
*/
2025
public class Processing <I extends ProcessingInstance> extends Widget {
2126

2227
interface ProcessingClientBundle extends ClientBundle {
@@ -26,21 +31,29 @@ interface ProcessingClientBundle extends ClientBundle {
2631
TextResource processingjs();
2732
}
2833

29-
protected String url;
3034
protected I pInstance;
3135
protected boolean isLoaded = false;
3236
protected final Canvas canvas;
33-
37+
38+
/**
39+
* Creates a Processing widget
40+
*/
3441
public Processing() {
3542
injectScript();
3643
canvas = Canvas.createIfSupported();
3744
setElement(canvas.getElement());
3845
}
3946

40-
public void loadFromUrl(String url,final Runnable onLoad) throws RequestException
47+
/**
48+
* Loads the ProcessingJS sketch from a URL.
49+
*
50+
* @param url URL to the ProcessingJS sketch
51+
* @param onLoad optional callback that is executed when the sketch is loaded
52+
* @throws RequestException if the request to the URL throws an Exception
53+
*/
54+
public void load(SafeUri url,final Runnable onLoad) throws RequestException
4155
{
42-
this.url = url;
43-
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url);
56+
RequestBuilder builder = new RequestBuilder(RequestBuilder.GET, url.asString());
4457
builder.setCallback(new RequestCallback() {
4558

4659
@Override
@@ -56,6 +69,12 @@ public void onError(Request request, Throwable exception) {
5669
builder.send();
5770
}
5871

72+
/**
73+
* Loads a ProcessingJS sketch from an {@link ExternalTextResource}
74+
*
75+
* @param code the code of the ProcessingJS sketch
76+
* @param onLoad optional callback that is executed when the sketch is loaded
77+
*/
5978
public void load(ExternalTextResource code ,final Runnable onLoad) {
6079
try
6180
{
@@ -73,20 +92,37 @@ public void onError(ResourceException e) {
7392
}
7493
catch (Exception e) {}
7594
}
76-
95+
96+
/**
97+
* Loads a ProcessingJS sketch from a String
98+
*
99+
* @param code the code of the ProcessingJS sketch
100+
* @param onLoad optional callback that is executed when the sketch is loaded
101+
*/
77102
public void load(String code,final Runnable onLoad)
78103
{
79104
pInstance = init(code,getElement());
80105
isLoaded = true;
81106
if (onLoad != null)
82107
onLoad.run();
83108
}
84-
109+
110+
/**
111+
* Provides access to the (custom) ProcessingInstance that allows the user
112+
* to interface with the ProcessingJS sketch
113+
*
114+
* @return the actual {@link ProcessingInstance} instance
115+
*/
85116
public I getInstance()
86117
{
87118
return pInstance;
88119
}
89-
120+
121+
/**
122+
* Can be used to check if the sketch is loaded
123+
*
124+
* @return true if the sketch is loaded
125+
*/
90126
public boolean isLoaded()
91127
{
92128
return isLoaded;
@@ -96,8 +132,13 @@ public boolean isLoaded()
96132
protected final native I init(String programm,Element elem) /*-{
97133
return new $wnd.Processing(elem,programm);
98134
}-*/;
99-
100-
135+
136+
137+
/**
138+
* Provides access to the Canvas widget
139+
*
140+
* @return the {@link Canvas} widget
141+
*/
101142
public Canvas getCanvas() {
102143
return canvas;
103144
}

processingjs-gwt/src/main/java/com/github/timeu/gwtlibs/processingjsgwt/client/ProcessingInstance.java

Lines changed: 62 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,71 @@
33
import com.google.gwt.core.client.js.JsType;
44

55

6+
/**
7+
* ProcessingInstance is the base class that is used to interface with the ProcessingJS sketch.
8+
* Every ProcessingJS sketch has some default methods (draw, setup, etc)
9+
* Users should create their own custom interface extending ProcessingInstance and define the API methods
10+
* similar to draw and size. The custom interface must be annotated with {@link @JsType}
11+
*/
612
@JsType
713
public interface ProcessingInstance {
814

15+
/**
16+
* Called once when the program is started. Used to define initial enviroment properties such as screen size, background color, loading images, etc. before the draw() begins executing.
17+
* Variables declared within setup() are not accessible within other functions, includingdraw().
18+
* There can only be one setup() function for each program and it should not be called again after it's initial execution.
19+
*/
20+
void setup();
21+
22+
/**
23+
* Defines the dimension of the display window in units of pixels. The size() function must be the first line in setup().
24+
* If size() is not called, the default size of the window is 100x100 pixels.
25+
* The system variables width and height are set by the parameters passed to the size() function.
26+
*
27+
* @param width width of the sketch
28+
* @param height height of the sketch
29+
*/
930
void size(int width,int height);
31+
32+
/**
33+
* Called directly after setup() and continuously executes the lines of code contained inside its block until the program is stopped or noLoop() is called.
34+
* The draw() function is called automatically and should never be called explicitly.
35+
* It should always be controlled with noLoop(), redraw() and loop().
36+
* After noLoop() stops the code in draw() from executing, redraw() causes the code inside draw() to execute once and loop() will causes the code inside draw() to execute continuously again.
37+
* The number of times draw() executes in each second may be controlled with the delay() and frameRate() functions.
38+
* There can only be one draw() function for each sketch and draw() must exist if you want the code to run continuously or to process events such as mousePressed().
39+
* Sometimes, you might have an empty call to draw() in your program as shown in the above example.
40+
*/
1041
void draw();
42+
43+
/**
44+
* Executes the code within draw() one time.
45+
* This functions allows the program to update the display window only when necessary, for example when an event registered by mousePressed() or keyPressed() occurs.
46+
*
47+
* In structuring a program, it only makes sense to call redraw() within events such as mousePressed().
48+
* This is because redraw() does not run draw() immediately (it only sets a flag that indicates an update is needed).
49+
*
50+
* Calling redraw() within draw() has no effect because draw() is continuously called anyway.
51+
*/
52+
void redraw();
53+
54+
/**
55+
* Stops Processing from continuously executing the code within draw().
56+
* If loop() is called, the code in draw() begin to run continuously again.
57+
* If using noLoop() in setup(), it should be the last line inside the block.
58+
*
59+
* When noLoop() is used, it's not possible to manipulate or access the screen inside event handling functions such as mousePressed() or keyPressed().
60+
* Instead, use those functions to call redraw() or loop(), which will run draw(), which can update the screen properly.
61+
* This means that when noLoop() has been called, no drawing can happen, and functions like saveFrame() or loadPixels() may not be used.
62+
*
63+
* Note that if the sketch is resized, redraw() will be called to update the sketch, even after noLoop() has been specified.
64+
* Otherwise, the sketch would enter an odd state until loop() was called.
65+
*/
66+
void noLoop();
67+
68+
/**
69+
* Causes Processing to continuously execute the code within draw().
70+
* If noLoop() is called, the code in draw() stops executing.
71+
*/
72+
void loop();
1173
}

0 commit comments

Comments
 (0)