propane 3.3.1-java → 3.6.0-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 (157) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -2
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -3
  5. data/.travis.yml +9 -0
  6. data/CHANGELOG.md +17 -5
  7. data/Gemfile +2 -0
  8. data/README.md +17 -8
  9. data/Rakefile +16 -30
  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 +21 -15
  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/mvnw +127 -51
  38. data/mvnw.cmd +182 -145
  39. data/pom.rb +53 -50
  40. data/pom.xml +17 -8
  41. data/propane.gemspec +13 -11
  42. data/src/main/java/monkstone/ColorUtil.java +13 -1
  43. data/src/main/java/monkstone/MathToolModule.java +253 -203
  44. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  45. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  46. data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
  47. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  48. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  51. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  52. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  53. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  54. data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
  55. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  56. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
  57. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  58. data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
  59. data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
  60. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  61. data/src/main/java/processing/awt/PGraphicsJava2D.java +2164 -1661
  62. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  63. data/src/main/java/processing/awt/PShapeJava2D.java +280 -268
  64. data/src/main/java/processing/awt/PSurfaceAWT.java +942 -829
  65. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  66. data/src/main/java/processing/core/PApplet.java +831 -824
  67. data/src/main/java/processing/core/PConstants.java +477 -447
  68. data/src/main/java/processing/core/PFont.java +914 -880
  69. data/src/main/java/processing/core/PGraphics.java +229 -213
  70. data/src/main/java/processing/core/PImage.java +620 -318
  71. data/src/main/java/processing/core/PMatrix.java +172 -159
  72. data/src/main/java/processing/core/PMatrix2D.java +478 -409
  73. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  74. data/src/main/java/processing/core/PShape.java +2888 -2652
  75. data/src/main/java/processing/core/PShapeOBJ.java +436 -415
  76. data/src/main/java/processing/core/PShapeSVG.java +1702 -1479
  77. data/src/main/java/processing/core/PStyle.java +40 -37
  78. data/src/main/java/processing/core/PSurface.java +139 -97
  79. data/src/main/java/processing/core/PSurfaceNone.java +296 -208
  80. data/src/main/java/processing/core/PVector.java +997 -965
  81. data/src/main/java/processing/core/ThinkDifferent.java +12 -17
  82. data/src/main/java/processing/data/DoubleDict.java +756 -710
  83. data/src/main/java/processing/data/DoubleList.java +749 -696
  84. data/src/main/java/processing/data/FloatDict.java +748 -702
  85. data/src/main/java/processing/data/FloatList.java +751 -697
  86. data/src/main/java/processing/data/IntDict.java +720 -673
  87. data/src/main/java/processing/data/IntList.java +699 -633
  88. data/src/main/java/processing/data/JSONArray.java +931 -873
  89. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  90. data/src/main/java/processing/data/JSONTokener.java +351 -341
  91. data/src/main/java/processing/data/LongDict.java +710 -663
  92. data/src/main/java/processing/data/LongList.java +701 -635
  93. data/src/main/java/processing/data/Sort.java +37 -41
  94. data/src/main/java/processing/data/StringDict.java +525 -486
  95. data/src/main/java/processing/data/StringList.java +626 -580
  96. data/src/main/java/processing/data/Table.java +3690 -3510
  97. data/src/main/java/processing/data/TableRow.java +182 -183
  98. data/src/main/java/processing/data/XML.java +957 -883
  99. data/src/main/java/processing/dxf/RawDXF.java +404 -0
  100. data/src/main/java/processing/event/Event.java +87 -66
  101. data/src/main/java/processing/event/KeyEvent.java +48 -41
  102. data/src/main/java/processing/event/MouseEvent.java +88 -113
  103. data/src/main/java/processing/event/TouchEvent.java +10 -6
  104. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  105. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  106. data/src/main/java/processing/net/Client.java +744 -0
  107. data/src/main/java/processing/net/Server.java +388 -0
  108. data/src/main/java/processing/opengl/FontTexture.java +289 -270
  109. data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
  110. data/src/main/java/processing/opengl/LinePath.java +547 -500
  111. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  112. data/src/main/java/processing/opengl/PGL.java +3047 -2914
  113. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  114. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  115. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  116. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  117. data/src/main/java/processing/opengl/PShader.java +1266 -1257
  118. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  119. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  120. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  121. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  122. data/test/create_test.rb +21 -20
  123. data/test/deglut_spec_test.rb +4 -2
  124. data/test/helper_methods_test.rb +49 -20
  125. data/test/math_tool_test.rb +39 -32
  126. data/test/native_folder.rb +47 -0
  127. data/test/respond_to_test.rb +3 -2
  128. data/test/sketches/key_event.rb +2 -2
  129. data/test/sketches/library/my_library/my_library.rb +3 -0
  130. data/test/test_helper.rb +2 -0
  131. data/test/vecmath_spec_test.rb +35 -22
  132. data/vendors/Rakefile +33 -62
  133. metadata +54 -45
  134. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
  135. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
  136. data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
  137. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
  138. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
  139. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
  140. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
  141. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
  142. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
  143. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
  144. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
  145. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
  146. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
  147. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
  148. data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
  149. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
  150. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
  151. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
  152. data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
  153. data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
  154. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  155. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  156. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  157. 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
 
@@ -16,7 +18,8 @@
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.awt;
21
24
 
22
25
  import java.awt.Canvas;
@@ -38,6 +41,7 @@ import java.awt.Toolkit;
38
41
  import java.awt.event.*;
39
42
  import java.awt.geom.Rectangle2D;
40
43
  import java.awt.image.*;
44
+ import java.io.File;
41
45
  import java.lang.management.ManagementFactory;
42
46
  import java.lang.reflect.InvocationTargetException;
43
47
  import java.lang.reflect.Method;
@@ -46,7 +50,6 @@ import java.util.ArrayList;
46
50
  import java.util.List;
47
51
 
48
52
  import javax.swing.JFrame;
49
- import processing.core.ThinkDifferent;
50
53
 
51
54
  import processing.core.PApplet;
52
55
  import processing.core.PConstants;
@@ -56,43 +59,47 @@ import processing.core.PSurfaceNone;
56
59
  import processing.event.KeyEvent;
57
60
  import processing.event.MouseEvent;
58
61
 
59
- public class PSurfaceAWT extends PSurfaceNone {
60
62
 
61
- GraphicsDevice displayDevice;
63
+ public class PSurfaceAWT extends PSurfaceNone {
64
+ GraphicsDevice displayDevice;
62
65
 
63
- // used for canvas to determine whether resizable or not
66
+ // used for canvas to determine whether resizable or not
64
67
  // boolean resizable; // default is false
65
- // Internally, we know it's always a JFrame (not just a Frame)
68
+
69
+ // Internally, we know it's always a JFrame (not just a Frame)
66
70
  // JFrame frame;
67
- // Trying Frame again with a11 to see if this avoids some Swing nastiness.
68
- // In the past, AWT Frames caused some problems on Windows and Linux,
69
- // but those may not be a problem for our reworked PSurfaceAWT class.
70
- Frame frame;
71
+ // Trying Frame again with a11 to see if this avoids some Swing nastiness.
72
+ // In the past, AWT Frames caused some problems on Windows and Linux,
73
+ // but those may not be a problem for our reworked PSurfaceAWT class.
74
+ Frame frame;
71
75
 
72
- // Note that x and y may not be zero, depending on the display configuration
73
- Rectangle screenRect;
76
+ // Note that x and y may not be zero, depending on the display configuration
77
+ Rectangle screenRect;
74
78
 
75
- // Used for resizing, at least on Windows insets size changes when
76
- // frame.setResizable() is called, and in resize listener we need
77
- // to know what size the window was before.
78
- Insets currentInsets = new Insets(0, 0, 0, 0);
79
+ // Used for resizing, at least on Windows insets size changes when
80
+ // frame.setResizable() is called, and in resize listener we need
81
+ // to know what size the window was before.
82
+ Insets currentInsets = new Insets(0, 0, 0, 0);
79
83
 
80
- // 3.0a5 didn't use strategy, and active was shut off during init() w/ retina
84
+ // 3.0a5 didn't use strategy, and active was shut off during init() w/ retina
81
85
  // boolean useStrategy = true;
82
- Canvas canvas;
86
+
87
+ Canvas canvas;
83
88
  // Component canvas;
84
89
 
85
90
  // PGraphics graphics; // moved to PSurfaceNone
86
- int sketchWidth;
87
- int sketchHeight;
88
91
 
89
- int windowScaleFactor;
92
+ int sketchWidth;
93
+ int sketchHeight;
94
+
95
+ int windowScaleFactor;
90
96
 
91
- public PSurfaceAWT(PGraphics graphics) {
92
- //this.graphics = graphics;
93
- super(graphics);
94
97
 
95
- /*
98
+ public PSurfaceAWT(PGraphics graphics) {
99
+ //this.graphics = graphics;
100
+ super(graphics);
101
+
102
+ /*
96
103
  if (checkRetina()) {
97
104
  // System.out.println("retina in use");
98
105
 
@@ -113,31 +120,32 @@ public class PSurfaceAWT extends PSurfaceNone {
113
120
  // flicker--pushing pixels out before the screen has finished rendering.
114
121
  // useStrategy = false;
115
122
  }
116
- */
117
- canvas = new SmoothCanvas();
123
+ */
124
+ canvas = new SmoothCanvas();
118
125
  // if (useStrategy) {
119
- //canvas.setIgnoreRepaint(true);
126
+ //canvas.setIgnoreRepaint(true);
120
127
  // }
121
128
 
122
- // Pass tab key to the sketch, rather than moving between components
123
- canvas.setFocusTraversalKeysEnabled(false);
124
-
125
- canvas.addComponentListener(new ComponentAdapter() {
126
- @Override
127
- public void componentResized(ComponentEvent e) {
128
- if (!sketch.isLooping()) {
129
- // make sure this is a real resize event, not just initial setup
130
- // https://github.com/processing/processing/issues/3310
131
- Dimension canvasSize = canvas.getSize();
132
- if (canvasSize.width != sketch.sketchWidth()
133
- || canvasSize.height != sketch.sketchHeight()) {
134
- sketch.redraw();
135
- }
136
- }
137
- }
138
- });
139
- addListeners();
140
- }
129
+ // Pass tab key to the sketch, rather than moving between components
130
+ canvas.setFocusTraversalKeysEnabled(false);
131
+
132
+ canvas.addComponentListener(new ComponentAdapter() {
133
+ @Override
134
+ public void componentResized(ComponentEvent e) {
135
+ if (!sketch.isLooping()) {
136
+ // make sure this is a real resize event, not just initial setup
137
+ // https://github.com/processing/processing/issues/3310
138
+ Dimension canvasSize = canvas.getSize();
139
+ if (canvasSize.width != sketch.sketchWidth() ||
140
+ canvasSize.height != sketch.sketchHeight()) {
141
+ sketch.redraw();
142
+ }
143
+ }
144
+ }
145
+ });
146
+ addListeners();
147
+ }
148
+
141
149
 
142
150
  // /**
143
151
  // * Handle grabbing the focus on startup. Other renderers can override this
@@ -173,71 +181,81 @@ public class PSurfaceAWT extends PSurfaceNone {
173
181
  // }
174
182
  // });
175
183
  // }
176
- // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
177
- public class SmoothCanvas extends Canvas {
178
184
 
179
- private Dimension oldSize = new Dimension(0, 0);
180
- private Dimension newSize = new Dimension(0, 0);
181
185
 
182
- // Turns out getParent() returns a JPanel on a JFrame. Yech.
183
- public Frame getFrame() {
184
- return frame;
185
- }
186
+ // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
186
187
 
187
- @Override
188
- public Dimension getPreferredSize() {
189
- return new Dimension(sketchWidth, sketchHeight);
190
- }
191
188
 
192
- @Override
193
- public Dimension getMinimumSize() {
194
- return getPreferredSize();
195
- }
189
+ public class SmoothCanvas extends Canvas {
190
+ private Dimension oldSize = new Dimension(0, 0);
191
+ private Dimension newSize = new Dimension(0, 0);
196
192
 
197
- @Override
198
- public Dimension getMaximumSize() {
199
- //return resizable ? super.getMaximumSize() : getPreferredSize();
200
- return frame.isResizable() ? super.getMaximumSize() : getPreferredSize();
201
- }
202
193
 
203
- @Override
204
- public void validate() {
205
- super.validate();
206
- newSize.width = getWidth();
207
- newSize.height = getHeight();
194
+ // Turns out getParent() returns a JPanel on a JFrame. Yech.
195
+ public Frame getFrame() {
196
+ return frame;
197
+ }
198
+
199
+
200
+ @Override
201
+ public Dimension getPreferredSize() {
202
+ return new Dimension(sketchWidth, sketchHeight);
203
+ }
204
+
205
+
206
+ @Override
207
+ public Dimension getMinimumSize() {
208
+ return getPreferredSize();
209
+ }
210
+
211
+
212
+ @Override
213
+ public Dimension getMaximumSize() {
214
+ //return resizable ? super.getMaximumSize() : getPreferredSize();
215
+ return frame.isResizable() ? super.getMaximumSize() : getPreferredSize();
216
+ }
217
+
218
+
219
+ @Override
220
+ public void validate() {
221
+ super.validate();
222
+ newSize.width = getWidth();
223
+ newSize.height = getHeight();
208
224
  // if (oldSize.equals(newSize)) {
209
225
  //// System.out.println("validate() return " + oldSize);
210
226
  // return;
211
227
  // } else {
212
- if (!oldSize.equals(newSize)) {
228
+ if (!oldSize.equals(newSize)) {
213
229
  // System.out.println("validate() render old=" + oldSize + " -> new=" + newSize);
214
- oldSize = newSize;
215
- sketch.setSize(newSize.width / windowScaleFactor, newSize.height / windowScaleFactor);
230
+ oldSize = newSize;
231
+ sketch.setSize(newSize.width / windowScaleFactor, newSize.height / windowScaleFactor);
216
232
  // try {
217
- render();
233
+ render();
218
234
  // } catch (IllegalStateException ise) {
219
235
  // System.out.println(ise.getMessage());
220
236
  // }
221
- }
222
- }
237
+ }
238
+ }
223
239
 
224
- @Override
225
- public void update(Graphics g) {
240
+
241
+ @Override
242
+ public void update(Graphics g) {
226
243
  // System.out.println("updating");
227
- paint(g);
228
- }
244
+ paint(g);
245
+ }
229
246
 
230
- @Override
231
- public void paint(Graphics screen) {
247
+
248
+ @Override
249
+ public void paint(Graphics screen) {
232
250
  // System.out.println("painting");
233
251
  // if (useStrategy) {
234
- render();
235
- /*
252
+ render();
253
+ /*
236
254
  if (graphics != null) {
237
255
  System.out.println("drawing to screen " + canvas);
238
256
  screen.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null);
239
257
  }
240
- */
258
+ */
241
259
 
242
260
  // } else {
243
261
  //// new Exception("painting").printStackTrace(System.out);
@@ -251,8 +269,8 @@ public class PSurfaceAWT extends PSurfaceNone {
251
269
  // }
252
270
  // }
253
271
  // }
254
- }
255
272
  }
273
+ }
256
274
 
257
275
  /*
258
276
  @Override
@@ -262,38 +280,40 @@ public class PSurfaceAWT extends PSurfaceNone {
262
280
  // prior to Java 7 on OS X, this no longer works [121222]
263
281
  // createBufferStrategy(2);
264
282
  }
265
- */
266
- synchronized protected void render() {
267
- if (canvas.isDisplayable()
268
- && graphics.image != null) {
269
- if (canvas.getBufferStrategy() == null) {
270
- canvas.createBufferStrategy(2);
271
- }
272
- BufferStrategy strategy = canvas.getBufferStrategy();
273
- if (strategy != null) {
274
- // Render single frame
283
+ */
284
+
285
+
286
+ synchronized protected void render() {
287
+ if (canvas.isDisplayable() &&
288
+ graphics.image != null) {
289
+ if (canvas.getBufferStrategy() == null) {
290
+ canvas.createBufferStrategy(2);
291
+ }
292
+ BufferStrategy strategy = canvas.getBufferStrategy();
293
+ if (strategy != null) {
294
+ // Render single frame
275
295
  // try {
276
- do {
277
- // The following loop ensures that the contents of the drawing buffer
278
- // are consistent in case the underlying surface was recreated
279
- do {
280
- Graphics2D draw = (Graphics2D) strategy.getDrawGraphics();
281
- // draw to width/height, since this may be a 2x image
282
- draw.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null);
283
- draw.dispose();
284
- } while (strategy.contentsRestored());
285
-
286
- // Display the buffer
287
- strategy.show();
288
-
289
- // Repeat the rendering if the drawing buffer was lost
290
- } while (strategy.contentsLost());
291
- }
292
- }
296
+ do {
297
+ // The following loop ensures that the contents of the drawing buffer
298
+ // are consistent in case the underlying surface was recreated
299
+ do {
300
+ Graphics2D draw = (Graphics2D) strategy.getDrawGraphics();
301
+ // draw to width/height, since this may be a 2x image
302
+ draw.drawImage(graphics.image, 0, 0, sketchWidth, sketchHeight, null);
303
+ draw.dispose();
304
+ } while (strategy.contentsRestored());
305
+
306
+ // Display the buffer
307
+ strategy.show();
308
+
309
+ // Repeat the rendering if the drawing buffer was lost
310
+ } while (strategy.contentsLost());
311
+ }
293
312
  }
313
+ }
294
314
 
295
315
 
296
- /*
316
+ /*
297
317
  protected void blit() {
298
318
  // Other folks that call render() (i.e. paint()) are already on the EDT.
299
319
  // We need to be using the EDT since we're messing with the Canvas
@@ -335,23 +355,60 @@ public class PSurfaceAWT extends PSurfaceNone {
335
355
  }
336
356
  }
337
357
  }
338
- */
339
- // what needs to happen here?
340
- @Override
341
- public void initOffscreen(PApplet sketch) {
342
- this.sketch = sketch;
343
- }
358
+ */
344
359
 
345
- /*
360
+
361
+ /*
362
+ @Override
363
+ public int displayDensity() {
364
+ return shim.displayDensity();
365
+ }
366
+
367
+
368
+ @Override
369
+ public int displayDensity(int display) {
370
+ return shim.displayDensity(display);
371
+ }
372
+ */
373
+
374
+
375
+ @Override
376
+ public void selectInput(String prompt, String callback,
377
+ File file, Object callbackObject) {
378
+ ShimAWT.selectInput(prompt, callback, file, callbackObject);
379
+ }
380
+
381
+
382
+ @Override
383
+ public void selectOutput(String prompt, String callback,
384
+ File file, Object callbackObject) {
385
+ ShimAWT.selectOutput(prompt, callback, file, callbackObject);
386
+ }
387
+
388
+
389
+ @Override
390
+ public void selectFolder(String prompt, String callback,
391
+ File file, Object callbackObject) {
392
+ ShimAWT.selectFolder(prompt, callback, file, callbackObject);
393
+ }
394
+
395
+
396
+ // what needs to happen here?
397
+ @Override
398
+ public void initOffscreen(PApplet sketch) {
399
+ this.sketch = sketch;
400
+ }
401
+
402
+ /*
346
403
  public Frame initOffscreen() {
347
404
  Frame dummy = new Frame();
348
405
  dummy.pack(); // get legit AWT graphics
349
406
  // but don't show it
350
407
  return dummy;
351
408
  }
352
- */
409
+ */
353
410
 
354
- /*
411
+ /*
355
412
  @Override
356
413
  public Component initComponent(PApplet sketch) {
357
414
  this.sketch = sketch;
@@ -362,59 +419,61 @@ public class PSurfaceAWT extends PSurfaceNone {
362
419
 
363
420
  return canvas;
364
421
  }
365
- */
366
- @Override
367
- public void initFrame(final PApplet sketch) {/*, int backgroundColor,
422
+ */
423
+
424
+
425
+ @Override
426
+ public void initFrame(final PApplet sketch) {/*, int backgroundColor,
368
427
  int deviceIndex, boolean fullScreen, boolean spanDisplays) {*/
369
- this.sketch = sketch;
428
+ this.sketch = sketch;
370
429
 
371
- GraphicsEnvironment environment
372
- = GraphicsEnvironment.getLocalGraphicsEnvironment();
430
+ GraphicsEnvironment environment =
431
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
373
432
 
374
- int displayNum = sketch.sketchDisplay();
433
+ int displayNum = sketch.sketchDisplay();
375
434
  // System.out.println("display from sketch is " + displayNum);
376
- if (displayNum > 0) { // if -1, use the default device
377
- GraphicsDevice[] devices = environment.getScreenDevices();
378
- if (displayNum <= devices.length) {
379
- displayDevice = devices[displayNum - 1];
380
- } else {
381
- System.err.format("Display %d does not exist, "
382
- + "using the default display instead.%n", displayNum);
383
- for (int i = 0; i < devices.length; i++) {
384
- System.err.format("Display %d is %s%n", (i + 1), devices[i]);
385
- }
386
- }
387
- }
388
- if (displayDevice == null) {
389
- displayDevice = environment.getDefaultScreenDevice();
435
+ if (displayNum > 0) { // if -1, use the default device
436
+ GraphicsDevice[] devices = environment.getScreenDevices();
437
+ if (displayNum <= devices.length) {
438
+ displayDevice = devices[displayNum - 1];
439
+ } else {
440
+ System.err.format("Display %d does not exist, " +
441
+ "using the default display instead.%n", displayNum);
442
+ for (int i = 0; i < devices.length; i++) {
443
+ System.err.format("Display %d is %s%n", (i+1), devices[i]);
390
444
  }
445
+ }
446
+ }
447
+ if (displayDevice == null) {
448
+ displayDevice = environment.getDefaultScreenDevice();
449
+ }
391
450
 
392
- // Need to save the window bounds at full screen,
393
- // because pack() will cause the bounds to go to zero.
394
- // http://dev.processing.org/bugs/show_bug.cgi?id=923
395
- boolean spanDisplays = sketch.sketchDisplay() == PConstants.SPAN;
396
- screenRect = spanDisplays ? getDisplaySpan()
397
- : displayDevice.getDefaultConfiguration().getBounds();
398
- // DisplayMode doesn't work here, because we can't get the upper-left
399
- // corner of the display, which is important for multi-display setups.
400
-
401
- // Set the displayWidth/Height variables inside PApplet, so that they're
402
- // usable and can even be returned by the sketchWidth()/Height() methods.
403
- sketch.displayWidth = screenRect.width;
404
- sketch.displayHeight = screenRect.height;
405
-
406
- windowScaleFactor = PApplet.platform == PConstants.MACOSX
407
- ? 1 : sketch.pixelDensity;
408
-
409
- sketchWidth = sketch.sketchWidth() * windowScaleFactor;
410
- sketchHeight = sketch.sketchHeight() * windowScaleFactor;
411
-
412
- boolean fullScreen = sketch.sketchFullScreen();
413
- // Removing the section below because sometimes people want to do the
414
- // full screen size in a window, and it also breaks insideSettings().
415
- // With 3.x, fullScreen() is so easy, that it's just better that way.
416
- // https://github.com/processing/processing/issues/3545
417
- /*
451
+ // Need to save the window bounds at full screen,
452
+ // because pack() will cause the bounds to go to zero.
453
+ // http://dev.processing.org/bugs/show_bug.cgi?id=923
454
+ boolean spanDisplays = sketch.sketchDisplay() == PConstants.SPAN;
455
+ screenRect = spanDisplays ? getDisplaySpan() :
456
+ displayDevice.getDefaultConfiguration().getBounds();
457
+ // DisplayMode doesn't work here, because we can't get the upper-left
458
+ // corner of the display, which is important for multi-display setups.
459
+
460
+ // Set the displayWidth/Height variables inside PApplet, so that they're
461
+ // usable and can even be returned by the sketchWidth()/Height() methods.
462
+ sketch.displayWidth = screenRect.width;
463
+ sketch.displayHeight = screenRect.height;
464
+
465
+ windowScaleFactor = PApplet.platform == PConstants.MACOS ?
466
+ 1 : sketch.pixelDensity;
467
+
468
+ sketchWidth = sketch.sketchWidth() * windowScaleFactor;
469
+ sketchHeight = sketch.sketchHeight() * windowScaleFactor;
470
+
471
+ boolean fullScreen = sketch.sketchFullScreen();
472
+ // Removing the section below because sometimes people want to do the
473
+ // full screen size in a window, and it also breaks insideSettings().
474
+ // With 3.x, fullScreen() is so easy, that it's just better that way.
475
+ // https://github.com/processing/processing/issues/3545
476
+ /*
418
477
  // Sketch has already requested to be the same as the screen's
419
478
  // width and height, so let's roll with full screen mode.
420
479
  if (screenRect.width == sketchWidth &&
@@ -422,18 +481,18 @@ public class PSurfaceAWT extends PSurfaceNone {
422
481
  fullScreen = true;
423
482
  sketch.fullScreen(); // won't change the renderer
424
483
  }
425
- */
484
+ */
426
485
 
427
- if (fullScreen || spanDisplays) {
428
- sketchWidth = screenRect.width;
429
- sketchHeight = screenRect.height;
430
- }
486
+ if (fullScreen || spanDisplays) {
487
+ sketchWidth = screenRect.width;
488
+ sketchHeight = screenRect.height;
489
+ }
431
490
 
432
- // Using a JFrame fixes a Windows problem with Present mode. This might
433
- // be our error, but usually this is the sort of crap we usually get from
434
- // OS X. It's time for a turnaround: Redmond is thinking different too!
435
- // https://github.com/processing/processing/issues/1955
436
- frame = new JFrame(displayDevice.getDefaultConfiguration());
491
+ // Using a JFrame fixes a Windows problem with Present mode. This might
492
+ // be our error, but usually this is the sort of crap we usually get from
493
+ // OS X. It's time for a turnaround: Redmond is thinking different too!
494
+ // https://github.com/processing/processing/issues/1955
495
+ frame = new JFrame(displayDevice.getDefaultConfiguration());
437
496
  // frame = new Frame(displayDevice.getDefaultConfiguration());
438
497
  // // Default Processing gray, which will be replaced below if another
439
498
  // // color is specified on the command line (i.e. in the prefs).
@@ -445,27 +504,28 @@ public class PSurfaceAWT extends PSurfaceNone {
445
504
  // if (backgroundColor == 0) {
446
505
  // backgroundColor = WINDOW_BGCOLOR;
447
506
  // }
448
- final Color windowColor = new Color(sketch.sketchWindowColor(), false);
449
- if (frame instanceof JFrame) {
450
- ((JFrame) frame).getContentPane().setBackground(windowColor);
451
- } else {
452
- frame.setBackground(windowColor);
453
- }
507
+ final Color windowColor = new Color(sketch.sketchWindowColor(), false);
508
+ if (frame instanceof JFrame) {
509
+ ((JFrame) frame).getContentPane().setBackground(windowColor);
510
+ } else {
511
+ frame.setBackground(windowColor);
512
+ }
454
513
 
455
- // Put the p5 logo in the Frame's corner to override the Java coffee cup.
456
- setProcessingIcon(frame);
514
+ // Put the p5 logo in the Frame's corner to override the Java coffee cup.
515
+ setProcessingIcon(frame);
457
516
 
458
- // For 0149, moving this code (up to the pack() method) before init().
459
- // For OpenGL (and perhaps other renderers in the future), a peer is
460
- // needed before a GLDrawable can be created. So pack() needs to be
461
- // called on the Frame before applet.init(), which itself calls size(),
462
- // and launches the Thread that will kick off setup().
463
- // http://dev.processing.org/bugs/show_bug.cgi?id=891
464
- // http://dev.processing.org/bugs/show_bug.cgi?id=908
465
- frame.add(canvas);
466
- setSize(sketchWidth / windowScaleFactor, sketchHeight / windowScaleFactor);
517
+ // For 0149, moving this code (up to the pack() method) before init().
518
+ // For OpenGL (and perhaps other renderers in the future), a peer is
519
+ // needed before a GLDrawable can be created. So pack() needs to be
520
+ // called on the Frame before applet.init(), which itself calls size(),
521
+ // and launches the Thread that will kick off setup().
522
+ // http://dev.processing.org/bugs/show_bug.cgi?id=891
523
+ // http://dev.processing.org/bugs/show_bug.cgi?id=908
467
524
 
468
- /*
525
+ frame.add(canvas);
526
+ setSize(sketchWidth / windowScaleFactor, sketchHeight / windowScaleFactor);
527
+
528
+ /*
469
529
  if (fullScreen) {
470
530
  // Called here because the graphics device is needed before we can
471
531
  // determine whether the sketch wants size(displayWidth, displayHeight),
@@ -488,162 +548,189 @@ public class PSurfaceAWT extends PSurfaceNone {
488
548
  // will be set visible in placeWindow() [3.0a10]
489
549
  //frame.setVisible(true); // re-add native resources
490
550
  }
491
- */
492
- frame.setLayout(null);
493
- //frame.add(applet);
551
+ */
552
+ frame.setLayout(null);
553
+ //frame.add(applet);
494
554
 
495
- // Need to pass back our new sketchWidth/Height here, because it may have
496
- // been overridden by numbers we calculated above if fullScreen and/or
497
- // spanScreens was in use.
555
+ // Need to pass back our new sketchWidth/Height here, because it may have
556
+ // been overridden by numbers we calculated above if fullScreen and/or
557
+ // spanScreens was in use.
498
558
  // pg = sketch.makePrimaryGraphics(sketchWidth, sketchHeight);
499
559
  // pg = sketch.makePrimaryGraphics();
500
- // resize sketch to sketchWidth/sketchHeight here
501
- if (fullScreen) {
502
- frame.invalidate();
503
- } else {
560
+
561
+ // resize sketch to sketchWidth/sketchHeight here
562
+
563
+ if (fullScreen) {
564
+ frame.invalidate();
565
+ } else {
504
566
  // frame.pack();
505
- }
567
+ }
506
568
 
507
- // insufficient, places the 100x100 sketches offset strangely
508
- //frame.validate();
509
- // disabling resize has to happen after pack() to avoid apparent Apple bug
510
- // http://code.google.com/p/processing/issues/detail?id=467
511
- frame.setResizable(false);
569
+ // insufficient, places the 100x100 sketches offset strangely
570
+ //frame.validate();
512
571
 
513
- frame.addWindowListener(new WindowAdapter() {
514
- @Override
515
- public void windowClosing(WindowEvent e) {
516
- sketch.exit(); // don't quit, need to just shut everything down (0133)
517
- }
518
- });
572
+ // disabling resize has to happen after pack() to avoid apparent Apple bug
573
+ // http://code.google.com/p/processing/issues/detail?id=467
574
+ frame.setResizable(false);
575
+
576
+ frame.addWindowListener(new WindowAdapter() {
577
+ @Override
578
+ public void windowClosing(WindowEvent e) {
579
+ sketch.exit(); // don't quit, need to just shut everything down (0133)
580
+ }
581
+ });
519
582
 
520
583
  // sketch.setFrame(frame);
521
- }
584
+ }
585
+
586
+
587
+ @Override
588
+ public Object getNative() {
589
+ return canvas;
590
+ }
522
591
 
523
- @Override
524
- public Object getNative() {
525
- return canvas;
526
- }
527
592
 
528
593
  // public Toolkit getToolkit() {
529
594
  // return canvas.getToolkit();
530
595
  // }
531
- /**
532
- * Set the window (and dock, or whatever necessary) title.
533
- *
534
- * @param title
535
- */
536
- @Override
537
- public void setTitle(String title) {
538
- frame.setTitle(title);
539
- // Workaround for apparent Java bug on OS X?
540
- // https://github.com/processing/processing/issues/3472
541
- if (cursorVisible
542
- && (PApplet.platform == PConstants.MACOSX)
543
- && (cursorType != PConstants.ARROW)) {
544
- hideCursor();
545
- showCursor();
546
- }
547
- }
548
596
 
549
- /**
550
- * Set true if we want to resize things (default is not resizable)
551
- */
552
- @Override
553
- public void setResizable(boolean resizable) {
554
- //this.resizable = resizable; // really only used for canvas
555
597
 
556
- if (frame != null) {
557
- frame.setResizable(resizable);
558
- }
598
+ /** Set the window (and dock, or whatever necessary) title.
599
+ * @param title */
600
+ @Override
601
+ public void setTitle(String title) {
602
+ frame.setTitle(title);
603
+ // Workaround for apparent Java bug on OS X?
604
+ // https://github.com/processing/processing/issues/3472
605
+ if (cursorVisible &&
606
+ (PApplet.platform == PConstants.MACOS) &&
607
+ (cursorType != PConstants.ARROW)) {
608
+ hideCursor();
609
+ showCursor();
559
610
  }
611
+ }
560
612
 
561
- @Override
562
- public void setIcon(PImage image) {
563
- Image awtImage = (Image) image.getNative();
564
- ThinkDifferent.init(sketch);
565
- ThinkDifferent.setIconImage(awtImage);
566
- }
567
613
 
568
- @Override
569
- public void setAlwaysOnTop(boolean always) {
570
- frame.setAlwaysOnTop(always);
614
+ /** Set true if we want to resize things (default is not resizable)
615
+ * @param resizable */
616
+ @Override
617
+ public void setResizable(boolean resizable) {
618
+ //this.resizable = resizable; // really only used for canvas
619
+
620
+ if (frame != null) {
621
+ frame.setResizable(resizable);
571
622
  }
623
+ }
572
624
 
573
- @Override
574
- public void setLocation(int x, int y) {
575
- frame.setLocation(x, y);
625
+
626
+ @Override
627
+ public void setIcon(PImage image) {
628
+ Image awtImage = (Image) image.getNative();
629
+
630
+ if (PApplet.platform != PConstants.MACOS) {
631
+ frame.setIconImage(awtImage);
632
+
633
+ } else {
634
+ try {
635
+ final String td = "processing.core.ThinkDifferent";
636
+ Class<?> thinkDifferent =
637
+ Thread.currentThread().getContextClassLoader().loadClass(td);
638
+ Method method =
639
+ thinkDifferent.getMethod("setIconImage", Image.class);
640
+ method.invoke(null, awtImage);
641
+ } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException e) {
642
+ // That's unfortunate
643
+
644
+ }
576
645
  }
646
+ }
577
647
 
578
- List<Image> iconImages;
579
-
580
- protected void setProcessingIcon(Frame frame) {
581
- // On OS X, this only affects what shows up in the dock when minimized.
582
- // So replacing it is actually a step backwards. Brilliant.
583
- if (PApplet.platform != PConstants.MACOSX) {
584
- //Image image = Toolkit.getDefaultToolkit().createImage(ICON_IMAGE);
585
- //frame.setIconImage(image);
586
- // try {
587
- if (iconImages == null) {
588
- iconImages = new ArrayList<>();
589
- final int[] sizes = {16, 32, 48, 64, 128, 256, 512};
590
-
591
- for (int sz : sizes) {
592
- //URL url = getClass().getResource("/icon/icon-" + sz + ".png");
593
- URL url = PApplet.class.getResource("/icon/icon-" + sz + ".png");
594
- Image image = Toolkit.getDefaultToolkit().getImage(url);
595
- iconImages.add(image);
596
- //iconImages.add(Toolkit.getLibImage("icons/pde-" + sz + ".png", frame));
597
- }
598
- }
599
- frame.setIconImages(iconImages);
600
-
601
- // } catch (Exception e) {
602
- // } // harmless; keep this to ourselves
603
- } else { // handle OS X differently
604
- if (!dockIconSpecified()) { // don't override existing -Xdock param
605
- // On OS X, set this for AWT surfaces, which handles the dock image
606
- // as well as the cmd-tab image that's shown. Just one size, I guess.
607
- URL url = PApplet.class.getResource("/icon/icon-512.png");
608
- // Seems dangerous to have this in code instead of using reflection, no?
609
- // ThinkDifferent.setIconImage(Toolkit.getDefaultToolkit().getImage(url));
610
- try {
611
- final String td = "processing.core.ThinkDifferent";
612
- Class<?> thinkDifferent
613
- = Thread.currentThread().getContextClassLoader().loadClass(td);
614
- Method method
615
- = thinkDifferent.getMethod("setIconImage", new Class[]{java.awt.Image.class});
616
- method.invoke(null, new Object[]{Toolkit.getDefaultToolkit().getImage(url)});
617
- } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException e) {
618
- e.printStackTrace(); // That's unfortunate
619
- }
620
- }
648
+
649
+ @Override
650
+ public void setAlwaysOnTop(boolean always) {
651
+ frame.setAlwaysOnTop(always);
652
+ }
653
+
654
+
655
+ @Override
656
+ public void setLocation(int x, int y) {
657
+ frame.setLocation(x, y);
658
+ }
659
+
660
+
661
+ List<Image> iconImages;
662
+
663
+ protected void setProcessingIcon(Frame frame) {
664
+ // On OS X, this only affects what shows up in the dock when minimized.
665
+ // So replacing it is actually a step backwards. Brilliant.
666
+ if (PApplet.platform != PConstants.MACOS) {
667
+ //Image image = Toolkit.getDefaultToolkit().createImage(ICON_IMAGE);
668
+ //frame.setIconImage(image);
669
+ try {
670
+ if (iconImages == null) {
671
+ iconImages = new ArrayList<>();
672
+ final int[] sizes = { 16, 32, 48, 64, 128, 256, 512 };
673
+
674
+ for (int sz : sizes) {
675
+ //URL url = getClass().getResource("/icon/icon-" + sz + ".png");
676
+ URL url = PApplet.class.getResource("/icon/icon-" + sz + ".png");
677
+ Image image = Toolkit.getDefaultToolkit().getImage(url);
678
+ iconImages.add(image);
679
+ //iconImages.add(Toolkit.getLibImage("icons/pde-" + sz + ".png", frame));
680
+ }
621
681
  }
622
- }
682
+ frame.setIconImages(iconImages);
623
683
 
624
- /**
625
- * @return true if -Xdock:icon was specified on the command line
626
- */
627
- private boolean dockIconSpecified() {
628
- // TODO This is incomplete... Haven't yet found a way to figure out if
629
- // the app has an icns file specified already. Help?
630
- List<String> jvmArgs
631
- = ManagementFactory.getRuntimeMXBean().getInputArguments();
632
- return (jvmArgs.stream().anyMatch((arg) -> (arg.startsWith("-Xdock:icon"))));
684
+ } catch (Exception e) { } // harmless; keep this to ourselves
685
+
686
+ } else { // handle OS X differently
687
+ if (!dockIconSpecified()) { // don't override existing -Xdock param
688
+ // On OS X, set this for AWT surfaces, which handles the dock image
689
+ // as well as the cmd-tab image that's shown. Just one size, I guess.
690
+ URL url = PApplet.class.getResource("/icon/icon-512.png");
691
+ // Seems dangerous to have this in code instead of using reflection, no?
692
+ //ThinkDifferent.setIconImage(Toolkit.getDefaultToolkit().getImage(url));
693
+ try {
694
+ final String td = "processing.core.ThinkDifferent";
695
+ Class<?> thinkDifferent =
696
+ Thread.currentThread().getContextClassLoader().loadClass(td);
697
+ Method method =
698
+ thinkDifferent.getMethod("setIconImage", Image.class);
699
+ method.invoke(null, Toolkit.getDefaultToolkit().getImage(url));
700
+ } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException e) {
701
+ // That's unfortunate
702
+
703
+ }
704
+ }
633
705
  }
706
+ }
634
707
 
635
- @Override
636
- public void setVisible(boolean visible) {
637
- frame.setVisible(visible);
638
708
 
639
- // Generally useful whenever setting the frame visible
640
- if (canvas != null) {
641
- //canvas.requestFocusInWindow();
642
- canvas.requestFocus();
643
- }
709
+ /**
710
+ * @return true if -Xdock:icon was specified on the command line
711
+ */
712
+ private boolean dockIconSpecified() {
713
+ // TODO This is incomplete... Haven't yet found a way to figure out if
714
+ // the app has an icns file specified already. Help?
715
+ List<String> jvmArgs =
716
+ ManagementFactory.getRuntimeMXBean().getInputArguments();
717
+ // dock image already set
718
+ return jvmArgs.stream().anyMatch((arg) -> (arg.startsWith("-Xdock:icon")));
719
+ }
720
+
644
721
 
645
- // removing per https://github.com/processing/processing/pull/3162
646
- // can remove the code below once 3.0a6 is tested and behaving
722
+ @Override
723
+ public void setVisible(boolean visible) {
724
+ frame.setVisible(visible);
725
+
726
+ // Generally useful whenever setting the frame visible
727
+ if (canvas != null) {
728
+ //canvas.requestFocusInWindow();
729
+ canvas.requestFocus();
730
+ }
731
+
732
+ // removing per https://github.com/processing/processing/pull/3162
733
+ // can remove the code below once 3.0a6 is tested and behaving
647
734
  /*
648
735
  if (visible && PApplet.platform == PConstants.LINUX) {
649
736
  // Linux doesn't deal with insets the same way. We get fake insets
@@ -657,50 +744,52 @@ public class PSurfaceAWT extends PSurfaceNone {
657
744
  insets.top + insets.bottom);
658
745
  }
659
746
  }
660
- */
661
- }
747
+ */
748
+ }
662
749
 
663
- //public void placeFullScreen(boolean hideStop) {
664
- @Override
665
- public void placePresent(int stopColor) {
666
- setFullFrame();
667
750
 
668
- // After the pack(), the screen bounds are gonna be 0s
751
+ //public void placeFullScreen(boolean hideStop) {
752
+ @Override
753
+ public void placePresent(int stopColor) {
754
+ setFullFrame();
755
+
756
+ // After the pack(), the screen bounds are gonna be 0s
669
757
  // frame.setBounds(screenRect); // already called in setFullFrame()
670
- canvas.setBounds((screenRect.width - sketchWidth) / 2,
671
- (screenRect.height - sketchHeight) / 2,
672
- sketchWidth, sketchHeight);
758
+ canvas.setBounds((screenRect.width - sketchWidth) / 2,
759
+ (screenRect.height - sketchHeight) / 2,
760
+ sketchWidth, sketchHeight);
673
761
 
674
762
  // if (PApplet.platform == PConstants.MACOSX) {
675
763
  // macosxFullScreenEnable(frame);
676
764
  // macosxFullScreenToggle(frame);
677
765
  // }
678
- if (stopColor != 0) {
679
- Label label = new Label("stop");
680
- label.setForeground(new Color(stopColor, false));
681
- label.addMouseListener(new MouseAdapter() {
682
- @Override
683
- public void mousePressed(java.awt.event.MouseEvent e) {
684
- sketch.exit();
685
- }
686
- });
687
- frame.add(label);
688
-
689
- Dimension labelSize = label.getPreferredSize();
690
- // sometimes shows up truncated on mac
691
- //System.out.println("label width is " + labelSize.width);
692
- labelSize = new Dimension(100, labelSize.height);
693
- label.setSize(labelSize);
694
- label.setLocation(20, screenRect.height - labelSize.height - 20);
766
+
767
+ if (stopColor != 0) {
768
+ Label label = new Label("stop");
769
+ label.setForeground(new Color(stopColor, false));
770
+ label.addMouseListener(new MouseAdapter() {
771
+ @Override
772
+ public void mousePressed(java.awt.event.MouseEvent e) {
773
+ sketch.exit();
695
774
  }
775
+ });
776
+ frame.add(label);
777
+
778
+ Dimension labelSize = label.getPreferredSize();
779
+ // sometimes shows up truncated on mac
780
+ //System.out.println("label width is " + labelSize.width);
781
+ labelSize = new Dimension(100, labelSize.height);
782
+ label.setSize(labelSize);
783
+ label.setLocation(20, screenRect.height - labelSize.height - 20);
784
+ }
696
785
 
697
786
  // if (sketch.getGraphics().displayable()) {
698
787
  // setVisible(true);
699
788
  // }
700
- }
789
+ }
701
790
 
702
791
 
703
- /*
792
+ /*
704
793
  @Override
705
794
  public void placeWindow(int[] location) {
706
795
  setFrameSize(); //sketchWidth, sketchHeight);
@@ -744,132 +833,135 @@ public class PSurfaceAWT extends PSurfaceNone {
744
833
  frame.setVisible(true);
745
834
  }
746
835
  }
747
- */
748
- private void setCanvasSize() {
836
+ */
837
+
838
+
839
+ private void setCanvasSize() {
749
840
  // System.out.format("setting canvas size %d %d%n", sketchWidth, sketchHeight);
750
841
  // new Exception().printStackTrace(System.out);
751
- int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
752
- int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
842
+ int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
843
+ int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
753
844
 
754
- canvas.setBounds((contentW - sketchWidth) / 2,
755
- (contentH - sketchHeight) / 2,
756
- sketchWidth, sketchHeight);
757
- }
845
+ canvas.setBounds((contentW - sketchWidth)/2,
846
+ (contentH - sketchHeight)/2,
847
+ sketchWidth, sketchHeight);
848
+ }
758
849
 
759
- /**
760
- * Resize frame for these sketch (canvas) dimensions.
761
- */
762
- private Dimension setFrameSize() { //int sketchWidth, int sketchHeight) {
763
- // https://github.com/processing/processing/pull/3162
764
- frame.addNotify(); // using instead of show() to add the peer [fry]
850
+
851
+ /** Resize frame for these sketch (canvas) dimensions. */
852
+ private Dimension setFrameSize() { //int sketchWidth, int sketchHeight) {
853
+ // https://github.com/processing/processing/pull/3162
854
+ frame.addNotify(); // using instead of show() to add the peer [fry]
765
855
 
766
856
  // System.out.format("setting frame size %d %d %n", sketchWidth, sketchHeight);
767
857
  // new Exception().printStackTrace(System.out);
768
- currentInsets = frame.getInsets();
769
- int windowW = Math.max(sketchWidth, MIN_WINDOW_WIDTH)
770
- + currentInsets.left + currentInsets.right;
771
- int windowH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT)
772
- + currentInsets.top + currentInsets.bottom;
773
- frame.setSize(windowW, windowH);
774
- return new Dimension(windowW, windowH);
775
- }
858
+ currentInsets = frame.getInsets();
859
+ int windowW = Math.max(sketchWidth, MIN_WINDOW_WIDTH) +
860
+ currentInsets.left + currentInsets.right;
861
+ int windowH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT) +
862
+ currentInsets.top + currentInsets.bottom;
863
+ frame.setSize(windowW, windowH);
864
+ return new Dimension(windowW, windowH);
865
+ }
776
866
 
777
- private void setFrameCentered() {
778
- // Can't use frame.setLocationRelativeTo(null) because it sends the
779
- // frame to the main display, which undermines the --display setting.
780
- frame.setLocation(screenRect.x + (screenRect.width - sketchWidth) / 2,
781
- screenRect.y + (screenRect.height - sketchHeight) / 2);
782
- }
783
867
 
784
- /**
785
- * Hide the menu bar, make the Frame undecorated, set it to screenRect.
786
- */
787
- private void setFullFrame() {
788
- // Called here because the graphics device is needed before we can
789
- // determine whether the sketch wants size(displayWidth, displayHeight),
790
- // and getting the graphics device will be PSurface-specific.
791
- PApplet.hideMenuBar();
792
-
793
- // Tried to use this to fix the 'present' mode issue.
794
- // Did not help, and the screenRect setup seems to work fine.
795
- //frame.setExtendedState(Frame.MAXIMIZED_BOTH);
796
- // https://github.com/processing/processing/pull/3162
797
- //frame.dispose(); // release native resources, allows setUndecorated()
798
- frame.removeNotify();
799
- frame.setUndecorated(true);
800
- frame.addNotify();
868
+ private void setFrameCentered() {
869
+ // Can't use frame.setLocationRelativeTo(null) because it sends the
870
+ // frame to the main display, which undermines the --display setting.
871
+ frame.setLocation(screenRect.x + (screenRect.width - sketchWidth) / 2,
872
+ screenRect.y + (screenRect.height - sketchHeight) / 2);
873
+ }
801
874
 
802
- // this may be the bounds of all screens
803
- frame.setBounds(screenRect);
804
- // will be set visible in placeWindow() [3.0a10]
805
- //frame.setVisible(true); // re-add native resources
806
- }
807
875
 
808
- @Override
809
- public void placeWindow(int[] location, int[] editorLocation) {
810
- //Dimension window = setFrameSize(sketchWidth, sketchHeight);
811
- Dimension window = setFrameSize(); //sketchWidth, sketchHeight);
876
+ /** Hide the menu bar, make the Frame undecorated, set it to screenRect. */
877
+ private void setFullFrame() {
878
+ // Called here because the graphics device is needed before we can
879
+ // determine whether the sketch wants size(displayWidth, displayHeight),
880
+ // and getting the graphics device will be PSurface-specific.
881
+ PApplet.hideMenuBar();
812
882
 
813
- int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
814
- int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
883
+ // Tried to use this to fix the 'present' mode issue.
884
+ // Did not help, and the screenRect setup seems to work fine.
885
+ //frame.setExtendedState(Frame.MAXIMIZED_BOTH);
815
886
 
816
- if (sketch.sketchFullScreen()) {
817
- setFullFrame();
818
- }
887
+ // https://github.com/processing/processing/pull/3162
888
+ //frame.dispose(); // release native resources, allows setUndecorated()
889
+ frame.removeNotify();
890
+ frame.setUndecorated(true);
891
+ frame.addNotify();
819
892
 
820
- // Ignore placement of previous window and editor when full screen
821
- if (!sketch.sketchFullScreen()) {
822
- if (location != null) {
823
- // a specific location was received from the Runner
824
- // (applet has been run more than once, user placed window)
825
- frame.setLocation(location[0], location[1]);
826
-
827
- } else if (editorLocation != null) {
828
- int locationX = editorLocation[0] - 20;
829
- int locationY = editorLocation[1];
830
-
831
- if (locationX - window.width > 10) {
832
- // if it fits to the left of the window
833
- frame.setLocation(locationX - window.width, locationY);
834
-
835
- } else { // doesn't fit
836
- // if it fits inside the editor window,
837
- // offset slightly from upper lefthand corner
838
- // so that it's plunked inside the text area
839
- //locationX = editorLocation[0] + 66;
840
- //locationY = editorLocation[1] + 66;
841
- locationX = (sketch.displayWidth - window.width) / 2;
842
- locationY = (sketch.displayHeight - window.height) / 2;
843
-
844
- /*
893
+ // this may be the bounds of all screens
894
+ frame.setBounds(screenRect);
895
+ // will be set visible in placeWindow() [3.0a10]
896
+ //frame.setVisible(true); // re-add native resources
897
+ }
898
+
899
+
900
+ @Override
901
+ public void placeWindow(int[] location, int[] editorLocation) {
902
+ //Dimension window = setFrameSize(sketchWidth, sketchHeight);
903
+ Dimension window = setFrameSize(); //sketchWidth, sketchHeight);
904
+
905
+ int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
906
+ int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
907
+
908
+ if (sketch.sketchFullScreen()) {
909
+ setFullFrame();
910
+ }
911
+
912
+ // Ignore placement of previous window and editor when full screen
913
+ if (!sketch.sketchFullScreen()) {
914
+ if (location != null) {
915
+ // a specific location was received from the Runner
916
+ // (applet has been run more than once, user placed window)
917
+ frame.setLocation(location[0], location[1]);
918
+
919
+ } else if (editorLocation != null) {
920
+ int locationX = editorLocation[0] - 20;
921
+ int locationY = editorLocation[1];
922
+
923
+ if (locationX - window.width > 10) {
924
+ // if it fits to the left of the window
925
+ frame.setLocation(locationX - window.width, locationY);
926
+
927
+ } else { // doesn't fit
928
+ // if it fits inside the editor window,
929
+ // offset slightly from upper lefthand corner
930
+ // so that it's plunked inside the text area
931
+ //locationX = editorLocation[0] + 66;
932
+ //locationY = editorLocation[1] + 66;
933
+ locationX = (sketch.displayWidth - window.width) / 2;
934
+ locationY = (sketch.displayHeight - window.height) / 2;
935
+
936
+ /*
845
937
  if ((locationX + window.width > sketch.displayWidth - 33) ||
846
938
  (locationY + window.height > sketch.displayHeight - 33)) {
847
939
  // otherwise center on screen
848
940
  locationX = (sketch.displayWidth - window.width) / 2;
849
941
  locationY = (sketch.displayHeight - window.height) / 2;
850
942
  }
851
- */
852
- frame.setLocation(locationX, locationY);
853
- }
854
- } else { // just center on screen
855
- setFrameCentered();
856
- }
857
- Point frameLoc = frame.getLocation();
858
- if (frameLoc.y < 0) {
859
- // Windows actually allows you to place frames where they can't be
860
- // closed. Awesome. http://dev.processing.org/bugs/show_bug.cgi?id=1508
861
- frame.setLocation(frameLoc.x, 30);
862
- }
943
+ */
944
+ frame.setLocation(locationX, locationY);
863
945
  }
946
+ } else { // just center on screen
947
+ setFrameCentered();
948
+ }
949
+ Point frameLoc = frame.getLocation();
950
+ if (frameLoc.y < 0) {
951
+ // Windows actually allows you to place frames where they can't be
952
+ // closed. Awesome. http://dev.processing.org/bugs/show_bug.cgi?id=1508
953
+ frame.setLocation(frameLoc.x, 30);
954
+ }
955
+ }
864
956
 
865
- canvas.setBounds((contentW - sketchWidth) / 2,
866
- (contentH - sketchHeight) / 2,
867
- sketchWidth, sketchHeight);
957
+ canvas.setBounds((contentW - sketchWidth)/2,
958
+ (contentH - sketchHeight)/2,
959
+ sketchWidth, sketchHeight);
868
960
 
869
- // handle frame resizing events
870
- setupFrameResizeListener();
961
+ // handle frame resizing events
962
+ setupFrameResizeListener();
871
963
 
872
- /*
964
+ /*
873
965
  // If displayable() is false, then PSurfaceNone should be used, but...
874
966
  if (sketch.getGraphics().displayable()) {
875
967
  frame.setVisible(true);
@@ -880,64 +972,68 @@ public class PSurfaceAWT extends PSurfaceNone {
880
972
  // canvas.requestFocus();
881
973
  // }
882
974
  }
883
- */
975
+ */
884
976
  // if (sketch.getGraphics().displayable()) {
885
977
  // setVisible(true);
886
978
  // }
887
- }
979
+ }
888
980
 
889
- // needs to resize the frame, which will resize the canvas, and so on...
890
- @Override
891
- public void setSize(int wide, int high) {
892
- // When the surface is set to resizable via surface.setResizable(true),
893
- // a crash may occur if the user sets the window to size zero.
894
- // https://github.com/processing/processing/issues/5052
895
- if (high <= 0) {
896
- high = 1;
897
- }
898
- if (wide <= 0) {
899
- wide = 1;
900
- }
981
+
982
+ // needs to resize the frame, which will resize the canvas, and so on...
983
+ @Override
984
+ public void setSize(int wide, int high) {
985
+ // When the surface is set to resizable via surface.setResizable(true),
986
+ // a crash may occur if the user sets the window to size zero.
987
+ // https://github.com/processing/processing/issues/5052
988
+ if (high <= 0) {
989
+ high = 1;
990
+ }
991
+ if (wide <= 0) {
992
+ wide = 1;
993
+ }
901
994
 
902
995
  // if (PApplet.DEBUG) {
903
996
  // //System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high);
904
997
  // new Exception(String.format("setSize(%d, %d)", wide, high)).printStackTrace(System.out);
905
998
  // }
906
- //if (wide == sketchWidth && high == sketchHeight) { // doesn't work on launch
907
- if (wide == sketch.width && high == sketch.height
908
- && (frame == null || currentInsets.equals(frame.getInsets()))) {
999
+
1000
+ //if (wide == sketchWidth && high == sketchHeight) { // doesn't work on launch
1001
+ if (wide == sketch.width && high == sketch.height &&
1002
+ (frame == null || currentInsets.equals(frame.getInsets()))) {
909
1003
  // if (PApplet.DEBUG) {
910
1004
  // new Exception("w/h unchanged " + wide + " " + high).printStackTrace(System.out);
911
1005
  // }
912
- return; // unchanged, don't rebuild everything
913
- }
1006
+ return; // unchanged, don't rebuild everything
1007
+ }
914
1008
 
915
- sketchWidth = wide * windowScaleFactor;
916
- sketchHeight = high * windowScaleFactor;
1009
+ sketchWidth = wide * windowScaleFactor;
1010
+ sketchHeight = high * windowScaleFactor;
917
1011
 
918
1012
  // canvas.setSize(wide, high);
919
1013
  // frame.setSize(wide, high);
920
- if (frame != null) { // skip if just a canvas
921
- setFrameSize(); //wide, high);
922
- }
923
- setCanvasSize();
1014
+ if (frame != null) { // skip if just a canvas
1015
+ setFrameSize(); //wide, high);
1016
+ }
1017
+ setCanvasSize();
924
1018
  // if (frame != null) {
925
1019
  // frame.setLocationRelativeTo(null);
926
1020
  // }
927
1021
 
928
- //initImage(graphics, wide, high);
929
- //throw new RuntimeException("implement me, see readme.md");
930
- sketch.setSize(wide, high);
1022
+ //initImage(graphics, wide, high);
1023
+
1024
+ //throw new RuntimeException("implement me, see readme.md");
1025
+ sketch.setSize(wide, high);
931
1026
  // sketch.width = wide;
932
1027
  // sketch.height = high;
933
1028
 
934
- // set PGraphics variables for width/height/pixelWidth/pixelHeight
935
- graphics.setSize(wide, high);
1029
+ // set PGraphics variables for width/height/pixelWidth/pixelHeight
1030
+ graphics.setSize(wide, high);
936
1031
  // System.out.println("out of setSize()");
937
- }
1032
+ }
938
1033
 
939
- //public void initImage(PGraphics gr, int wide, int high) {
940
- /*
1034
+
1035
+ //public void initImage(PGraphics gr, int wide, int high) {
1036
+ /*
941
1037
  @Override
942
1038
  public void initImage(PGraphics graphics) {
943
1039
  GraphicsConfiguration gc = canvas.getGraphicsConfiguration();
@@ -954,15 +1050,21 @@ public class PSurfaceAWT extends PSurfaceNone {
954
1050
  int high = graphics.height * graphics.pixelFactor;
955
1051
  graphics.image = gc.createCompatibleImage(wide, high);
956
1052
  }
957
- */
1053
+ */
1054
+
1055
+
958
1056
  // @Override
959
1057
  // public Component getComponent() {
960
1058
  // return canvas;
961
1059
  // }
1060
+
1061
+
962
1062
  // @Override
963
1063
  // public void setSmooth(int level) {
964
1064
  // }
965
- /*
1065
+
1066
+
1067
+ /*
966
1068
  private boolean checkRetina() {
967
1069
  if (PApplet.platform == PConstants.MACOSX) {
968
1070
  // This should probably be reset each time there's a display change.
@@ -988,24 +1090,24 @@ public class PSurfaceAWT extends PSurfaceNone {
988
1090
  }
989
1091
  return false;
990
1092
  }
991
- */
992
- /**
993
- * Get the bounds rectangle for all displays.
994
- */
995
- static Rectangle getDisplaySpan() {
996
- Rectangle bounds = new Rectangle();
997
- GraphicsEnvironment environment
998
- = GraphicsEnvironment.getLocalGraphicsEnvironment();
999
- for (GraphicsDevice device : environment.getScreenDevices()) {
1000
- for (GraphicsConfiguration config : device.getConfigurations()) {
1001
- Rectangle2D.union(bounds, config.getBounds(), bounds);
1002
- }
1003
- }
1004
- return bounds;
1093
+ */
1094
+
1095
+
1096
+ /** Get the bounds rectangle for all displays. */
1097
+ static Rectangle getDisplaySpan() {
1098
+ Rectangle bounds = new Rectangle();
1099
+ GraphicsEnvironment environment =
1100
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
1101
+ for (GraphicsDevice device : environment.getScreenDevices()) {
1102
+ for (GraphicsConfiguration config : device.getConfigurations()) {
1103
+ Rectangle2D.union(bounds, config.getBounds(), bounds);
1104
+ }
1005
1105
  }
1106
+ return bounds;
1107
+ }
1006
1108
 
1007
1109
 
1008
- /*
1110
+ /*
1009
1111
  private void checkDisplaySize() {
1010
1112
  if (canvas.getGraphicsConfiguration() != null) {
1011
1113
  GraphicsDevice displayDevice = getGraphicsConfiguration().getDevice();
@@ -1019,81 +1121,85 @@ public class PSurfaceAWT extends PSurfaceNone {
1019
1121
  }
1020
1122
  }
1021
1123
  }
1022
- */
1023
- /**
1024
- * Set this sketch to communicate its state back to the PDE.
1025
- * <p/>
1026
- * This uses the stderr stream to write positions of the window (so that it
1027
- * will be saved by the PDE for the next run) and notify on quit. See more
1028
- * notes in the Worker class.
1029
- */
1030
- @Override
1031
- public void setupExternalMessages() {
1032
- frame.addComponentListener(new ComponentAdapter() {
1033
- @Override
1034
- public void componentMoved(ComponentEvent e) {
1035
- Point where = ((Frame) e.getSource()).getLocation();
1036
- sketch.frameMoved(where.x, where.y);
1037
- }
1038
- });
1039
- }
1124
+ */
1125
+
1126
+
1127
+ /**
1128
+ * Set this sketch to communicate its state back to the PDE.
1129
+ *
1130
+ * This uses the stderr stream to write positions of the window
1131
+ * (so that it will be saved by the PDE for the next run) and
1132
+ * notify on quit. See more notes in the Worker class.
1133
+ */
1134
+ @Override
1135
+ public void setupExternalMessages() {
1136
+ frame.addComponentListener(new ComponentAdapter() {
1137
+ @Override
1138
+ public void componentMoved(ComponentEvent e) {
1139
+ Point where = ((Frame) e.getSource()).getLocation();
1140
+ sketch.frameMoved(where.x, where.y);
1141
+ }
1142
+ });
1143
+ }
1144
+
1145
+
1146
+ /**
1147
+ * Set up a listener that will fire proper component resize events
1148
+ * in cases where frame.setResizable(true) is called.
1149
+ */
1150
+ private void setupFrameResizeListener() {
1151
+ frame.addWindowStateListener((WindowEvent e) -> {
1152
+ // This seems to be firing when dragging the window on OS X
1153
+ // https://github.com/processing/processing/issues/3092
1154
+ if (Frame.MAXIMIZED_BOTH == e.getNewState()) {
1155
+ // Supposedly, sending the frame to back and then front is a
1156
+ // workaround for this bug:
1157
+ // http://stackoverflow.com/a/23897602
1158
+ // but is not working for me...
1159
+ //frame.toBack();
1160
+ //frame.toFront();
1161
+ // Packing the frame works, but that causes the window to collapse
1162
+ // on OS X when the window is dragged. Changing to addNotify() for
1163
+ // https://github.com/processing/processing/issues/3092
1164
+ //frame.pack();
1165
+ frame.addNotify();
1166
+ }
1167
+ });
1168
+
1169
+ frame.addComponentListener(new ComponentAdapter() {
1170
+ @Override
1171
+ public void componentResized(ComponentEvent e) {
1172
+ // Ignore bad resize events fired during setup to fix
1173
+ // http://dev.processing.org/bugs/show_bug.cgi?id=341
1174
+ // This should also fix the blank screen on Linux bug
1175
+ // http://dev.processing.org/bugs/show_bug.cgi?id=282
1176
+ if (frame.isResizable()) {
1177
+ // might be multiple resize calls before visible (i.e. first
1178
+ // when pack() is called, then when it's resized for use).
1179
+ // ignore them because it's not the user resizing things.
1180
+ Frame farm = (Frame) e.getComponent();
1181
+ if (farm.isVisible()) {
1182
+ Dimension windowSize = farm.getSize();
1183
+ int x = farm.getX() + currentInsets.left;
1184
+ int y = farm.getY() + currentInsets.top;
1185
+
1186
+ // JFrame (unlike java.awt.Frame) doesn't include the left/top
1187
+ // insets for placement (though it does seem to need them for
1188
+ // overall size of the window. Perhaps JFrame sets its coord
1189
+ // system so that (0, 0) is always the upper-left of the content
1190
+ // area. Which seems nice, but breaks any f*ing AWT-based code.
1191
+ int w = windowSize.width - currentInsets.left - currentInsets.right;
1192
+ int h = windowSize.height - currentInsets.top - currentInsets.bottom;
1193
+ setSize(w / windowScaleFactor, h / windowScaleFactor);
1194
+
1195
+ // correct the location when inset size changes
1196
+ setLocation(x - currentInsets.left, y - currentInsets.top);
1197
+ }
1198
+ }
1199
+ }
1200
+ });
1201
+ }
1040
1202
 
1041
- /**
1042
- * Set up a listener that will fire proper component resize events in cases
1043
- * where frame.setResizable(true) is called.
1044
- */
1045
- private void setupFrameResizeListener() {
1046
- frame.addWindowStateListener((WindowEvent e) -> {
1047
- // This seems to be firing when dragging the window on OS X
1048
- // https://github.com/processing/processing/issues/3092
1049
- if (Frame.MAXIMIZED_BOTH == e.getNewState()) {
1050
- // Supposedly, sending the frame to back and then front is a
1051
- // workaround for this bug:
1052
- // http://stackoverflow.com/a/23897602
1053
- // but is not working for me...
1054
- //frame.toBack();
1055
- //frame.toFront();
1056
- // Packing the frame works, but that causes the window to collapse
1057
- // on OS X when the window is dragged. Changing to addNotify() for
1058
- // https://github.com/processing/processing/issues/3092
1059
- //frame.pack();
1060
- frame.addNotify();
1061
- }
1062
- });
1063
-
1064
- frame.addComponentListener(new ComponentAdapter() {
1065
- @Override
1066
- public void componentResized(ComponentEvent e) {
1067
- // Ignore bad resize events fired during setup to fix
1068
- // http://dev.processing.org/bugs/show_bug.cgi?id=341
1069
- // This should also fix the blank screen on Linux bug
1070
- // http://dev.processing.org/bugs/show_bug.cgi?id=282
1071
- if (frame.isResizable()) {
1072
- // might be multiple resize calls before visible (i.e. first
1073
- // when pack() is called, then when it's resized for use).
1074
- // ignore them because it's not the user resizing things.
1075
- Frame farm = (Frame) e.getComponent();
1076
- if (farm.isVisible()) {
1077
- Dimension windowSize = farm.getSize();
1078
- int x = farm.getX() + currentInsets.left;
1079
- int y = farm.getY() + currentInsets.top;
1080
-
1081
- // JFrame (unlike java.awt.Frame) doesn't include the left/top
1082
- // insets for placement (though it does seem to need them for
1083
- // overall size of the window. Perhaps JFrame sets its coord
1084
- // system so that (0, 0) is always the upper-left of the content
1085
- // area. Which seems nice, but breaks any f*ing AWT-based code.
1086
- int w = windowSize.width - currentInsets.left - currentInsets.right;
1087
- int h = windowSize.height - currentInsets.top - currentInsets.bottom;
1088
- setSize(w / windowScaleFactor, h / windowScaleFactor);
1089
-
1090
- // correct the location when inset size changes
1091
- setLocation(x - currentInsets.left, y - currentInsets.top);
1092
- }
1093
- }
1094
- }
1095
- });
1096
- }
1097
1203
 
1098
1204
  // /**
1099
1205
  // * (No longer in use) Use reflection to call
@@ -1135,8 +1241,12 @@ public class PSurfaceAWT extends PSurfaceNone {
1135
1241
  // e.printStackTrace();
1136
1242
  // }
1137
1243
  // }
1138
- //////////////////////////////////////////////////////////////
1139
- /*
1244
+
1245
+
1246
+ //////////////////////////////////////////////////////////////
1247
+
1248
+
1249
+ /*
1140
1250
  // disabling for now; requires Java 1.7 and "precise" semantics are odd...
1141
1251
  // returns 0.1 for tick-by-tick scrolling on OS X, but it's not a matter of
1142
1252
  // calling ceil() on the value: 1.5 goes to 1, but 2.3 goes to 2.
@@ -1149,46 +1259,46 @@ public class PSurfaceAWT extends PSurfaceNone {
1149
1259
  // ignored, the method will just be set to null
1150
1260
  }
1151
1261
  }
1152
- */
1153
- /**
1154
- * Figure out how to process a mouse event.When loop() has been called, the
1155
- * events will be queued up until drawing is complete. If noLoop() has been
1156
- * called, then events will happen immediately.
1157
- *
1158
- * @param nativeEvent
1159
- */
1160
- protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) {
1161
- // the 'amount' is the number of button clicks for a click event,
1162
- // or the number of steps/clicks on the wheel for a mouse wheel event.
1163
- int peCount = nativeEvent.getClickCount();
1164
-
1165
- int peAction = 0;
1166
- switch (nativeEvent.getID()) {
1167
- case java.awt.event.MouseEvent.MOUSE_PRESSED:
1168
- peAction = MouseEvent.PRESS;
1169
- break;
1170
- case java.awt.event.MouseEvent.MOUSE_RELEASED:
1171
- peAction = MouseEvent.RELEASE;
1172
- break;
1173
- case java.awt.event.MouseEvent.MOUSE_CLICKED:
1174
- peAction = MouseEvent.CLICK;
1175
- break;
1176
- case java.awt.event.MouseEvent.MOUSE_DRAGGED:
1177
- peAction = MouseEvent.DRAG;
1178
- break;
1179
- case java.awt.event.MouseEvent.MOUSE_MOVED:
1180
- peAction = MouseEvent.MOVE;
1181
- break;
1182
- case java.awt.event.MouseEvent.MOUSE_ENTERED:
1183
- peAction = MouseEvent.ENTER;
1184
- break;
1185
- case java.awt.event.MouseEvent.MOUSE_EXITED:
1186
- peAction = MouseEvent.EXIT;
1187
- break;
1188
- //case java.awt.event.MouseWheelEvent.WHEEL_UNIT_SCROLL:
1189
- case java.awt.event.MouseEvent.MOUSE_WHEEL:
1190
- peAction = MouseEvent.WHEEL;
1191
- /*
1262
+ */
1263
+
1264
+
1265
+ /**
1266
+ * Figure out how to process a mouse event.When loop() has been
1267
+ called, the events will be queued up until drawing is complete. If noLoop() has been called, then events will happen immediately.
1268
+ * @param nativeEvent
1269
+ */
1270
+ protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) {
1271
+ // the 'amount' is the number of button clicks for a click event,
1272
+ // or the number of steps/clicks on the wheel for a mouse wheel event.
1273
+ int peCount = nativeEvent.getClickCount();
1274
+
1275
+ int peAction = 0;
1276
+ switch (nativeEvent.getID()) {
1277
+ case java.awt.event.MouseEvent.MOUSE_PRESSED:
1278
+ peAction = MouseEvent.PRESS;
1279
+ break;
1280
+ case java.awt.event.MouseEvent.MOUSE_RELEASED:
1281
+ peAction = MouseEvent.RELEASE;
1282
+ break;
1283
+ case java.awt.event.MouseEvent.MOUSE_CLICKED:
1284
+ peAction = MouseEvent.CLICK;
1285
+ break;
1286
+ case java.awt.event.MouseEvent.MOUSE_DRAGGED:
1287
+ peAction = MouseEvent.DRAG;
1288
+ break;
1289
+ case java.awt.event.MouseEvent.MOUSE_MOVED:
1290
+ peAction = MouseEvent.MOVE;
1291
+ break;
1292
+ case java.awt.event.MouseEvent.MOUSE_ENTERED:
1293
+ peAction = MouseEvent.ENTER;
1294
+ break;
1295
+ case java.awt.event.MouseEvent.MOUSE_EXITED:
1296
+ peAction = MouseEvent.EXIT;
1297
+ break;
1298
+ //case java.awt.event.MouseWheelEvent.WHEEL_UNIT_SCROLL:
1299
+ case java.awt.event.MouseEvent.MOUSE_WHEEL:
1300
+ peAction = MouseEvent.WHEEL;
1301
+ /*
1192
1302
  if (preciseWheelMethod != null) {
1193
1303
  try {
1194
1304
  peAmount = ((Double) preciseWheelMethod.invoke(nativeEvent, (Object[]) null)).floatValue();
@@ -1196,167 +1306,157 @@ public class PSurfaceAWT extends PSurfaceNone {
1196
1306
  preciseWheelMethod = null;
1197
1307
  }
1198
1308
  }
1199
- */
1200
- peCount = ((MouseWheelEvent) nativeEvent).getWheelRotation();
1201
- break;
1202
- }
1309
+ */
1310
+ peCount = ((MouseWheelEvent) nativeEvent).getWheelRotation();
1311
+ break;
1312
+ }
1203
1313
 
1204
- //System.out.println(nativeEvent);
1205
- //int modifiers = nativeEvent.getModifiersEx();
1206
- // If using getModifiersEx(), the regular modifiers don't set properly.
1207
- int modifiers = nativeEvent.getModifiers();
1208
-
1209
- int peModifiers = modifiers
1210
- & (InputEvent.SHIFT_MASK
1211
- | InputEvent.CTRL_MASK
1212
- | InputEvent.META_MASK
1213
- | InputEvent.ALT_MASK);
1214
-
1215
- // Windows and OS X seem to disagree on how to handle this. Windows only
1216
- // sets BUTTON1_DOWN_MASK, while OS X seems to set BUTTON1_MASK.
1217
- // This is an issue in particular with mouse release events:
1218
- // http://code.google.com/p/processing/issues/detail?id=1294
1219
- // The fix for which led to a regression (fixed here by checking both):
1220
- // http://code.google.com/p/processing/issues/detail?id=1332
1221
- int peButton = 0;
1222
- // if ((modifiers & InputEvent.BUTTON1_MASK) != 0 ||
1223
- // (modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
1224
- // peButton = LEFT;
1225
- // } else if ((modifiers & InputEvent.BUTTON2_MASK) != 0 ||
1226
- // (modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
1227
- // peButton = CENTER;
1228
- // } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0 ||
1229
- // (modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
1230
- // peButton = RIGHT;
1231
- // }
1232
- if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
1233
- peButton = PConstants.LEFT;
1234
- } else if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
1235
- peButton = PConstants.CENTER;
1236
- } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
1237
- peButton = PConstants.RIGHT;
1238
- }
1314
+ // Switching to getModifiersEx() for 4.0a2 because of Java 9 deprecation.
1315
+ // Had trouble with this in the past and rolled it back because it was
1316
+ // optional at the time. This time around, just need to iron out the issue.
1317
+ // http://code.google.com/p/processing/issues/detail?id=1294
1318
+ // http://code.google.com/p/processing/issues/detail?id=1332
1319
+ int modifiers = nativeEvent.getModifiersEx();
1320
+
1321
+ int peButton = 0;
1322
+ if ((modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
1323
+ peButton = PConstants.LEFT;
1324
+ } else if ((modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
1325
+ peButton = PConstants.CENTER;
1326
+ } else if ((modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
1327
+ peButton = PConstants.RIGHT;
1328
+ }
1329
+
1330
+ sketch.postEvent(new MouseEvent(nativeEvent, nativeEvent.getWhen(),
1331
+ peAction, modifiers,
1332
+ nativeEvent.getX() / windowScaleFactor,
1333
+ nativeEvent.getY() / windowScaleFactor,
1334
+ peButton,
1335
+ peCount));
1336
+ }
1239
1337
 
1240
- // If running on Mac OS, allow ctrl-click as right mouse. Prior to 0215,
1241
- // this used isPopupTrigger() on the native event, but that doesn't work
1242
- // for mouseClicked and mouseReleased (or others).
1243
- if (PApplet.platform == PConstants.MACOSX) {
1244
- //if (nativeEvent.isPopupTrigger()) {
1245
- if ((modifiers & InputEvent.CTRL_MASK) != 0) {
1246
- peButton = PConstants.RIGHT;
1247
- }
1248
- }
1249
1338
 
1250
- sketch.postEvent(new MouseEvent(nativeEvent, nativeEvent.getWhen(),
1251
- peAction, peModifiers,
1252
- nativeEvent.getX() / windowScaleFactor,
1253
- nativeEvent.getY() / windowScaleFactor,
1254
- peButton,
1255
- peCount));
1339
+ protected void nativeKeyEvent(java.awt.event.KeyEvent event) {
1340
+ int peAction = 0;
1341
+ switch (event.getID()) {
1342
+ case java.awt.event.KeyEvent.KEY_PRESSED:
1343
+ peAction = KeyEvent.PRESS;
1344
+ break;
1345
+ case java.awt.event.KeyEvent.KEY_RELEASED:
1346
+ peAction = KeyEvent.RELEASE;
1347
+ break;
1348
+ case java.awt.event.KeyEvent.KEY_TYPED:
1349
+ peAction = KeyEvent.TYPE;
1350
+ break;
1256
1351
  }
1257
1352
 
1258
- protected void nativeKeyEvent(java.awt.event.KeyEvent event) {
1259
- int peAction = 0;
1260
- switch (event.getID()) {
1261
- case java.awt.event.KeyEvent.KEY_PRESSED:
1262
- peAction = KeyEvent.PRESS;
1263
- break;
1264
- case java.awt.event.KeyEvent.KEY_RELEASED:
1265
- peAction = KeyEvent.RELEASE;
1266
- break;
1267
- case java.awt.event.KeyEvent.KEY_TYPED:
1268
- peAction = KeyEvent.TYPE;
1269
- break;
1270
- }
1353
+ int modifiers = event.getModifiersEx();
1271
1354
 
1355
+ /*
1272
1356
  // int peModifiers = event.getModifiersEx() &
1273
1357
  // (InputEvent.SHIFT_DOWN_MASK |
1274
1358
  // InputEvent.CTRL_DOWN_MASK |
1275
1359
  // InputEvent.META_DOWN_MASK |
1276
1360
  // InputEvent.ALT_DOWN_MASK);
1277
- int peModifiers = event.getModifiers()
1278
- & (InputEvent.SHIFT_MASK
1279
- | InputEvent.CTRL_MASK
1280
- | InputEvent.META_MASK
1281
- | InputEvent.ALT_MASK);
1282
-
1283
- sketch.postEvent(new KeyEvent(event, event.getWhen(),
1284
- peAction, peModifiers,
1285
- event.getKeyChar(), event.getKeyCode()));
1286
- }
1361
+ int peModifiers = event.getModifiers() &
1362
+ (InputEvent.SHIFT_MASK |
1363
+ InputEvent.CTRL_MASK |
1364
+ InputEvent.META_MASK |
1365
+ InputEvent.ALT_MASK);
1366
+ */
1287
1367
 
1288
- // listeners, for all my men!
1289
- protected void addListeners() {
1368
+ sketch.postEvent(new KeyEvent(event, event.getWhen(),
1369
+ peAction, modifiers,
1370
+ event.getKeyChar(), event.getKeyCode()));
1371
+ }
1290
1372
 
1291
- canvas.addMouseListener(new MouseListener() {
1292
1373
 
1293
- public void mousePressed(java.awt.event.MouseEvent e) {
1294
- nativeMouseEvent(e);
1295
- }
1374
+ // listeners, for all my men!
1375
+ protected void addListeners() {
1296
1376
 
1297
- public void mouseReleased(java.awt.event.MouseEvent e) {
1298
- nativeMouseEvent(e);
1299
- }
1377
+ canvas.addMouseListener(new MouseListener() {
1300
1378
 
1301
- public void mouseClicked(java.awt.event.MouseEvent e) {
1302
- nativeMouseEvent(e);
1303
- }
1379
+ @Override
1380
+ public void mousePressed(java.awt.event.MouseEvent e) {
1381
+ nativeMouseEvent(e);
1382
+ }
1304
1383
 
1305
- public void mouseEntered(java.awt.event.MouseEvent e) {
1306
- nativeMouseEvent(e);
1307
- }
1384
+ @Override
1385
+ public void mouseReleased(java.awt.event.MouseEvent e) {
1386
+ nativeMouseEvent(e);
1387
+ }
1308
1388
 
1309
- public void mouseExited(java.awt.event.MouseEvent e) {
1310
- nativeMouseEvent(e);
1311
- }
1312
- });
1389
+ @Override
1390
+ public void mouseClicked(java.awt.event.MouseEvent e) {
1391
+ nativeMouseEvent(e);
1392
+ }
1313
1393
 
1314
- canvas.addMouseMotionListener(new MouseMotionListener() {
1394
+ @Override
1395
+ public void mouseEntered(java.awt.event.MouseEvent e) {
1396
+ nativeMouseEvent(e);
1397
+ }
1315
1398
 
1316
- public void mouseDragged(java.awt.event.MouseEvent e) {
1317
- nativeMouseEvent(e);
1318
- }
1399
+ @Override
1400
+ public void mouseExited(java.awt.event.MouseEvent e) {
1401
+ nativeMouseEvent(e);
1402
+ }
1403
+ });
1319
1404
 
1320
- public void mouseMoved(java.awt.event.MouseEvent e) {
1321
- nativeMouseEvent(e);
1322
- }
1323
- });
1405
+ canvas.addMouseMotionListener(new MouseMotionListener() {
1324
1406
 
1325
- canvas.addMouseWheelListener((MouseWheelEvent e) -> {
1326
- nativeMouseEvent(e);
1327
- });
1407
+ @Override
1408
+ public void mouseDragged(java.awt.event.MouseEvent e) {
1409
+ nativeMouseEvent(e);
1410
+ }
1328
1411
 
1329
- canvas.addKeyListener(new KeyListener() {
1412
+ @Override
1413
+ public void mouseMoved(java.awt.event.MouseEvent e) {
1414
+ nativeMouseEvent(e);
1415
+ }
1416
+ });
1330
1417
 
1331
- public void keyPressed(java.awt.event.KeyEvent e) {
1332
- nativeKeyEvent(e);
1333
- }
1418
+ canvas.addMouseWheelListener((MouseWheelEvent e) -> {
1419
+ nativeMouseEvent(e);
1420
+ });
1334
1421
 
1335
- public void keyReleased(java.awt.event.KeyEvent e) {
1336
- nativeKeyEvent(e);
1337
- }
1422
+ canvas.addKeyListener(new KeyListener() {
1338
1423
 
1339
- public void keyTyped(java.awt.event.KeyEvent e) {
1340
- nativeKeyEvent(e);
1341
- }
1342
- });
1424
+ @Override
1425
+ public void keyPressed(java.awt.event.KeyEvent e) {
1426
+ nativeKeyEvent(e);
1427
+ }
1343
1428
 
1344
- canvas.addFocusListener(new FocusListener() {
1345
1429
 
1346
- public void focusGained(FocusEvent e) {
1347
- sketch.focused = true;
1348
- sketch.focusGained();
1349
- }
1430
+ @Override
1431
+ public void keyReleased(java.awt.event.KeyEvent e) {
1432
+ nativeKeyEvent(e);
1433
+ }
1350
1434
 
1351
- public void focusLost(FocusEvent e) {
1352
- sketch.focused = false;
1353
- sketch.focusLost();
1354
- }
1355
- });
1356
- }
1357
1435
 
1436
+ @Override
1437
+ public void keyTyped(java.awt.event.KeyEvent e) {
1438
+ nativeKeyEvent(e);
1439
+ }
1440
+ });
1441
+
1442
+ canvas.addFocusListener(new FocusListener() {
1358
1443
 
1359
- /*
1444
+ @Override
1445
+ public void focusGained(FocusEvent e) {
1446
+ sketch.focused = true;
1447
+ sketch.focusGained();
1448
+ }
1449
+
1450
+ @Override
1451
+ public void focusLost(FocusEvent e) {
1452
+ sketch.focused = false;
1453
+ sketch.focusLost();
1454
+ }
1455
+ });
1456
+ }
1457
+
1458
+
1459
+ /*
1360
1460
  public void addListeners(Component comp) {
1361
1461
  comp.addMouseListener(this);
1362
1462
  comp.addMouseWheelListener(this);
@@ -1373,7 +1473,9 @@ public class PSurfaceAWT extends PSurfaceNone {
1373
1473
  comp.removeKeyListener(this);
1374
1474
  comp.removeFocusListener(this);
1375
1475
  }
1376
- */
1476
+ */
1477
+
1478
+
1377
1479
  // /**
1378
1480
  // * Call to remove, then add, listeners to a component.
1379
1481
  // * Avoids issues with double-adding.
@@ -1382,87 +1484,98 @@ public class PSurfaceAWT extends PSurfaceNone {
1382
1484
  // removeListeners(comp);
1383
1485
  // addListeners(comp);
1384
1486
  // }
1385
- // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1386
- int cursorType = PConstants.ARROW;
1387
- boolean cursorVisible = true;
1388
- Cursor invisibleCursor;
1389
1487
 
1390
- @Override
1391
- public void setCursor(int kind) {
1392
- // Swap the HAND cursor because MOVE doesn't seem to be available on OS X
1393
- // https://github.com/processing/processing/issues/2358
1394
- if (PApplet.platform == PConstants.MACOSX && kind == PConstants.MOVE) {
1395
- kind = PConstants.HAND;
1396
- }
1397
- canvas.setCursor(Cursor.getPredefinedCursor(kind));
1398
- cursorVisible = true;
1399
- this.cursorType = kind;
1400
- }
1401
1488
 
1402
- @Override
1403
- public void setCursor(PImage img, int x, int y) {
1404
- // Don't set cursorType, instead use cursorType to save the last
1405
- // regular cursor type used for when cursor() is called.
1406
- //cursor_type = Cursor.CUSTOM_CURSOR;
1407
-
1408
- // this is a temporary workaround for the CHIP, will be removed
1409
- Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(img.width, img.height);
1410
- if (cursorSize.width == 0 || cursorSize.height == 0) {
1411
- return;
1412
- }
1413
1489
 
1414
- Cursor cursor
1415
- = canvas.getToolkit().createCustomCursor((Image) img.getNative(),
1416
- new Point(x, y),
1417
- "custom");
1418
- canvas.setCursor(cursor);
1419
- cursorVisible = true;
1420
- }
1490
+ // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1421
1491
 
1422
- @Override
1423
- public void showCursor() {
1424
- // Maybe should always set here? Seems dangerous, since it's likely that
1425
- // Java will set the cursor to something else on its own, and the sketch
1426
- // will be stuck b/c p5 thinks the cursor is set to one particular thing.
1427
- if (!cursorVisible) {
1428
- cursorVisible = true;
1429
- canvas.setCursor(Cursor.getPredefinedCursor(cursorType));
1430
- }
1492
+
1493
+ int cursorType = PConstants.ARROW;
1494
+ boolean cursorVisible = true;
1495
+ Cursor invisibleCursor;
1496
+
1497
+
1498
+ @Override
1499
+ public void setCursor(int kind) {
1500
+ // Swap the HAND cursor because MOVE doesn't seem to be available on OS X
1501
+ // https://github.com/processing/processing/issues/2358
1502
+ if (PApplet.platform == PConstants.MACOS && kind == PConstants.MOVE) {
1503
+ kind = PConstants.HAND;
1431
1504
  }
1505
+ canvas.setCursor(Cursor.getPredefinedCursor(kind));
1506
+ cursorVisible = true;
1507
+ this.cursorType = kind;
1508
+ }
1432
1509
 
1433
- @Override
1434
- public void hideCursor() {
1435
- // Because the OS may have shown the cursor on its own,
1436
- // don't return if 'cursorVisible' is set to true. [rev 0216]
1437
-
1438
- if (invisibleCursor == null) {
1439
- BufferedImage cursorImg
1440
- = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
1441
- // this is a temporary workaround for the CHIP, will be removed
1442
- Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(16, 16);
1443
- if (cursorSize.width == 0 || cursorSize.height == 0) {
1444
- invisibleCursor = Cursor.getDefaultCursor();
1445
- } else {
1446
- invisibleCursor
1447
- = canvas.getToolkit().createCustomCursor(cursorImg, new Point(8, 8), "blank");
1448
- }
1449
- }
1450
- canvas.setCursor(invisibleCursor);
1451
- cursorVisible = false;
1510
+
1511
+ @Override
1512
+ public void setCursor(PImage img, int x, int y) {
1513
+ // Don't set cursorType, instead use cursorType to save the last
1514
+ // regular cursor type used for when cursor() is called.
1515
+ //cursor_type = Cursor.CUSTOM_CURSOR;
1516
+
1517
+ // this is a temporary workaround for the CHIP, will be removed
1518
+ Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(img.width, img.height);
1519
+ if (cursorSize.width == 0 || cursorSize.height == 0) {
1520
+ return;
1452
1521
  }
1453
1522
 
1454
- @Override
1455
- public Thread createThread() {
1456
- return new AnimationThread() {
1457
- @Override
1458
- public void callDraw() {
1459
- sketch.handleDraw();
1460
- render();
1461
- }
1462
- };
1523
+ Cursor cursor =
1524
+ canvas.getToolkit().createCustomCursor((Image) img.getNative(),
1525
+ new Point(x, y),
1526
+ "custom");
1527
+ canvas.setCursor(cursor);
1528
+ cursorVisible = true;
1529
+ }
1530
+
1531
+
1532
+ @Override
1533
+ public void showCursor() {
1534
+ // Maybe should always set here? Seems dangerous, since it's likely that
1535
+ // Java will set the cursor to something else on its own, and the sketch
1536
+ // will be stuck b/c p5 thinks the cursor is set to one particular thing.
1537
+ if (!cursorVisible) {
1538
+ cursorVisible = true;
1539
+ canvas.setCursor(Cursor.getPredefinedCursor(cursorType));
1463
1540
  }
1541
+ }
1542
+
1464
1543
 
1465
- void debug(String format, Object... args) {
1466
- System.out.format(format + "%n", args);
1544
+ @Override
1545
+ public void hideCursor() {
1546
+ // Because the OS may have shown the cursor on its own,
1547
+ // don't return if 'cursorVisible' is set to true. [rev 0216]
1548
+
1549
+ if (invisibleCursor == null) {
1550
+ BufferedImage cursorImg =
1551
+ new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
1552
+ // this is a temporary workaround for the CHIP, will be removed
1553
+ Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(16, 16);
1554
+ if (cursorSize.width == 0 || cursorSize.height == 0) {
1555
+ invisibleCursor = Cursor.getDefaultCursor();
1556
+ } else {
1557
+ invisibleCursor =
1558
+ canvas.getToolkit().createCustomCursor(cursorImg, new Point(8, 8), "blank");
1559
+ }
1467
1560
  }
1561
+ canvas.setCursor(invisibleCursor);
1562
+ cursorVisible = false;
1563
+ }
1564
+
1565
+
1566
+ @Override
1567
+ public Thread createThread() {
1568
+ return new AnimationThread() {
1569
+ @Override
1570
+ public void callDraw() {
1571
+ sketch.handleDraw();
1572
+ render();
1573
+ }
1574
+ };
1575
+ }
1576
+
1577
+
1578
+ void debug(String format, Object ... args) {
1579
+ System.out.format(format + "%n", args);
1580
+ }
1468
1581
  }