Browse Source

Merge pull request #618 in DESIGN/design from ~YAOH.WU/design:feature/10.0 to feature/10.0

* commit '1c2a3684b1c4ceb391a42f09712ea485f5bbce14':
  TinyFormulaPane
  限制输入负数
  REPORT-12788 网络报表对话框标题支持字符串和公式
research/10.0
yaoh.wu 6 years ago
parent
commit
43babaf109
  1. 107
      designer-base/src/main/java/com/fr/design/hyperlink/ReportletHyperNorthPane.java

107
designer-base/src/main/java/com/fr/design/hyperlink/ReportletHyperNorthPane.java

@ -4,10 +4,7 @@ import com.fr.base.BaseFormula;
import com.fr.design.actions.UpdateAction; import com.fr.design.actions.UpdateAction;
import com.fr.design.dialog.BasicDialog; import com.fr.design.dialog.BasicDialog;
import com.fr.design.dialog.DialogActionAdapter; import com.fr.design.dialog.DialogActionAdapter;
import com.fr.design.event.UIObserverListener; import com.fr.design.formula.TinyFormulaPane;
import com.fr.design.formula.FormulaFactory;
import com.fr.design.formula.UIFormula;
import com.fr.design.formula.VariableResolver;
import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.ibutton.UIButton;
import com.fr.design.gui.ibutton.UIRadioButton; import com.fr.design.gui.ibutton.UIRadioButton;
import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.icheckbox.UICheckBox;
@ -20,9 +17,9 @@ import com.fr.design.i18n.Toolkit;
import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.FRGUIPaneFactory;
import com.fr.design.layout.TableLayoutHelper; import com.fr.design.layout.TableLayoutHelper;
import com.fr.design.utils.gui.GUICoreUtils; import com.fr.design.utils.gui.GUICoreUtils;
import com.fr.general.IOUtils;
import com.fr.js.ReportletHyperlink; import com.fr.js.ReportletHyperlink;
import com.fr.js.ReportletHyperlinkDialogAttr; import com.fr.js.ReportletHyperlinkDialogAttr;
import com.fr.stable.CommonUtils;
import com.fr.stable.FormulaProvider; import com.fr.stable.FormulaProvider;
import com.fr.stable.StringUtils; import com.fr.stable.StringUtils;
@ -76,7 +73,7 @@ public class ReportletHyperNorthPane extends AbstractHyperNorthPane<ReportletHyp
/** /**
* 对话框标题输入框 * 对话框标题输入框
*/ */
private JFormulaField titleFiled; private TinyFormulaPane titleFiled;
/** /**
@ -186,14 +183,19 @@ public class ReportletHyperNorthPane extends AbstractHyperNorthPane<ReportletHyp
this.postComboBox.setSelectedIndex(link.isByPost() ? 1 : 0); this.postComboBox.setSelectedIndex(link.isByPost() ? 1 : 0);
ReportletHyperlinkDialogAttr attr = link.getAttr(); ReportletHyperlinkDialogAttr attr = link.getAttr();
titleFiled.setFormulaText(StringUtils.EMPTY); titleFiled.populateBean(StringUtils.EMPTY);
leftLocation.setText(StringUtils.EMPTY); leftLocation.setText(StringUtils.EMPTY);
topLocation.setText(StringUtils.EMPTY); topLocation.setText(StringUtils.EMPTY);
center.setSelected(true); center.setSelected(true);
if (attr != null) { if (attr != null) {
FormulaProvider title = attr.getTitleFormula(); Object title = attr.getTitle();
String titleContent = title == null ? StringUtils.EMPTY : title.getPureContent(); String titleContent;
titleFiled.setFormulaText(titleContent); if (title instanceof FormulaProvider) {
titleContent = ((FormulaProvider) title).getContent();
} else {
titleContent = title == null ? StringUtils.EMPTY : title.toString();
}
titleFiled.populateBean(titleContent);
boolean isCenter = attr.isCenter(); boolean isCenter = attr.isCenter();
if (!isCenter) { if (!isCenter) {
int left = attr.getLeft(), top = attr.getTop(); int left = attr.getLeft(), top = attr.getTop();
@ -222,7 +224,12 @@ public class ReportletHyperNorthPane extends AbstractHyperNorthPane<ReportletHyp
reportletHyperlink.setByPost(postComboBox.getSelectedIndex() == 1); reportletHyperlink.setByPost(postComboBox.getSelectedIndex() == 1);
ReportletHyperlinkDialogAttr attr = new ReportletHyperlinkDialogAttr(); ReportletHyperlinkDialogAttr attr = new ReportletHyperlinkDialogAttr();
attr.setTitleFormula(BaseFormula.createFormulaBuilder().build(titleFiled.getFormulaText())); String title = titleFiled.updateBean();
if (CommonUtils.maybeFormula(title)) {
attr.setTitle(BaseFormula.createFormulaBuilder().build(titleFiled.updateBean()));
} else {
attr.setTitle(title);
}
attr.setCenter(center.isSelected()); attr.setCenter(center.isSelected());
if (!attr.isCenter()) { if (!attr.isCenter()) {
attr.setLeft((int) leftLocation.getValue()); attr.setLeft((int) leftLocation.getValue());
@ -346,7 +353,8 @@ public class ReportletHyperNorthPane extends AbstractHyperNorthPane<ReportletHyp
private void initTitlePanel(List<Component[]> dialogComponents) { private void initTitlePanel(List<Component[]> dialogComponents) {
// 对话框标题 // 对话框标题
titleFiled = new JFormulaField(15); titleFiled = new TinyFormulaPane();
titleFiled.getUITextField().setColumns(15);
final JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0)); final JPanel titlePanel = new JPanel(new FlowLayout(FlowLayout.LEFT, 0, 0));
titlePanel.add(titleFiled); titlePanel.add(titleFiled);
Component[] titleComponents = new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Basic_Hyperlink_Dialog_Title") + ":"), titlePanel}; Component[] titleComponents = new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Basic_Hyperlink_Dialog_Title") + ":"), titlePanel};
@ -359,6 +367,7 @@ public class ReportletHyperNorthPane extends AbstractHyperNorthPane<ReportletHyp
heightLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10)); heightLabel.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 10));
sizeJPanel.add(heightLabel); sizeJPanel.add(heightLabel);
UINumberField heightTextFiled = new UINumberField(); UINumberField heightTextFiled = new UINumberField();
heightTextFiled.setMinValue(0);
heightTextFiled.setText(String.valueOf(DEFAULT_H_VALUE)); heightTextFiled.setText(String.valueOf(DEFAULT_H_VALUE));
heightTextFiled.setPreferredSize(new Dimension(40, 20)); heightTextFiled.setPreferredSize(new Dimension(40, 20));
sizeJPanel.add(heightTextFiled); sizeJPanel.add(heightTextFiled);
@ -367,6 +376,7 @@ public class ReportletHyperNorthPane extends AbstractHyperNorthPane<ReportletHyp
widthLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10)); widthLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
sizeJPanel.add(widthLabel); sizeJPanel.add(widthLabel);
UINumberField widthTextFiled = new UINumberField(); UINumberField widthTextFiled = new UINumberField();
widthTextFiled.setMinValue(0);
widthTextFiled.setText(String.valueOf(DEFAULT_V_VALUE)); widthTextFiled.setText(String.valueOf(DEFAULT_V_VALUE));
widthTextFiled.setPreferredSize(new Dimension(40, 20)); widthTextFiled.setPreferredSize(new Dimension(40, 20));
sizeJPanel.add(widthTextFiled); sizeJPanel.add(widthTextFiled);
@ -395,11 +405,13 @@ public class ReportletHyperNorthPane extends AbstractHyperNorthPane<ReportletHyp
final UILabel leftLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Hyperlink_Dialog_Position_Left")); final UILabel leftLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Hyperlink_Dialog_Position_Left"));
leftLabel.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 10)); leftLabel.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 10));
leftLocation = new UINumberField(); leftLocation = new UINumberField();
leftLocation.setMinValue(0);
leftLocation.setPreferredSize(new Dimension(40, 20)); leftLocation.setPreferredSize(new Dimension(40, 20));
// 位置 距上 // 位置 距上
final UILabel topLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Hyperlink_Dialog_Position_Top")); final UILabel topLabel = new UILabel(Toolkit.i18nText("Fine-Design_Basic_Hyperlink_Dialog_Position_Top"));
topLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10)); topLabel.setBorder(BorderFactory.createEmptyBorder(0, 10, 0, 10));
topLocation = new UINumberField(); topLocation = new UINumberField();
topLocation.setMinValue(0);
topLocation.setPreferredSize(new Dimension(40, 20)); topLocation.setPreferredSize(new Dimension(40, 20));
locationPanel.add(leftLabel); locationPanel.add(leftLabel);
@ -435,75 +447,4 @@ public class ReportletHyperNorthPane extends AbstractHyperNorthPane<ReportletHyp
dialogComponents.add(footerComponents); dialogComponents.add(footerComponents);
othersComponents.add(footerComponents); othersComponents.add(footerComponents);
} }
/**
* 公式输入框
*/
public class JFormulaField extends JPanel {
private UITextField formulaTextField;
public JFormulaField(int columns) {
formulaTextField = new UITextField(columns);
JPanel textFieldPane = new JPanel(new BorderLayout());
textFieldPane.add(formulaTextField, BorderLayout.CENTER);
textFieldPane.setBorder(BorderFactory.createEmptyBorder(0, 0, 0, 5));
UIButton formulaButton = new UIButton(IOUtils.readIcon("/com/fr/design/images/m_insert/formula.png"));
formulaButton.setToolTipText(Toolkit.i18nText("Fine-Design_Report_Formula") + "...");
formulaButton.setPreferredSize(new Dimension(24, formulaTextField.getPreferredSize().height));
formulaButton.addActionListener(formulaButtonActionListener);
JPanel pane = new JPanel(new BorderLayout());
pane.add(textFieldPane, BorderLayout.CENTER);
pane.add(formulaButton, BorderLayout.EAST);
this.setLayout(new BorderLayout());
this.add(pane, BorderLayout.NORTH);
}
public void setFormulaText(String formulaContent) {
this.formulaTextField.setText(formulaContent);
}
public String getFormulaText() {
String text = formulaTextField.getText();
if (text == null) {
text = StringUtils.EMPTY;
}
return text;
}
/**
* 添加事件监听器
*
* @param listener 公式文本输入框改动事件监听器
*/
public void addListener(UIObserverListener listener) {
this.formulaTextField.registerChangeListener(listener);
}
/**
* 取消事件监听器
*/
public void removeListener() {
this.formulaTextField.registerChangeListener(null);
}
private ActionListener formulaButtonActionListener = new ActionListener() {
@Override
public void actionPerformed(ActionEvent evt) {
BaseFormula valueFormula = BaseFormula.createFormulaBuilder().build();
valueFormula.setContent(getFormulaText());
final UIFormula formulaPane = FormulaFactory.createFormulaPaneWhenReserveFormula();
formulaPane.populate(valueFormula, VariableResolver.DEFAULT);
formulaPane.showLargeWindow(SwingUtilities.getWindowAncestor(ReportletHyperNorthPane.this), new DialogActionAdapter() {
@Override
public void doOk() {
BaseFormula valueFormula = formulaPane.update();
setFormulaText(valueFormula.getContent());
}
}).setVisible(true);
}
};
}
} }

Loading…
Cancel
Save