|
|
|
package com.fr.solution.plugin.design.formula.ui.type.impl;
|
|
|
|
|
|
|
|
import com.fanruan.api.util.StringKit;
|
|
|
|
import com.fr.base.Formula;
|
|
|
|
import com.fr.base.Parameter;
|
|
|
|
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.RSyntaxTextArea;
|
|
|
|
import com.fr.design.gui.syntax.ui.rsyntaxtextarea.SyntaxConstants;
|
|
|
|
import com.fr.general.FRLogger;
|
|
|
|
import com.fr.script.Calculator;
|
|
|
|
import com.fr.solution.plugin.design.formula.ui.type.BaseFormulaPane;
|
|
|
|
import com.fr.stable.script.Expression;
|
|
|
|
import com.fr.third.antlr.ANTLRException;
|
|
|
|
|
|
|
|
import java.util.Set;
|
|
|
|
|
|
|
|
public class BasicFormulaPane extends BaseFormulaPane<Formula> {
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public boolean accept(Object ob) {
|
|
|
|
return ob instanceof Formula;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public void populateBean(Formula formula) {
|
|
|
|
if (formula != null) {
|
|
|
|
String content = formula.getContent();
|
|
|
|
fixContent(content);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Formula createWrittenFormula(String content) {
|
|
|
|
return new Formula();
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected Formula createFormula(String content) {
|
|
|
|
Formula formula;
|
|
|
|
if (StringKit.isEmpty(content) || content.trim().charAt(0) == '=') {
|
|
|
|
formula = new Formula(content);
|
|
|
|
} else {
|
|
|
|
formula = new Formula("=" + content);
|
|
|
|
}
|
|
|
|
return formula;
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected RSyntaxTextArea createContentEditor() {
|
|
|
|
RSyntaxTextArea formulaTextArea = new RSyntaxTextArea();
|
|
|
|
configFormulaArea(formulaTextArea);
|
|
|
|
return formulaTextArea;
|
|
|
|
}
|
|
|
|
|
|
|
|
protected void configFormulaArea(RSyntaxTextArea formulaTextArea) {
|
|
|
|
formulaTextArea.setSyntaxEditingStyle(SyntaxConstants.SYNTAX_STYLE_FORMULA);
|
|
|
|
formulaTextArea.setAnimateBracketMatching(true);
|
|
|
|
formulaTextArea.setAntiAliasingEnabled(true);
|
|
|
|
formulaTextArea.setAutoIndentEnabled(true);
|
|
|
|
formulaTextArea.setCodeFoldingEnabled(true);
|
|
|
|
formulaTextArea.setUseSelectedTextColor(true);
|
|
|
|
formulaTextArea.setCloseCurlyBraces(true);
|
|
|
|
formulaTextArea.setBracketMatchingEnabled(true);
|
|
|
|
formulaTextArea.setAntiAliasingEnabled(true);
|
|
|
|
formulaTextArea.setCloseMarkupTags(true);
|
|
|
|
formulaTextArea.setLineWrap(true);
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
protected boolean isValidFormula(String formulaText) {
|
|
|
|
Formula formula = createFormula(formulaText);
|
|
|
|
Expression expression = null;
|
|
|
|
try {
|
|
|
|
expression = formula.parse(Calculator.createCalculator());
|
|
|
|
} catch (ANTLRException e) {
|
|
|
|
FRLogger.getLogger().error(e.getMessage(), e);
|
|
|
|
}
|
|
|
|
return expression != null;
|
|
|
|
}
|
|
|
|
|
|
|
|
@Override
|
|
|
|
public Parameter[] analyze4Parameters(Calculator calculator) {
|
|
|
|
Formula formula = updateBean();
|
|
|
|
if (formula == null) {
|
|
|
|
return new Parameter[0];
|
|
|
|
}
|
|
|
|
String[] arr = formula.dependence(calculator);
|
|
|
|
Parameter[] parameters = new Parameter[arr.length];
|
|
|
|
for (int i = 0, len = arr.length; i < len; i ++) {
|
|
|
|
parameters[i] = new Parameter(arr[i]);
|
|
|
|
}
|
|
|
|
return parameters;
|
|
|
|
}
|
|
|
|
}
|