clearing up bugs and attempting a compile

This commit is contained in:
benfry
2004-01-20 04:22:50 +00:00
parent 6faef3f83a
commit c2d2ad764e
7 changed files with 137 additions and 97 deletions
+2 -1
View File
@@ -399,7 +399,8 @@ public class PdeBase {
}
static public void copyDir(File sourceDir, File targetDir) {
static public void copyDir(File sourceDir,
File targetDir) throws IOException {
String files[] = sourceDir.list();
for (int i = 0; i < files.length; i++) {
if (files[i].equals(".") || files[i].equals("..")) continue;
+76
View File
@@ -0,0 +1,76 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
PdeCode - data class for a single file inside a sketch
Part of the Processing project - http://processing.org
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
*/
import java.io.*;
public class PdeCode {
String name; // pretty name (no extension), not the full file name
String preprocName; // name of .java file after preproc
File file;
int flavor;
String program;
boolean modified;
//History history; // later
public PdeCode(String name, File file, int flavor) {
this.name = name;
this.file = file;
this.flavor = flavor;
}
public void load() {
program = null;
try {
if (files[i].length() != 0) {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(files[i])));
StringBuffer buffer = new StringBuffer();
String line = null;
while ((line = reader.readLine()) != null) {
buffer.append(line);
buffer.append('\n');
}
reader.close();
program = buffer.toString();
} else {
// empty code file.. no worries, might be getting filled up
program = "";
}
} catch (IOException e) {
PdeBase.showWarning("Error loading file",
"Error while opening the file\n" +
file.getPath(), e);
program = null; // just in case
}
//if (program != null) {
//history = new History(file);
//}
}
}
+2 -2
View File
@@ -122,7 +122,7 @@ public class PdeEditor extends JFrame
//
PdeHistory history;
//PdeHistory history;
PdeSketchbook sketchbook;
PdePreferences preferences;
PdeEditorFind find;
@@ -827,7 +827,7 @@ public class PdeEditor extends JFrame
JMenuItem menuItem = new JMenuItem(title);
int modifiers = Toolkit.getDefaultToolkit().getMenuShortcutKeyMask();
if (shift) modifiers |= ActionEvent.SHIFT_MASK;
menuItem.setAccelerator(KeyStroke.getKeyStroke(what, modifiers);
menuItem.setAccelerator(KeyStroke.getKeyStroke(what, modifiers));
return menuItem;
}
+48 -39
View File
@@ -27,12 +27,14 @@ import java.awt.event.*;
import java.io.*;
import javax.swing.*;
import javax.swing.event.*;
public class PdeEditorHeader extends JComponent implements MouseInputListener {
public class PdeEditorHeader extends JComponent /*implements MouseListener*/ {
//static final String SKETCH_TITLER = "sketch";
//static Color primaryColor;
static Color backgroundColor;
static Color textColor[] = new Color[2];
//static Color unselectedColor;
@@ -51,6 +53,8 @@ public class PdeEditorHeader extends JComponent implements MouseInputListener {
FontMetrics metrics;
int fontAscent;
PdeSketch sketch;
//
JMenu menu;
@@ -107,6 +111,7 @@ public class PdeEditorHeader extends JComponent implements MouseInputListener {
//secondaryColor = PdePreferences.getColor("header.fgcolor.secondary");
}
/*
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
//System.out.println("got mouse");
@@ -116,9 +121,30 @@ public class PdeEditorHeader extends JComponent implements MouseInputListener {
}
}
});
*/
addMouseListener(this);
//addMouseListener(this);
//addMouseMotionListener(this);
addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
if ((x > menuLeft) && (x < menuRight)) {
popup.show(this, x, y);
} else {
for (int i = 0; i < sketch.codeCount; i++) {
if ((x > tabLeft[i]) && (x < tabRight[i])) {
//setCurrent(i);
sketch.setCurrent(i);
repaint();
}
}
}
}
});
}
@@ -132,7 +158,7 @@ public class PdeEditorHeader extends JComponent implements MouseInputListener {
if (screen == null) return;
//if (editor.sketchName == null) return;
PdeSketch sketch = editor.sketch;
//PdeSketch sketch = editor.sketch;
Dimension size = getSize();
if ((size.width != sizeW) || (size.height != sizeH)) {
@@ -167,22 +193,23 @@ public class PdeEditorHeader extends JComponent implements MouseInputListener {
}
if ((tabLeft == null) ||
(tabLeft.length < sketch.fileCount)) {
tabLeft = new int[sketch.fileCount];
tabRight = new int[sketch.fileCount];
(tabLeft.length < sketch.codeCount)) {
tabLeft = new int[sketch.codeCount];
tabRight = new int[sketch.codeCount];
}
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");
for (int i = 0; i < sketch.codeCount; i++) {
PdeCode code = sketch.code[i];
// if modified, add the li'l glyph next to the name
String text = " " + code.name + (code.modified ? " \u00A7" : " ");
int textWidth = metrics.stringWidth(text);
int pieceCount = 2 + (textWidth / PIECE_WIDTH);
int pieceWidth = pieceCount * PIECE_WIDTH;
state = (i == sketch.current) ? SELECTED : UNSELECTED;
int state = (code == sketch.current) ? SELECTED : UNSELECTED;
g.drawImage(pieces[state][LEFT], x, 0, null);
x += PIECE_WIDTH;
@@ -197,17 +224,18 @@ public class PdeEditorHeader extends JComponent implements MouseInputListener {
g.setColor(textColor[STATUS]);
int baseline = (sizeH + fontAscent) / 2;
g.drawString(names[i], textLeft, baseline);
//g.drawString(sketch.code[i].name, textLeft, baseline);
g.drawString(text, textLeft, baseline);
g.drawImage(pieces[state][RIGHT], x, 0, null);
x += PIECE_WIDTH - 1; // overlap by 1 pixel
}
menuLeft = sizeW - (16 + pieces[0][MENU].getWidth());
menuLeft = sizeW - (16 + pieces[0][MENU].getWidth(this));
menuRight = sizeW - 16;
// draw the dropdown menu target
g.drawImage(pieces[popup.isVisible() ? SELECTED : UNSELECTED][MENU],
menuLeft, 0);
menuLeft, 0, null);
/*
sketchTitleLeft = PdePreferences.GUI_SMALL;
@@ -246,7 +274,7 @@ public class PdeEditorHeader extends JComponent implements MouseInputListener {
menu.removeAll();
} else {
menu = new JMenu();
popup = menu.getPopUp();
popup = menu.getPopupMenu();
add(popup);
popup.addPopupMenuListener(new PopupMenuListener() {
public void popupMenuCanceled(PopupMenuEvent e) {
@@ -256,8 +284,8 @@ public class PdeEditorHeader extends JComponent implements MouseInputListener {
repaint();
}
//public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
//public void popupMenuWillBecomeVisible(PopupMenuEvent e) { }
public void popupMenuWillBecomeInvisible(PopupMenuEvent e) { }
public void popupMenuWillBecomeVisible(PopupMenuEvent e) { }
});
}
JMenuItem item;
@@ -331,8 +359,8 @@ public class PdeEditorHeader extends JComponent implements MouseInputListener {
System.out.println("jump to " + e);
}
};
for (int i = 0; i < fileCount; i++) {
item = new JMenuItem(names[i]);
for (int i = 0; i < sketch.codeCount; i++) {
item = new JMenuItem(sketch.code[i].name);
//item.setActionCommand(files[i]);
item.addActionListener(jumpListener);
menu.add(item);
@@ -346,25 +374,6 @@ public class PdeEditorHeader extends JComponent implements MouseInputListener {
}
public void mousePressed(MouseEvent e) {
int x = e.getX();
int y = e.getY();
if ((x > menuLeft) && (x < menuRight)) {
popup.show(this, x, y);
} else {
for (int i = 0; i < fileCount; i++) {
if ((x > tabLeft[i]) && (x < tabRight[i])) {
//setCurrent(i);
editor.sketch.setCurrent(i);
repaint();
}
}
}
}
/*
public void setCurrent(int which) {
current = which;
@@ -378,7 +387,7 @@ public class PdeEditorHeader extends JComponent implements MouseInputListener {
public Dimension getPreferredSize() {
return getMinimumSize();
return getMinimumSize();
}
public Dimension getMinimumSize() {
+3 -4
View File
@@ -75,9 +75,8 @@ public class PdePreprocessor {
* preprocesses a pde file and write out a java file
* @return the classname of the exported Java
*/
public String write(String program, String buildPath,
String name, String extraImports[])
throws java.lang.Exception {
public String write(String program, String buildPath, String name,
String extraImports[]) throws java.lang.Exception {
if (PdePreferences.getBoolean("compiler.substitute_unicode")) {
// check for non-ascii chars (these will be/must be in unicode format)
@@ -89,7 +88,7 @@ public class PdePreprocessor {
// if non-ascii chars are in there, convert to unicode escapes
if (unicodeCount != 0) {
// add unicodeCount * 5.. replacing each unicode char
// with six digit \u XXXX sequence (xxxx is in hex)
// with six digit uXXXX sequence (xxxx is in hex)
// (except for nbsp chars which will be a replaced with a space)
int index = 0;
char p2[] = new char[p.length + unicodeCount*5];
+5 -50
View File
@@ -22,6 +22,11 @@
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.io.*;
import java.util.*;
import java.util.zip.*;
public class PdeSketch {
static String TEMP_BUILD_PATH = "lib" + File.separator + "build";
static String tempBuildFolder;
@@ -1074,53 +1079,3 @@ public class PdeSketch {
}
}
class PdeCode {
String name; // pretty name (no extension), not the full file name
String preprocName; // name of .java file after preproc
File file;
int flavor;
String program;
boolean modified;
//History history; // later
public PdeCode(String name, File file, int flavor) {
this.name = name;
this.file = file;
this.flavor = flavor;
}
public void load() {
program = null;
try {
if (files[i].length() != 0) {
BufferedReader reader = new BufferedReader(new InputStreamReader(new FileInputStream(files[i])));
StringBuffer buffer = new StringBuffer();
String line = null;
while ((line = reader.readLine()) != null) {
buffer.append(line);
buffer.append('\n');
}
reader.close();
program = buffer.toString();
} else {
// empty code file.. no worries, might be getting filled up
program = "";
}
} catch (IOException e) {
PdeBase.showWarning("Error loading file",
"Error while opening the file\n" +
files[i].getPath(), e);
program = null; // just in case
}
//if (program != null) {
//history = new History(file);
//}
}
}