Skip to content

Commit 9fd0098

Browse files
committed
Merge branch 'master' into static_imports
2 parents c458863 + ddb8224 commit 9fd0098

69 files changed

Lines changed: 1483 additions & 2181 deletions

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

README.md

Lines changed: 11 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,15 @@
1-
This is an experimental fork to attempt the move to JDK 11. Because that's a major, API-breaking change, it would be Processing 4.
1+
This is an experimental fork to attempt the move to JDK 11. Because that's a major, API-breaking change, it would be Processing 4.
22

33
I'm working with Sam Pottinger to incorporate [his changes](https://github.com/sampottinger/processing) to see if that can be the basis for this new release. Getting things moved to OpenJDK 11 will help the longevity of the project.
44

5-
**It's not clear if we'll ship an actual Processing 4.0**, since I have less free time than ever, and very little development help. If you'd like to help, contribute bug fixes.
5+
**It's not clear if we'll ship an actual Processing 4.0**, since I have less free time than ever, and very little development help. If you'd like to help, contribute bug fixes.
66

7-
Ben Fry, 4 October 2019
7+
Ben Fry, 4 October 2019
8+
9+
---
10+
11+
## API changes
12+
13+
As with all releases, I'll do everything possible to avoid breaking API. However, there will still be tweaks that have to be made. We'll try to keep them minor.
14+
15+
* `Base.defaultFileMenu` is now `protected` instead of `static public`

app/.classpath

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,6 @@
1111
<classpathentry kind="lib" path="lib/jna-platform.jar"/>
1212
<classpathentry exported="true" kind="lib" path="lib/ant.jar"/>
1313
<classpathentry exported="true" kind="lib" path="lib/ant-launcher.jar"/>
14-
<classpathentry kind="lib" path="/processing4-core/apple.jar"/>
1514
<classpathentry kind="lib" path="/processing4-core/library-test/junit-4.8.1.jar"/>
1615
<classpathentry kind="output" path="bin"/>
1716
</classpath>

app/build.xml

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -28,8 +28,8 @@
2828
<!-- env used to set classpath below -->
2929
<property environment="env" />
3030

31-
<javac source="1.8"
32-
target="1.8"
31+
<javac source="11"
32+
target="11"
3333
destdir="bin"
3434
excludes="**/tools/format/**"
3535
encoding="UTF-8"

app/src/processing/app/Base.java

Lines changed: 44 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -84,7 +84,7 @@ public class Base {
8484
Collections.synchronizedList(new ArrayList<Editor>());
8585
protected Editor activeEditor;
8686
/** A lone file menu to be used when all sketch windows are closed. */
87-
static public JMenu defaultFileMenu;
87+
protected JMenu defaultFileMenu;
8888

8989
/**
9090
* Starts with the last mode used with the environment,
@@ -437,6 +437,49 @@ public Base(String[] args) throws Exception {
437437
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
438438

439439

440+
/**
441+
* Limited file menu to be used on OS X when no sketches are open.
442+
*/
443+
public JMenu initDefaultFileMenu() {
444+
defaultFileMenu = new JMenu(Language.text("menu.file"));
445+
446+
JMenuItem item = Toolkit.newJMenuItem(Language.text("menu.file.new"), 'N');
447+
item.addActionListener(new ActionListener() {
448+
public void actionPerformed(ActionEvent e) {
449+
handleNew();
450+
}
451+
});
452+
defaultFileMenu.add(item);
453+
454+
item = Toolkit.newJMenuItem(Language.text("menu.file.open"), 'O');
455+
item.addActionListener(new ActionListener() {
456+
public void actionPerformed(ActionEvent e) {
457+
handleOpenPrompt();
458+
}
459+
});
460+
defaultFileMenu.add(item);
461+
462+
item = Toolkit.newJMenuItemShift(Language.text("menu.file.sketchbook"), 'K');
463+
item.addActionListener(new ActionListener() {
464+
@Override
465+
public void actionPerformed(ActionEvent e) {
466+
getNextMode().showSketchbookFrame();
467+
}
468+
});
469+
defaultFileMenu.add(item);
470+
471+
item = Toolkit.newJMenuItemShift(Language.text("menu.file.examples"), 'O');
472+
item.addActionListener(new ActionListener() {
473+
public void actionPerformed(ActionEvent e) {
474+
thinkDifferentExamples();
475+
}
476+
});
477+
defaultFileMenu.add(item);
478+
479+
return defaultFileMenu;
480+
}
481+
482+
440483
void buildCoreModes() {
441484
Mode javaMode =
442485
ModeContribution.load(this, Platform.getContentFile("modes/java"),

app/src/processing/app/Preferences.java

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -404,17 +404,17 @@ static public Font getFont(String attr) {
404404

405405

406406
/**
407-
* Check for a 3.0 sketchbook location, and if none exists,
408-
* try to grab it from the 2.0 sketchbook location.
407+
* Check for a 4.0 sketchbook location, and if none exists,
408+
* try to grab it from the 3.0 sketchbook location.
409409
* @return true if a location was found and the pref didn't exist
410410
*/
411411
static protected boolean checkSketchbookPref() {
412-
// If a 3.0 sketchbook location has never been inited
412+
// If a 4.0 sketchbook location has never been inited
413413
if (getSketchbookPath() == null) {
414-
String twoPath = get("sketchbook.path");
415-
// If they've run the 2.0 version, start with that location
416-
if (twoPath != null) {
417-
setSketchbookPath(twoPath);
414+
String threePath = get("sketchbook.path.three"); //$NON-NLS-1$
415+
// If they've run the 3.0 version, start with that location
416+
if (threePath != null) {
417+
setSketchbookPath(threePath);
418418
return true; // save the sketchbook right away
419419
}
420420
// Otherwise it'll be null, and reset properly by Base
@@ -424,16 +424,16 @@ static protected boolean checkSketchbookPref() {
424424

425425

426426
static public String getOldSketchbookPath() {
427-
return get("sketchbook.path");
427+
return get("sketchbook.path.three"); //$NON-NLS-1$
428428
}
429429

430430

431431
static public String getSketchbookPath() {
432-
return get("sketchbook.path.three"); //$NON-NLS-1$
432+
return get("sketchbook.path.four"); //$NON-NLS-1$
433433
}
434434

435435

436436
static protected void setSketchbookPath(String path) {
437-
set("sketchbook.path.three", path); //$NON-NLS-1$
437+
set("sketchbook.path.four", path); //$NON-NLS-1$
438438
}
439439
}

app/src/processing/app/platform/DefaultPlatform.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -129,7 +129,7 @@ public void openFolder(File file) throws Exception {
129129

130130

131131
public interface CLibrary extends Library {
132-
CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class);
132+
CLibrary INSTANCE = Native.loadLibrary("c", CLibrary.class);
133133
int setenv(String name, String value, int overwrite);
134134
String getenv(String name);
135135
int unsetenv(String name);

app/src/processing/app/platform/LinuxPlatform.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,6 @@
2727
import java.awt.Toolkit;
2828

2929
import processing.app.Base;
30-
import processing.app.Messages;
3130
import processing.app.Preferences;
3231
import processing.app.platform.DefaultPlatform;
3332
import processing.core.PApplet;

app/src/processing/app/platform/MacPlatform.java

Lines changed: 48 additions & 111 deletions
Original file line numberDiff line numberDiff line change
@@ -28,29 +28,20 @@
2828
import java.io.IOException;
2929
import java.net.URI;
3030

31-
import com.apple.eio.FileManager;
31+
import javax.swing.JMenu;
32+
import javax.swing.JMenuBar;
3233

3334
import processing.app.Base;
3435
import processing.app.Messages;
3536
import processing.app.platform.DefaultPlatform;
37+
import processing.app.ui.About;
3638

3739

3840
/**
39-
* Platform handler for Mac OS X.
41+
* Platform handler for macOS.
4042
*/
4143
public class MacPlatform extends DefaultPlatform {
4244

43-
// Removing for 2.0b8 because Quaqua doesn't have OS X 10.8 version.
44-
/*
45-
public void setLookAndFeel() throws Exception {
46-
// Use the Quaqua L & F on OS X to make JFileChooser less awful
47-
UIManager.setLookAndFeel("ch.randelshofer.quaqua.QuaquaLookAndFeel");
48-
// undo quaqua trying to fix the margins, since we've already
49-
// hacked that in, bit by bit, over the years
50-
UIManager.put("Component.visualMargin", new Insets(1, 1, 1, 1));
51-
}
52-
*/
53-
5445
public void saveLanguage(String language) {
5546
String[] cmdarray = new String[]{
5647
"defaults", "write",
@@ -67,35 +58,42 @@ public void saveLanguage(String language) {
6758

6859
public void initBase(Base base) {
6960
super.initBase(base);
61+
62+
final Desktop desktop = Desktop.getDesktop();
63+
7064
System.setProperty("apple.laf.useScreenMenuBar", "true");
71-
ThinkDifferent.init(base);
72-
/*
73-
try {
74-
String name = "processing.app.macosx.ThinkDifferent";
75-
Class osxAdapter = ClassLoader.getSystemClassLoader().loadClass(name);
76-
77-
Class[] defArgs = { Base.class };
78-
Method registerMethod = osxAdapter.getDeclaredMethod("register", defArgs);
79-
if (registerMethod != null) {
80-
Object[] args = { this };
81-
registerMethod.invoke(osxAdapter, args);
65+
66+
// Set the menu bar to be used when nothing else is open.
67+
JMenuBar defaultMenuBar = new JMenuBar();
68+
JMenu fileMenu = base.initDefaultFileMenu();
69+
defaultMenuBar.add(fileMenu);
70+
desktop.setDefaultMenuBar(defaultMenuBar);
71+
72+
desktop.setAboutHandler((event) -> {
73+
new About(null);
74+
});
75+
76+
desktop.setPreferencesHandler((event) -> {
77+
base.handlePrefs();
78+
});
79+
80+
desktop.setOpenFileHandler((event) -> {
81+
for (File file : event.getFiles()) {
82+
base.handleOpen(file.getAbsolutePath());
8283
}
83-
} catch (NoClassDefFoundError e) {
84-
// This will be thrown first if the OSXAdapter is loaded on a system without the EAWT
85-
// because OSXAdapter extends ApplicationAdapter in its def
86-
System.err.println("This version of Mac OS X does not support the Apple EAWT." +
87-
"Application Menu handling has been disabled (" + e + ")");
88-
89-
} catch (ClassNotFoundException e) {
90-
// This shouldn't be reached; if there's a problem with the OSXAdapter
91-
// we should get the above NoClassDefFoundError first.
92-
System.err.println("This version of Mac OS X does not support the Apple EAWT. " +
93-
"Application Menu handling has been disabled (" + e + ")");
94-
} catch (Exception e) {
95-
System.err.println("Exception while loading BaseOSX:");
96-
e.printStackTrace();
97-
}
98-
*/
84+
});
85+
86+
desktop.setPrintFileHandler((event) -> {
87+
// TODO not yet implemented
88+
});
89+
90+
desktop.setQuitHandler((event, quitResponse) -> {
91+
if (base.handleQuit()) {
92+
quitResponse.performQuit();
93+
} else {
94+
quitResponse.cancelQuit();
95+
}
96+
});
9997
}
10098

10199

@@ -106,30 +104,9 @@ public File getSettingsFolder() throws Exception {
106104

107105
public File getDefaultSketchbookFolder() throws Exception {
108106
return new File(getDocumentsFolder(), "Processing");
109-
/*
110-
// looking for /Users/blah/Documents/Processing
111-
try {
112-
Class clazz = Class.forName("processing.app.BaseMacOS");
113-
Method m = clazz.getMethod("getDocumentsFolder", new Class[] { });
114-
String documentsPath = (String) m.invoke(null, new Object[] { });
115-
sketchbookFolder = new File(documentsPath, "Processing");
116-
117-
} catch (Exception e) {
118-
sketchbookFolder = promptSketchbookLocation();
119-
}
120-
*/
121107
}
122108

123109

124-
// /**
125-
// * Moves the specified File object (which might be a file or folder)
126-
// * to the trash.
127-
// */
128-
// public boolean deleteFile(File file) throws IOException {
129-
// return FileManager.moveToTrash(file);
130-
// }
131-
132-
133110
public void openURL(String url) throws Exception {
134111
try {
135112
Desktop.getDesktop().browse(new URI(url));
@@ -145,64 +122,23 @@ public void openURL(String url) throws Exception {
145122
}
146123

147124

148-
/*
149-
public void openURL(String url) throws Exception {
150-
if (PApplet.javaVersion < 1.6f) {
151-
if (url.startsWith("http://")) {
152-
// formerly com.apple.eio.FileManager.openURL(url);
153-
// but due to deprecation, instead loading dynamically
154-
try {
155-
Class<?> eieio = Class.forName("com.apple.eio.FileManager");
156-
Method openMethod =
157-
eieio.getMethod("openURL", new Class[] { String.class });
158-
openMethod.invoke(null, new Object[] { url });
159-
} catch (Exception e) {
160-
e.printStackTrace();
161-
}
162-
} else {
163-
// Assume this is a file instead, and just open it.
164-
// Extension of http://dev.processing.org/bugs/show_bug.cgi?id=1010
165-
processing.core.PApplet.open(url);
166-
}
167-
} else {
168-
try {
169-
Class<?> desktopClass = Class.forName("java.awt.Desktop");
170-
Method getMethod = desktopClass.getMethod("getDesktop");
171-
Object desktop = getMethod.invoke(null, new Object[] { });
172-
173-
// for Java 1.6, replacing with java.awt.Desktop.browse()
174-
// and java.awt.Desktop.open()
175-
if (url.startsWith("http://")) { // browse to a location
176-
Method browseMethod =
177-
desktopClass.getMethod("browse", new Class[] { URI.class });
178-
browseMethod.invoke(desktop, new Object[] { new URI(url) });
179-
} else { // open a file
180-
Method openMethod =
181-
desktopClass.getMethod("open", new Class[] { File.class });
182-
openMethod.invoke(desktop, new Object[] { new File(url) });
183-
}
184-
} catch (Exception e) {
185-
e.printStackTrace();
186-
}
187-
}
188-
}
125+
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
189126

190127

191-
public boolean openFolderAvailable() {
192-
return true;
128+
// TODO I suspect this won't work much longer, since access to the user's
129+
// home directory seems verboten on more recent macOS versions [fry 191008]
130+
protected String getLibraryFolder() throws FileNotFoundException {
131+
return System.getProperty("user.home") + "/Library";
193132
}
194133

195134

196-
public void openFolder(File file) throws Exception {
197-
//openURL(file.getAbsolutePath()); // handles char replacement, etc
198-
processing.core.PApplet.open(file.getAbsolutePath());
135+
// see notes on getLibraryFolder()
136+
protected String getDocumentsFolder() throws FileNotFoundException {
137+
return System.getProperty("user.home") + "/Documents";
199138
}
200-
*/
201-
202-
203-
// . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .
204139

205140

141+
/*
206142
// Some of these are supposedly constants in com.apple.eio.FileManager,
207143
// however they don't seem to link properly from Eclipse.
208144
@@ -237,4 +173,5 @@ protected String getLibraryFolder() throws FileNotFoundException {
237173
protected String getDocumentsFolder() throws FileNotFoundException {
238174
return FileManager.findFolder(kUserDomain, kDocumentsFolderType);
239175
}
176+
*/
240177
}

0 commit comments

Comments
 (0)