propane 3.4.0-java → 3.7.0.pre-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (155) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -2
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +2 -2
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -2
  5. data/.travis.yml +2 -2
  6. data/CHANGELOG.md +12 -0
  7. data/Gemfile +2 -0
  8. data/README.md +17 -8
  9. data/Rakefile +10 -11
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +6 -4
  12. data/lib/propane/app.rb +20 -10
  13. data/lib/propane/creators/sketch_class.rb +7 -1
  14. data/lib/propane/creators/sketch_factory.rb +4 -2
  15. data/lib/propane/creators/sketch_writer.rb +1 -0
  16. data/lib/propane/helper_methods.rb +23 -24
  17. data/lib/propane/helpers/numeric.rb +2 -0
  18. data/lib/propane/helpers/version_error.rb +1 -0
  19. data/lib/propane/library.rb +5 -1
  20. data/lib/propane/library_loader.rb +2 -0
  21. data/lib/propane/native_folder.rb +10 -9
  22. data/lib/propane/native_loader.rb +3 -0
  23. data/lib/propane/runner.rb +14 -6
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +28 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +6 -0
  29. data/library/file_chooser/chooser.rb +10 -9
  30. data/library/file_chooser/file_chooser.rb +10 -9
  31. data/library/library_proxy/library_proxy.rb +2 -0
  32. data/library/net/net.rb +7 -0
  33. data/library/simplex_noise/simplex_noise.rb +2 -0
  34. data/library/slider/slider.rb +23 -22
  35. data/library/vector_utils/vector_utils.rb +4 -0
  36. data/library/video_event/video_event.rb +4 -1
  37. data/pom.rb +37 -36
  38. data/pom.xml +7 -7
  39. data/propane.gemspec +16 -12
  40. data/src/main/java/monkstone/ColorUtil.java +13 -1
  41. data/src/main/java/monkstone/MathToolModule.java +253 -203
  42. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  43. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  44. data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
  45. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  46. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  47. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  48. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  51. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  52. data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
  53. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  54. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  55. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +3 -3
  56. data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
  57. data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
  58. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  59. data/src/main/java/processing/awt/PGraphicsJava2D.java +781 -285
  60. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  61. data/src/main/java/processing/awt/PShapeJava2D.java +56 -52
  62. data/src/main/java/processing/awt/PSurfaceAWT.java +309 -209
  63. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  64. data/src/main/java/processing/core/PApplet.java +4510 -4503
  65. data/src/main/java/processing/core/PConstants.java +477 -447
  66. data/src/main/java/processing/core/PFont.java +914 -880
  67. data/src/main/java/processing/core/PGraphics.java +193 -177
  68. data/src/main/java/processing/core/PImage.java +611 -309
  69. data/src/main/java/processing/core/PMatrix.java +172 -159
  70. data/src/main/java/processing/core/PMatrix2D.java +478 -415
  71. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  72. data/src/main/java/processing/core/PShape.java +2888 -2652
  73. data/src/main/java/processing/core/PShapeOBJ.java +97 -92
  74. data/src/main/java/processing/core/PShapeSVG.java +1705 -1490
  75. data/src/main/java/processing/core/PStyle.java +40 -37
  76. data/src/main/java/processing/core/PSurface.java +139 -97
  77. data/src/main/java/processing/core/PSurfaceNone.java +296 -218
  78. data/src/main/java/processing/core/PVector.java +997 -965
  79. data/src/main/java/processing/core/ThinkDifferent.java +15 -13
  80. data/src/main/java/processing/data/DoubleDict.java +756 -710
  81. data/src/main/java/processing/data/DoubleList.java +749 -696
  82. data/src/main/java/processing/data/FloatDict.java +748 -702
  83. data/src/main/java/processing/data/FloatList.java +751 -697
  84. data/src/main/java/processing/data/IntDict.java +720 -673
  85. data/src/main/java/processing/data/IntList.java +699 -633
  86. data/src/main/java/processing/data/JSONArray.java +931 -873
  87. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  88. data/src/main/java/processing/data/JSONTokener.java +351 -341
  89. data/src/main/java/processing/data/LongDict.java +710 -663
  90. data/src/main/java/processing/data/LongList.java +701 -635
  91. data/src/main/java/processing/data/Sort.java +37 -41
  92. data/src/main/java/processing/data/StringDict.java +525 -486
  93. data/src/main/java/processing/data/StringList.java +626 -580
  94. data/src/main/java/processing/data/Table.java +3690 -3510
  95. data/src/main/java/processing/data/TableRow.java +182 -183
  96. data/src/main/java/processing/data/XML.java +957 -883
  97. data/src/main/java/processing/dxf/RawDXF.java +404 -0
  98. data/src/main/java/processing/event/Event.java +87 -67
  99. data/src/main/java/processing/event/KeyEvent.java +48 -41
  100. data/src/main/java/processing/event/MouseEvent.java +88 -113
  101. data/src/main/java/processing/event/TouchEvent.java +10 -6
  102. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  103. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  104. data/src/main/java/processing/net/Client.java +744 -0
  105. data/src/main/java/processing/net/Server.java +388 -0
  106. data/src/main/java/processing/opengl/FontTexture.java +289 -270
  107. data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
  108. data/src/main/java/processing/opengl/LinePath.java +547 -500
  109. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  110. data/src/main/java/processing/opengl/PGL.java +3047 -2914
  111. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  112. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  113. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  114. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  115. data/src/main/java/processing/opengl/PShader.java +1266 -1257
  116. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  117. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  118. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  119. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  120. data/test/create_test.rb +21 -20
  121. data/test/deglut_spec_test.rb +4 -2
  122. data/test/helper_methods_test.rb +49 -20
  123. data/test/math_tool_test.rb +39 -32
  124. data/test/native_folder.rb +47 -0
  125. data/test/respond_to_test.rb +3 -2
  126. data/test/sketches/key_event.rb +2 -2
  127. data/test/sketches/library/my_library/my_library.rb +3 -0
  128. data/test/test_helper.rb +2 -0
  129. data/test/vecmath_spec_test.rb +35 -22
  130. data/vendors/Rakefile +33 -62
  131. metadata +56 -48
  132. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
  133. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
  134. data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
  135. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
  136. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
  137. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
  138. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
  139. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
  140. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
  141. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
  142. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
  143. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
  144. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
  145. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
  146. data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
  147. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
  148. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
  149. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
  150. data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
  151. data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
  152. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  153. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  154. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  155. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,3 +1,5 @@
1
+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
1
3
  /*
2
4
  Part of the Processing project - http://processing.org
3
5
 
@@ -17,44 +19,45 @@
17
19
  Public License along with this library; if not, write to the
18
20
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
19
21
  Boston, MA 02111-1307 USA
20
- */
22
+ */
23
+
21
24
  package processing.core;
22
25
 
23
- public class PStyle implements PConstants {
24
26
 
25
- public int imageMode;
26
- public int rectMode;
27
- public int ellipseMode;
28
- public int shapeMode;
29
-
30
- public int blendMode;
31
-
32
- public int colorMode;
33
- public float colorModeX;
34
- public float colorModeY;
35
- public float colorModeZ;
36
- public float colorModeA;
37
-
38
- public boolean tint;
39
- public int tintColor;
40
- public boolean fill;
41
- public int fillColor;
42
- public boolean stroke;
43
- public int strokeColor;
44
- public float strokeWeight;
45
- public int strokeCap;
46
- public int strokeJoin;
47
-
48
- // TODO these fellas are inconsistent, and may need to go elsewhere
49
- public float ambientR, ambientG, ambientB;
50
- public float specularR, specularG, specularB;
51
- public float emissiveR, emissiveG, emissiveB;
52
- public float shininess;
53
-
54
- public PFont textFont;
55
- public int textAlign;
56
- public int textAlignY;
57
- public int textMode;
58
- public float textSize;
59
- public float textLeading;
27
+ public class PStyle implements PConstants {
28
+ public int imageMode;
29
+ public int rectMode;
30
+ public int ellipseMode;
31
+ public int shapeMode;
32
+
33
+ public int blendMode;
34
+
35
+ public int colorMode;
36
+ public float colorModeX;
37
+ public float colorModeY;
38
+ public float colorModeZ;
39
+ public float colorModeA;
40
+
41
+ public boolean tint;
42
+ public int tintColor;
43
+ public boolean fill;
44
+ public int fillColor;
45
+ public boolean stroke;
46
+ public int strokeColor;
47
+ public float strokeWeight;
48
+ public int strokeCap;
49
+ public int strokeJoin;
50
+
51
+ // TODO these fellas are inconsistent, and may need to go elsewhere
52
+ public float ambientR, ambientG, ambientB;
53
+ public float specularR, specularG, specularB;
54
+ public float emissiveR, emissiveG, emissiveB;
55
+ public float shininess;
56
+
57
+ public PFont textFont;
58
+ public int textAlign;
59
+ public int textAlignY;
60
+ public int textMode;
61
+ public float textSize;
62
+ public float textLeading;
60
63
  }
@@ -1,3 +1,5 @@
1
+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
1
3
  /*
2
4
  Part of the Processing project - http://processing.org
3
5
 
@@ -16,84 +18,113 @@
16
18
  Public License along with this library; if not, write to the
17
19
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18
20
  Boston, MA 02111-1307 USA
19
- */
21
+ */
22
+
20
23
  package processing.core;
21
24
 
25
+ import java.io.File;
26
+
22
27
  public interface PSurface {
28
+ /**
29
+ * Minimum dimensions for the window holding an applet. This varies between
30
+ * platforms, Mac OS X 10.3 (confirmed with 10.7 and Java 6) can do any
31
+ * height but requires at least 128 pixels width. Windows XP has another
32
+ * set of limitations. And for all I know, Linux probably allows window
33
+ * sizes to be negative numbers.
34
+ */
35
+ static public final int MIN_WINDOW_WIDTH = 128;
36
+ static public final int MIN_WINDOW_HEIGHT = 128;
37
+
38
+ //public int displayDensity();
39
+
40
+ //public int displayDensity(int display);
23
41
 
24
- /**
25
- * Minimum dimensions for the window holding an applet. This varies between
26
- * platforms, Mac OS X 10.3 (confirmed with 10.7 and Java 6) can do any
27
- * height but requires at least 128 pixels width. Windows XP has another set
28
- * of limitations. And for all I know, Linux probably allows window sizes to
29
- * be negative numbers.
30
- */
31
- static public final int MIN_WINDOW_WIDTH = 128;
32
- static public final int MIN_WINDOW_HEIGHT = 128;
33
-
34
- // renderer that doesn't draw to the screen
35
- public void initOffscreen(PApplet sketch);
36
-
37
- // considering removal in favor of separate Component classes for appropriate renderers
38
- // (i.e. for Java2D or a generic Image surface, but not PDF, debatable for GL or )
39
- //public Component initComponent(PApplet sketch);
40
- //public Frame initFrame(PApplet sketch, Color backgroundColor,
42
+ //
43
+
44
+ // renderer that doesn't draw to the screen
45
+ public void initOffscreen(PApplet sketch);
46
+
47
+ // considering removal in favor of separate Component classes for appropriate renderers
48
+ // (i.e. for Java2D or a generic Image surface, but not PDF, debatable for GL or FX)
49
+ //public Component initComponent(PApplet sketch);
50
+
51
+ //public Frame initFrame(PApplet sketch, Color backgroundColor,
41
52
  // public void initFrame(PApplet sketch, int backgroundColor,
42
53
  // int deviceIndex, boolean fullScreen, boolean spanDisplays);
43
- public void initFrame(PApplet sketch);
44
-
45
- /**
46
- * Get the native window object associated with this drawing surface. For
47
- * Java2D, this will be an AWT Frame object. For OpenGL, the window. The
48
- * data returned here is subject to the whims of the renderer, and using
49
- * this method means you're willing to deal with underlying implementation
50
- * changes and that you won't throw a fit like a toddler if your code breaks
51
- * sometime in the future.
52
- */
53
- public Object getNative();
54
-
55
- //
56
- // Just call these on an AWT Frame object stored in PApplet.
57
- // Silly, but prevents a lot of rewrite and extra methods for little benefit.
58
- // However, maybe prevents us from having to document the 'frame' variable?
59
- /**
60
- * Set the window (and dock, or whatever necessary) title.
61
- */
62
- public void setTitle(String title);
63
-
64
- /**
65
- * Show or hide the window.
66
- */
67
- public void setVisible(boolean visible);
68
-
69
- /**
70
- * Set true if we want to resize things (default is not resizable)
71
- */
72
- public void setResizable(boolean resizable);
73
-
74
- /**
75
- * Dumb name, but inherited from Frame and no better ideas.
76
- */
77
- public void setAlwaysOnTop(boolean always);
78
-
79
- public void setIcon(PImage icon);
80
-
81
- //
54
+ public void initFrame(PApplet sketch);
55
+
56
+ //
57
+
58
+ public PImage loadImage(String path, Object... args);
59
+
60
+ //
61
+
62
+ public void selectInput(String prompt, String callback,
63
+ File file, Object callbackObject);
64
+
65
+ public void selectOutput(String prompt, String callback,
66
+ File file, Object callbackObject);
67
+
68
+ public void selectFolder(String prompt, String callback,
69
+ File file, Object callbackObject);
70
+
71
+ //
72
+
73
+ /**
74
+ * Get the native window object associated with this drawing surface.For Java2D, this will be an AWT Frame object.
75
+ * For OpenGL, the window.
76
+ The data returned here is subject to the whims of the renderer,
77
+ and using this method means you're willing to deal with underlying
78
+ implementation changes and that you won't throw a fit like a toddler
79
+ if your code breaks sometime in the future.
80
+ * @return
81
+ */
82
+ public Object getNative();
83
+
84
+ //
85
+
86
+ // Just call these on an AWT Frame object stored in PApplet.
87
+ // Silly, but prevents a lot of rewrite and extra methods for little benefit.
88
+ // However, maybe prevents us from having to document the 'frame' variable?
89
+
90
+ /** Set the window (and dock, or whatever necessary) title.
91
+ * @param title */
92
+ public void setTitle(String title);
93
+
94
+ /** Show or hide the window.
95
+ * @param visible */
96
+ public void setVisible(boolean visible);
97
+
98
+ /** Set true if we want to resize things (default is not resizable)
99
+ * @param resizable */
100
+ public void setResizable(boolean resizable);
101
+
102
+ /** Dumb name, but inherited from Frame and no better ideas.
103
+ * @param always */
104
+ public void setAlwaysOnTop(boolean always);
105
+
106
+ public void setIcon(PImage icon);
107
+
108
+ //
109
+
82
110
  // public void placeWindow(int[] location);
83
- public void placeWindow(int[] location, int[] editorLocation);
84
111
 
85
- //public void placeFullScreen(boolean hideStop);
86
- public void placePresent(int stopColor);
112
+ public void placeWindow(int[] location, int[] editorLocation);
113
+
114
+ //public void placeFullScreen(boolean hideStop);
115
+ public void placePresent(int stopColor);
116
+
117
+ // Sketch is running from the PDE, set up messaging back to the PDE
118
+ public void setupExternalMessages();
119
+
120
+ //
87
121
 
88
- // Sketch is running from the PDE, set up messaging back to the PDE
89
- public void setupExternalMessages();
122
+ // sets displayWidth/Height inside PApplet
123
+ //public void checkDisplaySize();
90
124
 
91
- //
92
- // sets displayWidth/Height inside PApplet
93
- //public void checkDisplaySize();
94
- public void setLocation(int x, int y);
125
+ public void setLocation(int x, int y);
95
126
 
96
- public void setSize(int width, int height);
127
+ public void setSize(int width, int height);
97
128
 
98
129
  // /**
99
130
  // * Called by {@link PApplet#createGraphics} to initialize the
@@ -103,54 +134,65 @@ public interface PSurface {
103
134
  // * @param wide
104
135
  // * @param high
105
136
  // */
106
- // create pixel buffer (pulled out for offscreen graphics)
107
- //public void initImage(PGraphics gr, int wide, int high);
108
- // create pixel buffer, called from allocate() to produce a compatible image for rendering efficiently
137
+ // create pixel buffer (pulled out for offscreen graphics)
138
+ //public void initImage(PGraphics gr, int wide, int high);
139
+ // create pixel buffer, called from allocate() to produce a compatible image for rendering efficiently
109
140
  // public void initImage(PGraphics gr);
110
- //public Component getComponent();
141
+
142
+ //public Component getComponent();
143
+
111
144
  // /**
112
145
  // * Sometimes smoothing must be set at the drawing surface level
113
146
  // * not just inside the renderer itself.
114
147
  // */
115
148
  // public void setSmooth(int level);
116
- public void setFrameRate(float fps);
149
+
150
+ public void setFrameRate(float fps);
117
151
 
118
152
  // // called on the first frame so that the now-visible drawing surface can
119
153
  // // receive key and mouse events
120
154
  // public void requestFocus();
155
+
121
156
  // // finish rendering to the screen (called by PApplet)
122
157
  // public void blit();
123
- //
124
- public void setCursor(int kind);
125
158
 
126
- public void setCursor(PImage image, int hotspotX, int hotspotY);
159
+ //
160
+
161
+ public void setCursor(int kind);
162
+
163
+ public void setCursor(PImage image, int hotspotX, int hotspotY);
164
+
165
+ public void showCursor();
166
+
167
+ public void hideCursor();
168
+
169
+ //
127
170
 
128
- public void showCursor();
171
+ /**
172
+ * @param url the link to open
173
+ * @return false if unable to find a viable way to open
174
+ */
175
+ public boolean openLink(String url);
129
176
 
130
- public void hideCursor();
177
+ //
131
178
 
132
- //
133
- /**
134
- * Start the animation thread
135
- */
136
- public void startThread();
179
+ /** Start the animation thread */
180
+ public void startThread();
137
181
 
138
- /**
139
- * On the next trip through the animation thread, things should go
140
- * sleepy-bye. Does not pause the thread immediately because that needs to
141
- * happen on the animation thread itself, so fires on the next trip through
142
- * draw().
143
- */
144
- public void pauseThread();
182
+ /**
183
+ * On the next trip through the animation thread, things should go sleepy-bye.
184
+ * Does not pause the thread immediately because that needs to happen on the
185
+ * animation thread itself, so fires on the next trip through draw().
186
+ */
187
+ public void pauseThread();
145
188
 
146
- public void resumeThread();
189
+ public void resumeThread();
147
190
 
148
- /**
149
- * Stop the animation thread (set it null)
150
- *
151
- * @return false if already stopped
152
- */
153
- public boolean stopThread();
191
+ /**
192
+ * Stop the animation thread (set it null)
193
+ * @return false if already stopped
194
+ */
195
+ public boolean stopThread();
154
196
 
155
- public boolean isStopped();
197
+ public boolean isStopped();
156
198
  }
@@ -1,3 +1,5 @@
1
+ /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
+
1
3
  /*
2
4
  Part of the Processing project - http://processing.org
3
5
 
@@ -16,248 +18,320 @@
16
18
  Public License along with this library; if not, write to the
17
19
  Free Software Foundation, Inc., 59 Temple Place, Suite 330,
18
20
  Boston, MA 02111-1307 USA
19
- */
21
+ */
22
+
20
23
  package processing.core;
21
24
 
25
+ import java.io.File;
26
+
27
+ import processing.awt.ShimAWT;
28
+
22
29
  /**
23
30
  * Surface that's not really visible. Used for PDF and friends, or as a base
24
31
  * class for other drawing surfaces. It includes the standard rendering loop.
25
32
  */
26
33
  public class PSurfaceNone implements PSurface {
34
+ protected PApplet sketch;
35
+ protected PGraphics graphics;
27
36
 
28
- protected PApplet sketch;
29
- protected PGraphics graphics;
37
+ protected Thread thread;
38
+ protected boolean paused;
39
+ protected Object pauseObject = new Object();
30
40
 
31
- protected Thread thread;
32
- protected boolean paused;
33
- protected Object pauseObject = new Object();
41
+ protected float frameRateTarget = 60;
42
+ protected long frameRatePeriod = 1000000000L / 60L;
34
43
 
35
- protected float frameRateTarget = 60;
36
- protected long frameRatePeriod = 1000000000L / 60L;
37
44
 
38
- public PSurfaceNone(PGraphics graphics) {
39
- this.graphics = graphics;
40
- }
45
+ public PSurfaceNone(PGraphics graphics) {
46
+ this.graphics = graphics;
47
+ }
41
48
 
42
- @Override
43
- public void initOffscreen(PApplet sketch) {
44
- this.sketch = sketch;
45
49
 
46
- setSize(sketch.sketchWidth(), sketch.sketchHeight());
47
- }
50
+ public int displayDensity() {
51
+ return 1;
52
+ }
53
+
54
+
55
+ public int displayDensity(int display) {
56
+ return 1;
57
+ }
58
+
59
+
60
+ @Override
61
+ public PImage loadImage(String path, Object... args) {
62
+ return ShimAWT.loadImage(sketch, path, args);
63
+ }
64
+
65
+
66
+ @Override
67
+ public void selectInput(String prompt, String callback, File file,
68
+ Object callbackObject) {
69
+ }
70
+
71
+
72
+ @Override
73
+ public void selectOutput(String prompt, String callback, File file,
74
+ Object callbackObject) {
75
+ }
76
+
77
+
78
+ @Override
79
+ public void selectFolder(String prompt, String callback, File file,
80
+ Object callbackObject) {
81
+ }
82
+
83
+
84
+ @Override
85
+ public void initOffscreen(PApplet sketch) {
86
+ this.sketch = sketch;
87
+
88
+ setSize(sketch.sketchWidth(), sketch.sketchHeight());
89
+ }
90
+
48
91
 
49
92
  // public Component initComponent(PApplet sketch) {
50
93
  // return null;
51
94
  // }
52
- @Override
53
- public void initFrame(PApplet sketch) {
54
- throw new IllegalStateException("initFrame() not available with "
55
- + getClass().getSimpleName());
56
- }
57
95
 
58
- @Override
59
- public Object getNative() {
60
- return null;
61
- }
62
96
 
63
- /**
64
- * Set the window (and dock, or whatever necessary) title.
65
- */
66
- @Override
67
- public void setTitle(String title) {
68
- // You're in a utopian PSurface implementation where titles don't exist.
69
- }
97
+ @Override
98
+ public void initFrame(PApplet sketch) {
99
+ throw new IllegalStateException("initFrame() not available with " +
100
+ getClass().getSimpleName());
101
+ }
70
102
 
71
- @Override
72
- public void setIcon(PImage image) {
73
- // I ain't visible, man.
74
- }
75
103
 
76
- /**
77
- * Show or hide the window.
78
- */
79
- @Override
80
- public void setVisible(boolean visible) {
81
- // I'm always invisible. You can't catch me.
82
- }
104
+ @Override
105
+ public Object getNative() {
106
+ return null;
107
+ }
83
108
 
84
- /**
85
- * Set true if we want to resize things (default is not resizable)
86
- */
87
- @Override
88
- public void setResizable(boolean resizable) {
89
- // I don't need size to know my worth.
90
- }
91
109
 
92
- @Override
93
- public void placeWindow(int[] location, int[] editorLocation) {
94
- }
110
+ /** Set the window (and dock, or whatever necessary) title.
111
+ * @param title */
112
+ @Override
113
+ public void setTitle(String title) {
114
+ // You're in a utopian PSurface implementation where titles don't exist.
115
+ }
95
116
 
96
- @Override
97
- public void placePresent(int stopColor) {
98
- }
99
117
 
100
- @Override
101
- public void setupExternalMessages() {
102
- }
118
+ @Override
119
+ public void setIcon(PImage image) {
120
+ // I ain't visible, man.
121
+ }
103
122
 
104
- @Override
105
- public void setAlwaysOnTop(boolean always) {
106
- }
107
123
 
108
- //
109
- @Override
110
- public void setLocation(int x, int y) {
111
- // I'm everywhere, because I'm nowhere.
112
- }
124
+ /** Show or hide the window.
125
+ * @param visible */
126
+ @Override
127
+ public void setVisible(boolean visible) {
128
+ // I'm always invisible. You can't catch me.
129
+ }
113
130
 
114
- @Override
115
- public void setSize(int wide, int high) {
116
- if (PApplet.DEBUG) {
117
- //System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high);
118
- new Exception(String.format("setSize(%d, %d)", wide, high)).printStackTrace(System.out);
119
- }
120
131
 
121
- //if (wide == sketchWidth && high == sketchHeight) { // doesn't work on launch
122
- if (wide == sketch.width && high == sketch.height) {
123
- if (PApplet.DEBUG) {
124
- new Exception("w/h unchanged " + wide + " " + high).printStackTrace(System.out);
125
- }
126
- return; // unchanged, don't rebuild everything
127
- }
132
+ /** Set true if we want to resize things (default is not resizable)
133
+ * @param resizable */
134
+ @Override
135
+ public void setResizable(boolean resizable) {
136
+ // I don't need size to know my worth.
137
+ }
138
+
139
+
140
+ @Override
141
+ public void placeWindow(int[] location, int[] editorLocation) { }
142
+
143
+
144
+ @Override
145
+ public void placePresent(int stopColor) { }
146
+
147
+
148
+ @Override
149
+ public void setupExternalMessages() { }
150
+
151
+
152
+ @Override
153
+ public void setAlwaysOnTop(boolean always) { }
128
154
 
129
- //throw new RuntimeException("implement me, see readme.md");
130
- sketch.width = wide;
131
- sketch.height = high;
132
155
 
133
- // set PGraphics variables for width/height/pixelWidth/pixelHeight
134
- graphics.setSize(wide, high);
156
+ //
157
+
158
+
159
+ @Override
160
+ public void setLocation(int x, int y) {
161
+ // I'm everywhere, because I'm nowhere.
162
+ }
163
+
164
+
165
+ @Override
166
+ public void setSize(int wide, int high) {
167
+ if (PApplet.DEBUG) {
168
+ //System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high);
169
+ new Exception(String.format("setSize(%d, %d)", wide, high)).printStackTrace(System.out);
135
170
  }
136
171
 
172
+ //if (wide == sketchWidth && high == sketchHeight) { // doesn't work on launch
173
+ if (wide == sketch.width && high == sketch.height) {
174
+ if (PApplet.DEBUG) {
175
+ new Exception("w/h unchanged " + wide + " " + high).printStackTrace(System.out);
176
+ }
177
+ return; // unchanged, don't rebuild everything
178
+ }
179
+
180
+ //throw new RuntimeException("implement me, see readme.md");
181
+ sketch.width = wide;
182
+ sketch.height = high;
183
+
184
+ // set PGraphics variables for width/height/pixelWidth/pixelHeight
185
+ graphics.setSize(wide, high);
186
+ }
187
+
188
+
137
189
  // public void initImage(PGraphics graphics) {
138
190
  // // TODO Auto-generated method stub
139
191
  //
140
192
  // }
193
+
141
194
  // public Component getComponent() {
142
195
  // return null;
143
196
  // }
197
+
198
+
144
199
  // public void setSmooth(int level) {
145
200
  // // TODO Auto-generated method stub
146
201
  // }
202
+
147
203
  // void requestFocus() {
148
204
  // }
205
+
149
206
  // public void blit() {
150
207
  // // TODO Auto-generated method stub
151
208
  // }
152
- @Override
153
- public void setCursor(int kind) {
154
- }
155
209
 
156
- @Override
157
- public void setCursor(PImage image, int hotspotX, int hotspotY) {
158
- }
210
+ @Override
211
+ public void setCursor(int kind) { }
159
212
 
160
- @Override
161
- public void showCursor() {
162
- }
213
+ @Override
214
+ public void setCursor(PImage image, int hotspotX, int hotspotY) { }
163
215
 
164
- @Override
165
- public void hideCursor() {
166
- }
216
+ @Override
217
+ public void showCursor() { }
167
218
 
168
- //
169
- public Thread createThread() {
170
- return new AnimationThread();
171
- }
219
+ @Override
220
+ public void hideCursor() { }
172
221
 
173
- @Override
174
- public void startThread() {
175
- if (thread == null) {
176
- thread = createThread();
177
- thread.start();
178
- } else {
179
- throw new IllegalStateException("Thread already started in "
180
- + getClass().getSimpleName());
181
- }
182
- }
183
222
 
184
- @Override
185
- public boolean stopThread() {
186
- if (thread == null) {
187
- return false;
188
- }
189
- thread = null;
190
- return true;
191
- }
223
+ //
192
224
 
193
- @Override
194
- public boolean isStopped() {
195
- return thread == null || !thread.isAlive();
225
+
226
+ @Override
227
+ public boolean openLink(String url) {
228
+ return false;
229
+ }
230
+
231
+
232
+ //
233
+
234
+
235
+ public Thread createThread() {
236
+ return new AnimationThread();
237
+ }
238
+
239
+
240
+ @Override
241
+ public void startThread() {
242
+ if (thread == null) {
243
+ thread = createThread();
244
+ thread.start();
245
+ } else {
246
+ throw new IllegalStateException("Thread already started in " +
247
+ getClass().getSimpleName());
196
248
  }
249
+ }
197
250
 
198
- // sets a flag to pause the thread when ready
199
- @Override
200
- public void pauseThread() {
201
- PApplet.debug("PApplet.run() paused, calling object wait...");
202
- paused = true;
251
+
252
+ @Override
253
+ public boolean stopThread() {
254
+ if (thread == null) {
255
+ return false;
203
256
  }
257
+ thread = null;
258
+ return true;
259
+ }
260
+
261
+
262
+ @Override
263
+ public boolean isStopped() {
264
+ return thread == null || !thread.isAlive();
265
+ }
266
+
204
267
 
205
- // halts the animation thread if the pause flag is set
206
- protected void checkPause() {
207
- if (paused) {
208
- synchronized (pauseObject) {
209
- try {
210
- pauseObject.wait();
268
+ // sets a flag to pause the thread when ready
269
+ @Override
270
+ public void pauseThread() {
271
+ PApplet.debug("PApplet.run() paused, calling object wait...");
272
+ paused = true;
273
+ }
274
+
275
+
276
+ // halts the animation thread if the pause flag is set
277
+ protected void checkPause() {
278
+ if (paused) {
279
+ synchronized (pauseObject) {
280
+ try {
281
+ pauseObject.wait();
211
282
  // PApplet.debug("out of wait");
212
- } catch (InterruptedException e) {
213
- // waiting for this interrupt on a start() (resume) call
214
- }
215
- }
283
+ } catch (InterruptedException e) {
284
+ // waiting for this interrupt on a start() (resume) call
216
285
  }
217
- // PApplet.debug("done with pause");
286
+ }
218
287
  }
288
+ // PApplet.debug("done with pause");
289
+ }
219
290
 
220
- @Override
221
- public void resumeThread() {
222
- paused = false;
223
- synchronized (pauseObject) {
224
- pauseObject.notifyAll(); // wake up the animation thread
225
- }
291
+
292
+ @Override
293
+ public void resumeThread() {
294
+ paused = false;
295
+ synchronized (pauseObject) {
296
+ pauseObject.notifyAll(); // wake up the animation thread
226
297
  }
298
+ }
299
+
300
+
301
+ @Override
302
+ public void setFrameRate(float fps) {
303
+ frameRateTarget = fps;
304
+ frameRatePeriod = (long) (1000000000.0 / frameRateTarget);
305
+ //g.setFrameRate(fps);
306
+ }
307
+
227
308
 
228
- public void setFrameRate(float fps) {
229
- frameRateTarget = fps;
230
- frameRatePeriod = (long) (1000000000.0 / frameRateTarget);
231
- //g.setFrameRate(fps);
309
+ public class AnimationThread extends Thread {
310
+
311
+ public AnimationThread() {
312
+ super("Animation Thread");
232
313
  }
233
314
 
234
- public class AnimationThread extends Thread {
315
+ // broken out so it can be overridden by Danger et al
316
+ public void callDraw() {
317
+ sketch.handleDraw();
318
+ }
235
319
 
236
- public AnimationThread() {
237
- super("Animation Thread");
238
- }
320
+ /**
321
+ * Main method for the primary animation thread.
322
+ * <A HREF="http://java.sun.com/products/jfc/tsc/articles/painting/">Painting in AWT and Swing</A>
323
+ */
324
+ @Override
325
+ public void run() { // not good to make this synchronized, locks things up
326
+ long beforeTime = System.nanoTime();
327
+ long overSleepTime = 0L;
239
328
 
240
- // broken out so it can be overridden by Danger et al
241
- public void callDraw() {
242
- sketch.handleDraw();
243
- }
329
+ int noDelays = 0;
330
+ // Number of frames with a delay of 0 ms before the
331
+ // animation thread yields to other running threads.
332
+ final int NO_DELAYS_PER_YIELD = 15;
244
333
 
245
- /**
246
- * Main method for the primary animation thread.
247
- * <A HREF="http://java.sun.com/products/jfc/tsc/articles/painting/">Painting
248
- * in AWT and Swing</A>
249
- */
250
- @Override
251
- public void run() { // not good to make this synchronized, locks things up
252
- long beforeTime = System.nanoTime();
253
- long overSleepTime = 0L;
254
-
255
- int noDelays = 0;
256
- // Number of frames with a delay of 0 ms before the
257
- // animation thread yields to other running threads.
258
- final int NO_DELAYS_PER_YIELD = 15;
259
-
260
- /*
334
+ /*
261
335
  // If size un-initialized, might be a Canvas. Call setSize() here since
262
336
  // we now have a parent object that this Canvas can use as a peer.
263
337
  if (graphics.image == null) {
@@ -275,26 +349,28 @@ public class PSurfaceNone implements PSurface {
275
349
  }
276
350
  // System.out.format(" but now, sketchW/H changed to %d %d%n", sketchWidth, sketchHeight);
277
351
  }
278
- */
279
- // un-pause the sketch and get rolling
280
- sketch.start();
352
+ */
281
353
 
282
- while ((Thread.currentThread() == thread) && !sketch.finished) {
283
- checkPause();
354
+ // un-pause the sketch and get rolling
355
+ sketch.start();
284
356
 
285
- // Don't resize the renderer from the EDT (i.e. from a ComponentEvent),
286
- // otherwise it may attempt a resize mid-render.
357
+ while ((Thread.currentThread() == thread) && !sketch.finished) {
358
+ checkPause();
359
+
360
+ // Don't resize the renderer from the EDT (i.e. from a ComponentEvent),
361
+ // otherwise it may attempt a resize mid-render.
287
362
  // Dimension currentSize = canvas.getSize();
288
363
  // if (currentSize.width != sketchWidth || currentSize.height != sketchHeight) {
289
364
  // System.err.format("need to resize from %s to %d, %d%n", currentSize, sketchWidth, sketchHeight);
290
365
  // }
291
- // render a single frame
366
+
367
+ // render a single frame
292
368
  // try {
293
369
  // EventQueue.invokeAndWait(new Runnable() {
294
370
  // public void run() {
295
371
  // System.out.println("calling draw, finished = " + sketch.finished);
296
- //System.out.println("calling draw, looping = " + sketch.looping + ", frameCount = " + sketch.frameCount);
297
- callDraw();
372
+ //System.out.println("calling draw, looping = " + sketch.looping + ", frameCount = " + sketch.frameCount);
373
+ callDraw();
298
374
 
299
375
  // EventQueue.invokeLater(new Runnable() {
300
376
  // public void run() {
@@ -303,6 +379,7 @@ public class PSurfaceNone implements PSurface {
303
379
  // }
304
380
  // }
305
381
  // });
382
+
306
383
  // }
307
384
  // });
308
385
  // } catch (InterruptedException ie) {
@@ -310,44 +387,45 @@ public class PSurfaceNone implements PSurface {
310
387
  // } catch (InvocationTargetException ite) {
311
388
  // ite.getTargetException().printStackTrace();
312
389
  // }
313
- // wait for update & paint to happen before drawing next frame
314
- // this is necessary since the drawing is sometimes in a
315
- // separate thread, meaning that the next frame will start
316
- // before the update/paint is completed
317
- long afterTime = System.nanoTime();
318
- long timeDiff = afterTime - beforeTime;
319
- //System.out.println("time diff is " + timeDiff);
320
- long sleepTime = (frameRatePeriod - timeDiff) - overSleepTime;
321
-
322
- if (sleepTime > 0) { // some time left in this cycle
323
- try {
324
- Thread.sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L));
325
- noDelays = 0; // Got some sleep, not delaying anymore
326
- } catch (InterruptedException ex) {
327
- }
328
-
329
- overSleepTime = (System.nanoTime() - afterTime) - sleepTime;
330
-
331
- } else { // sleepTime <= 0; the frame took longer than the period
332
- overSleepTime = 0L;
333
- noDelays++;
334
-
335
- if (noDelays > NO_DELAYS_PER_YIELD) {
336
- Thread.yield(); // give another thread a chance to run
337
- noDelays = 0;
338
- }
339
- }
340
-
341
- beforeTime = System.nanoTime();
342
- }
343
390
 
344
- sketch.dispose(); // call to shutdown libs?
391
+ // wait for update & paint to happen before drawing next frame
392
+ // this is necessary since the drawing is sometimes in a
393
+ // separate thread, meaning that the next frame will start
394
+ // before the update/paint is completed
345
395
 
346
- // If the user called the exit() function, the window should close,
347
- // rather than the sketch just halting.
348
- if (sketch.exitCalled) {
349
- sketch.exitActual();
350
- }
396
+ long afterTime = System.nanoTime();
397
+ long timeDiff = afterTime - beforeTime;
398
+ //System.out.println("time diff is " + timeDiff);
399
+ long sleepTime = (frameRatePeriod - timeDiff) - overSleepTime;
400
+
401
+ if (sleepTime > 0) { // some time left in this cycle
402
+ try {
403
+ Thread.sleep(sleepTime / 1000000L, (int) (sleepTime % 1000000L));
404
+ noDelays = 0; // Got some sleep, not delaying anymore
405
+ } catch (InterruptedException ex) { }
406
+
407
+ overSleepTime = (System.nanoTime() - afterTime) - sleepTime;
408
+
409
+ } else { // sleepTime <= 0; the frame took longer than the period
410
+ overSleepTime = 0L;
411
+ noDelays++;
412
+
413
+ if (noDelays > NO_DELAYS_PER_YIELD) {
414
+ Thread.yield(); // give another thread a chance to run
415
+ noDelays = 0;
416
+ }
351
417
  }
418
+
419
+ beforeTime = System.nanoTime();
420
+ }
421
+
422
+ sketch.dispose(); // call to shutdown libs?
423
+
424
+ // If the user called the exit() function, the window should close,
425
+ // rather than the sketch just halting.
426
+ if (sketch.exitCalled) {
427
+ sketch.exitActual();
428
+ }
352
429
  }
430
+ }
353
431
  }