-package org.simantics.scl.ui.editor;\r
-\r
-import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.custom.SashForm;\r
-import org.eclipse.swt.events.KeyAdapter;\r
-import org.eclipse.swt.events.KeyEvent;\r
-import org.eclipse.swt.graphics.Color;\r
-import org.eclipse.swt.graphics.Font;\r
-import org.eclipse.swt.layout.FillLayout;\r
-import org.eclipse.swt.widgets.Display;\r
-import org.eclipse.swt.widgets.Event;\r
-import org.eclipse.swt.widgets.Listener;\r
-import org.eclipse.swt.widgets.Shell;\r
-import org.eclipse.swt.widgets.Text;\r
-import org.simantics.scl.compiler.SCLCompiler;\r
-import org.simantics.scl.compiler.StandardSCLCompilerConfiguration;\r
-\r
-public class TestTextEditor {\r
-\r
- public static void main(String[] args) {\r
- Display display = new Display();\r
- final Shell shell = new Shell(display);\r
- shell.setText("SCL text widget example");\r
- shell.setLayout(new FillLayout());\r
- \r
- SashForm sashForm = new SashForm(shell, SWT.VERTICAL); \r
- \r
- final SCLTextEditor editor = new SCLTextEditor(sashForm, 0, StandardSCLCompilerConfiguration.INSTANCE);\r
- editor.setContent(\r
- "// Difficulty: 0\n" +\r
- "// Expected: [2.0, 3.0, 5.0, 7.0, 11.0, 13.0, 17.0, 19.0]\n\n" +\r
- "// and : [Boolean] -> Boolean\n" +\r
- "and = fold (&&) True\n\n" +\r
- "// isPrime : Integer -> Boolean\n" +\r
- "isPrime p = and (\n" +\r
- " d <- [2 .. sqrt p]\n" +\r
- " [p % d > 0]\n" +\r
- ")\n\n" +\r
- "x <- [2 .. 20]\n" +\r
- "isPrime x\n" +\r
- "[x]"\r
- );\r
- \r
- final Text resultArea = new Text(sashForm, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);\r
- resultArea.setText("Ctrl-S executes the code.");\r
- resultArea.setEditable(false);\r
- resultArea.setBackground(new Color(shell.getDisplay(), 255, 255, 255));\r
- resultArea.setFont(new Font(shell.getDisplay(), "Courier New", 10, SWT.NORMAL));\r
- \r
- sashForm.setWeights(new int[] {5, 1});\r
- \r
- display.addFilter(SWT.KeyDown, new Listener() {\r
- @Override\r
- public void handleEvent(Event event) {\r
- if(event.keyCode == 's' && event.stateMask == SWT.CTRL) {\r
- final String code = editor.getContent();\r
- new Thread() {\r
- public void run() {\r
- try {\r
- final String result = SCLCompiler.compileExpression(StandardSCLCompilerConfiguration.INSTANCE, code).execute().toString();\r
- shell.getDisplay().asyncExec(new Runnable() {\r
- public void run() {\r
- resultArea.setText(result); \r
- } \r
- });\r
- } catch (Exception e) {\r
- }\r
- }\r
- }.start();\r
- event.doit = false;\r
- }\r
- }\r
- });\r
- shell.addKeyListener(new KeyAdapter() {\r
- @Override\r
- public void keyPressed(KeyEvent e) {\r
- System.out.println(e);\r
- }\r
- });\r
- \r
- shell.open();\r
- while (!shell.isDisposed ()) {\r
- if (!display.readAndDispatch ()) display.sleep ();\r
- }\r
- display.dispose ();\r
- }\r
- \r
-}\r
+package org.simantics.scl.ui.editor;
+
+import org.eclipse.swt.SWT;
+import org.eclipse.swt.custom.SashForm;
+import org.eclipse.swt.events.KeyAdapter;
+import org.eclipse.swt.events.KeyEvent;
+import org.eclipse.swt.graphics.Color;
+import org.eclipse.swt.graphics.Font;
+import org.eclipse.swt.layout.FillLayout;
+import org.eclipse.swt.widgets.Display;
+import org.eclipse.swt.widgets.Event;
+import org.eclipse.swt.widgets.Listener;
+import org.eclipse.swt.widgets.Shell;
+import org.eclipse.swt.widgets.Text;
+import org.simantics.scl.compiler.SCLCompiler;
+import org.simantics.scl.compiler.StandardSCLCompilerConfiguration;
+
+public class TestTextEditor {
+
+ public static void main(String[] args) {
+ Display display = new Display();
+ final Shell shell = new Shell(display);
+ shell.setText("SCL text widget example");
+ shell.setLayout(new FillLayout());
+
+ SashForm sashForm = new SashForm(shell, SWT.VERTICAL);
+
+ final SCLTextEditor editor = new SCLTextEditor(sashForm, 0, StandardSCLCompilerConfiguration.INSTANCE);
+ editor.setContent(
+ "// Difficulty: 0\n" +
+ "// Expected: [2.0, 3.0, 5.0, 7.0, 11.0, 13.0, 17.0, 19.0]\n\n" +
+ "// and : [Boolean] -> Boolean\n" +
+ "and = fold (&&) True\n\n" +
+ "// isPrime : Integer -> Boolean\n" +
+ "isPrime p = and (\n" +
+ " d <- [2 .. sqrt p]\n" +
+ " [p % d > 0]\n" +
+ ")\n\n" +
+ "x <- [2 .. 20]\n" +
+ "isPrime x\n" +
+ "[x]"
+ );
+
+ final Text resultArea = new Text(sashForm, SWT.MULTI | SWT.WRAP | SWT.V_SCROLL);
+ resultArea.setText("Ctrl-S executes the code.");
+ resultArea.setEditable(false);
+ resultArea.setBackground(new Color(shell.getDisplay(), 255, 255, 255));
+ resultArea.setFont(new Font(shell.getDisplay(), "Courier New", 10, SWT.NORMAL));
+
+ sashForm.setWeights(new int[] {5, 1});
+
+ display.addFilter(SWT.KeyDown, new Listener() {
+ @Override
+ public void handleEvent(Event event) {
+ if(event.keyCode == 's' && event.stateMask == SWT.CTRL) {
+ final String code = editor.getContent();
+ new Thread() {
+ public void run() {
+ try {
+ final String result = SCLCompiler.compileExpression(StandardSCLCompilerConfiguration.INSTANCE, code).execute().toString();
+ shell.getDisplay().asyncExec(new Runnable() {
+ public void run() {
+ resultArea.setText(result);
+ }
+ });
+ } catch (Exception e) {
+ }
+ }
+ }.start();
+ event.doit = false;
+ }
+ }
+ });
+ shell.addKeyListener(new KeyAdapter() {
+ @Override
+ public void keyPressed(KeyEvent e) {
+ System.out.println(e);
+ }
+ });
+
+ shell.open();
+ while (!shell.isDisposed ()) {
+ if (!display.readAndDispatch ()) display.sleep ();
+ }
+ display.dispose ();
+ }
+
+}