propane 3.4.0-java → 3.7.0.pre-java

Sign up to get free protection for your applications and to get access to all the features.
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
 
@@ -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,12 +59,13 @@ 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
 
63
+ public class PSurfaceAWT extends PSurfaceNone {
61
64
  GraphicsDevice displayDevice;
62
65
 
63
66
  // used for canvas to determine whether resizable or not
64
67
  // boolean resizable; // default is false
68
+
65
69
  // Internally, we know it's always a JFrame (not just a Frame)
66
70
  // JFrame frame;
67
71
  // Trying Frame again with a11 to see if this avoids some Swing nastiness.
@@ -79,15 +83,18 @@ public class PSurfaceAWT extends PSurfaceNone {
79
83
 
80
84
  // 3.0a5 didn't use strategy, and active was shut off during init() w/ retina
81
85
  // boolean useStrategy = true;
86
+
82
87
  Canvas canvas;
83
88
  // Component canvas;
84
89
 
85
90
  // PGraphics graphics; // moved to PSurfaceNone
91
+
86
92
  int sketchWidth;
87
93
  int sketchHeight;
88
94
 
89
95
  int windowScaleFactor;
90
96
 
97
+
91
98
  public PSurfaceAWT(PGraphics graphics) {
92
99
  //this.graphics = graphics;
93
100
  super(graphics);
@@ -113,7 +120,7 @@ public class PSurfaceAWT extends PSurfaceNone {
113
120
  // flicker--pushing pixels out before the screen has finished rendering.
114
121
  // useStrategy = false;
115
122
  }
116
- */
123
+ */
117
124
  canvas = new SmoothCanvas();
118
125
  // if (useStrategy) {
119
126
  //canvas.setIgnoreRepaint(true);
@@ -129,8 +136,8 @@ public class PSurfaceAWT extends PSurfaceNone {
129
136
  // make sure this is a real resize event, not just initial setup
130
137
  // https://github.com/processing/processing/issues/3310
131
138
  Dimension canvasSize = canvas.getSize();
132
- if (canvasSize.width != sketch.sketchWidth()
133
- || canvasSize.height != sketch.sketchHeight()) {
139
+ if (canvasSize.width != sketch.sketchWidth() ||
140
+ canvasSize.height != sketch.sketchHeight()) {
134
141
  sketch.redraw();
135
142
  }
136
143
  }
@@ -139,6 +146,7 @@ public class PSurfaceAWT extends PSurfaceNone {
139
146
  addListeners();
140
147
  }
141
148
 
149
+
142
150
  // /**
143
151
  // * Handle grabbing the focus on startup. Other renderers can override this
144
152
  // * if handling needs to be different. For the AWT, the request is invoked
@@ -173,33 +181,41 @@ public class PSurfaceAWT extends PSurfaceNone {
173
181
  // }
174
182
  // });
175
183
  // }
184
+
185
+
176
186
  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
177
- public class SmoothCanvas extends Canvas {
178
187
 
188
+
189
+ public class SmoothCanvas extends Canvas {
179
190
  private Dimension oldSize = new Dimension(0, 0);
180
191
  private Dimension newSize = new Dimension(0, 0);
181
192
 
193
+
182
194
  // Turns out getParent() returns a JPanel on a JFrame. Yech.
183
195
  public Frame getFrame() {
184
196
  return frame;
185
197
  }
186
198
 
199
+
187
200
  @Override
188
201
  public Dimension getPreferredSize() {
189
202
  return new Dimension(sketchWidth, sketchHeight);
190
203
  }
191
204
 
205
+
192
206
  @Override
193
207
  public Dimension getMinimumSize() {
194
208
  return getPreferredSize();
195
209
  }
196
210
 
211
+
197
212
  @Override
198
213
  public Dimension getMaximumSize() {
199
214
  //return resizable ? super.getMaximumSize() : getPreferredSize();
200
215
  return frame.isResizable() ? super.getMaximumSize() : getPreferredSize();
201
216
  }
202
217
 
218
+
203
219
  @Override
204
220
  public void validate() {
205
221
  super.validate();
@@ -221,12 +237,14 @@ public class PSurfaceAWT extends PSurfaceNone {
221
237
  }
222
238
  }
223
239
 
240
+
224
241
  @Override
225
242
  public void update(Graphics g) {
226
243
  // System.out.println("updating");
227
244
  paint(g);
228
245
  }
229
246
 
247
+
230
248
  @Override
231
249
  public void paint(Graphics screen) {
232
250
  // System.out.println("painting");
@@ -237,7 +255,7 @@ public class PSurfaceAWT extends PSurfaceNone {
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);
@@ -254,7 +272,7 @@ public class PSurfaceAWT extends PSurfaceNone {
254
272
  }
255
273
  }
256
274
 
257
- /*
275
+ /*
258
276
  @Override
259
277
  public void addNotify() {
260
278
  // System.out.println("adding notify");
@@ -262,10 +280,12 @@ 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
- */
283
+ */
284
+
285
+
266
286
  synchronized protected void render() {
267
- if (canvas.isDisplayable()
268
- && graphics.image != null) {
287
+ if (canvas.isDisplayable() &&
288
+ graphics.image != null) {
269
289
  if (canvas.getBufferStrategy() == null) {
270
290
  canvas.createBufferStrategy(2);
271
291
  }
@@ -335,7 +355,44 @@ public class PSurfaceAWT extends PSurfaceNone {
335
355
  }
336
356
  }
337
357
  }
338
- */
358
+ */
359
+
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
+
339
396
  // what needs to happen here?
340
397
  @Override
341
398
  public void initOffscreen(PApplet sketch) {
@@ -349,9 +406,9 @@ public class PSurfaceAWT extends PSurfaceNone {
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,14 +419,16 @@ public class PSurfaceAWT extends PSurfaceNone {
362
419
 
363
420
  return canvas;
364
421
  }
365
- */
422
+ */
423
+
424
+
366
425
  @Override
367
426
  public void initFrame(final PApplet sketch) {/*, int backgroundColor,
368
427
  int deviceIndex, boolean fullScreen, boolean spanDisplays) {*/
369
428
  this.sketch = sketch;
370
429
 
371
- GraphicsEnvironment environment
372
- = GraphicsEnvironment.getLocalGraphicsEnvironment();
430
+ GraphicsEnvironment environment =
431
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
373
432
 
374
433
  int displayNum = sketch.sketchDisplay();
375
434
  // System.out.println("display from sketch is " + displayNum);
@@ -378,10 +437,10 @@ public class PSurfaceAWT extends PSurfaceNone {
378
437
  if (displayNum <= devices.length) {
379
438
  displayDevice = devices[displayNum - 1];
380
439
  } else {
381
- System.err.format("Display %d does not exist, "
382
- + "using the default display instead.%n", displayNum);
440
+ System.err.format("Display %d does not exist, " +
441
+ "using the default display instead.%n", displayNum);
383
442
  for (int i = 0; i < devices.length; i++) {
384
- System.err.format("Display %d is %s%n", (i + 1), devices[i]);
443
+ System.err.format("Display %d is %s%n", (i+1), devices[i]);
385
444
  }
386
445
  }
387
446
  }
@@ -393,8 +452,8 @@ public class PSurfaceAWT extends PSurfaceNone {
393
452
  // because pack() will cause the bounds to go to zero.
394
453
  // http://dev.processing.org/bugs/show_bug.cgi?id=923
395
454
  boolean spanDisplays = sketch.sketchDisplay() == PConstants.SPAN;
396
- screenRect = spanDisplays ? getDisplaySpan()
397
- : displayDevice.getDefaultConfiguration().getBounds();
455
+ screenRect = spanDisplays ? getDisplaySpan() :
456
+ displayDevice.getDefaultConfiguration().getBounds();
398
457
  // DisplayMode doesn't work here, because we can't get the upper-left
399
458
  // corner of the display, which is important for multi-display setups.
400
459
 
@@ -403,8 +462,8 @@ public class PSurfaceAWT extends PSurfaceNone {
403
462
  sketch.displayWidth = screenRect.width;
404
463
  sketch.displayHeight = screenRect.height;
405
464
 
406
- windowScaleFactor = PApplet.platform == PConstants.MACOSX
407
- ? 1 : sketch.pixelDensity;
465
+ windowScaleFactor = PApplet.platform == PConstants.MACOS ?
466
+ 1 : sketch.pixelDensity;
408
467
 
409
468
  sketchWidth = sketch.sketchWidth() * windowScaleFactor;
410
469
  sketchHeight = sketch.sketchHeight() * windowScaleFactor;
@@ -422,7 +481,7 @@ 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
486
  if (fullScreen || spanDisplays) {
428
487
  sketchWidth = screenRect.width;
@@ -462,6 +521,7 @@ public class PSurfaceAWT extends PSurfaceNone {
462
521
  // and launches the Thread that will kick off setup().
463
522
  // http://dev.processing.org/bugs/show_bug.cgi?id=891
464
523
  // http://dev.processing.org/bugs/show_bug.cgi?id=908
524
+
465
525
  frame.add(canvas);
466
526
  setSize(sketchWidth / windowScaleFactor, sketchHeight / windowScaleFactor);
467
527
 
@@ -488,7 +548,7 @@ 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
- */
551
+ */
492
552
  frame.setLayout(null);
493
553
  //frame.add(applet);
494
554
 
@@ -497,7 +557,9 @@ public class PSurfaceAWT extends PSurfaceNone {
497
557
  // spanScreens was in use.
498
558
  // pg = sketch.makePrimaryGraphics(sketchWidth, sketchHeight);
499
559
  // pg = sketch.makePrimaryGraphics();
560
+
500
561
  // resize sketch to sketchWidth/sketchHeight here
562
+
501
563
  if (fullScreen) {
502
564
  frame.invalidate();
503
565
  } else {
@@ -506,6 +568,7 @@ public class PSurfaceAWT extends PSurfaceNone {
506
568
 
507
569
  // insufficient, places the 100x100 sketches offset strangely
508
570
  //frame.validate();
571
+
509
572
  // disabling resize has to happen after pack() to avoid apparent Apple bug
510
573
  // http://code.google.com/p/processing/issues/detail?id=467
511
574
  frame.setResizable(false);
@@ -520,37 +583,36 @@ public class PSurfaceAWT extends PSurfaceNone {
520
583
  // sketch.setFrame(frame);
521
584
  }
522
585
 
586
+
523
587
  @Override
524
588
  public Object getNative() {
525
589
  return canvas;
526
590
  }
527
591
 
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
- */
596
+
597
+
598
+ /** Set the window (and dock, or whatever necessary) title.
599
+ * @param title */
536
600
  @Override
537
601
  public void setTitle(String title) {
538
602
  frame.setTitle(title);
539
603
  // Workaround for apparent Java bug on OS X?
540
604
  // https://github.com/processing/processing/issues/3472
541
- if (cursorVisible
542
- && (PApplet.platform == PConstants.MACOSX)
543
- && (cursorType != PConstants.ARROW)) {
605
+ if (cursorVisible &&
606
+ (PApplet.platform == PConstants.MACOS) &&
607
+ (cursorType != PConstants.ARROW)) {
544
608
  hideCursor();
545
609
  showCursor();
546
610
  }
547
611
  }
548
612
 
549
- /**
550
- * Set true if we want to resize things (default is not resizable)
551
- *
552
- * @param resizable
553
- */
613
+
614
+ /** Set true if we want to resize things (default is not resizable)
615
+ * @param resizable */
554
616
  @Override
555
617
  public void setResizable(boolean resizable) {
556
618
  //this.resizable = resizable; // really only used for canvas
@@ -560,80 +622,103 @@ public class PSurfaceAWT extends PSurfaceNone {
560
622
  }
561
623
  }
562
624
 
625
+
563
626
  @Override
564
627
  public void setIcon(PImage image) {
565
628
  Image awtImage = (Image) image.getNative();
566
- ThinkDifferent.init(sketch);
567
- ThinkDifferent.setIconImage(awtImage);
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
+ }
645
+ }
568
646
  }
569
647
 
648
+
570
649
  @Override
571
650
  public void setAlwaysOnTop(boolean always) {
572
651
  frame.setAlwaysOnTop(always);
573
652
  }
574
653
 
654
+
575
655
  @Override
576
656
  public void setLocation(int x, int y) {
577
657
  frame.setLocation(x, y);
578
658
  }
579
659
 
660
+
580
661
  List<Image> iconImages;
581
662
 
582
663
  protected void setProcessingIcon(Frame frame) {
583
664
  // On OS X, this only affects what shows up in the dock when minimized.
584
665
  // So replacing it is actually a step backwards. Brilliant.
585
- if (PApplet.platform != PConstants.MACOSX) {
666
+ if (PApplet.platform != PConstants.MACOS) {
586
667
  //Image image = Toolkit.getDefaultToolkit().createImage(ICON_IMAGE);
587
668
  //frame.setIconImage(image);
588
- // try {
589
- if (iconImages == null) {
590
- iconImages = new ArrayList<>();
591
- final int[] sizes = {16, 32, 48, 64, 128, 256, 512};
592
-
593
- for (int sz : sizes) {
594
- //URL url = getClass().getResource("/icon/icon-" + sz + ".png");
595
- URL url = PApplet.class.getResource("/icon/icon-" + sz + ".png");
596
- Image image = Toolkit.getDefaultToolkit().getImage(url);
597
- iconImages.add(image);
598
- //iconImages.add(Toolkit.getLibImage("icons/pde-" + sz + ".png", frame));
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
+ }
599
681
  }
600
- }
601
- frame.setIconImages(iconImages);
682
+ frame.setIconImages(iconImages);
683
+
684
+ } catch (Exception e) { } // harmless; keep this to ourselves
602
685
 
603
- // } catch (Exception e) {
604
- // } // harmless; keep this to ourselves
605
686
  } else { // handle OS X differently
606
687
  if (!dockIconSpecified()) { // don't override existing -Xdock param
607
688
  // On OS X, set this for AWT surfaces, which handles the dock image
608
689
  // as well as the cmd-tab image that's shown. Just one size, I guess.
609
690
  URL url = PApplet.class.getResource("/icon/icon-512.png");
610
691
  // Seems dangerous to have this in code instead of using reflection, no?
611
- // ThinkDifferent.setIconImage(Toolkit.getDefaultToolkit().getImage(url));
692
+ //ThinkDifferent.setIconImage(Toolkit.getDefaultToolkit().getImage(url));
612
693
  try {
613
694
  final String td = "processing.core.ThinkDifferent";
614
- Class<?> thinkDifferent
615
- = Thread.currentThread().getContextClassLoader().loadClass(td);
616
- Method method
617
- = thinkDifferent.getMethod("setIconImage", new Class[]{java.awt.Image.class});
618
- method.invoke(null, new Object[]{Toolkit.getDefaultToolkit().getImage(url)});
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));
619
700
  } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException e) {
620
701
  // That's unfortunate
702
+
621
703
  }
622
704
  }
623
705
  }
624
706
  }
625
707
 
708
+
626
709
  /**
627
710
  * @return true if -Xdock:icon was specified on the command line
628
711
  */
629
712
  private boolean dockIconSpecified() {
630
713
  // TODO This is incomplete... Haven't yet found a way to figure out if
631
714
  // the app has an icns file specified already. Help?
632
- List<String> jvmArgs
633
- = ManagementFactory.getRuntimeMXBean().getInputArguments();
634
- return (jvmArgs.stream().anyMatch((arg) -> (arg.startsWith("-Xdock:icon"))));
715
+ List<String> jvmArgs =
716
+ ManagementFactory.getRuntimeMXBean().getInputArguments();
717
+ // dock image already set
718
+ return jvmArgs.stream().anyMatch((arg) -> (arg.startsWith("-Xdock:icon")));
635
719
  }
636
720
 
721
+
637
722
  @Override
638
723
  public void setVisible(boolean visible) {
639
724
  frame.setVisible(visible);
@@ -659,9 +744,10 @@ public class PSurfaceAWT extends PSurfaceNone {
659
744
  insets.top + insets.bottom);
660
745
  }
661
746
  }
662
- */
747
+ */
663
748
  }
664
749
 
750
+
665
751
  //public void placeFullScreen(boolean hideStop) {
666
752
  @Override
667
753
  public void placePresent(int stopColor) {
@@ -670,13 +756,14 @@ public class PSurfaceAWT extends PSurfaceNone {
670
756
  // After the pack(), the screen bounds are gonna be 0s
671
757
  // frame.setBounds(screenRect); // already called in setFullFrame()
672
758
  canvas.setBounds((screenRect.width - sketchWidth) / 2,
673
- (screenRect.height - sketchHeight) / 2,
674
- sketchWidth, sketchHeight);
759
+ (screenRect.height - sketchHeight) / 2,
760
+ sketchWidth, sketchHeight);
675
761
 
676
762
  // if (PApplet.platform == PConstants.MACOSX) {
677
763
  // macosxFullScreenEnable(frame);
678
764
  // macosxFullScreenToggle(frame);
679
765
  // }
766
+
680
767
  if (stopColor != 0) {
681
768
  Label label = new Label("stop");
682
769
  label.setForeground(new Color(stopColor, false));
@@ -746,21 +833,22 @@ public class PSurfaceAWT extends PSurfaceNone {
746
833
  frame.setVisible(true);
747
834
  }
748
835
  }
749
- */
836
+ */
837
+
838
+
750
839
  private void setCanvasSize() {
751
840
  // System.out.format("setting canvas size %d %d%n", sketchWidth, sketchHeight);
752
841
  // new Exception().printStackTrace(System.out);
753
842
  int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
754
843
  int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
755
844
 
756
- canvas.setBounds((contentW - sketchWidth) / 2,
757
- (contentH - sketchHeight) / 2,
758
- sketchWidth, sketchHeight);
845
+ canvas.setBounds((contentW - sketchWidth)/2,
846
+ (contentH - sketchHeight)/2,
847
+ sketchWidth, sketchHeight);
759
848
  }
760
849
 
761
- /**
762
- * Resize frame for these sketch (canvas) dimensions.
763
- */
850
+
851
+ /** Resize frame for these sketch (canvas) dimensions. */
764
852
  private Dimension setFrameSize() { //int sketchWidth, int sketchHeight) {
765
853
  // https://github.com/processing/processing/pull/3162
766
854
  frame.addNotify(); // using instead of show() to add the peer [fry]
@@ -768,24 +856,24 @@ public class PSurfaceAWT extends PSurfaceNone {
768
856
  // System.out.format("setting frame size %d %d %n", sketchWidth, sketchHeight);
769
857
  // new Exception().printStackTrace(System.out);
770
858
  currentInsets = frame.getInsets();
771
- int windowW = Math.max(sketchWidth, MIN_WINDOW_WIDTH)
772
- + currentInsets.left + currentInsets.right;
773
- int windowH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT)
774
- + currentInsets.top + currentInsets.bottom;
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;
775
863
  frame.setSize(windowW, windowH);
776
864
  return new Dimension(windowW, windowH);
777
865
  }
778
866
 
867
+
779
868
  private void setFrameCentered() {
780
869
  // Can't use frame.setLocationRelativeTo(null) because it sends the
781
870
  // frame to the main display, which undermines the --display setting.
782
871
  frame.setLocation(screenRect.x + (screenRect.width - sketchWidth) / 2,
783
- screenRect.y + (screenRect.height - sketchHeight) / 2);
872
+ screenRect.y + (screenRect.height - sketchHeight) / 2);
784
873
  }
785
874
 
786
- /**
787
- * Hide the menu bar, make the Frame undecorated, set it to screenRect.
788
- */
875
+
876
+ /** Hide the menu bar, make the Frame undecorated, set it to screenRect. */
789
877
  private void setFullFrame() {
790
878
  // Called here because the graphics device is needed before we can
791
879
  // determine whether the sketch wants size(displayWidth, displayHeight),
@@ -795,6 +883,7 @@ public class PSurfaceAWT extends PSurfaceNone {
795
883
  // Tried to use this to fix the 'present' mode issue.
796
884
  // Did not help, and the screenRect setup seems to work fine.
797
885
  //frame.setExtendedState(Frame.MAXIMIZED_BOTH);
886
+
798
887
  // https://github.com/processing/processing/pull/3162
799
888
  //frame.dispose(); // release native resources, allows setUndecorated()
800
889
  frame.removeNotify();
@@ -807,6 +896,7 @@ public class PSurfaceAWT extends PSurfaceNone {
807
896
  //frame.setVisible(true); // re-add native resources
808
897
  }
809
898
 
899
+
810
900
  @Override
811
901
  public void placeWindow(int[] location, int[] editorLocation) {
812
902
  //Dimension window = setFrameSize(sketchWidth, sketchHeight);
@@ -850,7 +940,7 @@ public class PSurfaceAWT extends PSurfaceNone {
850
940
  locationX = (sketch.displayWidth - window.width) / 2;
851
941
  locationY = (sketch.displayHeight - window.height) / 2;
852
942
  }
853
- */
943
+ */
854
944
  frame.setLocation(locationX, locationY);
855
945
  }
856
946
  } else { // just center on screen
@@ -864,9 +954,9 @@ public class PSurfaceAWT extends PSurfaceNone {
864
954
  }
865
955
  }
866
956
 
867
- canvas.setBounds((contentW - sketchWidth) / 2,
868
- (contentH - sketchHeight) / 2,
869
- sketchWidth, sketchHeight);
957
+ canvas.setBounds((contentW - sketchWidth)/2,
958
+ (contentH - sketchHeight)/2,
959
+ sketchWidth, sketchHeight);
870
960
 
871
961
  // handle frame resizing events
872
962
  setupFrameResizeListener();
@@ -882,12 +972,13 @@ public class PSurfaceAWT extends PSurfaceNone {
882
972
  // canvas.requestFocus();
883
973
  // }
884
974
  }
885
- */
975
+ */
886
976
  // if (sketch.getGraphics().displayable()) {
887
977
  // setVisible(true);
888
978
  // }
889
979
  }
890
980
 
981
+
891
982
  // needs to resize the frame, which will resize the canvas, and so on...
892
983
  @Override
893
984
  public void setSize(int wide, int high) {
@@ -905,9 +996,10 @@ public class PSurfaceAWT extends PSurfaceNone {
905
996
  // //System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high);
906
997
  // new Exception(String.format("setSize(%d, %d)", wide, high)).printStackTrace(System.out);
907
998
  // }
999
+
908
1000
  //if (wide == sketchWidth && high == sketchHeight) { // doesn't work on launch
909
- if (wide == sketch.width && high == sketch.height
910
- && (frame == null || currentInsets.equals(frame.getInsets()))) {
1001
+ if (wide == sketch.width && high == sketch.height &&
1002
+ (frame == null || currentInsets.equals(frame.getInsets()))) {
911
1003
  // if (PApplet.DEBUG) {
912
1004
  // new Exception("w/h unchanged " + wide + " " + high).printStackTrace(System.out);
913
1005
  // }
@@ -928,6 +1020,7 @@ public class PSurfaceAWT extends PSurfaceNone {
928
1020
  // }
929
1021
 
930
1022
  //initImage(graphics, wide, high);
1023
+
931
1024
  //throw new RuntimeException("implement me, see readme.md");
932
1025
  sketch.setSize(wide, high);
933
1026
  // sketch.width = wide;
@@ -938,6 +1031,7 @@ public class PSurfaceAWT extends PSurfaceNone {
938
1031
  // System.out.println("out of setSize()");
939
1032
  }
940
1033
 
1034
+
941
1035
  //public void initImage(PGraphics gr, int wide, int high) {
942
1036
  /*
943
1037
  @Override
@@ -956,14 +1050,20 @@ public class PSurfaceAWT extends PSurfaceNone {
956
1050
  int high = graphics.height * graphics.pixelFactor;
957
1051
  graphics.image = gc.createCompatibleImage(wide, high);
958
1052
  }
959
- */
1053
+ */
1054
+
1055
+
960
1056
  // @Override
961
1057
  // public Component getComponent() {
962
1058
  // return canvas;
963
1059
  // }
1060
+
1061
+
964
1062
  // @Override
965
1063
  // public void setSmooth(int level) {
966
1064
  // }
1065
+
1066
+
967
1067
  /*
968
1068
  private boolean checkRetina() {
969
1069
  if (PApplet.platform == PConstants.MACOSX) {
@@ -990,14 +1090,14 @@ public class PSurfaceAWT extends PSurfaceNone {
990
1090
  }
991
1091
  return false;
992
1092
  }
993
- */
994
- /**
995
- * Get the bounds rectangle for all displays.
996
- */
1093
+ */
1094
+
1095
+
1096
+ /** Get the bounds rectangle for all displays. */
997
1097
  static Rectangle getDisplaySpan() {
998
1098
  Rectangle bounds = new Rectangle();
999
- GraphicsEnvironment environment
1000
- = GraphicsEnvironment.getLocalGraphicsEnvironment();
1099
+ GraphicsEnvironment environment =
1100
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
1001
1101
  for (GraphicsDevice device : environment.getScreenDevices()) {
1002
1102
  for (GraphicsConfiguration config : device.getConfigurations()) {
1003
1103
  Rectangle2D.union(bounds, config.getBounds(), bounds);
@@ -1021,13 +1121,15 @@ public class PSurfaceAWT extends PSurfaceNone {
1021
1121
  }
1022
1122
  }
1023
1123
  }
1024
- */
1124
+ */
1125
+
1126
+
1025
1127
  /**
1026
1128
  * Set this sketch to communicate its state back to the PDE.
1027
- * <p/>
1028
- * This uses the stderr stream to write positions of the window (so that it
1029
- * will be saved by the PDE for the next run) and notify on quit. See more
1030
- * notes in the Worker class.
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.
1031
1133
  */
1032
1134
  @Override
1033
1135
  public void setupExternalMessages() {
@@ -1040,9 +1142,10 @@ public class PSurfaceAWT extends PSurfaceNone {
1040
1142
  });
1041
1143
  }
1042
1144
 
1145
+
1043
1146
  /**
1044
- * Set up a listener that will fire proper component resize events in cases
1045
- * where frame.setResizable(true) is called.
1147
+ * Set up a listener that will fire proper component resize events
1148
+ * in cases where frame.setResizable(true) is called.
1046
1149
  */
1047
1150
  private void setupFrameResizeListener() {
1048
1151
  frame.addWindowStateListener((WindowEvent e) -> {
@@ -1097,6 +1200,7 @@ public class PSurfaceAWT extends PSurfaceNone {
1097
1200
  });
1098
1201
  }
1099
1202
 
1203
+
1100
1204
  // /**
1101
1205
  // * (No longer in use) Use reflection to call
1102
1206
  // * <code>com.apple.eawt.FullScreenUtilities.setWindowCanFullScreen(window, true);</code>
@@ -1137,7 +1241,11 @@ public class PSurfaceAWT extends PSurfaceNone {
1137
1241
  // e.printStackTrace();
1138
1242
  // }
1139
1243
  // }
1244
+
1245
+
1140
1246
  //////////////////////////////////////////////////////////////
1247
+
1248
+
1141
1249
  /*
1142
1250
  // disabling for now; requires Java 1.7 and "precise" semantics are odd...
1143
1251
  // returns 0.1 for tick-by-tick scrolling on OS X, but it's not a matter of
@@ -1151,12 +1259,12 @@ public class PSurfaceAWT extends PSurfaceNone {
1151
1259
  // ignored, the method will just be set to null
1152
1260
  }
1153
1261
  }
1154
- */
1262
+ */
1263
+
1264
+
1155
1265
  /**
1156
- * Figure out how to process a mouse event.When loop() has been called, the
1157
- * events will be queued up until drawing is complete. If noLoop() has been
1158
- * called, then events will happen immediately.
1159
- *
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.
1160
1268
  * @param nativeEvent
1161
1269
  */
1162
1270
  protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) {
@@ -1166,31 +1274,31 @@ public class PSurfaceAWT extends PSurfaceNone {
1166
1274
 
1167
1275
  int peAction = 0;
1168
1276
  switch (nativeEvent.getID()) {
1169
- case java.awt.event.MouseEvent.MOUSE_PRESSED:
1170
- peAction = MouseEvent.PRESS;
1171
- break;
1172
- case java.awt.event.MouseEvent.MOUSE_RELEASED:
1173
- peAction = MouseEvent.RELEASE;
1174
- break;
1175
- case java.awt.event.MouseEvent.MOUSE_CLICKED:
1176
- peAction = MouseEvent.CLICK;
1177
- break;
1178
- case java.awt.event.MouseEvent.MOUSE_DRAGGED:
1179
- peAction = MouseEvent.DRAG;
1180
- break;
1181
- case java.awt.event.MouseEvent.MOUSE_MOVED:
1182
- peAction = MouseEvent.MOVE;
1183
- break;
1184
- case java.awt.event.MouseEvent.MOUSE_ENTERED:
1185
- peAction = MouseEvent.ENTER;
1186
- break;
1187
- case java.awt.event.MouseEvent.MOUSE_EXITED:
1188
- peAction = MouseEvent.EXIT;
1189
- break;
1190
- //case java.awt.event.MouseWheelEvent.WHEEL_UNIT_SCROLL:
1191
- case java.awt.event.MouseEvent.MOUSE_WHEEL:
1192
- peAction = MouseEvent.WHEEL;
1193
- /*
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
+ /*
1194
1302
  if (preciseWheelMethod != null) {
1195
1303
  try {
1196
1304
  peAmount = ((Double) preciseWheelMethod.invoke(nativeEvent, (Object[]) null)).floatValue();
@@ -1198,95 +1306,71 @@ public class PSurfaceAWT extends PSurfaceNone {
1198
1306
  preciseWheelMethod = null;
1199
1307
  }
1200
1308
  }
1201
- */
1202
- peCount = ((MouseWheelEvent) nativeEvent).getWheelRotation();
1203
- break;
1309
+ */
1310
+ peCount = ((MouseWheelEvent) nativeEvent).getWheelRotation();
1311
+ break;
1204
1312
  }
1205
1313
 
1206
- //System.out.println(nativeEvent);
1207
- //int modifiers = nativeEvent.getModifiersEx();
1208
- // If using getModifiersEx(), the regular modifiers don't set properly.
1209
- int modifiers = nativeEvent.getModifiers();
1210
-
1211
- int peModifiers = modifiers
1212
- & (InputEvent.SHIFT_MASK
1213
- | InputEvent.CTRL_MASK
1214
- | InputEvent.META_MASK
1215
- | InputEvent.ALT_MASK);
1216
-
1217
- // Windows and OS X seem to disagree on how to handle this. Windows only
1218
- // sets BUTTON1_DOWN_MASK, while OS X seems to set BUTTON1_MASK.
1219
- // This is an issue in particular with mouse release events:
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.
1220
1317
  // http://code.google.com/p/processing/issues/detail?id=1294
1221
- // The fix for which led to a regression (fixed here by checking both):
1222
1318
  // http://code.google.com/p/processing/issues/detail?id=1332
1319
+ int modifiers = nativeEvent.getModifiersEx();
1320
+
1223
1321
  int peButton = 0;
1224
- // if ((modifiers & InputEvent.BUTTON1_MASK) != 0 ||
1225
- // (modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
1226
- // peButton = LEFT;
1227
- // } else if ((modifiers & InputEvent.BUTTON2_MASK) != 0 ||
1228
- // (modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
1229
- // peButton = CENTER;
1230
- // } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0 ||
1231
- // (modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
1232
- // peButton = RIGHT;
1233
- // }
1234
- if ((modifiers & InputEvent.BUTTON1_MASK) != 0) {
1322
+ if ((modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
1235
1323
  peButton = PConstants.LEFT;
1236
- } else if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
1324
+ } else if ((modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
1237
1325
  peButton = PConstants.CENTER;
1238
- } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
1326
+ } else if ((modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
1239
1327
  peButton = PConstants.RIGHT;
1240
1328
  }
1241
1329
 
1242
- // If running on Mac OS, allow ctrl-click as right mouse. Prior to 0215,
1243
- // this used isPopupTrigger() on the native event, but that doesn't work
1244
- // for mouseClicked and mouseReleased (or others).
1245
- if (PApplet.platform == PConstants.MACOSX) {
1246
- //if (nativeEvent.isPopupTrigger()) {
1247
- if ((modifiers & InputEvent.CTRL_MASK) != 0) {
1248
- peButton = PConstants.RIGHT;
1249
- }
1250
- }
1251
-
1252
1330
  sketch.postEvent(new MouseEvent(nativeEvent, nativeEvent.getWhen(),
1253
- peAction, peModifiers,
1254
- nativeEvent.getX() / windowScaleFactor,
1255
- nativeEvent.getY() / windowScaleFactor,
1256
- peButton,
1257
- peCount));
1331
+ peAction, modifiers,
1332
+ nativeEvent.getX() / windowScaleFactor,
1333
+ nativeEvent.getY() / windowScaleFactor,
1334
+ peButton,
1335
+ peCount));
1258
1336
  }
1259
1337
 
1338
+
1260
1339
  protected void nativeKeyEvent(java.awt.event.KeyEvent event) {
1261
1340
  int peAction = 0;
1262
1341
  switch (event.getID()) {
1263
- case java.awt.event.KeyEvent.KEY_PRESSED:
1264
- peAction = KeyEvent.PRESS;
1265
- break;
1266
- case java.awt.event.KeyEvent.KEY_RELEASED:
1267
- peAction = KeyEvent.RELEASE;
1268
- break;
1269
- case java.awt.event.KeyEvent.KEY_TYPED:
1270
- peAction = KeyEvent.TYPE;
1271
- break;
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;
1272
1351
  }
1273
1352
 
1353
+ int modifiers = event.getModifiersEx();
1354
+
1355
+ /*
1274
1356
  // int peModifiers = event.getModifiersEx() &
1275
1357
  // (InputEvent.SHIFT_DOWN_MASK |
1276
1358
  // InputEvent.CTRL_DOWN_MASK |
1277
1359
  // InputEvent.META_DOWN_MASK |
1278
1360
  // InputEvent.ALT_DOWN_MASK);
1279
- int peModifiers = event.getModifiers()
1280
- & (InputEvent.SHIFT_MASK
1281
- | InputEvent.CTRL_MASK
1282
- | InputEvent.META_MASK
1283
- | InputEvent.ALT_MASK);
1361
+ int peModifiers = event.getModifiers() &
1362
+ (InputEvent.SHIFT_MASK |
1363
+ InputEvent.CTRL_MASK |
1364
+ InputEvent.META_MASK |
1365
+ InputEvent.ALT_MASK);
1366
+ */
1284
1367
 
1285
1368
  sketch.postEvent(new KeyEvent(event, event.getWhen(),
1286
- peAction, peModifiers,
1287
- event.getKeyChar(), event.getKeyCode()));
1369
+ peAction, modifiers,
1370
+ event.getKeyChar(), event.getKeyCode()));
1288
1371
  }
1289
1372
 
1373
+
1290
1374
  // listeners, for all my men!
1291
1375
  protected void addListeners() {
1292
1376
 
@@ -1325,6 +1409,7 @@ public class PSurfaceAWT extends PSurfaceNone {
1325
1409
  nativeMouseEvent(e);
1326
1410
  }
1327
1411
 
1412
+ @Override
1328
1413
  public void mouseMoved(java.awt.event.MouseEvent e) {
1329
1414
  nativeMouseEvent(e);
1330
1415
  }
@@ -1341,11 +1426,13 @@ public class PSurfaceAWT extends PSurfaceNone {
1341
1426
  nativeKeyEvent(e);
1342
1427
  }
1343
1428
 
1429
+
1344
1430
  @Override
1345
1431
  public void keyReleased(java.awt.event.KeyEvent e) {
1346
1432
  nativeKeyEvent(e);
1347
1433
  }
1348
1434
 
1435
+
1349
1436
  @Override
1350
1437
  public void keyTyped(java.awt.event.KeyEvent e) {
1351
1438
  nativeKeyEvent(e);
@@ -1386,7 +1473,9 @@ public class PSurfaceAWT extends PSurfaceNone {
1386
1473
  comp.removeKeyListener(this);
1387
1474
  comp.removeFocusListener(this);
1388
1475
  }
1389
- */
1476
+ */
1477
+
1478
+
1390
1479
  // /**
1391
1480
  // * Call to remove, then add, listeners to a component.
1392
1481
  // * Avoids issues with double-adding.
@@ -1395,16 +1484,22 @@ public class PSurfaceAWT extends PSurfaceNone {
1395
1484
  // removeListeners(comp);
1396
1485
  // addListeners(comp);
1397
1486
  // }
1487
+
1488
+
1489
+
1398
1490
  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1491
+
1492
+
1399
1493
  int cursorType = PConstants.ARROW;
1400
1494
  boolean cursorVisible = true;
1401
1495
  Cursor invisibleCursor;
1402
1496
 
1497
+
1403
1498
  @Override
1404
1499
  public void setCursor(int kind) {
1405
1500
  // Swap the HAND cursor because MOVE doesn't seem to be available on OS X
1406
1501
  // https://github.com/processing/processing/issues/2358
1407
- if (PApplet.platform == PConstants.MACOSX && kind == PConstants.MOVE) {
1502
+ if (PApplet.platform == PConstants.MACOS && kind == PConstants.MOVE) {
1408
1503
  kind = PConstants.HAND;
1409
1504
  }
1410
1505
  canvas.setCursor(Cursor.getPredefinedCursor(kind));
@@ -1412,6 +1507,7 @@ public class PSurfaceAWT extends PSurfaceNone {
1412
1507
  this.cursorType = kind;
1413
1508
  }
1414
1509
 
1510
+
1415
1511
  @Override
1416
1512
  public void setCursor(PImage img, int x, int y) {
1417
1513
  // Don't set cursorType, instead use cursorType to save the last
@@ -1424,14 +1520,15 @@ public class PSurfaceAWT extends PSurfaceNone {
1424
1520
  return;
1425
1521
  }
1426
1522
 
1427
- Cursor cursor
1428
- = canvas.getToolkit().createCustomCursor((Image) img.getNative(),
1429
- new Point(x, y),
1430
- "custom");
1523
+ Cursor cursor =
1524
+ canvas.getToolkit().createCustomCursor((Image) img.getNative(),
1525
+ new Point(x, y),
1526
+ "custom");
1431
1527
  canvas.setCursor(cursor);
1432
1528
  cursorVisible = true;
1433
1529
  }
1434
1530
 
1531
+
1435
1532
  @Override
1436
1533
  public void showCursor() {
1437
1534
  // Maybe should always set here? Seems dangerous, since it's likely that
@@ -1443,27 +1540,29 @@ public class PSurfaceAWT extends PSurfaceNone {
1443
1540
  }
1444
1541
  }
1445
1542
 
1543
+
1446
1544
  @Override
1447
1545
  public void hideCursor() {
1448
1546
  // Because the OS may have shown the cursor on its own,
1449
1547
  // don't return if 'cursorVisible' is set to true. [rev 0216]
1450
1548
 
1451
1549
  if (invisibleCursor == null) {
1452
- BufferedImage cursorImg
1453
- = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
1550
+ BufferedImage cursorImg =
1551
+ new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
1454
1552
  // this is a temporary workaround for the CHIP, will be removed
1455
1553
  Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(16, 16);
1456
1554
  if (cursorSize.width == 0 || cursorSize.height == 0) {
1457
1555
  invisibleCursor = Cursor.getDefaultCursor();
1458
1556
  } else {
1459
- invisibleCursor
1460
- = canvas.getToolkit().createCustomCursor(cursorImg, new Point(8, 8), "blank");
1557
+ invisibleCursor =
1558
+ canvas.getToolkit().createCustomCursor(cursorImg, new Point(8, 8), "blank");
1461
1559
  }
1462
1560
  }
1463
1561
  canvas.setCursor(invisibleCursor);
1464
1562
  cursorVisible = false;
1465
1563
  }
1466
1564
 
1565
+
1467
1566
  @Override
1468
1567
  public Thread createThread() {
1469
1568
  return new AnimationThread() {
@@ -1475,7 +1574,8 @@ public class PSurfaceAWT extends PSurfaceNone {
1475
1574
  };
1476
1575
  }
1477
1576
 
1478
- void debug(String format, Object... args) {
1577
+
1578
+ void debug(String format, Object ... args) {
1479
1579
  System.out.format(format + "%n", args);
1480
1580
  }
1481
1581
  }