Merge branch 'master' into tree_listener_parameter

This commit is contained in:
A Samuel Pottinger
2019-10-11 08:41:19 -07:00
committed by GitHub
47 changed files with 415 additions and 742 deletions

View File

@@ -3,7 +3,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012-15 The Processing Foundation
Copyright (c) 2012-19 The Processing Foundation
Copyright (c) 2008-12 Ben Fry and Casey Reas
This program is free software; you can redistribute it and/or modify
@@ -42,8 +42,6 @@ import processing.mode.java.runner.Runner;
/**
* Class to handle running Processing from the command line.
*
* @author fry
*/
public class Commander implements RunnerListener {
static final String helpArg = "--help";
@@ -65,7 +63,6 @@ public class Commander implements RunnerListener {
static final int BUILD = 1;
static final int RUN = 2;
static final int PRESENT = 3;
// static final int EXPORT_APPLET = 4;
static final int EXPORT = 4;
Sketch sketch;
@@ -74,19 +71,6 @@ public class Commander implements RunnerListener {
PrintStream systemErr;
static public void main(String[] args) {
// Do this early so that error messages go to the console
Base.setCommandLine();
// init the platform so that prefs and other native code is ready to go
Platform.init();
// make sure a full JDK is installed
//Base.initRequirements();
// launch command line handler
new Commander(args);
}
public Commander(String[] args) {
String sketchPath = null;
File sketchFolder = null;
@@ -152,7 +136,6 @@ public class Commander implements RunnerListener {
embedJava = false;
} else if (arg.startsWith(platformArg)) {
// complainAndQuit("The --platform option has been removed from Processing 2.1.", false);
String platformStr = arg.substring(platformArg.length());
platform = Platform.getIndex(platformStr);
if (platform == -1) {
@@ -160,17 +143,6 @@ public class Commander implements RunnerListener {
"'windows', 'macosx', or 'linux'.", true);
}
} else if (arg.startsWith(bitsArg)) {
complainAndQuit("The --bits option has been removed.", false);
// String bitsStr = arg.substring(bitsArg.length());
// if (bitsStr.equals("32")) {
// platformBits = 32;
// } else if (bitsStr.equals("64")) {
// platformBits = 64;
// } else {
// complainAndQuit("Bits should be either 32 or 64, not " + bitsStr, true);
// }
} else if (arg.startsWith(sketchArg)) {
sketchPath = arg.substring(sketchArg.length());
sketchFolder = new File(sketchPath);
@@ -199,13 +171,6 @@ public class Commander implements RunnerListener {
}
String[] sketchArgs = PApplet.subset(args, argOffset);
// if ((outputPath == null) &&
// (task == PREPROCESS || task == BUILD ||
// task == RUN || task == PRESENT)) {
// complainAndQuit("An output path must be specified when using " +
// preprocArg + ", " + buildArg + ", " +
// runArg + ", or " + presentArg + ".");
// }
if (task == HELP) {
printCommandLine(systemOut);
System.exit(0);
@@ -256,8 +221,6 @@ public class Commander implements RunnerListener {
boolean success = false;
// JavaMode javaMode =
// new JavaMode(null, Base.getContentFile("modes/java"));
JavaMode javaMode = (JavaMode)
ModeContribution.load(null, Platform.getContentFile("modes/java"),
"processing.mode.java.JavaMode").getMode();
@@ -389,9 +352,6 @@ public class Commander implements RunnerListener {
out.println("--no-java Do not embed Java. Use at your own risk!");
out.println("--platform Specify the platform (export to application only).");
out.println(" Should be one of 'windows', 'macosx', or 'linux'.");
// out.println("--bits Must be specified if libraries are used that are");
// out.println(" 32- or 64-bit specific such as the OpenGL library.");
// out.println(" Otherwise specify 0 or leave it out.");
out.println();
out.println("The --build, --run, --present, or --export must be the final parameter");
@@ -406,22 +366,31 @@ public class Commander implements RunnerListener {
@Override
public void startIndeterminate() {
}
public void startIndeterminate() { }
@Override
public void stopIndeterminate() {
}
public void stopIndeterminate() { }
@Override
public void statusHalt() {
}
public void statusHalt() { }
@Override
public boolean isHalted() {
return false;
}
static public void main(String[] args) {
// Do this early so that error messages go to the console
Base.setCommandLine();
// init the platform so that prefs and other native code is ready to go
Platform.init();
// launch command line handler
new Commander(args);
}
}

View File

@@ -31,9 +31,6 @@ import java.io.*;
import java.lang.reflect.Method;
import java.util.HashMap;
//import org.eclipse.jdt.core.compiler.batch.BatchCompiler;
//import org.eclipse.jdt.core.compiler.CompilationProgress;
public class Compiler {

View File

@@ -24,7 +24,6 @@ Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
package processing.mode.java;
import java.io.*;
import java.nio.charset.StandardCharsets;
import java.util.*;
import java.util.zip.ZipEntry;
import java.util.zip.ZipFile;
@@ -231,20 +230,12 @@ public class JavaBuild {
outputFolder.mkdirs();
// Base.openFolder(outputFolder);
final File java = new File(outputFolder, sketch.getName() + ".java");
final PrintWriter stream = new PrintWriter(new FileWriter(java, StandardCharsets.UTF_8));
final PrintWriter stream = PApplet.createWriter(java);
try {
result = preprocessor.write(
stream,
bigCode.toString(),
codeFolderPackages
);
result = preprocessor.write(stream, bigCode.toString(), codeFolderPackages);
} finally {
stream.close();
}
} catch (FileNotFoundException fnfe) {
fnfe.printStackTrace();
String msg = "Build folder disappeared or could not be written";
throw new SketchException(msg);
} catch (SketchException pe) {
// RunnerExceptions are caught here and re-thrown, so that they don't
// get lost in the more general "Exception" handler below.
@@ -582,7 +573,7 @@ public class JavaBuild {
if (Library.hasMultipleArch(platform, importedLibraries)) {
// Don't try to export 32-bit on macOS, because it doesn't exist.
if (platform != PConstants.MACOSX) {
if (platform != PConstants.MACOS) {
// export the 32-bit version
folder = new File(sketch.getFolder(), "application." + platformName + "32");
if (!exportApplication(folder, platform, "32", embedJava && (bits == 32) && ("x86".equals(arch) || "i386".equals(arch)))) {
@@ -657,7 +648,7 @@ public class JavaBuild {
File dotAppFolder = null;
String jvmRuntime = "";
String jdkPath = null;
if (exportPlatform == PConstants.MACOSX) {
if (exportPlatform == PConstants.MACOS) {
dotAppFolder = new File(destFolder, sketch.getName() + ".app");
File contentsOrig = new File(Platform.getJavaHome(), "../../../..");
@@ -760,10 +751,10 @@ public class JavaBuild {
// the folder inside the .app package, while Linux and Windows will have a
// 'data' folder next to 'lib'.
if (sketch.hasDataFolder()) {
if (exportPlatform == PConstants.MACOSX) {
Util.copyDir(sketch.getDataFolder(), new File(jarFolder, "data"));
if (exportPlatform == PConstants.MACOS) {
Util.copyDir(sketch.getDataFolder(), new File(jarFolder, "data"));
} else {
Util.copyDir(sketch.getDataFolder(), new File(destFolder, "data"));
Util.copyDir(sketch.getDataFolder(), new File(destFolder, "data"));
}
}
@@ -820,7 +811,7 @@ public class JavaBuild {
/// create platform-specific CLASSPATH based on included jars
String exportClassPath = null;
if (exportPlatform == PConstants.MACOSX) {
if (exportPlatform == PConstants.MACOS) {
exportClassPath = "$JAVAROOT/" + jarList.join(":$JAVAROOT/");
} else if (exportPlatform == PConstants.WINDOWS) {
exportClassPath = jarList.join(",");
@@ -854,7 +845,7 @@ public class JavaBuild {
/// macosx: write out Info.plist (template for classpath, etc)
if (exportPlatform == PConstants.MACOSX) {
if (exportPlatform == PConstants.MACOS) {
StringBuilder runOptionsXML = new StringBuilder();
for (String opt : runOptions) {
runOptionsXML.append(" <string>");

View File

@@ -1,3 +1,26 @@
/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012-19 The Processing Foundation
Copyright (c) 2004-12 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
as published by the Free Software Foundation.
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
package processing.mode.java;
import java.awt.*;
@@ -1098,7 +1121,7 @@ public class JavaEditor extends Editor {
if (!tweak) {
runtime = jmode.handleLaunch(sketch, listener, present);
} else {
runtime = jmode.handleTweak(sketch, listener);
runtime = jmode.handleTweak(sketch, listener, JavaEditor.this);
}
}
}

View File

@@ -3,7 +3,7 @@
/*
Part of the Processing project - http://processing.org
Copyright (c) 2012-15 The Processing Foundation
Copyright (c) 2012-19 The Processing Foundation
Copyright (c) 2004-12 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
@@ -24,15 +24,15 @@
package processing.mode.java;
import java.awt.event.KeyEvent;
import java.util.Arrays;
import processing.app.Preferences;
import processing.app.Sketch;
import processing.app.syntax.*;
import processing.app.syntax.JEditTextArea;
import processing.app.syntax.PdeInputHandler;
import processing.app.ui.Editor;
import java.awt.*;
import java.awt.event.*;
import java.util.Arrays;
/**
* Filters key events for tab expansion/indent/etc. This is very old code
@@ -41,9 +41,9 @@ import java.util.Arrays;
*/
public class JavaInputHandler extends PdeInputHandler {
/** ctrl-alt on windows and linux, cmd-alt on mac os x */
static final int CTRL_ALT = ActionEvent.ALT_MASK |
Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
// /** ctrl-alt on windows and linux, cmd-alt on mac os x */
// static final int CTRL_ALT = ActionEvent.ALT_MASK |
// Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
public JavaInputHandler(Editor editor) {
@@ -66,7 +66,8 @@ public class JavaInputHandler extends PdeInputHandler {
Sketch sketch = editor.getSketch();
JEditTextArea textarea = editor.getTextArea();
if ((event.getModifiers() & InputEvent.META_MASK) != 0) {
if (event.isMetaDown()) {
//if ((event.getModifiers() & InputEvent.META_MASK) != 0) {
//event.consume(); // does nothing
return false;
}
@@ -76,8 +77,8 @@ public class JavaInputHandler extends PdeInputHandler {
sketch.setModified(true);
}
if ((code == KeyEvent.VK_UP) &&
((event.getModifiers() & InputEvent.CTRL_MASK) != 0)) {
if ((code == KeyEvent.VK_UP) && event.isControlDown()) {
//((event.getModifiers() & InputEvent.CTRL_MASK) != 0)) {
// back up to the last empty line
char contents[] = textarea.getText().toCharArray();
//int origIndex = textarea.getCaretPosition() - 1;
@@ -104,7 +105,8 @@ public class JavaInputHandler extends PdeInputHandler {
// if the first char, index will be -2
if (index < 0) index = 0;
if ((event.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
//if ((event.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
if (event.isShiftDown()) {
textarea.setSelectionStart(caretIndex);
textarea.setSelectionEnd(index);
} else {
@@ -113,8 +115,8 @@ public class JavaInputHandler extends PdeInputHandler {
event.consume();
// return true;
} else if ((code == KeyEvent.VK_DOWN) &&
((event.getModifiers() & InputEvent.CTRL_MASK) != 0)) {
} else if ((code == KeyEvent.VK_DOWN) && event.isControlDown()) {
//((event.getModifiers() & InputEvent.CTRL_MASK) != 0)) {
char contents[] = textarea.getText().toCharArray();
int caretIndex = textarea.getCaretPosition();
@@ -136,7 +138,8 @@ public class JavaInputHandler extends PdeInputHandler {
index++;
}
if ((event.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
//if ((event.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
if (event.isShiftDown()) {
textarea.setSelectionStart(caretIndex);
textarea.setSelectionEnd(index);
} else {
@@ -146,7 +149,8 @@ public class JavaInputHandler extends PdeInputHandler {
// return true;
} else if (c == 9) {
if ((event.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
//if ((event.getModifiers() & InputEvent.SHIFT_MASK) != 0) {
if (event.isShiftDown()) {
// if shift is down, the user always expects an outdent
// http://code.google.com/p/processing/issues/detail?id=458
editor.handleOutdent();
@@ -317,7 +321,8 @@ public class JavaInputHandler extends PdeInputHandler {
public boolean handleTyped(KeyEvent event) {
char c = event.getKeyChar();
if ((event.getModifiers() & InputEvent.CTRL_MASK) != 0) {
//if ((event.getModifiers() & InputEvent.CTRL_MASK) != 0) {
if (event.isControlDown()) { // TODO true on typed? [fry 191007]
// on linux, ctrl-comma (prefs) being passed through to the editor
if (c == KeyEvent.VK_COMMA) {
event.consume();

View File

@@ -4,7 +4,7 @@
Part of the Processing project - http://processing.org
Copyright (c) 2010-11 Ben Fry and Casey Reas
Copyright (c) 2012-15 The Processing Foundation
Copyright (c) 2012-19 The Processing Foundation
This program is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License version 2
@@ -37,6 +37,7 @@ import processing.app.*;
import processing.app.ui.Editor;
import processing.app.ui.EditorException;
import processing.app.ui.EditorState;
import processing.mode.java.runner.Runner;
import processing.mode.java.tweak.SketchParser;
@@ -140,10 +141,8 @@ public class JavaMode extends Mode {
/** Start a sketch in tweak mode */
public Runner handleTweak(Sketch sketch,
RunnerListener listener) throws SketchException {
// final boolean present) throws SketchException {
final JavaEditor editor = (JavaEditor) listener;
RunnerListener listener,
JavaEditor editor) throws SketchException {
// first try to build the unmodified code
JavaBuild build = new JavaBuild(sketch);
// String appletClassName = build.build(false);

View File

@@ -21,7 +21,6 @@
package processing.mode.java;
import java.awt.event.ActionEvent;
import java.awt.event.InputEvent;
import java.util.ArrayList;
import java.util.List;
@@ -131,7 +130,7 @@ public class JavaToolbar extends EditorToolbar {
@Override
public void handleRun(int modifiers) {
boolean shift = (modifiers & InputEvent.SHIFT_MASK) != 0;
boolean shift = (modifiers & ActionEvent.SHIFT_MASK) != 0;
if (shift) {
jeditor.handlePresent();
} else {

View File

@@ -1790,7 +1790,7 @@ public class CompletionGenerator {
// Now parse the expression into an ASTNode object
ASTNode nearestNode;
ASTParser parser = ASTParser.newParser(AST.JLS8);
ASTParser parser = ASTParser.newParser(AST.JLS11);
parser.setKind(ASTParser.K_EXPRESSION);
parser.setSource(phrase.toCharArray());
ASTNode testnode = parser.createAST(null);

View File

@@ -8,8 +8,6 @@ import processing.app.Problem;
import processing.app.ui.Editor;
import processing.mode.java.preproc.issue.PdePreprocessIssue;
import java.util.List;
/**
* Factory which helps create {Problem}s during preprocessing.

View File

@@ -20,22 +20,31 @@ along with this program; if not, write to the Free Software Foundation, Inc.
package processing.mode.java.pdex.util;
import com.google.classpath.ClassPathFactory;
import processing.app.*;
import processing.mode.java.JavaMode;
import processing.mode.java.pdex.ImportStatement;
import processing.mode.java.pdex.PreprocessedSketch;
import java.io.File;
import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.nio.file.Paths;
import java.util.*;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import java.util.Objects;
import java.util.StringJoiner;
import java.util.concurrent.atomic.AtomicReference;
import java.util.stream.Collectors;
import java.util.stream.Stream;
import com.google.classpath.ClassPathFactory;
import processing.app.Library;
import processing.app.Messages;
import processing.app.Sketch;
import processing.app.SketchException;
import processing.app.Util;
import processing.mode.java.JavaMode;
import processing.mode.java.pdex.ImportStatement;
import processing.mode.java.pdex.PreprocessedSketch;
/**
* Builder which generates runtime paths using a series of caches.

View File

@@ -662,10 +662,8 @@ public class Runner implements MessageConsumer {
protected Connector findConnector(String connectorName) {
// List connectors =
// com.sun.jdi.Bootstrap.virtualMachineManager().allConnectors();
List<Connector> connectors =
org.eclipse.jdi.Bootstrap.virtualMachineManager().allConnectors();
com.sun.jdi.Bootstrap.virtualMachineManager().allConnectors();
// // debug: code to list available connectors
// Iterator iter2 = connectors.iterator();

View File

@@ -23,6 +23,7 @@ package processing.mode.java.tweak;
import java.awt.Graphics2D;
import java.awt.geom.AffineTransform;
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Comparator;
import java.util.Locale;
@@ -171,7 +172,7 @@ public class Handle {
} else if ("float".equals(type)) {
BigDecimal bd = new BigDecimal(value.floatValue());
bd = bd.setScale(decimalPlaces, BigDecimal.ROUND_HALF_UP);
bd = bd.setScale(decimalPlaces, RoundingMode.HALF_UP);
newValue = bd.floatValue();
strNewValue = String.format(Locale.US, textFormat, newValue.floatValue());
}