mirror of
https://github.com/processing/processing4.git
synced 2026-02-02 13:21:07 +01:00
lots of changes from sunday/monday morning in japan
This commit is contained in:
@@ -111,11 +111,19 @@ public class PdeEditor extends Panel implements PdeEnvironment {
|
||||
add("North", top);
|
||||
|
||||
if (program == null) program = DEFAULT_PROGRAM;
|
||||
textarea = new TextArea(program, 20, 48);
|
||||
textarea = new TextArea(program, 20, 48,
|
||||
TextArea.SCROLLBARS_VERTICAL_ONLY );
|
||||
textarea.setFont(PdeApplet.getFont("editor"));
|
||||
//right.add("Center", textarea);
|
||||
add("Center", textarea);
|
||||
|
||||
/*
|
||||
TextArea console = new TextArea("welcome to pr0[3551ng", 5, 48,
|
||||
TextArea.SCROLLBARS_VERTICAL_ONLY);
|
||||
console.setBackground(Color.gray);
|
||||
add("South", console);
|
||||
*/
|
||||
|
||||
//#ifdef FANCY
|
||||
// right.add("South", PdeFancy.makeDescription());
|
||||
//#endif
|
||||
@@ -135,7 +143,8 @@ public class PdeEditor extends Panel implements PdeEnvironment {
|
||||
|
||||
|
||||
public void doPlay() {
|
||||
doStop();
|
||||
//doStop();
|
||||
doClose();
|
||||
playing = true;
|
||||
buttons.play();
|
||||
|
||||
@@ -146,14 +155,17 @@ public class PdeEditor extends Panel implements PdeEnvironment {
|
||||
//graphics.requestFocus(); // removed for pde
|
||||
}
|
||||
|
||||
|
||||
#ifdef RECORDER
|
||||
public void doRecord() {
|
||||
doStop();
|
||||
//doStop();
|
||||
doClose();
|
||||
PdeRecorder.start(this, graphics.width, graphics.height);
|
||||
doPlay();
|
||||
}
|
||||
#endif
|
||||
|
||||
|
||||
public void doStop() {
|
||||
#ifdef RECORDER
|
||||
if (!playing) return;
|
||||
@@ -164,6 +176,17 @@ public class PdeEditor extends Panel implements PdeEnvironment {
|
||||
}
|
||||
|
||||
|
||||
public void doClose() {
|
||||
if (playing) doStop();
|
||||
// some code to close the window here
|
||||
try {
|
||||
// runner.engine is null (runner is not)
|
||||
((KjcEngine)(runner.engine)).close();
|
||||
} catch (Exception e) { }
|
||||
buttons.clear();
|
||||
}
|
||||
|
||||
|
||||
public void doOpen() {
|
||||
FileDialog fd = new FileDialog(new Frame(),
|
||||
"Open a PDE program...",
|
||||
|
||||
@@ -7,30 +7,32 @@ import java.awt.*;
|
||||
public class PdeEditorButtons extends Panel {
|
||||
static final String EMPTY_STATUS = " ";
|
||||
|
||||
static final int BUTTON_COUNT = 9;
|
||||
static final int BUTTON_WIDTH = 24;
|
||||
static final int BUTTON_HEIGHT = 24;
|
||||
|
||||
static final String title[] = {
|
||||
"Play", "Stop",
|
||||
"Play", "Stop", "Close",
|
||||
"Open", "Save", "Save on Server", "Print", "Beautify",
|
||||
"Disable Full Screen", "Full Screen"
|
||||
};
|
||||
|
||||
static final int PLAY = 0;
|
||||
static final int STOP = 1;
|
||||
static final int OPEN = 2;
|
||||
static final int SAVE = 3;
|
||||
static final int SNAPSHOT = 4; // only available is save_as defined
|
||||
static final int PRINT = 5;
|
||||
static final int BEAUTIFY = 6;
|
||||
static final int BUTTON_COUNT = title.length;
|
||||
static final int BUTTON_WIDTH = 24;
|
||||
static final int BUTTON_HEIGHT = 24;
|
||||
|
||||
static final int DISABLE_FULL_SCREEN = 7;
|
||||
static final int FULL_SCREEN = 8;
|
||||
static final int PLAY = 0;
|
||||
static final int STOP = 1;
|
||||
static final int CLOSE = 2;
|
||||
|
||||
static final int OPEN = 3;
|
||||
static final int SAVE = 4;
|
||||
static final int SNAPSHOT = 5; // only available is save_as defined
|
||||
static final int PRINT = 6;
|
||||
static final int BEAUTIFY = 7;
|
||||
|
||||
static final int DISABLE_FULL_SCREEN = 8;
|
||||
static final int FULL_SCREEN = 9;
|
||||
|
||||
static final int INACTIVE = 0;
|
||||
static final int ROLLOVER = 1;
|
||||
static final int ACTIVE = 2;
|
||||
static final int ACTIVE = 2;
|
||||
|
||||
PdeEditor editor;
|
||||
Label status;
|
||||
@@ -65,6 +67,7 @@ public class PdeEditorButtons extends Panel {
|
||||
// always include these
|
||||
which[buttonCount++] = PLAY;
|
||||
which[buttonCount++] = STOP;
|
||||
which[buttonCount++] = CLOSE;
|
||||
|
||||
// the rest are conditional
|
||||
if (useOpenSave) {
|
||||
@@ -138,7 +141,7 @@ public class PdeEditorButtons extends Panel {
|
||||
x1[i] = offsetX;
|
||||
x2[i] = offsetX + BUTTON_WIDTH;
|
||||
offsetX += BUTTON_WIDTH + 4;
|
||||
if (i == 1) offsetX += 8; // extra space after play/stop
|
||||
if (i == 2) offsetX += 8; // extra space after play/stop/close
|
||||
}
|
||||
|
||||
/*
|
||||
@@ -279,6 +282,7 @@ public class PdeEditorButtons extends Panel {
|
||||
|
||||
case PLAY: editor.doPlay(); break;
|
||||
case STOP: setState(PLAY, INACTIVE, true); editor.doStop(); break;
|
||||
case CLOSE: editor.doClose(); break;
|
||||
|
||||
case OPEN: editor.doOpen(); break;
|
||||
case SAVE: editor.doSave(); break;
|
||||
@@ -347,7 +351,7 @@ public class PdeEditorButtons extends Panel {
|
||||
|
||||
|
||||
public Dimension preferredSize() {
|
||||
return new Dimension(200, 35);
|
||||
return new Dimension(220, 35);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
@@ -1,4 +1,5 @@
|
||||
public interface PdeEngine {
|
||||
public void start() throws PdeException;
|
||||
public void stop();
|
||||
public void close();
|
||||
}
|
||||
|
||||
@@ -4,14 +4,25 @@ public class PdeException extends Exception {
|
||||
public PdeException() { }
|
||||
|
||||
public PdeException(String message) {
|
||||
super(message);
|
||||
super(massage(message));
|
||||
//System.out.println("message for this error is " + message);
|
||||
}
|
||||
|
||||
public PdeException(String message, int line) {
|
||||
super(message);
|
||||
super(massage(message));
|
||||
this.line = line;
|
||||
}
|
||||
|
||||
// make static so that super() can call it
|
||||
static public final String massage(String msg) {
|
||||
if (msg.indexOf("java.lang.") == 0) {
|
||||
//int dot = msg.lastIndexOf('.');
|
||||
msg = msg.substring("java.lang.".length());
|
||||
}
|
||||
return msg;
|
||||
//return (dot == -1) ? msg : msg.substring(dot+1);
|
||||
}
|
||||
|
||||
#ifndef PLAYER
|
||||
#ifdef DBN
|
||||
public PdeException(String message, DbnToken token) {
|
||||
|
||||
@@ -117,10 +117,26 @@ public class PdeRunner implements Runnable {
|
||||
|
||||
engine = new KjcEngine(program, env);
|
||||
engine.start();
|
||||
|
||||
/*
|
||||
while (!((KjcEngine)engine).applet.finished) {
|
||||
System.out.println("waiting");
|
||||
try {
|
||||
Thread.sleep(500);
|
||||
} catch (InterruptedException e) { }
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
// maybe this code shouldn't be called automatically,
|
||||
// and instead ProcessingApplet and the others
|
||||
// must call it explicitly
|
||||
//System.out.println("finished");
|
||||
/*
|
||||
state = RUNNER_FINISHED;
|
||||
System.out.println("finishing");
|
||||
env.finished();
|
||||
*/
|
||||
//graphics.update(); // removed for pde
|
||||
|
||||
} catch (PdeException e) {
|
||||
@@ -138,6 +154,12 @@ public class PdeRunner implements Runnable {
|
||||
}
|
||||
|
||||
|
||||
public void finished() { // called by KjcProcessingApplet or something
|
||||
state = RUNNER_FINISHED;
|
||||
env.finished();
|
||||
}
|
||||
|
||||
|
||||
public void stop() {
|
||||
if (engine != null) {
|
||||
engine.stop();
|
||||
@@ -147,7 +169,8 @@ public class PdeRunner implements Runnable {
|
||||
thread = null;
|
||||
}
|
||||
*/
|
||||
engine = null;
|
||||
// is this necessary [fry]
|
||||
//engine = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -33,7 +33,7 @@ public class ProcessingApplet extends Applet
|
||||
|
||||
int width, height;
|
||||
|
||||
PrintStream errStream;
|
||||
//PrintStream errStream;
|
||||
|
||||
|
||||
public void init() {
|
||||
@@ -130,68 +130,69 @@ public class ProcessingApplet extends Applet
|
||||
public void run() {
|
||||
while ((Thread.currentThread() == thread) && !finished) {
|
||||
|
||||
try {
|
||||
// setup
|
||||
if (timing) {
|
||||
actualMillis = System.currentTimeMillis();
|
||||
calendar = null;
|
||||
}
|
||||
if (timing) {
|
||||
actualMillis = System.currentTimeMillis();
|
||||
calendar = null;
|
||||
}
|
||||
|
||||
// attempt to draw a static image using draw()
|
||||
if (!drawn) {
|
||||
// always do this once. empty if not overridden
|
||||
g.beginFrame();
|
||||
draw();
|
||||
if (!drawMethod) {
|
||||
// that frame was bogus, mark it as such
|
||||
// before ending the frame so that it doesn't get
|
||||
// saved to a quicktime movie or whatever
|
||||
|
||||
// might be as simple as not calling endFrame?
|
||||
}
|
||||
if (drawMethod) {
|
||||
g.endFrame();
|
||||
update();
|
||||
finished = true;
|
||||
}
|
||||
drawn = true;
|
||||
}
|
||||
|
||||
// if not a static app, run the loop
|
||||
// attempt to draw a static image using draw()
|
||||
if (!drawn) {
|
||||
// always do this once. empty if not overridden
|
||||
g.beginFrame();
|
||||
draw();
|
||||
if (!drawMethod) {
|
||||
g.beginFrame();
|
||||
loop();
|
||||
// that frame was bogus, mark it as such
|
||||
// before ending the frame so that it doesn't get
|
||||
// saved to a quicktime movie or whatever
|
||||
|
||||
// might be as simple as not calling endFrame?
|
||||
}
|
||||
if (drawMethod) {
|
||||
g.endFrame();
|
||||
update();
|
||||
}
|
||||
|
||||
// takedown
|
||||
if (!loopMethod) {
|
||||
finished = true;
|
||||
}
|
||||
drawn = true;
|
||||
}
|
||||
|
||||
if (mousePressedBriefly) {
|
||||
mousePressedBriefly = false;
|
||||
mousePressed = false;
|
||||
}
|
||||
// if not a static app, run the loop
|
||||
if (!drawMethod) {
|
||||
g.beginFrame();
|
||||
loop();
|
||||
g.endFrame();
|
||||
update();
|
||||
}
|
||||
|
||||
if (keyPressedBriefly) {
|
||||
keyPressedBriefly = false;
|
||||
keyPressed = false;
|
||||
}
|
||||
// takedown
|
||||
if (!loopMethod) {
|
||||
finished = true;
|
||||
}
|
||||
|
||||
if (mousePressedBriefly) {
|
||||
mousePressedBriefly = false;
|
||||
mousePressed = false;
|
||||
}
|
||||
|
||||
if (keyPressedBriefly) {
|
||||
keyPressedBriefly = false;
|
||||
keyPressed = false;
|
||||
}
|
||||
|
||||
/*
|
||||
// with any luck, kjcengine will be listening
|
||||
// and slurp this right up
|
||||
} catch (Exception e) {
|
||||
} catch (Exception e) {
|
||||
//System.out.println("exception caught in run");
|
||||
//System.err.println("i'm here in err");
|
||||
if (errStream != null) {
|
||||
errStream.print("MAKE WAY");
|
||||
e.printStackTrace(errStream);
|
||||
errStream.print("MAKE WAY");
|
||||
e.printStackTrace(errStream);
|
||||
} else {
|
||||
e.printStackTrace();
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// sleep to make OS happy
|
||||
try {
|
||||
thread.sleep(5);
|
||||
@@ -295,27 +296,31 @@ public class ProcessingApplet extends Applet
|
||||
}
|
||||
|
||||
public int getSecond() {
|
||||
//calendar.setTimeInMillis(actualMillis);
|
||||
if (calendar == null) calendar = Calendar.getInstance();
|
||||
return calendar.get(Calendar.SECOND);
|
||||
}
|
||||
|
||||
public int getMinute() {
|
||||
if (calendar == null) calendar = Calendar.getInstance();
|
||||
//calendar.setTimeInMillis(actualMillis);
|
||||
return calendar.get(Calendar.MINUTE);
|
||||
}
|
||||
|
||||
public int getHour() {
|
||||
if (calendar == null) calendar = Calendar.getInstance();
|
||||
//calendar.setTimeInMillis(actualMillis);
|
||||
return calendar.get(Calendar.HOUR_OF_DAY);
|
||||
}
|
||||
|
||||
// if users want day of week or day of year,
|
||||
// they can add their own functions
|
||||
public int getDay() {
|
||||
if (calendar == null) calendar = Calendar.getInstance();
|
||||
return calendar.get(Calendar.DAY_OF_MONTH);
|
||||
}
|
||||
|
||||
public int getMonth() {
|
||||
if (calendar == null) calendar = Calendar.getInstance();
|
||||
//calendar.setTimeInMillis(actualMillis);
|
||||
return calendar.get(Calendar.MONTH);
|
||||
// months are number 0..11 so change to colloquial 1..12
|
||||
return calendar.get(Calendar.MONTH) + 1;
|
||||
}
|
||||
|
||||
public int getYear() {
|
||||
@@ -324,6 +329,57 @@ public class ProcessingApplet extends Applet
|
||||
return calendar.get(Calendar.YEAR);
|
||||
}
|
||||
|
||||
public void delay(int howlong) {
|
||||
long stop = System.currentTimeMillis() + (long)howlong;
|
||||
while (System.currentTimeMillis() < stop) { }
|
||||
return;
|
||||
}
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
|
||||
|
||||
public void print(boolean what) {
|
||||
System.out.print(what);
|
||||
}
|
||||
|
||||
public void print(int what) {
|
||||
System.out.print(what);
|
||||
}
|
||||
|
||||
public void print(float what) {
|
||||
System.out.print(what);
|
||||
}
|
||||
|
||||
public void print(String what) {
|
||||
System.out.print(what);
|
||||
}
|
||||
|
||||
public void println(boolean what) {
|
||||
print(what); System.out.println();
|
||||
}
|
||||
|
||||
public void println(int what) {
|
||||
print(what); System.out.println();
|
||||
}
|
||||
|
||||
public void println(float what) {
|
||||
print(what); System.out.println();
|
||||
}
|
||||
|
||||
public void println(String what) {
|
||||
print(what); System.out.println();
|
||||
}
|
||||
|
||||
public void println() {
|
||||
System.out.println();
|
||||
}
|
||||
|
||||
// would be nice to have a way to write messages to the
|
||||
// console (whether in the browser or the environment)
|
||||
// this might be part of adding an AppletContext to the
|
||||
// environment.
|
||||
|
||||
|
||||
// ------------------------------------------------------------
|
||||
|
||||
@@ -727,6 +783,14 @@ public class ProcessingApplet extends Applet
|
||||
g.background(x, y, z);
|
||||
}
|
||||
|
||||
public void lightsOn() {
|
||||
g.lightsOn();
|
||||
}
|
||||
|
||||
public void lightsOff() {
|
||||
g.lightsOff();
|
||||
}
|
||||
|
||||
public void message(int level, String message) {
|
||||
g.message(level, message);
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user