/* WordDelegate */ import com.apple.yellow.foundation.*; import com.apple.yellow.application.*; public class WordDelegate { NSTextView theText; public void newText(Object sender) { theText.setString(""); NSWindow window = theText.window(); window.setTitle("Untitled"); window.makeKeyAndOrderFront(window); } public void openText(Object sender) { // Get a new Open Panel NSOpenPanel panel = NSOpenPanel.openPanel(); // Have it run modal and look for files of "rtf" or "rtfd" type: String[] types = { "rtf", "rtfd" }; if (panel.runModalForTypes( new NSArray(types) ) != 0) { // we have a valid file, ask theText to read it in String filename = (String) panel.filenames().lastObject(); theText.readRTFDFromFile(filename); // Update the window's name with the filename, but in a readable way: NSWindow window = theText.window(); window.setTitleWithRepresentedFilename(filename); // bring the window up in case the user has closed it: window.makeKeyAndOrderFront(window); } } public void saveText(Object sender) { // Get a new Save Panel: NSSavePanel panel = NSSavePanel.savePanel(); // Set it to save "rtfd" files: panel.setRequiredFileType("rtfd"); // Run modal, which returns YES if a valid path is chosen: if (panel.runModal() != 0) { // Ask the text to write itself to the chosen filename // But don't make it back up before // Set atomically:YES if you want "save backups", slower but more secure theText.writeRTFDToFile(panel.filename(), false); // Update the title bar of the window theText.window().setTitleWithRepresentedFilename(panel.filename()); } } }