working towards application with document launching

This commit is contained in:
benfry
2005-01-30 03:39:19 +00:00
parent 75198bb7d0
commit faec8ffd07
9 changed files with 336 additions and 114 deletions

View File

@@ -45,6 +45,8 @@ import com.apple.mrj.*;
public class PdeBase {
static final String VERSION = "0075 Alpha";
static String openedAtStartup;
PdeEditor editor;
static final int WINDOWS = 1;
@@ -61,6 +63,22 @@ public class PdeBase {
static public void main(String args[]) {
if (args.length == 1) {
PdeBase.openedAtStartup = args[0];
}
MRJOpenDocumentHandler startupOpen = new MRJOpenDocumentHandler() {
public void handleOpenFile(File file) {
// this will only get set once.. later will be handled
// by the PdeEditor version of this fella
if (PdeBase.openedAtStartup == null) {
//System.out.println("handling outside open file: " + file);
PdeBase.openedAtStartup = file.getAbsolutePath();
}
}
};
MRJApplicationUtils.registerOpenDocumentHandler(startupOpen);
PdeBase app = new PdeBase();
}
@@ -126,6 +144,146 @@ public class PdeBase {
// .................................................................
static final int kDocumentsFolderType =
('d' << 24) | ('o' << 16) | ('c' << 8) | 's';
static final int kPreferencesFolderType =
('p' << 24) | ('r' << 16) | ('e' << 8) | 'f';
static final int kDomainLibraryFolderType =
('d' << 24) | ('l' << 16) | ('i' << 8) | 'b';
static final short kUserDomain = -32763;
static public File getProcessingDataFolder() {
File dataFolder = null;
if (platform == MACOSX) {
// carbon folder constants
// http://developer.apple.com/documentation/Carbon/Reference
// /Folder_Manager/folder_manager_ref/constant_6.html#/
// /apple_ref/doc/uid/TP30000238/C006889
// additional information found int the local file:
// /System/Library/Frameworks/CoreServices.framework
// /Versions/Current/Frameworks/CarbonCore.framework/Headers/
// this is the 1.4 version.. but using 1.3 since i have the stubs
// import com.apple.eio.*
//println(FileManager.findFolder(kUserDomain,
// kDomainLibraryFolderType));
// not clear if i can write to this folder tho..
try {
if (false) {
new FileInputStream("ignored");
}
MRJOSType domainLibrary = new MRJOSType("dlib");
File libraryFolder = MRJFileUtils.findFolder(domainLibrary);
//MRJFileUtils.findFolder(kUserDomain, domainLibrary);
dataFolder = new File(libraryFolder, "Processing");
} catch (FileNotFoundException e) {
//e.printStackTrace();
//System.exit(1);
showError("Problem getting Library folder",
"Error getting the Processing library folder.", e);
}
} else if (platform == WINDOWS) {
// looking for Documents and Settings/blah/Application Data/Processing
// this is just based on the other documentation, and eyeballing
// that part of the registry.. not confirmed by any msft/msdn docs.
// HKEY_CURRENT_USER\Software\Microsoft
// \Windows\CurrentVersion\Explorer\Shell Folders
// Value Name: AppData
// Value Type: REG_SZ
// Value Data: path
/*
RegistryKey topKey = Registry.getTopLevelKey("HKCU");
String localKeyPath =
"\\Software\\Microsoft\\Windows\\CurrentVersion" +
"\\Explorer\\Shell Folders";
RegistryKey localKey = topKey.openSubkey(topKey, localKeyPath);
String appDataPath = localKey.getStringValue("AppData");
return new File(appDataPath, "Processing");
*/
return null;
} else {
// otherwise make a .processing directory int the user's home dir
File home = new File(System.getProperty("user.home"));
dataFolder = new File(home, ".processing");
}
// create the folder if it doesn't exist already
if (!dataFolder.exists()) dataFolder.mkdirs();
return dataFolder;
}
static public File getProcessingDataFile(String filename) {
return new File(getProcessingDataFolder(), filename);
}
static public File getDefaultSketchbookFolder() {
if (platform == MACOSX) {
// looking for /Users/blah/Documents/Processing
// carbon folder constants
// http://developer.apple.com/documentation/Carbon/Reference/Folder_Manager/folder_manager_ref/constant_6.html#//apple_ref/doc/uid/TP30000238/C006889
// additional information found int the local file:
// /System/Library/Frameworks/CoreServices.framework/Versions/Current/Frameworks/CarbonCore.framework/Headers/
// this is the 1.4 version.. but using 1.3 since i have the stubs
// import com.apple.eio.*
//println(FileManager.findFolder(kUserDomain,
// kDomainLibraryFolderType));
// not clear if i can write to this folder tho..
try {
MRJOSType domainDocuments = new MRJOSType("docs");
File libraryFolder = MRJFileUtils.findFolder(domainDocuments);
//MRJFileUtils.findFolder(kUserDomain, domainDocuments);
return new File(libraryFolder, "Processing");
} catch (FileNotFoundException e) {
showError("sketch folder problem",
"Could not locate default sketch folder location.", e);
}
} else if (platform == WINDOWS) {
// looking for Documents and Settings/blah/My Documents/Processing
// http://support.microsoft.com/?kbid=221837&sd=RMVP
// The path to the My Documents folder is stored in the
// following registry key, where path is the complete path
// to your storage location:
// HKEY_CURRENT_USER\Software\Microsoft\Windows\CurrentVersion\Explorer\Shell Folders
// Value Name: Personal
// Value Type: REG_SZ
// Value Data: path
}
return null;
// if it failed, or if on linux, prompt the user or quit
/*
File home = new File(System.getProperty("user.home"));
File phome = new File(home, ".processing");
if (!phome.exists()) phome.mkdirs();
return phome;
*/
}
/*
static public File getProcessingHome() {
File home = new File(System.getProperty("user.home"));
@@ -135,7 +293,7 @@ public class PdeBase {
// in the default preferences.txt because it mentions this path
if (PdeBase.platform == PdeBase.MACOSX) {
// on macosx put the sketchbook in the "Documents" folder
phome = new File(home, "Documents" + File.separator + "Processing");
//phome = new File(home, "Documents" + File.separator + "Processing");
} else if (PdeBase.platform == PdeBase.WINDOWS) {
// on windows put the sketchbook in the "My Documents" folder
@@ -150,11 +308,7 @@ public class PdeBase {
if (!phome.exists()) phome.mkdirs();
return phome;
}
static public File getProcessingHome(String filename) {
return new File(getProcessingHome(), filename);
}
*/
// .................................................................

View File

@@ -42,7 +42,8 @@ import com.apple.mrj.*;
public class PdeEditor extends JFrame
implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler
implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler,
MRJOpenDocumentHandler //, MRJOpenApplicationHandler
{
// yeah
static final String WINDOW_TITLE = "Processing";
@@ -120,13 +121,15 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler
public PdeEditor() {
super(WINDOW_TITLE + " - " + PdeBase.VERSION);
// this is needed by just about everything else
preferences = new PdePreferences();
// #@$*(@#$ apple.. always gotta think different
MRJApplicationUtils.registerAboutHandler(this);
MRJApplicationUtils.registerPrefsHandler(this);
MRJApplicationUtils.registerQuitHandler(this);
MRJApplicationUtils.registerOpenDocumentHandler(this);
// this is needed by just about everything else
preferences = new PdePreferences();
// set the window icon
try {
@@ -368,18 +371,23 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler
}
// last sketch that was in use
// last sketch that was in use, or used to launch the app
//String sketchName = PdePreferences.get("last.sketch.name");
String sketchPath = PdePreferences.get("last.sketch.path");
//PdeSketch sketchTemp = new PdeSketch(sketchPath);
if ((sketchPath != null) && (new File(sketchPath)).exists()) {
// don't check modified because nothing is open yet
handleOpen2(sketchPath);
if (PdeBase.openedAtStartup != null) {
handleOpen2(PdeBase.openedAtStartup);
} else {
handleNew2(true);
//String sketchName = PdePreferences.get("last.sketch.name");
String sketchPath = PdePreferences.get("last.sketch.path");
//PdeSketch sketchTemp = new PdeSketch(sketchPath);
if ((sketchPath != null) && (new File(sketchPath)).exists()) {
// don't check modified because nothing is open yet
handleOpen2(sketchPath);
} else {
handleNew2(true);
}
}
@@ -1031,19 +1039,25 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler
presentationWindow.toFront();
}
try {
if (!sketch.handleRun()) return;
final SwingWorker worker = new SwingWorker() {
public Object construct() {
try {
if (!sketch.handleRun()) return null;
runtime = new PdeRuntime(sketch, this);
runtime.start(presenting ? presentLocation : appletLocation);
watcher = new RunButtonWatcher();
runtime = new PdeRuntime(sketch, PdeEditor.this);
runtime.start(presenting ? presentLocation : appletLocation);
watcher = new RunButtonWatcher();
} catch (PdeException e) {
error(e);
} catch (PdeException e) {
error(e);
} catch (Exception e) {
e.printStackTrace();
}
} catch (Exception e) {
e.printStackTrace();
}
return null; // needn't return anything
}
};
worker.start();
//sketch.cleanup(); // where does this go?
}
@@ -1275,6 +1289,16 @@ implements MRJAboutHandler, MRJQuitHandler, MRJPrefsHandler
}
/**
* This is the implementation of the MRJ open document event,
* and the Windows XP open document will be routed through this too.
*/
public void handleOpenFile(File file) {
//System.out.println("handling open file: " + file);
handleOpen(file.getAbsolutePath());
}
/**
* Open a sketch given the full path to the .pde file.
* Pass in 'null' to prompt the user for the name of the sketch.

View File

@@ -17,8 +17,8 @@
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software Foundation,
Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*/
@@ -44,12 +44,12 @@ import javax.swing.undo.*;
on first run:
processing.properties is created in user.home
it contains the contents of
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
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 {
@@ -114,7 +114,7 @@ public class PdePreferences extends JComponent {
load(PdeBase.getStream("preferences.txt"));
} catch (Exception e) {
PdeBase.showError(null, "Could not read default settings.\n" +
PdeBase.showError(null, "Could not read default settings.\n" +
"You'll need to reinstall Processing.", e);
}
@@ -146,12 +146,12 @@ public class PdePreferences extends JComponent {
//File home = new File(System.getProperty("user.home"));
//File processingHome = new File(home, "Processing");
//preferencesFile = new File(home, PREFS_FILE);
preferencesFile = PdeBase.getProcessingHome(PREFS_FILE);
preferencesFile = PdeBase.getProcessingDataFile(PREFS_FILE);
if (!preferencesFile.exists()) {
// create a new preferences file if none exists
// saves the defaults out to the file
save();
save();
} else {
// load the previous preferences file
@@ -160,7 +160,7 @@ public class PdePreferences extends JComponent {
load(new FileInputStream(preferencesFile));
} catch (Exception ex) {
PdeBase.showError("Error reading preferences",
PdeBase.showError("Error reading preferences",
"Error reading the preferences file. " +
"Please delete (or move)\n" +
preferencesFile.getAbsolutePath() +
@@ -192,7 +192,7 @@ public class PdePreferences extends JComponent {
// [ ] Prompt for name and folder when creating new sketch
sketchPromptBox =
sketchPromptBox =
new JCheckBox("Prompt for name when opening or creating a sketch");
pain.add(sketchPromptBox);
d = sketchPromptBox.getPreferredSize();
@@ -211,7 +211,7 @@ public class PdePreferences extends JComponent {
top += d.height + GUI_BETWEEN;
// Sketchbook location:
// Sketchbook location:
// [...............................] [ Browse ]
label = new JLabel("Sketchbook location:");
@@ -243,14 +243,14 @@ public class PdePreferences extends JComponent {
// take max height of all components to vertically align em
vmax = Math.max(d.height, d2.height);
//label.setBounds(left, top + (vmax-d.height)/2,
//label.setBounds(left, top + (vmax-d.height)/2,
// d.width, d.height);
//h = left + d.width + GUI_BETWEEN;
sketchbookLocationField.setBounds(left, top + (vmax-d.height)/2,
sketchbookLocationField.setBounds(left, top + (vmax-d.height)/2,
d.width, d.height);
h = left + d.width + GUI_SMALL; //GUI_BETWEEN;
button.setBounds(h, top + (vmax-d2.height)/2,
button.setBounds(h, top + (vmax-d2.height)/2,
d2.width, d2.height);
right = Math.max(right, h + d2.width + GUI_BIG);
@@ -259,7 +259,7 @@ public class PdePreferences extends JComponent {
// [ ] Enable export to "Library"
exportLibraryBox = new JCheckBox("Enable advanced \"Library\" features" +
exportLibraryBox = new JCheckBox("Enable advanced \"Library\" features" +
" (requires restart)");
exportLibraryBox.setEnabled(false);
pain.add(exportLibraryBox);
@@ -282,11 +282,11 @@ public class PdePreferences extends JComponent {
// More preferences are in the ...
/*
String blather =
"More preferences can be edited directly\n" +
String blather =
"More preferences can be edited directly\n" +
"in the file " + preferencesFile.getAbsolutePath();
//"More preferences are in the 'lib' folder inside text files\n" +
//"named preferences.txt and pde_" +
//"named preferences.txt and pde_" +
//PdeBase.platforms[PdeBase.platform] + ".properties";
JTextArea textarea = new JTextArea(blather);
@@ -314,7 +314,7 @@ public class PdePreferences extends JComponent {
// [ OK ] [ Cancel ] maybe these should be next to the message?
right = Math.max(right, left + d.width + GUI_BETWEEN +
right = Math.max(right, left + d.width + GUI_BETWEEN +
BUTTON_WIDTH + GUI_SMALL + BUTTON_WIDTH);
button = new JButton(PROMPT_OK);
@@ -424,7 +424,7 @@ public class PdePreferences extends JComponent {
public void load(InputStream input) throws IOException {
BufferedReader reader =
BufferedReader reader =
new BufferedReader(new InputStreamReader(input));
//table = new Hashtable();
@@ -499,7 +499,7 @@ public class PdePreferences extends JComponent {
skprops.put("last.sketch.directory", sketchDir.getAbsolutePath());
//skprops.put("user.name", userName);
skprops.put("last.divider.location",
skprops.put("last.divider.location",
String.valueOf(splitPane.getDividerLocation()));
//
@@ -510,7 +510,7 @@ public class PdePreferences extends JComponent {
// save() is deprecated, and didn't properly
// throw exceptions when it wasn't working
skprops.store(output, "Settings for processing. " +
skprops.store(output, "Settings for processing. " +
"See lib/preferences.txt for defaults.");
// need to close the stream.. didn't do this before
@@ -540,7 +540,7 @@ public class PdePreferences extends JComponent {
//properties.getProperty(attribute) : applet.getParameter(attribute);
String value = properties.getProperty(attribute);
return (value == null) ?
return (value == null) ?
defaultValue : value;
*/
}
@@ -585,13 +585,13 @@ public class PdePreferences extends JComponent {
try {
return Integer.parseInt(value);
} catch (NumberFormatException e) {
} catch (NumberFormatException e) {
// ignored will just fall through to returning the default
System.err.println("expecting an integer: " + attribute + " = " + value);
}
return defaultValue;
//if (value == null) return defaultValue;
//return (value == null) ? defaultValue :
//return (value == null) ? defaultValue :
//Integer.parseInt(value);
*/
}
@@ -622,7 +622,7 @@ public class PdePreferences extends JComponent {
String r = Integer.toHexString(what.getRed());
String g = Integer.toHexString(what.getGreen());
String b = Integer.toHexString(what.getBlue());
set(attr, "#" + r.substring(r.length() - 2) +
set(attr, "#" + r.substring(r.length() - 2) +
g.substring(g.length() - 2) + b.substring(b.length() - 2));
}
@@ -634,8 +634,8 @@ public class PdePreferences extends JComponent {
StringTokenizer st = new StringTokenizer(str, ",");
String fontname = st.nextToken();
String fontstyle = st.nextToken();
return new Font(fontname,
((fontstyle.indexOf("bold") != -1) ? Font.BOLD : 0) |
return new Font(fontname,
((fontstyle.indexOf("bold") != -1) ? Font.BOLD : 0) |
((fontstyle.indexOf("italic") != -1) ? Font.ITALIC : 0),
Integer.parseInt(st.nextToken()));
}
@@ -682,11 +682,11 @@ public class PdePreferences extends JComponent {
}
vmax = Math.max(d.height, d2.height);
label.setBounds(left, top + (vmax-d.height)/2,
label.setBounds(left, top + (vmax-d.height)/2,
d.width, d.height);
h = left + d.width + BETWEEN;
combo.setBounds(h, top + (vmax-d2.height)/2,
d2.width, d2.height);
combo.setBounds(h, top + (vmax-d2.height)/2,
d2.width, d2.height);
right = Math.max(right, h + d2.width + BIG);
top += vmax + BETWEEN;
*/
@@ -705,7 +705,7 @@ public class PdePreferences extends JComponent {
//boolean ee = new Boolean(skprops.getProperty("editor.external", "false")).booleanValue();
//editor.setExternalEditor(ee);
///} catch (Exception e) {
///} catch (Exception e) {
// this exception doesn't matter, it's just the normal course of things
// the app reaches here when no sketch.properties file exists
//e.printStackTrace();

View File

@@ -109,7 +109,7 @@ public class PdeSketchbook {
//String folderName = PdePreferences.get("sketchbook.name.default");
//File sketchbookFolder = new File(home, folderName);
File sketchbookFolder = PdeBase.getProcessingHome();
File sketchbookFolder = PdeBase.getDefaultSketchbookFolder();
PdePreferences.set("sketchbook.path",
sketchbookFolder.getAbsolutePath());