Skip to content

Commit 6da5d9b

Browse files
committed
removing more AWT
1 parent 99ab612 commit 6da5d9b

File tree

9 files changed

+99
-87
lines changed

9 files changed

+99
-87
lines changed

core/src/processing/core/PApplet.java

Lines changed: 35 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -25,10 +25,13 @@
2525
package processing.core;
2626

2727
// used for setting bg colors and whatnot
28-
import java.awt.Color;
28+
//import java.awt.Color;
2929
// Component is further up the chain than Canvas
30-
import java.awt.Component;
30+
//import java.awt.Component;
3131
// use for the link() command (and maybe open()?)
32+
33+
// these are used for various methods (url opening, file selection, etc)
34+
// how many more can we remove?
3235
import java.awt.Desktop;
3336
import java.awt.EventQueue;
3437
import java.awt.FileDialog;
@@ -38,13 +41,6 @@
3841
import java.awt.Toolkit;
3942
import java.awt.color.ColorSpace;
4043
import java.awt.image.BufferedImage;
41-
import java.io.*;
42-
import java.lang.reflect.*;
43-
import java.net.*;
44-
import java.text.*;
45-
import java.util.*;
46-
import java.util.regex.*;
47-
import java.util.zip.*;
4844

4945
// used by loadImage() functions
5046
import javax.imageio.ImageIO;
@@ -54,6 +50,14 @@
5450
// used by desktopFile() method
5551
import javax.swing.filechooser.FileSystemView;
5652

53+
import java.io.*;
54+
import java.lang.reflect.*;
55+
import java.net.*;
56+
import java.text.*;
57+
import java.util.*;
58+
import java.util.regex.*;
59+
import java.util.zip.*;
60+
5761
import processing.data.*;
5862
import processing.event.*;
5963
import processing.opengl.*;
@@ -9409,8 +9413,9 @@ static protected void runSketchEDT(final String[] args,
94099413
int[] editorLocation = null;
94109414

94119415
String name = null;
9412-
Color backgroundColor = null;
9413-
Color stopColor = Color.GRAY;
9416+
int backgroundColor = 0;
9417+
//int stopColor = java.awt.Color.GRAY.getRGB();
9418+
int stopColor = 0xff808080;
94149419
boolean hideStop = false;
94159420

94169421
int displayIndex = -1; // -1 means use default, b/c numbered from 0
@@ -9436,11 +9441,11 @@ static protected void runSketchEDT(final String[] args,
94369441

94379442
} else if (param.equals(ARGS_BGCOLOR)) {
94389443
if (value.charAt(0) == '#') value = value.substring(1);
9439-
backgroundColor = new Color(Integer.parseInt(value, 16));
9444+
backgroundColor = 0xff000000 | Integer.parseInt(value, 16);
94409445

94419446
} else if (param.equals(ARGS_STOP_COLOR)) {
94429447
if (value.charAt(0) == '#') value = value.substring(1);
9443-
stopColor = new Color(Integer.parseInt(value, 16));
9448+
stopColor = 0xff000000 | Integer.parseInt(value, 16);
94449449

94459450
} else if (param.equals(ARGS_SKETCH_FOLDER)) {
94469451
folder = value;
@@ -9558,7 +9563,7 @@ static protected void runSketchEDT(final String[] args,
95589563
if (fullScreen) {
95599564
//surface.placeFullScreen(hideStop);
95609565
if (hideStop) {
9561-
stopColor = null; // they'll get the hint
9566+
stopColor = 0; // they'll get the hint
95629567
}
95639568
surface.placePresent(stopColor);
95649569
} else {
@@ -9571,7 +9576,7 @@ static protected void runSketchEDT(final String[] args,
95719576
}
95729577

95739578

9574-
protected PSurface initSurface(Color backgroundColor, int displayIndex,
9579+
protected PSurface initSurface(int backgroundColor, int displayIndex,
95759580
boolean present, boolean spanDisplays) {
95769581
// try {
95779582
// String renderer = applet.sketchRenderer();
@@ -9662,21 +9667,21 @@ private void deprecationWarning(String method) {
96629667
// }
96639668

96649669

9665-
/**
9666-
* Return a Canvas object that can be embedded into other Java GUIs.
9667-
* This is necessary because PApplet no longer subclasses Component.
9668-
*
9669-
* <pre>
9670-
* PApplet sketch = new EmbedSketch();
9671-
* Canvas canvas = sketch.getCanvas();
9672-
* // add the canvas object to your project and validate() it
9673-
* sketch.init() // start the animation thread
9674-
*/
9675-
public Component getComponent() {
9676-
g = createPrimaryGraphics();
9677-
surface = g.createSurface();
9678-
return surface.initComponent(this);
9679-
}
9670+
// /**
9671+
// * Return a Canvas object that can be embedded into other Java GUIs.
9672+
// * This is necessary because PApplet no longer subclasses Component.
9673+
// *
9674+
// * <pre>
9675+
// * PApplet sketch = new EmbedSketch();
9676+
// * Canvas canvas = sketch.getCanvas();
9677+
// * // add the canvas object to your project and validate() it
9678+
// * sketch.init() // start the animation thread
9679+
// */
9680+
// public Component getComponent() {
9681+
// g = createPrimaryGraphics();
9682+
// surface = g.createSurface();
9683+
// return surface.initComponent(this);
9684+
// }
96809685

96819686

96829687
/** Convenience method, should only be called by PSurface subclasses. */

core/src/processing/core/PGraphicsJava2D.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -285,7 +285,7 @@ public Graphics2D checkImage() {
285285

286286
GraphicsConfiguration gc = null;
287287
if (surface != null) {
288-
Component comp = surface.getComponent();
288+
Component comp = null; //surface.getComponent();
289289
if (comp == null) {
290290
// System.out.println("component null, but parent.frame is " + parent.frame);
291291
comp = parent.frame;

core/src/processing/core/PSurface.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -22,9 +22,6 @@
2222

2323
package processing.core;
2424

25-
import java.awt.Color;
26-
import java.awt.Component;
27-
2825

2926
public interface PSurface {
3027
/**
@@ -40,15 +37,18 @@ public interface PSurface {
4037
// Background default needs to be different from the default value in
4138
// PGraphics.backgroundColor, otherwise size(100, 100) bg spills over.
4239
// https://github.com/processing/processing/issues/2297
43-
static final Color WINDOW_BGCOLOR = new Color(0xDD, 0xDD, 0xDD);
40+
//static final Color WINDOW_BGCOLOR = new Color(0xDD, 0xDD, 0xDD);
41+
static final int WINDOW_BGCOLOR = 0xffDDDDDD;
4442

4543
// renderer that doesn't draw to the screen
4644
public void initOffscreen(PApplet sketch);
4745

48-
public Component initComponent(PApplet sketch);
46+
// considering removal in favor of separate Component classes for appropriate renderers
47+
// (i.e. for Java2D or a generic Image surface, but not PDF, debatable for GL or FX)
48+
//public Component initComponent(PApplet sketch);
4949

5050
//public Frame initFrame(PApplet sketch, Color backgroundColor,
51-
public void initFrame(PApplet sketch, Color backgroundColor,
51+
public void initFrame(PApplet sketch, int backgroundColor,
5252
int deviceIndex, boolean fullScreen, boolean spanDisplays);
5353

5454
//
@@ -73,7 +73,7 @@ public void initFrame(PApplet sketch, Color backgroundColor,
7373
public void placeWindow(int[] location, int[] editorLocation);
7474

7575
//public void placeFullScreen(boolean hideStop);
76-
public void placePresent(Color stopColor);
76+
public void placePresent(int stopColor);
7777

7878
// Sketch is running from the PDE, set up messaging back to the PDE
7979
public void setupExternalMessages();
@@ -98,7 +98,7 @@ public void initFrame(PApplet sketch, Color backgroundColor,
9898
// create pixel buffer, called from allocate() to produce a compatible image for rendering efficiently
9999
// public void initImage(PGraphics gr);
100100

101-
public Component getComponent();
101+
//public Component getComponent();
102102

103103
/**
104104
* Sometimes smoothing must be set at the drawing surface level

core/src/processing/core/PSurfaceAWT.java

Lines changed: 13 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -374,6 +374,7 @@ public Frame initOffscreen() {
374374
}
375375
*/
376376

377+
/*
377378
@Override
378379
public Component initComponent(PApplet sketch) {
379380
this.sketch = sketch;
@@ -384,11 +385,12 @@ public Component initComponent(PApplet sketch) {
384385
385386
return canvas;
386387
}
388+
*/
387389

388390

389391
@Override
390-
public void initFrame(PApplet sketch, Color backgroundColor,
391-
int deviceIndex, boolean fullScreen, boolean spanDisplays) {
392+
public void initFrame(PApplet sketch, int backgroundColor,
393+
int deviceIndex, boolean fullScreen, boolean spanDisplays) {
392394
this.sketch = sketch;
393395

394396
GraphicsEnvironment environment =
@@ -450,10 +452,10 @@ public void initFrame(PApplet sketch, Color backgroundColor,
450452

451453
// Removed code above, also removed from what's now in the placeXxxx()
452454
// methods. Not sure why it was being double-set; hopefully anachronistic.
453-
if (backgroundColor == null) {
455+
if (backgroundColor == 0) {
454456
backgroundColor = WINDOW_BGCOLOR;
455457
}
456-
frame.getContentPane().setBackground(backgroundColor);
458+
frame.getContentPane().setBackground(new Color(backgroundColor, false));
457459

458460
// Put the p5 logo in the Frame's corner to override the Java coffee cup.
459461
setIconImage(frame);
@@ -561,7 +563,7 @@ public void setVisible(boolean visible) {
561563

562564
//public void placeFullScreen(boolean hideStop) {
563565
@Override
564-
public void placePresent(Color stopColor) {
566+
public void placePresent(int stopColor) {
565567
// After the pack(), the screen bounds are gonna be 0s
566568
frame.setBounds(screenRect);
567569
canvas.setBounds((screenRect.width - sketchWidth) / 2,
@@ -573,9 +575,9 @@ public void placePresent(Color stopColor) {
573575
// macosxFullScreenToggle(frame);
574576
// }
575577

576-
if (stopColor != null) {
578+
if (stopColor != 0) {
577579
Label label = new Label("stop");
578-
label.setForeground(stopColor);
580+
label.setForeground(new Color(stopColor, false));
579581
label.addMouseListener(new MouseAdapter() {
580582
@Override
581583
public void mousePressed(java.awt.event.MouseEvent e) {
@@ -806,10 +808,10 @@ public void initImage(PGraphics graphics) {
806808
*/
807809

808810

809-
@Override
810-
public Component getComponent() {
811-
return canvas;
812-
}
811+
// @Override
812+
// public Component getComponent() {
813+
// return canvas;
814+
// }
813815

814816

815817
@Override

core/src/processing/core/PSurfaceFX.java

Lines changed: 18 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -22,8 +22,8 @@
2222

2323
package processing.core;
2424

25-
import java.awt.Component;
26-
import java.awt.Frame;
25+
//import java.awt.Component;
26+
//import java.awt.Frame;
2727

2828
import javafx.animation.AnimationTimer;
2929
import javafx.application.Application;
@@ -65,7 +65,7 @@ public class PSurfaceFX implements PSurface {
6565
PGraphicsFX fx;
6666
Stage stage;
6767
Canvas canvas;
68-
Frame dummy;
68+
// Frame dummy;
6969

7070
AnimationTimer timer;
7171

@@ -140,9 +140,9 @@ public void initOffscreen(PApplet sketch) {
140140
}
141141

142142

143-
public Component initComponent(PApplet sketch) {
144-
return null;
145-
}
143+
// public Component initComponent(PApplet sketch) {
144+
// return null;
145+
// }
146146

147147

148148
static public class PApplicationFX extends Application {
@@ -162,13 +162,13 @@ public void start(final Stage stage) {
162162

163163
//stage.setScene(new Scene(new Group(canvas)));
164164
stage.setScene(new Scene(stackPane));
165-
stage.show(); // move to setVisible(true)?
165+
//stage.show(); // move to setVisible(true)?
166166
}
167167
}
168168

169169

170170
//public Frame initFrame(PApplet sketch, java.awt.Color backgroundColor,
171-
public void initFrame(PApplet sketch, java.awt.Color backgroundColor,
171+
public void initFrame(PApplet sketch, int backgroundColor,
172172
int deviceIndex, boolean fullScreen,
173173
boolean spanDisplays) {
174174
this.sketch = sketch;
@@ -191,7 +191,7 @@ public void setTitle(String title) {
191191

192192
/** Show or hide the window. */
193193
public void setVisible(boolean visible) {
194-
// TODO ignored?
194+
stage.show();
195195
}
196196

197197

@@ -254,7 +254,6 @@ public void start(final Stage stage) {
254254

255255
public void placeWindow(int[] location) {
256256
// TODO Auto-generated method stub
257-
258257
}
259258

260259

@@ -264,28 +263,28 @@ public void placeWindow(int[] location, int[] editorLocation) {
264263
}
265264

266265

267-
public void placePresent(java.awt.Color stopColor) {
266+
// http://download.java.net/jdk8/jfxdocs/javafx/stage/Stage.html#setFullScreenExitHint-java.lang.String-
267+
// http://download.java.net/jdk8/jfxdocs/javafx/stage/Stage.html#setFullScreenExitKeyCombination-javafx.scene.input.KeyCombination-
268+
public void placePresent(int stopColor) {
268269
// TODO Auto-generated method stub
269-
270270
}
271271

272272

273273
public void setupExternalMessages() {
274274
// TODO Auto-generated method stub
275-
276275
}
277276

278277

279278
public void setSize(int width, int height) {
280-
// TODO Auto-generated method stub
281-
279+
System.out.println(getClass().getSimpleName() + " setSize()");
280+
stage.setWidth(width);
281+
stage.setHeight(height);
282282
}
283283

284284

285-
public Component getComponent() {
286-
// TODO Auto-generated method stub
287-
return null;
288-
}
285+
// public Component getComponent() {
286+
// return null;
287+
// }
289288

290289
public void setSmooth(int level) {
291290
// TODO Auto-generated method stub

0 commit comments

Comments
 (0)