Beispiel #1
0
 private void updateDisplay() {
   // first, set block colours
   textView.setBackground(getColour(backgroundColour("text-background-colour")));
   textView.setForeground(getColour(foregroundColour("text-foreground-colour")));
   textView.setCaretColor(getColour(foregroundColour("text-caret-colour")));
   problemsView.setBackground(getColour(backgroundColour("problems-background-colour")));
   problemsView.setForeground(getColour(foregroundColour("problems-foreground-colour")));
   consoleView.setBackground(getColour(backgroundColour("console-background-colour")));
   consoleView.setForeground(getColour(foregroundColour("console-foreground-colour")));
   // second, set colours on the code!
   java.util.List<Lexer.Token> tokens = Lexer.tokenise(textView.getText(), true);
   int pos = 0;
   for (Lexer.Token t : tokens) {
     int len = t.toString().length();
     if (t instanceof Lexer.RightBrace || t instanceof Lexer.LeftBrace) {
       highlightArea(pos, len, foregroundColour("text-brace-colour"));
     } else if (t instanceof Lexer.Strung) {
       highlightArea(pos, len, foregroundColour("text-string-colour"));
     } else if (t instanceof Lexer.Comment) {
       highlightArea(pos, len, foregroundColour("text-comment-colour"));
     } else if (t instanceof Lexer.Quote) {
       highlightArea(pos, len, foregroundColour("text-quote-colour"));
     } else if (t instanceof Lexer.Comma) {
       highlightArea(pos, len, foregroundColour("text-comma-colour"));
     } else if (t instanceof Lexer.Identifier) {
       highlightArea(pos, len, foregroundColour("text-identifier-colour"));
     } else if (t instanceof Lexer.Integer) {
       highlightArea(pos, len, foregroundColour("text-integer-colour"));
     }
     pos += len;
   }
 }
Beispiel #2
0
 public void evaluate() {
   try {
     // clear problems and console messages
     problemsView.setText("");
     consoleView.setText("");
     // update status view
     statusView.setText(" Parsing ...");
     tabbedPane.setSelectedIndex(0);
     LispExpr root = Parser.parse(textView.getText());
     statusView.setText(" Running ...");
     tabbedPane.setSelectedIndex(1);
     // update run button
     runButton.setIcon(stopImage);
     runButton.setActionCommand("Stop");
     // start run thread
     runThread = new RunThread(root);
     runThread.start();
   } catch (SyntaxError e) {
     tabbedPane.setSelectedIndex(0);
     System.err.println(
         "Syntax Error at " + e.getLine() + ", " + e.getColumn() + " : " + e.getMessage());
   } catch (Error e) {
     // parsing error
     System.err.println(e.getMessage());
     statusView.setText(" Errors.");
   }
 }
Beispiel #3
0
 private void redirectIO() {
   // redirect std I/O to console and problems:
   // > System.out => console
   // > System.err => problems
   // > console => System.in
   System.setOut(consoleView.getOutputStream());
   System.setErr(problemsView.getOutputStream());
   // redirect input from console to System.in
   System.setIn(consoleView.getInputStream());
 }
Beispiel #4
0
 public void newFile() {
   if (!dirty || checkForSave()) {
     textView.setText("");
     consoleView.setText("");
     problemsView.setText("");
     statusView.setText(" Created new file.");
     file = null;
     // reset dirty bit
     dirty = false;
   }
 }
Beispiel #5
0
 public void prettyPrint() {
   try {
     // clear old problem messages
     problemsView.setText("");
     // update status view
     statusView.setText(" Parsing ...");
     LispExpr root = Parser.parse(textView.getText());
     statusView.setText(" Pretty Printing ...");
     String newText = PrettyPrinter.prettyPrint(root);
     textView.setText(newText);
     statusView.setText(" Done.");
   } catch (Error e) {
     System.err.println(e.getMessage());
     statusView.setText(" Errors.");
   }
 }
Beispiel #6
0
 private JConsoleArea makeConsoleArea(int width, int height, boolean editable) {
   JConsoleArea ta = new JConsoleArea();
   ta.setEditable(editable);
   return ta;
 }