Skip to content

Commit daf1c06

Browse files
committed
ongoing work for core reworking
1 parent 36fef87 commit daf1c06

5 files changed

Lines changed: 148 additions & 130 deletions

File tree

core/README.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,8 @@ inside main, will know the screen that's being used for the app
5555
- The size() JavaDoc in PApplet is comically old
5656
- Does createFont() need to run through PGraphics?
5757
- Need to fix sketch placement issues (default size with long setup(), etc) Actually, the default size with long setup() is probably that defaultSize is set false, but the initial render doesn't finish before width/height are set to something useful.
58+
- selectInput(), selectOutput(), selectFolder() now passing 'null' as parent Window. Should just leave them un-anchored, but need to test to make this doesn't break anything else.
59+
- do we need sketchOutputPath() and sketchOutputStream()?
5860

5961
#### Removed functions (not final, just notes)
6062
param()

core/src/processing/core/PApplet.java

Lines changed: 113 additions & 102 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.awt.Desktop;
3131
import java.awt.EventQueue;
3232
import java.awt.FileDialog;
33+
import java.awt.Font;
3334
// for the Frame object (deprecate?)
3435
import java.awt.Frame;
3536
import java.awt.GraphicsConfiguration;
@@ -54,7 +55,6 @@
5455
// used by loadImage() functions
5556
import javax.imageio.ImageIO;
5657
import javax.swing.ImageIcon;
57-
5858
import javax.swing.JFrame;
5959
import javax.swing.JFileChooser;
6060
import javax.swing.filechooser.FileSystemView;
@@ -788,6 +788,16 @@ public boolean sketchSpanScreens() {
788788
}
789789

790790

791+
public String sketchOutputPath() {
792+
return null;
793+
}
794+
795+
796+
public OutputStream sketchOutputStream() {
797+
return null;
798+
}
799+
800+
791801
public void orientation(int which) {
792802
// ignore calls to the orientation command
793803
}
@@ -1336,6 +1346,7 @@ public void draw() {
13361346
//////////////////////////////////////////////////////////////
13371347

13381348

1349+
/*
13391350
protected void resizeRenderer(int newWidth, int newHeight) {
13401351
debug("resizeRenderer request for " + newWidth + " " + newHeight);
13411352
if (width != newWidth || height != newHeight) {
@@ -1345,6 +1356,7 @@ protected void resizeRenderer(int newWidth, int newHeight) {
13451356
height = newHeight;
13461357
}
13471358
}
1359+
*/
13481360

13491361

13501362
/**
@@ -1435,49 +1447,58 @@ public void size(int w, int h, String renderer) {
14351447
/**
14361448
* @nowebref
14371449
*/
1438-
public void size(final int w, final int h,
1439-
String renderer, String path) {
1440-
// Run this from the EDT, just cuz it's AWT stuff (or maybe later Swing)
1441-
EventQueue.invokeLater(new Runnable() {
1442-
public void run() {
1443-
// Set the preferred size so that the layout managers can handle it
1444-
setPreferredSize(new Dimension(w, h));
1445-
setSize(w, h);
1446-
}
1447-
});
1448-
1449-
// ensure that this is an absolute path
1450-
if (path != null) path = savePath(path);
1451-
1452-
String currentRenderer = g.getClass().getName();
1453-
if (currentRenderer.equals(renderer)) {
1454-
// // Avoid infinite loop of throwing exception to reset renderer
1455-
// resizeRenderer(w, h);
1456-
surface.setSize(w, h);
1457-
1458-
} else { // renderer change attempted
1459-
// no longer kosher with 3.0a5
1460-
throw new RuntimeException("Y'all need to implement sketchRenderer()");
1461-
/*
1462-
// otherwise ok to fall through and create renderer below
1463-
// the renderer is changing, so need to create a new object
1464-
g = makeGraphics(w, h, renderer, path, true);
1465-
this.width = w;
1466-
this.height = h;
1467-
1468-
// fire resize event to make sure the applet is the proper size
1469-
// setSize(iwidth, iheight);
1470-
// this is the function that will run if the user does their own
1471-
// size() command inside setup, so set defaultSize to false.
1472-
defaultSize = false;
1473-
1474-
// throw an exception so that setup() is called again
1475-
// but with a properly sized render
1476-
// this is for opengl, which needs a valid, properly sized
1477-
// display before calling anything inside setup().
1478-
throw new RendererChangeException();
1479-
*/
1480-
}
1450+
public void size(final int w, final int h, String renderer, String path) {
1451+
if (!renderer.equals(sketchRenderer())) {
1452+
System.err.println("Because you're not running from the PDE, add this to your code:");
1453+
System.err.println("public String sketchRenderer() {");
1454+
System.err.println(" return " + renderer + ";");
1455+
System.err.println("}");
1456+
throw new RuntimeException("The sketchRenderer() method is not implemented.");
1457+
}
1458+
surface.setSize(w, h);
1459+
g.setPath(path); // finally, a path
1460+
1461+
// // Run this from the EDT, just cuz it's AWT stuff (or maybe later Swing)
1462+
// EventQueue.invokeLater(new Runnable() {
1463+
// public void run() {
1464+
// // Set the preferred size so that the layout managers can handle it
1465+
// setPreferredSize(new Dimension(w, h));
1466+
// setSize(w, h);
1467+
// }
1468+
// });
1469+
//
1470+
// // ensure that this is an absolute path
1471+
// if (path != null) path = savePath(path);
1472+
//
1473+
// String currentRenderer = g.getClass().getName();
1474+
// if (currentRenderer.equals(renderer)) {
1475+
//// // Avoid infinite loop of throwing exception to reset renderer
1476+
//// resizeRenderer(w, h);
1477+
// surface.setSize(w, h);
1478+
//
1479+
// } else { // renderer change attempted
1480+
// // no longer kosher with 3.0a5
1481+
// throw new RuntimeException("Y'all need to implement sketchRenderer()");
1482+
// /*
1483+
// // otherwise ok to fall through and create renderer below
1484+
// // the renderer is changing, so need to create a new object
1485+
// g = makeGraphics(w, h, renderer, path, true);
1486+
// this.width = w;
1487+
// this.height = h;
1488+
//
1489+
// // fire resize event to make sure the applet is the proper size
1490+
//// setSize(iwidth, iheight);
1491+
// // this is the function that will run if the user does their own
1492+
// // size() command inside setup, so set defaultSize to false.
1493+
// defaultSize = false;
1494+
//
1495+
// // throw an exception so that setup() is called again
1496+
// // but with a properly sized render
1497+
// // this is for opengl, which needs a valid, properly sized
1498+
// // display before calling anything inside setup().
1499+
// throw new RendererChangeException();
1500+
// */
1501+
// }
14811502
}
14821503

14831504

@@ -1585,17 +1606,22 @@ public PGraphics createGraphics(int w, int h,
15851606
}
15861607

15871608

1588-
/**
1589-
* Version of createGraphics() used internally.
1590-
*/
1609+
public PGraphics makePrimaryGraphics(int wide, int high) {
1610+
return makeGraphics(wide, high, sketchRenderer(), null, true);
1611+
}
1612+
1613+
1614+
/** Version of createGraphics() used internally. */
15911615
protected PGraphics makeGraphics(int w, int h,
15921616
String renderer, String path,
15931617
boolean primary) {
1594-
String openglError = external ?
1595-
"Before using OpenGL, first select " +
1596-
"Import Library > OpenGL from the Sketch menu." :
1597-
"The Java classpath and native library path is not " + // welcome to Java programming!
1598-
"properly set for using the OpenGL library.";
1618+
// String openglError = external ?
1619+
// // This first one should no longer be possible
1620+
// "Before using OpenGL, first select " +
1621+
// "Import Library > OpenGL from the Sketch menu." :
1622+
// // Welcome to Java programming! The training wheels are off.
1623+
// "The Java classpath and native library path is not " +
1624+
// "properly set for using the OpenGL library.";
15991625

16001626
if (!primary && !g.isGL()) {
16011627
if (renderer.equals(P2D)) {
@@ -1625,26 +1651,30 @@ protected PGraphics makeGraphics(int w, int h,
16251651
String msg = ite.getTargetException().getMessage();
16261652
if ((msg != null) &&
16271653
(msg.indexOf("no jogl in java.library.path") != -1)) {
1628-
throw new RuntimeException(openglError +
1629-
" (The native library is missing.)");
1654+
// Is this true anymore, since the JARs contain the native libs?
1655+
throw new RuntimeException("The jogl library folder needs to be " +
1656+
"specified with -Djava.library.path=/path/to/jogl");
1657+
16301658
} else {
16311659
ite.getTargetException().printStackTrace();
16321660
Throwable target = ite.getTargetException();
1633-
if (platform == MACOSX) target.printStackTrace(System.out); // bug
1634-
// neither of these help, or work
1635-
//target.printStackTrace(System.err);
1636-
//System.err.flush();
1637-
//System.out.println(System.err); // and the object isn't null
1661+
if (platform == MACOSX) {
1662+
target.printStackTrace(System.out); // OS X bug (still true?)
1663+
}
16381664
throw new RuntimeException(target.getMessage());
16391665
}
16401666

16411667
} catch (ClassNotFoundException cnfe) {
1642-
if (cnfe.getMessage().indexOf("processing.opengl.PGraphicsOpenGL") != -1) {
1643-
throw new RuntimeException(openglError +
1644-
" (The library .jar file is missing.)");
1645-
} else {
1668+
// if (cnfe.getMessage().indexOf("processing.opengl.PGraphicsOpenGL") != -1) {
1669+
// throw new RuntimeException(openglError +
1670+
// " (The library .jar file is missing.)");
1671+
// } else {
1672+
if (external) {
16461673
throw new RuntimeException("You need to use \"Import Library\" " +
16471674
"to add " + renderer + " to your sketch.");
1675+
} else {
1676+
throw new RuntimeException("The " + renderer +
1677+
" renderer is not in the class path.");
16481678
}
16491679

16501680
} catch (Exception e) {
@@ -1663,7 +1693,9 @@ protected PGraphics makeGraphics(int w, int h,
16631693
throw new RuntimeException(msg);
16641694
}
16651695
} else {
1666-
if (platform == MACOSX) e.printStackTrace(System.out);
1696+
if (platform == MACOSX) {
1697+
e.printStackTrace(System.out); // OS X bug (still true?)
1698+
}
16671699
throw new RuntimeException(e.getMessage());
16681700
}
16691701
}
@@ -1732,7 +1764,8 @@ public void handleDraw() {
17321764
long now = System.nanoTime();
17331765

17341766
if (frameCount == 0) {
1735-
surface.checkDisplaySize();
1767+
// 3.0a5 should be no longer needed; handled by PSurface
1768+
//surface.checkDisplaySize();
17361769

17371770
// try {
17381771
//println("Calling setup()");
@@ -5466,6 +5499,7 @@ public PFont createFont(String name, float size,
54665499
// FILE/FOLDER SELECTION
54675500

54685501

5502+
/*
54695503
private Frame selectFrame;
54705504
54715505
private Frame selectFrame() {
@@ -5488,6 +5522,7 @@ private Frame selectFrame() {
54885522
}
54895523
return selectFrame;
54905524
}
5525+
*/
54915526

54925527

54935528
/**
@@ -5531,7 +5566,7 @@ public void selectInput(String prompt, String callback, File file) {
55315566

55325567
public void selectInput(String prompt, String callback,
55335568
File file, Object callbackObject) {
5534-
selectInput(prompt, callback, file, callbackObject, selectFrame());
5569+
selectInput(prompt, callback, file, callbackObject, null); //selectFrame());
55355570
}
55365571

55375572

@@ -5559,7 +5594,7 @@ public void selectOutput(String prompt, String callback, File file) {
55595594

55605595
public void selectOutput(String prompt, String callback,
55615596
File file, Object callbackObject) {
5562-
selectOutput(prompt, callback, file, callbackObject, selectFrame());
5597+
selectOutput(prompt, callback, file, callbackObject, null); //selectFrame());
55635598
}
55645599

55655600

@@ -5634,7 +5669,7 @@ public void selectFolder(String prompt, String callback, File file) {
56345669

56355670
public void selectFolder(String prompt, String callback,
56365671
File file, Object callbackObject) {
5637-
selectFolder(prompt, callback, file, callbackObject, selectFrame());
5672+
selectFolder(prompt, callback, file, callbackObject, null); //selectFrame());
56385673
}
56395674

56405675

@@ -6081,34 +6116,6 @@ public InputStream createInputRaw(String filename) {
60816116
}
60826117
}
60836118

6084-
// Finally, something special for the Internet Explorer users. Turns out
6085-
// that we can't get files that are part of the same folder using the
6086-
// methods above when using IE, so we have to resort to the old skool
6087-
// getDocumentBase() from teh applet dayz. 1996, my brotha.
6088-
try {
6089-
URL base = getDocumentBase();
6090-
if (base != null) {
6091-
URL url = new URL(base, filename);
6092-
URLConnection conn = url.openConnection();
6093-
return conn.getInputStream();
6094-
// if (conn instanceof HttpURLConnection) {
6095-
// HttpURLConnection httpConnection = (HttpURLConnection) conn;
6096-
// // test for 401 result (HTTP only)
6097-
// int responseCode = httpConnection.getResponseCode();
6098-
// }
6099-
}
6100-
} catch (Exception e) { } // IO or NPE or...
6101-
6102-
// Now try it with a 'data' subfolder. getting kinda desperate for data...
6103-
try {
6104-
URL base = getDocumentBase();
6105-
if (base != null) {
6106-
URL url = new URL(base, "data/" + filename);
6107-
URLConnection conn = url.openConnection();
6108-
return conn.getInputStream();
6109-
}
6110-
} catch (Exception e) { }
6111-
61126119
try {
61136120
// attempt to load from a local file, used when running as
61146121
// an application, or as a signed applet
@@ -9266,11 +9273,15 @@ static public void runSketch(final String args[], final PApplet constructedApple
92669273
}
92679274
}
92689275

9269-
String renderer = applet.sketchRenderer();
9270-
Class<?> rendererClass =
9271-
Thread.currentThread().getContextClassLoader().loadClass(renderer);
9272-
Method surfaceMethod = rendererClass.getMethod("createSurface");
9273-
PSurface surface = (PSurface) surfaceMethod.invoke(null, new Object[] { });
9276+
try {
9277+
String renderer = applet.sketchRenderer();
9278+
Class<?> rendererClass =
9279+
Thread.currentThread().getContextClassLoader().loadClass(renderer);
9280+
Method surfaceMethod = rendererClass.getMethod("createSurface");
9281+
PSurface surface = (PSurface) surfaceMethod.invoke(null, new Object[] { });
9282+
} catch (Exception e) {
9283+
throw new RuntimeException(e);
9284+
}
92749285

92759286
// A handful of things that need to be set before init/start.
92769287
applet.sketchPath = folder;
@@ -9319,7 +9330,7 @@ static public void runSketch(final String args[], final PApplet constructedApple
93199330
}
93209331
surface.placePresent(stopColor);
93219332
} else {
9322-
surface.placeWindow();
9333+
surface.placeWindow(external, location, editorLocation);
93239334
}
93249335
// not always running externally when in present mode
93259336
if (external) {

0 commit comments

Comments
 (0)