picrate 2.1.0-java → 2.4.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.mvn/extensions.xml +1 -1
- data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
- data/.mvn/wrapper/maven-wrapper.properties +2 -2
- data/CHANGELOG.md +10 -0
- data/README.md +6 -3
- data/Rakefile +2 -1
- data/docs/_includes/footer.html +1 -1
- data/docs/_layouts/post.html +1 -1
- data/docs/_methods/alternative_methods.md +2 -1
- data/docs/_methods/noise_mode.md +88 -0
- data/docs/_posts/2018-05-06-install_jruby.md +3 -3
- data/docs/_posts/2018-11-18-building-gem.md +3 -1
- data/docs/_posts/2020-03-09-auto_install_picrate.md +2 -3
- data/docs/_posts/2020-05-11-getting_started_manjaro.md +19 -7
- data/docs/classes.md +2 -2
- data/docs/editors.md +2 -2
- data/docs/gems.md +3 -3
- data/docs/index.html +1 -1
- data/docs/libraries.md +2 -2
- data/docs/live.md +2 -2
- data/docs/magic.md +2 -2
- data/docs/methods.md +2 -2
- data/docs/modules.md +3 -3
- data/docs/objects.md +2 -2
- data/lib/picrate.rb +2 -1
- data/lib/picrate/app.rb +3 -2
- data/lib/picrate/helper_methods.rb +1 -1
- data/lib/picrate/native_folder.rb +1 -3
- data/lib/picrate/runner.rb +4 -4
- data/lib/picrate/version.rb +1 -1
- data/library/jcomplex/jcomplex.rb +1 -0
- data/library/pdf/pdf.rb +7 -0
- data/library/svg/svg.rb +7 -0
- data/mvnw +2 -2
- data/mvnw.cmd +2 -2
- data/picrate.gemspec +5 -3
- data/pom.rb +31 -9
- data/pom.xml +41 -6
- data/src/main/java/monkstone/FastNoiseModuleJava.java +127 -0
- data/src/main/java/monkstone/PicrateLibrary.java +3 -1
- data/src/main/java/monkstone/SmoothNoiseModuleJava.java +127 -0
- data/src/main/java/monkstone/complex/JComplex.java +252 -0
- data/src/main/java/monkstone/fastmath/DegLutTables.java +111 -0
- data/src/main/java/monkstone/fastmath/Deglut.java +41 -93
- data/src/main/java/monkstone/noise/OpenSimplex2F.java +813 -0
- data/src/main/java/monkstone/noise/OpenSimplex2S.java +1138 -0
- data/src/main/java/monkstone/vecmath/package-info.java +1 -1
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
- data/src/main/java/monkstone/videoevent/package-info.java +1 -1
- data/src/main/java/processing/awt/ShimAWT.java +260 -94
- data/src/main/java/processing/core/PApplet.java +14664 -13450
- data/src/main/java/processing/core/PConstants.java +5 -5
- data/src/main/java/processing/core/PFont.java +1 -1
- data/src/main/java/processing/core/PGraphics.java +200 -201
- data/src/main/java/processing/core/PImage.java +539 -549
- data/src/main/java/processing/core/PShape.java +18 -18
- data/src/main/java/processing/core/PVector.java +23 -23
- data/src/main/java/processing/data/Table.java +4 -4
- data/src/main/java/processing/net/Client.java +13 -13
- data/src/main/java/processing/net/Server.java +5 -5
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +4 -4
- data/src/main/java/processing/pdf/PGraphicsPDF.java +529 -0
- data/src/main/java/processing/svg/PGraphicsSVG.java +378 -0
- data/test/deglut_spec_test.rb +2 -2
- data/test/respond_to_test.rb +0 -2
- data/vendors/Rakefile +31 -22
- data/vendors/geany.rb +3 -3
- metadata +26 -13
- data/src/main/java/monkstone/noise/SimplexNoise.java +0 -465
@@ -9,19 +9,27 @@ import java.awt.Image;
|
|
9
9
|
import java.awt.Toolkit;
|
10
10
|
import java.awt.color.ColorSpace;
|
11
11
|
import java.awt.image.BufferedImage;
|
12
|
+
import java.io.BufferedOutputStream;
|
12
13
|
import java.io.File;
|
13
14
|
import java.io.IOException;
|
14
15
|
import java.io.InputStream;
|
15
16
|
import java.net.URI;
|
16
17
|
import java.net.URISyntaxException;
|
17
|
-
|
18
|
+
import java.util.Iterator;
|
18
19
|
import java.awt.DisplayMode;
|
19
20
|
import java.awt.GraphicsConfiguration;
|
20
21
|
import java.awt.GraphicsDevice;
|
21
22
|
import java.awt.GraphicsEnvironment;
|
22
23
|
import java.awt.geom.AffineTransform;
|
23
24
|
|
25
|
+
import javax.imageio.IIOImage;
|
24
26
|
import javax.imageio.ImageIO;
|
27
|
+
import javax.imageio.ImageTypeSpecifier;
|
28
|
+
import javax.imageio.ImageWriteParam;
|
29
|
+
import javax.imageio.ImageWriter;
|
30
|
+
import javax.imageio.metadata.IIOInvalidTreeException;
|
31
|
+
import javax.imageio.metadata.IIOMetadata;
|
32
|
+
import javax.imageio.metadata.IIOMetadataNode;
|
25
33
|
import javax.swing.ImageIcon;
|
26
34
|
import javax.swing.JFileChooser;
|
27
35
|
import javax.swing.UIManager;
|
@@ -34,14 +42,14 @@ import processing.core.PApplet;
|
|
34
42
|
import processing.core.PConstants;
|
35
43
|
import processing.core.PImage;
|
36
44
|
|
45
|
+
|
37
46
|
/**
|
38
|
-
* This class exists as an abstraction layer to remove AWT from PApplet.
|
39
|
-
* staging area for AWT-specific code that's shared by the Java2D,
|
40
|
-
* JOGL renderers. Once PSurfaceFX and PSurfaceJOGL have
|
41
|
-
* implementations, these methods will move to PSurfaceAWT.
|
47
|
+
* This class exists as an abstraction layer to remove AWT from PApplet.
|
48
|
+
* It is a staging area for AWT-specific code that's shared by the Java2D,
|
49
|
+
* JavaFX, and JOGL renderers. Once PSurfaceFX and PSurfaceJOGL have
|
50
|
+
* their own implementations, these methods will move to PSurfaceAWT.
|
42
51
|
*/
|
43
52
|
public class ShimAWT implements PConstants {
|
44
|
-
|
45
53
|
/*
|
46
54
|
PGraphics graphics;
|
47
55
|
PApplet sketch;
|
@@ -51,17 +59,16 @@ public class ShimAWT implements PConstants {
|
|
51
59
|
this.graphics = graphics;
|
52
60
|
this.sketch = sketch;
|
53
61
|
}
|
54
|
-
|
62
|
+
*/
|
55
63
|
static private ShimAWT instance;
|
56
64
|
|
57
65
|
private GraphicsDevice[] displayDevices;
|
58
66
|
|
59
|
-
private
|
60
|
-
private
|
67
|
+
private int displayWidth;
|
68
|
+
private int displayHeight;
|
61
69
|
|
62
|
-
|
63
|
-
|
64
|
-
*/
|
70
|
+
|
71
|
+
/** Only needed for display functions */
|
65
72
|
static private ShimAWT getInstance() {
|
66
73
|
if (instance == null) {
|
67
74
|
instance = new ShimAWT();
|
@@ -69,6 +76,7 @@ public class ShimAWT implements PConstants {
|
|
69
76
|
return instance;
|
70
77
|
}
|
71
78
|
|
79
|
+
|
72
80
|
private ShimAWT() {
|
73
81
|
// Need the list of display devices to be queried already for usage below.
|
74
82
|
// https://github.com/processing/processing/issues/3295
|
@@ -87,24 +95,29 @@ public class ShimAWT implements PConstants {
|
|
87
95
|
// }
|
88
96
|
// When this was called, display will always be unset (even in 3.x),
|
89
97
|
// since this happens before settings() is called.
|
98
|
+
|
90
99
|
// Set displayWidth and displayHeight for people still using those.
|
91
100
|
DisplayMode displayMode = device.getDisplayMode();
|
92
101
|
displayWidth = displayMode.getWidth();
|
93
102
|
displayHeight = displayMode.getHeight();
|
94
103
|
}
|
95
104
|
|
105
|
+
|
96
106
|
static public int getDisplayWidth() {
|
97
107
|
return getInstance().displayWidth;
|
98
108
|
}
|
99
109
|
|
110
|
+
|
100
111
|
static public int getDisplayHeight() {
|
101
112
|
return getInstance().displayHeight;
|
102
113
|
}
|
103
114
|
|
115
|
+
|
104
116
|
static public int getDisplayCount() {
|
105
117
|
return getInstance().displayDevices.length;
|
106
118
|
}
|
107
119
|
|
120
|
+
|
108
121
|
static public int getDisplayDensity(int num) {
|
109
122
|
return getInstance().displayDensityImpl(num);
|
110
123
|
}
|
@@ -124,20 +137,29 @@ public class ShimAWT implements PConstants {
|
|
124
137
|
// If nobody's density is 2 then everyone is 1
|
125
138
|
return 1;
|
126
139
|
}
|
127
|
-
|
140
|
+
*/
|
141
|
+
|
142
|
+
|
128
143
|
private int displayDensityImpl(int display) {
|
129
144
|
if (display > 0 && display <= displayDevices.length) {
|
130
|
-
GraphicsConfiguration graphicsConfig
|
131
|
-
|
145
|
+
GraphicsConfiguration graphicsConfig =
|
146
|
+
displayDevices[display - 1].getDefaultConfiguration();
|
132
147
|
AffineTransform tx = graphicsConfig.getDefaultTransform();
|
133
148
|
return (int) Math.round(tx.getScaleX());
|
134
149
|
}
|
135
150
|
|
136
|
-
System.err.println("Display " + display + " does not exist, "
|
137
|
-
|
151
|
+
System.err.println("Display " + display + " does not exist, " +
|
152
|
+
"returning 1 for displayDensity(" + display + ")");
|
138
153
|
return 1; // not the end of the world, so don't throw a RuntimeException
|
139
154
|
}
|
140
155
|
|
156
|
+
|
157
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
158
|
+
|
159
|
+
|
160
|
+
static protected String[] loadImageFormats; // list of ImageIO formats
|
161
|
+
|
162
|
+
|
141
163
|
static public PImage loadImage(PApplet sketch, String filename, Object... args) {
|
142
164
|
String extension = null;
|
143
165
|
if (args != null && args.length > 0) {
|
@@ -169,22 +191,21 @@ public class ShimAWT implements PConstants {
|
|
169
191
|
if (extension.equals("tga")) {
|
170
192
|
try {
|
171
193
|
InputStream input = sketch.createInput(filename);
|
172
|
-
if (input == null)
|
173
|
-
return null;
|
174
|
-
}
|
194
|
+
if (input == null) return null;
|
175
195
|
|
176
196
|
PImage image = PImage.loadTGA(input);
|
177
197
|
image.parent = sketch;
|
178
198
|
return image;
|
179
199
|
|
180
200
|
} catch (IOException e) {
|
201
|
+
e.printStackTrace();
|
181
202
|
return null;
|
182
203
|
}
|
183
204
|
}
|
184
205
|
|
185
206
|
if (extension.equals("tif") || extension.equals("tiff")) {
|
186
207
|
InputStream input = sketch.createInput(filename);
|
187
|
-
PImage image =
|
208
|
+
PImage image = (input == null) ? null : PImage.loadTIFF(input);
|
188
209
|
return image;
|
189
210
|
}
|
190
211
|
|
@@ -192,9 +213,9 @@ public class ShimAWT implements PConstants {
|
|
192
213
|
// because the javax.imageio code was found to be much slower.
|
193
214
|
// http://dev.processing.org/bugs/show_bug.cgi?id=392
|
194
215
|
try {
|
195
|
-
if (extension.equals("jpg") || extension.equals("jpeg")
|
196
|
-
|
197
|
-
|
216
|
+
if (extension.equals("jpg") || extension.equals("jpeg") ||
|
217
|
+
extension.equals("gif") || extension.equals("png") ||
|
218
|
+
extension.equals("unknown")) {
|
198
219
|
byte[] bytes = sketch.loadBytes(filename);
|
199
220
|
if (bytes == null) {
|
200
221
|
return null;
|
@@ -206,8 +227,8 @@ public class ShimAWT implements PConstants {
|
|
206
227
|
BufferedImage buffImage = (BufferedImage) awtImage;
|
207
228
|
int space = buffImage.getColorModel().getColorSpace().getType();
|
208
229
|
if (space == ColorSpace.TYPE_CMYK) {
|
209
|
-
System.err.println(filename + " is a CMYK image, "
|
210
|
-
|
230
|
+
System.err.println(filename + " is a CMYK image, " +
|
231
|
+
"only RGB images are supported.");
|
211
232
|
return null;
|
212
233
|
/*
|
213
234
|
// wishful thinking, appears to not be supported
|
@@ -219,19 +240,19 @@ public class ShimAWT implements PConstants {
|
|
219
240
|
ColorConvertOp op = new ColorConvertOp(null);
|
220
241
|
op.filter(buffImage, destImage);
|
221
242
|
image = new PImage(destImage);
|
222
|
-
|
243
|
+
*/
|
223
244
|
}
|
224
245
|
}
|
225
246
|
|
226
247
|
PImage image = new PImageAWT(awtImage);
|
227
248
|
if (image.width == -1) {
|
228
|
-
System.err.println("The file " + filename
|
229
|
-
|
249
|
+
System.err.println("The file " + filename +
|
250
|
+
" contains bad image data, or may not be an image.");
|
230
251
|
}
|
231
252
|
|
232
253
|
// if it's a .gif image, test to see if it has transparency
|
233
|
-
if (extension.equals("gif") || extension.equals("png")
|
234
|
-
|
254
|
+
if (extension.equals("gif") || extension.equals("png") ||
|
255
|
+
extension.equals("unknown")) {
|
235
256
|
image.checkAlpha();
|
236
257
|
}
|
237
258
|
|
@@ -241,15 +262,15 @@ public class ShimAWT implements PConstants {
|
|
241
262
|
}
|
242
263
|
} catch (Exception e) {
|
243
264
|
// show error, but move on to the stuff below, see if it'll work
|
244
|
-
|
265
|
+
e.printStackTrace();
|
245
266
|
}
|
246
267
|
|
247
268
|
if (loadImageFormats == null) {
|
248
269
|
loadImageFormats = ImageIO.getReaderFormatNames();
|
249
270
|
}
|
250
271
|
if (loadImageFormats != null) {
|
251
|
-
for (
|
252
|
-
if (extension.equals(
|
272
|
+
for (int i = 0; i < loadImageFormats.length; i++) {
|
273
|
+
if (extension.equals(loadImageFormats[i])) {
|
253
274
|
return loadImageIO(sketch, filename);
|
254
275
|
}
|
255
276
|
}
|
@@ -260,7 +281,6 @@ public class ShimAWT implements PConstants {
|
|
260
281
|
return null;
|
261
282
|
}
|
262
283
|
|
263
|
-
static protected String[] loadImageFormats;
|
264
284
|
|
265
285
|
/**
|
266
286
|
* Use Java 1.4 ImageIO methods to load an image.
|
@@ -280,6 +300,7 @@ public class ShimAWT implements PConstants {
|
|
280
300
|
|
281
301
|
//bi.getRGB(0, 0, outgoing.width, outgoing.height,
|
282
302
|
// outgoing.pixels, 0, outgoing.width);
|
303
|
+
|
283
304
|
// check the alpha for this image
|
284
305
|
// was gonna call getType() on the image to see if RGB or ARGB,
|
285
306
|
// but it's not actually useful, since gif images will come through
|
@@ -293,11 +314,164 @@ public class ShimAWT implements PConstants {
|
|
293
314
|
// return the image
|
294
315
|
return outgoing;
|
295
316
|
|
296
|
-
} catch (
|
317
|
+
} catch (Exception e) {
|
318
|
+
e.printStackTrace();
|
297
319
|
return null;
|
298
320
|
}
|
299
321
|
}
|
300
322
|
|
323
|
+
|
324
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
325
|
+
|
326
|
+
|
327
|
+
static public boolean saveImage(PImage image, String path) {
|
328
|
+
if (saveImageFormats == null) {
|
329
|
+
saveImageFormats = javax.imageio.ImageIO.getWriterFormatNames();
|
330
|
+
}
|
331
|
+
try {
|
332
|
+
if (saveImageFormats != null) {
|
333
|
+
for (int i = 0; i < saveImageFormats.length; i++) {
|
334
|
+
if (path.endsWith("." + saveImageFormats[i])) {
|
335
|
+
if (!saveImageIO(image, path)) {
|
336
|
+
System.err.println("Error while saving image.");
|
337
|
+
return false;
|
338
|
+
}
|
339
|
+
return true;
|
340
|
+
}
|
341
|
+
}
|
342
|
+
}
|
343
|
+
} catch (IOException e) {
|
344
|
+
e.printStackTrace();
|
345
|
+
}
|
346
|
+
return false;
|
347
|
+
}
|
348
|
+
|
349
|
+
|
350
|
+
static protected String[] saveImageFormats;
|
351
|
+
|
352
|
+
|
353
|
+
/**
|
354
|
+
* Use ImageIO functions from Java 1.4 and later to handle image save.
|
355
|
+
* Various formats are supported, typically jpeg, png, bmp, and wbmp.
|
356
|
+
* To get a list of the supported formats for writing, use: <BR>
|
357
|
+
* <TT>println(javax.imageio.ImageIO.getReaderFormatNames())</TT>
|
358
|
+
*/
|
359
|
+
static protected boolean saveImageIO(PImage image, String path) throws IOException {
|
360
|
+
try {
|
361
|
+
int outputFormat = (image.format == ARGB) ?
|
362
|
+
BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB;
|
363
|
+
|
364
|
+
String extension =
|
365
|
+
path.substring(path.lastIndexOf('.') + 1).toLowerCase();
|
366
|
+
|
367
|
+
// JPEG and BMP images that have an alpha channel set get pretty unhappy.
|
368
|
+
// BMP just doesn't write, and JPEG writes it as a CMYK image.
|
369
|
+
// http://code.google.com/p/processing/issues/detail?id=415
|
370
|
+
if (extension.equals("bmp") || extension.equals("jpg") || extension.equals("jpeg")) {
|
371
|
+
outputFormat = BufferedImage.TYPE_INT_RGB;
|
372
|
+
}
|
373
|
+
|
374
|
+
BufferedImage bimage = new BufferedImage(image.pixelWidth, image.pixelHeight, outputFormat);
|
375
|
+
bimage.setRGB(0, 0, image.pixelWidth, image.pixelHeight, image.pixels, 0, image.pixelWidth);
|
376
|
+
|
377
|
+
File file = new File(path);
|
378
|
+
|
379
|
+
ImageWriter writer = null;
|
380
|
+
ImageWriteParam param = null;
|
381
|
+
IIOMetadata metadata = null;
|
382
|
+
|
383
|
+
if (extension.equals("jpg") || extension.equals("jpeg")) {
|
384
|
+
if ((writer = imageioWriter("jpeg")) != null) {
|
385
|
+
// Set JPEG quality to 90% with baseline optimization. Setting this
|
386
|
+
// to 1 was a huge jump (about triple the size), so this seems good.
|
387
|
+
// Oddly, a smaller file size than Photoshop at 90%, but I suppose
|
388
|
+
// it's a completely different algorithm.
|
389
|
+
param = writer.getDefaultWriteParam();
|
390
|
+
param.setCompressionMode(ImageWriteParam.MODE_EXPLICIT);
|
391
|
+
param.setCompressionQuality(0.9f);
|
392
|
+
}
|
393
|
+
}
|
394
|
+
|
395
|
+
if (extension.equals("png")) {
|
396
|
+
if ((writer = imageioWriter("png")) != null) {
|
397
|
+
param = writer.getDefaultWriteParam();
|
398
|
+
if (false) {
|
399
|
+
metadata = imageioDPI(writer, param, 100);
|
400
|
+
}
|
401
|
+
}
|
402
|
+
}
|
403
|
+
|
404
|
+
if (writer != null) {
|
405
|
+
BufferedOutputStream output =
|
406
|
+
new BufferedOutputStream(PApplet.createOutput(file));
|
407
|
+
writer.setOutput(ImageIO.createImageOutputStream(output));
|
408
|
+
// writer.write(null, new IIOImage(bimage, null, null), param);
|
409
|
+
writer.write(metadata, new IIOImage(bimage, null, metadata), param);
|
410
|
+
writer.dispose();
|
411
|
+
|
412
|
+
output.flush();
|
413
|
+
output.close();
|
414
|
+
return true;
|
415
|
+
}
|
416
|
+
// If iter.hasNext() somehow fails up top, it falls through to here
|
417
|
+
return javax.imageio.ImageIO.write(bimage, extension, file);
|
418
|
+
|
419
|
+
} catch (Exception e) {
|
420
|
+
e.printStackTrace();
|
421
|
+
throw new IOException("image save failed.");
|
422
|
+
}
|
423
|
+
}
|
424
|
+
|
425
|
+
|
426
|
+
static private ImageWriter imageioWriter(String extension) {
|
427
|
+
Iterator<ImageWriter> iter = ImageIO.getImageWritersByFormatName(extension);
|
428
|
+
if (iter.hasNext()) {
|
429
|
+
return iter.next();
|
430
|
+
}
|
431
|
+
return null;
|
432
|
+
}
|
433
|
+
|
434
|
+
|
435
|
+
static private IIOMetadata imageioDPI(ImageWriter writer, ImageWriteParam param, double dpi) {
|
436
|
+
// http://stackoverflow.com/questions/321736/how-to-set-dpi-information-in-an-image
|
437
|
+
ImageTypeSpecifier typeSpecifier =
|
438
|
+
ImageTypeSpecifier.createFromBufferedImageType(BufferedImage.TYPE_INT_RGB);
|
439
|
+
IIOMetadata metadata =
|
440
|
+
writer.getDefaultImageMetadata(typeSpecifier, param);
|
441
|
+
|
442
|
+
if (!metadata.isReadOnly() && metadata.isStandardMetadataFormatSupported()) {
|
443
|
+
// for PNG, it's dots per millimeter
|
444
|
+
double dotsPerMilli = dpi / 25.4;
|
445
|
+
|
446
|
+
IIOMetadataNode horiz = new IIOMetadataNode("HorizontalPixelSize");
|
447
|
+
horiz.setAttribute("value", Double.toString(dotsPerMilli));
|
448
|
+
|
449
|
+
IIOMetadataNode vert = new IIOMetadataNode("VerticalPixelSize");
|
450
|
+
vert.setAttribute("value", Double.toString(dotsPerMilli));
|
451
|
+
|
452
|
+
IIOMetadataNode dim = new IIOMetadataNode("Dimension");
|
453
|
+
dim.appendChild(horiz);
|
454
|
+
dim.appendChild(vert);
|
455
|
+
|
456
|
+
IIOMetadataNode root = new IIOMetadataNode("javax_imageio_1.0");
|
457
|
+
root.appendChild(dim);
|
458
|
+
|
459
|
+
try {
|
460
|
+
metadata.mergeTree("javax_imageio_1.0", root);
|
461
|
+
return metadata;
|
462
|
+
|
463
|
+
} catch (IIOInvalidTreeException e) {
|
464
|
+
System.err.println("Could not set the DPI of the output image");
|
465
|
+
e.printStackTrace();
|
466
|
+
}
|
467
|
+
}
|
468
|
+
return null;
|
469
|
+
}
|
470
|
+
|
471
|
+
|
472
|
+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
|
473
|
+
|
474
|
+
|
301
475
|
static public void initRun() {
|
302
476
|
// Supposed to help with flicker, but no effect on OS X.
|
303
477
|
// TODO IIRC this helped on Windows, but need to double check.
|
@@ -332,11 +506,13 @@ public class ShimAWT implements PConstants {
|
|
332
506
|
// If nobody's density is 2 then everyone is 1
|
333
507
|
return 1;
|
334
508
|
}
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
|
509
|
+
*/
|
510
|
+
|
511
|
+
|
512
|
+
/**
|
513
|
+
* @param display the display number to check
|
514
|
+
* (1-indexed to match the Preferences dialog box)
|
515
|
+
*/
|
340
516
|
/*
|
341
517
|
public int displayDensity(int display) {
|
342
518
|
if (display > 0 && display <= displayDevices.length) {
|
@@ -349,12 +525,14 @@ public class ShimAWT implements PConstants {
|
|
349
525
|
System.err.println("Display " + display + " does not exist, returning ");
|
350
526
|
return 1; // not the end of the world, so don't throw a RuntimeException
|
351
527
|
}
|
352
|
-
|
528
|
+
*/
|
529
|
+
|
530
|
+
|
353
531
|
static public void selectInput(String prompt, String callbackMethod,
|
354
|
-
|
532
|
+
File file, Object callbackObject) {
|
355
533
|
EventQueue.invokeLater(() -> {
|
356
534
|
selectImpl(prompt, callbackMethod, file,
|
357
|
-
|
535
|
+
callbackObject, null, FileDialog.LOAD);
|
358
536
|
});
|
359
537
|
}
|
360
538
|
|
@@ -371,12 +549,14 @@ public class ShimAWT implements PConstants {
|
|
371
549
|
PApplet sketch) {
|
372
550
|
selectImpl(prompt, callbackMethod, file, callbackObject, parent, FileDialog.SAVE, sketch);
|
373
551
|
}
|
374
|
-
|
552
|
+
*/
|
553
|
+
|
554
|
+
|
375
555
|
static public void selectOutput(String prompt, String callbackMethod,
|
376
|
-
|
556
|
+
File file, Object callbackObject) {
|
377
557
|
EventQueue.invokeLater(() -> {
|
378
558
|
selectImpl(prompt, callbackMethod, file,
|
379
|
-
|
559
|
+
callbackObject, null, FileDialog.SAVE);
|
380
560
|
});
|
381
561
|
}
|
382
562
|
|
@@ -405,13 +585,15 @@ public class ShimAWT implements PConstants {
|
|
405
585
|
}
|
406
586
|
});
|
407
587
|
}
|
408
|
-
|
588
|
+
*/
|
589
|
+
|
590
|
+
|
409
591
|
static public void selectImpl(final String prompt,
|
410
|
-
|
411
|
-
|
412
|
-
|
413
|
-
|
414
|
-
|
592
|
+
final String callbackMethod,
|
593
|
+
final File defaultSelection,
|
594
|
+
final Object callbackObject,
|
595
|
+
final Frame parentFrame,
|
596
|
+
final int mode) {
|
415
597
|
File selectedFile = null;
|
416
598
|
|
417
599
|
if (PApplet.useNativeSelect) {
|
@@ -448,13 +630,14 @@ public class ShimAWT implements PConstants {
|
|
448
630
|
PApplet.selectCallback(selectedFile, callbackMethod, callbackObject);
|
449
631
|
}
|
450
632
|
|
633
|
+
|
451
634
|
static public void selectFolder(final String prompt,
|
452
|
-
|
453
|
-
|
454
|
-
|
635
|
+
final String callbackMethod,
|
636
|
+
final File defaultSelection,
|
637
|
+
final Object callbackObject) {
|
455
638
|
EventQueue.invokeLater(() -> {
|
456
639
|
selectFolderImpl(prompt, callbackMethod, defaultSelection,
|
457
|
-
|
640
|
+
callbackObject, null);
|
458
641
|
});
|
459
642
|
}
|
460
643
|
|
@@ -482,49 +665,31 @@ public class ShimAWT implements PConstants {
|
|
482
665
|
callbackObject, parentFrame, sketch);
|
483
666
|
});
|
484
667
|
}
|
485
|
-
|
668
|
+
*/
|
669
|
+
|
670
|
+
|
486
671
|
static public void selectFolderImpl(final String prompt,
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
672
|
+
final String callbackMethod,
|
673
|
+
final File defaultSelection,
|
674
|
+
final Object callbackObject,
|
675
|
+
final Frame parentFrame) {
|
491
676
|
File selectedFile = null;
|
492
677
|
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
}
|
500
|
-
|
501
|
-
int result = fileChooser.showOpenDialog(parentFrame);
|
502
|
-
if (result == JFileChooser.APPROVE_OPTION) {
|
503
|
-
selectedFile = fileChooser.getSelectedFile();
|
504
|
-
}
|
678
|
+
JFileChooser fileChooser = new JFileChooser();
|
679
|
+
fileChooser.setDialogTitle(prompt);
|
680
|
+
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
681
|
+
if (defaultSelection != null) {
|
682
|
+
fileChooser.setCurrentDirectory(defaultSelection);
|
683
|
+
}
|
505
684
|
|
685
|
+
int result = fileChooser.showOpenDialog(parentFrame);
|
686
|
+
if (result == JFileChooser.APPROVE_OPTION) {
|
687
|
+
selectedFile = fileChooser.getSelectedFile();
|
688
|
+
}
|
689
|
+
|
506
690
|
PApplet.selectCallback(selectedFile, callbackMethod, callbackObject);
|
507
691
|
}
|
508
692
|
|
509
|
-
static private boolean lookAndFeelCheck;
|
510
|
-
|
511
|
-
/**
|
512
|
-
* Initialize the Look & Feel if it hasn't been already. Call this before
|
513
|
-
* using any Swing-related code in PApplet methods.
|
514
|
-
*/
|
515
|
-
static private void checkLookAndFeel() {
|
516
|
-
if (!lookAndFeelCheck) {
|
517
|
-
if (PApplet.platform == PConstants.WINDOWS) {
|
518
|
-
// Windows is defaulting to Metal or something else awful.
|
519
|
-
// Which also is not scaled properly with HiDPI interfaces.
|
520
|
-
try {
|
521
|
-
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
522
|
-
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException e) {
|
523
|
-
}
|
524
|
-
}
|
525
|
-
lookAndFeelCheck = true;
|
526
|
-
}
|
527
|
-
}
|
528
693
|
|
529
694
|
// TODO maybe call this with reflection from inside PApplet?
|
530
695
|
// longer term, develop a more general method for other platforms
|
@@ -532,6 +697,7 @@ public class ShimAWT implements PConstants {
|
|
532
697
|
return FileSystemView.getFileSystemView().getHomeDirectory();
|
533
698
|
}
|
534
699
|
|
700
|
+
|
535
701
|
static public boolean openLink(String url) {
|
536
702
|
try {
|
537
703
|
if (Desktop.isDesktopSupported()) {
|
@@ -542,4 +708,4 @@ public class ShimAWT implements PConstants {
|
|
542
708
|
}
|
543
709
|
return false;
|
544
710
|
}
|
545
|
-
}
|
711
|
+
}
|