propane 3.4.2-java → 3.5.0-java

Sign up to get free protection for your applications and to get access to all the features.
Files changed (131) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
  3. data/.travis.yml +1 -1
  4. data/CHANGELOG.md +5 -1
  5. data/Gemfile +2 -0
  6. data/README.md +15 -3
  7. data/Rakefile +9 -10
  8. data/bin/propane +3 -1
  9. data/lib/propane.rb +2 -1
  10. data/lib/propane/app.rb +2 -1
  11. data/lib/propane/creators/sketch_class.rb +7 -1
  12. data/lib/propane/creators/sketch_factory.rb +4 -2
  13. data/lib/propane/creators/sketch_writer.rb +1 -0
  14. data/lib/propane/helper_methods.rb +22 -22
  15. data/lib/propane/helpers/numeric.rb +2 -0
  16. data/lib/propane/helpers/version_error.rb +1 -0
  17. data/lib/propane/library.rb +5 -1
  18. data/lib/propane/library_loader.rb +2 -0
  19. data/lib/propane/native_folder.rb +10 -9
  20. data/lib/propane/native_loader.rb +3 -0
  21. data/lib/propane/runner.rb +11 -5
  22. data/lib/propane/version.rb +2 -1
  23. data/library/boids/boids.rb +21 -11
  24. data/library/color_group/color_group.rb +2 -0
  25. data/library/control_panel/control_panel.rb +8 -5
  26. data/library/dxf/dxf.rb +2 -0
  27. data/library/file_chooser/chooser.rb +10 -9
  28. data/library/file_chooser/file_chooser.rb +10 -9
  29. data/library/library_proxy/library_proxy.rb +2 -0
  30. data/library/net/net.rb +2 -0
  31. data/library/simplex_noise/simplex_noise.rb +2 -0
  32. data/library/slider/slider.rb +23 -22
  33. data/library/vector_utils/vector_utils.rb +4 -0
  34. data/library/video_event/video_event.rb +2 -0
  35. data/pom.rb +46 -45
  36. data/pom.xml +4 -4
  37. data/propane.gemspec +8 -7
  38. data/src/main/java/monkstone/ColorUtil.java +1 -3
  39. data/src/main/java/monkstone/MathToolModule.java +1 -1
  40. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  41. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  42. data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
  43. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  44. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  45. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  46. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  47. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  48. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  49. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  50. data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
  51. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  52. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
  53. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
  54. data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
  55. data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
  56. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  57. data/src/main/java/processing/awt/PGraphicsJava2D.java +788 -283
  58. data/src/main/java/processing/awt/PImageAWT.java +260 -0
  59. data/src/main/java/processing/awt/PShapeJava2D.java +56 -53
  60. data/src/main/java/processing/awt/PSurfaceAWT.java +309 -211
  61. data/src/main/java/processing/awt/ShimAWT.java +580 -0
  62. data/src/main/java/processing/core/PApplet.java +2877 -2098
  63. data/src/main/java/processing/core/PConstants.java +477 -447
  64. data/src/main/java/processing/core/PFont.java +930 -884
  65. data/src/main/java/processing/core/PGraphics.java +337 -309
  66. data/src/main/java/processing/core/PImage.java +1689 -1689
  67. data/src/main/java/processing/core/PMatrix.java +172 -159
  68. data/src/main/java/processing/core/PMatrix2D.java +456 -410
  69. data/src/main/java/processing/core/PMatrix3D.java +755 -735
  70. data/src/main/java/processing/core/PShape.java +2910 -2656
  71. data/src/main/java/processing/core/PShapeOBJ.java +97 -94
  72. data/src/main/java/processing/core/PShapeSVG.java +1656 -1462
  73. data/src/main/java/processing/core/PStyle.java +40 -37
  74. data/src/main/java/processing/core/PSurface.java +134 -97
  75. data/src/main/java/processing/core/PSurfaceNone.java +292 -218
  76. data/src/main/java/processing/core/PVector.java +991 -966
  77. data/src/main/java/processing/core/ThinkDifferent.java +12 -8
  78. data/src/main/java/processing/data/DoubleDict.java +756 -710
  79. data/src/main/java/processing/data/DoubleList.java +749 -696
  80. data/src/main/java/processing/data/FloatDict.java +748 -702
  81. data/src/main/java/processing/data/FloatList.java +751 -697
  82. data/src/main/java/processing/data/IntDict.java +720 -673
  83. data/src/main/java/processing/data/IntList.java +699 -633
  84. data/src/main/java/processing/data/JSONArray.java +931 -873
  85. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  86. data/src/main/java/processing/data/JSONTokener.java +351 -341
  87. data/src/main/java/processing/data/LongDict.java +710 -663
  88. data/src/main/java/processing/data/LongList.java +701 -635
  89. data/src/main/java/processing/data/Sort.java +37 -41
  90. data/src/main/java/processing/data/StringDict.java +525 -486
  91. data/src/main/java/processing/data/StringList.java +626 -580
  92. data/src/main/java/processing/data/Table.java +3693 -3513
  93. data/src/main/java/processing/data/TableRow.java +182 -183
  94. data/src/main/java/processing/data/XML.java +954 -880
  95. data/src/main/java/processing/event/Event.java +87 -67
  96. data/src/main/java/processing/event/KeyEvent.java +48 -41
  97. data/src/main/java/processing/event/MouseEvent.java +87 -113
  98. data/src/main/java/processing/event/TouchEvent.java +10 -6
  99. data/src/main/java/processing/javafx/PSurfaceFX.java +26 -0
  100. data/src/main/java/processing/net/Client.java +20 -20
  101. data/src/main/java/processing/net/Server.java +9 -9
  102. data/src/main/java/processing/opengl/FontTexture.java +286 -266
  103. data/src/main/java/processing/opengl/FrameBuffer.java +390 -376
  104. data/src/main/java/processing/opengl/LinePath.java +130 -91
  105. data/src/main/java/processing/opengl/LineStroker.java +593 -582
  106. data/src/main/java/processing/opengl/PGL.java +645 -579
  107. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  108. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  109. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12287 -12030
  110. data/src/main/java/processing/opengl/PJOGL.java +1743 -1672
  111. data/src/main/java/processing/opengl/PShader.java +345 -416
  112. data/src/main/java/processing/opengl/PShapeOpenGL.java +4601 -4543
  113. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1113 -1029
  114. data/src/main/java/processing/opengl/Texture.java +1489 -1401
  115. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  116. data/test/create_test.rb +21 -20
  117. data/test/deglut_spec_test.rb +4 -2
  118. data/test/helper_methods_test.rb +49 -20
  119. data/test/math_tool_test.rb +39 -32
  120. data/test/native_folder.rb +47 -0
  121. data/test/respond_to_test.rb +3 -2
  122. data/test/sketches/key_event.rb +2 -2
  123. data/test/sketches/library/my_library/my_library.rb +3 -0
  124. data/test/test_helper.rb +2 -0
  125. data/test/vecmath_spec_test.rb +35 -22
  126. data/vendors/Rakefile +28 -22
  127. metadata +13 -13
  128. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  129. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  130. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  131. 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,34 @@ 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. */
536
599
  @Override
537
600
  public void setTitle(String title) {
538
601
  frame.setTitle(title);
539
602
  // Workaround for apparent Java bug on OS X?
540
603
  // https://github.com/processing/processing/issues/3472
541
- if (cursorVisible
542
- && (PApplet.platform == PConstants.MACOSX)
543
- && (cursorType != PConstants.ARROW)) {
604
+ if (cursorVisible &&
605
+ (PApplet.platform == PConstants.MACOS) &&
606
+ (cursorType != PConstants.ARROW)) {
544
607
  hideCursor();
545
608
  showCursor();
546
609
  }
547
610
  }
548
611
 
549
- /**
550
- * Set true if we want to resize things (default is not resizable)
551
- *
552
- * @param resizable
553
- */
612
+
613
+ /** Set true if we want to resize things (default is not resizable) */
554
614
  @Override
555
615
  public void setResizable(boolean resizable) {
556
616
  //this.resizable = resizable; // really only used for canvas
@@ -560,80 +620,103 @@ public class PSurfaceAWT extends PSurfaceNone {
560
620
  }
561
621
  }
562
622
 
623
+
563
624
  @Override
564
625
  public void setIcon(PImage image) {
565
626
  Image awtImage = (Image) image.getNative();
566
- ThinkDifferent.init(sketch);
567
- ThinkDifferent.setIconImage(awtImage);
627
+
628
+ if (PApplet.platform != PConstants.MACOS) {
629
+ frame.setIconImage(awtImage);
630
+
631
+ } else {
632
+ try {
633
+ final String td = "processing.core.ThinkDifferent";
634
+ Class<?> thinkDifferent =
635
+ Thread.currentThread().getContextClassLoader().loadClass(td);
636
+ Method method =
637
+ thinkDifferent.getMethod("setIconImage", Image.class);
638
+ method.invoke(null, awtImage);
639
+ } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException e) {
640
+ // That's unfortunate
641
+
642
+ }
643
+ }
568
644
  }
569
645
 
646
+
570
647
  @Override
571
648
  public void setAlwaysOnTop(boolean always) {
572
649
  frame.setAlwaysOnTop(always);
573
650
  }
574
651
 
652
+
575
653
  @Override
576
654
  public void setLocation(int x, int y) {
577
655
  frame.setLocation(x, y);
578
656
  }
579
657
 
658
+
580
659
  List<Image> iconImages;
581
660
 
582
661
  protected void setProcessingIcon(Frame frame) {
583
662
  // On OS X, this only affects what shows up in the dock when minimized.
584
663
  // So replacing it is actually a step backwards. Brilliant.
585
- if (PApplet.platform != PConstants.MACOSX) {
664
+ if (PApplet.platform != PConstants.MACOS) {
586
665
  //Image image = Toolkit.getDefaultToolkit().createImage(ICON_IMAGE);
587
666
  //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));
667
+ try {
668
+ if (iconImages == null) {
669
+ iconImages = new ArrayList<>();
670
+ final int[] sizes = { 16, 32, 48, 64, 128, 256, 512 };
671
+
672
+ for (int sz : sizes) {
673
+ //URL url = getClass().getResource("/icon/icon-" + sz + ".png");
674
+ URL url = PApplet.class.getResource("/icon/icon-" + sz + ".png");
675
+ Image image = Toolkit.getDefaultToolkit().getImage(url);
676
+ iconImages.add(image);
677
+ //iconImages.add(Toolkit.getLibImage("icons/pde-" + sz + ".png", frame));
678
+ }
599
679
  }
600
- }
601
- frame.setIconImages(iconImages);
680
+ frame.setIconImages(iconImages);
681
+
682
+ } catch (Exception e) { } // harmless; keep this to ourselves
602
683
 
603
- // } catch (Exception e) {
604
- // } // harmless; keep this to ourselves
605
684
  } else { // handle OS X differently
606
685
  if (!dockIconSpecified()) { // don't override existing -Xdock param
607
686
  // On OS X, set this for AWT surfaces, which handles the dock image
608
687
  // as well as the cmd-tab image that's shown. Just one size, I guess.
609
688
  URL url = PApplet.class.getResource("/icon/icon-512.png");
610
689
  // Seems dangerous to have this in code instead of using reflection, no?
611
- // ThinkDifferent.setIconImage(Toolkit.getDefaultToolkit().getImage(url));
690
+ //ThinkDifferent.setIconImage(Toolkit.getDefaultToolkit().getImage(url));
612
691
  try {
613
692
  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)});
693
+ Class<?> thinkDifferent =
694
+ Thread.currentThread().getContextClassLoader().loadClass(td);
695
+ Method method =
696
+ thinkDifferent.getMethod("setIconImage", Image.class);
697
+ method.invoke(null, Toolkit.getDefaultToolkit().getImage(url));
619
698
  } catch (ClassNotFoundException | IllegalAccessException | IllegalArgumentException | NoSuchMethodException | SecurityException | InvocationTargetException e) {
620
699
  // That's unfortunate
700
+
621
701
  }
622
702
  }
623
703
  }
624
704
  }
625
705
 
706
+
626
707
  /**
627
708
  * @return true if -Xdock:icon was specified on the command line
628
709
  */
629
710
  private boolean dockIconSpecified() {
630
711
  // TODO This is incomplete... Haven't yet found a way to figure out if
631
712
  // 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"))));
713
+ List<String> jvmArgs =
714
+ ManagementFactory.getRuntimeMXBean().getInputArguments();
715
+ // dock image already set
716
+ return jvmArgs.stream().anyMatch((arg) -> (arg.startsWith("-Xdock:icon")));
635
717
  }
636
718
 
719
+
637
720
  @Override
638
721
  public void setVisible(boolean visible) {
639
722
  frame.setVisible(visible);
@@ -659,9 +742,10 @@ public class PSurfaceAWT extends PSurfaceNone {
659
742
  insets.top + insets.bottom);
660
743
  }
661
744
  }
662
- */
745
+ */
663
746
  }
664
747
 
748
+
665
749
  //public void placeFullScreen(boolean hideStop) {
666
750
  @Override
667
751
  public void placePresent(int stopColor) {
@@ -670,13 +754,14 @@ public class PSurfaceAWT extends PSurfaceNone {
670
754
  // After the pack(), the screen bounds are gonna be 0s
671
755
  // frame.setBounds(screenRect); // already called in setFullFrame()
672
756
  canvas.setBounds((screenRect.width - sketchWidth) / 2,
673
- (screenRect.height - sketchHeight) / 2,
674
- sketchWidth, sketchHeight);
757
+ (screenRect.height - sketchHeight) / 2,
758
+ sketchWidth, sketchHeight);
675
759
 
676
760
  // if (PApplet.platform == PConstants.MACOSX) {
677
761
  // macosxFullScreenEnable(frame);
678
762
  // macosxFullScreenToggle(frame);
679
763
  // }
764
+
680
765
  if (stopColor != 0) {
681
766
  Label label = new Label("stop");
682
767
  label.setForeground(new Color(stopColor, false));
@@ -746,21 +831,22 @@ public class PSurfaceAWT extends PSurfaceNone {
746
831
  frame.setVisible(true);
747
832
  }
748
833
  }
749
- */
834
+ */
835
+
836
+
750
837
  private void setCanvasSize() {
751
838
  // System.out.format("setting canvas size %d %d%n", sketchWidth, sketchHeight);
752
839
  // new Exception().printStackTrace(System.out);
753
840
  int contentW = Math.max(sketchWidth, MIN_WINDOW_WIDTH);
754
841
  int contentH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT);
755
842
 
756
- canvas.setBounds((contentW - sketchWidth) / 2,
757
- (contentH - sketchHeight) / 2,
758
- sketchWidth, sketchHeight);
843
+ canvas.setBounds((contentW - sketchWidth)/2,
844
+ (contentH - sketchHeight)/2,
845
+ sketchWidth, sketchHeight);
759
846
  }
760
847
 
761
- /**
762
- * Resize frame for these sketch (canvas) dimensions.
763
- */
848
+
849
+ /** Resize frame for these sketch (canvas) dimensions. */
764
850
  private Dimension setFrameSize() { //int sketchWidth, int sketchHeight) {
765
851
  // https://github.com/processing/processing/pull/3162
766
852
  frame.addNotify(); // using instead of show() to add the peer [fry]
@@ -768,24 +854,24 @@ public class PSurfaceAWT extends PSurfaceNone {
768
854
  // System.out.format("setting frame size %d %d %n", sketchWidth, sketchHeight);
769
855
  // new Exception().printStackTrace(System.out);
770
856
  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;
857
+ int windowW = Math.max(sketchWidth, MIN_WINDOW_WIDTH) +
858
+ currentInsets.left + currentInsets.right;
859
+ int windowH = Math.max(sketchHeight, MIN_WINDOW_HEIGHT) +
860
+ currentInsets.top + currentInsets.bottom;
775
861
  frame.setSize(windowW, windowH);
776
862
  return new Dimension(windowW, windowH);
777
863
  }
778
864
 
865
+
779
866
  private void setFrameCentered() {
780
867
  // Can't use frame.setLocationRelativeTo(null) because it sends the
781
868
  // frame to the main display, which undermines the --display setting.
782
869
  frame.setLocation(screenRect.x + (screenRect.width - sketchWidth) / 2,
783
- screenRect.y + (screenRect.height - sketchHeight) / 2);
870
+ screenRect.y + (screenRect.height - sketchHeight) / 2);
784
871
  }
785
872
 
786
- /**
787
- * Hide the menu bar, make the Frame undecorated, set it to screenRect.
788
- */
873
+
874
+ /** Hide the menu bar, make the Frame undecorated, set it to screenRect. */
789
875
  private void setFullFrame() {
790
876
  // Called here because the graphics device is needed before we can
791
877
  // determine whether the sketch wants size(displayWidth, displayHeight),
@@ -795,6 +881,7 @@ public class PSurfaceAWT extends PSurfaceNone {
795
881
  // Tried to use this to fix the 'present' mode issue.
796
882
  // Did not help, and the screenRect setup seems to work fine.
797
883
  //frame.setExtendedState(Frame.MAXIMIZED_BOTH);
884
+
798
885
  // https://github.com/processing/processing/pull/3162
799
886
  //frame.dispose(); // release native resources, allows setUndecorated()
800
887
  frame.removeNotify();
@@ -807,6 +894,7 @@ public class PSurfaceAWT extends PSurfaceNone {
807
894
  //frame.setVisible(true); // re-add native resources
808
895
  }
809
896
 
897
+
810
898
  @Override
811
899
  public void placeWindow(int[] location, int[] editorLocation) {
812
900
  //Dimension window = setFrameSize(sketchWidth, sketchHeight);
@@ -850,7 +938,7 @@ public class PSurfaceAWT extends PSurfaceNone {
850
938
  locationX = (sketch.displayWidth - window.width) / 2;
851
939
  locationY = (sketch.displayHeight - window.height) / 2;
852
940
  }
853
- */
941
+ */
854
942
  frame.setLocation(locationX, locationY);
855
943
  }
856
944
  } else { // just center on screen
@@ -864,9 +952,9 @@ public class PSurfaceAWT extends PSurfaceNone {
864
952
  }
865
953
  }
866
954
 
867
- canvas.setBounds((contentW - sketchWidth) / 2,
868
- (contentH - sketchHeight) / 2,
869
- sketchWidth, sketchHeight);
955
+ canvas.setBounds((contentW - sketchWidth)/2,
956
+ (contentH - sketchHeight)/2,
957
+ sketchWidth, sketchHeight);
870
958
 
871
959
  // handle frame resizing events
872
960
  setupFrameResizeListener();
@@ -882,12 +970,13 @@ public class PSurfaceAWT extends PSurfaceNone {
882
970
  // canvas.requestFocus();
883
971
  // }
884
972
  }
885
- */
973
+ */
886
974
  // if (sketch.getGraphics().displayable()) {
887
975
  // setVisible(true);
888
976
  // }
889
977
  }
890
978
 
979
+
891
980
  // needs to resize the frame, which will resize the canvas, and so on...
892
981
  @Override
893
982
  public void setSize(int wide, int high) {
@@ -905,9 +994,10 @@ public class PSurfaceAWT extends PSurfaceNone {
905
994
  // //System.out.format("frame visible %b, setSize(%d, %d) %n", frame.isVisible(), wide, high);
906
995
  // new Exception(String.format("setSize(%d, %d)", wide, high)).printStackTrace(System.out);
907
996
  // }
997
+
908
998
  //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()))) {
999
+ if (wide == sketch.width && high == sketch.height &&
1000
+ (frame == null || currentInsets.equals(frame.getInsets()))) {
911
1001
  // if (PApplet.DEBUG) {
912
1002
  // new Exception("w/h unchanged " + wide + " " + high).printStackTrace(System.out);
913
1003
  // }
@@ -928,6 +1018,7 @@ public class PSurfaceAWT extends PSurfaceNone {
928
1018
  // }
929
1019
 
930
1020
  //initImage(graphics, wide, high);
1021
+
931
1022
  //throw new RuntimeException("implement me, see readme.md");
932
1023
  sketch.setSize(wide, high);
933
1024
  // sketch.width = wide;
@@ -938,6 +1029,7 @@ public class PSurfaceAWT extends PSurfaceNone {
938
1029
  // System.out.println("out of setSize()");
939
1030
  }
940
1031
 
1032
+
941
1033
  //public void initImage(PGraphics gr, int wide, int high) {
942
1034
  /*
943
1035
  @Override
@@ -956,14 +1048,20 @@ public class PSurfaceAWT extends PSurfaceNone {
956
1048
  int high = graphics.height * graphics.pixelFactor;
957
1049
  graphics.image = gc.createCompatibleImage(wide, high);
958
1050
  }
959
- */
1051
+ */
1052
+
1053
+
960
1054
  // @Override
961
1055
  // public Component getComponent() {
962
1056
  // return canvas;
963
1057
  // }
1058
+
1059
+
964
1060
  // @Override
965
1061
  // public void setSmooth(int level) {
966
1062
  // }
1063
+
1064
+
967
1065
  /*
968
1066
  private boolean checkRetina() {
969
1067
  if (PApplet.platform == PConstants.MACOSX) {
@@ -990,14 +1088,14 @@ public class PSurfaceAWT extends PSurfaceNone {
990
1088
  }
991
1089
  return false;
992
1090
  }
993
- */
994
- /**
995
- * Get the bounds rectangle for all displays.
996
- */
1091
+ */
1092
+
1093
+
1094
+ /** Get the bounds rectangle for all displays. */
997
1095
  static Rectangle getDisplaySpan() {
998
1096
  Rectangle bounds = new Rectangle();
999
- GraphicsEnvironment environment
1000
- = GraphicsEnvironment.getLocalGraphicsEnvironment();
1097
+ GraphicsEnvironment environment =
1098
+ GraphicsEnvironment.getLocalGraphicsEnvironment();
1001
1099
  for (GraphicsDevice device : environment.getScreenDevices()) {
1002
1100
  for (GraphicsConfiguration config : device.getConfigurations()) {
1003
1101
  Rectangle2D.union(bounds, config.getBounds(), bounds);
@@ -1021,13 +1119,15 @@ public class PSurfaceAWT extends PSurfaceNone {
1021
1119
  }
1022
1120
  }
1023
1121
  }
1024
- */
1122
+ */
1123
+
1124
+
1025
1125
  /**
1026
1126
  * Set this sketch to communicate its state back to the PDE.
1027
1127
  *
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.
1128
+ * This uses the stderr stream to write positions of the window
1129
+ * (so that it will be saved by the PDE for the next run) and
1130
+ * notify on quit. See more notes in the Worker class.
1031
1131
  */
1032
1132
  @Override
1033
1133
  public void setupExternalMessages() {
@@ -1040,9 +1140,10 @@ public class PSurfaceAWT extends PSurfaceNone {
1040
1140
  });
1041
1141
  }
1042
1142
 
1143
+
1043
1144
  /**
1044
- * Set up a listener that will fire proper component resize events in cases
1045
- * where frame.setResizable(true) is called.
1145
+ * Set up a listener that will fire proper component resize events
1146
+ * in cases where frame.setResizable(true) is called.
1046
1147
  */
1047
1148
  private void setupFrameResizeListener() {
1048
1149
  frame.addWindowStateListener((WindowEvent e) -> {
@@ -1097,6 +1198,7 @@ public class PSurfaceAWT extends PSurfaceNone {
1097
1198
  });
1098
1199
  }
1099
1200
 
1201
+
1100
1202
  // /**
1101
1203
  // * (No longer in use) Use reflection to call
1102
1204
  // * <code>com.apple.eawt.FullScreenUtilities.setWindowCanFullScreen(window, true);</code>
@@ -1111,7 +1213,7 @@ public class PSurfaceAWT extends PSurfaceNone {
1111
1213
  // } catch (ClassNotFoundException cnfe) {
1112
1214
  // // ignored
1113
1215
  // } catch (Exception e) {
1114
- // e.printStackTrace();
1216
+ //
1115
1217
  // }
1116
1218
  // }
1117
1219
  //
@@ -1134,10 +1236,14 @@ public class PSurfaceAWT extends PSurfaceNone {
1134
1236
  // } catch (ClassNotFoundException cnfe) {
1135
1237
  // // ignored
1136
1238
  // } catch (Exception e) {
1137
- // e.printStackTrace();
1239
+ //
1138
1240
  // }
1139
1241
  // }
1242
+
1243
+
1140
1244
  //////////////////////////////////////////////////////////////
1245
+
1246
+
1141
1247
  /*
1142
1248
  // disabling for now; requires Java 1.7 and "precise" semantics are odd...
1143
1249
  // returns 0.1 for tick-by-tick scrolling on OS X, but it's not a matter of
@@ -1151,13 +1257,13 @@ public class PSurfaceAWT extends PSurfaceNone {
1151
1257
  // ignored, the method will just be set to null
1152
1258
  }
1153
1259
  }
1154
- */
1260
+ */
1261
+
1262
+
1155
1263
  /**
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
- *
1160
- * @param nativeEvent
1264
+ * Figure out how to process a mouse event. When loop() has been
1265
+ * called, the events will be queued up until drawing is complete.
1266
+ * If noLoop() has been called, then events will happen immediately.
1161
1267
  */
1162
1268
  protected void nativeMouseEvent(java.awt.event.MouseEvent nativeEvent) {
1163
1269
  // the 'amount' is the number of button clicks for a click event,
@@ -1166,31 +1272,31 @@ public class PSurfaceAWT extends PSurfaceNone {
1166
1272
 
1167
1273
  int peAction = 0;
1168
1274
  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
- /*
1275
+ case java.awt.event.MouseEvent.MOUSE_PRESSED:
1276
+ peAction = MouseEvent.PRESS;
1277
+ break;
1278
+ case java.awt.event.MouseEvent.MOUSE_RELEASED:
1279
+ peAction = MouseEvent.RELEASE;
1280
+ break;
1281
+ case java.awt.event.MouseEvent.MOUSE_CLICKED:
1282
+ peAction = MouseEvent.CLICK;
1283
+ break;
1284
+ case java.awt.event.MouseEvent.MOUSE_DRAGGED:
1285
+ peAction = MouseEvent.DRAG;
1286
+ break;
1287
+ case java.awt.event.MouseEvent.MOUSE_MOVED:
1288
+ peAction = MouseEvent.MOVE;
1289
+ break;
1290
+ case java.awt.event.MouseEvent.MOUSE_ENTERED:
1291
+ peAction = MouseEvent.ENTER;
1292
+ break;
1293
+ case java.awt.event.MouseEvent.MOUSE_EXITED:
1294
+ peAction = MouseEvent.EXIT;
1295
+ break;
1296
+ //case java.awt.event.MouseWheelEvent.WHEEL_UNIT_SCROLL:
1297
+ case java.awt.event.MouseEvent.MOUSE_WHEEL:
1298
+ peAction = MouseEvent.WHEEL;
1299
+ /*
1194
1300
  if (preciseWheelMethod != null) {
1195
1301
  try {
1196
1302
  peAmount = ((Double) preciseWheelMethod.invoke(nativeEvent, (Object[]) null)).floatValue();
@@ -1198,95 +1304,71 @@ public class PSurfaceAWT extends PSurfaceNone {
1198
1304
  preciseWheelMethod = null;
1199
1305
  }
1200
1306
  }
1201
- */
1202
- peCount = ((MouseWheelEvent) nativeEvent).getWheelRotation();
1203
- break;
1307
+ */
1308
+ peCount = ((MouseWheelEvent) nativeEvent).getWheelRotation();
1309
+ break;
1204
1310
  }
1205
1311
 
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:
1312
+ // Switching to getModifiersEx() for 4.0a2 because of Java 9 deprecation.
1313
+ // Had trouble with this in the past and rolled it back because it was
1314
+ // optional at the time. This time around, just need to iron out the issue.
1220
1315
  // 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
1316
  // http://code.google.com/p/processing/issues/detail?id=1332
1317
+ int modifiers = nativeEvent.getModifiersEx();
1318
+
1223
1319
  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) {
1320
+ if ((modifiers & InputEvent.BUTTON1_DOWN_MASK) != 0) {
1235
1321
  peButton = PConstants.LEFT;
1236
- } else if ((modifiers & InputEvent.BUTTON2_MASK) != 0) {
1322
+ } else if ((modifiers & InputEvent.BUTTON2_DOWN_MASK) != 0) {
1237
1323
  peButton = PConstants.CENTER;
1238
- } else if ((modifiers & InputEvent.BUTTON3_MASK) != 0) {
1324
+ } else if ((modifiers & InputEvent.BUTTON3_DOWN_MASK) != 0) {
1239
1325
  peButton = PConstants.RIGHT;
1240
1326
  }
1241
1327
 
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
1328
  sketch.postEvent(new MouseEvent(nativeEvent, nativeEvent.getWhen(),
1253
- peAction, peModifiers,
1254
- nativeEvent.getX() / windowScaleFactor,
1255
- nativeEvent.getY() / windowScaleFactor,
1256
- peButton,
1257
- peCount));
1329
+ peAction, modifiers,
1330
+ nativeEvent.getX() / windowScaleFactor,
1331
+ nativeEvent.getY() / windowScaleFactor,
1332
+ peButton,
1333
+ peCount));
1258
1334
  }
1259
1335
 
1336
+
1260
1337
  protected void nativeKeyEvent(java.awt.event.KeyEvent event) {
1261
1338
  int peAction = 0;
1262
1339
  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;
1340
+ case java.awt.event.KeyEvent.KEY_PRESSED:
1341
+ peAction = KeyEvent.PRESS;
1342
+ break;
1343
+ case java.awt.event.KeyEvent.KEY_RELEASED:
1344
+ peAction = KeyEvent.RELEASE;
1345
+ break;
1346
+ case java.awt.event.KeyEvent.KEY_TYPED:
1347
+ peAction = KeyEvent.TYPE;
1348
+ break;
1272
1349
  }
1273
1350
 
1351
+ int modifiers = event.getModifiersEx();
1352
+
1353
+ /*
1274
1354
  // int peModifiers = event.getModifiersEx() &
1275
1355
  // (InputEvent.SHIFT_DOWN_MASK |
1276
1356
  // InputEvent.CTRL_DOWN_MASK |
1277
1357
  // InputEvent.META_DOWN_MASK |
1278
1358
  // 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);
1359
+ int peModifiers = event.getModifiers() &
1360
+ (InputEvent.SHIFT_MASK |
1361
+ InputEvent.CTRL_MASK |
1362
+ InputEvent.META_MASK |
1363
+ InputEvent.ALT_MASK);
1364
+ */
1284
1365
 
1285
1366
  sketch.postEvent(new KeyEvent(event, event.getWhen(),
1286
- peAction, peModifiers,
1287
- event.getKeyChar(), event.getKeyCode()));
1367
+ peAction, modifiers,
1368
+ event.getKeyChar(), event.getKeyCode()));
1288
1369
  }
1289
1370
 
1371
+
1290
1372
  // listeners, for all my men!
1291
1373
  protected void addListeners() {
1292
1374
 
@@ -1325,6 +1407,7 @@ public class PSurfaceAWT extends PSurfaceNone {
1325
1407
  nativeMouseEvent(e);
1326
1408
  }
1327
1409
 
1410
+ @Override
1328
1411
  public void mouseMoved(java.awt.event.MouseEvent e) {
1329
1412
  nativeMouseEvent(e);
1330
1413
  }
@@ -1341,11 +1424,13 @@ public class PSurfaceAWT extends PSurfaceNone {
1341
1424
  nativeKeyEvent(e);
1342
1425
  }
1343
1426
 
1427
+
1344
1428
  @Override
1345
1429
  public void keyReleased(java.awt.event.KeyEvent e) {
1346
1430
  nativeKeyEvent(e);
1347
1431
  }
1348
1432
 
1433
+
1349
1434
  @Override
1350
1435
  public void keyTyped(java.awt.event.KeyEvent e) {
1351
1436
  nativeKeyEvent(e);
@@ -1386,7 +1471,9 @@ public class PSurfaceAWT extends PSurfaceNone {
1386
1471
  comp.removeKeyListener(this);
1387
1472
  comp.removeFocusListener(this);
1388
1473
  }
1389
- */
1474
+ */
1475
+
1476
+
1390
1477
  // /**
1391
1478
  // * Call to remove, then add, listeners to a component.
1392
1479
  // * Avoids issues with double-adding.
@@ -1395,16 +1482,22 @@ public class PSurfaceAWT extends PSurfaceNone {
1395
1482
  // removeListeners(comp);
1396
1483
  // addListeners(comp);
1397
1484
  // }
1485
+
1486
+
1487
+
1398
1488
  // . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
1489
+
1490
+
1399
1491
  int cursorType = PConstants.ARROW;
1400
1492
  boolean cursorVisible = true;
1401
1493
  Cursor invisibleCursor;
1402
1494
 
1495
+
1403
1496
  @Override
1404
1497
  public void setCursor(int kind) {
1405
1498
  // Swap the HAND cursor because MOVE doesn't seem to be available on OS X
1406
1499
  // https://github.com/processing/processing/issues/2358
1407
- if (PApplet.platform == PConstants.MACOSX && kind == PConstants.MOVE) {
1500
+ if (PApplet.platform == PConstants.MACOS && kind == PConstants.MOVE) {
1408
1501
  kind = PConstants.HAND;
1409
1502
  }
1410
1503
  canvas.setCursor(Cursor.getPredefinedCursor(kind));
@@ -1412,6 +1505,7 @@ public class PSurfaceAWT extends PSurfaceNone {
1412
1505
  this.cursorType = kind;
1413
1506
  }
1414
1507
 
1508
+
1415
1509
  @Override
1416
1510
  public void setCursor(PImage img, int x, int y) {
1417
1511
  // Don't set cursorType, instead use cursorType to save the last
@@ -1424,14 +1518,15 @@ public class PSurfaceAWT extends PSurfaceNone {
1424
1518
  return;
1425
1519
  }
1426
1520
 
1427
- Cursor cursor
1428
- = canvas.getToolkit().createCustomCursor((Image) img.getNative(),
1429
- new Point(x, y),
1430
- "custom");
1521
+ Cursor cursor =
1522
+ canvas.getToolkit().createCustomCursor((Image) img.getNative(),
1523
+ new Point(x, y),
1524
+ "custom");
1431
1525
  canvas.setCursor(cursor);
1432
1526
  cursorVisible = true;
1433
1527
  }
1434
1528
 
1529
+
1435
1530
  @Override
1436
1531
  public void showCursor() {
1437
1532
  // Maybe should always set here? Seems dangerous, since it's likely that
@@ -1443,27 +1538,29 @@ public class PSurfaceAWT extends PSurfaceNone {
1443
1538
  }
1444
1539
  }
1445
1540
 
1541
+
1446
1542
  @Override
1447
1543
  public void hideCursor() {
1448
1544
  // Because the OS may have shown the cursor on its own,
1449
1545
  // don't return if 'cursorVisible' is set to true. [rev 0216]
1450
1546
 
1451
1547
  if (invisibleCursor == null) {
1452
- BufferedImage cursorImg
1453
- = new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
1548
+ BufferedImage cursorImg =
1549
+ new BufferedImage(16, 16, BufferedImage.TYPE_INT_ARGB);
1454
1550
  // this is a temporary workaround for the CHIP, will be removed
1455
1551
  Dimension cursorSize = Toolkit.getDefaultToolkit().getBestCursorSize(16, 16);
1456
1552
  if (cursorSize.width == 0 || cursorSize.height == 0) {
1457
1553
  invisibleCursor = Cursor.getDefaultCursor();
1458
1554
  } else {
1459
- invisibleCursor
1460
- = canvas.getToolkit().createCustomCursor(cursorImg, new Point(8, 8), "blank");
1555
+ invisibleCursor =
1556
+ canvas.getToolkit().createCustomCursor(cursorImg, new Point(8, 8), "blank");
1461
1557
  }
1462
1558
  }
1463
1559
  canvas.setCursor(invisibleCursor);
1464
1560
  cursorVisible = false;
1465
1561
  }
1466
1562
 
1563
+
1467
1564
  @Override
1468
1565
  public Thread createThread() {
1469
1566
  return new AnimationThread() {
@@ -1475,7 +1572,8 @@ public class PSurfaceAWT extends PSurfaceNone {
1475
1572
  };
1476
1573
  }
1477
1574
 
1478
- void debug(String format, Object... args) {
1575
+
1576
+ void debug(String format, Object ... args) {
1479
1577
  System.out.format(format + "%n", args);
1480
1578
  }
1481
1579
  }