Browse Source
Merge in DESIGN/design from ~HARRISON/design:release/10.0 to release/10.0 * commit 'f23efebce31930931d7f58b96c0f1ba3ba84cc77': 回滚代码, 现有逻辑不支持功能feature/big-screen
Harrison
4 years ago
6 changed files with 79 additions and 276 deletions
@ -1,99 +0,0 @@
|
||||
package com.fr.design.formula; |
||||
|
||||
import com.fr.base.BaseFormula; |
||||
import com.fr.design.gui.itextfield.DictionaryTextField; |
||||
import com.fr.stable.StringUtils; |
||||
|
||||
import javax.swing.text.Document; |
||||
|
||||
/** |
||||
* 公式展示时使用。 |
||||
* 展示 String. |
||||
* 但实际保存的是 BaseFormula。 |
||||
* 从而保留公式的形态。 |
||||
* |
||||
* created by Harrison on 2020/08/03 |
||||
**/ |
||||
public class FormulaTextField extends DictionaryTextField<BaseFormula> { |
||||
|
||||
private static final String EMPTY_STRING = "="; |
||||
|
||||
public FormulaTextField() { |
||||
} |
||||
|
||||
public FormulaTextField(int columns) { |
||||
super(columns); |
||||
} |
||||
|
||||
public FormulaTextField(String text, int columns, BaseFormula value) { |
||||
super(text, columns, value); |
||||
} |
||||
|
||||
public FormulaTextField(String text, BaseFormula value) { |
||||
super(text, value); |
||||
} |
||||
|
||||
public FormulaTextField(Document doc, String text, int columns, BaseFormula value) { |
||||
super(doc, text, columns, value); |
||||
} |
||||
|
||||
@Override |
||||
public BaseFormula getValue() { |
||||
|
||||
if (this.value == null) { |
||||
this.value = createDefault(); |
||||
} |
||||
//保持联动
|
||||
linkValueByText(); |
||||
return value; |
||||
} |
||||
|
||||
private void linkValueByText() { |
||||
|
||||
String content = getText(); |
||||
this.value.setContent(content); |
||||
} |
||||
|
||||
/** |
||||
* 设置值时,会将展示的公式值一同设置进去 |
||||
* |
||||
* @param value 公式值 |
||||
*/ |
||||
@Override |
||||
public void setValue(BaseFormula value) { |
||||
|
||||
if (value == null) { |
||||
value = createDefault(); |
||||
} |
||||
this.value = value; |
||||
} |
||||
|
||||
/** |
||||
* 是需要设置不带 = 号,还是带 = 号。 |
||||
* |
||||
* @param value 值 |
||||
* @param isPure 带不带 = 号, 是 = 不带, 否 = 带。 |
||||
*/ |
||||
public void setValueAndText(BaseFormula value, boolean isPure) { |
||||
|
||||
setValue(value); |
||||
String content = null; |
||||
if (isPure) { |
||||
content = this.value.getPureContent(); |
||||
} else { |
||||
content = this.value.getContent(); |
||||
} |
||||
setText(content); |
||||
} |
||||
|
||||
private BaseFormula createDefault() { |
||||
|
||||
String text = getText(); |
||||
if (StringUtils.isNotEmpty(text)) { |
||||
return BaseFormula.createFormulaBuilder().build(text); |
||||
} else { |
||||
//防止默认值被修改, 每一次创建都是不一样的。
|
||||
return BaseFormula.createFormulaBuilder().build(EMPTY_STRING); |
||||
} |
||||
} |
||||
} |
@ -1,45 +0,0 @@
|
||||
package com.fr.design.gui.itextfield; |
||||
|
||||
import javax.swing.text.Document; |
||||
|
||||
/** |
||||
* 文字 ui. |
||||
* 保存实际值,展示值。 |
||||
* 允许实际值和展示值不同。 |
||||
* |
||||
* created by Harrison on 2020/08/03 |
||||
**/ |
||||
public class DictionaryTextField<T> extends UITextField { |
||||
|
||||
protected T value; |
||||
|
||||
public DictionaryTextField() { |
||||
} |
||||
|
||||
public DictionaryTextField(int columns) { |
||||
super(columns); |
||||
} |
||||
|
||||
public DictionaryTextField(String text, int columns, T value) { |
||||
super(text, columns); |
||||
this.value = value; |
||||
} |
||||
|
||||
public DictionaryTextField(String text, T value) { |
||||
super(text); |
||||
this.value = value; |
||||
} |
||||
|
||||
public DictionaryTextField(Document doc, String text, int columns, T value) { |
||||
super(doc, text, columns); |
||||
this.value = value; |
||||
} |
||||
|
||||
public T getValue() { |
||||
return value; |
||||
} |
||||
|
||||
public void setValue(T value) { |
||||
this.value = value; |
||||
} |
||||
} |
@ -1,28 +0,0 @@
|
||||
package com.fr.design.formula; |
||||
|
||||
import com.fr.base.BaseFormula; |
||||
import org.junit.Assert; |
||||
import org.junit.Test; |
||||
|
||||
import static org.junit.Assert.*; |
||||
|
||||
public class FormulaTextFieldTest { |
||||
|
||||
@Test |
||||
public void testSet() { |
||||
|
||||
FormulaTextField field = new FormulaTextField(); |
||||
BaseFormula aaaa = BaseFormula.createFormulaBuilder().build("aaaa"); |
||||
field.setValueAndText(aaaa, true); |
||||
|
||||
Assert.assertEquals("aaaa", field.getText()); |
||||
|
||||
field.setValueAndText(aaaa, false); |
||||
Assert.assertEquals("=aaaa", field.getText()); |
||||
|
||||
field.setText("bbbb"); |
||||
BaseFormula formula = field.getValue(); |
||||
Assert.assertEquals("bbbb", formula.getPureContent()); |
||||
} |
||||
|
||||
} |
Loading…
Reference in new issue