propane 3.3.1-java → 3.4.0-java

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