clean up warnings, typos, unused code

This commit is contained in:
Ben Fry
2021-07-05 07:45:25 -04:00
parent 32a6a9f281
commit 2be175b0a7
2 changed files with 64 additions and 236 deletions
+56 -233
View File
@@ -81,6 +81,7 @@ import processing.opengl.*;
* project of our (tiny) size, we should be focusing on the future, rather
* than working around legacy Java code.
*/
@SuppressWarnings("unused")
public class PApplet implements PConstants {
//public class PApplet extends PSketch { // possible in the next alpha
/** Full name of the Java version (i.e. 1.5.0_11). */
@@ -295,7 +296,7 @@ public class PApplet implements PConstants {
* be <b>pixelWidth*pixelHeight</b>, not <b>width*height</b>.
*
* @webref environment
* @webBrief The actual pixel heigh when using high resolution display
* @webBrief The actual pixel height when using high resolution display
* @see PApplet#pixelWidth
* @see #pixelDensity(int)
* @see #displayDensity()
@@ -725,7 +726,7 @@ public class PApplet implements PConstants {
// messages to send if attached as an external vm
/**
* Position of the upper-lefthand corner of the editor window
* Position of the upper left-hand corner of the editor window
* that launched this applet.
*/
static public final String ARGS_EDITOR_LOCATION = "--editor-location";
@@ -1537,7 +1538,7 @@ public class PApplet implements PConstants {
/**
*
* The <b>setup()</b> function is run once, when the program starts. It's used
* to define initial enviroment properties such as screen size and to load media
* to define initial environment properties such as screen size and to load media
* such as images and fonts as the program starts. There can only be one
* <b>setup()</b> function for each program and it shouldn't be called again
* after its initial execution.<br />
@@ -1831,72 +1832,6 @@ public class PApplet implements PConstants {
this.outputPath = path;
}
}
/*
if (!renderer.equals(sketchRenderer())) {
if (external) {
// The PDE should have parsed it, but something still went wrong
final String msg =
String.format("Something bad happened when calling " +
"size(%d, %d, %s, %s)", w, h, renderer, path);
throw new RuntimeException(msg);
} else {
System.err.println("Because you're not running from the PDE, add this to your code:");
System.err.println("public String sketchRenderer() {");
System.err.println(" return \"" + renderer + "\";");
System.err.println("}");
throw new RuntimeException("The sketchRenderer() method is not implemented.");
}
}
*/
// size() shouldn't actually do anything here [3.0a8]
// surface.setSize(w, h);
// this won't be absolute, which will piss off PDF [3.0a8]
// g.setPath(path); // finally, a path
// // Run this from the EDT, just cuz it's AWT stuff (or maybe later Swing)
// EventQueue.invokeLater(new Runnable() {
// public void run() {
// // Set the preferred size so that the layout managers can handle it
// setPreferredSize(new Dimension(w, h));
// setSize(w, h);
// }
// });
//
// // ensure that this is an absolute path
// if (path != null) path = savePath(path);
//
// String currentRenderer = g.getClass().getName();
// if (currentRenderer.equals(renderer)) {
//// // Avoid infinite loop of throwing exception to reset renderer
//// resizeRenderer(w, h);
// surface.setSize(w, h);
//
// } else { // renderer change attempted
// // no longer kosher with 3.0a5
// throw new RuntimeException("Y'all need to implement sketchRenderer()");
// /*
// // otherwise ok to fall through and create renderer below
// // the renderer is changing, so need to create a new object
// g = makeGraphics(w, h, renderer, path, true);
// this.width = w;
// this.height = h;
//
// // fire resize event to make sure the applet is the proper size
//// setSize(iwidth, iheight);
// // this is the function that will run if the user does their own
// // size() command inside setup, so set defaultSize to false.
// defaultSize = false;
//
// // throw an exception so that setup() is called again
// // but with a properly sized render
// // this is for opengl, which needs a valid, properly sized
// // display before calling anything inside setup().
// throw new RendererChangeException();
// */
// }
}
@@ -2013,24 +1948,9 @@ public class PApplet implements PConstants {
public PGraphics createGraphics(int w, int h,
String renderer, String path) {
return makeGraphics(w, h, renderer, path, false);
/*
if (path != null) {
path = savePath(path);
}
PGraphics pg = makeGraphics(w, h, renderer, path, false);
//pg.parent = this; // why wasn't setParent() used before 3.0a6?
//pg.setParent(this); // make save() work
// Nevermind, parent is set in makeGraphics()
return pg;
*/
}
// public PGraphics makePrimaryGraphics(int wide, int high) {
// return makeGraphics(wide, high, sketchRenderer(), null, true);
// }
/**
* Version of createGraphics() used internally.
* @param path A path (or null if none), can be absolute or relative ({@link PApplet#savePath} will be called)
@@ -2038,14 +1958,6 @@ public class PApplet implements PConstants {
protected PGraphics makeGraphics(int w, int h,
String renderer, String path,
boolean primary) {
// String openglError = external ?
// // This first one should no longer be possible
// "Before using OpenGL, first select " +
// "Import Library > OpenGL from the Sketch menu." :
// // Welcome to Java programming! The training wheels are off.
// "The Java classpath and native library path is not " +
// "properly set for using the OpenGL library.";
if (!primary && !g.isGL()) {
if (renderer.equals(P2D)) {
throw new RuntimeException("createGraphics() with P2D requires size() to use P2D or P3D");
@@ -2096,7 +2008,7 @@ public class PApplet implements PConstants {
}
} catch (ClassNotFoundException cnfe) {
// Clarify the error mesage for less confusion on 4.x
// Clarify the error message for less confusion on 4.x
if (renderer.equals(FX2D)) {
renderer = "JavaFX";
}
@@ -3669,7 +3581,7 @@ public class PApplet implements PConstants {
* Called to dispose of resources and shut down the sketch.
* Destroys the thread, dispose the renderer,and notify listeners.
* <p>
* Not to be called or overriden by users. If called multiple times,
* Not to be called or overridden by users. If called multiple times,
* will only notify listeners once. Register a dispose listener instead.
*/
public void dispose() {
@@ -3929,14 +3841,6 @@ public class PApplet implements PConstants {
* (<a href="https://github.com/processing/processing/issues/3791">Issue
* 3791</a>).
*
* <h3>Advanced</h3> Set a custom cursor to an image with a specific hotspot.
* Only works with JDK 1.2 and later. Currently seems to be broken on Java 1.4
* for Mac OS X
* <p>
* Based on code contributed by Amit Pitaru, plus additional code to handle
* Java versions via reflection by Jonathan Feinberg. Reflection removed for
* release 0128 and later.
*
* @webref environment
* @webBrief Sets the cursor to a predefined symbol, an image, or makes it
* visible if already hidden
@@ -4072,18 +3976,6 @@ public class PApplet implements PConstants {
}
/*
static public void print(Object what) {
if (what == null) {
// special case since this does fuggly things on > 1.1
System.out.print("null");
} else {
System.out.println(what.toString());
}
}
*/
/**
*
* The <b>println()</b> function writes to the console area, the black
@@ -4219,7 +4111,7 @@ public class PApplet implements PConstants {
*/
static public void printArray(Object what) {
if (what == null) {
// special case since this does fuggly things on > 1.1
// special case since this does fugly things on > 1.1
System.out.println("null");
} else {
@@ -5274,7 +5166,7 @@ public class PApplet implements PConstants {
// [toxi 040903]
// make perlin noise quality user controlled to allow
// for different levels of detail. lower values will produce
// smoother results as higher octaves are surpressed
// smoother results as higher octaves are suppressed
/**
*
@@ -5486,26 +5378,6 @@ public class PApplet implements PConstants {
// DATA I/O
// /**
// * @webref input:files
// * @brief Creates a new XML object
// * @param name the name to be given to the root element of the new XML object
// * @return an XML object, or null
// * @see XML
// * @see PApplet#loadXML(String)
// * @see PApplet#parseXML(String)
// * @see PApplet#saveXML(XML, String)
// */
// public XML createXML(String name) {
// try {
// return new XML(name);
// } catch (Exception e) {
// e.printStackTrace();
// return null;
// }
// }
/**
* Reads the contents of a file or URL and creates an XML
* object with its values. If a file is specified, it must
@@ -5854,18 +5726,6 @@ public class PApplet implements PConstants {
}
// /**
// * @webref input:files
// * @see Table
// * @see PApplet#loadTable(String)
// * @see PApplet#saveTable(Table, String)
// */
// public Table createTable() {
// return new Table();
// }
/**
* Reads the contents of a file or URL and creates an Table object with its
* values. If a file is specified, it must be located in the sketch's "data"
@@ -6086,7 +5946,7 @@ public class PApplet implements PConstants {
* distributed should be included with a sketch.<br />
* <br />
* The <b>size</b> parameter states the font size you want to generate. The
* <b>smooth</b> parameter specifies if the font should be antialiased or not.
* <b>smooth</b> parameter specifies if the font should be anti-aliased or not.
* The <b>charset</b> parameter is an array of chars that specifies the
* characters to generate.<br />
* <br />
@@ -6108,7 +5968,7 @@ public class PApplet implements PConstants {
* @param size
* point size of the font
* @param smooth
* true for an antialiased font, false for aliased
* true for an anti-aliased font, false for aliased
* @param charset
* array containing characters to be generated
* @see PFont
@@ -6131,32 +5991,6 @@ public class PApplet implements PConstants {
// FILE/FOLDER SELECTION
/*
private Frame selectFrame;
private Frame selectFrame() {
if (frame != null) {
selectFrame = frame;
} else if (selectFrame == null) {
Component comp = getParent();
while (comp != null) {
if (comp instanceof Frame) {
selectFrame = (Frame) comp;
break;
}
comp = comp.getParent();
}
// Who you callin' a hack?
if (selectFrame == null) {
selectFrame = new Frame();
}
}
return selectFrame;
}
*/
/**
* Open a platform-specific file chooser dialog to select a file for input.
* After the selection is made, the selected File will be passed to the
@@ -6174,7 +6008,7 @@ public class PApplet implements PConstants {
* if (selection == null) {
* println("Window was closed or the user hit cancel.");
* } else {
* println("User selected " + fileSeleted.getAbsolutePath());
* println("User selected " + fileSelected.getAbsolutePath());
* }
* }
* </pre>
@@ -6499,7 +6333,8 @@ public class PApplet implements PConstants {
files = false;
} else if (opt.equals("hidden")) {
hidden = true;
} else if (opt.equals("relative")) {
} else //noinspection StatementWithEmptyBody
if (opt.equals("relative")) {
// ignored
} else {
throw new RuntimeException(opt + " is not a listFiles() option");
@@ -6575,7 +6410,7 @@ public class PApplet implements PConstants {
*/
static public String checkExtension(String filename) {
// Don't consider the .gz as part of the name, createInput()
// and createOuput() will take care of fixing that up.
// and createOutput() will take care of fixing that up.
if (filename.toLowerCase().endsWith(".gz")) {
filename = filename.substring(0, filename.length() - 3);
}
@@ -7773,7 +7608,7 @@ public class PApplet implements PConstants {
if (platform == WINDOWS && !disableAWT) {
desktopFolder = ShimAWT.getWindowsDesktop();
} else {
throw new UnsupportedOperationException("Could not find a suitable Desktop foldder");
throw new UnsupportedOperationException("Could not find a suitable Desktop folder");
}
}
}
@@ -8032,6 +7867,7 @@ public class PApplet implements PConstants {
* number of array elements to be copied
* @see PApplet#concat(boolean[], boolean[])
*/
@SuppressWarnings("SuspiciousSystemArraycopy")
static public void arrayCopy(Object src, int srcPosition,
Object dst, int dstPosition,
int length) {
@@ -8042,6 +7878,7 @@ public class PApplet implements PConstants {
* Convenience method for arraycopy().
* Identical to <CODE>arraycopy(src, 0, dst, 0, length);</CODE>
*/
@SuppressWarnings("SuspiciousSystemArraycopy")
static public void arrayCopy(Object src, Object dst, int length) {
System.arraycopy(src, 0, dst, 0, length);
}
@@ -8051,6 +7888,7 @@ public class PApplet implements PConstants {
* the source into the destination array.
* Identical to <CODE>arraycopy(src, 0, dst, 0, src.length);</CODE>
*/
@SuppressWarnings("SuspiciousSystemArraycopy")
static public void arrayCopy(Object src, Object dst) {
System.arraycopy(src, 0, dst, 0, Array.getLength(src));
}
@@ -8058,6 +7896,7 @@ public class PApplet implements PConstants {
/**
* Use arrayCopy() instead.
*/
@SuppressWarnings("SuspiciousSystemArraycopy")
@Deprecated
static public void arraycopy(Object src, int srcPosition,
Object dst, int dstPosition,
@@ -8068,6 +7907,7 @@ public class PApplet implements PConstants {
/**
* Use arrayCopy() instead.
*/
@SuppressWarnings("SuspiciousSystemArraycopy")
@Deprecated
static public void arraycopy(Object src, Object dst, int length) {
System.arraycopy(src, 0, dst, 0, length);
@@ -8076,6 +7916,7 @@ public class PApplet implements PConstants {
/**
* Use arrayCopy() instead.
*/
@SuppressWarnings("SuspiciousSystemArraycopy")
@Deprecated
static public void arraycopy(Object src, Object dst) {
System.arraycopy(src, 0, dst, 0, Array.getLength(src));
@@ -8191,6 +8032,7 @@ public class PApplet implements PConstants {
return expand(array, len > 0 ? len << 1 : 1);
}
@SuppressWarnings("SuspiciousSystemArraycopy")
static public Object expand(Object list, int newSize) {
Class<?> type = list.getClass().getComponentType();
Object temp = Array.newInstance(type, newSize);
@@ -8449,9 +8291,10 @@ public class PApplet implements PConstants {
return outgoing;
}
@SuppressWarnings("SuspiciousSystemArraycopy")
static final public Object splice(Object list, Object value, int index) {
Class<?> type = list.getClass().getComponentType();
Object outgoing = null;
Object outgoing;
int length = Array.getLength(list);
// check whether item being spliced in is an array
@@ -8598,6 +8441,7 @@ public class PApplet implements PConstants {
}
@SuppressWarnings("SuspiciousSystemArraycopy")
static public Object subset(Object list, int start, int count) {
Class<?> type = list.getClass().getComponentType();
Object outgoing = Array.newInstance(type, count);
@@ -8667,6 +8511,7 @@ public class PApplet implements PConstants {
return c;
}
@SuppressWarnings("SuspiciousSystemArraycopy")
static public Object concat(Object a, Object b) {
Class<?> type = a.getClass().getComponentType();
int alength = Array.getLength(a);
@@ -8892,7 +8737,7 @@ public class PApplet implements PConstants {
* parameter divides the <b>str</b> parameter. Therefore, if you use
* characters such parentheses and brackets that are used with regular
* expressions as a part of the <b>delim</b> parameter, you'll need to put two
* blackslashes (\\\\) in front of the character (see example above). You can
* backslashes (\\\\) in front of the character (see example above). You can
* read more about
* <a href="http://en.wikipedia.org/wiki/Regular_expression">regular
* expressions</a> and
@@ -8921,7 +8766,7 @@ public class PApplet implements PConstants {
}
// make sure that there is something in the input string
//if (chars.length > 0) {
// if the last char is a delimeter, get rid of it..
// if the last char is a delimiter, get rid of it..
//if (chars[chars.length-1] == delim) splitCount--;
// on second thought, i don't agree with this, will disable
//}
@@ -9223,8 +9068,8 @@ public class PApplet implements PConstants {
return outgoing;
}
static final public char[] parseChar(int what[]) {
char outgoing[] = new char[what.length];
static final public char[] parseChar(int[] what) {
char[] outgoing = new char[what.length];
for (int i = 0; i < what.length; i++) {
outgoing[i] = (char) what[i];
}
@@ -9294,7 +9139,7 @@ public class PApplet implements PConstants {
return list;
}
static final public int[] parseInt(byte[] what) { // note this unsigns
static final public int[] parseInt(byte[] what) { // note this un-signs
int[] list = new int[what.length];
for (int i = 0; i < what.length; i++) {
list[i] = (what[i] & 0xff);
@@ -9468,6 +9313,7 @@ public class PApplet implements PConstants {
// INT NUMBER FORMATTING
static public String nf(float num) {
int inum = (int) num;
if (num == inum) {
@@ -9476,6 +9322,7 @@ public class PApplet implements PConstants {
return str(num);
}
static public String[] nf(float[] nums) {
String[] outgoing = new String[nums.length];
for (int i = 0; i < nums.length; i++) {
@@ -9484,16 +9331,16 @@ public class PApplet implements PConstants {
return outgoing;
}
/**
* Integer number formatter.
*/
static private NumberFormat int_nf;
static private int int_nf_digits;
static private boolean int_nf_commas;
/**
*
* Utility function for formatting numbers into strings. There are two
* versions: one for formatting floats, and one for formatting ints. The
* values for the <b>digits</b> and <b>right</b> parameters should always be
@@ -9517,7 +9364,6 @@ public class PApplet implements PConstants {
* @see <a href=
* "https://processing.org/reference/intconvert_.html">int(float)</a>
*/
static public String[] nf(int[] nums, int digits) {
String[] formatted = new String[nums.length];
for (int i = 0; i < formatted.length; i++) {
@@ -9526,6 +9372,7 @@ public class PApplet implements PConstants {
return formatted;
}
/**
* @param num the number to format
*/
@@ -9544,8 +9391,8 @@ public class PApplet implements PConstants {
return int_nf.format(num);
}
/**
*
* Utility function for formatting numbers into strings and placing
* appropriate commas to mark units of 1000. There are four versions: one for
* formatting ints, one for formatting an array of ints, one for formatting
@@ -9554,8 +9401,8 @@ public class PApplet implements PConstants {
* The value for the <b>right</b> parameter should always be a positive
* integer.<br />
* <br />
* For a non-US locale, this will insert periods instead of commas, or
* whatever is apprioriate for that region.
* For a non-US locale, this will insert periods instead of commas,
* or whatever is appropriate for that region.
*
* @webref data:string_functions
* @webBrief Utility function for formatting numbers into strings and placing
@@ -9595,14 +9442,6 @@ public class PApplet implements PConstants {
/**
* number format signed (or space)
* Formats a number but leaves a blank space in the front
* when it's positive so that it can be properly aligned with
* numbers that have a negative sign in front of them.
*/
/**
*
* Utility function for formatting numbers into strings. Similar to
* <b>nf()</b> but leaves a blank space in front of positive numbers so
* they align with negative numbers in spite of the minus symbol. There are
@@ -9610,18 +9449,19 @@ public class PApplet implements PConstants {
* values for the <b>digits</b>, <b>left</b>, and <b>right</b> parameters
* should always be positive integers.
*
* @webref data:string_functions
* @webBrief Utility function for formatting numbers into strings
* @param num the number to format
* @param digits number of digits to pad with zeroes
* @see PApplet#nf(float, int, int)
* @see PApplet#nfp(float, int, int)
* @see PApplet#nfc(float, int)
*/
* @webref data:string_functions
* @webBrief Utility function for formatting numbers into strings
* @param num the number to format
* @param digits number of digits to pad with zeroes
* @see PApplet#nf(float, int, int)
* @see PApplet#nfp(float, int, int)
* @see PApplet#nfc(float, int)
*/
static public String nfs(int num, int digits) {
return (num < 0) ? nf(num, digits) : (' ' + nf(num, digits));
}
/**
* @param nums the numbers to format
*/
@@ -9633,15 +9473,8 @@ public class PApplet implements PConstants {
return formatted;
}
//
/**
* number format positive (or plus)
* Formats a number, always placing a - or + sign
* in the front when it's negative or positive.
*/
/**
*
* Utility function for formatting numbers into strings. Similar to <b>nf()</b>
* but puts a "+" in front of positive numbers and a "-" in front of negative
* numbers. There are two versions: one for formatting floats, and one for
@@ -9661,6 +9494,8 @@ public class PApplet implements PConstants {
static public String nfp(int num, int digits) {
return (num < 0) ? nf(num, digits) : ('+' + nf(num, digits));
}
/**
* @param nums the numbers to format
*/
@@ -10185,7 +10020,7 @@ public class PApplet implements PConstants {
* <PRE>
* Parameters useful for launching or also used by the PDE:
*
* --location=x,y Upper-lefthand corner of where the applet
* --location=x,y Upper left-hand corner of where the applet
* should appear on screen. If not used,
* the default is to center on the main screen.
*
@@ -10224,7 +10059,7 @@ public class PApplet implements PConstants {
*
* --external set when the applet is being used by the PDE
*
* --editor-location=x,y position of the upper-lefthand corner of the
* --editor-location=x,y position of the upper left-hand corner of the
* editor window, for placement of applet window
*
* All parameters *after* the sketch class name are passed to the sketch
@@ -10281,11 +10116,9 @@ public class PApplet implements PConstants {
// also suspecting that these "not showing up" bugs might be EDT issues.
static public void runSketch(final String[] args,
final PApplet constructedSketch) {
Thread.setDefaultUncaughtExceptionHandler(new Thread.UncaughtExceptionHandler() {
public void uncaughtException(Thread t, Throwable e) {
e.printStackTrace();
uncaughtThrowable = e;
}
Thread.setDefaultUncaughtExceptionHandler((t, e) -> {
e.printStackTrace();
uncaughtThrowable = e;
});
// This doesn't work, need to mess with Info.plist instead
@@ -10333,7 +10166,7 @@ public class PApplet implements PConstants {
// boolean spanDisplays = false;
int density = -1;
String param = null, value = null;
String param, value;
String folder = calcSketchPath();
int argIndex = 0;
@@ -10789,15 +10622,6 @@ public class PApplet implements PConstants {
}
/**
* Starts shape recording and returns the PShape object that will
* contain the geometry.
*/
/*
public PShape beginRecord() {
return g.beginRecord();
}
*/
//////////////////////////////////////////////////////////////
@@ -13478,7 +13302,6 @@ public class PApplet implements PConstants {
* @webref transform
* @webBrief Multiplies the current matrix by the one specified through the
* parameters
* @source
* @see PGraphics#pushMatrix()
* @see PGraphics#popMatrix()
* @see PGraphics#resetMatrix()
+8 -3
View File
@@ -4237,15 +4237,20 @@ public class PGraphics extends PImage implements PConstants {
* Used by PGraphics to remove the requirement for loading a font.
*/
protected PFont createDefaultFont(float size) {
Font baseFont;
Font baseFont = null;
try {
// For 4.0 alpha 4 and later, include a built-in font
InputStream input = getClass().getResourceAsStream("/font/ProcessingSansPro-Regular.ttf");
baseFont = Font.createFont(Font.TRUETYPE_FONT, input);
if (input != null) {
baseFont = Font.createFont(Font.TRUETYPE_FONT, input);
}
} catch (Exception e) {
// Fall back to how this was handled in 3.x, ugly!
e.printStackTrace(); // dammit
}
if (baseFont == null) {
baseFont = new Font("Lucida Sans", Font.PLAIN, 1);
}
// Create a PFont from this java.awt.Font
@@ -5770,7 +5775,6 @@ public class PGraphics extends PImage implements PConstants {
* @webref transform
* @webBrief Multiplies the current matrix by the one specified through the
* parameters
* @source
* @see PGraphics#pushMatrix()
* @see PGraphics#popMatrix()
* @see PGraphics#resetMatrix()
@@ -8592,6 +8596,7 @@ public class PGraphics extends PImage implements PConstants {
public void dispose() { // ignore
saveExecutor.shutdown();
try {
//noinspection ResultOfMethodCallIgnored
saveExecutor.awaitTermination(5000, TimeUnit.SECONDS);
} catch (InterruptedException ignored) { }
}