mirror of
https://github.com/processing/processing4.git
synced 2026-06-16 04:26:26 +02:00
pde applet / application -> pdebase, and all the mess that entails..
remove lots of dead code from dbn
This commit is contained in:
@@ -1,376 +0,0 @@
|
||||
#ifndef KVM
|
||||
|
||||
|
||||
import java.awt.*;
|
||||
import java.applet.Applet;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
|
||||
|
||||
public class PdeApplet extends Applet
|
||||
{
|
||||
static PdeApplet applet;
|
||||
static Properties properties;
|
||||
boolean errorState;
|
||||
|
||||
#ifndef PLAYER
|
||||
String encoding;
|
||||
//PdeEnvironment environment;
|
||||
PdeEditor editor;
|
||||
#endif
|
||||
|
||||
public void init() {
|
||||
applet = this;
|
||||
//System.getProperties().list(System.out);
|
||||
//System.out.println("home = " + System.getProperty("user.home"));
|
||||
//System.out.println("prefix = " + System.getProperty("sys.prefix"));
|
||||
|
||||
#ifdef PLAYER
|
||||
// because it's the player version, cut out all the
|
||||
// other crap, so that this file is as small as possible
|
||||
|
||||
//} else if (mode.equals("player")) {
|
||||
// could also do a class.forname for jdk11
|
||||
//PdePlayerProgram dpp = new PdePlayerProgram(this);
|
||||
try {
|
||||
String program = get("program");
|
||||
PdePlayer player =
|
||||
((PdePlayer) Class.forName(program).newInstance());
|
||||
add(player);
|
||||
//editor = player;
|
||||
player.init(this);
|
||||
player.start();
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
errorState = true;
|
||||
}
|
||||
#else
|
||||
encoding = get("encoding");
|
||||
|
||||
#ifdef DBN
|
||||
new DbnPreprocessor(this);
|
||||
#endif
|
||||
|
||||
String mode = get("mode", "editor");
|
||||
//System.err.println("mode is " + mode);
|
||||
if (mode.equals("editor")) {
|
||||
#ifdef EDITOR
|
||||
//System.err.println("editor not yet complete");
|
||||
//System.err.println("editor dammit");
|
||||
//System.exit(0);
|
||||
boolean beautify = false;
|
||||
boolean convertSemicolons = false;
|
||||
String program = get("program");
|
||||
if (program != null) {
|
||||
program = readFile(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
//add(hostess = new PdeEditor(this, program));
|
||||
//PdeEditor editor = new PdeEditor(this, program);
|
||||
editor = new PdeEditor(this, program);
|
||||
//if (beautify) editor.doBeautify();
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
add("Center", editor);
|
||||
//editor = editor;
|
||||
|
||||
//convert();
|
||||
#endif
|
||||
|
||||
/*
|
||||
} else if (mode.equals("grid")) {
|
||||
// read 1 or more programs to be laid out in grid mode
|
||||
// first count how many programs
|
||||
int counter = 0;
|
||||
while (true) {
|
||||
if (get("program" + counter) == null)
|
||||
break;
|
||||
counter++;
|
||||
}
|
||||
// next load the programs
|
||||
// what to do if zero programs in griddify?
|
||||
String filenames[] = new String[counter];
|
||||
String programs[] = new String[counter];
|
||||
for (int i = 0; i < counter; i++) {
|
||||
String filename = get("program" + i);
|
||||
programs[i] = readFile(filename);
|
||||
}
|
||||
PdeGrid grid = new PdeGrid(this, programs);
|
||||
setLayout(new BorderLayout());
|
||||
add("Center", grid);
|
||||
environment = grid;
|
||||
*/
|
||||
|
||||
} else if (mode.equals("none")) {
|
||||
// don't do anything, handled by subclass
|
||||
}
|
||||
#endif PLAYER
|
||||
}
|
||||
|
||||
|
||||
#ifndef PLAYER
|
||||
public void destroy() {
|
||||
if (editor != null) {
|
||||
editor.terminate();
|
||||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
/*
|
||||
#ifdef EDITOR
|
||||
// this is used by PdeFancy, but could be useful in other
|
||||
// contexts as well, i would imagine
|
||||
public void setProgram(String p) {
|
||||
if (environment instanceof PdeEditor) {
|
||||
((PdeEditor)environment).setProgram(p);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
public void paint(Graphics g) {
|
||||
if (errorState) {
|
||||
g.setColor(Color.red);
|
||||
Dimension d = size();
|
||||
g.fillRect(0, 0, d.width, d.height);
|
||||
//} else {
|
||||
//super(g);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifndef PLAYER
|
||||
/* loading order:
|
||||
* 0. if application, a file on the disk
|
||||
* 1. a file relative to the .html file containing the applet
|
||||
* 2. a url
|
||||
* 3. a file relative to the .class files
|
||||
*/
|
||||
public String readFile(String filename) {
|
||||
if (filename.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
URL url;
|
||||
InputStream stream = null;
|
||||
String openMe;
|
||||
byte temp[] = new byte[65536]; // 64k, 16k was too small
|
||||
|
||||
try {
|
||||
// this is two cases, one is bound to throw (or work)
|
||||
if (isApplet()) {
|
||||
// Try to open it relative to the document base
|
||||
url = new URL(getDocumentBase(), filename);
|
||||
stream = url.openStream();
|
||||
} else {
|
||||
// if running as an application, get file from disk
|
||||
stream = new FileInputStream(filename);
|
||||
}
|
||||
|
||||
} catch (Exception e1) { try {
|
||||
if (isApplet()) {
|
||||
// now try to open it relative to the code base
|
||||
url = new URL(getCodeBase(), filename);
|
||||
stream = url.openStream();
|
||||
} else {
|
||||
url = getClass().getResource(filename);
|
||||
stream = url.openStream();
|
||||
}
|
||||
|
||||
} catch (Exception e2) { try {
|
||||
// Try to open the param string as a URL
|
||||
url = new URL(filename);
|
||||
stream = url.openStream();
|
||||
|
||||
} catch (Exception e3) {
|
||||
//e1.printStackTrace();
|
||||
//e2.printStackTrace();
|
||||
return null;
|
||||
} } }
|
||||
|
||||
try {
|
||||
int offset = 0;
|
||||
while (true) {
|
||||
int byteCount = stream.read(temp, offset, 1024);
|
||||
if (byteCount <= 0) break;
|
||||
offset += byteCount;
|
||||
}
|
||||
byte program[] = new byte[offset];
|
||||
System.arraycopy(temp, 0, program, 0, offset);
|
||||
|
||||
//return languageEncode(program);
|
||||
// convert the bytes based on the current encoding
|
||||
try {
|
||||
if (encoding == null)
|
||||
return new String(program);
|
||||
return new String(program, encoding);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
encoding = null;
|
||||
return new String(program);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("problem during download");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
#ifdef EDITOR
|
||||
static public Image readImage(String name) {
|
||||
Image image = null;
|
||||
if (isApplet()) {
|
||||
image = applet.getImage(applet.getCodeBase(), name);
|
||||
} else {
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
image = tk.getImage("lib/" + name);
|
||||
//URL url = PdeApplet.class.getResource(name);
|
||||
//image = tk.getImage(url);
|
||||
}
|
||||
MediaTracker tracker = new MediaTracker(applet);
|
||||
tracker.addImage(image, 0);
|
||||
try {
|
||||
tracker.waitForAll();
|
||||
} catch (InterruptedException e) { }
|
||||
return image;
|
||||
}
|
||||
#endif // EDITOR
|
||||
|
||||
#endif // !PLAYER
|
||||
|
||||
// all the information from PdeProperties
|
||||
|
||||
static public String get(String attribute) {
|
||||
return get(attribute, null);
|
||||
}
|
||||
|
||||
static public String get(String attribute, String defaultValue) {
|
||||
String value = (properties != null) ?
|
||||
properties.getProperty(attribute) : applet.getParameter(attribute);
|
||||
|
||||
return (value == null) ?
|
||||
defaultValue : value;
|
||||
}
|
||||
|
||||
#ifndef PLAYER
|
||||
static public boolean getBoolean(String attribute, boolean defaultValue) {
|
||||
String value = get(attribute, null);
|
||||
return (value == null) ? defaultValue :
|
||||
(new Boolean(value)).booleanValue();
|
||||
}
|
||||
|
||||
static public int getInteger(String attribute, int defaultValue) {
|
||||
String value = get(attribute, null);
|
||||
return (value == null) ? defaultValue :
|
||||
Integer.parseInt(value);
|
||||
}
|
||||
|
||||
static public Color getColor(String name, Color otherwise) {
|
||||
Color parsed = null;
|
||||
String s = get(name, null);
|
||||
if ((s != null) && (s.indexOf("#") == 0)) {
|
||||
try {
|
||||
int v = Integer.parseInt(s.substring(1), 16);
|
||||
parsed = new Color(v);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (parsed == null) return otherwise;
|
||||
return parsed;
|
||||
}
|
||||
|
||||
static public boolean isMacintosh() {
|
||||
return System.getProperty("os.name").toLowerCase().indexOf("mac") != -1;
|
||||
}
|
||||
|
||||
static public boolean hasFullPrivileges() {
|
||||
//if (applet == null) return true; // application
|
||||
//return false;
|
||||
return !isApplet();
|
||||
}
|
||||
|
||||
static public Font getFont(String which, Font otherwise) {
|
||||
//System.out.println("getting font '" + which + "'");
|
||||
String str = get(which);
|
||||
if (str == null) return otherwise; // ENABLE LATER
|
||||
StringTokenizer st = new StringTokenizer(str, ",");
|
||||
return new Font(st.nextToken(),
|
||||
st.nextToken().equals("bold") ? Font.BOLD : Font.PLAIN,
|
||||
Integer.parseInt(st.nextToken()));
|
||||
}
|
||||
#endif // PLAYER
|
||||
|
||||
public String getNetServer() {
|
||||
String host = get("net_server", null);
|
||||
if (host != null) return host;
|
||||
|
||||
if (isApplet()) {
|
||||
return getCodeBase().getHost();
|
||||
}
|
||||
return "dbn.media.mit.edu";
|
||||
}
|
||||
|
||||
static public boolean isApplet() {
|
||||
return (properties == null);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#else // if it is the KVM
|
||||
|
||||
|
||||
public class PdeApplet {
|
||||
public PdeApplet() {
|
||||
}
|
||||
|
||||
String get(String something) {
|
||||
return get(something, null);
|
||||
}
|
||||
|
||||
String get(String something, String otherwise) {
|
||||
return null;
|
||||
}
|
||||
|
||||
String readFile(String name) {
|
||||
// grab something out of the database
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
#endif
|
||||
|
||||
|
||||
/* temporary, a little something for the kids */
|
||||
/*
|
||||
static public void debugString(String s) {
|
||||
byte output[] = s.getBytes();
|
||||
for (int i = 0; i < output.length; i++) {
|
||||
if (output[i] >= 32) {
|
||||
System.out.print((char)output[i]);
|
||||
} else {
|
||||
System.out.print("\\" + (int)output[i]);
|
||||
if (output[i] == '\n') System.out.println();
|
||||
}
|
||||
}
|
||||
System.out.println();
|
||||
}
|
||||
*/
|
||||
@@ -1,104 +0,0 @@
|
||||
import java.awt.*;
|
||||
import java.applet.Applet;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
|
||||
public class PdeApplication extends PdeApplet
|
||||
#ifdef RECORDER
|
||||
implements ActionListener
|
||||
#endif
|
||||
{
|
||||
// made static so that toFront() can be called by
|
||||
// full screen code in editor
|
||||
static Frame frame;
|
||||
WindowAdapter windowListener;
|
||||
|
||||
//static final String WINDOW_TITLE = " P r o c e 5 5 i n g ");
|
||||
static final String WINDOW_TITLE = "Proce55ing";
|
||||
|
||||
static public void main(String args[]) {
|
||||
PdeApplication app = new PdeApplication();
|
||||
//if (args.length != 0) {
|
||||
//app.setProgramFile(args[0]);
|
||||
//}
|
||||
|
||||
// this is getting moved back inside the constructor
|
||||
// because it was for pockyvision, which is going away
|
||||
//app.frame.show();
|
||||
}
|
||||
|
||||
public PdeApplication() {
|
||||
frame = new Frame(WINDOW_TITLE);
|
||||
|
||||
windowListener = new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
};
|
||||
frame.addWindowListener(windowListener);
|
||||
|
||||
#ifdef RECORDER
|
||||
MenuBar menubar = new MenuBar();
|
||||
Menu goodies = new Menu("Processing");
|
||||
goodies.add(new MenuItem("Save QuickTime movie..."));
|
||||
goodies.add(new MenuItem("Quit"));
|
||||
goodies.addActionListener(this);
|
||||
menubar.add(goodies);
|
||||
frame.setMenuBar(menubar);
|
||||
#endif
|
||||
|
||||
properties = new Properties();
|
||||
try {
|
||||
properties.load(new FileInputStream("lib/pde.properties"));
|
||||
|
||||
} 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);
|
||||
// ms jdk requires that BorderLayout is set explicitly
|
||||
frame.setLayout(new BorderLayout());
|
||||
frame.add("Center", this);
|
||||
init();
|
||||
|
||||
Insets insets = frame.getInsets();
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
Dimension screen = tk.getScreenSize();
|
||||
int frameX = getInteger("window.x", (screen.width - width) / 2);
|
||||
int frameY = getInteger("window.y", (screen.height - height) / 2);
|
||||
|
||||
frame.setBounds(frameX, frameY,
|
||||
width + insets.left + insets.right,
|
||||
height + insets.top + insets.bottom);
|
||||
//frame.reshape(50, 50, width + insets.left + insets.right,
|
||||
// height + insets.top + insets.bottom);
|
||||
|
||||
// i don't like this being here, but..
|
||||
//((PdeEditor)environment).graphics.frame = frame;
|
||||
//((PdeEditor)environment).frame = frame;
|
||||
editor.frame = frame;
|
||||
|
||||
frame.pack();
|
||||
frame.show(); // added back in for pde
|
||||
}
|
||||
|
||||
|
||||
|
||||
#ifdef RECORDER
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String command = event.getActionCommand();
|
||||
if (command.equals("Save QuickTime movie...")) {
|
||||
((PdeEditor)environment).doRecord();
|
||||
} else if (command.equals("Quit")) {
|
||||
System.exit(0);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
#endif
|
||||
@@ -0,0 +1,300 @@
|
||||
import java.awt.*;
|
||||
import java.applet.Applet;
|
||||
import java.io.*;
|
||||
import java.net.*;
|
||||
import java.util.*;
|
||||
import java.awt.event.*;
|
||||
|
||||
|
||||
public class PdeBase /*extends Component*/ implements ActionListener {
|
||||
//static PdeApplet applet;
|
||||
static Properties properties;
|
||||
boolean errorState;
|
||||
|
||||
String encoding;
|
||||
PdeEditor editor;
|
||||
|
||||
// made static so that toFront() can be called by
|
||||
// full screen code in editor
|
||||
static Frame frame;
|
||||
WindowAdapter windowListener;
|
||||
|
||||
static final String WINDOW_TITLE = "Proce55ing";
|
||||
|
||||
static public void main(String args[]) {
|
||||
PdeBase app = new PdeBase();
|
||||
}
|
||||
|
||||
|
||||
public PdeBase() {
|
||||
frame = new Frame(WINDOW_TITLE);
|
||||
|
||||
windowListener = new WindowAdapter() {
|
||||
public void windowClosing(WindowEvent e) {
|
||||
System.exit(0);
|
||||
}
|
||||
};
|
||||
frame.addWindowListener(windowListener);
|
||||
|
||||
#ifdef RECORDER
|
||||
MenuBar menubar = new MenuBar();
|
||||
Menu goodies = new Menu("Processing");
|
||||
goodies.add(new MenuItem("Save QuickTime movie..."));
|
||||
goodies.add(new MenuItem("Quit"));
|
||||
goodies.addActionListener(this);
|
||||
menubar.add(goodies);
|
||||
frame.setMenuBar(menubar);
|
||||
#endif
|
||||
|
||||
properties = new Properties();
|
||||
try {
|
||||
properties.load(new FileInputStream("lib/pde.properties"));
|
||||
|
||||
} 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);
|
||||
// ms jdk requires that BorderLayout is set explicitly
|
||||
//frame.add("Center", this);
|
||||
|
||||
//applet = this;
|
||||
//System.getProperties().list(System.out);
|
||||
//System.out.println("home = " + System.getProperty("user.home"));
|
||||
//System.out.println("prefix = " + System.getProperty("sys.prefix"));
|
||||
|
||||
encoding = get("encoding");
|
||||
|
||||
//String mode = get("mode", "editor");
|
||||
//System.err.println("mode is " + mode);
|
||||
//if (mode.equals("editor")) {
|
||||
|
||||
//System.err.println("editor not yet complete");
|
||||
//System.err.println("editor dammit");
|
||||
//System.exit(0);
|
||||
boolean beautify = false;
|
||||
boolean convertSemicolons = false;
|
||||
String program = get("program");
|
||||
if (program != null) {
|
||||
program = readFile(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;
|
||||
}
|
||||
}
|
||||
}
|
||||
//add(hostess = new PdeEditor(this, program));
|
||||
//PdeEditor editor = new PdeEditor(this, program);
|
||||
editor = new PdeEditor(/*this,*/ program);
|
||||
//if (beautify) editor.doBeautify();
|
||||
|
||||
frame.setLayout(new BorderLayout());
|
||||
//setLayout(new BorderLayout());
|
||||
//add("Center", editor);
|
||||
frame.add("Center", editor);
|
||||
|
||||
Insets insets = frame.getInsets();
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
Dimension screen = tk.getScreenSize();
|
||||
int frameX = getInteger("window.x", (screen.width - width) / 2);
|
||||
int frameY = getInteger("window.y", (screen.height - height) / 2);
|
||||
|
||||
frame.setBounds(frameX, frameY,
|
||||
width + insets.left + insets.right,
|
||||
height + insets.top + insets.bottom);
|
||||
//frame.reshape(50, 50, width + insets.left + insets.right,
|
||||
// height + insets.top + insets.bottom);
|
||||
|
||||
// i don't like this being here, but..
|
||||
//((PdeEditor)environment).graphics.frame = frame;
|
||||
//((PdeEditor)environment).frame = frame;
|
||||
editor.frame = frame;
|
||||
|
||||
frame.pack();
|
||||
frame.show(); // added back in for pde
|
||||
}
|
||||
|
||||
|
||||
public void actionPerformed(ActionEvent event) {
|
||||
String command = event.getActionCommand();
|
||||
//if (command.equals("Save QuickTime movie...")) {
|
||||
// ((PdeEditor)environment).doRecord();
|
||||
//} else if (command.equals("Quit")) {
|
||||
// System.exit(0);
|
||||
//}
|
||||
}
|
||||
|
||||
|
||||
// does this do anything useful?
|
||||
public void destroy() {
|
||||
if (editor != null) {
|
||||
editor.terminate();
|
||||
}
|
||||
}
|
||||
|
||||
/*
|
||||
public void paint(Graphics g) {
|
||||
if (errorState) {
|
||||
g.setColor(Color.red);
|
||||
Dimension d = size();
|
||||
g.fillRect(0, 0, d.width, d.height);
|
||||
}
|
||||
}
|
||||
*/
|
||||
|
||||
// this could be pruned further
|
||||
public String readFile(String filename) {
|
||||
if (filename.length() == 0) {
|
||||
return null;
|
||||
}
|
||||
URL url;
|
||||
InputStream stream = null;
|
||||
String openMe;
|
||||
byte temp[] = new byte[65536]; // 64k, 16k was too small
|
||||
|
||||
try {
|
||||
// if running as an application, get file from disk
|
||||
stream = new FileInputStream(filename);
|
||||
|
||||
} catch (Exception e1) { try {
|
||||
url = getClass().getResource(filename);
|
||||
stream = url.openStream();
|
||||
|
||||
} catch (Exception e2) { try {
|
||||
// Try to open the param string as a URL
|
||||
url = new URL(filename);
|
||||
stream = url.openStream();
|
||||
|
||||
} catch (Exception e3) {
|
||||
return null;
|
||||
} } }
|
||||
|
||||
try {
|
||||
int offset = 0;
|
||||
while (true) {
|
||||
int byteCount = stream.read(temp, offset, 1024);
|
||||
if (byteCount <= 0) break;
|
||||
offset += byteCount;
|
||||
}
|
||||
byte program[] = new byte[offset];
|
||||
System.arraycopy(temp, 0, program, 0, offset);
|
||||
|
||||
//return languageEncode(program);
|
||||
// convert the bytes based on the current encoding
|
||||
try {
|
||||
if (encoding == null)
|
||||
return new String(program);
|
||||
return new String(program, encoding);
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
e.printStackTrace();
|
||||
encoding = null;
|
||||
return new String(program);
|
||||
}
|
||||
|
||||
} catch (Exception e) {
|
||||
System.err.println("problem during download");
|
||||
e.printStackTrace();
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
// used by PdeEditorButtons
|
||||
static public Image readImage(String name) {
|
||||
Image image = null;
|
||||
//if (isApplet()) {
|
||||
//image = applet.getImage(applet.getCodeBase(), name);
|
||||
//} else {
|
||||
Toolkit tk = Toolkit.getDefaultToolkit();
|
||||
image = tk.getImage("lib/" + name);
|
||||
//URL url = PdeApplet.class.getResource(name);
|
||||
//image = tk.getImage(url);
|
||||
//}
|
||||
//MediaTracker tracker = new MediaTracker(applet);
|
||||
MediaTracker tracker = new MediaTracker(frame);
|
||||
tracker.addImage(image, 0);
|
||||
try {
|
||||
tracker.waitForAll();
|
||||
} catch (InterruptedException e) { }
|
||||
return image;
|
||||
}
|
||||
|
||||
|
||||
// all the information from pde.properties
|
||||
|
||||
static public String get(String attribute) {
|
||||
return get(attribute, null);
|
||||
}
|
||||
|
||||
static public String get(String attribute, String defaultValue) {
|
||||
//String value = (properties != null) ?
|
||||
//properties.getProperty(attribute) : applet.getParameter(attribute);
|
||||
String value = properties.getProperty(attribute);
|
||||
|
||||
return (value == null) ?
|
||||
defaultValue : value;
|
||||
}
|
||||
|
||||
static public boolean getBoolean(String attribute, boolean defaultValue) {
|
||||
String value = get(attribute, null);
|
||||
return (value == null) ? defaultValue :
|
||||
(new Boolean(value)).booleanValue();
|
||||
}
|
||||
|
||||
static public int getInteger(String attribute, int defaultValue) {
|
||||
String value = get(attribute, null);
|
||||
return (value == null) ? defaultValue :
|
||||
Integer.parseInt(value);
|
||||
}
|
||||
|
||||
static public Color getColor(String name, Color otherwise) {
|
||||
Color parsed = null;
|
||||
String s = get(name, null);
|
||||
if ((s != null) && (s.indexOf("#") == 0)) {
|
||||
try {
|
||||
int v = Integer.parseInt(s.substring(1), 16);
|
||||
parsed = new Color(v);
|
||||
} catch (Exception e) {
|
||||
}
|
||||
}
|
||||
if (parsed == null) return otherwise;
|
||||
return parsed;
|
||||
}
|
||||
|
||||
static public Font getFont(String which, Font otherwise) {
|
||||
//System.out.println("getting font '" + which + "'");
|
||||
String str = get(which);
|
||||
if (str == null) return otherwise; // ENABLE LATER
|
||||
StringTokenizer st = new StringTokenizer(str, ",");
|
||||
return new Font(st.nextToken(),
|
||||
st.nextToken().equals("bold") ? Font.BOLD : Font.PLAIN,
|
||||
Integer.parseInt(st.nextToken()));
|
||||
}
|
||||
|
||||
static public boolean isMacintosh() {
|
||||
return System.getProperty("os.name").toLowerCase().indexOf("mac") != -1;
|
||||
}
|
||||
|
||||
/*
|
||||
static public boolean hasFullPrivileges() {
|
||||
//if (applet == null) return true; // application
|
||||
//return false;
|
||||
return !isApplet();
|
||||
}
|
||||
*/
|
||||
}
|
||||
|
||||
@@ -7,11 +7,65 @@ import java.net.*;
|
||||
import java.util.*;
|
||||
import java.util.zip.*;
|
||||
|
||||
|
||||
// play, stop, open, save, courseware, print, beautify
|
||||
// height of button panel is 35
|
||||
|
||||
public class PdeEditor extends Panel /*implements PdeEnvironment*/ {
|
||||
/*
|
||||
|
||||
|
||||
[ File ]
|
||||
New
|
||||
Open ->
|
||||
Save
|
||||
Duplicate
|
||||
Export
|
||||
-
|
||||
Proce55ing.net
|
||||
Reference
|
||||
-
|
||||
Quit
|
||||
|
||||
|
||||
[ Open-> (Sketchbook) ]
|
||||
sketch-001
|
||||
sketch-002
|
||||
sketch-003
|
||||
--
|
||||
Course ->
|
||||
Examples ->
|
||||
Users ->
|
||||
Proce55ing.net ->
|
||||
--
|
||||
Refresh List
|
||||
Compile All
|
||||
|
||||
|
||||
[ Edit ]
|
||||
Undo
|
||||
-
|
||||
Cut
|
||||
Copy
|
||||
Paste
|
||||
-
|
||||
Select all
|
||||
|
||||
|
||||
[ Sketch ]
|
||||
Play
|
||||
Present
|
||||
Stop
|
||||
|
||||
|
||||
new sketch just makes a new sketch, doesn't ask for name
|
||||
tries to do numbered version based on sketches already present
|
||||
|
||||
last section is configurable
|
||||
choose a name for the entries, and a url for the base of the code
|
||||
file urls will be local, don't include file:/// to user
|
||||
http urls are base of directory where the code is found
|
||||
|
||||
*/
|
||||
|
||||
|
||||
public class PdeEditor extends Panel {
|
||||
|
||||
static final String DEFAULT_PROGRAM = "// type program here\n";
|
||||
|
||||
@@ -22,7 +76,7 @@ public class PdeEditor extends Panel /*implements PdeEnvironment*/ {
|
||||
// otherwise, if the window is resized with the message label
|
||||
// set to blank, it's preferredSize() will be fukered
|
||||
static final String EMPTY = " ";
|
||||
PdeApplet app;
|
||||
//PdeBase app;
|
||||
|
||||
PdeEditorButtons buttons;
|
||||
PdeEditorHeader header;
|
||||
@@ -44,20 +98,20 @@ public class PdeEditor extends Panel /*implements PdeEnvironment*/ {
|
||||
boolean playing;
|
||||
|
||||
|
||||
public PdeEditor(PdeApplet app, String program) {
|
||||
this.app = app;
|
||||
public PdeEditor(/*PdeBase app,*/ String program) {
|
||||
//this.app = app;
|
||||
|
||||
setLayout(new BorderLayout());
|
||||
|
||||
Panel leftPanel = new Panel();
|
||||
leftPanel.setLayout(new BorderLayout());
|
||||
|
||||
Color buttonBgColor =
|
||||
PdeApplet.getColor("editor.buttons.bgcolor", new Color(153, 0, 0));
|
||||
// set bgcolor of buttons here, b/c also used for empty component
|
||||
buttons = new PdeEditorButtons(this);
|
||||
Color buttonBgColor =
|
||||
PdeBase.getColor("editor.buttons.bgcolor", new Color(153, 0, 0));
|
||||
buttons.setBackground(buttonBgColor);
|
||||
leftPanel.add("North", buttons);
|
||||
|
||||
Label dummy = new Label();
|
||||
dummy.setBackground(buttonBgColor);
|
||||
leftPanel.add("Center", dummy);
|
||||
@@ -73,10 +127,10 @@ public class PdeEditor extends Panel /*implements PdeEnvironment*/ {
|
||||
if (program == null) program = DEFAULT_PROGRAM;
|
||||
textarea =
|
||||
new TextArea(program,
|
||||
PdeApplet.getInteger("editor.program.rows", 20),
|
||||
PdeApplet.getInteger("editor.program.columns", 60),
|
||||
PdeBase.getInteger("editor.program.rows", 20),
|
||||
PdeBase.getInteger("editor.program.columns", 60),
|
||||
TextArea.SCROLLBARS_VERTICAL_ONLY);
|
||||
textarea.setFont(PdeApplet.getFont("editor.program.font",
|
||||
textarea.setFont(PdeBase.getFont("editor.program.font",
|
||||
new Font("Monospaced",
|
||||
Font.PLAIN, 12)));
|
||||
rightPanel.add("Center", textarea);
|
||||
@@ -91,7 +145,7 @@ public class PdeEditor extends Panel /*implements PdeEnvironment*/ {
|
||||
|
||||
add("Center", rightPanel);
|
||||
|
||||
if (!PdeApplet.isMacintosh()) { // this still relevant?
|
||||
if (!PdeBase.isMacintosh()) { // this still relevant?
|
||||
PdeEditorListener listener = new PdeEditorListener();
|
||||
textarea.addKeyListener(listener);
|
||||
textarea.addFocusListener(listener);
|
||||
@@ -294,10 +348,10 @@ public class PdeEditor extends Panel /*implements PdeEnvironment*/ {
|
||||
// local encoding for this system.
|
||||
//textarea.setText(app.languageEncode(data));
|
||||
// what the hell was i thinking when i wrote this code
|
||||
if (app.encoding == null)
|
||||
textarea.setText(new String(data));
|
||||
else
|
||||
textarea.setText(new String(data, app.encoding));
|
||||
//if (app.encoding == null)
|
||||
textarea.setText(new String(data));
|
||||
//else
|
||||
//textarea.setText(new String(data, app.encoding));
|
||||
|
||||
} catch (FileNotFoundException e1) {
|
||||
e1.printStackTrace();
|
||||
@@ -537,7 +591,7 @@ public class PdeEditor extends Panel /*implements PdeEnvironment*/ {
|
||||
new DataOutputStream(conn.getOutputStream());
|
||||
|
||||
String content =
|
||||
"save_as=" + URLEncoder.encode(PdeApplet.get("save_as")) +
|
||||
"save_as=" + URLEncoder.encode(PdeBase.get("save_as")) +
|
||||
"&save_image=" + URLEncoder.encode(imageStr) +
|
||||
"&save_program=" + URLEncoder.encode(programStr);
|
||||
|
||||
@@ -773,7 +827,7 @@ public class PdeEditor extends Panel /*implements PdeEnvironment*/ {
|
||||
public void enableFullScreen() {
|
||||
if (fullScreenWindow == null) {
|
||||
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
|
||||
if (PdeApplet.isMacintosh()) {
|
||||
if (PdeBase.isMacintosh()) {
|
||||
fullScreenWindow = new Frame();
|
||||
|
||||
// mrj is still (with version 2.2.x) a piece of shit,
|
||||
@@ -792,7 +846,7 @@ public class PdeEditor extends Panel /*implements PdeEnvironment*/ {
|
||||
fullScreenWindow.setBounds(0, 0, screen.width, screen.height);
|
||||
}
|
||||
Color fullScreenBgColor =
|
||||
PdeApplet.getColor("fullscreen.bgcolor", new Color(102, 102, 102));
|
||||
PdeBase.getColor("fullscreen.bgcolor", new Color(102, 102, 102));
|
||||
fullScreenWindow.setBackground(fullScreenBgColor);
|
||||
|
||||
/*
|
||||
|
||||
@@ -67,7 +67,7 @@ public class PdeEditorButtons extends Panel {
|
||||
boolean useBeautify*/) {
|
||||
this.editor = editor;
|
||||
// this could be causing trouble
|
||||
buttons = PdeApplet.readImage("buttons.gif");
|
||||
buttons = PdeBase.readImage("buttons.gif");
|
||||
|
||||
buttonCount = 0;
|
||||
which = new int[BUTTON_COUNT];
|
||||
@@ -83,13 +83,16 @@ public class PdeEditorButtons extends Panel {
|
||||
|
||||
setLayout(null);
|
||||
status = new Label();
|
||||
status.setFont(PdeApplet.getFont("editor.buttons.status.font",
|
||||
status.setFont(PdeBase.getFont("editor.buttons.status.font",
|
||||
new Font("SansSerif", Font.PLAIN, 10)));
|
||||
status.setForeground(PdeApplet.getColor("editor.buttons.status.color",
|
||||
status.setForeground(PdeBase.getColor("editor.buttons.status.color",
|
||||
Color.black));
|
||||
//status.setForeground(Color.black);
|
||||
//status.setBackground(Color.yellow);
|
||||
add(status);
|
||||
|
||||
Color buttonBgColor =
|
||||
PdeBase.getColor("editor.buttons.bgcolor", new Color(153, 0, 0));
|
||||
setBackground(buttonBgColor);
|
||||
|
||||
status.setBounds(-5, BUTTON_COUNT*BUTTON_HEIGHT,
|
||||
BUTTON_WIDTH + 15, BUTTON_HEIGHT);
|
||||
status.setAlignment(Label.CENTER);
|
||||
|
||||
@@ -51,7 +51,7 @@ public class PdeEditorConsole extends Component {
|
||||
public PdeEditorConsole(PdeEditor editor) {
|
||||
this.editor = editor;
|
||||
|
||||
lineCount = PdeApplet.getInteger("editor.console.lines", 6);
|
||||
lineCount = PdeBase.getInteger("editor.console.lines", 6);
|
||||
|
||||
if (systemOut == null) {
|
||||
systemOut = System.out;
|
||||
@@ -87,11 +87,11 @@ public class PdeEditorConsole extends Component {
|
||||
public void paint(Graphics screen) {
|
||||
//systemOut.println("paint()");
|
||||
if (bgColor == null) {
|
||||
bgColor = PdeApplet.getColor("editor.console.bgcolor",
|
||||
bgColor = PdeBase.getColor("editor.console.bgcolor",
|
||||
new Color(26, 26, 26));
|
||||
fgColorOut = PdeApplet.getColor("editor.console.fgcolor.output",
|
||||
fgColorOut = PdeBase.getColor("editor.console.fgcolor.output",
|
||||
new Color(153, 153, 153));
|
||||
fgColorErr = PdeApplet.getColor("editor.console.fgcolor.error",
|
||||
fgColorErr = PdeBase.getColor("editor.console.fgcolor.error",
|
||||
new Color(153, 0, 0));
|
||||
screen.setFont(font);
|
||||
metrics = screen.getFontMetrics();
|
||||
@@ -130,7 +130,7 @@ public class PdeEditorConsole extends Component {
|
||||
Graphics g = offscreen.getGraphics();
|
||||
/*
|
||||
if (font == null) {
|
||||
font = PdeApplet.getFont("editor.console.font",
|
||||
font = PdeBase.getFont("editor.console.font",
|
||||
new Font("Monospaced", Font.PLAIN, 11));
|
||||
//font = new Font("SansSerif", Font.PLAIN, 10);
|
||||
g.setFont(font);
|
||||
@@ -205,7 +205,7 @@ public class PdeEditorConsole extends Component {
|
||||
public Dimension getPreferredSize() {
|
||||
//systemOut.println("pref'd sizde");
|
||||
if (font == null) {
|
||||
font = PdeApplet.getFont("editor.console.font",
|
||||
font = PdeBase.getFont("editor.console.font",
|
||||
new Font("Monospaced", Font.PLAIN, 11));
|
||||
//font = new Font("SansSerif", Font.PLAIN, 10);
|
||||
//g.setFont(font);
|
||||
|
||||
@@ -51,11 +51,11 @@ public class PdeEditorHeader extends Panel /* implements ActionListener*/ {
|
||||
this.user = user;
|
||||
|
||||
if (primaryColor == null) {
|
||||
backgroundColor = PdeApplet.getColor("editor.header.bgcolor",
|
||||
backgroundColor = PdeBase.getColor("editor.header.bgcolor",
|
||||
new Color(51, 51, 51));
|
||||
primaryColor = PdeApplet.getColor("editor.header.fgcolor.primary",
|
||||
primaryColor = PdeBase.getColor("editor.header.fgcolor.primary",
|
||||
new Color(255, 255, 255));
|
||||
secondaryColor = PdeApplet.getColor("editor.header.fgcolor.secondary",
|
||||
secondaryColor = PdeBase.getColor("editor.header.fgcolor.secondary",
|
||||
new Color(153, 153, 153));
|
||||
}
|
||||
}
|
||||
@@ -111,7 +111,7 @@ public class PdeEditorHeader extends Panel /* implements ActionListener*/ {
|
||||
Graphics g = offscreen.getGraphics();
|
||||
if (font == null) {
|
||||
//font = new Font("SansSerif", Font.PLAIN, 12);
|
||||
font = PdeApplet.getFont("editor.header.font",
|
||||
font = PdeBase.getFont("editor.header.font",
|
||||
new Font("SansSerif", Font.PLAIN, 12));
|
||||
g.setFont(font);
|
||||
metrics = g.getFontMetrics();
|
||||
|
||||
@@ -22,11 +22,11 @@ public class PdeEditorListener extends KeyAdapter implements FocusListener {
|
||||
|
||||
|
||||
public PdeEditorListener() {
|
||||
expandTabs = PdeApplet.getBoolean("editor.expandTabs", false);
|
||||
tabSize = PdeApplet.getInteger("editor.tabSize", 2);
|
||||
expandTabs = PdeBase.getBoolean("editor.expandTabs", false);
|
||||
tabSize = PdeBase.getInteger("editor.tabSize", 2);
|
||||
tabString = spaces.substring(0, tabSize);
|
||||
autoIndent = PdeApplet.getBoolean("editor.autoIndent", false);
|
||||
balanceParens = PdeApplet.getBoolean("editor.balanceParens", false);
|
||||
autoIndent = PdeBase.getBoolean("editor.autoIndent", false);
|
||||
balanceParens = PdeBase.getBoolean("editor.balanceParens", false);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -41,18 +41,18 @@ public class PdeEditorStatus extends Panel implements ActionListener {
|
||||
|
||||
if (bgColor == null) {
|
||||
bgColor = new Color[3];
|
||||
bgColor[0] = PdeApplet.getColor("editor.status.notice.bgcolor",
|
||||
bgColor[0] = PdeBase.getColor("editor.status.notice.bgcolor",
|
||||
new Color(102, 102, 102));
|
||||
bgColor[1] = PdeApplet.getColor("editor.status.error.bgcolor",
|
||||
bgColor[1] = PdeBase.getColor("editor.status.error.bgcolor",
|
||||
new Color(102, 26, 0));
|
||||
bgColor[2] = PdeApplet.getColor("editor.status.prompt.bgcolor",
|
||||
bgColor[2] = PdeBase.getColor("editor.status.prompt.bgcolor",
|
||||
new Color(204, 153, 0));
|
||||
fgColor = new Color[3];
|
||||
fgColor[0] = PdeApplet.getColor("editor.status.notice.fgcolor",
|
||||
fgColor[0] = PdeBase.getColor("editor.status.notice.fgcolor",
|
||||
new Color(255, 255, 255));
|
||||
fgColor[1] = PdeApplet.getColor("editor.status.error.fgcolor",
|
||||
fgColor[1] = PdeBase.getColor("editor.status.error.fgcolor",
|
||||
new Color(255, 255, 255));
|
||||
fgColor[2] = PdeApplet.getColor("editor.status.prompt.fgcolor",
|
||||
fgColor[2] = PdeBase.getColor("editor.status.prompt.fgcolor",
|
||||
new Color(0, 0, 0));
|
||||
}
|
||||
}
|
||||
@@ -153,7 +153,7 @@ public class PdeEditorStatus extends Panel implements ActionListener {
|
||||
|
||||
Graphics g = offscreen.getGraphics();
|
||||
if (font == null) {
|
||||
font = PdeApplet.getFont("editor.status.font",
|
||||
font = PdeBase.getFont("editor.status.font",
|
||||
new Font("SansSerif", Font.PLAIN, 10));
|
||||
//font = new Font("SansSerif", Font.PLAIN, 10);
|
||||
g.setFont(font);
|
||||
|
||||
Reference in New Issue
Block a user