From 7d37fe2863479efaf307a3d5092093237ecdc762 Mon Sep 17 00:00:00 2001 From: benfry Date: Wed, 3 Jul 2002 14:52:03 +0000 Subject: [PATCH] a light at the end of the tunnel.. sketchbook starting to work --- processing/app/PdeBase.java | 30 +++++++------ processing/app/PdeEditor.java | 83 ++++++++++++++++++++++------------- processing/todo.txt | 13 +++++- 3 files changed, 82 insertions(+), 44 deletions(-) diff --git a/processing/app/PdeBase.java b/processing/app/PdeBase.java index 6520e305a..673ddbf7f 100644 --- a/processing/app/PdeBase.java +++ b/processing/app/PdeBase.java @@ -86,18 +86,19 @@ public class PdeBase implements ActionListener { MenuItem item; menu = new Menu("File"); - menu.add(new MenuItem("New")); + menu.add(new MenuItem("New", new MenuShortcut('N'))); Menu openMenu = new Menu("Open"); rebuildSketchbookMenu(openMenu); menu.add(openMenu); - menu.add(new MenuItem("Save")); - menu.add(new MenuItem("Duplicate")); - menu.add(new MenuItem("Export")); + menu.add(new MenuItem("Save", new MenuShortcut('S'))); + menu.add(new MenuItem("Duplicate", new MenuShortcut('D'))); + menu.add(new MenuItem("Export to Web", new MenuShortcut('E'))); + menu.add(new MenuItem("Export Application", new MenuShortcut('E', true))); menu.addSeparator(); - menu.add(new MenuItem("Proce55ing.net")); - menu.add(new MenuItem("Reference")); + menu.add(new MenuItem("Proce55ing.net", new MenuShortcut('5'))); + menu.add(new MenuItem("Reference", new MenuShortcut('R'))); menu.addSeparator(); - menu.add(new MenuItem("Quit")); + menu.add(new MenuItem("Quit", new MenuShortcut('Q'))); menu.addActionListener(this); menubar.add(menu); @@ -116,11 +117,11 @@ public class PdeBase implements ActionListener { menubar.add(menu); menu = new Menu("Sketch"); - menu.add(new MenuItem("Play")); - menu.add(new MenuItem("Present")); + menu.add(new MenuItem("Play", new MenuShortcut('P'))); + menu.add(new MenuItem("Present", new MenuShortcut('P', true))); menu.add(new MenuItem("Stop")); menu.addSeparator(); - menu.add(new MenuItem("Beautify")); + menu.add(new MenuItem("Beautify", new MenuShortcut('B'))); menu.addActionListener(this); menubar.add(menu); @@ -141,6 +142,8 @@ public class PdeBase implements ActionListener { Insets insets = frame.getInsets(); Toolkit tk = Toolkit.getDefaultToolkit(); Dimension screen = tk.getScreenSize(); + + // THESE CAN BE REMOVED TO SOME EXTENT int frameX = getInteger("window.x", (screen.width - width) / 2); int frameY = getInteger("window.y", (screen.height - height) / 2); @@ -152,10 +155,11 @@ public class PdeBase implements ActionListener { // i don't like this being here, but.. //((PdeEditor)environment).graphics.frame = frame; - //((PdeEditor)environment).frame = frame; - editor.frame = frame; + //((PdeEditor)environment).frame = frame + frame.pack(); // maybe this should be before the setBounds call - frame.pack(); + editor.frame = frame; // no longer really used + editor.init(); frame.show(); // added back in for pde } diff --git a/processing/app/PdeEditor.java b/processing/app/PdeEditor.java index a25a268d7..bd4baa434 100644 --- a/processing/app/PdeEditor.java +++ b/processing/app/PdeEditor.java @@ -105,26 +105,31 @@ public class PdeEditor extends Panel { } runner = new PdeRunner(this); + } + + public void init() { // load the last program that was in use Properties skprops = new Properties(); try { skprops.load(getClass().getResource("sketch.properties").openStream()); - int windowX = Integer.parseInt(skprops.getProperty("window.x"), -1); - int windowY = Integer.parseInt(skprops.getProperty("window.y"), -1); - int windowW = Integer.parseInt(skprops.getProperty("window.w"), -1); - int windowH = Integer.parseInt(skprops.getProperty("window.h"), -1); + int windowX = Integer.parseInt(skprops.getProperty("window.x", "-1")); + int windowY = Integer.parseInt(skprops.getProperty("window.y", "-1")); + int windowW = Integer.parseInt(skprops.getProperty("window.w", "-1")); + int windowH = Integer.parseInt(skprops.getProperty("window.h", "-1")); // if screen size has changed, the window coordinates no longer // make sense, so don't use them unless they're identical - int screenW = Integer.parseInt(skprops.getProperty("screen.w"), -1); - int screenH = Integer.parseInt(skprops.getProperty("screen.h"), -1); + int screenW = Integer.parseInt(skprops.getProperty("screen.w", "-1")); + int screenH = Integer.parseInt(skprops.getProperty("screen.h", "-1")); Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); + if ((windowX != -1) && - ((screen.width == screenW) || (screen.height == screenH))) { + (screen.width == screenW) && (screen.height == screenH)) { + //System.out.println("setting bounds of frame"); PdeBase.frame.setBounds(windowX, windowY, windowW, windowH); } @@ -132,16 +137,21 @@ public class PdeEditor extends Panel { String path = skprops.getProperty("sketch.directory"); String user = skprops.getProperty("user.name"); - if (new File(path + File.separator + name + - File.separator + name + ".pde").exists()) { + String what = path + File.separator + name + ".pde"; + System.out.println(what); + + if (new File(what).exists()) { userName = user; skOpen(path, name); } else { + userName = "default"; skNew(); } } catch (Exception e) { + e.printStackTrace(); + // even if folder for 'default' user doesn't exist, or // sketchbook itself is missing, mkdirs() will make it happy userName = "default"; @@ -320,9 +330,17 @@ public class PdeEditor extends Panel { public void skOpen(String path, String name) { //header.isProject = true; //header.project = name; - handleOpen(name, - new File(path + File.separator + name, name + ".pde"), - new File(path)); + //System.out.println("skopen " + path + " " + name); + File osketchFile = new File(path, name + ".pde"); + File osketchDir = new File(path); + //System.out.println("skopen:"); + //System.out.println("1: " + name); + //System.out.println("2: " + osketchFile); + //System.out.println("3: " + osketchDir); + handleOpen(name, osketchFile, osketchDir); + //handleOpen(name, + // new File(path, name + ".pde"), + // new File(path)); } @@ -348,29 +366,34 @@ public class PdeEditor extends Panel { protected void handleOpen(String isketchName, File isketchFile, File isketchDir) { + //System.out.println("handleOpen " + isketchName + " " + + // isketchFile + " " + isketchDir); try { + //if (true) throw new IOException("blah"); + FileInputStream input = new FileInputStream(isketchFile); int length = (int) isketchFile.length(); - byte data[] = new byte[length]; + if (length == 0) { + byte data[] = new byte[length]; - int count = 0; - while (count != length) { - data[count++] = (byte) input.read(); + int count = 0; + while (count != length) { + data[count++] = (byte) input.read(); + } + // set the last dir and file, so that they're + // the defaults when you try to save again + //lastDirectory = file.getCanonicalPath(); //directory; + //lastFile = file.getName(); //filename; + + // once read all the bytes, convert it to the proper + // local encoding for this system. + //textarea.setText(app.languageEncode(data)); + // what the hell was i thinking when i wrote this code + //if (app.encoding == null) + textarea.setText(new String(data)); + //else + //textarea.setText(new String(data, app.encoding)); } - // set the last dir and file, so that they're - // the defaults when you try to save again - //lastDirectory = file.getCanonicalPath(); //directory; - //lastFile = file.getName(); //filename; - - // once read all the bytes, convert it to the proper - // local encoding for this system. - //textarea.setText(app.languageEncode(data)); - // what the hell was i thinking when i wrote this code - //if (app.encoding == null) - textarea.setText(new String(data)); - //else - //textarea.setText(new String(data, app.encoding)); - sketchName = isketchName; sketchFile = isketchFile; sketchDir = isketchDir; diff --git a/processing/todo.txt b/processing/todo.txt index c724f33a6..c57ca67dc 100644 --- a/processing/todo.txt +++ b/processing/todo.txt @@ -8,10 +8,22 @@ _ cleanup lastFile/lastDirectory _ renaming projects _ sketch: sketch-000 is dumb _ make sure compiling into build directory +_ remove everything from build when starting a new build +_ and once compiled there, read all classes for export _ implement popup menu _ save (just) last program run in sketch.properties _ move structure of app/application dirs around a bit +_ saving to gzipped 'versions' file +_ autosave every few minutes, also on each compile +_ remove Editor's frame instance, replace refs with PdeBase.frame +_ small script to remove CVS directories from a tree + +_ remove projects if created but nothing happens to them +_ need to implement code for whether changes have been made +_ check for key events in textarea or something +_ if key events, compare contents against the existing file + pdebase simple _ remove 'encoding' crap from PdeBase _ only existed b/c of reading as bytes and not using jdk11 methods @@ -132,7 +144,6 @@ a _ Compiler.disable() message is weird and doesn't always work a _ probably just remove it for now other mess -_ modify to allow for the 'build' directory in lib _ make a new 'dist' function for building _ exceptions in draw() apps aren't caught _ the program resize(200, 200); just does nothing (doesn't complain)