From 48560cb0cc2746dea08df5fb9c3ec21d4665ae94 Mon Sep 17 00:00:00 2001 From: benfry Date: Sun, 20 Jun 2004 17:13:53 +0000 Subject: [PATCH] working on tabs.. now actually working/displaying semi-properly --- app/PdeBase.java | 2 +- app/PdeCode.java | 6 +++++ app/PdeEditor.java | 2 ++ app/PdeEditorHeader.java | 56 +++++++++++++++++++++++++++++----------- app/PdePreferences.java | 1 + app/PdeSketch.java | 8 +++++- 6 files changed, 58 insertions(+), 17 deletions(-) diff --git a/app/PdeBase.java b/app/PdeBase.java index 5d258ee4f..b59e0d789 100644 --- a/app/PdeBase.java +++ b/app/PdeBase.java @@ -45,7 +45,7 @@ import com.apple.mrj.*; * files and images, etc) that comes from that. */ public class PdeBase { - static final String VERSION = "0068 Alpha"; + static final String VERSION = "007X Alpha"; PdeEditor editor; diff --git a/app/PdeCode.java b/app/PdeCode.java index 0a214ce3b..3c6e0ec3a 100644 --- a/app/PdeCode.java +++ b/app/PdeCode.java @@ -41,6 +41,12 @@ public class PdeCode { this.name = name; this.file = file; this.flavor = flavor; + + try { + load(); + } catch (IOException e) { + System.err.println("error while loading code " + name); + } } diff --git a/app/PdeEditor.java b/app/PdeEditor.java index 31318b06e..83af6ca6b 100644 --- a/app/PdeEditor.java +++ b/app/PdeEditor.java @@ -685,6 +685,7 @@ public class PdeEditor extends JFrame handleAbout(); } }); + menu.add(item); } return menu; @@ -1237,6 +1238,7 @@ public class PdeEditor extends JFrame protected void handleOpen2(String path) { try { sketch = new PdeSketch(this, path); + header.rebuild(); } catch (Exception e) { error(e); } diff --git a/app/PdeEditorHeader.java b/app/PdeEditorHeader.java index bb408848d..42951b28b 100644 --- a/app/PdeEditorHeader.java +++ b/app/PdeEditorHeader.java @@ -2,10 +2,10 @@ /* PdeEditorHeader - sketch tabs at the top of the screen - Part of the Processing project - http://Proce55ing.net + Part of the Processing project - http://processing.org Except where noted, code is written by Ben Fry and - Copyright (c) 2001-03 Massachusetts Institute of Technology + 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 @@ -53,7 +53,7 @@ public class PdeEditorHeader extends JComponent /*implements MouseListener*/ { FontMetrics metrics; int fontAscent; - PdeSketch sketch; + //PdeSketch sketch; // @@ -92,8 +92,8 @@ public class PdeEditorHeader extends JComponent /*implements MouseListener*/ { this.editor = eddie; // weird name for listener pieces = new Image[STATUS.length][WHERE.length]; - for (int i = 0; i < 2; i++) { - for (int j = 0; j < 4; j++) { + for (int i = 0; i < STATUS.length; i++) { + for (int j = 0; j < WHERE.length; j++) { pieces[i][j] = PdeBase.getImage("tab-" + STATUS[i] + "-" + WHERE[j] + ".gif", this); } @@ -135,10 +135,11 @@ public class PdeEditorHeader extends JComponent /*implements MouseListener*/ { popup.show(PdeEditorHeader.this, x, y); } else { - for (int i = 0; i < sketch.codeCount; i++) { + //for (int i = 0; i < sketch.codeCount; i++) { + for (int i = 0; i < editor.sketch.codeCount; i++) { if ((x > tabLeft[i]) && (x < tabRight[i])) { //setCurrent(i); - sketch.setCurrent(i); + editor.sketch.setCurrent(i); repaint(); } } @@ -160,7 +161,8 @@ public class PdeEditorHeader extends JComponent /*implements MouseListener*/ { if (screen == null) return; //if (editor.sketchName == null) return; - //PdeSketch sketch = editor.sketch; + PdeSketch sketch = editor.sketch; + if (sketch == null) return; // ?? Dimension size = getSize(); if ((size.width != sizeW) || (size.height != sizeH)) { @@ -194,6 +196,12 @@ public class PdeEditorHeader extends JComponent /*implements MouseListener*/ { fontAscent = metrics.getAscent(); } + // set the background for the offscreen + g.setColor(backgroundColor); + //System.out.println("bg = " + backgroundColor); + //g.setColor(Color.red); + g.fillRect(0, 0, imageW, imageH); + if ((tabLeft == null) || (tabLeft.length < sketch.codeCount)) { tabLeft = new int[sketch.codeCount]; @@ -206,6 +214,7 @@ public class PdeEditorHeader extends JComponent /*implements MouseListener*/ { // if modified, add the li'l glyph next to the name String text = " " + code.name + (code.modified ? " \u00A7" : " "); + //System.out.println("code " + i + " " + text); int textWidth = metrics.stringWidth(text); int pieceCount = 2 + (textWidth / PIECE_WIDTH); @@ -263,6 +272,16 @@ public class PdeEditorHeader extends JComponent /*implements MouseListener*/ { } + /** + * Called when a new sketch is opened. + */ + public void rebuild() { + System.out.println("rebuilding editor header"); + rebuildMenu(); + repaint(); + } + + /* New [code,tab,source] file... Cmd-shift-N Rename @@ -330,17 +349,24 @@ public class PdeEditorHeader extends JComponent /*implements MouseListener*/ { JMenu unhide = new JMenu("Unhide"); ActionListener unhideListener = new ActionListener() { public void actionPerformed(ActionEvent e) { - sketch.unhide((String) (e.getActionCommand())); + editor.sketch.unhide((String) (e.getActionCommand())); rebuildMenu(); } }; - for (int i = 0; i < sketch.hiddenCount; i++) { - item = new JMenuItem(sketch.hidden[i].name); - //item.setActionCommand(hiddenFiles[i]); - item.setActionCommand(sketch.hidden[i].name); - item.addActionListener(unhideListener); - unhide.add(item); + PdeSketch sketch = editor.sketch; + if (sketch != null) { + for (int i = 0; i < sketch.hiddenCount; i++) { + item = new JMenuItem(sketch.hidden[i].name); + //item.setActionCommand(hiddenFiles[i]); + item.setActionCommand(sketch.hidden[i].name); + item.addActionListener(unhideListener); + unhide.add(item); + } } + if (unhide.getItemCount() == 0) { + unhide.setEnabled(false); + } + menu.add(unhide); menu.addSeparator(); diff --git a/app/PdePreferences.java b/app/PdePreferences.java index a238e9b66..d85628a57 100644 --- a/app/PdePreferences.java +++ b/app/PdePreferences.java @@ -578,6 +578,7 @@ public class PdePreferences extends JComponent { static public Color getColor(String name /*, Color otherwise*/) { Color parsed = null; String s = get(name); //, null); + //System.out.println(name + " = " + s); if ((s != null) && (s.indexOf("#") == 0)) { try { int v = Integer.parseInt(s.substring(1), 16); diff --git a/app/PdeSketch.java b/app/PdeSketch.java index 7d98edb67..b1e22ba9c 100644 --- a/app/PdeSketch.java +++ b/app/PdeSketch.java @@ -168,6 +168,7 @@ public class PdeSketch { JAVA); } } + //System.out.println("code count 2 is " + codeCount); // remove any entries that didn't load properly int index = 0; @@ -183,12 +184,14 @@ public class PdeSketch { index++; } } + //System.out.println("code count 3 is " + codeCount); // move the main class to the first tab // start at 1, if it's at zero, don't bother + //System.out.println("looking for " + mainFilename); for (int i = 1; i < codeCount; i++) { if (code[i].file.getName().equals(mainFilename)) { - System.out.println("found main code at slot " + i); + //System.out.println("found main code at slot " + i); PdeCode temp = code[0]; code[0] = code[i]; code[i] = temp; @@ -196,6 +199,9 @@ public class PdeSketch { } } + // set the main file to be the current tab + current = code[0]; + // cheap-ass sort of the rest of the files // it's a dumb, slow sort, but there shouldn't be more than ~5 files for (int i = 1; i < codeCount; i++) {