From 2886d3b5d9d73eb90601f593510d25b68daebfde Mon Sep 17 00:00:00 2001 From: Harrison Date: Tue, 4 Aug 2020 19:42:16 +0800 Subject: [PATCH] =?UTF-8?q?1=E3=80=81=E6=9B=B4=E6=96=B0=E6=B3=A8=E9=87=8A?= =?UTF-8?q?=202=E3=80=81=E4=BC=98=E5=8C=96=E4=B8=80=E4=B8=8B=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=E7=BB=93=E6=9E=84?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/formula/FormulaTextField.java | 10 ++++++++++ .../design/gui/itextfield/DictionaryTextField.java | 4 ++++ .../fr/design/dscolumn/DSColumnAdvancedPane.java | 8 +++----- .../quickeditor/cellquick/CellDSColumnEditor.java | 14 ++++++++------ 4 files changed, 25 insertions(+), 11 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java b/designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java index e14266278..146085e3d 100644 --- a/designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java +++ b/designer-base/src/main/java/com/fr/design/formula/FormulaTextField.java @@ -7,6 +7,11 @@ import com.fr.stable.StringUtils; import javax.swing.text.Document; /** + * 公式展示时使用。 + * 展示 String. + * 但实际保存的是 BaseFormula。 + * 从而保留公式的形态。 + * * created by Harrison on 2020/08/03 **/ public class FormulaTextField extends DictionaryTextField { @@ -41,6 +46,11 @@ public class FormulaTextField extends DictionaryTextField { return this.value; } + /** + * 设置值时,会将展示的公式值一同设置进去 + * + * @param value 公式值 + */ @Override public void setValue(BaseFormula value) { diff --git a/designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java b/designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java index 6d47cd090..b8805b61d 100644 --- a/designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java +++ b/designer-base/src/main/java/com/fr/design/gui/itextfield/DictionaryTextField.java @@ -3,6 +3,10 @@ package com.fr.design.gui.itextfield; import javax.swing.text.Document; /** + * 文字 ui. + * 保存实际值,展示值。 + * 允许实际值和展示值不同。 + * * created by Harrison on 2020/08/03 **/ public class DictionaryTextField extends UITextField { diff --git a/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java b/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java index 8fd8aaed0..f25d730d0 100644 --- a/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java +++ b/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java @@ -410,17 +410,16 @@ public class DSColumnAdvancedPane extends BasicPane { private static class JFormulaField extends JPanel { private CellElement cellElement; private FormulaTextField formulaTextField; - private String defaultValue; + private BaseFormula defaultFormula; public JFormulaField(String defaultValue) { - this.defaultValue = defaultValue; + this.defaultFormula = BaseFormula.createFormulaBuilder().build(defaultValue); this.setLayout(FRGUIPaneFactory.createBoxFlowLayout()); UILabel bottomLabel = new UILabel("="); bottomLabel.setFont(new Font("Dialog", Font.BOLD, 12)); this.add(bottomLabel); formulaTextField = new FormulaTextField(24); - this.add(formulaTextField); formulaTextField.setText(defaultValue); UIButton bottomFrmulaButton = new UIButton("..."); @@ -481,9 +480,8 @@ public class DSColumnAdvancedPane extends BasicPane { public void doOk() { BaseFormula valueFormula = formulaPane.update(); if (valueFormula.getContent().length() <= 1) { - formulaTextField.setText(defaultValue); + formulaTextField.setValue(defaultFormula); } else { - formulaTextField.setText(valueFormula.getPureContent()); formulaTextField.setValue(valueFormula); } } diff --git a/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java b/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java index 61223f167..983fbb9da 100644 --- a/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java +++ b/designer-realize/src/main/java/com/fr/quickeditor/cellquick/CellDSColumnEditor.java @@ -1064,13 +1064,14 @@ public class CellDSColumnEditor extends CellQuickEditor { public class JFormulaField extends JPanel { private CellElement cellElement; private FormulaTextField formulaTextField; - private String defaultValue; + private BaseFormula defaultFormula; public JFormulaField(String defaultValue) { - this.defaultValue = defaultValue; + this.defaultFormula = BaseFormula.createFormulaBuilder().build(defaultValue); formulaTextField = new FormulaTextField(); - formulaTextField.setText(defaultValue); + formulaTextField.setValue(defaultFormula); + JPanel textFieldPane = new JPanel(new BorderLayout()); textFieldPane.add(formulaTextField, BorderLayout.CENTER); textFieldPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); @@ -1101,7 +1102,6 @@ public class CellDSColumnEditor extends CellQuickEditor { public void populateFormula(BaseFormula baseFormula) { this.formulaTextField.setValue(baseFormula); - this.formulaTextField.setText(baseFormula.getContent()); } public BaseFormula getFormula() { @@ -1145,9 +1145,8 @@ public class CellDSColumnEditor extends CellQuickEditor { public void doOk() { BaseFormula valueFormula = formulaPane.update(); if (valueFormula.getContent().length() <= 1) { - formulaTextField.setText(defaultValue); + formulaTextField.setValue(defaultFormula); } else { - formulaTextField.setText(valueFormula.getPureContent()); formulaTextField.setValue(valueFormula); } } @@ -1165,6 +1164,7 @@ public class CellDSColumnEditor extends CellQuickEditor { */ public class CustomValuePane extends JPanel { private static final String DEFAULT_VALUE = "=$$$"; + private final BaseFormula DEFAULT_FORMULA = BaseFormula.createFormulaBuilder().build(DEFAULT_VALUE); private JFormulaField formulaField; @@ -1187,6 +1187,8 @@ public class CellDSColumnEditor extends CellQuickEditor { BaseFormula valueFormula = dSColumn.getResultObject(); if (valueFormula != null) { formulaField.populateFormula(valueFormula); + } else { + formulaField.populateFormula(DEFAULT_FORMULA); } formulaField.populateElement(cellElement);