Browse Source

Pull request #1676: REPORT-29409 表格和图表百分比格式化近似结果不同

Merge in DESIGN/design from ~LANLAN/design:release/10.0 to release/10.0

* commit '163a09c0014aa5edc40e8da1c2092ccf5a4bb4a8':
  REPORT-29409 表格和图表百分比格式化近似结果不同
feature/big-screen
Lanlan 4 years ago
parent
commit
455ed9efb2
  1. 43
      designer-base/src/main/java/com/fr/design/gui/style/FormatPane.java

43
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()));

Loading…
Cancel
Save