From df45798d9c66dd58ecf6306ba5f705979db62990 Mon Sep 17 00:00:00 2001 From: benfry Date: Fri, 16 Jul 2004 06:32:00 +0000 Subject: [PATCH] move location of prefs and sketchbook, fixed nasty bugs --- app/PdePreferences.java | 28 +++++++++++++++++++++++++--- app/PdePreprocessor.java | 6 +++++- app/PdeRuntime.java | 6 +++++- app/PdeSketchbook.java | 4 ++++ core/PApplet.java | 34 ++++++++++++++++------------------ todo.txt | 9 +++++---- 6 files changed, 60 insertions(+), 27 deletions(-) diff --git a/app/PdePreferences.java b/app/PdePreferences.java index 18948d888..bd7b4967b 100644 --- a/app/PdePreferences.java +++ b/app/PdePreferences.java @@ -56,7 +56,7 @@ public class PdePreferences extends JComponent { // what to call the feller - static final String PREFS_FILE = "Processing Preferences.txt"; + static final String PREFS_FILE = "preferences.txt"; // prompt text stuff @@ -143,8 +143,10 @@ public class PdePreferences extends JComponent { // next load user preferences file - File home = new File(System.getProperty("user.home")); - preferencesFile = new File(home, PREFS_FILE); + //File home = new File(System.getProperty("user.home")); + //File processingHome = new File(home, "Processing"); + //preferencesFile = new File(home, PREFS_FILE); + preferencesFile = new File(getProcessingHome(), PREFS_FILE); if (!preferencesFile.exists()) { // create a new preferences file if none exists @@ -512,6 +514,26 @@ public class PdePreferences extends JComponent { // ................................................................. + static public File getProcessingHome() { + File home = new File(System.getProperty("user.home")); + + if (PdeBase.platform == PdeBase.MACOSX) { + // on macosx put the sketchbook in the "Documents" folder + return new File(home, "Documents" + File.separator + "Processing"); + + } else if (PdeBase.platform == PdeBase.WINDOWS) { + // on windows put the sketchbook in the "My Documents" folder + return new File(home, "My Documents" + File.separator + "Processing"); + } + + // all others, just say home directory + return new File(home, "processing"); + } + + + // ................................................................. + + // all the information from preferences.txt //static public String get(String attribute) { diff --git a/app/PdePreprocessor.java b/app/PdePreprocessor.java index 4a82ff9b9..e7f75dc6b 100644 --- a/app/PdePreprocessor.java +++ b/app/PdePreprocessor.java @@ -262,7 +262,11 @@ public class PdePreprocessor { if (programType == STATIC) { // now that size() and background() can go inside of draw() - out.print("public void draw() {"); + // actually, use setup(), because when running externally + // the applet size needs to be set before the window is drawn, + // meaning that after setup() things need to be ducky. + //out.print("public void draw() {"); + out.print("public void setup() {"); } } } diff --git a/app/PdeRuntime.java b/app/PdeRuntime.java index 1b49ac54c..cf725d472 100644 --- a/app/PdeRuntime.java +++ b/app/PdeRuntime.java @@ -88,7 +88,6 @@ public class PdeRuntime implements PdeMessageConsumer { windowLocation.x + "," + windowLocation.y) : (PApplet.EXT_LOCATION + x1 + "," + y1); - //java "-Djava.library.path=C:\Documents and Settings\fry\My Documents\sketchbook\image_loading_problems\code" -cp "lib\build;java\lib\rt.jar;lib;lib\build;lib\pde.jar;lib\core.jar;lib\mrj.jar;lib\antlr.jar;lib\oro.jar;C:\WINDOWS\system32\QTJava.zip;;C:\Documents and Settings\fry\My Documents\sketchbook\image_loading_problems\code" processing.core.PApplet --location=710,61 "--sketch-folder=C:\Documents and Settings\fry\My Documents\sketchbook\image_loading_problems" Temporary_6879_7583 String command[] = new String[] { "java", "-Djava.library.path=" + sketch.libraryPath, // might be "" @@ -130,6 +129,10 @@ public class PdeRuntime implements PdeMessageConsumer { } applet.start(); + /* + // appears to be no longer necessary now that draw() + // is gonna be run inside of setup() + // check to see if it's a draw mode applet boolean drawMode = false; try { @@ -152,6 +155,7 @@ public class PdeRuntime implements PdeMessageConsumer { } catch (InterruptedException e) { } } } + */ if (editor.presenting) { //window = new Window(new Frame()); diff --git a/app/PdeSketchbook.java b/app/PdeSketchbook.java index dbb25316e..36fff2cb2 100644 --- a/app/PdeSketchbook.java +++ b/app/PdeSketchbook.java @@ -74,6 +74,8 @@ public class PdeSketchbook { if (PdePreferences.get("sketchbook.path") == null) { // by default, set default sketchbook path to the user's // home folder with 'sketchbook' as a subdirectory of that + + /* File home = new File(System.getProperty("user.home")); if (PdeBase.platform == PdeBase.MACOSX) { @@ -84,6 +86,8 @@ public class PdeSketchbook { // on windows put the sketchbook in the "My Documents" folder home = new File(home, "My Documents"); } + */ + File home = PdePreferences.getProcessingHome(); String folderName = PdePreferences.get("sketchbook.name.default"); //System.out.println("home = " + home); diff --git a/core/PApplet.java b/core/PApplet.java index 1093a4520..aa32b6177 100644 --- a/core/PApplet.java +++ b/core/PApplet.java @@ -147,6 +147,7 @@ public class PApplet extends Applet static public final String EXTERNAL_MOVE = "__MOVE__"; //boolean externalRuntime; + //static boolean setupComplete = false; public void init() { //checkParams(); @@ -199,6 +200,8 @@ public class PApplet extends Applet this.height = g.height; //g.applet = this; + //setupComplete = true; + try { getAppletContext(); online = true; @@ -297,6 +300,8 @@ public class PApplet extends Applet public void size(int iwidth, int iheight) { + //width = iwidth; + //height = iheight; //if (g != null) return; // would this ever happen? is this a good idea? g.resize(iwidth, iheight); @@ -1545,16 +1550,15 @@ public class PApplet extends Applet gimmeImage(getClass().getResource("data/" + filename), force); } if (awtimage == null) { - /* try { //FileInputStream fis = //new FileInputStream(folder + "data/" + filename); - URL url = new URL("file:/" + folder + "data/" + filename); - awtimage = gimmeImage(url, force); + String url = "file:/" + folder + "/data/" + filename; + //URL url = new URL("file:/" + folder + "data/" + filename); + awtimage = gimmeImage(new URL(url), force); } catch (IOException e) { e.printStackTrace(); } - */ } } if (awtimage == null) { @@ -2856,7 +2860,7 @@ public class PApplet extends Applet } else if (args[argIndex].indexOf(EXT_EXACT_LOCATION) == 0) { external = true; String locationStr = - args[argIndex].substring(EXT_LOCATION.length()); + args[argIndex].substring(EXT_EXACT_LOCATION.length()); location = toInt(split(locationStr, ',')); exactLocation = true; @@ -2871,13 +2875,13 @@ public class PApplet extends Applet } Frame frame = new Frame(); - frame.pack(); // maybe get insets + frame.pack(); // get insets. get more. Class c = Class.forName(name); PApplet applet = (PApplet) c.newInstance(); // these are needed before init/start applet.folder = folder; - int argc = args.length - argIndex; + int argc = args.length - (argIndex+1); applet.args = new String[argc]; System.arraycopy(args, argc, applet.args, 0, argc); @@ -2887,21 +2891,14 @@ public class PApplet extends Applet Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); if (external) { - /* - String argh = args[0].substring(EXTERNAL_FLAG.length()); - boolean exact = argh.charAt(0) == EXTERNAL_EXACT_LOCATION; - if (exact) argh = argh.substring(1); - int location[] = toInt(split(argh, ',')); - int locationX = location[0] - 20; - int locationY = location[1]; - */ - - Insets insets = frame.getInsets(); // pack() first? + Insets insets = frame.getInsets(); // does pack() first above //System.out.println(insets); int locationX = location[0] - 20; int locationY = location[1]; + //System.out.println("x,y " + locationX + " " + locationY); + //frame.setTitle(str(setupComplete)); int minW = 120; int minH = 120; int windowW = @@ -2909,10 +2906,11 @@ public class PApplet extends Applet int windowH = Math.max(applet.height, minH) + insets.top + insets.bottom; frame.setSize(windowW, windowH); + //frame.setTitle(windowW + " " + windowH); if (exactLocation) { frame.setLocation(location[0], location[1]); - + } else { if (locationX - windowW > 10) { // if it fits to the left of the window diff --git a/todo.txt b/todo.txt index bfc15310d..ba940d7d3 100644 --- a/todo.txt +++ b/todo.txt @@ -8,10 +8,11 @@ X was this the big one? a big one? X threading issues resolved X fixed bug with errors not coming through X fixed bug with errors not being recognized amonst exceptions - -_ moving p5 prefs on mac into documents? or inside sketchbook? -_ Documents -> Processing -> preferences.txt -_ do the same for windows, with sketchbook as a subfolder +X fixed bug with draw mode apps, they now run inside setup +X width/height wasn't getting set during setup(), so window bad +X moving p5 prefs on mac into documents? or inside sketchbook? +X Documents -> Processing -> preferences.txt +X do the same for windows, with sketchbook as a subfolder _ don't exit p5 if platform is unknown