From 19954cabfd990c5e51821c8716e6e6b61be9ec88 Mon Sep 17 00:00:00 2001 From: Starryi Date: Mon, 13 Dec 2021 16:58:42 +0800 Subject: [PATCH] =?UTF-8?q?REPORT-63808=20=E3=80=90=E4=B8=BB=E9=A2=98?= =?UTF-8?q?=E4=BC=98=E5=8C=96=E3=80=91=E6=A0=BC=E5=BC=8F=E5=8D=95=E7=8B=AC?= =?UTF-8?q?=E6=8B=BF=E5=87=BA=E6=9D=A5=E4=BB=A5=E5=90=8E=EF=BC=8C=E5=8F=91?= =?UTF-8?q?=E7=8E=B0=E6=95=B0=E6=8D=AE=E5=88=97=E7=9A=84=E5=BC=B9=E7=AA=97?= =?UTF-8?q?=E9=85=8D=E7=BD=AE=E4=B8=AD=E6=B2=A1=E6=9C=89=E6=A0=BC=E5=BC=8F?= =?UTF-8?q?=E9=A1=B9?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit 【问题原因】 格式设置项从样式中分离出来后,数据列的弹窗 中需要按照新的设计稿增加格式设置 【改动思路】 同上 --- .../fr/design/gui/style/TextFormatPane.java | 217 ++++++++---------- .../design/dscolumn/DSColumnAdvancedPane.java | 54 ++--- 2 files changed, 115 insertions(+), 156 deletions(-) diff --git a/designer-base/src/main/java/com/fr/design/gui/style/TextFormatPane.java b/designer-base/src/main/java/com/fr/design/gui/style/TextFormatPane.java index 8c96c4c862..fbe63218ec 100644 --- a/designer-base/src/main/java/com/fr/design/gui/style/TextFormatPane.java +++ b/designer-base/src/main/java/com/fr/design/gui/style/TextFormatPane.java @@ -7,7 +7,6 @@ import com.fr.base.TextFormat; import com.fr.data.core.FormatField; import com.fr.data.core.FormatField.FormatContents; import com.fr.design.border.UIRoundedBorder; -import com.fr.design.constants.LayoutConstants; import com.fr.design.constants.UIConstants; import com.fr.design.event.GlobalNameListener; import com.fr.design.event.GlobalNameObserver; @@ -18,21 +17,18 @@ import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.icombobox.UIComboBoxRenderer; import com.fr.design.gui.ilable.UILabel; import com.fr.design.i18n.Toolkit; -import com.fr.design.layout.TableLayout; -import com.fr.design.layout.TableLayoutHelper; import com.fr.general.ComparatorUtils; import com.fr.stable.StringUtils; import javax.swing.BorderFactory; +import javax.swing.JComponent; import javax.swing.JLabel; import javax.swing.JList; import javax.swing.JPanel; -import javax.swing.SwingConstants; import javax.swing.UIManager; import javax.swing.border.Border; import javax.swing.border.TitledBorder; import java.awt.BorderLayout; -import java.awt.CardLayout; import java.awt.Color; import java.awt.Component; import java.awt.Dimension; @@ -43,7 +39,6 @@ import java.awt.event.ItemListener; import java.math.RoundingMode; import java.text.Format; import java.text.SimpleDateFormat; -import java.util.Arrays; /** * @author Starryi @@ -68,69 +63,45 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName private static final Integer[] DATE_TYPES = new Integer[]{FormatContents.NULL, FormatContents.DATE, FormatContents.TIME}; - private Format format; - - private UIComboBox typeComboBox; - private TextFontComboBox textField; - private UILabel sampleLabel; - private JPanel contentPane; - private JPanel txtCenterPane; - private JPanel centerPane; - private JPanel optionPane; - private UICheckBox roundingBox; - private JPanel formatFontPane; + protected UIComboBox typeComboBox; + protected TextFontComboBox textField; + protected UICheckBox roundingBox; + protected UILabel previewLabel; + private boolean isRightFormat; private boolean isDate = false; private GlobalNameListener globalNameListener = null; - /** - * Constructor. - */ public TextFormatPane() { - this.initComponents(TYPES); - } - protected UIComboBox getTypeComboBox() { - return typeComboBox; + initFormatTypesComboBox(); + initTextFontComboBox4GeneralFormats(); + initRoundingCheckBox4PercentFormat(); + initPreviewLabel4GeneralFormat(); + + initLayout(); + + setTextFieldVisible(false); + setRoundingBoxVisible(false); + setPreviewLabelVisible(false); } - protected void initComponents(Integer[] types) { - this.setLayout(new BorderLayout(0, 4)); - initSampleLabel(); - contentPane = new JPanel(new BorderLayout(0, 4)) { - @Override - public Dimension getPreferredSize() { - return new Dimension(super.getPreferredSize().width, 65); - } - }; - typeComboBox = new UIComboBox(types); - UIComboBoxRenderer render = createComBoxRender(); - typeComboBox.setRenderer(render); + private void initFormatTypesComboBox() { + typeComboBox = new UIComboBox(TextFormatPane.TYPES); + typeComboBox.setRenderer(createComBoxRender()); typeComboBox.addItemListener(itemListener); typeComboBox.setGlobalName("typeComboBox"); - contentPane.add(sampleLabel, BorderLayout.NORTH); + typeComboBox.setPreferredSize(new Dimension(155,20)); + } - txtCenterPane = new JPanel(new BorderLayout()); - textField = new TextFontComboBox(); + private void initTextFontComboBox4GeneralFormats() { + textField = new TextFontComboBox<>(); textField.addItemListener(textFieldItemListener); textField.setEditable(true); textField.setGlobalName("textField"); - txtCenterPane.add(textField, BorderLayout.NORTH); - - contentPane.add(txtCenterPane, BorderLayout.CENTER); - - centerPane = new JPanel(new CardLayout()); - centerPane.add(new JPanel(), "hide"); - centerPane.setPreferredSize(new Dimension(0, 0)); - centerPane.add(contentPane, "show"); - - typeComboBox.setPreferredSize(new Dimension(155,20)); - JPanel typePane = new JPanel(new BorderLayout()); - typePane.add(typeComboBox, BorderLayout.CENTER); - typePane.setBorder(BorderFactory.createEmptyBorder(0, 20, 0, 0)); + } - JPanel option = new JPanel(new BorderLayout()); - option.add(new UILabel(Toolkit.i18nText("Fine-Design_Report_Base_Option"), SwingConstants.LEFT), BorderLayout.WEST); + private void initRoundingCheckBox4PercentFormat() { roundingBox = new UICheckBox(Toolkit.i18nText("Fine-Design_Report_Base_Option_Half_Up")); roundingBox.setBorder(BorderFactory.createEmptyBorder(0, 30, 0, 0)); roundingBox.addItemListener(new ItemListener() { @@ -139,54 +110,13 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName } }); 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(centerPane, typePane); - this.add(createContentPane(components), BorderLayout.CENTER); } - protected JPanel createContentPane (Component[][] components) { - double f = TableLayout.FILL; - double p = TableLayout.PREFERRED; - double[] rowSize = new double[components.length]; - Arrays.fill(rowSize, p); - double[] columnSize = {p, f}; - int[][] rowCount = new int[components.length][2]; - Arrays.fill(rowCount, new int[] {1, 1}); - return TableLayoutHelper.createGapTableLayoutPane(components, rowSize, columnSize, rowCount, LayoutConstants.VGAP_LARGE, LayoutConstants.VGAP_MEDIUM); - } - - - protected Component[][] getComponent (JPanel centerPane, JPanel typePane) { - return new Component[][]{ - new Component[]{new UILabel(Toolkit.i18nText("Fine-Design_Report_Base_Format"), SwingConstants.LEFT), typePane}, - new Component[]{centerPane, null}, - new Component[]{optionPane, null}, - }; - } - - protected UIComboBoxRenderer createComBoxRender() { - return new UIComboBoxRenderer() { - @Override - public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { - JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); - if (value instanceof Integer) { - label.setText(" " + FormatField.getInstance().getName((Integer) value)); - } - return label; - } - }; - } - - private void initSampleLabel() { + private void initPreviewLabel4GeneralFormat() { Border interBorder = new UIRoundedBorder(UIConstants.LINE_COLOR, 1, 4); String title = Toolkit.i18nText("Fine-Design_Report_Base_StyleFormat_Sample"); Border border = BorderFactory.createTitledBorder(interBorder, title, TitledBorder.LEFT, 0, null, UIConstants.LINE_COLOR); - sampleLabel = new UILabel(FormatField.getInstance().getFormatValue()) { + previewLabel = new UILabel(FormatField.getInstance().getFormatValue()) { @Override public void paint(Graphics g) { @@ -198,12 +128,65 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName g.setColor(UIConstants.LINE_COLOR); FontMetrics cellFM = g.getFontMetrics(); int textWidth = cellFM.stringWidth(getText()); - GraphHelper.drawString(g, getText(), (width - textWidth) / 2, 26); + GraphHelper.drawString(g, getText(), (width - textWidth) / 2F, 26); g.setColor(original); } }; - sampleLabel.setHorizontalAlignment(UILabel.CENTER); - sampleLabel.setBorder(border); + previewLabel.setHorizontalAlignment(UILabel.CENTER); + previewLabel.setBorder(border); + } + + protected void initLayout() { + JPanel labeledFormatTypeComboBoxPane = new JPanel(new BorderLayout(20, 0)); + labeledFormatTypeComboBoxPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Report_Base_Format")), BorderLayout.WEST); + labeledFormatTypeComboBoxPane.add(typeComboBox, BorderLayout.CENTER); + + JPanel labeledRoundingCheckboxPane = new JPanel(new BorderLayout(0, 0)); + labeledRoundingCheckboxPane.add(new UILabel(Toolkit.i18nText("Fine-Design_Report_Base_Option")), BorderLayout.WEST); + labeledRoundingCheckboxPane.add(roundingBox, BorderLayout.CENTER); + + addComponents(4, new JComponent[] { labeledFormatTypeComboBoxPane, textField, labeledRoundingCheckboxPane, previewLabel}); + } + + protected void setTextFieldVisible(boolean visible) { + textField.setVisible(visible); + } + + protected void setRoundingBoxVisible(boolean visible) { + roundingBox.getParent().setVisible(visible); + } + + protected void setPreviewLabelVisible(boolean visible) { + previewLabel.setVisible(visible); + } + + protected void addComponents(int gap, JComponent[] components) { + JPanel container = this; + container.setLayout(new BorderLayout(0, gap)); + for (JComponent component: components) { + if (component != null) { + container.add(component, BorderLayout.NORTH); + JPanel nextContainer = new JPanel(new BorderLayout(0, gap)); + container.add(nextContainer, BorderLayout.CENTER); + container = nextContainer; + } + } + if (container.getComponentCount() == 0) { + container.getParent().remove(container); + } + } + + protected UIComboBoxRenderer createComBoxRender() { + return new UIComboBoxRenderer() { + @Override + public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { + JLabel label = (JLabel) super.getListCellRendererComponent(list, value, index, isSelected, cellHasFocus); + if (value instanceof Integer) { + label.setText(" " + FormatField.getInstance().getName((Integer) value)); + } + return label; + } + }; } @@ -231,8 +214,6 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName * Populate */ public void populateBean(Format format) { - this.format = format; - if (format == null) { this.typeComboBox.setSelectedIndex(FormatContents.NULL); } else { @@ -325,17 +306,17 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName * Refresh preview label. */ private void refreshPreviewLabel() { - this.sampleLabel.setText(FormatField.getInstance().getFormatValue()); - this.sampleLabel.setForeground(UIManager.getColor("Label.foreground")); + this.previewLabel.setText(FormatField.getInstance().getFormatValue()); + this.previewLabel.setForeground(UIManager.getColor("Label.foreground")); try { isRightFormat = true; if (StringUtils.isEmpty(String.valueOf(textField.getSelectedItem()))) { return; } - this.sampleLabel.setText(FormatField.getInstance().getFormatValue(getFormatContents(), String.valueOf(textField.getSelectedItem()))); + this.previewLabel.setText(FormatField.getInstance().getFormatValue(getFormatContents(), String.valueOf(textField.getSelectedItem()))); } catch (Exception e) { - this.sampleLabel.setForeground(Color.red); - this.sampleLabel.setText(e.getMessage()); + this.previewLabel.setForeground(Color.red); + this.previewLabel.setText(e.getMessage()); isRightFormat = false; } } @@ -354,28 +335,16 @@ public class TextFormatPane extends AbstractBasicStylePane implements GlobalName public void itemStateChanged(ItemEvent e) { if (e.getStateChange() == ItemEvent.SELECTED) { int contents = getFormatContents(); - String[] items = FormatField.getInstance().getFormatArray(contents, false); - CardLayout cardLayout = (CardLayout) centerPane.getLayout(); - if (isTextOrNull()) { - centerPane.setPreferredSize(new Dimension(0, 0)); - cardLayout.show(centerPane, "hide"); - } else { + if (!isTextOrNull()) { textField.removeAllItems(); + String[] items = FormatField.getInstance().getFormatArray(contents, false); textField.setItemArray(items); textField.setSelectedIndex(0); - 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); } + setTextFieldVisible(!isTextOrNull()); + setPreviewLabelVisible(!isTextOrNull()); + setRoundingBoxVisible(getFormatContents() == FormatContents.PERCENT); } } diff --git a/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java b/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java index fdc14efa39..1061b63635 100644 --- a/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java +++ b/designer-realize/src/main/java/com/fr/design/dscolumn/DSColumnAdvancedPane.java @@ -2,6 +2,7 @@ package com.fr.design.dscolumn; import com.fr.base.BaseFormula; import com.fr.data.util.SortOrder; +import com.fr.design.border.UITitledBorder; import com.fr.design.data.DesignTableDataManager; import com.fr.design.dialog.BasicPane; import com.fr.design.dialog.DialogActionAdapter; @@ -9,7 +10,6 @@ import com.fr.design.formula.CustomVariableResolver; import com.fr.design.formula.FormulaFactory; import com.fr.design.formula.SortFormulaPane; import com.fr.design.formula.UIFormula; -import com.fr.design.gui.frpane.AbstractAttrNoScrollPane; import com.fr.design.gui.ibutton.UIButton; import com.fr.design.gui.icheckbox.UICheckBox; import com.fr.design.gui.icombobox.UIComboBox; @@ -20,14 +20,12 @@ import com.fr.design.gui.style.TextFormatPane; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayout; import com.fr.design.layout.TableLayoutHelper; -import com.fr.design.style.FormatPane; import com.fr.design.utils.gui.GUICoreUtils; import com.fr.report.cell.CellElement; import com.fr.report.cell.TemplateCellElement; import com.fr.report.cell.cellattr.CellExpandAttr; import com.fr.report.cell.cellattr.core.group.DSColumn; import com.fr.report.cell.cellattr.core.group.SelectCount; -import com.fr.van.chart.designer.component.format.FormatPaneWithOutFont; import javax.swing.*; import java.awt.*; @@ -59,18 +57,19 @@ public class DSColumnAdvancedPane extends BasicPane { this.setLayout(FRGUIPaneFactory.createBorderLayout()); sortPane = new SortPane(); - sortPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Sort_Sort_Order"), null)); + sortPane.setBorder(UITitledBorder.createBorderWithTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Sort_Sort_Order"))); if (setting > DSColumnPane.SETTING_DSRELATED) { selectCountPane = new SelectCountPane(); - selectCountPane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Bind_Column_Results_Filter"), null)); + selectCountPane.setBorder(UITitledBorder.createBorderWithTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Bind_Column_Results_Filter"))); } valuePane = new ValuePane(); - valuePane.setBorder(GUICoreUtils.createTitledBorder(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Bind_Column_Custom_Data_Appearance"), null)); + valuePane.setBorder(UITitledBorder.createBorderWithTitle(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Bind_Column_Custom_Data_Appearance"))); formatAttrPane = new FormatAttrPane(); - + JPanel titleBorderedFormatPane = FRGUIPaneFactory.createTitledBorderPane(com.fr.design.i18n.Toolkit.i18nText("Fine-Design_Report_Base_Format")); + titleBorderedFormatPane.add(formatAttrPane, BorderLayout.NORTH); JPanel extendablePane = null; if (setting > DSColumnPane.SETTING_DSRELATED) { @@ -109,7 +108,7 @@ public class DSColumnAdvancedPane extends BasicPane { {sortPane}, {selectCountPane}, {valuePane}, - {formatAttrPane}, + {titleBorderedFormatPane}, {extendablePane}, {multiNumPane} }; @@ -117,7 +116,7 @@ public class DSColumnAdvancedPane extends BasicPane { components = new Component[][]{ {sortPane}, {valuePane}, - {formatAttrPane} + {titleBorderedFormatPane} }; } @@ -538,40 +537,31 @@ public class DSColumnAdvancedPane extends BasicPane { } } - public class FormatAttrPane extends AbstractAttrNoScrollPane { - private TextFormatPane formatPane; + public static class FormatAttrPane extends TextFormatPane { - @Override - protected JPanel createContentPane() { - this.formatPane = new TextFormatPane(); - return this.formatPane; - } + protected void initLayout() { + JPanel settingPane = FRGUIPaneFactory.createBoxFlowInnerContainer_S_Pane(0, 4, 0); + settingPane.add(typeComboBox); + settingPane.add(textField); + settingPane.add(roundingBox); - @Override - public Dimension getPreferredSize() { - if (formatPane == null) { - return super.getPreferredSize(); - } - return formatPane.getPreferredSize(); + addComponents(4, new JComponent[] { settingPane, previewLabel}); } - protected void initContentPane() { - leftContentPane = createContentPane(); - if (leftContentPane != null) { - leftContentPane.setBorder(BorderFactory.createEmptyBorder()); - this.add(leftContentPane, BorderLayout.CENTER); - } + @Override + protected void setRoundingBoxVisible(boolean visible) { + roundingBox.setVisible(visible); } public void populate(CellElement cellElement) { - if (cellElement != null && formatPane != null) { - formatPane.populateBean(cellElement.getStyle()); + if (cellElement != null) { + populateBean(cellElement.getStyle()); } } public void update(CellElement cellElement) { - if (cellElement != null && formatPane != null) { - cellElement.setStyle(formatPane.update(cellElement.getStyle())); + if (cellElement != null) { + cellElement.setStyle(update(cellElement.getStyle())); } } }