moved reference code into PdeBase, tidying readme, cleanup console

This commit is contained in:
benfry
2003-07-29 03:11:48 +00:00
parent bf67b180fa
commit 6f434cfe94
7 changed files with 244 additions and 245 deletions
+62 -45
View File
@@ -39,6 +39,8 @@ import javax.swing.undo.*;
public class PdeBase extends Frame implements ActionListener {
static Properties properties;
static Properties keywords; // keyword -> reference html lookup
static Frame frame; // now 'this'
static String encoding;
static Image icon;
@@ -175,7 +177,7 @@ public class PdeBase extends Frame implements ActionListener {
try {
icon = Toolkit.getDefaultToolkit().getImage("lib/icon.gif");
frame.setIconImage(icon);
} catch (Exception e) { } // fail silently
} catch (Exception e) { } // fail silently, no big whup
windowListener = new WindowAdapter() {
public void windowClosing(WindowEvent e) {
@@ -213,40 +215,33 @@ public class PdeBase extends Frame implements ActionListener {
}
//properties.list(System.out);
} catch (Exception e) {
System.err.println("Error reading pde.properties");
e.printStackTrace();
//System.exit(1);
}
// int width = getInteger("window.width", 600);
// int height = getInteger("window.height", 350);
/*
encoding = get("encoding");
boolean beautify = false;
boolean convertSemicolons = false;
String program = get("program");
if (program != null) {
//program = getFile(program);
} else {
program = get("inline_program");
convertSemicolons = true;
}
if (program != null) {
// don't beautify if it's java code
if (program.indexOf("extends PdePlayer") == -1) {
// don't convert ; to \n if scheme
if (program.charAt(0) != ';') {
if (convertSemicolons) {
program = program.replace(';', '\n');
}
// not scheme, but don't beautify if it's python
if (program.charAt(0) != '#')
beautify = true;
}
}
}
*/
// read in the keywords for the reference
final String KEYWORDS = "pde_keywords.properties";
keywords = new Properties();
try {
// this probably won't work on macos9
// seems to work on macosx java 1.4, though i don't think
// it worked on java 1.3 for macosx (see implementation above)
keywords.load(getClass().getResource(KEYWORDS).openStream());
} catch (Exception e) {
System.err.println("Error loading keywords, " +
"reference lookup will be unavailable");
System.err.println(e.toString());
e.printStackTrace();
}
// build the editor object
editor = new PdeEditor(this);
frame.setLayout(new BorderLayout());
@@ -259,17 +254,12 @@ public class PdeBase extends Frame implements ActionListener {
menu = new Menu("File");
menu.add(new MenuItem("New", new MenuShortcut('N')));
sketchbookMenu = new Menu("Open");
//rebuildSketchbookMenu(openMenu);
menu.add(sketchbookMenu);
saveMenuItem = new MenuItem("Save", new MenuShortcut('S'));
saveAsMenuItem = new MenuItem("Save as...", new MenuShortcut('S', true));
menu.add(saveMenuItem);
menu.add(saveAsMenuItem);
menu.add(new MenuItem("Rename..."));
//menu.add(new MenuItem("Save", new MenuShortcut('S')));
//menu.add(new MenuItem("Save as...", new MenuShortcut('S', true)));
//menu.add(new MenuItem("Rename", new MenuShortcut('S', true)));
//menu.add(new MenuItem("Duplicate", new MenuShortcut('D')));
menu.add(new MenuItem("Export to Web", new MenuShortcut('E')));
item = new MenuItem("Export Application", new MenuShortcut('E', true));
item.setEnabled(false);
@@ -331,6 +321,20 @@ public class PdeBase extends Frame implements ActionListener {
});
menu.add(item);
menu.addSeparator();
item = new MenuItem("Find in Reference");
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
if (editor.textarea.isSelectionActive()) {
String text = editor.textarea.getSelectedText();
String referenceFile = (String) keywords.get(text);
showReference(referenceFile);
}
}
});
menu.add(item);
menubar.add(menu);
Document document = editor.textarea.getDocument();
@@ -338,7 +342,7 @@ public class PdeBase extends Frame implements ActionListener {
menu = new Menu("Sketch");
menu.add(new MenuItem("Run", new MenuShortcut('R')));
menu.add(new MenuItem("Present", new MenuShortcut('P')));
menu.add(new MenuItem("Present", new MenuShortcut('R', true)));
menu.add(new MenuItem("Stop", new MenuShortcut('T')));
menu.addSeparator();
@@ -809,26 +813,31 @@ public class PdeBase extends Frame implements ActionListener {
e.printStackTrace();
}
if (serialMenu.getItemCount() == 0) {
//System.out.println("dimming serial menu");
serialMenu.setEnabled(false);
}
// macosx fails on its own when trying to load the library
// so need to explicitly try here.. not sure if this is the
// correct lib, but it's at least one that's loaded inside
// the javacomm solaris stuff, which is the .jar that's included
// with the osx release (and rxtx takes over)
if (platform == MACOSX) {
try {
System.loadLibrary("SolarisSerialParallel");
} catch (UnsatisfiedLinkError e) {
//e.printStackTrace();
problem = true;
}
try {
System.loadLibrary("SolarisSerialParallel");
} catch (UnsatisfiedLinkError e) {
//e.printStackTrace();
problem = true;
}
}
// only warn them if this is the first time
if (problem && firstTime) {
JOptionPane.showMessageDialog(frame,
"Serial port support not installed.\n" +
"Check the readme for instructions if you " +
"need to use the serial port. ",
"Check the readme for instructions\n" +
"if you need to use the serial port. ",
"Serial Port Warning",
JOptionPane.WARNING_MESSAGE);
}
@@ -906,6 +915,14 @@ public class PdeBase extends Frame implements ActionListener {
}
static public void showReference(String referenceFile) {
String currentDir = System.getProperty("user.dir");
openURL(currentDir + File.separator +
"reference" + File.separator +
referenceFile + ".html");
}
static public void openURL(String url) {
try {
if (platform == WINDOWS) {
@@ -915,7 +932,7 @@ public class PdeBase extends Frame implements ActionListener {
// include me) it'd be annoying to be dropped into ie.
//Runtime.getRuntime().exec("c:\\progra~1\\intern~1\\iexplore "+ currentDir
// this uses a shell execute to launch the .html file
// the following uses a shell execute to launch the .html file
// note that under cygwin, the .html files have to be chmodded +x
// after they're unpacked from the zip file. i don't know why,
// and don't understand what this does in terms of windows
@@ -929,7 +946,7 @@ public class PdeBase extends Frame implements ActionListener {
} else if (platform == MACOSX) {
//com.apple.eio.FileManager.openURL(url);
if (!url.startsWith("http://")) url = "file://" + url;
System.out.println("trying to open " + url);
//System.out.println("trying to open " + url);
com.apple.mrj.MRJFileUtils.openURL(url);
} else if (platform == MACOS9) {
+5 -26
View File
@@ -414,7 +414,7 @@ public class PdeEditor extends JPanel {
if(serialPort != null) {
PdeBase.properties.put("serial.port", serialPort);
}
boolean ee = new Boolean(skprops.getProperty("editor.external", "false")).booleanValue();
setExternalEditor(ee);
@@ -1504,32 +1504,16 @@ afterwards, some of these steps need a cleanup function
ps.println("</body>");
ps.println("</html>");
/*
ps.println("<HTML> <BODY BGCOLOR=\"white\">");
ps.println();
ps.println("<BR> <BR> <BR> <CENTER>");
ps.println();
ps.print("<APPLET CODE=\"" + exportSketchName + "\" ARCHIVE=\"");
ps.print(exportSketchName + ".jar");
ps.println("\" WIDTH=" + wide + " HEIGHT=" + high + ">");
ps.println("</APPLET>");
ps.println();
ps.println("<A HREF=\"" + exportSketchName + ".java\">source code</A>");
ps.println();
ps.println("</CENTER>");
ps.println("</BODY> </HTML>");
*/
ps.flush();
ps.close();
#ifdef MACOS
// this chunk left disabled, because safari doesn't actually
// set the type/creator of html files it makes
// however, for macos9, this should be re-enabled
// (but it's not here since macos9 isn't supported for beta)
/*
// thank you apple, for changing this
//com.apple.eio.setFileTypeAndCreator(String filename, int, int);
@@ -1774,11 +1758,6 @@ afterwards, some of these steps need a cleanup function
String prog = textarea.getText();
makeHistory(prog, BEAUTIFY);
//if ((prog.charAt(0) == '#') || (prog.charAt(0) == ';')) {
//message("Only DBN code can be made beautiful.");
//buttons.clear();
//return;
//}
char program[] = prog.toCharArray();
StringBuffer buffer = new StringBuffer();
boolean gotBlankLine = false;
+35 -79
View File
@@ -38,22 +38,14 @@ import javax.swing.text.*;
public class PdeEditorConsole extends JScrollPane {
PdeEditor editor;
JTextPane consoleTextPane;
StyledDocument consoleDoc;
MutableAttributeSet stdStyle;
MutableAttributeSet errStyle;
/* for potential cross platform whitespace munging
static final byte CR = (byte)'\r';
static final byte LF = (byte)'\n';
static final byte TAB = (byte)'\t';
static final int TAB_SIZE = 2;
*/
boolean cerror;
//static final int HINSET = 6;
//static final int VINSET = 6;
static PrintStream systemOut;
static PrintStream systemErr;
@@ -67,7 +59,7 @@ public class PdeEditorConsole extends JScrollPane {
public PdeEditorConsole(PdeEditor editor) {
this.editor = editor;
JTextPane consoleTextPane = new JTextPane();
consoleTextPane = new JTextPane();
consoleTextPane.setEditable(false);
consoleDoc = consoleTextPane.getStyledDocument();
@@ -75,16 +67,16 @@ public class PdeEditorConsole extends JScrollPane {
MutableAttributeSet standard = new SimpleAttributeSet();
StyleConstants.setAlignment(standard, StyleConstants.ALIGN_LEFT);
consoleDoc.setParagraphAttributes(0, 0, standard, true);
// build styles for different types of console output
Color bgColor = PdeBase.getColor("editor.console.bgcolor",
new Color(26, 26, 26));
new Color(26, 26, 26));
Color fgColorOut = PdeBase.getColor("editor.console.fgcolor.output",
new Color(153, 153, 153));
new Color(153, 153, 153));
Color fgColorErr = PdeBase.getColor("editor.console.fgcolor.error",
new Color(204, 51, 0));
new Color(204, 51, 0));
Font font = PdeBase.getFont("editor.console.font",
new Font("Monospaced", Font.PLAIN, 11));
new Font("Monospaced", Font.PLAIN, 11));
stdStyle = new SimpleAttributeSet();
StyleConstants.setForeground(stdStyle, fgColorOut);
@@ -93,7 +85,7 @@ public class PdeEditorConsole extends JScrollPane {
StyleConstants.setFontFamily(stdStyle, font.getFamily());
StyleConstants.setBold(stdStyle, font.isBold());
StyleConstants.setItalic(stdStyle, font.isItalic());
errStyle = new SimpleAttributeSet();
StyleConstants.setForeground(errStyle, fgColorErr);
StyleConstants.setBackground(errStyle, bgColor);
@@ -103,23 +95,25 @@ public class PdeEditorConsole extends JScrollPane {
StyleConstants.setItalic(errStyle, font.isItalic());
consoleTextPane.setBackground(bgColor);
// add the jtextpane to this scrollpane
this.setViewportView(consoleTextPane);
// calculate height of a line of text in pixels and size window accordingly
// calculate height of a line of text in pixels
// and size window accordingly
FontMetrics metrics = this.getFontMetrics(font);
int height = metrics.getAscent() + metrics.getDescent();
int lines = PdeBase.getInteger("editor.console.lines", 6);
int sizeFudge = 10; // unclear why this is necessary, but it is
Dimension prefDimension = new Dimension(1024, (height * lines) + sizeFudge);
Dimension prefDimension =
new Dimension(1024, (height * lines) + sizeFudge);
setPreferredSize(prefDimension);
if (systemOut == null) {
systemOut = System.out;
systemErr = System.err;
// no text thing on macos
// macos9/macosx do this by default, disable for those platforms
boolean tod = ((PdeBase.platform != PdeBase.MACOSX) &&
(PdeBase.platform != PdeBase.MACOS9));
@@ -157,27 +151,25 @@ public class PdeEditorConsole extends JScrollPane {
public void write(byte b[], int offset, int length, boolean err) {
if (err != cerror) {
// advance the line because switching between err/out streams
// potentially, could check whether we're already on a new line
message("", cerror, true);
}
// synchronized (cerror) { // has to be an object...
if (err != cerror) {
// advance the line because switching between err/out streams
// potentially, could check whether we're already on a new line
message("", cerror, true);
}
// we could do some cross platform CR/LF mangling here before outputting
// we could do some cross platform CR/LF mangling here before outputting
// add text to output document
message(new String(b, offset, length), err, false);
// set last error state
cerror = err;
// }
// add text to output document
message(new String(b, offset, length), err, false);
// set last error state
cerror = err;
}
public void message(String what, boolean err, boolean advance) {
// under osx, suppress the spew about the serial port
// to avoid an error every time someone loads their app
// (the error is dealt with in PdeBase with a message dialog)
if (PdeBase.platform == PdeBase.MACOSX) {
if (what.equals("Error loading SolarisSerial: java.lang.UnsatisfiedLinkError: no SolarisSerialParallel in java.library.path")) return;
if (what.equals("Caught java.lang.UnsatisfiedLinkError: readRegistrySerial while loading driver com.sun.comm.SolarisDriver")) return;
@@ -185,7 +177,7 @@ public class PdeEditorConsole extends JScrollPane {
// to console display
appendText(what, err);
if (err) {
systemErr.print(what);
} else {
@@ -202,32 +194,20 @@ public class PdeEditorConsole extends JScrollPane {
}
}
private void appendText(String text, boolean err)
{
private void appendText(String text, boolean err) {
try {
consoleDoc.insertString(consoleDoc.getLength(), text, err ? errStyle : stdStyle);
}
catch(Exception e) {}
}
consoleDoc.insertString(consoleDoc.getLength(), text,
err ? errStyle : stdStyle);
/*
// no longer needed because setPreferredSize is used
// always move to the end of the text as it's added
consoleTextPane.setCaretPosition(consoleDoc.getLength());
public Dimension getPreferredSize() {
return getMinimumSize();
} catch (Exception e) { }
}
public Dimension getMinimumSize() {
return new Dimension(600, PdeEditor.GRID_SIZE * 3);
}
public Dimension getMaximumSize() {
return new Dimension(3000, PdeEditor.GRID_SIZE * 3);
}
*/
}
class PdeEditorConsoleStream extends OutputStream {
PdeEditorConsole parent;
boolean err; // whether stderr or stdout
@@ -269,29 +249,6 @@ class PdeEditorConsoleStream extends OutputStream {
echo = null;
}
}
/*
//System.out.println("leech2:");
if (length >= 1) {
int lastchar = b[offset + length - 1];
if (lastchar == '\r') {
length--;
} else if (lastchar == '\n') {
if (length >= 2) {
int secondtolastchar = b[offset + length - 2];
if (secondtolastchar == '\r') {
length -= 2;
} else {
length--;
}
} else {
length--;
}
}
//if ((lastchar = '\r') || (lastchar == '\n')) length--;
}
//if (b[offset + length - 1] == '\r'
parent.message("2: " + length + " " + new String(b, offset, length), err);
*/
}
public void write(int b) {
@@ -306,6 +263,5 @@ class PdeEditorConsoleStream extends OutputStream {
echo = null;
}
}
//parent.message(String.valueOf((char)b), err);
}
}