diff --git a/processing/app/PdeBase.java b/processing/app/PdeBase.java index 1af93fac1..aa6330c45 100644 --- a/processing/app/PdeBase.java +++ b/processing/app/PdeBase.java @@ -140,11 +140,11 @@ public class PdeBase /*extends JFrame implements ActionListener*/ // read in the keywords for the reference - final String KEYWORDS = "pde_keywords.properties"; + //final String KEYWORDS = "pde_keywords.properties"; keywords = new Properties(); try { - keywords.load(PdeBase.getStream(KEYWORDS)); + keywords.load(PdeBase.getStream("pde_keywords.properties")); } catch (Exception e) { String message = @@ -368,7 +368,7 @@ public class PdeBase /*extends JFrame implements ActionListener*/ // - static public InputStream getStream(String filename) throws IOException { + public InputStream getStream(String filename) throws IOException { if ((PdeBase.platform == PdeBase.MACOSX) || (PdeBase.platform == PdeBase.MACOS9)) { // macos doesn't seem to think that files in the lib folder diff --git a/processing/app/PdeEditor.java b/processing/app/PdeEditor.java index 2248c09fa..b0033a49f 100644 --- a/processing/app/PdeEditor.java +++ b/processing/app/PdeEditor.java @@ -145,7 +145,7 @@ public class PdeEditor extends JFrame try { //icon = Toolkit.getDefaultToolkit().getImage("lib/icon.gif"); - icon = PdeBase.getImage("icon.gif"); + icon = PdeBase.getImage("icon.gif", this); setIconImage(icon); } catch (Exception e) { } // fail silently, no big whup @@ -195,8 +195,9 @@ public class PdeEditor extends JFrame rightPanel.add(header, BorderLayout.NORTH); textarea = new JEditTextArea(); + textarea.setRightClickPopup(new TextAreaPopup(this)); textarea.setTokenMarker(new PdeTokenMarker()); - + // assemble console panel, consisting of status area and the console itself consolePanel = new JPanel(); //System.out.println(consolePanel.getInsets()); @@ -519,6 +520,19 @@ public class PdeEditor extends JFrame exportMenu = buildExportMenu(); menu.add(exportMenu); + menu.addSeparator(); + + item = newMenuItem("Page Setup", 'P', true); + item.setEnabled(false); + menu.add(item); + + item = newMenuItem("Print", 'P'); + item.setEnabled(false); + menu.add(item); + + menu.addSeparator(); + + // macosx already has its own preferences and quit menu if (PdeBase.platform != PdeBase.MACOSX) { item = new JMenuItem("Preferences"); item.addActionListener(new ActionListener() { @@ -886,7 +900,7 @@ public class PdeEditor extends JFrame public void handleAbout() { //System.out.println("the about box will now be shown"); - final Image image = getImage("about.jpg", this); + final Image image = PdeBase.getImage("about.jpg", this); int w = image.getWidth(this); int h = image.getHeight(this); final Window window = new Window(this) { @@ -938,10 +952,11 @@ public class PdeEditor extends JFrame */ public void handleQuit() { storePreferences(); - editor.storePreferences(); + //editor.storePreferences(); // this will save the prefs even if quit is cancelled, but who cares - PdePreferences.save(); + //PdePreferences.save(); + preferences.save(); // check to see if the person actually wants to quit //editor.doQuit(); @@ -956,7 +971,7 @@ public class PdeEditor extends JFrame textarea.setText(what); // TODO need to wipe out the undo state here - if (emptyUndo) PdeBase.undo.discardAllEdits(); + if (emptyUndo) undo.discardAllEdits(); textarea.select(0, 0); // move to the beginning of the document textarea.requestFocus(); // get the caret blinking @@ -1119,11 +1134,11 @@ public class PdeEditor extends JFrame for (int i = 0; i < 10; i++) System.out.println(); - if (PdeBase.getBoolen("editor.external")) { + if (PdeBase.getBoolean("editor.external")) { // history gets screwed by the open.. - String historySaved = historyLast; + String historySaved = history.lastRecorded; handleOpen(sketchName, sketchFile, sketchDir); - historyLast = historySaved; + history.lastRecorded = historySaved; } presenting = present; @@ -1136,7 +1151,8 @@ public class PdeEditor extends JFrame } String program = textarea.getText(); - makeHistory(program, RUN); + //makeHistory(program, RUN); + history.record(program, PdeHistory.RUN); //if (PdeBase.platform == PdeBase.MACOSX) { //String pkg = "Proce55ing.app/Contents/Resources/Java/"; @@ -1155,7 +1171,7 @@ public class PdeEditor extends JFrame //if (dataPath != null) { File dataDir = new File(dataPath); if (dataDir.exists()) { - PdeEditor.copyDir(dataDir, buildDir); + PdeBase.copyDir(dataDir, buildDir); } //} int numero1 = (int) (Math.random() * 10000); @@ -1341,7 +1357,7 @@ public class PdeEditor extends JFrame //} // toxi_030903: focus the PDE again after quitting presentation mode - base.toFront(); + toFront(); } @@ -1644,7 +1660,8 @@ public class PdeEditor extends JFrame return; // user cancelled } } - makeHistory(s, SAVE); + //makeHistory(s, SAVE); + history.record(s, PdeHistory.SAVE); File file = new File(directory, filename); try { @@ -1720,7 +1737,7 @@ public class PdeEditor extends JFrame copyFile(sketchFile, newSketchFile); // copy everything from the old dir to the new one - copyDir(sketchDir, newSketchDir); + PdeBase.copyDir(sketchDir, newSketchDir); // remove the old sketch file from the new dir new File(newSketchDir, sketchName + ".pde").delete(); @@ -1745,7 +1762,8 @@ public class PdeEditor extends JFrame } // get the changes into the sketchbook menu - base.rebuildSketchbookMenu(); + //base.rebuildSketchbookMenu(); + sketchbook.rebuildMenu(); // open the new guy handleOpen(newSketchName, newSketchFile, newSketchDir); @@ -1960,7 +1978,7 @@ public class PdeEditor extends JFrame if (!bagelClasses[i].endsWith(".class")) continue; entry = new ZipEntry(bagelClasses[i]); zos.putNextEntry(entry); - zos.write(grabFile(new File(exportDir + bagelClasses[i]))); + zos.write(PdeBase.grabFile(new File(exportDir + bagelClasses[i]))); zos.closeEntry(); } @@ -1975,7 +1993,7 @@ public class PdeEditor extends JFrame //} entry = new ZipEntry(datafiles[i]); zos.putNextEntry(entry); - zos.write(grabFile(new File(dataDir, datafiles[i]))); + zos.write(PdeBase.grabFile(new File(dataDir, datafiles[i]))); zos.closeEntry(); } } @@ -1989,7 +2007,7 @@ public class PdeEditor extends JFrame if (classfiles[i].endsWith(".class")) { entry = new ZipEntry(classfiles[i]); zos.putNextEntry(entry); - zos.write(grabFile(new File(appletDir, classfiles[i]))); + zos.write(PdeBase.grabFile(new File(appletDir, classfiles[i]))); zos.closeEntry(); } } @@ -2170,7 +2188,8 @@ public class PdeEditor extends JFrame public void doBeautify() { String prog = textarea.getText(); - makeHistory(prog, BEAUTIFY); + //makeHistory(prog, BEAUTIFY); + history.record(prog, PdeHistory.BEAUTIFY); char program[] = prog.toCharArray(); StringBuffer buffer = new StringBuffer(); @@ -2396,6 +2415,127 @@ public class PdeEditor extends JFrame removeDescendants(dirObject); } } + + + /** + * Returns the edit popup menu. + */ + class TextAreaPopup extends JPopupMenu { + //protected ReferenceKeys referenceItems = new ReferenceKeys(); + String currentDir = System.getProperty("user.dir"); + String referenceFile = null; + + JEditTextArea parent; + + JMenuItem cutItem, copyItem; + JMenuItem referenceItem; + + + public TextAreaPopup(JEditTextArea parent) { + this.parent = parent; + + JMenuItem item; + + cutItem = new JMenuItem("Cut"); + cutItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + parent.cut(); + } + }); + this.add(cutItem); + + copyItem = new JMenuItem("Copy"); + copyItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + parent.copy(); + } + }); + this.add(copyItem); + + item = new JMenuItem("Paste"); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + parent.paste(); + } + }); + this.add(item); + + //this.addSeparator(); + + item = new JMenuItem("Select All"); + item.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + parent.selectAll(); + } + }); + this.add(item); + + this.addSeparator(); + + referenceItem = new JMenuItem("Find in Reference"); + referenceItem.addActionListener(new ActionListener() { + public void actionPerformed(ActionEvent e) { + PdeBase.showReference(referenceFile); + } + }); + this.add(referenceItem); + } + + /* + // enables/disables "Reference Lookup" option + public void setReferenceLookup(String file) + { + if (file != null) { + this.getComponent(5).setEnabled(true); + referenceFile = file; + } + else { + this.getComponent(5).setEnabled(false); + } + } + */ + + /* + public void showReferenceFile() + { + PdeBase.openURL(currentDir + File.separator + + "reference" + File.separator + + referenceFile + ".html"); + } + */ + + // if no text is selected, disable copy and cut menu items + public void show(Component component, int x, int y) + { + if (parent.isSelectionActive()) { + cutItem.setEnabled(true); + copyItem.setEnabled(true); + + referenceFile = PdeBase.keywords.get(getSelectedText()); + if (referenceFile != null) { + referenceItem.setEnabled(true); + } + } else { + cutItem.setEnabled(false); + copyItem.setEnabled(false); + referenceItem.setEnabled(false); + } + super.show(component, x, y); + + /* + //popup.setEnabledCut(selectionIsActive); + //popup.setEnabledCopy(selectionIsActive); + + String file = null; + if (selectionIsActive) { + file = (String) PdeBase.keywords.get(getSelectedText()); + } + popup.setReferenceLookup(file); + + super.show(invoker, x, y); + */ + } + } } diff --git a/processing/app/PdeHistory.java b/processing/app/PdeHistory.java index cd59ceb97..3830ab95c 100644 --- a/processing/app/PdeHistory.java +++ b/processing/app/PdeHistory.java @@ -44,10 +44,17 @@ public class PdeHistory { static final String HISTORY_SEPARATOR = "#################################################"; + //boolean recordingHistory; + //JMenu historyMenu; + JMenu menu; + File historyFile; //OutputStream historyStream; //PrintWriter historyWriter; - String historyLast; + //String historyLast; + String lastRecorded; + + ActionListener menuListener; /* ActionListener historyMenuListener = @@ -61,25 +68,34 @@ public class PdeHistory { public PdeHistory(PdeEditor editor) { this.editor = editor; + + menuListener = new ActionListener() { + public void actionPerformed(ActionEvent e) { + retrieve(e.getActionCommand()); + } + }; } - public void attachMenu(JMenu menu) { - if (PdePreferences.getBoolean("history.recording")) { - historyMenu = new JMenu("History"); - menu.add(historyMenu); - } + public void attachMenu(JMenu parent) { + //if (PdePreferences.getBoolean("history.recording")) { + menu = new JMenu("History"); + parent.add(menu); + + // should leave enabled, since can still get old history + // even if the new stuff isn't being recorded + //menu.setEnabled(PdePreferences.getBoolean("history.recording")); + //} } - //boolean recordingHistory; - JMenu historyMenu; + /** + * Check to see if history should be recorded. + * mode is RUN, SAVE, AUTOSAVE, or BEAUTIFY + */ + public void record(String program, int mode) { + if (!PdePreferences.getBoolean("history.recording")) return; - - // mode is RUN, SAVE or AUTO - public void makeHistory(String program, int mode) { - if (!base.recordingHistory) return; - //if (historyLast.equals(program) && !externalEditor) return; if ((historyLast != null) && (historyLast.equals(program))) return; @@ -154,16 +170,16 @@ public class PdeHistory { historyLast = program; //JMenuItem menuItem = new JMenuItem(modeStr + " - " + readableDate); - MenuItem menuItem = new MenuItem(modeStr + " - " + readableDate); - menuItem.addActionListener(base.historyMenuListener); - base.historyMenu.insert(menuItem, 2); + JMenuItem menuItem = new JMenuItem(modeStr + " - " + readableDate); + menuItem.addActionListener(menuListener); + menu.insert(menuItem, 2); historyWriter.flush(); historyWriter.close(); if (noPreviousHistory) { // to get add the actual menu, to get the 'clear' item in there - base.rebuildHistoryMenu(historyFile.getPath()); + rebuildMenu(historyFile.getPath()); } } catch (IOException e) { @@ -172,13 +188,13 @@ public class PdeHistory { } - public void retrieveHistory(String selection) { + public void retrieve(String selection) { //System.out.println("sel '" + selection + "'"); String readableDate = selection.substring(selection.indexOf("-") + 2); // make history for the current guy - makeHistory(textarea.getText(), AUTOSAVE); + record(editor.textarea.getText(), AUTOSAVE); // mark editor text as having been edited try { @@ -192,7 +208,7 @@ public class PdeHistory { boolean found = false; while ((line = reader.readLine()) != null) { //System.out.println("->" + line); - if (line.equals(PdeEditor.HISTORY_SEPARATOR)) { + if (line.equals(HISTORY_SEPARATOR)) { line = reader.readLine(); if (line.indexOf(readableDate) != -1) { // this is the one found = true; @@ -206,16 +222,16 @@ public class PdeHistory { //String sep = System.getProperty("line.separator"); StringBuffer buffer = new StringBuffer(); while ((line = reader.readLine()) != null) { - if (line.equals(PdeEditor.HISTORY_SEPARATOR)) break; + if (line.equals(HISTORY_SEPARATOR)) break; //textarea.append(line + sep); //buffer.append(line + sep); // JTextPane wants only \n going in buffer.append(line + "\n"); //System.out.println("'" + line + "'"); } //textarea.editorSetText(buffer.toString()); - changeText(buffer.toString(), true); - historyLast = textarea.getText(); - setSketchModified(false); + editor.changeText(buffer.toString(), true); + historyLast = editor.textarea.getText(); + editor.setSketchModified(false); } else { System.err.println("couldn't find history entry for " + @@ -239,25 +255,28 @@ public class PdeHistory { */ - public void rebuildHistoryMenu(String path) { - rebuildHistoryMenu(historyMenu, path); - } + //public void rebuildHistoryMenu(String path) { + //rebuildHistoryMenu(historyMenu, path); + //} - public void rebuildHistoryMenu(Menu menu, String path) { - if (!recordingHistory) return; + + //public void rebuildHistoryMenu(Menu menu, String path) { + public void rebuildMenu(String path) { + //if (!recordingHistory) return; + //if (!PdePreferences.getBoolean("history.recording")) return; menu.removeAll(); File hfile = new File(path); if (!hfile.exists()) return; // no history yet - MenuItem item = new MenuItem("Clear History"); + JMenuItem item = new JMenuItem("Clear History"); item.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { - if (!editor.historyFile.delete()) { + if (!historyFile.delete()) { System.err.println("couldn't erase history"); } - rebuildHistoryMenu(historyMenu, editor.historyFile.getPath()); + rebuildMenu(historyFile.getPath()); } }); menu.add(item); @@ -276,7 +295,7 @@ public class PdeHistory { //while (true) { line = reader.readLine(); //if (line == null) continue; //System.out.println("line: " + line); - if (line.equals(PdeEditor.HISTORY_SEPARATOR)) { + if (line.equals(HISTORY_SEPARATOR)) { // next line is the good stuff line = reader.readLine(); int version = @@ -313,8 +332,8 @@ public class PdeHistory { */ for (int i = historyCount-1; i >= 0; --i) { - MenuItem mi = new MenuItem(historyList[i]); - mi.addActionListener(historyMenuListener); + JMenuItem mi = new JMenuItem(historyList[i]); + mi.addActionListener(menuListener); menu.add(mi); } diff --git a/processing/app/PdeRuntime.java b/processing/app/PdeRuntime.java index 38a243233..96da5b0bf 100644 --- a/processing/app/PdeRuntime.java +++ b/processing/app/PdeRuntime.java @@ -109,8 +109,8 @@ public class PdeRuntime implements PdeMessageConsumer { this.leechErr = leechErr; - Point parentLoc = editor.base.getLocation(); - Insets parentInsets = editor.base.getInsets(); + Point parentLoc = editor.getLocation(); + Insets parentInsets = editor.getInsets(); int x1 = parentLoc.x - 20; int y1 = parentLoc.y; @@ -146,7 +146,7 @@ public class PdeRuntime implements PdeMessageConsumer { applet.leechErr = leechErr; // has to be before init - applet.serialProperties(PdePreferences.properties); + //applet.serialProperties(PdePreferences.properties); applet.init(); if (applet.exception != null) { if (applet.exception instanceof PortInUseException) { @@ -257,8 +257,8 @@ public class PdeRuntime implements PdeMessageConsumer { Insets insets = window.getInsets(); //System.out.println(insets); - int minW = PdePreferences.getInteger("run.window.width.minimum", 120); - int minH = PdePreferences.getInteger("run.window.height.minimum", 120); + int minW = PdePreferences.getInteger("run.window.width.minimum"); + int minH = PdePreferences.getInteger("run.window.height.minimum"); int windowW = Math.max(applet.width, minW) + insets.left + insets.right; int windowH = Math.max(applet.height, minH) + insets.top + insets.bottom; diff --git a/processing/build/shared/lib/pde.properties b/processing/build/shared/lib/pde.properties index 23a452506..2da5f4a3f 100644 --- a/processing/build/shared/lib/pde.properties +++ b/processing/build/shared/lib/pde.properties @@ -129,7 +129,12 @@ editor.wheelmouse.multiplier = 3 run.present.bgcolor = #666666 # set internally -#run.window.bgcolor = +#run.window.bgcolor= + +# minimum size for the run window. windows can't go much smaller. +# macosx can, though it's sorta nice to have the border. +run.window.width.minimum = 120 +run.window.height.minimum = 120 # prompt for sketch location when 'new' is hit sketchbook.prompt = false