// Essentially links an InputStream to the proper channels in the log box. private static void printOutput(InputStream in, SimpleAttributeSet set) { int i = 0; String s = ""; try { while ((i = in.read()) != -1) { s += (char) i; // print(, set); } } catch (IOException io) { println("Error: IOException when reading InputStream " + in.toString(), progErr); } println(s); }
private byte[] loadClassData(String className) throws IOException { Playground.println("Loading class " + className + ".class", warning); File f = new File(System.getProperty("user.dir") + "/" + className + ".class"); byte[] b = new byte[(int) f.length()]; new FileInputStream(f).read(b); return b; }
// Makes sure the log is visible. private static void displayLog() { println("Displayed", warning); if (!consoleDisplayed) { splitter.add(outputScroll); splitter.setDividerLocation(.8); consoleDisplayed = true; } }
// This is used for when the user's code has something wrong. // This has checks in place to make some more sense of the error messages. // Internal errors should be logged using println and the progErr font. private static void logError(String message) { if (message.contains("Playground$FrameAction")) { // This is a reflection error, so that means that we have a malformed class or method. String code = text.getText(); if (!code.startsWith("public class")) { println( "Error: You defined a private class. Please use \"public class <classname>\".", progErr); } else { println( "Error: Malformed method. Make sure your main method is defined as \"public static void main(<any args>)\".", progErr); } } else { println(message, progErr); } }
private static void println(String message) { println(message, null); }