further changes, more reworking

This commit is contained in:
benfry
2003-11-08 23:52:51 +00:00
parent d63eeda0a2
commit 227788d1ed
8 changed files with 157 additions and 102 deletions

View File

@@ -49,13 +49,9 @@ public class PdeBase /*extends JFrame implements ActionListener*/
{
static final String VERSION = "0068 Alpha";
//static Properties properties;
PdePreferences preferences;
static Properties keywords; // keyword -> reference html lookup
//static Frame frame; // now 'this'
//static String encoding;
static Image icon;
//static Image icon;
// indicator that this is the first time this feller has used p5
//static boolean firstTime;
@@ -90,6 +86,12 @@ public class PdeBase /*extends JFrame implements ActionListener*/
public PdeBase() {
// build the editor object
editor = new PdeEditor();
editor.pack();
// figure out which operating system
if (System.getProperty("mrj.version") != null) { // running on a mac
@@ -133,31 +135,22 @@ public class PdeBase /*extends JFrame implements ActionListener*/
// load in preferences (last sketch used, window placement, etc)
preferences = new PdePreferences();
//preferences = new PdePreferences();
// read in the keywords for the reference
final String KEYWORDS = "pde_keywords.properties";
keywords = new Properties();
try {
if ((PdeBase.platform == PdeBase.MACOSX) ||
(PdeBase.platform == PdeBase.MACOS9)) {
// macos doesn't seem to think that files in the lib folder
// are part of the resources, unlike windows or linux.
// actually, this is only the case when running as a .app,
// since it works fine from run.sh, but not Processing.app
keywords.load(new FileInputStream("lib/" + KEYWORDS));
} else { // other, more reasonable operating systems
keywords.load(getClass().getResource(KEYWORDS).openStream());
}
try {
keywords.load(PdeBase.getStream(KEYWORDS));
} catch (Exception e) {
String message =
"An error occurred while loading the keywords,\n" +
"\"Find in reference\" will not be available.";
JOptionPane.showMessageDialog(this, message,
JOptionPane.showMessageDialog(editor, message,
"Problem loading keywords",
JOptionPane.WARNING_MESSAGE);
@@ -166,10 +159,9 @@ public class PdeBase /*extends JFrame implements ActionListener*/
}
// build the editor object
// get things rawkin
editor = new PdeEditor();
editor.pack();
editor.restorePreferences();
editor.show();
@@ -318,7 +310,7 @@ public class PdeBase /*extends JFrame implements ActionListener*/
static public void showMessage(String title, String message) {
if (title == null) title = "Message";
JOptionPane.showMessageDialog(this, message, title,
JOptionPane.showMessageDialog(new Frame(), message, title,
JOptionPane.INFORMATION_MESSAGE);
}
@@ -327,7 +319,7 @@ public class PdeBase /*extends JFrame implements ActionListener*/
static public void showWarning(String title, String message,
Exception e) {
if (title == null) title = "Warning";
JOptionPane.showMessageDialog(this, message, title,
JOptionPane.showMessageDialog(new Frame(), message, title,
JOptionPane.WARNING_MESSAGE);
//System.err.println(e.toString());
@@ -339,7 +331,7 @@ public class PdeBase /*extends JFrame implements ActionListener*/
static public void showError(String title, String message,
Exception e) {
if (title == null) title = "Error";
JOptionPane.showMessageDialog(this, message, title,
JOptionPane.showMessageDialog(new Frame(), message, title,
JOptionPane.ERROR_MESSAGE);
if (e != null) e.printStackTrace();
@@ -374,6 +366,23 @@ public class PdeBase /*extends JFrame implements ActionListener*/
return image;
}
//
static 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
// are part of the resources, unlike windows or linux.
// actually, this is only the case when running as a .app,
// since it works fine from run.sh, but not Processing.app
return new FileInputStream("lib/" + filename);
}
// all other, more reasonable operating systems
return getClass().getResource(filename).openStream();
}
// ...................................................................
@@ -435,30 +444,6 @@ public class PdeBase /*extends JFrame implements ActionListener*/
}
}
// cleanup temp files
//
//static protected void cleanTempFiles(String buildPath) {
//static protected void cleanTempFiles() {
protected void cleanTempFiles() {
if (tempBuildPath == null) return;
// if the java runtime is holding onto any files in the build dir, we
// won't be able to delete them, so we need to force a gc here
//
System.gc();
//File dirObject = new File(buildPath);
File dirObject = new File(tempBuildPath);
// note that we can't remove the builddir itself, otherwise
// the next time we start up, internal runs using PdeRuntime won't
// work because the build dir won't exist at startup, so the classloader
// will ignore the fact that that dir is in the CLASSPATH in run.sh
//
if (dirObject.exists()) {
removeDescendants(dirObject);
}
}
// remove all files in a directory
//
@@ -468,7 +453,8 @@ public class PdeBase /*extends JFrame implements ActionListener*/
if (files[i].equals(".") || files[i].equals("..")) continue;
File dead = new File(dir, files[i]);
if (!dead.isDirectory()) {
if (!PdePreferences.getBoolean("editor.save_build_files", false)) {
//if (!PdePreferences.getBoolean("editor.save_build_files", false)) {
if (!PdePreferences.getBoolean("editor.save_build_files")) {
if (!dead.delete()) {
// temporarily disabled
//System.err.println("couldn't delete " + dead);
@@ -481,6 +467,7 @@ public class PdeBase /*extends JFrame implements ActionListener*/
}
}
// remove all files in a directory and the dir itself
//
static protected void removeDir(File dir) {

View File

@@ -51,6 +51,9 @@ public class PdeEditor extends JFrame
// yeah
static final String WINDOW_TITLE = "Processing";
// p5 icon for the window
Image icon;
// otherwise, if the window is resized with the message label
// set to blank, it's preferredSize() will be fukered
static final String EMPTY = " ";
@@ -120,8 +123,15 @@ public class PdeEditor extends JFrame
protected RedoAction redoAction;
static public UndoManager undo = new UndoManager(); // editor needs this guy
//
public PdeEditor(PdeBase base) {
PdeHistory history;
PdeSketchbook sketchbook;
PdePreferences preferences;
static Properties keywords; // keyword -> reference html lookup
public PdeEditor() { //PdeBase base) {
//this.base = base;
#ifdef MACOS
@@ -134,7 +144,8 @@ public class PdeEditor extends JFrame
// set the window icon
try {
icon = Toolkit.getDefaultToolkit().getImage("lib/icon.gif");
//icon = Toolkit.getDefaultToolkit().getImage("lib/icon.gif");
icon = PdeBase.getImage("icon.gif");
setIconImage(icon);
} catch (Exception e) { } // fail silently, no big whup
@@ -152,12 +163,13 @@ public class PdeEditor extends JFrame
history = new PdeHistory(this);
sketchbook = new PdeSketchbook(this);
preferences = new PdePreferences();
JMenuBar menubar = new JMenuBar();
menubar.add(buildFileMenu());
menubar.add(buildEditMenu());
menubar.setHelpMenu(buildHelpMenu());
setMenuBar(menubar);
setJMenuBar(menubar);
Container pain = getContentPane();
pain.setLayout(new BorderLayout());
@@ -340,8 +352,8 @@ public class PdeEditor extends JFrame
if (PdePreferences.get("last.screen.height") != null) {
// if screen size has changed, the window coordinates no longer
// make sense, so don't use them unless they're identical
int screenW = getInteger("last.screen.width");
int screenH = getInteger("last.screen.height");
int screenW = PdePreferences.getInteger("last.screen.width");
int screenH = PdePreferences.getInteger("last.screen.height");
if ((screen.width != screenW) || (screen.height != screenH)) {
windowPositionInvalid = true;
@@ -390,7 +402,7 @@ public class PdeEditor extends JFrame
// read the preferences that are settable in the preferences window
applyPreferences()
applyPreferences();
}
@@ -401,7 +413,7 @@ public class PdeEditor extends JFrame
public void applyPreferences() {
// apply the setting for 'use external editor'
boolean external = getBoolean("editor.external");
boolean external = PdePreferences.getBoolean("editor.external");
textarea.setEditable(!external);
saveMenuItem.setEnabled(!external);
@@ -411,14 +423,16 @@ public class PdeEditor extends JFrame
TextAreaPainter painter = textarea.getPainter();
if (external) {
// disable line highlight and turn off the caret when disabling
Color bg = PdePreferences.getColor("editor.program.bgcolor.external");
painter.setBackground(bg);
Color color = PdePreferences.getColor("editor.program.bgcolor.external");
painter.setBackground(color);
painter.lineHighlight = false;
textarea.setCaretVisible(false);
} else {
painter.setBackground(PdePreferences.getColor("editor.program.bgcolor")); //, Color.white));
painter.lineHighlight = PdePreferences.getBoolean("editor.program.linehighlight");
Color color = PdePreferences.getColor("editor.program.bgcolor");
painter.setBackground(color);
painter.lineHighlight =
PdePreferences.getBoolean("editor.program.linehighlight");
textarea.setCaretVisible(true);
}
@@ -430,7 +444,8 @@ public class PdeEditor extends JFrame
// in case moved to a new location
rebuildSketchbookMenu(sketchbookMenu);
//rebuildSketchbookMenu(sketchbookMenu);
sketchbook.rebuildMenu();
}
@@ -447,8 +462,8 @@ public class PdeEditor extends JFrame
PdePreferences.setInteger("last.window.height", bounds.height);
// last sketch that was in use
PdePreferences.put("last.sketch.name", sketchName);
PdePreference.put("last.sketch.path", sketchDir.getAbsolutePath());
PdePreferences.set("last.sketch.name", sketchName);
PdePreferences.set("last.sketch.path", sketchDir.getAbsolutePath());
// location for the console/editor area divider
int location = splitPane.getDividerLocation();
@@ -461,7 +476,7 @@ public class PdeEditor extends JFrame
protected JMenu buildFileMenu() {
JMenuItem item;
JMenu menu = new Menu("File");
JMenu menu = new JMenu("File");
item = newMenuItem("New", 'N');
item.addActionListener(new ActionListener() {
@@ -471,8 +486,9 @@ public class PdeEditor extends JFrame
});
menu.add(item);
sketchbookMenu = new Menu("Open");
menu.add(sketchbookMenu);
//sketchbookMenu = new JMenu("Open");
//menu.add(sketchbookMenu);
menu.add(sketchbook.rebuildMenu());
saveMenuItem = newMenuItem("Save", 'S');
saveMenuItem.addActionListener(new ActionListener() {
@@ -490,7 +506,7 @@ public class PdeEditor extends JFrame
});
menu.add(saveAsMenuItem);
item = new MenuItem("Rename...");
item = new JMenuItem("Rename...");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
skSaveAs(true);
@@ -559,7 +575,7 @@ public class PdeEditor extends JFrame
protected JMenu buildSketchMenu() {
JMenuItem item;
JMenu menu = new Menu("Sketch");
JMenu menu = new JMenu("Sketch");
item = newMenuItem("Run", 'R');
item.addActionListener(new ActionListener() {
@@ -589,7 +605,7 @@ public class PdeEditor extends JFrame
});
menu.addSeparator();
item = newMenuItem("Add file...");
item = new JMenuItem("Add file...");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
addFile();
@@ -597,7 +613,7 @@ public class PdeEditor extends JFrame
});
menu.add(item);
item = newMenuItem("Create font...");
item = new JMenuItem("Create font...");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
new PdeFontBuilder(new File(sketchDir, "data"));
@@ -605,7 +621,8 @@ public class PdeEditor extends JFrame
});
menu.add(item);
if ((platform == WINDOWS) || (platform == MACOSX)) {
if ((PdeBase.platform == PdeBase.WINDOWS) ||
(PdeBase.platform == PdeBase.MACOSX)) {
// no way to do an 'open in file browser' on other platforms
// since there isn't any sort of standard
item = new JMenuItem("Show sketch folder");
@@ -626,7 +643,8 @@ public class PdeEditor extends JFrame
protected JMenu buildHelpMenu() {
JMenu menu = new Menu("Help");
JMenu menu = new JMenu("Help");
JMenuItem item;
item = new JMenuItem("Help");
item.addActionListener(new ActionListener() {
@@ -642,8 +660,8 @@ public class PdeEditor extends JFrame
item = new JMenuItem("Reference");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openURL(System.getProperty("user.dir") + File.separator +
"reference" + File.separator + "index.html");
PdeBase.openURL(System.getProperty("user.dir") + File.separator +
"reference" + File.separator + "index.html");
}
});
menu.add(item);
@@ -651,13 +669,13 @@ public class PdeEditor extends JFrame
item = new JMenuItem("Proce55ing.net", '5');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
openURL("http://Proce55ing.net/");
PdeBase.openURL("http://Proce55ing.net/");
}
});
menu.add(item);
// macosx already has its own about menu
if (platform != MACOSX) {
if (PdeBase.platform != PdeBase.MACOSX) {
menu.addSeparator();
item = new JMenuItem("About Processing");
item.addActionListener(new ActionListener() {
@@ -756,17 +774,19 @@ public class PdeEditor extends JFrame
message("First select a word to find in the reference.");
} else {
String referenceFile = (String) keywords.get(text);
String referenceFile = (String) PdeBase.keywords.get(text);
if (referenceFile == null) {
message("No reference available for \"" + text + "\"");
} else {
showReference(referenceFile);
PdeBase.showReference(referenceFile);
}
}
}
}
});
menu.add(item);
return menu;
}
@@ -882,7 +902,7 @@ public class PdeEditor extends JFrame
g.setFont(new Font("SansSerif", Font.PLAIN, 11));
g.setColor(Color.white);
g.drawString(VERSION, 50, 30);
g.drawString(PdeBase.VERSION, 50, 30);
}
};
window.addMouseListener(new MouseAdapter() {
@@ -907,7 +927,7 @@ public class PdeEditor extends JFrame
applyPreferences();
// next have editor do its thing
editor.appyPreferences();
//editor.appyPreferences();
}
@@ -924,7 +944,8 @@ public class PdeEditor extends JFrame
PdePreferences.save();
// check to see if the person actually wants to quit
editor.doQuit();
//editor.doQuit();
doQuit();
}
@@ -2349,6 +2370,32 @@ public class PdeEditor extends JFrame
public void messageClear(String msg) {
status.unnotice(msg);
}
// cleanup temp files
//
//static protected void cleanTempFiles(String buildPath) {
//static protected void cleanTempFiles() {
protected void cleanTempFiles() {
if (tempBuildPath == null) return;
// if the java runtime is holding onto any files in the build dir, we
// won't be able to delete them, so we need to force a gc here
//
System.gc();
//File dirObject = new File(buildPath);
File dirObject = new File(tempBuildPath);
// note that we can't remove the builddir itself, otherwise
// the next time we start up, internal runs using PdeRuntime won't
// work because the build dir won't exist at startup, so the classloader
// will ignore the fact that that dir is in the CLASSPATH in run.sh
//
if (dirObject.exists()) {
removeDescendants(dirObject);
}
}
}

View File

@@ -23,10 +23,14 @@
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
import java.awt.*;
import java.awt.event.*;
import java.io.*;
import java.util.*;
import java.util.zip.*;
import javax.swing.*;
public class PdeHistory {
PdeEditor editor;
@@ -45,14 +49,14 @@ public class PdeHistory {
//PrintWriter historyWriter;
String historyLast;
/*
ActionListener historyMenuListener =
new ActionListener() {
public void actionPerformed(ActionEvent e) {
editor.retrieveHistory(e.getActionCommand());
}
};
*/
public PdeHistory(PdeEditor editor) {
@@ -62,7 +66,7 @@ public class PdeHistory {
public void attachMenu(JMenu menu) {
if (PdePreferences.getBoolean("history.recording")) {
historyMenu = new Menu("History");
historyMenu = new JMenu("History");
menu.add(historyMenu);
}
}

View File

@@ -151,6 +151,11 @@ public class PdePreferences extends JComponent {
}
// other things that have to be set explicitly for the defaults
setColor("run.window.bgcolor", SystemColor.control);
// next load user preferences file
String home = System.getProperty("user.home");

View File

@@ -191,8 +191,8 @@ public class PdeRuntime implements PdeMessageConsumer {
} else {
window = new Frame(editor.sketchName); // use ugly windows
((Frame)window).setResizable(false);
if (PdeBase.icon != null) {
((Frame)window).setIconImage(PdeBase.icon);
if (editor.icon != null) {
((Frame)window).setIconImage(editor.icon);
}
window.pack(); // to get a peer, size set later, need for insets
@@ -268,11 +268,11 @@ public class PdeRuntime implements PdeMessageConsumer {
//windowY = y1;
} else { // if it fits inside the editor window
x1 = parentLoc.x + PdeEditor.GRID_SIZE * 2; // 66
y1 = parentLoc.y + PdeEditor.GRID_SIZE * 2; // 66
x1 = parentLoc.x + PdePreferences.GRID_SIZE * 2; // 66
y1 = parentLoc.y + PdePreferences.GRID_SIZE * 2; // 66
if ((x1 + windowW > screen.width - PdeEditor.GRID_SIZE) ||
(y1 + windowH > screen.height - PdeEditor.GRID_SIZE)) {
if ((x1 + windowW > screen.width - PdePreferences.GRID_SIZE) ||
(y1 + windowH > screen.height - PdePreferences.GRID_SIZE)) {
// otherwise center on screen
x1 = (screen.width - windowW) / 2;
y1 = (screen.height - windowH) / 2;
@@ -281,7 +281,7 @@ public class PdeRuntime implements PdeMessageConsumer {
}
Color windowBgColor =
PdePreferences.getColor("run.window.bgcolor", SystemColor.control);
PdePreferences.getColor("run.window.bgcolor");
//new Color(102, 102, 102));
window.setBackground(windowBgColor);
//window.setBackground(SystemColor.windowBorder);

View File

@@ -36,11 +36,18 @@ import javax.swing.undo.*;
public class PdeSketchbook {
JMenu sketchbookMenu;
PdeEditor editor;
//JMenu sketchbookMenu;
JMenu menu;
File sketchbookFolder;
String sketchbookPath;
public PdeSketchbook(PdeEditor editor) {
this.editor = editor;
}
// listener for sketchbk items uses getParent() to figure out
// the directories above it
@@ -58,12 +65,13 @@ public class PdeSketchbook {
}
}
public void rebuildSketchbookMenu() {
rebuildSketchbookMenu(sketchbookMenu);
}
public void rebuildSketchbookMenu(Menu menu) {
menu.removeAll();
public JMenu rebuildMenu() {
if (menu == null) {
menu = new JMenu("Open");
} else {
menu.removeAll();
}
try {
//MenuItem newSketchItem = new MenuItem("New Sketch");
@@ -141,6 +149,7 @@ public class PdeSketchbook {
} catch (IOException e) {
e.printStackTrace();
}
return menu;
}

View File

@@ -122,10 +122,10 @@ cd app
# but for now, the parser is only built when the work dir
# is created, to speed the build process.
#if test -f preprocessor/expandedpde.g
#then
#echo
#else
if test -f preprocessor/expandedpde.g
then
echo
else
cd preprocessor
# build classes/grammar for preprocessor
echo Building antlr grammar code...
@@ -134,7 +134,7 @@ cd app
# now build the pde stuff that extends the java classes
java -cp ../../build/macosx/work/lib/antlr.jar antlr.Tool -glib java.g pde.g
cd ..
#fi
fi
### -- BUILD PDE ------------------------------------------------

View File

@@ -128,6 +128,9 @@ editor.wheelmouse.multiplier = 3
# background color for full-screen presentation mode
run.present.bgcolor = #666666
# set internally
#run.window.bgcolor =
# prompt for sketch location when 'new' is hit
sketchbook.prompt = false