|
|
@ -341,13 +341,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void focusGained(FocusEvent e) { |
|
|
|
public void focusGained(FocusEvent e) { |
|
|
|
// 获得焦点时 安装
|
|
|
|
// 获得焦点时 安装
|
|
|
|
if (autoCompletion == null && autoCompletionCheck.isSelected()) { |
|
|
|
installAutoCompletion(); |
|
|
|
CompletionProvider provider = createCompletionProvider(); |
|
|
|
|
|
|
|
autoCompletion = new FormulaPaneAutoCompletion(provider); |
|
|
|
|
|
|
|
autoCompletion.setListCellRenderer(new CompletionCellRenderer()); |
|
|
|
|
|
|
|
autoCompletion.install(formulaTextArea); |
|
|
|
|
|
|
|
autoCompletion.installVariableTree(variableTreeAndDescriptionArea); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
@ -410,6 +404,16 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void installAutoCompletion() { |
|
|
|
|
|
|
|
if (autoCompletion == null && autoCompletionCheck.isSelected()) { |
|
|
|
|
|
|
|
CompletionProvider provider = createCompletionProvider(); |
|
|
|
|
|
|
|
autoCompletion = new FormulaPaneAutoCompletion(provider); |
|
|
|
|
|
|
|
autoCompletion.setListCellRenderer(new CompletionCellRenderer()); |
|
|
|
|
|
|
|
autoCompletion.install(formulaTextArea); |
|
|
|
|
|
|
|
autoCompletion.installVariableTree(variableTreeAndDescriptionArea); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
protected void extendCheckBoxPane(JPanel checkBoxPane) { |
|
|
|
protected void extendCheckBoxPane(JPanel checkBoxPane) { |
|
|
|
|
|
|
|
|
|
|
@ -795,58 +799,62 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { |
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void calculateFormula() { |
|
|
|
|
|
|
|
String formulaText = formulaTextArea.getText().trim(); |
|
|
|
|
|
|
|
String unSupportFormula = containsUnsupportedSimulationFormulas(formulaText); |
|
|
|
|
|
|
|
if (unSupportFormula != null) { |
|
|
|
|
|
|
|
showMessageDialog(Toolkit.i18nText("Fine-Design_Basic_Formula_Unsupported_Formulas") + ":" + unSupportFormula, false); |
|
|
|
|
|
|
|
return; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
private final ActionListener calculateActionListener = new ActionListener() { |
|
|
|
String messageTips; |
|
|
|
|
|
|
|
FormulaCheckResult checkResult = FormulaChecker.check(formulaText); |
|
|
|
|
|
|
|
if (checkResult.grammarValid()) { |
|
|
|
|
|
|
|
messageTips = checkResult.getTips() + NEWLINE; |
|
|
|
|
|
|
|
Map<String, Object> paramsMap = setParamsIfExist(formulaText); |
|
|
|
|
|
|
|
Calculator calculator = Calculator.createCalculator(); |
|
|
|
|
|
|
|
ParameterMapNameSpace parameterMapNameSpace = ParameterMapNameSpace.create(paramsMap); |
|
|
|
|
|
|
|
calculator.pushNameSpace(parameterMapNameSpace); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JTemplate<?, ?> currentEditingTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
|
|
|
if (currentEditingTemplate != null) { |
|
|
|
|
|
|
|
IOFile file = (IOFile) currentEditingTemplate.getTarget(); |
|
|
|
|
|
|
|
calculator.setAttribute(TableDataSource.KEY, file); |
|
|
|
|
|
|
|
calculator.pushNameSpace(TableDataNameSpace.getInstance()); |
|
|
|
|
|
|
|
calculator.pushNameSpace(SimpleCellValueNameSpace.getInstance()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
BaseFormula baseFormula = BaseFormula.createFormulaBuilder().build(formulaText); |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
Object calResult; |
|
|
|
String formulaText = formulaTextArea.getText().trim(); |
|
|
|
try { |
|
|
|
String unSupportFormula = containsUnsupportedSimulationFormulas(formulaText); |
|
|
|
calResult = calculator.evalValue(baseFormula); |
|
|
|
if (unSupportFormula != null) { |
|
|
|
String objectToString = EssentialUtils.objectToString(calResult); |
|
|
|
showMessageDialog(Toolkit.i18nText("Fine-Design_Basic_Formula_Unsupported_Formulas") + ":" + unSupportFormula, false); |
|
|
|
String result = objectToString.length() > DEFUAL_FOMULA_LENGTH ? |
|
|
|
return; |
|
|
|
objectToString.substring(0, DEFUAL_FOMULA_LENGTH - ELLIPSIS.length()) + ELLIPSIS : objectToString; |
|
|
|
|
|
|
|
messageTips = messageTips + Toolkit.i18nText("Fine-Design_Basic_Formula_Cal_Result") + ":" + result; |
|
|
|
|
|
|
|
} catch (Exception ce) { |
|
|
|
|
|
|
|
//模拟计算如果出现错误,则抛出错误
|
|
|
|
|
|
|
|
calResult = ce.getMessage(); |
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().error(ce.getMessage(), ce); |
|
|
|
|
|
|
|
messageTips = messageTips + Toolkit.i18nText("Fine-Design_Basic_Formula_Cal_Error") + ":" + calResult; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().info("value:{}", calResult); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
messageTips = checkResult.getTips(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (checkResult.isValid()) { |
|
|
|
|
|
|
|
showMessageDialog(messageTips, checkResult.isValid()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
confirmCheckResult(checkResult, messageTips); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
String messageTips; |
|
|
|
|
|
|
|
FormulaCheckResult checkResult = FormulaChecker.check(formulaText); |
|
|
|
|
|
|
|
if (checkResult.grammarValid()) { |
|
|
|
|
|
|
|
messageTips = checkResult.getTips() + NEWLINE; |
|
|
|
|
|
|
|
Map<String, Object> paramsMap = setParamsIfExist(formulaText); |
|
|
|
|
|
|
|
Calculator calculator = Calculator.createCalculator(); |
|
|
|
|
|
|
|
ParameterMapNameSpace parameterMapNameSpace = ParameterMapNameSpace.create(paramsMap); |
|
|
|
|
|
|
|
calculator.pushNameSpace(parameterMapNameSpace); |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
JTemplate<?, ?> currentEditingTemplate = HistoryTemplateListCache.getInstance().getCurrentEditingTemplate(); |
|
|
|
|
|
|
|
if (currentEditingTemplate != null) { |
|
|
|
|
|
|
|
IOFile file = (IOFile) currentEditingTemplate.getTarget(); |
|
|
|
|
|
|
|
calculator.setAttribute(TableDataSource.KEY, file); |
|
|
|
|
|
|
|
calculator.pushNameSpace(TableDataNameSpace.getInstance()); |
|
|
|
|
|
|
|
calculator.pushNameSpace(SimpleCellValueNameSpace.getInstance()); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
BaseFormula baseFormula = BaseFormula.createFormulaBuilder().build(formulaText); |
|
|
|
private final ActionListener calculateActionListener = new ActionListener() { |
|
|
|
Object calResult; |
|
|
|
|
|
|
|
try { |
|
|
|
@Override |
|
|
|
calResult = calculator.evalValue(baseFormula); |
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
String objectToString = EssentialUtils.objectToString(calResult); |
|
|
|
calculateFormula(); |
|
|
|
String result = objectToString.length() > DEFUAL_FOMULA_LENGTH ? |
|
|
|
|
|
|
|
objectToString.substring(0, DEFUAL_FOMULA_LENGTH - ELLIPSIS.length()) + ELLIPSIS : objectToString; |
|
|
|
|
|
|
|
messageTips = messageTips + Toolkit.i18nText("Fine-Design_Basic_Formula_Cal_Result") + ":" + result; |
|
|
|
|
|
|
|
} catch (Exception ce) { |
|
|
|
|
|
|
|
//模拟计算如果出现错误,则抛出错误
|
|
|
|
|
|
|
|
calResult = ce.getMessage(); |
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().error(ce.getMessage(), ce); |
|
|
|
|
|
|
|
messageTips = messageTips + Toolkit.i18nText("Fine-Design_Basic_Formula_Cal_Error") + ":" + calResult; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
FineLoggerFactory.getLogger().info("value:{}", calResult); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
messageTips = checkResult.getTips(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
if (checkResult.isValid()) { |
|
|
|
|
|
|
|
showMessageDialog(messageTips, checkResult.isValid()); |
|
|
|
|
|
|
|
} else { |
|
|
|
|
|
|
|
confirmCheckResult(checkResult, messageTips); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|
}; |
|
|
|
}; |
|
|
|
|
|
|
|
|
|
|
|