propane 3.3.1-java → 3.6.0-java

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (157) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +1 -2
  3. data/.mvn/wrapper/MavenWrapperDownloader.java +117 -0
  4. data/.mvn/wrapper/maven-wrapper.properties +2 -3
  5. data/.travis.yml +9 -0
  6. data/CHANGELOG.md +17 -5
  7. data/Gemfile +2 -0
  8. data/README.md +17 -8
  9. data/Rakefile +16 -30
  10. data/bin/propane +3 -1
  11. data/lib/propane.rb +6 -4
  12. data/lib/propane/app.rb +20 -10
  13. data/lib/propane/creators/sketch_class.rb +7 -1
  14. data/lib/propane/creators/sketch_factory.rb +4 -2
  15. data/lib/propane/creators/sketch_writer.rb +1 -0
  16. data/lib/propane/helper_methods.rb +23 -24
  17. data/lib/propane/helpers/numeric.rb +2 -0
  18. data/lib/propane/helpers/version_error.rb +1 -0
  19. data/lib/propane/library.rb +5 -1
  20. data/lib/propane/library_loader.rb +2 -0
  21. data/lib/propane/native_folder.rb +21 -15
  22. data/lib/propane/native_loader.rb +3 -0
  23. data/lib/propane/runner.rb +14 -6
  24. data/lib/propane/version.rb +2 -1
  25. data/library/boids/boids.rb +21 -11
  26. data/library/color_group/color_group.rb +28 -0
  27. data/library/control_panel/control_panel.rb +8 -5
  28. data/library/dxf/dxf.rb +6 -0
  29. data/library/file_chooser/chooser.rb +10 -9
  30. data/library/file_chooser/file_chooser.rb +10 -9
  31. data/library/library_proxy/library_proxy.rb +2 -0
  32. data/library/net/net.rb +7 -0
  33. data/library/simplex_noise/simplex_noise.rb +2 -0
  34. data/library/slider/slider.rb +23 -22
  35. data/library/vector_utils/vector_utils.rb +4 -0
  36. data/library/video_event/video_event.rb +4 -1
  37. data/mvnw +127 -51
  38. data/mvnw.cmd +182 -145
  39. data/pom.rb +53 -50
  40. data/pom.xml +17 -8
  41. data/propane.gemspec +13 -11
  42. data/src/main/java/monkstone/ColorUtil.java +13 -1
  43. data/src/main/java/monkstone/MathToolModule.java +253 -203
  44. data/src/main/java/monkstone/PropaneLibrary.java +2 -2
  45. data/src/main/java/monkstone/fastmath/Deglut.java +1 -1
  46. data/src/main/java/monkstone/filechooser/Chooser.java +2 -1
  47. data/src/main/java/monkstone/noise/SimplexNoise.java +2 -2
  48. data/src/main/java/monkstone/slider/CustomHorizontalSlider.java +1 -1
  49. data/src/main/java/monkstone/slider/CustomVerticalSlider.java +1 -1
  50. data/src/main/java/monkstone/slider/SimpleHorizontalSlider.java +1 -1
  51. data/src/main/java/monkstone/slider/SimpleVerticalSlider.java +1 -1
  52. data/src/main/java/monkstone/slider/SliderBar.java +1 -1
  53. data/src/main/java/monkstone/slider/SliderGroup.java +1 -1
  54. data/src/main/java/monkstone/slider/WheelHandler.java +7 -6
  55. data/src/main/java/monkstone/vecmath/package-info.java +1 -1
  56. data/src/main/java/monkstone/vecmath/vec2/Vec2.java +2 -2
  57. data/src/main/java/monkstone/vecmath/vec3/Vec3.java +1 -1
  58. data/src/main/java/monkstone/videoevent/CaptureEvent.java +27 -0
  59. data/src/main/java/monkstone/videoevent/{VideoInterface.java → MovieEvent.java} +11 -27
  60. data/src/main/java/monkstone/videoevent/package-info.java +1 -1
  61. data/src/main/java/processing/awt/PGraphicsJava2D.java +2164 -1661
  62. data/src/main/java/processing/awt/PImageAWT.java +377 -0
  63. data/src/main/java/processing/awt/PShapeJava2D.java +280 -268
  64. data/src/main/java/processing/awt/PSurfaceAWT.java +942 -829
  65. data/src/main/java/processing/awt/ShimAWT.java +581 -0
  66. data/src/main/java/processing/core/PApplet.java +831 -824
  67. data/src/main/java/processing/core/PConstants.java +477 -447
  68. data/src/main/java/processing/core/PFont.java +914 -880
  69. data/src/main/java/processing/core/PGraphics.java +229 -213
  70. data/src/main/java/processing/core/PImage.java +620 -318
  71. data/src/main/java/processing/core/PMatrix.java +172 -159
  72. data/src/main/java/processing/core/PMatrix2D.java +478 -409
  73. data/src/main/java/processing/core/PMatrix3D.java +762 -735
  74. data/src/main/java/processing/core/PShape.java +2888 -2652
  75. data/src/main/java/processing/core/PShapeOBJ.java +436 -415
  76. data/src/main/java/processing/core/PShapeSVG.java +1702 -1479
  77. data/src/main/java/processing/core/PStyle.java +40 -37
  78. data/src/main/java/processing/core/PSurface.java +139 -97
  79. data/src/main/java/processing/core/PSurfaceNone.java +296 -208
  80. data/src/main/java/processing/core/PVector.java +997 -965
  81. data/src/main/java/processing/core/ThinkDifferent.java +12 -17
  82. data/src/main/java/processing/data/DoubleDict.java +756 -710
  83. data/src/main/java/processing/data/DoubleList.java +749 -696
  84. data/src/main/java/processing/data/FloatDict.java +748 -702
  85. data/src/main/java/processing/data/FloatList.java +751 -697
  86. data/src/main/java/processing/data/IntDict.java +720 -673
  87. data/src/main/java/processing/data/IntList.java +699 -633
  88. data/src/main/java/processing/data/JSONArray.java +931 -873
  89. data/src/main/java/processing/data/JSONObject.java +1262 -1165
  90. data/src/main/java/processing/data/JSONTokener.java +351 -341
  91. data/src/main/java/processing/data/LongDict.java +710 -663
  92. data/src/main/java/processing/data/LongList.java +701 -635
  93. data/src/main/java/processing/data/Sort.java +37 -41
  94. data/src/main/java/processing/data/StringDict.java +525 -486
  95. data/src/main/java/processing/data/StringList.java +626 -580
  96. data/src/main/java/processing/data/Table.java +3690 -3510
  97. data/src/main/java/processing/data/TableRow.java +182 -183
  98. data/src/main/java/processing/data/XML.java +957 -883
  99. data/src/main/java/processing/dxf/RawDXF.java +404 -0
  100. data/src/main/java/processing/event/Event.java +87 -66
  101. data/src/main/java/processing/event/KeyEvent.java +48 -41
  102. data/src/main/java/processing/event/MouseEvent.java +88 -113
  103. data/src/main/java/processing/event/TouchEvent.java +10 -6
  104. data/src/main/java/processing/javafx/PGraphicsFX2D.java +20 -345
  105. data/src/main/java/processing/javafx/PSurfaceFX.java +149 -121
  106. data/src/main/java/processing/net/Client.java +744 -0
  107. data/src/main/java/processing/net/Server.java +388 -0
  108. data/src/main/java/processing/opengl/FontTexture.java +289 -270
  109. data/src/main/java/processing/opengl/FrameBuffer.java +386 -364
  110. data/src/main/java/processing/opengl/LinePath.java +547 -500
  111. data/src/main/java/processing/opengl/LineStroker.java +588 -581
  112. data/src/main/java/processing/opengl/PGL.java +3047 -2914
  113. data/src/main/java/processing/opengl/PGraphics2D.java +408 -315
  114. data/src/main/java/processing/opengl/PGraphics3D.java +107 -72
  115. data/src/main/java/processing/opengl/PGraphicsOpenGL.java +12378 -12075
  116. data/src/main/java/processing/opengl/PJOGL.java +1753 -1670
  117. data/src/main/java/processing/opengl/PShader.java +1266 -1257
  118. data/src/main/java/processing/opengl/PShapeOpenGL.java +4678 -4580
  119. data/src/main/java/processing/opengl/PSurfaceJOGL.java +1114 -1027
  120. data/src/main/java/processing/opengl/Texture.java +1492 -1401
  121. data/src/main/java/processing/opengl/VertexBuffer.java +57 -55
  122. data/test/create_test.rb +21 -20
  123. data/test/deglut_spec_test.rb +4 -2
  124. data/test/helper_methods_test.rb +49 -20
  125. data/test/math_tool_test.rb +39 -32
  126. data/test/native_folder.rb +47 -0
  127. data/test/respond_to_test.rb +3 -2
  128. data/test/sketches/key_event.rb +2 -2
  129. data/test/sketches/library/my_library/my_library.rb +3 -0
  130. data/test/test_helper.rb +2 -0
  131. data/test/vecmath_spec_test.rb +35 -22
  132. data/vendors/Rakefile +33 -62
  133. metadata +54 -45
  134. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +0 -161
  135. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +0 -169
  136. data/src/main/java/processing/core/util/image/constants/TifConstants.java +0 -45
  137. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +0 -80
  138. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +0 -73
  139. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +0 -70
  140. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +0 -132
  141. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +0 -48
  142. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +0 -45
  143. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +0 -255
  144. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +0 -98
  145. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +0 -49
  146. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +0 -48
  147. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +0 -179
  148. data/src/main/java/processing/core/util/image/save/SaveImageException.java +0 -41
  149. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +0 -198
  150. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +0 -91
  151. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +0 -57
  152. data/src/main/java/processing/core/util/io/InputFactory.java +0 -285
  153. data/src/main/java/processing/core/util/io/PathUtil.java +0 -109
  154. data/src/main/java/processing/opengl/shaders/LightVert-brcm.glsl +0 -154
  155. data/src/main/java/processing/opengl/shaders/LightVert-vc4.glsl +0 -154
  156. data/src/main/java/processing/opengl/shaders/TexLightVert-brcm.glsl +0 -160
  157. data/src/main/java/processing/opengl/shaders/TexLightVert-vc4.glsl +0 -160
@@ -1,91 +0,0 @@
1
- /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
-
3
- /*
4
- Part of the Processing project - http://processing.org
5
-
6
- Copyright (c) 2012-18 The Processing Foundation
7
- Copyright (c) 2004-12 Ben Fry and Casey Reas
8
- Copyright (c) 2001-04 Massachusetts Institute of Technology
9
-
10
- This library is free software; you can redistribute it and/or
11
- modify it under the terms of the GNU Lesser General Public
12
- License as published by the Free Software Foundation, version 2.1.
13
-
14
- This library is distributed in the hope that it will be useful,
15
- but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
- Lesser General Public License for more details.
18
-
19
- You should have received a copy of the GNU Lesser General
20
- Public License along with this library; if not, write to the
21
- Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22
- Boston, MA 02111-1307 USA
23
- */
24
-
25
- package processing.core.util.image.save;
26
-
27
- import processing.core.util.image.constants.TifConstants;
28
-
29
- import java.io.FileNotFoundException;
30
- import java.io.IOException;
31
- import java.io.OutputStream;
32
-
33
-
34
- /**
35
- * Strategy for saving tiff images.
36
- */
37
- public class TiffImageSaveStrategy implements ImageSaveStrategy {
38
-
39
- @Override
40
- public boolean save(int[] pixels, int pixelWidth, int pixelHeight, int format,
41
- String filename) throws FileNotFoundException {
42
-
43
- OutputStream output = ImageSaveUtil.createForFile(filename);
44
-
45
- // shutting off the warning, people can figure this out themselves
46
- /*
47
- if (format != RGB) {
48
- System.err.println("Warning: only RGB information is saved with " +
49
- ".tif files. Use .tga or .png for ARGB images and others.");
50
- }
51
- */
52
- try {
53
- byte tiff[] = new byte[768];
54
- System.arraycopy(
55
- TifConstants.TIFF_HEADER,
56
- 0,
57
- tiff,
58
- 0,
59
- TifConstants.TIFF_HEADER.length
60
- );
61
-
62
- tiff[30] = (byte) ((pixelWidth >> 8) & 0xff);
63
- tiff[31] = (byte) ((pixelWidth) & 0xff);
64
- tiff[42] = tiff[102] = (byte) ((pixelHeight >> 8) & 0xff);
65
- tiff[43] = tiff[103] = (byte) ((pixelHeight) & 0xff);
66
-
67
- int count = pixelWidth*pixelHeight*3;
68
- tiff[114] = (byte) ((count >> 24) & 0xff);
69
- tiff[115] = (byte) ((count >> 16) & 0xff);
70
- tiff[116] = (byte) ((count >> 8) & 0xff);
71
- tiff[117] = (byte) ((count) & 0xff);
72
-
73
- // spew the header to the disk
74
- output.write(tiff);
75
-
76
- for (int i = 0; i < pixels.length; i++) {
77
- output.write((pixels[i] >> 16) & 0xff);
78
- output.write((pixels[i] >> 8) & 0xff);
79
- output.write(pixels[i] & 0xff);
80
- }
81
- output.flush();
82
- output.close();
83
- return true;
84
-
85
- } catch (IOException e) {
86
- e.printStackTrace();
87
- }
88
- return false;
89
- }
90
-
91
- }
@@ -1,57 +0,0 @@
1
- /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
-
3
- /*
4
- Part of the Processing project - http://processing.org
5
-
6
- Copyright (c) 2012-18 The Processing Foundation
7
- Copyright (c) 2004-12 Ben Fry and Casey Reas
8
- Copyright (c) 2001-04 Massachusetts Institute of Technology
9
-
10
- This library is free software; you can redistribute it and/or
11
- modify it under the terms of the GNU Lesser General Public
12
- License as published by the Free Software Foundation, version 2.1.
13
-
14
- This library is distributed in the hope that it will be useful,
15
- but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
- Lesser General Public License for more details.
18
-
19
- You should have received a copy of the GNU Lesser General
20
- Public License along with this library; if not, write to the
21
- Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22
- Boston, MA 02111-1307 USA
23
- */
24
-
25
- package processing.core.util.image.save;
26
-
27
- import java.io.IOException;
28
-
29
-
30
- /**
31
- * Strategy for saving a Tiff and appending ".tif" to the filename.
32
- */
33
- public class TiffNakedFilenameImageSaveStrategy implements ImageSaveStrategy {
34
-
35
- private final ImageSaveStrategy tiffImageSaveStrategy;
36
-
37
- /**
38
- * Create a new Tiff save strategy where ".tif" is appended to the filename.
39
- */
40
- public TiffNakedFilenameImageSaveStrategy() {
41
- tiffImageSaveStrategy = new TiffImageSaveStrategy();
42
- }
43
-
44
- @Override
45
- public boolean save(int[] pixels, int pixelWidth, int pixelHeight, int format,
46
- String filename) throws IOException {
47
-
48
- filename += ".tif";
49
- return tiffImageSaveStrategy.save(
50
- pixels,
51
- pixelWidth,
52
- pixelHeight,
53
- format,
54
- filename
55
- );
56
- }
57
- }
@@ -1,285 +0,0 @@
1
- /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
-
3
- /*
4
- Part of the Processing project - http://processing.org
5
-
6
- Copyright (c) 2012-18 The Processing Foundation
7
- Copyright (c) 2004-12 Ben Fry and Casey Reas
8
- Copyright (c) 2001-04 Massachusetts Institute of Technology
9
-
10
- This library is free software; you can redistribute it and/or
11
- modify it under the terms of the GNU Lesser General Public
12
- License as published by the Free Software Foundation, version 2.1.
13
-
14
- This library is distributed in the hope that it will be useful,
15
- but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
- Lesser General Public License for more details.
18
-
19
- You should have received a copy of the GNU Lesser General
20
- Public License along with this library; if not, write to the
21
- Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22
- Boston, MA 02111-1307 USA
23
- */
24
-
25
- package processing.core.util.io;
26
-
27
- import processing.core.PApplet;
28
-
29
- import java.io.*;
30
- import java.net.*;
31
- import java.util.zip.GZIPInputStream;
32
-
33
-
34
- /**
35
- * Factory producing InputStreams under various parameter sets.
36
- */
37
- public class InputFactory {
38
-
39
- /**
40
- * Create a new input stream from a file.
41
- *
42
- * @param file The file for which an input stream should be created.
43
- * @return InputStream for the input file.
44
- */
45
- public static InputStream createInput(File file) {
46
- if (file == null) {
47
- throw new IllegalArgumentException("File passed to createInput() was null");
48
- }
49
- if (!file.exists()) {
50
- System.err.println(file + " does not exist, createInput() will return null");
51
- return null;
52
- }
53
- try {
54
- InputStream input = new FileInputStream(file);
55
- final String lower = file.getName().toLowerCase();
56
- if (lower.endsWith(".gz") || lower.endsWith(".svgz")) {
57
- return new BufferedInputStream(new GZIPInputStream(input));
58
- }
59
- return new BufferedInputStream(input);
60
-
61
- } catch (IOException e) {
62
- System.err.println("Could not createInput() for " + file);
63
- e.printStackTrace();
64
- return null;
65
- }
66
- }
67
-
68
- /**
69
- * Create an InputStream using path information from a PApplet.
70
- *
71
- * <p>
72
- * Create an InputStream using path information from a PApplet with some pre-processing of file
73
- * contents like unzipping a gzip compressed file. This is in contrast to createInputRaw which
74
- * will not perform any pre-processing.
75
- * </p>
76
- *
77
- * @param pApplet The PApplet whose sketch path informatino should be used.
78
- * @param filename THe filename (url, absolute path, or relative path) to open.
79
- * @return InputStream for the given filename or null if no input path could be created.
80
- */
81
- public static InputStream createInput(PApplet pApplet, String filename) {
82
- InputStream input = createInputRaw(pApplet, filename);
83
- if (input != null) {
84
- // if it's gzip-encoded, automatically decode
85
- if (isGzipCompressed(filename)) {
86
- try {
87
- // buffered has to go *around* the GZ, otherwise 25x slower
88
- return new BufferedInputStream(new GZIPInputStream(input));
89
-
90
- } catch (IOException e) {
91
- e.printStackTrace();
92
- }
93
- } else {
94
- return new BufferedInputStream(input);
95
- }
96
- }
97
- return null;
98
- }
99
-
100
- /**
101
- * Create an InputStream without any pre-processing of file content before it is returned.
102
- *
103
- * <p>
104
- * Create an InputStream using path information from a PApplet without any pre-processing of file
105
- * contents like unzipping a gzip compressed file. This is in contrast to createInput which will
106
- * perform some pre-processing.
107
- * </p>
108
- *
109
- * @param pApplet The PApplet whose sketch path information should be used.
110
- * @param filename THe filename (url, absolute path, or relative path) to open.
111
- * @return InputStream for the given filename or null if no input path could be created.
112
- */
113
- public static InputStream createInputRaw(PApplet pApplet, String filename) {
114
- if (filename == null) return null;
115
-
116
- String sketchPath = pApplet.sketchPath();
117
-
118
- if (sketchPath == null) {
119
- System.err.println("The sketch path is not set.");
120
- throw new RuntimeException("Files must be loaded inside setup() or after it has been called.");
121
- }
122
-
123
- if (filename.length() == 0) {
124
- // an error will be called by the parent function
125
- //System.err.println("The filename passed to openStream() was empty.");
126
- return null;
127
- }
128
-
129
- // First check whether this looks like a URL
130
- if (filename.contains(":")) { // at least smells like URL
131
- try {
132
- URL url = new URL(filename);
133
- URLConnection conn = url.openConnection();
134
-
135
- if (conn instanceof HttpURLConnection) {
136
- HttpURLConnection httpConn = (HttpURLConnection) conn;
137
- // Will not handle a protocol change (see below)
138
- httpConn.setInstanceFollowRedirects(true);
139
- int response = httpConn.getResponseCode();
140
- // Default won't follow HTTP -> HTTPS redirects for security reasons
141
- // http://stackoverflow.com/a/1884427
142
- if (response >= 300 && response < 400) {
143
- String newLocation = httpConn.getHeaderField("Location");
144
- return createInputRaw(pApplet, newLocation);
145
- }
146
- return conn.getInputStream();
147
- } else if (conn instanceof JarURLConnection) {
148
- return url.openStream();
149
- }
150
- } catch (MalformedURLException mfue) {
151
- // not a url, that's fine
152
-
153
- } catch (FileNotFoundException fnfe) {
154
- // Added in 0119 b/c Java 1.5 throws FNFE when URL not available.
155
- // http://dev.processing.org/bugs/show_bug.cgi?id=403
156
-
157
- } catch (IOException e) {
158
- // changed for 0117, shouldn't be throwing exception
159
- e.printStackTrace();
160
- //System.err.println("Error downloading from URL " + filename);
161
- return null;
162
- //throw new RuntimeException("Error downloading from URL " + filename);
163
- }
164
- }
165
-
166
- InputStream stream = null;
167
-
168
- // Moved this earlier than the getResourceAsStream() checks, because
169
- // calling getResourceAsStream() on a directory lists its contents.
170
- // http://dev.processing.org/bugs/show_bug.cgi?id=716
171
- try {
172
- // First see if it's in a data folder. This may fail by throwing
173
- // a SecurityException. If so, this whole block will be skipped.
174
- File file = new File(pApplet.dataPath(filename));
175
-
176
- if (!file.exists()) {
177
- // next see if it's just in the sketch folder
178
- file = pApplet.sketchFile(filename);
179
- }
180
-
181
- if (file.isDirectory()) {
182
- return null;
183
- }
184
- if (file.exists()) {
185
- try {
186
- // handle case sensitivity check
187
- String filePath = file.getCanonicalPath();
188
- String filenameActual = new File(filePath).getName();
189
- // make sure there isn't a subfolder prepended to the name
190
- String filenameShort = new File(filename).getName();
191
- // if the actual filename is the same, but capitalized
192
- // differently, warn the user.
193
- //if (filenameActual.equalsIgnoreCase(filenameShort) &&
194
- //!filenameActual.equals(filenameShort)) {
195
- if (!filenameActual.equals(filenameShort)) {
196
- throw new RuntimeException("This file is named " +
197
- filenameActual + " not " +
198
- filename + ". Rename the file " +
199
- "or change your code.");
200
- }
201
- } catch (IOException e) { }
202
- }
203
-
204
- // if this file is ok, may as well just load it
205
- stream = new FileInputStream(file);
206
- if (stream != null) {
207
- return stream;
208
- }
209
-
210
- // have to break these out because a general Exception might
211
- // catch the RuntimeException being thrown above
212
- } catch (IOException ioe) {
213
- } catch (SecurityException se) { }
214
-
215
- // Using getClassLoader() prevents java from converting dots
216
- // to slashes or requiring a slash at the beginning.
217
- // (a slash as a prefix means that it'll load from the root of
218
- // the jar, rather than trying to dig into the package location)
219
- ClassLoader cl = pApplet.getClass().getClassLoader();
220
-
221
- // by default, data files are exported to the root path of the jar.
222
- // (not the data folder) so check there first.
223
- stream = cl.getResourceAsStream("data/" + filename);
224
- if (stream != null) {
225
- String cn = stream.getClass().getName();
226
- // this is an irritation of sun's java plug-in, which will return
227
- // a non-null stream for an object that doesn't exist. like all good
228
- // things, this is probably introduced in java 1.5. awesome!
229
- // http://dev.processing.org/bugs/show_bug.cgi?id=359
230
- if (!cn.equals("sun.plugin.cache.EmptyInputStream")) {
231
- return stream;
232
- }
233
- }
234
-
235
- // When used with an online script, also need to check without the
236
- // data folder, in case it's not in a subfolder called 'data'.
237
- // http://dev.processing.org/bugs/show_bug.cgi?id=389
238
- stream = cl.getResourceAsStream(filename);
239
- if (stream != null) {
240
- String cn = stream.getClass().getName();
241
- if (!cn.equals("sun.plugin.cache.EmptyInputStream")) {
242
- return stream;
243
- }
244
- }
245
-
246
- try {
247
- // attempt to load from a local file, used when running as
248
- // an application, or as a signed applet
249
- try { // first try to catch any security exceptions
250
- try {
251
- stream = new FileInputStream(pApplet.dataPath(filename));
252
- if (stream != null) return stream;
253
- } catch (IOException e2) { }
254
-
255
- try {
256
- stream = new FileInputStream(pApplet.sketchPath(filename));
257
- if (stream != null) return stream;
258
- } catch (Exception e) { } // ignored
259
-
260
- try {
261
- stream = new FileInputStream(filename);
262
- if (stream != null) return stream;
263
- } catch (IOException e1) { }
264
-
265
- } catch (SecurityException se) { } // online, whups
266
-
267
- } catch (Exception e) {
268
- e.printStackTrace();
269
- }
270
-
271
- return null;
272
- }
273
-
274
- /**
275
- * Determine if a file is gzip compressed.
276
- *
277
- * @param filename The name of the fiel to check.
278
- * @return True if the file is a gzip compressed file and false otherwise.
279
- */
280
- private static boolean isGzipCompressed(String filename) {
281
- String extension = PathUtil.parseExtension(filename);
282
- return extension.equalsIgnoreCase("gz") || extension.equalsIgnoreCase("svgz");
283
- }
284
-
285
- }
@@ -1,109 +0,0 @@
1
- /* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
2
-
3
- /*
4
- Part of the Processing project - http://processing.org
5
-
6
- Copyright (c) 2012-18 The Processing Foundation
7
- Copyright (c) 2004-12 Ben Fry and Casey Reas
8
- Copyright (c) 2001-04 Massachusetts Institute of Technology
9
-
10
- This library is free software; you can redistribute it and/or
11
- modify it under the terms of the GNU Lesser General Public
12
- License as published by the Free Software Foundation, version 2.1.
13
-
14
- This library is distributed in the hope that it will be useful,
15
- but WITHOUT ANY WARRANTY; without even the implied warranty of
16
- MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
17
- Lesser General Public License for more details.
18
-
19
- You should have received a copy of the GNU Lesser General
20
- Public License along with this library; if not, write to the
21
- Free Software Foundation, Inc., 59 Temple Place, Suite 330,
22
- Boston, MA 02111-1307 USA
23
- */
24
-
25
- package processing.core.util.io;
26
-
27
- import java.io.File;
28
-
29
-
30
- /**
31
- * Convenience functions for managing file paths.
32
- */
33
- public class PathUtil {
34
- private static final String UNKNOWN_FILE_EXTENSION = "unknown";
35
-
36
- /**
37
- * Determine the extension of a file given in a path.
38
- *
39
- * @param path The path like directory/subdirectory/image.png.
40
- * @return The extension of the file at path like "png" or "unknown" if could not be determined.
41
- */
42
- public static String parseExtension(String path) {
43
- String lower = path.toLowerCase();
44
- String extension;
45
-
46
- int dot = path.lastIndexOf('.');
47
- if (dot == -1) {
48
- extension = UNKNOWN_FILE_EXTENSION; // no extension found
49
-
50
- } else {
51
- extension = lower.substring(dot + 1);
52
-
53
- // check for, and strip any parameters on the url, i.e.
54
- // filename.jpg?blah=blah&something=that
55
- int question = extension.indexOf('?');
56
- if (question != -1) {
57
- extension = extension.substring(0, question);
58
- }
59
- }
60
-
61
- return extension;
62
- }
63
-
64
- /**
65
- * Clean up irregularities like leading period or capitalization from an extension string.
66
- *
67
- * @param extension The extension to clean up like ".PNG".
68
- * @return The cleaned up extension like "png".
69
- */
70
- public static String cleanExtension(String extension) {
71
- extension = extension == null ? UNKNOWN_FILE_EXTENSION : extension.toLowerCase();
72
-
73
- if (extension.startsWith(".")) {
74
- extension = extension.substring(1);
75
- }
76
-
77
- return extension;
78
- }
79
-
80
- /**
81
- * Create the directories so that files can be created at a path.
82
- *
83
- * @param path The path like folder1/folder2/image.png. In this example, folder1 and folder2 would
84
- * both be created if not already existing.
85
- */
86
- public static void createPath(String path) {
87
- createPath(new File(path));
88
- }
89
-
90
- /**
91
- * Create the directories so that files can be created at a path.
92
- *
93
- * @param file The file describing the path that should be created. A path of
94
- * folder1/folder2/image.png would cause folder1 and folder2 to be created if not already
95
- * existing.
96
- */
97
- public static void createPath(File file) {
98
- try {
99
- String parent = file.getParent();
100
- if (parent != null) {
101
- File unit = new File(parent);
102
- if (!unit.exists()) unit.mkdirs();
103
- }
104
- } catch (SecurityException se) {
105
- System.err.println("You don't have permissions to create " +
106
- file.getAbsolutePath());
107
- }
108
- }
109
- }