mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
working on tabs.. now actually working/displaying semi-properly
This commit is contained in:
@@ -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;
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -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);
|
||||
}
|
||||
|
||||
@@ -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();
|
||||
|
||||
@@ -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);
|
||||
|
||||
@@ -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++) {
|
||||
|
||||
Reference in New Issue
Block a user