From e43794bfbdd3d81b66bb9501b4db7fa7f59c479b Mon Sep 17 00:00:00 2001 From: benfry Date: Thu, 8 Jan 2004 23:15:56 +0000 Subject: [PATCH] serious internal changes for sketchbook and syntax stuff --- app/PdeEditor.java | 45 +++++++------ app/PdeEditorHeader.java | 142 ++++++++++++++++++++++----------------- app/PdeSketch.java | 113 +++++++++++++++++++++++++++++++ build/shared/bugs.txt | 2 +- todo.txt | 70 +++++++++---------- 5 files changed, 255 insertions(+), 117 deletions(-) create mode 100644 app/PdeSketch.java diff --git a/app/PdeEditor.java b/app/PdeEditor.java index 3f3fcfca9..450fb0c1d 100644 --- a/app/PdeEditor.java +++ b/app/PdeEditor.java @@ -78,10 +78,11 @@ public class PdeEditor extends JFrame JEditTextArea textarea; // currently opened program - String sketchName; // name of the file (w/o pde if a sketch) - File sketchFile; // the .pde file itself - File sketchDir; // if a sketchbook project, the parent dir - boolean sketchModified; + //String sketchName; // name of the file (w/o pde if a sketch) + //File sketchFile; // the .pde file itself + //File sketchDir; // if a sketchbook project, the parent dir + //boolean sketchModified; + PdeSketch sketch; Point appletLocation; //= new Point(0, 0); Point presentLocation; // = new Point(0, 0); @@ -401,16 +402,19 @@ public class PdeEditor extends JFrame // last sketch that was in use - String sketchName = PdePreferences.get("last.sketch.name"); - String sketchDir = PdePreferences.get("last.sketch.path"); + //String sketchName = PdePreferences.get("last.sketch.name"); + String sketchPath = PdePreferences.get("last.sketch.path"); + //PdeSketch sketchTemp = new PdeSketch(sketchPath); - if (sketchName != null) { - if (new File(sketchDir + File.separator + sketchName + ".pde").exists()) { - skOpen(sketchDir, sketchName); + //if (sketchName != null) { + if ((sketchPath != null) && (new File(sketchPath)).exists()) { + skOpen(new PdeSketch(sketchFile)); + //if (new File(sketchDir + File.separator + sketchName + ".pde").exists()) { + //skOpen(sketchDir, sketchName); - } else { - skNew2(true); - } + //} else { + //skNew2(true); + //} } else { skNew2(true); } @@ -490,8 +494,9 @@ public class PdeEditor extends JFrame PdePreferences.setInteger("last.screen.height", screen.height); // last sketch that was in use - PdePreferences.set("last.sketch.name", sketchName); - PdePreferences.set("last.sketch.path", sketchDir.getAbsolutePath()); + //PdePreferences.set("last.sketch.name", sketchName); + //PdePreferences.set("last.sketch.name", sketch.name); + PdePreferences.set("last.sketch.path", sketch.getPath()); // location for the console/editor area divider int location = splitPane.getDividerLocation(); @@ -1175,7 +1180,9 @@ public class PdeEditor extends JFrame if (PdePreferences.getBoolean("editor.external")) { // history gets screwed by the open.. String historySaved = history.lastRecorded; - handleOpen(sketchName, sketchFile, sketchDir); + //handleOpen(sketchName, sketchFile, sketchDir); + //handleOpen(sketch.name, sketch.file, sketch.directory); + handleOpen(sketch); history.lastRecorded = historySaved; } @@ -1431,7 +1438,7 @@ public class PdeEditor extends JFrame openingName = name; if (sketchModified) { - String prompt = "Save changes to " + sketchName + "? "; + String prompt = "Save changes to " + sketch.name + "? "; if (checking == DO_QUIT) { @@ -1653,9 +1660,9 @@ public class PdeEditor extends JFrame changeText("", true); } - sketchName = isketchName; - sketchFile = isketchFile; - sketchDir = isketchDir; + sketch.name = isketchName; + sketch.file = isketchFile; + sketch.directory = isketchDir; setSketchModified(false); history.setPath(sketchFile.getParent(), readOnlySketch()); diff --git a/app/PdeEditorHeader.java b/app/PdeEditorHeader.java index bb5b68e40..b50e83edc 100644 --- a/app/PdeEditorHeader.java +++ b/app/PdeEditorHeader.java @@ -1,7 +1,7 @@ /* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ /* - PdeEditorHeader - panel that containing the sketch title + PdeEditorHeader - sketch tabs at the top of the screen Part of the Processing project - http://Proce55ing.net Except where noted, code is written by Ben Fry and @@ -29,25 +29,43 @@ import java.io.*; import javax.swing.*; -//public class PdeEditorHeader extends JPanel { public class PdeEditorHeader extends JComponent { - static final String SKETCH_TITLER = "sketch"; + //static final String SKETCH_TITLER = "sketch"; - static Color primaryColor; - static Color secondaryColor; - static Color backgroundColor; + //static Color primaryColor; + static Color textColor[] = new Color[2]; + //static Color unselectedColor; PdeEditor editor; + //PdeSketch sketch; - int sketchLeft; - int sketchRight; - int sketchTitleLeft; - boolean sketchModified; + //int sketchLeft; + //int sketchRight; + //int sketchTitleLeft; + //boolean sketchModified; Font font; FontMetrics metrics; int fontAscent; + // + + static final String STATUS[] = { "unsel", "sel" }; + static final int UNSELECTED = 0; + static final int SELECTED = 1; + + static final String WHERE[] = { "left", "mid", "right", "menu" }; + static final int LEFT = 0; + static final int MIDDLE = 1; + static final int RIGHT = 2; + static final int MENU = 3; + + static final int PIECE_WIDTH = 4; + + Image[][] pieces; + + // + Image offscreen; int sizeW, sizeH; int imageW, imageH; @@ -56,10 +74,24 @@ public class PdeEditorHeader extends JComponent { public PdeEditorHeader(PdeEditor eddie) { this.editor = eddie; // weird name for listener - if (primaryColor == null) { - backgroundColor = PdePreferences.getColor("header.bgcolor"); - primaryColor = PdePreferences.getColor("header.fgcolor.primary"); - secondaryColor = PdePreferences.getColor("header.fgcolor.secondary"); + pieces = new Image[2][3]; + for (int i = 0; i < 2; i++) { + for (int j = 0; j < 4; j++) { + pieces[i][j] = PdeBase.getImage("tab-" + STATUS[i] + "-" + + WHERE[j] + ".gif", this); + } + } + + if (backgroundColor == null) { + backgroundColor = + PdePreferences.getColor("header.bgcolor"); + textColor[SELECTED] = + PdePreferences.getColor("header.text.selected.color"); + textColor[UNSELECTED] = + PdePreferences.getColor("header.text.unselected.color"); + + //primaryColor = PdePreferences.getColor("header.fgcolor.primary"); + //secondaryColor = PdePreferences.getColor("header.fgcolor.secondary"); } addMouseListener(new MouseAdapter() { @@ -76,26 +108,15 @@ public class PdeEditorHeader extends JComponent { public void reset() { sketchLeft = 0; - //userLeft = 0; - //update(); repaint(); } - /* - public void update() { - paint(this.getGraphics()); - } - - public void update(Graphics g) { - paint(g); - } - */ - - public void paintComponent(Graphics screen) { if (screen == null) return; - if (editor.sketchName == null) return; + //if (editor.sketchName == null) return; + + PdeSketch sketch = editor.sketch; Dimension size = getSize(); if ((size.width != sizeW) || (size.height != sizeH)) { @@ -116,7 +137,6 @@ public class PdeEditorHeader extends JComponent { if (offscreen == null) { sizeW = size.width; sizeH = size.height; - //userLeft = 0; // reset imageW = sizeW; imageH = sizeH; offscreen = createImage(imageW, imageH); @@ -124,58 +144,60 @@ public class PdeEditorHeader extends JComponent { Graphics g = offscreen.getGraphics(); if (font == null) { - font = PdePreferences.getFont("header.font"); + font = PdePreferences.getFont("header.text.font"); g.setFont(font); metrics = g.getFontMetrics(); fontAscent = metrics.getAscent(); } - //if (sketchLeft == 0) { + int x = PdePreferences.GUI_SMALL; + for (int i = 0; i < sketch.fileCount; i++) { + String text = sketch.modified[i] ? + (" " + sketch.names[i] + " ") : + (" " + sketch.names[i] + " \u00A7"); + + int textWidth = metrics.stringWidth(text); + int pieceCount = 2 + (textWidth / PIECE_WIDTH); + int pieceWidth = pieceCount * PIECE_WIDTH; + + state = (i == sketch.current) ? SELECTED : UNSELECTED; + g.drawImage(pieces[state][LEFT], x, 0, null); + x += PIECE_WIDTH; + + int contentLeft = x; + for (int j = 0; j < pieceCount; j++) { + g.drawImage(pieces[state][MIDDLE], x, 0, null); + x += PIECE_WIDTH; + } + int textLeft = contentLeft + (pieceWidth - textWidth) / 2; + + g.setColor(textColor[STATUS]); + int baseline = (sizeH + fontAscent) / 2; + g.drawString(names[i], textLeft, baseline); + + g.drawImage(pieces[state][RIGHT], x, 0, null); + x += PIECE_WIDTH - 1; // overlap by 1 pixel + } + + /* sketchTitleLeft = PdePreferences.GUI_SMALL; sketchLeft = sketchTitleLeft + metrics.stringWidth(SKETCH_TITLER) + PdePreferences.GUI_SMALL; sketchRight = sketchLeft + metrics.stringWidth(editor.sketchName); int modifiedLeft = sketchRight + PdePreferences.GUI_SMALL; - //int modifiedLeft = sketchLeft + - //metrics.stringWidth(editor.sketchName) + PdePreferences.GUI_SMALL; - - //sketch = editor.sketchName; - //if (sketch == null) sketch = ""; - //} - - //if (userLeft == 0) { - //userLeft = sizeW - 20 - metrics.stringWidth(editor.userName); - //userTitleLeft = userLeft - PdePreferences.GUI_SMALL - - //metrics.stringWidth(USER_TITLER); - - //user = editor.userName; - //if (user == null) user = ""; - //} int baseline = (sizeH + fontAscent) / 2; g.setColor(backgroundColor); g.fillRect(0, 0, imageW, imageH); - //boolean boringUser = editor.userName.equals("default"); - g.setFont(font); // needs to be set each time g.setColor(secondaryColor); g.drawString(SKETCH_TITLER, sketchTitleLeft, baseline); - if (sketchModified) g.drawString("\u00A7", modifiedLeft, baseline); - //if (!boringUser) g.drawString(USER_TITLER, userTitleLeft, baseline); + if (sketch.getModified()) g.drawString("\u00A7", modifiedLeft, baseline); - g.setColor(primaryColor); - //g.drawString(sketch, sketchLeft, baseline); - //String additional = sketchModified ? " \u2020" : ""; - //String additional = sketchModified ? " \u00A4" : ""; - //String additional = sketchModified ? " \u2022" : ""; g.drawString(editor.sketchName, sketchLeft, baseline); - - //if (!boringUser) g.drawString(editor.userName, userLeft, baseline); - - //g.setColor(fgColor[mode]); - //g.drawString(message, PdePreferences.GUI_SMALL, (sizeH + fontAscent) / 2); + */ screen.drawImage(offscreen, 0, 0, null); } diff --git a/app/PdeSketch.java b/app/PdeSketch.java new file mode 100644 index 000000000..b41af9181 --- /dev/null +++ b/app/PdeSketch.java @@ -0,0 +1,113 @@ +/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */ + +/* + PdeSketch - stores information about files in the current sketch + Part of the Processing project - http://Proce55ing.net + + Except where noted, code is written by Ben Fry + Copyright (c) 2001-03 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. + + This program is distributed in the hope that it will be useful, + but WITHOUT ANY WARRANTY; without even the implied warranty of + MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + GNU General Public License for more details. + + You should have received a copy of the GNU General Public License + along with this program; if not, write to the Free Software Foundation, + Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA +*/ + +public class PdeSketch { + String name; + File directory; + + int current; + + int fileCount; + String names[]; + File files[]; + boolean modified[]; + + int hiddenCount; + String hiddenNames[]; + File hiddenFiles[]; + + + /** + * path is location of the main .pde file, because this is also + * simplest to use when opening the file from the finder/explorer. + */ + public PdeSketch(String path) { + File mainFile = new File(path); + System.out.println("main file is " + mainFile); + directory = new File(path.getParent()); + System.out.println("sketch dir is " + directory); + + rebuild(); + } + + + public void rebuild() { + // get list of files in the folder + String list[] = directory.list(); + + for (int i = 0; i < list.length; i++) { + if (list[i].endsWith(".pde")) fileCount++; + else if (list[i].endsWith(".java")) fileCount++; + else if (list[i].endsWith(".pde.x")) hiddenCount++; + else if (list[i].endsWith(".java.x")) hiddenCount++; + } + + names = new String[fileCount]; + files = new File[fileCount]; + modified = new boolean[fileCount]; + hiddenNames = new String[hiddenCount]; + hiddenFiles = new File[hiddenCount]; + + int fileCounter = 0; + int hiddenCounter = 0; + + for (int i = 0; i < list.length; i++) { + int sub = 0; + + if (list[i].endsWith(".pde")) { + names[fileCounter] = list[i].substring(0, list[i].length() - 4); + files[fileCounter] = new File(directory, list[i]); + fileCounter++; + + } else if (list[i].endsWith(".java")) { + names[fileCounter] = list[i].substring(0, list[i].length() - 5); + files[fileCounter] = new File(directory, list[i]); + fileCounter++; + + } else if (list[i].endsWith(".pde.x")) { + names[hiddenCounter] = list[i].substring(0, list[i].length() - 6); + files[hiddenCounter] = new File(directory, list[i]); + hiddenCounter++; + + } else if (list[i].endsWith(".java.x")) { + names[hiddenCounter] = list[i].substring(0, list[i].length() - 7); + files[hiddenCounter] = new File(directory, list[i]); + hiddenCounter++; + } + } + } + + + public boolean getModified() { + return modified[current]; + } + + + /** + * Returns path to the main .pde file for this sketch. + */ + public String getPath() { + return files[0].getAbsolutePath(); + } +} diff --git a/build/shared/bugs.txt b/build/shared/bugs.txt index 0d920cb66..e38029bcd 100644 --- a/build/shared/bugs.txt +++ b/build/shared/bugs.txt @@ -174,4 +174,4 @@ these are things that are out of our control - video sometimes likes to crash the application completely on windows. this seems to be due to problems with quicktime for java (since we shouldn't be able to write code that crashes using - java.. heh right). so this is probably outside of our control. \ No newline at end of file + java.. heh right). so this is probably outside of our control. diff --git a/todo.txt b/todo.txt index 4e9bab19e..f8356111c 100644 --- a/todo.txt +++ b/todo.txt @@ -27,12 +27,13 @@ X do this once unicode support has been added to the regular fonts X make a preference panel to set pde.properties stuff X new html code for eolas patent case X move html to external file in the lib folder - +X re-merge old code back in for textareadefaults? X re-enable line highlight X fix background color X get bracket highlighting to work X why won't loop() go bold? -> java 1.4 problem on the mac -_ test what it does on the pc +X test what it does on the pc +X seems to be a mac-specific problem (probably because of monaco) goodbye macos9 X posted to message board about it going away @@ -65,8 +66,10 @@ o try ariel's Thread.yield() suggestion o set default framerate of 24? 30? 2x that? +_ fix command keys for menus (broken since switching to swing) + _ option for having multiple files open -_ need ui for tabs from casey +X need ui for tabs from casey _ tabbed interface for multiple files _ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_Software;action=display;num=1052077800;start=0 _ "new text java/pde file" menu item @@ -150,25 +153,35 @@ void toGrayscale() { } -BUGS +BUGS / PDE _ find/replace hangs when recapitalizing things -_ doesn't work when outside a function: -_ color bg_color = color(255,0,0); +_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1072994196;start=0 _ if last line of code is a comment with no CR after it, _ an OutOfMemoryError ensues _ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1067717095 _ jikes errors have no newlines because it's a buffered reader _ and the newlines are removed when read +_ mouse wheel not working properly, need to dynamically load 1.4 code +_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1065826758;start=0 +_ preproc bug: text(String.valueOf(i+1), left + i*20, top); +_ unexpected token "String" + + +BUGS / Bagel +_ doesn't work when outside a function: +_ color bg_color = color(255,0,0); +_ rect is not getting it's stroke color set +_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1073582391;start=0 +_ alpha of zero still draws boogers on screen +_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1073329613;start=0 _ new sphere code from toxi _ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Syntax;action=display;num=1067005325 _ colorMode broken for red() green() etc _ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1068664455 _ z values not set properly on ellipses? _ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1068752615 -_ mouse wheel not working properly, need to dynamically load 1.4 code -_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1065826758;start=0 -_ preproc bug: text(String.valueOf(i+1), left + i*20, top); -_ unexpected token "String" +_ ellipses are just plain ugly +_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1073409011;start=0 BUGS / Windows @@ -182,7 +195,9 @@ _ doesn't seem interested in quitting properly (?) BUGS / Mac OS X -_ why are cmd keys for menus not working (on mac only?) +_ flickering several times on startup +_ also a strange box showing up in the corner +_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1073111031 NETWORK @@ -198,6 +213,7 @@ VIDEO _ selecting input source (wintv board and quickcam installed.. problem) _ including qtjava in path when in java mode (oops) _ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1069724180;start=0 +_ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1073523928;start=0 _ beginVideo not colored _ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1069342913;start=0 _ things will freeze if winvdig not installed @@ -231,34 +247,13 @@ _ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs CONSOLE -_ console -> should be using JEditTextArea not TextPane -_ set decent fonts (probably same as editor above), looks bad on mac +_ set max frame rate at 60 fps? avoid the full-on spew to the console _ console runs really really slow with a lot of println() calls _ http://proce55ing.net/discourse/yabb/YaBB.cgi?board=Proce55ing_software_bugs;action=display;num=1064182823 - - -................ - - -// Rect is not getting it's stroke color set - -void setup() { -size(400, 400); -//fill(255, 153); // This line fixes the issue -} - -void loop() { -//translate(0, 0, 0); //This line makes lines disappear -background(0); -strokeWeight(10.0); -stroke(0, 102, 153, 153); -line(0, 0, mouseX, mouseY); -line(width, height, width-mouseX, height-mouseX); -rect(mouseX, mouseY, 200, 200); -} - - -................ +_ console -> should be using JEditTextArea not TextPane +_ make new TextAreaDefaults class for the console +_ figure out how to color lines for errors and non (since not syntax) +_ set decent fonts (probably same as editor above), looks bad on mac @@ -501,6 +496,7 @@ BAGEL / Rendering b _ lists of names of objects, or the 'line number' buffer b _ but how to determine *where* on object the hit occurs + ca b _ lines ca b X rewrite line and stroke code, it's a buggy mess ca b X lines become 2 pixels thick after a 3D transform