propane 3.2.0-java → 3.3.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 (40) hide show
  1. checksums.yaml +4 -4
  2. data/.mvn/extensions.xml +9 -0
  3. data/.mvn/wrapper/maven-wrapper.properties +3 -1
  4. data/CHANGELOG.md +3 -1
  5. data/README.md +4 -4
  6. data/lib/propane/app.rb +1 -1
  7. data/lib/propane/version.rb +1 -1
  8. data/pom.rb +79 -0
  9. data/pom.xml +32 -43
  10. data/propane.gemspec +2 -2
  11. data/src/main/java/japplemenubar/JAppleMenuBar.java +47 -41
  12. data/src/main/java/monkstone/vecmath/{AppRender.java → GfxRender.java} +12 -12
  13. data/src/main/java/processing/awt/PSurfaceAWT.java +3 -3
  14. data/src/main/java/processing/core/PApplet.java +14004 -14573
  15. data/src/main/java/processing/core/PGraphics.java +7563 -7213
  16. data/src/main/java/processing/core/PImage.java +2783 -3080
  17. data/src/main/java/processing/core/ThinkDifferent.java +120 -0
  18. data/src/main/java/processing/core/util/image/ImageLoadFacade.java +161 -0
  19. data/src/main/java/processing/core/util/image/ImageSaveFacade.java +169 -0
  20. data/src/main/java/processing/core/util/image/constants/TifConstants.java +45 -0
  21. data/src/main/java/processing/core/util/image/load/AwtImageLoadStrategy.java +80 -0
  22. data/src/main/java/processing/core/util/image/load/Base64StringImageLoadStrategy.java +73 -0
  23. data/src/main/java/processing/core/util/image/load/FallbackImageLoadStrategy.java +70 -0
  24. data/src/main/java/processing/core/util/image/load/ImageIoImageLoadStrategy.java +132 -0
  25. data/src/main/java/processing/core/util/image/load/ImageLoadStrategy.java +48 -0
  26. data/src/main/java/processing/core/util/image/load/ImageLoadUtil.java +45 -0
  27. data/src/main/java/processing/core/util/image/load/TgaImageLoadStrategy.java +255 -0
  28. data/src/main/java/processing/core/util/image/load/TiffImageLoadStrategy.java +98 -0
  29. data/src/main/java/processing/core/util/image/save/ImageSaveStrategy.java +49 -0
  30. data/src/main/java/processing/core/util/image/save/ImageSaveUtil.java +48 -0
  31. data/src/main/java/processing/core/util/image/save/ImageWriterImageSaveStrategy.java +179 -0
  32. data/src/main/java/processing/core/util/image/save/SaveImageException.java +41 -0
  33. data/src/main/java/processing/core/util/image/save/TgaImageSaveStrategy.java +198 -0
  34. data/src/main/java/processing/core/util/image/save/TiffImageSaveStrategy.java +91 -0
  35. data/src/main/java/processing/core/util/image/save/TiffNakedFilenameImageSaveStrategy.java +57 -0
  36. data/src/main/java/processing/core/util/io/InputFactory.java +285 -0
  37. data/src/main/java/processing/core/util/io/PathUtil.java +109 -0
  38. data/vendors/Rakefile +1 -1
  39. metadata +30 -7
  40. data/src/main/java/processing/core/DesktopHandler.java +0 -94
@@ -0,0 +1,120 @@
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-2014 The Processing Foundation
7
+ Copyright (c) 2007-2012 Ben Fry and Casey Reas
8
+
9
+ This program is free software; you can redistribute it and/or
10
+ modify it under the terms of the GNU General Public License
11
+ version 2, as published by the Free Software Foundation.
12
+
13
+ This program is distributed in the hope that it will be useful,
14
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
15
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
16
+ GNU General Public License for more details.
17
+
18
+ You should have received a copy of the GNU General Public License
19
+ along with this program; if not, write to the Free Software Foundation,
20
+ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
21
+ */
22
+
23
+ package processing.core;
24
+
25
+ import java.awt.*;
26
+
27
+
28
+ /**
29
+ * Deal with issues related to Mac OS window behavior.
30
+ *
31
+ * We have to register a quit handler to safely shut down the sketch,
32
+ * otherwise OS X will just kill the sketch when a user hits Cmd-Q.
33
+ * In addition, we have a method to set the dock icon image so we look more
34
+ * like a native desktop.
35
+ *
36
+ * This is a stripped-down version of what's in processing.app.platform to fix
37
+ * <a href="https://github.com/processing/processing/issues/3301">3301</a>.
38
+ */
39
+ public class ThinkDifferent {
40
+
41
+ private static Desktop desktop;
42
+ private static Taskbar taskbar;
43
+
44
+ // True if user has tried to quit once. Prevents us from canceling the quit
45
+ // call if the sketch is held up for some reason, like an exception that's
46
+ // managed to put the sketch in a bad state.
47
+ static boolean attemptedQuit;
48
+
49
+ /**
50
+ * Initialize the sketch with the quit handler.
51
+ *
52
+ * Initialize the sketch with the quit handler such that, if there is no known
53
+ * crash, the application will not exit on its own if this is the first quit
54
+ * attempt.
55
+ *
56
+ * @param sketch The sketch whose quit handler callback should be set.
57
+ */
58
+ static public void init(final PApplet sketch) {
59
+ getDesktop().setQuitHandler((event, quitResponse) -> {
60
+ sketch.exit();
61
+
62
+ boolean noKnownCrash = PApplet.uncaughtThrowable == null;
63
+
64
+ if (noKnownCrash && !attemptedQuit) { // haven't tried yet
65
+ quitResponse.cancelQuit(); // tell OS X we'll handle this
66
+ attemptedQuit = true;
67
+ } else {
68
+ quitResponse.performQuit(); // just force it this time
69
+ }
70
+ });
71
+ }
72
+
73
+ /**
74
+ * Remove the quit handler.
75
+ */
76
+ static public void cleanup() {
77
+ getDesktop().setQuitHandler(null);
78
+ }
79
+
80
+ /**
81
+ * Called via reflection from PSurfaceAWT and others, set the dock icon image.
82
+ *
83
+ * @param image The image to provide for Processing icon.
84
+ */
85
+ static public void setIconImage(Image image) {
86
+ getTaskbar().setIconImage(image);
87
+ }
88
+
89
+ /**
90
+ * Get the taskbar where OS visual settings can be provided.
91
+ *
92
+ * @return Cached taskbar singleton instance.
93
+ */
94
+ static private Taskbar getTaskbar() {
95
+ if (taskbar == null) {
96
+ taskbar = Taskbar.getTaskbar();
97
+ }
98
+
99
+ return taskbar;
100
+ }
101
+
102
+ /**
103
+ * Get the desktop where OS behavior can be provided.
104
+ *
105
+ * @return Cached desktop singleton instance.
106
+ */
107
+ static private Desktop getDesktop() {
108
+ if (desktop == null) {
109
+ desktop = Desktop.getDesktop();
110
+ }
111
+
112
+ return desktop;
113
+ }
114
+
115
+
116
+ // Instead, just use Application.getApplication() inside your app
117
+ // static public Application getApplication() {
118
+ // return desktop;
119
+ // }
120
+ }
@@ -0,0 +1,161 @@
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;
26
+
27
+ import processing.core.PApplet;
28
+ import processing.core.PImage;
29
+ import processing.core.util.image.load.*;
30
+ import processing.core.util.io.PathUtil;
31
+
32
+ import java.util.HashMap;
33
+ import java.util.Map;
34
+ import java.util.concurrent.atomic.AtomicReference;
35
+
36
+
37
+ /**
38
+ * Utility for loading images either from file system or string encoding using a set of strategies.
39
+ */
40
+ public class ImageLoadFacade {
41
+
42
+ private static final AtomicReference<ImageLoadFacade> instance = new AtomicReference<>(null);
43
+
44
+ private static final String PREFIX_BASE64_STRING_IMAGE = "data:image";
45
+ private static final String PREFIX_FILE_PATH = "file://";
46
+
47
+ private final Map<String, ImageLoadStrategy> loadStrategies;
48
+ private final ImageLoadStrategy defaultImageLoadStrategy;
49
+
50
+ /**
51
+ * Get a shared instance of this singleton.
52
+ *
53
+ * @return Shared instance of this singleton.
54
+ */
55
+ public static ImageLoadFacade get() {
56
+ instance.compareAndSet(null, new ImageLoadFacade());
57
+ return instance.get();
58
+ }
59
+
60
+ /**
61
+ * Hidden constructor. Clients should use get().
62
+ */
63
+ private ImageLoadFacade() {
64
+ loadStrategies = new HashMap<>();
65
+
66
+ loadStrategies.put("base64", new Base64StringImageLoadStrategy());
67
+
68
+ loadStrategies.put("tga", new TgaImageLoadStrategy());
69
+
70
+ ImageLoadStrategy tifImageLoadStrategy = new TiffImageLoadStrategy();
71
+ loadStrategies.put("tif", tifImageLoadStrategy);
72
+ loadStrategies.put("tiff", tifImageLoadStrategy);
73
+
74
+ ImageLoadStrategy awtImageLoadStrategy = new AwtImageLoadStrategy();
75
+ defaultImageLoadStrategy = new ImageIoImageLoadStrategy();
76
+
77
+ ImageLoadStrategy awtFallbackStrategy = new FallbackImageLoadStrategy(
78
+ awtImageLoadStrategy,
79
+ defaultImageLoadStrategy
80
+ );
81
+ loadStrategies.put("jpg", awtFallbackStrategy);
82
+ loadStrategies.put("jpeg", awtFallbackStrategy);
83
+ loadStrategies.put("gif", awtFallbackStrategy);
84
+ loadStrategies.put("png", awtFallbackStrategy);
85
+ loadStrategies.put("unknown", awtFallbackStrategy);
86
+ }
87
+
88
+ /**
89
+ * Load an image embedded within an SVG string.
90
+ *
91
+ * @param pApplet The PApplet on whose behalf an SVG is being parsed. This must be given so that
92
+ * image can be retrieved in the case of sketch relative file.
93
+ * @param svgImageStr The SVG string to load which can be data:image or file://.
94
+ * @return The image loaded as a PImage.
95
+ */
96
+ public PImage loadFromSvg(PApplet pApplet, String svgImageStr) {
97
+ if (svgImageStr == null) {
98
+ return null;
99
+ }
100
+
101
+ if (svgImageStr.startsWith(PREFIX_BASE64_STRING_IMAGE)) {
102
+ String[] parts = svgImageStr.split(";base64,");
103
+ String extension = parts[0].substring(11);
104
+ String encodedData = parts[1];
105
+ return loadStrategies.get("base64").load(pApplet, encodedData, extension);
106
+ } else if (svgImageStr.startsWith(PREFIX_FILE_PATH)) {
107
+ String filePath = svgImageStr.substring(PREFIX_FILE_PATH.length());
108
+ return loadFromFile(pApplet, filePath);
109
+ } else {
110
+ return null;
111
+ }
112
+ }
113
+
114
+ /**
115
+ * Load an image from a file.
116
+ *
117
+ * @param pApplet The PApplet through which the image should be retrieved in the case of sketch
118
+ * relative file (data folder for example).
119
+ * @param path The path to the file to be opened.
120
+ * @return The image loaded.
121
+ */
122
+ public PImage loadFromFile(PApplet pApplet, String path) {
123
+ return loadFromFile(pApplet, path, null);
124
+ }
125
+
126
+ /**
127
+ * Load an image from a file using the given file extension.
128
+ *
129
+ * @param pApplet The PApplet through which the image should be retrieved in the case of sketch
130
+ * relative file (data folder for example).
131
+ * @param path The path to the file to be opened.
132
+ * @param extension The extension with which the image should be loaded like "png".
133
+ * @return The image loaded.
134
+ */
135
+ public PImage loadFromFile(PApplet pApplet, String path, String extension) {
136
+ if (extension == null) {
137
+ extension = PathUtil.parseExtension(path);
138
+ }
139
+
140
+ // just in case. them users will try anything!
141
+ extension = PathUtil.cleanExtension(extension);
142
+
143
+ // Find strategy for loading
144
+ ImageLoadStrategy imageLoadStrategy = loadStrategies.getOrDefault(
145
+ extension,
146
+ defaultImageLoadStrategy
147
+ );
148
+
149
+ // Load image
150
+ PImage resultImage = imageLoadStrategy.load(pApplet, path, extension);
151
+
152
+ // Report error or return
153
+ if (resultImage == null) {
154
+ System.err.println("Could not find a method to load " + path);
155
+ return null;
156
+ } else {
157
+ return resultImage;
158
+ }
159
+ }
160
+
161
+ }
@@ -0,0 +1,169 @@
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;
26
+
27
+ import processing.core.PApplet;
28
+ import processing.core.PGraphics;
29
+ import processing.core.util.image.save.*;
30
+ import processing.core.util.io.PathUtil;
31
+
32
+ import java.io.File;
33
+ import java.io.IOException;
34
+ import java.util.HashMap;
35
+ import java.util.Map;
36
+ import java.util.concurrent.atomic.AtomicReference;
37
+
38
+
39
+ /**
40
+ * Facade to load PImages from various sources.
41
+ */
42
+ public class ImageSaveFacade {
43
+
44
+ private static final AtomicReference<ImageSaveFacade> instance = new AtomicReference<>(null);
45
+
46
+ private final Map<String, ImageSaveStrategy> saveStrategies;
47
+ private final ImageSaveStrategy defaultImageSaveStrategy;
48
+
49
+ /**
50
+ * Get a shared instance of this singleton.
51
+ *
52
+ * @return Shared instance of ImageSaveFacade.
53
+ */
54
+ public static ImageSaveFacade get() {
55
+ instance.compareAndSet(null, new ImageSaveFacade());
56
+ return instance.get();
57
+ }
58
+
59
+ /**
60
+ * Private hidden constructor requiring clients to use get().
61
+ */
62
+ private ImageSaveFacade() {
63
+ saveStrategies = new HashMap<>();
64
+
65
+ ImageSaveStrategy imageWriterImageSaveStrategy = new ImageWriterImageSaveStrategy();
66
+ for (String format : javax.imageio.ImageIO.getWriterFormatNames()) {
67
+ saveStrategies.put(format.toLowerCase(), imageWriterImageSaveStrategy);
68
+ }
69
+
70
+ ImageSaveStrategy tgaImageSaveStrategy = new TgaImageSaveStrategy();
71
+ saveStrategies.put("tga", tgaImageSaveStrategy);
72
+
73
+ ImageSaveStrategy tiffImageSaveStrategy = new TiffImageSaveStrategy();
74
+ saveStrategies.put("tiff", tiffImageSaveStrategy);
75
+
76
+ defaultImageSaveStrategy = new TiffNakedFilenameImageSaveStrategy();
77
+ }
78
+
79
+ /**
80
+ * Save a raw representation of pixel values to a file given that file's path.
81
+ *
82
+ * @param pixels The raw representation of the image to save.
83
+ * @param pixelWidth Width of the image in pixels.
84
+ * @param pixelheight Height of the image in pixels.
85
+ * @param format Format corresponding to value in PConstants like PConstants.ARGB.
86
+ * @param filename The path at which the file should be saved like "test/path/output.png".
87
+ */
88
+ public boolean save(int[] pixels, int pixelWidth, int pixelHeight, int format, String filename) {
89
+ return save(
90
+ pixels,
91
+ pixelWidth,
92
+ pixelHeight,
93
+ format,
94
+ filename,
95
+ null
96
+ );
97
+ }
98
+
99
+ /**
100
+ * Save a raw representation of pixel values to a file given that file's path.
101
+ *
102
+ * @param pixels The raw representation of the image to save.
103
+ * @param pixelWidth Width of the image in pixels.
104
+ * @param pixelheight Height of the image in pixels.
105
+ * @param format Format corresponding to value in PConstants like PConstants.ARGB.
106
+ * @param filename The path at which the file should be saved like "test/path/output.png".
107
+ * @param pApplet The applet through which files should be saved when using sketch relative paths.
108
+ * Can pass null if using absolute paths.
109
+ */
110
+ public boolean save(int[] pixels, int pixelWidth, int pixelHeight, int format, String filename,
111
+ PApplet pApplet) {
112
+
113
+ filename = preparePath(pApplet, filename);
114
+
115
+ String extension = PathUtil.parseExtension(filename);
116
+
117
+ ImageSaveStrategy imageSaveStrategy = saveStrategies.getOrDefault(
118
+ extension,
119
+ defaultImageSaveStrategy
120
+ );
121
+
122
+ try {
123
+ return imageSaveStrategy.save(
124
+ pixels,
125
+ pixelWidth,
126
+ pixelHeight,
127
+ format,
128
+ filename
129
+ );
130
+ } catch (IOException e) {
131
+ System.err.println("Error while saving image.");
132
+ e.printStackTrace();
133
+ return false;
134
+ } catch (SaveImageException e) {
135
+ PGraphics.showException(e.getMessage());
136
+ return false;
137
+ }
138
+
139
+ }
140
+
141
+ /**
142
+ * Ensure that the path is ready so that a file can be saved.
143
+ *
144
+ * @param pApplet The applet through which files should be saved when using sketch relative paths.
145
+ * Can pass null if using absolute paths.
146
+ * @param filename The filename that will be written and for which a path needs to be prepared.
147
+ * @return Completed path useable for writing like a file path that has been made relative to
148
+ * the sketch folder.
149
+ */
150
+ private String preparePath(PApplet pApplet, String filename) {
151
+ if (pApplet != null) {
152
+ return pApplet.savePath(filename);
153
+ } else {
154
+ File file = new File(filename);
155
+ if (file.isAbsolute()) {
156
+ // make sure that the intermediate folders have been created
157
+ PathUtil.createPath(file);
158
+ return filename;
159
+ } else {
160
+ String msg =
161
+ "PImage.save() requires an absolute path. " +
162
+ "Use createImage(), or pass savePath() to save().";
163
+
164
+ throw new SaveImageException(msg);
165
+ }
166
+ }
167
+ }
168
+
169
+ }