diff --git a/app/src/processing/app/Base.java b/app/src/processing/app/Base.java index 2b778d607..d1e9541e0 100644 --- a/app/src/processing/app/Base.java +++ b/app/src/processing/app/Base.java @@ -3,13 +3,12 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2004-08 Ben Fry and Casey Reas + Copyright (c) 2004-09 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 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 @@ -44,14 +43,14 @@ public class Base { static final int REVISION = 18; static String VERSION_NAME = "0018"; - static HashMap platformNames = new HashMap(); + static HashMap platformNames = new HashMap(); static { platformNames.put(PConstants.WINDOWS, "windows"); platformNames.put(PConstants.MACOSX, "macosx"); platformNames.put(PConstants.LINUX, "linux"); } - static HashMap platformIndices = new HashMap(); + static HashMap platformIndices = new HashMap(); static { platformIndices.put("windows", PConstants.WINDOWS); platformIndices.put("macosx", PConstants.MACOSX); @@ -75,7 +74,7 @@ public class Base { static private File librariesFolder; static private File toolsFolder; static private File hardwareFolder; - + static HashSet libraries; // maps imported packages to their library folder @@ -90,7 +89,7 @@ public class Base { static File untitledFolder; // p5 icon for the window - static Image icon; +// static Image icon; // int editorCount; // Editor[] editors; @@ -102,8 +101,24 @@ public class Base { // int nextEditorX; // int nextEditorY; +// import com.sun.jna.Library; +// import com.sun.jna.Native; + +// public interface CLibrary extends Library { +// CLibrary INSTANCE = (CLibrary)Native.loadLibrary("c", CLibrary.class); +// int setenv(String name, String value, int overwrite); +// String getenv(String name); +// int unsetenv(String name); +// int putenv(String string); +// } + static public void main(String args[]) { +// /Users/fry/coconut/sketchbook/libraries/gsvideo/library +// CLibrary clib = CLibrary.INSTANCE; +// clib.setenv("DYLD_LIBRARY_PATH", "/Users/fry/coconut/sketchbook/libraries/gsvideo/library", 1); +// System.out.println("env is now " + clib.getenv("DYLD_LIBRARY_PATH")); + try { File versionFile = getContentFile("lib/version.txt"); if (versionFile.exists()) { @@ -188,12 +203,14 @@ public class Base { "b { font: 13pt \"Lucida Grande\" }"+ "p { font: 11pt \"Lucida Grande\"; margin-top: 8px }"+ " " + - "The standard menu bar has been disabled." + - "

Due to an Apple bug, the Arduino menu bar " + - "is unusable on Mac OS X 10.5.
" + - "As a workaround, the menu bar will be placed inside " + - "the editor window. This
setting can be changed in the " + - "Preferences window. If this bug makes you sad,
" + + "Some menus have been disabled." + + "

Due to an Apple bug, the Sketchbook and Example menus " + + "are unusable.
" + + "As a workaround, these items will be disabled from the " + + "standard menu bar,
" + + "but you can use the Open button on " + + "the toolbar to access the same items.
" + + "If this bug makes you sad, " + "please contact Apple via bugreporter.apple.com.

" + " "; Object[] options = { "OK", "More Info" }; @@ -210,13 +227,18 @@ public class Base { // But don't bother setting the preference in the file } else { // Shut off in the preferences for next time - Preferences.set(properMenuBar, "false"); + //Preferences.set(properMenuBar, "false"); + // For 1.0.4, we'll stick with the Apple menu bar, + // and just disable the sketchbook and examples sub-menus. + Preferences.set(properMenuBar, "true"); if (result == 1) { // More Info Base.openURL("http://dev.processing.org/bugs/show_bug.cgi?id=786"); } } // Whether or not canceled, set to false (right now) if we're on 10.5 - System.setProperty(properMenuBar, "false"); + //System.setProperty(properMenuBar, "false"); + // Changing this behavior for 1.0.4 + System.setProperty(properMenuBar, "true"); } } } @@ -711,13 +733,17 @@ public class Base { protected Editor handleOpen(String path, int[] location) { +// System.err.println("entering handleOpen " + path); + File file = new File(path); if (!file.exists()) return null; +// System.err.println(" editors: " + editors); // Cycle through open windows to make sure that it's not already open. for (Editor editor : editors) { if (editor.getSketch().getMainFilePath().equals(path)) { editor.toFront(); +// System.err.println(" handleOpen: already opened"); return editor; } } @@ -736,10 +762,23 @@ public class Base { // } // } +// System.err.println(" creating new editor"); Editor editor = new Editor(this, path, location); +// Editor editor = null; +// try { +// editor = new Editor(this, path, location); +// } catch (Exception e) { +// e.printStackTrace(); +// System.err.flush(); +// System.out.flush(); +// System.exit(1); +// } +// System.err.println(" done creating new editor"); +// EditorConsole.systemErr.println(" done creating new editor"); // Make sure that the sketch actually loaded if (editor.getSketch() == null) { +// System.err.println("sketch was null, getting out of handleOpen"); return null; // Just walk away quietly } @@ -763,6 +802,8 @@ public class Base { // (don't do earlier, cuz we might move it based on a window being closed) editor.setVisible(true); +// System.err.println("exiting handleOpen"); + return editor; } @@ -952,9 +993,16 @@ public class Base { protected void rebuildSketchbookMenu(JMenu menu) { //System.out.println("rebuilding sketchbook menu"); //new Exception().printStackTrace(); + boolean nativeButBroken = Base.isMacOS() ? + Preferences.getBoolean("apple.laf.useScreenMenuBar") : false; + try { - menu.removeAll(); - addSketches(menu, getSketchbookFolder(), false); + if (nativeButBroken) { // osx workaround + menu.setEnabled(false); + } else { + menu.removeAll(); + addSketches(menu, getSketchbookFolder(), false); + } } catch (IOException e) { e.printStackTrace(); } @@ -964,40 +1012,52 @@ public class Base { public void rebuildImportMenu(JMenu importMenu) { //System.out.println("rebuilding import menu"); importMenu.removeAll(); - + // reset the set of libraries libraries = new HashSet(); // reset the table mapping imports to libraries importToLibraryTable = new HashMap(); - // Add libraries found in the sketchbook folder - try { - File sketchbookLibraries = getSketchbookLibrariesFolder(); - boolean found = addLibraries(importMenu, sketchbookLibraries); - if (found) importMenu.addSeparator(); - } catch (IOException e) { - e.printStackTrace(); - } // Add from the "libraries" subfolder in the Processing directory try { addLibraries(importMenu, librariesFolder); } catch (IOException e) { e.printStackTrace(); } + // Add libraries found in the sketchbook folder + int separatorIndex = importMenu.getItemCount(); + try { + File sketchbookLibraries = getSketchbookLibrariesFolder(); + boolean found = addLibraries(importMenu, sketchbookLibraries); + if (found) { + JMenuItem contrib = new JMenuItem("Contributed"); + contrib.setEnabled(false); + importMenu.insert(contrib, separatorIndex); + importMenu.insertSeparator(separatorIndex); + } + } catch (IOException e) { + e.printStackTrace(); + } } public void rebuildExamplesMenu(JMenu menu) { //System.out.println("rebuilding examples menu"); + boolean nativeButBroken = Base.isMacOS() ? + Preferences.getBoolean("apple.laf.useScreenMenuBar") : false; try { - menu.removeAll(); - boolean found = addSketches(menu, examplesFolder, false); - if (found) menu.addSeparator(); - found = addSketches(menu, getSketchbookLibrariesFolder(), false); - if (found) menu.addSeparator(); - addSketches(menu, librariesFolder, false); + if (nativeButBroken) { // osx workaround + menu.setEnabled(false); + } else { + menu.removeAll(); + boolean found = addSketches(menu, examplesFolder, false); + if (found) menu.addSeparator(); + found = addSketches(menu, getSketchbookLibrariesFolder(), false); + if (found) menu.addSeparator(); + addSketches(menu, librariesFolder, false); + } } catch (IOException e) { e.printStackTrace(); } @@ -1084,18 +1144,18 @@ public class Base { boolean found = addSketches(menu, subfolder, openReplaces); //, false); if (found) ifound = true; } else { - // not a sketch folder, but maybe a subfolder containing sketches - JMenu submenu = new JMenu(list[i]); - // needs to be separate var - // otherwise would set ifound to false - boolean found = addSketches(submenu, subfolder, openReplaces); //, false); - if (found) { - menu.add(submenu); - ifound = true; - } + // not a sketch folder, but maybe a subfolder containing sketches + JMenu submenu = new JMenu(list[i]); + // needs to be separate var + // otherwise would set ifound to false + boolean found = addSketches(submenu, subfolder, openReplaces); //, false); + if (found) { + menu.add(submenu); + ifound = true; } } } + } return ifound; // actually ignored, but.. } @@ -1126,23 +1186,24 @@ public class Base { boolean ifound = false; - for (String libraryName : list) { - File subfolder = new File(folder, libraryName); + for (String potentialName : list) { + File subfolder = new File(folder, potentialName); // File libraryFolder = new File(subfolder, "library"); -// File libraryJar = new File(libraryFolder, libraryName + ".jar"); +// File libraryJar = new File(libraryFolder, potentialName + ".jar"); // // If a .jar file of the same prefix as the folder exists // // inside the 'library' subfolder of the sketch // if (libraryJar.exists()) { - String sanityCheck = Sketch.sanitizeName(libraryName); - if (!sanityCheck.equals(libraryName)) { + String sanityCheck = Sketch.sanitizeName(potentialName); + if (!sanityCheck.equals(potentialName)) { String mess = - "The library \"" + libraryName + "\" cannot be used.\n" + + "The library \"" + potentialName + "\" cannot be used.\n" + "Library names must contain only basic letters and numbers.\n" + - "(ascii only and no spaces, and it cannot start with a number)"; + "(ASCII only and no spaces, and it cannot start with a number)"; Base.showMessage("Ignoring bad library name", mess); continue; } + String libraryName = potentialName; // // get the path for all .jar files in this code folder // String libraryClassPath = // Compiler.contentsToClassPath(libraryFolder); @@ -1399,8 +1460,8 @@ public class Base { } return null; } - - + + static public Set getLibraries() { return libraries; } @@ -1424,8 +1485,8 @@ public class Base { static public String getToolsPath() { return toolsFolder.getAbsolutePath(); } - - + + static public File getHardwareFolder() { // calculate on the fly because it's needed by Preferences.init() to find // the boards.txt and programmers.txt preferences files (which happens @@ -1457,8 +1518,8 @@ public class Base { static public File getSketchbookLibrariesFolder() { return new File(getSketchbookFolder(), "libraries"); } - - + + static public String getSketchbookLibrariesPath() { return getSketchbookLibrariesFolder().getAbsolutePath(); } @@ -1658,7 +1719,7 @@ public class Base { File referenceFile = new File(referenceFolder, filename); openURL(referenceFile.getAbsolutePath()); } - + static public void showGettingStarted() { if (Base.isMacOS()) { Base.showReference("Guide_MacOSX.html"); @@ -1687,8 +1748,8 @@ public class Base { static public void showTroubleshooting() { showReference("Guide_Troubleshooting.html"); } - - + + static public void showFAQ() { showReference("faq.html"); } diff --git a/app/src/processing/app/Editor.java b/app/src/processing/app/Editor.java index dd49ec04d..1775e171d 100644 --- a/app/src/processing/app/Editor.java +++ b/app/src/processing/app/Editor.java @@ -3,13 +3,12 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2004-08 Ben Fry and Casey Reas + Copyright (c) 2004-09 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 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 @@ -81,7 +80,7 @@ public class Editor extends JFrame implements RunnerListener { JMenu fileMenu; JMenu sketchMenu; JMenu toolsMenu; - + int numTools = 0; EditorToolbar toolbar; @@ -91,7 +90,7 @@ public class Editor extends JFrame implements RunnerListener { static JMenu sketchbookMenu; static JMenu examplesMenu; static JMenu importMenu; - + // these menus are shared so that the board and serial port selections // are the same for all windows (since the board and serial port that are // actually used are determined by the preferences, which are shared) @@ -161,8 +160,8 @@ public class Editor extends JFrame implements RunnerListener { // When bringing a window to front, let the Base know addWindowListener(new WindowAdapter() { public void windowActivated(WindowEvent e) { +// System.err.println("activate"); // not coming through base.handleActivated(Editor.this); - // re-add the sub-menus that are shared by all windows fileMenu.insert(sketchbookMenu, 2); fileMenu.insert(examplesMenu, 3); @@ -170,11 +169,22 @@ public class Editor extends JFrame implements RunnerListener { toolsMenu.insert(boardsMenu, numTools); toolsMenu.insert(serialMenu, numTools + 1); } + + // added for 1.0.5 + // http://dev.processing.org/bugs/show_bug.cgi?id=1260 + public void windowDeactivated(WindowEvent e) { +// System.err.println("deactivate"); // not coming through + fileMenu.remove(sketchbookMenu); + fileMenu.remove(examplesMenu); + sketchMenu.remove(importMenu); + toolsMenu.remove(boardsMenu); + toolsMenu.remove(serialMenu); + } }); //PdeKeywords keywords = new PdeKeywords(); //sketchbook = new Sketchbook(this); - + if (serialMonitor == null) serialMonitor = new SerialMonitor(Preferences.get("serial.port")); @@ -717,7 +727,7 @@ public class Editor extends JFrame implements RunnerListener { URL[] urlList = new URL[archives.length]; for (int j = 0; j < urlList.length; j++) { - urlList[j] = archives[j].toURL(); + urlList[j] = archives[j].toURI().toURL(); } URLClassLoader loader = new URLClassLoader(urlList); @@ -819,7 +829,7 @@ public class Editor extends JFrame implements RunnerListener { final Tool tool = (Tool) toolClass.newInstance(); JMenuItem item = new JMenuItem(tool.getMenuTitle()); - + tool.init(Editor.this); item.addActionListener(new ActionListener() { @@ -828,14 +838,14 @@ public class Editor extends JFrame implements RunnerListener { } }); return item; - + } catch (Exception e) { e.printStackTrace(); return null; } } - - + + protected JMenu addInternalTools(JMenu menu) { JMenuItem item; @@ -963,7 +973,9 @@ public class Editor extends JFrame implements RunnerListener { protected JMenu buildHelpMenu() { - JMenu menu = new JMenu("Help"); + // To deal with a Mac OS X 10.5 bug, add an extra space after the name + // so that the OS doesn't try to insert its slow help menu. + JMenu menu = new JMenu("Help "); JMenuItem item; /* @@ -1764,7 +1776,7 @@ public class Editor extends JFrame implements RunnerListener { SwingUtilities.invokeLater(new Runnable() { public void run() { - try { + try { sketch.compile(new Target( Base.getHardwarePath() + File.separator + "cores", Preferences.get("boards." + Preferences.get("board") + ".build.core")), @@ -1776,10 +1788,10 @@ public class Editor extends JFrame implements RunnerListener { } catch (Exception e) { e.printStackTrace(); - } - + } + toolbar.deactivate(EditorToolbar.RUN); - } + } }); } @@ -2237,8 +2249,8 @@ public class Editor extends JFrame implements RunnerListener { } return true; } - - + + public void handleSerial() { if (uploading) return; serialMonitor.setVisible(true); diff --git a/app/src/processing/app/EditorConsole.java b/app/src/processing/app/EditorConsole.java index e8dc578f1..002fb3edd 100644 --- a/app/src/processing/app/EditorConsole.java +++ b/app/src/processing/app/EditorConsole.java @@ -305,16 +305,17 @@ public class EditorConsole extends JScrollPane { public void flush() { } public void write(byte b[]) { // appears never to be used -// if (currentConsole.isDisplayable()) { - currentConsole.write(b, 0, b.length, err); -// } else { -// systemOut.println("not displayable"); -// if (err) { -// systemErr.write(b, 0, b.length); -// } else { -// systemOut.write(b, 0, b.length); -// } -// } + if (currentConsole != null) { + currentConsole.write(b, 0, b.length, err); + } else { + try { + if (err) { + systemErr.write(b); + } else { + systemOut.write(b); + } + } catch (IOException e) { } // just ignore, where would we write? + } OutputStream echo = err ? stderrFile : stdoutFile; if (echo != null) { @@ -329,18 +330,17 @@ public class EditorConsole extends JScrollPane { } public void write(byte b[], int offset, int length) { - currentConsole.write(b, offset, length, err); -// if (currentConsole.isDisplayable()) { -// systemOut.println("is displayable"); -// currentConsole.write(b, offset, length, err); -// } else { -// systemOut.println("not displayable"); -// if (err) { -// systemErr.write(b, offset, length); -// } else { -// systemOut.write(b, offset, length); -// } -// } + if (currentConsole != null) { + currentConsole.write(b, offset, length, err); + } else { + try { + if (err) { + systemErr.write(b); + } else { + systemOut.write(b); + } + } catch (IOException e) { } // just ignore, where would we write? + } OutputStream echo = err ? stderrFile : stdoutFile; if (echo != null) { @@ -356,7 +356,12 @@ public class EditorConsole extends JScrollPane { public void write(int b) { single[0] = (byte)b; - currentConsole.write(single, 0, 1, err); + if (currentConsole != null) { + currentConsole.write(single, 0, 1, err); + } else { + // redirect for all the extra handling above + write(new byte[] { (byte) b }, 0, 1); + } OutputStream echo = err ? stderrFile : stdoutFile; if (echo != null) { diff --git a/app/src/processing/app/EditorToolbar.java b/app/src/processing/app/EditorToolbar.java index 38d8d5648..6a5fe2214 100644 --- a/app/src/processing/app/EditorToolbar.java +++ b/app/src/processing/app/EditorToolbar.java @@ -53,7 +53,7 @@ public class EditorToolbar extends JComponent implements MouseInputListener { static final int OPEN = 3; static final int SAVE = 4; static final int EXPORT = 5; - + static final int SERIAL = 6; static final int INACTIVE = 0; diff --git a/app/src/processing/app/Preferences.java b/app/src/processing/app/Preferences.java index 623ff807f..23bb979d8 100644 --- a/app/src/processing/app/Preferences.java +++ b/app/src/processing/app/Preferences.java @@ -3,7 +3,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2004-06 Ben Fry and Casey Reas + Copyright (c) 2004-09 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 @@ -34,8 +34,6 @@ import processing.app.syntax.*; import processing.core.*; - - /** * Storage class for user preferences and environment settings. *

@@ -144,9 +142,9 @@ public class Preferences { // data model - static Hashtable defaults; - static Hashtable table = new Hashtable();; - static Hashtable prefixes = new Hashtable(); + static HashMap defaults; + static HashMap table = new HashMap();; + static HashMap> prefixes = new HashMap>(); static File preferencesFile; @@ -161,22 +159,8 @@ public class Preferences { "You'll need to reinstall Arduino.", e); } - // check for platform-specific properties in the defaults - String platformExt = "." + PConstants.platformNames[PApplet.platform]; - int platformExtLength = platformExt.length(); - Enumeration e = table.keys(); - while (e.hasMoreElements()) { - String key = (String) e.nextElement(); - if (key.endsWith(platformExt)) { - // this is a key specific to a particular platform - String actualKey = key.substring(0, key.length() - platformExtLength); - String value = get(key); - table.put(actualKey, value); - } - } - // clone the hash table - defaults = (Hashtable) table.clone(); + defaults = (HashMap) table.clone(); // other things that have to be set explicitly for the defaults setColor("run.window.bgcolor", SystemColor.control); @@ -231,8 +215,8 @@ public class Preferences { "Error reading the board definitions file (" + new File(Base.getHardwareFolder(), "boards.txt").getAbsolutePath() + "). " + "Please re-download or re-unzip Arduino.\n", ex); - } - + } + try { load(new FileInputStream(new File(Base.getHardwareFolder(), "programmers.txt")), "programmers"); @@ -445,6 +429,20 @@ public class Preferences { top += d.height; // + GUI_SMALL; label = new JLabel(preferencesFile.getAbsolutePath()); + final JLabel clickable = label; + label.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + Base.openFolder(Base.getSettingsFolder()); + } + + public void mouseEntered(MouseEvent e) { + clickable.setForeground(new Color(0, 0, 140)); + } + + public void mouseExited(MouseEvent e) { + clickable.setForeground(Color.BLACK); + } + }); pain.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); @@ -678,12 +676,16 @@ public class Preferences { } static protected void load(InputStream input, String prefix) throws IOException { - Map table = new LinkedHashMap(); + LinkedHashMap table = new LinkedHashMap(); prefixes.put(prefix, table); load(input, table); } static protected void load(InputStream input, Map table) throws IOException { + // check for platform-specific properties in the defaults + String platformExt = "." + PConstants.platformNames[PApplet.platform]; + int platformExtLength = platformExt.length(); + String[] lines = PApplet.loadStrings(input); // Reads as UTF-8 for (String line : lines) { if ((line.length() == 0) || @@ -693,6 +695,12 @@ public class Preferences { int equals = line.indexOf('='); if (equals != -1) { String key = line.substring(0, equals).trim(); + + // check if this is a platform-specific key, and if so, shave things + if (key.endsWith(platformExt)) { + // this is a key specific to this platform + key = key.substring(0, key.length() - platformExtLength); + } String value = line.substring(equals + 1).trim(); table.put(key, value); } @@ -713,10 +721,8 @@ public class Preferences { // Fix for 0163 to properly use Unicode when writing preferences.txt PrintWriter writer = PApplet.createWriter(preferencesFile); - Enumeration e = table.keys(); //properties.propertyNames(); - while (e.hasMoreElements()) { - String key = (String) e.nextElement(); - writer.println(key + "=" + ((String) table.get(key))); + for (String key : table.keySet()) { + writer.println(key + "=" + table.get(key)); } writer.flush(); @@ -742,15 +748,15 @@ public class Preferences { // preference files, look up the attribute in that file's Hashtable // (don't override with or fallback to the main file). otherwise, // look up the attribute in the main file's Hashtable. - Map table = Preferences.table; + HashMap table = Preferences.table; if (attribute.indexOf('.') != -1) { String prefix = attribute.substring(0, attribute.indexOf('.')); if (prefixes.containsKey(prefix)) { - table = (Map) prefixes.get(prefix); + table = prefixes.get(prefix); attribute = attribute.substring(attribute.indexOf('.') + 1); } } - return (String) table.get(attribute); + return table.get(attribute); /* //String value = (properties != null) ? //properties.getProperty(attribute) : applet.getParameter(attribute); @@ -785,7 +791,7 @@ public class Preferences { static public String getDefault(String attribute) { - return (String) defaults.get(attribute); + return defaults.get(attribute); } @@ -845,7 +851,7 @@ public class Preferences { static public Color getColor(String name) { - Color parsed = Color.GRAY; // set a default + Color parsed = Color.GRAY; // set a default String s = get(name); if ((s != null) && (s.indexOf("#") == 0)) { try { @@ -857,11 +863,6 @@ public class Preferences { static public void setColor(String attr, Color what) { -// String r = Integer.toHexString(what.getRed()); -// String g = Integer.toHexString(what.getGreen()); -// String b = Integer.toHexString(what.getBlue()); -// set(attr, "#" + r.substring(r.length() - 2) + -// g.substring(g.length() - 2) + b.substring(b.length() - 2)); set(attr, "#" + PApplet.hex(what.getRGB() & 0xffffff, 6)); } @@ -911,7 +912,7 @@ public class Preferences { String s = st.nextToken(); if (s.indexOf("#") == 0) s = s.substring(1); - Color color = Color.DARK_GRAY; + Color color = Color.DARK_GRAY; try { color = new Color(Integer.parseInt(s, 16)); } catch (Exception e) { } diff --git a/app/src/processing/app/PresentMode.java b/app/src/processing/app/PresentMode.java index 63f4578d9..34cba7928 100644 --- a/app/src/processing/app/PresentMode.java +++ b/app/src/processing/app/PresentMode.java @@ -3,7 +3,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2005-06 Ben Fry and Casey Reas + Copyright (c) 2005-09 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 as published by @@ -59,7 +59,7 @@ public class PresentMode { devices = environment.getScreenDevices(); GraphicsDevice defaultDevice = environment.getDefaultScreenDevice(); - Vector names = new Vector(); + Vector names = new Vector(); for (int i = 0; i < devices.length; i++) { String name = String.valueOf(i + 1); if (devices[i] == defaultDevice) { diff --git a/app/src/processing/app/Sketch.java b/app/src/processing/app/Sketch.java index bde6b8dd3..d56b127cf 100644 --- a/app/src/processing/app/Sketch.java +++ b/app/src/processing/app/Sketch.java @@ -3,7 +3,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2004-08 Ben Fry and Casey Reas + Copyright (c) 2004-09 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 @@ -1431,7 +1431,7 @@ public class Sketch { upload(appletFolder.getPath(), foundName, verbose); return true; - } + } protected void size(String buildPath, String suggestedClassName) @@ -1439,23 +1439,23 @@ public class Sketch { long size = 0; long maxsize = Preferences.getInteger("boards." + Preferences.get("board") + ".upload.maximum_size"); Sizer sizer = new Sizer(buildPath, suggestedClassName); - try { + try { size = sizer.computeSize(); System.out.println("Binary sketch size: " + size + " bytes (of a " + maxsize + " byte maximum)"); } catch (RunnerException e) { System.err.println("Couldn't determine program size: " + e.getMessage()); - } + } if (size > maxsize) throw new RunnerException( "Sketch too big; see http://www.arduino.cc/en/Guide/Troubleshooting#size for tips on reducing it."); - } + } protected String upload(String buildPath, String suggestedClassName, boolean verbose) throws RunnerException { - + Uploader uploader; // download the program @@ -1466,7 +1466,7 @@ public class Sketch { verbose); return success ? suggestedClassName : null; - } + } /** * Replace all commented portions of a given String as spaces. @@ -1528,8 +1528,8 @@ public class Sketch { * Export to application via GUI. */ protected boolean exportApplication() throws IOException, RunnerException { - return false; - } + return false; + } /** @@ -1537,8 +1537,8 @@ public class Sketch { */ public boolean exportApplication(String destPath, int exportPlatform) throws IOException, RunnerException { - return false; - } + return false; + } protected void addManifest(ZipOutputStream zos) throws IOException { @@ -1558,8 +1558,8 @@ public class Sketch { * Read from a file with a bunch of attribute/value pairs * that are separated by = and ignore comments with #. */ - protected Hashtable readSettings(File inputFile) { - Hashtable outgoing = new Hashtable(); + protected HashMap readSettings(File inputFile) { + HashMap outgoing = new HashMap(); if (!inputFile.exists()) return outgoing; // return empty hash String lines[] = PApplet.loadStrings(inputFile); @@ -1589,7 +1589,7 @@ public class Sketch { */ protected void packClassPathIntoZipFile(String path, ZipOutputStream zos, - Hashtable zipFileContents) + HashMap zipFileContents) throws IOException { String[] pieces = PApplet.split(path, File.pathSeparatorChar); @@ -1601,7 +1601,7 @@ public class Sketch { pieces[i].toLowerCase().endsWith(".zip")) { try { ZipFile file = new ZipFile(pieces[i]); - Enumeration entries = file.entries(); + Enumeration entries = file.entries(); while (entries.hasMoreElements()) { ZipEntry entry = (ZipEntry) entries.nextElement(); if (entry.isDirectory()) { @@ -1887,8 +1887,8 @@ public class Sketch { } return codeFolder; } - - + + public ArrayList getImportedLibraries() { return importedLibraries; } diff --git a/app/src/processing/app/Theme.java b/app/src/processing/app/Theme.java index b62f18828..8b68f4f45 100644 --- a/app/src/processing/app/Theme.java +++ b/app/src/processing/app/Theme.java @@ -39,9 +39,9 @@ import processing.core.*; public class Theme { /** Copy of the defaults in case the user mangles a preference. */ - static Hashtable defaults; + static HashMap defaults; /** Table of attributes/values for the theme. */ - static Hashtable table = new Hashtable();; + static HashMap table = new HashMap();; static protected void init() { @@ -55,9 +55,7 @@ public class Theme { // check for platform-specific properties in the defaults String platformExt = "." + Base.getPlatformName(); int platformExtLength = platformExt.length(); - Enumeration e = table.keys(); - while (e.hasMoreElements()) { - String key = (String) e.nextElement(); + for (String key : table.keySet()) { if (key.endsWith(platformExt)) { // this is a key specific to a particular platform String actualKey = key.substring(0, key.length() - platformExtLength); @@ -70,7 +68,7 @@ public class Theme { setColor("run.window.bgcolor", SystemColor.control); // clone the hash table - defaults = (Hashtable) table.clone(); + defaults = (HashMap) table.clone(); } @@ -142,11 +140,7 @@ public class Theme { static public void setColor(String attr, Color what) { - String r = Integer.toHexString(what.getRed()); - String g = Integer.toHexString(what.getGreen()); - String b = Integer.toHexString(what.getBlue()); - set(attr, "#" + r.substring(r.length() - 2) + - g.substring(g.length() - 2) + b.substring(b.length() - 2)); + set(attr, "#" + PApplet.hex(what.getRGB() & 0xffffff, 6)); } diff --git a/app/src/processing/app/debug/Compiler.java b/app/src/processing/app/debug/Compiler.java index d5d59d2a8..7abb6c174 100644 --- a/app/src/processing/app/debug/Compiler.java +++ b/app/src/processing/app/debug/Compiler.java @@ -73,7 +73,7 @@ public class Compiler implements MessageConsumer { MessageStream pms = new MessageStream(this); String avrBasePath = Base.getAvrBasePath(); - + List objectFiles = new ArrayList(); List includePaths = new ArrayList(); @@ -99,15 +99,15 @@ public class Compiler implements MessageConsumer { List commandAR = new ArrayList(baseCommandAR); commandAR.add(file.getAbsolutePath()); execAsynchronously(commandAR); - } + } // 2. compile the libraries, outputting .o files to: // - + // use library directories as include paths for all libraries for (File file : sketch.getImportedLibraries()) { includePaths.add(file.getPath()); } - + for (File libraryFolder : sketch.getImportedLibraries()) { File outputFolder = new File(buildPath, libraryFolder.getName()); createFolder(outputFolder); @@ -125,17 +125,17 @@ public class Compiler implements MessageConsumer { findFilesInFolder(new File(libraryFolder, "utility"), "cpp", false))); // other libraries should not see this library's utility/ folder includePaths.remove(includePaths.size() - 1); - } - + } + // 3. compile the sketch (already in the buildPath) - + objectFiles.addAll( compileFiles(avrBasePath, buildPath, includePaths, findFilesInPath(buildPath, "c", false), findFilesInPath(buildPath, "cpp", false))); - + // 4. link it all together into the .elf file - + List baseCommandLinker = new ArrayList(Arrays.asList(new String[] { avrBasePath + "avr-gcc", "-Os", @@ -144,7 +144,7 @@ public class Compiler implements MessageConsumer { "-o", buildPath + File.separator + primaryClassName + ".elf" })); - + for (File file : objectFiles) { baseCommandLinker.add(file.getAbsolutePath()); } @@ -185,14 +185,14 @@ public class Compiler implements MessageConsumer { execAsynchronously(commandObjcopy); return true; - } - - + } + + private List compileFiles(String avrBasePath, String buildPath, List includePaths, List cSources, List cppSources) throws RunnerException { - + List objectPaths = new ArrayList(); for (File file : cSources) { @@ -201,7 +201,7 @@ public class Compiler implements MessageConsumer { execAsynchronously(getCommandCompilerC(avrBasePath, includePaths, file.getAbsolutePath(), objectPath)); - } + } for (File file : cppSources) { String objectPath = buildPath + File.separator + file.getName() + ".o"; @@ -209,12 +209,12 @@ public class Compiler implements MessageConsumer { execAsynchronously(getCommandCompilerCPP(avrBasePath, includePaths, file.getAbsolutePath(), objectPath)); - } + } return objectPaths; - } - - + } + + boolean firstErrorFound; boolean secondErrorFound; @@ -229,9 +229,9 @@ public class Compiler implements MessageConsumer { if (verbose || Preferences.getBoolean("build.verbose")) { for(int j = 0; j < command.length; j++) { System.out.print(command[j] + " "); - } + } System.out.println(); - } + } firstErrorFound = false; // haven't found any errors yet secondErrorFound = false; @@ -244,8 +244,8 @@ public class Compiler implements MessageConsumer { RunnerException re = new RunnerException(e.getMessage()); re.hideStackTrace(); throw re; - } - + } + MessageSiphon in = new MessageSiphon(process.getInputStream(), this); MessageSiphon err = new MessageSiphon(process.getErrorStream(), this); @@ -263,7 +263,7 @@ public class Compiler implements MessageConsumer { compiling = false; } catch (InterruptedException ignored) { } } - + // an error was queued up by message(), barf this back to compile(), // which will barf it back to Editor. if you're having trouble // discerning the imagery, consider how cows regurgitate their food @@ -271,18 +271,18 @@ public class Compiler implements MessageConsumer { // //System.out.println("throwing up " + exception); if (exception != null) { throw exception; } - + if (result > 1) { // a failure in the tool (e.g. unable to locate a sub-executable) System.err.println(command[0] + " returned " + result); - } - + } + if (result != 0) { RunnerException re = new RunnerException("Error compiling."); re.hideStackTrace(); throw re; - } - } + } + } /** @@ -312,14 +312,14 @@ public class Compiler implements MessageConsumer { String partialTempPath = null; int partialStartIndex = -1; //s.indexOf(partialTempPath); int fileIndex = -1; // use this to build a better exception - + // check the main sketch file first. partialTempPath = buildPathSubst + primaryClassName; partialStartIndex = s.indexOf(partialTempPath); if (partialStartIndex != -1) { fileIndex = 0; - } else { + } else { // wasn't there, check the other (non-pde) files in the sketch. // iterate through the project files to see who's causing the trouble for (int i = 0; i < sketch.getCodeCount(); i++) { @@ -332,7 +332,7 @@ public class Compiler implements MessageConsumer { fileIndex = i; //System.out.println("fileIndex is " + fileIndex); break; - } + } } //+ className + ".java"; } @@ -353,7 +353,7 @@ public class Compiler implements MessageConsumer { System.err.print(s1); //firstErrorFound = true; return; - } + } int lineNumber; try { @@ -361,7 +361,7 @@ public class Compiler implements MessageConsumer { } catch (NumberFormatException e) { System.err.print(s1); return; - } + } //System.out.println("pde / line number: " + lineNumber); @@ -372,15 +372,15 @@ public class Compiler implements MessageConsumer { if (sketch.getCode(i).getPreprocOffset() < lineNumber) { fileIndex = i; //System.out.println("i'm thinkin file " + i); - } - } } + } + } // XXX: DAM: if the lineNumber is less than sketch.getCode(0).getPreprocOffset() // we shouldn't subtract anything from it, as the error is above the // location where the function prototypes and #include "WProgram.h" // were inserted. lineNumber -= sketch.getCode(fileIndex).getPreprocOffset(); - } + } //String s2 = s1.substring(colon + 2); int err = s1.indexOf(":"); @@ -391,7 +391,7 @@ public class Compiler implements MessageConsumer { if (firstErrorFound) { secondErrorFound = true; return; - } + } // if executing at this point, this is *at least* the first error firstErrorFound = true; @@ -421,13 +421,13 @@ public class Compiler implements MessageConsumer { // are probably associated with the first error message, // which is already in the status bar, and are likely to be // of interest to the user, so spit them to the console. - // +// if (!secondErrorFound) { System.err.println(s); } } } - + ///////////////////////////////////////////////////////////////////////////// static private List getCommandCompilerC(String avrBasePath, List includePaths, @@ -447,13 +447,13 @@ public class Compiler implements MessageConsumer { for (int i = 0; i < includePaths.size(); i++) { baseCommandCompiler.add("-I" + (String) includePaths.get(i)); } - + baseCommandCompiler.add(sourceName); baseCommandCompiler.add("-o"+ objectName); - + return baseCommandCompiler; } - + static private List getCommandCompilerCPP(String avrBasePath, List includePaths, String sourceName, String objectName) { @@ -472,15 +472,15 @@ public class Compiler implements MessageConsumer { for (int i = 0; i < includePaths.size(); i++) { baseCommandCompilerCPP.add("-I" + (String) includePaths.get(i)); - } - + } + baseCommandCompilerCPP.add(sourceName); baseCommandCompilerCPP.add("-o"+ objectName); - + return baseCommandCompilerCPP; } - + ///////////////////////////////////////////////////////////////////////////// diff --git a/app/src/processing/app/debug/EventThread.java b/app/src/processing/app/debug/EventThread.java index 918600f1f..d4f93d503 100644 --- a/app/src/processing/app/debug/EventThread.java +++ b/app/src/processing/app/debug/EventThread.java @@ -40,31 +40,9 @@ import java.util.Iterator; import java.util.List; import java.util.Map; -import com.sun.jdi.Field; -import com.sun.jdi.IncompatibleThreadStateException; -import com.sun.jdi.ThreadReference; -import com.sun.jdi.VMDisconnectedException; -import com.sun.jdi.Value; -import com.sun.jdi.VirtualMachine; -import com.sun.jdi.event.ClassPrepareEvent; -import com.sun.jdi.event.Event; -import com.sun.jdi.event.EventIterator; -import com.sun.jdi.event.EventQueue; -import com.sun.jdi.event.EventSet; -import com.sun.jdi.event.ExceptionEvent; -import com.sun.jdi.event.MethodEntryEvent; -import com.sun.jdi.event.MethodExitEvent; -import com.sun.jdi.event.ModificationWatchpointEvent; -import com.sun.jdi.event.StepEvent; -import com.sun.jdi.event.ThreadDeathEvent; -import com.sun.jdi.event.VMDeathEvent; -import com.sun.jdi.event.VMDisconnectEvent; -import com.sun.jdi.event.VMStartEvent; -import com.sun.jdi.request.EventRequest; -import com.sun.jdi.request.EventRequestManager; -import com.sun.jdi.request.ExceptionRequest; -import com.sun.jdi.request.ModificationWatchpointRequest; -import com.sun.jdi.request.StepRequest; +import com.sun.jdi.*; +import com.sun.jdi.event.*; +import com.sun.jdi.request.*; /** * This class processes incoming JDI events and displays them @@ -132,8 +110,9 @@ public class EventThread extends Thread { // deathReq.setSuspendPolicy(EventRequest.SUSPEND_ALL); // deathReq.enable(); - // want all exceptions + // get only the uncaught exceptions ExceptionRequest excReq = mgr.createExceptionRequest(null, false, true); + // this version reports all exceptions, caught or uncaught //ExceptionRequest excReq = mgr.createExceptionRequest(null, true, true); // suspend so we can step excReq.setSuspendPolicy(EventRequest.SUSPEND_ALL); @@ -380,7 +359,7 @@ public class EventThread extends Thread { } private void exceptionEvent(ExceptionEvent event) { -// ObjectReference or = event.exception(); +// com.sun.jdi.ObjectReference or = event.exception(); // System.out.println("exceptionEvent() fired " + or); // System.out.println("catch location " + event.catchLocation()); diff --git a/app/src/processing/app/debug/Runner.java b/app/src/processing/app/debug/Runner.java index b63f6ed74..b78ee41c3 100644 --- a/app/src/processing/app/debug/Runner.java +++ b/app/src/processing/app/debug/Runner.java @@ -3,7 +3,7 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2004-08 Ben Fry and Casey Reas + Copyright (c) 2004-09 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 @@ -379,11 +379,16 @@ public class Runner implements MessageConsumer { //String addr = "localhost:" + (8000 + (int) (Math.random() * 1000)); //String addr = "" + (8000 + (int) (Math.random() * 1000)); - String commandArgs = Base.isWindows() ? - "java -Xrunjdwp:transport=dt_shmem,address=" + addr + ",suspend=y " : + String commandArgs = "java -Xrunjdwp:transport=dt_socket,address=" + addr + ",suspend=y "; - //String commandArgs = "java -agentlib:jdwp=transport=dt_socket,address=" + addr + ",suspend=y "; - //String commandArgs = "java -agentlib:jdwp=transport=dt_socket,address=" + addr + ",server=n,suspend=y "; + if (Base.isWindows()) { + commandArgs = + "java -Xrunjdwp:transport=dt_shmem,address=" + addr + ",suspend=y "; + } else if (Base.isMacOS()) { + commandArgs = + "java -d32 -Xrunjdwp:transport=dt_socket,address=" + addr + ",suspend=y "; + } + for (int i = 0; i < vmParams.length; i++) { commandArgs = addArgument(commandArgs, vmParams[i], ' '); } @@ -519,11 +524,13 @@ public class Runner implements MessageConsumer { // Shutdown begins when event thread terminates try { if (eventThread != null) eventThread.join(); +// System.out.println("in here"); // Bug #852 tracked to this next line in the code. // http://dev.processing.org/bugs/show_bug.cgi?id=852 errThread.join(); // Make sure output is forwarded +// System.out.println("and then"); outThread.join(); // before we exit - //System.out.println("out of it"); +// System.out.println("out of it"); // At this point, disable the run button. // This happens when the sketch is exited by hitting ESC, @@ -573,6 +580,7 @@ public class Runner implements MessageConsumer { public void exception(ExceptionEvent event) { +// System.out.println(event); ObjectReference or = event.exception(); ReferenceType rt = or.referenceType(); String exceptionName = rt.name(); @@ -644,7 +652,7 @@ public class Runner implements MessageConsumer { // message to the console. List frames = thread.frames(); for (StackFrame frame : frames) { - //System.out.println("frame: " + frame); +// System.out.println("frame: " + frame); Location location = frame.location(); String filename = null; filename = location.sourceName(); diff --git a/app/src/processing/app/macosx/ThinkDifferent.java b/app/src/processing/app/macosx/ThinkDifferent.java index 38cb6cb9a..1d292b399 100644 --- a/app/src/processing/app/macosx/ThinkDifferent.java +++ b/app/src/processing/app/macosx/ThinkDifferent.java @@ -86,13 +86,14 @@ public class ThinkDifferent implements ApplicationListener { throw new IllegalStateException("handlePreferences: Base instance detached from listener"); } } - - + + public void handleOpenApplication(ApplicationEvent ae) { } public void handleOpenFile(ApplicationEvent ae) { +// System.out.println("got open file event " + ae.getFilename()); String filename = ae.getFilename(); base.handleOpen(filename); ae.setHandled(true); diff --git a/app/src/processing/app/syntax/JEditTextArea.java b/app/src/processing/app/syntax/JEditTextArea.java index af01ea16c..0cc9e0146 100644 --- a/app/src/processing/app/syntax/JEditTextArea.java +++ b/app/src/processing/app/syntax/JEditTextArea.java @@ -51,7 +51,7 @@ import java.util.Vector; * + "}"); * * @author Slava Pestov - * @version $Id: JEditTextArea.java 5343 2008-11-29 17:22:59Z fry $ + * @version $Id: JEditTextArea.java 5625 2009-06-07 21:08:59Z fry $ */ public class JEditTextArea extends JComponent { @@ -103,6 +103,9 @@ public class JEditTextArea extends JComponent painter.addMouseListener(new MouseHandler()); painter.addMouseMotionListener(new DragHandler()); addFocusListener(new FocusHandler()); + // send tab keys through to the text area + // http://dev.processing.org/bugs/show_bug.cgi?id=1267 + setFocusTraversalKeysEnabled(false); // Load the defaults setInputHandler(defaults.inputHandler); @@ -145,9 +148,9 @@ public class JEditTextArea extends JComponent * Returns if this component can be traversed by pressing * the Tab key. This returns false. */ - public final boolean isManagingFocus() { - return true; - } +// public final boolean isManagingFocus() { +// return true; +// } /** * Returns the object responsible for painting this text area. @@ -1028,8 +1031,8 @@ public class JEditTextArea extends JComponent { select(selectionStart,selectionEnd); } - - + + public final boolean isSelectionActive() { return(selectionStart != selectionEnd); diff --git a/app/src/processing/app/syntax/TextAreaPainter.java b/app/src/processing/app/syntax/TextAreaPainter.java index ef205b079..229df09b7 100644 --- a/app/src/processing/app/syntax/TextAreaPainter.java +++ b/app/src/processing/app/syntax/TextAreaPainter.java @@ -30,6 +30,8 @@ implements TabExpander, Printable { /** True if inside printing, will handle disabling the highlight */ boolean printing; + /** Current setting for editor.antialias preference */ + boolean antialias; /** * Creates a new repaint manager. This should be not be called @@ -54,6 +56,8 @@ implements TabExpander, Printable setForeground(defaults.fgcolor); setBackground(defaults.bgcolor); + antialias = Preferences.getBoolean("editor.antialias"); + blockCaret = defaults.blockCaret; styles = defaults.styles; cols = defaults.cols; @@ -73,10 +77,10 @@ implements TabExpander, Printable * Returns if this component can be traversed by pressing the * Tab key. This returns false. */ - public final boolean isManagingFocus() - { - return false; - } +// public final boolean isManagingFocus() +// { +// return false; +// } /** * Returns the syntax styles used to paint colorized text. Entry n @@ -366,11 +370,11 @@ implements TabExpander, Printable */ public void paint(Graphics gfx) { - if (Base.isMacOS()) { - Graphics2D g2 = (Graphics2D) gfx; - g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, - RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); - } + Graphics2D g2 = (Graphics2D) gfx; + g2.setRenderingHint(RenderingHints.KEY_TEXT_ANTIALIASING, + antialias ? + RenderingHints.VALUE_TEXT_ANTIALIAS_ON : + RenderingHints.VALUE_TEXT_ANTIALIAS_OFF); tabSize = fm.charWidth(' ') * ((Integer)textArea.getDocument().getProperty(PlainDocument.tabSizeAttribute)).intValue(); diff --git a/app/src/processing/app/tools/AutoFormat.java b/app/src/processing/app/tools/AutoFormat.java index 2397967c5..ba4fba89f 100644 --- a/app/src/processing/app/tools/AutoFormat.java +++ b/app/src/processing/app/tools/AutoFormat.java @@ -3,13 +3,14 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2005-06 Ben Fry and Casey Reas - Copyright (c) 2003 Martin Gomez, Ateneo de Manila University + Original Copyright (c) 1997, 1998 Van Di-Han HO. All Rights Reserved. + Updates Copyright (c) 2001 Jason Pell. + Further updates Copyright (c) 2003 Martin Gomez, Ateneo de Manila University + Bug fixes Copyright (c) 2005-09 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 as published by - the Free Software Foundation; either version 2 of the License, or - (at your option) any later version. + the Free Software Foundation, version 2. This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -24,13 +25,21 @@ package processing.app.tools; import processing.app.*; +import processing.core.PApplet; import java.io.*; /** - * Alternate handler for dealing with auto format. + * Handler for dealing with auto format. * Contributed by Martin Gomez, additional bug fixes by Ben Fry. + * + * After some further digging, this code in fact appears to be a modified + * version of Jason Pell's GPLed "Java Beautifier" class found here: + * http://www.geocities.com/jasonpell/programs.html + * Which is itself based on code from Van Di-Han Ho: + * http://www.geocities.com/~starkville/vancbj_idx.html + * [Ben Fry, August 2009] */ public class AutoFormat implements Tool { Editor editor; @@ -38,15 +47,12 @@ public class AutoFormat implements Tool { static final int BLOCK_MAXLEN = 1024; StringBuffer strOut; - //String formattedText; int indentValue; String indentChar; - //String uhOh = null; - //String theStuff; int EOF; - BufferedInputStream bin = null; - int nBytesRead, indexBlock, lineLength, lineNumber; - byte bArray[]; + CharArrayReader reader; + int readCount, indexBlock, lineLength, lineNumber; + char chars[]; String strBlock; int s_level[]; int c_level; @@ -64,23 +70,17 @@ public class AutoFormat implements Tool { String w_if_, w_else, w_for, w_ds, w_case, w_cpp_comment, w_jdoc; int jdoc, j; char string[]; - byte bstring[]; - byte bblank; char cc; - int s_flg, b_flg; + int s_flg; int peek; char peekc; int tabs; - char next_char, last_char; - char lastc0, lastc1; - char c, c0; - char w_kptr; + char last_char; + char c; String line_feed; - //static int outfil; // temporary - - + public void init(Editor editor) { this.editor = editor; } @@ -236,6 +236,7 @@ public class AutoFormat implements Tool { } } + public void cpp_comment() throws IOException { c = getchr(); @@ -283,32 +284,26 @@ public class AutoFormat implements Tool { indexBlock++; if (indexBlock >= lineLength) { - for (int ib=0; ib 0) - { - nBytesRead = bin.read(bArray); - lineLength = nBytesRead; - strBlock = new String(bArray); - indexBlock = 0; - last_char = strBlock.charAt(indexBlock); - peek = -1; - peekc = '`'; - } - else - { - //System.out.println("eof a"); - EOF = 1; - peekc = '\0'; - } - //} - //catch(IOException ioe) - //{ - //System.out.println(ioe.toString()); - //} + lineLength = readCount = 0; + reader.mark(1); + if (reader.read() != -1) + { + reader.reset(); // back to the mark + readCount = reader.read(chars); + lineLength = readCount; + strBlock = new String(chars); + indexBlock = 0; + last_char = strBlock.charAt(indexBlock); + peek = -1; + peekc = '`'; + } + else + { + EOF = 1; + peekc = '\0'; + } } else { @@ -446,13 +441,11 @@ public class AutoFormat implements Tool { indentChar = new String(" "); lineNumber = 0; - //BLOCK_MAXLEN = 256; c_level = if_lev = level = e_flg = paren = 0; - a_flg = q_flg = j = b_flg = tabs = 0; + a_flg = q_flg = j = tabs = 0; if_flg = peek = -1; peekc = '`'; s_flg = 1; - bblank = ' '; jdoc = 0; s_level = new int[10]; @@ -476,24 +469,23 @@ public class AutoFormat implements Tool { // read as long as there is something to read EOF = 0; // = 1 set in getchr when EOF - bArray = new byte[BLOCK_MAXLEN]; + chars = new char[BLOCK_MAXLEN]; string = new char[BLOCK_MAXLEN]; try { // the whole process // open for input - ByteArrayInputStream in = - new ByteArrayInputStream(originalText.getBytes()); + reader = new CharArrayReader(originalText.toCharArray()); // add buffering to that InputStream - bin = new BufferedInputStream(in); +// bin = new BufferedInputStream(in); - for (int ib = 0; ib < BLOCK_MAXLEN; ib++) bArray[ib] = '\0'; + for (int ib = 0; ib < BLOCK_MAXLEN; ib++) chars[ib] = '\0'; - lineLength = nBytesRead = 0; + lineLength = readCount = 0; // read up a block - remember how many bytes read - nBytesRead = bin.read(bArray); - strBlock = new String(bArray); + readCount = reader.read(chars); + strBlock = new String(chars); - lineLength = nBytesRead; + lineLength = readCount; lineNumber = 1; indexBlock = -1; j = 0; @@ -561,6 +553,10 @@ public class AutoFormat implements Tool { case '{': if(lookup(w_else) == 1)gotelse(); + if (s_if_lev.length == c_level) { + s_if_lev = PApplet.expand(s_if_lev); + s_if_flg = PApplet.expand(s_if_flg); + } s_if_lev[c_level] = if_lev; s_if_flg[c_level] = if_flg; if_lev = if_flg = 0; @@ -736,7 +732,6 @@ public class AutoFormat implements Tool { peekc = getchr(); if(peekc == ';') { - //fprintf(outfil,";"); fprintf(";"); peek = -1; peekc = '`'; @@ -747,13 +742,11 @@ public class AutoFormat implements Tool { } getnl(); indent_puts(); - //fprintf(outfil,"\n"); fprintf("\n"); s_flg = 1; break; case '/': - c0 = string[j]; string[j++] = c; peekc = getchr(); @@ -912,7 +905,7 @@ public class AutoFormat implements Tool { selectionEnd = strOut.length() - 1; } - bin.close(); // close buff + reader.close(); // close buff String formattedText = strOut.toString(); if (formattedText.equals(originalText)) { diff --git a/build/macosx/dist.sh b/build/macosx/dist.sh index 69f998333..0df062c61 100755 --- a/build/macosx/dist.sh +++ b/build/macosx/dist.sh @@ -7,6 +7,13 @@ if [ $1 ] then RELEASE=$1 echo Creating Arduino release $RELEASE... + INFO_SOUGHT="$RELEASE," + INFO_FOUND=`cat ./dist/Arduino.app/Contents/Info.plist | grep $INFO_SOUGHT` + if [ -z "$INFO_FOUND" ] + then + echo Fix the version number in Info.plist + exit + fi else RELEASE=$REVISION echo Creating Arduino distribution for revision $REVISION... diff --git a/build/macosx/make.sh b/build/macosx/make.sh index 3cb005066..e53091bc5 100755 --- a/build/macosx/make.sh +++ b/build/macosx/make.sh @@ -1,5 +1,22 @@ #!/bin/sh +# http://dev.processing.org/bugs/show_bug.cgi?id=1179 +OSX_VERSION=`sw_vers | grep ProductVersion | awk '{print $2}' | awk '{print substr($0,1,4)}'` +if [ "$OSX_VERSION" = "10.4" ] +then + echo "This script uses the -X option for cp (to disable resource forks)," + echo "which is not supported on OS X 10.4. Please either upgrade to 10.5," + echo "or modify this script to remove use of the -X switch to continue." + # and you will also need to remove this error message + exit +else + if [ "$OSX_VERSION" != "10.6" ] + then + echo "Note: This script has not been tested on this " + echo "release of Mac OS and may cause errors." + fi +fi + ### -- SETUP WORK DIR ------------------------------------------- @@ -27,7 +44,7 @@ else cp -rX ../shared/lib "$RESOURCES/" cp -rX ../shared/libraries "$RESOURCES/" cp -rX ../shared/tools "$RESOURCES/" - + cp -rX ../../hardware "$RESOURCES/" cp -X ../../app/lib/antlr.jar "$RESOURCES/" @@ -41,7 +58,7 @@ else echo Extracting reference... unzip -q -d "$RESOURCES/" ../shared/reference.zip - + echo Extracting avr tools... unzip -q -d "$RESOURCES/hardware" dist/tools-universal.zip fi @@ -115,4 +132,4 @@ cd ../.. echo -echo Done. +echo Done. \ No newline at end of file diff --git a/build/shared/revisions.txt b/build/shared/revisions.txt index f50448527..71599c041 100644 --- a/build/shared/revisions.txt +++ b/build/shared/revisions.txt @@ -1,3 +1,188 @@ +PROCESSING 1.0.7 (REV 0169) - 4 September 2009 + +Bug fixes and updates, also some tweaks for Mac OS X Snow Leopard. + +[ changes ] + ++ Tweaks for Mac OS X Snow Leopard, to force it to run in 32-bit mode. + This should bring back the video library (if temporarily), and hopefully + fix serial as well, though I didn't have a serial device handy to test. + ++ Fix problem where line highlighting was off in 'static' mode. + http://dev.processing.org/bugs/show_bug.cgi?id=1263 + ++ Auto-format was killing Unicode characters (how did this last so long?) + http://dev.processing.org/bugs/show_bug.cgi?id=1312 + ++ PVector.angleDistance() returning NaN due to precision errors + http://dev.processing.org/bugs/show_bug.cgi?id=1316 + ++ Removed a major try/catch block from PApplet.main(), hopefully + this will allow some exception stuff to come through properly. + + +. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + +PROCESSING 1.0.6 (REV 0168) - 12 August 2009 + +Bug fixes and minor changes. Most important are replacement JOGL libraries +so that OpenGL applets won't present an "expired certificate" error. + +[ bug fixes ] + ++ Replaced the faulty JOGL library that had expired certificates (Sun bug). + http://dev.processing.org/bugs/show_bug.cgi?id=1271 + https://jogl.dev.java.net/servlets/ProjectDocumentList?folderID=9260&expandFolder=9260&folderID=0 + ++ Updated the Linux launcher script that enables Processing to be run + from other directories, symlinks, or from launch items. + http://dev.processing.org/bugs/show_bug.cgi?id=825 + Thanks to Ferdinand Kasper for the fix! + ++ strokeWeight() was making lines 2x too thick with P2D + http://dev.processing.org/bugs/show_bug.cgi?id=1283 + ++ PImage.getImage() setting the wrong image type + http://dev.processing.org/bugs/show_bug.cgi?id=1282 + ++ image() not working with P2D, P3D, and OPENGL when noFill() used + http://dev.processing.org/bugs/show_bug.cgi?id=1299 + http://dev.processing.org/bugs/show_bug.cgi?id=1222 + ++ Auto format problem with program deeper then 10 levels + http://dev.processing.org/bugs/show_bug.cgi?id=1297 + ++ Fixed a crash on startup problem (console being null) + ++ Recursive subfolder copy of library folders when exporting application + http://dev.processing.org/bugs/show_bug.cgi?id=1295 + +[ changes ] + ++ PDF member functions set protected instead of private + http://dev.processing.org/bugs/show_bug.cgi?id=1276 + ++ On OS X, update Info.plist to be 32/64 explicit and also updated + JavaApplicationStub for update 4. + ++ Clicking the preferences location in the Preferences window will + now open the parent folder for the preferences file. + http://dev.processing.org/bugs/show_bug.cgi?id=1279 + ++ Update to Java 6 update 15 for the Windows and Linux releases. + +[ fixed earlier ] + ++ Mangled menu text with Java 6u10. + http://dev.processing.org/bugs/show_bug.cgi?id=1065 + + +. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + +PROCESSING 1.0.5 (REV 0167) - 7 June 2009 + +Bug fix release, mostly dealing with regressions from 1.0.4. + +[ bug fixes ] + ++ Make the tab key work again inside the editor + http://dev.processing.org/bugs/show_bug.cgi?id=1267 + ++ Deal with duplicate entries for sketchbook in the file menu + http://dev.processing.org/bugs/show_bug.cgi?id=1260 + +[ changes ] + ++ Support for smooth text in the PDE editor. Set editor.antialias=true + inside preferences.txt to enable smooth text. + http://dev.processing.org/bugs/show_bug.cgi?id=1266 + ++ Updated reference files. + + +. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + +PROCESSING 1.0.4 (REV 0166) - 31 May 2009 + +Bug fix release. + +[ changes ] + ++ Changed the workaround for Apple's Java bug related to the menus in OS X. + Rather than placing the menubar inside the sketch window, File > Sketchbook + and File > Examples are simply dimmed out. Instead, use the Open button + on the toolbar, which provides access to the same items. The preference + to place the menu bar inside the window is still available, in case you + prefer the previous workaround. + http://dev.processing.org/bugs/show_bug.cgi?id=786 + ++ Also updated the included runtime on Windows and Linux to Java 6u14. + +[ bug fixes ] + ++ Fixed IDE crash when changing color scheme on windows + http://dev.processing.org/bugs/show_bug.cgi?id=1237 + ++ Typo in the Linux shell script was preventing it from running + http://dev.processing.org/bugs/show_bug.cgi?id=1250 + ++ OS X finder info on application updated to say 1.0.4 + http://dev.processing.org/bugs/show_bug.cgi?id=1226 + ++ Removed warning message "Non-String for 8 value in 'Properties' + sub-dictionary in 'Java' sub-dictionary of Info.plist" on OS X + ++ Added warning to build script for users on OS X 10.4 + http://dev.processing.org/bugs/show_bug.cgi?id=1179 + ++ Disable point() going to set() from PGraphicsJava2D. The set() command + doesn't honor alpha consistently, and it also causes problems with PDF + ++ PImage cacheMap problem when using PImage.get() + http://dev.processing.org/bugs/show_bug.cgi?id=1245 + ++ Fix problems with > 512 points and P3D/OPENGL + http://dev.processing.org/bugs/show_bug.cgi?id=1255 + Thanks to user DopeShow for the patch + ++ imageMode(CENTER) doesn't work properly with P2D + http://dev.processing.org/bugs/show_bug.cgi?id=1232 + ++ Reset matrices when using beginRecord() with PDF + http://dev.processing.org/bugs/show_bug.cgi?id=1227 + ++ Resizing window no longer distorts OpenGL graphics + http://dev.processing.org/bugs/show_bug.cgi?id=1176 + Many thanks to Pablo Funes for the patch + ++ Fix significant point() and set() slowdown on OS X + http://dev.processing.org/bugs/show_bug.cgi?id=1094 + +[ known issues ] + ++ Currently no 64-bit support for any platforms. On some platforms, you'll + simply need to replace the Java folder with the distribution with something + more suitable for your operating system. + ++ Command line support is currently broken + http://dev.processing.org/bugs/show_bug.cgi?id=1048 + ++ Text of menus/interface elements sometimes mangled (e.g. toolbar repeats + several times, other oddness). See bug report for a workaround + http://dev.processing.org/bugs/show_bug.cgi?id=1065 + ++ Video library threading problems with other libraries + http://dev.processing.org/bugs/show_bug.cgi?id=882 + ++ See dev.processing.org/bugs for much, much more! + + +. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + PROCESSING 1.0.3 (REV 0165) - 24 February 2009 Bug fix release to repair a couple of regressions caused by changes in 1.0.2, @@ -24,6 +209,9 @@ as well as a couple other new problems encountered since. + Update to iText 2.1.4 for the PDF library +. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . + + PROCESSING 1.0.2 (REV 0164) - 21 February 2009 This release fixes many bugs and adds two minor functions to the XML library. diff --git a/build/windows/jre.zip b/build/windows/jre.zip index a9522ec68..9a2ea0ea7 100644 Binary files a/build/windows/jre.zip and b/build/windows/jre.zip differ diff --git a/core/done.txt b/core/done.txt index e2eb2ec90..caf3ddeb2 100644 --- a/core/done.txt +++ b/core/done.txt @@ -1,3 +1,53 @@ +0168 core (1.0.6) +X getImage() setting the wrong image type +X http://dev.processing.org/bugs/show_bug.cgi?id=1282 +X strokeWeight() makes lines 2x too thick with P2D +X http://dev.processing.org/bugs/show_bug.cgi?id=1283 +X image() doesn't work with P2D, P3D, and OPENGL with noFill() +X http://dev.processing.org/bugs/show_bug.cgi?id=1299 +o maybe using rgb instead of tint inside drawing loops? +X http://dev.processing.org/bugs/show_bug.cgi?id=1222 + + +0167 core (1.0.5) +X changed text layout methods from private to protected + + +0166 core (1.0.4) +X disable point() going to set() from PGraphicsJava2D +X set() doesn't honor alpha consistently +X also causes problems with PDF +X preliminary thread() implementation +X double param version of map() +X PImage cacheMap problem when using PImage.get() +X http://dev.processing.org/bugs/show_bug.cgi?id=1245 +X problems with > 512 points and P3D/OPENGL (thx DopeShow) +X http://dev.processing.org/bugs/show_bug.cgi?id=1255 +X imageMode(CENTER) doesn't work properly with P2D +X http://dev.processing.org/bugs/show_bug.cgi?id=1232 +X reset matrices when using beginRecord() with PDF +X http://dev.processing.org/bugs/show_bug.cgi?id=1227 +X resizing window distorts gl graphics +X patch from Pablo Funes +X http://dev.processing.org/bugs/show_bug.cgi?id=1176 +X significant point() and set() slowdown on OS X +X http://dev.processing.org/bugs/show_bug.cgi?id=1094 + + +0165 core (1.0.3) +X update to itext 2.1.4 +X endRecord or endRaw produces RuntimeException with PDF library +X http://dev.processing.org/bugs/show_bug.cgi?id=1169 +X problem with beginRaw/endRaw and OpenGL +X http://dev.processing.org/bugs/show_bug.cgi?id=1171 +X set strokeWeight with begin/endRaw +X http://dev.processing.org/bugs/show_bug.cgi?id=1172 +X fix strokeWeight with P3D (better version of line hack) +X make P3D use proper weights +X ArrayIndexOutOfBoundsException with point() +X http://dev.processing.org/bugs/show_bug.cgi?id=1168 + + 0164 core (1.0.2) X requestImage() causing problems with JAVA2D X fix minor strokeWeight bug with OpenGL diff --git a/core/src/processing/core/PApplet.java b/core/src/processing/core/PApplet.java index 4e1cff550..ecbd40d98 100644 --- a/core/src/processing/core/PApplet.java +++ b/core/src/processing/core/PApplet.java @@ -3,13 +3,12 @@ /* Part of the Processing project - http://processing.org - Copyright (c) 2004-08 Ben Fry and Casey Reas + Copyright (c) 2004-09 Ben Fry and Casey Reas Copyright (c) 2001-04 Massachusetts Institute of Technology This library is free software; you can redistribute it and/or modify it under the terms of the GNU Lesser General Public - License as published by the Free Software Foundation; either - version 2.1 of the License, or (at your option) any later version. + License as published by the Free Software Foundation, version 2.1. This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of @@ -606,13 +605,13 @@ public class PApplet extends Applet // though it's here for applications anyway start(); } - - + + public int getSketchWidth() { return DEFAULT_WIDTH; } - - + + public int getSketchHeight() { return DEFAULT_HEIGHT; } @@ -621,8 +620,8 @@ public class PApplet extends Applet public String getSketchRenderer() { return JAVA2D; } - - + + /** * Called by the browser or applet viewer to inform this applet that it * should start its execution. It is called after the init method and @@ -825,7 +824,7 @@ public class PApplet extends Applet meth.add(o, method); } catch (NoSuchMethodException nsme) { - die("There is no " + name + "() method in the class " + + die("There is no public " + name + "() method in the class " + o.getClass().getName()); } catch (Exception e) { @@ -842,7 +841,7 @@ public class PApplet extends Applet meth.add(o, method); } catch (NoSuchMethodException nsme) { - die("There is no " + name + "() method in the class " + + die("There is no public " + name + "() method in the class " + o.getClass().getName()); } catch (Exception e) { @@ -1391,6 +1390,9 @@ public class PApplet extends Applet //System.out.println("handleDraw() " + frameCount); g.beginDraw(); + if (recorder != null) { + recorder.beginDraw(); + } long now = System.nanoTime(); @@ -1442,6 +1444,9 @@ public class PApplet extends Applet } g.endDraw(); + if (recorder != null) { + recorder.endDraw(); + } frameRateLastNanos = now; frameCount++; @@ -2233,6 +2238,76 @@ public class PApplet extends Applet } + + ////////////////////////////////////////////////////////////// + + + public void method(String name) { +// final Object o = this; +// final Class c = getClass(); + try { + Method method = getClass().getMethod(name, new Class[] {}); + method.invoke(this, new Object[] { }); + + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.getTargetException().printStackTrace(); + } catch (NoSuchMethodException nsme) { + System.err.println("There is no public " + name + "() method " + + "in the class " + getClass().getName()); + } catch (Exception e) { + e.printStackTrace(); + } + } + + + public void thread(final String name) { + Thread later = new Thread() { + public void run() { + method(name); + } + }; + later.start(); + } + + + /* + public void thread(String name) { + final Object o = this; + final Class c = getClass(); + try { + final Method method = c.getMethod(name, new Class[] {}); + Thread later = new Thread() { + public void run() { + try { + method.invoke(o, new Object[] { }); + + } catch (IllegalArgumentException e) { + e.printStackTrace(); + } catch (IllegalAccessException e) { + e.printStackTrace(); + } catch (InvocationTargetException e) { + e.getTargetException().printStackTrace(); + } + } + }; + later.start(); + + } catch (NoSuchMethodException nsme) { + System.err.println("There is no " + name + "() method " + + "in the class " + getClass().getName()); + + } catch (Exception e) { + e.printStackTrace(); + } + } + */ + + + ////////////////////////////////////////////////////////////// // SCREEN GRABASS @@ -2813,6 +2888,13 @@ public class PApplet extends Applet } + static public final double map(double value, + double istart, double istop, + double ostart, double ostop) { + return ostart + (ostop - ostart) * ((value - istart) / (istop - istart)); + } + + ////////////////////////////////////////////////////////////// @@ -4417,7 +4499,8 @@ public class PApplet extends Applet * "data" folder. However, when exported (as application or applet), * sketch's data folder is exported as part of the applications jar file, * and it's not possible to read/write from the jar file in a generic way. - * If you need to read data from the jar file, you should use createInput(). + * If you need to read data from the jar file, you should use other methods + * such as createInput(), createReader(), or loadStrings(). */ public String dataPath(String where) { // isAbsolute() could throw an access exception, but so will writing @@ -4445,8 +4528,8 @@ public class PApplet extends Applet static public void createPath(String path) { createPath(new File(path)); } - - + + static public void createPath(File file) { try { String parent = file.getParent(); @@ -4455,7 +4538,7 @@ public class PApplet extends Applet if (!unit.exists()) unit.mkdirs(); } } catch (SecurityException se) { - System.err.println("You don't have permissions to create " + + System.err.println("You don't have permissions to create " + file.getAbsolutePath()); } } @@ -5257,10 +5340,10 @@ public class PApplet extends Applet /** - * Split a String on a specific delimiter. Unlike Java's String.split() + * Split a String on a specific delimiter. Unlike Java's String.split() * method, this does not parse the delimiter as a regexp because it's more * confusing than necessary, and String.split() is always available for - * those who want regexp. + * those who want regexp. */ static public String[] split(String what, String delim) { ArrayList items = new ArrayList(); @@ -6345,9 +6428,9 @@ public class PApplet extends Applet * * --present put the applet into full screen presentation * mode. requires java 1.4 or later. - * + * * --exclusive use full screen exclusive mode when presenting. - * disables new windows or interaction with other + * disables new windows or interaction with other * monitors, this is like a "game" mode. * * --hide-stop use to hide the stop button in situations where @@ -6401,104 +6484,103 @@ public class PApplet extends Applet System.exit(1); } + boolean external = false; + int[] location = null; + int[] editorLocation = null; + + String name = null; + boolean present = false; + boolean exclusive = false; + Color backgroundColor = Color.BLACK; + Color stopColor = Color.GRAY; + GraphicsDevice displayDevice = null; + boolean hideStop = false; + + String param = null, value = null; + + // try to get the user folder. if running under java web start, + // this may cause a security exception if the code is not signed. + // http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Integrate;action=display;num=1159386274 + String folder = null; try { - boolean external = false; - int[] location = null; - int[] editorLocation = null; + folder = System.getProperty("user.dir"); + } catch (Exception e) { } - String name = null; - boolean present = false; - boolean exclusive = false; - Color backgroundColor = Color.BLACK; - Color stopColor = Color.GRAY; - GraphicsDevice displayDevice = null; - boolean hideStop = false; + int argIndex = 0; + while (argIndex < args.length) { + int equals = args[argIndex].indexOf('='); + if (equals != -1) { + param = args[argIndex].substring(0, equals); + value = args[argIndex].substring(equals + 1); - String param = null, value = null; + if (param.equals(ARGS_EDITOR_LOCATION)) { + external = true; + editorLocation = parseInt(split(value, ',')); - // try to get the user folder. if running under java web start, - // this may cause a security exception if the code is not signed. - // http://processing.org/discourse/yabb_beta/YaBB.cgi?board=Integrate;action=display;num=1159386274 - String folder = null; - try { - folder = System.getProperty("user.dir"); - } catch (Exception e) { } + } else if (param.equals(ARGS_DISPLAY)) { + int deviceIndex = Integer.parseInt(value) - 1; - int argIndex = 0; - while (argIndex < args.length) { - int equals = args[argIndex].indexOf('='); - if (equals != -1) { - param = args[argIndex].substring(0, equals); - value = args[argIndex].substring(equals + 1); + //DisplayMode dm = device.getDisplayMode(); + //if ((dm.getWidth() == 1024) && (dm.getHeight() == 768)) { - if (param.equals(ARGS_EDITOR_LOCATION)) { - external = true; - editorLocation = parseInt(split(value, ',')); - - } else if (param.equals(ARGS_DISPLAY)) { - int deviceIndex = Integer.parseInt(value) - 1; - - //DisplayMode dm = device.getDisplayMode(); - //if ((dm.getWidth() == 1024) && (dm.getHeight() == 768)) { - - GraphicsEnvironment environment = - GraphicsEnvironment.getLocalGraphicsEnvironment(); - GraphicsDevice devices[] = environment.getScreenDevices(); - if ((deviceIndex >= 0) && (deviceIndex < devices.length)) { - displayDevice = devices[deviceIndex]; - } else { - System.err.println("Display " + value + " does not exist, " + - "using the default display instead."); - } - - } else if (param.equals(ARGS_BGCOLOR)) { - if (value.charAt(0) == '#') value = value.substring(1); - backgroundColor = new Color(Integer.parseInt(value, 16)); - - } else if (param.equals(ARGS_STOP_COLOR)) { - if (value.charAt(0) == '#') value = value.substring(1); - stopColor = new Color(Integer.parseInt(value, 16)); - - } else if (param.equals(ARGS_SKETCH_FOLDER)) { - folder = value; - - } else if (param.equals(ARGS_LOCATION)) { - location = parseInt(split(value, ',')); + GraphicsEnvironment environment = + GraphicsEnvironment.getLocalGraphicsEnvironment(); + GraphicsDevice devices[] = environment.getScreenDevices(); + if ((deviceIndex >= 0) && (deviceIndex < devices.length)) { + displayDevice = devices[deviceIndex]; + } else { + System.err.println("Display " + value + " does not exist, " + + "using the default display instead."); } + } else if (param.equals(ARGS_BGCOLOR)) { + if (value.charAt(0) == '#') value = value.substring(1); + backgroundColor = new Color(Integer.parseInt(value, 16)); + + } else if (param.equals(ARGS_STOP_COLOR)) { + if (value.charAt(0) == '#') value = value.substring(1); + stopColor = new Color(Integer.parseInt(value, 16)); + + } else if (param.equals(ARGS_SKETCH_FOLDER)) { + folder = value; + + } else if (param.equals(ARGS_LOCATION)) { + location = parseInt(split(value, ',')); + } + + } else { + if (args[argIndex].equals(ARGS_PRESENT)) { + present = true; + + } else if (args[argIndex].equals(ARGS_EXCLUSIVE)) { + exclusive = true; + + } else if (args[argIndex].equals(ARGS_HIDE_STOP)) { + hideStop = true; + + } else if (args[argIndex].equals(ARGS_EXTERNAL)) { + external = true; + } else { - if (args[argIndex].equals(ARGS_PRESENT)) { - present = true; - - } else if (args[argIndex].equals(ARGS_EXCLUSIVE)) { - exclusive = true; - - } else if (args[argIndex].equals(ARGS_HIDE_STOP)) { - hideStop = true; - - } else if (args[argIndex].equals(ARGS_EXTERNAL)) { - external = true; - - } else { - name = args[argIndex]; - break; - } + name = args[argIndex]; + break; } - argIndex++; } + argIndex++; + } - // Set this property before getting into any GUI init code - //System.setProperty("com.apple.mrj.application.apple.menu.about.name", name); - // This )*)(*@#$ Apple crap don't work no matter where you put it - // (static method of the class, at the top of main, wherever) + // Set this property before getting into any GUI init code + //System.setProperty("com.apple.mrj.application.apple.menu.about.name", name); + // This )*)(*@#$ Apple crap don't work no matter where you put it + // (static method of the class, at the top of main, wherever) - if (displayDevice == null) { - GraphicsEnvironment environment = - GraphicsEnvironment.getLocalGraphicsEnvironment(); - displayDevice = environment.getDefaultScreenDevice(); - } + if (displayDevice == null) { + GraphicsEnvironment environment = + GraphicsEnvironment.getLocalGraphicsEnvironment(); + displayDevice = environment.getDefaultScreenDevice(); + } - Frame frame = new Frame(displayDevice.getDefaultConfiguration()); + Frame frame = new Frame(displayDevice.getDefaultConfiguration()); /* Frame frame = null; if (displayDevice != null) { @@ -6509,195 +6591,191 @@ public class PApplet extends Applet */ //Dimension screen = Toolkit.getDefaultToolkit().getScreenSize(); - // remove the grow box by default - // users who want it back can call frame.setResizable(true) - frame.setResizable(false); + // remove the grow box by default + // users who want it back can call frame.setResizable(true) + frame.setResizable(false); - // Set the trimmings around the image - Image image = Toolkit.getDefaultToolkit().createImage(ICON_IMAGE); - frame.setIconImage(image); - frame.setTitle(name); + // Set the trimmings around the image + Image image = Toolkit.getDefaultToolkit().createImage(ICON_IMAGE); + frame.setIconImage(image); + frame.setTitle(name); -// Class c = Class.forName(name); + final PApplet applet; + try { Class c = Thread.currentThread().getContextClassLoader().loadClass(name); - final PApplet applet = (PApplet) c.newInstance(); - - // these are needed before init/start - applet.frame = frame; - applet.sketchPath = folder; - applet.args = PApplet.subset(args, 1); - applet.external = external; - - // Need to save the window bounds at full screen, - // because pack() will cause the bounds to go to zero. - // http://dev.processing.org/bugs/show_bug.cgi?id=923 - Rectangle fullScreenRect = null; - - // For 0149, moving this code (up to the pack() method) before init(). - // For OpenGL (and perhaps other renderers in the future), a peer is - // needed before a GLDrawable can be created. So pack() needs to be - // called on the Frame before applet.init(), which itself calls size(), - // and launches the Thread that will kick off setup(). - // http://dev.processing.org/bugs/show_bug.cgi?id=891 - // http://dev.processing.org/bugs/show_bug.cgi?id=908 - if (present) { - frame.setUndecorated(true); - frame.setBackground(backgroundColor); - if (exclusive) { - displayDevice.setFullScreenWindow(frame); - fullScreenRect = frame.getBounds(); - } else { - DisplayMode mode = displayDevice.getDisplayMode(); - fullScreenRect = new Rectangle(0, 0, mode.getWidth(), mode.getHeight()); - frame.setBounds(fullScreenRect); - frame.setVisible(true); - } - } - frame.setLayout(null); - frame.add(applet); - if (present) { - frame.invalidate(); - } else { - frame.pack(); - } - // insufficient, places the 100x100 sketches offset strangely - //frame.validate(); - - applet.init(); - - // Wait until the applet has figured out its width. - // In a static mode app, this will be after setup() has completed, - // and the empty draw() has set "finished" to true. - // TODO make sure this won't hang if the applet has an exception. - while (applet.defaultSize && !applet.finished) { - //System.out.println("default size"); - try { - Thread.sleep(5); - - } catch (InterruptedException e) { - //System.out.println("interrupt"); - } - } - //println("not default size " + applet.width + " " + applet.height); - //println(" (g width/height is " + applet.g.width + "x" + applet.g.height + ")"); - - if (present) { - // After the pack(), the screen bounds are gonna be 0s - frame.setBounds(fullScreenRect); - applet.setBounds((fullScreenRect.width - applet.width) / 2, - (fullScreenRect.height - applet.height) / 2, - applet.width, applet.height); - - if (!hideStop) { - Label label = new Label("stop"); - label.setForeground(stopColor); - label.addMouseListener(new MouseAdapter() { - public void mousePressed(MouseEvent e) { - System.exit(0); - } - }); - frame.add(label); - - Dimension labelSize = label.getPreferredSize(); - // sometimes shows up truncated on mac - //System.out.println("label width is " + labelSize.width); - labelSize = new Dimension(100, labelSize.height); - label.setSize(labelSize); - label.setLocation(20, fullScreenRect.height - labelSize.height - 20); - } - - // not always running externally when in present mode - if (external) { - applet.setupExternalMessages(); - } - - } else { // if not presenting - // can't do pack earlier cuz present mode don't like it - // (can't go full screen with a frame after calling pack) -// frame.pack(); // get insets. get more. - Insets insets = frame.getInsets(); - - int windowW = Math.max(applet.width, MIN_WINDOW_WIDTH) + - insets.left + insets.right; - int windowH = Math.max(applet.height, MIN_WINDOW_HEIGHT) + - insets.top + insets.bottom; - - frame.setSize(windowW, windowH); - - if (location != null) { - // a specific location was received from PdeRuntime - // (applet has been run more than once, user placed window) - frame.setLocation(location[0], location[1]); - - } else if (external) { - int locationX = editorLocation[0] - 20; - int locationY = editorLocation[1]; - - if (locationX - windowW > 10) { - // if it fits to the left of the window - frame.setLocation(locationX - windowW, locationY); - - } else { // doesn't fit - // if it fits inside the editor window, - // offset slightly from upper lefthand corner - // so that it's plunked inside the text area - locationX = editorLocation[0] + 66; - locationY = editorLocation[1] + 66; - - if ((locationX + windowW > applet.screen.width - 33) || - (locationY + windowH > applet.screen.height - 33)) { - // otherwise center on screen - locationX = (applet.screen.width - windowW) / 2; - locationY = (applet.screen.height - windowH) / 2; - } - frame.setLocation(locationX, locationY); - } - } else { // just center on screen - frame.setLocation((applet.screen.width - applet.width) / 2, - (applet.screen.height - applet.height) / 2); - } - -// frame.setLayout(null); -// frame.add(applet); - - if (backgroundColor == Color.black) { //BLACK) { - // this means no bg color unless specified - backgroundColor = SystemColor.control; - } - frame.setBackground(backgroundColor); - - int usableWindowH = windowH - insets.top - insets.bottom; - applet.setBounds((windowW - applet.width)/2, - insets.top + (usableWindowH - applet.height)/2, - applet.width, applet.height); - - if (external) { - applet.setupExternalMessages(); - - } else { // !external - frame.addWindowListener(new WindowAdapter() { - public void windowClosing(WindowEvent e) { - System.exit(0); - } - }); - } - - // handle frame resizing events - applet.setupFrameResizeListener(); - - // all set for rockin - if (applet.displayable()) { - frame.setVisible(true); - } - } - - applet.requestFocus(); // ask for keydowns - //System.out.println("exiting main()"); - + applet = (PApplet) c.newInstance(); } catch (Exception e) { - e.printStackTrace(); - System.exit(1); + throw new RuntimeException(e); } + + // these are needed before init/start + applet.frame = frame; + applet.sketchPath = folder; + applet.args = PApplet.subset(args, 1); + applet.external = external; + + // Need to save the window bounds at full screen, + // because pack() will cause the bounds to go to zero. + // http://dev.processing.org/bugs/show_bug.cgi?id=923 + Rectangle fullScreenRect = null; + + // For 0149, moving this code (up to the pack() method) before init(). + // For OpenGL (and perhaps other renderers in the future), a peer is + // needed before a GLDrawable can be created. So pack() needs to be + // called on the Frame before applet.init(), which itself calls size(), + // and launches the Thread that will kick off setup(). + // http://dev.processing.org/bugs/show_bug.cgi?id=891 + // http://dev.processing.org/bugs/show_bug.cgi?id=908 + if (present) { + frame.setUndecorated(true); + frame.setBackground(backgroundColor); + if (exclusive) { + displayDevice.setFullScreenWindow(frame); + fullScreenRect = frame.getBounds(); + } else { + DisplayMode mode = displayDevice.getDisplayMode(); + fullScreenRect = new Rectangle(0, 0, mode.getWidth(), mode.getHeight()); + frame.setBounds(fullScreenRect); + frame.setVisible(true); + } + } + frame.setLayout(null); + frame.add(applet); + if (present) { + frame.invalidate(); + } else { + frame.pack(); + } + // insufficient, places the 100x100 sketches offset strangely + //frame.validate(); + + applet.init(); + + // Wait until the applet has figured out its width. + // In a static mode app, this will be after setup() has completed, + // and the empty draw() has set "finished" to true. + // TODO make sure this won't hang if the applet has an exception. + while (applet.defaultSize && !applet.finished) { + //System.out.println("default size"); + try { + Thread.sleep(5); + + } catch (InterruptedException e) { + //System.out.println("interrupt"); + } + } + //println("not default size " + applet.width + " " + applet.height); + //println(" (g width/height is " + applet.g.width + "x" + applet.g.height + ")"); + + if (present) { + // After the pack(), the screen bounds are gonna be 0s + frame.setBounds(fullScreenRect); + applet.setBounds((fullScreenRect.width - applet.width) / 2, + (fullScreenRect.height - applet.height) / 2, + applet.width, applet.height); + + if (!hideStop) { + Label label = new Label("stop"); + label.setForeground(stopColor); + label.addMouseListener(new MouseAdapter() { + public void mousePressed(MouseEvent e) { + System.exit(0); + } + }); + frame.add(label); + + Dimension labelSize = label.getPreferredSize(); + // sometimes shows up truncated on mac + //System.out.println("label width is " + labelSize.width); + labelSize = new Dimension(100, labelSize.height); + label.setSize(labelSize); + label.setLocation(20, fullScreenRect.height - labelSize.height - 20); + } + + // not always running externally when in present mode + if (external) { + applet.setupExternalMessages(); + } + + } else { // if not presenting + // can't do pack earlier cuz present mode don't like it + // (can't go full screen with a frame after calling pack) + // frame.pack(); // get insets. get more. + Insets insets = frame.getInsets(); + + int windowW = Math.max(applet.width, MIN_WINDOW_WIDTH) + + insets.left + insets.right; + int windowH = Math.max(applet.height, MIN_WINDOW_HEIGHT) + + insets.top + insets.bottom; + + frame.setSize(windowW, windowH); + + if (location != null) { + // a specific location was received from PdeRuntime + // (applet has been run more than once, user placed window) + frame.setLocation(location[0], location[1]); + + } else if (external) { + int locationX = editorLocation[0] - 20; + int locationY = editorLocation[1]; + + if (locationX - windowW > 10) { + // if it fits to the left of the window + frame.setLocation(locationX - windowW, locationY); + + } else { // doesn't fit + // if it fits inside the editor window, + // offset slightly from upper lefthand corner + // so that it's plunked inside the text area + locationX = editorLocation[0] + 66; + locationY = editorLocation[1] + 66; + + if ((locationX + windowW > applet.screen.width - 33) || + (locationY + windowH > applet.screen.height - 33)) { + // otherwise center on screen + locationX = (applet.screen.width - windowW) / 2; + locationY = (applet.screen.height - windowH) / 2; + } + frame.setLocation(locationX, locationY); + } + } else { // just center on screen + frame.setLocation((applet.screen.width - applet.width) / 2, + (applet.screen.height - applet.height) / 2); + } + + if (backgroundColor == Color.black) { //BLACK) { + // this means no bg color unless specified + backgroundColor = SystemColor.control; + } + frame.setBackground(backgroundColor); + + int usableWindowH = windowH - insets.top - insets.bottom; + applet.setBounds((windowW - applet.width)/2, + insets.top + (usableWindowH - applet.height)/2, + applet.width, applet.height); + + if (external) { + applet.setupExternalMessages(); + + } else { // !external + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + System.exit(0); + } + }); + } + + // handle frame resizing events + applet.setupFrameResizeListener(); + + // all set for rockin + if (applet.displayable()) { + frame.setVisible(true); + } + } + + applet.requestFocus(); // ask for keydowns + //System.out.println("exiting main()"); } @@ -7225,6 +7303,11 @@ public class PApplet extends Applet } + public float textWidth(char[] chars, int start, int length) { + return g.textWidth(chars, start, length); + } + + public void text(char c) { if (recorder != null) recorder.text(c); g.text(c); diff --git a/core/src/processing/core/PGraphics.java b/core/src/processing/core/PGraphics.java index fbee90fac..cc5562bcd 100644 --- a/core/src/processing/core/PGraphics.java +++ b/core/src/processing/core/PGraphics.java @@ -2604,6 +2604,14 @@ public class PGraphics extends PImage implements PConstants { } + /** + * TODO not sure if this stays... + */ + public float textWidth(char[] chars, int start, int length) { + return textWidthImpl(chars, start, start + length); + } + + /** * Implementation of returning the text width of * the chars [start, stop) in the buffer. @@ -2914,8 +2922,8 @@ public class PGraphics extends PImage implements PConstants { * Emit a sentence of text, defined as a chunk of text without any newlines. * @param stop non-inclusive, the end of the text in question */ - private boolean textSentence(char[] buffer, int start, int stop, - float boxWidth, float spaceWidth) { + protected boolean textSentence(char[] buffer, int start, int stop, + float boxWidth, float spaceWidth) { float runningX = 0; // Keep track of this separately from index, since we'll need to back up @@ -2980,7 +2988,7 @@ public class PGraphics extends PImage implements PConstants { } - private void textSentenceBreak(int start, int stop) { + protected void textSentenceBreak(int start, int stop) { if (textBreakCount == textBreakStart.length) { textBreakStart = PApplet.expand(textBreakStart); textBreakStop = PApplet.expand(textBreakStop); diff --git a/core/src/processing/core/PGraphics2D.java b/core/src/processing/core/PGraphics2D.java index 69d857c10..0c0bfa77e 100644 --- a/core/src/processing/core/PGraphics2D.java +++ b/core/src/processing/core/PGraphics2D.java @@ -283,9 +283,9 @@ public class PGraphics2D extends PGraphics { case TRIANGLE_FAN: // do fill and stroke separately because otherwise // the lines will be stroked more than necessary - if (fill) { + if (fill || textureImage != null) { fpolygon.vertexCount = 3; - + for (int i = 1; i < vertexCount-1; i++) { // System.out.println(i + " of " + vertexCount); @@ -311,7 +311,7 @@ public class PGraphics2D extends PGraphics { fpolygon.vertices[j][TX] = vertices[i+j][TX]; fpolygon.vertices[j][TY] = vertices[i+j][TY]; - + // System.out.println(fpolygon.vertices[j][TX] + " " + fpolygon.vertices[j][TY]); if (textureImage != null) { @@ -342,7 +342,7 @@ public class PGraphics2D extends PGraphics { increment = (shape == TRIANGLES) ? 3 : 1; // do fill and stroke separately because otherwise // the lines will be stroked more than necessary - if (fill) { + if (fill || textureImage != null) { fpolygon.vertexCount = 3; for (int i = 0; i < vertexCount-2; i += increment) { for (int j = 0; j < 3; j++) { @@ -379,7 +379,7 @@ public class PGraphics2D extends PGraphics { break; case QUADS: - if (fill) { + if (fill || textureImage != null) { fpolygon.vertexCount = 4; for (int i = 0; i < vertexCount-3; i += 4) { for (int j = 0; j < 4; j++) { @@ -412,14 +412,14 @@ public class PGraphics2D extends PGraphics { break; case QUAD_STRIP: - if (fill) { + if (fill || textureImage != null) { fpolygon.vertexCount = 4; for (int i = 0; i < vertexCount-3; i += 2) { for (int j = 0; j < 4; j++) { int jj = i+j; if (j == 2) jj = i+3; // swap 2nd and 3rd vertex if (j == 3) jj = i+2; - + fpolygon.vertices[j][R] = vertices[jj][R]; fpolygon.vertices[j][G] = vertices[jj][G]; fpolygon.vertices[j][B] = vertices[jj][B]; @@ -445,7 +445,7 @@ public class PGraphics2D extends PGraphics { case POLYGON: if (isConvex()) { - if (fill) { + if (fill || textureImage != null) { //System.out.println("convex"); fpolygon.renderPolygon(vertices, vertexCount); //if (stroke) polygon.unexpand(); @@ -463,7 +463,7 @@ public class PGraphics2D extends PGraphics { } } else { // not convex //System.out.println("concave"); - if (fill) { + if (fill || textureImage != null) { // the triangulator produces polygons that don't align // when smoothing is enabled. but if there is a stroke around // the polygon, then smoothing can be temporarily disabled. @@ -1041,14 +1041,14 @@ public class PGraphics2D extends PGraphics { protected void ellipseImpl(float x, float y, float w, float h) { if (smooth || (strokeWeight != 1) || fillAlpha || strokeAlpha || ctm.isWarped()) { - // identical to PGraphics version, but uses POLYGON + // identical to PGraphics version, but uses POLYGON // for the fill instead of a TRIANGLE_FAN float radiusH = w / 2; float radiusV = h / 2; float centerX = x + radiusH; float centerY = y + radiusV; - + float sx1 = screenX(x, y); float sy1 = screenY(x, y); float sx2 = screenX(x+w, y+h); @@ -1423,11 +1423,6 @@ public class PGraphics2D extends PGraphics { */ private void simple_image(PImage image, int sx1, int sy1, int ix1, int iy1, int ix2, int iy2) { - if (imageMode == CENTER) { - sx1 -= image.width / 2; - sy1 -= image.height / 2; - } - int sx2 = sx1 + image.width; int sy2 = sy1 + image.height; @@ -1703,7 +1698,7 @@ public class PGraphics2D extends PGraphics { float len = (float) Math.sqrt(dX*dX + dY*dY); // TODO stroke width should be transformed! - float rh = strokeWeight / len; + float rh = (strokeWeight / len) / 2; float dx0 = rh * dY; float dy0 = rh * dX; @@ -1765,7 +1760,7 @@ public class PGraphics2D extends PGraphics { } } - + /** * @param max is what to count to * @param offset is offset to the 'next' vertex @@ -2018,7 +2013,7 @@ public class PGraphics2D extends PGraphics { public float screenY(float x, float y) { return ctm.m10 * x + ctm.m11 * y + ctm.m12; } - + ////////////////////////////////////////////////////////////// diff --git a/core/src/processing/core/PGraphics3D.java b/core/src/processing/core/PGraphics3D.java index de615683d..ba5af3c15 100644 --- a/core/src/processing/core/PGraphics3D.java +++ b/core/src/processing/core/PGraphics3D.java @@ -608,7 +608,7 @@ public class PGraphics3D extends PGraphics { endShapeStroke(mode); } - if (fill) { + if (fill || textureImage != null) { endShapeFill(); } @@ -622,7 +622,7 @@ public class PGraphics3D extends PGraphics { // render shape and fill here if not saving the shapes for later // if true, the shapes will be rendered on endDraw if (!hints[ENABLE_DEPTH_SORT]) { - if (fill) { + if (fill || textureImage != null) { if (triangleCount > 0) { renderTriangles(0, triangleCount); if (raw != null) { @@ -957,8 +957,8 @@ public class PGraphics3D extends PGraphics { protected void addPoint(int a) { if (pointCount == points.length) { int[][] temp = new int[pointCount << 1][LINE_FIELD_COUNT]; - System.arraycopy(lines, 0, temp, 0, lineCount); - lines = temp; + System.arraycopy(points, 0, temp, 0, lineCount); + points = temp; } points[pointCount][VERTEX1] = a; //points[pointCount][STROKE_MODE] = strokeCap | strokeJoin; @@ -1135,12 +1135,12 @@ public class PGraphics3D extends PGraphics { protected void renderLines(int start, int stop) { for (int i = start; i < stop; i++) { - renderLineVertices(vertices[lines[i][VERTEX1]], + renderLineVertices(vertices[lines[i][VERTEX1]], vertices[lines[i][VERTEX2]]); } } - - + + protected void renderLineVertices(float[] a, float[] b) { // 2D hack added by ewjordan 6/13/07 // Offset coordinates by a little bit if drawing 2D graphics. @@ -1181,7 +1181,7 @@ public class PGraphics3D extends PGraphics { float oy2 = b[TY]; // TODO strokeWeight should be transformed! - float weight = a[SW] / 2; + float weight = a[SW] / 2; // when drawing points with stroke weight, need to extend a bit if (ox1 == ox2 && oy1 == oy2) { @@ -2615,8 +2615,8 @@ public class PGraphics3D extends PGraphics { //public void ellipse(float a, float b, float c, float d) - - + + protected void ellipseImpl(float x, float y, float w, float h) { float radiusH = w / 2; float radiusV = h / 2; @@ -2632,7 +2632,7 @@ public class PGraphics3D extends PGraphics { // returning to pre-1.0 version of algorithm because of problems int rough = (int)(4+Math.sqrt(w+h)*3); int accuracy = PApplet.constrain(rough, 6, 100); - + if (fill) { // returning to pre-1.0 version of algorithm because of problems // int rough = (int)(4+Math.sqrt(w+h)*3); @@ -2755,7 +2755,7 @@ public class PGraphics3D extends PGraphics { } } - + ////////////////////////////////////////////////////////////// diff --git a/core/src/processing/core/PGraphicsJava2D.java b/core/src/processing/core/PGraphicsJava2D.java index efce3fc92..c45ae77ca 100644 --- a/core/src/processing/core/PGraphicsJava2D.java +++ b/core/src/processing/core/PGraphicsJava2D.java @@ -90,13 +90,13 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { public PGraphicsJava2D() { } - + //public void setParent(PApplet parent) - - + + //public void setPrimary(boolean primary) - - + + //public void setPath(String path) @@ -131,9 +131,9 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { //reapplySettings = true; } - + //public void dispose() - + ////////////////////////////////////////////////////////////// @@ -144,11 +144,11 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { public boolean canDraw() { return true; } - - + + public void beginDraw() { checkSettings(); - + resetMatrix(); // reset model matrix // reset vertices @@ -171,37 +171,37 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { ////////////////////////////////////////////////////////////// - + // SETTINGS - - + + //protected void checkSettings() - - + + //protected void defaultSettings() - - + + //protected void reapplySettings() - + ////////////////////////////////////////////////////////////// // HINT - - + + //public void hint(int which) - - - + + + ////////////////////////////////////////////////////////////// // SHAPES //public void beginShape(int kind) - - + + public void beginShape(int kind) { //super.beginShape(kind); shape = kind; @@ -215,14 +215,14 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { // then just use it to continue the shape. gpath = null; } - - + + //public boolean edge(boolean e) //public void normal(float nx, float ny, float nz) { - + //public void textureMode(int mode) @@ -355,7 +355,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { showDepthWarningXYZ("vertex"); } - + public void breakShape() { breakShape = true; } @@ -374,16 +374,16 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } - + ////////////////////////////////////////////////////////////// // BEZIER VERTICES - - + + public void bezierVertex(float x1, float y1, float x2, float y2, float x3, float y3) { - bezierVertexCheck(); + bezierVertexCheck(); gpath.curveTo(x1, y1, x2, y2, x3, y3); } @@ -394,13 +394,13 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { showDepthWarningXYZ("bezierVertex"); } - + ////////////////////////////////////////////////////////////// // CURVE VERTICES - - + + protected void curveVertexCheck() { super.curveVertexCheck(); @@ -413,9 +413,9 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } - protected void curveVertexSegment(float x1, float y1, - float x2, float y2, - float x3, float y3, + protected void curveVertexSegment(float x1, float y1, + float x2, float y2, + float x3, float y3, float x4, float y4) { curveCoordX[0] = x1; curveCoordY[0] = y1; @@ -443,8 +443,8 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { curveDrawX[2], curveDrawY[2], curveDrawX[3], curveDrawY[3]); } - - + + public void curveVertex(float x, float y, float z) { showDepthWarningXYZ("curveVertex"); } @@ -454,24 +454,24 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { ////////////////////////////////////////////////////////////// // RENDERER - - + + //public void flush() - - - + + + ////////////////////////////////////////////////////////////// // POINT, LINE, TRIANGLE, QUAD - + public void point(float x, float y) { if (stroke) { - if (strokeWeight > 1) { - line(x, y, x + EPSILON, y + EPSILON); - } else { - set((int) screenX(x, y), (int) screenY(x, y), strokeColor); - } +// if (strokeWeight > 1) { + line(x, y, x + EPSILON, y + EPSILON); +// } else { +// set((int) screenX(x, y), (int) screenY(x, y), strokeColor); +// } } } @@ -504,43 +504,43 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { drawShape(gp); } - + ////////////////////////////////////////////////////////////// // RECT - + //public void rectMode(int mode) - - + + //public void rect(float a, float b, float c, float d) - + protected void rectImpl(float x1, float y1, float x2, float y2) { rect.setFrame(x1, y1, x2-x1, y2-y1); drawShape(rect); } - + ////////////////////////////////////////////////////////////// // ELLIPSE - + //public void ellipseMode(int mode) - - + + //public void ellipse(float a, float b, float c, float d) - + protected void ellipseImpl(float x, float y, float w, float h) { ellipse.setFrame(x, y, w, h); drawShape(ellipse); } - + ////////////////////////////////////////////////////////////// @@ -550,7 +550,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { //public void arc(float a, float b, float c, float d, // float start, float stop) - + protected void arcImpl(float x, float y, float w, float h, float start, float stop) { // 0 to 90 in java would be 0 to -90 for p5 renderer @@ -584,13 +584,13 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } } - - + + ////////////////////////////////////////////////////////////// // JAVA2D SHAPE/PATH HANDLING - + protected void fillShape(Shape s) { if (fillGradient) { g2.setPaint(fillGradientObject); @@ -601,7 +601,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } } - + protected void strokeShape(Shape s) { if (strokeGradient) { g2.setPaint(strokeGradientObject); @@ -612,7 +612,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } } - + protected void drawShape(Shape s) { if (fillGradient) { g2.setPaint(fillGradientObject); @@ -630,121 +630,122 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } } - + ////////////////////////////////////////////////////////////// - + // BOX - + //public void box(float size) - - + + public void box(float w, float h, float d) { showMethodWarning("box"); } - - + + ////////////////////////////////////////////////////////////// - + // SPHERE - + //public void sphereDetail(int res) - - + + //public void sphereDetail(int ures, int vres) - - + + public void sphere(float r) { showMethodWarning("sphere"); } - + ////////////////////////////////////////////////////////////// // BEZIER - + //public float bezierPoint(float a, float b, float c, float d, float t) - - + + //public float bezierTangent(float a, float b, float c, float d, float t) - - + + //protected void bezierInitCheck() - - + + //protected void bezierInit() - - + + /** Ignored (not needed) in Java 2D. */ public void bezierDetail(int detail) { } - - + + //public void bezier(float x1, float y1, // float x2, float y2, // float x3, float y3, // float x4, float y4) - - + + //public void bezier(float x1, float y1, float z1, // float x2, float y2, float z2, // float x3, float y3, float z3, // float x4, float y4, float z4) - + ////////////////////////////////////////////////////////////// // CURVE - + //public float curvePoint(float a, float b, float c, float d, float t) - - + + //public float curveTangent(float a, float b, float c, float d, float t) - + /** Ignored (not needed) in Java 2D. */ public void curveDetail(int detail) { } - + //public void curveTightness(float tightness) - - + + //protected void curveInitCheck() - - + + //protected void curveInit() - - + + //public void curve(float x1, float y1, // float x2, float y2, // float x3, float y3, // float x4, float y4) - - + + //public void curve(float x1, float y1, float z1, // float x2, float y2, float z2, // float x3, float y3, float z3, // float x4, float y4, float z4) - + ////////////////////////////////////////////////////////////// - + // SMOOTH - + public void smooth() { smooth = true; g2.setRenderingHint(RenderingHints.KEY_ANTIALIASING, RenderingHints.VALUE_ANTIALIAS_ON); g2.setRenderingHint(RenderingHints.KEY_INTERPOLATION, +// RenderingHints.VALUE_INTERPOLATION_BILINEAR); RenderingHints.VALUE_INTERPOLATION_BICUBIC); } @@ -758,21 +759,21 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } - + ////////////////////////////////////////////////////////////// // IMAGE - - + + //public void imageMode(int mode) - - + + //public void image(PImage image, float x, float y) - - + + //public void image(PImage image, float x, float y, float c, float d) - - + + //public void image(PImage image, // float a, float b, float c, float d, // int u1, int v1, int u2, int v2) @@ -786,7 +787,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { int u1, int v1, int u2, int v2) { // Image not ready yet, or an error if (who.width <= 0 || who.height <= 0) return; - + if (who.getCache(this) == null) { //System.out.println("making new image cache"); who.setCache(this, new ImageCache(who)); @@ -934,39 +935,39 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } } - + ////////////////////////////////////////////////////////////// // SHAPE - + //public void shapeMode(int mode) - - + + //public void shape(PShape shape) - - + + //public void shape(PShape shape, float x, float y) - - + + //public void shape(PShape shape, float x, float y, float c, float d) - + ////////////////////////////////////////////////////////////// // TEXT ATTRIBTUES - + //public void textAlign(int align) - - + + //public void textAlign(int alignX, int alignY) - + public float textAscent() { - Font font = textFont.getFont(); + Font font = textFont.getFont(); if (font == null) { return super.textAscent(); } @@ -976,7 +977,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { public float textDescent() { - Font font = textFont.getFont(); + Font font = textFont.getFont(); if (font == null) { return super.textDescent(); } @@ -986,21 +987,21 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { //public void textFont(PFont which) - - + + //public void textFont(PFont which, float size) - - + + //public void textLeading(float leading) - - + + //public void textMode(int mode) - - + + protected boolean textModeCheck(int mode) { return (mode == MODEL) || (mode == SCREEN); } - + /** * Same as parent, but override for native version of the font. @@ -1030,10 +1031,10 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { //public float textWidth(char c) - - + + //public float textWidth(String str) - + protected float textWidthImpl(char buffer[], int start, int stop) { Font font = textFont.getFont(); @@ -1051,20 +1052,20 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { ////////////////////////////////////////////////////////////// // TEXT - + // None of the variations of text() are overridden from PGraphics. - - - + + + ////////////////////////////////////////////////////////////// // TEXT IMPL - - + + //protected void textLineAlignImpl(char buffer[], int start, int stop, // float x, float y) - + protected void textLineImpl(char buffer[], int start, int stop, float x, float y) { Font font = textFont.getFont(); @@ -1118,7 +1119,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { // and creates garbage because of the new temporary object //java.awt.font.GlyphVector gv = textFontNative.createGlyphVector(g2.getFontRenderContext(), new String(buffer, start, stop)); //g2.drawGlyphVector(gv, x, y); - + // System.out.println("text() " + new String(buffer, start, stop)); // return to previous smoothing state if it was changed @@ -1131,11 +1132,11 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } - + ////////////////////////////////////////////////////////////// // MATRIX STACK - + public void pushMatrix() { if (transformCount == transformStack.length) { @@ -1157,11 +1158,11 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } - + ////////////////////////////////////////////////////////////// // MATRIX TRANSFORMS - + public void translate(float tx, float ty) { g2.translate(tx, ty); @@ -1169,28 +1170,28 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { //public void translate(float tx, float ty, float tz) - + public void rotate(float angle) { g2.rotate(angle); } - + public void rotateX(float angle) { showDepthWarning("rotateX"); } - - + + public void rotateY(float angle) { showDepthWarning("rotateY"); } - - + + public void rotateZ(float angle) { showDepthWarning("rotateZ"); } - - + + public void rotate(float angle, float vx, float vy, float vz) { showVariationWarning("rotate"); } @@ -1205,25 +1206,25 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { g2.scale(sx, sy); } - + public void scale(float sx, float sy, float sz) { showDepthWarningXYZ("scale"); } - + ////////////////////////////////////////////////////////////// // MATRIX MORE - + public void resetMatrix() { g2.setTransform(new AffineTransform()); } //public void applyMatrix(PMatrix2D source) - + public void applyMatrix(float n00, float n01, float n02, float n10, float n11, float n12) { @@ -1232,10 +1233,10 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { g2.transform(new AffineTransform(n00, n10, n01, n11, n02, n12)); //g2.transform(new AffineTransform(n00, n01, n02, n10, n11, n12)); } - - + + //public void applyMatrix(PMatrix3D source) - + public void applyMatrix(float n00, float n01, float n02, float n03, float n10, float n11, float n12, float n13, @@ -1244,7 +1245,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { showVariationWarning("applyMatrix"); } - + ////////////////////////////////////////////////////////////// @@ -1254,53 +1255,53 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { public PMatrix getMatrix() { return getMatrix((PMatrix2D) null); } - - + + public PMatrix2D getMatrix(PMatrix2D target) { if (target == null) { target = new PMatrix2D(); } g2.getTransform().getMatrix(transform); - target.set((float) transform[0], (float) transform[2], (float) transform[4], + target.set((float) transform[0], (float) transform[2], (float) transform[4], (float) transform[1], (float) transform[3], (float) transform[5]); return target; } - + public PMatrix3D getMatrix(PMatrix3D target) { showVariationWarning("getMatrix"); return target; } - + //public void setMatrix(PMatrix source) - + public void setMatrix(PMatrix2D source) { - g2.setTransform(new AffineTransform(source.m00, source.m10, + g2.setTransform(new AffineTransform(source.m00, source.m10, source.m01, source.m11, source.m02, source.m12)); } - + public void setMatrix(PMatrix3D source) { showVariationWarning("setMatrix"); } - - + + public void printMatrix() { getMatrix((PMatrix2D) null).print(); } - + ////////////////////////////////////////////////////////////// - + // CAMERA and PROJECTION - - // Inherit the plaintive warnings from PGraphics - - + + // Inherit the plaintive warnings from PGraphics + + //public void beginCamera() //public void endCamera() //public void camera() @@ -1315,12 +1316,12 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { // float near, float far) //public void perspective() //public void perspective(float fov, float aspect, float near, float far) - //public void frustum(float left, float right, - // float bottom, float top, + //public void frustum(float left, float right, + // float bottom, float top, // float near, float far) //public void printProjection() - + ////////////////////////////////////////////////////////////// @@ -1338,47 +1339,47 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { return (float)transform[1]*x + (float)transform[3]*y + (float)transform[5]; } - + public float screenX(float x, float y, float z) { showDepthWarningXYZ("screenX"); return 0; } - - + + public float screenY(float x, float y, float z) { showDepthWarningXYZ("screenY"); return 0; } - - + + public float screenZ(float x, float y, float z) { showDepthWarningXYZ("screenZ"); return 0; } - - + + //public float modelX(float x, float y, float z) - - + + //public float modelY(float x, float y, float z) - - + + //public float modelZ(float x, float y, float z) - + ////////////////////////////////////////////////////////////// - + // STYLE - - // pushStyle(), popStyle(), style() and getStyle() inherited. + + // pushStyle(), popStyle(), style() and getStyle() inherited. + - ////////////////////////////////////////////////////////////// // STROKE CAP/JOIN/WEIGHT - + public void strokeCap(int cap) { super.strokeCap(cap); @@ -1423,7 +1424,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { // STROKE // noStroke() and stroke() inherited from PGraphics. - + protected void strokeFromCalc() { super.strokeFromCalc(); @@ -1431,14 +1432,14 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { strokeGradient = false; } - - + + ////////////////////////////////////////////////////////////// // TINT // noTint() and tint() inherited from PGraphics. - + protected void tintFromCalc() { super.tintFromCalc(); @@ -1446,14 +1447,14 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { tintColorObject = new Color(tintColor, true); } - - + + ////////////////////////////////////////////////////////////// // FILL // noFill() and fill() inherited from PGraphics. - + protected void fillFromCalc() { super.fillFromCalc(); @@ -1466,8 +1467,8 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { ////////////////////////////////////////////////////////////// // MATERIAL PROPERTIES - - + + //public void ambient(int rgb) //public void ambient(float gray) //public void ambient(float x, float y, float z) @@ -1482,12 +1483,12 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { //public void emissive(float x, float y, float z ) //protected void emissiveFromCalc() - + ////////////////////////////////////////////////////////////// // LIGHTS - + //public void lights() //public void noLights() @@ -1507,34 +1508,34 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { //protected void lightPosition(int num, float x, float y, float z) //protected void lightDirection(int num, float x, float y, float z) - + ////////////////////////////////////////////////////////////// // BACKGROUND - // background() methods inherited from PGraphics, along with the + // background() methods inherited from PGraphics, along with the // PImage version of backgroundImpl(), since it just calls set(). - + //public void backgroundImpl(PImage image) - - + + int[] clearPixels; public void backgroundImpl() { if (backgroundAlpha) { - // Create a small array that can be used to set the pixels several times. - // Using a single-pixel line of length 'width' is a tradeoff between - // speed (setting each pixel individually is too slow) and memory - // (an array for width*height would waste lots of memory if it stayed - // resident, and would terrify the gc if it were re-created on each trip + // Create a small array that can be used to set the pixels several times. + // Using a single-pixel line of length 'width' is a tradeoff between + // speed (setting each pixel individually is too slow) and memory + // (an array for width*height would waste lots of memory if it stayed + // resident, and would terrify the gc if it were re-created on each trip // to background(). WritableRaster raster = ((BufferedImage) image).getRaster(); if ((clearPixels == null) || (clearPixels.length < width)) { clearPixels = new int[width]; } - java.util.Arrays.fill(clearPixels, backgroundColor); + java.util.Arrays.fill(clearPixels, backgroundColor); for (int i = 0; i < height; i++) { raster.setDataElements(0, i, width, 1, clearPixels); } @@ -1553,51 +1554,51 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { ////////////////////////////////////////////////////////////// - + // COLOR MODE - + // All colorMode() variations are inherited from PGraphics. - + ////////////////////////////////////////////////////////////// - + // COLOR CALC - + // colorCalc() and colorCalcARGB() inherited from PGraphics. - + ////////////////////////////////////////////////////////////// // COLOR DATATYPE STUFFING - + // final color() variations inherited. - - + + ////////////////////////////////////////////////////////////// // COLOR DATATYPE EXTRACTION - - // final methods alpha, red, green, blue, + + // final methods alpha, red, green, blue, // hue, saturation, and brightness all inherited. - + ////////////////////////////////////////////////////////////// // COLOR DATATYPE INTERPOLATION - + // both lerpColor variants inherited. - - - + + + ////////////////////////////////////////////////////////////// // BEGIN/END RAW - + public void beginRaw(PGraphics recorderRaw) { showMethodWarning("beginRaw"); } @@ -1608,35 +1609,35 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } - + ////////////////////////////////////////////////////////////// // WARNINGS and EXCEPTIONS - + // showWarning and showException inherited. - + ////////////////////////////////////////////////////////////// // RENDERER SUPPORT QUERIES - - + + //public boolean displayable() // true - - + + //public boolean is2D() // true - - + + //public boolean is3D() // false - + ////////////////////////////////////////////////////////////// - + // PIMAGE METHODS - + // getImage, setCache, getCache, removeCache, isModified, setModified @@ -1677,18 +1678,18 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } updatePixels(); } - - + + public void resize(int wide, int high) { showMethodWarning("resize"); } - + ////////////////////////////////////////////////////////////// // GET/SET - + static int getset[] = new int[1]; @@ -1704,7 +1705,7 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { //public PImage get(int x, int y, int w, int h) - + public PImage getImpl(int x, int y, int w, int h) { PImage output = new PImage(w, h); output.parent = parent; @@ -1743,13 +1744,13 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { raster.setDataElements(dx, dy, temp.width, temp.height, temp.pixels); } } - + ////////////////////////////////////////////////////////////// // MASK - + public void mask(int alpha[]) { showMethodWarning("mask"); @@ -1761,26 +1762,26 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { } - + ////////////////////////////////////////////////////////////// // FILTER - - // Because the PImage versions call loadPixels() and + + // Because the PImage versions call loadPixels() and // updatePixels(), no need to override anything here. - + //public void filter(int kind) //public void filter(int kind, float param) - + ////////////////////////////////////////////////////////////// // COPY - + public void copy(int sx, int sy, int sw, int sh, int dx, int dy, int dw, int dh) { @@ -1805,30 +1806,30 @@ public class PGraphicsJava2D extends PGraphics /*PGraphics2D*/ { // } - + ////////////////////////////////////////////////////////////// // BLEND - + // static public int blendColor(int c1, int c2, int mode) - - + + // public void blend(int sx, int sy, int sw, int sh, // int dx, int dy, int dw, int dh, int mode) - - + + // public void blend(PImage src, // int sx, int sy, int sw, int sh, // int dx, int dy, int dw, int dh, int mode) - + ////////////////////////////////////////////////////////////// // SAVE - + // public void save(String filename) { // loadPixels(); // super.save(filename); diff --git a/core/src/processing/core/PImage.java b/core/src/processing/core/PImage.java index ab6788be9..9dd126e4b 100644 --- a/core/src/processing/core/PImage.java +++ b/core/src/processing/core/PImage.java @@ -203,7 +203,7 @@ public class PImage implements PConstants, Cloneable { public java.awt.Image getImage() { loadPixels(); int type = (format == RGB) ? - BufferedImage.TYPE_INT_ARGB : BufferedImage.TYPE_INT_RGB; + BufferedImage.TYPE_INT_RGB : BufferedImage.TYPE_INT_ARGB; BufferedImage image = new BufferedImage(width, height, type); WritableRaster wr = image.getRaster(); wr.setDataElements(0, 0, width, height, pixels); @@ -499,7 +499,11 @@ public class PImage implements PConstants, Cloneable { */ public PImage get() { try { - return (PImage) clone(); + PImage clone = (PImage) clone(); + // don't want to pass this down to the others + // http://dev.processing.org/bugs/show_bug.cgi?id=1245 + clone.cacheMap = null; + return clone; } catch (CloneNotSupportedException e) { return null; } diff --git a/core/src/processing/core/PVector.java b/core/src/processing/core/PVector.java index 5f9be436e..78209bb60 100644 --- a/core/src/processing/core/PVector.java +++ b/core/src/processing/core/PVector.java @@ -529,9 +529,10 @@ public class PVector { * @return the angle between the vectors */ static public float angleBetween(PVector v1, PVector v2) { - float dot = v1.dot(v2); - float theta = (float) Math.acos(dot / (v1.mag() * v2.mag())); - return theta; + double dot = v1.x * v2.x + v1.y * v2.y + v1.z * v2.z; + double v1mag = Math.sqrt(v1.x * v1.x + v1.y * v1.y + v1.z * v1.z); + double v2mag = Math.sqrt(v2.x * v2.x + v2.y * v2.y + v2.z * v2.z); + return (float) Math.acos(dot / (v1mag * v2mag)); } diff --git a/core/src/processing/xml/XMLElement.java b/core/src/processing/xml/XMLElement.java index c306ff419..873828996 100644 --- a/core/src/processing/xml/XMLElement.java +++ b/core/src/processing/xml/XMLElement.java @@ -1335,6 +1335,11 @@ public class XMLElement implements Serializable { } + public String toString() { + return toString(true); + } + + public String toString(boolean pretty) { ByteArrayOutputStream baos = new ByteArrayOutputStream(); OutputStreamWriter osw = new OutputStreamWriter(baos); diff --git a/core/todo.txt b/core/todo.txt index 0f8461a04..988df2d09 100644 --- a/core/todo.txt +++ b/core/todo.txt @@ -1,24 +1,58 @@ -0165 core (1.0.3) -X update to itext 2.1.4 -X endRecord or endRaw produces RuntimeException with PDF library -X http://dev.processing.org/bugs/show_bug.cgi?id=1169 -X problem with beginRaw/endRaw and OpenGL -X http://dev.processing.org/bugs/show_bug.cgi?id=1171 -X set strokeWeight with begin/endRaw -X http://dev.processing.org/bugs/show_bug.cgi?id=1172 -X fix strokeWeight with P3D (better version of line hack) -X make P3D use proper weights -X ArrayIndexOutOfBoundsException with point() -X http://dev.processing.org/bugs/show_bug.cgi?id=1168 +0169 core +X remove major try/catch block from PApplet.main() +X hopefully will allow some exception stuff to come through properly +X PVector.angleDistance() returns NaN +X http://dev.processing.org/bugs/show_bug.cgi?id=1316 + +_ make the index lookup use numbers up to 256? + +_ decide whether to keep: +_ public float textWidth(char[] chars, int start, int length) + +_ textAlign(JUSTIFY) (with implementation) +_ http://dev.processing.org/bugs/show_bug.cgi?id=1309 + +_ create characters on the fly when createFont() is used + +_ Semitransparent rect drawn over image not rendered correctly +_ http://dev.processing.org/bugs/show_bug.cgi?id=1280 + +_ should map() actually constrain to the low and high values? + +_ file chooser fails with opengl on linux +_ http://dev.processing.org/bugs/show_bug.cgi?id=1221 + +_ resizing opengl destroys context and textures +_ http://dev.processing.org/bugs/show_bug.cgi?id=1176 +_ what's the difference with ascent on loadFont vs. createFont? +_ noCursor() doesn't work in present mode +_ http://dev.processing.org/bugs/show_bug.cgi?id=1177 +_ modelx/y/z broken when aiming a camera +_ http://dev.processing.org/bugs/show_bug.cgi?id=1074 +_ in P2D, two vertex() line calls with fill() causes duplicate output +_ works fine in other renderers, has to do with tesselation +_ http://dev.processing.org/bugs/show_bug.cgi?id=1191 +_ extra triangles being seen in P2D +_ http://dev.processing.org/bugs/show_bug.cgi?id=1192 +_ noloop ref even says that redraw will be called on resize, make sure it is +_ public PImage(java.awt.Image) sets format to RGB (but could be ARGB) +[ features ] + +_ add version of math functions that use doubles? +_ what other methods should work with doubles? all math functions? +_ seems like internal (mostly static) things, but not graphics api +_ look into replacing nanoxml +_ http://www.exampledepot.com/egs/javax.xml.parsers/pkg.html _ if no draw() method, and renderer is not displayable, then exit _ static mode PDFs shouldn't just hang -_ public PImage(java.awt.Image) sets format to RGB (but could be ARGB) [ known problems ] +_ memory leak problem with fonts in JAVA2D +_ http://dev.processing.org/bugs/show_bug.cgi?id=1252 _ OPENGL sketches flicker w/ Vista when background() not used inside draw() _ http://dev.processing.org/bugs/show_bug.cgi?id=930 _ Disabling Aero scheme sometimes prevents the problem