diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index ffaf32d3e..8a3eaec56 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -54,10 +54,11 @@ public class Base { static public String VERSION_NAME = "0204"; /** Set true if this a proper release rather than a numbered revision. */ static public boolean RELEASE = false; + /** True if heavy debugging error/log messages are enabled */ static public boolean DEBUG = false; //static public boolean DEBUG = true; - + static HashMap platformNames = new HashMap(); static { @@ -109,7 +110,7 @@ public class Base { // Location for untitled items static File untitledFolder; - java.util.List editors = + List editors = Collections.synchronizedList(new ArrayList()); protected Editor activeEditor; // a lone file menu to be used when all sketch windows are closed @@ -329,8 +330,9 @@ public class Base { // // Get the sketchbook path, and make sure it's set properly // determineSketchbookFolder(); - // Check if there were previously opened sketches to be restored - boolean opened = restoreSketches(); +// // Check if there were previously opened sketches to be restored +// boolean opened = restoreSketches(); + boolean opened = false; // Check if any files were passed in on the command line for (int i = 0; i < args.length; i++) { @@ -388,7 +390,7 @@ public class Base { * The complement to "storePreferences", this is called when the * application is first launched. */ - protected boolean restoreSketches() { + protected void restoreSketches() { String lastMode = Preferences.get("last.sketch.mode"); if (DEBUG) { System.out.println("setting mode to " + lastMode); @@ -411,107 +413,105 @@ public class Base { } } - if (DEBUG) { - System.out.println("default mode set to " + defaultMode.getClass().getName()); - } + log("default mode set to " + defaultMode.getClass().getName()); - if (!Preferences.getBoolean("last.sketch.restore")) { - return false; - } - - // figure out window placement - Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - boolean windowPositionValid = true; - - if (Preferences.get("last.screen.height") != null) { - // if screen size has changed, the window coordinates no longer - // make sense, so don't use them unless they're identical - int screenW = Preferences.getInteger("last.screen.width"); - int screenH = Preferences.getInteger("last.screen.height"); - - if ((screen.width != screenW) || (screen.height != screenH)) { - windowPositionValid = false; - } - /* - int windowX = Preferences.getInteger("last.window.x"); - int windowY = Preferences.getInteger("last.window.y"); - if ((windowX < 0) || (windowY < 0) || - (windowX > screenW) || (windowY > screenH)) { - windowPositionValid = false; - } - */ - } else { - windowPositionValid = false; - } - - // Iterate through all sketches that were open last time p5 was running. - // If !windowPositionValid, then ignore the coordinates found for each. - - // Save the sketch path and window placement for each open sketch - int count = Preferences.getInteger("last.sketch.count"); - int opened = 0; - for (int i = 0; i < count; i++) { - String path = Preferences.get("last.sketch" + i + ".path"); - int[] location; - if (windowPositionValid) { - String locationStr = Preferences.get("last.sketch" + i + ".location"); - location = PApplet.parseInt(PApplet.split(locationStr, ',')); - } else { - location = nextEditorLocation(); - } - // If file did not exist, null will be returned for the Editor - if (handleOpen(path, location) != null) { - opened++; - } - } - return (opened > 0); +// if (Preferences.getBoolean("last.sketch.restore")) { +// return false; +// } +// +// // figure out window placement +// Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); +// boolean windowPositionValid = true; +// +// if (Preferences.get("last.screen.height") != null) { +// // if screen size has changed, the window coordinates no longer +// // make sense, so don't use them unless they're identical +// int screenW = Preferences.getInteger("last.screen.width"); +// int screenH = Preferences.getInteger("last.screen.height"); +// +// if ((screen.width != screenW) || (screen.height != screenH)) { +// windowPositionValid = false; +// } +// /* +// int windowX = Preferences.getInteger("last.window.x"); +// int windowY = Preferences.getInteger("last.window.y"); +// if ((windowX < 0) || (windowY < 0) || +// (windowX > screenW) || (windowY > screenH)) { +// windowPositionValid = false; +// } +// */ +// } else { +// windowPositionValid = false; +// } +// +// // Iterate through all sketches that were open last time p5 was running. +// // If !windowPositionValid, then ignore the coordinates found for each. +// +// // Save the sketch path and window placement for each open sketch +// int count = Preferences.getInteger("last.sketch.count"); +// int opened = 0; +// for (int i = 0; i < count; i++) { +// String path = Preferences.get("last.sketch" + i + ".path"); +// int[] location; +// if (windowPositionValid) { +// String locationStr = Preferences.get("last.sketch" + i + ".location"); +// location = PApplet.parseInt(PApplet.split(locationStr, ',')); +// } else { +// location = nextEditorLocation(); +// } +// // If file did not exist, null will be returned for the Editor +// if (handleOpen(path, location) != null) { +// opened++; +// } +// } +// return (opened > 0); } - /** - * Store list of sketches that are currently open. - * Called when the application is quitting and documents are still open. - */ - protected void storeSketches() { - // Save the width and height of the screen - Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - Preferences.setInteger("last.screen.width", screen.width); - Preferences.setInteger("last.screen.height", screen.height); - - String untitledPath = untitledFolder.getAbsolutePath(); - - // Save the sketch path and window placement for each open sketch - int index = 0; - for (Editor editor : editors) { - String path = editor.getSketch().getMainFilePath(); - // In case of a crash, save untitled sketches if they contain changes. - // (Added this for release 0158, may not be a good idea.) - if (path.startsWith(untitledPath) && - !editor.getSketch().isModified()) { - continue; - } - Preferences.set("last.sketch" + index + ".path", path); - - int[] location = editor.getPlacement(); - String locationStr = PApplet.join(PApplet.str(location), ","); - Preferences.set("last.sketch" + index + ".location", locationStr); - index++; - } - Preferences.setInteger("last.sketch.count", index); - Preferences.set("last.sketch.mode", defaultMode.getClass().getName()); - } - - - // If a sketch is untitled on quit, may need to store the new name - // rather than the location from the temp folder. - protected void storeSketchPath(Editor editor, int index) { - String path = editor.getSketch().getMainFilePath(); - String untitledPath = untitledFolder.getAbsolutePath(); - if (path.startsWith(untitledPath)) { - path = ""; - } - Preferences.set("last.sketch" + index + ".path", path); - } +// /** +// * Store list of sketches that are currently open. +// * Called when the application is quitting and documents are still open. +// */ +// protected void storeSketches() { +// // Save the width and height of the screen +// Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); +// Preferences.setInteger("last.screen.width", screen.width); +// Preferences.setInteger("last.screen.height", screen.height); +// +// String untitledPath = untitledFolder.getAbsolutePath(); +// +// // Save the sketch path and window placement for each open sketch +// int index = 0; +// for (Editor editor : editors) { +// String path = editor.getSketch().getMainFilePath(); +// // In case of a crash, save untitled sketches if they contain changes. +// // (Added this for release 0158, may not be a good idea.) +// if (path.startsWith(untitledPath) && +// !editor.getSketch().isModified()) { +// continue; +// } +// Preferences.set("last.sketch" + index + ".path", path); +// +// int[] location = editor.getPlacement(); +// String locationStr = PApplet.join(PApplet.str(location), ","); +// Preferences.set("last.sketch" + index + ".location", locationStr); +// index++; +// } +// Preferences.setInteger("last.sketch.count", index); +// Preferences.set("last.sketch.mode", defaultMode.getClass().getName()); +// } +// +// +// // If a sketch is untitled on quit, may need to store the new name +// // rather than the location from the temp folder. +// protected void storeSketchPath(Editor editor, int index) { +// String path = editor.getSketch().getMainFilePath(); +// String untitledPath = untitledFolder.getAbsolutePath(); +// if (path.startsWith(untitledPath)) { +// path = ""; +// } +// Preferences.set("last.sketch" + index + ".path", path); +// } /* @@ -635,12 +635,15 @@ public class Base { // writer.flush(); // writer.close(); - // close this sketch - int[] where = activeEditor.getPlacement(); +// // close this sketch +//// int[] where = activeEditor.getPlacement(); +// Rectangle bounds = activeEditor.getBounds(); +// int divider = activeEditor.getDividerLocation(); + EditorState state = activeEditor.state; handleClose(activeEditor, true); // re-open the sketch - Editor editor = handleOpen(mainPath, where); + Editor editor = handleOpen(mainPath, state); if (editor != null) { editor.untitled = untitled; } @@ -674,52 +677,50 @@ public class Base { } - protected int[] nextEditorLocation() { - Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - int defaultWidth = Preferences.getInteger("editor.window.width.default"); - int defaultHeight = Preferences.getInteger("editor.window.height.default"); - -// if (activeEditor == null) { - if (editors.size() == 0) { -// System.out.println("active editor is " + activeEditor); - // If no current active editor, use default placement - return new int[] { - (screen.width - defaultWidth) / 2, - (screen.height - defaultHeight) / 2, - defaultWidth, defaultHeight, 0 - }; - - } else { - // With a currently active editor, open the new window - // using the same dimensions, but offset slightly. - synchronized (editors) { - final int OVER = 50; - // In release 0160, don't - //location = activeEditor.getPlacement(); - Editor lastOpened = editors.get(editors.size() - 1); - int[] location = lastOpened.getPlacement(); - // Just in case the bounds for that window are bad - location[0] += OVER; - location[1] += OVER; - - if (location[0] == OVER || - location[2] == OVER || - location[0] + location[2] > screen.width || - location[1] + location[3] > screen.height) { - // Warp the next window to a randomish location on screen. - return new int[] { - (int) (Math.random() * (screen.width - defaultWidth)), - (int) (Math.random() * (screen.height - defaultHeight)), - defaultWidth, defaultHeight, 0 - }; - } - - return location; - } - } - } - - +// protected int[] nextEditorLocation() { +// Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); +// int defaultWidth = Preferences.getInteger("editor.window.width.default"); +// int defaultHeight = Preferences.getInteger("editor.window.height.default"); +// +//// if (activeEditor == null) { +// if (editors.size() == 0) { +//// System.out.println("active editor is " + activeEditor); +// // If no current active editor, use default placement +// return new int[] { +// (screen.width - defaultWidth) / 2, +// (screen.height - defaultHeight) / 2, +// defaultWidth, defaultHeight, 0 +// }; +// +// } else { +// // With a currently active editor, open the new window +// // using the same dimensions, but offset slightly. +// synchronized (editors) { +// final int OVER = 50; +// Editor lastOpened = editors.get(editors.size() - 1); +// int[] location = lastOpened.getPlacement(); +// // Just in case the bounds for that window are bad +// location[0] += OVER; +// location[1] += OVER; +// +// if (location[0] == OVER || +// location[2] == OVER || +// location[0] + location[2] > screen.width || +// location[1] + location[3] > screen.height) { +// // Warp the next window to a randomish location on screen. +// return new int[] { +// (int) (Math.random() * (screen.width - defaultWidth)), +// (int) (Math.random() * (screen.height - defaultHeight)), +// defaultWidth, defaultHeight, 0 +// }; +// } +// +// return location; +// } +// } +// } + + /** * Return the same mode as the active editor, or the default mode, which * begins as Java/Standard, but is updated with the last mode used. @@ -930,11 +931,14 @@ public class Base { * can be set by the caller */ public Editor handleOpen(String path) { - return handleOpen(path, nextEditorLocation()); + //return handleOpen(path, nextEditorLocation()); + return handleOpen(path, new EditorState(editors)); } - protected Editor handleOpen(String path, int[] location) { +// protected Editor handleOpen(String path, int[] location) { +// protected Editor handleOpen(String path, Rectangle bounds, int divider) { + protected Editor handleOpen(String path, EditorState state) { // System.err.println("entering handleOpen " + path); File file = new File(path); @@ -983,9 +987,9 @@ public class Base { nextMode = findMode(modeTitle); if (nextMode == null) { final String msg = - "This sketch was last used in “" + modeTitle + "â€� mode,\n" + + "This sketch was last used in “" + modeTitle + "” mode,\n" + "which does not appear to be installed. The sketch will\n" + - "be opened in “" + defaultMode.getTitle() + "â€� mode instead."; + "be opened in “" + defaultMode.getTitle() + "” mode instead."; Base.showWarning("Depeche Mode", msg, null); nextMode = defaultMode; } @@ -994,7 +998,8 @@ public class Base { } catch (Exception e) { e.printStackTrace(); } - Editor editor = nextMode.createEditor(this, path, location); +// Editor.State state = new Editor.State(editors); + Editor editor = nextMode.createEditor(this, path, state); if (editor == null) { // if it's the last editor window // if (editors.size() == 0 && defaultFileMenu == null) { @@ -1007,7 +1012,7 @@ public class Base { "unfortunate bit of indigestion.", null); } else { - editor = defaultMode.createEditor(this, path, location); + editor = defaultMode.createEditor(this, path, state); } } @@ -1091,7 +1096,7 @@ public class Base { // This will store the sketch count as zero editors.remove(editor); - storeSketches(); +// storeSketches(); // Save out the current prefs state Preferences.save(); @@ -1144,7 +1149,7 @@ public class Base { public boolean handleQuit() { // If quit is canceled, this will be replaced anyway // by a later handleQuit() that is not canceled. - storeSketches(); +// storeSketches(); if (handleQuitEach()) { // make sure running sketches close before quitting @@ -1170,14 +1175,17 @@ public class Base { * @return false if canceled along the way */ protected boolean handleQuitEach() { - int index = 0; +// int index = 0; for (Editor editor : editors) { - if (editor.checkModified()) { - // Update to the new/final sketch path for this fella - storeSketchPath(editor, index); - index++; - - } else { +// if (editor.checkModified()) { +// // Update to the new/final sketch path for this fella +// storeSketchPath(editor, index); +// index++; +// +// } else { +// return false; +// } + if (!editor.checkModified()) { return false; } } @@ -1676,8 +1684,7 @@ public class Base { /** * Convenience method to get a File object for the specified filename inside - * the settings folder. - * For now, only used by Preferences to get the preferences.txt file. + * the settings folder. Used to get preferences and recent sketch files. * @param filename A file inside the settings folder. * @return filename wrapped as a File object inside the settings folder */ @@ -2787,4 +2794,9 @@ public class Base { } } } + + + static public void log(String message) { + if (DEBUG) System.out.println(message); + } } diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index 187c0cc31..5be4308c1 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -45,6 +45,7 @@ import javax.swing.undo.*; */ public abstract class Editor extends JFrame implements RunnerListener { protected Base base; + protected EditorState state; protected Mode mode; // otherwise, if the window is resized with the message label @@ -109,9 +110,12 @@ public abstract class Editor extends JFrame implements RunnerListener { ArrayList coreTools; public ArrayList contribTools; - protected Editor(final Base base, String path, int[] location, final Mode mode) { - super("Processing"); + +// protected Editor(final Base base, String path, int[] location, final Mode mode) { + protected Editor(final Base base, String path, EditorState state, final Mode mode) { + super("Processing", state.checkConfig()); this.base = base; + this.state = state; this.mode = mode; Base.setIcon(this); // TODO should this be per-mode? @@ -244,7 +248,8 @@ public abstract class Editor extends JFrame implements RunnerListener { pack(); // Set the window bounds and the divider location before setting it visible - setPlacement(location); +// setPlacement(location); + state.apply(this); // Set the minimum size for the editor window setMinimumSize(new Dimension(Preferences.getInteger("editor.window.width.min"), @@ -393,28 +398,38 @@ public abstract class Editor extends JFrame implements RunnerListener { abstract public Formatter createFormatter(); - protected void setPlacement(int[] location) { - setBounds(location[0], location[1], location[2], location[3]); - if (location[4] != 0) { - splitPane.setDividerLocation(location[4]); - } +// protected void setPlacement(int[] location) { +// setBounds(location[0], location[1], location[2], location[3]); +// if (location[4] != 0) { +// splitPane.setDividerLocation(location[4]); +// } +// } +// +// +// protected int[] getPlacement() { +// int[] location = new int[5]; +// +// // Get the dimensions of the Frame +// Rectangle bounds = getBounds(); +// location[0] = bounds.x; +// location[1] = bounds.y; +// location[2] = bounds.width; +// location[3] = bounds.height; +// +// // Get the current placement of the divider +// location[4] = splitPane.getDividerLocation(); +// +// return location; +// } + + + protected void setDividerLocation(int pos) { + splitPane.setDividerLocation(pos); } - - - protected int[] getPlacement() { - int[] location = new int[5]; - - // Get the dimensions of the Frame - Rectangle bounds = getBounds(); - location[0] = bounds.x; - location[1] = bounds.y; - location[2] = bounds.width; - location[3] = bounds.height; - - // Get the current placement of the divider - location[4] = splitPane.getDividerLocation(); - - return location; + + + protected int getDividerLocation() { + return splitPane.getDividerLocation(); } @@ -2004,7 +2019,7 @@ public abstract class Editor extends JFrame implements RunnerListener { // Store information on who's open and running // (in case there's a crash or something that can't be recovered) - base.storeSketches(); +// base.storeSketches(); Preferences.save(); // opening was successful diff --git a/app/src/processing/app/EditorState.java b/app/src/processing/app/EditorState.java new file mode 100644 index 000000000..9f2660f39 --- /dev/null +++ b/app/src/processing/app/EditorState.java @@ -0,0 +1,185 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2004-11 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.app; + +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.GraphicsEnvironment; +import java.awt.Rectangle; +import java.io.BufferedReader; +import java.io.IOException; +import java.io.PrintWriter; +import java.util.List; + + +import processing.core.PApplet; + + public class EditorState { + // path to the main .pde file for the sketch +// String path; + // placement of the window +// int windowX, windowY, windowW, windowH; + Rectangle editorBounds; + int dividerLocation; + // width/height of the screen on which this window was placed +// int displayW, displayH; + String deviceName; + Rectangle deviceBounds; + + + EditorState(List editors) { + defaultConfig(); + defaultLocation(editors); + } + + + EditorState(BufferedReader reader) throws IOException { + String line = reader.readLine(); + String[] pieces = PApplet.split(line, '\t'); +// path = pieces[0]; + +// windowX = Integer.parseInt(pieces[1]); +// windowY = Integer.parseInt(pieces[2]); +// windowW = Integer.parseInt(pieces[3]); +// windowH = Integer.parseInt(pieces[4]); + +// displayW = Integer.parseInt(pieces[5]); +// displayH = Integer.parseInt(pieces[6]); + } + + // scenarios: + // 1) new untitled sketch (needs device, needs bounds) + // 2) restoring sketch from recent menu + // - device cannot be found + // - device is found but it's a different size + // - device is found and size is correct + // 3) re-opening sketch in a new mode + + GraphicsConfiguration checkConfig() { + GraphicsEnvironment graphicsEnvironment = + GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice[] screenDevices = graphicsEnvironment.getScreenDevices(); + for (GraphicsDevice device : screenDevices) { + GraphicsConfiguration[] configurations = device.getConfigurations(); + for (GraphicsConfiguration config : configurations) { + if (config.getDevice().getIDstring().equals(deviceName)) { + if (deviceBounds != null && config.getBounds().equals(deviceBounds)) { + return config; + } else { + + } + } + } + } + // otherwise go to the default config + return defaultConfig(); + } + + + GraphicsConfiguration defaultConfig() { + GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice device = ge.getDefaultScreenDevice(); + GraphicsConfiguration config = device.getDefaultConfiguration(); + deviceName = device.getIDstring(); + deviceBounds = config.getBounds(); + return config; + } + + + void defaultLocation(List editors) { + int defaultWidth = Preferences.getInteger("editor.window.width.default"); + int defaultHeight = Preferences.getInteger("editor.window.height.default"); + + if (editors.size() == 0) { + // If no current active editor, use default placement. + // Center the window on ths screen, taking into account that the + // upper-left corner of the device may have a non (0, 0) origin. + int editorX = + deviceBounds.x + (deviceBounds.width - defaultWidth) / 2; + int editorY = + deviceBounds.y + (deviceBounds.height - defaultHeight) / 2; + editorBounds = + new Rectangle(editorX, editorY, defaultWidth, defaultHeight); + dividerLocation = 0; + + } else { + // With a currently active editor, open the new window using the same + // dimensions and divider location, but offset slightly. + synchronized (editors) { + final int OVER = 50; + Editor lastOpened = editors.get(editors.size() - 1); + editorBounds = lastOpened.getBounds(); + editorBounds.x += OVER; + editorBounds.y += OVER; + dividerLocation = lastOpened.getDividerLocation(); + + if (!deviceBounds.contains(editorBounds)) { + // Warp the next window to a randomish location on screen. + editorBounds.x = deviceBounds.x + (int) (Math.random() * (deviceBounds.width - defaultWidth)); + editorBounds.y = deviceBounds.y + (int) (Math.random() * (deviceBounds.height - defaultHeight)); + } + } + } + } + + + void update(Editor editor) { +// path = editor.getSketch().getMainFilePath(); + editorBounds = editor.getBounds(); + dividerLocation = editor.getDividerLocation(); + GraphicsConfiguration config = editor.getGraphicsConfiguration(); + GraphicsDevice device = config.getDevice(); + deviceBounds = config.getBounds(); + deviceName = device.getIDstring(); + } + + + void apply(Editor editor) { + editor.setBounds(editorBounds); + if (dividerLocation != 0) { + editor.setDividerLocation(dividerLocation); + } + } + + + void write(PrintWriter writer) { +// writer.print(path); + writer.print('\t'); + writeRect(writer, editorBounds); + writer.print('\t'); + writer.print(deviceName); + writer.print('\t'); + writeRect(writer, deviceBounds); + } + + + void writeRect(PrintWriter writer, Rectangle rect) { + writer.print(rect.x); + writer.print('\t'); + writer.print(rect.y); + writer.print('\t'); + writer.print(rect.width); + writer.print('\t'); + writer.print(rect.height); + } + } \ No newline at end of file diff --git a/app/src/processing/app/Mode.java b/app/src/processing/app/Mode.java index 93b44962b..5d92da41f 100644 --- a/app/src/processing/app/Mode.java +++ b/app/src/processing/app/Mode.java @@ -94,7 +94,8 @@ public abstract class Mode { /** * Create a new editor associated with this mode. */ - abstract public Editor createEditor(Base base, String path, int[] location); + abstract public Editor createEditor(Base base, String path, EditorState state); + //abstract public Editor createEditor(Base base, String path, int[] location); public File getExamplesFolder() { diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 7cc42a12b..51cdfc4c4 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -7,9 +7,8 @@ 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 as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + 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 diff --git a/app/src/processing/app/Recent.java b/app/src/processing/app/Recent.java new file mode 100644 index 000000000..e0df2ee59 --- /dev/null +++ b/app/src/processing/app/Recent.java @@ -0,0 +1,135 @@ +/* -*- mode: java; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + Part of the Processing project - http://processing.org + + Copyright (c) 2011 Ben Fry and Casey Reas + + 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.app; + +import java.awt.Dimension; +import java.awt.GraphicsConfiguration; +import java.awt.GraphicsDevice; +import java.awt.Rectangle; +import java.awt.Toolkit; +import java.io.*; + +import processing.core.PApplet; + + +public class Recent { + static final String FILENAME = "recent.txt"; + static final String VERSION = "1"; + File file; + + public Recent() throws IOException { + file = Base.getSettingsFile(FILENAME); + if (!file.exists()) { + BufferedReader reader = PApplet.createReader(file); + String version = reader.readLine(); + if (version != null && version.equals(VERSION)) { + + } + } + } + + +// class Record { +// // path to the main .pde file for the sketch +// String path; +// // placement of the window +//// int windowX, windowY, windowW, windowH; +// Rectangle editorBounds; +// // width/height of the screen on which this window was placed +//// int displayW, displayH; +// String deviceName; +// Rectangle deviceBounds; +// +// +// Record(BufferedReader reader) throws IOException { +// String line = reader.readLine(); +// String[] pieces = PApplet.split(line, '\t'); +// path = pieces[0]; +// +//// windowX = Integer.parseInt(pieces[1]); +//// windowY = Integer.parseInt(pieces[2]); +//// windowW = Integer.parseInt(pieces[3]); +//// windowH = Integer.parseInt(pieces[4]); +// +//// displayW = Integer.parseInt(pieces[5]); +//// displayH = Integer.parseInt(pieces[6]); +// } +// +// +// void update(Editor editor) { +// path = editor.getSketch().getMainFilePath(); +// editorBounds = editor.getBounds(); +// GraphicsConfiguration config = editor.getGraphicsConfiguration(); +// GraphicsDevice device = config.getDevice(); +// deviceBounds = config.getBounds(); +// deviceName = device.getIDstring(); +// } +// +// +// void write(PrintWriter writer) { +// writer.print(path); +// writer.print('\t'); +// writeRect(writer, editorBounds); +// writer.print('\t'); +// writer.print(deviceName); +// writer.print('\t'); +// writeRect(writer, deviceBounds); +// } +// +// +// void writeRect(PrintWriter writer, Rectangle rect) { +// writer.print(rect.x); +// writer.print('\t'); +// writer.print(rect.y); +// writer.print('\t'); +// writer.print(rect.width); +// writer.print('\t'); +// writer.print(rect.height); +// } +// } + +// Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); +// Preferences.setInteger("last.screen.width", screen.width); +// Preferences.setInteger("last.screen.height", screen.height); +// +// String untitledPath = untitledFolder.getAbsolutePath(); +// +// // Save the sketch path and window placement for each open sketch +// int index = 0; +// for (Editor editor : editors) { +// String path = editor.getSketch().getMainFilePath(); +// // In case of a crash, save untitled sketches if they contain changes. +// // (Added this for release 0158, may not be a good idea.) +// if (path.startsWith(untitledPath) && +// !editor.getSketch().isModified()) { +// continue; +// } +// Preferences.set("last.sketch" + index + ".path", path); +// +// int[] location = editor.getPlacement(); +// String locationStr = PApplet.join(PApplet.str(location), ","); +// Preferences.set("last.sketch" + index + ".location", locationStr); +// index++; +// } +// Preferences.setInteger("last.sketch.count", index); +// Preferences.set("last.sketch.mode", defaultMode.getClass().getName()); +} \ No newline at end of file diff --git a/app/src/processing/app/SingleInstance.java b/app/src/processing/app/SingleInstance.java index 15f9261a4..ae359d4ca 100644 --- a/app/src/processing/app/SingleInstance.java +++ b/app/src/processing/app/SingleInstance.java @@ -82,18 +82,18 @@ public class SingleInstance { SwingUtilities.invokeLater(new Runnable() { public void run() { try { - if (Base.DEBUG) System.out.println("about to read line"); + Base.log("about to read line"); String filename = reader.readLine(); if (filename != null) { - if (Base.DEBUG) System.out.println("calling open with " + filename); + Base.log("calling open with " + filename); platform.base.handleOpen(filename); // see if there is more than one file that was passed in while ((filename = reader.readLine()) != null) { - if (Base.DEBUG) System.out.println("continuing to call open with " + filename); + Base.log("continuing to call open with " + filename); platform.base.handleOpen(filename); } } else { - if (Base.DEBUG) System.out.println("opening new empty sketch"); + Base.log("opening new empty sketch"); platform.base.handleNew(); } } catch (IOException e) { @@ -102,7 +102,7 @@ public class SingleInstance { } }); } else { - if (Base.DEBUG) System.out.println("keys do not match"); + Base.log("keys do not match"); } } } catch (IOException e) { diff --git a/app/src/processing/app/UpdateCheck.java b/app/src/processing/app/UpdateCheck.java index 5ef4b298b..a36ff5976 100644 --- a/app/src/processing/app/UpdateCheck.java +++ b/app/src/processing/app/UpdateCheck.java @@ -132,11 +132,11 @@ public class UpdateCheck { } } - protected boolean promptToVisitDownloadPage() { - + + protected boolean promptToVisitDownloadPage() { String prompt = - "A new version of Processing is available,\n" + - "would you like to visit the Processing download page?"; + "A new version of Processing is available,\n" + + "would you like to visit the Processing download page?"; Object[] options = { "Yes", "No" }; int result = JOptionPane.showOptionDialog(base.activeEditor, @@ -155,11 +155,11 @@ public class UpdateCheck { return false; } + protected boolean promptToOpenContributionManager() { - String contributionPrompt = - "There are updates available for some of the installed contributions,\n" + - "would you like to open the the Contribution Manager now?"; + "There are updates available for some of the installed contributions,\n" + + "would you like to open the the Contribution Manager now?"; Object[] options = { "Yes", "No" }; int result = JOptionPane.showOptionDialog(base.activeEditor, @@ -177,7 +177,8 @@ public class UpdateCheck { return false; } - + + protected int readInt(String filename) throws Exception { URL url = new URL(filename); InputStream stream = url.openStream(); diff --git a/app/src/processing/mode/android/AndroidEditor.java b/app/src/processing/mode/android/AndroidEditor.java index b6b5814d2..6e3f34e3b 100644 --- a/app/src/processing/mode/android/AndroidEditor.java +++ b/app/src/processing/mode/android/AndroidEditor.java @@ -29,13 +29,11 @@ import java.io.IOException; import javax.swing.JMenu; import javax.swing.JMenuItem; -import processing.app.Base; -import processing.app.EditorToolbar; -import processing.app.Mode; -import processing.app.SketchException; -import processing.core.PApplet; +import processing.app.*; import processing.mode.java.JavaEditor; +import processing.core.PApplet; + // http://dl.google.com/android/repository/repository.xml // http://dl.google.com/android/android-sdk_r3-mac.zip // http://dl.google.com/android/repository/tools_r03-macosx.zip @@ -59,8 +57,8 @@ public class AndroidEditor extends JavaEditor { - protected AndroidEditor(Base base, String path, int[] location, Mode mode) throws Exception { - super(base, path, location, mode); + protected AndroidEditor(Base base, String path, EditorState state, Mode mode) throws Exception { + super(base, path, state, mode); amode = (AndroidMode) mode; // try { diff --git a/app/src/processing/mode/android/AndroidMode.java b/app/src/processing/mode/android/AndroidMode.java index ed0127f54..965c9735c 100644 --- a/app/src/processing/mode/android/AndroidMode.java +++ b/app/src/processing/mode/android/AndroidMode.java @@ -28,6 +28,7 @@ import java.util.Date; import processing.app.Base; import processing.app.Editor; +import processing.app.EditorState; import processing.app.RunnerListener; import processing.app.Sketch; import processing.app.SketchException; @@ -46,9 +47,9 @@ public class AndroidMode extends JavaMode { @Override - public Editor createEditor(Base base, String path, int[] location) { + public Editor createEditor(Base base, String path, EditorState state) { try { - return new AndroidEditor(base, path, location, this); + return new AndroidEditor(base, path, state, this); } catch (Exception e) { e.printStackTrace(); } diff --git a/app/src/processing/mode/java/JavaEditor.java b/app/src/processing/mode/java/JavaEditor.java index 4c750bd2f..97c8c1ec9 100644 --- a/app/src/processing/mode/java/JavaEditor.java +++ b/app/src/processing/mode/java/JavaEditor.java @@ -22,8 +22,8 @@ public class JavaEditor extends Editor { private Runner runtime; - protected JavaEditor(Base base, String path, int[] location, Mode mode) { - super(base, path, location, mode); + protected JavaEditor(Base base, String path, EditorState state, Mode mode) { + super(base, path, state, mode); // hopefully these are no longer needed w/ swing // (har har har.. that was wishful thinking) diff --git a/app/src/processing/mode/java/JavaMode.java b/app/src/processing/mode/java/JavaMode.java index b00149015..55c1e6deb 100644 --- a/app/src/processing/mode/java/JavaMode.java +++ b/app/src/processing/mode/java/JavaMode.java @@ -28,6 +28,7 @@ import java.util.HashMap; import processing.app.Base; import processing.app.Editor; +import processing.app.EditorState; import processing.app.Mode; import processing.app.RunnerListener; import processing.app.Sketch; @@ -44,8 +45,8 @@ public class JavaMode extends Mode { // static public String librariesClassPath; - public Editor createEditor(Base base, String path, int[] location) { - return new JavaEditor(base, path, location, this); + public Editor createEditor(Base base, String path, EditorState state) { + return new JavaEditor(base, path, state, this); } diff --git a/app/src/processing/mode/javascript/JavaScriptEditor.java b/app/src/processing/mode/javascript/JavaScriptEditor.java index 45d3022de..0d3892bd1 100644 --- a/app/src/processing/mode/javascript/JavaScriptEditor.java +++ b/app/src/processing/mode/javascript/JavaScriptEditor.java @@ -10,6 +10,7 @@ import javax.swing.JMenuItem; import javax.swing.JOptionPane; import processing.app.Base; +import processing.app.EditorState; import processing.app.Settings; import processing.app.Editor; import processing.app.EditorToolbar; @@ -34,9 +35,9 @@ public class JavaScriptEditor extends Editor // tapping into Java mode might not be wanted? processing.mode.java.PdeKeyListener listener; - protected JavaScriptEditor ( Base base, String path, int[] location, Mode mode ) + protected JavaScriptEditor ( Base base, String path, EditorState state, Mode mode ) { - super(base, path, location, mode); + super(base, path, state, mode); listener = new processing.mode.java.PdeKeyListener(this,textarea); diff --git a/app/src/processing/mode/javascript/JavaScriptMode.java b/app/src/processing/mode/javascript/JavaScriptMode.java index ac580ba40..d1ee43957 100644 --- a/app/src/processing/mode/javascript/JavaScriptMode.java +++ b/app/src/processing/mode/javascript/JavaScriptMode.java @@ -7,6 +7,7 @@ import java.util.HashMap; import processing.app.Base; import processing.app.Editor; +import processing.app.EditorState; import processing.app.Mode; import processing.app.Sketch; import processing.app.SketchException; @@ -24,9 +25,9 @@ public class JavaScriptMode extends Mode private JavaScriptEditor jsEditor; // create a new editor with the mode - public Editor createEditor( Base base, String path, int[] location ) + public Editor createEditor( Base base, String path, EditorState state ) { - jsEditor = new JavaScriptEditor( base, path, location, this ); + jsEditor = new JavaScriptEditor( base, path, state, this ); return jsEditor; } diff --git a/core/todo.txt b/core/todo.txt index 4fde0abd3..302e285b6 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -6,6 +6,8 @@ X "Framingham" example has BufferOverflowException X http://code.google.com/p/processing/issues/detail?id=900 X enable smooth() by default X better to learn noSmooth() later +X repeatedly calling texture() with new image raises memory error +X http://code.google.com/p/processing/issues/detail?id=806 earlier o text using textMode(SCREEN) not displayed in Processing 1.5.1 diff --git a/todo.txt b/todo.txt index a6b6e4d07..6a5227a49 100644 --- a/todo.txt +++ b/todo.txt @@ -11,6 +11,10 @@ X work on code to quit if multiple instances are running X need to bring the other instance to front X and/or open a new window X fix bug with 'base' not getting set in the Mac OS X platform class +X add EditorState class, device-aware placement +X get rid of restore sketch feature +_ remove pref for restoring sketches +_ implement recent sketches menu fixed in 2.0a3 X Commenting via menu or shortcut does not set sketch to "need save" @@ -26,11 +30,12 @@ A need to get GLGraphics examples out of the video examples A Examples > Video > GLGraphics X write quicktime uncompressed (w/o qtjava) X wrapped into the new moviemaker tool -X http://www.randelshofer.ch/blog/2010/10/writing-quicktime-movies-in-pure-java/ +X www.randelshofer.ch/blog/2010/10/writing-quicktime-movies-in-pure-java +X library imports failing for libs that define the same packages in 1.5.1 +X http://code.google.com/p/processing/issues/detail?id=725 +X Closing applet window in Processing 1.5 causes serial crash +X http://code.google.com/p/processing/issues/detail?id=635 -maybe fixed -_ library imports failing for libs that define the same packages in 1.5.1 -_ http://code.google.com/p/processing/issues/detail?id=725 _ renaming a normal tab to same name with ".java" fails with ".pde" version already exists _ http://code.google.com/p/processing/issues/detail?id=776 @@ -41,7 +46,6 @@ http://code.google.com/p/processing/issues/detail?id=545 recent sketches: http://code.google.com/p/processing/issues/detail?id=188 - _ move Movie Maker out to its own separate tool package (with separate build) _ http://code.google.com/p/processing/issues/detail?id=837 @@ -180,9 +184,6 @@ _ might be problematic since it might be opposite the javascript meaning _ jer: it's a decent time to start talking abt references/vars -_ Closing applet window in Processing 1.5 causes serial crash -_ http://code.google.com/p/processing/issues/detail?id=635 - _ Export reports "Could not copy source file" (even though it works) _ http://code.google.com/p/processing/issues/detail?id=638