X set bg/fg color of text editing area

X add option for running with external editor
X   sets text area to not editable, changes color
X   gets new text on each run.. calls handleOpen2 or whatever
X   disables save.. save as ?
X organizing directories, save to other directories blows up
X   for now, disallow the / or : characters
X   there was a bug that required a noop() b/c of jikes or 1.3 problems
X is problem w/ beautify that it has no menu event handler?
X   write event handler, and make sure it doesn't work for external ed
This commit is contained in:
benfry
2002-09-02 00:27:18 +00:00
parent 38d21b30d9
commit de22f7b105
6 changed files with 245 additions and 85 deletions
+38 -6
View File
@@ -33,6 +33,10 @@ public class PdeBase implements ActionListener {
};
Menu serialMenu;
MenuItem saveMenuItem;
MenuItem saveAsMenuItem;
MenuItem beautifyMenuItem;
CheckboxMenuItem externalEditorItem;
static final String WINDOW_TITLE = "Proce55ing";
@@ -172,8 +176,12 @@ public class PdeBase implements ActionListener {
sketchbookMenu = new Menu("Open");
//rebuildSketchbookMenu(openMenu);
menu.add(sketchbookMenu);
menu.add(new MenuItem("Save", new MenuShortcut('S')));
menu.add(new MenuItem("Save as...", new MenuShortcut('S', true)));
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("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')));
@@ -228,16 +236,29 @@ public class PdeBase implements ActionListener {
menu.addSeparator();
}
item = new MenuItem("Beautify", new MenuShortcut('B'));
item.setEnabled(false);
menu.add(item);
menu.addActionListener(this);
beautifyMenuItem = new MenuItem("Beautify", new MenuShortcut('B'));
//item.setEnabled(false);
menu.add(beautifyMenuItem);
//menu.addSeparator();
serialMenu = new Menu("Serial Port");
menu.add(serialMenu);
buildSerialMenu();
externalEditorItem = new CheckboxMenuItem("Use External Editor");
externalEditorItem.addItemListener(new ItemListener() {
public void itemStateChanged(ItemEvent e) {
//System.out.println(e);
if (e.getStateChange() == ItemEvent.SELECTED) {
editor.setExternalEditor(true);
} else {
editor.setExternalEditor(false);
}
}
});
menu.add(externalEditorItem);
menu.addActionListener(this);
menubar.add(menu); // add the sketch menu
frame.setMenuBar(menubar);
@@ -627,6 +648,17 @@ public class PdeBase implements ActionListener {
} else if (command.equals("Refresh")) {
//System.err.println("got refresh");
rebuildSketchbookMenu(sketchbookMenu);
} else if (command.equals("Beautify")) {
editor.doBeautify();
//} else if (command.equals("Use External Editor")) {
//boolean external = externalEditorItem.getState();
//external = !external;
//editor.setExternalEditor(external);
// disable save, save as menus
}
//if (command.equals("Save QuickTime movie...")) {
// ((PdeEditor)environment).doRecord();
+57 -9
View File
@@ -33,9 +33,10 @@ public class PdeEditor extends Panel {
String openingPath;
String openingName;
static final int RUN = 5; // for history
static final int SAVE = 6;
static final int AUTO = 7;
static final int RUN = 5; // for history
static final int SAVE = 6;
static final int AUTOSAVE = 7;
static final int BEAUTIFY = 8;
PdeEditorButtons buttons;
PdeEditorHeader header;
@@ -46,6 +47,7 @@ public class PdeEditor extends Panel {
#else
JEditTextArea textarea;
#endif
boolean externalEditor;
// currently opened program
String userName; // user currently logged in
@@ -116,6 +118,10 @@ public class PdeEditor extends Panel {
textarea.setFont(PdeBase.getFont("editor.program.font",
new Font("Monospaced",
Font.PLAIN, 12)));
textarea.setForeground(PdeBase.getColor("editor.program.fgcolor",
Color.black));
textarea.setBackground(PdeBase.getColor("editor.program.bgcolor",
Color.white));
textarea.addMouseMotionListener(new MouseMotionAdapter() {
public void mouseMoved(MouseEvent e) {
frame.setCursor(Frame.CROSSHAIR_CURSOR);
@@ -249,6 +255,9 @@ public class PdeEditor extends Panel {
skNew();
}
boolean ee = new Boolean(skprops.getProperty("editor.external", "false")).booleanValue();
setExternalEditor(ee);
} catch (Exception e) {
// this exception doesn't matter, it's just the normal course of things
// the app reaches here when no sketch.properties file exists
@@ -261,7 +270,6 @@ public class PdeEditor extends Panel {
// doesn't exist, not available, make my own
skNew();
}
//rebuildSketchbookMenu(PdeBase.sketchbookMenu);
}
@@ -269,10 +277,17 @@ public class PdeEditor extends Panel {
// mode is RUN, SAVE or AUTO
public void makeHistory(String program, int mode) {
if (!base.recordingHistory) return;
//if (historyLast.equals(program) && !externalEditor) return;
if (historyLast.equals(program)) return;
String modeStr = (mode == RUN) ? "run" : ((mode == SAVE) ? "save" : "autosave");
String modeStr = null;
switch (mode) {
case RUN: modeStr = "run"; break;
case SAVE: modeStr = "save"; break;
case AUTOSAVE: modeStr = "autosave"; break;
case BEAUTIFY: modeStr = "beautify"; break;
}
//String modeStr = (mode == RUN) ? "run" : ((mode == SAVE) ? "save" : "autosave");
try {
//PrintWriter historyWriter = new PrintWriter(new OutputStreamWriter(new GZIPOutputStream(new FileOutputStream(historyFile.getPath(), true))));
@@ -356,7 +371,7 @@ public class PdeEditor extends Panel {
selection.substring(selection.indexOf("-") + 2);
// make history for the current guy
makeHistory(textarea.getText(), AUTO);
makeHistory(textarea.getText(), AUTOSAVE);
// mark editor text as having been edited
try {
@@ -413,6 +428,13 @@ public class PdeEditor extends Panel {
//System.out.println("RUNNING");
buttons.run();
if (externalEditor) {
// history gets screwed by the open..
String historySaved = historyLast;
handleOpen(sketchName, sketchFile, sketchDir);
historyLast = historySaved;
}
presenting = present;
try {
@@ -1314,6 +1336,8 @@ public class PdeEditor extends Panel {
skprops.put("sketch.directory", sketchDir.getCanonicalPath());
skprops.put("user.name", userName);
skprops.put("editor.external", externalEditor ? "true" : "false");
skprops.save(output, "auto-generated by pde, please don't touch");
} catch (IOException e) {
@@ -1327,6 +1351,8 @@ public class PdeEditor extends Panel {
public void doBeautify() {
String prog = textarea.getText();
makeHistory(prog, BEAUTIFY);
//if ((prog.charAt(0) == '#') || (prog.charAt(0) == ';')) {
//message("Only DBN code can be made beautiful.");
//buttons.clear();
@@ -1368,7 +1394,7 @@ public class PdeEditor extends Panel {
gotBlankLine = true;
}
} else {
System.out.println(level);
//System.out.println(level);
int idx = -1;
String myline = line.substring(0);
while (myline.lastIndexOf('}') != idx) {
@@ -1376,7 +1402,8 @@ public class PdeEditor extends Panel {
myline = myline.substring(idx+1);
level--;
}
for (int i = 0; i < level*2; i++) {
//for (int i = 0; i < level*2; i++) {
for (int i = 0; i < level; i++) {
buffer.append(' ');
}
buffer.append(line);
@@ -1395,10 +1422,31 @@ public class PdeEditor extends Panel {
}
}
textarea.setText(buffer.toString());
setSketchModified(true);
buttons.clear();
}
public void setExternalEditor(boolean external) {
this.externalEditor = external;
//System.out.println("setting ee to " + externalEditor);
textarea.setEditable(!external);
base.externalEditorItem.setState(external);
base.saveMenuItem.setEnabled(!external);
base.saveAsMenuItem.setEnabled(!external);
base.beautifyMenuItem.setEnabled(!external);
if (external) {
textarea.setBackground(PdeBase.getColor("editor.program.bgcolor.external", new Color(204, 204, 204)));
} else {
textarea.setBackground(PdeBase.getColor("editor.program.bgcolor",
Color.white));
}
}
/*
public void terminate() { // part of PdeEnvironment
//runner.stop();
+3
View File
@@ -32,6 +32,9 @@ public class PdeEditorListener extends KeyAdapter implements FocusListener {
public void keyPressed(KeyEvent event) {
// don't do things if the textarea isn't editable
if (editor.externalEditor) return;
// only works with TextArea, because it needs 'insert'
//TextComponent tc = (TextComponent) event.getSource();
tc = (TextArea) event.getSource();
+11 -1
View File
@@ -218,7 +218,10 @@ public class PdeEditorStatus extends Panel
editField = new TextField();
editField.addActionListener(this);
editField.addKeyListener(new KeyAdapter() {
protected void noop() { }
public void keyPressed(KeyEvent event) {
//System.out.println("got event " + event + " " + KeyEvent.VK_SPACE);
int c = event.getKeyChar();
int code = event.getKeyCode();
@@ -238,13 +241,17 @@ public class PdeEditorStatus extends Panel
(code == KeyEvent.VK_HOME) ||
(code == KeyEvent.VK_END) ||
(code == KeyEvent.VK_SHIFT)) {
//System.out.println("nothing to see here");
noop();
} else if (code == KeyEvent.VK_ESCAPE) {
unedit();
editor.buttons.clear();
event.consume();
} else if (c == ' ') {
//} else if (c == ' ') {
} else if (code == KeyEvent.VK_SPACE) {
//System.out.println("got a space");
// if a space, insert an underscore
//editField.insert("_", editField.getCaretPosition());
/* tried to play nice and see where it got me
@@ -264,15 +271,18 @@ public class PdeEditorStatus extends Panel
int end = editField.getSelectionEnd();
editField.setText(t.substring(0, start) + "_" +
t.substring(end));
editField.setCaretPosition(start+1);
event.consume();
} else if (c == '_') {
noop();
// everything fine
} else if (((code >= 'A') && (code <= 'Z')) &&
(((c >= 'A') && (c <= 'Z')) ||
((c >= 'a') && (c <= 'z')))) {
// everything fine, catches upper and lower
noop();
} else if ((c >= '0') && (c <= '9')) {
if (editField.getCaretPosition() == 0) {
+60
View File
@@ -1,3 +1,63 @@
ABOUT REV 0044
[ features ]
- can now use an external program to edit, such as bbedit on the pc or
emacs on unix. select 'use exteral editor' and the textarea will
become un-editable. you can then edit with your favorite text
editor, and the code will be updated in the window each time you hit
the 'run' button.
- added ability to set foreground and background colors of the
editor. editor.program.fgcolor and editor.program.bgcolor can be set
to your favorite color in pde.properties. also the the background
color indicating 'external editor' is in use can be set via
editor.program.bgcolor.external.
- more file i/o and data processing capabilities, see changes under
api additions
- 'beautify' is now enabled, though it may eat all your code in the
process. if it does, just go back to the previous version by using
the history menu, and get to the proce55ing website and let us know
the change of events.
[ api additions ]
- String[] loadStrings(String filename)
returns the lines of a file as entries in an array of strings
- byte[] loadBytes(String filename)
retrieves a file's contents and places them into a byte array for
easy processing
- String[] splitStrings(String what)
String[] splitStrings(String what, char splitChar)
splits a String into several smaller strings wherever there's a
space. ie. splitStrings("quick brown fox") becomes an array with
elements "quick", "brown" and "fox". the 'splitChar' is optional,
you can have the line broken up by tabs (if you use '\t') or any
other character.
- int[] splitInts(String what)
int[] splitInts(String what, char splitChar)
same as above, but parses the line as integers
- float[] splitFloats(String what)
float[] splitFloats(String what, char splitChar)
you can imagine what this one does
[ api changes ]
- getStream is now loadStream
[ bug fixes ]
- names with underscores and other illegal characters weren't being
restrained. this allowed / and : to be used when renaming/saving
sketches, which caused the app to blow up.
ABOUT REV 0043 - "ALPHA" - 2 august 2002
- this is the official "alpha" release. released for all platforms
+76 -69
View File
@@ -1,10 +1,85 @@
0044
X added optimized flat circle (not ellipse) function
X then removed it again because it's not quite finished
X need to be able to fill using the same function
X added additional file i/o functions to bagel
X loadStrings and splitInts, splitFloats, etc
X getStream is now loadStream
X set bg/fg color of text editing area
X add option for running with external editor
X sets text area to not editable, changes color
X gets new text on each run.. calls handleOpen2 or whatever
X disables save.. save as ?
X organizing directories, save to other directories blows up
X for now, disallow the / or : characters
X there was a bug that required a noop() b/c of jikes or 1.3 problems
X is problem w/ beautify that it has no menu event handler?
X write event handler, and make sure it doesn't work for external ed
language
bagel
_ need to finish fill mode of flat circle function
_ 'image' is too generic a variable to have inside BApplet
_ check for others that shouldn't be used
pde
_ don't popup offscreen if editor window is way left.
_ just make sure the x coord > 10 or so (if not presenting)
_ don't throw exceptions for serial on startup if no serial available?
_ gets upset on osx if rxtx not installed during menu building
_ as approaches 1000 lines, editorconsole has arrayindexoutof bounds
int a;
void loop()
{
a++;
println(a);
}
_ locking up on run (under win2k? others?)
_ rare but present, every 100th time or so
readme
_ mention shift-run for present mode
_ size() and background() need regular nums, no vars
_ click sketch title to rename
windows
_ use self-extractor and make sure no 8.3 filenames
_ windows 95/98/ME seems to be broken
_ ME seems to be very broken
macos
_ console scroller obscured by window resizer intruding
_ make sure space->underscore conversion working properly for 'save as'
_ file names with a space get "_ " instead of a space ?
macosx
_ include instructions for rxtx or the install itself
_ just include the .pkg, since causing exceptions now
_ use a .dmg to distribute
o viewer window shows up in odd places
_ arrow keys broken (but with shift they work..)
_ escape key not quitting presentation mode
_ apple-a for select all tries to quit
_ sketch window resizing strangely
_ can make width/height larger, but only height smaller
X check apple site for technote/bug listing
X jes grabbed examples for me
suggestions
_ make versions available w/o fonts and jre
_ lock feature for present mode (part of export to application?)
_ error messages with link to what's wrong
_ moving sketchbook folder for lab environments
_ lots of ui ideas from adrien in the bboard
_ can't copy text from console directly
o make note in readme about stderr.txt and stdout.txt
////////////////////////////////////////////////////////////////////
LANGUAGE
foreach String line (lines)
foreach (String line = lines)
@@ -31,74 +106,6 @@ emit(arrayImageX, arrayImageY)
println("arrayImageX, arrayImageY = " + arrayImageX + ", " + arrayImageY)
bagel
_ 'image' is too generic a variable to have inside BApplet
_ check for others that shouldn't be used
suggestions
_ lock feature for present mode (part of export to application?)
_ error messages with link to what's wrong
_ moving sketchbook folder for lab environments
_ lots of ui ideas from adrien in the bboard
pde
_ locking up on run (under win2k? others?)
_ rare but present, every 100th time or so
_ can't copy text from console directly
_ file names with a space get "_ " instead of a space
_ add option for running with external editor
_ sets text area to not editable, changes color
_ gets new text on each run.. calls handleOpen2 or whatever
_ disables save.. save as ?
_ set bg/fg color of text editing area
_ don't popup offscreen if editor window is way left.
_ just make sure the x coord > 10 or so (if not presenting)
_ don't throw exceptions for serial on startup if no serial available?
_ as approaches 1000 lines, editorconsole has arrayindexoutof bounds
int a;
void loop()
{
a++;
println(a);
}
sketchbook
_ organizing directories, save to other directories blows up
_ for now, disallow the / or : characters
readme
_ mention shift-run for present mode
_ size() and background() need regular nums, no vars
_ click sketch title to rename
release
_ make versions available w/o fonts and jre
windows
_ use self-extractor and make sure no 8.3 filenames
_ windows 95/98/ME seems to be broken
_ ME seems to be very broken
macos
_ console scroller obscured by window resizer intruding
macosx
_ include instructions for rxtx or the install itself
_ just include the .pkg, since causing exceptions now
_ use a .dmg to distribute
o viewer window shows up in odd places
_ arrow keys broken (but with shift they work..)
_ escape key not quitting presentation mode
_ apple-a for select all tries to quit
_ sketch window resizing strangely
_ can make width/height larger, but only height smaller
X check apple site for technote/bug listing
X jes grabbed examples for me
////////////////////////////////////////////////////////////////////
BAGEL / high
b _ better access to projX et al
b _ what's a better name? calcX? or write to an array?