From 1439bcebc24df8839f0643d1e71b058b81eedb7c Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 5 Sep 2004 20:28:23 +0000 Subject: [PATCH] working on "add library" functionality --- processing/app/PdeBase.java | 32 ++++++++ processing/app/PdeCompiler.java | 16 ++-- processing/app/PdeEditor.java | 4 + processing/app/PdePreferences.java | 40 ++++------ processing/app/PdeSketch.java | 14 +++- processing/app/PdeSketchbook.java | 120 ++++++++++++++++++++++++++--- processing/build/windows/make.sh | 9 ++- processing/core/todo.txt | 14 ++-- processing/todo.txt | 51 ++++++------ 9 files changed, 221 insertions(+), 79 deletions(-) diff --git a/processing/app/PdeBase.java b/processing/app/PdeBase.java index fad7a31a8..1b5e94583 100644 --- a/processing/app/PdeBase.java +++ b/processing/app/PdeBase.java @@ -123,6 +123,38 @@ public class PdeBase { } + // ................................................................. + + + static public File getProcessingHome() { + File home = new File(System.getProperty("user.home")); + + if (PdeBase.platform == PdeBase.MACOSX) { + // on macosx put the sketchbook in the "Documents" folder + return new File(home, "Documents" + File.separator + "Processing"); + + } else if (PdeBase.platform == PdeBase.WINDOWS) { + // on windows put the sketchbook in the "My Documents" folder + return new File(home, "My Documents" + File.separator + "Processing"); + } + + // for linux et al, make a dot folder + // if people don't like things being buried, they can move the sketches + // but the prefs will stay hidden in the dot folder + File phome = new File(home, ".processing"); + if (!phome.exists()) phome.mkdirs(); + return phome; + } + + + static public File getProcessingHome(String filename) { + return new File(getProcessingHome(), filename); + } + + + // ................................................................. + + /** * Given the reference filename from the keywords list, * builds a URL and passes it to openURL. diff --git a/processing/app/PdeCompiler.java b/processing/app/PdeCompiler.java index d223a3764..de7ff54c3 100644 --- a/processing/app/PdeCompiler.java +++ b/processing/app/PdeCompiler.java @@ -370,7 +370,7 @@ public class PdeCompiler implements PdeMessageConsumer { e.printStackTrace(); // this would be odd } //System.out.println("included path is " + abuffer.toString()); - makeImportsFromClassPath(abuffer.toString()); + packageListFromClassPath(abuffer.toString()); return abuffer.toString(); } @@ -383,7 +383,7 @@ public class PdeCompiler implements PdeMessageConsumer { * @param path the input classpath * @return array of possible package names */ - static public String[] makeImportsFromClassPath(String path) { + static public String[] packageListFromClassPath(String path) { Hashtable table = new Hashtable(); String pieces[] = PApplet.split(path, File.pathSeparatorChar); @@ -394,12 +394,12 @@ public class PdeCompiler implements PdeMessageConsumer { if (pieces[i].toLowerCase().endsWith(".jar") || pieces[i].toLowerCase().endsWith(".zip")) { - makeImportsFromZip(pieces[i], table); + packageListFromZip(pieces[i], table); } else { // it's another type of file or directory File dir = new File(pieces[i]); if (dir.exists() && dir.isDirectory()) { - makeImportsFromFolder(dir, null, table); + packageListFromFolder(dir, null, table); //importCount = magicImportsRecursive(dir, null, // table); //imports, importCount); @@ -418,7 +418,7 @@ public class PdeCompiler implements PdeMessageConsumer { } - static public void makeImportsFromZip(String filename, Hashtable table) { + static private void packageListFromZip(String filename, Hashtable table) { try { ZipFile file = new ZipFile(filename); Enumeration entries = file.entries(); @@ -452,8 +452,8 @@ public class PdeCompiler implements PdeMessageConsumer { * of folders to the package list. If another folder is found, * walk down into that folder and continue. */ - static public void makeImportsFromFolder(File dir, String sofar, - Hashtable table) { + static private void packageListFromFolder(File dir, String sofar, + Hashtable table) { //String imports[], //int importCount) { //System.err.println("checking dir '" + dir + "'"); @@ -467,7 +467,7 @@ public class PdeCompiler implements PdeMessageConsumer { if (sub.isDirectory()) { String nowfar = (sofar == null) ? files[i] : (sofar + "." + files[i]); - makeImportsFromFolder(sub, nowfar, table); + packageListFromFolder(sub, nowfar, table); //System.out.println(nowfar); //imports[importCount++] = nowfar; //importCount = magicImportsRecursive(sub, nowfar, diff --git a/processing/app/PdeEditor.java b/processing/app/PdeEditor.java index b38655162..e33f5f2eb 100644 --- a/processing/app/PdeEditor.java +++ b/processing/app/PdeEditor.java @@ -579,6 +579,10 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler }); menu.addSeparator(); + // + + menu.add(sketchbook.getAddLibraryMenu()); + item = new JMenuItem("Import..."); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { diff --git a/processing/app/PdePreferences.java b/processing/app/PdePreferences.java index 4a503422e..0cd070335 100644 --- a/processing/app/PdePreferences.java +++ b/processing/app/PdePreferences.java @@ -146,12 +146,11 @@ public class PdePreferences extends JComponent { //File home = new File(System.getProperty("user.home")); //File processingHome = new File(home, "Processing"); //preferencesFile = new File(home, PREFS_FILE); - preferencesFile = new File(getProcessingHome(), PREFS_FILE); + preferencesFile = PdeBase.getProcessingHome(PREFS_FILE); if (!preferencesFile.exists()) { // create a new preferences file if none exists // saves the defaults out to the file - getProcessingHome().mkdirs(); save(); } else { @@ -260,7 +259,7 @@ public class PdePreferences extends JComponent { // [ ] Enable export to "Library" - exportLibraryBox = new JCheckBox("Enable export to \"Library\""); + exportLibraryBox = new JCheckBox("Enable advanced \"Library\" features"); pain.add(exportLibraryBox); d = exportLibraryBox.getPreferredSize(); exportLibraryBox.setBounds(left, top, d.width, d.height); @@ -295,13 +294,15 @@ public class PdePreferences extends JComponent { textarea.setFont(new Font("Dialog", Font.PLAIN, 12)); pain.add(textarea); */ - label = new JLabel("More preferences can be edited directly"); + label = new JLabel("More preferences can be edited directly in the file"); + label.setForeground(Color.GRAY); pain.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); top += d.height; // + GUI_SMALL; - label = new JLabel("in the file " + preferencesFile.getAbsolutePath()); + label = new JLabel(preferencesFile.getAbsolutePath()); + label.setForeground(Color.GRAY); pain.add(label); d = label.getPreferredSize(); label.setBounds(left, top, d.width, d.height); @@ -350,6 +351,15 @@ public class PdePreferences extends JComponent { high = top + GUI_BIG; setSize(wide, high); + + // closing the window is same as hitting cancel button + + frame.addWindowListener(new WindowAdapter() { + public void windowClosing(WindowEvent e) { + disposeFrame(); + } + }); + Container content = frame.getContentPane(); content.setLayout(new BorderLayout()); content.add(this, BorderLayout.CENTER); @@ -515,26 +525,6 @@ public class PdePreferences extends JComponent { // ................................................................. - static public File getProcessingHome() { - File home = new File(System.getProperty("user.home")); - - if (PdeBase.platform == PdeBase.MACOSX) { - // on macosx put the sketchbook in the "Documents" folder - return new File(home, "Documents" + File.separator + "Processing"); - - } else if (PdeBase.platform == PdeBase.WINDOWS) { - // on windows put the sketchbook in the "My Documents" folder - return new File(home, "My Documents" + File.separator + "Processing"); - } - - // all others, just say home directory - return new File(home, "processing"); - } - - - // ................................................................. - - // all the information from preferences.txt //static public String get(String attribute) { diff --git a/processing/app/PdeSketch.java b/processing/app/PdeSketch.java index 595d2d49b..d81db3c2c 100644 --- a/processing/app/PdeSketch.java +++ b/processing/app/PdeSketch.java @@ -727,6 +727,18 @@ public class PdeSketch { } + public void addLibrary(String jarPath) { + String list[] = PdeCompiler.packageListFromClassPath(jarPath); + + // if the current code is a .java file, insert into current + // else import statements into the main sketch file (code[0]) + + for (int i = 0; i < list.length; i++) { + System.out.println(list[i]); + } + } + + /** * Change what file is currently being edited. * 1. store the String for the text of the current file. @@ -959,7 +971,7 @@ public class PdeSketch { externalRuntime = true; classPath += File.pathSeparator + PdeCompiler.contentsToClassPath(codeFolder); - importPackageList = PdeCompiler.makeImportsFromClassPath(classPath); + importPackageList = PdeCompiler.packageListFromClassPath(classPath); //libraryPath = codeFolder.getCanonicalPath(); libraryPath = codeFolder.getAbsolutePath(); } else { diff --git a/processing/app/PdeSketchbook.java b/processing/app/PdeSketchbook.java index 829512195..d20280189 100644 --- a/processing/app/PdeSketchbook.java +++ b/processing/app/PdeSketchbook.java @@ -43,6 +43,7 @@ public class PdeSketchbook { JMenu menu; JMenu popup; + JMenu addlib; // set to true after the first time it's built. // so that the errors while building don't show up again. @@ -60,6 +61,9 @@ public class PdeSketchbook { static File examplesFolder; static String examplesPath; // canonical path (for comparison) + static File librariesFolder; + static String librariesPath; + public PdeSketchbook(PdeEditor editor) { this.editor = editor; @@ -69,6 +73,9 @@ public class PdeSketchbook { examplesFolder = new File(System.getProperty("user.dir"), "examples"); examplesPath = examplesFolder.getAbsolutePath(); + librariesFolder = new File(System.getProperty("user.dir"), "libraries"); + librariesPath = librariesFolder.getAbsolutePath(); + //String sketchbookPath = PdePreferences.get("sketchbook.path"); //if (sketchbookPath == null) { if (PdePreferences.get("sketchbook.path") == null) { @@ -87,12 +94,13 @@ public class PdeSketchbook { home = new File(home, "My Documents"); } */ - File home = PdePreferences.getProcessingHome(); - String folderName = PdePreferences.get("sketchbook.name.default"); - //System.out.println("home = " + home); - //System.out.println("fname = " + folderName); - File sketchbookFolder = new File(home, folderName); + // use a subfolder called 'sketchbook' + //File home = PdePreferences.getProcessingHome(); + //String folderName = PdePreferences.get("sketchbook.name.default"); + //File sketchbookFolder = new File(home, folderName); + + File sketchbookFolder = PdeBase.getProcessingHome(); PdePreferences.set("sketchbook.path", sketchbookFolder.getAbsolutePath()); @@ -100,6 +108,7 @@ public class PdeSketchbook { } menu = new JMenu("Sketchbook"); popup = new JMenu("Sketchbook"); + addlib = new JMenu("Add Library"); } @@ -276,11 +285,15 @@ public class PdeSketchbook { public JPopupMenu getPopupMenu() { - //return menu.getPopupMenu(); return popup.getPopupMenu(); } + public JMenu getAddLibraryMenu() { + return addlib; + } + + /** * Rebuild the menu full of sketches based on the * contents of the sketchbook. @@ -290,10 +303,10 @@ public class PdeSketchbook { * the menu will disappear from its original location. */ public JMenu rebuildMenu() { - menu.removeAll(); - popup.removeAll(); - try { + // rebuild the popup menu + popup.removeAll(); + JMenuItem item = new JMenuItem("Open..."); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { @@ -303,7 +316,6 @@ public class PdeSketchbook { popup.add(item); popup.addSeparator(); - // identical to below boolean sketches = addSketches(popup, new File(PdePreferences.get("sketchbook.path"))); if (sketches) popup.addSeparator(); @@ -314,7 +326,10 @@ public class PdeSketchbook { // disable error messages while loading builtOnce = true; - // (mostly) identical to above + + // rebuild the open menu + menu.removeAll(); + if (sketches) { addSketches(menu, new File(PdePreferences.get("sketchbook.path"))); menu.addSeparator(); @@ -323,6 +338,14 @@ public class PdeSketchbook { addSketches(examples, examplesFolder); menu.add(examples); + + // rebuild the "add library" menu + addlib.removeAll(); + boolean libs = + addLibraries(addlib, new File(PdePreferences.get("sketchbook.path"))); + if (libs) menu.addSeparator(); + addLibraries(addlib, librariesFolder); + } catch (IOException e) { PdeBase.showWarning("Problem while building sketchbook menu", "There was a problem with building the\n" + @@ -411,6 +434,81 @@ public class PdeSketchbook { } + protected boolean addLibraries(JMenu menu, File folder) throws IOException { + // skip .DS_Store files, etc + if (!folder.isDirectory()) return false; + + String list[] = folder.list(); + // if a bad folder or something like that, this might come back null + if (list == null) return false; + + // alphabetize list, since it's not always alpha order + // use cheapie bubble-style sort which should be fine + // since not a tone of files, and things will mostly be sorted + // or may be completely sorted already by the os + for (int i = 0; i < list.length; i++) { + int who = i; + for (int j = i+1; j < list.length; j++) { + if (list[j].compareTo(list[who]) < 0) { + who = j; // this guy is earlier in the alphabet + } + } + if (who != i) { // swap with someone if changes made + String temp = list[who]; + list[who] = list[i]; + list[i] = temp; + } + } + + ActionListener listener = new ActionListener() { + public void actionPerformed(ActionEvent e) { + editor.sketch.addLibrary(e.getActionCommand()); + } + }; + + boolean ifound = false; + + for (int i = 0; i < list.length; i++) { + if ((list[i].charAt(0) == '.') || + list[i].equals("CVS")) continue; + + File subfolder = new File(folder, list[i]); + File exported = new File(subfolder, "library"); + File entry = new File(exported, list[i] + ".jar"); + // if a .jar file of the same prefix as the folder exists + // inside the 'library' subfolder of the sketch + if (entry.exists()) { + String sanityCheck = sanitizedName(list[i]); + if (!sanityCheck.equals(list[i])) { + String mess = + "The library \"" + list[i] + "\" 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)"; + PdeBase.showMessage("Ignoring bad sketch name", mess); + continue; + } + + JMenuItem item = new JMenuItem(list[i]); + item.addActionListener(listener); + item.setActionCommand(entry.getAbsolutePath()); + menu.add(item); + ifound = true; + + } else { // might contain other dirs, get recursive + JMenu submenu = new JMenu(list[i]); + // needs to be separate var + // otherwise would set ifound to false + boolean found = addLibraries(submenu, subfolder); //, false); + if (found) { + menu.add(submenu); + ifound = true; + } + } + } + return ifound; + } + + /** * Clear out projects that are empty. */ diff --git a/processing/build/windows/make.sh b/processing/build/windows/make.sh index 7bd17ddf5..d65c1a89c 100755 --- a/processing/build/windows/make.sh +++ b/processing/build/windows/make.sh @@ -210,7 +210,8 @@ cd ../../lib/serial ../../build/windows/work/jikes +D -classpath "RXTXcomm.jar;$CLASSPATH" -d . *.java zip -r0q serial.jar processing rm -rf processing -#cp serial.jar "C:\\Documents and Settings\\fry\\My Documents\\Processing\\sketchbook\\rxtx_work\\code" +mkdir -p ../../build/windows/work/libraries/serial/library/ +cp serial.jar ../../build/windows/work/libraries/serial/library/ # NET LIBRARY @@ -218,6 +219,8 @@ cd ../../lib/net ../../build/windows/work/jikes +D -d . *.java zip -r0q net.jar processing rm -rf processing +mkdir -p ../../build/windows/work/libraries/net/library/ +cp net.jar ../../build/windows/work/libraries/net/library/ # VIDEO LIBRARY @@ -235,5 +238,5 @@ cd ../../lib/video ../../build/windows/work/jikes +D -classpath "$QTJAVA;$CLASSPATH" -d . *.java zip -r0q video.jar processing rm -rf processing -#cp video.jar "C:\\Documents and Settings\\fry\\My Documents\\Processing\\sketchbook\\new_camera_action\\code" -#cp video.jar "C:\\Documents and Settings\\fry\\My Documents\\Processing\\sketchbook\\movie_action\\code" +mkdir -p ../../build/windows/work/libraries/video/library/ +cp video.jar ../../build/windows/work/libraries/video/library/ diff --git a/processing/core/todo.txt b/processing/core/todo.txt index 9d249963d..1a99bed73 100644 --- a/processing/core/todo.txt +++ b/processing/core/todo.txt @@ -151,6 +151,13 @@ X processing.net -> PClient, PServer X write client/server implementations for new-style api X basic test with old net server has things working fine +_ massive graphics engine changes +_ explicitly state depth()/nodepth() +_ move to new graphics engine +_ test with rgb cube, shut off smoothing +_ make sure line artifacts are because of smoothing +_ implement 2x oversampling for anti-aliasing + _ api for file-based renderers _ need to work this out since it will affect other api changes _ size(0, 0) and then ai.size(10000, 20000) @@ -167,13 +174,6 @@ _ better lighting model to show darkness at various depths _ maybe just ultra-high res bitmaps from gl _ version of BApplet that replaces g. with ai. or pdf. -_ massive graphics engine changes -_ explicitly state depth()/nodepth() -_ move to new graphics engine -_ test with rgb cube, shut off smoothing -_ make sure line artifacts are because of smoothing -_ implement 2x oversampling for anti-aliasing - ............................................................ diff --git a/processing/todo.txt b/processing/todo.txt index 9f957cf7a..261ae7fce 100644 --- a/processing/todo.txt +++ b/processing/todo.txt @@ -39,15 +39,13 @@ X not able to write "preferences.txt" on the first run 040903 X examples should be in a submenu of open -_ System.out isn't being heard from P* classes -_ errors inside those classes also causing weirdness -_ this might be a broader running as external app problem -_ errorMessage in PSerial/PClient/PServer are all using System.out +040905 +_ "add library" menu item and submenu +_ looks for subfolder called 'libraries' inside p5 folder +_ libraries are determined by having a subfolder named 'library' _ add preference for showing library stuff _ make built-in libraries read-only -_ "add library" menu item and submenu -_ looks for subfolder called 'library' inside sketches _ libraries: static and non-static init for libs _ final stop() for static shutdown of lib _ but also potential stop() for individual items @@ -70,27 +68,29 @@ _ or rename the old applet folder to something else? (nah, too messy) _ don't force everything into a single .jar on export _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1067360903;start=0 +_ package processing.app for PdeBase, PdeEditor.. + +_ System.out isn't being heard from P* classes +_ errors inside those classes also causing weirdness +_ this might be a broader running as external app problem +_ errorMessage in PSerial/PClient/PServer are all using System.out + _ support for editor plugins -_ make beautify plugin ("autoformat"?) _ make dynamically loaded plugins and "tools" menu _ break out beautify as its own plugin - - 1 _ beautify - 1 _ //for (int i = 0; i < 10; i++) { - 1 _ } catch (IOException e) { } - 1 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1086555381 - 1 _ need to ignore comments.. but not those inside quotes.. oog - 1 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1067309918;start=0 - 1 _ ignores colons for case statements - 1 _ need to tie this to the parser instead - 1 _ do a better job of maintaining cursor during beautify - 1 _ only beautify a particular section of code - 1 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1087227217 - -_ make "get quicktime libs" function -_ can java get the root directory for system/win32 etc? - -_ processing.app -> PdeBase, PdeEditor.. +_ make "get quicktime libs" function +_ can java get the root directory for system/win32 etc? +_ make beautify plugin ("autoformat"?) +_ //for (int i = 0; i < 10; i++) { +_ } catch (IOException e) { } +_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1086555381 +_ need to ignore comments.. but not those inside quotes.. oog +_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1067309918;start=0 +_ ignores colons for case statements +_ need to tie this to the parser instead +_ do a better job of maintaining cursor during beautify +_ only beautify a particular section of code +_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1087227217 _ implement new version of history _ make history folder, and a zip (not gz) file for each entry @@ -111,8 +111,11 @@ _ or handle this some more intelligent way, super.stop() is needed. _ http://processing.org/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1083574943 _ http://processing.org/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1067383998 +_ redo preferences panel to use proper swing layout etc + README +_ make the whole thing an html file? _ cut out some of the chatter _ processing won't start.. _ people with non-ascii chars in the folder name