From dd64efada6d477325a251ebdf14bd0792193e229 Mon Sep 17 00:00:00 2001 From: Lanlan Date: Tue, 19 May 2020 10:32:13 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-29409=20=E8=A1=A8=E6=A0=BC=E5=92=8C?= =?UTF-8?q?=E5=9B=BE=E8=A1=A8=E7=99=BE=E5=88=86=E6=AF=94=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E5=8C=96=E8=BF=91=E4=BC=BC=E7=BB=93=E6=9E=9C=E4=B8=8D=E5=90=8C?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../com/fr/design/gui/style/FormatPane.java | 43 +++++++++++++++++-- 1 file changed, 39 insertions(+), 4 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/style/FormatPane.java b/designer-base/src/main/java/com/fr/design/gui/style/FormatPane.java index cf362f7f5..22f0a3647 100644 --- a/designer-base/src/main/java/com/fr/design/gui/style/FormatPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/style/FormatPane.java @@ -6,6 +6,7 @@ import com.fr.base.Style; import com.fr.base.TextFormat; import com.fr.data.core.FormatField; import com.fr.data.core.FormatField.FormatContents; +import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.i18n.Toolkit; import com.fr.design.border.UIRoundedBorder; import com.fr.design.constants.LayoutConstants; @@ -22,6 +23,8 @@ import com.fr.general.ComparatorUtils; import com.fr.stable.StringUtils; +import java.math.BigDecimal; +import java.math.RoundingMode; import javax.swing.*; import javax.swing.border.Border; import javax.swing.border.TitledBorder; @@ -63,6 +66,8 @@ public class FormatPane extends AbstractBasicStylePane implements GlobalNameObse private JPanel contentPane; private JPanel txtCenterPane; private JPanel centerPane; + private JPanel optionPane; + private UICheckBox roundingBox; private JPanel formatFontPane; private FRFontPane frFontPane; private boolean isRightFormat; @@ -123,7 +128,23 @@ public class FormatPane extends AbstractBasicStylePane implements GlobalNameObse // centerPane.setBorder(LEFT_BORDER); frFontPane.setBorder(LEFT_BORDER); - Component[][] components = getComponent(fontPane, centerPane, typePane); + JPanel option = new JPanel(new BorderLayout()); + option.add(new UILabel(Toolkit.i18nText("Fine-Design_Report_Base_Option"), SwingConstants.LEFT), BorderLayout.WEST); + roundingBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_Base_Option_Half_Up")); + roundingBox.setBorder(BorderFactory.createEmptyBorder(0, 40, 0, 0)); + roundingBox.addItemListener(new ItemListener() { + @Override + public void itemStateChanged(ItemEvent e) { + } + }); + roundingBox.setGlobalName("roundingBox"); + option.add(roundingBox, BorderLayout.CENTER); + optionPane = new JPanel(new CardLayout()); + optionPane.add(new JPanel(), "hide"); + optionPane.setPreferredSize(new Dimension(0, 0)); + optionPane.add(option, "show"); + + Component[][] components = getComponent(fontPane, centerPane, typePane, optionPane); this.add(createContentPane(components), BorderLayout.CENTER); } @@ -137,11 +158,12 @@ public class FormatPane extends AbstractBasicStylePane implements GlobalNameObse } - protected Component[][] getComponent (JPanel fontPane, JPanel centerPane, JPanel typePane) { + protected Component[][] getComponent (JPanel fontPane, JPanel centerPane, JPanel typePane, JPanel optionPane) { return new Component[][]{ new Component[]{null, null}, new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Report_Base_Format"), SwingConstants.LEFT), typePane}, new Component[]{centerPane, null}, + new Component[]{optionPane, null}, new Component[]{fontPane, frFontPane}, }; } @@ -220,6 +242,7 @@ public class FormatPane extends AbstractBasicStylePane implements GlobalNameObse setPatternComboBoxAndList(FormatContents.CURRENCY, pattern); } else if (pattern.indexOf("%") > 0) { setPatternComboBoxAndList(FormatContents.PERCENT, pattern); + this.roundingBox.setSelected(((CoreDecimalFormat) format).getRoundingMode().equals(RoundingMode.HALF_UP)); } else if (pattern.indexOf("E") > 0) { setPatternComboBoxAndList(FormatContents.SCIENTIFIC, pattern); } else { @@ -286,7 +309,8 @@ public class FormatPane extends AbstractBasicStylePane implements GlobalNameObse } if (isRightFormat) { if (StringUtils.isNotEmpty(patternString)) { - return FormatField.getInstance().getFormat(getFormatContents(), patternString); + RoundingMode roundingMode = roundingBox.isSelected() ? RoundingMode.HALF_UP : RoundingMode.HALF_EVEN; + return FormatField.getInstance().getFormat(getFormatContents(), patternString, roundingMode); } } return null; @@ -342,6 +366,15 @@ public class FormatPane extends AbstractBasicStylePane implements GlobalNameObse centerPane.setPreferredSize(new Dimension(270, 65)); cardLayout.show(centerPane, "show"); } + CardLayout optionLayout = ((CardLayout) optionPane.getLayout()); + if (getFormatContents() == FormatContents.PERCENT) { + optionPane.setPreferredSize(new Dimension(100, 20)); + optionLayout.show(optionPane, "show"); + } else { + optionPane.setPreferredSize(new Dimension(0, 0)); + optionLayout.show(optionPane, "hide"); + roundingBox.setSelected(false); + } } } @@ -370,7 +403,9 @@ public class FormatPane extends AbstractBasicStylePane implements GlobalNameObse * update */ public Style update(Style style) { - if (ComparatorUtils.equals(globalNameListener.getGlobalName(), "textField") || ComparatorUtils.equals(globalNameListener.getGlobalName(), "typeComboBox")) { + if (ComparatorUtils.equals(globalNameListener.getGlobalName(), "textField") + || ComparatorUtils.equals(globalNameListener.getGlobalName(), "typeComboBox") + || ComparatorUtils.equals(globalNameListener.getGlobalName(), "roundingBox")) { return style.deriveFormat(this.update()); } else { return style.deriveFRFont(this.frFontPane.update(style.getFRFont()));