1 package org.simantics.sysdyn.ui.equation.expressions;
\r
3 import java.io.StringReader;
\r
5 import org.eclipse.swt.SWT;
\r
6 import org.eclipse.swt.events.KeyEvent;
\r
7 import org.eclipse.swt.events.KeyListener;
\r
8 import org.eclipse.swt.graphics.Color;
\r
9 import org.eclipse.swt.widgets.Text;
\r
10 import org.simantics.sysdyn.expressionParser.ExpressionParser;
\r
11 import org.simantics.sysdyn.expressionParser.ParseException;
\r
13 public class ExpressionFieldKeyListener implements KeyListener {
\r
15 String originalText;
\r
17 public ExpressionFieldKeyListener(String originalText) {
\r
18 this.originalText = originalText;
\r
21 public void keyPressed(KeyEvent e) {
\r
22 if(e.keyCode == SWT.ESC && e.widget instanceof Text) {
\r
23 ((Text)e.widget).setText(originalText);
\r
24 ((Text)e.widget).setSelection(originalText.length());
\r
29 public void keyReleased(KeyEvent e) {
\r
30 if(e.widget instanceof Text) {
\r
31 Text text = (Text)e.widget;
\r
33 ExpressionParser parser = new ExpressionParser(
\r
34 new StringReader(text.getText())
\r
38 text.setBackground(new Color(text.getDisplay(), 255, 255, 255));
\r
39 } catch (ParseException e1) {
\r
40 text.setBackground(new Color(text.getDisplay(), 255, 230, 230));
\r