diff --git a/processing/core/PApplet.java b/processing/core/PApplet.java index 2017e52be..e81cd2396 100644 --- a/processing/core/PApplet.java +++ b/processing/core/PApplet.java @@ -1746,6 +1746,82 @@ public class PApplet extends Applet // FILE INPUT + public File inputFile() { + Frame frame = null; + Component comp = getParent(); + while (comp != null) { + if (comp instanceof Frame) { + frame = (Frame) comp; + break; + } + comp = comp.getParent(); + } + //System.out.println("found frame " + frame); + if (frame == null) frame = new Frame(); + + FileDialog fd = new FileDialog(frame, + "Select a file...", + FileDialog.LOAD); + fd.show(); + + String directory = fd.getDirectory(); + String filename = fd.getFile(); + if (filename == null) return null; + return new File(directory, filename); + } + + + public File outputFile() { + Frame frame = null; + Component comp = getParent(); + while (comp != null) { + if (comp instanceof Frame) { + frame = (Frame) comp; + break; + } + comp = comp.getParent(); + } + //System.out.println("found frame " + frame); + if (frame == null) frame = new Frame(); + + FileDialog fd = new FileDialog(frame, + "Save as...", + FileDialog.SAVE); + fd.show(); + + String directory = fd.getDirectory(); + String filename = fd.getFile(); + if (filename == null) return null; + return new File(directory, filename); + } + + + public BufferedReader reader(File file) { + try { + FileInputStream fis = new FileInputStream(file); + InputStreamReader isr = new InputStreamReader(fis); + return new BufferedReader(isr); + + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + + public PrintWriter writer(File file) { + try { + FileOutputStream fos = new FileOutputStream(file); + OutputStreamWriter osw = new OutputStreamWriter(fos); + return new PrintWriter(osw); + + } catch (IOException e) { + e.printStackTrace(); + } + return null; + } + + public InputStream openStream(String filename) throws IOException { InputStream stream = null; @@ -1825,6 +1901,17 @@ public class PApplet extends Applet } + static public String[] loadStrings(File file) { + try { + return loadStrings(new FileInputStream(file)); + + } catch (IOException e) { + System.err.println("problem loading strings from " + file); + e.printStackTrace(); + } + return null; + } + public String[] loadStrings(String filename) { try { return loadStrings(openStream(filename)); diff --git a/processing/core/todo.txt b/processing/core/todo.txt index 1a99bed73..3d76f75ad 100644 --- a/processing/core/todo.txt +++ b/processing/core/todo.txt @@ -151,6 +151,10 @@ X processing.net -> PClient, PServer X write client/server implementations for new-style api X basic test with old net server has things working fine +040908 +X inputFile, outputFile, reader, writer commands +X also loadStrings(File file) + _ massive graphics engine changes _ explicitly state depth()/nodepth() _ move to new graphics engine