From f8c570a3f1243f41c12236ebbbca8e4481b6ed74 Mon Sep 17 00:00:00 2001 From: Hoky <303455184@qq.com> Date: Thu, 25 Nov 2021 15:32:37 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-62175=20&&=20REPORT-63204=201.=E5=9F=8B?= =?UTF-8?q?=E7=82=B9=E9=80=82=E9=85=8D=202.=E9=92=88=E5=AF=B9sum(1,)?= =?UTF-8?q?=E7=AD=89=E6=AD=A4=E7=B1=BB=E5=85=AC=E5=BC=8F=E8=BF=9B=E8=A1=8C?= =?UTF-8?q?=E5=90=88=E6=B3=95=E6=80=A7=E5=88=A4=E6=96=AD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/formula/FormulaPane.java | 116 ++++++++++-------- 1 file changed, 62 insertions(+), 54 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java b/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java index dc1e03027..189b9e042 100644 --- a/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java +++ b/designer-base/src/main/java/com/fr/design/formula/FormulaPane.java @@ -341,13 +341,7 @@ public class FormulaPane extends BasicPane implements KeyListener, UIFormula { @Override public void focusGained(FocusEvent e) { // 获得焦点时 安装 - if (autoCompletion == null && autoCompletionCheck.isSelected()) { - CompletionProvider provider = createCompletionProvider(); - autoCompletion = new FormulaPaneAutoCompletion(provider); - autoCompletion.setListCellRenderer(new CompletionCellRenderer()); - autoCompletion.install(formulaTextArea); - autoCompletion.installVariableTree(variableTreeAndDescriptionArea); - } + installAutoCompletion(); } @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) { @@ -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 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 - public void actionPerformed(ActionEvent e) { - String formulaText = formulaTextArea.getText().trim(); - String unSupportFormula = containsUnsupportedSimulationFormulas(formulaText); - if (unSupportFormula != null) { - showMessageDialog(Toolkit.i18nText("Fine-Design_Basic_Formula_Unsupported_Formulas") + ":" + unSupportFormula, false); - return; + BaseFormula baseFormula = BaseFormula.createFormulaBuilder().build(formulaText); + Object calResult; + try { + calResult = calculator.evalValue(baseFormula); + String objectToString = EssentialUtils.objectToString(calResult); + 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); + } + } - String messageTips; - FormulaCheckResult checkResult = FormulaChecker.check(formulaText); - if (checkResult.grammarValid()) { - messageTips = checkResult.getTips() + NEWLINE; - Map 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); - Object calResult; - try { - calResult = calculator.evalValue(baseFormula); - String objectToString = EssentialUtils.objectToString(calResult); - 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); - } + private final ActionListener calculateActionListener = new ActionListener() { + + @Override + public void actionPerformed(ActionEvent e) { + calculateFormula(); } };