|
|
|
@ -1,39 +1,35 @@
|
|
|
|
|
package com.fr.quickeditor.floatquick; |
|
|
|
|
|
|
|
|
|
import com.fine.theme.icon.LazyIcon; |
|
|
|
|
import com.fr.base.BaseFormula; |
|
|
|
|
import com.fr.base.BaseUtils; |
|
|
|
|
import com.fr.base.Style; |
|
|
|
|
import com.fr.base.TextFormat; |
|
|
|
|
import com.fr.design.constants.UIConstants; |
|
|
|
|
import com.fr.design.file.HistoryTemplateListPane; |
|
|
|
|
import com.fr.design.gui.ibutton.UIButton; |
|
|
|
|
import com.fr.design.gui.itextarea.UITextArea; |
|
|
|
|
import com.fr.design.mainframe.ElementCasePane; |
|
|
|
|
import com.fr.design.utils.DesignUtils; |
|
|
|
|
import com.fr.quickeditor.FloatQuickEditor; |
|
|
|
|
import com.fr.report.ReportHelper; |
|
|
|
|
import com.fr.stable.StringUtils; |
|
|
|
|
|
|
|
|
|
import javax.swing.BorderFactory; |
|
|
|
|
import javax.swing.JPanel; |
|
|
|
|
import javax.swing.JTextArea; |
|
|
|
|
import javax.swing.event.DocumentEvent; |
|
|
|
|
import javax.swing.event.DocumentListener; |
|
|
|
|
import java.awt.BorderLayout; |
|
|
|
|
import java.awt.Color; |
|
|
|
|
import java.awt.Dimension; |
|
|
|
|
import java.awt.Insets; |
|
|
|
|
import java.awt.event.ActionEvent; |
|
|
|
|
import java.awt.event.ActionListener; |
|
|
|
|
|
|
|
|
|
import static com.fine.swing.ui.layout.Layouts.cell; |
|
|
|
|
import static com.fine.swing.ui.layout.Layouts.row; |
|
|
|
|
|
|
|
|
|
public class FloatStringQuickEditor extends FloatQuickEditor { |
|
|
|
|
private JTextArea stringTextField; |
|
|
|
|
private UIButton formulaButton; |
|
|
|
|
private static final char FORMULA_BEGINNING = '='; |
|
|
|
|
private final UITextArea stringTextField; |
|
|
|
|
private final UIButton formulaButton; |
|
|
|
|
|
|
|
|
|
// august:如果是原来编辑的是公式,要保留公式里的这些属性,不然在公式和字符串转化时,就会丢失这些属性设置
|
|
|
|
|
private boolean reserveInResult = false; |
|
|
|
|
private boolean reserveOnWriteOrAnaly = true; |
|
|
|
|
|
|
|
|
|
private DocumentListener documentListener = new DocumentListener() { |
|
|
|
|
private final DocumentListener documentListener = new DocumentListener() { |
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
|
public void insertUpdate(DocumentEvent e) { |
|
|
|
@ -54,36 +50,19 @@ public class FloatStringQuickEditor extends FloatQuickEditor {
|
|
|
|
|
|
|
|
|
|
public FloatStringQuickEditor() { |
|
|
|
|
super(); |
|
|
|
|
stringTextField = new JTextArea(); |
|
|
|
|
initTextField(); |
|
|
|
|
stringTextField = new UITextArea(); |
|
|
|
|
formulaButton = new UIButton(); |
|
|
|
|
formulaButton.setPreferredSize(new Dimension(25, 23)); |
|
|
|
|
formulaButton.setIcon(BaseUtils.readIcon("/com/fr/design/images/m_insert/formula.png")); |
|
|
|
|
ActionListener getFormulaActionListener = new ActionListener() { |
|
|
|
|
@Override |
|
|
|
|
public void actionPerformed(ActionEvent e) { |
|
|
|
|
((ElementCasePane) HistoryTemplateListPane.getInstance().getCurrentEditingTemplate().getCurrentElementCasePane()).getGrid().startEditing(); |
|
|
|
|
} |
|
|
|
|
}; |
|
|
|
|
formulaButton.addActionListener(getFormulaActionListener); |
|
|
|
|
JPanel pane = new JPanel(new BorderLayout(5, 0)); |
|
|
|
|
pane.add(stringTextField, BorderLayout.CENTER); |
|
|
|
|
pane.add(formulaButton, BorderLayout.EAST); |
|
|
|
|
pane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5)); |
|
|
|
|
formulaButton.setIcon(new LazyIcon("formula")); |
|
|
|
|
formulaButton.addActionListener(e -> ((ElementCasePane<?>) HistoryTemplateListPane.getInstance() |
|
|
|
|
.getCurrentEditingTemplate().getCurrentElementCasePane()) |
|
|
|
|
.getGrid().startEditing()); |
|
|
|
|
formulaButton.setVisible(false); |
|
|
|
|
this.setLayout(new BorderLayout()); |
|
|
|
|
this.setBorder(BorderFactory.createEmptyBorder(10, 10, 10, 10)); |
|
|
|
|
this.add(pane, BorderLayout.NORTH); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private void initTextField() { |
|
|
|
|
stringTextField.setFont(DesignUtils.getDefaultGUIFont()); |
|
|
|
|
stringTextField.setOpaque(true); |
|
|
|
|
stringTextField.setLineWrap(true); |
|
|
|
|
stringTextField.setWrapStyleWord(true); |
|
|
|
|
stringTextField.setMargin(new Insets(5, 5, 5, 5)); |
|
|
|
|
stringTextField.setBorder(BorderFactory.createLineBorder(UIConstants.POP_DIALOG_BORDER)); |
|
|
|
|
stringTextField.setBackground(Color.WHITE); |
|
|
|
|
add(row(10, |
|
|
|
|
cell(stringTextField).weight(1), |
|
|
|
|
cell(formulaButton) |
|
|
|
|
).getComponent(), BorderLayout.NORTH); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
@ -92,19 +71,17 @@ public class FloatStringQuickEditor extends FloatQuickEditor {
|
|
|
|
|
String str; |
|
|
|
|
Object value = null; |
|
|
|
|
//处理撤销时npe
|
|
|
|
|
if (floatElement != null){ |
|
|
|
|
if (floatElement != null) { |
|
|
|
|
value = floatElement.getValue(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
if (value == null) { |
|
|
|
|
str = StringUtils.EMPTY; |
|
|
|
|
} else if (value instanceof BaseFormula) { |
|
|
|
|
//MoMeak: 没拆文本框和公式所以需要这么个玩意
|
|
|
|
|
formulaButton.setVisible(true); |
|
|
|
|
BaseFormula formula = (BaseFormula) value; |
|
|
|
|
str = formula.getContent(); |
|
|
|
|
stringTextField.setLineWrap(false); |
|
|
|
|
this.setBorder(BorderFactory.createEmptyBorder(10, 75, 10, 10)); |
|
|
|
|
reserveInResult = formula.isReserveInResult(); |
|
|
|
|
reserveOnWriteOrAnaly = formula.isReserveOnWriteOrAnaly(); |
|
|
|
|
} else { |
|
|
|
@ -121,7 +98,7 @@ public class FloatStringQuickEditor extends FloatQuickEditor {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void changeReportPaneCell(String tmpText) { |
|
|
|
|
if (tmpText != null && (tmpText.length() > 0 && tmpText.charAt(0) == '=')) { |
|
|
|
|
if (isFormula(tmpText)) { |
|
|
|
|
BaseFormula textFormula = BaseFormula.createFormulaBuilder().build(tmpText); |
|
|
|
|
textFormula.setReserveInResult(reserveInResult); |
|
|
|
|
textFormula.setReserveOnWriteOrAnaly(reserveOnWriteOrAnaly); |
|
|
|
@ -137,4 +114,9 @@ public class FloatStringQuickEditor extends FloatQuickEditor {
|
|
|
|
|
fireTargetModified(); |
|
|
|
|
stringTextField.requestFocus(); |
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
private static boolean isFormula(String tmpText) { |
|
|
|
|
return StringUtils.isNotEmpty(tmpText) |
|
|
|
|
&& tmpText.charAt(0) == FORMULA_BEGINNING; |
|
|
|
|
} |
|
|
|
|
} |