mirror of
https://github.com/processing/processing4.git
synced 2026-02-01 12:51:37 +01:00
167 lines
4.6 KiB
Java
167 lines
4.6 KiB
Java
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
|
|
{
|
|
Frame frame;
|
|
WindowAdapter windowListener;
|
|
|
|
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(" p r o c e s s i n g ");
|
|
|
|
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();
|
|
|
|
/*
|
|
// check for updates from the server, if enabled
|
|
if (getBoolean("update.enabled", false)) {
|
|
// open the update file to get the latest version
|
|
long lastUpdate = 0;
|
|
try {
|
|
DataInputStream dis = new DataInputStream(new FileInputStream("lib/version"));
|
|
lastUpdate = dis.readLong();
|
|
} catch (IOException e) { }
|
|
|
|
String baseUrl = get("update.url");
|
|
try {
|
|
URL url = new URL(baseUrl + "version");
|
|
URLConnection conn = url.openConnection();
|
|
//conn.connect();
|
|
|
|
//System.out.println("date of last update" + conn.getDate());
|
|
long newDate = conn.getDate();
|
|
if (newDate > lastUpdate) {
|
|
System.out.println("new update available");
|
|
|
|
DataOutputStream vos =
|
|
new DataOutputStream(new FileOutputStream("lib/version.update"));
|
|
vos.writeLong(newDate);
|
|
vos.flush();
|
|
vos.close();
|
|
|
|
url = new URL(baseUrl + "pde.jar");
|
|
conn = url.openConnection();
|
|
|
|
// move the old pde.jar file out of the way
|
|
//File pdeJar = new File("lib/pde.jar");
|
|
//pdeJar.renameTo("lib/pde.old.jar");
|
|
|
|
// download the new pde.jar file
|
|
FileOutputStream os = new FileOutputStream("lib/pde.jar.update");
|
|
//Object object = conn.getContent();
|
|
//System.out.println(object);
|
|
InputStream is = conn.getInputStream();
|
|
copyStream(is, os);
|
|
os.close();
|
|
|
|
// if everything copied ok, rename new/old files
|
|
// this probably needs to be way more bulletproof
|
|
File file = new File("lib/version");
|
|
if (file.exists()) file.renameTo(new File("lib/version.old"));
|
|
file = new File("lib/version.update");
|
|
file.renameTo(new File("lib/version"));
|
|
|
|
file = new File("lib/pde.jar");
|
|
file.renameTo(new File("lib/pde.jar.old"));
|
|
file = new File("lib/pde.jar.update");
|
|
file.renameTo(new File("lib/pde.jar"));
|
|
|
|
// restart or relaunch
|
|
System.out.println("done copying new version, restart");
|
|
System.exit(0);
|
|
}
|
|
|
|
} catch (IOException e1) {
|
|
e1.printStackTrace();
|
|
|
|
//} catch (MalformedURLException e2) {
|
|
//e2.printStackTrace();
|
|
}
|
|
}
|
|
*/
|
|
|
|
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;
|
|
|
|
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
|