size(300, 300, OPENGL).. rewrite of present mode.. java 1.4 only.. a

zillion other runtime fixes
This commit is contained in:
benfry
2005-04-04 17:00:58 +00:00
parent 4d9c91fd2f
commit fc1e1a34f8
30 changed files with 1619 additions and 908 deletions
+64 -54
View File
@@ -38,6 +38,8 @@ import javax.swing.undo.*;
import com.apple.mrj.*;
import com.ice.jni.registry.*;
import processing.core.*;
/**
* Primary role of this class is for platform identification and
@@ -45,32 +47,41 @@ import com.ice.jni.registry.*;
* files and images, etc) that comes from that.
*/
public class PdeBase {
static final String VERSION = "0080 Alpha";
static final String VERSION = "0081 Alpha";
/**
* Path of filename opened on the command line,
* or via the MRJ open document handler.
*/
static String openedAtStartup;
//static ClassLoader loader;
PdeEditor editor;
static final int WINDOWS = 1;
static final int MACOS9 = 2;
static final int MACOSX = 3;
static final int LINUX = 4;
static final int IRIX = 5;
static final int UNKNOWN = 5;
static int platform;
static final String platforms[] = {
"", "windows", "macos9", "macosx", "linux", "irix"
};
static public void main(String args[]) {
// make sure that this is running on java 1.4
if (PApplet.JDK_VERSION < 1.4) {
//System.err.println("no way man");
PdeBase.showError("Need to install Java 1.4",
"This version of Processing requires \n" +
"Java 1.4 or later to run properly.\n" +
"Please visit java.com to upgrade.", null);
}
// grab any opened file from the command line
if (args.length == 1) {
PdeBase.openedAtStartup = args[0];
}
// register a temporary/early version of the mrj open document handler,
// because the event may be lost (sometimes, not always) by the time
// that PdeEditor is properly constructed.
MRJOpenDocumentHandler startupOpen = new MRJOpenDocumentHandler() {
public void handleOpenFile(File file) {
// this will only get set once.. later will be handled
@@ -88,36 +99,11 @@ public class PdeBase {
public PdeBase() {
// figure out which operating system
// this has to be first, since editor needs to know
if (System.getProperty("mrj.version") != null) { // running on a mac
platform = (System.getProperty("os.name").equals("Mac OS X")) ?
MACOSX : MACOS9;
} else {
String osname = System.getProperty("os.name");
if (osname.indexOf("Windows") != -1) {
platform = WINDOWS;
} else if (osname.equals("Linux")) { // true for the ibm vm
platform = LINUX;
} else if (osname.equals("Irix")) {
platform = IRIX;
} else {
platform = UNKNOWN;
//System.out.println("unhandled osname: \"" + osname + "\"");
}
}
// set the look and feel before opening the window
try {
if (platform == LINUX) {
if (PdeBase.isLinux()) {
// linux is by default (motif?) even uglier than metal
// actually, i'm using native menus, so they're ugly and
// motif-looking. ick. need to fix this.
@@ -141,10 +127,34 @@ public class PdeBase {
// show the window
editor.show();
}
// maybe?
//loader = new PdeClassLoader();
// .................................................................
/**
* returns true if the Processing is running on a Mac OS machine,
* specifically a Mac OS X machine because it doesn't un on OS 9 anymore.
*/
static public boolean isMacOS() {
return PApplet.platform == PConstants.MACOSX;
}
/**
* returns true if running on windows.
*/
static public boolean isWindows() {
return PApplet.platform == PConstants.WINDOWS;
}
/**
* true if running on linux.
*/
static public boolean isLinux() {
return PApplet.platform == PConstants.LINUX;
}
@@ -167,7 +177,7 @@ public class PdeBase {
if (pref != null) {
dataFolder = new File(pref);
} else if (platform == MACOSX) {
} else if (PdeBase.isMacOS()) {
// carbon folder constants
// http://developer.apple.com/documentation/Carbon/Reference
// /Folder_Manager/folder_manager_ref/constant_6.html#/
@@ -213,7 +223,7 @@ public class PdeBase {
"Error getting the Processing data folder.", e);
}
} else if (platform == WINDOWS) {
} else if (PdeBase.isWindows()) {
// looking for Documents and Settings/blah/Application Data/Processing
// this is just based on the other documentation, and eyeballing
@@ -306,7 +316,7 @@ public class PdeBase {
static public File getDefaultSketchbookFolder() {
File sketchbookFolder = null;
if (platform == MACOSX) {
if (PdeBase.isMacOS()) {
// looking for /Users/blah/Documents/Processing
// carbon folder constants
@@ -340,7 +350,7 @@ public class PdeBase {
"Could not locate default sketch folder location.", e);
}
} else if (platform == WINDOWS) {
} else if (isWindows()) {
// looking for Documents and Settings/blah/My Documents/Processing
// (though using a reg key since it's different on other platforms)
@@ -462,7 +472,7 @@ public class PdeBase {
static public void openURL(String url) {
//System.out.println("opening url " + url);
try {
if (platform == WINDOWS) {
if (PdeBase.isWindows()) {
// this is not guaranteed to work, because who knows if the
// path will always be c:\progra~1 et al. also if the user has
// a different browser set as their default (which would
@@ -491,7 +501,7 @@ public class PdeBase {
Runtime.getRuntime().exec("cmd /c \"" + url + "\"");
}
} else if (platform == MACOSX) {
} else if (PdeBase.isMacOS()) {
//com.apple.eio.FileManager.openURL(url);
if (!url.startsWith("http://")) {
@@ -518,10 +528,10 @@ public class PdeBase {
//System.out.println("trying to open " + url);
com.apple.mrj.MRJFileUtils.openURL(url);
} else if (platform == MACOS9) {
com.apple.mrj.MRJFileUtils.openURL(url);
//} else if (platform == MACOS9) {
//com.apple.mrj.MRJFileUtils.openURL(url);
} else if (platform == LINUX) {
} else if (PdeBase.isLinux()) {
// how's mozilla sound to ya, laddie?
//Runtime.getRuntime().exec(new String[] { "mozilla", url });
String browser = PdePreferences.get("browser");
@@ -548,7 +558,7 @@ public class PdeBase {
try {
String folder = file.getAbsolutePath();
if (platform == WINDOWS) {
if (PdeBase.isWindows()) {
// doesn't work
//Runtime.getRuntime().exec("cmd /c \"" + folder + "\"");
@@ -558,7 +568,7 @@ public class PdeBase {
// not tested
//Runtime.getRuntime().exec("start explorer \"" + folder + "\"");
} else if (platform == MACOSX) {
} else if (PdeBase.isMacOS()) {
openURL(folder); // handles char replacement, etc
}
+2 -2
View File
@@ -74,7 +74,7 @@ public class PdeCompiler implements PdeMessageConsumer {
// user.dir is folder containing P5 (and therefore jikes)
// macosx needs the extra path info. linux doesn't like it, though
// windows doesn't seem to care. write once, headache anywhere.
((PdeBase.platform != PdeBase.MACOSX) ? "jikes" :
((!PdeBase.isMacOS()) ? "jikes" :
System.getProperty("user.dir") + File.separator + "jikes"),
// this doesn't help much.. also java 1.4 seems to not support
@@ -359,7 +359,7 @@ public class PdeCompiler implements PdeMessageConsumer {
static public String calcBootClassPath() {
if (bootClassPath == null) {
String additional = "";
if (PdeBase.platform == PdeBase.MACOSX) {
if (PdeBase.isMacOS()) {
additional =
contentsToClassPath(new File("/System/Library/Java/Extensions/"));
}
+62 -59
View File
@@ -46,7 +46,7 @@ public class PdeEditor extends JFrame
MRJOpenDocumentHandler //, MRJOpenApplicationHandler
{
// yeah
static final String WINDOW_TITLE = "Processing";
static final String WINDOW_TITLE = "Processing" + " - " + PdeBase.VERSION;
// p5 icon for the window
Image icon;
@@ -58,6 +58,9 @@ public class PdeEditor extends JFrame
" " +
" ";
static public final KeyStroke WINDOW_CLOSE_KEYSTROKE =
KeyStroke.getKeyStroke('W', Toolkit.getDefaultToolkit().getMenuShortcutKeyMask());
static final int HANDLE_NEW = 1;
static final int HANDLE_OPEN = 2;
static final int HANDLE_QUIT = 3;
@@ -65,8 +68,6 @@ public class PdeEditor extends JFrame
String handleOpenPath;
boolean handleNewShift;
boolean handleNewLibrary;
//String handleSaveAsPath;
//String openingName;
PdeEditorButtons buttons;
PdeEditorHeader header;
@@ -88,22 +89,14 @@ public class PdeEditor extends JFrame
// runtime information and window placement
Point appletLocation;
Point presentLocation;
Window presentationWindow;
//Point presentLocation;
//Window presentationWindow;
RunButtonWatcher watcher;
PdeRuntime runtime;
//boolean externalRuntime;
//String externalPaths;
//File externalCode;
JMenuItem exportAppItem;
JMenuItem saveMenuItem;
JMenuItem saveAsMenuItem;
//JMenuItem beautifyMenuItem;
JRadioButtonMenuItem coreRendererItem;
JRadioButtonMenuItem openglRendererItem;
//
@@ -120,14 +113,14 @@ public class PdeEditor extends JFrame
//PdeHistory history; // TODO re-enable history
PdeSketchbook sketchbook;
PdePreferences preferences;
//PdePreferences preferences;
PdeEditorFind find;
//static Properties keywords; // keyword -> reference html lookup
public PdeEditor() {
super(WINDOW_TITLE + " - " + PdeBase.VERSION);
super(WINDOW_TITLE);
// #@$*(@#$ apple.. always gotta think different
MRJApplicationUtils.registerAboutHandler(this);
@@ -135,8 +128,8 @@ public class PdeEditor extends JFrame
MRJApplicationUtils.registerQuitHandler(this);
MRJApplicationUtils.registerOpenDocumentHandler(this);
// this is needed by just about everything else
preferences = new PdePreferences();
// run static initialization that grabs all the prefs
PdePreferences.init();
// set the window icon
try {
@@ -240,7 +233,7 @@ public class PdeEditor extends JFrame
// to fix ugliness.. normally macosx java 1.3 puts an
// ugly white border around this object, so turn it off.
if (PdeBase.platform == PdeBase.MACOSX) {
if (PdeBase.isMacOS()) {
splitPane.setBorder(null);
}
@@ -274,9 +267,9 @@ public class PdeEditor extends JFrame
Document document = textarea.getDocument();
document.addUndoableEditListener(new PdeUndoableEditListener());
/*
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
if ((PdeBase.platform == PdeBase.MACOSX) ||
(PdeBase.platform == PdeBase.MACOS9)) {
if (PdeBase.isMacOS()) {
presentationWindow = new Frame();
// mrj is still (with version 2.2.x) a piece of shit,
@@ -291,17 +284,7 @@ public class PdeEditor extends JFrame
screen.height + insets.top + insets.bottom);
} else {
presentationWindow = new Frame();
//((Frame)presentationWindow).setUndecorated(true);
try {
Method undecoratedMethod =
Frame.class.getMethod("setUndecorated",
new Class[] { Boolean.TYPE });
undecoratedMethod.invoke(presentationWindow,
new Object[] { Boolean.TRUE });
} catch (Exception e) { }
//} catch (NoSuchMethodException e) { }
//} catch (NoSuchMethodError e) { }
((Frame)presentationWindow).setUndecorated(true);
presentationWindow.setBounds(0, 0, screen.width, screen.height);
}
@@ -358,6 +341,7 @@ public class PdeEditor extends JFrame
}
}
});
*/
}
@@ -478,6 +462,12 @@ public class PdeEditor extends JFrame
textarea.setCaretVisible(true);
}
// apply changes to the font size for the editor
//TextAreaPainter painter = textarea.getPainter();
painter.setFont(PdePreferences.getFont("editor.font"));
//Font font = painter.getFont();
//textarea.getPainter().setFont(new Font("Courier", Font.PLAIN, 36));
// in case tab expansion stuff has changed
listener.applyPreferences();
@@ -522,6 +512,15 @@ public class PdeEditor extends JFrame
JMenuItem item;
JMenu menu = new JMenu("File");
/*
menu.add(item = new JMenuItem("do the editor thing"));
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
textarea.getPainter().setFont(new Font("Courier", Font.PLAIN, 36));
}
});
*/
if (!PdePreferences.getBoolean("export.library")) {
item = newJMenuItem("New", 'N');
item.addActionListener(new ActionListener() {
@@ -615,10 +614,10 @@ public class PdeEditor extends JFrame
menu.add(item);
// macosx already has its own preferences and quit menu
if (PdeBase.platform != PdeBase.MACOSX) {
if (!PdeBase.isMacOS()) {
menu.addSeparator();
item = new JMenuItem("Preferences");
item = newJMenuItem("Preferences", ',');
item.addActionListener(new ActionListener() {
public void actionPerformed(ActionEvent e) {
handlePrefs();
@@ -668,6 +667,7 @@ public class PdeEditor extends JFrame
});
menu.add(item);
/*
JMenu rendererMenu = new JMenu("Renderer");
menu.add(rendererMenu);
@@ -700,6 +700,7 @@ public class PdeEditor extends JFrame
boolean useOpenGL = PdePreferences.get("renderer").equals("opengl");
coreRendererItem.setSelected(!useOpenGL);
openglRendererItem.setSelected(useOpenGL);
*/
//
@@ -717,8 +718,7 @@ public class PdeEditor extends JFrame
menu.add(sketchbook.getImportMenu());
if ((PdeBase.platform == PdeBase.WINDOWS) ||
(PdeBase.platform == PdeBase.MACOSX)) {
if (PdeBase.isWindows() || PdeBase.isMacOS()) {
// no way to do an 'open in file browser' on other platforms
// since there isn't any sort of standard
item = new JMenuItem("Show Sketch Folder");
@@ -825,7 +825,7 @@ public class PdeEditor extends JFrame
menu.add(item);
// macosx already has its own about menu
if (PdeBase.platform != PdeBase.MACOSX) {
if (!PdeBase.isMacOS()) {
menu.addSeparator();
item = new JMenuItem("About Processing");
item.addActionListener(new ActionListener() {
@@ -915,8 +915,7 @@ public class PdeEditor extends JFrame
/**
* Convenience method for the antidote to overthought
* swing api mess for setting accelerators.
* Convenience method, see below.
*/
static public JMenuItem newJMenuItem(String title, int what) {
return newJMenuItem(title, what, false);
@@ -925,9 +924,9 @@ public class PdeEditor extends JFrame
/**
* A software engineer, somewhere, needs to have his abstraction
* taken away. I hear they jail people in third world countries for
* writing the sort of crappy api that would require a four line
* helpher function to *set the command key* for a menu item.
* taken away. In some countries they jail people for writing the
* sort of crappy api that would require a four line helper function
* to set the command key for a menu item.
*/
static public JMenuItem newJMenuItem(String title,
int what, boolean shift) {
@@ -1054,12 +1053,15 @@ public class PdeEditor extends JFrame
/**
* Show the (already created on app init) preferences window.
* Show the preferences window.
*/
public void handlePrefs() {
PdePreferences preferences = new PdePreferences();
preferences.showFrame(this);
// since this can't actually block, it'll hide
// the editor window while the prefs are open
preferences.showFrame(this);
//preferences.showFrame(this);
// and then call applyPreferences if 'ok' is hit
// and then unhide
@@ -1113,17 +1115,19 @@ public class PdeEditor extends JFrame
}
presenting = present;
/*
if (presenting) {
// wipe everything out with a bulbous screen-covering window
presentationWindow.show();
presentationWindow.toFront();
}
*/
try {
if (!sketch.handleRun()) return;
runtime = new PdeRuntime(sketch, PdeEditor.this);
runtime.start(presenting ? presentLocation : appletLocation);
runtime.start(appletLocation);
watcher = new RunButtonWatcher();
} catch (PdeException e) {
@@ -1231,20 +1235,19 @@ public class PdeEditor extends JFrame
* mode, this will always be called instead of doStop().
*/
public void doClose() {
if (presenting) {
presentationWindow.hide();
} else {
try {
// the window will also be null the process was running
// externally. so don't even try setting if window is null
// since PdeRuntime will set the appletLocation when an
// external process is in use.
if (runtime.window != null) {
appletLocation = runtime.window.getLocation();
}
} catch (NullPointerException e) { }
}
//if (presenting) {
//presentationWindow.hide();
//} else {
try {
// the window will also be null the process was running
// externally. so don't even try setting if window is null
// since PdeRuntime will set the appletLocation when an
// external process is in use.
if (runtime.window != null) {
appletLocation = runtime.window.getLocation();
}
} catch (NullPointerException e) { }
//}
//if (running) doStop();
doStop(); // need to stop if runtime error
@@ -1642,7 +1645,7 @@ public class PdeEditor extends JFrame
*/
protected void handleQuit2() {
storePreferences();
preferences.save();
PdePreferences.save();
sketchbook.clean();
+1 -1
View File
@@ -145,7 +145,7 @@ public class PdeEditorConsole extends JScrollPane {
// to fix ugliness.. normally macosx java 1.3 puts an
// ugly white border around this object, so turn it off.
if (PdeBase.platform == PdeBase.MACOSX) {
if (PdeBase.isMacOS()) {
setBorder(null);
}
}
+3 -3
View File
@@ -94,8 +94,7 @@ public class PdeEditorFind extends JFrame
buttons.setLayout(new FlowLayout());
// ordering is different on mac versus pc
if ((PdeBase.platform == PdeBase.MACOSX) ||
(PdeBase.platform == PdeBase.MACOS9)) {
if (PdeBase.isMacOS()) {
buttons.add(replaceButton = new JButton("Replace"));
buttons.add(replaceAllButton = new JButton("Replace All"));
buttons.add(findButton = new JButton("Find"));
@@ -112,7 +111,8 @@ public class PdeEditorFind extends JFrame
// to fix ugliness.. normally macosx java 1.3 puts an
// ugly white border around this object, so turn it off.
if (PdeBase.platform == PdeBase.MACOSX) {
//if (PdeBase.platform == PdeBase.MACOSX) {
if (PdeBase.isMacOS()) {
buttons.setBorder(null);
}
+2 -2
View File
@@ -366,14 +366,14 @@ public class PdeEditorHeader extends JComponent {
}
public Dimension getMinimumSize() {
if (PdeBase.platform == PdeBase.MACOSX) {
if (PdeBase.isMacOS()) {
return new Dimension(300, PdePreferences.GRID_SIZE);
}
return new Dimension(300, PdePreferences.GRID_SIZE - 1);
}
public Dimension getMaximumSize() {
if (PdeBase.platform == PdeBase.MACOSX) {
if (PdeBase.isMacOS()) {
return new Dimension(3000, PdePreferences.GRID_SIZE);
}
return new Dimension(3000, PdePreferences.GRID_SIZE - 1);
+1 -1
View File
@@ -239,7 +239,7 @@ public class PdeEditorStatus extends JPanel implements ActionListener {
// !@#(* aqua ui #($*(( that turtle-neck wearing #(** (#$@)(
// os9 seems to work if bg of component is set, but x still a bastard
if (PdeBase.platform == PdeBase.MACOSX) {
if (PdeBase.isMacOS()) {
yesButton.setBackground(bgcolor[PROMPT]);
noButton.setBackground(bgcolor[PROMPT]);
cancelButton.setBackground(bgcolor[PROMPT]);
+99 -38
View File
@@ -36,21 +36,15 @@ import javax.swing.filechooser.*;
import javax.swing.text.*;
import javax.swing.undo.*;
import processing.core.PApplet;
/*
need to bring all the prefs into here
PdeEditor with its sketch.properties
and PdeBase with preferences.txt
on first run:
processing.properties is created in user.home
it contains the contents of
preferences.txt + pde_platform.properties
and then begins writing additional sketch.properties stuff
this class no longer uses the Properties class, since
properties files are iso8859-1, which is highly likely to
be a problem when trying to save sketch folders and locations
/**
* Preferences storage class.
* <P>
* This class no longer uses the Properties class, since
* properties files are iso8859-1, which is highly likely to
* be a problem when trying to save sketch folders and locations.
*/
public class PdePreferences extends JComponent {
@@ -58,6 +52,14 @@ public class PdePreferences extends JComponent {
static final String PREFS_FILE = "preferences.txt";
// platform strings (used to get settings for specific platforms)
static final String platforms[] = {
"other", "windows", "macos9", "macosx", "linux"
};
// prompt text stuff
static final String PROMPT_YES = "Yes";
@@ -84,15 +86,19 @@ public class PdePreferences extends JComponent {
// gui elements
JFrame frame;
//JFrame frame;
JDialog frame;
int wide, high;
JTextField sketchbookLocationField;
JCheckBox sketchPromptBox;
JCheckBox sketchCleanBox;
JCheckBox exportLibraryBox;
//JCheckBox exportLibraryBox;
JCheckBox externalEditorBox;
JTextField fontSizeField;
// the calling editor, so updates can be applied
PdeEditor editor;
@@ -100,12 +106,11 @@ public class PdePreferences extends JComponent {
// data model
static Hashtable table = new Hashtable();;
File preferencesFile;
static File preferencesFile;
//boolean firstTime; // first time this feller has been run
public PdePreferences() {
static public void init() {
// start by loading the defaults, in case something
// important was deleted from the user prefs
@@ -118,10 +123,10 @@ public class PdePreferences extends JComponent {
"You'll need to reinstall Processing.", e);
}
// check for platform-specific properties in the defaults
String platformExtension = "." + PdeBase.platforms[PdeBase.platform];
String platformExtension = "." +
platforms[processing.core.PApplet.platform];
int extensionLength = platformExtension.length();
Enumeration e = table.keys(); //properties.propertyNames();
@@ -167,16 +172,19 @@ public class PdePreferences extends JComponent {
" and restart Processing.", ex);
}
}
}
public PdePreferences() {
// setup frame for the prefs
frame = new JFrame("Preferences");
//frame = new JDialog("Preferences");
frame.setResizable(false);
//frame = new JFrame("Preferences");
frame = new JDialog(editor, "Preferences", true);
//frame.setResizable(false);
Container pain = this;
//Container pain = frame.getContentPane();
//Container pain = this;
Container pain = frame.getContentPane();
pain.setLayout(null);
int top = GUI_BIG;
@@ -257,8 +265,24 @@ public class PdePreferences extends JComponent {
top += vmax + GUI_BETWEEN;
// Editor font size [ ]
Container box = Box.createHorizontalBox();
label = new JLabel("Editor font size: ");
box.add(label);
fontSizeField = new JTextField(4);
box.add(fontSizeField);
pain.add(box);
d = box.getPreferredSize();
box.setBounds(left, top, d.width, d.height);
Font editorFont = PdePreferences.getFont("editor.font");
fontSizeField.setText(String.valueOf(editorFont.getSize()));
top += d.height + GUI_BETWEEN;
// [ ] Enable export to "Library"
/*
exportLibraryBox = new JCheckBox("Enable advanced \"Library\" features" +
" (requires restart)");
exportLibraryBox.setEnabled(false);
@@ -267,6 +291,7 @@ public class PdePreferences extends JComponent {
exportLibraryBox.setBounds(left, top, d.width, d.height);
right = Math.max(right, left + d.width);
top += d.height + GUI_BETWEEN;
*/
// [ ] Use external editor
@@ -297,14 +322,20 @@ public class PdePreferences extends JComponent {
pain.add(textarea);
*/
label = new JLabel("More preferences can be edited directly in the file");
label.setForeground(Color.gray);
pain.add(label);
d = label.getPreferredSize();
label.setForeground(Color.gray);
label.setBounds(left, top, d.width, d.height);
top += d.height; // + GUI_SMALL;
label = new JLabel(preferencesFile.getAbsolutePath());
label.setForeground(Color.gray);
label.addMouseListener(new MouseAdapter() {
public void mousePressed(MouseEvent e) {
PdeBase.openURL(preferencesFile.getAbsolutePath());
}
});
label.setForeground(new Color(51, 25, 153));
pain.add(label);
d = label.getPreferredSize();
label.setBounds(left, top, d.width, d.height);
@@ -371,6 +402,19 @@ public class PdePreferences extends JComponent {
Dimension screen = Toolkit.getDefaultToolkit().getScreenSize();
frame.setLocation((screen.width - wide) / 2,
(screen.height - high) / 2);
// handle window closing commands for ctrl/cmd-W or hitting ESC.
addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
KeyStroke wc = PdeEditor.WINDOW_CLOSE_KEYSTROKE;
if ((e.getKeyCode() == KeyEvent.VK_ESCAPE) ||
(KeyStroke.getKeyStrokeForEvent(e).equals(wc))) {
disposeFrame();
}
}
});
}
@@ -382,16 +426,21 @@ public class PdePreferences extends JComponent {
// .................................................................
/**
* Close the window after an OK or Cancel.
*/
public void disposeFrame() {
frame.hide();
editor.applyPreferences();
editor.show();
//frame.dispose();
//frame.hide();
//editor.applyPreferences();
//editor.show();
frame.dispose();
}
// change settings based on what was chosen in the prefs
/**
* Change internal settings based on what was chosen in the prefs,
* then send a message to the editor saying that it's time to do the same.
*/
public void applyFrame() {
//editor.setExternalEditor(getBoolean("editor.external"));
// put each of the settings into the table
@@ -399,21 +448,33 @@ public class PdePreferences extends JComponent {
setBoolean("sketchbook.prompt", sketchPromptBox.isSelected());
setBoolean("sketchbook.auto_clean", sketchCleanBox.isSelected());
set("sketchbook.path", sketchbookLocationField.getText());
setBoolean("export.library", exportLibraryBox.isSelected());
//setBoolean("export.library", exportLibraryBox.isSelected());
setBoolean("editor.external", externalEditorBox.isSelected());
String newSizeText = fontSizeField.getText();
try {
int newSize = Integer.parseInt(newSizeText.trim());
String pieces[] = PApplet.split(get("editor.font"), ',');
pieces[2] = String.valueOf(newSize);
set("editor.font", PApplet.join(pieces, ','));
} catch (Exception e) {
System.err.println("ignoring invalid font size " + newSizeText);
}
editor.applyPreferences();
}
public void showFrame(PdeEditor editor) {
// hide the editor window so it can't be messed with
this.editor = editor;
editor.hide();
//editor.hide();
// set all settings entry boxes to their actual status
sketchPromptBox.setSelected(getBoolean("sketchbook.prompt"));
sketchCleanBox.setSelected(getBoolean("sketchbook.auto_clean"));
sketchbookLocationField.setText(get("sketchbook.path"));
exportLibraryBox.setSelected(getBoolean("export.library"));
//exportLibraryBox.setSelected(getBoolean("export.library"));
externalEditorBox.setSelected(getBoolean("editor.external"));
frame.show();
@@ -423,7 +484,7 @@ public class PdePreferences extends JComponent {
// .................................................................
public void load(InputStream input) throws IOException {
static public void load(InputStream input) throws IOException {
BufferedReader reader =
new BufferedReader(new InputStreamReader(input));
@@ -448,7 +509,7 @@ public class PdePreferences extends JComponent {
// .................................................................
public void save() {
static public void save() {
try {
FileOutputStream output = new FileOutputStream(preferencesFile);
PrintWriter writer = new PrintWriter(new OutputStreamWriter(output));
+11 -9
View File
@@ -181,11 +181,13 @@ public class PdePreprocessor {
imports.copyInto(extraImports);
// if using opengl, add it to the special imports
/*
if (PdePreferences.get("renderer").equals("opengl")) {
extraImports = new String[imports.size() + 1];
imports.copyInto(extraImports);
extraImports[extraImports.length - 1] = "processing.opengl.*";
}
*/
/*
if (codeFolderPackages != null) {
@@ -348,19 +350,19 @@ public class PdePreprocessor {
}
}
boolean opengl = PdePreferences.get("renderer").equals("opengl");
if (opengl) {
out.println("import processing.opengl.*; ");
}
//boolean opengl = PdePreferences.get("renderer").equals("opengl");
//if (opengl) {
//out.println("import processing.opengl.*; ");
//}
if (programType < JAVA) {
// open the class definition
out.print("public class " + className + " extends ");
if (opengl) {
out.print("PAppletGL");
} else {
out.print("PApplet");
}
//if (opengl) {
//out.print("PAppletGL");
//} else {
out.print("PApplet");
//}
out.print(" {");
if (programType == STATIC) {
+176 -240
View File
@@ -1,10 +1,10 @@
/* -*- mode: jde; c-basic-offset: 2; indent-tabs-mode: nil -*- */
/*
PdeRuntime - runs compiled java applet
PdeRuntime - runs a compiled java applet
Part of the Processing project - http://processing.org
Except where noted, code is written by Ben Fry and is
Copyright (c) 2004-05 Ben Fry and Casey Reas
Copyright (c) 2001-04 Massachusetts Institute of Technology
This program is free software; you can redistribute it and/or modify
@@ -52,10 +52,6 @@ public class PdeRuntime implements PdeMessageConsumer {
OutputStream processOutput;
PdeMessageSiphon processError;
//boolean externalRuntime;
//String libraryPath;
//String classPath;
public PdeRuntime(PdeSketch sketch, PdeEditor editor) {
this.sketch = sketch;
@@ -64,245 +60,18 @@ public class PdeRuntime implements PdeMessageConsumer {
public void start(Point windowLocation) throws PdeException {
//System.out.println(" externalRuntime is " + sketch.externalRuntime);
this.leechErr = new PrintStream(new PdeMessageStream(this));
Point parentLoc = editor.getLocation();
Insets parentInsets = editor.getInsets();
int x1 = parentLoc.x - 20;
int y1 = parentLoc.y;
// try to figure out the size of the applet from the code
int initialWidth = PApplet.DEFAULT_WIDTH;
int initialHeight = PApplet.DEFAULT_HEIGHT;
try {
PatternMatcher matcher = new Perl5Matcher();
PatternCompiler compiler = new Perl5Compiler();
if (editor.presenting) {
startPresenting();
// this matches against any uses of the size() function,
// whether they contain numbers of variables or whatever.
// this way, no warning is shown if size() isn't actually
// used in the applet, which is the case especially for
// beginners that are cutting/pasting from the reference.
String sizing =
"[\\s\\;]size\\s*\\(\\s*(\\S+)\\s*,\\s*(\\S+)\\s*\\);";
Pattern pattern = compiler.compile(sizing);
} else if (sketch.externalRuntime) {
startExternalRuntime(windowLocation);
// adds a space at the beginning, in case size() is the very
// first thing in the program (very common), since the regexp
// needs to check for things in front of it.
PatternMatcherInput input =
new PatternMatcherInput(" " + sketch.code[0].program);
if (matcher.contains(input, pattern)) {
MatchResult result = matcher.getMatch();
try {
initialWidth = Integer.parseInt(result.group(1).toString());
initialHeight = Integer.parseInt(result.group(2).toString());
} catch (NumberFormatException e) {
/*
// found a reference to size, but it didn't
// seem to contain numbers
final String message =
"The size of this applet could not automatically be\n" +
"determined from your code. You'll have to edit the\n" +
"HTML file to set the size of the applet.";
PdeBase.showWarning("Could not find applet size", message, null);
*/
}
} // else no size() command found
} catch (Exception e) {
e.printStackTrace(); // later fail silently
}
try {
if (sketch.externalRuntime) {
// if there was a saved location (this guy has been run more than
// once) then windowLocation will be set to the last position of
// the sketch window. this will be passed to the PApplet runner
// using something like --external=e30,20 where the e stands for
// exact. otherwise --external=x,y for just the regular positioning.
/*
String location = (windowLocation != null) ?
(PApplet.EXTERNAL_EXACT_LOCATION +
windowLocation.x + "," + windowLocation.y) :
(x1 + "," + y1);
*/
String location =
(windowLocation != null) ?
(PApplet.EXT_EXACT_LOCATION +
windowLocation.x + "," + windowLocation.y) :
(PApplet.EXT_LOCATION + x1 + "," + y1);
//System.out.println("library path is " + sketch.libraryPath);
String command[] = new String[] {
//"cmd", "/c", "start",
"java",
"-Djava.library.path=" +
// sketch.libraryPath might be ""
// librariesClassPath will always have sep char prepended
sketch.libraryPath +
File.pathSeparator + System.getProperty("java.library.path"),
"-cp",
sketch.classPath + PdeSketchbook.librariesClassPath,
"processing.core.PApplet",
location,
PApplet.EXT_SIZE + initialWidth + "," + initialHeight,
PApplet.EXT_SKETCH_FOLDER + sketch.folder.getAbsolutePath(),
sketch.mainClassName
};
//PApplet.printarr(command);
//PApplet.println(PApplet.join(command, " "));
process = Runtime.getRuntime().exec(command);
processInput = new SystemOutSiphon(process.getInputStream());
processError = new PdeMessageSiphon(process.getErrorStream(), this);
processOutput = process.getOutputStream();
} else { // !externalRuntime
PdeClassLoader loader = new PdeClassLoader();
Class c = loader.loadClass(sketch.mainClassName);
applet = (PApplet) c.newInstance();
// replaces setRuntime with PApplet having leechErr [fry]
applet.leechErr = leechErr;
applet.folder = sketch.folder.getAbsolutePath();
// has to be before init
//applet.serialProperties(PdePreferences.properties);
applet.init();
if (applet.exception != null) {
/*
TODO: fix me
if (applet.exception instanceof PortInUseException) {
throw new PdeException("Another program is already " +
"using the serial port.");
} else {
*/
throw new PdeException(applet.exception.getMessage());
}
applet.start();
if (editor.presenting) {
//window = new Window(new Frame());
// toxi_030903: attach applet window to editor's presentation window
window = new Window(editor.presentationWindow);
// toxi_030903: moved keyListener to PdeEditor's presentationWindow
} else {
//window = new Frame(sketch.name); // use ugly windows
window = new Frame(sketch.name); // use ugly windows
((Frame)window).setResizable(false);
if (editor.icon != null) {
((Frame)window).setIconImage(editor.icon);
}
window.pack(); // to get a peer, size set later, need for insets
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
stop();
editor.doClose();
}
});
// toxi_030903: only attach keyListener if not in presentation mode
// else events are coming directly from editor.presentationWindow
applet.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
//System.out.println("applet got " + e);
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
stop();
editor.doClose();
}
}
});
y1 += parentInsets.top;
}
window.add(applet);
Dimension screen =
Toolkit.getDefaultToolkit().getScreenSize();
window.setLayout(null);
if (editor.presenting) {
/*
window.setBounds((screen.width - applet.width) / 2,
(screen.height - applet.height) / 2,
applet.width, applet.height);
applet.setBounds(0, 0, applet.width, applet.height);
*/
window.setBounds((screen.width - initialWidth) / 2,
(screen.height - initialHeight) / 2,
initialWidth, initialHeight);
applet.setBounds(0, 0, initialWidth, initialHeight);
} else {
Insets insets = window.getInsets();
//System.out.println(insets);
if ((applet.width != 0) &&
(applet.height != 0) &&
(applet.width != PApplet.DEFAULT_WIDTH) &&
(applet.height != PApplet.DEFAULT_HEIGHT)) {
initialWidth = applet.width;
initialHeight = applet.height;
}
int minW = PdePreferences.getInteger("run.window.width.minimum");
int minH = PdePreferences.getInteger("run.window.height.minimum");
int windowW =
Math.max(initialWidth, minW) + insets.left + insets.right;
//Math.max(applet.width, minW) + insets.left + insets.right;
int windowH =
Math.max(initialHeight, minH) + insets.top + insets.bottom;
//Math.max(applet.height, minH) + insets.top + insets.bottom;
if (x1 - windowW > 10) { // if it fits to the left of the window
window.setBounds(x1 - windowW, y1, windowW, windowH);
//windowX = x1 - ww;
//windowY = y1;
} else { // if it fits inside the editor window
x1 = parentLoc.x + PdePreferences.GRID_SIZE * 2; // 66
y1 = parentLoc.y + PdePreferences.GRID_SIZE * 2; // 66
if ((x1 + windowW > screen.width - PdePreferences.GRID_SIZE) ||
(y1 + windowH > screen.height - PdePreferences.GRID_SIZE)) {
// otherwise center on screen
x1 = (screen.width - windowW) / 2;
y1 = (screen.height - windowH) / 2;
}
window.setBounds(x1, y1, windowW, windowH); //ww, wh);
}
Color windowBgColor = PdePreferences.getColor("run.window.bgcolor");
window.setBackground(windowBgColor);
/*
applet.setBounds((windowW - applet.width)/2,
insets.top + ((windowH -
insets.top - insets.bottom) -
applet.height)/2,
windowW, windowH);
*/
applet.setBounds((windowW - initialWidth)/2,
insets.top + ((windowH -
insets.top - insets.bottom) -
initialHeight)/2,
windowW, windowH);
}
applet.setVisible(true); // no effect
if (windowLocation != null) {
window.setLocation(windowLocation);
}
window.show();
applet.requestFocus(); // necessary for key events
} else {
startInternal(windowLocation);
}
} catch (Exception e) {
@@ -319,6 +88,173 @@ public class PdeRuntime implements PdeMessageConsumer {
}
public void startPresenting() throws Exception {
String command[] = new String[] {
"java",
"-Djava.library.path=" +
sketch.libraryPath +
File.pathSeparator + System.getProperty("java.library.path"),
"-cp",
sketch.classPath + PdeSketchbook.librariesClassPath,
"processing.core.PApplet",
PApplet.ARGS_EXTERNAL,
PApplet.ARGS_PRESENT,
PApplet.ARGS_PRESENT_BGCOLOR + "=" +
PdePreferences.get("run.present.bgcolor"),
PApplet.ARGS_DISPLAY + "=" +
PdePreferences.get("run.display"),
PApplet.ARGS_SKETCH_FOLDER + "=" +
sketch.folder.getAbsolutePath(),
sketch.mainClassName
};
process = Runtime.getRuntime().exec(command);
processInput = new SystemOutSiphon(process.getInputStream());
processError = new PdeMessageSiphon(process.getErrorStream(), this);
processOutput = process.getOutputStream();
}
public void startExternalRuntime(Point windowLocation) throws Exception {
// if there was a saved location (this guy has been run more than
// once) then windowLocation will be set to the last position of
// the sketch window. this will be passed to the PApplet runner
// using something like --external=e30,20 where the e stands for
// exact. otherwise --external=x,y for just the regular positioning.
Point editorLocation = editor.getLocation();
String location =
(windowLocation != null) ?
(PApplet.ARGS_LOCATION + "=" +
windowLocation.x + "," + windowLocation.y) :
(PApplet.ARGS_EDITOR_LOCATION + "=" +
editorLocation.x + "," + editorLocation.y);
//System.out.println("library path is " + sketch.libraryPath);
String command[] = new String[] {
// this made the code folder bug go away, but killed stdio
//"cmd", "/c", "start",
"java",
"-Djava.library.path=" +
// sketch.libraryPath might be ""
// librariesClassPath will always have sep char prepended
sketch.libraryPath +
File.pathSeparator + System.getProperty("java.library.path"),
"-cp",
sketch.classPath + PdeSketchbook.librariesClassPath,
"processing.core.PApplet",
location,
PApplet.ARGS_EXTERNAL,
PApplet.ARGS_DISPLAY + "=" + PdePreferences.get("run.display"),
PApplet.ARGS_SKETCH_FOLDER + "=" + sketch.folder.getAbsolutePath(),
sketch.mainClassName
};
//PApplet.printarr(command);
//PApplet.println(PApplet.join(command, " "));
process = Runtime.getRuntime().exec(command);
processInput = new SystemOutSiphon(process.getInputStream());
processError = new PdeMessageSiphon(process.getErrorStream(), this);
processOutput = process.getOutputStream();
}
public void startInternal(Point windowLocation) throws Exception {
Point editorLocation = editor.getLocation();
//Insets editorInsets = editor.getInsets();
int windowX = editorLocation.x;
int windowY = editorLocation.y + editor.getInsets().top;
PdeClassLoader loader = new PdeClassLoader();
Class c = loader.loadClass(sketch.mainClassName);
applet = (PApplet) c.newInstance();
applet.leechErr = leechErr;
applet.folder = sketch.folder.getAbsolutePath();
applet.init();
//applet.start();
while ((applet.width == 0) && !applet.finished) {
try {
if (applet.exception != null) {
throw new PdeException(applet.exception.getMessage());
}
Thread.sleep(5);
} catch (InterruptedException e) { }
}
window = new Frame(sketch.name); // use ugly window
((Frame)window).setResizable(false);
if (editor.icon != null) {
((Frame)window).setIconImage(editor.icon);
}
window.pack(); // to get a peer, size set later, need for insets
window.addWindowListener(new WindowAdapter() {
public void windowClosing(WindowEvent e) {
stop();
editor.doClose();
}
});
applet.addKeyListener(new KeyAdapter() {
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ESCAPE) {
stop();
editor.doClose();
}
}
});
window.add(applet);
Dimension screen =
Toolkit.getDefaultToolkit().getScreenSize();
window.setLayout(null);
Insets insets = window.getInsets();
int minW = PdePreferences.getInteger("run.window.width.minimum");
int minH = PdePreferences.getInteger("run.window.height.minimum");
int windowW =
Math.max(applet.width, minW) + insets.left + insets.right;
int windowH =
Math.max(applet.height, minH) + insets.top + insets.bottom;
if (windowX - windowW > 10) { // if it fits to the left of the window
window.setBounds(windowX - windowW, windowY, windowW, windowH);
} else { // if it fits inside the editor window
windowX = editorLocation.x + PdePreferences.GRID_SIZE * 2; // 66
windowY = editorLocation.y + PdePreferences.GRID_SIZE * 2; // 66
if ((windowX + windowW > screen.width - PdePreferences.GRID_SIZE) ||
(windowY + windowH > screen.height - PdePreferences.GRID_SIZE)) {
// otherwise center on screen
windowX = (screen.width - windowW) / 2;
windowY = (screen.height - windowH) / 2;
}
window.setBounds(windowX, windowY, windowW, windowH); //ww, wh);
}
Color windowBgColor = PdePreferences.getColor("run.window.bgcolor");
window.setBackground(windowBgColor);
int usableH = windowH - insets.top - insets.bottom;
applet.setBounds((windowW - applet.width)/2,
insets.top + (usableH - applet.height) / 2,
windowW, windowH);
applet.setVisible(true); // no effect
if (windowLocation != null) {
window.setLocation(windowLocation);
}
window.show();
applet.requestFocus(); // necessary for key events
}
public void stop() {
// check for null in case stop is called during compilation
if (applet != null) {
+3 -3
View File
@@ -1153,9 +1153,9 @@ public class PdeSketch {
}
// if running in opengl mode, this is gonna be external
if (PdePreferences.get("renderer").equals("opengl")) {
externalRuntime = true;
}
//if (PdePreferences.get("renderer").equals("opengl")) {
//externalRuntime = true;
//}
// 2. run preproc on that code using the sugg class name
// to create a single .java file and write to buildpath
+1 -2
View File
@@ -199,8 +199,7 @@ public class PdeSketchbook {
// jdk13 on osx, or jdk11
// though apparently still available for 1.4
if ((PdeBase.platform == PdeBase.MACOS9) ||
(PdeBase.platform == PdeBase.MACOSX)) {
if (PdeBase.isMacOS()) {
MRJFileUtils.setFileTypeAndCreator(newbieFile,
MRJOSType.kTypeTEXT,
new MRJOSType("Pde1"));