diff --git a/app/PdeEditor.java b/app/PdeEditor.java index 92a2f4451..705239952 100644 --- a/app/PdeEditor.java +++ b/app/PdeEditor.java @@ -62,6 +62,7 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler int checkModifiedMode; String handleOpenPath; boolean handleNewShift; + boolean handleNewLibrary; //String handleSaveAsPath; //String openingName; @@ -90,9 +91,10 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler //String externalPaths; //File externalCode; + JMenuItem exportAppItem; JMenuItem saveMenuItem; JMenuItem saveAsMenuItem; - JMenuItem beautifyMenuItem; + //JMenuItem beautifyMenuItem; // @@ -148,6 +150,7 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler menubar.add(buildFileMenu()); menubar.add(buildEditMenu()); menubar.add(buildSketchMenu()); + menubar.add(buildToolsMenu()); // what platform has their help menu way on the right? //if ((PdeBase.platform == PdeBase.WINDOWS) || //menubar.add(Box.createHorizontalGlue()); @@ -400,7 +403,7 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler textarea.setEditable(!external); saveMenuItem.setEnabled(!external); saveAsMenuItem.setEnabled(!external); - beautifyMenuItem.setEnabled(!external); + //beautifyMenuItem.setEnabled(!external); TextAreaPainter painter = textarea.getPainter(); if (external) { @@ -462,13 +465,32 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler JMenuItem item; JMenu menu = new JMenu("File"); - item = newJMenuItem("New sketch", 'N'); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - handleNew(false); - } - }); - menu.add(item); + if (!PdePreferences.getBoolean("export.library")) { + item = newJMenuItem("New", 'N'); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + handleNew(false); + } + }); + menu.add(item); + + } else { + item = newJMenuItem("New Sketch", 'N'); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + handleNew(false); + } + }); + menu.add(item); + + item = new JMenuItem("New Library"); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + handleNewLibrary(); + } + }); + menu.add(item); + } /* item = newJMenuItem("New code", 'N', true); @@ -498,7 +520,7 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler }); menu.add(saveMenuItem); - saveAsMenuItem = newJMenuItem("Save as...", 'S', true); + saveAsMenuItem = newJMenuItem("Save As...", 'S', true); saveAsMenuItem.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { handleSaveAs(); @@ -514,6 +536,14 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler }); menu.add(item); + exportAppItem = newJMenuItem("Export Application", 'E', true); + exportAppItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + handleExportApp(); + } + }); + menu.add(exportAppItem); + menu.addSeparator(); item = newJMenuItem("Page Setup", 'P', true); @@ -591,19 +621,11 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler menu.add(sketchbook.getAddLibraryMenu()); - item = new JMenuItem("Create font..."); - item.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - new PdeFontBuilder().show(sketch.dataFolder); - } - }); - menu.add(item); - if ((PdeBase.platform == PdeBase.WINDOWS) || (PdeBase.platform == PdeBase.MACOSX)) { // no way to do an 'open in file browser' on other platforms // since there isn't any sort of standard - item = new JMenuItem("Show sketch folder"); + item = new JMenuItem("Show Sketch Folder"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { //PdeBase.openFolder(sketchDir); @@ -619,6 +641,30 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler } + protected JMenu buildToolsMenu() { + JMenuItem item; + JMenu menu = new JMenu("Tools"); + + item = new JMenuItem("Auto Format"); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + handleBeautify(); + } + }); + menu.add(item); + + item = new JMenuItem("Create Font..."); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + new PdeFontBuilder().show(sketch.dataFolder); + } + }); + menu.add(item); + + return menu; + } + + protected JMenu buildHelpMenu() { JMenu menu = new JMenu("Help"); JMenuItem item; @@ -736,14 +782,6 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler }); menu.add(item); - beautifyMenuItem = newJMenuItem("Beautify", 'B'); - beautifyMenuItem.addActionListener(new ActionListener() { - public void actionPerformed(ActionEvent e) { - handleBeautify(); - } - }); - menu.add(beautifyMenuItem); - menu.addSeparator(); item = newJMenuItem("Find...", 'F'); @@ -1176,6 +1214,20 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler public void handleNew(boolean shift) { doStop(); handleNewShift = shift; + handleNewLibrary = false; + checkModified(HANDLE_NEW); + } + + + /** + * User selected "New Library", this will act just like handleNew + * but internally set a flag that the new guy is a library, + * meaning that a "library" subfolder will be added. + */ + public void handleNewLibrary() { + doStop(); + handleNewShift = false; + handleNewLibrary = true; checkModified(HANDLE_NEW); } @@ -1187,7 +1239,8 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler */ protected void handleNew2(boolean startup) { try { - String pdePath = sketchbook.handleNew(startup, handleNewShift); + String pdePath = + sketchbook.handleNew(startup, handleNewShift, handleNewLibrary); if (pdePath != null) handleOpen2(pdePath); } catch (IOException e) { @@ -1298,6 +1351,8 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler } sketch = new PdeSketch(this, path); + exportAppItem.setEnabled(!sketch.isLibrary()); + buttons.disableRun(sketch.isLibrary()); header.rebuild(); if (PdePreferences.getBoolean("console.auto_clear")) { console.clear(); @@ -1362,9 +1417,28 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler * hitting export twice, quickly, and horking things up. */ synchronized public void handleExport() { - message("Exporting code..."); + String what = sketch.isLibrary() ? "Applet" : "Library"; + message("Exporting " + what + "..."); try { - if (sketch.export()) { + boolean success = sketch.isLibrary() ? + sketch.exportLibrary() : sketch.exportApplet(); + if (success) { + message("Done exporting."); + } else { + // error message will already be visible + } + } catch (Exception e) { + message("Error during export."); + e.printStackTrace(); + } + buttons.clear(); + } + + + synchronized public void handleExportApp() { + message("Exporting application..."); + try { + if (sketch.exportApplication()) { message("Done exporting."); } else { // error message will already be visible diff --git a/app/PdeEditorButtons.java b/app/PdeEditorButtons.java index 511abf1bf..ce956f009 100644 --- a/app/PdeEditorButtons.java +++ b/app/PdeEditorButtons.java @@ -4,7 +4,9 @@ PdeEditorButtons - run/stop/etc buttons for the ide Part of the Processing project - http://processing.org - Except where noted, code is written by Ben Fry and + Copyright (c) 2004 Ben Fry and the Processing project. + + The original rendition of this code was written by Ben Fry and Copyright (c) 2001-03 Massachusetts Institute of Technology This program is free software; you can redistribute it and/or modify @@ -54,6 +56,7 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener { static final int ACTIVE = 2; PdeEditor editor; + boolean disableRun; //Label status; Image offscreen; @@ -242,10 +245,12 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener { } int sel = findSelection(x, y); if (sel == -1) return; - + if (state[sel] != ACTIVE) { - setState(sel, ROLLOVER, true); - currentRollover = sel; + if (!(disableRun && ((sel == RUN) || (sel == STOP)))) { + setState(sel, ROLLOVER, true); + currentRollover = sel; + } } } @@ -318,7 +323,9 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener { if (sel == -1) return; currentRollover = -1; currentSelection = sel; - setState(sel, ACTIVE, true); + if (!(disableRun && ((sel == RUN) || (sel == STOP)))) { + setState(sel, ACTIVE, true); + } if (currentSelection == OPEN) { if (popup == null) { @@ -337,8 +344,19 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener { public void mouseReleased(MouseEvent e) { switch (currentSelection) { - case RUN: editor.handleRun(e.isShiftDown()); break; - case STOP: setState(RUN, INACTIVE, true); editor.handleStop(); break; + case RUN: + if (!disableRun) { + editor.handleRun(e.isShiftDown()); + } + break; + + case STOP: + if (!disableRun) { + setState(RUN, INACTIVE, true); + editor.handleStop(); + } + break; + case OPEN: setState(OPEN, INACTIVE, true); break; case NEW: editor.handleNew(e.isShiftDown()); break; case SAVE: editor.handleSave(); break; @@ -348,6 +366,11 @@ public class PdeEditorButtons extends JComponent implements MouseInputListener { } + public void disableRun(boolean what) { + disableRun = what; + } + + public void clear() { // (int button) { if (inactive == null) return; diff --git a/app/PdeSketch.java b/app/PdeSketch.java index b1a724696..ab93f6aa0 100644 --- a/app/PdeSketch.java +++ b/app/PdeSketch.java @@ -51,6 +51,8 @@ public class PdeSketch { // true if any of the files have been modified boolean modified; + boolean library; // true if it's a library + File folder; //sketchFolder; File dataFolder; File codeFolder; @@ -114,6 +116,11 @@ public class PdeSketch { codeFolder = new File(folder, "code"); dataFolder = new File(folder, "data"); + File libraryFolder = new File(folder, "library"); + if (libraryFolder.exists()) { + library = true; + } + load(); } @@ -497,6 +504,14 @@ public class PdeSketch { } + /** + * Return true if this sketch is a library. + */ + public boolean isLibrary() { + return library; + } + + /** * Sets the modified value for the code in the frontmost tab. */ @@ -1242,12 +1257,13 @@ public class PdeSketch { * + + * +-------------------------------------------------------+ */ - public boolean export() throws Exception { - return exportApplet(true); - } + //public boolean export() throws Exception { + //return exportApplet(true); + //} - public boolean exportApplet(boolean replaceHtml) throws Exception { + public boolean exportApplet(/*boolean replaceHtml*/) throws Exception { + boolean replaceHtml = true; //File appletDir, String exportSketchName, File dataDir) { //String program = textarea.getText(); @@ -1505,6 +1521,16 @@ public class PdeSketch { } + public boolean exportApplication() { + return true; + } + + + public boolean exportLibrary() { + return true; + } + + /** * Slurps up .class files from a colon (or semicolon on windows) * separated list of paths and adds them to a ZipOutputStream. diff --git a/app/PdeSketchbook.java b/app/PdeSketchbook.java index d20280189..e3f4c8325 100644 --- a/app/PdeSketchbook.java +++ b/app/PdeSketchbook.java @@ -108,7 +108,7 @@ public class PdeSketchbook { } menu = new JMenu("Sketchbook"); popup = new JMenu("Sketchbook"); - addlib = new JMenu("Add Library"); + addlib = new JMenu("Import Library"); } @@ -117,7 +117,8 @@ public class PdeSketchbook { * or null if the operation was cancelled. */ public String handleNew(boolean startup, - boolean shift) throws IOException { + boolean shift, + boolean library) throws IOException { File newbieDir = null; String newbieName = null; @@ -169,13 +170,18 @@ public class PdeSketchbook { // make the directory for the new sketch newbieDir.mkdirs(); + // if it's a library, make a library subfolder to tag it as such + if (library) { + new File(newbieDir, "library").mkdirs(); + } + // make an empty pde file File newbieFile = new File(newbieDir, newbieName + ".pde"); new FileOutputStream(newbieFile); // create the file // TODO this wouldn't be needed if i could figure out how to // associate document icons via a dot-extension/mime-type scenario - // help me steve jobs. you're my only hope + // help me steve jobs, you're my only hope. // jdk13 on osx, or jdk11 // though apparently still available for 1.4 diff --git a/todo.txt b/todo.txt index fc8d36827..7e722790c 100644 --- a/todo.txt +++ b/todo.txt @@ -40,17 +40,28 @@ X not able to write "preferences.txt" on the first run X examples should be in a submenu of open 040905 -_ "add library" menu item and submenu -_ looks for subfolder called 'libraries' inside p5 folder -_ libraries are determined by having a subfolder named 'library' +X "add library" menu item and submenu +X looks for subfolder called 'libraries' inside p5 folder +X libraries are determined by having a subfolder named 'library' +X String in apache classes and java.lang +X maybe ignore classes not inside the p5 libs dir? +o need to be able to select between which to include +o auto-resolve by saying java.* wins, others ask +X make built-in libraries read-only +040912 +X several menu changes as discussed with casey +X (capitalization, export/export app, tools) +X add preference for showing library stuff +_ figure out why user libraries not being added +_ show internal libraries as part of the 'open' menu (in lib mode) +_ after export of library, rebuild "import library" menu _ import all libraries into classpath _ all libs found during sketchbook build + all libs in libraries _ this means sketchbook menu will need to be rebuilt after lib build _ append the user's classpath to the end of that -_ add preference for showing library stuff -_ make built-in libraries read-only + _ libraries: static and non-static init for libs _ final stop() for static shutdown of lib _ but also potential stop() for individual items @@ -61,17 +72,15 @@ _ be able to link against, but not export, certain parts of lib _ jsyn.jar not needed on export, netscape libs not needed on export _ where do libraries for distribution go? _ libraries subfolder of p5 -_ String in apache classes and java.lang -_ maybe ignore classes not inside the p5 libs dir? -o need to be able to select between which to include -o auto-resolve by saying java.* wins, others ask _ get export working again -_ make multiple jar files thing work.. blech +_ make multiple jar files thing work as an option +_ http://processing.org/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1067360903;start=0 +_ applet default is one file, application default is multiple +_ user in advanced mode can switch to the other +_ buttons on side of sketch do default (last) behavior _ include a note that 'applet' folder will get emptied/rewritten _ 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.. @@ -83,9 +92,7 @@ _ errorMessage in PSerial/PClient/PServer are all using System.out _ support for editor plugins _ make dynamically loaded plugins and "tools" menu _ break out beautify as its own plugin -_ make "get quicktime libs" function -_ can java get the root directory for system/win32 etc? -_ make beautify plugin ("autoformat"?) +_ make beautify plugin "Auto Format" _ //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 @@ -96,6 +103,8 @@ _ 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 +o make "get quicktime libs" function +o can java get the root directory for system/win32 etc? _ implement new version of history _ make history folder, and a zip (not gz) file for each entry