From 658e44fba128db83d9404bd241c9af17df5e93f8 Mon Sep 17 00:00:00 2001 From: "Henry.Wang" Date: Tue, 31 Aug 2021 13:54:05 +0800 Subject: [PATCH] =?UTF-8?q?KERNEL-8879=20=E8=87=AA=E9=80=82=E5=BA=94?= =?UTF-8?q?=E9=A2=84=E8=A7=88=E4=B8=8B=20=E7=BB=99=E6=8A=A5=E8=A1=A8?= =?UTF-8?q?=E5=9D=97=E5=A2=9E=E5=8A=A0=E8=87=AA=E9=80=82=E5=BA=94=E9=80=BB?= =?UTF-8?q?=E8=BE=91=E6=8E=A5=E5=8F=A3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../java/com/fr/design/fun/PcFitProvider.java | 19 ++++ .../fun/impl/AbstractPcFitProvider.java | 19 ++++ .../fit/attrpane/PcFitExpandablePane.java | 95 +++++++++++-------- 3 files changed, 96 insertions(+), 37 deletions(-) create mode 100644 designer-base/src/main/java/com/fr/design/fun/PcFitProvider.java create mode 100644 designer-base/src/main/java/com/fr/design/fun/impl/AbstractPcFitProvider.java diff --git a/designer-base/src/main/java/com/fr/design/fun/PcFitProvider.java b/designer-base/src/main/java/com/fr/design/fun/PcFitProvider.java new file mode 100644 index 000000000..46437917e --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/PcFitProvider.java @@ -0,0 +1,19 @@ +package com.fr.design.fun; + +import com.fr.stable.fun.mark.Mutable; + + +public interface PcFitProvider extends Mutable { + String XML_TAG = "PcFitProvider"; + int CURRENT_LEVEL = 1; + + //设计器上看到的选项 + String getContentDisplayValue(); + + //返回给前端的值 + int getContentDisplayKey(); + + //设计器上的提示信息 + String getContentDisplayTip(); + +} \ No newline at end of file diff --git a/designer-base/src/main/java/com/fr/design/fun/impl/AbstractPcFitProvider.java b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractPcFitProvider.java new file mode 100644 index 000000000..b3a43754e --- /dev/null +++ b/designer-base/src/main/java/com/fr/design/fun/impl/AbstractPcFitProvider.java @@ -0,0 +1,19 @@ +package com.fr.design.fun.impl; + +import com.fr.design.fun.PcFitProvider; +import com.fr.stable.fun.mark.API; + + +@API(level = PcFitProvider.CURRENT_LEVEL) +public abstract class AbstractPcFitProvider implements PcFitProvider { + + @Override + public int currentAPILevel() { + return CURRENT_LEVEL; + } + + @Override + public String mark4Provider() { + return getClass().getName(); + } +} \ No newline at end of file diff --git a/designer-form/src/main/java/com/fr/design/fit/attrpane/PcFitExpandablePane.java b/designer-form/src/main/java/com/fr/design/fit/attrpane/PcFitExpandablePane.java index 0bd1e2bd2..81ae07762 100644 --- a/designer-form/src/main/java/com/fr/design/fit/attrpane/PcFitExpandablePane.java +++ b/designer-form/src/main/java/com/fr/design/fit/attrpane/PcFitExpandablePane.java @@ -1,9 +1,12 @@ package com.fr.design.fit.attrpane; +import com.finebi.cbb.utils.CompareUtils; +import com.fr.design.ExtraDesignClassManager; import com.fr.design.designer.IntervalConstants; -import com.fr.design.fit.FitStateCompatible; +import com.fr.design.fun.PcFitProvider; import com.fr.design.gui.icombobox.UIComboBox; import com.fr.design.gui.ilable.UILabel; +import com.fr.design.i18n.Toolkit; import com.fr.design.layout.FRGUIPaneFactory; import com.fr.design.layout.TableLayoutHelper; import com.fr.design.widget.DataModify; @@ -17,23 +20,30 @@ import java.awt.Color; import java.awt.Component; import java.awt.event.ItemEvent; import java.awt.event.ItemListener; +import java.util.HashMap; +import java.util.Map; +import java.util.Set; /** * Created by kerry on 2020-04-22 */ public class PcFitExpandablePane extends JPanel { - UIComboBox comboBox = new UIComboBox( - new String[]{com.fr.design.i18n.Toolkit.i18nText("Fine-Designer_Fit_Ec_Double_Fit"), - com.fr.design.i18n.Toolkit.i18nText("Fine-Designer_Fit_Ec_Hor_Fit"), - com.fr.design.i18n.Toolkit.i18nText("Fine-Designer_Fit_Ec_No_Fit")}); - UILabel tipLabel = new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Designer_Fit_Ec_No_Fit_Tip")); + Item[] defaultItems = new Item[]{new Item(Toolkit.i18nText("Fine-Designer_Fit_Ec_Double_Fit"), 2, Toolkit.i18nText("Fine-Designer_Fit_Ec_Double_Fit_Tip")), + new Item(Toolkit.i18nText("Fine-Designer_Fit_Ec_Hor_Fit"), 1, Toolkit.i18nText("Fine-Designer_Fit_Ec_Hor_Fit_Tip")), + new Item(Toolkit.i18nText("Fine-Designer_Fit_Ec_No_Fit"), 3, Toolkit.i18nText("Fine-Designer_Fit_Ec_No_Fit_Tip"))}; + UIComboBox comboBox = new UIComboBox(); + UILabel tipLabel = new UILabel(Toolkit.i18nText("Fine-Designer_Fit_Ec_No_Fit_Tip")); + + Map contentDisplayType = new HashMap<>(); + Map contentDisplayTip = new HashMap<>(); public PcFitExpandablePane(DataModify attrPane) { init(attrPane); } public void init(final DataModify attrPane) { + initComboBox(); this.setLayout(FRGUIPaneFactory.createBorderLayout()); JPanel pcFitPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); final JPanel borderPane = FRGUIPaneFactory.createBorderLayout_S_Pane(); @@ -42,11 +52,11 @@ public class PcFitExpandablePane extends JPanel { comboBox.addItemListener(new ItemListener() { @Override public void itemStateChanged(ItemEvent e) { - tipLabel.setText(ScaleTipType.getScaleTip(comboBox.getSelectedIndex()).getTip()); + tipLabel.setText(contentDisplayTip.get(comboBox.getSelectedItem())); } }); Component[][] components = new Component[][]{ - new Component[]{new UILabel(com.fr.design.i18n.Toolkit.i18nText("Fine-Designer_Fit_Ec_Content_Display_Type")), comboBox}, + new Component[]{new UILabel(Toolkit.i18nText("Fine-Designer_Fit_Ec_Content_Display_Type")), comboBox}, new Component[]{tipLabel, null}, }; JPanel panel = TableLayoutHelper.createGapTableLayoutPane(components, TableLayoutHelper.FILL_LASTCOLUMN, IntervalConstants.INTERVAL_W0, IntervalConstants.INTERVAL_W0); @@ -58,50 +68,61 @@ public class PcFitExpandablePane extends JPanel { this.add(pcFitPane, BorderLayout.CENTER); } + private void initComboBox() { + for (Item item : defaultItems) { + comboBox.addItem(item.value); + contentDisplayType.put(item.key, item.value); + contentDisplayTip.put(item.value, item.tip); + } + + Set pcFitProviders = ExtraDesignClassManager.getInstance().getArray(PcFitProvider.XML_TAG); + + for (PcFitProvider pcFitProvider : pcFitProviders) { + comboBox.addItem(pcFitProvider.getContentDisplayValue()); + contentDisplayType.put(pcFitProvider.getContentDisplayKey(), pcFitProvider.getContentDisplayValue()); + contentDisplayTip.put(pcFitProvider.getContentDisplayValue(), pcFitProvider.getContentDisplayTip()); + } + } + public ReportFitAttr update() { - ReportFitAttr fitAttr = getReportFitAttr(); - fitAttr.setFitStateInPC(FitStateCompatible.getOldTypeFromNew(comboBox.getSelectedIndex())); + ReportFitAttr fitAttr = getDefaultReportFitAttr(); + String selectType = (String) comboBox.getSelectedItem(); + for (Integer key : contentDisplayType.keySet()) { + if (CompareUtils.isEqual(contentDisplayType.get(key), selectType)) { + fitAttr.setFitStateInPC(key); + } + } return fitAttr; } public void populate(ReportFitAttr fitAttr) { - if (fitAttr == null) { - fitAttr = getReportFitAttr(); + if (fitAttr == null || !contentDisplayType.keySet().contains(fitAttr.fitStateInPC())) { + fitAttr = getDefaultReportFitAttr(); + } + String selectType = contentDisplayType.get(fitAttr.fitStateInPC()); + for (int i = 0; i < comboBox.getItemCount(); i++) { + if (CompareUtils.isEqual(selectType, comboBox.getItemAt(i))) { + comboBox.setSelectedIndex(i); + tipLabel.setText(contentDisplayTip.get(selectType)); + } } - int selectIndex = FitStateCompatible.getNewTypeFromOld(fitAttr.fitStateInPC()); - comboBox.setSelectedIndex(selectIndex); - tipLabel.setText(ScaleTipType.getScaleTip(selectIndex).getTip()); } - private ReportFitAttr getReportFitAttr() { + private ReportFitAttr getDefaultReportFitAttr() { ReportFitAttr fitAttr = new ReportFitAttr(); fitAttr.setFitStateInPC(FitAttrState.NOT_FIT.getState()); return fitAttr; } - private enum ScaleTipType { - EC_DOUBLE_FIT(0, com.fr.design.i18n.Toolkit.i18nText("Fine-Designer_Fit_Ec_Double_Fit_Tip")), - EC_HOR_FIT(1, com.fr.design.i18n.Toolkit.i18nText("Fine-Designer_Fit_Ec_Hor_Fit_Tip")), - EC_NO_FIT(2, com.fr.design.i18n.Toolkit.i18nText("Fine-Designer_Fit_Ec_No_Fit_Tip")); - private int index; - private String tip; + class Item { + public String value; + public int key; + public String tip; - ScaleTipType(int index, String tip) { - this.index = index; + Item(String value, int key, String tip) { + this.value = value; + this.key = key; this.tip = tip; } - - public String getTip() { - return tip; - } - - public static ScaleTipType getScaleTip(int selectIndex) { - for (ScaleTipType tipType : values()) { - if (selectIndex == tipType.index) { - return tipType; - } - } - return EC_NO_FIT; - } } }