public static final HoverTextElementNoBounds INSTANCE = new HoverTextElementNoBounds();\r
\r
private IHintListener hoverHintListener;\r
- \r
+\r
public HoverTextElementNoBounds() {\r
super(0, 0, Alignment.LEADING, 0);\r
}\r
node.setPadding(paddingX, paddingY);\r
node.setBorderWidth((float) borderWidth);\r
node.setEditable(editable);\r
- \r
+\r
this.hoverHintListener = new IHintListener() {\r
@Override\r
public void hintRemoved(IHintObservable sender, Key key, Object oldValue) {\r
if(key == ElementHints.KEY_HOVER) {\r
IElement e = (IElement)sender;\r
TextNode name = (TextNode) e.getHint(SG_NODE);\r
- name.setHover((Boolean)e.getHint(ElementHints.KEY_HOVER));\r
+ if(name != null)\r
+ name.setHover((Boolean)e.getHint(ElementHints.KEY_HOVER));\r
}\r
}\r
};\r
e.addHintListener(hoverHintListener);\r
}\r
- \r
+\r
@Override\r
public void cleanup(IElement e) {\r
if(hoverHintListener != null)\r
public void run() {\r
if(expressionWidget!= null) {\r
expressionWidget.getExpression().replaceSelection(var);\r
+ expressionWidget.getExpression().focus();\r
}\r
}\r
});\r
try {\r
parser.table();\r
ArrayList<Token> xTokens = parser.getXTokens();\r
- for(Token token : xTokens) {\r
+ ArrayList<Token> yTokens = parser.getYTokens();\r
+ for(int i = 0; i < xTokens.size(); i++) {\r
table.addLocation(new Point2D.Double(\r
- Double.parseDouble(token.image), \r
- Double.parseDouble(token.next.next.image)));\r
+ Double.parseDouble(xTokens.get(i).image), \r
+ Double.parseDouble(yTokens.get(i).image)));\r
}\r
} catch (ParseException e1) {\r
}\r
try {\r
parser.table();\r
ArrayList<Token> xTokens = parser.getXTokens();\r
- for(Token token : xTokens) {\r
- series.add(Double.parseDouble(token.image), \r
- Double.parseDouble(token.next.next.image));\r
+ ArrayList<Token> yTokens = parser.getYTokens();\r
+ for(int i = 0; i < xTokens.size(); i++) {\r
+ series.add(\r
+ Double.parseDouble(xTokens.get(i).image), \r
+ Double.parseDouble(yTokens.get(i).image));\r
}\r
} catch (ParseException e1) {\r
}\r
import org.eclipse.jface.text.BadLocationException;\r
import org.eclipse.jface.text.IDocument;\r
import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.FocusAdapter;\r
-import org.eclipse.swt.events.FocusEvent;\r
import org.eclipse.swt.events.FocusListener;\r
import org.eclipse.swt.events.KeyListener;\r
import org.eclipse.swt.events.ModifyListener;\r
import org.simantics.ui.SimanticsUI;\r
\r
public class BasicExpression implements IExpression {\r
- \r
+\r
private ExpressionField expression;\r
protected Resource expressionType;\r
- private Point caretPosition; // Bug or something in source viewer's text widget. Cursor goes to 0, 0 on focus lost\r
- \r
+\r
@Override\r
public void createExpressionFields(Composite parent, Map<String, Object> data) {\r
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(parent);\r
String equation = data.get("equation") != null ? (String)data.get("equation") : "";\r
- \r
+\r
Label l = new Label(parent, SWT.NONE);\r
l.setText("=");\r
- \r
+\r
expression = new ExpressionField(parent, SWT.BORDER);\r
expression.setExpression(equation);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(expression);\r
- \r
- expression.getSourceViewer().getTextWidget().addFocusListener(new FocusAdapter() {\r
\r
- @Override\r
- public void focusLost(FocusEvent e) {\r
- caretPosition = expression.getSelection();\r
- }\r
- });\r
}\r
\r
@Override\r
public void focus() {\r
- if(this.expression != null && caretPosition != null) {\r
- this.expression.focus();\r
- expression.getSourceViewer().getTextWidget().setSelection(caretPosition.x, caretPosition.x + caretPosition.y);\r
- }\r
- \r
+ this.expression.focus();\r
+\r
}\r
\r
@Override\r
@Override\r
public void save(final Resource variable, Map<String, Object> data) {\r
final String currentText = expression.getExpression();\r
- if(currentText != null && expressionType != null) {\r
+ String oldEquation = (String)data.get("equation");\r
+ if(oldEquation == null || \r
+ (currentText != null && expressionType != null && !currentText.equals(oldEquation))) {\r
data.put("equation", currentText);\r
SimanticsUI.getSession().asyncRequest(new WriteRequest() {\r
@Override\r
SysdynResource sr = SysdynResource.getInstance(g);\r
Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
Builtins b = g.getBuiltins();\r
- if(expression != null) {\r
+ if(expression != null && !g.isInstanceOf(expression, expressionType)) {\r
g.deny(variable, sr.HasExpression);\r
+ expression = null;\r
+ }\r
+ if(expression == null) {\r
+ expression = g.newResource();\r
+ g.claim(expression, b.InstanceOf, null, expressionType);\r
+ g.claim(variable, sr.HasExpression, expression);\r
}\r
- expression = g.newResource();\r
- g.claim(expression, b.InstanceOf, null, expressionType);\r
- g.claim(variable, sr.HasExpression, expression);\r
g.claimValue(expression, sr.HasEquation, currentText);\r
}\r
\r
});\r
}\r
- expression.setExpression(currentText);\r
}\r
\r
@Override\r
@Override\r
public void addKeyListener(KeyListener listener) {\r
this.expression.getSourceViewer().getTextWidget().addKeyListener(listener);\r
- \r
+\r
}\r
\r
@Override\r
public void addModifyListener(ModifyListener listener) {\r
this.expression.getSourceViewer().getTextWidget().addModifyListener(listener);\r
- \r
+\r
}\r
- \r
+\r
@Override\r
public void addFocusListener(FocusListener listener) {\r
this.expression.getSourceViewer().getTextWidget().addFocusListener(listener);\r
import org.simantics.sysdyn.manager.SysdynModelManager;\r
import org.simantics.sysdyn.representation.Configuration;\r
import org.simantics.sysdyn.representation.IElement;\r
-import org.simantics.sysdyn.representation.IndependentVariable;\r
+import org.simantics.sysdyn.representation.Variable;\r
import org.simantics.sysdyn.ui.properties.widgets.expressions.IExpression;\r
import org.simantics.ui.SimanticsUI;\r
\r
Configuration conf = model.getConfiguration();\r
ArrayList<IElement> elements = conf.getElements();\r
for(IElement e : elements) {\r
- if(e instanceof IndependentVariable) {\r
- IndependentVariable v = (IndependentVariable) e;\r
+ if(e instanceof Variable) {\r
+ Variable v = (Variable) e;\r
modelVariables.add(v.getName());\r
}\r
}\r
* @param clazz String.class or Double.class\r
* @return input as string or double or null if asked for something else\r
*/\r
- @SuppressWarnings("unchecked")\r
public Object getInput(Class clazz) {\r
if(clazz == String.class) {\r
return "" + input;\r
* @param clazz String.class or Double.class\r
* @return output as string or double or null if asked for something else\r
*/\r
- @SuppressWarnings("unchecked")\r
public Object getOutput(Class clazz) {\r
if(clazz == String.class) {\r
return "" + output;\r
import org.eclipse.jface.text.BadLocationException;\r
import org.eclipse.jface.text.IDocument;\r
import org.eclipse.swt.SWT;\r
-import org.eclipse.swt.events.FocusAdapter;\r
-import org.eclipse.swt.events.FocusEvent;\r
import org.eclipse.swt.events.FocusListener;\r
import org.eclipse.swt.events.KeyListener;\r
import org.eclipse.swt.events.ModifyListener;\r
\r
private Text integral;\r
private ExpressionField expression;\r
- private Point caretPosition; // Bug or something in source viewer's text widget. Cursor goes to 0, 0 on focus lost\r
- \r
+\r
@Override\r
public void createExpressionFields(Composite parent, Map<String, Object> data) {\r
GridLayoutFactory.fillDefaults().numColumns(2).applyTo(parent);\r
String initialEquation = data.get("initialEquation") != null ? (String)data.get("initialEquation") : "";\r
String integralEquation = data.get("integral") != null ? (String)data.get("integral") : "";\r
\r
- \r
+\r
Label label = new Label(parent, SWT.NONE);\r
label.setText("Integral");\r
- \r
+\r
integral = new Text(parent, SWT.MULTI | SWT.V_SCROLL | SWT.BORDER);\r
integral.setEditable(false);\r
integral.setText(integralEquation);\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(integral);\r
- \r
- \r
+\r
+\r
label = new Label(parent, SWT.NONE);\r
label.setText("Initial\nValue");\r
- \r
+\r
expression = new ExpressionField(parent, SWT.BORDER);\r
expression.setExpression(initialEquation);\r
- \r
+\r
GridDataFactory.fillDefaults().grab(true, true).applyTo(expression);\r
- \r
- expression.getSourceViewer().getTextWidget().addFocusListener(new FocusAdapter() {\r
\r
- @Override\r
- public void focusLost(FocusEvent e) {\r
- caretPosition = expression.getSelection();\r
- }\r
- });\r
- \r
}\r
\r
@Override\r
public void focus() {\r
- if(this.expression != null && caretPosition != null) {\r
- this.expression.focus();\r
- expression.getSourceViewer().getTextWidget().setSelection(caretPosition.x, caretPosition.x + caretPosition.y);\r
- }\r
- \r
+ this.expression.focus();\r
}\r
\r
@Override\r
}\r
\r
data.put("integral", getIntegral(variable));\r
- \r
+\r
}\r
\r
@Override\r
SysdynResource sr = SysdynResource.getInstance(g);\r
Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
Builtins b = g.getBuiltins();\r
- if(expression != null) {\r
+ if(expression != null && !g.isInstanceOf(expression, sr.StockExpression)) {\r
g.deny(variable, sr.HasExpression);\r
+ expression = null;\r
}\r
- expression = g.newResource();\r
- g.claim(expression, b.InstanceOf, null, sr.StockExpression);\r
- g.claim(variable, sr.HasExpression, expression);\r
+ if(expression == null) {\r
+ expression = g.newResource();\r
+ g.claim(expression, b.InstanceOf, null, sr.StockExpression);\r
+ g.claim(variable, sr.HasExpression, expression);\r
+ } \r
g.claimValue(expression, sr.HasInitialEquation, currentText);\r
}\r
\r
if(this.integral != null && this.integral.getText() != null)\r
data.put("integral", this.integral.getText());\r
}\r
- \r
- \r
+\r
+\r
private String getIntegral(final Resource variable) {\r
String integral = "";\r
try {\r
Object name = graph.getPossibleRelatedValue(tail, b.HasName);\r
if (name != null) \r
builder.append(" + " + name);\r
- \r
+\r
}\r
}\r
}\r
@Override\r
public void addKeyListener(KeyListener listener) {\r
this.expression.getSourceViewer().getTextWidget().addKeyListener(listener);\r
- \r
+\r
}\r
\r
@Override\r
public void addModifyListener(ModifyListener listener) {\r
this.expression.getSourceViewer().getTextWidget().addModifyListener(listener);\r
- \r
+\r
}\r
- \r
+\r
@Override\r
public void addFocusListener(FocusListener listener) {\r
this.expression.getSourceViewer().getTextWidget().addFocusListener(listener);\r
\r
private ChartPanel smallPanel;\r
private Frame smallFrame;\r
- \r
+\r
private Resource variable;\r
\r
public WithLookupExpression(Resource variable) {\r
updateChartTimer.restart();\r
}\r
});\r
- \r
- \r
+\r
+\r
SimanticsUI.getSession().asyncRequest(new Read<String>() {\r
\r
@Override\r
public void execute(final String result) {\r
if(lookup != null)\r
lookup.getDisplay().asyncExec(new Runnable() {\r
- \r
+\r
@Override\r
public void run() {\r
lookup.setExpression(result); \r
\r
@Override\r
public void readData(final Resource variable, Map<String, Object> data) {\r
- \r
+\r
class Auxiliary {\r
String equation, lookup;\r
}\r
- \r
+\r
Auxiliary results = null;\r
\r
if (variable != null && data.get("equation") == null) {\r
public void save(final Resource variable, Map<String, Object> data) {\r
final String currentExpression = expression.getExpression();\r
final String currentLookupTable = lookup.getExpression();\r
+ String oldExpression = (String)data.get("equation");\r
+ String oldLookupTable = (String)data.get("lookup");\r
\r
- if(currentExpression != null && currentLookupTable != null) {\r
+ if(oldExpression == null || oldLookupTable == null ||\r
+ (currentExpression != null && currentLookupTable != null\r
+ && (!currentExpression.equals(oldExpression) || \r
+ !currentLookupTable.equals(oldLookupTable)))) {\r
data.putAll(data);\r
data.put("equation", currentExpression);\r
data.put("lookup", currentLookupTable);\r
SysdynResource sr = SysdynResource.getInstance(g);\r
Resource expression = g.getPossibleObject(variable, sr.HasExpression);\r
Builtins b = g.getBuiltins();\r
- if(expression != null) {\r
+ if(expression != null && !g.isInstanceOf(expression, sr.WithLookupExpression)) {\r
g.deny(variable, sr.HasExpression);\r
+ expression = null;\r
}\r
- expression = g.newResource();\r
- g.claim(expression, b.InstanceOf, null, sr.WithLookupExpression);\r
- g.claim(variable, sr.HasExpression, expression);\r
- g.claimValue(expression, sr.HasEquation, currentExpression);\r
- g.claimValue(expression, sr.HasLookup, currentLookupTable);\r
- if(!g.hasStatement(expression, sr.HasMinX))\r
+ if(expression == null) {\r
+ expression = g.newResource();\r
+ g.claim(expression, b.InstanceOf, null, sr.WithLookupExpression);\r
+ g.claim(variable, sr.HasExpression, expression);\r
g.claimValue(expression, sr.HasMinX, 0.0);\r
- if(!g.hasStatement(expression, sr.HasMaxX))\r
g.claimValue(expression, sr.HasMaxX, 10.0);\r
- if(!g.hasStatement(expression, sr.HasMinY))\r
g.claimValue(expression, sr.HasMinY, 0.0);\r
- if(!g.hasStatement(expression, sr.HasMaxY))\r
g.claimValue(expression, sr.HasMaxY, 10.0);\r
+\r
+ } \r
+ g.claimValue(expression, sr.HasEquation, currentExpression);\r
+ g.claimValue(expression, sr.HasLookup, currentLookupTable);\r
}\r
});\r
}\r
false\r
);\r
chart.removeLegend();\r
- chart.getXYPlot().getDomainAxis().setTickLabelsVisible(false);\r
+ chart.getXYPlot().getDomainAxis().setTickLabelsVisible(true);\r
chart.getXYPlot().getDomainAxis().setAxisLineVisible(false);\r
- chart.getXYPlot().getDomainAxis().setTickMarksVisible(false);\r
- chart.getXYPlot().getRangeAxis().setTickLabelsVisible(false);\r
+ chart.getXYPlot().getDomainAxis().setTickMarksVisible(true);\r
+ chart.getXYPlot().getRangeAxis().setTickLabelsVisible(true);\r
chart.getXYPlot().getRangeAxis().setAxisLineVisible(false);\r
- chart.getXYPlot().getRangeAxis().setTickMarksVisible(false);\r
+ chart.getXYPlot().getRangeAxis().setTickMarksVisible(true);\r
chart.getXYPlot().getRenderer().setSeriesStroke(0, new BasicStroke(3.0f));\r
return chart;\r
}\r
try {\r
parser.table();\r
ArrayList<Token> xTokens = parser.getXTokens();\r
- for(Token token : xTokens) {\r
+ ArrayList<Token> yTokens = parser.getYTokens();\r
+ for(int i = 0; i < xTokens.size(); i++) {\r
dataPoints.add(new Point2D.Double(\r
- Double.parseDouble(token.image), \r
- Double.parseDouble(token.next.next.image)));\r
+ Double.parseDouble(xTokens.get(i).image), \r
+ Double.parseDouble(yTokens.get(i).image)));\r
}\r
} catch (ParseException e1) {\r
+// e1.printStackTrace();\r
return;\r
}\r
\r
- if(dataPoints.size() == 0) return;\r
-\r
XYSeries series = new XYSeries("Lookup Table");\r
for(Point2D point : dataPoints) {\r
series.add(point.getX(), point.getY());\r