diff --git a/processing/app/PdeBase.java b/processing/app/PdeBase.java index cb0cbad41..ad1ab8db4 100644 --- a/processing/app/PdeBase.java +++ b/processing/app/PdeBase.java @@ -479,11 +479,43 @@ public class PdeBase extends Frame this.pack(); // maybe this should be before the setBounds call - //editor.frame = frame; // no longer really used - //editor.init(); + + // figure out window placement + + Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); + boolean windowPositionInvalid = false; + + if (PdePreferences.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 = getInteger("last.screen.width"); + int screenH = getInteger("last.screen.height"); + + if ((screen.width != screenW) || (screen.height != screenH)) { + windowPositionInvalid = true; + } + } else { + windowPositionInvalid = true; + } + + if (windowPositionInvalid) { + int windowH = PdePreferences.getInteger("default.window.height"); + int windowW = PdePreferences.getInteger("default.window.width"); + setBounds((screen.width - windowW) / 2, + (screen.height - windowH) / 2, + windowW, windowH); + // this will be invalid as well, so grab the new value + PdePreferences.setInteger("last.divider.location", + splitPane.getDividerLocation()); + } else { + setBounds(PdePreferences.getInteger("last.window.x"), + PdePreferences.getInteger("last.window.y"), + PdePreferences.getInteger("last.window.width"), + PdePreferences.getInteger("last.window.height")); + } // now that everything is set up, open last-used sketch, etc. - prefs.apply(); + editor.init(); rebuildSketchbookMenu(sketchbookMenu); //buildSerialMenu(); diff --git a/processing/app/PdeEditor.java b/processing/app/PdeEditor.java index 7a0290259..8005771c7 100644 --- a/processing/app/PdeEditor.java +++ b/processing/app/PdeEditor.java @@ -73,7 +73,7 @@ public class PdeEditor extends JPanel { JEditTextArea textarea; - boolean externalEditor; + //boolean externalEditor; // currently opened program //String userName; // user currently logged in @@ -276,6 +276,66 @@ public class PdeEditor extends JPanel { } + /** + * Post-constructor setup for the editor area. Loads the last + * sketch that was used (if any), and restores other Editor settings. + */ + public void initPreferences() { + // load the last program that was in use + + String sketchName = PdePreferences.get("last.sketch.name"); + String sketchDir = PdePreferences.get("last.sketch.directory"); + + if (sketchName != null) { + if (new File(sketchDir + File.separator + sketchName).exists()) { + editor.skOpen(sketchDir, sketchName); + + } else { + editor.skNew(); + } + } + + // get the location for the console/editor area divider + + int location = PdePreferences.getInteger("last.divider.location"); + splitPane.setDividerLocation(location); + + // read the preferences that are settable in the preferences window + + applyPreferences() + } + + + public void applyPreferences() { + + // apply the setting for 'use external editor' + + boolean external = getBoolean("editor.external"); + + textarea.setEditable(!external); + base.saveMenuItem.setEnabled(!external); + base.saveAsMenuItem.setEnabled(!external); + base.beautifyMenuItem.setEnabled(!external); + + TextAreaPainter painter = textarea.getPainter(); + if (external) { + // disable line highlight and turn off the caret when disabling + Color bg = PdePreferences.getColor("editor.program.bgcolor.external"); + painter.setBackground(bg); + painter.lineHighlight = false; + textarea.setCaretVisible(false); + + } else { + painter.setBackground(PdePreferences.getColor("editor.program.bgcolor")); //, Color.white)); + painter.lineHighlight = PdePreferences.getBoolean("editor.program.linehighlight"); + textarea.setCaretVisible(true); + } + + + // + } + + protected void changeText(String what, boolean emptyUndo) { textarea.setText(what); @@ -597,7 +657,7 @@ public class PdeEditor extends JPanel { for (int i = 0; i < 10; i++) System.out.println(); - if (externalEditor) { + if (PdeBase.getBoolen("editor.external")) { // history gets screwed by the open.. String historySaved = historyLast; handleOpen(sketchName, sketchFile, sketchDir); @@ -1716,31 +1776,6 @@ public class PdeEditor extends JPanel { } - public void setExternalEditor(boolean external) { - this.externalEditor = external; - //System.out.println("setting ee to " + externalEditor); - - textarea.setEditable(!external); - //base.externalEditorItem.setState(external); - base.saveMenuItem.setEnabled(!external); - base.saveAsMenuItem.setEnabled(!external); - base.beautifyMenuItem.setEnabled(!external); - - // disable line highlight and turn off the caret when disabling - TextAreaPainter painter = textarea.getPainter(); - if (external) { - painter.setBackground(PdePreferences.getColor("editor.program.bgcolor.external", new Color(204, 204, 204))); - painter.lineHighlight = false; - textarea.setCaretVisible(false); - - } else { - painter.setBackground(PdePreferences.getColor("editor.program.bgcolor", Color.white)); - painter.lineHighlight = PdePreferences.getBoolean("editor.program.linehighlight.enabled", true); - textarea.setCaretVisible(true); - } - } - - public void addFile() { // get a dialog, select a file to add to the sketch String prompt = "Select an image or other data file to copy to your sketch"; diff --git a/processing/app/PdePreferences.java b/processing/app/PdePreferences.java index 305634cbf..c2c109380 100644 --- a/processing/app/PdePreferences.java +++ b/processing/app/PdePreferences.java @@ -55,6 +55,10 @@ import gnu.io.*; it contains the contents of pde.properties + pde_platform.properties and then begins writing additional sketch.properties stuff + + this class no longer uses the Properties class, since + properties files are iso8859-1, which is highly likely to + be a problem when trying to save sketch folders and locations */ public class PdePreferences extends JComponent { @@ -74,37 +78,14 @@ public class PdePreferences extends JComponent { // data model - static Properties properties; // needs to be accessible everywhere - static Hashtable defaults; + static Hashtable table; File preferencesFile; - boolean firstTime; // first time this feller has been run + //boolean firstTime; // first time this feller has been run public PdePreferences() { - /* - switch (PdeBase.platform) { - case PdeBase.WINDOWS: - // the larger divider on windows is ugly with the little arrows - // this makes it large enough to see (mouse changes) and use, - // but keeps it from being annoyingly obtrusive - defaults.put("editor.divider.size", "2"); - break; - - case PdeBase.MACOSX: - // the usual 12 point from other platforms is too big on osx - // monospaced on java 1.3 was monaco, but on 1.4 it has changed - // to courier, which actually matches other platforms better. - // (and removes the 12 point being too large issue) - // and monaco is nicer on macosx, so use that explicitly - defaults.put("editor.program.font", "Monaco,plain,10"); - defaults.put("editor.console.font", "Monaco,plain,10"); - break; - } - */ - - // getting started properties = new Properties(); @@ -119,25 +100,59 @@ public class PdePreferences extends JComponent { if (!preferencesFile.exists()) { // create a new preferences file if none exists - String platformFilename = - "pde_" + PdeBase.platforms[PdeBase.platform] + ".properties"; - try { if ((PdeBase.platform == PdeBase.MACOSX) || (PdeBase.platform == PdeBase.MACOS9)) { - properties.load(new FileInputStream("lib/pde.properties")); - properties.load(new FileInputStream("lib/" + platformFilename)); + load(new FileInputStream("lib/pde.properties")); } else { // under win95, current dir not set properly // so using a relative url like "lib/" won't work - properties.load(getClass().getResource("pde.properties").openStream()); - properties.load(getClass().getResource(platformFilename).openStream()); + load(getClass().getResource("pde.properties").openStream()); } } catch (Exception e) { - System.err.println("Error reading default settings"); - e.printStackTrace(); + showError(null, "Could not read default settings.\n" + + "You'll need to reinstall Processing.", e); + System.exit(1); + //System.err.println("Error reading default settings"); + //e.printStackTrace(); + } + + firstTime = true; + + } else { + // load the previous preferences file + + try { + load(new FileInputStream(preferencesFile)); + + } catch (Exception e) { + showError("Error reading preferences", + "Error reading the preferences file. Please delete\n" + + perferencesFile.getCanonicalPath() + "\n" + + "and restart Processing.", e); + } + } + + + // check for platform-specific properties + + String platformExtension = "." + PdeBase.platforms[PdeBase.platform]; + int extensionLength = platformExtension.length(); + + Enumeration e = properties.propertyNames(); + while (e.hasMoreElements()) { + String key = (String) e.nextElement(); + if (key.endsWith(platformExtension)) { + // this is a key specific to a particular platform + String actualKey = key.substring(0, key.length() - extensionLength); + String value = get(key); + + System.out.println("found platform specific prop \"" + + actualKey + "\" \"" + value + "\""); + properties.put(actualKey, value); + System.out.println("now set to " + table.get(actualKey)); } } @@ -295,76 +310,39 @@ public class PdePreferences extends JComponent { } + public void load(InputStream input) { + BufferedReader reader = + new BufferedReader(new InputStreamReader(input)); + + table = new Hashtable(); + String line = null; + while ((line = reader.readLine()) != null) { + if (line.charAt(0) == '#') continue; + + int equals = line.indexOf('='); + String key = line.substring(0, equals).trim(); + String value = line.substring(equals + 1).trim(); + table.put(key, value); + } + reader.close(); + } + + + // change settings based on what was chosen in the prefs public void apply() { - //if (external editor checked) { - editor.setExternalEditor(true); - //} + //editor.setExternalEditor(getBoolean("editor.external")); + // put each of the settings into the table } // open the last-used sketch, etc public void init() { - // load the last program that was in use - - Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - int windowX = -1, windowY = 0, windowW = 0, windowH = 0; - - //Properties skprops = new Properties(); - //try { - //if (PdeBase.platform == PdeBase.MACOSX) { - //String pkg = "Proce55ing.app/Contents/Resources/Java/"; - //skprops.load(new FileInputStream(pkg + "sketch.properties")); - //skprops.load(new FileInputStream("lib/sketch.properties")); - - //} else if (PdeBase.platform == PdeBase.MACOS9) { - // skprops.load(new FileInputStream("lib/sketch.properties")); - - //} else { - //skprops.load(getClass().getResource("sketch.properties").openStream()); - //} - - windowX = Integer.parseInt(skprops.getProperty("last.window.x", "-1")); - windowY = Integer.parseInt(skprops.getProperty("last.window.y", "-1")); - windowW = Integer.parseInt(skprops.getProperty("last.window.w", "-1")); - windowH = Integer.parseInt(skprops.getProperty("last.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("last.screen.w", "-1")); - int screenH = Integer.parseInt(skprops.getProperty("last.screen.h", "-1")); - - if ((screen.width != screenW) || (screen.height != screenH)) { - // probably not valid for this machine, so invalidate sizing - windowX = -1; - } - - if (windowX != -1) { - String dividerLocation = - skprops.getProperty("last.divider.location"); - if (dividerLocation != null) { - splitPane.setDividerLocation(Integer.parseInt(dividerLocation)); - } - } - - // - - String path = skprops.getProperty("last.sketch.directory"); - String name = skprops.getProperty("last.sketch.name"); //String what = path + File.separator + name + ".pde"; - if (new File(path + File.separator + name + ".pde").exists()) { - //userName = user; - editor.skOpen(path, name); - - } else { - //userName = "default"; - editor.skNew(); - } - // ///String serialPort = skprops.getProperty("serial.port"); @@ -381,26 +359,15 @@ public class PdePreferences extends JComponent { //e.printStackTrace(); // indicator that this is the first time this feller has used p5 - firstTime = true; + //firstTime = true; // even if folder for 'default' user doesn't exist, or // sketchbook itself is missing, mkdirs() will make it happy //userName = "default"; // doesn't exist, not available, make my own - skNew(); - } - - if (windowX == -1) { - //System.out.println("using defaults for window size"); - windowW = PdePreferences.getInteger("window.width", 500); - windowH = PdePreferences.getInteger("window.height", 500); - windowX = (screen.width - windowW) / 2; - windowY = (screen.height - windowH) / 2; - } - //PdeBase.frame.setBounds(windowX, windowY, windowW, windowH); - base.setBounds(windowX, windowY, windowW, windowH); - //rebuildSketchbookMenu(PdeBase.sketchbookMenu); + //skNew(); + //} } /* @@ -478,8 +445,13 @@ public class PdePreferences extends JComponent { //skprops.put("serial.port", PdePreferences.get("serial.port", "unspecified")); - skprops.save(output, "Settings for processing. " + - "See lib/pde.properties for defaults."); + // save() is deprecated, and didn't properly + // throw exceptions when it wasn't working + skprops.store(output, "Settings for processing. " + + "See lib/pde.properties for defaults."); + + // need to close the stream.. didn't do this before + skprops.close(); } catch (IOException e) { PdeBase.showError(null, "Error while saving the settings file", e); diff --git a/processing/build/linux/dist.sh b/processing/build/linux/dist.sh index 15d4898e3..943607952 100755 --- a/processing/build/linux/dist.sh +++ b/processing/build/linux/dist.sh @@ -54,14 +54,14 @@ rm -rf processing/lib/export/CVS #cp work/Proce55ing processing/ #cp work/processing processing/ install -m 755 stub.sh processing/processing -cp dist/lib/pde_linux.properties processing/lib/ +#cp dist/lib/pde_linux.properties processing/lib/ # make sure notes.txt is unix LFs # the 2> is because the app is a little chatty dos2unix processing/readme.txt 2> /dev/null dos2unix processing/revisions.txt 2> /dev/null dos2unix processing/lib/pde.properties 2> /dev/null -dos2unix processing/lib/pde_linux.properties 2> /dev/null +#dos2unix processing/lib/pde_linux.properties 2> /dev/null # get the serial stuff echo Copying serial support from bagel dir diff --git a/processing/build/linux/dist/lib/pde_linux.properties b/processing/build/linux/dist/lib/pde_linux.properties deleted file mode 100644 index e69de29bb..000000000 diff --git a/processing/build/linux/make.sh b/processing/build/linux/make.sh index 42338c880..ce941adfc 100755 --- a/processing/build/linux/make.sh +++ b/processing/build/linux/make.sh @@ -26,7 +26,7 @@ else mkdir work/lib/build mkdir work/classes - cp dist/lib/pde_linux.properties work/lib/ + #cp dist/lib/pde_linux.properties work/lib/ # get the serial stuff echo Copying serial support from bagel dir diff --git a/processing/build/macosx/dist.sh b/processing/build/macosx/dist.sh index c93fa1807..d1a695da3 100755 --- a/processing/build/macosx/dist.sh +++ b/processing/build/macosx/dist.sh @@ -97,7 +97,7 @@ rm -rf processing/lib/export/CVS cp dist/jikes processing/ chmod a+x processing/jikes -cp dist/lib/pde_macosx.properties processing/lib/ +#cp dist/lib/pde_macosx.properties processing/lib/ # convert notes.txt to windows LFs # the 2> is because the app is a little chatty diff --git a/processing/build/macosx/dist/lib/pde_macosx.properties b/processing/build/macosx/dist/lib/pde_macosx.properties deleted file mode 100644 index 2962304c9..000000000 --- a/processing/build/macosx/dist/lib/pde_macosx.properties +++ /dev/null @@ -1,11 +0,0 @@ -# the usual 12 point from other platforms is too big on osx - -# monospaced on java 1.3 was monaco, but on 1.4 it has changed -# to courier, which actually matches other platforms better. -# (and removes the 12 point being too large issue) -#editor.program.font = Monospaced,plain,10 -#editor.console.font = Monospaced,plain,10 - -# ...but monaco is nicer on macosx, so use that explicitly -editor.program.font = Monaco,plain,10 -editor.console.font = Monaco,plain,10 diff --git a/processing/build/macosx/make.sh b/processing/build/macosx/make.sh index 98eddffc2..f76c9ec7e 100755 --- a/processing/build/macosx/make.sh +++ b/processing/build/macosx/make.sh @@ -48,7 +48,7 @@ else mkdir work/classes # get a copy of the mac-specific properties - cp dist/lib/pde_macosx.properties work/lib/ + #cp dist/lib/pde_macosx.properties work/lib/ # grab serial goodies echo Copying serial support from bagel dir... diff --git a/processing/build/shared/lib/pde.properties b/processing/build/shared/lib/pde.properties index f2af1b486..89ac3e825 100644 --- a/processing/build/shared/lib/pde.properties +++ b/processing/build/shared/lib/pde.properties @@ -8,69 +8,74 @@ # usually, the default is listed here, just commented out +# default size for the main window +default.window.width = 500 +default.window.height = 500 + + # TextAreaDefaults.java # font size for editor -editor.program.font=Monospaced,plain,12 +editor.font=Monospaced,plain,12 # anti-aliased text, turned off by default -editor.program.antialias=false +editor.antialias=false # foreground and background colors -editor.program.fgcolor=#000000 -editor.program.bgcolor=#ffffff +editor.fgcolor=#000000 +editor.bgcolor=#ffffff # color to be used for background when 'external editor' enabled -editor.program.bgcolor.external=#ddddbb +editor.bgcolor.external=#ddddbb # styles for various types of text # comments -editor.program.comment1.style=#777755,plain -editor.program.comment2.style=#777755,plain +editor.comment1.style=#777755,plain +editor.comment2.style=#777755,plain # abstract, final, private -editor.program.keyword1.style=#cc6600,plain +editor.keyword1.style=#cc6600,plain # beginShape, point, line -editor.program.keyword2.style=#996600,plain +editor.keyword2.style=#996600,plain # byte, char, short, color -editor.program.keyword3.style=#993300,bold +editor.keyword3.style=#993300,bold # constants: null, true, this, RGB, TWO_PI -editor.program.literal1.style=#cc0000,plain +editor.literal1.style=#cc0000,plain # p5 built in variables: mouseX, width, pixels -editor.program.literal2.style=#cc0000,plain +editor.literal2.style=#cc0000,plain # ?? maybe this is for words followed by a colon # like in case statements or goto -editor.program.label.style=#7E7E00,bold +editor.label.style=#7E7E00,bold # + - = / -editor.program.operator.style=#000000,plain +editor.operator.style=#000000,plain # caret blinking and caret color -editor.program.caret.blink=true -editor.program.caret.color=#333300 +editor.caret.blink=true +editor.caret.color=#333300 # selection color -editor.program.selection.color=#ffcc00 -editor.program.selection.color=#cccc00 +editor.selection.color=#ffcc00 +editor.selection.color=#cccc00 # highlight for the current line -editor.program.linehighlight.enabled=true -editor.program.linehighlight.color=#ddddbb +editor.linehighlight=true +editor.linehighlight.color=#ddddbb # bracket/brace highlighting -editor.program.brackethighlight.enabled=true -editor.program.brackethighligh.color=#ffcc00 +editor.brackethighlight=true +editor.brackethighligh.color=#ffcc00 # little pooties at the end of lines that show where they finish -editor.program.eolmarkers.enabled=false -editor.program.eolmarkers.color=#99991A +editor.eolmarkers=false +editor.eolmarkers.color=#99991A # area that's not in use by the text (replaced with tildes) -editor.program.invalid.enabled=false -editor.program.invalid.style=#7E7E00,bold +editor.invalid=false +editor.invalid.style=#7E7E00,bold editor.buttons.bgcolor = #999988 @@ -82,11 +87,18 @@ editor.header.fgcolor.primary = #ffffff editor.header.fgcolor.secondary = #ccccbb editor.header.font = SansSerif,plain,12 -editor.console.bgcolor = #1A1A00 -editor.console.fgcolor.output = #ccccbb -editor.console.fgcolor.error = #ff3000 -editor.console.font = Monospaced,plain,11 -editor.console.lines = 4 +console.bgcolor = #1A1A00 +console.fgcolor.output = #ccccbb +console.fgcolor.error = #ff3000 +console.font = Monospaced,plain,11 +console.lines = 4 + +# monospaced on java 1.3 was monaco, but on 1.4 it has changed +# to courier, which actually matches other platforms better. +# (and removes the 12 point being too large issue) +# monaco is nicer on macosx, so use that explicitly +editor.font.macosx = Monaco,plain,10 +console.font.macosx = Monaco,plain,10 editor.status.notice.fgcolor = #333322 editor.status.notice.bgcolor = #bbbbaa @@ -100,6 +112,13 @@ editor.status.font = SansSerif,plain,12 editor.tabs.expand = true editor.tabs.size = 2 +# size of divider between editing area and the console +editor.divider.size = 0 +# the larger divider on windows is ugly with the little arrows +# this makes it large enough to see (mouse changes) and use, +# but keeps it from being annoyingly obtrusive +editor.divider.size.windows = 2 + # automatically indent each line editor.indent = true @@ -109,15 +128,6 @@ editor.wheelmouse.multiplier = 3 # background color for full-screen presentation mode run.present.bgcolor = #666666 -# these are the defaults for the serial port -# un-comment them and set them to different values if you'd -# rather have something else as the default -#serial.port = COM1 -#serial.rate = 9600 -#serial.parity = N -#serial.databits = 8 -#serial.stopbits = 1 - # preliminary for rev 0047, can point sketchbook at # another location. this can be a full or relative path diff --git a/processing/build/windows/dist.sh b/processing/build/windows/dist.sh index c3d85c7f2..0fab00f6d 100755 --- a/processing/build/windows/dist.sh +++ b/processing/build/windows/dist.sh @@ -64,7 +64,7 @@ chmod +x processing/jikes.exe # get platform-specific goodies from the dist dir cp launcher/processing.exe processing/ cp dist/run.bat processing/ -cp dist/lib/pde_windows.properties processing/lib/ +#cp dist/lib/pde_windows.properties processing/lib/ # get serial stuff from the bagel dir cp ../../bagel/serial/comm.jar processing/lib/ @@ -77,7 +77,7 @@ chmod +x processing/win32com.dll unix2dos processing/readme.txt 2> /dev/null unix2dos processing/revisions.txt 2> /dev/null unix2dos processing/lib/pde.properties 2> /dev/null -unix2dos processing/lib/pde_windows.properties 2> /dev/null +#unix2dos processing/lib/pde_windows.properties 2> /dev/null # zip it all up for release echo Packaging standard release... diff --git a/processing/build/windows/dist/lib/pde_windows.properties b/processing/build/windows/dist/lib/pde_windows.properties deleted file mode 100644 index a06983a0d..000000000 --- a/processing/build/windows/dist/lib/pde_windows.properties +++ /dev/null @@ -1,7 +0,0 @@ -# default serial port for windows -serial.port=COM1 - -# the larger divider on windows is ugly with the little arrows -# this makes it large enough to see (mouse changes) and use, -# but keeps it from being annoyingly obtrusive -editor.divider.size=2 diff --git a/processing/build/windows/make.sh b/processing/build/windows/make.sh index 574131524..cd05d4155 100755 --- a/processing/build/windows/make.sh +++ b/processing/build/windows/make.sh @@ -68,7 +68,7 @@ else # could be made and checked back in.. interesting mkdir work/classes - cp dist/lib/pde_windows.properties work/lib/ + #cp dist/lib/pde_windows.properties work/lib/ echo Compiling processing.exe cd launcher make && cp processing.exe ../work/