propane 3.4.2-java → 3.5.0-java
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.mvn/wrapper/MavenWrapperDownloader.java +1 -1
- data/.travis.yml +1 -1
- data/CHANGELOG.md +5 -1
- data/Gemfile +2 -0
- data/README.md +15 -3
- data/Rakefile +9 -10
- data/bin/propane +3 -1
- data/lib/propane.rb +2 -1
- data/lib/propane/app.rb +2 -1
- data/lib/propane/creators/sketch_class.rb +7 -1
- data/lib/propane/creators/sketch_factory.rb +4 -2
- data/lib/propane/creators/sketch_writer.rb +1 -0
- data/lib/propane/helper_methods.rb +22 -22
- data/lib/propane/helpers/numeric.rb +2 -0
- data/lib/propane/helpers/version_error.rb +1 -0
- data/lib/propane/library.rb +5 -1
- data/lib/propane/library_loader.rb +2 -0
- data/lib/propane/native_folder.rb +10 -9
- data/lib/propane/native_loader.rb +3 -0
- data/lib/propane/runner.rb +11 -5
- data/lib/propane/version.rb +2 -1
- data/library/boids/boids.rb +21 -11
- data/library/color_group/color_group.rb +2 -0
- data/library/control_panel/control_panel.rb +8 -5
- data/library/dxf/dxf.rb +2 -0
- data/library/file_chooser/chooser.rb +10 -9
- data/library/file_chooser/file_chooser.rb +10 -9
- data/library/library_proxy/library_proxy.rb +2 -0
- data/library/net/net.rb +2 -0
- data/library/simplex_noise/simplex_noise.rb +2 -0
- data/library/slider/slider.rb +23 -22
- data/library/vector_utils/vector_utils.rb +4 -0
- data/library/video_event/video_event.rb +2 -0
- data/pom.rb +46 -45
- data/pom.xml +4 -4
- data/propane.gemspec +8 -7
- data/src/main/java/monkstone/ColorUtil.java +1 -3
- data/src/main/java/monkstone/MathToolModule.java +1 -1
- data/src/main/java/monkstone/PropaneLibrary.java +2 -2
- data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
- data/src/main/java/monkstone/filechooser/Chooser.java +1 -1
- data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
- data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
- data/src/main/java/monkstone/slider/SliderBar.java +1 -1
- data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
- data/src/main/java/monkstone/slider/WheelHandler.java +1 -1
- data/src/main/java/monkstone/vecmath/package-info.java +1 -1
- data/src/main/java/monkstone/vecmath/vec2/Vec2.java +1 -1
- data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -2
- data/src/main/java/monkstone/videoevent/CaptureEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/MovieEvent.java +1 -1
- data/src/main/java/monkstone/videoevent/package-info.java +1 -1
- data/src/main/java/processing/awt/PGraphicsJava2D.java +788 -283
- data/src/main/java/processing/awt/PImageAWT.java +260 -0
- data/src/main/java/processing/awt/PShapeJava2D.java +56 -53
- data/src/main/java/processing/awt/PSurfaceAWT.java +309 -211
- data/src/main/java/processing/awt/ShimAWT.java +580 -0
- data/src/main/java/processing/core/PApplet.java +2877 -2098
- data/src/main/java/processing/core/PConstants.java +477 -447
- data/src/main/java/processing/core/PFont.java +930 -884
- data/src/main/java/processing/core/PGraphics.java +337 -309
- data/src/main/java/processing/core/PImage.java +1689 -1689
- data/src/main/java/processing/core/PMatrix.java +172 -159
- data/src/main/java/processing/core/PMatrix2D.java +456 -410
- data/src/main/java/processing/core/PMatrix3D.java +755 -735
- data/src/main/java/processing/core/PShape.java +2910 -2656
- data/src/main/java/processing/core/PShapeOBJ.java +97 -94
- data/src/main/java/processing/core/PShapeSVG.java +1656 -1462
- data/src/main/java/processing/core/PStyle.java +40 -37
- data/src/main/java/processing/core/PSurface.java +134 -97
- data/src/main/java/processing/core/PSurfaceNone.java +292 -218
- data/src/main/java/processing/core/PVector.java +991 -966
- data/src/main/java/processing/core/ThinkDifferent.java +12 -8
- data/src/main/java/processing/data/DoubleDict.java +756 -710
- data/src/main/java/processing/data/DoubleList.java +749 -696
- data/src/main/java/processing/data/FloatDict.java +748 -702
- data/src/main/java/processing/data/FloatList.java +751 -697
- data/src/main/java/processing/data/IntDict.java +720 -673
- data/src/main/java/processing/data/IntList.java +699 -633
- data/src/main/java/processing/data/JSONArray.java +931 -873
- data/src/main/java/processing/data/JSONObject.java +1262 -1165
- data/src/main/java/processing/data/JSONTokener.java +351 -341
- data/src/main/java/processing/data/LongDict.java +710 -663
- data/src/main/java/processing/data/LongList.java +701 -635
- data/src/main/java/processing/data/Sort.java +37 -41
- data/src/main/java/processing/data/StringDict.java +525 -486
- data/src/main/java/processing/data/StringList.java +626 -580
- data/src/main/java/processing/data/Table.java +3693 -3513
- data/src/main/java/processing/data/TableRow.java +182 -183
- data/src/main/java/processing/data/XML.java +954 -880
- data/src/main/java/processing/event/Event.java +87 -67
- data/src/main/java/processing/event/KeyEvent.java +48 -41
- data/src/main/java/processing/event/MouseEvent.java +87 -113
- data/src/main/java/processing/event/TouchEvent.java +10 -6
- data/src/main/java/processing/javafx/PSurfaceFX.java +26 -0
- data/src/main/java/processing/net/Client.java +20 -20
- data/src/main/java/processing/net/Server.java +9 -9
- data/src/main/java/processing/opengl/FontTexture.java +286 -266
- data/src/main/java/processing/opengl/FrameBuffer.java +390 -376
- data/src/main/java/processing/opengl/LinePath.java +130 -91
- data/src/main/java/processing/opengl/LineStroker.java +593 -582
- data/src/main/java/processing/opengl/PGL.java +645 -579
- data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
- data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
- data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12287 -12030
- data/src/main/java/processing/opengl/PJOGL.java +1743 -1672
- data/src/main/java/processing/opengl/PShader.java +345 -416
- data/src/main/java/processing/opengl/PShapeOpenGL.java +4601 -4543
- data/src/main/java/processing/opengl/PSurfaceJOGL.java +1113 -1029
- data/src/main/java/processing/opengl/Texture.java +1489 -1401
- data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
- data/test/create_test.rb +21 -20
- data/test/deglut_spec_test.rb +4 -2
- data/test/helper_methods_test.rb +49 -20
- data/test/math_tool_test.rb +39 -32
- data/test/native_folder.rb +47 -0
- data/test/respond_to_test.rb +3 -2
- data/test/sketches/key_event.rb +2 -2
- data/test/sketches/library/my_library/my_library.rb +3 -0
- data/test/test_helper.rb +2 -0
- data/test/vecmath_spec_test.rb +35 -22
- data/vendors/Rakefile +28 -22
- metadata +13 -13
- data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
- data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
- data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -0,0 +1,580 @@
|
|
1
|
+
package processing.awt;
|
2
|
+
|
3
|
+
import java.awt.Desktop;
|
4
|
+
import java.awt.EventQueue;
|
5
|
+
import java.awt.FileDialog;
|
6
|
+
import java.awt.Frame;
|
7
|
+
import java.awt.HeadlessException;
|
8
|
+
import java.awt.Image;
|
9
|
+
import java.awt.Toolkit;
|
10
|
+
import java.awt.color.ColorSpace;
|
11
|
+
import java.awt.image.BufferedImage;
|
12
|
+
import java.io.File;
|
13
|
+
import java.io.IOException;
|
14
|
+
import java.io.InputStream;
|
15
|
+
import java.net.URI;
|
16
|
+
import java.net.URISyntaxException;
|
17
|
+
|
18
|
+
import java.awt.DisplayMode;
|
19
|
+
import java.awt.GraphicsConfiguration;
|
20
|
+
import java.awt.GraphicsDevice;
|
21
|
+
import java.awt.GraphicsEnvironment;
|
22
|
+
import java.awt.geom.AffineTransform;
|
23
|
+
|
24
|
+
import javax.imageio.ImageIO;
|
25
|
+
import javax.swing.ImageIcon;
|
26
|
+
import javax.swing.JFileChooser;
|
27
|
+
import javax.swing.UIManager;
|
28
|
+
import javax.swing.UnsupportedLookAndFeelException;
|
29
|
+
|
30
|
+
// used by desktopFile() method
|
31
|
+
import javax.swing.filechooser.FileSystemView;
|
32
|
+
|
33
|
+
import processing.core.PApplet;
|
34
|
+
import processing.core.PConstants;
|
35
|
+
import processing.core.PImage;
|
36
|
+
|
37
|
+
|
38
|
+
/**
|
39
|
+
* This class exists as an abstraction layer to remove AWT from PApplet.
|
40
|
+
* It is a staging area for AWT-specific code that's shared by the Java2D,
|
41
|
+
* JavaFX, and JOGL renderers. Once PSurfaceFX and PSurfaceJOGL have
|
42
|
+
* their own implementations, these methods will move to PSurfaceAWT.
|
43
|
+
*/
|
44
|
+
public class ShimAWT implements PConstants {
|
45
|
+
/*
|
46
|
+
PGraphics graphics;
|
47
|
+
PApplet sketch;
|
48
|
+
|
49
|
+
|
50
|
+
public ShimAWT(PApplet sketch) {
|
51
|
+
this.graphics = graphics;
|
52
|
+
this.sketch = sketch;
|
53
|
+
}
|
54
|
+
*/
|
55
|
+
static private ShimAWT instance;
|
56
|
+
|
57
|
+
private final GraphicsDevice[] displayDevices;
|
58
|
+
|
59
|
+
private final int displayWidth;
|
60
|
+
private final int displayHeight;
|
61
|
+
|
62
|
+
|
63
|
+
/** Only needed for display functions */
|
64
|
+
static private ShimAWT getInstance() {
|
65
|
+
if (instance == null) {
|
66
|
+
instance = new ShimAWT();
|
67
|
+
}
|
68
|
+
return instance;
|
69
|
+
}
|
70
|
+
|
71
|
+
|
72
|
+
private ShimAWT() {
|
73
|
+
// Need the list of display devices to be queried already for usage below.
|
74
|
+
// https://github.com/processing/processing/issues/3295
|
75
|
+
// https://github.com/processing/processing/issues/3296
|
76
|
+
// Not doing this from a static initializer because it may cause
|
77
|
+
// PApplet to cache and the values to stick through subsequent runs.
|
78
|
+
// Instead make it a runtime thing and a local variable.
|
79
|
+
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
|
80
|
+
GraphicsDevice device = ge.getDefaultScreenDevice();
|
81
|
+
displayDevices = ge.getScreenDevices();
|
82
|
+
|
83
|
+
// // Default or unparsed will be -1, spanning will be 0, actual displays will
|
84
|
+
// // be numbered from 1 because it's too weird to say "display 0" in prefs.
|
85
|
+
// if (display > 0 && display <= displayDevices.length) {
|
86
|
+
// device = displayDevices[display-1];
|
87
|
+
// }
|
88
|
+
// When this was called, display will always be unset (even in 3.x),
|
89
|
+
// since this happens before settings() is called.
|
90
|
+
|
91
|
+
// Set displayWidth and displayHeight for people still using those.
|
92
|
+
DisplayMode displayMode = device.getDisplayMode();
|
93
|
+
displayWidth = displayMode.getWidth();
|
94
|
+
displayHeight = displayMode.getHeight();
|
95
|
+
}
|
96
|
+
|
97
|
+
|
98
|
+
static public int getDisplayWidth() {
|
99
|
+
return getInstance().displayWidth;
|
100
|
+
}
|
101
|
+
|
102
|
+
|
103
|
+
static public int getDisplayHeight() {
|
104
|
+
return getInstance().displayHeight;
|
105
|
+
}
|
106
|
+
|
107
|
+
|
108
|
+
static public int getDisplayCount() {
|
109
|
+
return getInstance().displayDevices.length;
|
110
|
+
}
|
111
|
+
|
112
|
+
|
113
|
+
static public int getDisplayDensity(int num) {
|
114
|
+
return getInstance().displayDensityImpl(num);
|
115
|
+
}
|
116
|
+
|
117
|
+
|
118
|
+
/*
|
119
|
+
private int displayDensityImpl() {
|
120
|
+
if (display != SPAN && (fullScreen || present)) {
|
121
|
+
return displayDensity(display);
|
122
|
+
}
|
123
|
+
// walk through all displays, use 2 if any display is 2
|
124
|
+
for (int i = 0; i < displayDevices.length; i++) {
|
125
|
+
if (displayDensity(i+1) == 2) {
|
126
|
+
return 2;
|
127
|
+
}
|
128
|
+
}
|
129
|
+
// If nobody's density is 2 then everyone is 1
|
130
|
+
return 1;
|
131
|
+
}
|
132
|
+
*/
|
133
|
+
|
134
|
+
|
135
|
+
private int displayDensityImpl(int display) {
|
136
|
+
if (display > 0 && display <= displayDevices.length) {
|
137
|
+
GraphicsConfiguration graphicsConfig =
|
138
|
+
displayDevices[display - 1].getDefaultConfiguration();
|
139
|
+
AffineTransform tx = graphicsConfig.getDefaultTransform();
|
140
|
+
return (int) Math.round(tx.getScaleX());
|
141
|
+
}
|
142
|
+
|
143
|
+
System.err.println("Display " + display + " does not exist, " +
|
144
|
+
"returning 1 for displayDensity(" + display + ")");
|
145
|
+
return 1; // not the end of the world, so don't throw a RuntimeException
|
146
|
+
}
|
147
|
+
|
148
|
+
|
149
|
+
static public PImage loadImage(PApplet sketch, String filename, Object... args) {
|
150
|
+
String extension = null;
|
151
|
+
if (args != null && args.length > 0) {
|
152
|
+
// the only one that's supported for now
|
153
|
+
extension = (String) args[0];
|
154
|
+
}
|
155
|
+
|
156
|
+
if (extension == null) {
|
157
|
+
String lower = filename.toLowerCase();
|
158
|
+
int dot = filename.lastIndexOf('.');
|
159
|
+
if (dot == -1) {
|
160
|
+
extension = "unknown"; // no extension found
|
161
|
+
|
162
|
+
} else {
|
163
|
+
extension = lower.substring(dot + 1);
|
164
|
+
|
165
|
+
// check for, and strip any parameters on the url, i.e.
|
166
|
+
// filename.jpg?blah=blah&something=that
|
167
|
+
int question = extension.indexOf('?');
|
168
|
+
if (question != -1) {
|
169
|
+
extension = extension.substring(0, question);
|
170
|
+
}
|
171
|
+
}
|
172
|
+
}
|
173
|
+
|
174
|
+
// just in case. them users will try anything!
|
175
|
+
extension = extension.toLowerCase();
|
176
|
+
|
177
|
+
if (extension.equals("tga")) {
|
178
|
+
try {
|
179
|
+
InputStream input = sketch.createInput(filename);
|
180
|
+
if (input == null) return null;
|
181
|
+
|
182
|
+
PImage image = PImage.loadTGA(input);
|
183
|
+
image.parent = sketch;
|
184
|
+
return image;
|
185
|
+
|
186
|
+
} catch (IOException e) {
|
187
|
+
return null;
|
188
|
+
}
|
189
|
+
}
|
190
|
+
|
191
|
+
if (extension.equals("tif") || extension.equals("tiff")) {
|
192
|
+
InputStream input = sketch.createInput(filename);
|
193
|
+
PImage image = (input == null) ? null : PImage.loadTIFF(input);
|
194
|
+
return image;
|
195
|
+
}
|
196
|
+
|
197
|
+
// For jpeg, gif, and png, load them using createImage(),
|
198
|
+
// because the javax.imageio code was found to be much slower.
|
199
|
+
// http://dev.processing.org/bugs/show_bug.cgi?id=392
|
200
|
+
try {
|
201
|
+
if (extension.equals("jpg") || extension.equals("jpeg") ||
|
202
|
+
extension.equals("gif") || extension.equals("png") ||
|
203
|
+
extension.equals("unknown")) {
|
204
|
+
byte[] bytes = sketch.loadBytes(filename);
|
205
|
+
if (bytes == null) {
|
206
|
+
return null;
|
207
|
+
} else {
|
208
|
+
//Image awtImage = Toolkit.getDefaultToolkit().createImage(bytes);
|
209
|
+
Image awtImage = new ImageIcon(bytes).getImage();
|
210
|
+
|
211
|
+
if (awtImage instanceof BufferedImage) {
|
212
|
+
BufferedImage buffImage = (BufferedImage) awtImage;
|
213
|
+
int space = buffImage.getColorModel().getColorSpace().getType();
|
214
|
+
if (space == ColorSpace.TYPE_CMYK) {
|
215
|
+
System.err.println(filename + " is a CMYK image, " +
|
216
|
+
"only RGB images are supported.");
|
217
|
+
return null;
|
218
|
+
/*
|
219
|
+
// wishful thinking, appears to not be supported
|
220
|
+
// https://community.oracle.com/thread/1272045?start=0&tstart=0
|
221
|
+
BufferedImage destImage =
|
222
|
+
new BufferedImage(buffImage.getWidth(),
|
223
|
+
buffImage.getHeight(),
|
224
|
+
BufferedImage.TYPE_3BYTE_BGR);
|
225
|
+
ColorConvertOp op = new ColorConvertOp(null);
|
226
|
+
op.filter(buffImage, destImage);
|
227
|
+
image = new PImage(destImage);
|
228
|
+
*/
|
229
|
+
}
|
230
|
+
}
|
231
|
+
|
232
|
+
PImage image = new PImageAWT(awtImage);
|
233
|
+
if (image.width == -1) {
|
234
|
+
System.err.println("The file " + filename +
|
235
|
+
" contains bad image data, or may not be an image.");
|
236
|
+
}
|
237
|
+
|
238
|
+
// if it's a .gif image, test to see if it has transparency
|
239
|
+
if (extension.equals("gif") || extension.equals("png") ||
|
240
|
+
extension.equals("unknown")) {
|
241
|
+
image.checkAlpha();
|
242
|
+
}
|
243
|
+
|
244
|
+
image.parent = sketch;
|
245
|
+
return image;
|
246
|
+
}
|
247
|
+
}
|
248
|
+
} catch (Exception e) {
|
249
|
+
// show error, but move on to the stuff below, see if it'll work
|
250
|
+
|
251
|
+
}
|
252
|
+
|
253
|
+
if (loadImageFormats == null) {
|
254
|
+
loadImageFormats = ImageIO.getReaderFormatNames();
|
255
|
+
}
|
256
|
+
if (loadImageFormats != null) {
|
257
|
+
for (String loadImageFormat : loadImageFormats) {
|
258
|
+
if (extension.equals(loadImageFormat)) {
|
259
|
+
return loadImageIO(sketch, filename);
|
260
|
+
}
|
261
|
+
}
|
262
|
+
}
|
263
|
+
|
264
|
+
// failed, could not load image after all those attempts
|
265
|
+
System.err.println("Could not find a method to load " + filename);
|
266
|
+
return null;
|
267
|
+
}
|
268
|
+
|
269
|
+
static protected String[] loadImageFormats;
|
270
|
+
|
271
|
+
|
272
|
+
/**
|
273
|
+
* Use Java 1.4 ImageIO methods to load an image.
|
274
|
+
*/
|
275
|
+
static protected PImage loadImageIO(PApplet sketch, String filename) {
|
276
|
+
InputStream stream = sketch.createInput(filename);
|
277
|
+
if (stream == null) {
|
278
|
+
System.err.println("The image " + filename + " could not be found.");
|
279
|
+
return null;
|
280
|
+
}
|
281
|
+
|
282
|
+
try {
|
283
|
+
BufferedImage bi = ImageIO.read(stream);
|
284
|
+
//PImage outgoing = new PImage(bi.getWidth(), bi.getHeight());
|
285
|
+
PImage outgoing = new PImageAWT(bi);
|
286
|
+
outgoing.parent = sketch;
|
287
|
+
|
288
|
+
//bi.getRGB(0, 0, outgoing.width, outgoing.height,
|
289
|
+
// outgoing.pixels, 0, outgoing.width);
|
290
|
+
|
291
|
+
// check the alpha for this image
|
292
|
+
// was gonna call getType() on the image to see if RGB or ARGB,
|
293
|
+
// but it's not actually useful, since gif images will come through
|
294
|
+
// as TYPE_BYTE_INDEXED, which means it'll still have to check for
|
295
|
+
// the transparency. also, would have to iterate through all the other
|
296
|
+
// types and guess whether alpha was in there, so.. just gonna stick
|
297
|
+
// with the old method.
|
298
|
+
outgoing.checkAlpha();
|
299
|
+
|
300
|
+
stream.close();
|
301
|
+
// return the image
|
302
|
+
return outgoing;
|
303
|
+
|
304
|
+
} catch (IOException e) {
|
305
|
+
return null;
|
306
|
+
}
|
307
|
+
}
|
308
|
+
|
309
|
+
|
310
|
+
static public void initRun() {
|
311
|
+
// Supposed to help with flicker, but no effect on OS X.
|
312
|
+
// TODO IIRC this helped on Windows, but need to double check.
|
313
|
+
System.setProperty("sun.awt.noerasebackground", "true");
|
314
|
+
|
315
|
+
// Remove 60fps limit on the JavaFX "pulse" timer
|
316
|
+
System.setProperty("javafx.animation.fullspeed", "true");
|
317
|
+
|
318
|
+
// Catch any HeadlessException to provide more useful feedback
|
319
|
+
try {
|
320
|
+
// Call validate() while resize events are in progress
|
321
|
+
Toolkit.getDefaultToolkit().setDynamicLayout(true);
|
322
|
+
} catch (HeadlessException e) {
|
323
|
+
System.err.println("Cannot run sketch without a display. Read this for possible solutions:");
|
324
|
+
System.err.println("https://github.com/processing/processing/wiki/Running-without-a-Display");
|
325
|
+
System.exit(1);
|
326
|
+
}
|
327
|
+
}
|
328
|
+
|
329
|
+
|
330
|
+
/*
|
331
|
+
public int displayDensity() {
|
332
|
+
if (sketch.display != PConstants.SPAN && (sketch.fullScreen || sketch.present)) {
|
333
|
+
return displayDensity(sketch.display);
|
334
|
+
}
|
335
|
+
// walk through all displays, use 2 if any display is 2
|
336
|
+
for (int i = 0; i < displayDevices.length; i++) {
|
337
|
+
if (displayDensity(i+1) == 2) {
|
338
|
+
return 2;
|
339
|
+
}
|
340
|
+
}
|
341
|
+
// If nobody's density is 2 then everyone is 1
|
342
|
+
return 1;
|
343
|
+
}
|
344
|
+
*/
|
345
|
+
|
346
|
+
|
347
|
+
/**
|
348
|
+
* @param display the display number to check
|
349
|
+
* (1-indexed to match the Preferences dialog box)
|
350
|
+
*/
|
351
|
+
/*
|
352
|
+
public int displayDensity(int display) {
|
353
|
+
if (display > 0 && display <= displayDevices.length) {
|
354
|
+
GraphicsConfiguration graphicsConfig =
|
355
|
+
displayDevices[display - 1].getDefaultConfiguration();
|
356
|
+
AffineTransform tx = graphicsConfig.getDefaultTransform();
|
357
|
+
return (int) Math.round(tx.getScaleX());
|
358
|
+
}
|
359
|
+
|
360
|
+
System.err.println("Display " + display + " does not exist, returning ");
|
361
|
+
return 1; // not the end of the world, so don't throw a RuntimeException
|
362
|
+
}
|
363
|
+
*/
|
364
|
+
|
365
|
+
|
366
|
+
static public void selectInput(String prompt, String callbackMethod,
|
367
|
+
File file, Object callbackObject) {
|
368
|
+
EventQueue.invokeLater(() -> {
|
369
|
+
selectImpl(prompt, callbackMethod, file,
|
370
|
+
callbackObject, null, FileDialog.LOAD);
|
371
|
+
});
|
372
|
+
}
|
373
|
+
|
374
|
+
|
375
|
+
/*
|
376
|
+
static public void selectOutput(String prompt, String callbackMethod,
|
377
|
+
File file, Object callbackObject, Frame parent) {
|
378
|
+
selectImpl(prompt, callbackMethod, file, callbackObject, parent, FileDialog.SAVE, null);
|
379
|
+
}
|
380
|
+
|
381
|
+
|
382
|
+
static public void selectOutput(String prompt, String callbackMethod,
|
383
|
+
File file, Object callbackObject, Frame parent,
|
384
|
+
PApplet sketch) {
|
385
|
+
selectImpl(prompt, callbackMethod, file, callbackObject, parent, FileDialog.SAVE, sketch);
|
386
|
+
}
|
387
|
+
*/
|
388
|
+
|
389
|
+
|
390
|
+
static public void selectOutput(String prompt, String callbackMethod,
|
391
|
+
File file, Object callbackObject) {
|
392
|
+
EventQueue.invokeLater(() -> {
|
393
|
+
selectImpl(prompt, callbackMethod, file,
|
394
|
+
callbackObject, null, FileDialog.SAVE);
|
395
|
+
});
|
396
|
+
}
|
397
|
+
|
398
|
+
|
399
|
+
/*
|
400
|
+
// Will remove the 'sketch' parameter once we get an upstream JOGL fix
|
401
|
+
// https://github.com/processing/processing/issues/3831
|
402
|
+
static protected void selectEvent(final String prompt,
|
403
|
+
final String callbackMethod,
|
404
|
+
final File defaultSelection,
|
405
|
+
final Object callbackObject,
|
406
|
+
final Frame parentFrame,
|
407
|
+
final int mode,
|
408
|
+
final PApplet sketch) {
|
409
|
+
EventQueue.invokeLater(new Runnable() {
|
410
|
+
public void run() {
|
411
|
+
boolean hide = (sketch != null) &&
|
412
|
+
(sketch.g instanceof PGraphicsOpenGL) &&
|
413
|
+
(PApplet.platform == PConstants.WINDOWS);
|
414
|
+
if (hide) sketch.getSurface().setVisible(false);
|
415
|
+
|
416
|
+
selectImpl(prompt, callbackMethod, defaultSelection, callbackObject,
|
417
|
+
parentFrame, mode, sketch);
|
418
|
+
|
419
|
+
if (hide) sketch.getSurface().setVisible(true);
|
420
|
+
}
|
421
|
+
});
|
422
|
+
}
|
423
|
+
*/
|
424
|
+
|
425
|
+
|
426
|
+
static public void selectImpl(final String prompt,
|
427
|
+
final String callbackMethod,
|
428
|
+
final File defaultSelection,
|
429
|
+
final Object callbackObject,
|
430
|
+
final Frame parentFrame,
|
431
|
+
final int mode) {
|
432
|
+
File selectedFile = null;
|
433
|
+
|
434
|
+
if (PApplet.useNativeSelect) {
|
435
|
+
FileDialog dialog = new FileDialog(parentFrame, prompt, mode);
|
436
|
+
if (defaultSelection != null) {
|
437
|
+
dialog.setDirectory(defaultSelection.getParent());
|
438
|
+
dialog.setFile(defaultSelection.getName());
|
439
|
+
}
|
440
|
+
|
441
|
+
dialog.setVisible(true);
|
442
|
+
String directory = dialog.getDirectory();
|
443
|
+
String filename = dialog.getFile();
|
444
|
+
if (filename != null) {
|
445
|
+
selectedFile = new File(directory, filename);
|
446
|
+
}
|
447
|
+
|
448
|
+
} else {
|
449
|
+
JFileChooser chooser = new JFileChooser();
|
450
|
+
chooser.setDialogTitle(prompt);
|
451
|
+
if (defaultSelection != null) {
|
452
|
+
chooser.setSelectedFile(defaultSelection);
|
453
|
+
}
|
454
|
+
|
455
|
+
int result = -1;
|
456
|
+
if (mode == FileDialog.SAVE) {
|
457
|
+
result = chooser.showSaveDialog(parentFrame);
|
458
|
+
} else if (mode == FileDialog.LOAD) {
|
459
|
+
result = chooser.showOpenDialog(parentFrame);
|
460
|
+
}
|
461
|
+
if (result == JFileChooser.APPROVE_OPTION) {
|
462
|
+
selectedFile = chooser.getSelectedFile();
|
463
|
+
}
|
464
|
+
}
|
465
|
+
PApplet.selectCallback(selectedFile, callbackMethod, callbackObject);
|
466
|
+
}
|
467
|
+
|
468
|
+
|
469
|
+
static public void selectFolder(final String prompt,
|
470
|
+
final String callbackMethod,
|
471
|
+
final File defaultSelection,
|
472
|
+
final Object callbackObject) {
|
473
|
+
EventQueue.invokeLater(() -> {
|
474
|
+
selectFolderImpl(prompt, callbackMethod, defaultSelection,
|
475
|
+
callbackObject, null);
|
476
|
+
});
|
477
|
+
}
|
478
|
+
|
479
|
+
|
480
|
+
/*
|
481
|
+
static public void selectFolder(final String prompt,
|
482
|
+
final String callbackMethod,
|
483
|
+
final File defaultSelection,
|
484
|
+
final Object callbackObject,
|
485
|
+
final Frame parentFrame) {
|
486
|
+
selectFolderEvent(prompt, callbackMethod, defaultSelection, callbackObject, parentFrame, null);
|
487
|
+
}
|
488
|
+
|
489
|
+
|
490
|
+
// Will remove the 'sketch' parameter once we get an upstream JOGL fix
|
491
|
+
// https://github.com/processing/processing/issues/3831
|
492
|
+
static public void selectFolderEvent(final String prompt,
|
493
|
+
final String callbackMethod,
|
494
|
+
final File defaultSelection,
|
495
|
+
final Object callbackObject,
|
496
|
+
final Frame parentFrame,
|
497
|
+
final PApplet sketch) {
|
498
|
+
EventQueue.invokeLater(() -> {
|
499
|
+
selectFolderImpl(prompt, callbackMethod, defaultSelection,
|
500
|
+
callbackObject, parentFrame, sketch);
|
501
|
+
});
|
502
|
+
}
|
503
|
+
*/
|
504
|
+
|
505
|
+
|
506
|
+
static public void selectFolderImpl(final String prompt,
|
507
|
+
final String callbackMethod,
|
508
|
+
final File defaultSelection,
|
509
|
+
final Object callbackObject,
|
510
|
+
final Frame parentFrame) {
|
511
|
+
File selectedFile = null;
|
512
|
+
if (PApplet.platform == PConstants.MACOS && PApplet.useNativeSelect) {
|
513
|
+
FileDialog fileDialog =
|
514
|
+
new FileDialog(parentFrame, prompt, FileDialog.LOAD);
|
515
|
+
if (defaultSelection != null) {
|
516
|
+
fileDialog.setDirectory(defaultSelection.getAbsolutePath());
|
517
|
+
}
|
518
|
+
System.setProperty("apple.awt.fileDialogForDirectories", "true");
|
519
|
+
fileDialog.setVisible(true);
|
520
|
+
System.setProperty("apple.awt.fileDialogForDirectories", "false");
|
521
|
+
String filename = fileDialog.getFile();
|
522
|
+
if (filename != null) {
|
523
|
+
selectedFile = new File(fileDialog.getDirectory(), fileDialog.getFile());
|
524
|
+
}
|
525
|
+
} else {
|
526
|
+
checkLookAndFeel();
|
527
|
+
JFileChooser fileChooser = new JFileChooser();
|
528
|
+
fileChooser.setDialogTitle(prompt);
|
529
|
+
fileChooser.setFileSelectionMode(JFileChooser.DIRECTORIES_ONLY);
|
530
|
+
if (defaultSelection != null) {
|
531
|
+
fileChooser.setCurrentDirectory(defaultSelection);
|
532
|
+
}
|
533
|
+
|
534
|
+
int result = fileChooser.showOpenDialog(parentFrame);
|
535
|
+
if (result == JFileChooser.APPROVE_OPTION) {
|
536
|
+
selectedFile = fileChooser.getSelectedFile();
|
537
|
+
}
|
538
|
+
}
|
539
|
+
PApplet.selectCallback(selectedFile, callbackMethod, callbackObject);
|
540
|
+
}
|
541
|
+
|
542
|
+
|
543
|
+
static private boolean lookAndFeelCheck;
|
544
|
+
|
545
|
+
/**
|
546
|
+
* Initialize the Look & Feel if it hasn't been already.
|
547
|
+
* Call this before using any Swing-related code in PApplet methods.
|
548
|
+
*/
|
549
|
+
static private void checkLookAndFeel() {
|
550
|
+
if (!lookAndFeelCheck) {
|
551
|
+
if (PApplet.platform == PConstants.WINDOWS) {
|
552
|
+
// Windows is defaulting to Metal or something else awful.
|
553
|
+
// Which also is not scaled properly with HiDPI interfaces.
|
554
|
+
try {
|
555
|
+
UIManager.setLookAndFeel(UIManager.getSystemLookAndFeelClassName());
|
556
|
+
} catch (ClassNotFoundException | IllegalAccessException | InstantiationException | UnsupportedLookAndFeelException e) { }
|
557
|
+
}
|
558
|
+
lookAndFeelCheck = true;
|
559
|
+
}
|
560
|
+
}
|
561
|
+
|
562
|
+
|
563
|
+
// TODO maybe call this with reflection from inside PApplet?
|
564
|
+
// longer term, develop a more general method for other platforms
|
565
|
+
static public File getWindowsDesktop() {
|
566
|
+
return FileSystemView.getFileSystemView().getHomeDirectory();
|
567
|
+
}
|
568
|
+
|
569
|
+
|
570
|
+
static public boolean openLink(String url) {
|
571
|
+
try {
|
572
|
+
if (Desktop.isDesktopSupported()) {
|
573
|
+
Desktop.getDesktop().browse(new URI(url));
|
574
|
+
return true;
|
575
|
+
}
|
576
|
+
} catch (IOException | URISyntaxException e) {
|
577
|
+
}
|
578
|
+
return false;
|
579
|
+
}
|
580
|
+
}
|